aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS8
-rw-r--r--Documentation/ABI/testing/debugfs-pktcdvd20
-rw-r--r--Documentation/ABI/testing/sysfs-class-pktcdvd72
-rw-r--r--Documentation/CodingStyle126
-rw-r--r--Documentation/DocBook/kernel-api.tmpl8
-rw-r--r--Documentation/SubmitChecklist6
-rw-r--r--Documentation/accounting/getdelays.c64
-rw-r--r--Documentation/cdrom/packet-writing.txt35
-rw-r--r--Documentation/dvb/cards.txt4
-rw-r--r--Documentation/fault-injection/failcmd.sh4
-rw-r--r--Documentation/fault-injection/failmodule.sh31
-rw-r--r--Documentation/fault-injection/fault-injection.txt225
-rw-r--r--Documentation/feature-removal-schedule.txt11
-rw-r--r--Documentation/filesystems/ocfs2.txt3
-rw-r--r--Documentation/i2c/busses/i2c-amd81112
-rw-r--r--Documentation/i2c/busses/i2c-i8015
-rw-r--r--Documentation/i2c/busses/i2c-nforce26
-rw-r--r--Documentation/ioctl-number.txt2
-rw-r--r--Documentation/ioctl/ioctl-decoding.txt24
-rw-r--r--Documentation/kernel-parameters.txt7
-rw-r--r--Documentation/networking/dccp.txt6
-rw-r--r--Documentation/s390/driver-model.txt7
-rw-r--r--Documentation/spi/pxa2xx16
-rw-r--r--Documentation/video4linux/CARDLIST.cx882
-rw-r--r--Documentation/video4linux/CARDLIST.saa71347
-rw-r--r--Documentation/video4linux/cafe_ccic54
-rw-r--r--Documentation/video4linux/zr36120.txt162
-rw-r--r--MAINTAINERS36
-rw-r--r--Makefile17
-rw-r--r--arch/alpha/Kconfig8
-rw-r--r--arch/alpha/kernel/osf_sys.c8
-rw-r--r--arch/arm/Kconfig8
-rw-r--r--arch/arm/mach-at91rm9200/at91sam9260_devices.c1
-rw-r--r--arch/arm/mach-at91rm9200/board-sam9260ek.c1
-rw-r--r--arch/arm/mach-pnx4008/Makefile2
-rw-r--r--arch/arm/mach-pnx4008/i2c.c167
-rw-r--r--arch/arm/mach-realview/core.c13
-rw-r--r--arch/arm/mach-realview/core.h1
-rw-r--r--arch/arm/mach-realview/realview_eb.c1
-rw-r--r--arch/arm/mach-versatile/core.c14
-rw-r--r--arch/arm26/Kconfig8
-rw-r--r--arch/avr32/Kconfig8
-rw-r--r--arch/avr32/boards/atstk1000/atstk1002.c76
-rw-r--r--arch/avr32/kernel/avr32_ksyms.c2
-rw-r--r--arch/avr32/kernel/process.c7
-rw-r--r--arch/avr32/kernel/setup.c24
-rw-r--r--arch/avr32/lib/delay.c2
-rw-r--r--arch/avr32/mach-at32ap/at32ap7000.c182
-rw-r--r--arch/avr32/mach-at32ap/extint.c22
-rw-r--r--arch/avr32/mach-at32ap/intc.c4
-rw-r--r--arch/avr32/mach-at32ap/pio.c85
-rw-r--r--arch/avr32/mach-at32ap/sm.c289
-rw-r--r--arch/cris/Kconfig8
-rw-r--r--arch/cris/arch-v32/drivers/sync_serial.c8
-rw-r--r--arch/frv/Kconfig8
-rw-r--r--arch/frv/kernel/pm.c6
-rw-r--r--arch/frv/mm/elf-fdpic.c4
-rw-r--r--arch/h8300/Kconfig8
-rw-r--r--arch/i386/Kconfig6
-rw-r--r--arch/i386/Kconfig.cpu8
-rw-r--r--arch/i386/defconfig28
-rw-r--r--arch/i386/kernel/cpuid.c4
-rw-r--r--arch/i386/kernel/io_apic.c2
-rw-r--r--arch/i386/kernel/module.c4
-rw-r--r--arch/i386/kernel/msr.c6
-rw-r--r--arch/i386/kernel/nmi.c8
-rw-r--r--arch/i386/kernel/quirks.c33
-rw-r--r--arch/i386/kernel/smpboot.c4
-rw-r--r--arch/i386/kernel/traps.c41
-rw-r--r--arch/i386/kernel/vmlinux.lds.S3
-rw-r--r--arch/i386/mach-visws/setup.c3
-rw-r--r--arch/ia64/Kconfig8
-rw-r--r--arch/ia64/ia32/sys_ia32.c4
-rw-r--r--arch/ia64/kernel/perfmon.c10
-rw-r--r--arch/ia64/kernel/salinfo.c6
-rw-r--r--arch/m32r/Kconfig8
-rw-r--r--arch/m32r/boot/compressed/m32r_sio.c7
-rw-r--r--arch/m32r/kernel/entry.S67
-rw-r--r--arch/m32r/kernel/io_opsput.c71
-rw-r--r--arch/m32r/kernel/setup_opsput.c17
-rw-r--r--arch/m32r/mm/fault.c4
-rw-r--r--arch/m68k/Kconfig8
-rw-r--r--arch/m68k/atari/stdma.c2
-rw-r--r--arch/m68k/kernel/sun3-head.S10
-rw-r--r--arch/m68k/kernel/vmlinux-sun3.lds2
-rw-r--r--arch/m68k/mm/memory.c4
-rw-r--r--arch/m68k/mm/sun3mmu.c7
-rw-r--r--arch/m68knommu/Kconfig8
-rw-r--r--arch/mips/Kconfig33
-rw-r--r--arch/mips/Makefile15
-rw-r--r--arch/mips/configs/atlas_defconfig2
-rw-r--r--arch/mips/configs/bigsur_defconfig2
-rw-r--r--arch/mips/configs/capcella_defconfig2
-rw-r--r--arch/mips/configs/cobalt_defconfig2
-rw-r--r--arch/mips/configs/db1000_defconfig2
-rw-r--r--arch/mips/configs/db1100_defconfig2
-rw-r--r--arch/mips/configs/db1200_defconfig2
-rw-r--r--arch/mips/configs/db1500_defconfig2
-rw-r--r--arch/mips/configs/db1550_defconfig2
-rw-r--r--arch/mips/configs/ddb5477_defconfig2
-rw-r--r--arch/mips/configs/decstation_defconfig2
-rw-r--r--arch/mips/configs/e55_defconfig2
-rw-r--r--arch/mips/configs/emma2rh_defconfig2
-rw-r--r--arch/mips/configs/ev64120_defconfig2
-rw-r--r--arch/mips/configs/excite_defconfig2
-rw-r--r--arch/mips/configs/ip22_defconfig2
-rw-r--r--arch/mips/configs/ip27_defconfig2
-rw-r--r--arch/mips/configs/ip32_defconfig2
-rw-r--r--arch/mips/configs/jaguar-atx_defconfig2
-rw-r--r--arch/mips/configs/jazz_defconfig2
-rw-r--r--arch/mips/configs/jmr3927_defconfig2
-rw-r--r--arch/mips/configs/lasat200_defconfig2
-rw-r--r--arch/mips/configs/malta_defconfig82
-rw-r--r--arch/mips/configs/mipssim_defconfig2
-rw-r--r--arch/mips/configs/mpc30x_defconfig2
-rw-r--r--arch/mips/configs/ocelot_3_defconfig2
-rw-r--r--arch/mips/configs/ocelot_c_defconfig2
-rw-r--r--arch/mips/configs/ocelot_defconfig2
-rw-r--r--arch/mips/configs/ocelot_g_defconfig2
-rw-r--r--arch/mips/configs/pb1100_defconfig2
-rw-r--r--arch/mips/configs/pb1500_defconfig2
-rw-r--r--arch/mips/configs/pb1550_defconfig2
-rw-r--r--arch/mips/configs/pnx8550-jbs_defconfig2
-rw-r--r--arch/mips/configs/pnx8550-stb810_defconfig1229
-rw-r--r--arch/mips/configs/pnx8550-v2pci_defconfig2
-rw-r--r--arch/mips/configs/qemu_defconfig2
-rw-r--r--arch/mips/configs/rbhma4500_defconfig2
-rw-r--r--arch/mips/configs/rm200_defconfig2
-rw-r--r--arch/mips/configs/sb1250-swarm_defconfig2
-rw-r--r--arch/mips/configs/sead_defconfig2
-rw-r--r--arch/mips/configs/tb0226_defconfig2
-rw-r--r--arch/mips/configs/tb0229_defconfig2
-rw-r--r--arch/mips/configs/tb0287_defconfig2
-rw-r--r--arch/mips/configs/workpad_defconfig2
-rw-r--r--arch/mips/configs/wrppmc_defconfig2
-rw-r--r--arch/mips/configs/yosemite_defconfig2
-rw-r--r--arch/mips/defconfig2
-rw-r--r--arch/mips/kernel/head.S2
-rw-r--r--arch/mips/kernel/irixelf.c2
-rw-r--r--arch/mips/kernel/kspd.c2
-rw-r--r--arch/mips/kernel/reset.c2
-rw-r--r--arch/mips/kernel/rtlx.c6
-rw-r--r--arch/mips/kernel/sysirix.c10
-rw-r--r--arch/mips/kernel/vmlinux.lds.S2
-rw-r--r--arch/mips/kernel/vpe.c2
-rw-r--r--arch/mips/lasat/sysctl.c23
-rw-r--r--arch/mips/lib/csum_partial.S293
-rw-r--r--arch/mips/lib/csum_partial_copy.c3
-rw-r--r--arch/mips/mips-boards/malta/Makefile2
-rw-r--r--arch/mips/mips-boards/malta/malta_setup.c39
-rw-r--r--arch/mips/mm/cache.c1
-rw-r--r--arch/mips/mm/init.c17
-rw-r--r--arch/mips/mm/ioremap.c96
-rw-r--r--arch/mips/pci/Makefile2
-rw-r--r--arch/mips/pci/fixup-pnx8550.c4
-rw-r--r--arch/mips/philips/pnx8550/common/prom.c20
-rw-r--r--arch/mips/philips/pnx8550/jbs/irqmap.c8
-rw-r--r--arch/mips/philips/pnx8550/stb810/Makefile4
-rw-r--r--arch/mips/philips/pnx8550/stb810/board_setup.c49
-rw-r--r--arch/mips/philips/pnx8550/stb810/irqmap.c23
-rw-r--r--arch/mips/philips/pnx8550/stb810/prom_init.c49
-rw-r--r--arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_irq.c27
-rw-r--r--arch/mips/vr41xx/Kconfig5
-rw-r--r--arch/mips/vr41xx/nec-cmbvr4133/irq.c9
-rw-r--r--arch/parisc/Kconfig8
-rw-r--r--arch/parisc/hpux/sys_hpux.c2
-rw-r--r--arch/parisc/mm/ioremap.c111
-rw-r--r--arch/powerpc/Kconfig16
-rw-r--r--arch/powerpc/configs/ps3_defconfig1
-rw-r--r--arch/powerpc/kernel/Makefile1
-rw-r--r--arch/powerpc/kernel/cputable.c5
-rw-r--r--arch/powerpc/kernel/head_32.S7
-rw-r--r--arch/powerpc/kernel/module_32.c23
-rw-r--r--arch/powerpc/kernel/module_64.c23
-rw-r--r--arch/powerpc/kernel/of_device.c4
-rw-r--r--arch/powerpc/kernel/of_platform.c2
-rw-r--r--arch/powerpc/kernel/pci_32.c143
-rw-r--r--arch/powerpc/kernel/pci_64.c42
-rw-r--r--arch/powerpc/kernel/ppc_ksyms.c2
-rw-r--r--arch/powerpc/kernel/proc_ppc64.c6
-rw-r--r--arch/powerpc/kernel/prom.c55
-rw-r--r--arch/powerpc/kernel/prom_init.c2
-rw-r--r--arch/powerpc/kernel/rtas.c35
-rw-r--r--arch/powerpc/kernel/rtas_flash.c16
-rw-r--r--arch/powerpc/kernel/sysfs.c16
-rw-r--r--arch/powerpc/kernel/traps.c56
-rw-r--r--arch/powerpc/kernel/vmlinux.lds.S6
-rw-r--r--arch/powerpc/mm/numa.c65
-rw-r--r--arch/powerpc/platforms/52xx/lite5200.c2
-rw-r--r--arch/powerpc/platforms/cell/cbe_thermal.c2
-rw-r--r--arch/powerpc/platforms/cell/pmu.c5
-rw-r--r--arch/powerpc/platforms/cell/spufs/coredump.c2
-rw-r--r--arch/powerpc/platforms/cell/spufs/inode.c4
-rw-r--r--arch/powerpc/platforms/cell/spufs/syscalls.c2
-rw-r--r--arch/powerpc/platforms/iseries/mf.c2
-rw-r--r--arch/powerpc/platforms/maple/pci.c2
-rw-r--r--arch/powerpc/platforms/maple/setup.c12
-rw-r--r--arch/powerpc/platforms/ps3/Kconfig11
-rw-r--r--arch/powerpc/platforms/pseries/Makefile2
-rw-r--r--arch/powerpc/platforms/pseries/eeh.c1
-rw-r--r--arch/powerpc/platforms/pseries/eeh_driver.c13
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-cpu.c275
-rw-r--r--arch/powerpc/platforms/pseries/hvCall_inst.c2
-rw-r--r--arch/powerpc/platforms/pseries/scanlog.c2
-rw-r--r--arch/powerpc/platforms/pseries/setup.c30
-rw-r--r--arch/powerpc/platforms/pseries/smp.c200
-rw-r--r--arch/powerpc/sysdev/Makefile3
-rw-r--r--arch/powerpc/sysdev/dcr.S39
-rw-r--r--arch/powerpc/sysdev/qe_lib/qe_ic.c40
-rw-r--r--arch/powerpc/sysdev/rom.c1
-rw-r--r--arch/powerpc/xmon/xmon.c10
-rw-r--r--arch/ppc/8xx_io/cs4218_tdm.c12
-rw-r--r--arch/ppc/Kconfig13
-rw-r--r--arch/ppc/kernel/pci.c41
-rw-r--r--arch/ppc/kernel/traps.c64
-rw-r--r--arch/s390/Kconfig22
-rw-r--r--arch/s390/defconfig1
-rw-r--r--arch/s390/hypfs/inode.c4
-rw-r--r--arch/s390/kernel/debug.c4
-rw-r--r--arch/s390/kernel/setup.c55
-rw-r--r--arch/s390/lib/uaccess_pt.c5
-rw-r--r--arch/s390/mm/Makefile2
-rw-r--r--arch/s390/mm/extmem.c106
-rw-r--r--arch/s390/mm/init.c184
-rw-r--r--arch/s390/mm/ioremap.c84
-rw-r--r--arch/s390/mm/vmem.c381
-rw-r--r--arch/sh/Kconfig22
-rw-r--r--arch/sh/Kconfig.debug3
-rw-r--r--arch/sh/Makefile7
-rw-r--r--arch/sh/boards/landisk/irq.c4
-rw-r--r--arch/sh/boards/se/7206/irq.c16
-rw-r--r--arch/sh/boards/se/7619/Makefile2
-rw-r--r--arch/sh/boards/se/7619/io.c102
-rw-r--r--arch/sh/boards/se/7619/setup.c21
-rw-r--r--arch/sh/boot/Makefile40
-rw-r--r--arch/sh/boot/compressed/Makefile6
-rw-r--r--arch/sh/boot/compressed/head.S3
-rw-r--r--arch/sh/boot/compressed/misc.c3
-rw-r--r--arch/sh/configs/landisk_defconfig85
-rw-r--r--arch/sh/configs/se7206_defconfig142
-rw-r--r--arch/sh/configs/se7619_defconfig744
-rw-r--r--arch/sh/drivers/push-switch.c13
-rw-r--r--arch/sh/kernel/cpu/Makefile1
-rw-r--r--arch/sh/kernel/cpu/sh2/entry.S32
-rw-r--r--arch/sh/kernel/cpu/sh2/setup-sh7619.c41
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7206.c62
-rw-r--r--arch/sh/kernel/cpu/sh4/Makefile9
-rw-r--r--arch/sh/kernel/cpu/sh4/probe.c9
-rw-r--r--arch/sh/kernel/cpu/sh4/setup-sh7750.c31
-rw-r--r--arch/sh/kernel/cpu/sh4/sq.c7
-rw-r--r--arch/sh/kernel/cpu/sh4a/Makefile19
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh73180.c (renamed from arch/sh/kernel/cpu/sh4/clock-sh73180.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7343.c99
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7770.c (renamed from arch/sh/kernel/cpu/sh4/clock-sh7770.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7780.c (renamed from arch/sh/kernel/cpu/sh4/clock-sh7780.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh73180.c (renamed from arch/sh/kernel/cpu/sh4/setup-sh73180.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7343.c (renamed from arch/sh/kernel/cpu/sh4/setup-sh7343.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7722.c80
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7770.c (renamed from arch/sh/kernel/cpu/sh4/setup-sh7770.c)0
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7780.c (renamed from arch/sh/kernel/cpu/sh4/setup-sh7780.c)0
-rw-r--r--arch/sh/kernel/early_printk.c20
-rw-r--r--arch/sh/kernel/entry-common.S15
-rw-r--r--arch/sh/kernel/head.S3
-rw-r--r--arch/sh/kernel/process.c15
-rw-r--r--arch/sh/kernel/setup.c41
-rw-r--r--arch/sh/kernel/sh_ksyms.c15
-rw-r--r--arch/sh/kernel/signal.c2
-rw-r--r--arch/sh/kernel/sys_sh.c8
-rw-r--r--arch/sh/kernel/traps.c35
-rw-r--r--arch/sh/kernel/vmlinux.lds.S2
-rw-r--r--arch/sh/mm/Kconfig12
-rw-r--r--arch/sh/mm/cache-sh4.c2
-rw-r--r--arch/sh/mm/init.c2
-rw-r--r--arch/sh/mm/ioremap.c90
-rw-r--r--arch/sh/oprofile/op_model_sh7750.c2
-rw-r--r--arch/sh64/Kconfig8
-rw-r--r--arch/sh64/mm/ioremap.c100
-rw-r--r--arch/sparc/Kconfig8
-rw-r--r--arch/sparc/kernel/ioport.c6
-rw-r--r--arch/sparc/kernel/of_device.c3
-rw-r--r--arch/sparc/kernel/ptrace.c5
-rw-r--r--arch/sparc/kernel/sun4d_irq.c7
-rw-r--r--arch/sparc/kernel/sys_sunos.c6
-rw-r--r--arch/sparc/mm/io-unit.c8
-rw-r--r--arch/sparc64/Kconfig16
-rw-r--r--arch/sparc64/Kconfig.debug4
-rw-r--r--arch/sparc64/defconfig54
-rw-r--r--arch/sparc64/kernel/Makefile1
-rw-r--r--arch/sparc64/kernel/binfmt_aout32.c4
-rw-r--r--arch/sparc64/kernel/chmc.c3
-rw-r--r--arch/sparc64/kernel/entry.S27
-rw-r--r--arch/sparc64/kernel/head.S8
-rw-r--r--arch/sparc64/kernel/isa.c12
-rw-r--r--arch/sparc64/kernel/kprobes.c91
-rw-r--r--arch/sparc64/kernel/of_device.c3
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c16
-rw-r--r--arch/sparc64/kernel/ptrace.c5
-rw-r--r--arch/sparc64/kernel/rtrap.S23
-rw-r--r--arch/sparc64/kernel/stacktrace.c41
-rw-r--r--arch/sparc64/kernel/sun4v_ivec.S20
-rw-r--r--arch/sparc64/kernel/sys_sunos32.c4
-rw-r--r--arch/sparc64/kernel/traps.c30
-rw-r--r--arch/sparc64/kernel/unaligned.c44
-rw-r--r--arch/sparc64/kernel/visemul.c6
-rw-r--r--arch/sparc64/mm/ultra.S8
-rw-r--r--arch/sparc64/solaris/fs.c4
-rw-r--r--arch/sparc64/solaris/ioctl.c6
-rw-r--r--arch/sparc64/solaris/misc.c6
-rw-r--r--arch/sparc64/solaris/socksys.c14
-rw-r--r--arch/sparc64/solaris/timod.c10
-rw-r--r--arch/um/Kconfig5
-rw-r--r--arch/um/drivers/line.c2
-rw-r--r--arch/um/include/line.h2
-rw-r--r--arch/um/kernel/exec.c7
-rw-r--r--arch/um/sys-i386/Makefile2
-rw-r--r--arch/um/sys-i386/bug.c20
-rw-r--r--arch/um/sys-x86_64/Makefile2
-rw-r--r--arch/um/sys-x86_64/bug.c20
-rw-r--r--arch/v850/Kconfig8
-rw-r--r--arch/x86_64/Kconfig15
-rw-r--r--arch/x86_64/defconfig29
-rw-r--r--arch/x86_64/ia32/ia32_aout.c8
-rw-r--r--arch/x86_64/kernel/module.c5
-rw-r--r--arch/x86_64/kernel/nmi.c9
-rw-r--r--arch/x86_64/kernel/traps.c36
-rw-r--r--arch/x86_64/kernel/vmlinux.lds.S3
-rw-r--r--arch/x86_64/kernel/vsyscall.c3
-rw-r--r--arch/xtensa/Kconfig29
-rw-r--r--arch/xtensa/Makefile25
-rw-r--r--arch/xtensa/boot/boot-elf/bootstrap.S3
-rw-r--r--arch/xtensa/boot/boot-redboot/bootstrap.S37
-rw-r--r--arch/xtensa/configs/iss_defconfig6
-rw-r--r--arch/xtensa/kernel/align.S42
-rw-r--r--arch/xtensa/kernel/asm-offsets.c5
-rw-r--r--arch/xtensa/kernel/coprocessor.S2
-rw-r--r--arch/xtensa/kernel/entry.S256
-rw-r--r--arch/xtensa/kernel/head.S53
-rw-r--r--arch/xtensa/kernel/irq.c107
-rw-r--r--arch/xtensa/kernel/pci-dma.c44
-rw-r--r--arch/xtensa/kernel/process.c108
-rw-r--r--arch/xtensa/kernel/ptrace.c28
-rw-r--r--arch/xtensa/kernel/setup.c41
-rw-r--r--arch/xtensa/kernel/signal.c28
-rw-r--r--arch/xtensa/kernel/syscall.c95
-rw-r--r--arch/xtensa/kernel/syscalls.c288
-rw-r--r--arch/xtensa/kernel/syscalls.h247
-rw-r--r--arch/xtensa/kernel/time.c8
-rw-r--r--arch/xtensa/kernel/traps.c56
-rw-r--r--arch/xtensa/kernel/vectors.S12
-rw-r--r--arch/xtensa/kernel/vmlinux.lds.S26
-rw-r--r--arch/xtensa/lib/checksum.S3
-rw-r--r--arch/xtensa/lib/memcopy.S2
-rw-r--r--arch/xtensa/lib/memset.S2
-rw-r--r--arch/xtensa/lib/strncpy_user.S2
-rw-r--r--arch/xtensa/lib/strnlen_user.S2
-rw-r--r--arch/xtensa/lib/usercopy.S2
-rw-r--r--arch/xtensa/mm/fault.c10
-rw-r--r--arch/xtensa/mm/init.c6
-rw-r--r--arch/xtensa/mm/misc.S265
-rw-r--r--arch/xtensa/mm/tlb.c445
-rw-r--r--arch/xtensa/platform-iss/console.c8
-rw-r--r--arch/xtensa/platform-iss/network.c2
-rw-r--r--block/genhd.c31
-rw-r--r--block/ioctl.c6
-rw-r--r--block/ll_rw_blk.c59
-rw-r--r--block/scsi_ioctl.c10
-rw-r--r--crypto/sha512.c2
-rw-r--r--drivers/Kconfig4
-rw-r--r--drivers/Makefile2
-rw-r--r--drivers/acorn/char/i2c.c2
-rw-r--r--drivers/atm/.gitignore2
-rw-r--r--drivers/atm/Kconfig1
-rw-r--r--drivers/atm/ambassador.c17
-rw-r--r--drivers/block/Kconfig14
-rw-r--r--drivers/block/acsi_slm.c4
-rw-r--r--drivers/block/cciss.c2
-rw-r--r--drivers/block/loop.c4
-rw-r--r--drivers/block/nbd.c2
-rw-r--r--drivers/block/pktcdvd.c547
-rw-r--r--drivers/char/Kconfig15
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/amiserial.c6
-rw-r--r--drivers/char/cs5535_gpio.c4
-rw-r--r--drivers/char/cyclades.c7769
-rw-r--r--drivers/char/drm/drm.h33
-rw-r--r--drivers/char/drm/drmP.h23
-rw-r--r--drivers/char/drm/drm_bufs.c10
-rw-r--r--drivers/char/drm/drm_core.h8
-rw-r--r--drivers/char/drm/drm_drawable.c294
-rw-r--r--drivers/char/drm/drm_drv.c14
-rw-r--r--drivers/char/drm/drm_ioc32.c56
-rw-r--r--drivers/char/drm/drm_irq.c155
-rw-r--r--drivers/char/drm/drm_lock.c11
-rw-r--r--drivers/char/drm/drm_stub.c2
-rw-r--r--drivers/char/drm/drm_vm.c16
-rw-r--r--drivers/char/drm/i915_dma.c2
-rw-r--r--drivers/char/drm/i915_drm.h19
-rw-r--r--drivers/char/drm/i915_drv.c4
-rw-r--r--drivers/char/drm/i915_drv.h22
-rw-r--r--drivers/char/drm/i915_ioc32.c12
-rw-r--r--drivers/char/drm/i915_irq.c265
-rw-r--r--drivers/char/drm/mga_ioc32.c8
-rw-r--r--drivers/char/drm/r128_ioc32.c10
-rw-r--r--drivers/char/drm/radeon_ioc32.c20
-rw-r--r--drivers/char/dsp56k.c6
-rw-r--r--drivers/char/dtlk.c4
-rw-r--r--drivers/char/epca.c16
-rw-r--r--drivers/char/esp.c2
-rw-r--r--drivers/char/generic_serial.c4
-rw-r--r--drivers/char/hvcs.c6
-rw-r--r--drivers/char/hvsi.c2
-rw-r--r--drivers/char/ip2/ip2main.c12
-rw-r--r--drivers/char/ipmi/ipmi_bt_sm.c4
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c6
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c12
-rw-r--r--drivers/char/ipmi/ipmi_poweroff.c6
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c132
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c18
-rw-r--r--drivers/char/isicom.c296
-rw-r--r--drivers/char/istallion.c1164
-rw-r--r--drivers/char/keyboard.c2
-rw-r--r--drivers/char/lp.c4
-rw-r--r--drivers/char/mem.c16
-rw-r--r--drivers/char/moxa.c18
-rw-r--r--drivers/char/mxser.c32
-rw-r--r--drivers/char/mxser_new.c2804
-rw-r--r--drivers/char/mxser_new.h450
-rw-r--r--drivers/char/n_r3964.c4
-rw-r--r--drivers/char/n_tty.c2
-rw-r--r--drivers/char/nsc_gpio.c4
-rw-r--r--drivers/char/pcmcia/synclink_cs.c2
-rw-r--r--drivers/char/ppdev.c4
-rw-r--r--drivers/char/pty.c10
-rw-r--r--drivers/char/random.c4
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/riscom8.c4
-rw-r--r--drivers/char/rocket.c10
-rw-r--r--drivers/char/ser_a2232.c2
-rw-r--r--drivers/char/serial167.c2
-rw-r--r--drivers/char/sonypi.c2
-rw-r--r--drivers/char/specialix.c9
-rw-r--r--drivers/char/stallion.c2148
-rw-r--r--drivers/char/sx.c2232
-rw-r--r--drivers/char/sx.h1
-rw-r--r--drivers/char/synclink.c4
-rw-r--r--drivers/char/synclink_gt.c6
-rw-r--r--drivers/char/synclinkmp.c6
-rw-r--r--drivers/char/tb0219.c4
-rw-r--r--drivers/char/tipar.c4
-rw-r--r--drivers/char/tty_io.c396
-rw-r--r--drivers/char/tty_ioctl.c264
-rw-r--r--drivers/char/vc_screen.c6
-rw-r--r--drivers/char/viotape.c10
-rw-r--r--drivers/char/vme_scc.c2
-rw-r--r--drivers/char/vr41xx_giu.c4
-rw-r--r--drivers/clocksource/acpi_pm.c42
-rw-r--r--drivers/crypto/Kconfig2
-rw-r--r--drivers/hid/Kconfig18
-rw-r--r--drivers/hid/Makefile15
-rw-r--r--drivers/hid/hid-core.c1003
-rw-r--r--drivers/hid/hid-input.c (renamed from drivers/usb/input/hid-input.c)153
-rw-r--r--drivers/i2c/algos/Kconfig11
-rw-r--r--drivers/i2c/algos/Makefile1
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c8
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.c806
-rw-r--r--drivers/i2c/algos/i2c-algo-ite.h117
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c7
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c8
-rw-r--r--drivers/i2c/algos/i2c-algo-sgi.c8
-rw-r--r--drivers/i2c/busses/Kconfig49
-rw-r--r--drivers/i2c/busses/Makefile4
-rw-r--r--drivers/i2c/busses/i2c-at91.c325
-rw-r--r--drivers/i2c/busses/i2c-elektor.c2
-rw-r--r--drivers/i2c/busses/i2c-hydra.c2
-rw-r--r--drivers/i2c/busses/i2c-i801.c16
-rw-r--r--drivers/i2c/busses/i2c-i810.c6
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c9
-rw-r--r--drivers/i2c/busses/i2c-ite.c278
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c89
-rw-r--r--drivers/i2c/busses/i2c-omap.c4
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c2
-rw-r--r--drivers/i2c/busses/i2c-parport.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c2
-rw-r--r--drivers/i2c/busses/i2c-pnx.c708
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c2
-rw-r--r--drivers/i2c/busses/i2c-savage4.c2
-rw-r--r--drivers/i2c/busses/i2c-versatile.c153
-rw-r--r--drivers/i2c/busses/i2c-via.c2
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c6
-rw-r--r--drivers/i2c/busses/scx200_i2c.c2
-rw-r--r--drivers/i2c/chips/ds1337.c8
-rw-r--r--drivers/i2c/i2c-core.c67
-rw-r--r--drivers/i2c/i2c-dev.c48
-rw-r--r--drivers/ide/ide-cd.c7
-rw-r--r--drivers/ide/ide-probe.c4
-rw-r--r--drivers/ide/pci/alim15x3.c16
-rw-r--r--drivers/ide/pci/pdc202xx_new.c503
-rw-r--r--drivers/ide/pci/piix.c4
-rw-r--r--drivers/ide/pci/sis5513.c3
-rw-r--r--drivers/ide/pci/sl82c105.c31
-rw-r--r--drivers/ide/setup-pci.c4
-rw-r--r--drivers/ieee1394/ieee1394_core.h2
-rw-r--r--drivers/ieee1394/pcilynx.c2
-rw-r--r--drivers/infiniband/core/uverbs_main.c6
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_fs.c10
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c4
-rw-r--r--drivers/infiniband/ulp/iser/iser_memory.c4
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/ff-core.c4
-rw-r--r--drivers/input/ff-memless.c2
-rw-r--r--drivers/input/gameport/gameport.c19
-rw-r--r--drivers/input/gameport/lightning.c4
-rw-r--r--drivers/input/input.c25
-rw-r--r--drivers/input/joystick/adi.c10
-rw-r--r--drivers/input/joystick/amijoy.c6
-rw-r--r--drivers/input/joystick/analog.c10
-rw-r--r--drivers/input/joystick/cobra.c7
-rw-r--r--drivers/input/joystick/gf2k.c4
-rw-r--r--drivers/input/joystick/grip_mp.c13
-rw-r--r--drivers/input/joystick/guillemot.c4
-rw-r--r--drivers/input/joystick/iforce/iforce-main.c31
-rw-r--r--drivers/input/joystick/iforce/iforce-serio.c20
-rw-r--r--drivers/input/joystick/interact.c4
-rw-r--r--drivers/input/joystick/magellan.c17
-rw-r--r--drivers/input/joystick/spaceball.c17
-rw-r--r--drivers/input/joystick/spaceorb.c17
-rw-r--r--drivers/input/joystick/stinger.c17
-rw-r--r--drivers/input/joystick/twidjoy.c17
-rw-r--r--drivers/input/joystick/warrior.c17
-rw-r--r--drivers/input/keyboard/Kconfig11
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/aaed2000_kbd.c203
-rw-r--r--drivers/input/keyboard/amikbd.c22
-rw-r--r--drivers/input/keyboard/atkbd.c162
-rw-r--r--drivers/input/keyboard/corgikbd.c17
-rw-r--r--drivers/input/keyboard/hil_kbd.c3
-rw-r--r--drivers/input/keyboard/lkkbd.c17
-rw-r--r--drivers/input/keyboard/locomokbd.c28
-rw-r--r--drivers/input/keyboard/maple_keyb.c160
-rw-r--r--drivers/input/keyboard/newtonkbd.c17
-rw-r--r--drivers/input/keyboard/spitzkbd.c24
-rw-r--r--drivers/input/keyboard/stowaway.c3
-rw-r--r--drivers/input/keyboard/sunkbd.c23
-rw-r--r--drivers/input/keyboard/xtkbd.c17
-rw-r--r--drivers/input/mouse/amimouse.c11
-rw-r--r--drivers/input/mouse/hil_ptr.c3
-rw-r--r--drivers/input/mouse/inport.c23
-rw-r--r--drivers/input/mouse/lifebook.c82
-rw-r--r--drivers/input/mouse/logibm.c24
-rw-r--r--drivers/input/mouse/logips2pp.c11
-rw-r--r--drivers/input/mouse/pc110pad.c26
-rw-r--r--drivers/input/mouse/psmouse-base.c101
-rw-r--r--drivers/input/mouse/rpcmouse.c20
-rw-r--r--drivers/input/mouse/sermouse.c16
-rw-r--r--drivers/input/mouse/trackpoint.c12
-rw-r--r--drivers/input/mouse/vsxxxaa.c16
-rw-r--r--drivers/input/mousedev.c2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h7
-rw-r--r--drivers/input/serio/i8042.c39
-rw-r--r--drivers/input/serio/serio.c147
-rw-r--r--drivers/input/serio/serio_raw.c3
-rw-r--r--drivers/input/touchscreen/Kconfig15
-rw-r--r--drivers/input/touchscreen/Makefile1
-rw-r--r--drivers/input/touchscreen/ads7846.c95
-rw-r--r--drivers/input/touchscreen/corgi_ts.c30
-rw-r--r--drivers/input/touchscreen/elo.c3
-rw-r--r--drivers/input/touchscreen/gunze.c17
-rw-r--r--drivers/input/touchscreen/h3600_ts_input.c3
-rw-r--r--drivers/input/touchscreen/hp680_ts_input.c29
-rw-r--r--drivers/input/touchscreen/mk712.c26
-rw-r--r--drivers/input/touchscreen/mtouch.c16
-rw-r--r--drivers/input/touchscreen/penmount.c3
-rw-r--r--drivers/input/touchscreen/touchright.c3
-rw-r--r--drivers/input/touchscreen/touchwin.c3
-rw-r--r--drivers/input/touchscreen/ucb1400_ts.c579
-rw-r--r--drivers/isdn/act2000/module.c3
-rw-r--r--drivers/isdn/capi/capi.c13
-rw-r--r--drivers/isdn/capi/capidrv.c9
-rw-r--r--drivers/isdn/gigaset/Kconfig1
-rw-r--r--drivers/isdn/gigaset/asyncdata.c5
-rw-r--r--drivers/isdn/gigaset/common.c37
-rw-r--r--drivers/isdn/gigaset/gigaset.h4
-rw-r--r--drivers/isdn/gigaset/interface.c4
-rw-r--r--drivers/isdn/gigaset/isocdata.c5
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c3
-rw-r--r--drivers/isdn/hardware/avm/b1.c10
-rw-r--r--drivers/isdn/hardware/avm/t1isa.c1
-rw-r--r--drivers/isdn/hardware/eicon/debug.c4
-rw-r--r--drivers/isdn/hardware/eicon/di.c8
-rw-r--r--drivers/isdn/hardware/eicon/divasmain.c2
-rw-r--r--drivers/isdn/hardware/eicon/io.c2
-rw-r--r--drivers/isdn/hardware/eicon/istream.c4
-rw-r--r--drivers/isdn/hardware/eicon/platform.h8
-rw-r--r--drivers/isdn/hisax/Kconfig18
-rw-r--r--drivers/isdn/hisax/avma1_cs.c3
-rw-r--r--drivers/isdn/hisax/config.c21
-rw-r--r--drivers/isdn/hisax/diva.c4
-rw-r--r--drivers/isdn/hisax/elsa_cs.c3
-rw-r--r--drivers/isdn/hisax/fsm.c4
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c3
-rw-r--r--drivers/isdn/hisax/hfc_pci.c10
-rw-r--r--drivers/isdn/hisax/hfc_usb.c3
-rw-r--r--drivers/isdn/hisax/hisax.h6
-rw-r--r--drivers/isdn/hisax/hisax_fcpcipnp.c4
-rw-r--r--drivers/isdn/hisax/hisax_isac.c2
-rw-r--r--drivers/isdn/hisax/isdnhdlc.c25
-rw-r--r--drivers/isdn/hisax/isdnhdlc.h2
-rw-r--r--drivers/isdn/hisax/sedlbauer.c4
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c3
-rw-r--r--drivers/isdn/hisax/st5481_b.c3
-rw-r--r--drivers/isdn/hisax/st5481_d.c4
-rw-r--r--drivers/isdn/hisax/st5481_init.c4
-rw-r--r--drivers/isdn/hisax/teles_cs.c3
-rw-r--r--drivers/isdn/hysdn/hycapi.c3
-rw-r--r--drivers/isdn/hysdn/hysdn_boot.c3
-rw-r--r--drivers/isdn/hysdn/hysdn_init.c3
-rw-r--r--drivers/isdn/hysdn/hysdn_net.c3
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c7
-rw-r--r--drivers/isdn/i4l/isdn_bsdcomp.c4
-rw-r--r--drivers/isdn/i4l/isdn_common.c15
-rw-r--r--drivers/isdn/i4l/isdn_net.c6
-rw-r--r--drivers/isdn/i4l/isdn_ppp.c21
-rw-r--r--drivers/isdn/i4l/isdn_tty.c2
-rw-r--r--drivers/isdn/i4l/isdn_v110.c3
-rw-r--r--drivers/isdn/icn/icn.c3
-rw-r--r--drivers/isdn/isdnloop/isdnloop.c3
-rw-r--r--drivers/isdn/pcbit/drv.c9
-rw-r--r--drivers/isdn/pcbit/layer2.c3
-rw-r--r--drivers/isdn/sc/init.c9
-rw-r--r--drivers/kvm/Kconfig33
-rw-r--r--drivers/kvm/Makefile10
-rw-r--r--drivers/kvm/kvm.h551
-rw-r--r--drivers/kvm/kvm_main.c1935
-rw-r--r--drivers/kvm/kvm_svm.h44
-rw-r--r--drivers/kvm/kvm_vmx.h14
-rw-r--r--drivers/kvm/mmu.c699
-rw-r--r--drivers/kvm/paging_tmpl.h397
-rw-r--r--drivers/kvm/segment_descriptor.h17
-rw-r--r--drivers/kvm/svm.c1677
-rw-r--r--drivers/kvm/svm.h315
-rw-r--r--drivers/kvm/vmx.c2002
-rw-r--r--drivers/kvm/vmx.h296
-rw-r--r--drivers/kvm/x86_emulate.c1409
-rw-r--r--drivers/kvm/x86_emulate.h185
-rw-r--r--drivers/macintosh/Kconfig1
-rw-r--r--drivers/macintosh/adbhid.c10
-rw-r--r--drivers/macintosh/mac_hid.c8
-rw-r--r--drivers/md/Kconfig1
-rw-r--r--drivers/md/bitmap.c8
-rw-r--r--drivers/md/dm-bio-list.h14
-rw-r--r--drivers/md/dm-crypt.c4
-rw-r--r--drivers/md/dm-emc.c10
-rw-r--r--drivers/md/dm-hw-handler.h2
-rw-r--r--drivers/md/dm-io.c15
-rw-r--r--drivers/md/dm-ioctl.c16
-rw-r--r--drivers/md/dm-linear.c4
-rw-r--r--drivers/md/dm-log.c24
-rw-r--r--drivers/md/dm-log.h10
-rw-r--r--drivers/md/dm-mpath.c52
-rw-r--r--drivers/md/dm-mpath.h4
-rw-r--r--drivers/md/dm-path-selector.h12
-rw-r--r--drivers/md/dm-raid1.c25
-rw-r--r--drivers/md/dm-round-robin.c12
-rw-r--r--drivers/md/dm-snap.c33
-rw-r--r--drivers/md/dm-stripe.c2
-rw-r--r--drivers/md/dm-zero.c2
-rw-r--r--drivers/md/dm.c130
-rw-r--r--drivers/md/dm.h19
-rw-r--r--drivers/md/md.c29
-rw-r--r--drivers/md/raid1.c1
-rw-r--r--drivers/md/raid5.c351
-rw-r--r--drivers/media/Kconfig2
-rw-r--r--drivers/media/common/ir-keymaps.c55
-rw-r--r--drivers/media/common/saa7146_i2c.c16
-rw-r--r--drivers/media/dvb/b2c2/Kconfig1
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c10
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig2
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c9
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.h2
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c13
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig14
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c36
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c271
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h5
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c40
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c200
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c113
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c26
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c22
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c24
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h14
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c37
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c22
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c34
-rw-r--r--drivers/media/dvb/dvb-usb/ttusb2.c270
-rw-r--r--drivers/media/dvb/dvb-usb/ttusb2.h70
-rw-r--r--drivers/media/dvb/dvb-usb/umt-010.c24
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c20
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c40
-rw-r--r--drivers/media/dvb/frontends/Kconfig24
-rw-r--r--drivers/media/dvb/frontends/Makefile3
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c7
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c1191
-rw-r--r--drivers/media/dvb/frontends/dib7000m.h51
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c1019
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h46
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.h13
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c67
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h7
-rw-r--r--drivers/media/dvb/frontends/lg_h06xf.h64
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c257
-rw-r--r--drivers/media/dvb/frontends/lgdt330x_priv.h15
-rw-r--r--drivers/media/dvb/frontends/lgh06xf.c134
-rw-r--r--drivers/media/dvb/frontends/lgh06xf.h35
-rw-r--r--drivers/media/dvb/frontends/or51132.c176
-rw-r--r--drivers/media/dvb/frontends/or51211.c124
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c10
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h5
-rw-r--r--drivers/media/dvb/frontends/tda8083.c30
-rw-r--r--drivers/media/dvb/frontends/tda826x.c12
-rw-r--r--drivers/media/dvb/frontends/tua6100.c3
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c8
-rw-r--r--drivers/media/dvb/ttpci/Kconfig1
-rw-r--r--drivers/media/dvb/ttpci/av7110.c2
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c25
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c26
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c334
-rw-r--r--drivers/media/dvb/ttpci/budget.c2
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c11
-rw-r--r--drivers/media/video/Kconfig31
-rw-r--r--drivers/media/video/Makefile6
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c6
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c101
-rw-r--r--drivers/media/video/cafe_ccic-regs.h160
-rw-r--r--drivers/media/video/cafe_ccic.c2228
-rw-r--r--drivers/media/video/compat_ioctl32.c2
-rw-r--r--drivers/media/video/cx88/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c179
-rw-r--r--drivers/media/video/cx88/cx88-cards.c86
-rw-r--r--drivers/media/video/cx88/cx88-core.c2
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c333
-rw-r--r--drivers/media/video/cx88/cx88-input.c77
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c348
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c13
-rw-r--r--drivers/media/video/cx88/cx88-video.c32
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c2
-rw-r--r--drivers/media/video/cx88/cx88.h47
-rw-r--r--drivers/media/video/ir-kbd-i2c.c46
-rw-r--r--drivers/media/video/mxb.c8
-rw-r--r--drivers/media/video/ov7670.c1333
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c16
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c26
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c81
-rw-r--r--drivers/media/video/saa7115.c18
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c63
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c222
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c11
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c222
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c76
-rw-r--r--drivers/media/video/saa7134/saa7134.h8
-rw-r--r--drivers/media/video/stv680.c21
-rw-r--r--drivers/media/video/tda9887.c6
-rw-r--r--drivers/media/video/tuner-core.c4
-rw-r--r--drivers/media/video/tuner-simple.c4
-rw-r--r--drivers/media/video/tuner-types.c15
-rw-r--r--drivers/media/video/tveeprom.c9
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.c9
-rw-r--r--drivers/media/video/usbvision/Kconfig12
-rw-r--r--drivers/media/video/usbvision/Makefile5
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c157
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c2554
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c571
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c2051
-rw-r--r--drivers/media/video/usbvision/usbvision.h558
-rw-r--r--drivers/media/video/v4l1-compat.c18
-rw-r--r--drivers/media/video/v4l2-common.c85
-rw-r--r--drivers/media/video/videodev.c175
-rw-r--r--drivers/media/video/vino.c2
-rw-r--r--drivers/media/video/vivi.c16
-rw-r--r--drivers/media/video/zoran_card.c2
-rw-r--r--drivers/media/video/zoran_procfs.c4
-rw-r--r--drivers/media/video/zr36120.c2079
-rw-r--r--drivers/media/video/zr36120.h279
-rw-r--r--drivers/media/video/zr36120_i2c.c132
-rw-r--r--drivers/media/video/zr36120_mem.c78
-rw-r--r--drivers/media/video/zr36120_mem.h3
-rw-r--r--drivers/mmc/at91_mci.c346
-rw-r--r--drivers/mmc/au1xmmc.c2
-rw-r--r--drivers/mmc/mmc_queue.c4
-rw-r--r--drivers/mmc/pxamci.c4
-rw-r--r--drivers/mmc/sdhci.c4
-rw-r--r--drivers/mmc/tifm_sd.c2
-rw-r--r--drivers/net/7990.c2
-rw-r--r--drivers/net/8139too.c5
-rw-r--r--drivers/net/Kconfig8
-rw-r--r--drivers/net/apne.c3
-rw-r--r--drivers/net/bnx2.c2
-rw-r--r--drivers/net/chelsio/cxgb2.c23
-rw-r--r--drivers/net/chelsio/sge.c115
-rw-r--r--drivers/net/chelsio/sge.h4
-rw-r--r--drivers/net/hamradio/6pack.c9
-rw-r--r--drivers/net/hamradio/baycom_epp.c10
-rw-r--r--drivers/net/hamradio/bpqether.c9
-rw-r--r--drivers/net/hamradio/dmascc.c10
-rw-r--r--drivers/net/hamradio/hdlcdrv.c16
-rw-r--r--drivers/net/hamradio/mkiss.c9
-rw-r--r--drivers/net/hamradio/scc.c9
-rw-r--r--drivers/net/hamradio/yam.c9
-rw-r--r--drivers/net/hplance.c14
-rw-r--r--drivers/net/irda/irtty-sir.c4
-rw-r--r--drivers/net/macb.c8
-rw-r--r--drivers/net/macb.h6
-rw-r--r--drivers/net/myri10ge/myri10ge.c498
-rw-r--r--drivers/net/smc91x.h90
-rw-r--r--drivers/net/ucc_geth.c12
-rw-r--r--drivers/net/via-velocity.c2
-rw-r--r--drivers/net/wan/Kconfig5
-rw-r--r--drivers/net/wan/cosa.c4
-rw-r--r--drivers/net/wireless/strip.c2
-rw-r--r--drivers/oprofile/buffer_sync.c8
-rw-r--r--drivers/parport/Kconfig6
-rw-r--r--drivers/pci/hotplug/Kconfig3
-rw-r--r--drivers/pci/proc.c8
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c6
-rw-r--r--drivers/pnp/isapnp/proc.c2
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/vuart.c965
-rw-r--r--drivers/ps3/vuart.h94
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/rtc-at91rm9200.c (renamed from drivers/rtc/rtc-at91.c)0
-rw-r--r--drivers/rtc/rtc-ds1672.c2
-rw-r--r--drivers/rtc/rtc-lib.c81
-rw-r--r--drivers/rtc/rtc-pcf8563.c6
-rw-r--r--drivers/rtc/rtc-rs5c372.c2
-rw-r--r--drivers/rtc/rtc-sh.c245
-rw-r--r--drivers/rtc/rtc-x1205.c10
-rw-r--r--drivers/s390/block/dasd.c8
-rw-r--r--drivers/s390/block/dasd_3990_erp.c23
-rw-r--r--drivers/s390/block/dasd_devmap.c49
-rw-r--r--drivers/s390/block/dasd_int.h4
-rw-r--r--drivers/s390/block/dasd_ioctl.c2
-rw-r--r--drivers/s390/char/ctrlchar.c9
-rw-r--r--drivers/s390/char/fs3270.c16
-rw-r--r--drivers/s390/char/sclp_tty.c2
-rw-r--r--drivers/s390/char/tape.h3
-rw-r--r--drivers/s390/char/tape_34xx.c23
-rw-r--r--drivers/s390/char/tape_3590.c7
-rw-r--r--drivers/s390/char/tape_block.c14
-rw-r--r--drivers/s390/char/tape_char.c8
-rw-r--r--drivers/s390/char/tape_core.c14
-rw-r--r--drivers/s390/char/tty3270.c2
-rw-r--r--drivers/s390/cio/chsc.c28
-rw-r--r--drivers/s390/cio/cio.c62
-rw-r--r--drivers/s390/cio/cio.h6
-rw-r--r--drivers/s390/cio/css.c69
-rw-r--r--drivers/s390/cio/css.h9
-rw-r--r--drivers/s390/cio/device.c456
-rw-r--r--drivers/s390/cio/device.h6
-rw-r--r--drivers/s390/cio/device_fsm.c58
-rw-r--r--drivers/s390/cio/device_ops.c28
-rw-r--r--drivers/s390/cio/qdio.c234
-rw-r--r--drivers/s390/cio/qdio.h28
-rw-r--r--drivers/s390/crypto/ap_bus.c17
-rw-r--r--drivers/sbus/char/bpp.c4
-rw-r--r--drivers/sbus/char/cpwatchdog.c2
-rw-r--r--drivers/sbus/char/display7seg.c2
-rw-r--r--drivers/sbus/char/openprom.c2
-rw-r--r--drivers/sbus/char/vfc_dev.c2
-rw-r--r--drivers/scsi/Kconfig2
-rw-r--r--drivers/scsi/sd.c2
-rw-r--r--drivers/scsi/st.c2
-rw-r--r--drivers/scsi/sun3_NCR5380.c4
-rw-r--r--drivers/scsi/sun3_scsi.c2
-rw-r--r--drivers/scsi/sun3_scsi.h2
-rw-r--r--drivers/scsi/sun3_scsi_vme.c2
-rw-r--r--drivers/serial/21285.c4
-rw-r--r--drivers/serial/68328serial.c2
-rw-r--r--drivers/serial/68360serial.c2
-rw-r--r--drivers/serial/8250.c4
-rw-r--r--drivers/serial/Kconfig53
-rw-r--r--drivers/serial/amba-pl010.c4
-rw-r--r--drivers/serial/amba-pl011.c4
-rw-r--r--drivers/serial/atmel_serial.c2
-rw-r--r--drivers/serial/clps711x.c4
-rw-r--r--drivers/serial/crisv10.c8
-rw-r--r--drivers/serial/crisv10.h4
-rw-r--r--drivers/serial/dz.c4
-rw-r--r--drivers/serial/icom.c4
-rw-r--r--drivers/serial/imx.c4
-rw-r--r--drivers/serial/ioc3_serial.c4
-rw-r--r--drivers/serial/ioc4_serial.c6
-rw-r--r--drivers/serial/ip22zilog.c4
-rw-r--r--drivers/serial/jsm/jsm_tty.c10
-rw-r--r--drivers/serial/m32r_sio.c2
-rw-r--r--drivers/serial/mcfserial.c2
-rw-r--r--drivers/serial/mpc52xx_uart.c4
-rw-r--r--drivers/serial/mpsc.c4
-rw-r--r--drivers/serial/mux.c4
-rw-r--r--drivers/serial/netx-serial.c4
-rw-r--r--drivers/serial/pmac_zilog.c10
-rw-r--r--drivers/serial/pmac_zilog.h2
-rw-r--r--drivers/serial/pxa.c4
-rw-r--r--drivers/serial/s3c2410.c4
-rw-r--r--drivers/serial/sa1100.c4
-rw-r--r--drivers/serial/serial_core.c21
-rw-r--r--drivers/serial/serial_lh7a40x.c4
-rw-r--r--drivers/serial/serial_txx9.c4
-rw-r--r--drivers/serial/sh-sci.c26
-rw-r--r--drivers/serial/sh-sci.h19
-rw-r--r--drivers/serial/sn_console.c4
-rw-r--r--drivers/serial/sunhv.c4
-rw-r--r--drivers/serial/sunsab.c4
-rw-r--r--drivers/serial/sunsu.c4
-rw-r--r--drivers/serial/sunzilog.c4
-rw-r--r--drivers/serial/uartlite.c4
-rw-r--r--drivers/serial/v850e_uart.c4
-rw-r--r--drivers/serial/vr41xx_siu.c4
-rw-r--r--drivers/spi/pxa2xx_spi.c733
-rw-r--r--drivers/tc/zs.c2
-rw-r--r--drivers/telephony/ixj.c10
-rw-r--r--drivers/usb/class/cdc-acm.c4
-rw-r--r--drivers/usb/core/inode.c4
-rw-r--r--drivers/usb/gadget/file_storage.c16
-rw-r--r--drivers/usb/gadget/serial.c4
-rw-r--r--drivers/usb/input/Kconfig21
-rw-r--r--drivers/usb/input/Makefile3
-rw-r--r--drivers/usb/input/appletouch.c95
-rw-r--r--drivers/usb/input/hid-core.c1422
-rw-r--r--drivers/usb/input/hid-ff.c8
-rw-r--r--drivers/usb/input/hid-lgff.c7
-rw-r--r--drivers/usb/input/hid-pidff.c58
-rw-r--r--drivers/usb/input/hid-tmff.c5
-rw-r--r--drivers/usb/input/hid-zpff.c7
-rw-r--r--drivers/usb/input/hiddev.c37
-rw-r--r--drivers/usb/input/usbhid.h84
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb.c2
-rw-r--r--drivers/usb/serial/ark3116.c4
-rw-r--r--drivers/usb/serial/belkin_sa.c4
-rw-r--r--drivers/usb/serial/console.c2
-rw-r--r--drivers/usb/serial/cp2101.c4
-rw-r--r--drivers/usb/serial/cypress_m8.c10
-rw-r--r--drivers/usb/serial/digi_acceleport.c6
-rw-r--r--drivers/usb/serial/empeg.c4
-rw-r--r--drivers/usb/serial/ftdi_sio.c4
-rw-r--r--drivers/usb/serial/io_edgeport.c8
-rw-r--r--drivers/usb/serial/io_ti.c6
-rw-r--r--drivers/usb/serial/ir-usb.c4
-rw-r--r--drivers/usb/serial/keyspan.c2
-rw-r--r--drivers/usb/serial/keyspan.h2
-rw-r--r--drivers/usb/serial/keyspan_pda.c2
-rw-r--r--drivers/usb/serial/kl5kusb105.c6
-rw-r--r--drivers/usb/serial/kobil_sct.c10
-rw-r--r--drivers/usb/serial/mct_u232.c4
-rw-r--r--drivers/usb/serial/mos7720.c4
-rw-r--r--drivers/usb/serial/mos7840.c4
-rw-r--r--drivers/usb/serial/option.c4
-rw-r--r--drivers/usb/serial/pl2303.c4
-rw-r--r--drivers/usb/serial/sierra.c2
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c4
-rw-r--r--drivers/usb/serial/usb-serial.c2
-rw-r--r--drivers/usb/serial/visor.c4
-rw-r--r--drivers/usb/serial/whiteheat.c6
-rw-r--r--drivers/video/Kconfig14
-rw-r--r--drivers/video/Makefile1
-rw-r--r--drivers/video/S3triofb.c7
-rw-r--r--drivers/video/amifb.c8
-rw-r--r--drivers/video/arcfb.c2
-rw-r--r--drivers/video/atafb.c13
-rw-r--r--drivers/video/aty/aty128fb.c5
-rw-r--r--drivers/video/aty/atyfb.h9
-rw-r--r--drivers/video/aty/atyfb_base.c193
-rw-r--r--drivers/video/aty/mach64_ct.c47
-rw-r--r--drivers/video/aty/radeon_i2c.c8
-rw-r--r--drivers/video/aty/radeon_monitor.c3
-rw-r--r--drivers/video/au1100fb.h2
-rw-r--r--drivers/video/backlight/backlight.c95
-rw-r--r--drivers/video/backlight/corgi_bl.c4
-rw-r--r--drivers/video/backlight/hp680_bl.c4
-rw-r--r--drivers/video/backlight/lcd.c80
-rw-r--r--drivers/video/backlight/locomolcd.c4
-rw-r--r--drivers/video/cfbimgblt.c8
-rw-r--r--drivers/video/cirrusfb.c15
-rw-r--r--drivers/video/console/softcursor.c26
-rw-r--r--drivers/video/console/sticon.c2
-rw-r--r--drivers/video/console/vgacon.c30
-rw-r--r--drivers/video/cyberfb.c4
-rw-r--r--drivers/video/epson1355fb.c4
-rw-r--r--drivers/video/fbcmap.c55
-rw-r--r--drivers/video/fbcvt.c2
-rw-r--r--drivers/video/fbmem.c22
-rw-r--r--drivers/video/fbmon.c2
-rw-r--r--drivers/video/ffb.c4
-rw-r--r--drivers/video/fm2fb.c1
-rw-r--r--drivers/video/geode/Kconfig20
-rw-r--r--drivers/video/geode/display_gx.c23
-rw-r--r--drivers/video/geode/display_gx.h7
-rw-r--r--drivers/video/geode/gxfb_core.c53
-rw-r--r--drivers/video/geode/video_gx.c107
-rw-r--r--drivers/video/geode/video_gx.h25
-rw-r--r--drivers/video/gxt4500.c741
-rw-r--r--drivers/video/hpfb.c2
-rw-r--r--drivers/video/i810/i810-i2c.c10
-rw-r--r--drivers/video/igafb.c6
-rw-r--r--drivers/video/intelfb/intelfb_i2c.c4
-rw-r--r--drivers/video/intelfb/intelfbdrv.c3
-rw-r--r--drivers/video/macfb.c20
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c2
-rw-r--r--drivers/video/mbx/mbxdebugfs.c188
-rw-r--r--drivers/video/mbx/mbxfb.c359
-rw-r--r--drivers/video/mbx/reg_bits.h114
-rw-r--r--drivers/video/mbx/regs.h2
-rw-r--r--drivers/video/modedb.c6
-rw-r--r--drivers/video/neofb.c2
-rw-r--r--drivers/video/nvidia/nv_accel.c35
-rw-r--r--drivers/video/nvidia/nv_i2c.c13
-rw-r--r--drivers/video/nvidia/nv_local.h11
-rw-r--r--drivers/video/nvidia/nv_of.c3
-rw-r--r--drivers/video/nvidia/nv_proto.h1
-rw-r--r--drivers/video/offb.c3
-rw-r--r--drivers/video/platinumfb.c3
-rw-r--r--drivers/video/pmagb-b-fb.c2
-rw-r--r--drivers/video/pvr2fb.c18
-rw-r--r--drivers/video/retz3fb.c4
-rw-r--r--drivers/video/riva/fbdev.c66
-rw-r--r--drivers/video/riva/riva_hw.c10
-rw-r--r--drivers/video/riva/riva_hw.h17
-rw-r--r--drivers/video/riva/rivafb-i2c.c6
-rw-r--r--drivers/video/s3c2410fb.c213
-rw-r--r--drivers/video/savage/savagefb-i2c.c9
-rw-r--r--drivers/video/sis/init301.c7
-rw-r--r--drivers/video/stifb.c3
-rw-r--r--drivers/video/tgafb.c58
-rw-r--r--drivers/video/tridentfb.c22
-rw-r--r--drivers/video/vesafb.c24
-rw-r--r--drivers/video/vga16fb.c28
-rw-r--r--drivers/video/virgefb.c17
-rw-r--r--drivers/zorro/proc.c2
-rw-r--r--fs/9p/vfs_addr.c2
-rw-r--r--fs/9p/vfs_dir.c4
-rw-r--r--fs/9p/vfs_file.c8
-rw-r--r--fs/Makefile3
-rw-r--r--fs/adfs/dir.c2
-rw-r--r--fs/affs/dir.c4
-rw-r--r--fs/afs/dir.c4
-rw-r--r--fs/afs/mntpt.c10
-rw-r--r--fs/autofs/root.c4
-rw-r--r--fs/autofs4/autofs_i.h3
-rw-r--r--fs/autofs4/root.c16
-rw-r--r--fs/befs/linuxvfs.c4
-rw-r--r--fs/bfs/dir.c2
-rw-r--r--fs/binfmt_aout.c8
-rw-r--r--fs/binfmt_elf.c6
-rw-r--r--fs/binfmt_elf_fdpic.c8
-rw-r--r--fs/binfmt_flat.c2
-rw-r--r--fs/binfmt_misc.c10
-rw-r--r--fs/block_dev.c204
-rw-r--r--fs/buffer.c33
-rw-r--r--fs/cifs/CHANGES3
-rw-r--r--fs/cifs/cifsencrypt.c4
-rw-r--r--fs/cifs/cifsfs.c4
-rw-r--r--fs/cifs/cifspdu.h8
-rw-r--r--fs/cifs/fcntl.c4
-rw-r--r--fs/cifs/file.c116
-rw-r--r--fs/cifs/readdir.c32
-rw-r--r--fs/coda/dir.c8
-rw-r--r--fs/coda/file.c14
-rw-r--r--fs/coda/inode.c2
-rw-r--r--fs/compat.c22
-rw-r--r--fs/compat_ioctl.c2
-rw-r--r--fs/configfs/dir.c10
-rw-r--r--fs/configfs/file.c12
-rw-r--r--fs/cramfs/inode.c2
-rw-r--r--fs/direct-io.c323
-rw-r--r--fs/dnotify.c4
-rw-r--r--fs/dquot.c18
-rw-r--r--fs/ecryptfs/dentry.c3
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h16
-rw-r--r--fs/ecryptfs/file.c15
-rw-r--r--fs/ecryptfs/inode.c79
-rw-r--r--fs/ecryptfs/main.c5
-rw-r--r--fs/ecryptfs/mmap.c16
-rw-r--r--fs/efs/dir.c2
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/exec.c17
-rw-r--r--fs/ext2/dir.c2
-rw-r--r--fs/ext2/ioctl.c2
-rw-r--r--fs/ext2/super.c6
-rw-r--r--fs/ext3/dir.c8
-rw-r--r--fs/ext3/file.c2
-rw-r--r--fs/ext3/ioctl.c2
-rw-r--r--fs/ext3/namei.c4
-rw-r--r--fs/ext3/super.c6
-rw-r--r--fs/ext4/dir.c8
-rw-r--r--fs/ext4/file.c2
-rw-r--r--fs/ext4/inode.c2
-rw-r--r--fs/ext4/ioctl.c2
-rw-r--r--fs/ext4/namei.c4
-rw-r--r--fs/fat/dir.c6
-rw-r--r--fs/fat/file.c2
-rw-r--r--fs/fcntl.c7
-rw-r--r--fs/file.c255
-rw-r--r--fs/file_table.c10
-rw-r--r--fs/freevxfs/vxfs_lookup.c2
-rw-r--r--fs/fuse/control.c2
-rw-r--r--fs/fuse/dir.c2
-rw-r--r--fs/fuse/file.c18
-rw-r--r--fs/gfs2/ops_file.c6
-rw-r--r--fs/hfs/dir.c2
-rw-r--r--fs/hfs/inode.c2
-rw-r--r--fs/hfsplus/dir.c2
-rw-r--r--fs/hfsplus/inode.c2
-rw-r--r--fs/hostfs/hostfs_kern.c6
-rw-r--r--fs/hpfs/dir.c4
-rw-r--r--fs/hpfs/file.c2
-rw-r--r--fs/hppfs/hppfs_kern.c12
-rw-r--r--fs/hugetlbfs/inode.c6
-rw-r--r--fs/inode.c2
-rw-r--r--fs/inotify_user.c6
-rw-r--r--fs/ioctl.c14
-rw-r--r--fs/isofs/compress.c2
-rw-r--r--fs/isofs/dir.c5
-rw-r--r--fs/jbd/transaction.c2
-rw-r--r--fs/jffs/inode-v23.c6
-rw-r--r--fs/jffs2/dir.c6
-rw-r--r--fs/jfs/jfs_dtree.c2
-rw-r--r--fs/jfs/jfs_filsys.h42
-rw-r--r--fs/libfs.c14
-rw-r--r--fs/lockd/clntlock.c2
-rw-r--r--fs/lockd/clntproc.c2
-rw-r--r--fs/lockd/svclock.c16
-rw-r--r--fs/lockd/svcsubs.c2
-rw-r--r--fs/locks.c32
-rw-r--r--fs/minix/dir.c2
-rw-r--r--fs/namei.c15
-rw-r--r--fs/namespace.c113
-rw-r--r--fs/ncpfs/dir.c8
-rw-r--r--fs/ncpfs/file.c4
-rw-r--r--fs/ncpfs/inode.c4
-rw-r--r--fs/ncpfs/ioctl.c8
-rw-r--r--fs/ncpfs/mmap.c4
-rw-r--r--fs/nfs/dir.c18
-rw-r--r--fs/nfs/direct.c10
-rw-r--r--fs/nfs/file.c14
-rw-r--r--fs/nfs/getroot.c2
-rw-r--r--fs/nfs/idmap.c2
-rw-r--r--fs/nfs/inode.c6
-rw-r--r--fs/nfs/nfs3proc.c2
-rw-r--r--fs/nfs/proc.c2
-rw-r--r--fs/nfs/write.c4
-rw-r--r--fs/nfsd/nfs2acl.c8
-rw-r--r--fs/nfsd/nfs3acl.c8
-rw-r--r--fs/nfsd/nfs4recover.c2
-rw-r--r--fs/nfsd/nfs4state.c10
-rw-r--r--fs/nfsd/nfscache.c3
-rw-r--r--fs/nfsd/nfsctl.c2
-rw-r--r--fs/nfsd/vfs.c53
-rw-r--r--fs/ntfs/dir.c6
-rw-r--r--fs/ntfs/file.c2
-rw-r--r--fs/ocfs2/aops.c4
-rw-r--r--fs/ocfs2/cluster/nodemanager.c192
-rw-r--r--fs/ocfs2/cluster/nodemanager.h17
-rw-r--r--fs/ocfs2/cluster/tcp.c152
-rw-r--r--fs/ocfs2/cluster/tcp.h8
-rw-r--r--fs/ocfs2/cluster/tcp_internal.h15
-rw-r--r--fs/ocfs2/dir.c2
-rw-r--r--fs/ocfs2/dlm/dlmfs.c4
-rw-r--r--fs/ocfs2/dlmglue.c79
-rw-r--r--fs/ocfs2/file.c34
-rw-r--r--fs/ocfs2/heartbeat.c9
-rw-r--r--fs/ocfs2/inode.c3
-rw-r--r--fs/ocfs2/journal.c46
-rw-r--r--fs/ocfs2/journal.h5
-rw-r--r--fs/ocfs2/mmap.c6
-rw-r--r--fs/ocfs2/namei.c8
-rw-r--r--fs/ocfs2/ocfs2.h5
-rw-r--r--fs/ocfs2/ocfs2_fs.h14
-rw-r--r--fs/ocfs2/super.c90
-rw-r--r--fs/ocfs2/vote.c3
-rw-r--r--fs/open.c30
-rw-r--r--fs/openpromfs/inode.c2
-rw-r--r--fs/partitions/Kconfig2
-rw-r--r--fs/partitions/check.c27
-rw-r--r--fs/pipe.c28
-rw-r--r--fs/pnode.c2
-rw-r--r--fs/pnode.h2
-rw-r--r--fs/proc/array.c18
-rw-r--r--fs/proc/base.c161
-rw-r--r--fs/proc/generic.c10
-rw-r--r--fs/proc/nommu.c4
-rw-r--r--fs/proc/proc_misc.c17
-rw-r--r--fs/proc/task_mmu.c8
-rw-r--r--fs/proc/task_nommu.c4
-rw-r--r--fs/qnx4/dir.c2
-rw-r--r--fs/ramfs/file-nommu.c2
-rw-r--r--fs/read_write.c20
-rw-r--r--fs/readdir.c2
-rw-r--r--fs/reiserfs/bitmap.c2
-rw-r--r--fs/reiserfs/dir.c4
-rw-r--r--fs/reiserfs/file.c4
-rw-r--r--fs/reiserfs/fix_node.c6
-rw-r--r--fs/reiserfs/inode.c12
-rw-r--r--fs/reiserfs/ioctl.c2
-rw-r--r--fs/reiserfs/namei.c6
-rw-r--r--fs/reiserfs/procfs.c2
-rw-r--r--fs/reiserfs/stree.c42
-rw-r--r--fs/reiserfs/super.c2
-rw-r--r--fs/reiserfs/tail_conversion.c4
-rw-r--r--fs/reiserfs/xattr.c10
-rw-r--r--fs/romfs/inode.c2
-rw-r--r--fs/select.c10
-rw-r--r--fs/seq_file.c2
-rw-r--r--fs/smbfs/cache.c2
-rw-r--r--fs/smbfs/dir.c6
-rw-r--r--fs/smbfs/file.c14
-rw-r--r--fs/smbfs/proc.c10
-rw-r--r--fs/smbfs/sock.c4
-rw-r--r--fs/splice.c18
-rw-r--r--fs/stack.c40
-rw-r--r--fs/stat.c2
-rw-r--r--fs/super.c2
-rw-r--r--fs/sync.c4
-rw-r--r--fs/sysfs/bin.c14
-rw-r--r--fs/sysfs/dir.c10
-rw-r--r--fs/sysfs/file.c16
-rw-r--r--fs/sysv/dir.c2
-rw-r--r--fs/udf/dir.c4
-rw-r--r--fs/udf/file.c2
-rw-r--r--fs/ufs/dir.c2
-rw-r--r--fs/xattr.c8
-rw-r--r--fs/xfs/linux-2.6/xfs_aops.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_file.c28
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c10
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl32.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_lrw.c2
-rw-r--r--fs/xfs/xfs_dfrag.c4
-rw-r--r--include/asm-alpha/termbits.h13
-rw-r--r--include/asm-arm/arch-pnx4008/i2c.h67
-rw-r--r--include/asm-arm/arch-pxa/pxa2xx_spi.h5
-rw-r--r--include/asm-arm/arch-s3c2410/fb.h3
-rw-r--r--include/asm-arm/termbits.h12
-rw-r--r--include/asm-arm26/termbits.h12
-rw-r--r--include/asm-avr32/arch-at32ap/at32ap7000.h33
-rw-r--r--include/asm-avr32/arch-at32ap/board.h3
-rw-r--r--include/asm-avr32/arch-at32ap/portmux.h20
-rw-r--r--include/asm-avr32/dma-mapping.h12
-rw-r--r--include/asm-avr32/termbits.h11
-rw-r--r--include/asm-cris/termbits.h11
-rw-r--r--include/asm-frv/bitops.h44
-rw-r--r--include/asm-frv/termbits.h11
-rw-r--r--include/asm-generic/bug.h18
-rw-r--r--include/asm-generic/page.h38
-rw-r--r--include/asm-generic/termios.h4
-rw-r--r--include/asm-generic/vmlinux.lds.h9
-rw-r--r--include/asm-h8300/termbits.h11
-rw-r--r--include/asm-i386/bug.h28
-rw-r--r--include/asm-i386/ide.h4
-rw-r--r--include/asm-i386/termbits.h11
-rw-r--r--include/asm-i386/topology.h1
-rw-r--r--include/asm-ia64/termbits.h11
-rw-r--r--include/asm-ia64/topology.h1
-rw-r--r--include/asm-m32r/ide.h3
-rw-r--r--include/asm-m32r/m32102.h7
-rw-r--r--include/asm-m32r/ptrace.h28
-rw-r--r--include/asm-m32r/sigcontext.h13
-rw-r--r--include/asm-m32r/termbits.h11
-rw-r--r--include/asm-m68k/sun3-head.h1
-rw-r--r--include/asm-m68k/sun3ints.h1
-rw-r--r--include/asm-m68k/termbits.h11
-rw-r--r--include/asm-mips/bootinfo.h1
-rw-r--r--include/asm-mips/compat.h1
-rw-r--r--include/asm-mips/mach-ip27/irq.h2
-rw-r--r--include/asm-mips/mach-ip27/topology.h1
-rw-r--r--include/asm-mips/mach-rm/cpu-feature-overrides.h (renamed from include/asm-mips/mach-rm200/cpu-feature-overrides.h)0
-rw-r--r--include/asm-mips/mach-rm/mc146818rtc.h (renamed from include/asm-mips/mach-rm200/mc146818rtc.h)0
-rw-r--r--include/asm-mips/mach-rm/timex.h (renamed from include/asm-mips/mach-rm200/timex.h)0
-rw-r--r--include/asm-mips/pci.h6
-rw-r--r--include/asm-mips/ptrace.h8
-rw-r--r--include/asm-mips/sn/arch.h1
-rw-r--r--include/asm-mips/sn/klconfig.h2
-rw-r--r--include/asm-mips/system.h9
-rw-r--r--include/asm-mips/termbits.h11
-rw-r--r--include/asm-mips/war.h2
-rw-r--r--include/asm-parisc/termbits.h11
-rw-r--r--include/asm-powerpc/Kbuild2
-rw-r--r--include/asm-powerpc/bitops.h21
-rw-r--r--include/asm-powerpc/bug.h80
-rw-r--r--include/asm-powerpc/cputable.h16
-rw-r--r--include/asm-powerpc/dcr-native.h37
-rw-r--r--include/asm-powerpc/dcr.h2
-rw-r--r--include/asm-powerpc/hw_irq.h19
-rw-r--r--include/asm-powerpc/module.h2
-rw-r--r--include/asm-powerpc/page_32.h10
-rw-r--r--include/asm-powerpc/pci-bridge.h4
-rw-r--r--include/asm-powerpc/pci.h33
-rw-r--r--include/asm-powerpc/reg.h2
-rw-r--r--include/asm-powerpc/rtas.h3
-rw-r--r--include/asm-powerpc/termbits.h13
-rw-r--r--include/asm-powerpc/topology.h1
-rw-r--r--include/asm-ppc/pci-bridge.h8
-rw-r--r--include/asm-ppc/pci.h23
-rw-r--r--include/asm-ppc/reg_booke.h36
-rw-r--r--include/asm-s390/dasd.h2
-rw-r--r--include/asm-s390/page.h22
-rw-r--r--include/asm-s390/pgalloc.h3
-rw-r--r--include/asm-s390/pgtable.h16
-rw-r--r--include/asm-s390/termbits.h11
-rw-r--r--include/asm-sh/atomic-irq.h71
-rw-r--r--include/asm-sh/atomic-llsc.h107
-rw-r--r--include/asm-sh/atomic.h153
-rw-r--r--include/asm-sh/bug.h53
-rw-r--r--include/asm-sh/bugs.h12
-rw-r--r--include/asm-sh/checksum.h69
-rw-r--r--include/asm-sh/cpu-sh4/cache.h2
-rw-r--r--include/asm-sh/cpu-sh4/freq.h2
-rw-r--r--include/asm-sh/dma-mapping.h10
-rw-r--r--include/asm-sh/irq.h5
-rw-r--r--include/asm-sh/pgtable.h47
-rw-r--r--include/asm-sh/processor.h8
-rw-r--r--include/asm-sh/push-switch.h3
-rw-r--r--include/asm-sh/termbits.h11
-rw-r--r--include/asm-sparc/termbits.h12
-rw-r--r--include/asm-sparc64/dma.h6
-rw-r--r--include/asm-sparc64/irqflags.h89
-rw-r--r--include/asm-sparc64/kprobes.h11
-rw-r--r--include/asm-sparc64/rwsem.h32
-rw-r--r--include/asm-sparc64/system.h49
-rw-r--r--include/asm-sparc64/termbits.h12
-rw-r--r--include/asm-sparc64/ttable.h45
-rw-r--r--include/asm-um/bug.h4
-rw-r--r--include/asm-v850/termbits.h11
-rw-r--r--include/asm-x86_64/bug.h44
-rw-r--r--include/asm-x86_64/ioctls.h4
-rw-r--r--include/asm-x86_64/termbits.h27
-rw-r--r--include/asm-x86_64/termios.h6
-rw-r--r--include/asm-x86_64/topology.h1
-rw-r--r--include/asm-xtensa/asmmacro.h153
-rw-r--r--include/asm-xtensa/bug.h25
-rw-r--r--include/asm-xtensa/byteorder.h5
-rw-r--r--include/asm-xtensa/cache.h20
-rw-r--r--include/asm-xtensa/cacheasm.h177
-rw-r--r--include/asm-xtensa/cacheflush.h2
-rw-r--r--include/asm-xtensa/checksum.h2
-rw-r--r--include/asm-xtensa/coprocessor.h13
-rw-r--r--include/asm-xtensa/dma.h5
-rw-r--r--include/asm-xtensa/elf.h9
-rw-r--r--include/asm-xtensa/fcntl.h98
-rw-r--r--include/asm-xtensa/fixmap.h252
-rw-r--r--include/asm-xtensa/io.h64
-rw-r--r--include/asm-xtensa/irq.h8
-rw-r--r--include/asm-xtensa/irq_regs.h1
-rw-r--r--include/asm-xtensa/mmu_context.h269
-rw-r--r--include/asm-xtensa/page.h10
-rw-r--r--include/asm-xtensa/param.h2
-rw-r--r--include/asm-xtensa/pgtable.h41
-rw-r--r--include/asm-xtensa/platform-iss/hardware.h10
-rw-r--r--include/asm-xtensa/platform-iss/simcall.h62
-rw-r--r--include/asm-xtensa/posix_types.h2
-rw-r--r--include/asm-xtensa/processor.h24
-rw-r--r--include/asm-xtensa/ptrace.h2
-rw-r--r--include/asm-xtensa/regs.h138
-rw-r--r--include/asm-xtensa/sembuf.h2
-rw-r--r--include/asm-xtensa/shmbuf.h21
-rw-r--r--include/asm-xtensa/stat.h112
-rw-r--r--include/asm-xtensa/syscall.h20
-rw-r--r--include/asm-xtensa/system.h2
-rw-r--r--include/asm-xtensa/timex.h17
-rw-r--r--include/asm-xtensa/tlbflush.h42
-rw-r--r--include/asm-xtensa/unistd.h798
-rw-r--r--include/asm-xtensa/variant-fsf/core.h359
-rw-r--r--include/asm-xtensa/variant-fsf/tie.h22
-rw-r--r--include/asm-xtensa/xtensa/cacheasm.h708
-rw-r--r--include/asm-xtensa/xtensa/cacheattrasm.h432
-rw-r--r--include/asm-xtensa/xtensa/config-linux_be/core.h1270
-rw-r--r--include/asm-xtensa/xtensa/config-linux_be/defs.h270
-rw-r--r--include/asm-xtensa/xtensa/config-linux_be/specreg.h99
-rw-r--r--include/asm-xtensa/xtensa/config-linux_be/system.h198
-rw-r--r--include/asm-xtensa/xtensa/config-linux_be/tie.h275
-rw-r--r--include/asm-xtensa/xtensa/coreasm.h526
-rw-r--r--include/asm-xtensa/xtensa/corebits.h77
-rw-r--r--include/asm-xtensa/xtensa/hal.h822
-rw-r--r--include/asm-xtensa/xtensa/simcall.h130
-rw-r--r--include/asm-xtensa/xtensa/xt2000-uart.h155
-rw-r--r--include/asm-xtensa/xtensa/xt2000.h408
-rw-r--r--include/asm-xtensa/xtensa/xtboard.h120
-rw-r--r--include/linux/Kbuild2
-rw-r--r--include/linux/bitrev.h15
-rw-r--r--include/linux/blkdev.h5
-rw-r--r--include/linux/bug.h47
-rw-r--r--include/linux/clocksource.h2
-rw-r--r--include/linux/crc32.h4
-rw-r--r--include/linux/dccp.h26
-rw-r--r--include/linux/device-mapper.h7
-rw-r--r--include/linux/dm-ioctl.h9
-rw-r--r--include/linux/fault-inject.h84
-rw-r--r--include/linux/fb.h6
-rw-r--r--include/linux/file.h15
-rw-r--r--include/linux/freezer.h2
-rw-r--r--include/linux/fs.h27
-rw-r--r--include/linux/fs_stack.h31
-rw-r--r--include/linux/fsl_devices.h1
-rw-r--r--include/linux/fsnotify.h2
-rw-r--r--include/linux/futex.h2
-rw-r--r--include/linux/generic_serial.h2
-rw-r--r--include/linux/genhd.h4
-rw-r--r--include/linux/hid-debug.h (renamed from drivers/usb/input/hid-debug.h)0
-rw-r--r--include/linux/hid.h (renamed from drivers/usb/input/hid.h)87
-rw-r--r--include/linux/i2c-algo-bit.h5
-rw-r--r--include/linux/i2c-algo-ite.h72
-rw-r--r--include/linux/i2c-algo-pca.h1
-rw-r--r--include/linux/i2c-algo-pcf.h3
-rw-r--r--include/linux/i2c-algo-sgi.h1
-rw-r--r--include/linux/i2c-id.h19
-rw-r--r--include/linux/i2c-pnx.h43
-rw-r--r--include/linux/i2c.h75
-rw-r--r--include/linux/ide.h3
-rw-r--r--include/linux/if_addr.h6
-rw-r--r--include/linux/if_link.h6
-rw-r--r--include/linux/init.h1
-rw-r--r--include/linux/init_task.h18
-rw-r--r--include/linux/input.h18
-rw-r--r--include/linux/interrupt.h3
-rw-r--r--include/linux/isdn.h8
-rw-r--r--include/linux/istallion.h36
-rw-r--r--include/linux/kernel.h17
-rw-r--r--include/linux/kvm.h227
-rw-r--r--include/linux/lockd/lockd.h2
-rw-r--r--include/linux/log2.h157
-rw-r--r--include/linux/mnt_namespace.h42
-rw-r--r--include/linux/module.h7
-rw-r--r--include/linux/mount.h4
-rw-r--r--include/linux/mutex.h2
-rw-r--r--include/linux/namei.h5
-rw-r--r--include/linux/namespace.h42
-rw-r--r--include/linux/netdevice.h11
-rw-r--r--include/linux/nsproxy.h7
-rw-r--r--include/linux/pci_ids.h3
-rw-r--r--include/linux/pid.h5
-rw-r--r--include/linux/pid_namespace.h45
-rw-r--r--include/linux/pktcdvd.h25
-rw-r--r--include/linux/pspace.h23
-rw-r--r--include/linux/raid/raid5.h3
-rw-r--r--include/linux/reiserfs_fs.h44
-rw-r--r--include/linux/rtc.h1
-rw-r--r--include/linux/rtnetlink.h2
-rw-r--r--include/linux/sched.h30
-rw-r--r--include/linux/seqlock.h7
-rw-r--r--include/linux/serial_core.h8
-rw-r--r--include/linux/serio.h12
-rw-r--r--include/linux/stallion.h52
-rw-r--r--include/linux/sysctl.h5
-rw-r--r--include/linux/task_io_accounting.h37
-rw-r--r--include/linux/task_io_accounting_ops.h47
-rw-r--r--include/linux/taskstats.h28
-rw-r--r--include/linux/tfrc.h8
-rw-r--r--include/linux/timer.h6
-rw-r--r--include/linux/topology.h5
-rw-r--r--include/linux/tty.h20
-rw-r--r--include/linux/tty_driver.h12
-rw-r--r--include/linux/tty_ldisc.h4
-rw-r--r--include/linux/usb/serial.h2
-rw-r--r--include/linux/videodev2.h1
-rw-r--r--include/linux/xfrm.h2
-rw-r--r--include/media/ir-common.h1
-rw-r--r--include/media/saa7146.h20
-rw-r--r--include/media/tuner-types.h4
-rw-r--r--include/media/tuner.h1
-rw-r--r--include/media/tveeprom.h2
-rw-r--r--include/media/v4l2-common.h7
-rw-r--r--include/media/v4l2-dev.h14
-rw-r--r--include/net/ax25.h22
-rw-r--r--include/net/ip.h3
-rw-r--r--include/net/irda/ircomm_tty.h2
-rw-r--r--include/net/neighbour.h18
-rw-r--r--include/net/sctp/sctp.h2
-rw-r--r--include/video/mbxfb.h31
-rw-r--r--include/video/pm3fb.h24
-rw-r--r--init/Kconfig9
-rw-r--r--init/Makefile1
-rw-r--r--init/initramfs.c6
-rw-r--r--init/main.c20
-rw-r--r--init/version.c4
-rw-r--r--ipc/mqueue.c16
-rw-r--r--ipc/shm.c16
-rw-r--r--kernel/acct.c26
-rw-r--r--kernel/auditsc.c6
-rw-r--r--kernel/cpuset.c22
-rw-r--r--kernel/exit.c75
-rw-r--r--kernel/fork.c81
-rw-r--r--kernel/futex.c10
-rw-r--r--kernel/irq/proc.c3
-rw-r--r--kernel/kallsyms.c16
-rw-r--r--kernel/kmod.c2
-rw-r--r--kernel/mutex.c9
-rw-r--r--kernel/nsproxy.c42
-rw-r--r--kernel/pid.c75
-rw-r--r--kernel/relay.c4
-rw-r--r--kernel/sched.c511
-rw-r--r--kernel/signal.c13
-rw-r--r--kernel/sys.c23
-rw-r--r--kernel/sysctl.c387
-rw-r--r--kernel/time/clocksource.c8
-rw-r--r--kernel/timer.c148
-rw-r--r--kernel/tsacct.c9
-rw-r--r--kernel/workqueue.c21
-rw-r--r--lib/Kconfig4
-rw-r--r--lib/Kconfig.debug84
-rw-r--r--lib/Makefile4
-rw-r--r--lib/bitrev.c58
-rw-r--r--lib/bug.c163
-rw-r--r--lib/crc32.c28
-rw-r--r--lib/fault-inject.c336
-rw-r--r--mm/fadvise.c2
-rw-r--r--mm/filemap.c11
-rw-r--r--mm/filemap_xip.c2
-rw-r--r--mm/memory.c32
-rw-r--r--mm/mempolicy.c2
-rw-r--r--mm/mmap.c10
-rw-r--r--mm/nommu.c12
-rw-r--r--mm/page-writeback.c89
-rw-r--r--mm/page_alloc.c93
-rw-r--r--mm/readahead.c4
-rw-r--r--mm/shmem.c20
-rw-r--r--mm/slab.c88
-rw-r--r--mm/swapfile.c4
-rw-r--r--mm/tiny-shmem.c4
-rw-r--r--mm/truncate.c4
-rw-r--r--net/atm/proc.c2
-rw-r--r--net/ax25/ax25_addr.c36
-rw-r--r--net/bluetooth/rfcomm/tty.c4
-rw-r--r--net/core/neighbour.c11
-rw-r--r--net/core/netpoll.c53
-rw-r--r--net/dccp/ackvec.c4
-rw-r--r--net/dccp/ccid.h10
-rw-r--r--net/dccp/ccids/ccid2.c12
-rw-r--r--net/dccp/ccids/ccid3.c517
-rw-r--r--net/dccp/ccids/ccid3.h46
-rw-r--r--net/dccp/ccids/lib/packet_history.c219
-rw-r--r--net/dccp/ccids/lib/packet_history.h128
-rw-r--r--net/dccp/ccids/lib/tfrc.h23
-rw-r--r--net/dccp/ccids/lib/tfrc_equation.c28
-rw-r--r--net/dccp/dccp.h3
-rw-r--r--net/dccp/feat.c6
-rw-r--r--net/dccp/input.c47
-rw-r--r--net/dccp/ipv4.c26
-rw-r--r--net/dccp/ipv6.c24
-rw-r--r--net/dccp/minisocks.c2
-rw-r--r--net/dccp/options.c5
-rw-r--r--net/dccp/output.c39
-rw-r--r--net/dccp/proto.c6
-rw-r--r--net/dccp/timer.c14
-rw-r--r--net/decnet/dn_dev.c6
-rw-r--r--net/decnet/sysctl_net_decnet.c6
-rw-r--r--net/ieee80211/softmac/ieee80211softmac_assoc.c2
-rw-r--r--net/ipv4/devinet.c3
-rw-r--r--net/ipv4/ip_output.c14
-rw-r--r--net/ipv4/ipvs/ip_vs_sync.c17
-rw-r--r--net/ipv4/netfilter/ipt_CLUSTERIP.c2
-rw-r--r--net/ipv4/netfilter/ipt_recent.c2
-rw-r--r--net/ipv4/route.c3
-rw-r--r--net/ipv4/sysctl_net_ipv4.c16
-rw-r--r--net/ipv6/addrconf.c3
-rw-r--r--net/ipv6/ip6_output.c17
-rw-r--r--net/ipv6/ndisc.c9
-rw-r--r--net/irda/ircomm/ircomm_tty_ioctl.c2
-rw-r--r--net/netlink/af_netlink.c2
-rw-r--r--net/sched/sch_cbq.c21
-rw-r--r--net/sched/sch_htb.c51
-rw-r--r--net/socket.c16
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c2
-rw-r--r--net/sunrpc/cache.c10
-rw-r--r--net/sunrpc/rpc_pipe.c8
-rw-r--r--net/unix/garbage.c2
-rw-r--r--scripts/Kbuild.include19
-rw-r--r--scripts/kallsyms.c2
-rw-r--r--security/selinux/hooks.c33
-rw-r--r--security/selinux/selinuxfs.c8
-rw-r--r--sound/Kconfig8
-rw-r--r--sound/Makefile3
-rw-r--r--sound/ac97_bus.c (renamed from sound/pci/ac97/ac97_bus.c)0
-rw-r--r--sound/core/info.c2
-rw-r--r--sound/core/pcm_native.c2
-rw-r--r--sound/drivers/Kconfig6
-rw-r--r--sound/oss/dmasound/dmasound_core.c4
-rw-r--r--sound/oss/msnd_pinnacle.c4
-rw-r--r--sound/oss/soundcard.c8
-rw-r--r--sound/pci/ac97/Makefile2
-rw-r--r--sound/sound_firmware.c2
1596 files changed, 64925 insertions, 33008 deletions
diff --git a/CREDITS b/CREDITS
index d0880082c19b..8218e790f43d 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1808,6 +1808,14 @@ S: Kruislaan 419
1808S: 1098 VA Amsterdam 1808S: 1098 VA Amsterdam
1809S: The Netherlands 1809S: The Netherlands
1810 1810
1811N: Jiri Kosina
1812E: jikos@jikos.cz
1813E: jkosina@suse.cz
1814D: Generic HID layer - original code split, fixes
1815D: Various ACPI fixes, keeping correct battery state through suspend
1816D: various lockdep annotations, autofs and other random bugfixes
1817S: Prague, Czech Republic
1818
1811N: Gene Kozin 1819N: Gene Kozin
1812E: 74604.152@compuserve.com 1820E: 74604.152@compuserve.com
1813W: http://www.sangoma.com 1821W: http://www.sangoma.com
diff --git a/Documentation/ABI/testing/debugfs-pktcdvd b/Documentation/ABI/testing/debugfs-pktcdvd
new file mode 100644
index 000000000000..03dbd883cc41
--- /dev/null
+++ b/Documentation/ABI/testing/debugfs-pktcdvd
@@ -0,0 +1,20 @@
1What: /debug/pktcdvd/pktcdvd[0-7]
2Date: Oct. 2006
3KernelVersion: 2.6.19
4Contact: Thomas Maier <balagi@justmail.de>
5Description:
6
7debugfs interface
8-----------------
9
10The pktcdvd module (packet writing driver) creates
11these files in debugfs:
12
13/debug/pktcdvd/pktcdvd[0-7]/
14 info (0444) Lots of human readable driver
15 statistics and infos. Multiple lines!
16
17Example:
18-------
19
20cat /debug/pktcdvd/pktcdvd0/info
diff --git a/Documentation/ABI/testing/sysfs-class-pktcdvd b/Documentation/ABI/testing/sysfs-class-pktcdvd
new file mode 100644
index 000000000000..c4c55edc9a5c
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-pktcdvd
@@ -0,0 +1,72 @@
1What: /sys/class/pktcdvd/
2Date: Oct. 2006
3KernelVersion: 2.6.19
4Contact: Thomas Maier <balagi@justmail.de>
5Description:
6
7sysfs interface
8---------------
9
10The pktcdvd module (packet writing driver) creates
11these files in the sysfs:
12(<devid> is in format major:minor )
13
14/sys/class/pktcdvd/
15 add (0200) Write a block device id (major:minor)
16 to create a new pktcdvd device and map
17 it to the block device.
18
19 remove (0200) Write the pktcdvd device id (major:minor)
20 to it to remove the pktcdvd device.
21
22 device_map (0444) Shows the device mapping in format:
23 pktcdvd[0-7] <pktdevid> <blkdevid>
24
25/sys/class/pktcdvd/pktcdvd[0-7]/
26 dev (0444) Device id
27 uevent (0200) To send an uevent.
28
29/sys/class/pktcdvd/pktcdvd[0-7]/stat/
30 packets_started (0444) Number of started packets.
31 packets_finished (0444) Number of finished packets.
32
33 kb_written (0444) kBytes written.
34 kb_read (0444) kBytes read.
35 kb_read_gather (0444) kBytes read to fill write packets.
36
37 reset (0200) Write any value to it to reset
38 pktcdvd device statistic values, like
39 bytes read/written.
40
41/sys/class/pktcdvd/pktcdvd[0-7]/write_queue/
42 size (0444) Contains the size of the bio write
43 queue.
44
45 congestion_off (0644) If bio write queue size is below
46 this mark, accept new bio requests
47 from the block layer.
48
49 congestion_on (0644) If bio write queue size is higher
50 as this mark, do no longer accept
51 bio write requests from the block
52 layer and wait till the pktcdvd
53 device has processed enough bio's
54 so that bio write queue size is
55 below congestion off mark.
56 A value of <= 0 disables congestion
57 control.
58
59
60Example:
61--------
62To use the pktcdvd sysfs interface directly, you can do:
63
64# create a new pktcdvd device mapped to /dev/hdc
65echo "22:0" >/sys/class/pktcdvd/add
66cat /sys/class/pktcdvd/device_map
67# assuming device pktcdvd0 was created, look at stat's
68cat /sys/class/pktcdvd/pktcdvd0/stat/kb_written
69# print the device id of the mapped block device
70fgrep pktcdvd0 /sys/class/pktcdvd/device_map
71# remove device, using pktcdvd0 device id 253:0
72echo "253:0" >/sys/class/pktcdvd/remove
diff --git a/Documentation/CodingStyle b/Documentation/CodingStyle
index 29c18966b050..0ad6dcb5d45f 100644
--- a/Documentation/CodingStyle
+++ b/Documentation/CodingStyle
@@ -35,12 +35,37 @@ In short, 8-char indents make things easier to read, and have the added
35benefit of warning you when you're nesting your functions too deep. 35benefit of warning you when you're nesting your functions too deep.
36Heed that warning. 36Heed that warning.
37 37
38The preferred way to ease multiple indentation levels in a switch statement is
39to align the "switch" and its subordinate "case" labels in the same column
40instead of "double-indenting" the "case" labels. E.g.:
41
42 switch (suffix) {
43 case 'G':
44 case 'g':
45 mem <<= 30;
46 break;
47 case 'M':
48 case 'm':
49 mem <<= 20;
50 break;
51 case 'K':
52 case 'k':
53 mem <<= 10;
54 /* fall through */
55 default:
56 break;
57 }
58
59
38Don't put multiple statements on a single line unless you have 60Don't put multiple statements on a single line unless you have
39something to hide: 61something to hide:
40 62
41 if (condition) do_this; 63 if (condition) do_this;
42 do_something_everytime; 64 do_something_everytime;
43 65
66Don't put multiple assignments on a single line either. Kernel coding style
67is super simple. Avoid tricky expressions.
68
44Outside of comments, documentation and except in Kconfig, spaces are never 69Outside of comments, documentation and except in Kconfig, spaces are never
45used for indentation, and the above example is deliberately broken. 70used for indentation, and the above example is deliberately broken.
46 71
@@ -69,7 +94,7 @@ void fun(int a, int b, int c)
69 next_statement; 94 next_statement;
70} 95}
71 96
72 Chapter 3: Placing Braces 97 Chapter 3: Placing Braces and Spaces
73 98
74The other issue that always comes up in C styling is the placement of 99The other issue that always comes up in C styling is the placement of
75braces. Unlike the indent size, there are few technical reasons to 100braces. Unlike the indent size, there are few technical reasons to
@@ -81,6 +106,20 @@ brace last on the line, and put the closing brace first, thusly:
81 we do y 106 we do y
82 } 107 }
83 108
109This applies to all non-function statement blocks (if, switch, for,
110while, do). E.g.:
111
112 switch (action) {
113 case KOBJ_ADD:
114 return "add";
115 case KOBJ_REMOVE:
116 return "remove";
117 case KOBJ_CHANGE:
118 return "change";
119 default:
120 return NULL;
121 }
122
84However, there is one special case, namely functions: they have the 123However, there is one special case, namely functions: they have the
85opening brace at the beginning of the next line, thus: 124opening brace at the beginning of the next line, thus:
86 125
@@ -121,6 +160,49 @@ supply of new-lines on your screen is not a renewable resource (think
12125-line terminal screens here), you have more empty lines to put 16025-line terminal screens here), you have more empty lines to put
122comments on. 161comments on.
123 162
163 3.1: Spaces
164
165Linux kernel style for use of spaces depends (mostly) on
166function-versus-keyword usage. Use a space after (most) keywords. The
167notable exceptions are sizeof, typeof, alignof, and __attribute__, which look
168somewhat like functions (and are usually used with parentheses in Linux,
169although they are not required in the language, as in: "sizeof info" after
170"struct fileinfo info;" is declared).
171
172So use a space after these keywords:
173 if, switch, case, for, do, while
174but not with sizeof, typeof, alignof, or __attribute__. E.g.,
175 s = sizeof(struct file);
176
177Do not add spaces around (inside) parenthesized expressions. This example is
178*bad*:
179
180 s = sizeof( struct file );
181
182When declaring pointer data or a function that returns a pointer type, the
183preferred use of '*' is adjacent to the data name or function name and not
184adjacent to the type name. Examples:
185
186 char *linux_banner;
187 unsigned long long memparse(char *ptr, char **retptr);
188 char *match_strdup(substring_t *s);
189
190Use one space around (on each side of) most binary and ternary operators,
191such as any of these:
192
193 = + - < > * / % | & ^ <= >= == != ? :
194
195but no space after unary operators:
196 & * + - ~ ! sizeof typeof alignof __attribute__ defined
197
198no space before the postfix increment & decrement unary operators:
199 ++ --
200
201no space after the prefix increment & decrement unary operators:
202 ++ --
203
204and no space around the '.' and "->" structure member operators.
205
124 206
125 Chapter 4: Naming 207 Chapter 4: Naming
126 208
@@ -152,7 +234,7 @@ variable that is used to hold a temporary value.
152 234
153If you are afraid to mix up your local variable names, you have another 235If you are afraid to mix up your local variable names, you have another
154problem, which is called the function-growth-hormone-imbalance syndrome. 236problem, which is called the function-growth-hormone-imbalance syndrome.
155See next chapter. 237See chapter 6 (Functions).
156 238
157 239
158 Chapter 5: Typedefs 240 Chapter 5: Typedefs
@@ -258,6 +340,20 @@ generally easily keep track of about 7 different things, anything more
258and it gets confused. You know you're brilliant, but maybe you'd like 340and it gets confused. You know you're brilliant, but maybe you'd like
259to understand what you did 2 weeks from now. 341to understand what you did 2 weeks from now.
260 342
343In source files, separate functions with one blank line. If the function is
344exported, the EXPORT* macro for it should follow immediately after the closing
345function brace line. E.g.:
346
347int system_is_up(void)
348{
349 return system_state == SYSTEM_RUNNING;
350}
351EXPORT_SYMBOL(system_is_up);
352
353In function prototypes, include parameter names with their data types.
354Although this is not required by the C language, it is preferred in Linux
355because it is a simple way to add valuable information for the reader.
356
261 357
262 Chapter 7: Centralized exiting of functions 358 Chapter 7: Centralized exiting of functions
263 359
@@ -306,16 +402,36 @@ time to explain badly written code.
306Generally, you want your comments to tell WHAT your code does, not HOW. 402Generally, you want your comments to tell WHAT your code does, not HOW.
307Also, try to avoid putting comments inside a function body: if the 403Also, try to avoid putting comments inside a function body: if the
308function is so complex that you need to separately comment parts of it, 404function is so complex that you need to separately comment parts of it,
309you should probably go back to chapter 5 for a while. You can make 405you should probably go back to chapter 6 for a while. You can make
310small comments to note or warn about something particularly clever (or 406small comments to note or warn about something particularly clever (or
311ugly), but try to avoid excess. Instead, put the comments at the head 407ugly), but try to avoid excess. Instead, put the comments at the head
312of the function, telling people what it does, and possibly WHY it does 408of the function, telling people what it does, and possibly WHY it does
313it. 409it.
314 410
315When commenting the kernel API functions, please use the kerneldoc format. 411When commenting the kernel API functions, please use the kernel-doc format.
316See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc 412See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/kernel-doc
317for details. 413for details.
318 414
415Linux style for comments is the C89 "/* ... */" style.
416Don't use C99-style "// ..." comments.
417
418The preferred style for long (multi-line) comments is:
419
420 /*
421 * This is the preferred style for multi-line
422 * comments in the Linux kernel source code.
423 * Please use it consistently.
424 *
425 * Description: A column of asterisks on the left side,
426 * with beginning and ending almost-blank lines.
427 */
428
429It's also important to comment data, whether they are basic types or derived
430types. To this end, use just one data declaration per line (no commas for
431multiple data declarations). This leaves you room for a small comment on each
432item, explaining its use.
433
434
319 Chapter 9: You've made a mess of it 435 Chapter 9: You've made a mess of it
320 436
321That's OK, we all do. You've probably been told by your long-time Unix 437That's OK, we all do. You've probably been told by your long-time Unix
@@ -591,4 +707,4 @@ Kernel CodingStyle, by greg@kroah.com at OLS 2002:
591http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/ 707http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
592 708
593-- 709--
594Last updated on 30 April 2006. 710Last updated on 2006-December-06.
diff --git a/Documentation/DocBook/kernel-api.tmpl b/Documentation/DocBook/kernel-api.tmpl
index ca094913c555..3fa0c4b4541e 100644
--- a/Documentation/DocBook/kernel-api.tmpl
+++ b/Documentation/DocBook/kernel-api.tmpl
@@ -559,4 +559,12 @@ X!Idrivers/video/console/fonts.c
559--> 559-->
560 </sect1> 560 </sect1>
561 </chapter> 561 </chapter>
562
563 <chapter id="input_subsystem">
564 <title>Input Subsystem</title>
565!Iinclude/linux/input.h
566!Edrivers/input/input.c
567!Edrivers/input/ff-core.c
568!Edrivers/input/ff-memless.c
569 </chapter>
562</book> 570</book>
diff --git a/Documentation/SubmitChecklist b/Documentation/SubmitChecklist
index 7ac61f60037a..2270efa10153 100644
--- a/Documentation/SubmitChecklist
+++ b/Documentation/SubmitChecklist
@@ -66,3 +66,9 @@ kernel patches.
66 See Documentation/ABI/README for more information. 66 See Documentation/ABI/README for more information.
67 67
6820: Check that it all passes `make headers_check'. 6820: Check that it all passes `make headers_check'.
69
7021: Has been checked with injection of at least slab and page-allocation
71 fauilures. See Documentation/fault-injection/.
72
73 If the new code is substantial, addition of subsystem-specific fault
74 injection might be appropriate.
diff --git a/Documentation/accounting/getdelays.c b/Documentation/accounting/getdelays.c
index bf2b0e2f87e1..e9126e794ed7 100644
--- a/Documentation/accounting/getdelays.c
+++ b/Documentation/accounting/getdelays.c
@@ -7,6 +7,8 @@
7 * Copyright (C) Balbir Singh, IBM Corp. 2006 7 * Copyright (C) Balbir Singh, IBM Corp. 2006
8 * Copyright (c) Jay Lan, SGI. 2006 8 * Copyright (c) Jay Lan, SGI. 2006
9 * 9 *
10 * Compile with
11 * gcc -I/usr/src/linux/include getdelays.c -o getdelays
10 */ 12 */
11 13
12#include <stdio.h> 14#include <stdio.h>
@@ -35,13 +37,20 @@
35#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN)) 37#define NLA_DATA(na) ((void *)((char*)(na) + NLA_HDRLEN))
36#define NLA_PAYLOAD(len) (len - NLA_HDRLEN) 38#define NLA_PAYLOAD(len) (len - NLA_HDRLEN)
37 39
38#define err(code, fmt, arg...) do { printf(fmt, ##arg); exit(code); } while (0) 40#define err(code, fmt, arg...) \
39int done = 0; 41 do { \
40int rcvbufsz=0; 42 fprintf(stderr, fmt, ##arg); \
41 43 exit(code); \
42 char name[100]; 44 } while (0)
43int dbg=0, print_delays=0; 45
46int done;
47int rcvbufsz;
48char name[100];
49int dbg;
50int print_delays;
51int print_io_accounting;
44__u64 stime, utime; 52__u64 stime, utime;
53
45#define PRINTF(fmt, arg...) { \ 54#define PRINTF(fmt, arg...) { \
46 if (dbg) { \ 55 if (dbg) { \
47 printf(fmt, ##arg); \ 56 printf(fmt, ##arg); \
@@ -78,8 +87,9 @@ static int create_nl_socket(int protocol)
78 if (rcvbufsz) 87 if (rcvbufsz)
79 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, 88 if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF,
80 &rcvbufsz, sizeof(rcvbufsz)) < 0) { 89 &rcvbufsz, sizeof(rcvbufsz)) < 0) {
81 printf("Unable to set socket rcv buf size to %d\n", 90 fprintf(stderr, "Unable to set socket rcv buf size "
82 rcvbufsz); 91 "to %d\n",
92 rcvbufsz);
83 return -1; 93 return -1;
84 } 94 }
85 95
@@ -186,6 +196,15 @@ void print_delayacct(struct taskstats *t)
186 "count", "delay total", t->swapin_count, t->swapin_delay_total); 196 "count", "delay total", t->swapin_count, t->swapin_delay_total);
187} 197}
188 198
199void print_ioacct(struct taskstats *t)
200{
201 printf("%s: read=%llu, write=%llu, cancelled_write=%llu\n",
202 t->ac_comm,
203 (unsigned long long)t->read_bytes,
204 (unsigned long long)t->write_bytes,
205 (unsigned long long)t->cancelled_write_bytes);
206}
207
189int main(int argc, char *argv[]) 208int main(int argc, char *argv[])
190{ 209{
191 int c, rc, rep_len, aggr_len, len2, cmd_type; 210 int c, rc, rep_len, aggr_len, len2, cmd_type;
@@ -208,7 +227,7 @@ int main(int argc, char *argv[])
208 struct msgtemplate msg; 227 struct msgtemplate msg;
209 228
210 while (1) { 229 while (1) {
211 c = getopt(argc, argv, "dw:r:m:t:p:v:l"); 230 c = getopt(argc, argv, "diw:r:m:t:p:v:l");
212 if (c < 0) 231 if (c < 0)
213 break; 232 break;
214 233
@@ -217,6 +236,10 @@ int main(int argc, char *argv[])
217 printf("print delayacct stats ON\n"); 236 printf("print delayacct stats ON\n");
218 print_delays = 1; 237 print_delays = 1;
219 break; 238 break;
239 case 'i':
240 printf("printing IO accounting\n");
241 print_io_accounting = 1;
242 break;
220 case 'w': 243 case 'w':
221 strncpy(logfile, optarg, MAX_FILENAME); 244 strncpy(logfile, optarg, MAX_FILENAME);
222 printf("write to file %s\n", logfile); 245 printf("write to file %s\n", logfile);
@@ -238,14 +261,12 @@ int main(int argc, char *argv[])
238 if (!tid) 261 if (!tid)
239 err(1, "Invalid tgid\n"); 262 err(1, "Invalid tgid\n");
240 cmd_type = TASKSTATS_CMD_ATTR_TGID; 263 cmd_type = TASKSTATS_CMD_ATTR_TGID;
241 print_delays = 1;
242 break; 264 break;
243 case 'p': 265 case 'p':
244 tid = atoi(optarg); 266 tid = atoi(optarg);
245 if (!tid) 267 if (!tid)
246 err(1, "Invalid pid\n"); 268 err(1, "Invalid pid\n");
247 cmd_type = TASKSTATS_CMD_ATTR_PID; 269 cmd_type = TASKSTATS_CMD_ATTR_PID;
248 print_delays = 1;
249 break; 270 break;
250 case 'v': 271 case 'v':
251 printf("debug on\n"); 272 printf("debug on\n");
@@ -277,7 +298,7 @@ int main(int argc, char *argv[])
277 mypid = getpid(); 298 mypid = getpid();
278 id = get_family_id(nl_sd); 299 id = get_family_id(nl_sd);
279 if (!id) { 300 if (!id) {
280 printf("Error getting family id, errno %d", errno); 301 fprintf(stderr, "Error getting family id, errno %d\n", errno);
281 goto err; 302 goto err;
282 } 303 }
283 PRINTF("family id %d\n", id); 304 PRINTF("family id %d\n", id);
@@ -288,7 +309,7 @@ int main(int argc, char *argv[])
288 &cpumask, strlen(cpumask) + 1); 309 &cpumask, strlen(cpumask) + 1);
289 PRINTF("Sent register cpumask, retval %d\n", rc); 310 PRINTF("Sent register cpumask, retval %d\n", rc);
290 if (rc < 0) { 311 if (rc < 0) {
291 printf("error sending register cpumask\n"); 312 fprintf(stderr, "error sending register cpumask\n");
292 goto err; 313 goto err;
293 } 314 }
294 } 315 }
@@ -298,7 +319,7 @@ int main(int argc, char *argv[])
298 cmd_type, &tid, sizeof(__u32)); 319 cmd_type, &tid, sizeof(__u32));
299 PRINTF("Sent pid/tgid, retval %d\n", rc); 320 PRINTF("Sent pid/tgid, retval %d\n", rc);
300 if (rc < 0) { 321 if (rc < 0) {
301 printf("error sending tid/tgid cmd\n"); 322 fprintf(stderr, "error sending tid/tgid cmd\n");
302 goto done; 323 goto done;
303 } 324 }
304 } 325 }
@@ -310,13 +331,15 @@ int main(int argc, char *argv[])
310 PRINTF("received %d bytes\n", rep_len); 331 PRINTF("received %d bytes\n", rep_len);
311 332
312 if (rep_len < 0) { 333 if (rep_len < 0) {
313 printf("nonfatal reply error: errno %d\n", errno); 334 fprintf(stderr, "nonfatal reply error: errno %d\n",
335 errno);
314 continue; 336 continue;
315 } 337 }
316 if (msg.n.nlmsg_type == NLMSG_ERROR || 338 if (msg.n.nlmsg_type == NLMSG_ERROR ||
317 !NLMSG_OK((&msg.n), rep_len)) { 339 !NLMSG_OK((&msg.n), rep_len)) {
318 struct nlmsgerr *err = NLMSG_DATA(&msg); 340 struct nlmsgerr *err = NLMSG_DATA(&msg);
319 printf("fatal reply error, errno %d\n", err->error); 341 fprintf(stderr, "fatal reply error, errno %d\n",
342 err->error);
320 goto done; 343 goto done;
321 } 344 }
322 345
@@ -356,6 +379,8 @@ int main(int argc, char *argv[])
356 count++; 379 count++;
357 if (print_delays) 380 if (print_delays)
358 print_delayacct((struct taskstats *) NLA_DATA(na)); 381 print_delayacct((struct taskstats *) NLA_DATA(na));
382 if (print_io_accounting)
383 print_ioacct((struct taskstats *) NLA_DATA(na));
359 if (fd) { 384 if (fd) {
360 if (write(fd, NLA_DATA(na), na->nla_len) < 0) { 385 if (write(fd, NLA_DATA(na), na->nla_len) < 0) {
361 err(1,"write error\n"); 386 err(1,"write error\n");
@@ -365,7 +390,9 @@ int main(int argc, char *argv[])
365 goto done; 390 goto done;
366 break; 391 break;
367 default: 392 default:
368 printf("Unknown nested nla_type %d\n", na->nla_type); 393 fprintf(stderr, "Unknown nested"
394 " nla_type %d\n",
395 na->nla_type);
369 break; 396 break;
370 } 397 }
371 len2 += NLA_ALIGN(na->nla_len); 398 len2 += NLA_ALIGN(na->nla_len);
@@ -374,7 +401,8 @@ int main(int argc, char *argv[])
374 break; 401 break;
375 402
376 default: 403 default:
377 printf("Unknown nla_type %d\n", na->nla_type); 404 fprintf(stderr, "Unknown nla_type %d\n",
405 na->nla_type);
378 break; 406 break;
379 } 407 }
380 na = (struct nlattr *) (GENLMSG_DATA(&msg) + len); 408 na = (struct nlattr *) (GENLMSG_DATA(&msg) + len);
diff --git a/Documentation/cdrom/packet-writing.txt b/Documentation/cdrom/packet-writing.txt
index 3d44c561fe6d..7715d2247c4d 100644
--- a/Documentation/cdrom/packet-writing.txt
+++ b/Documentation/cdrom/packet-writing.txt
@@ -90,6 +90,41 @@ Notes
90 to create an ext2 filesystem on the disc. 90 to create an ext2 filesystem on the disc.
91 91
92 92
93Using the pktcdvd sysfs interface
94---------------------------------
95
96Since Linux 2.6.19, the pktcdvd module has a sysfs interface
97and can be controlled by it. For example the "pktcdvd" tool uses
98this interface. (see http://people.freenet.de/BalaGi#pktcdvd )
99
100"pktcdvd" works similar to "pktsetup", e.g.:
101
102 # pktcdvd -a dev_name /dev/hdc
103 # mkudffs /dev/pktcdvd/dev_name
104 # mount -t udf -o rw,noatime /dev/pktcdvd/dev_name /dvdram
105 # cp files /dvdram
106 # umount /dvdram
107 # pktcdvd -r dev_name
108
109
110For a description of the sysfs interface look into the file:
111
112 Documentation/ABI/testing/sysfs-block-pktcdvd
113
114
115Using the pktcdvd debugfs interface
116-----------------------------------
117
118To read pktcdvd device infos in human readable form, do:
119
120 # cat /debug/pktcdvd/pktcdvd[0-7]/info
121
122For a description of the debugfs interface look into the file:
123
124 Documentation/ABI/testing/debugfs-pktcdvd
125
126
127
93Links 128Links
94----- 129-----
95 130
diff --git a/Documentation/dvb/cards.txt b/Documentation/dvb/cards.txt
index ca58e339d85f..cc09187a5db7 100644
--- a/Documentation/dvb/cards.txt
+++ b/Documentation/dvb/cards.txt
@@ -22,10 +22,10 @@ o Frontends drivers:
22 - ves1x93 : Alps BSRV2 (ves1893 demodulator) and dbox2 (ves1993) 22 - ves1x93 : Alps BSRV2 (ves1893 demodulator) and dbox2 (ves1993)
23 - cx24110 : Conexant HM1221/HM1811 (cx24110 or cx24106 demod, cx24108 PLL) 23 - cx24110 : Conexant HM1221/HM1811 (cx24110 or cx24106 demod, cx24108 PLL)
24 - grundig_29504-491 : Grundig 29504-491 (Philips TDA8083 demodulator), tsa5522 PLL 24 - grundig_29504-491 : Grundig 29504-491 (Philips TDA8083 demodulator), tsa5522 PLL
25 - mt312 : Zarlink mt312 or Mitel vp310 demodulator, sl1935 or tsa5059 PLL 25 - mt312 : Zarlink mt312 or Mitel vp310 demodulator, sl1935 or tsa5059 PLLi, Technisat Sky2Pc with bios Rev. 2.3
26 - stv0299 : Alps BSRU6 (tsa5059 PLL), LG TDQB-S00x (tsa5059 PLL), 26 - stv0299 : Alps BSRU6 (tsa5059 PLL), LG TDQB-S00x (tsa5059 PLL),
27 LG TDQF-S001F (sl1935 PLL), Philips SU1278 (tua6100 PLL), 27 LG TDQF-S001F (sl1935 PLL), Philips SU1278 (tua6100 PLL),
28 Philips SU1278SH (tsa5059 PLL), Samsung TBMU24112IMB 28 Philips SU1278SH (tsa5059 PLL), Samsung TBMU24112IMB, Technisat Sky2Pc with bios Rev. 2.6
29 DVB-C: 29 DVB-C:
30 - ves1820 : various (ves1820 demodulator, sp5659c or spXXXX PLL) 30 - ves1820 : various (ves1820 demodulator, sp5659c or spXXXX PLL)
31 - at76c651 : Atmel AT76c651(B) with DAT7021 PLL 31 - at76c651 : Atmel AT76c651(B) with DAT7021 PLL
diff --git a/Documentation/fault-injection/failcmd.sh b/Documentation/fault-injection/failcmd.sh
new file mode 100644
index 000000000000..63177aba8106
--- /dev/null
+++ b/Documentation/fault-injection/failcmd.sh
@@ -0,0 +1,4 @@
1#!/bin/bash
2
3echo 1 > /proc/self/make-it-fail
4exec $*
diff --git a/Documentation/fault-injection/failmodule.sh b/Documentation/fault-injection/failmodule.sh
new file mode 100644
index 000000000000..474a8b971f9c
--- /dev/null
+++ b/Documentation/fault-injection/failmodule.sh
@@ -0,0 +1,31 @@
1#!/bin/bash
2#
3# Usage: failmodule <failname> <modulename> [stacktrace-depth]
4#
5# <failname>: "failslab", "fail_alloc_page", or "fail_make_request"
6#
7# <modulename>: module name that you want to inject faults.
8#
9# [stacktrace-depth]: the maximum number of stacktrace walking allowed
10#
11
12STACKTRACE_DEPTH=5
13if [ $# -gt 2 ]; then
14 STACKTRACE_DEPTH=$3
15fi
16
17if [ ! -d /debug/$1 ]; then
18 echo "Fault-injection $1 does not exist" >&2
19 exit 1
20fi
21if [ ! -d /sys/module/$2 ]; then
22 echo "Module $2 does not exist" >&2
23 exit 1
24fi
25
26# Disable any fault injection
27echo 0 > /debug/$1/stacktrace-depth
28
29echo `cat /sys/module/$2/sections/.text` > /debug/$1/require-start
30echo `cat /sys/module/$2/sections/.exit.text` > /debug/$1/require-end
31echo $STACKTRACE_DEPTH > /debug/$1/stacktrace-depth
diff --git a/Documentation/fault-injection/fault-injection.txt b/Documentation/fault-injection/fault-injection.txt
new file mode 100644
index 000000000000..b7ca560b9340
--- /dev/null
+++ b/Documentation/fault-injection/fault-injection.txt
@@ -0,0 +1,225 @@
1Fault injection capabilities infrastructure
2===========================================
3
4See also drivers/md/faulty.c and "every_nth" module option for scsi_debug.
5
6
7Available fault injection capabilities
8--------------------------------------
9
10o failslab
11
12 injects slab allocation failures. (kmalloc(), kmem_cache_alloc(), ...)
13
14o fail_page_alloc
15
16 injects page allocation failures. (alloc_pages(), get_free_pages(), ...)
17
18o fail_make_request
19
20 injects disk IO errors on devices permitted by setting
21 /sys/block/<device>/make-it-fail or
22 /sys/block/<device>/<partition>/make-it-fail. (generic_make_request())
23
24Configure fault-injection capabilities behavior
25-----------------------------------------------
26
27o debugfs entries
28
29fault-inject-debugfs kernel module provides some debugfs entries for runtime
30configuration of fault-injection capabilities.
31
32- /debug/fail*/probability:
33
34 likelihood of failure injection, in percent.
35 Format: <percent>
36
37 Note that one-failure-per-hundred is a very high error rate
38 for some testcases. Consider setting probability=100 and configure
39 /debug/fail*/interval for such testcases.
40
41- /debug/fail*/interval:
42
43 specifies the interval between failures, for calls to
44 should_fail() that pass all the other tests.
45
46 Note that if you enable this, by setting interval>1, you will
47 probably want to set probability=100.
48
49- /debug/fail*/times:
50
51 specifies how many times failures may happen at most.
52 A value of -1 means "no limit".
53
54- /debug/fail*/space:
55
56 specifies an initial resource "budget", decremented by "size"
57 on each call to should_fail(,size). Failure injection is
58 suppressed until "space" reaches zero.
59
60- /debug/fail*/verbose
61
62 Format: { 0 | 1 | 2 }
63 specifies the verbosity of the messages when failure is
64 injected. '0' means no messages; '1' will print only a single
65 log line per failure; '2' will print a call trace too -- useful
66 to debug the problems revealed by fault injection.
67
68- /debug/fail*/task-filter:
69
70 Format: { 'Y' | 'N' }
71 A value of 'N' disables filtering by process (default).
72 Any positive value limits failures to only processes indicated by
73 /proc/<pid>/make-it-fail==1.
74
75- /debug/fail*/require-start:
76- /debug/fail*/require-end:
77- /debug/fail*/reject-start:
78- /debug/fail*/reject-end:
79
80 specifies the range of virtual addresses tested during
81 stacktrace walking. Failure is injected only if some caller
82 in the walked stacktrace lies within the required range, and
83 none lies within the rejected range.
84 Default required range is [0,ULONG_MAX) (whole of virtual address space).
85 Default rejected range is [0,0).
86
87- /debug/fail*/stacktrace-depth:
88
89 specifies the maximum stacktrace depth walked during search
90 for a caller within [require-start,require-end) OR
91 [reject-start,reject-end).
92
93- /debug/fail_page_alloc/ignore-gfp-highmem:
94
95 Format: { 'Y' | 'N' }
96 default is 'N', setting it to 'Y' won't inject failures into
97 highmem/user allocations.
98
99- /debug/failslab/ignore-gfp-wait:
100- /debug/fail_page_alloc/ignore-gfp-wait:
101
102 Format: { 'Y' | 'N' }
103 default is 'N', setting it to 'Y' will inject failures
104 only into non-sleep allocations (GFP_ATOMIC allocations).
105
106o Boot option
107
108In order to inject faults while debugfs is not available (early boot time),
109use the boot option:
110
111 failslab=
112 fail_page_alloc=
113 fail_make_request=<interval>,<probability>,<space>,<times>
114
115How to add new fault injection capability
116-----------------------------------------
117
118o #include <linux/fault-inject.h>
119
120o define the fault attributes
121
122 DECLARE_FAULT_INJECTION(name);
123
124 Please see the definition of struct fault_attr in fault-inject.h
125 for details.
126
127o provide a way to configure fault attributes
128
129- boot option
130
131 If you need to enable the fault injection capability from boot time, you can
132 provide boot option to configure it. There is a helper function for it:
133
134 setup_fault_attr(attr, str);
135
136- debugfs entries
137
138 failslab, fail_page_alloc, and fail_make_request use this way.
139 Helper functions:
140
141 init_fault_attr_entries(entries, attr, name);
142 void cleanup_fault_attr_entries(entries);
143
144- module parameters
145
146 If the scope of the fault injection capability is limited to a
147 single kernel module, it is better to provide module parameters to
148 configure the fault attributes.
149
150o add a hook to insert failures
151
152 Upon should_fail() returning true, client code should inject a failure.
153
154 should_fail(attr, size);
155
156Application Examples
157--------------------
158
159o inject slab allocation failures into module init/cleanup code
160
161------------------------------------------------------------------------------
162#!/bin/bash
163
164FAILCMD=Documentation/fault-injection/failcmd.sh
165BLACKLIST="root_plug evbug"
166
167FAILNAME=failslab
168echo Y > /debug/$FAILNAME/task-filter
169echo 10 > /debug/$FAILNAME/probability
170echo 100 > /debug/$FAILNAME/interval
171echo -1 > /debug/$FAILNAME/times
172echo 2 > /debug/$FAILNAME/verbose
173echo 1 > /debug/$FAILNAME/ignore-gfp-wait
174
175blacklist()
176{
177 echo $BLACKLIST | grep $1 > /dev/null 2>&1
178}
179
180oops()
181{
182 dmesg | grep BUG > /dev/null 2>&1
183}
184
185find /lib/modules/`uname -r` -name '*.ko' -exec basename {} .ko \; |
186 while read i
187 do
188 oops && exit 1
189
190 if ! blacklist $i
191 then
192 echo inserting $i...
193 bash $FAILCMD modprobe $i
194 fi
195 done
196
197lsmod | awk '{ if ($3 == 0) { print $1 } }' |
198 while read i
199 do
200 oops && exit 1
201
202 if ! blacklist $i
203 then
204 echo removing $i...
205 bash $FAILCMD modprobe -r $i
206 fi
207 done
208
209------------------------------------------------------------------------------
210
211o inject slab allocation failures only for a specific module
212
213------------------------------------------------------------------------------
214#!/bin/bash
215
216FAILMOD=Documentation/fault-injection/failmodule.sh
217
218echo injecting errors into the module $1...
219
220modprobe $1
221bash $FAILMOD failslab $1 10
222echo 25 > /debug/failslab/probability
223
224------------------------------------------------------------------------------
225
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 46f2a559b27c..031029e89fd9 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -216,17 +216,6 @@ Who: Thomas Gleixner <tglx@linutronix.de>
216 216
217--------------------------- 217---------------------------
218 218
219What: i2c-ite and i2c-algo-ite drivers
220When: September 2006
221Why: These drivers never compiled since they were added to the kernel
222 tree 5 years ago. This feature removal can be reevaluated if
223 someone shows interest in the drivers, fixes them and takes over
224 maintenance.
225 http://marc.theaimsgroup.com/?l=linux-mips&m=115040510817448
226Who: Jean Delvare <khali@linux-fr.org>
227
228---------------------------
229
230What: Bridge netfilter deferred IPv4/IPv6 output hook calling 219What: Bridge netfilter deferred IPv4/IPv6 output hook calling
231When: January 2007 220When: January 2007
232Why: The deferred output hooks are a layering violation causing unusual 221Why: The deferred output hooks are a layering violation causing unusual
diff --git a/Documentation/filesystems/ocfs2.txt b/Documentation/filesystems/ocfs2.txt
index af6defd10cb6..8ccf0c1b58ed 100644
--- a/Documentation/filesystems/ocfs2.txt
+++ b/Documentation/filesystems/ocfs2.txt
@@ -54,3 +54,6 @@ errors=panic Panic and halt the machine if an error occurs.
54intr (*) Allow signals to interrupt cluster operations. 54intr (*) Allow signals to interrupt cluster operations.
55nointr Do not allow signals to interrupt cluster 55nointr Do not allow signals to interrupt cluster
56 operations. 56 operations.
57atime_quantum=60(*) OCFS2 will not update atime unless this number
58 of seconds has passed since the last update.
59 Set to zero to always update atime.
diff --git a/Documentation/i2c/busses/i2c-amd8111 b/Documentation/i2c/busses/i2c-amd8111
index db294ee7455a..460dd6635fd2 100644
--- a/Documentation/i2c/busses/i2c-amd8111
+++ b/Documentation/i2c/busses/i2c-amd8111
@@ -5,7 +5,7 @@ Supported adapters:
5 5
6Datasheets: 6Datasheets:
7 AMD datasheet not yet available, but almost everything can be found 7 AMD datasheet not yet available, but almost everything can be found
8 in publically available ACPI 2.0 specification, which the adapter 8 in the publicly available ACPI 2.0 specification, which the adapter
9 follows. 9 follows.
10 10
11Author: Vojtech Pavlik <vojtech@suse.cz> 11Author: Vojtech Pavlik <vojtech@suse.cz>
diff --git a/Documentation/i2c/busses/i2c-i801 b/Documentation/i2c/busses/i2c-i801
index e46c23458242..3db69a086c41 100644
--- a/Documentation/i2c/busses/i2c-i801
+++ b/Documentation/i2c/busses/i2c-i801
@@ -9,7 +9,10 @@ Supported adapters:
9 * Intel 82801EB/ER (ICH5) (HW PEC supported, 32 byte buffer not supported) 9 * Intel 82801EB/ER (ICH5) (HW PEC supported, 32 byte buffer not supported)
10 * Intel 6300ESB 10 * Intel 6300ESB
11 * Intel 82801FB/FR/FW/FRW (ICH6) 11 * Intel 82801FB/FR/FW/FRW (ICH6)
12 * Intel ICH7 12 * Intel 82801G (ICH7)
13 * Intel 631xESB/632xESB (ESB2)
14 * Intel 82801H (ICH8)
15 * Intel ICH9
13 Datasheets: Publicly available at the Intel website 16 Datasheets: Publicly available at the Intel website
14 17
15Authors: 18Authors:
diff --git a/Documentation/i2c/busses/i2c-nforce2 b/Documentation/i2c/busses/i2c-nforce2
index cd49c428a3ab..7f61fbc03f7f 100644
--- a/Documentation/i2c/busses/i2c-nforce2
+++ b/Documentation/i2c/busses/i2c-nforce2
@@ -10,11 +10,11 @@ Supported adapters:
10 * nForce4 MCP51 10de:0264 10 * nForce4 MCP51 10de:0264
11 * nForce4 MCP55 10de:0368 11 * nForce4 MCP55 10de:0368
12 12
13Datasheet: not publically available, but seems to be similar to the 13Datasheet: not publicly available, but seems to be similar to the
14 AMD-8111 SMBus 2.0 adapter. 14 AMD-8111 SMBus 2.0 adapter.
15 15
16Authors: 16Authors:
17 Hans-Frieder Vogt <hfvogt@arcor.de>, 17 Hans-Frieder Vogt <hfvogt@gmx.net>,
18 Thomas Leibold <thomas@plx.com>, 18 Thomas Leibold <thomas@plx.com>,
19 Patrick Dreker <patrick@dreker.de> 19 Patrick Dreker <patrick@dreker.de>
20 20
@@ -38,7 +38,7 @@ Notes
38----- 38-----
39 39
40The SMBus adapter in the nForce2 chipset seems to be very similar to the 40The SMBus adapter in the nForce2 chipset seems to be very similar to the
41SMBus 2.0 adapter in the AMD-8111 southbridge. However, I could only get 41SMBus 2.0 adapter in the AMD-8111 south bridge. However, I could only get
42the driver to work with direct I/O access, which is different to the EC 42the driver to work with direct I/O access, which is different to the EC
43interface of the AMD-8111. Tested on Asus A7N8X. The ACPI DSDT table of the 43interface of the AMD-8111. Tested on Asus A7N8X. The ACPI DSDT table of the
44Asus A7N8X lists two SMBuses, both of which are supported by this driver. 44Asus A7N8X lists two SMBuses, both of which are supported by this driver.
diff --git a/Documentation/ioctl-number.txt b/Documentation/ioctl-number.txt
index edc04d74ae23..5a8bd5bd88ef 100644
--- a/Documentation/ioctl-number.txt
+++ b/Documentation/ioctl-number.txt
@@ -191,3 +191,5 @@ Code Seq# Include File Comments
191 <mailto:aherrman@de.ibm.com> 191 <mailto:aherrman@de.ibm.com>
1920xF3 00-3F video/sisfb.h sisfb (in development) 1920xF3 00-3F video/sisfb.h sisfb (in development)
193 <mailto:thomas@winischhofer.net> 193 <mailto:thomas@winischhofer.net>
1940xF4 00-1F video/mbxfb.h mbxfb
195 <mailto:raph@8d.com>
diff --git a/Documentation/ioctl/ioctl-decoding.txt b/Documentation/ioctl/ioctl-decoding.txt
new file mode 100644
index 000000000000..bfdf7f3ee4f0
--- /dev/null
+++ b/Documentation/ioctl/ioctl-decoding.txt
@@ -0,0 +1,24 @@
1To decode a hex IOCTL code:
2
3Most architecures use this generic format, but check
4include/ARCH/ioctl.h for specifics, e.g. powerpc
5uses 3 bits to encode read/write and 13 bits for size.
6
7 bits meaning
8 31-30 00 - no parameters: uses _IO macro
9 10 - read: _IOR
10 01 - write: _IOW
11 11 - read/write: _IOWR
12
13 29-16 size of arguments
14
15 15-8 ascii character supposedly
16 unique to each driver
17
18 7-0 function #
19
20
21 So for example 0x82187201 is a read with arg length of 0x218,
22character 'r' function 1. Grepping the source reveals this is:
23
24#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index b79bcdf16319..d8323b8893c3 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -548,6 +548,13 @@ and is between 256 and 4096 characters. It is defined in the file
548 eurwdt= [HW,WDT] Eurotech CPU-1220/1410 onboard watchdog. 548 eurwdt= [HW,WDT] Eurotech CPU-1220/1410 onboard watchdog.
549 Format: <io>[,<irq>] 549 Format: <io>[,<irq>]
550 550
551 failslab=
552 fail_page_alloc=
553 fail_make_request=[KNL]
554 General fault injection mechanism.
555 Format: <interval>,<probability>,<space>,<times>
556 See also /Documentation/fault-injection/.
557
551 fd_mcs= [HW,SCSI] 558 fd_mcs= [HW,SCSI]
552 See header of drivers/scsi/fd_mcs.c. 559 See header of drivers/scsi/fd_mcs.c.
553 560
diff --git a/Documentation/networking/dccp.txt b/Documentation/networking/dccp.txt
index dda15886bcb5..387482e46c47 100644
--- a/Documentation/networking/dccp.txt
+++ b/Documentation/networking/dccp.txt
@@ -19,7 +19,8 @@ for real time and multimedia traffic.
19 19
20It has a base protocol and pluggable congestion control IDs (CCIDs). 20It has a base protocol and pluggable congestion control IDs (CCIDs).
21 21
22It is at experimental RFC status and the homepage for DCCP as a protocol is at: 22It is at proposed standard RFC status and the homepage for DCCP as a protocol
23is at:
23 http://www.read.cs.ucla.edu/dccp/ 24 http://www.read.cs.ucla.edu/dccp/
24 25
25Missing features 26Missing features
@@ -34,9 +35,6 @@ The known bugs are at:
34Socket options 35Socket options
35============== 36==============
36 37
37DCCP_SOCKOPT_PACKET_SIZE is used for CCID3 to set default packet size for
38calculations.
39
40DCCP_SOCKOPT_SERVICE sets the service. The specification mandates use of 38DCCP_SOCKOPT_SERVICE sets the service. The specification mandates use of
41service codes (RFC 4340, sec. 8.1.2); if this socket option is not set, 39service codes (RFC 4340, sec. 8.1.2); if this socket option is not set,
42the socket will fall back to 0 (which means that no meaningful service code 40the socket will fall back to 0 (which means that no meaningful service code
diff --git a/Documentation/s390/driver-model.txt b/Documentation/s390/driver-model.txt
index 77bf450ec39b..e938c442277d 100644
--- a/Documentation/s390/driver-model.txt
+++ b/Documentation/s390/driver-model.txt
@@ -18,11 +18,18 @@ devices/
18 - 0.0.0002/ 18 - 0.0.0002/
19 - 0.1.0000/0.1.1234/ 19 - 0.1.0000/0.1.1234/
20 ... 20 ...
21 - defunct/
21 22
22In this example, device 0815 is accessed via subchannel 0 in subchannel set 0, 23In this example, device 0815 is accessed via subchannel 0 in subchannel set 0,
23device 4711 via subchannel 1 in subchannel set 0, and subchannel 2 is a non-I/O 24device 4711 via subchannel 1 in subchannel set 0, and subchannel 2 is a non-I/O
24subchannel. Device 1234 is accessed via subchannel 0 in subchannel set 1. 25subchannel. Device 1234 is accessed via subchannel 0 in subchannel set 1.
25 26
27The subchannel named 'defunct' does not represent any real subchannel on the
28system; it is a pseudo subchannel where disconnnected ccw devices are moved to
29if they are displaced by another ccw device becoming operational on their
30former subchannel. The ccw devices will be moved again to a proper subchannel
31if they become operational again on that subchannel.
32
26You should address a ccw device via its bus id (e.g. 0.0.4711); the device can 33You should address a ccw device via its bus id (e.g. 0.0.4711); the device can
27be found under bus/ccw/devices/. 34be found under bus/ccw/devices/.
28 35
diff --git a/Documentation/spi/pxa2xx b/Documentation/spi/pxa2xx
index a1e0ee20f595..f9717fe9bd85 100644
--- a/Documentation/spi/pxa2xx
+++ b/Documentation/spi/pxa2xx
@@ -102,7 +102,7 @@ struct pxa2xx_spi_chip {
102 u8 tx_threshold; 102 u8 tx_threshold;
103 u8 rx_threshold; 103 u8 rx_threshold;
104 u8 dma_burst_size; 104 u8 dma_burst_size;
105 u32 timeout_microsecs; 105 u32 timeout;
106 u8 enable_loopback; 106 u8 enable_loopback;
107 void (*cs_control)(u32 command); 107 void (*cs_control)(u32 command);
108}; 108};
@@ -121,7 +121,7 @@ the PXA2xx "Developer Manual" sections on the DMA controller and SSP Controllers
121to determine the correct value. An SSP configured for byte-wide transfers would 121to determine the correct value. An SSP configured for byte-wide transfers would
122use a value of 8. 122use a value of 8.
123 123
124The "pxa2xx_spi_chip.timeout_microsecs" fields is used to efficiently handle 124The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle
125trailing bytes in the SSP receiver fifo. The correct value for this field is 125trailing bytes in the SSP receiver fifo. The correct value for this field is
126dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific 126dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific
127slave device. Please note that the PXA2xx SSP 1 does not support trailing byte 127slave device. Please note that the PXA2xx SSP 1 does not support trailing byte
@@ -162,18 +162,18 @@ static void cs8405a_cs_control(u32 command)
162} 162}
163 163
164static struct pxa2xx_spi_chip cs8415a_chip_info = { 164static struct pxa2xx_spi_chip cs8415a_chip_info = {
165 .tx_threshold = 12, /* SSP hardward FIFO threshold */ 165 .tx_threshold = 8, /* SSP hardward FIFO threshold */
166 .rx_threshold = 4, /* SSP hardward FIFO threshold */ 166 .rx_threshold = 8, /* SSP hardward FIFO threshold */
167 .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */ 167 .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */
168 .timeout_microsecs = 64, /* Wait at least 64usec to handle trailing */ 168 .timeout = 235, /* See Intel documentation */
169 .cs_control = cs8415a_cs_control, /* Use external chip select */ 169 .cs_control = cs8415a_cs_control, /* Use external chip select */
170}; 170};
171 171
172static struct pxa2xx_spi_chip cs8405a_chip_info = { 172static struct pxa2xx_spi_chip cs8405a_chip_info = {
173 .tx_threshold = 12, /* SSP hardward FIFO threshold */ 173 .tx_threshold = 8, /* SSP hardward FIFO threshold */
174 .rx_threshold = 4, /* SSP hardward FIFO threshold */ 174 .rx_threshold = 8, /* SSP hardward FIFO threshold */
175 .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */ 175 .dma_burst_size = 8, /* Byte wide transfers used so 8 byte bursts */
176 .timeout_microsecs = 64, /* Wait at least 64usec to handle trailing */ 176 .timeout = 235, /* See Intel documentation */
177 .cs_control = cs8405a_cs_control, /* Use external chip select */ 177 .cs_control = cs8405a_cs_control, /* Use external chip select */
178}; 178};
179 179
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index 8755b3e7b09e..62e32b49cec9 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -43,7 +43,7 @@
43 42 -> digitalnow DNTV Live! DVB-T Pro [1822:0025,1822:0019] 43 42 -> digitalnow DNTV Live! DVB-T Pro [1822:0025,1822:0019]
44 43 -> KWorld/VStream XPert DVB-T with cx22702 [17de:08a1,12ab:2300] 44 43 -> KWorld/VStream XPert DVB-T with cx22702 [17de:08a1,12ab:2300]
45 44 -> DViCO FusionHDTV DVB-T Dual Digital [18ac:db50,18ac:db54] 45 44 -> DViCO FusionHDTV DVB-T Dual Digital [18ac:db50,18ac:db54]
46 45 -> KWorld HardwareMpegTV XPert [17de:0840] 46 45 -> KWorld HardwareMpegTV XPert [17de:0840,1421:0305]
47 46 -> DViCO FusionHDTV DVB-T Hybrid [18ac:db40,18ac:db44] 47 46 -> DViCO FusionHDTV DVB-T Hybrid [18ac:db40,18ac:db44]
48 47 -> pcHDTV HD5500 HDTV [7063:5500] 48 47 -> pcHDTV HD5500 HDTV [7063:5500]
49 48 -> Kworld MCE 200 Deluxe [17de:0841] 49 48 -> Kworld MCE 200 Deluxe [17de:0841]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 53ce6a39083c..f6201cc37ec5 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -76,7 +76,7 @@
76 75 -> AVerMedia AVerTVHD MCE A180 [1461:1044] 76 75 -> AVerMedia AVerTVHD MCE A180 [1461:1044]
77 76 -> SKNet MonsterTV Mobile [1131:4ee9] 77 76 -> SKNet MonsterTV Mobile [1131:4ee9]
78 77 -> Pinnacle PCTV 40i/50i/110i (saa7133) [11bd:002e] 78 77 -> Pinnacle PCTV 40i/50i/110i (saa7133) [11bd:002e]
79 78 -> ASUSTeK P7131 Dual [1043:4862] 79 78 -> ASUSTeK P7131 Dual [1043:4862,1043:4876]
80 79 -> Sedna/MuchTV PC TV Cardbus TV/Radio (ITO25 Rev:2B) 80 79 -> Sedna/MuchTV PC TV Cardbus TV/Radio (ITO25 Rev:2B)
81 80 -> ASUS Digimatrix TV [1043:0210] 81 80 -> ASUS Digimatrix TV [1043:0210]
82 81 -> Philips Tiger reference design [1131:2018] 82 81 -> Philips Tiger reference design [1131:2018]
@@ -99,3 +99,8 @@
99 98 -> Proteus Pro 2309 [0919:2003] 99 98 -> Proteus Pro 2309 [0919:2003]
100 99 -> AVerMedia TV Hybrid A16AR [1461:2c00] 100 99 -> AVerMedia TV Hybrid A16AR [1461:2c00]
101100 -> Asus Europa2 OEM [1043:4860] 101100 -> Asus Europa2 OEM [1043:4860]
102101 -> Pinnacle PCTV 310i [11bd:002f]
103102 -> Avermedia AVerTV Studio 507 [1461:9715]
104103 -> Compro Videomate DVB-T200A
105104 -> Hauppauge WinTV-HVR1110 DVB-T/Hybrid [0070:6701]
106105 -> Terratec Cinergy HT PCMCIA [153b:1172]
diff --git a/Documentation/video4linux/cafe_ccic b/Documentation/video4linux/cafe_ccic
new file mode 100644
index 000000000000..88821022a5de
--- /dev/null
+++ b/Documentation/video4linux/cafe_ccic
@@ -0,0 +1,54 @@
1"cafe_ccic" is a driver for the Marvell 88ALP01 "cafe" CMOS camera
2controller. This is the controller found in first-generation OLPC systems,
3and this driver was written with support from the OLPC project.
4
5Current status: the core driver works. It can generate data in YUV422,
6RGB565, and RGB444 formats. (Anybody looking at the code will see RGB32 as
7well, but that is a debugging aid which will be removed shortly). VGA and
8QVGA modes work; CIF is there but the colors remain funky. Only the OV7670
9sensor is known to work with this controller at this time.
10
11To try it out: either of these commands will work:
12
13 mplayer tv:// -tv driver=v4l2:width=640:height=480 -nosound
14 mplayer tv:// -tv driver=v4l2:width=640:height=480:outfmt=bgr16 -nosound
15
16The "xawtv" utility also works; gqcam does not, for unknown reasons.
17
18There are a few load-time options, most of which can be changed after
19loading via sysfs as well:
20
21 - alloc_bufs_at_load: Normally, the driver will not allocate any DMA
22 buffers until the time comes to transfer data. If this option is set,
23 then worst-case-sized buffers will be allocated at module load time.
24 This option nails down the memory for the life of the module, but
25 perhaps decreases the chances of an allocation failure later on.
26
27 - dma_buf_size: The size of DMA buffers to allocate. Note that this
28 option is only consulted for load-time allocation; when buffers are
29 allocated at run time, they will be sized appropriately for the current
30 camera settings.
31
32 - n_dma_bufs: The controller can cycle through either two or three DMA
33 buffers. Normally, the driver tries to use three buffers; on faster
34 systems, however, it will work well with only two.
35
36 - min_buffers: The minimum number of streaming I/O buffers that the driver
37 will consent to work with. Default is one, but, on slower systems,
38 better behavior with mplayer can be achieved by setting to a higher
39 value (like six).
40
41 - max_buffers: The maximum number of streaming I/O buffers; default is
42 ten. That number was carefully picked out of a hat and should not be
43 assumed to actually mean much of anything.
44
45 - flip: If this boolean parameter is set, the sensor will be instructed to
46 invert the video image. Whether it makes sense is determined by how
47 your particular camera is mounted.
48
49Work is ongoing with this driver, stay tuned.
50
51jon
52
53Jonathan Corbet
54corbet@lwn.net
diff --git a/Documentation/video4linux/zr36120.txt b/Documentation/video4linux/zr36120.txt
deleted file mode 100644
index 1a1c2d03a5c8..000000000000
--- a/Documentation/video4linux/zr36120.txt
+++ /dev/null
@@ -1,162 +0,0 @@
1Driver for Trust Computer Products Framegrabber, version 0.6.1
2------ --- ----- -------- -------- ------------ ------- - - -
3
4- ZORAN ------------------------------------------------------
5 Author: Pauline Middelink <middelin@polyware.nl>
6 Date: 18 September 1999
7Version: 0.6.1
8
9- Description ------------------------------------------------
10
11Video4Linux compatible driver for an unknown brand framegrabber
12(Sold in the Netherlands by TRUST Computer Products) and various
13other zoran zr36120 based framegrabbers.
14
15The card contains a ZR36120 Multimedia PCI Interface and a Philips
16SAA7110 Onechip Frontend videodecoder. There is also an DSP of
17which I have forgotten the number, since i will never get that thing
18to work without specs from the vendor itself.
19
20The SAA711x are capable of processing 6 different video inputs,
21CVBS1..6 and Y1+C1, Y2+C2, Y3+C3. All in 50/60Hz, NTSC, PAL or
22SECAM and delivering a YUV datastream. On my card the input
23'CVBS-0' corresponds to channel CVBS2 and 'S-Video' to Y2+C2.
24
25I have some reports of other cards working with the mentioned
26chip sets. For a list of other working cards please have a look
27at the cards named in the tvcards struct in the beginning of
28zr36120.c
29
30After some testing, I discovered that the carddesigner messed up
31on the I2C interface. The Zoran chip includes 2 lines SDA and SCL
32which (s)he connected reversely. So we have to clock on the SDA
33and r/w data on the SCL pin. Life is fun... Each cardtype now has
34a bit which signifies if you have a card with the same deficiency.
35
36Oh, for the completeness of this story I must mention that my
37card delivers the VSYNC pulse of the SAA chip to GIRQ1, not
38GIRQ0 as some other cards have. This is also incorporated in
39the driver be clearing/setting the 'useirq1' bit in the tvcard
40description.
41
42Another problems of continuous capturing data with a Zoran chip
43is something nasty inside the chip. It effectively halves the
44fps we ought to get... Here is the scenario: capturing frames
45to memory is done in the so-called snapshot mode. In this mode
46the Zoran stops after capturing a frame worth of data and wait
47till the application set GRAB bit to indicate readiness for the
48next frame. After detecting a set bit, the chip neatly waits
49till the start of a frame, captures it and it goes back to off.
50Smart ppl will notice the problem here. Its the waiting on the
51_next_ frame each time we set the GRAB bit... Oh well, 12,5 fps
52is still plenty fast for me.
53-- update 28/7/1999 --
54Don't believe a word I just said... Proof is the output
55of `streamer -t 300 -r 25 -f avi15 -o /dev/null`
56 ++--+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
57 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
58 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
59 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
60 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
61 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
62 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
63 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
64 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
65 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
66 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+- 25/25
67 +-s+-+-+-+-+-+-+-+-+-+-+-+-+-s+-+-+-+-+-+-+-+-+-+-+-
68 syncer: done
69 writer: done
70(note the /dev/null is prudent here, my system is not able to
71 grab /and/ write 25 fps to a file... gifts welcome :) )
72The technical reasoning follows: The zoran completed the last
73frame, the VSYNC goes low, and GRAB is cleared. The interrupt
74routine starts to work since its VSYNC driven, and again
75activates the GRAB bit. A few ms later the VSYNC (re-)rises and
76the zoran starts to work on a new and freshly broadcasted frame....
77
78For pointers I used the specs of both chips. Below are the URLs:
79 http://www.zoran.com/ftp/download/devices/pci/ZR36120/36120data.pdf
80 http://www-us.semiconductor.philips.com/acrobat/datasheets/SAA_7110_A_1.pdf
81Some alternatives for the Philips SAA 7110 datasheet are:
82 http://www.datasheetcatalog.com/datasheets_pdf/S/A/A/7/SAA7110.shtml
83 http://www.datasheetarchive.com/search.php?search=SAA7110&sType=part
84
85The documentation has very little on absolute numbers or timings
86needed for the various modes/resolutions, but there are other
87programs you can borrow those from.
88
89------ Install --------------------------------------------
90Read the file called TODO. Note its long list of limitations.
91
92Build a kernel with VIDEO4LINUX enabled. Activate the
93BT848 driver; we need this because we have need for the
94other modules (i2c and videodev) it enables.
95
96To install this software, extract it into a suitable directory.
97Examine the makefile and change anything you don't like. Type "make".
98
99After making the modules check if you have the much needed
100/dev/video devices. If not, execute the following 4 lines:
101 mknod /dev/video c 81 0
102 mknod /dev/video1 c 81 1
103 mknod /dev/video2 c 81 2
104 mknod /dev/video3 c 81 3
105 mknod /dev/video4 c 81 4
106
107After making/checking the devices do:
108 modprobe i2c
109 modprobe videodev
110 modprobe saa7110 (optional)
111 modprobe saa7111 (optional)
112 modprobe tuner (optional)
113 insmod zoran cardtype=<n>
114
115<n> is the cardtype of the card you have. The cardnumber can
116be found in the source of zr36120. Look for tvcards. If your
117card is not there, please try if any other card gives some
118response, and mail me if you got a working tvcard addition.
119
120PS. <TVCard editors behold!)
121 Don't forget to set video_input to the number of inputs
122 you defined in the video_mux part of the tvcard definition.
123 It's a common error to add a channel but not incrementing
124 video_input and getting angry with me/v4l/linux/linus :(
125
126You are now ready to test the framegrabber with your favorite
127video4linux compatible tool
128
129------ Application ----------------------------------------
130
131This device works with all Video4Linux compatible applications,
132given the limitations in the TODO file.
133
134------ API ------------------------------------------------
135
136This uses the V4L interface as of kernel release 2.1.116, and in
137fact has not been tested on any lower version. There are a couple
138of minor differences due to the fact that the amount of data returned
139with each frame varies, and no doubt there are discrepancies due to my
140misunderstanding of the API. I intend to convert this driver to the
141new V4L2 API when it has stabilized more.
142
143------ Current state --------------------------------------
144
145The driver is capable of overlaying a video image in screen, and
146even capable of grabbing frames. It uses the BIGPHYSAREA patch
147to allocate lots of large memory blocks when tis patch is
148found in the kernel, but it doesn't need it.
149The consequence is that, when loading the driver as a module,
150the module may tell you it's out of memory, but 'free' says
151otherwise. The reason is simple; the modules wants its memory
152contiguous, not fragmented, and after a long uptime there
153probably isn't a fragment of memory large enough...
154
155The driver uses a double buffering scheme, which should really
156be an n-way buffer, depending on the size of allocated framebuffer
157and the requested grab-size/format.
158This current version also fixes a dead-lock situation during irq
159time, which really, really froze my system... :)
160
161Good luck.
162 Pauline
diff --git a/MAINTAINERS b/MAINTAINERS
index 89ef018cc4bc..b2024938adcf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -684,7 +684,7 @@ S: Supported
684CIRRUS LOGIC GENERIC FBDEV DRIVER 684CIRRUS LOGIC GENERIC FBDEV DRIVER
685P: Jeff Garzik 685P: Jeff Garzik
686M: jgarzik@pobox.com 686M: jgarzik@pobox.com
687L: linux-fbdev-devel@lists.sourceforge.net 687L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
688S: Odd Fixes 688S: Odd Fixes
689 689
690CIRRUS LOGIC CS4280/CS461x SOUNDDRIVER 690CIRRUS LOGIC CS4280/CS461x SOUNDDRIVER
@@ -791,7 +791,7 @@ S: Maintained
791CYBLAFB FRAMEBUFFER DRIVER 791CYBLAFB FRAMEBUFFER DRIVER
792P: Knut Petersen 792P: Knut Petersen
793M: Knut_Petersen@t-online.de 793M: Knut_Petersen@t-online.de
794L: linux-fbdev-devel@lists.sourceforge.net 794L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
795S: Maintained 795S: Maintained
796 796
797CYCLADES 2X SYNC CARD DRIVER 797CYCLADES 2X SYNC CARD DRIVER
@@ -1128,7 +1128,7 @@ S: Supported
1128FRAMEBUFFER LAYER 1128FRAMEBUFFER LAYER
1129P: Antonino Daplas 1129P: Antonino Daplas
1130M: adaplas@pol.net 1130M: adaplas@pol.net
1131L: linux-fbdev-devel@lists.sourceforge.net 1131L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
1132W: http://linux-fbdev.sourceforge.net/ 1132W: http://linux-fbdev.sourceforge.net/
1133S: Maintained 1133S: Maintained
1134 1134
@@ -1479,7 +1479,7 @@ S: Maintained
1479IMS TWINTURBO FRAMEBUFFER DRIVER 1479IMS TWINTURBO FRAMEBUFFER DRIVER
1480P: Paul Mundt 1480P: Paul Mundt
1481M: lethal@chaoticdreams.org 1481M: lethal@chaoticdreams.org
1482L: linux-fbdev-devel@lists.sourceforge.net 1482L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
1483S: Maintained 1483S: Maintained
1484 1484
1485INFINIBAND SUBSYSTEM 1485INFINIBAND SUBSYSTEM
@@ -1512,13 +1512,13 @@ S: Maintained
1512INTEL FRAMEBUFFER DRIVER (excluding 810 and 815) 1512INTEL FRAMEBUFFER DRIVER (excluding 810 and 815)
1513P: Sylvain Meyer 1513P: Sylvain Meyer
1514M: sylvain.meyer@worldonline.fr 1514M: sylvain.meyer@worldonline.fr
1515L: linux-fbdev-devel@lists.sourceforge.net 1515L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
1516S: Maintained 1516S: Maintained
1517 1517
1518INTEL 810/815 FRAMEBUFFER DRIVER 1518INTEL 810/815 FRAMEBUFFER DRIVER
1519P: Antonino Daplas 1519P: Antonino Daplas
1520M: adaplas@pol.net 1520M: adaplas@pol.net
1521L: linux-fbdev-devel@lists.sourceforge.net 1521L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
1522S: Maintained 1522S: Maintained
1523 1523
1524INTEL APIC/IOAPIC, LOWLEVEL X86 SMP SUPPORT 1524INTEL APIC/IOAPIC, LOWLEVEL X86 SMP SUPPORT
@@ -1964,7 +1964,7 @@ S: Odd Fixes for 2.4; Maintained for 2.6.
1964MATROX FRAMEBUFFER DRIVER 1964MATROX FRAMEBUFFER DRIVER
1965P: Petr Vandrovec 1965P: Petr Vandrovec
1966M: vandrove@vc.cvut.cz 1966M: vandrove@vc.cvut.cz
1967L: linux-fbdev-devel@lists.sourceforge.net 1967L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
1968S: Maintained 1968S: Maintained
1969 1969
1970MEGARAID SCSI DRIVERS 1970MEGARAID SCSI DRIVERS
@@ -2025,6 +2025,12 @@ M: rubini@ipvvis.unipv.it
2025L: linux-kernel@vger.kernel.org 2025L: linux-kernel@vger.kernel.org
2026S: Maintained 2026S: Maintained
2027 2027
2028MOXA SMARTIO/INDUSTIO SERIAL CARD (MXSER 2.0)
2029P: Jiri Slaby
2030M: jirislaby@gmail.com
2031L: linux-kernel@vger.kernel.org
2032S: Maintained
2033
2028MSI LAPTOP SUPPORT 2034MSI LAPTOP SUPPORT
2029P: Lennart Poettering 2035P: Lennart Poettering
2030M: mzxreary@0pointer.de 2036M: mzxreary@0pointer.de
@@ -2050,6 +2056,12 @@ P: Andrew Veliath
2050M: andrewtv@usa.net 2056M: andrewtv@usa.net
2051S: Maintained 2057S: Maintained
2052 2058
2059MULTITECH MULTIPORT CARD (ISICOM)
2060P: Jiri Slaby
2061M: jirislaby@gmail.com
2062L: linux-kernel@vger.kernel.org
2063S: Maintained
2064
2053NATSEMI ETHERNET DRIVER (DP8381x) 2065NATSEMI ETHERNET DRIVER (DP8381x)
2054P: Tim Hockin 2066P: Tim Hockin
2055M: thockin@hockin.org 2067M: thockin@hockin.org
@@ -2210,7 +2222,7 @@ S: Maintained
2210NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER 2222NVIDIA (rivafb and nvidiafb) FRAMEBUFFER DRIVER
2211P: Antonino Daplas 2223P: Antonino Daplas
2212M: adaplas@pol.net 2224M: adaplas@pol.net
2213L: linux-fbdev-devel@lists.sourceforge.net 2225L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
2214S: Maintained 2226S: Maintained
2215 2227
2216OPENCORES I2C BUS DRIVER 2228OPENCORES I2C BUS DRIVER
@@ -2494,13 +2506,13 @@ S: Maintained
2494RADEON FRAMEBUFFER DISPLAY DRIVER 2506RADEON FRAMEBUFFER DISPLAY DRIVER
2495P: Benjamin Herrenschmidt 2507P: Benjamin Herrenschmidt
2496M: benh@kernel.crashing.org 2508M: benh@kernel.crashing.org
2497L: linux-fbdev-devel@lists.sourceforge.net 2509L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
2498S: Maintained 2510S: Maintained
2499 2511
2500RAGE128 FRAMEBUFFER DISPLAY DRIVER 2512RAGE128 FRAMEBUFFER DISPLAY DRIVER
2501P: Paul Mackerras 2513P: Paul Mackerras
2502M: paulus@samba.org 2514M: paulus@samba.org
2503L: linux-fbdev-devel@lists.sourceforge.net 2515L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
2504S: Maintained 2516S: Maintained
2505 2517
2506RAYLINK/WEBGEAR 802.11 WIRELESS LAN DRIVER 2518RAYLINK/WEBGEAR 802.11 WIRELESS LAN DRIVER
@@ -2542,7 +2554,7 @@ S: Maintained
2542REAL TIME CLOCK (RTC) SUBSYSTEM 2554REAL TIME CLOCK (RTC) SUBSYSTEM
2543P: Alessandro Zummo 2555P: Alessandro Zummo
2544M: a.zummo@towertech.it 2556M: a.zummo@towertech.it
2545L: linux-kernel@vger.kernel.org 2557L: rtc-linux@googlegroups.com
2546S: Maintained 2558S: Maintained
2547 2559
2548REISERFS FILE SYSTEM 2560REISERFS FILE SYSTEM
@@ -2570,7 +2582,7 @@ S: Orphan
2570S3 SAVAGE FRAMEBUFFER DRIVER 2582S3 SAVAGE FRAMEBUFFER DRIVER
2571P: Antonino Daplas 2583P: Antonino Daplas
2572M: adaplas@pol.net 2584M: adaplas@pol.net
2573L: linux-fbdev-devel@lists.sourceforge.net 2585L: linux-fbdev-devel@lists.sourceforge.net (subscribers-only)
2574S: Maintained 2586S: Maintained
2575 2587
2576S390 2588S390
diff --git a/Makefile b/Makefile
index aef96259051f..73e825b39a08 100644
--- a/Makefile
+++ b/Makefile
@@ -10,8 +10,11 @@ NAME=Avast! A bilge rat!
10# Comments in this file are targeted only to the developer, do not 10# Comments in this file are targeted only to the developer, do not
11# expect to learn how to build the kernel reading this file. 11# expect to learn how to build the kernel reading this file.
12 12
13# Do not print "Entering directory ..." 13# Do not:
14MAKEFLAGS += --no-print-directory 14# o use make's built-in rules and variables
15# (this increases performance and avoid hard-to-debug behavour);
16# o print "Entering directory ...";
17MAKEFLAGS += -rR --no-print-directory
15 18
16# We are using a recursive build, so we need to do a little thinking 19# We are using a recursive build, so we need to do a little thinking
17# to get the ordering right. 20# to get the ordering right.
@@ -271,12 +274,8 @@ export quiet Q KBUILD_VERBOSE
271# Look for make include files relative to root of kernel src 274# Look for make include files relative to root of kernel src
272MAKEFLAGS += --include-dir=$(srctree) 275MAKEFLAGS += --include-dir=$(srctree)
273 276
274# We need some generic definitions 277# We need some generic definitions.
275include $(srctree)/scripts/Kbuild.include 278include $(srctree)/scripts/Kbuild.include
276
277# Do not use make's built-in rules and variables
278# This increases performance and avoid hard-to-debug behavour
279MAKEFLAGS += -rR
280 279
281# Make variables (CC, etc...) 280# Make variables (CC, etc...)
282 281
@@ -1484,6 +1483,8 @@ endif # skip-makefile
1484PHONY += FORCE 1483PHONY += FORCE
1485FORCE: 1484FORCE:
1486 1485
1486# Cancel implicit rules on top Makefile, `-rR' will apply to sub-makes.
1487Makefile: ;
1487 1488
1488# Declare the contents of the .PHONY variable as phony. We keep that 1489# Declare the contents of the .PHONY variable as phony. We keep that
1489# information in a variable se we can use it in if_changed and friends. 1490# information in a variable se we can use it in if_changed and friends.
diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 7e55ea66c6d4..84caf50725b5 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -25,6 +25,14 @@ config RWSEM_XCHGADD_ALGORITHM
25 bool 25 bool
26 default y 26 default y
27 27
28config ARCH_HAS_ILOG2_U32
29 bool
30 default n
31
32config ARCH_HAS_ILOG2_U64
33 bool
34 default n
35
28config GENERIC_FIND_NEXT_BIT 36config GENERIC_FIND_NEXT_BIT
29 bool 37 bool
30 default y 38 default y
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index ad6173651995..be133f1f75a4 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -277,7 +277,7 @@ osf_fstatfs(unsigned long fd, struct osf_statfs __user *buffer, unsigned long bu
277 retval = -EBADF; 277 retval = -EBADF;
278 file = fget(fd); 278 file = fget(fd);
279 if (file) { 279 if (file) {
280 retval = do_osf_statfs(file->f_dentry, buffer, bufsiz); 280 retval = do_osf_statfs(file->f_path.dentry, buffer, bufsiz);
281 fput(file); 281 fput(file);
282 } 282 }
283 return retval; 283 return retval;
@@ -979,7 +979,7 @@ osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
979 long timeout; 979 long timeout;
980 int ret = -EINVAL; 980 int ret = -EINVAL;
981 struct fdtable *fdt; 981 struct fdtable *fdt;
982 int max_fdset; 982 int max_fds;
983 983
984 timeout = MAX_SCHEDULE_TIMEOUT; 984 timeout = MAX_SCHEDULE_TIMEOUT;
985 if (tvp) { 985 if (tvp) {
@@ -1003,9 +1003,9 @@ osf_select(int n, fd_set __user *inp, fd_set __user *outp, fd_set __user *exp,
1003 1003
1004 rcu_read_lock(); 1004 rcu_read_lock();
1005 fdt = files_fdtable(current->files); 1005 fdt = files_fdtable(current->files);
1006 max_fdset = fdt->max_fdset; 1006 max_fds = fdt->max_fds;
1007 rcu_read_unlock(); 1007 rcu_read_unlock();
1008 if (n < 0 || n > max_fdset) 1008 if (n < 0 || n > max_fds)
1009 goto out_nofds; 1009 goto out_nofds;
1010 1010
1011 /* 1011 /*
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 63e7c0c582df..6783c2e5512d 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -74,6 +74,14 @@ config RWSEM_GENERIC_SPINLOCK
74config RWSEM_XCHGADD_ALGORITHM 74config RWSEM_XCHGADD_ALGORITHM
75 bool 75 bool
76 76
77config ARCH_HAS_ILOG2_U32
78 bool
79 default n
80
81config ARCH_HAS_ILOG2_U64
82 bool
83 default n
84
77config GENERIC_HWEIGHT 85config GENERIC_HWEIGHT
78 bool 86 bool
79 default y 87 default y
diff --git a/arch/arm/mach-at91rm9200/at91sam9260_devices.c b/arch/arm/mach-at91rm9200/at91sam9260_devices.c
index a6c596dc4516..f42d3a40ec3c 100644
--- a/arch/arm/mach-at91rm9200/at91sam9260_devices.c
+++ b/arch/arm/mach-at91rm9200/at91sam9260_devices.c
@@ -18,6 +18,7 @@
18#include <asm/arch/gpio.h> 18#include <asm/arch/gpio.h>
19#include <asm/arch/at91sam9260.h> 19#include <asm/arch/at91sam9260.h>
20#include <asm/arch/at91sam926x_mc.h> 20#include <asm/arch/at91sam926x_mc.h>
21#include <asm/arch/at91sam9260_matrix.h>
21 22
22#include "generic.h" 23#include "generic.h"
23 24
diff --git a/arch/arm/mach-at91rm9200/board-sam9260ek.c b/arch/arm/mach-at91rm9200/board-sam9260ek.c
index ffca9bdec37b..da5d58ac870b 100644
--- a/arch/arm/mach-at91rm9200/board-sam9260ek.c
+++ b/arch/arm/mach-at91rm9200/board-sam9260ek.c
@@ -119,6 +119,7 @@ static struct spi_board_info ek_spi_devices[] = {
119 * MACB Ethernet device 119 * MACB Ethernet device
120 */ 120 */
121static struct __initdata eth_platform_data ek_macb_data = { 121static struct __initdata eth_platform_data ek_macb_data = {
122 .phy_irq_pin = AT91_PIN_PA7,
122 .is_rmii = 1, 123 .is_rmii = 1,
123}; 124};
124 125
diff --git a/arch/arm/mach-pnx4008/Makefile b/arch/arm/mach-pnx4008/Makefile
index b457ca0a431a..777564c90a12 100644
--- a/arch/arm/mach-pnx4008/Makefile
+++ b/arch/arm/mach-pnx4008/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4 4
5obj-y := core.o irq.o time.o clock.o gpio.o serial.o dma.o 5obj-y := core.o irq.o time.o clock.o gpio.o serial.o dma.o i2c.o
6obj-m := 6obj-m :=
7obj-n := 7obj-n :=
8obj- := 8obj- :=
diff --git a/arch/arm/mach-pnx4008/i2c.c b/arch/arm/mach-pnx4008/i2c.c
new file mode 100644
index 000000000000..6f308827c4fe
--- /dev/null
+++ b/arch/arm/mach-pnx4008/i2c.c
@@ -0,0 +1,167 @@
1/*
2 * I2C initialization for PNX4008.
3 *
4 * Author: Vitaly Wool <vitalywool@gmail.com>
5 *
6 * 2005-2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#include <linux/clk.h>
13#include <linux/i2c.h>
14#include <linux/i2c-pnx.h>
15#include <linux/platform_device.h>
16#include <linux/err.h>
17#include <asm/arch/platform.h>
18#include <asm/arch/i2c.h>
19
20static int set_clock_run(struct platform_device *pdev)
21{
22 struct clk *clk;
23 char name[10];
24 int retval = 0;
25
26 snprintf(name, 10, "i2c%d_ck", pdev->id);
27 clk = clk_get(&pdev->dev, name);
28 if (!IS_ERR(clk)) {
29 clk_set_rate(clk, 1);
30 clk_put(clk);
31 } else
32 retval = -ENOENT;
33
34 return retval;
35}
36
37static int set_clock_stop(struct platform_device *pdev)
38{
39 struct clk *clk;
40 char name[10];
41 int retval = 0;
42
43 snprintf(name, 10, "i2c%d_ck", pdev->id);
44 clk = clk_get(&pdev->dev, name);
45 if (!IS_ERR(clk)) {
46 clk_set_rate(clk, 0);
47 clk_put(clk);
48 } else
49 retval = -ENOENT;
50
51 return retval;
52}
53
54static int i2c_pnx_suspend(struct platform_device *pdev, pm_message_t state)
55{
56 int retval = 0;
57#ifdef CONFIG_PM
58 retval = set_clock_run(pdev);
59#endif
60 return retval;
61}
62
63static int i2c_pnx_resume(struct platform_device *pdev)
64{
65 int retval = 0;
66#ifdef CONFIG_PM
67 retval = set_clock_run(pdev);
68#endif
69 return retval;
70}
71
72static u32 calculate_input_freq(struct platform_device *pdev)
73{
74 return HCLK_MHZ;
75}
76
77
78static struct i2c_pnx_algo_data pnx_algo_data0 = {
79 .base = PNX4008_I2C1_BASE,
80 .irq = I2C_1_INT,
81};
82
83static struct i2c_pnx_algo_data pnx_algo_data1 = {
84 .base = PNX4008_I2C2_BASE,
85 .irq = I2C_2_INT,
86};
87
88static struct i2c_pnx_algo_data pnx_algo_data2 = {
89 .base = (PNX4008_USB_CONFIG_BASE + 0x300),
90 .irq = USB_I2C_INT,
91};
92
93static struct i2c_adapter pnx_adapter0 = {
94 .name = I2C_CHIP_NAME "0",
95 .algo_data = &pnx_algo_data0,
96};
97static struct i2c_adapter pnx_adapter1 = {
98 .name = I2C_CHIP_NAME "1",
99 .algo_data = &pnx_algo_data1,
100};
101
102static struct i2c_adapter pnx_adapter2 = {
103 .name = "USB-I2C",
104 .algo_data = &pnx_algo_data2,
105};
106
107static struct i2c_pnx_data i2c0_data = {
108 .suspend = i2c_pnx_suspend,
109 .resume = i2c_pnx_resume,
110 .calculate_input_freq = calculate_input_freq,
111 .set_clock_run = set_clock_run,
112 .set_clock_stop = set_clock_stop,
113 .adapter = &pnx_adapter0,
114};
115
116static struct i2c_pnx_data i2c1_data = {
117 .suspend = i2c_pnx_suspend,
118 .resume = i2c_pnx_resume,
119 .calculate_input_freq = calculate_input_freq,
120 .set_clock_run = set_clock_run,
121 .set_clock_stop = set_clock_stop,
122 .adapter = &pnx_adapter1,
123};
124
125static struct i2c_pnx_data i2c2_data = {
126 .suspend = i2c_pnx_suspend,
127 .resume = i2c_pnx_resume,
128 .calculate_input_freq = calculate_input_freq,
129 .set_clock_run = set_clock_run,
130 .set_clock_stop = set_clock_stop,
131 .adapter = &pnx_adapter2,
132};
133
134static struct platform_device i2c0_device = {
135 .name = "pnx-i2c",
136 .id = 0,
137 .dev = {
138 .platform_data = &i2c0_data,
139 },
140};
141
142static struct platform_device i2c1_device = {
143 .name = "pnx-i2c",
144 .id = 1,
145 .dev = {
146 .platform_data = &i2c1_data,
147 },
148};
149
150static struct platform_device i2c2_device = {
151 .name = "pnx-i2c",
152 .id = 2,
153 .dev = {
154 .platform_data = &i2c2_data,
155 },
156};
157
158static struct platform_device *devices[] __initdata = {
159 &i2c0_device,
160 &i2c1_device,
161 &i2c2_device,
162};
163
164void __init pnx4008_register_i2c_devices(void)
165{
166 platform_add_devices(devices, ARRAY_SIZE(devices));
167}
diff --git a/arch/arm/mach-realview/core.c b/arch/arm/mach-realview/core.c
index 68c67053f479..84d3fe76e94e 100644
--- a/arch/arm/mach-realview/core.c
+++ b/arch/arm/mach-realview/core.c
@@ -141,6 +141,19 @@ struct platform_device realview_smc91x_device = {
141 .resource = realview_smc91x_resources, 141 .resource = realview_smc91x_resources,
142}; 142};
143 143
144static struct resource realview_i2c_resource = {
145 .start = REALVIEW_I2C_BASE,
146 .end = REALVIEW_I2C_BASE + SZ_4K - 1,
147 .flags = IORESOURCE_MEM,
148};
149
150struct platform_device realview_i2c_device = {
151 .name = "versatile-i2c",
152 .id = -1,
153 .num_resources = 1,
154 .resource = &realview_i2c_resource,
155};
156
144#define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET) 157#define REALVIEW_SYSMCI (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_MCI_OFFSET)
145 158
146static unsigned int realview_mmc_status(struct device *dev) 159static unsigned int realview_mmc_status(struct device *dev)
diff --git a/arch/arm/mach-realview/core.h b/arch/arm/mach-realview/core.h
index 93e86d9f439c..2b53420f9c1b 100644
--- a/arch/arm/mach-realview/core.h
+++ b/arch/arm/mach-realview/core.h
@@ -108,6 +108,7 @@ static struct amba_device name##_device = { \
108 108
109extern struct platform_device realview_flash_device; 109extern struct platform_device realview_flash_device;
110extern struct platform_device realview_smc91x_device; 110extern struct platform_device realview_smc91x_device;
111extern struct platform_device realview_i2c_device;
111extern struct mmc_platform_data realview_mmc0_plat_data; 112extern struct mmc_platform_data realview_mmc0_plat_data;
112extern struct mmc_platform_data realview_mmc1_plat_data; 113extern struct mmc_platform_data realview_mmc1_plat_data;
113extern struct clk realview_clcd_clk; 114extern struct clk realview_clcd_clk;
diff --git a/arch/arm/mach-realview/realview_eb.c b/arch/arm/mach-realview/realview_eb.c
index 84a959530fb6..9741b4d3c9cf 100644
--- a/arch/arm/mach-realview/realview_eb.c
+++ b/arch/arm/mach-realview/realview_eb.c
@@ -155,6 +155,7 @@ static void __init realview_eb_init(void)
155 155
156 platform_device_register(&realview_flash_device); 156 platform_device_register(&realview_flash_device);
157 platform_device_register(&realview_smc91x_device); 157 platform_device_register(&realview_smc91x_device);
158 platform_device_register(&realview_i2c_device);
158 159
159 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { 160 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
160 struct amba_device *d = amba_devs[i]; 161 struct amba_device *d = amba_devs[i];
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index 57196947559f..bf71507c76fd 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -325,6 +325,19 @@ static struct platform_device smc91x_device = {
325 .resource = smc91x_resources, 325 .resource = smc91x_resources,
326}; 326};
327 327
328static struct resource versatile_i2c_resource = {
329 .start = VERSATILE_I2C_BASE,
330 .end = VERSATILE_I2C_BASE + SZ_4K - 1,
331 .flags = IORESOURCE_MEM,
332};
333
334static struct platform_device versatile_i2c_device = {
335 .name = "versatile-i2c",
336 .id = -1,
337 .num_resources = 1,
338 .resource = &versatile_i2c_resource,
339};
340
328#define VERSATILE_SYSMCI (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET) 341#define VERSATILE_SYSMCI (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_MCI_OFFSET)
329 342
330unsigned int mmc_status(struct device *dev) 343unsigned int mmc_status(struct device *dev)
@@ -775,6 +788,7 @@ void __init versatile_init(void)
775 clk_register(&versatile_clcd_clk); 788 clk_register(&versatile_clcd_clk);
776 789
777 platform_device_register(&versatile_flash_device); 790 platform_device_register(&versatile_flash_device);
791 platform_device_register(&versatile_i2c_device);
778 platform_device_register(&smc91x_device); 792 platform_device_register(&smc91x_device);
779 793
780 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) { 794 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
diff --git a/arch/arm26/Kconfig b/arch/arm26/Kconfig
index c14fe918bc4c..74eba8b5a8ca 100644
--- a/arch/arm26/Kconfig
+++ b/arch/arm26/Kconfig
@@ -41,6 +41,14 @@ config RWSEM_GENERIC_SPINLOCK
41config RWSEM_XCHGADD_ALGORITHM 41config RWSEM_XCHGADD_ALGORITHM
42 bool 42 bool
43 43
44config ARCH_HAS_ILOG2_U32
45 bool
46 default n
47
48config ARCH_HAS_ILOG2_U64
49 bool
50 default n
51
44config GENERIC_HWEIGHT 52config GENERIC_HWEIGHT
45 bool 53 bool
46 default y 54 default y
diff --git a/arch/avr32/Kconfig b/arch/avr32/Kconfig
index 5f1694eea842..bb059a4e1df9 100644
--- a/arch/avr32/Kconfig
+++ b/arch/avr32/Kconfig
@@ -45,6 +45,14 @@ config GENERIC_TIME
45config RWSEM_XCHGADD_ALGORITHM 45config RWSEM_XCHGADD_ALGORITHM
46 bool 46 bool
47 47
48config ARCH_HAS_ILOG2_U32
49 bool
50 default n
51
52config ARCH_HAS_ILOG2_U64
53 bool
54 default n
55
48config GENERIC_BUST_SPINLOCK 56config GENERIC_BUST_SPINLOCK
49 bool 57 bool
50 58
diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index cced73c58115..32b361f31c2c 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -7,20 +7,83 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/clk.h>
11#include <linux/etherdevice.h>
10#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/platform_device.h>
15#include <linux/string.h>
16#include <linux/types.h>
11 17
18#include <asm/io.h>
19#include <asm/setup.h>
12#include <asm/arch/board.h> 20#include <asm/arch/board.h>
13#include <asm/arch/init.h> 21#include <asm/arch/init.h>
14 22
15struct eth_platform_data __initdata eth0_data = { 23struct eth_addr {
16 .valid = 1, 24 u8 addr[6];
17 .mii_phy_addr = 0x10,
18 .is_rmii = 0,
19 .hw_addr = { 0x6a, 0x87, 0x71, 0x14, 0xcd, 0xcb },
20}; 25};
21 26
27static struct eth_addr __initdata hw_addr[2];
28
29static struct eth_platform_data __initdata eth_data[2];
22extern struct lcdc_platform_data atstk1000_fb0_data; 30extern struct lcdc_platform_data atstk1000_fb0_data;
23 31
32/*
33 * The next two functions should go away as the boot loader is
34 * supposed to initialize the macb address registers with a valid
35 * ethernet address. But we need to keep it around for a while until
36 * we can be reasonably sure the boot loader does this.
37 *
38 * The phy_id is ignored as the driver will probe for it.
39 */
40static int __init parse_tag_ethernet(struct tag *tag)
41{
42 int i;
43
44 i = tag->u.ethernet.mac_index;
45 if (i < ARRAY_SIZE(hw_addr))
46 memcpy(hw_addr[i].addr, tag->u.ethernet.hw_address,
47 sizeof(hw_addr[i].addr));
48
49 return 0;
50}
51__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
52
53static void __init set_hw_addr(struct platform_device *pdev)
54{
55 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
56 const u8 *addr;
57 void __iomem *regs;
58 struct clk *pclk;
59
60 if (!res)
61 return;
62 if (pdev->id >= ARRAY_SIZE(hw_addr))
63 return;
64
65 addr = hw_addr[pdev->id].addr;
66 if (!is_valid_ether_addr(addr))
67 return;
68
69 /*
70 * Since this is board-specific code, we'll cheat and use the
71 * physical address directly as we happen to know that it's
72 * the same as the virtual address.
73 */
74 regs = (void __iomem __force *)res->start;
75 pclk = clk_get(&pdev->dev, "pclk");
76 if (!pclk)
77 return;
78
79 clk_enable(pclk);
80 __raw_writel((addr[3] << 24) | (addr[2] << 16)
81 | (addr[1] << 8) | addr[0], regs + 0x98);
82 __raw_writel((addr[5] << 8) | addr[4], regs + 0x9c);
83 clk_disable(pclk);
84 clk_put(pclk);
85}
86
24void __init setup_board(void) 87void __init setup_board(void)
25{ 88{
26 at32_map_usart(1, 0); /* /dev/ttyS0 */ 89 at32_map_usart(1, 0); /* /dev/ttyS0 */
@@ -38,7 +101,8 @@ static int __init atstk1002_init(void)
38 at32_add_device_usart(1); 101 at32_add_device_usart(1);
39 at32_add_device_usart(2); 102 at32_add_device_usart(2);
40 103
41 at32_add_device_eth(0, &eth0_data); 104 set_hw_addr(at32_add_device_eth(0, &eth_data[0]));
105
42 at32_add_device_spi(0); 106 at32_add_device_spi(0);
43 at32_add_device_lcdc(0, &atstk1000_fb0_data); 107 at32_add_device_lcdc(0, &atstk1000_fb0_data);
44 108
diff --git a/arch/avr32/kernel/avr32_ksyms.c b/arch/avr32/kernel/avr32_ksyms.c
index 372e3f8b2417..7c4c76114bba 100644
--- a/arch/avr32/kernel/avr32_ksyms.c
+++ b/arch/avr32/kernel/avr32_ksyms.c
@@ -7,12 +7,12 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/delay.h>
10#include <linux/io.h> 11#include <linux/io.h>
11#include <linux/module.h> 12#include <linux/module.h>
12 13
13#include <asm/checksum.h> 14#include <asm/checksum.h>
14#include <asm/uaccess.h> 15#include <asm/uaccess.h>
15#include <asm/delay.h>
16 16
17/* 17/*
18 * GCC functions 18 * GCC functions
diff --git a/arch/avr32/kernel/process.c b/arch/avr32/kernel/process.c
index 317dc50945f2..0b4325946a41 100644
--- a/arch/avr32/kernel/process.c
+++ b/arch/avr32/kernel/process.c
@@ -38,6 +38,13 @@ void cpu_idle(void)
38 38
39void machine_halt(void) 39void machine_halt(void)
40{ 40{
41 /*
42 * Enter Stop mode. The 32 kHz oscillator will keep running so
43 * the RTC will keep the time properly and the system will
44 * boot quickly.
45 */
46 asm volatile("sleep 3\n\t"
47 "sub pc, -2");
41} 48}
42 49
43void machine_power_off(void) 50void machine_power_off(void)
diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
index ea2d1ffee478..a34211601008 100644
--- a/arch/avr32/kernel/setup.c
+++ b/arch/avr32/kernel/setup.c
@@ -229,30 +229,6 @@ static int __init parse_tag_rsvd_mem(struct tag *tag)
229} 229}
230__tagtable(ATAG_RSVD_MEM, parse_tag_rsvd_mem); 230__tagtable(ATAG_RSVD_MEM, parse_tag_rsvd_mem);
231 231
232static int __init parse_tag_ethernet(struct tag *tag)
233{
234#if 0
235 const struct platform_device *pdev;
236
237 /*
238 * We really need a bus type that supports "classes"...this
239 * will do for now (until we must handle other kinds of
240 * ethernet controllers)
241 */
242 pdev = platform_get_device("macb", tag->u.ethernet.mac_index);
243 if (pdev && pdev->dev.platform_data) {
244 struct eth_platform_data *data = pdev->dev.platform_data;
245
246 data->valid = 1;
247 data->mii_phy_addr = tag->u.ethernet.mii_phy_addr;
248 memcpy(data->hw_addr, tag->u.ethernet.hw_address,
249 sizeof(data->hw_addr));
250 }
251#endif
252 return 0;
253}
254__tagtable(ATAG_ETHERNET, parse_tag_ethernet);
255
256/* 232/*
257 * Scan the tag table for this tag, and call its parse function. The 233 * Scan the tag table for this tag, and call its parse function. The
258 * tag table is built by the linker from all the __tagtable 234 * tag table is built by the linker from all the __tagtable
diff --git a/arch/avr32/lib/delay.c b/arch/avr32/lib/delay.c
index 462c8307b680..b3bc0b56e2c6 100644
--- a/arch/avr32/lib/delay.c
+++ b/arch/avr32/lib/delay.c
@@ -12,9 +12,9 @@
12 12
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/param.h>
15#include <linux/types.h> 16#include <linux/types.h>
16 17
17#include <asm/delay.h>
18#include <asm/processor.h> 18#include <asm/processor.h>
19#include <asm/sysreg.h> 19#include <asm/sysreg.h>
20 20
diff --git a/arch/avr32/mach-at32ap/at32ap7000.c b/arch/avr32/mach-at32ap/at32ap7000.c
index 7ff6ad8bab5f..48f4ef38c70e 100644
--- a/arch/avr32/mach-at32ap/at32ap7000.c
+++ b/arch/avr32/mach-at32ap/at32ap7000.c
@@ -11,6 +11,7 @@
11 11
12#include <asm/io.h> 12#include <asm/io.h>
13 13
14#include <asm/arch/at32ap7000.h>
14#include <asm/arch/board.h> 15#include <asm/arch/board.h>
15#include <asm/arch/portmux.h> 16#include <asm/arch/portmux.h>
16#include <asm/arch/sm.h> 17#include <asm/arch/sm.h>
@@ -57,6 +58,9 @@ static struct platform_device _name##_id##_device = { \
57 .num_resources = ARRAY_SIZE(_name##_id##_resource), \ 58 .num_resources = ARRAY_SIZE(_name##_id##_resource), \
58} 59}
59 60
61#define select_peripheral(pin, periph, flags) \
62 at32_select_periph(GPIO_PIN_##pin, GPIO_##periph, flags)
63
60#define DEV_CLK(_name, devname, bus, _index) \ 64#define DEV_CLK(_name, devname, bus, _index) \
61static struct clk devname##_##_name = { \ 65static struct clk devname##_##_name = { \
62 .name = #_name, \ 66 .name = #_name, \
@@ -67,18 +71,6 @@ static struct clk devname##_##_name = { \
67 .index = _index, \ 71 .index = _index, \
68} 72}
69 73
70enum {
71 PIOA,
72 PIOB,
73 PIOC,
74 PIOD,
75};
76
77enum {
78 FUNC_A,
79 FUNC_B,
80};
81
82unsigned long at32ap7000_osc_rates[3] = { 74unsigned long at32ap7000_osc_rates[3] = {
83 [0] = 32768, 75 [0] = 32768,
84 /* FIXME: these are ATSTK1002-specific */ 76 /* FIXME: these are ATSTK1002-specific */
@@ -569,26 +561,26 @@ DEV_CLK(usart, atmel_usart3, pba, 6);
569 561
570static inline void configure_usart0_pins(void) 562static inline void configure_usart0_pins(void)
571{ 563{
572 portmux_set_func(PIOA, 8, FUNC_B); /* RXD */ 564 select_peripheral(PA(8), PERIPH_B, 0); /* RXD */
573 portmux_set_func(PIOA, 9, FUNC_B); /* TXD */ 565 select_peripheral(PA(9), PERIPH_B, 0); /* TXD */
574} 566}
575 567
576static inline void configure_usart1_pins(void) 568static inline void configure_usart1_pins(void)
577{ 569{
578 portmux_set_func(PIOA, 17, FUNC_A); /* RXD */ 570 select_peripheral(PA(17), PERIPH_A, 0); /* RXD */
579 portmux_set_func(PIOA, 18, FUNC_A); /* TXD */ 571 select_peripheral(PA(18), PERIPH_A, 0); /* TXD */
580} 572}
581 573
582static inline void configure_usart2_pins(void) 574static inline void configure_usart2_pins(void)
583{ 575{
584 portmux_set_func(PIOB, 26, FUNC_B); /* RXD */ 576 select_peripheral(PB(26), PERIPH_B, 0); /* RXD */
585 portmux_set_func(PIOB, 27, FUNC_B); /* TXD */ 577 select_peripheral(PB(27), PERIPH_B, 0); /* TXD */
586} 578}
587 579
588static inline void configure_usart3_pins(void) 580static inline void configure_usart3_pins(void)
589{ 581{
590 portmux_set_func(PIOB, 18, FUNC_B); /* RXD */ 582 select_peripheral(PB(18), PERIPH_B, 0); /* RXD */
591 portmux_set_func(PIOB, 17, FUNC_B); /* TXD */ 583 select_peripheral(PB(17), PERIPH_B, 0); /* TXD */
592} 584}
593 585
594static struct platform_device *at32_usarts[4]; 586static struct platform_device *at32_usarts[4];
@@ -654,6 +646,15 @@ DEFINE_DEV_DATA(macb, 0);
654DEV_CLK(hclk, macb0, hsb, 8); 646DEV_CLK(hclk, macb0, hsb, 8);
655DEV_CLK(pclk, macb0, pbb, 6); 647DEV_CLK(pclk, macb0, pbb, 6);
656 648
649static struct eth_platform_data macb1_data;
650static struct resource macb1_resource[] = {
651 PBMEM(0xfff01c00),
652 IRQ(26),
653};
654DEFINE_DEV_DATA(macb, 1);
655DEV_CLK(hclk, macb1, hsb, 9);
656DEV_CLK(pclk, macb1, pbb, 7);
657
657struct platform_device *__init 658struct platform_device *__init
658at32_add_device_eth(unsigned int id, struct eth_platform_data *data) 659at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
659{ 660{
@@ -663,27 +664,54 @@ at32_add_device_eth(unsigned int id, struct eth_platform_data *data)
663 case 0: 664 case 0:
664 pdev = &macb0_device; 665 pdev = &macb0_device;
665 666
666 portmux_set_func(PIOC, 3, FUNC_A); /* TXD0 */ 667 select_peripheral(PC(3), PERIPH_A, 0); /* TXD0 */
667 portmux_set_func(PIOC, 4, FUNC_A); /* TXD1 */ 668 select_peripheral(PC(4), PERIPH_A, 0); /* TXD1 */
668 portmux_set_func(PIOC, 7, FUNC_A); /* TXEN */ 669 select_peripheral(PC(7), PERIPH_A, 0); /* TXEN */
669 portmux_set_func(PIOC, 8, FUNC_A); /* TXCK */ 670 select_peripheral(PC(8), PERIPH_A, 0); /* TXCK */
670 portmux_set_func(PIOC, 9, FUNC_A); /* RXD0 */ 671 select_peripheral(PC(9), PERIPH_A, 0); /* RXD0 */
671 portmux_set_func(PIOC, 10, FUNC_A); /* RXD1 */ 672 select_peripheral(PC(10), PERIPH_A, 0); /* RXD1 */
672 portmux_set_func(PIOC, 13, FUNC_A); /* RXER */ 673 select_peripheral(PC(13), PERIPH_A, 0); /* RXER */
673 portmux_set_func(PIOC, 15, FUNC_A); /* RXDV */ 674 select_peripheral(PC(15), PERIPH_A, 0); /* RXDV */
674 portmux_set_func(PIOC, 16, FUNC_A); /* MDC */ 675 select_peripheral(PC(16), PERIPH_A, 0); /* MDC */
675 portmux_set_func(PIOC, 17, FUNC_A); /* MDIO */ 676 select_peripheral(PC(17), PERIPH_A, 0); /* MDIO */
677
678 if (!data->is_rmii) {
679 select_peripheral(PC(0), PERIPH_A, 0); /* COL */
680 select_peripheral(PC(1), PERIPH_A, 0); /* CRS */
681 select_peripheral(PC(2), PERIPH_A, 0); /* TXER */
682 select_peripheral(PC(5), PERIPH_A, 0); /* TXD2 */
683 select_peripheral(PC(6), PERIPH_A, 0); /* TXD3 */
684 select_peripheral(PC(11), PERIPH_A, 0); /* RXD2 */
685 select_peripheral(PC(12), PERIPH_A, 0); /* RXD3 */
686 select_peripheral(PC(14), PERIPH_A, 0); /* RXCK */
687 select_peripheral(PC(18), PERIPH_A, 0); /* SPD */
688 }
689 break;
690
691 case 1:
692 pdev = &macb1_device;
693
694 select_peripheral(PD(13), PERIPH_B, 0); /* TXD0 */
695 select_peripheral(PD(14), PERIPH_B, 0); /* TXD1 */
696 select_peripheral(PD(11), PERIPH_B, 0); /* TXEN */
697 select_peripheral(PD(12), PERIPH_B, 0); /* TXCK */
698 select_peripheral(PD(10), PERIPH_B, 0); /* RXD0 */
699 select_peripheral(PD(6), PERIPH_B, 0); /* RXD1 */
700 select_peripheral(PD(5), PERIPH_B, 0); /* RXER */
701 select_peripheral(PD(4), PERIPH_B, 0); /* RXDV */
702 select_peripheral(PD(3), PERIPH_B, 0); /* MDC */
703 select_peripheral(PD(2), PERIPH_B, 0); /* MDIO */
676 704
677 if (!data->is_rmii) { 705 if (!data->is_rmii) {
678 portmux_set_func(PIOC, 0, FUNC_A); /* COL */ 706 select_peripheral(PC(19), PERIPH_B, 0); /* COL */
679 portmux_set_func(PIOC, 1, FUNC_A); /* CRS */ 707 select_peripheral(PC(23), PERIPH_B, 0); /* CRS */
680 portmux_set_func(PIOC, 2, FUNC_A); /* TXER */ 708 select_peripheral(PC(26), PERIPH_B, 0); /* TXER */
681 portmux_set_func(PIOC, 5, FUNC_A); /* TXD2 */ 709 select_peripheral(PC(27), PERIPH_B, 0); /* TXD2 */
682 portmux_set_func(PIOC, 6, FUNC_A); /* TXD3 */ 710 select_peripheral(PC(28), PERIPH_B, 0); /* TXD3 */
683 portmux_set_func(PIOC, 11, FUNC_A); /* RXD2 */ 711 select_peripheral(PC(29), PERIPH_B, 0); /* RXD2 */
684 portmux_set_func(PIOC, 12, FUNC_A); /* RXD3 */ 712 select_peripheral(PC(30), PERIPH_B, 0); /* RXD3 */
685 portmux_set_func(PIOC, 14, FUNC_A); /* RXCK */ 713 select_peripheral(PC(24), PERIPH_B, 0); /* RXCK */
686 portmux_set_func(PIOC, 18, FUNC_A); /* SPD */ 714 select_peripheral(PD(15), PERIPH_B, 0); /* SPD */
687 } 715 }
688 break; 716 break;
689 717
@@ -714,12 +742,12 @@ struct platform_device *__init at32_add_device_spi(unsigned int id)
714 switch (id) { 742 switch (id) {
715 case 0: 743 case 0:
716 pdev = &spi0_device; 744 pdev = &spi0_device;
717 portmux_set_func(PIOA, 0, FUNC_A); /* MISO */ 745 select_peripheral(PA(0), PERIPH_A, 0); /* MISO */
718 portmux_set_func(PIOA, 1, FUNC_A); /* MOSI */ 746 select_peripheral(PA(1), PERIPH_A, 0); /* MOSI */
719 portmux_set_func(PIOA, 2, FUNC_A); /* SCK */ 747 select_peripheral(PA(2), PERIPH_A, 0); /* SCK */
720 portmux_set_func(PIOA, 3, FUNC_A); /* NPCS0 */ 748 select_peripheral(PA(3), PERIPH_A, 0); /* NPCS0 */
721 portmux_set_func(PIOA, 4, FUNC_A); /* NPCS1 */ 749 select_peripheral(PA(4), PERIPH_A, 0); /* NPCS1 */
722 portmux_set_func(PIOA, 5, FUNC_A); /* NPCS2 */ 750 select_peripheral(PA(5), PERIPH_A, 0); /* NPCS2 */
723 break; 751 break;
724 752
725 default: 753 default:
@@ -762,37 +790,37 @@ at32_add_device_lcdc(unsigned int id, struct lcdc_platform_data *data)
762 switch (id) { 790 switch (id) {
763 case 0: 791 case 0:
764 pdev = &lcdc0_device; 792 pdev = &lcdc0_device;
765 portmux_set_func(PIOC, 19, FUNC_A); /* CC */ 793 select_peripheral(PC(19), PERIPH_A, 0); /* CC */
766 portmux_set_func(PIOC, 20, FUNC_A); /* HSYNC */ 794 select_peripheral(PC(20), PERIPH_A, 0); /* HSYNC */
767 portmux_set_func(PIOC, 21, FUNC_A); /* PCLK */ 795 select_peripheral(PC(21), PERIPH_A, 0); /* PCLK */
768 portmux_set_func(PIOC, 22, FUNC_A); /* VSYNC */ 796 select_peripheral(PC(22), PERIPH_A, 0); /* VSYNC */
769 portmux_set_func(PIOC, 23, FUNC_A); /* DVAL */ 797 select_peripheral(PC(23), PERIPH_A, 0); /* DVAL */
770 portmux_set_func(PIOC, 24, FUNC_A); /* MODE */ 798 select_peripheral(PC(24), PERIPH_A, 0); /* MODE */
771 portmux_set_func(PIOC, 25, FUNC_A); /* PWR */ 799 select_peripheral(PC(25), PERIPH_A, 0); /* PWR */
772 portmux_set_func(PIOC, 26, FUNC_A); /* DATA0 */ 800 select_peripheral(PC(26), PERIPH_A, 0); /* DATA0 */
773 portmux_set_func(PIOC, 27, FUNC_A); /* DATA1 */ 801 select_peripheral(PC(27), PERIPH_A, 0); /* DATA1 */
774 portmux_set_func(PIOC, 28, FUNC_A); /* DATA2 */ 802 select_peripheral(PC(28), PERIPH_A, 0); /* DATA2 */
775 portmux_set_func(PIOC, 29, FUNC_A); /* DATA3 */ 803 select_peripheral(PC(29), PERIPH_A, 0); /* DATA3 */
776 portmux_set_func(PIOC, 30, FUNC_A); /* DATA4 */ 804 select_peripheral(PC(30), PERIPH_A, 0); /* DATA4 */
777 portmux_set_func(PIOC, 31, FUNC_A); /* DATA5 */ 805 select_peripheral(PC(31), PERIPH_A, 0); /* DATA5 */
778 portmux_set_func(PIOD, 0, FUNC_A); /* DATA6 */ 806 select_peripheral(PD(0), PERIPH_A, 0); /* DATA6 */
779 portmux_set_func(PIOD, 1, FUNC_A); /* DATA7 */ 807 select_peripheral(PD(1), PERIPH_A, 0); /* DATA7 */
780 portmux_set_func(PIOD, 2, FUNC_A); /* DATA8 */ 808 select_peripheral(PD(2), PERIPH_A, 0); /* DATA8 */
781 portmux_set_func(PIOD, 3, FUNC_A); /* DATA9 */ 809 select_peripheral(PD(3), PERIPH_A, 0); /* DATA9 */
782 portmux_set_func(PIOD, 4, FUNC_A); /* DATA10 */ 810 select_peripheral(PD(4), PERIPH_A, 0); /* DATA10 */
783 portmux_set_func(PIOD, 5, FUNC_A); /* DATA11 */ 811 select_peripheral(PD(5), PERIPH_A, 0); /* DATA11 */
784 portmux_set_func(PIOD, 6, FUNC_A); /* DATA12 */ 812 select_peripheral(PD(6), PERIPH_A, 0); /* DATA12 */
785 portmux_set_func(PIOD, 7, FUNC_A); /* DATA13 */ 813 select_peripheral(PD(7), PERIPH_A, 0); /* DATA13 */
786 portmux_set_func(PIOD, 8, FUNC_A); /* DATA14 */ 814 select_peripheral(PD(8), PERIPH_A, 0); /* DATA14 */
787 portmux_set_func(PIOD, 9, FUNC_A); /* DATA15 */ 815 select_peripheral(PD(9), PERIPH_A, 0); /* DATA15 */
788 portmux_set_func(PIOD, 10, FUNC_A); /* DATA16 */ 816 select_peripheral(PD(10), PERIPH_A, 0); /* DATA16 */
789 portmux_set_func(PIOD, 11, FUNC_A); /* DATA17 */ 817 select_peripheral(PD(11), PERIPH_A, 0); /* DATA17 */
790 portmux_set_func(PIOD, 12, FUNC_A); /* DATA18 */ 818 select_peripheral(PD(12), PERIPH_A, 0); /* DATA18 */
791 portmux_set_func(PIOD, 13, FUNC_A); /* DATA19 */ 819 select_peripheral(PD(13), PERIPH_A, 0); /* DATA19 */
792 portmux_set_func(PIOD, 14, FUNC_A); /* DATA20 */ 820 select_peripheral(PD(14), PERIPH_A, 0); /* DATA20 */
793 portmux_set_func(PIOD, 15, FUNC_A); /* DATA21 */ 821 select_peripheral(PD(15), PERIPH_A, 0); /* DATA21 */
794 portmux_set_func(PIOD, 16, FUNC_A); /* DATA22 */ 822 select_peripheral(PD(16), PERIPH_A, 0); /* DATA22 */
795 portmux_set_func(PIOD, 17, FUNC_A); /* DATA23 */ 823 select_peripheral(PD(17), PERIPH_A, 0); /* DATA23 */
796 824
797 clk_set_parent(&lcdc0_pixclk, &pll0); 825 clk_set_parent(&lcdc0_pixclk, &pll0);
798 clk_set_rate(&lcdc0_pixclk, clk_get_rate(&pll0)); 826 clk_set_rate(&lcdc0_pixclk, clk_get_rate(&pll0));
@@ -838,6 +866,8 @@ struct clk *at32_clock_list[] = {
838 &atmel_usart3_usart, 866 &atmel_usart3_usart,
839 &macb0_hclk, 867 &macb0_hclk,
840 &macb0_pclk, 868 &macb0_pclk,
869 &macb1_hclk,
870 &macb1_pclk,
841 &spi0_mck, 871 &spi0_mck,
842 &lcdc0_hclk, 872 &lcdc0_hclk,
843 &lcdc0_pixclk, 873 &lcdc0_pixclk,
diff --git a/arch/avr32/mach-at32ap/extint.c b/arch/avr32/mach-at32ap/extint.c
index 4dff1f988900..b59272e81b9a 100644
--- a/arch/avr32/mach-at32ap/extint.c
+++ b/arch/avr32/mach-at32ap/extint.c
@@ -49,12 +49,25 @@ static void eim_unmask_irq(unsigned int irq)
49static int eim_set_irq_type(unsigned int irq, unsigned int flow_type) 49static int eim_set_irq_type(unsigned int irq, unsigned int flow_type)
50{ 50{
51 struct at32_sm *sm = get_irq_chip_data(irq); 51 struct at32_sm *sm = get_irq_chip_data(irq);
52 struct irq_desc *desc;
52 unsigned int i = irq - sm->eim_first_irq; 53 unsigned int i = irq - sm->eim_first_irq;
53 u32 mode, edge, level; 54 u32 mode, edge, level;
54 unsigned long flags; 55 unsigned long flags;
55 int ret = 0; 56 int ret = 0;
56 57
57 flow_type &= IRQ_TYPE_SENSE_MASK; 58 if (flow_type == IRQ_TYPE_NONE)
59 flow_type = IRQ_TYPE_LEVEL_LOW;
60
61 desc = &irq_desc[irq];
62 desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL);
63 desc->status |= flow_type & IRQ_TYPE_SENSE_MASK;
64
65 if (flow_type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH)) {
66 desc->status |= IRQ_LEVEL;
67 set_irq_handler(irq, handle_level_irq);
68 } else {
69 set_irq_handler(irq, handle_edge_irq);
70 }
58 71
59 spin_lock_irqsave(&sm->lock, flags); 72 spin_lock_irqsave(&sm->lock, flags);
60 73
@@ -148,10 +161,15 @@ static int __init eim_init(void)
148 pattern = sm_readl(sm, EIM_MODE); 161 pattern = sm_readl(sm, EIM_MODE);
149 nr_irqs = fls(pattern); 162 nr_irqs = fls(pattern);
150 163
164 /* Trigger on falling edge unless overridden by driver */
165 sm_writel(sm, EIM_MODE, 0UL);
166 sm_writel(sm, EIM_EDGE, 0UL);
167
151 sm->eim_chip = &eim_chip; 168 sm->eim_chip = &eim_chip;
152 169
153 for (i = 0; i < nr_irqs; i++) { 170 for (i = 0; i < nr_irqs; i++) {
154 set_irq_chip(sm->eim_first_irq + i, &eim_chip); 171 set_irq_chip_and_handler(sm->eim_first_irq + i, &eim_chip,
172 handle_edge_irq);
155 set_irq_chip_data(sm->eim_first_irq + i, sm); 173 set_irq_chip_data(sm->eim_first_irq + i, sm);
156 } 174 }
157 175
diff --git a/arch/avr32/mach-at32ap/intc.c b/arch/avr32/mach-at32ap/intc.c
index eb87a18ad7b2..dd5c009cf224 100644
--- a/arch/avr32/mach-at32ap/intc.c
+++ b/arch/avr32/mach-at32ap/intc.c
@@ -136,3 +136,7 @@ fail:
136 panic("Interrupt controller initialization failed!\n"); 136 panic("Interrupt controller initialization failed!\n");
137} 137}
138 138
139unsigned long intc_get_pending(int group)
140{
141 return intc_readl(&intc0, INTREQ0 + 4 * group);
142}
diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
index d3aabfca8598..f1280ed8ed6d 100644
--- a/arch/avr32/mach-at32ap/pio.c
+++ b/arch/avr32/mach-at32ap/pio.c
@@ -25,27 +25,98 @@ struct pio_device {
25 void __iomem *regs; 25 void __iomem *regs;
26 const struct platform_device *pdev; 26 const struct platform_device *pdev;
27 struct clk *clk; 27 struct clk *clk;
28 u32 alloc_mask; 28 u32 pinmux_mask;
29 char name[32]; 29 char name[32];
30}; 30};
31 31
32static struct pio_device pio_dev[MAX_NR_PIO_DEVICES]; 32static struct pio_device pio_dev[MAX_NR_PIO_DEVICES];
33 33
34void portmux_set_func(unsigned int portmux_id, unsigned int pin_id, 34static struct pio_device *gpio_to_pio(unsigned int gpio)
35 unsigned int function_id)
36{ 35{
37 struct pio_device *pio; 36 struct pio_device *pio;
38 u32 mask = 1 << pin_id; 37 unsigned int index;
39 38
40 BUG_ON(portmux_id >= MAX_NR_PIO_DEVICES); 39 index = gpio >> 5;
40 if (index >= MAX_NR_PIO_DEVICES)
41 return NULL;
42 pio = &pio_dev[index];
43 if (!pio->regs)
44 return NULL;
41 45
42 pio = &pio_dev[portmux_id]; 46 return pio;
47}
48
49/* Pin multiplexing API */
50
51void __init at32_select_periph(unsigned int pin, unsigned int periph,
52 unsigned long flags)
53{
54 struct pio_device *pio;
55 unsigned int pin_index = pin & 0x1f;
56 u32 mask = 1 << pin_index;
57
58 pio = gpio_to_pio(pin);
59 if (unlikely(!pio)) {
60 printk("pio: invalid pin %u\n", pin);
61 goto fail;
62 }
43 63
44 if (function_id) 64 if (unlikely(test_and_set_bit(pin_index, &pio->pinmux_mask))) {
65 printk("%s: pin %u is busy\n", pio->name, pin_index);
66 goto fail;
67 }
68
69 pio_writel(pio, PUER, mask);
70 if (periph)
45 pio_writel(pio, BSR, mask); 71 pio_writel(pio, BSR, mask);
46 else 72 else
47 pio_writel(pio, ASR, mask); 73 pio_writel(pio, ASR, mask);
74
48 pio_writel(pio, PDR, mask); 75 pio_writel(pio, PDR, mask);
76 if (!(flags & AT32_GPIOF_PULLUP))
77 pio_writel(pio, PUDR, mask);
78
79 return;
80
81fail:
82 dump_stack();
83}
84
85void __init at32_select_gpio(unsigned int pin, unsigned long flags)
86{
87 struct pio_device *pio;
88 unsigned int pin_index = pin & 0x1f;
89 u32 mask = 1 << pin_index;
90
91 pio = gpio_to_pio(pin);
92 if (unlikely(!pio)) {
93 printk("pio: invalid pin %u\n", pin);
94 goto fail;
95 }
96
97 if (unlikely(test_and_set_bit(pin_index, &pio->pinmux_mask))) {
98 printk("%s: pin %u is busy\n", pio->name, pin_index);
99 goto fail;
100 }
101
102 pio_writel(pio, PUER, mask);
103 if (flags & AT32_GPIOF_HIGH)
104 pio_writel(pio, SODR, mask);
105 else
106 pio_writel(pio, CODR, mask);
107 if (flags & AT32_GPIOF_OUTPUT)
108 pio_writel(pio, OER, mask);
109 else
110 pio_writel(pio, ODR, mask);
111
112 pio_writel(pio, PER, mask);
113 if (!(flags & AT32_GPIOF_PULLUP))
114 pio_writel(pio, PUDR, mask);
115
116 return;
117
118fail:
119 dump_stack();
49} 120}
50 121
51static int __init pio_probe(struct platform_device *pdev) 122static int __init pio_probe(struct platform_device *pdev)
diff --git a/arch/avr32/mach-at32ap/sm.c b/arch/avr32/mach-at32ap/sm.c
deleted file mode 100644
index 03306eb0345e..000000000000
--- a/arch/avr32/mach-at32ap/sm.c
+++ /dev/null
@@ -1,289 +0,0 @@
1/*
2 * System Manager driver for AT32AP CPUs
3 *
4 * Copyright (C) 2006 Atmel Corporation
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/errno.h>
12#include <linux/init.h>
13#include <linux/interrupt.h>
14#include <linux/kernel.h>
15#include <linux/platform_device.h>
16#include <linux/random.h>
17#include <linux/spinlock.h>
18
19#include <asm/intc.h>
20#include <asm/io.h>
21#include <asm/irq.h>
22
23#include <asm/arch/sm.h>
24
25#include "sm.h"
26
27#define SM_EIM_IRQ_RESOURCE 1
28#define SM_PM_IRQ_RESOURCE 2
29#define SM_RTC_IRQ_RESOURCE 3
30
31#define to_eim(irqc) container_of(irqc, struct at32_sm, irqc)
32
33struct at32_sm system_manager;
34
35int __init at32_sm_init(void)
36{
37 struct resource *regs;
38 struct at32_sm *sm = &system_manager;
39 int ret = -ENXIO;
40
41 regs = platform_get_resource(&at32_sm_device, IORESOURCE_MEM, 0);
42 if (!regs)
43 goto fail;
44
45 spin_lock_init(&sm->lock);
46 sm->pdev = &at32_sm_device;
47
48 ret = -ENOMEM;
49 sm->regs = ioremap(regs->start, regs->end - regs->start + 1);
50 if (!sm->regs)
51 goto fail;
52
53 return 0;
54
55fail:
56 printk(KERN_ERR "Failed to initialize System Manager: %d\n", ret);
57 return ret;
58}
59
60/*
61 * External Interrupt Module (EIM).
62 *
63 * EIM gets level- or edge-triggered interrupts of either polarity
64 * from the outside and converts it to active-high level-triggered
65 * interrupts that the internal interrupt controller can handle. EIM
66 * also provides masking/unmasking of interrupts, as well as
67 * acknowledging of edge-triggered interrupts.
68 */
69
70static irqreturn_t spurious_eim_interrupt(int irq, void *dev_id,
71 struct pt_regs *regs)
72{
73 printk(KERN_WARNING "Spurious EIM interrupt %d\n", irq);
74 disable_irq(irq);
75 return IRQ_NONE;
76}
77
78static struct irqaction eim_spurious_action = {
79 .handler = spurious_eim_interrupt,
80};
81
82static irqreturn_t eim_handle_irq(int irq, void *dev_id, struct pt_regs *regs)
83{
84 struct irq_controller * irqc = dev_id;
85 struct at32_sm *sm = to_eim(irqc);
86 unsigned long pending;
87
88 /*
89 * No need to disable interrupts globally. The interrupt
90 * level relevant to this group must be masked all the time,
91 * so we know that this particular EIM instance will not be
92 * re-entered.
93 */
94 spin_lock(&sm->lock);
95
96 pending = intc_get_pending(sm->irqc.irq_group);
97 if (unlikely(!pending)) {
98 printk(KERN_ERR "EIM (group %u): No interrupts pending!\n",
99 sm->irqc.irq_group);
100 goto unlock;
101 }
102
103 do {
104 struct irqaction *action;
105 unsigned int i;
106
107 i = fls(pending) - 1;
108 pending &= ~(1 << i);
109 action = sm->action[i];
110
111 /* Acknowledge the interrupt */
112 sm_writel(sm, EIM_ICR, 1 << i);
113
114 spin_unlock(&sm->lock);
115
116 if (action->flags & SA_INTERRUPT)
117 local_irq_disable();
118 action->handler(sm->irqc.first_irq + i, action->dev_id, regs);
119 local_irq_enable();
120 spin_lock(&sm->lock);
121 if (action->flags & SA_SAMPLE_RANDOM)
122 add_interrupt_randomness(sm->irqc.first_irq + i);
123 } while (pending);
124
125unlock:
126 spin_unlock(&sm->lock);
127 return IRQ_HANDLED;
128}
129
130static void eim_mask(struct irq_controller *irqc, unsigned int irq)
131{
132 struct at32_sm *sm = to_eim(irqc);
133 unsigned int i;
134
135 i = irq - sm->irqc.first_irq;
136 sm_writel(sm, EIM_IDR, 1 << i);
137}
138
139static void eim_unmask(struct irq_controller *irqc, unsigned int irq)
140{
141 struct at32_sm *sm = to_eim(irqc);
142 unsigned int i;
143
144 i = irq - sm->irqc.first_irq;
145 sm_writel(sm, EIM_IER, 1 << i);
146}
147
148static int eim_setup(struct irq_controller *irqc, unsigned int irq,
149 struct irqaction *action)
150{
151 struct at32_sm *sm = to_eim(irqc);
152 sm->action[irq - sm->irqc.first_irq] = action;
153 /* Acknowledge earlier interrupts */
154 sm_writel(sm, EIM_ICR, (1<<(irq - sm->irqc.first_irq)));
155 eim_unmask(irqc, irq);
156 return 0;
157}
158
159static void eim_free(struct irq_controller *irqc, unsigned int irq,
160 void *dev)
161{
162 struct at32_sm *sm = to_eim(irqc);
163 eim_mask(irqc, irq);
164 sm->action[irq - sm->irqc.first_irq] = &eim_spurious_action;
165}
166
167static int eim_set_type(struct irq_controller *irqc, unsigned int irq,
168 unsigned int type)
169{
170 struct at32_sm *sm = to_eim(irqc);
171 unsigned long flags;
172 u32 value, pattern;
173
174 spin_lock_irqsave(&sm->lock, flags);
175
176 pattern = 1 << (irq - sm->irqc.first_irq);
177
178 value = sm_readl(sm, EIM_MODE);
179 if (type & IRQ_TYPE_LEVEL)
180 value |= pattern;
181 else
182 value &= ~pattern;
183 sm_writel(sm, EIM_MODE, value);
184 value = sm_readl(sm, EIM_EDGE);
185 if (type & IRQ_EDGE_RISING)
186 value |= pattern;
187 else
188 value &= ~pattern;
189 sm_writel(sm, EIM_EDGE, value);
190 value = sm_readl(sm, EIM_LEVEL);
191 if (type & IRQ_LEVEL_HIGH)
192 value |= pattern;
193 else
194 value &= ~pattern;
195 sm_writel(sm, EIM_LEVEL, value);
196
197 spin_unlock_irqrestore(&sm->lock, flags);
198
199 return 0;
200}
201
202static unsigned int eim_get_type(struct irq_controller *irqc,
203 unsigned int irq)
204{
205 struct at32_sm *sm = to_eim(irqc);
206 unsigned long flags;
207 unsigned int type = 0;
208 u32 mode, edge, level, pattern;
209
210 pattern = 1 << (irq - sm->irqc.first_irq);
211
212 spin_lock_irqsave(&sm->lock, flags);
213 mode = sm_readl(sm, EIM_MODE);
214 edge = sm_readl(sm, EIM_EDGE);
215 level = sm_readl(sm, EIM_LEVEL);
216 spin_unlock_irqrestore(&sm->lock, flags);
217
218 if (mode & pattern)
219 type |= IRQ_TYPE_LEVEL;
220 if (edge & pattern)
221 type |= IRQ_EDGE_RISING;
222 if (level & pattern)
223 type |= IRQ_LEVEL_HIGH;
224
225 return type;
226}
227
228static struct irq_controller_class eim_irq_class = {
229 .typename = "EIM",
230 .handle = eim_handle_irq,
231 .setup = eim_setup,
232 .free = eim_free,
233 .mask = eim_mask,
234 .unmask = eim_unmask,
235 .set_type = eim_set_type,
236 .get_type = eim_get_type,
237};
238
239static int __init eim_init(void)
240{
241 struct at32_sm *sm = &system_manager;
242 unsigned int i;
243 u32 pattern;
244 int ret;
245
246 /*
247 * The EIM is really the same module as SM, so register
248 * mapping, etc. has been taken care of already.
249 */
250
251 /*
252 * Find out how many interrupt lines that are actually
253 * implemented in hardware.
254 */
255 sm_writel(sm, EIM_IDR, ~0UL);
256 sm_writel(sm, EIM_MODE, ~0UL);
257 pattern = sm_readl(sm, EIM_MODE);
258 sm->irqc.nr_irqs = fls(pattern);
259
260 ret = -ENOMEM;
261 sm->action = kmalloc(sizeof(*sm->action) * sm->irqc.nr_irqs,
262 GFP_KERNEL);
263 if (!sm->action)
264 goto out;
265
266 for (i = 0; i < sm->irqc.nr_irqs; i++)
267 sm->action[i] = &eim_spurious_action;
268
269 spin_lock_init(&sm->lock);
270 sm->irqc.irq_group = sm->pdev->resource[SM_EIM_IRQ_RESOURCE].start;
271 sm->irqc.class = &eim_irq_class;
272
273 ret = intc_register_controller(&sm->irqc);
274 if (ret < 0)
275 goto out_free_actions;
276
277 printk("EIM: External Interrupt Module at 0x%p, IRQ group %u\n",
278 sm->regs, sm->irqc.irq_group);
279 printk("EIM: Handling %u external IRQs, starting with IRQ%u\n",
280 sm->irqc.nr_irqs, sm->irqc.first_irq);
281
282 return 0;
283
284out_free_actions:
285 kfree(sm->action);
286out:
287 return ret;
288}
289arch_initcall(eim_init);
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index 6a1238a29d6c..3474309e049c 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -16,6 +16,14 @@ config RWSEM_GENERIC_SPINLOCK
16config RWSEM_XCHGADD_ALGORITHM 16config RWSEM_XCHGADD_ALGORITHM
17 bool 17 bool
18 18
19config ARCH_HAS_ILOG2_U32
20 bool
21 default n
22
23config ARCH_HAS_ILOG2_U64
24 bool
25 default n
26
19config GENERIC_FIND_NEXT_BIT 27config GENERIC_FIND_NEXT_BIT
20 bool 28 bool
21 default y 29 default y
diff --git a/arch/cris/arch-v32/drivers/sync_serial.c b/arch/cris/arch-v32/drivers/sync_serial.c
index e067806b2208..424eb0eb1cd5 100644
--- a/arch/cris/arch-v32/drivers/sync_serial.c
+++ b/arch/cris/arch-v32/drivers/sync_serial.c
@@ -504,7 +504,7 @@ static int sync_serial_release(struct inode *inode, struct file *file)
504 504
505static unsigned int sync_serial_poll(struct file *file, poll_table *wait) 505static unsigned int sync_serial_poll(struct file *file, poll_table *wait)
506{ 506{
507 int dev = iminor(file->f_dentry->d_inode); 507 int dev = iminor(file->f_path.dentry->d_inode);
508 unsigned int mask = 0; 508 unsigned int mask = 0;
509 sync_port* port; 509 sync_port* port;
510 DEBUGPOLL( static unsigned int prev_mask = 0; ); 510 DEBUGPOLL( static unsigned int prev_mask = 0; );
@@ -531,7 +531,7 @@ static int sync_serial_ioctl(struct inode *inode, struct file *file,
531 unsigned int cmd, unsigned long arg) 531 unsigned int cmd, unsigned long arg)
532{ 532{
533 int return_val = 0; 533 int return_val = 0;
534 int dev = iminor(file->f_dentry->d_inode); 534 int dev = iminor(file->f_path.dentry->d_inode);
535 sync_port* port; 535 sync_port* port;
536 reg_sser_rw_tr_cfg tr_cfg; 536 reg_sser_rw_tr_cfg tr_cfg;
537 reg_sser_rw_rec_cfg rec_cfg; 537 reg_sser_rw_rec_cfg rec_cfg;
@@ -789,7 +789,7 @@ static int sync_serial_ioctl(struct inode *inode, struct file *file,
789static ssize_t sync_serial_write(struct file * file, const char * buf, 789static ssize_t sync_serial_write(struct file * file, const char * buf,
790 size_t count, loff_t *ppos) 790 size_t count, loff_t *ppos)
791{ 791{
792 int dev = iminor(file->f_dentry->d_inode); 792 int dev = iminor(file->f_path.dentry->d_inode);
793 DECLARE_WAITQUEUE(wait, current); 793 DECLARE_WAITQUEUE(wait, current);
794 sync_port *port; 794 sync_port *port;
795 unsigned long c, c1; 795 unsigned long c, c1;
@@ -919,7 +919,7 @@ static ssize_t sync_serial_write(struct file * file, const char * buf,
919static ssize_t sync_serial_read(struct file * file, char * buf, 919static ssize_t sync_serial_read(struct file * file, char * buf,
920 size_t count, loff_t *ppos) 920 size_t count, loff_t *ppos)
921{ 921{
922 int dev = iminor(file->f_dentry->d_inode); 922 int dev = iminor(file->f_path.dentry->d_inode);
923 int avail; 923 int avail;
924 sync_port *port; 924 sync_port *port;
925 unsigned char* start; 925 unsigned char* start;
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index cf1c446e003a..7561d7b72e75 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -41,6 +41,14 @@ config TIME_LOW_RES
41 bool 41 bool
42 default y 42 default y
43 43
44config ARCH_HAS_ILOG2_U32
45 bool
46 default y
47
48config ARCH_HAS_ILOG2_U64
49 bool
50 default y
51
44mainmenu "Fujitsu FR-V Kernel Configuration" 52mainmenu "Fujitsu FR-V Kernel Configuration"
45 53
46source "init/Kconfig" 54source "init/Kconfig"
diff --git a/arch/frv/kernel/pm.c b/arch/frv/kernel/pm.c
index c1d9fc8f1a85..ee677ced7b68 100644
--- a/arch/frv/kernel/pm.c
+++ b/arch/frv/kernel/pm.c
@@ -223,7 +223,7 @@ static int cmode_procctl(ctl_table *ctl, int write, struct file *filp,
223 223
224static int cmode_sysctl(ctl_table *table, int __user *name, int nlen, 224static int cmode_sysctl(ctl_table *table, int __user *name, int nlen,
225 void __user *oldval, size_t __user *oldlenp, 225 void __user *oldval, size_t __user *oldlenp,
226 void __user *newval, size_t newlen, void **context) 226 void __user *newval, size_t newlen)
227{ 227{
228 if (oldval && oldlenp) { 228 if (oldval && oldlenp) {
229 size_t oldlen; 229 size_t oldlen;
@@ -326,7 +326,7 @@ static int p0_procctl(ctl_table *ctl, int write, struct file *filp,
326 326
327static int p0_sysctl(ctl_table *table, int __user *name, int nlen, 327static int p0_sysctl(ctl_table *table, int __user *name, int nlen,
328 void __user *oldval, size_t __user *oldlenp, 328 void __user *oldval, size_t __user *oldlenp,
329 void __user *newval, size_t newlen, void **context) 329 void __user *newval, size_t newlen)
330{ 330{
331 if (oldval && oldlenp) { 331 if (oldval && oldlenp) {
332 size_t oldlen; 332 size_t oldlen;
@@ -370,7 +370,7 @@ static int cm_procctl(ctl_table *ctl, int write, struct file *filp,
370 370
371static int cm_sysctl(ctl_table *table, int __user *name, int nlen, 371static int cm_sysctl(ctl_table *table, int __user *name, int nlen,
372 void __user *oldval, size_t __user *oldlenp, 372 void __user *oldval, size_t __user *oldlenp,
373 void __user *newval, size_t newlen, void **context) 373 void __user *newval, size_t newlen)
374{ 374{
375 if (oldval && oldlenp) { 375 if (oldval && oldlenp) {
376 size_t oldlen; 376 size_t oldlen;
diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
index f5a653033fe0..9477ccce070e 100644
--- a/arch/frv/mm/elf-fdpic.c
+++ b/arch/frv/mm/elf-fdpic.c
@@ -110,14 +110,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
110 110
111#if 0 111#if 0
112 printk("[area] l=%lx (ENOMEM) f='%s'\n", 112 printk("[area] l=%lx (ENOMEM) f='%s'\n",
113 len, filp ? filp->f_dentry->d_name.name : ""); 113 len, filp ? filp->f_path.dentry->d_name.name : "");
114#endif 114#endif
115 return -ENOMEM; 115 return -ENOMEM;
116 116
117 success: 117 success:
118#if 0 118#if 0
119 printk("[area] l=%lx ad=%lx f='%s'\n", 119 printk("[area] l=%lx ad=%lx f='%s'\n",
120 len, addr, filp ? filp->f_dentry->d_name.name : ""); 120 len, addr, filp ? filp->f_path.dentry->d_name.name : "");
121#endif 121#endif
122 return addr; 122 return addr;
123} /* end arch_get_unmapped_area() */ 123} /* end arch_get_unmapped_area() */
diff --git a/arch/h8300/Kconfig b/arch/h8300/Kconfig
index cabf0bfffc53..34a84bc4baf5 100644
--- a/arch/h8300/Kconfig
+++ b/arch/h8300/Kconfig
@@ -29,6 +29,14 @@ config RWSEM_XCHGADD_ALGORITHM
29 bool 29 bool
30 default n 30 default n
31 31
32config ARCH_HAS_ILOG2_U32
33 bool
34 default n
35
36config ARCH_HAS_ILOG2_U64
37 bool
38 default n
39
32config GENERIC_FIND_NEXT_BIT 40config GENERIC_FIND_NEXT_BIT
33 bool 41 bool
34 default y 42 default y
diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig
index ea70359b02d0..0d67a0a1151e 100644
--- a/arch/i386/Kconfig
+++ b/arch/i386/Kconfig
@@ -49,6 +49,11 @@ config GENERIC_IOMAP
49 bool 49 bool
50 default y 50 default y
51 51
52config GENERIC_BUG
53 bool
54 default y
55 depends on BUG
56
52config GENERIC_HWEIGHT 57config GENERIC_HWEIGHT
53 bool 58 bool
54 default y 59 default y
@@ -185,6 +190,7 @@ endchoice
185config PARAVIRT 190config PARAVIRT
186 bool "Paravirtualization support (EXPERIMENTAL)" 191 bool "Paravirtualization support (EXPERIMENTAL)"
187 depends on EXPERIMENTAL 192 depends on EXPERIMENTAL
193 depends on !(X86_VISWS || X86_VOYAGER)
188 help 194 help
189 Paravirtualization is a way of running multiple instances of 195 Paravirtualization is a way of running multiple instances of
190 Linux on the same machine, under a hypervisor. This option 196 Linux on the same machine, under a hypervisor. This option
diff --git a/arch/i386/Kconfig.cpu b/arch/i386/Kconfig.cpu
index 821fd269ca58..2aecfba4ac4f 100644
--- a/arch/i386/Kconfig.cpu
+++ b/arch/i386/Kconfig.cpu
@@ -248,6 +248,14 @@ config RWSEM_XCHGADD_ALGORITHM
248 depends on !M386 248 depends on !M386
249 default y 249 default y
250 250
251config ARCH_HAS_ILOG2_U32
252 bool
253 default n
254
255config ARCH_HAS_ILOG2_U64
256 bool
257 default n
258
251config GENERIC_CALIBRATE_DELAY 259config GENERIC_CALIBRATE_DELAY
252 bool 260 bool
253 default y 261 default y
diff --git a/arch/i386/defconfig b/arch/i386/defconfig
index 65891f11aced..3265208e5899 100644
--- a/arch/i386/defconfig
+++ b/arch/i386/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19-git7 3# Linux kernel version: 2.6.19-git14
4# Wed Dec 6 23:50:49 2006 4# Sat Dec 9 21:23:14 2006
5# 5#
6CONFIG_X86_32=y 6CONFIG_X86_32=y
7CONFIG_GENERIC_TIME=y 7CONFIG_GENERIC_TIME=y
@@ -12,6 +12,7 @@ CONFIG_X86=y
12CONFIG_MMU=y 12CONFIG_MMU=y
13CONFIG_GENERIC_ISA_DMA=y 13CONFIG_GENERIC_ISA_DMA=y
14CONFIG_GENERIC_IOMAP=y 14CONFIG_GENERIC_IOMAP=y
15CONFIG_GENERIC_BUG=y
15CONFIG_GENERIC_HWEIGHT=y 16CONFIG_GENERIC_HWEIGHT=y
16CONFIG_ARCH_MAY_HAVE_PC_FDC=y 17CONFIG_ARCH_MAY_HAVE_PC_FDC=y
17CONFIG_DMI=y 18CONFIG_DMI=y
@@ -141,6 +142,8 @@ CONFIG_X86_CMPXCHG=y
141CONFIG_X86_XADD=y 142CONFIG_X86_XADD=y
142CONFIG_X86_L1_CACHE_SHIFT=7 143CONFIG_X86_L1_CACHE_SHIFT=7
143CONFIG_RWSEM_XCHGADD_ALGORITHM=y 144CONFIG_RWSEM_XCHGADD_ALGORITHM=y
145# CONFIG_ARCH_HAS_ILOG2_U32 is not set
146# CONFIG_ARCH_HAS_ILOG2_U64 is not set
144CONFIG_GENERIC_CALIBRATE_DELAY=y 147CONFIG_GENERIC_CALIBRATE_DELAY=y
145CONFIG_X86_WP_WORKS_OK=y 148CONFIG_X86_WP_WORKS_OK=y
146CONFIG_X86_INVLPG=y 149CONFIG_X86_INVLPG=y
@@ -203,6 +206,7 @@ CONFIG_MTRR=y
203CONFIG_SECCOMP=y 206CONFIG_SECCOMP=y
204# CONFIG_HZ_100 is not set 207# CONFIG_HZ_100 is not set
205CONFIG_HZ_250=y 208CONFIG_HZ_250=y
209# CONFIG_HZ_300 is not set
206# CONFIG_HZ_1000 is not set 210# CONFIG_HZ_1000 is not set
207CONFIG_HZ=250 211CONFIG_HZ=250
208# CONFIG_KEXEC is not set 212# CONFIG_KEXEC is not set
@@ -563,6 +567,7 @@ CONFIG_IDEDMA_AUTO=y
563# 567#
564# CONFIG_RAID_ATTRS is not set 568# CONFIG_RAID_ATTRS is not set
565CONFIG_SCSI=y 569CONFIG_SCSI=y
570# CONFIG_SCSI_TGT is not set
566CONFIG_SCSI_NETLINK=y 571CONFIG_SCSI_NETLINK=y
567# CONFIG_SCSI_PROC_FS is not set 572# CONFIG_SCSI_PROC_FS is not set
568 573
@@ -583,6 +588,7 @@ CONFIG_CHR_DEV_SG=y
583# CONFIG_SCSI_MULTI_LUN is not set 588# CONFIG_SCSI_MULTI_LUN is not set
584# CONFIG_SCSI_CONSTANTS is not set 589# CONFIG_SCSI_CONSTANTS is not set
585# CONFIG_SCSI_LOGGING is not set 590# CONFIG_SCSI_LOGGING is not set
591# CONFIG_SCSI_SCAN_ASYNC is not set
586 592
587# 593#
588# SCSI Transports 594# SCSI Transports
@@ -642,6 +648,7 @@ CONFIG_AIC79XX_DEBUG_MASK=0
642# CONFIG_SCSI_DC390T is not set 648# CONFIG_SCSI_DC390T is not set
643# CONFIG_SCSI_NSP32 is not set 649# CONFIG_SCSI_NSP32 is not set
644# CONFIG_SCSI_DEBUG is not set 650# CONFIG_SCSI_DEBUG is not set
651# CONFIG_SCSI_SRP is not set
645 652
646# 653#
647# Serial ATA (prod) and Parallel ATA (experimental) drivers 654# Serial ATA (prod) and Parallel ATA (experimental) drivers
@@ -1082,10 +1089,7 @@ CONFIG_SOUND=y
1082# Open Sound System 1089# Open Sound System
1083# 1090#
1084CONFIG_SOUND_PRIME=y 1091CONFIG_SOUND_PRIME=y
1085CONFIG_OSS_OBSOLETE_DRIVER=y
1086# CONFIG_SOUND_BT878 is not set 1092# CONFIG_SOUND_BT878 is not set
1087# CONFIG_SOUND_EMU10K1 is not set
1088# CONFIG_SOUND_FUSION is not set
1089# CONFIG_SOUND_ES1371 is not set 1093# CONFIG_SOUND_ES1371 is not set
1090CONFIG_SOUND_ICH=y 1094CONFIG_SOUND_ICH=y
1091# CONFIG_SOUND_TRIDENT is not set 1095# CONFIG_SOUND_TRIDENT is not set
@@ -1095,6 +1099,11 @@ CONFIG_SOUND_ICH=y
1095# CONFIG_SOUND_OSS is not set 1099# CONFIG_SOUND_OSS is not set
1096 1100
1097# 1101#
1102# HID Devices
1103#
1104CONFIG_HID=y
1105
1106#
1098# USB support 1107# USB support
1099# 1108#
1100CONFIG_USB_ARCH_HAS_HCD=y 1109CONFIG_USB_ARCH_HAS_HCD=y
@@ -1158,8 +1167,7 @@ CONFIG_USB_STORAGE=y
1158# USB Input Devices 1167# USB Input Devices
1159# 1168#
1160CONFIG_USB_HID=y 1169CONFIG_USB_HID=y
1161CONFIG_USB_HIDINPUT=y 1170# CONFIG_USB_HID_POWERBOOK is not set
1162# CONFIG_USB_HIDINPUT_POWERBOOK is not set
1163# CONFIG_HID_FF is not set 1171# CONFIG_HID_FF is not set
1164# CONFIG_USB_HIDDEV is not set 1172# CONFIG_USB_HIDDEV is not set
1165# CONFIG_USB_AIPTEK is not set 1173# CONFIG_USB_AIPTEK is not set
@@ -1444,6 +1452,11 @@ CONFIG_NLS_ISO8859_15=y
1444CONFIG_NLS_UTF8=y 1452CONFIG_NLS_UTF8=y
1445 1453
1446# 1454#
1455# Distributed Lock Manager
1456#
1457# CONFIG_DLM is not set
1458
1459#
1447# Instrumentation Support 1460# Instrumentation Support
1448# 1461#
1449CONFIG_PROFILING=y 1462CONFIG_PROFILING=y
@@ -1509,6 +1522,7 @@ CONFIG_DOUBLEFAULT=y
1509# 1522#
1510# Library routines 1523# Library routines
1511# 1524#
1525CONFIG_BITREVERSE=y
1512# CONFIG_CRC_CCITT is not set 1526# CONFIG_CRC_CCITT is not set
1513# CONFIG_CRC16 is not set 1527# CONFIG_CRC16 is not set
1514CONFIG_CRC32=y 1528CONFIG_CRC32=y
diff --git a/arch/i386/kernel/cpuid.c b/arch/i386/kernel/cpuid.c
index db6dd20c3589..51130b39cd2e 100644
--- a/arch/i386/kernel/cpuid.c
+++ b/arch/i386/kernel/cpuid.c
@@ -116,7 +116,7 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
116 char __user *tmp = buf; 116 char __user *tmp = buf;
117 u32 data[4]; 117 u32 data[4];
118 u32 reg = *ppos; 118 u32 reg = *ppos;
119 int cpu = iminor(file->f_dentry->d_inode); 119 int cpu = iminor(file->f_path.dentry->d_inode);
120 120
121 if (count % 16) 121 if (count % 16)
122 return -EINVAL; /* Invalid chunk size */ 122 return -EINVAL; /* Invalid chunk size */
@@ -134,7 +134,7 @@ static ssize_t cpuid_read(struct file *file, char __user *buf,
134 134
135static int cpuid_open(struct inode *inode, struct file *file) 135static int cpuid_open(struct inode *inode, struct file *file)
136{ 136{
137 unsigned int cpu = iminor(file->f_dentry->d_inode); 137 unsigned int cpu = iminor(file->f_path.dentry->d_inode);
138 struct cpuinfo_x86 *c = &(cpu_data)[cpu]; 138 struct cpuinfo_x86 *c = &(cpu_data)[cpu];
139 139
140 if (cpu >= NR_CPUS || !cpu_online(cpu)) 140 if (cpu >= NR_CPUS || !cpu_online(cpu))
diff --git a/arch/i386/kernel/io_apic.c b/arch/i386/kernel/io_apic.c
index e21dcde0790e..2424cc9c7b3d 100644
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/i386/kernel/io_apic.c
@@ -2485,7 +2485,7 @@ device_initcall(ioapic_init_sysfs);
2485int create_irq(void) 2485int create_irq(void)
2486{ 2486{
2487 /* Allocate an unused irq */ 2487 /* Allocate an unused irq */
2488 int irq, new, vector; 2488 int irq, new, vector = 0;
2489 unsigned long flags; 2489 unsigned long flags;
2490 2490
2491 irq = -ENOSPC; 2491 irq = -ENOSPC;
diff --git a/arch/i386/kernel/module.c b/arch/i386/kernel/module.c
index d7d9c8b23f72..3db0a5442eb1 100644
--- a/arch/i386/kernel/module.c
+++ b/arch/i386/kernel/module.c
@@ -21,6 +21,7 @@
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/bug.h>
24 25
25#if 0 26#if 0
26#define DEBUGP printk 27#define DEBUGP printk
@@ -141,10 +142,11 @@ int module_finalize(const Elf_Ehdr *hdr,
141 apply_paravirt(pseg, pseg + para->sh_size); 142 apply_paravirt(pseg, pseg + para->sh_size);
142 } 143 }
143 144
144 return 0; 145 return module_bug_finalize(hdr, sechdrs, me);
145} 146}
146 147
147void module_arch_cleanup(struct module *mod) 148void module_arch_cleanup(struct module *mod)
148{ 149{
149 alternatives_smp_module_del(mod); 150 alternatives_smp_module_del(mod);
151 module_bug_cleanup(mod);
150} 152}
diff --git a/arch/i386/kernel/msr.c b/arch/i386/kernel/msr.c
index 1d1a56cae340..4a472a17d1c6 100644
--- a/arch/i386/kernel/msr.c
+++ b/arch/i386/kernel/msr.c
@@ -172,7 +172,7 @@ static ssize_t msr_read(struct file *file, char __user * buf,
172 u32 __user *tmp = (u32 __user *) buf; 172 u32 __user *tmp = (u32 __user *) buf;
173 u32 data[2]; 173 u32 data[2];
174 u32 reg = *ppos; 174 u32 reg = *ppos;
175 int cpu = iminor(file->f_dentry->d_inode); 175 int cpu = iminor(file->f_path.dentry->d_inode);
176 int err; 176 int err;
177 177
178 if (count % 8) 178 if (count % 8)
@@ -196,7 +196,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
196 const u32 __user *tmp = (const u32 __user *)buf; 196 const u32 __user *tmp = (const u32 __user *)buf;
197 u32 data[2]; 197 u32 data[2];
198 u32 reg = *ppos; 198 u32 reg = *ppos;
199 int cpu = iminor(file->f_dentry->d_inode); 199 int cpu = iminor(file->f_path.dentry->d_inode);
200 int err; 200 int err;
201 201
202 if (count % 8) 202 if (count % 8)
@@ -216,7 +216,7 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
216 216
217static int msr_open(struct inode *inode, struct file *file) 217static int msr_open(struct inode *inode, struct file *file)
218{ 218{
219 unsigned int cpu = iminor(file->f_dentry->d_inode); 219 unsigned int cpu = iminor(file->f_path.dentry->d_inode);
220 struct cpuinfo_x86 *c = &(cpu_data)[cpu]; 220 struct cpuinfo_x86 *c = &(cpu_data)[cpu];
221 221
222 if (cpu >= NR_CPUS || !cpu_online(cpu)) 222 if (cpu >= NR_CPUS || !cpu_online(cpu))
diff --git a/arch/i386/kernel/nmi.c b/arch/i386/kernel/nmi.c
index f5bc7e1be801..a5e34d655965 100644
--- a/arch/i386/kernel/nmi.c
+++ b/arch/i386/kernel/nmi.c
@@ -195,6 +195,8 @@ static __cpuinit inline int nmi_known_cpu(void)
195 return 0; 195 return 0;
196} 196}
197 197
198static int endflag __initdata = 0;
199
198#ifdef CONFIG_SMP 200#ifdef CONFIG_SMP
199/* The performance counters used by NMI_LOCAL_APIC don't trigger when 201/* The performance counters used by NMI_LOCAL_APIC don't trigger when
200 * the CPU is idle. To make sure the NMI watchdog really ticks on all 202 * the CPU is idle. To make sure the NMI watchdog really ticks on all
@@ -202,7 +204,6 @@ static __cpuinit inline int nmi_known_cpu(void)
202 */ 204 */
203static __init void nmi_cpu_busy(void *data) 205static __init void nmi_cpu_busy(void *data)
204{ 206{
205 volatile int *endflag = data;
206 local_irq_enable_in_hardirq(); 207 local_irq_enable_in_hardirq();
207 /* Intentionally don't use cpu_relax here. This is 208 /* Intentionally don't use cpu_relax here. This is
208 to make sure that the performance counter really ticks, 209 to make sure that the performance counter really ticks,
@@ -210,14 +211,13 @@ static __init void nmi_cpu_busy(void *data)
210 pause instruction. On a real HT machine this is fine because 211 pause instruction. On a real HT machine this is fine because
211 all other CPUs are busy with "useless" delay loops and don't 212 all other CPUs are busy with "useless" delay loops and don't
212 care if they get somewhat less cycles. */ 213 care if they get somewhat less cycles. */
213 while (*endflag == 0) 214 while (endflag == 0)
214 barrier(); 215 mb();
215} 216}
216#endif 217#endif
217 218
218static int __init check_nmi_watchdog(void) 219static int __init check_nmi_watchdog(void)
219{ 220{
220 volatile int endflag = 0;
221 unsigned int *prev_nmi_count; 221 unsigned int *prev_nmi_count;
222 int cpu; 222 int cpu;
223 223
diff --git a/arch/i386/kernel/quirks.c b/arch/i386/kernel/quirks.c
index a01320a7b636..34874c398b44 100644
--- a/arch/i386/kernel/quirks.c
+++ b/arch/i386/kernel/quirks.c
@@ -10,13 +10,38 @@
10#if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI) 10#if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI)
11static void __devinit verify_quirk_intel_irqbalance(struct pci_dev *dev) 11static void __devinit verify_quirk_intel_irqbalance(struct pci_dev *dev)
12{ 12{
13 u8 config, rev;
14 u32 word;
15
16 /* BIOS may enable hardware IRQ balancing for
17 * E7520/E7320/E7525(revision ID 0x9 and below)
18 * based platforms.
19 * For those platforms, make sure that the genapic is set to 'flat'
20 */
21 pci_read_config_byte(dev, PCI_CLASS_REVISION, &rev);
22 if (rev > 0x9)
23 return;
24
25 /* enable access to config space*/
26 pci_read_config_byte(dev, 0xf4, &config);
27 pci_write_config_byte(dev, 0xf4, config|0x2);
28
29 /* read xTPR register */
30 raw_pci_ops->read(0, 0, 0x40, 0x4c, 2, &word);
31
32 if (!(word & (1 << 13))) {
13#ifdef CONFIG_X86_64 33#ifdef CONFIG_X86_64
14 if (genapic != &apic_flat) 34 if (genapic != &apic_flat)
15 panic("APIC mode must be flat on this system\n"); 35 panic("APIC mode must be flat on this system\n");
16#elif defined(CONFIG_X86_GENERICARCH) 36#elif defined(CONFIG_X86_GENERICARCH)
17 if (genapic != &apic_default) 37 if (genapic != &apic_default)
18 panic("APIC mode must be default(flat) on this system. Use apic=default\n"); 38 panic("APIC mode must be default(flat) on this system. Use apic=default\n");
19#endif 39#endif
40 }
41
42 /* put back the original value for config space*/
43 if (!(config & 0x2))
44 pci_write_config_byte(dev, 0xf4, config);
20} 45}
21 46
22void __init quirk_intel_irqbalance(void) 47void __init quirk_intel_irqbalance(void)
diff --git a/arch/i386/kernel/smpboot.c b/arch/i386/kernel/smpboot.c
index 4bf0e3c83b8b..b0f84e5778ad 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/i386/kernel/smpboot.c
@@ -69,7 +69,7 @@ static int __devinitdata smp_b_stepping;
69 69
70/* Number of siblings per CPU package */ 70/* Number of siblings per CPU package */
71int smp_num_siblings = 1; 71int smp_num_siblings = 1;
72#ifdef CONFIG_X86_HT 72#ifdef CONFIG_SMP
73EXPORT_SYMBOL(smp_num_siblings); 73EXPORT_SYMBOL(smp_num_siblings);
74#endif 74#endif
75 75
@@ -1118,7 +1118,7 @@ static int __cpuinit __smp_prepare_cpu(int cpu)
1118 1118
1119 /* init low mem mapping */ 1119 /* init low mem mapping */
1120 clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS, 1120 clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
1121 KERNEL_PGD_PTRS); 1121 min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS));
1122 flush_tlb_all(); 1122 flush_tlb_all();
1123 schedule_work(&info.task); 1123 schedule_work(&info.task);
1124 wait_for_completion(&done); 1124 wait_for_completion(&done);
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index 68de48e498ca..2b30dbf8d117 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -30,6 +30,7 @@
30#include <linux/unwind.h> 30#include <linux/unwind.h>
31#include <linux/uaccess.h> 31#include <linux/uaccess.h>
32#include <linux/nmi.h> 32#include <linux/nmi.h>
33#include <linux/bug.h>
33 34
34#ifdef CONFIG_EISA 35#ifdef CONFIG_EISA
35#include <linux/ioport.h> 36#include <linux/ioport.h>
@@ -420,43 +421,22 @@ void show_registers(struct pt_regs *regs)
420 printk("\n"); 421 printk("\n");
421} 422}
422 423
423static void handle_BUG(struct pt_regs *regs) 424int is_valid_bugaddr(unsigned long eip)
424{ 425{
425 unsigned long eip = regs->eip;
426 unsigned short ud2; 426 unsigned short ud2;
427 427
428 if (eip < PAGE_OFFSET) 428 if (eip < PAGE_OFFSET)
429 return; 429 return 0;
430 if (probe_kernel_address((unsigned short *)eip, ud2)) 430 if (probe_kernel_address((unsigned short *)eip, ud2))
431 return; 431 return 0;
432 if (ud2 != 0x0b0f)
433 return;
434
435 printk(KERN_EMERG "------------[ cut here ]------------\n");
436
437#ifdef CONFIG_DEBUG_BUGVERBOSE
438 do {
439 unsigned short line;
440 char *file;
441 char c;
442
443 if (probe_kernel_address((unsigned short *)(eip + 2), line))
444 break;
445 if (probe_kernel_address((char **)(eip + 4), file) ||
446 (unsigned long)file < PAGE_OFFSET ||
447 probe_kernel_address(file, c))
448 file = "<bad filename>";
449 432
450 printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line); 433 return ud2 == 0x0b0f;
451 return;
452 } while (0);
453#endif
454 printk(KERN_EMERG "Kernel BUG at [verbose debug info unavailable]\n");
455} 434}
456 435
457/* This is gone through when something in the kernel 436/*
458 * has done something bad and is about to be terminated. 437 * This is gone through when something in the kernel has done something bad and
459*/ 438 * is about to be terminated.
439 */
460void die(const char * str, struct pt_regs * regs, long err) 440void die(const char * str, struct pt_regs * regs, long err)
461{ 441{
462 static struct { 442 static struct {
@@ -488,7 +468,8 @@ void die(const char * str, struct pt_regs * regs, long err)
488 unsigned long esp; 468 unsigned long esp;
489 unsigned short ss; 469 unsigned short ss;
490 470
491 handle_BUG(regs); 471 report_bug(regs->eip);
472
492 printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter); 473 printk(KERN_EMERG "%s: %04lx [#%d]\n", str, err & 0xffff, ++die_counter);
493#ifdef CONFIG_PREEMPT 474#ifdef CONFIG_PREEMPT
494 printk(KERN_EMERG "PREEMPT "); 475 printk(KERN_EMERG "PREEMPT ");
diff --git a/arch/i386/kernel/vmlinux.lds.S b/arch/i386/kernel/vmlinux.lds.S
index 56e6ad5cb045..a53c8b1854b5 100644
--- a/arch/i386/kernel/vmlinux.lds.S
+++ b/arch/i386/kernel/vmlinux.lds.S
@@ -26,6 +26,7 @@ OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
26OUTPUT_ARCH(i386) 26OUTPUT_ARCH(i386)
27ENTRY(phys_startup_32) 27ENTRY(phys_startup_32)
28jiffies = jiffies_64; 28jiffies = jiffies_64;
29_proxy_pda = 0;
29 30
30PHDRS { 31PHDRS {
31 text PT_LOAD FLAGS(5); /* R_E */ 32 text PT_LOAD FLAGS(5); /* R_E */
@@ -57,6 +58,8 @@ SECTIONS
57 58
58 RODATA 59 RODATA
59 60
61 BUG_TABLE
62
60 . = ALIGN(4); 63 . = ALIGN(4);
61 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) { 64 .tracedata : AT(ADDR(.tracedata) - LOAD_OFFSET) {
62 __tracedata_start = .; 65 __tracedata_start = .;
diff --git a/arch/i386/mach-visws/setup.c b/arch/i386/mach-visws/setup.c
index 885c7cbfd478..233ee20907b9 100644
--- a/arch/i386/mach-visws/setup.c
+++ b/arch/i386/mach-visws/setup.c
@@ -6,6 +6,7 @@
6#include <linux/smp.h> 6#include <linux/smp.h>
7#include <linux/init.h> 7#include <linux/init.h>
8#include <linux/interrupt.h> 8#include <linux/interrupt.h>
9#include <linux/module.h>
9 10
10#include <asm/fixmap.h> 11#include <asm/fixmap.h>
11#include <asm/arch_hooks.h> 12#include <asm/arch_hooks.h>
@@ -142,6 +143,8 @@ void __init time_init_hook(void)
142 143
143unsigned long sgivwfb_mem_phys; 144unsigned long sgivwfb_mem_phys;
144unsigned long sgivwfb_mem_size; 145unsigned long sgivwfb_mem_size;
146EXPORT_SYMBOL(sgivwfb_mem_phys);
147EXPORT_SYMBOL(sgivwfb_mem_size);
145 148
146long long mem_size __initdata = 0; 149long long mem_size __initdata = 0;
147 150
diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
index 75d839715b2f..fcacfe291b9b 100644
--- a/arch/ia64/Kconfig
+++ b/arch/ia64/Kconfig
@@ -34,6 +34,14 @@ config RWSEM_XCHGADD_ALGORITHM
34 bool 34 bool
35 default y 35 default y
36 36
37config ARCH_HAS_ILOG2_U32
38 bool
39 default n
40
41config ARCH_HAS_ILOG2_U64
42 bool
43 default n
44
37config GENERIC_FIND_NEXT_BIT 45config GENERIC_FIND_NEXT_BIT
38 bool 46 bool
39 default y 47 default y
diff --git a/arch/ia64/ia32/sys_ia32.c b/arch/ia64/ia32/sys_ia32.c
index a4a6e1463af8..957681c39ad9 100644
--- a/arch/ia64/ia32/sys_ia32.c
+++ b/arch/ia64/ia32/sys_ia32.c
@@ -235,7 +235,7 @@ mmap_subpage (struct file *file, unsigned long start, unsigned long end, int pro
235 235
236 if (!(flags & MAP_ANONYMOUS)) { 236 if (!(flags & MAP_ANONYMOUS)) {
237 /* read the file contents */ 237 /* read the file contents */
238 inode = file->f_dentry->d_inode; 238 inode = file->f_path.dentry->d_inode;
239 if (!inode->i_fop || !file->f_op->read 239 if (!inode->i_fop || !file->f_op->read
240 || ((*file->f_op->read)(file, (char __user *) start, end - start, &off) < 0)) 240 || ((*file->f_op->read)(file, (char __user *) start, end - start, &off) < 0))
241 { 241 {
@@ -837,7 +837,7 @@ emulate_mmap (struct file *file, unsigned long start, unsigned long len, int pro
837 837
838 if (!is_congruent) { 838 if (!is_congruent) {
839 /* read the file contents */ 839 /* read the file contents */
840 inode = file->f_dentry->d_inode; 840 inode = file->f_path.dentry->d_inode;
841 if (!inode->i_fop || !file->f_op->read 841 if (!inode->i_fop || !file->f_op->read
842 || ((*file->f_op->read)(file, (char __user *) pstart, pend - pstart, &poff) 842 || ((*file->f_op->read)(file, (char __user *) pstart, pend - pstart, &poff)
843 < 0)) 843 < 0))
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index dbb28164b19b..aa94f60fa8e7 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -2188,13 +2188,13 @@ pfm_alloc_fd(struct file **cfile)
2188 /* 2188 /*
2189 * allocate a new dcache entry 2189 * allocate a new dcache entry
2190 */ 2190 */
2191 file->f_dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this); 2191 file->f_path.dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this);
2192 if (!file->f_dentry) goto out; 2192 if (!file->f_path.dentry) goto out;
2193 2193
2194 file->f_dentry->d_op = &pfmfs_dentry_operations; 2194 file->f_path.dentry->d_op = &pfmfs_dentry_operations;
2195 2195
2196 d_add(file->f_dentry, inode); 2196 d_add(file->f_path.dentry, inode);
2197 file->f_vfsmnt = mntget(pfmfs_mnt); 2197 file->f_path.mnt = mntget(pfmfs_mnt);
2198 file->f_mapping = inode->i_mapping; 2198 file->f_mapping = inode->i_mapping;
2199 2199
2200 file->f_op = &pfm_file_ops; 2200 file->f_op = &pfm_file_ops;
diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
index fd607ca51a8d..e375a2f0f2c3 100644
--- a/arch/ia64/kernel/salinfo.c
+++ b/arch/ia64/kernel/salinfo.c
@@ -302,7 +302,7 @@ salinfo_event_open(struct inode *inode, struct file *file)
302static ssize_t 302static ssize_t
303salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 303salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
304{ 304{
305 struct inode *inode = file->f_dentry->d_inode; 305 struct inode *inode = file->f_path.dentry->d_inode;
306 struct proc_dir_entry *entry = PDE(inode); 306 struct proc_dir_entry *entry = PDE(inode);
307 struct salinfo_data *data = entry->data; 307 struct salinfo_data *data = entry->data;
308 char cmd[32]; 308 char cmd[32];
@@ -464,7 +464,7 @@ retry:
464static ssize_t 464static ssize_t
465salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos) 465salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
466{ 466{
467 struct inode *inode = file->f_dentry->d_inode; 467 struct inode *inode = file->f_path.dentry->d_inode;
468 struct proc_dir_entry *entry = PDE(inode); 468 struct proc_dir_entry *entry = PDE(inode);
469 struct salinfo_data *data = entry->data; 469 struct salinfo_data *data = entry->data;
470 u8 *buf; 470 u8 *buf;
@@ -525,7 +525,7 @@ salinfo_log_clear(struct salinfo_data *data, int cpu)
525static ssize_t 525static ssize_t
526salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) 526salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
527{ 527{
528 struct inode *inode = file->f_dentry->d_inode; 528 struct inode *inode = file->f_path.dentry->d_inode;
529 struct proc_dir_entry *entry = PDE(inode); 529 struct proc_dir_entry *entry = PDE(inode);
530 struct salinfo_data *data = entry->data; 530 struct salinfo_data *data = entry->data;
531 char cmd[32]; 531 char cmd[32];
diff --git a/arch/m32r/Kconfig b/arch/m32r/Kconfig
index 41fd490af3b4..f383dab973f5 100644
--- a/arch/m32r/Kconfig
+++ b/arch/m32r/Kconfig
@@ -214,6 +214,14 @@ config RWSEM_XCHGADD_ALGORITHM
214 bool 214 bool
215 default n 215 default n
216 216
217config ARCH_HAS_ILOG2_U32
218 bool
219 default n
220
221config ARCH_HAS_ILOG2_U64
222 bool
223 default n
224
217config GENERIC_FIND_NEXT_BIT 225config GENERIC_FIND_NEXT_BIT
218 bool 226 bool
219 default y 227 default y
diff --git a/arch/m32r/boot/compressed/m32r_sio.c b/arch/m32r/boot/compressed/m32r_sio.c
index bce8af5e3bb2..ee3c8be12fa0 100644
--- a/arch/m32r/boot/compressed/m32r_sio.c
+++ b/arch/m32r/boot/compressed/m32r_sio.c
@@ -2,6 +2,7 @@
2 * arch/m32r/boot/compressed/m32r_sio.c 2 * arch/m32r/boot/compressed/m32r_sio.c
3 * 3 *
4 * 2003-02-12: Takeo Takahashi 4 * 2003-02-12: Takeo Takahashi
5 * 2006-11-30: OPSPUT support by Kazuhiro Inaoka
5 * 6 *
6 */ 7 */
7 8
@@ -16,7 +17,7 @@ static int puts(const char *s)
16 return 0; 17 return 0;
17} 18}
18 19
19#if defined(CONFIG_PLAT_M32700UT_Alpha) || defined(CONFIG_PLAT_M32700UT) 20#if defined(CONFIG_PLAT_M32700UT_Alpha) || defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_OPSPUT)
20#include <asm/m32r.h> 21#include <asm/m32r.h>
21#include <asm/io.h> 22#include <asm/io.h>
22 23
@@ -31,7 +32,11 @@ static int puts(const char *s)
31#define BOOT_SIO0TXB (volatile unsigned short *)(0x02c00000 + 0x2000c) 32#define BOOT_SIO0TXB (volatile unsigned short *)(0x02c00000 + 0x2000c)
32#else 33#else
33#undef PLD_BASE 34#undef PLD_BASE
35#if defined(CONFIG_PLAT_OPSPUT)
36#define PLD_BASE 0x1cc00000
37#else
34#define PLD_BASE 0xa4c00000 38#define PLD_BASE 0xa4c00000
39#endif
35#define BOOT_SIO0STS PLD_ESIO0STS 40#define BOOT_SIO0STS PLD_ESIO0STS
36#define BOOT_SIO0TXB PLD_ESIO0TXB 41#define BOOT_SIO0TXB PLD_ESIO0TXB
37#endif 42#endif
diff --git a/arch/m32r/kernel/entry.S b/arch/m32r/kernel/entry.S
index ac6d840b382b..a2c472c0549f 100644
--- a/arch/m32r/kernel/entry.S
+++ b/arch/m32r/kernel/entry.S
@@ -23,35 +23,35 @@
23 * updated in fork.c:copy_thread, signal.c:do_signal, 23 * updated in fork.c:copy_thread, signal.c:do_signal,
24 * ptrace.c and ptrace.h 24 * ptrace.c and ptrace.h
25 * 25 *
26 * M32Rx/M32R2 M32R 26 * M32R/M32Rx/M32R2
27 * @(sp) - r4 ditto 27 * @(sp) - r4
28 * @(0x04,sp) - r5 ditto 28 * @(0x04,sp) - r5
29 * @(0x08,sp) - r6 ditto 29 * @(0x08,sp) - r6
30 * @(0x0c,sp) - *pt_regs ditto 30 * @(0x0c,sp) - *pt_regs
31 * @(0x10,sp) - r0 ditto 31 * @(0x10,sp) - r0
32 * @(0x14,sp) - r1 ditto 32 * @(0x14,sp) - r1
33 * @(0x18,sp) - r2 ditto 33 * @(0x18,sp) - r2
34 * @(0x1c,sp) - r3 ditto 34 * @(0x1c,sp) - r3
35 * @(0x20,sp) - r7 ditto 35 * @(0x20,sp) - r7
36 * @(0x24,sp) - r8 ditto 36 * @(0x24,sp) - r8
37 * @(0x28,sp) - r9 ditto 37 * @(0x28,sp) - r9
38 * @(0x2c,sp) - r10 ditto 38 * @(0x2c,sp) - r10
39 * @(0x30,sp) - r11 ditto 39 * @(0x30,sp) - r11
40 * @(0x34,sp) - r12 ditto 40 * @(0x34,sp) - r12
41 * @(0x38,sp) - syscall_nr ditto 41 * @(0x38,sp) - syscall_nr
42 * @(0x3c,sp) - acc0h @(0x3c,sp) - acch 42 * @(0x3c,sp) - acc0h
43 * @(0x40,sp) - acc0l @(0x40,sp) - accl 43 * @(0x40,sp) - acc0l
44 * @(0x44,sp) - acc1h @(0x44,sp) - dummy_acc1h 44 * @(0x44,sp) - acc1h ; ISA_DSP_LEVEL2 only
45 * @(0x48,sp) - acc1l @(0x48,sp) - dummy_acc1l 45 * @(0x48,sp) - acc1l ; ISA_DSP_LEVEL2 only
46 * @(0x4c,sp) - psw ditto 46 * @(0x4c,sp) - psw
47 * @(0x50,sp) - bpc ditto 47 * @(0x50,sp) - bpc
48 * @(0x54,sp) - bbpsw ditto 48 * @(0x54,sp) - bbpsw
49 * @(0x58,sp) - bbpc ditto 49 * @(0x58,sp) - bbpc
50 * @(0x5c,sp) - spu (cr3) ditto 50 * @(0x5c,sp) - spu (cr3)
51 * @(0x60,sp) - fp (r13) ditto 51 * @(0x60,sp) - fp (r13)
52 * @(0x64,sp) - lr (r14) ditto 52 * @(0x64,sp) - lr (r14)
53 * @(0x68,sp) - spi (cr2) ditto 53 * @(0x68,sp) - spi (cr2)
54 * @(0x6c,sp) - orig_r0 ditto 54 * @(0x6c,sp) - orig_r0
55 */ 55 */
56 56
57#include <linux/linkage.h> 57#include <linux/linkage.h>
@@ -95,17 +95,10 @@
95#define R11(reg) @(0x30,reg) 95#define R11(reg) @(0x30,reg)
96#define R12(reg) @(0x34,reg) 96#define R12(reg) @(0x34,reg)
97#define SYSCALL_NR(reg) @(0x38,reg) 97#define SYSCALL_NR(reg) @(0x38,reg)
98#if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
99#define ACC0H(reg) @(0x3C,reg) 98#define ACC0H(reg) @(0x3C,reg)
100#define ACC0L(reg) @(0x40,reg) 99#define ACC0L(reg) @(0x40,reg)
101#define ACC1H(reg) @(0x44,reg) 100#define ACC1H(reg) @(0x44,reg)
102#define ACC1L(reg) @(0x48,reg) 101#define ACC1L(reg) @(0x48,reg)
103#elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
104#define ACCH(reg) @(0x3C,reg)
105#define ACCL(reg) @(0x40,reg)
106#else
107#error unknown isa configuration
108#endif
109#define PSW(reg) @(0x4C,reg) 102#define PSW(reg) @(0x4C,reg)
110#define BPC(reg) @(0x50,reg) 103#define BPC(reg) @(0x50,reg)
111#define BBPSW(reg) @(0x54,reg) 104#define BBPSW(reg) @(0x54,reg)
@@ -603,8 +596,6 @@ ENTRY(ace_handler)
603 beqz r1, inst 596 beqz r1, inst
604oprand: 597oprand:
605 ld r2, @(low(MDEVA_offset),r2) ; set address 598 ld r2, @(low(MDEVA_offset),r2) ; set address
606 srli r2, #12
607 slli r2, #12
608 srli r1, #1 599 srli r1, #1
609 bra 1f 600 bra 1f
610inst: 601inst:
diff --git a/arch/m32r/kernel/io_opsput.c b/arch/m32r/kernel/io_opsput.c
index da6c5f5c1f82..3cbb1f717e50 100644
--- a/arch/m32r/kernel/io_opsput.c
+++ b/arch/m32r/kernel/io_opsput.c
@@ -30,14 +30,34 @@ extern void pcc_iowrite_byte(int, unsigned long, void *, size_t, size_t, int);
30extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int); 30extern void pcc_iowrite_word(int, unsigned long, void *, size_t, size_t, int);
31#endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */ 31#endif /* CONFIG_PCMCIA && CONFIG_M32R_CFC */
32 32
33#define PORT2ADDR(port) _port2addr(port) 33#define PORT2ADDR(port) _port2addr(port)
34#define PORT2ADDR_USB(port) _port2addr_usb(port) 34#define PORT2ADDR_USB(port) _port2addr_usb(port)
35 35
36static inline void *_port2addr(unsigned long port) 36static inline void *_port2addr(unsigned long port)
37{ 37{
38 return (void *)(port | NONCACHE_OFFSET); 38 return (void *)(port | NONCACHE_OFFSET);
39} 39}
40 40
41#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
42static inline void *__port2addr_ata(unsigned long port)
43{
44 static int dummy_reg;
45
46 switch (port) {
47 case 0x1f0: return (void *)(0x0c002000 | NONCACHE_OFFSET);
48 case 0x1f1: return (void *)(0x0c012800 | NONCACHE_OFFSET);
49 case 0x1f2: return (void *)(0x0c012002 | NONCACHE_OFFSET);
50 case 0x1f3: return (void *)(0x0c012802 | NONCACHE_OFFSET);
51 case 0x1f4: return (void *)(0x0c012004 | NONCACHE_OFFSET);
52 case 0x1f5: return (void *)(0x0c012804 | NONCACHE_OFFSET);
53 case 0x1f6: return (void *)(0x0c012006 | NONCACHE_OFFSET);
54 case 0x1f7: return (void *)(0x0c012806 | NONCACHE_OFFSET);
55 case 0x3f6: return (void *)(0x0c01200e | NONCACHE_OFFSET);
56 default: return (void *)&dummy_reg;
57 }
58}
59#endif
60
41/* 61/*
42 * OPSPUT-LAN is located in the extended bus space 62 * OPSPUT-LAN is located in the extended bus space
43 * from 0x10000000 to 0x13ffffff on physical address. 63 * from 0x10000000 to 0x13ffffff on physical address.
@@ -97,6 +117,12 @@ unsigned char _inb(unsigned long port)
97{ 117{
98 if (port >= LAN_IOSTART && port < LAN_IOEND) 118 if (port >= LAN_IOSTART && port < LAN_IOEND)
99 return _ne_inb(PORT2ADDR_NE(port)); 119 return _ne_inb(PORT2ADDR_NE(port));
120
121#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
122 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
123 return *(volatile unsigned char *)__port2addr_ata(port);
124 }
125#endif
100#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) 126#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
101 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { 127 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
102 unsigned char b; 128 unsigned char b;
@@ -112,6 +138,11 @@ unsigned short _inw(unsigned long port)
112{ 138{
113 if (port >= LAN_IOSTART && port < LAN_IOEND) 139 if (port >= LAN_IOSTART && port < LAN_IOEND)
114 return _ne_inw(PORT2ADDR_NE(port)); 140 return _ne_inw(PORT2ADDR_NE(port));
141#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
142 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
143 return *(volatile unsigned short *)__port2addr_ata(port);
144 }
145#endif
115#if defined(CONFIG_USB) 146#if defined(CONFIG_USB)
116 else if(port >= 0x340 && port < 0x3a0) 147 else if(port >= 0x340 && port < 0x3a0)
117 return *(volatile unsigned short *)PORT2ADDR_USB(port); 148 return *(volatile unsigned short *)PORT2ADDR_USB(port);
@@ -164,6 +195,11 @@ void _outb(unsigned char b, unsigned long port)
164 if (port >= LAN_IOSTART && port < LAN_IOEND) 195 if (port >= LAN_IOSTART && port < LAN_IOEND)
165 _ne_outb(b, PORT2ADDR_NE(port)); 196 _ne_outb(b, PORT2ADDR_NE(port));
166 else 197 else
198#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
199 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
200 *(volatile unsigned char *)__port2addr_ata(port) = b;
201 } else
202#endif
167#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) 203#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
168 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { 204 if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
169 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0); 205 pcc_iowrite_byte(0, port, &b, sizeof(b), 1, 0);
@@ -177,6 +213,11 @@ void _outw(unsigned short w, unsigned long port)
177 if (port >= LAN_IOSTART && port < LAN_IOEND) 213 if (port >= LAN_IOSTART && port < LAN_IOEND)
178 _ne_outw(w, PORT2ADDR_NE(port)); 214 _ne_outw(w, PORT2ADDR_NE(port));
179 else 215 else
216#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
217 if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
218 *(volatile unsigned short *)__port2addr_ata(port) = w;
219 } else
220#endif
180#if defined(CONFIG_USB) 221#if defined(CONFIG_USB)
181 if(port >= 0x340 && port < 0x3a0) 222 if(port >= 0x340 && port < 0x3a0)
182 *(volatile unsigned short *)PORT2ADDR_USB(port) = w; 223 *(volatile unsigned short *)PORT2ADDR_USB(port) = w;
@@ -222,6 +263,14 @@ void _insb(unsigned int port, void *addr, unsigned long count)
222{ 263{
223 if (port >= LAN_IOSTART && port < LAN_IOEND) 264 if (port >= LAN_IOSTART && port < LAN_IOEND)
224 _ne_insb(PORT2ADDR_NE(port), addr, count); 265 _ne_insb(PORT2ADDR_NE(port), addr, count);
266#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
267 else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
268 unsigned char *buf = addr;
269 unsigned char *portp = __port2addr_ata(port);
270 while (count--)
271 *buf++ = *(volatile unsigned char *)portp;
272 }
273#endif
225#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) 274#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
226 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { 275 else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
227 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char), 276 pcc_ioread_byte(0, port, (void *)addr, sizeof(unsigned char),
@@ -254,6 +303,12 @@ void _insw(unsigned int port, void *addr, unsigned long count)
254 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short), 303 pcc_ioread_word(9, port, (void *)addr, sizeof(unsigned short),
255 count, 1); 304 count, 1);
256#endif 305#endif
306#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
307 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
308 portp = __port2addr_ata(port);
309 while (count--)
310 *buf++ = *(volatile unsigned short *)portp;
311#endif
257 } else { 312 } else {
258 portp = PORT2ADDR(port); 313 portp = PORT2ADDR(port);
259 while (count--) 314 while (count--)
@@ -280,6 +335,12 @@ void _outsb(unsigned int port, const void *addr, unsigned long count)
280 portp = PORT2ADDR_NE(port); 335 portp = PORT2ADDR_NE(port);
281 while (count--) 336 while (count--)
282 _ne_outb(*buf++, portp); 337 _ne_outb(*buf++, portp);
338#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
339 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
340 portp = __port2addr_ata(port);
341 while (count--)
342 *(volatile unsigned char *)portp = *buf++;
343#endif
283#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) 344#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
284 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { 345 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
285 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char), 346 pcc_iowrite_byte(0, port, (void *)addr, sizeof(unsigned char),
@@ -305,6 +366,12 @@ void _outsw(unsigned int port, const void *addr, unsigned long count)
305 portp = PORT2ADDR_NE(port); 366 portp = PORT2ADDR_NE(port);
306 while (count--) 367 while (count--)
307 *(volatile unsigned short *)portp = *buf++; 368 *(volatile unsigned short *)portp = *buf++;
369#if defined(CONFIG_IDE) && !defined(CONFIG_M32R_CFC)
370 } else if ((port >= 0x1f0 && port <=0x1f7) || port == 0x3f6) {
371 portp = __port2addr_ata(port);
372 while (count--)
373 *(volatile unsigned short *)portp = *buf++;
374#endif
308#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC) 375#if defined(CONFIG_PCMCIA) && defined(CONFIG_M32R_CFC)
309 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) { 376 } else if (port >= M32R_PCC_IOSTART0 && port <= M32R_PCC_IOEND0) {
310 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short), 377 pcc_iowrite_word(9, port, (void *)addr, sizeof(unsigned short),
diff --git a/arch/m32r/kernel/setup_opsput.c b/arch/m32r/kernel/setup_opsput.c
index 61d3b01cbe07..62d6b71de45f 100644
--- a/arch/m32r/kernel/setup_opsput.c
+++ b/arch/m32r/kernel/setup_opsput.c
@@ -218,13 +218,13 @@ static void shutdown_opsput_lanpld_irq(unsigned int irq)
218 218
219static struct hw_interrupt_type opsput_lanpld_irq_type = 219static struct hw_interrupt_type opsput_lanpld_irq_type =
220{ 220{
221 "OPSPUT-PLD-LAN-IRQ", 221 .typename = "OPSPUT-PLD-LAN-IRQ",
222 startup_opsput_lanpld_irq, 222 .startup = startup_opsput_lanpld_irq,
223 shutdown_opsput_lanpld_irq, 223 .shutdown = shutdown_opsput_lanpld_irq,
224 enable_opsput_lanpld_irq, 224 .enable = enable_opsput_lanpld_irq,
225 disable_opsput_lanpld_irq, 225 .disable = disable_opsput_lanpld_irq,
226 mask_and_ack_opsput_lanpld, 226 .ack = mask_and_ack_opsput_lanpld,
227 end_opsput_lanpld_irq 227 .end = end_opsput_lanpld_irq
228}; 228};
229 229
230/* 230/*
@@ -374,7 +374,6 @@ void __init init_IRQ(void)
374 disable_opsput_pld_irq(PLD_IRQ_SIO0_SND); 374 disable_opsput_pld_irq(PLD_IRQ_SIO0_SND);
375#endif /* CONFIG_SERIAL_M32R_PLDSIO */ 375#endif /* CONFIG_SERIAL_M32R_PLDSIO */
376 376
377#if defined(CONFIG_M32R_CFC)
378 /* INT#1: CFC IREQ on PLD */ 377 /* INT#1: CFC IREQ on PLD */
379 irq_desc[PLD_IRQ_CFIREQ].status = IRQ_DISABLED; 378 irq_desc[PLD_IRQ_CFIREQ].status = IRQ_DISABLED;
380 irq_desc[PLD_IRQ_CFIREQ].chip = &opsput_pld_irq_type; 379 irq_desc[PLD_IRQ_CFIREQ].chip = &opsput_pld_irq_type;
@@ -398,8 +397,6 @@ void __init init_IRQ(void)
398 irq_desc[PLD_IRQ_CFC_EJECT].depth = 1; /* disable nested irq */ 397 irq_desc[PLD_IRQ_CFC_EJECT].depth = 1; /* disable nested irq */
399 pld_icu_data[irq2pldirq(PLD_IRQ_CFC_EJECT)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD02; /* 'H' edge sense */ 398 pld_icu_data[irq2pldirq(PLD_IRQ_CFC_EJECT)].icucr = PLD_ICUCR_IEN|PLD_ICUCR_ISMOD02; /* 'H' edge sense */
400 disable_opsput_pld_irq(PLD_IRQ_CFC_EJECT); 399 disable_opsput_pld_irq(PLD_IRQ_CFC_EJECT);
401#endif /* CONFIG_M32R_CFC */
402
403 400
404 /* 401 /*
405 * INT0# is used for LAN, DIO 402 * INT0# is used for LAN, DIO
diff --git a/arch/m32r/mm/fault.c b/arch/m32r/mm/fault.c
index 8d5f551b5754..9b9feb0f1610 100644
--- a/arch/m32r/mm/fault.c
+++ b/arch/m32r/mm/fault.c
@@ -173,7 +173,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
173 goto good_area; 173 goto good_area;
174 if (!(vma->vm_flags & VM_GROWSDOWN)) 174 if (!(vma->vm_flags & VM_GROWSDOWN))
175 goto bad_area; 175 goto bad_area;
176#if 0 176
177 if (error_code & ACE_USERMODE) { 177 if (error_code & ACE_USERMODE) {
178 /* 178 /*
179 * accessing the stack below "spu" is always a bug. 179 * accessing the stack below "spu" is always a bug.
@@ -184,7 +184,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
184 if (address + 4 < regs->spu) 184 if (address + 4 < regs->spu)
185 goto bad_area; 185 goto bad_area;
186 } 186 }
187#endif 187
188 if (expand_stack(vma, address)) 188 if (expand_stack(vma, address))
189 goto bad_area; 189 goto bad_area;
190/* 190/*
diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 7bc14461a6ac..70a577c89c7c 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -17,6 +17,14 @@ config RWSEM_GENERIC_SPINLOCK
17config RWSEM_XCHGADD_ALGORITHM 17config RWSEM_XCHGADD_ALGORITHM
18 bool 18 bool
19 19
20config ARCH_HAS_ILOG2_U32
21 bool
22 default n
23
24config ARCH_HAS_ILOG2_U64
25 bool
26 default n
27
20config GENERIC_HWEIGHT 28config GENERIC_HWEIGHT
21 bool 29 bool
22 default y 30 default y
diff --git a/arch/m68k/atari/stdma.c b/arch/m68k/atari/stdma.c
index d64b5804e980..d01deb46ebbc 100644
--- a/arch/m68k/atari/stdma.c
+++ b/arch/m68k/atari/stdma.c
@@ -174,7 +174,7 @@ int stdma_islocked(void)
174void __init stdma_init(void) 174void __init stdma_init(void)
175{ 175{
176 stdma_isr = NULL; 176 stdma_isr = NULL;
177 request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW, 177 request_irq(IRQ_MFP_FDC, stdma_int, IRQ_TYPE_SLOW | SA_SHIRQ,
178 "ST-DMA: floppy/ACSI/IDE/Falcon-SCSI", stdma_int); 178 "ST-DMA: floppy/ACSI/IDE/Falcon-SCSI", stdma_int);
179} 179}
180 180
diff --git a/arch/m68k/kernel/sun3-head.S b/arch/m68k/kernel/sun3-head.S
index bffd69a4a1ab..4b5f050204e8 100644
--- a/arch/m68k/kernel/sun3-head.S
+++ b/arch/m68k/kernel/sun3-head.S
@@ -67,16 +67,6 @@ ENTRY(_start)
671: lea init_task,%curptr | get initial thread... 671: lea init_task,%curptr | get initial thread...
68 lea init_thread_union+THREAD_SIZE,%sp | ...and its stack. 68 lea init_thread_union+THREAD_SIZE,%sp | ...and its stack.
69 69
70/* copy bootinfo records from the loader to _end */
71 lea _end, %a1
72 lea BI_START, %a0
73 /* number of longs to copy */
74 movel %a0@, %d0
751: addl #4, %a0
76 movel %a0@, %a1@
77 addl #4, %a1
78 dbf %d0, 1b
79
80/* Point MSP at an invalid page to trap if it's used. --m */ 70/* Point MSP at an invalid page to trap if it's used. --m */
81 movl #(PAGESIZE),%d0 71 movl #(PAGESIZE),%d0
82 movc %d0,%msp 72 movc %d0,%msp
diff --git a/arch/m68k/kernel/vmlinux-sun3.lds b/arch/m68k/kernel/vmlinux-sun3.lds
index 2550b4ae2732..8c7eccbfc982 100644
--- a/arch/m68k/kernel/vmlinux-sun3.lds
+++ b/arch/m68k/kernel/vmlinux-sun3.lds
@@ -8,7 +8,7 @@ ENTRY(_start)
8jiffies = jiffies_64 + 4; 8jiffies = jiffies_64 + 4;
9SECTIONS 9SECTIONS
10{ 10{
11 . = 0xE004000; 11 . = 0xE002000;
12 _text = .; /* Text and read-only data */ 12 _text = .; /* Text and read-only data */
13 .text : { 13 .text : {
14 *(.head) 14 *(.head)
diff --git a/arch/m68k/mm/memory.c b/arch/m68k/mm/memory.c
index 0f88812822b1..13c0b4ad01eb 100644
--- a/arch/m68k/mm/memory.c
+++ b/arch/m68k/mm/memory.c
@@ -299,7 +299,7 @@ void cache_clear (unsigned long paddr, int len)
299 mach_l2_flush(0); 299 mach_l2_flush(0);
300#endif 300#endif
301} 301}
302EXPORT_SYMBOL(cache_clear); /* probably can be unexported */ 302EXPORT_SYMBOL(cache_clear);
303 303
304 304
305/* 305/*
@@ -352,7 +352,7 @@ void cache_push (unsigned long paddr, int len)
352 mach_l2_flush(1); 352 mach_l2_flush(1);
353#endif 353#endif
354} 354}
355EXPORT_SYMBOL(cache_push); /* probably can be unexported */ 355EXPORT_SYMBOL(cache_push);
356 356
357#ifndef CONFIG_SINGLE_MEMORY_CHUNK 357#ifndef CONFIG_SINGLE_MEMORY_CHUNK
358int mm_end_of_chunk (unsigned long addr, int len) 358int mm_end_of_chunk (unsigned long addr, int len)
diff --git a/arch/m68k/mm/sun3mmu.c b/arch/m68k/mm/sun3mmu.c
index ac6640ade0b1..6a6513aa1ce8 100644
--- a/arch/m68k/mm/sun3mmu.c
+++ b/arch/m68k/mm/sun3mmu.c
@@ -49,7 +49,6 @@ void __init paging_init(void)
49 unsigned long zones_size[MAX_NR_ZONES] = { 0, }; 49 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
50 unsigned long size; 50 unsigned long size;
51 51
52
53#ifdef TEST_VERIFY_AREA 52#ifdef TEST_VERIFY_AREA
54 wp_works_ok = 0; 53 wp_works_ok = 0;
55#endif 54#endif
@@ -94,7 +93,11 @@ void __init paging_init(void)
94 /* memory sizing is a hack stolen from motorola.c.. hope it works for us */ 93 /* memory sizing is a hack stolen from motorola.c.. hope it works for us */
95 zones_size[ZONE_DMA] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT; 94 zones_size[ZONE_DMA] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT;
96 95
97 free_area_init(zones_size); 96 /* I really wish I knew why the following change made things better... -- Sam */
97/* free_area_init(zones_size); */
98 free_area_init_node(0, NODE_DATA(0), zones_size,
99 (__pa(PAGE_OFFSET) >> PAGE_SHIFT) + 1, NULL);
100
98 101
99} 102}
100 103
diff --git a/arch/m68knommu/Kconfig b/arch/m68knommu/Kconfig
index aa70dde54228..25993c2a8fbb 100644
--- a/arch/m68knommu/Kconfig
+++ b/arch/m68knommu/Kconfig
@@ -25,6 +25,14 @@ config RWSEM_XCHGADD_ALGORITHM
25 bool 25 bool
26 default n 26 default n
27 27
28config ARCH_HAS_ILOG2_U32
29 bool
30 default n
31
32config ARCH_HAS_ILOG2_U64
33 bool
34 default n
35
28config GENERIC_FIND_NEXT_BIT 36config GENERIC_FIND_NEXT_BIT
29 bool 37 bool
30 default y 38 default y
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index d8af858fe3f5..fd2ff0698a85 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -165,6 +165,7 @@ config MIPS_COBALT
165 select SYS_SUPPORTS_32BIT_KERNEL 165 select SYS_SUPPORTS_32BIT_KERNEL
166 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL 166 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
167 select SYS_SUPPORTS_LITTLE_ENDIAN 167 select SYS_SUPPORTS_LITTLE_ENDIAN
168 select GENERIC_HARDIRQS_NO__DO_IRQ
168 169
169config MACH_DECSTATION 170config MACH_DECSTATION
170 bool "DECstations" 171 bool "DECstations"
@@ -225,6 +226,7 @@ config MACH_JAZZ
225 select SYS_SUPPORTS_32BIT_KERNEL 226 select SYS_SUPPORTS_32BIT_KERNEL
226 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL 227 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
227 select SYS_SUPPORTS_100HZ 228 select SYS_SUPPORTS_100HZ
229 select GENERIC_HARDIRQS_NO__DO_IRQ
228 help 230 help
229 This a family of machines based on the MIPS R4030 chipset which was 231 This a family of machines based on the MIPS R4030 chipset which was
230 used by several vendors to build RISC/os and Windows NT workstations. 232 used by several vendors to build RISC/os and Windows NT workstations.
@@ -459,6 +461,11 @@ config PNX8550_JBS
459 select PNX8550 461 select PNX8550
460 select SYS_SUPPORTS_LITTLE_ENDIAN 462 select SYS_SUPPORTS_LITTLE_ENDIAN
461 463
464config PNX8550_STB810
465 bool "Support for Philips PNX8550 based STB810 board"
466 select PNX8550
467 select SYS_SUPPORTS_LITTLE_ENDIAN
468
462config DDB5477 469config DDB5477
463 bool "NEC DDB Vrc-5477" 470 bool "NEC DDB Vrc-5477"
464 select DDB5XXX_COMMON 471 select DDB5XXX_COMMON
@@ -482,6 +489,7 @@ config MACH_VR41XX
482 select SYS_HAS_CPU_VR41XX 489 select SYS_HAS_CPU_VR41XX
483 select SYS_SUPPORTS_32BIT_KERNEL 490 select SYS_SUPPORTS_32BIT_KERNEL
484 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL 491 select SYS_SUPPORTS_64BIT_KERNEL if EXPERIMENTAL
492 select GENERIC_HARDIRQS_NO__DO_IRQ
485 493
486config PMC_YOSEMITE 494config PMC_YOSEMITE
487 bool "PMC-Sierra Yosemite eval board" 495 bool "PMC-Sierra Yosemite eval board"
@@ -515,6 +523,7 @@ config QEMU
515 select SYS_SUPPORTS_BIG_ENDIAN 523 select SYS_SUPPORTS_BIG_ENDIAN
516 select SYS_SUPPORTS_LITTLE_ENDIAN 524 select SYS_SUPPORTS_LITTLE_ENDIAN
517 select ARCH_SPARSEMEM_ENABLE 525 select ARCH_SPARSEMEM_ENABLE
526 select GENERIC_HARDIRQS_NO__DO_IRQ
518 help 527 help
519 Qemu is a software emulator which among other architectures also 528 Qemu is a software emulator which among other architectures also
520 can simulate a MIPS32 4Kc system. This patch adds support for the 529 can simulate a MIPS32 4Kc system. This patch adds support for the
@@ -701,8 +710,8 @@ config SIBYTE_CRHONE
701 select SYS_SUPPORTS_HIGHMEM 710 select SYS_SUPPORTS_HIGHMEM
702 select SYS_SUPPORTS_LITTLE_ENDIAN 711 select SYS_SUPPORTS_LITTLE_ENDIAN
703 712
704config SNI_RM200_PCI 713config SNI_RM
705 bool "SNI RM200 PCI" 714 bool "SNI RM200/300/400"
706 select ARC if CPU_LITTLE_ENDIAN 715 select ARC if CPU_LITTLE_ENDIAN
707 select ARC32 if CPU_LITTLE_ENDIAN 716 select ARC32 if CPU_LITTLE_ENDIAN
708 select ARCH_MAY_HAVE_PC_FDC 717 select ARCH_MAY_HAVE_PC_FDC
@@ -725,8 +734,8 @@ config SNI_RM200_PCI
725 select SYS_SUPPORTS_HIGHMEM 734 select SYS_SUPPORTS_HIGHMEM
726 select SYS_SUPPORTS_LITTLE_ENDIAN 735 select SYS_SUPPORTS_LITTLE_ENDIAN
727 help 736 help
728 The SNI RM200 PCI was a MIPS-based platform manufactured by Siemens 737 The SNI RM200/300/400 are MIPS-based machines manufactured by
729 Nixdorf Informationssysteme (SNI), parent company of Pyramid 738 Siemens Nixdorf Informationssysteme (SNI), parent company of Pyramid
730 Technology and now in turn merged with Fujitsu. Say Y here to 739 Technology and now in turn merged with Fujitsu. Say Y here to
731 support this machine type. 740 support this machine type.
732 741
@@ -754,6 +763,7 @@ config TOSHIBA_RBTX4927
754 select SYS_SUPPORTS_64BIT_KERNEL 763 select SYS_SUPPORTS_64BIT_KERNEL
755 select SYS_SUPPORTS_BIG_ENDIAN 764 select SYS_SUPPORTS_BIG_ENDIAN
756 select TOSHIBA_BOARDS 765 select TOSHIBA_BOARDS
766 select GENERIC_HARDIRQS_NO__DO_IRQ
757 help 767 help
758 This Toshiba board is based on the TX4927 processor. Say Y here to 768 This Toshiba board is based on the TX4927 processor. Say Y here to
759 support this machine type 769 support this machine type
@@ -773,6 +783,7 @@ config TOSHIBA_RBTX4938
773 select SYS_SUPPORTS_LITTLE_ENDIAN 783 select SYS_SUPPORTS_LITTLE_ENDIAN
774 select SYS_SUPPORTS_BIG_ENDIAN 784 select SYS_SUPPORTS_BIG_ENDIAN
775 select TOSHIBA_BOARDS 785 select TOSHIBA_BOARDS
786 select GENERIC_HARDIRQS_NO__DO_IRQ
776 help 787 help
777 This Toshiba board is based on the TX4938 processor. Say Y here to 788 This Toshiba board is based on the TX4938 processor. Say Y here to
778 support this machine type 789 support this machine type
@@ -819,6 +830,14 @@ config RWSEM_GENERIC_SPINLOCK
819config RWSEM_XCHGADD_ALGORITHM 830config RWSEM_XCHGADD_ALGORITHM
820 bool 831 bool
821 832
833config ARCH_HAS_ILOG2_U32
834 bool
835 default n
836
837config ARCH_HAS_ILOG2_U64
838 bool
839 default n
840
822config GENERIC_FIND_NEXT_BIT 841config GENERIC_FIND_NEXT_BIT
823 bool 842 bool
824 default y 843 default y
@@ -1062,16 +1081,16 @@ config HAVE_STD_PC_SERIAL_PORT
1062 1081
1063config ARC_CONSOLE 1082config ARC_CONSOLE
1064 bool "ARC console support" 1083 bool "ARC console support"
1065 depends on SGI_IP22 || SNI_RM200_PCI 1084 depends on SGI_IP22 || SNI_RM
1066 1085
1067config ARC_MEMORY 1086config ARC_MEMORY
1068 bool 1087 bool
1069 depends on MACH_JAZZ || SNI_RM200_PCI || SGI_IP32 1088 depends on MACH_JAZZ || SNI_RM || SGI_IP32
1070 default y 1089 default y
1071 1090
1072config ARC_PROMLIB 1091config ARC_PROMLIB
1073 bool 1092 bool
1074 depends on MACH_JAZZ || SNI_RM200_PCI || SGI_IP22 || SGI_IP32 1093 depends on MACH_JAZZ || SNI_RM || SGI_IP22 || SGI_IP32
1075 default y 1094 default y
1076 1095
1077config ARC64 1096config ARC64
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 641aa30b3638..d1b026a0337d 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -463,6 +463,11 @@ libs-$(CONFIG_PNX8550_JBS) += arch/mips/philips/pnx8550/jbs/
463#cflags-$(CONFIG_PNX8550_JBS) += -Iinclude/asm-mips/mach-pnx8550 463#cflags-$(CONFIG_PNX8550_JBS) += -Iinclude/asm-mips/mach-pnx8550
464load-$(CONFIG_PNX8550_JBS) += 0xffffffff80060000 464load-$(CONFIG_PNX8550_JBS) += 0xffffffff80060000
465 465
466# Philips PNX8550 STB810 board
467#
468libs-$(CONFIG_PNX8550_STB810) += arch/mips/philips/pnx8550/stb810/
469load-$(CONFIG_PNX8550_STB810) += 0xffffffff80060000
470
466# NEC EMMA2RH boards 471# NEC EMMA2RH boards
467# 472#
468core-$(CONFIG_EMMA2RH) += arch/mips/emma2rh/common/ 473core-$(CONFIG_EMMA2RH) += arch/mips/emma2rh/common/
@@ -569,11 +574,11 @@ libs-$(CONFIG_SIBYTE_BIGSUR) += arch/mips/sibyte/swarm/
569load-$(CONFIG_SIBYTE_BIGSUR) := 0xffffffff80100000 574load-$(CONFIG_SIBYTE_BIGSUR) := 0xffffffff80100000
570 575
571# 576#
572# SNI RM200 PCI 577# SNI RM
573# 578#
574core-$(CONFIG_SNI_RM200_PCI) += arch/mips/sni/ 579core-$(CONFIG_SNI_RM) += arch/mips/sni/
575cflags-$(CONFIG_SNI_RM200_PCI) += -Iinclude/asm-mips/mach-rm200 580cflags-$(CONFIG_SNI_RM) += -Iinclude/asm-mips/mach-rm
576load-$(CONFIG_SNI_RM200_PCI) += 0xffffffff80600000 581load-$(CONFIG_SNI_RM) += 0xffffffff80600000
577 582
578# 583#
579# Toshiba JMR-TX3927 board 584# Toshiba JMR-TX3927 board
@@ -695,7 +700,7 @@ ifdef CONFIG_QEMU
695all: vmlinux.bin 700all: vmlinux.bin
696endif 701endif
697 702
698ifdef CONFIG_SNI_RM200_PCI 703ifdef CONFIG_SNI_RM
699all: vmlinux.ecoff 704all: vmlinux.ecoff
700endif 705endif
701 706
diff --git a/arch/mips/configs/atlas_defconfig b/arch/mips/configs/atlas_defconfig
index 35931bedc3df..ac1891687520 100644
--- a/arch/mips/configs/atlas_defconfig
+++ b/arch/mips/configs/atlas_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_ATLAS=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/bigsur_defconfig b/arch/mips/configs/bigsur_defconfig
index ba3bf733d27d..9554257c6f3a 100644
--- a/arch/mips/configs/bigsur_defconfig
+++ b/arch/mips/configs/bigsur_defconfig
@@ -57,7 +57,7 @@ CONFIG_SIBYTE_BIGSUR=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/capcella_defconfig b/arch/mips/configs/capcella_defconfig
index e5358121d2da..49590d443712 100644
--- a/arch/mips/configs/capcella_defconfig
+++ b/arch/mips/configs/capcella_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/cobalt_defconfig b/arch/mips/configs/cobalt_defconfig
index adf1e8c98c65..0607fc239087 100644
--- a/arch/mips/configs/cobalt_defconfig
+++ b/arch/mips/configs/cobalt_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_COBALT=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/db1000_defconfig b/arch/mips/configs/db1000_defconfig
index 4fd29ffdfb8d..1a57b3375483 100644
--- a/arch/mips/configs/db1000_defconfig
+++ b/arch/mips/configs/db1000_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_DB1000=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/db1100_defconfig b/arch/mips/configs/db1100_defconfig
index 025b960ba990..0055ec41f207 100644
--- a/arch/mips/configs/db1100_defconfig
+++ b/arch/mips/configs/db1100_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_DB1100=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/db1200_defconfig b/arch/mips/configs/db1200_defconfig
index 80c9dd98f897..c41823b81be0 100644
--- a/arch/mips/configs/db1200_defconfig
+++ b/arch/mips/configs/db1200_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_DB1200=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/db1500_defconfig b/arch/mips/configs/db1500_defconfig
index 6caa90b0e176..7d6d92187880 100644
--- a/arch/mips/configs/db1500_defconfig
+++ b/arch/mips/configs/db1500_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_DB1500=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/db1550_defconfig b/arch/mips/configs/db1550_defconfig
index c6cae86c6ab7..c681c91763aa 100644
--- a/arch/mips/configs/db1550_defconfig
+++ b/arch/mips/configs/db1550_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_DB1550=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ddb5477_defconfig b/arch/mips/configs/ddb5477_defconfig
index 72f24001c99e..dd4bb0080211 100644
--- a/arch/mips/configs/ddb5477_defconfig
+++ b/arch/mips/configs/ddb5477_defconfig
@@ -59,7 +59,7 @@ CONFIG_DDB5477=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/decstation_defconfig b/arch/mips/configs/decstation_defconfig
index fe1387eb83c9..8a31ce4be12c 100644
--- a/arch/mips/configs/decstation_defconfig
+++ b/arch/mips/configs/decstation_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_DECSTATION=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/e55_defconfig b/arch/mips/configs/e55_defconfig
index 6133c28beb8c..6fa4f914f6e4 100644
--- a/arch/mips/configs/e55_defconfig
+++ b/arch/mips/configs/e55_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/emma2rh_defconfig b/arch/mips/configs/emma2rh_defconfig
index a484b7d396fc..4c9d0405a5df 100644
--- a/arch/mips/configs/emma2rh_defconfig
+++ b/arch/mips/configs/emma2rh_defconfig
@@ -59,7 +59,7 @@ CONFIG_MARKEINS=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ev64120_defconfig b/arch/mips/configs/ev64120_defconfig
index 21bfcdebf8f5..d5b49735683b 100644
--- a/arch/mips/configs/ev64120_defconfig
+++ b/arch/mips/configs/ev64120_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_EV64120=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/excite_defconfig b/arch/mips/configs/excite_defconfig
index 1a5b06cfb4d6..697140c6562f 100644
--- a/arch/mips/configs/excite_defconfig
+++ b/arch/mips/configs/excite_defconfig
@@ -60,7 +60,7 @@ CONFIG_BASLER_EXCITE=y
60# CONFIG_SIBYTE_LITTLESUR is not set 60# CONFIG_SIBYTE_LITTLESUR is not set
61# CONFIG_SIBYTE_CRHINE is not set 61# CONFIG_SIBYTE_CRHINE is not set
62# CONFIG_SIBYTE_CRHONE is not set 62# CONFIG_SIBYTE_CRHONE is not set
63# CONFIG_SNI_RM200_PCI is not set 63# CONFIG_SNI_RM is not set
64# CONFIG_TOSHIBA_JMR3927 is not set 64# CONFIG_TOSHIBA_JMR3927 is not set
65# CONFIG_TOSHIBA_RBTX4927 is not set 65# CONFIG_TOSHIBA_RBTX4927 is not set
66# CONFIG_TOSHIBA_RBTX4938 is not set 66# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ip22_defconfig b/arch/mips/configs/ip22_defconfig
index 21d53e0c9ee8..f9812d1e4579 100644
--- a/arch/mips/configs/ip22_defconfig
+++ b/arch/mips/configs/ip22_defconfig
@@ -59,7 +59,7 @@ CONFIG_SGI_IP22=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ip27_defconfig b/arch/mips/configs/ip27_defconfig
index e3e94c7e5ee1..96090f28373b 100644
--- a/arch/mips/configs/ip27_defconfig
+++ b/arch/mips/configs/ip27_defconfig
@@ -59,7 +59,7 @@ CONFIG_SGI_IP27=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ip32_defconfig b/arch/mips/configs/ip32_defconfig
index b4ab2bea9723..61e069a0f1aa 100644
--- a/arch/mips/configs/ip32_defconfig
+++ b/arch/mips/configs/ip32_defconfig
@@ -59,7 +59,7 @@ CONFIG_SGI_IP32=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/jaguar-atx_defconfig b/arch/mips/configs/jaguar-atx_defconfig
index 9d4d17ace123..88966666f4c6 100644
--- a/arch/mips/configs/jaguar-atx_defconfig
+++ b/arch/mips/configs/jaguar-atx_defconfig
@@ -59,7 +59,7 @@ CONFIG_MOMENCO_JAGUAR_ATX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/jazz_defconfig b/arch/mips/configs/jazz_defconfig
index 382083ebea0a..835764d834f7 100644
--- a/arch/mips/configs/jazz_defconfig
+++ b/arch/mips/configs/jazz_defconfig
@@ -57,7 +57,7 @@ CONFIG_MACH_JAZZ=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/jmr3927_defconfig b/arch/mips/configs/jmr3927_defconfig
index d03746667a96..50fd9557e646 100644
--- a/arch/mips/configs/jmr3927_defconfig
+++ b/arch/mips/configs/jmr3927_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63CONFIG_TOSHIBA_JMR3927=y 63CONFIG_TOSHIBA_JMR3927=y
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/lasat200_defconfig b/arch/mips/configs/lasat200_defconfig
index 1db8249b4c0f..05f539f84f58 100644
--- a/arch/mips/configs/lasat200_defconfig
+++ b/arch/mips/configs/lasat200_defconfig
@@ -59,7 +59,7 @@ CONFIG_LASAT=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/malta_defconfig b/arch/mips/configs/malta_defconfig
index 101e80347dce..96e941084c04 100644
--- a/arch/mips/configs/malta_defconfig
+++ b/arch/mips/configs/malta_defconfig
@@ -57,7 +57,7 @@ CONFIG_MIPS_MALTA=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
@@ -644,7 +644,85 @@ CONFIG_CONNECTOR=m
644# 644#
645# Memory Technology Devices (MTD) 645# Memory Technology Devices (MTD)
646# 646#
647# CONFIG_MTD is not set 647CONFIG_MTD=y
648# CONFIG_MTD_DEBUG is not set
649# CONFIG_MTD_CONCAT is not set
650CONFIG_MTD_PARTITIONS=y
651# CONFIG_MTD_REDBOOT_PARTS is not set
652# CONFIG_MTD_CMDLINE_PARTS is not set
653
654#
655# User Modules And Translation Layers
656#
657CONFIG_MTD_CHAR=y
658CONFIG_MTD_BLOCK=y
659# CONFIG_FTL is not set
660# CONFIG_NFTL is not set
661# CONFIG_INFTL is not set
662# CONFIG_RFD_FTL is not set
663# CONFIG_SSFDC is not set
664
665#
666# RAM/ROM/Flash chip drivers
667#
668CONFIG_MTD_CFI=y
669# CONFIG_MTD_JEDECPROBE is not set
670CONFIG_MTD_GEN_PROBE=y
671# CONFIG_MTD_CFI_ADV_OPTIONS is not set
672CONFIG_MTD_MAP_BANK_WIDTH_1=y
673CONFIG_MTD_MAP_BANK_WIDTH_2=y
674CONFIG_MTD_MAP_BANK_WIDTH_4=y
675# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
676# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
677# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
678CONFIG_MTD_CFI_I1=y
679CONFIG_MTD_CFI_I2=y
680# CONFIG_MTD_CFI_I4 is not set
681# CONFIG_MTD_CFI_I8 is not set
682CONFIG_MTD_CFI_INTELEXT=y
683CONFIG_MTD_CFI_AMDSTD=y
684CONFIG_MTD_CFI_STAA=y
685CONFIG_MTD_CFI_UTIL=y
686# CONFIG_MTD_RAM is not set
687# CONFIG_MTD_ROM is not set
688# CONFIG_MTD_ABSENT is not set
689# CONFIG_MTD_OBSOLETE_CHIPS is not set
690
691#
692# Mapping drivers for chip access
693#
694# CONFIG_MTD_COMPLEX_MAPPINGS is not set
695CONFIG_MTD_PHYSMAP=y
696CONFIG_MTD_PHYSMAP_START=0x0
697CONFIG_MTD_PHYSMAP_LEN=0x0
698CONFIG_MTD_PHYSMAP_BANKWIDTH=0
699# CONFIG_MTD_PLATRAM is not set
700
701#
702# Self-contained MTD device drivers
703#
704# CONFIG_MTD_PMC551 is not set
705# CONFIG_MTD_SLRAM is not set
706# CONFIG_MTD_PHRAM is not set
707# CONFIG_MTD_MTDRAM is not set
708# CONFIG_MTD_BLOCK2MTD is not set
709
710#
711# Disk-On-Chip Device Drivers
712#
713# CONFIG_MTD_DOC2000 is not set
714# CONFIG_MTD_DOC2001 is not set
715# CONFIG_MTD_DOC2001PLUS is not set
716
717#
718# NAND Flash Device Drivers
719#
720# CONFIG_MTD_NAND is not set
721
722#
723# OneNAND Flash Device Drivers
724#
725# CONFIG_MTD_ONENAND is not set
648 726
649# 727#
650# Parallel port support 728# Parallel port support
diff --git a/arch/mips/configs/mipssim_defconfig b/arch/mips/configs/mipssim_defconfig
index a3cbd23bf217..03efcfd0503b 100644
--- a/arch/mips/configs/mipssim_defconfig
+++ b/arch/mips/configs/mipssim_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_SIM=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/mpc30x_defconfig b/arch/mips/configs/mpc30x_defconfig
index 6570b47426ce..e4221aafbc4c 100644
--- a/arch/mips/configs/mpc30x_defconfig
+++ b/arch/mips/configs/mpc30x_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ocelot_3_defconfig b/arch/mips/configs/ocelot_3_defconfig
index 440d65f93a94..32b1afdd1c20 100644
--- a/arch/mips/configs/ocelot_3_defconfig
+++ b/arch/mips/configs/ocelot_3_defconfig
@@ -59,7 +59,7 @@ CONFIG_MOMENCO_OCELOT_3=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ocelot_c_defconfig b/arch/mips/configs/ocelot_c_defconfig
index c2c7ae77da3e..ebe75c1c71af 100644
--- a/arch/mips/configs/ocelot_c_defconfig
+++ b/arch/mips/configs/ocelot_c_defconfig
@@ -59,7 +59,7 @@ CONFIG_MOMENCO_OCELOT_C=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ocelot_defconfig b/arch/mips/configs/ocelot_defconfig
index 67efe270e0cc..5a9603c12902 100644
--- a/arch/mips/configs/ocelot_defconfig
+++ b/arch/mips/configs/ocelot_defconfig
@@ -59,7 +59,7 @@ CONFIG_MOMENCO_OCELOT=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/ocelot_g_defconfig b/arch/mips/configs/ocelot_g_defconfig
index a10f34de5f7e..46a942c253cf 100644
--- a/arch/mips/configs/ocelot_g_defconfig
+++ b/arch/mips/configs/ocelot_g_defconfig
@@ -59,7 +59,7 @@ CONFIG_MOMENCO_OCELOT_G=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/pb1100_defconfig b/arch/mips/configs/pb1100_defconfig
index 9e672f63a0aa..7d3c688181d5 100644
--- a/arch/mips/configs/pb1100_defconfig
+++ b/arch/mips/configs/pb1100_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_PB1100=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/pb1500_defconfig b/arch/mips/configs/pb1500_defconfig
index d0c0f4af1bff..a77805af0819 100644
--- a/arch/mips/configs/pb1500_defconfig
+++ b/arch/mips/configs/pb1500_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_PB1500=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/pb1550_defconfig b/arch/mips/configs/pb1550_defconfig
index 3db7427d1b55..8318d74d6adb 100644
--- a/arch/mips/configs/pb1550_defconfig
+++ b/arch/mips/configs/pb1550_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_PB1550=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/pnx8550-jbs_defconfig b/arch/mips/configs/pnx8550-jbs_defconfig
index 280a8001eacf..fcb8fea3052c 100644
--- a/arch/mips/configs/pnx8550-jbs_defconfig
+++ b/arch/mips/configs/pnx8550-jbs_defconfig
@@ -57,7 +57,7 @@ CONFIG_PNX8550_JBS=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/pnx8550-stb810_defconfig b/arch/mips/configs/pnx8550-stb810_defconfig
new file mode 100644
index 000000000000..f38a2c123037
--- /dev/null
+++ b/arch/mips/configs/pnx8550-stb810_defconfig
@@ -0,0 +1,1229 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19
4# Thu Dec 7 16:35:12 2006
5#
6CONFIG_MIPS=y
7
8#
9# Machine selection
10#
11# CONFIG_MIPS_MTX1 is not set
12# CONFIG_MIPS_BOSPORUS is not set
13# CONFIG_MIPS_PB1000 is not set
14# CONFIG_MIPS_PB1100 is not set
15# CONFIG_MIPS_PB1500 is not set
16# CONFIG_MIPS_PB1550 is not set
17# CONFIG_MIPS_PB1200 is not set
18# CONFIG_MIPS_DB1000 is not set
19# CONFIG_MIPS_DB1100 is not set
20# CONFIG_MIPS_DB1500 is not set
21# CONFIG_MIPS_DB1550 is not set
22# CONFIG_MIPS_DB1200 is not set
23# CONFIG_MIPS_MIRAGE is not set
24# CONFIG_BASLER_EXCITE is not set
25# CONFIG_MIPS_COBALT is not set
26# CONFIG_MACH_DECSTATION is not set
27# CONFIG_MIPS_EV64120 is not set
28# CONFIG_MACH_JAZZ is not set
29# CONFIG_LASAT is not set
30# CONFIG_MIPS_ATLAS is not set
31# CONFIG_MIPS_MALTA is not set
32# CONFIG_MIPS_SEAD is not set
33# CONFIG_WR_PPMC is not set
34# CONFIG_MIPS_SIM is not set
35# CONFIG_MOMENCO_JAGUAR_ATX is not set
36# CONFIG_MOMENCO_OCELOT is not set
37# CONFIG_MOMENCO_OCELOT_3 is not set
38# CONFIG_MOMENCO_OCELOT_C is not set
39# CONFIG_MOMENCO_OCELOT_G is not set
40# CONFIG_MIPS_XXS1500 is not set
41# CONFIG_PNX8550_V2PCI is not set
42# CONFIG_PNX8550_JBS is not set
43CONFIG_PNX8550_STB810=y
44# CONFIG_DDB5477 is not set
45# CONFIG_MACH_VR41XX is not set
46# CONFIG_PMC_YOSEMITE is not set
47# CONFIG_QEMU is not set
48# CONFIG_MARKEINS is not set
49# CONFIG_SGI_IP22 is not set
50# CONFIG_SGI_IP27 is not set
51# CONFIG_SGI_IP32 is not set
52# CONFIG_SIBYTE_BIGSUR is not set
53# CONFIG_SIBYTE_SWARM is not set
54# CONFIG_SIBYTE_SENTOSA is not set
55# CONFIG_SIBYTE_RHONE is not set
56# CONFIG_SIBYTE_CARMEL is not set
57# CONFIG_SIBYTE_PTSWARM is not set
58# CONFIG_SIBYTE_LITTLESUR is not set
59# CONFIG_SIBYTE_CRHINE is not set
60# CONFIG_SIBYTE_CRHONE is not set
61# CONFIG_SNI_RM200_PCI is not set
62# CONFIG_TOSHIBA_JMR3927 is not set
63# CONFIG_TOSHIBA_RBTX4927 is not set
64# CONFIG_TOSHIBA_RBTX4938 is not set
65# CONFIG_KEXEC is not set
66CONFIG_RWSEM_GENERIC_SPINLOCK=y
67CONFIG_GENERIC_FIND_NEXT_BIT=y
68CONFIG_GENERIC_HWEIGHT=y
69CONFIG_GENERIC_CALIBRATE_DELAY=y
70CONFIG_GENERIC_TIME=y
71CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER=y
72CONFIG_DMA_NONCOHERENT=y
73CONFIG_DMA_NEED_PCI_MAP_STATE=y
74# CONFIG_CPU_BIG_ENDIAN is not set
75CONFIG_CPU_LITTLE_ENDIAN=y
76CONFIG_SYS_SUPPORTS_LITTLE_ENDIAN=y
77CONFIG_PNX8550=y
78CONFIG_SOC_PNX8550=y
79CONFIG_MIPS_L1_CACHE_SHIFT=5
80
81#
82# CPU selection
83#
84CONFIG_CPU_MIPS32_R1=y
85# CONFIG_CPU_MIPS32_R2 is not set
86# CONFIG_CPU_MIPS64_R1 is not set
87# CONFIG_CPU_MIPS64_R2 is not set
88# CONFIG_CPU_R3000 is not set
89# CONFIG_CPU_TX39XX is not set
90# CONFIG_CPU_VR41XX is not set
91# CONFIG_CPU_R4300 is not set
92# CONFIG_CPU_R4X00 is not set
93# CONFIG_CPU_TX49XX is not set
94# CONFIG_CPU_R5000 is not set
95# CONFIG_CPU_R5432 is not set
96# CONFIG_CPU_R6000 is not set
97# CONFIG_CPU_NEVADA is not set
98# CONFIG_CPU_R8000 is not set
99# CONFIG_CPU_R10000 is not set
100# CONFIG_CPU_RM7000 is not set
101# CONFIG_CPU_RM9000 is not set
102# CONFIG_CPU_SB1 is not set
103CONFIG_SYS_HAS_CPU_MIPS32_R1=y
104CONFIG_CPU_MIPS32=y
105CONFIG_CPU_MIPSR1=y
106CONFIG_SYS_SUPPORTS_32BIT_KERNEL=y
107CONFIG_CPU_SUPPORTS_32BIT_KERNEL=y
108
109#
110# Kernel type
111#
112CONFIG_32BIT=y
113# CONFIG_64BIT is not set
114CONFIG_PAGE_SIZE_4KB=y
115# CONFIG_PAGE_SIZE_8KB is not set
116# CONFIG_PAGE_SIZE_16KB is not set
117# CONFIG_PAGE_SIZE_64KB is not set
118CONFIG_CPU_HAS_PREFETCH=y
119CONFIG_MIPS_MT_DISABLED=y
120# CONFIG_MIPS_MT_SMP is not set
121# CONFIG_MIPS_MT_SMTC is not set
122# CONFIG_MIPS_VPE_LOADER is not set
123# CONFIG_64BIT_PHYS_ADDR is not set
124CONFIG_CPU_HAS_LLSC=y
125CONFIG_CPU_HAS_SYNC=y
126CONFIG_GENERIC_HARDIRQS=y
127CONFIG_GENERIC_IRQ_PROBE=y
128CONFIG_CPU_SUPPORTS_HIGHMEM=y
129CONFIG_ARCH_FLATMEM_ENABLE=y
130CONFIG_SELECT_MEMORY_MODEL=y
131CONFIG_FLATMEM_MANUAL=y
132# CONFIG_DISCONTIGMEM_MANUAL is not set
133# CONFIG_SPARSEMEM_MANUAL is not set
134CONFIG_FLATMEM=y
135CONFIG_FLAT_NODE_MEM_MAP=y
136# CONFIG_SPARSEMEM_STATIC is not set
137CONFIG_SPLIT_PTLOCK_CPUS=4
138# CONFIG_RESOURCES_64BIT is not set
139# CONFIG_HZ_48 is not set
140# CONFIG_HZ_100 is not set
141# CONFIG_HZ_128 is not set
142CONFIG_HZ_250=y
143# CONFIG_HZ_256 is not set
144# CONFIG_HZ_1000 is not set
145# CONFIG_HZ_1024 is not set
146CONFIG_SYS_SUPPORTS_ARBIT_HZ=y
147CONFIG_HZ=250
148CONFIG_PREEMPT_NONE=y
149# CONFIG_PREEMPT_VOLUNTARY is not set
150# CONFIG_PREEMPT is not set
151CONFIG_LOCKDEP_SUPPORT=y
152CONFIG_STACKTRACE_SUPPORT=y
153CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
154
155#
156# Code maturity level options
157#
158CONFIG_EXPERIMENTAL=y
159CONFIG_BROKEN_ON_SMP=y
160CONFIG_INIT_ENV_ARG_LIMIT=32
161
162#
163# General setup
164#
165CONFIG_LOCALVERSION=""
166CONFIG_LOCALVERSION_AUTO=y
167CONFIG_SWAP=y
168CONFIG_SYSVIPC=y
169# CONFIG_IPC_NS is not set
170# CONFIG_POSIX_MQUEUE is not set
171# CONFIG_BSD_PROCESS_ACCT is not set
172# CONFIG_TASKSTATS is not set
173# CONFIG_UTS_NS is not set
174# CONFIG_AUDIT is not set
175CONFIG_IKCONFIG=y
176CONFIG_IKCONFIG_PROC=y
177CONFIG_SYSFS_DEPRECATED=y
178# CONFIG_RELAY is not set
179CONFIG_INITRAMFS_SOURCE=""
180# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
181CONFIG_SYSCTL=y
182CONFIG_EMBEDDED=y
183# CONFIG_SYSCTL_SYSCALL is not set
184CONFIG_KALLSYMS=y
185# CONFIG_KALLSYMS_ALL is not set
186# CONFIG_KALLSYMS_EXTRA_PASS is not set
187# CONFIG_HOTPLUG is not set
188CONFIG_PRINTK=y
189CONFIG_BUG=y
190CONFIG_ELF_CORE=y
191CONFIG_BASE_FULL=y
192CONFIG_FUTEX=y
193CONFIG_EPOLL=y
194CONFIG_SHMEM=y
195CONFIG_SLAB=y
196CONFIG_VM_EVENT_COUNTERS=y
197CONFIG_RT_MUTEXES=y
198# CONFIG_TINY_SHMEM is not set
199CONFIG_BASE_SMALL=0
200# CONFIG_SLOB is not set
201
202#
203# Loadable module support
204#
205CONFIG_MODULES=y
206# CONFIG_MODULE_UNLOAD is not set
207# CONFIG_MODVERSIONS is not set
208# CONFIG_MODULE_SRCVERSION_ALL is not set
209CONFIG_KMOD=y
210
211#
212# Block layer
213#
214CONFIG_BLOCK=y
215# CONFIG_LBD is not set
216# CONFIG_BLK_DEV_IO_TRACE is not set
217# CONFIG_LSF is not set
218
219#
220# IO Schedulers
221#
222CONFIG_IOSCHED_NOOP=y
223CONFIG_IOSCHED_AS=y
224CONFIG_IOSCHED_DEADLINE=y
225CONFIG_IOSCHED_CFQ=y
226CONFIG_DEFAULT_AS=y
227# CONFIG_DEFAULT_DEADLINE is not set
228# CONFIG_DEFAULT_CFQ is not set
229# CONFIG_DEFAULT_NOOP is not set
230CONFIG_DEFAULT_IOSCHED="anticipatory"
231
232#
233# Bus options (PCI, PCMCIA, EISA, ISA, TC)
234#
235CONFIG_HW_HAS_PCI=y
236CONFIG_PCI=y
237# CONFIG_PCI_MULTITHREAD_PROBE is not set
238# CONFIG_PCI_DEBUG is not set
239CONFIG_MMU=y
240
241#
242# PCCARD (PCMCIA/CardBus) support
243#
244
245#
246# PCI Hotplug Support
247#
248
249#
250# Executable file formats
251#
252CONFIG_BINFMT_ELF=y
253# CONFIG_BINFMT_MISC is not set
254CONFIG_TRAD_SIGNALS=y
255
256#
257# Networking
258#
259CONFIG_NET=y
260
261#
262# Networking options
263#
264# CONFIG_NETDEBUG is not set
265CONFIG_PACKET=y
266# CONFIG_PACKET_MMAP is not set
267CONFIG_UNIX=y
268CONFIG_XFRM=y
269# CONFIG_XFRM_USER is not set
270# CONFIG_XFRM_SUB_POLICY is not set
271# CONFIG_NET_KEY is not set
272CONFIG_INET=y
273# CONFIG_IP_MULTICAST is not set
274# CONFIG_IP_ADVANCED_ROUTER is not set
275CONFIG_IP_FIB_HASH=y
276CONFIG_IP_PNP=y
277CONFIG_IP_PNP_DHCP=y
278CONFIG_IP_PNP_BOOTP=y
279# CONFIG_IP_PNP_RARP is not set
280# CONFIG_NET_IPIP is not set
281# CONFIG_NET_IPGRE is not set
282# CONFIG_ARPD is not set
283# CONFIG_SYN_COOKIES is not set
284# CONFIG_INET_AH is not set
285# CONFIG_INET_ESP is not set
286# CONFIG_INET_IPCOMP is not set
287# CONFIG_INET_XFRM_TUNNEL is not set
288# CONFIG_INET_TUNNEL is not set
289CONFIG_INET_XFRM_MODE_TRANSPORT=y
290CONFIG_INET_XFRM_MODE_TUNNEL=y
291CONFIG_INET_XFRM_MODE_BEET=y
292CONFIG_INET_DIAG=y
293CONFIG_INET_TCP_DIAG=y
294# CONFIG_TCP_CONG_ADVANCED is not set
295CONFIG_TCP_CONG_CUBIC=y
296CONFIG_DEFAULT_TCP_CONG="cubic"
297# CONFIG_TCP_MD5SIG is not set
298# CONFIG_IPV6 is not set
299# CONFIG_INET6_XFRM_TUNNEL is not set
300# CONFIG_INET6_TUNNEL is not set
301# CONFIG_NETWORK_SECMARK is not set
302# CONFIG_NETFILTER is not set
303
304#
305# DCCP Configuration (EXPERIMENTAL)
306#
307# CONFIG_IP_DCCP is not set
308
309#
310# SCTP Configuration (EXPERIMENTAL)
311#
312# CONFIG_IP_SCTP is not set
313
314#
315# TIPC Configuration (EXPERIMENTAL)
316#
317# CONFIG_TIPC is not set
318# CONFIG_ATM is not set
319# CONFIG_BRIDGE is not set
320# CONFIG_VLAN_8021Q is not set
321# CONFIG_DECNET is not set
322# CONFIG_LLC2 is not set
323# CONFIG_IPX is not set
324# CONFIG_ATALK is not set
325# CONFIG_X25 is not set
326# CONFIG_LAPB is not set
327# CONFIG_ECONET is not set
328# CONFIG_WAN_ROUTER is not set
329
330#
331# QoS and/or fair queueing
332#
333# CONFIG_NET_SCHED is not set
334
335#
336# Network testing
337#
338# CONFIG_NET_PKTGEN is not set
339# CONFIG_HAMRADIO is not set
340# CONFIG_IRDA is not set
341# CONFIG_BT is not set
342# CONFIG_IEEE80211 is not set
343
344#
345# Device Drivers
346#
347
348#
349# Generic Driver Options
350#
351CONFIG_STANDALONE=y
352CONFIG_PREVENT_FIRMWARE_BUILD=y
353# CONFIG_DEBUG_DRIVER is not set
354# CONFIG_SYS_HYPERVISOR is not set
355
356#
357# Connector - unified userspace <-> kernelspace linker
358#
359# CONFIG_CONNECTOR is not set
360
361#
362# Memory Technology Devices (MTD)
363#
364# CONFIG_MTD is not set
365
366#
367# Parallel port support
368#
369# CONFIG_PARPORT is not set
370
371#
372# Plug and Play support
373#
374
375#
376# Block devices
377#
378# CONFIG_BLK_CPQ_DA is not set
379# CONFIG_BLK_CPQ_CISS_DA is not set
380# CONFIG_BLK_DEV_DAC960 is not set
381# CONFIG_BLK_DEV_UMEM is not set
382# CONFIG_BLK_DEV_COW_COMMON is not set
383CONFIG_BLK_DEV_LOOP=y
384# CONFIG_BLK_DEV_CRYPTOLOOP is not set
385# CONFIG_BLK_DEV_NBD is not set
386# CONFIG_BLK_DEV_SX8 is not set
387# CONFIG_BLK_DEV_UB is not set
388CONFIG_BLK_DEV_RAM=y
389CONFIG_BLK_DEV_RAM_COUNT=16
390CONFIG_BLK_DEV_RAM_SIZE=8192
391CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
392CONFIG_BLK_DEV_INITRD=y
393# CONFIG_CDROM_PKTCDVD is not set
394# CONFIG_ATA_OVER_ETH is not set
395
396#
397# Misc devices
398#
399# CONFIG_SGI_IOC4 is not set
400# CONFIG_TIFM_CORE is not set
401
402#
403# ATA/ATAPI/MFM/RLL support
404#
405CONFIG_IDE=y
406CONFIG_IDE_MAX_HWIFS=4
407CONFIG_BLK_DEV_IDE=y
408
409#
410# Please see Documentation/ide.txt for help/info on IDE drives
411#
412# CONFIG_BLK_DEV_IDE_SATA is not set
413CONFIG_BLK_DEV_IDEDISK=y
414# CONFIG_IDEDISK_MULTI_MODE is not set
415CONFIG_BLK_DEV_IDECD=m
416# CONFIG_BLK_DEV_IDETAPE is not set
417# CONFIG_BLK_DEV_IDEFLOPPY is not set
418CONFIG_BLK_DEV_IDESCSI=y
419# CONFIG_IDE_TASK_IOCTL is not set
420
421#
422# IDE chipset support/bugfixes
423#
424CONFIG_IDE_GENERIC=y
425CONFIG_BLK_DEV_IDEPCI=y
426CONFIG_IDEPCI_SHARE_IRQ=y
427CONFIG_BLK_DEV_OFFBOARD=y
428CONFIG_BLK_DEV_GENERIC=y
429# CONFIG_BLK_DEV_OPTI621 is not set
430CONFIG_BLK_DEV_IDEDMA_PCI=y
431# CONFIG_BLK_DEV_IDEDMA_FORCED is not set
432# CONFIG_IDEDMA_PCI_AUTO is not set
433# CONFIG_BLK_DEV_AEC62XX is not set
434# CONFIG_BLK_DEV_ALI15X3 is not set
435# CONFIG_BLK_DEV_AMD74XX is not set
436# CONFIG_BLK_DEV_CMD64X is not set
437# CONFIG_BLK_DEV_TRIFLEX is not set
438# CONFIG_BLK_DEV_CY82C693 is not set
439# CONFIG_BLK_DEV_CS5520 is not set
440# CONFIG_BLK_DEV_CS5530 is not set
441# CONFIG_BLK_DEV_HPT34X is not set
442CONFIG_BLK_DEV_HPT366=y
443# CONFIG_BLK_DEV_JMICRON is not set
444# CONFIG_BLK_DEV_SC1200 is not set
445# CONFIG_BLK_DEV_PIIX is not set
446# CONFIG_BLK_DEV_IT821X is not set
447# CONFIG_BLK_DEV_NS87415 is not set
448# CONFIG_BLK_DEV_PDC202XX_OLD is not set
449# CONFIG_BLK_DEV_PDC202XX_NEW is not set
450# CONFIG_BLK_DEV_SVWKS is not set
451# CONFIG_BLK_DEV_SIIMAGE is not set
452# CONFIG_BLK_DEV_SLC90E66 is not set
453# CONFIG_BLK_DEV_TRM290 is not set
454# CONFIG_BLK_DEV_VIA82CXXX is not set
455# CONFIG_IDE_ARM is not set
456CONFIG_BLK_DEV_IDEDMA=y
457# CONFIG_IDEDMA_IVB is not set
458# CONFIG_IDEDMA_AUTO is not set
459# CONFIG_BLK_DEV_HD is not set
460
461#
462# SCSI device support
463#
464# CONFIG_RAID_ATTRS is not set
465CONFIG_SCSI=y
466# CONFIG_SCSI_NETLINK is not set
467CONFIG_SCSI_PROC_FS=y
468
469#
470# SCSI support type (disk, tape, CD-ROM)
471#
472CONFIG_BLK_DEV_SD=y
473# CONFIG_CHR_DEV_ST is not set
474# CONFIG_CHR_DEV_OSST is not set
475# CONFIG_BLK_DEV_SR is not set
476# CONFIG_CHR_DEV_SG is not set
477# CONFIG_CHR_DEV_SCH is not set
478
479#
480# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
481#
482# CONFIG_SCSI_MULTI_LUN is not set
483CONFIG_SCSI_CONSTANTS=y
484# CONFIG_SCSI_LOGGING is not set
485
486#
487# SCSI Transports
488#
489# CONFIG_SCSI_SPI_ATTRS is not set
490# CONFIG_SCSI_FC_ATTRS is not set
491CONFIG_SCSI_ISCSI_ATTRS=m
492# CONFIG_SCSI_SAS_ATTRS is not set
493# CONFIG_SCSI_SAS_LIBSAS is not set
494
495#
496# SCSI low-level drivers
497#
498CONFIG_ISCSI_TCP=m
499# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
500# CONFIG_SCSI_3W_9XXX is not set
501# CONFIG_SCSI_ACARD is not set
502# CONFIG_SCSI_AACRAID is not set
503# CONFIG_SCSI_AIC7XXX is not set
504# CONFIG_SCSI_AIC7XXX_OLD is not set
505# CONFIG_SCSI_AIC79XX is not set
506# CONFIG_SCSI_AIC94XX is not set
507# CONFIG_SCSI_DPT_I2O is not set
508# CONFIG_SCSI_ARCMSR is not set
509# CONFIG_MEGARAID_NEWGEN is not set
510# CONFIG_MEGARAID_LEGACY is not set
511# CONFIG_MEGARAID_SAS is not set
512# CONFIG_SCSI_HPTIOP is not set
513# CONFIG_SCSI_DMX3191D is not set
514# CONFIG_SCSI_FUTURE_DOMAIN is not set
515# CONFIG_SCSI_IPS is not set
516# CONFIG_SCSI_INITIO is not set
517# CONFIG_SCSI_INIA100 is not set
518# CONFIG_SCSI_STEX is not set
519# CONFIG_SCSI_SYM53C8XX_2 is not set
520# CONFIG_SCSI_QLOGIC_1280 is not set
521# CONFIG_SCSI_QLA_FC is not set
522# CONFIG_SCSI_QLA_ISCSI is not set
523# CONFIG_SCSI_LPFC is not set
524# CONFIG_SCSI_DC395x is not set
525# CONFIG_SCSI_DC390T is not set
526# CONFIG_SCSI_NSP32 is not set
527# CONFIG_SCSI_DEBUG is not set
528
529#
530# Serial ATA (prod) and Parallel ATA (experimental) drivers
531#
532# CONFIG_ATA is not set
533
534#
535# Multi-device support (RAID and LVM)
536#
537# CONFIG_MD is not set
538
539#
540# Fusion MPT device support
541#
542# CONFIG_FUSION is not set
543# CONFIG_FUSION_SPI is not set
544# CONFIG_FUSION_FC is not set
545# CONFIG_FUSION_SAS is not set
546
547#
548# IEEE 1394 (FireWire) support
549#
550# CONFIG_IEEE1394 is not set
551
552#
553# I2O device support
554#
555# CONFIG_I2O is not set
556
557#
558# Network device support
559#
560CONFIG_NETDEVICES=y
561# CONFIG_DUMMY is not set
562# CONFIG_BONDING is not set
563# CONFIG_EQUALIZER is not set
564# CONFIG_TUN is not set
565
566#
567# ARCnet devices
568#
569# CONFIG_ARCNET is not set
570
571#
572# PHY device support
573#
574# CONFIG_PHYLIB is not set
575
576#
577# Ethernet (10 or 100Mbit)
578#
579CONFIG_NET_ETHERNET=y
580CONFIG_MII=y
581# CONFIG_HAPPYMEAL is not set
582# CONFIG_SUNGEM is not set
583# CONFIG_CASSINI is not set
584# CONFIG_NET_VENDOR_3COM is not set
585# CONFIG_DM9000 is not set
586
587#
588# Tulip family network device support
589#
590# CONFIG_NET_TULIP is not set
591# CONFIG_HP100 is not set
592CONFIG_NET_PCI=y
593# CONFIG_PCNET32 is not set
594# CONFIG_AMD8111_ETH is not set
595# CONFIG_ADAPTEC_STARFIRE is not set
596# CONFIG_B44 is not set
597# CONFIG_FORCEDETH is not set
598# CONFIG_DGRS is not set
599# CONFIG_EEPRO100 is not set
600# CONFIG_E100 is not set
601# CONFIG_FEALNX is not set
602CONFIG_NATSEMI=y
603# CONFIG_NE2K_PCI is not set
604# CONFIG_8139CP is not set
605# CONFIG_8139TOO is not set
606# CONFIG_SIS900 is not set
607# CONFIG_EPIC100 is not set
608# CONFIG_SUNDANCE is not set
609# CONFIG_TLAN is not set
610# CONFIG_VIA_RHINE is not set
611
612#
613# Ethernet (1000 Mbit)
614#
615# CONFIG_ACENIC is not set
616# CONFIG_DL2K is not set
617# CONFIG_E1000 is not set
618# CONFIG_NS83820 is not set
619# CONFIG_HAMACHI is not set
620# CONFIG_YELLOWFIN is not set
621# CONFIG_R8169 is not set
622# CONFIG_SIS190 is not set
623# CONFIG_SKGE is not set
624# CONFIG_SKY2 is not set
625# CONFIG_SK98LIN is not set
626# CONFIG_VIA_VELOCITY is not set
627# CONFIG_TIGON3 is not set
628# CONFIG_BNX2 is not set
629# CONFIG_QLA3XXX is not set
630
631#
632# Ethernet (10000 Mbit)
633#
634# CONFIG_CHELSIO_T1 is not set
635# CONFIG_IXGB is not set
636# CONFIG_S2IO is not set
637# CONFIG_MYRI10GE is not set
638# CONFIG_NETXEN_NIC is not set
639
640#
641# Token Ring devices
642#
643# CONFIG_TR is not set
644
645#
646# Wireless LAN (non-hamradio)
647#
648# CONFIG_NET_RADIO is not set
649
650#
651# Wan interfaces
652#
653# CONFIG_WAN is not set
654# CONFIG_FDDI is not set
655# CONFIG_HIPPI is not set
656# CONFIG_PPP is not set
657# CONFIG_SLIP is not set
658# CONFIG_NET_FC is not set
659# CONFIG_SHAPER is not set
660# CONFIG_NETCONSOLE is not set
661# CONFIG_NETPOLL is not set
662# CONFIG_NET_POLL_CONTROLLER is not set
663
664#
665# ISDN subsystem
666#
667# CONFIG_ISDN is not set
668
669#
670# Telephony Support
671#
672# CONFIG_PHONE is not set
673
674#
675# Input device support
676#
677CONFIG_INPUT=y
678# CONFIG_INPUT_FF_MEMLESS is not set
679
680#
681# Userland interfaces
682#
683# CONFIG_INPUT_MOUSEDEV is not set
684# CONFIG_INPUT_JOYDEV is not set
685# CONFIG_INPUT_TSDEV is not set
686# CONFIG_INPUT_EVDEV is not set
687# CONFIG_INPUT_EVBUG is not set
688
689#
690# Input Device Drivers
691#
692# CONFIG_INPUT_KEYBOARD is not set
693# CONFIG_INPUT_MOUSE is not set
694# CONFIG_INPUT_JOYSTICK is not set
695# CONFIG_INPUT_TOUCHSCREEN is not set
696# CONFIG_INPUT_MISC is not set
697
698#
699# Hardware I/O ports
700#
701CONFIG_SERIO=y
702# CONFIG_SERIO_I8042 is not set
703# CONFIG_SERIO_SERPORT is not set
704# CONFIG_SERIO_PCIPS2 is not set
705CONFIG_SERIO_LIBPS2=y
706# CONFIG_SERIO_RAW is not set
707# CONFIG_GAMEPORT is not set
708
709#
710# Character devices
711#
712CONFIG_VT=y
713CONFIG_VT_CONSOLE=y
714CONFIG_HW_CONSOLE=y
715# CONFIG_VT_HW_CONSOLE_BINDING is not set
716# CONFIG_SERIAL_NONSTANDARD is not set
717
718#
719# Serial drivers
720#
721# CONFIG_SERIAL_8250 is not set
722
723#
724# Non-8250 serial port support
725#
726# CONFIG_SERIAL_PNX8XXX is not set
727# CONFIG_SERIAL_JSM is not set
728CONFIG_UNIX98_PTYS=y
729CONFIG_LEGACY_PTYS=y
730CONFIG_LEGACY_PTY_COUNT=256
731
732#
733# IPMI
734#
735# CONFIG_IPMI_HANDLER is not set
736
737#
738# Watchdog Cards
739#
740# CONFIG_WATCHDOG is not set
741CONFIG_HW_RANDOM=y
742# CONFIG_RTC is not set
743# CONFIG_GEN_RTC is not set
744# CONFIG_DTLK is not set
745# CONFIG_R3964 is not set
746# CONFIG_APPLICOM is not set
747# CONFIG_DRM is not set
748# CONFIG_RAW_DRIVER is not set
749
750#
751# TPM devices
752#
753# CONFIG_TCG_TPM is not set
754
755#
756# I2C support
757#
758# CONFIG_I2C is not set
759
760#
761# SPI support
762#
763# CONFIG_SPI is not set
764# CONFIG_SPI_MASTER is not set
765
766#
767# Dallas's 1-wire bus
768#
769# CONFIG_W1 is not set
770
771#
772# Hardware Monitoring support
773#
774CONFIG_HWMON=y
775# CONFIG_HWMON_VID is not set
776# CONFIG_SENSORS_ABITUGURU is not set
777# CONFIG_SENSORS_F71805F is not set
778# CONFIG_SENSORS_VT1211 is not set
779# CONFIG_HWMON_DEBUG_CHIP is not set
780
781#
782# Multimedia devices
783#
784# CONFIG_VIDEO_DEV is not set
785
786#
787# Digital Video Broadcasting Devices
788#
789# CONFIG_DVB is not set
790# CONFIG_USB_DABUSB is not set
791
792#
793# Graphics support
794#
795CONFIG_FIRMWARE_EDID=y
796# CONFIG_FB is not set
797
798#
799# Console display driver support
800#
801# CONFIG_VGA_CONSOLE is not set
802CONFIG_DUMMY_CONSOLE=y
803# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
804
805#
806# Sound
807#
808# CONFIG_SOUND is not set
809
810#
811# USB support
812#
813CONFIG_USB_ARCH_HAS_HCD=y
814CONFIG_USB_ARCH_HAS_OHCI=y
815CONFIG_USB_ARCH_HAS_EHCI=y
816CONFIG_USB=y
817# CONFIG_USB_DEBUG is not set
818
819#
820# Miscellaneous USB options
821#
822# CONFIG_USB_DEVICEFS is not set
823# CONFIG_USB_BANDWIDTH is not set
824# CONFIG_USB_DYNAMIC_MINORS is not set
825# CONFIG_USB_MULTITHREAD_PROBE is not set
826# CONFIG_USB_OTG is not set
827
828#
829# USB Host Controller Drivers
830#
831# CONFIG_USB_EHCI_HCD is not set
832# CONFIG_USB_ISP116X_HCD is not set
833CONFIG_USB_OHCI_HCD=y
834# CONFIG_USB_OHCI_BIG_ENDIAN is not set
835CONFIG_USB_OHCI_LITTLE_ENDIAN=y
836# CONFIG_USB_UHCI_HCD is not set
837# CONFIG_USB_SL811_HCD is not set
838
839#
840# USB Device Class drivers
841#
842# CONFIG_USB_ACM is not set
843# CONFIG_USB_PRINTER is not set
844
845#
846# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
847#
848
849#
850# may also be needed; see USB_STORAGE Help for more information
851#
852CONFIG_USB_STORAGE=y
853# CONFIG_USB_STORAGE_DEBUG is not set
854CONFIG_USB_STORAGE_DATAFAB=y
855CONFIG_USB_STORAGE_FREECOM=y
856CONFIG_USB_STORAGE_ISD200=y
857CONFIG_USB_STORAGE_DPCM=y
858CONFIG_USB_STORAGE_USBAT=y
859CONFIG_USB_STORAGE_SDDR09=y
860CONFIG_USB_STORAGE_SDDR55=y
861CONFIG_USB_STORAGE_JUMPSHOT=y
862# CONFIG_USB_STORAGE_ALAUDA is not set
863# CONFIG_USB_STORAGE_KARMA is not set
864# CONFIG_USB_LIBUSUAL is not set
865
866#
867# USB Input Devices
868#
869# CONFIG_USB_HID is not set
870
871#
872# USB HID Boot Protocol drivers
873#
874# CONFIG_USB_KBD is not set
875# CONFIG_USB_MOUSE is not set
876# CONFIG_USB_AIPTEK is not set
877# CONFIG_USB_WACOM is not set
878# CONFIG_USB_ACECAD is not set
879# CONFIG_USB_KBTAB is not set
880# CONFIG_USB_POWERMATE is not set
881# CONFIG_USB_TOUCHSCREEN is not set
882# CONFIG_USB_YEALINK is not set
883# CONFIG_USB_XPAD is not set
884# CONFIG_USB_ATI_REMOTE is not set
885# CONFIG_USB_ATI_REMOTE2 is not set
886# CONFIG_USB_KEYSPAN_REMOTE is not set
887# CONFIG_USB_APPLETOUCH is not set
888
889#
890# USB Imaging devices
891#
892# CONFIG_USB_MDC800 is not set
893# CONFIG_USB_MICROTEK is not set
894
895#
896# USB Network Adapters
897#
898# CONFIG_USB_CATC is not set
899# CONFIG_USB_KAWETH is not set
900# CONFIG_USB_PEGASUS is not set
901# CONFIG_USB_RTL8150 is not set
902# CONFIG_USB_USBNET_MII is not set
903# CONFIG_USB_USBNET is not set
904CONFIG_USB_MON=y
905
906#
907# USB port drivers
908#
909
910#
911# USB Serial Converter support
912#
913# CONFIG_USB_SERIAL is not set
914
915#
916# USB Miscellaneous drivers
917#
918# CONFIG_USB_EMI62 is not set
919# CONFIG_USB_EMI26 is not set
920# CONFIG_USB_ADUTUX is not set
921# CONFIG_USB_AUERSWALD is not set
922# CONFIG_USB_RIO500 is not set
923# CONFIG_USB_LEGOTOWER is not set
924# CONFIG_USB_LCD is not set
925# CONFIG_USB_LED is not set
926# CONFIG_USB_CYPRESS_CY7C63 is not set
927# CONFIG_USB_CYTHERM is not set
928# CONFIG_USB_PHIDGET is not set
929# CONFIG_USB_IDMOUSE is not set
930# CONFIG_USB_FTDI_ELAN is not set
931# CONFIG_USB_APPLEDISPLAY is not set
932# CONFIG_USB_LD is not set
933# CONFIG_USB_TRANCEVIBRATOR is not set
934
935#
936# USB DSL modem support
937#
938
939#
940# USB Gadget Support
941#
942# CONFIG_USB_GADGET is not set
943
944#
945# MMC/SD Card support
946#
947# CONFIG_MMC is not set
948
949#
950# LED devices
951#
952# CONFIG_NEW_LEDS is not set
953
954#
955# LED drivers
956#
957
958#
959# LED Triggers
960#
961
962#
963# InfiniBand support
964#
965# CONFIG_INFINIBAND is not set
966
967#
968# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
969#
970
971#
972# Real Time Clock
973#
974# CONFIG_RTC_CLASS is not set
975
976#
977# DMA Engine support
978#
979# CONFIG_DMA_ENGINE is not set
980
981#
982# DMA Clients
983#
984
985#
986# DMA Devices
987#
988
989#
990# File systems
991#
992CONFIG_EXT2_FS=y
993# CONFIG_EXT2_FS_XATTR is not set
994# CONFIG_EXT2_FS_XIP is not set
995# CONFIG_EXT3_FS is not set
996# CONFIG_EXT4DEV_FS is not set
997# CONFIG_REISERFS_FS is not set
998# CONFIG_JFS_FS is not set
999# CONFIG_FS_POSIX_ACL is not set
1000# CONFIG_XFS_FS is not set
1001# CONFIG_GFS2_FS is not set
1002# CONFIG_OCFS2_FS is not set
1003# CONFIG_MINIX_FS is not set
1004# CONFIG_ROMFS_FS is not set
1005CONFIG_INOTIFY=y
1006CONFIG_INOTIFY_USER=y
1007# CONFIG_QUOTA is not set
1008# CONFIG_DNOTIFY is not set
1009# CONFIG_AUTOFS_FS is not set
1010# CONFIG_AUTOFS4_FS is not set
1011# CONFIG_FUSE_FS is not set
1012
1013#
1014# CD-ROM/DVD Filesystems
1015#
1016# CONFIG_ISO9660_FS is not set
1017# CONFIG_UDF_FS is not set
1018
1019#
1020# DOS/FAT/NT Filesystems
1021#
1022CONFIG_FAT_FS=y
1023CONFIG_MSDOS_FS=y
1024CONFIG_VFAT_FS=y
1025CONFIG_FAT_DEFAULT_CODEPAGE=437
1026CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1027# CONFIG_NTFS_FS is not set
1028
1029#
1030# Pseudo filesystems
1031#
1032CONFIG_PROC_FS=y
1033# CONFIG_PROC_KCORE is not set
1034CONFIG_PROC_SYSCTL=y
1035CONFIG_SYSFS=y
1036CONFIG_TMPFS=y
1037# CONFIG_TMPFS_POSIX_ACL is not set
1038# CONFIG_HUGETLB_PAGE is not set
1039CONFIG_RAMFS=y
1040# CONFIG_CONFIGFS_FS is not set
1041
1042#
1043# Miscellaneous filesystems
1044#
1045# CONFIG_ADFS_FS is not set
1046# CONFIG_AFFS_FS is not set
1047# CONFIG_HFS_FS is not set
1048# CONFIG_HFSPLUS_FS is not set
1049# CONFIG_BEFS_FS is not set
1050# CONFIG_BFS_FS is not set
1051# CONFIG_EFS_FS is not set
1052# CONFIG_CRAMFS is not set
1053# CONFIG_VXFS_FS is not set
1054# CONFIG_HPFS_FS is not set
1055# CONFIG_QNX4FS_FS is not set
1056# CONFIG_SYSV_FS is not set
1057# CONFIG_UFS_FS is not set
1058
1059#
1060# Network File Systems
1061#
1062CONFIG_NFS_FS=y
1063CONFIG_NFS_V3=y
1064# CONFIG_NFS_V3_ACL is not set
1065# CONFIG_NFS_V4 is not set
1066# CONFIG_NFS_DIRECTIO is not set
1067CONFIG_NFSD=m
1068# CONFIG_NFSD_V3 is not set
1069# CONFIG_NFSD_TCP is not set
1070CONFIG_ROOT_NFS=y
1071CONFIG_LOCKD=y
1072CONFIG_LOCKD_V4=y
1073CONFIG_EXPORTFS=m
1074CONFIG_NFS_COMMON=y
1075CONFIG_SUNRPC=y
1076# CONFIG_RPCSEC_GSS_KRB5 is not set
1077# CONFIG_RPCSEC_GSS_SPKM3 is not set
1078# CONFIG_SMB_FS is not set
1079# CONFIG_CIFS is not set
1080# CONFIG_NCP_FS is not set
1081# CONFIG_CODA_FS is not set
1082# CONFIG_AFS_FS is not set
1083# CONFIG_9P_FS is not set
1084
1085#
1086# Partition Types
1087#
1088# CONFIG_PARTITION_ADVANCED is not set
1089CONFIG_MSDOS_PARTITION=y
1090
1091#
1092# Native Language Support
1093#
1094CONFIG_NLS=y
1095CONFIG_NLS_DEFAULT="iso8859-1"
1096# CONFIG_NLS_CODEPAGE_437 is not set
1097# CONFIG_NLS_CODEPAGE_737 is not set
1098# CONFIG_NLS_CODEPAGE_775 is not set
1099# CONFIG_NLS_CODEPAGE_850 is not set
1100# CONFIG_NLS_CODEPAGE_852 is not set
1101# CONFIG_NLS_CODEPAGE_855 is not set
1102# CONFIG_NLS_CODEPAGE_857 is not set
1103# CONFIG_NLS_CODEPAGE_860 is not set
1104# CONFIG_NLS_CODEPAGE_861 is not set
1105# CONFIG_NLS_CODEPAGE_862 is not set
1106# CONFIG_NLS_CODEPAGE_863 is not set
1107# CONFIG_NLS_CODEPAGE_864 is not set
1108# CONFIG_NLS_CODEPAGE_865 is not set
1109# CONFIG_NLS_CODEPAGE_866 is not set
1110# CONFIG_NLS_CODEPAGE_869 is not set
1111# CONFIG_NLS_CODEPAGE_936 is not set
1112# CONFIG_NLS_CODEPAGE_950 is not set
1113# CONFIG_NLS_CODEPAGE_932 is not set
1114# CONFIG_NLS_CODEPAGE_949 is not set
1115# CONFIG_NLS_CODEPAGE_874 is not set
1116# CONFIG_NLS_ISO8859_8 is not set
1117# CONFIG_NLS_CODEPAGE_1250 is not set
1118# CONFIG_NLS_CODEPAGE_1251 is not set
1119# CONFIG_NLS_ASCII is not set
1120# CONFIG_NLS_ISO8859_1 is not set
1121# CONFIG_NLS_ISO8859_2 is not set
1122# CONFIG_NLS_ISO8859_3 is not set
1123# CONFIG_NLS_ISO8859_4 is not set
1124# CONFIG_NLS_ISO8859_5 is not set
1125# CONFIG_NLS_ISO8859_6 is not set
1126# CONFIG_NLS_ISO8859_7 is not set
1127# CONFIG_NLS_ISO8859_9 is not set
1128# CONFIG_NLS_ISO8859_13 is not set
1129# CONFIG_NLS_ISO8859_14 is not set
1130# CONFIG_NLS_ISO8859_15 is not set
1131# CONFIG_NLS_KOI8_R is not set
1132# CONFIG_NLS_KOI8_U is not set
1133# CONFIG_NLS_UTF8 is not set
1134
1135#
1136# Profiling support
1137#
1138# CONFIG_PROFILING is not set
1139
1140#
1141# Kernel hacking
1142#
1143CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1144# CONFIG_PRINTK_TIME is not set
1145CONFIG_ENABLE_MUST_CHECK=y
1146CONFIG_MAGIC_SYSRQ=y
1147# CONFIG_UNUSED_SYMBOLS is not set
1148CONFIG_DEBUG_KERNEL=y
1149CONFIG_LOG_BUF_SHIFT=14
1150CONFIG_DETECT_SOFTLOCKUP=y
1151# CONFIG_SCHEDSTATS is not set
1152CONFIG_DEBUG_SLAB=y
1153# CONFIG_DEBUG_SLAB_LEAK is not set
1154# CONFIG_DEBUG_RT_MUTEXES is not set
1155# CONFIG_RT_MUTEX_TESTER is not set
1156# CONFIG_DEBUG_SPINLOCK is not set
1157# CONFIG_DEBUG_MUTEXES is not set
1158# CONFIG_DEBUG_RWSEMS is not set
1159# CONFIG_DEBUG_LOCK_ALLOC is not set
1160# CONFIG_PROVE_LOCKING is not set
1161# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1162# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1163# CONFIG_DEBUG_KOBJECT is not set
1164# CONFIG_DEBUG_INFO is not set
1165# CONFIG_DEBUG_FS is not set
1166# CONFIG_DEBUG_VM is not set
1167# CONFIG_DEBUG_LIST is not set
1168CONFIG_FORCED_INLINING=y
1169CONFIG_HEADERS_CHECK=y
1170# CONFIG_RCU_TORTURE_TEST is not set
1171CONFIG_CROSSCOMPILE=y
1172CONFIG_CMDLINE="console=ttyS1,38400n8 kgdb=ttyS0 root=/dev/nfs ip=bootp"
1173# CONFIG_DEBUG_STACK_USAGE is not set
1174# CONFIG_KGDB is not set
1175# CONFIG_RUNTIME_DEBUG is not set
1176# CONFIG_MIPS_UNCACHED is not set
1177
1178#
1179# Security options
1180#
1181# CONFIG_KEYS is not set
1182# CONFIG_SECURITY is not set
1183
1184#
1185# Cryptographic options
1186#
1187CONFIG_CRYPTO=y
1188CONFIG_CRYPTO_ALGAPI=m
1189CONFIG_CRYPTO_BLKCIPHER=m
1190CONFIG_CRYPTO_MANAGER=m
1191# CONFIG_CRYPTO_HMAC is not set
1192# CONFIG_CRYPTO_NULL is not set
1193# CONFIG_CRYPTO_MD4 is not set
1194CONFIG_CRYPTO_MD5=m
1195# CONFIG_CRYPTO_SHA1 is not set
1196# CONFIG_CRYPTO_SHA256 is not set
1197# CONFIG_CRYPTO_SHA512 is not set
1198# CONFIG_CRYPTO_WP512 is not set
1199# CONFIG_CRYPTO_TGR192 is not set
1200CONFIG_CRYPTO_ECB=m
1201CONFIG_CRYPTO_CBC=m
1202# CONFIG_CRYPTO_DES is not set
1203# CONFIG_CRYPTO_BLOWFISH is not set
1204# CONFIG_CRYPTO_TWOFISH is not set
1205# CONFIG_CRYPTO_SERPENT is not set
1206# CONFIG_CRYPTO_AES is not set
1207# CONFIG_CRYPTO_CAST5 is not set
1208# CONFIG_CRYPTO_CAST6 is not set
1209# CONFIG_CRYPTO_TEA is not set
1210# CONFIG_CRYPTO_ARC4 is not set
1211# CONFIG_CRYPTO_KHAZAD is not set
1212# CONFIG_CRYPTO_ANUBIS is not set
1213# CONFIG_CRYPTO_DEFLATE is not set
1214# CONFIG_CRYPTO_MICHAEL_MIC is not set
1215CONFIG_CRYPTO_CRC32C=m
1216# CONFIG_CRYPTO_TEST is not set
1217
1218#
1219# Hardware crypto devices
1220#
1221
1222#
1223# Library routines
1224#
1225CONFIG_CRC_CCITT=m
1226# CONFIG_CRC16 is not set
1227CONFIG_CRC32=y
1228CONFIG_LIBCRC32C=m
1229CONFIG_PLIST=y
diff --git a/arch/mips/configs/pnx8550-v2pci_defconfig b/arch/mips/configs/pnx8550-v2pci_defconfig
index 64b9fbf44a64..5bc3248e50e4 100644
--- a/arch/mips/configs/pnx8550-v2pci_defconfig
+++ b/arch/mips/configs/pnx8550-v2pci_defconfig
@@ -57,7 +57,7 @@ CONFIG_PNX8550_V2PCI=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/qemu_defconfig b/arch/mips/configs/qemu_defconfig
index 9b0dab822bd0..aa61f0f030a5 100644
--- a/arch/mips/configs/qemu_defconfig
+++ b/arch/mips/configs/qemu_defconfig
@@ -59,7 +59,7 @@ CONFIG_QEMU=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/rbhma4500_defconfig b/arch/mips/configs/rbhma4500_defconfig
index dd0296036026..f9e8f41d17f2 100644
--- a/arch/mips/configs/rbhma4500_defconfig
+++ b/arch/mips/configs/rbhma4500_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65CONFIG_TOSHIBA_RBTX4938=y 65CONFIG_TOSHIBA_RBTX4938=y
diff --git a/arch/mips/configs/rm200_defconfig b/arch/mips/configs/rm200_defconfig
index d8a498d64d62..496aa67b9f82 100644
--- a/arch/mips/configs/rm200_defconfig
+++ b/arch/mips/configs/rm200_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62CONFIG_SNI_RM200_PCI=y 62CONFIG_SNI_RM=y
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/sb1250-swarm_defconfig b/arch/mips/configs/sb1250-swarm_defconfig
index 805a4fe450f5..e33c17200b39 100644
--- a/arch/mips/configs/sb1250-swarm_defconfig
+++ b/arch/mips/configs/sb1250-swarm_defconfig
@@ -59,7 +59,7 @@ CONFIG_SIBYTE_SWARM=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/sead_defconfig b/arch/mips/configs/sead_defconfig
index 6fcb656d8d87..83fb932f9d4b 100644
--- a/arch/mips/configs/sead_defconfig
+++ b/arch/mips/configs/sead_defconfig
@@ -59,7 +59,7 @@ CONFIG_MIPS_SEAD=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/tb0226_defconfig b/arch/mips/configs/tb0226_defconfig
index dc312f19ada7..e9d4eae45bfa 100644
--- a/arch/mips/configs/tb0226_defconfig
+++ b/arch/mips/configs/tb0226_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/tb0229_defconfig b/arch/mips/configs/tb0229_defconfig
index 85615d99b01a..c19597fb0c32 100644
--- a/arch/mips/configs/tb0229_defconfig
+++ b/arch/mips/configs/tb0229_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/tb0287_defconfig b/arch/mips/configs/tb0287_defconfig
index f7e8194809a1..97d94f96990f 100644
--- a/arch/mips/configs/tb0287_defconfig
+++ b/arch/mips/configs/tb0287_defconfig
@@ -57,7 +57,7 @@ CONFIG_MACH_VR41XX=y
57# CONFIG_SIBYTE_LITTLESUR is not set 57# CONFIG_SIBYTE_LITTLESUR is not set
58# CONFIG_SIBYTE_CRHINE is not set 58# CONFIG_SIBYTE_CRHINE is not set
59# CONFIG_SIBYTE_CRHONE is not set 59# CONFIG_SIBYTE_CRHONE is not set
60# CONFIG_SNI_RM200_PCI is not set 60# CONFIG_SNI_RM is not set
61# CONFIG_TOSHIBA_JMR3927 is not set 61# CONFIG_TOSHIBA_JMR3927 is not set
62# CONFIG_TOSHIBA_RBTX4927 is not set 62# CONFIG_TOSHIBA_RBTX4927 is not set
63# CONFIG_TOSHIBA_RBTX4938 is not set 63# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/workpad_defconfig b/arch/mips/configs/workpad_defconfig
index 863f6a7cadfd..553734a47b62 100644
--- a/arch/mips/configs/workpad_defconfig
+++ b/arch/mips/configs/workpad_defconfig
@@ -59,7 +59,7 @@ CONFIG_MACH_VR41XX=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/wrppmc_defconfig b/arch/mips/configs/wrppmc_defconfig
index c10267d61cc9..d3dfb702bb7c 100644
--- a/arch/mips/configs/wrppmc_defconfig
+++ b/arch/mips/configs/wrppmc_defconfig
@@ -59,7 +59,7 @@ CONFIG_WR_PPMC=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/configs/yosemite_defconfig b/arch/mips/configs/yosemite_defconfig
index 4d3c1329f3cf..b9f74d6745ee 100644
--- a/arch/mips/configs/yosemite_defconfig
+++ b/arch/mips/configs/yosemite_defconfig
@@ -59,7 +59,7 @@ CONFIG_PMC_YOSEMITE=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/defconfig b/arch/mips/defconfig
index 21d53e0c9ee8..f9812d1e4579 100644
--- a/arch/mips/defconfig
+++ b/arch/mips/defconfig
@@ -59,7 +59,7 @@ CONFIG_SGI_IP22=y
59# CONFIG_SIBYTE_LITTLESUR is not set 59# CONFIG_SIBYTE_LITTLESUR is not set
60# CONFIG_SIBYTE_CRHINE is not set 60# CONFIG_SIBYTE_CRHINE is not set
61# CONFIG_SIBYTE_CRHONE is not set 61# CONFIG_SIBYTE_CRHONE is not set
62# CONFIG_SNI_RM200_PCI is not set 62# CONFIG_SNI_RM is not set
63# CONFIG_TOSHIBA_JMR3927 is not set 63# CONFIG_TOSHIBA_JMR3927 is not set
64# CONFIG_TOSHIBA_RBTX4927 is not set 64# CONFIG_TOSHIBA_RBTX4927 is not set
65# CONFIG_TOSHIBA_RBTX4938 is not set 65# CONFIG_TOSHIBA_RBTX4938 is not set
diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S
index a2e095adaa3f..9a7811d13db2 100644
--- a/arch/mips/kernel/head.S
+++ b/arch/mips/kernel/head.S
@@ -138,7 +138,7 @@
138EXPORT(stext) # used for profiling 138EXPORT(stext) # used for profiling
139EXPORT(_stext) 139EXPORT(_stext)
140 140
141#if defined(CONFIG_QEMU) || defined(CONFIG_MIPS_SIM) 141#ifdef CONFIG_MIPS_SIM
142 /* 142 /*
143 * Give us a fighting chance of running if execution beings at the 143 * Give us a fighting chance of running if execution beings at the
144 * kernel load address. This is needed because this platform does 144 * kernel load address. This is needed because this platform does
diff --git a/arch/mips/kernel/irixelf.c b/arch/mips/kernel/irixelf.c
index 1bbefbf43373..37cad5de515c 100644
--- a/arch/mips/kernel/irixelf.c
+++ b/arch/mips/kernel/irixelf.c
@@ -1145,7 +1145,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
1145 psinfo.pr_pid = prstatus.pr_pid = current->pid; 1145 psinfo.pr_pid = prstatus.pr_pid = current->pid;
1146 psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid; 1146 psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid;
1147 psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current); 1147 psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current);
1148 psinfo.pr_sid = prstatus.pr_sid = current->signal->session; 1148 psinfo.pr_sid = prstatus.pr_sid = process_session(current);
1149 if (current->pid == current->tgid) { 1149 if (current->pid == current->tgid) {
1150 /* 1150 /*
1151 * This is the record for the group leader. Add in the 1151 * This is the record for the group leader. Add in the
diff --git a/arch/mips/kernel/kspd.c b/arch/mips/kernel/kspd.c
index 2c82412b9efe..5929f883e46b 100644
--- a/arch/mips/kernel/kspd.c
+++ b/arch/mips/kernel/kspd.c
@@ -301,7 +301,7 @@ static void sp_cleanup(void)
301 for (;;) { 301 for (;;) {
302 unsigned long set; 302 unsigned long set;
303 i = j * __NFDBITS; 303 i = j * __NFDBITS;
304 if (i >= fdt->max_fdset || i >= fdt->max_fds) 304 if (i >= fdt->max_fds)
305 break; 305 break;
306 set = fdt->open_fds->fds_bits[j++]; 306 set = fdt->open_fds->fds_bits[j++];
307 while (set) { 307 while (set) {
diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
index 621037db2290..060563a712b6 100644
--- a/arch/mips/kernel/reset.c
+++ b/arch/mips/kernel/reset.c
@@ -23,6 +23,8 @@ void (*_machine_restart)(char *command);
23void (*_machine_halt)(void); 23void (*_machine_halt)(void);
24void (*pm_power_off)(void); 24void (*pm_power_off)(void);
25 25
26EXPORT_SYMBOL(pm_power_off);
27
26void machine_restart(char *command) 28void machine_restart(char *command)
27{ 29{
28 if (_machine_restart) 30 if (_machine_restart)
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index 8c8c8324f775..5a99e3e0c96d 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -415,7 +415,7 @@ static unsigned int file_poll(struct file *file, poll_table * wait)
415 int minor; 415 int minor;
416 unsigned int mask = 0; 416 unsigned int mask = 0;
417 417
418 minor = iminor(file->f_dentry->d_inode); 418 minor = iminor(file->f_path.dentry->d_inode);
419 419
420 poll_wait(file, &channel_wqs[minor].rt_queue, wait); 420 poll_wait(file, &channel_wqs[minor].rt_queue, wait);
421 poll_wait(file, &channel_wqs[minor].lx_queue, wait); 421 poll_wait(file, &channel_wqs[minor].lx_queue, wait);
@@ -437,7 +437,7 @@ static unsigned int file_poll(struct file *file, poll_table * wait)
437static ssize_t file_read(struct file *file, char __user * buffer, size_t count, 437static ssize_t file_read(struct file *file, char __user * buffer, size_t count,
438 loff_t * ppos) 438 loff_t * ppos)
439{ 439{
440 int minor = iminor(file->f_dentry->d_inode); 440 int minor = iminor(file->f_path.dentry->d_inode);
441 441
442 /* data available? */ 442 /* data available? */
443 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) { 443 if (!rtlx_read_poll(minor, (file->f_flags & O_NONBLOCK) ? 0 : 1)) {
@@ -454,7 +454,7 @@ static ssize_t file_write(struct file *file, const char __user * buffer,
454 struct rtlx_channel *rt; 454 struct rtlx_channel *rt;
455 DECLARE_WAITQUEUE(wait, current); 455 DECLARE_WAITQUEUE(wait, current);
456 456
457 minor = iminor(file->f_dentry->d_inode); 457 minor = iminor(file->f_path.dentry->d_inode);
458 rt = &rtlx->channel[minor]; 458 rt = &rtlx->channel[minor];
459 459
460 /* any space left... */ 460 /* any space left... */
diff --git a/arch/mips/kernel/sysirix.c b/arch/mips/kernel/sysirix.c
index 93c74fefff76..6c2406a93f2b 100644
--- a/arch/mips/kernel/sysirix.c
+++ b/arch/mips/kernel/sysirix.c
@@ -732,7 +732,7 @@ asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs __user *buf)
732 goto out; 732 goto out;
733 } 733 }
734 734
735 error = vfs_statfs(file->f_dentry, &kbuf); 735 error = vfs_statfs(file->f_path.dentry, &kbuf);
736 if (error) 736 if (error)
737 goto out_f; 737 goto out_f;
738 738
@@ -1041,7 +1041,7 @@ asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
1041 unsigned long old_pos; 1041 unsigned long old_pos;
1042 long max_size = offset + len; 1042 long max_size = offset + len;
1043 1043
1044 if (max_size > file->f_dentry->d_inode->i_size) { 1044 if (max_size > file->f_path.dentry->d_inode->i_size) {
1045 old_pos = sys_lseek (fd, max_size - 1, 0); 1045 old_pos = sys_lseek (fd, max_size - 1, 0);
1046 sys_write (fd, (void __user *) "", 1); 1046 sys_write (fd, (void __user *) "", 1);
1047 sys_lseek (fd, old_pos, 0); 1047 sys_lseek (fd, old_pos, 0);
@@ -1406,7 +1406,7 @@ asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs __user *buf)
1406 error = -EBADF; 1406 error = -EBADF;
1407 goto out; 1407 goto out;
1408 } 1408 }
1409 error = vfs_statfs(file->f_dentry, &kbuf); 1409 error = vfs_statfs(file->f_path.dentry, &kbuf);
1410 if (error) 1410 if (error)
1411 goto out_f; 1411 goto out_f;
1412 1412
@@ -1526,7 +1526,7 @@ asmlinkage int irix_mmap64(struct pt_regs *regs)
1526 unsigned long old_pos; 1526 unsigned long old_pos;
1527 long max_size = off2 + len; 1527 long max_size = off2 + len;
1528 1528
1529 if (max_size > file->f_dentry->d_inode->i_size) { 1529 if (max_size > file->f_path.dentry->d_inode->i_size) {
1530 old_pos = sys_lseek (fd, max_size - 1, 0); 1530 old_pos = sys_lseek (fd, max_size - 1, 0);
1531 sys_write (fd, (void __user *) "", 1); 1531 sys_write (fd, (void __user *) "", 1);
1532 sys_lseek (fd, old_pos, 0); 1532 sys_lseek (fd, old_pos, 0);
@@ -1658,7 +1658,7 @@ asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs __user *buf)
1658 error = -EBADF; 1658 error = -EBADF;
1659 goto out; 1659 goto out;
1660 } 1660 }
1661 error = vfs_statfs(file->f_dentry, &kbuf); 1661 error = vfs_statfs(file->f_path.dentry, &kbuf);
1662 if (error) 1662 if (error)
1663 goto out_f; 1663 goto out_f;
1664 1664
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index 79f0317d84ac..cecff24cc972 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -112,6 +112,7 @@ SECTIONS
112 /* .exit.text is discarded at runtime, not link time, to deal with 112 /* .exit.text is discarded at runtime, not link time, to deal with
113 references from .rodata */ 113 references from .rodata */
114 .exit.text : { *(.exit.text) } 114 .exit.text : { *(.exit.text) }
115 .exit.data : { *(.exit.data) }
115 . = ALIGN(_PAGE_SIZE); 116 . = ALIGN(_PAGE_SIZE);
116 __initramfs_start = .; 117 __initramfs_start = .;
117 .init.ramfs : { *(.init.ramfs) } 118 .init.ramfs : { *(.init.ramfs) }
@@ -139,7 +140,6 @@ SECTIONS
139 140
140 /* Sections to be discarded */ 141 /* Sections to be discarded */
141 /DISCARD/ : { 142 /DISCARD/ : {
142 *(.exit.data)
143 *(.exitcall.exit) 143 *(.exitcall.exit)
144 144
145 /* ABI crap starts here */ 145 /* ABI crap starts here */
diff --git a/arch/mips/kernel/vpe.c b/arch/mips/kernel/vpe.c
index 51ddd2166898..666bef484dcb 100644
--- a/arch/mips/kernel/vpe.c
+++ b/arch/mips/kernel/vpe.c
@@ -1179,7 +1179,7 @@ static ssize_t vpe_write(struct file *file, const char __user * buffer,
1179 size_t ret = count; 1179 size_t ret = count;
1180 struct vpe *v; 1180 struct vpe *v;
1181 1181
1182 minor = iminor(file->f_dentry->d_inode); 1182 minor = iminor(file->f_path.dentry->d_inode);
1183 if ((v = get_vpe(minor)) == NULL) 1183 if ((v = get_vpe(minor)) == NULL)
1184 return -ENODEV; 1184 return -ENODEV;
1185 1185
diff --git a/arch/mips/lasat/sysctl.c b/arch/mips/lasat/sysctl.c
index 6dd7ae1b7c25..12878359f2c8 100644
--- a/arch/mips/lasat/sysctl.c
+++ b/arch/mips/lasat/sysctl.c
@@ -40,12 +40,12 @@ static DEFINE_MUTEX(lasat_info_mutex);
40/* Strategy function to write EEPROM after changing string entry */ 40/* Strategy function to write EEPROM after changing string entry */
41int sysctl_lasatstring(ctl_table *table, int *name, int nlen, 41int sysctl_lasatstring(ctl_table *table, int *name, int nlen,
42 void *oldval, size_t *oldlenp, 42 void *oldval, size_t *oldlenp,
43 void *newval, size_t newlen, void **context) 43 void *newval, size_t newlen)
44{ 44{
45 int r; 45 int r;
46 mutex_lock(&lasat_info_mutex); 46 mutex_lock(&lasat_info_mutex);
47 r = sysctl_string(table, name, 47 r = sysctl_string(table, name,
48 nlen, oldval, oldlenp, newval, newlen, context); 48 nlen, oldval, oldlenp, newval, newlen);
49 if (r < 0) { 49 if (r < 0) {
50 mutex_unlock(&lasat_info_mutex); 50 mutex_unlock(&lasat_info_mutex);
51 return r; 51 return r;
@@ -119,11 +119,11 @@ int proc_dolasatrtc(ctl_table *table, int write, struct file *filp,
119/* Sysctl for setting the IP addresses */ 119/* Sysctl for setting the IP addresses */
120int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen, 120int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
121 void *oldval, size_t *oldlenp, 121 void *oldval, size_t *oldlenp,
122 void *newval, size_t newlen, void **context) 122 void *newval, size_t newlen)
123{ 123{
124 int r; 124 int r;
125 mutex_lock(&lasat_info_mutex); 125 mutex_lock(&lasat_info_mutex);
126 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); 126 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
127 if (r < 0) { 127 if (r < 0) {
128 mutex_unlock(&lasat_info_mutex); 128 mutex_unlock(&lasat_info_mutex);
129 return r; 129 return r;
@@ -139,14 +139,14 @@ int sysctl_lasat_intvec(ctl_table *table, int *name, int nlen,
139/* Same for RTC */ 139/* Same for RTC */
140int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen, 140int sysctl_lasat_rtc(ctl_table *table, int *name, int nlen,
141 void *oldval, size_t *oldlenp, 141 void *oldval, size_t *oldlenp,
142 void *newval, size_t newlen, void **context) 142 void *newval, size_t newlen)
143{ 143{
144 int r; 144 int r;
145 mutex_lock(&lasat_info_mutex); 145 mutex_lock(&lasat_info_mutex);
146 rtctmp = ds1603_read(); 146 rtctmp = ds1603_read();
147 if (rtctmp < 0) 147 if (rtctmp < 0)
148 rtctmp = 0; 148 rtctmp = 0;
149 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); 149 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
150 if (r < 0) { 150 if (r < 0) {
151 mutex_unlock(&lasat_info_mutex); 151 mutex_unlock(&lasat_info_mutex);
152 return r; 152 return r;
@@ -251,13 +251,12 @@ int proc_lasat_ip(ctl_table *table, int write, struct file *filp,
251 251
252static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen, 252static int sysctl_lasat_eeprom_value(ctl_table *table, int *name, int nlen,
253 void *oldval, size_t *oldlenp, 253 void *oldval, size_t *oldlenp,
254 void *newval, size_t newlen, 254 void *newval, size_t newlen)
255 void **context)
256{ 255{
257 int r; 256 int r;
258 257
259 mutex_lock(&lasat_info_mutex); 258 mutex_lock(&lasat_info_mutex);
260 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen, context); 259 r = sysctl_intvec(table, name, nlen, oldval, oldlenp, newval, newlen);
261 if (r < 0) { 260 if (r < 0) {
262 mutex_unlock(&lasat_info_mutex); 261 mutex_unlock(&lasat_info_mutex);
263 return r; 262 return r;
@@ -286,11 +285,11 @@ int proc_lasat_eeprom_value(ctl_table *table, int write, struct file *filp,
286 mutex_unlock(&lasat_info_mutex); 285 mutex_unlock(&lasat_info_mutex);
287 return r; 286 return r;
288 } 287 }
289 if (filp && filp->f_dentry) 288 if (filp && filp->f_path.dentry)
290 { 289 {
291 if (!strcmp(filp->f_dentry->d_name.name, "prid")) 290 if (!strcmp(filp->f_path.dentry->d_name.name, "prid"))
292 lasat_board_info.li_eeprom_info.prid = lasat_board_info.li_prid; 291 lasat_board_info.li_eeprom_info.prid = lasat_board_info.li_prid;
293 if (!strcmp(filp->f_dentry->d_name.name, "debugaccess")) 292 if (!strcmp(filp->f_path.dentry->d_name.name, "debugaccess"))
294 lasat_board_info.li_eeprom_info.debugaccess = lasat_board_info.li_debugaccess; 293 lasat_board_info.li_eeprom_info.debugaccess = lasat_board_info.li_debugaccess;
295 } 294 }
296 lasat_write_eeprom_info(); 295 lasat_write_eeprom_info();
diff --git a/arch/mips/lib/csum_partial.S b/arch/mips/lib/csum_partial.S
index 15611d9df7ac..9db357294be1 100644
--- a/arch/mips/lib/csum_partial.S
+++ b/arch/mips/lib/csum_partial.S
@@ -12,43 +12,66 @@
12#include <asm/regdef.h> 12#include <asm/regdef.h>
13 13
14#ifdef CONFIG_64BIT 14#ifdef CONFIG_64BIT
15#define T0 ta0 15/*
16#define T1 ta1 16 * As we are sharing code base with the mips32 tree (which use the o32 ABI
17#define T2 ta2 17 * register definitions). We need to redefine the register definitions from
18#define T3 ta3 18 * the n64 ABI register naming to the o32 ABI register naming.
19#define T4 t0 19 */
20#define T7 t3 20#undef t0
21#else 21#undef t1
22#define T0 t0 22#undef t2
23#define T1 t1 23#undef t3
24#define T2 t2 24#define t0 $8
25#define T3 t3 25#define t1 $9
26#define T4 t4 26#define t2 $10
27#define T7 t7 27#define t3 $11
28#define t4 $12
29#define t5 $13
30#define t6 $14
31#define t7 $15
32
33#define USE_DOUBLE
28#endif 34#endif
29 35
36#ifdef USE_DOUBLE
37
38#define LOAD ld
39#define ADD daddu
40#define NBYTES 8
41
42#else
43
44#define LOAD lw
45#define ADD addu
46#define NBYTES 4
47
48#endif /* USE_DOUBLE */
49
50#define UNIT(unit) ((unit)*NBYTES)
51
30#define ADDC(sum,reg) \ 52#define ADDC(sum,reg) \
31 addu sum, reg; \ 53 ADD sum, reg; \
32 sltu v1, sum, reg; \ 54 sltu v1, sum, reg; \
33 addu sum, v1 55 ADD sum, v1
34 56
35#define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \ 57#define CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3) \
36 lw _t0, (offset + 0x00)(src); \ 58 LOAD _t0, (offset + UNIT(0))(src); \
37 lw _t1, (offset + 0x04)(src); \ 59 LOAD _t1, (offset + UNIT(1))(src); \
38 lw _t2, (offset + 0x08)(src); \ 60 LOAD _t2, (offset + UNIT(2))(src); \
39 lw _t3, (offset + 0x0c)(src); \ 61 LOAD _t3, (offset + UNIT(3))(src); \
40 ADDC(sum, _t0); \
41 ADDC(sum, _t1); \
42 ADDC(sum, _t2); \
43 ADDC(sum, _t3); \
44 lw _t0, (offset + 0x10)(src); \
45 lw _t1, (offset + 0x14)(src); \
46 lw _t2, (offset + 0x18)(src); \
47 lw _t3, (offset + 0x1c)(src); \
48 ADDC(sum, _t0); \ 62 ADDC(sum, _t0); \
49 ADDC(sum, _t1); \ 63 ADDC(sum, _t1); \
50 ADDC(sum, _t2); \ 64 ADDC(sum, _t2); \
51 ADDC(sum, _t3); \ 65 ADDC(sum, _t3)
66
67#ifdef USE_DOUBLE
68#define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \
69 CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3)
70#else
71#define CSUM_BIGCHUNK(src, offset, sum, _t0, _t1, _t2, _t3) \
72 CSUM_BIGCHUNK1(src, offset, sum, _t0, _t1, _t2, _t3); \
73 CSUM_BIGCHUNK1(src, offset + 0x10, sum, _t0, _t1, _t2, _t3)
74#endif
52 75
53/* 76/*
54 * a0: source address 77 * a0: source address
@@ -61,86 +84,27 @@
61 84
62 .text 85 .text
63 .set noreorder 86 .set noreorder
64
65/* unknown src alignment and < 8 bytes to go */
66small_csumcpy:
67 move a1, T2
68
69 andi T0, a1, 4
70 beqz T0, 1f
71 andi T0, a1, 2
72
73 /* Still a full word to go */
74 ulw T1, (src)
75 PTR_ADDIU src, 4
76 ADDC(sum, T1)
77
781: move T1, zero
79 beqz T0, 1f
80 andi T0, a1, 1
81
82 /* Still a halfword to go */
83 ulhu T1, (src)
84 PTR_ADDIU src, 2
85
861: beqz T0, 1f
87 sll T1, T1, 16
88
89 lbu T2, (src)
90 nop
91
92#ifdef __MIPSEB__
93 sll T2, T2, 8
94#endif
95 or T1, T2
96
971: ADDC(sum, T1)
98
99 /* fold checksum */
100 sll v1, sum, 16
101 addu sum, v1
102 sltu v1, sum, v1
103 srl sum, sum, 16
104 addu sum, v1
105
106 /* odd buffer alignment? */
107 beqz T7, 1f
108 nop
109 sll v1, sum, 8
110 srl sum, sum, 8
111 or sum, v1
112 andi sum, 0xffff
1131:
114 .set reorder
115 /* Add the passed partial csum. */
116 ADDC(sum, a2)
117 jr ra
118 .set noreorder
119
120/* ------------------------------------------------------------------------- */
121
122 .align 5 87 .align 5
123LEAF(csum_partial) 88LEAF(csum_partial)
124 move sum, zero 89 move sum, zero
125 move T7, zero 90 move t7, zero
126 91
127 sltiu t8, a1, 0x8 92 sltiu t8, a1, 0x8
128 bnez t8, small_csumcpy /* < 8 bytes to copy */ 93 bnez t8, small_csumcpy /* < 8 bytes to copy */
129 move T2, a1 94 move t2, a1
130 95
131 beqz a1, out 96 andi t7, src, 0x1 /* odd buffer? */
132 andi T7, src, 0x1 /* odd buffer? */
133 97
134hword_align: 98hword_align:
135 beqz T7, word_align 99 beqz t7, word_align
136 andi t8, src, 0x2 100 andi t8, src, 0x2
137 101
138 lbu T0, (src) 102 lbu t0, (src)
139 LONG_SUBU a1, a1, 0x1 103 LONG_SUBU a1, a1, 0x1
140#ifdef __MIPSEL__ 104#ifdef __MIPSEL__
141 sll T0, T0, 8 105 sll t0, t0, 8
142#endif 106#endif
143 ADDC(sum, T0) 107 ADDC(sum, t0)
144 PTR_ADDU src, src, 0x1 108 PTR_ADDU src, src, 0x1
145 andi t8, src, 0x2 109 andi t8, src, 0x2
146 110
@@ -148,9 +112,9 @@ word_align:
148 beqz t8, dword_align 112 beqz t8, dword_align
149 sltiu t8, a1, 56 113 sltiu t8, a1, 56
150 114
151 lhu T0, (src) 115 lhu t0, (src)
152 LONG_SUBU a1, a1, 0x2 116 LONG_SUBU a1, a1, 0x2
153 ADDC(sum, T0) 117 ADDC(sum, t0)
154 sltiu t8, a1, 56 118 sltiu t8, a1, 56
155 PTR_ADDU src, src, 0x2 119 PTR_ADDU src, src, 0x2
156 120
@@ -162,9 +126,9 @@ dword_align:
162 beqz t8, qword_align 126 beqz t8, qword_align
163 andi t8, src, 0x8 127 andi t8, src, 0x8
164 128
165 lw T0, 0x00(src) 129 lw t0, 0x00(src)
166 LONG_SUBU a1, a1, 0x4 130 LONG_SUBU a1, a1, 0x4
167 ADDC(sum, T0) 131 ADDC(sum, t0)
168 PTR_ADDU src, src, 0x4 132 PTR_ADDU src, src, 0x4
169 andi t8, src, 0x8 133 andi t8, src, 0x8
170 134
@@ -172,11 +136,17 @@ qword_align:
172 beqz t8, oword_align 136 beqz t8, oword_align
173 andi t8, src, 0x10 137 andi t8, src, 0x10
174 138
175 lw T0, 0x00(src) 139#ifdef USE_DOUBLE
176 lw T1, 0x04(src) 140 ld t0, 0x00(src)
141 LONG_SUBU a1, a1, 0x8
142 ADDC(sum, t0)
143#else
144 lw t0, 0x00(src)
145 lw t1, 0x04(src)
177 LONG_SUBU a1, a1, 0x8 146 LONG_SUBU a1, a1, 0x8
178 ADDC(sum, T0) 147 ADDC(sum, t0)
179 ADDC(sum, T1) 148 ADDC(sum, t1)
149#endif
180 PTR_ADDU src, src, 0x8 150 PTR_ADDU src, src, 0x8
181 andi t8, src, 0x10 151 andi t8, src, 0x10
182 152
@@ -184,75 +154,120 @@ oword_align:
184 beqz t8, begin_movement 154 beqz t8, begin_movement
185 LONG_SRL t8, a1, 0x7 155 LONG_SRL t8, a1, 0x7
186 156
187 lw T3, 0x08(src) 157#ifdef USE_DOUBLE
188 lw T4, 0x0c(src) 158 ld t0, 0x00(src)
189 lw T0, 0x00(src) 159 ld t1, 0x08(src)
190 lw T1, 0x04(src) 160 ADDC(sum, t0)
191 ADDC(sum, T3) 161 ADDC(sum, t1)
192 ADDC(sum, T4) 162#else
193 ADDC(sum, T0) 163 CSUM_BIGCHUNK1(src, 0x00, sum, t0, t1, t3, t4)
194 ADDC(sum, T1) 164#endif
195 LONG_SUBU a1, a1, 0x10 165 LONG_SUBU a1, a1, 0x10
196 PTR_ADDU src, src, 0x10 166 PTR_ADDU src, src, 0x10
197 LONG_SRL t8, a1, 0x7 167 LONG_SRL t8, a1, 0x7
198 168
199begin_movement: 169begin_movement:
200 beqz t8, 1f 170 beqz t8, 1f
201 andi T2, a1, 0x40 171 andi t2, a1, 0x40
202 172
203move_128bytes: 173move_128bytes:
204 CSUM_BIGCHUNK(src, 0x00, sum, T0, T1, T3, T4) 174 CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
205 CSUM_BIGCHUNK(src, 0x20, sum, T0, T1, T3, T4) 175 CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4)
206 CSUM_BIGCHUNK(src, 0x40, sum, T0, T1, T3, T4) 176 CSUM_BIGCHUNK(src, 0x40, sum, t0, t1, t3, t4)
207 CSUM_BIGCHUNK(src, 0x60, sum, T0, T1, T3, T4) 177 CSUM_BIGCHUNK(src, 0x60, sum, t0, t1, t3, t4)
208 LONG_SUBU t8, t8, 0x01 178 LONG_SUBU t8, t8, 0x01
209 bnez t8, move_128bytes 179 bnez t8, move_128bytes
210 PTR_ADDU src, src, 0x80 180 PTR_ADDU src, src, 0x80
211 181
2121: 1821:
213 beqz T2, 1f 183 beqz t2, 1f
214 andi T2, a1, 0x20 184 andi t2, a1, 0x20
215 185
216move_64bytes: 186move_64bytes:
217 CSUM_BIGCHUNK(src, 0x00, sum, T0, T1, T3, T4) 187 CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
218 CSUM_BIGCHUNK(src, 0x20, sum, T0, T1, T3, T4) 188 CSUM_BIGCHUNK(src, 0x20, sum, t0, t1, t3, t4)
219 PTR_ADDU src, src, 0x40 189 PTR_ADDU src, src, 0x40
220 190
2211: 1911:
222 beqz T2, do_end_words 192 beqz t2, do_end_words
223 andi t8, a1, 0x1c 193 andi t8, a1, 0x1c
224 194
225move_32bytes: 195move_32bytes:
226 CSUM_BIGCHUNK(src, 0x00, sum, T0, T1, T3, T4) 196 CSUM_BIGCHUNK(src, 0x00, sum, t0, t1, t3, t4)
227 andi t8, a1, 0x1c 197 andi t8, a1, 0x1c
228 PTR_ADDU src, src, 0x20 198 PTR_ADDU src, src, 0x20
229 199
230do_end_words: 200do_end_words:
231 beqz t8, maybe_end_cruft 201 beqz t8, small_csumcpy
232 LONG_SRL t8, t8, 0x2 202 andi t2, a1, 0x3
203 LONG_SRL t8, t8, 0x2
233 204
234end_words: 205end_words:
235 lw T0, (src) 206 lw t0, (src)
236 LONG_SUBU t8, t8, 0x1 207 LONG_SUBU t8, t8, 0x1
237 ADDC(sum, T0) 208 ADDC(sum, t0)
238 bnez t8, end_words 209 bnez t8, end_words
239 PTR_ADDU src, src, 0x4 210 PTR_ADDU src, src, 0x4
240 211
241maybe_end_cruft: 212/* unknown src alignment and < 8 bytes to go */
242 andi T2, a1, 0x3 213small_csumcpy:
214 move a1, t2
243 215
244small_memcpy: 216 andi t0, a1, 4
245 j small_csumcpy; move a1, T2 /* XXX ??? */ 217 beqz t0, 1f
246 beqz t2, out 218 andi t0, a1, 2
247 move a1, T2
248 219
249end_bytes: 220 /* Still a full word to go */
250 lb T0, (src) 221 ulw t1, (src)
251 LONG_SUBU a1, a1, 0x1 222 PTR_ADDIU src, 4
252 bnez a2, end_bytes 223 ADDC(sum, t1)
253 PTR_ADDU src, src, 0x1 224
2251: move t1, zero
226 beqz t0, 1f
227 andi t0, a1, 1
228
229 /* Still a halfword to go */
230 ulhu t1, (src)
231 PTR_ADDIU src, 2
232
2331: beqz t0, 1f
234 sll t1, t1, 16
235
236 lbu t2, (src)
237 nop
254 238
255out: 239#ifdef __MIPSEB__
240 sll t2, t2, 8
241#endif
242 or t1, t2
243
2441: ADDC(sum, t1)
245
246 /* fold checksum */
247#ifdef USE_DOUBLE
248 dsll32 v1, sum, 0
249 daddu sum, v1
250 sltu v1, sum, v1
251 dsra32 sum, sum, 0
252 addu sum, v1
253#endif
254 sll v1, sum, 16
255 addu sum, v1
256 sltu v1, sum, v1
257 srl sum, sum, 16
258 addu sum, v1
259
260 /* odd buffer alignment? */
261 beqz t7, 1f
262 nop
263 sll v1, sum, 8
264 srl sum, sum, 8
265 or sum, v1
266 andi sum, 0xffff
2671:
268 .set reorder
269 /* Add the passed partial csum. */
270 ADDC(sum, a2)
256 jr ra 271 jr ra
257 move v0, sum 272 .set noreorder
258 END(csum_partial) 273 END(csum_partial)
diff --git a/arch/mips/lib/csum_partial_copy.c b/arch/mips/lib/csum_partial_copy.c
index 1720f2ceeeae..06771040a267 100644
--- a/arch/mips/lib/csum_partial_copy.c
+++ b/arch/mips/lib/csum_partial_copy.c
@@ -7,6 +7,7 @@
7 * Copyright (C) 1998, 1999 Ralf Baechle 7 * Copyright (C) 1998, 1999 Ralf Baechle
8 */ 8 */
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h>
10#include <linux/types.h> 11#include <linux/types.h>
11#include <asm/byteorder.h> 12#include <asm/byteorder.h>
12#include <asm/string.h> 13#include <asm/string.h>
@@ -29,6 +30,8 @@ __wsum csum_partial_copy_nocheck(const void *src,
29 return sum; 30 return sum;
30} 31}
31 32
33EXPORT_SYMBOL(csum_partial_copy_nocheck);
34
32/* 35/*
33 * Copy from userspace and compute checksum. If we catch an exception 36 * Copy from userspace and compute checksum. If we catch an exception
34 * then zero the rest of the buffer. 37 * then zero the rest of the buffer.
diff --git a/arch/mips/mips-boards/malta/Makefile b/arch/mips/mips-boards/malta/Makefile
index 77ee5c6d33c1..b662c75fb28e 100644
--- a/arch/mips/mips-boards/malta/Makefile
+++ b/arch/mips/mips-boards/malta/Makefile
@@ -19,5 +19,5 @@
19# under Linux. 19# under Linux.
20# 20#
21 21
22obj-y := malta_int.o malta_setup.o 22obj-y := malta_int.o malta_mtd.o malta_setup.o
23obj-$(CONFIG_SMP) += malta_smp.o 23obj-$(CONFIG_SMP) += malta_smp.o
diff --git a/arch/mips/mips-boards/malta/malta_setup.c b/arch/mips/mips-boards/malta/malta_setup.c
index 282f3e52eea3..56ea76679cd4 100644
--- a/arch/mips/mips-boards/malta/malta_setup.c
+++ b/arch/mips/mips-boards/malta/malta_setup.c
@@ -21,13 +21,6 @@
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/screen_info.h> 22#include <linux/screen_info.h>
23 23
24#ifdef CONFIG_MTD
25#include <linux/mtd/partitions.h>
26#include <linux/mtd/physmap.h>
27#include <linux/mtd/mtd.h>
28#include <linux/mtd/map.h>
29#endif
30
31#include <asm/cpu.h> 24#include <asm/cpu.h>
32#include <asm/bootinfo.h> 25#include <asm/bootinfo.h>
33#include <asm/irq.h> 26#include <asm/irq.h>
@@ -58,30 +51,6 @@ struct resource standard_io_resources[] = {
58 { .name = "dma2", .start = 0xc0, .end = 0xdf, .flags = IORESOURCE_BUSY }, 51 { .name = "dma2", .start = 0xc0, .end = 0xdf, .flags = IORESOURCE_BUSY },
59}; 52};
60 53
61#ifdef CONFIG_MTD
62static struct mtd_partition malta_mtd_partitions[] = {
63 {
64 .name = "YAMON",
65 .offset = 0x0,
66 .size = 0x100000,
67 .mask_flags = MTD_WRITEABLE
68 },
69 {
70 .name = "User FS",
71 .offset = 0x100000,
72 .size = 0x2e0000
73 },
74 {
75 .name = "Board Config",
76 .offset = 0x3e0000,
77 .size = 0x020000,
78 .mask_flags = MTD_WRITEABLE
79 }
80};
81
82#define number_partitions (sizeof(malta_mtd_partitions)/sizeof(struct mtd_partition))
83#endif
84
85const char *get_system_type(void) 54const char *get_system_type(void)
86{ 55{
87 return "MIPS Malta"; 56 return "MIPS Malta";
@@ -211,14 +180,6 @@ void __init plat_mem_setup(void)
211#endif 180#endif
212#endif 181#endif
213 182
214#ifdef CONFIG_MTD
215 /*
216 * Support for MTD on Malta. Use the generic physmap driver
217 */
218 physmap_configure(0x1e000000, 0x400000, 4, NULL);
219 physmap_set_partitions(malta_mtd_partitions, number_partitions);
220#endif
221
222 mips_reboot_setup(); 183 mips_reboot_setup();
223 184
224 board_time_init = mips_time_init; 185 board_time_init = mips_time_init;
diff --git a/arch/mips/mm/cache.c b/arch/mips/mm/cache.c
index caf807ded514..1f954a238a63 100644
--- a/arch/mips/mm/cache.c
+++ b/arch/mips/mm/cache.c
@@ -32,6 +32,7 @@ void (*local_flush_data_cache_page)(void * addr);
32void (*flush_data_cache_page)(unsigned long addr); 32void (*flush_data_cache_page)(unsigned long addr);
33void (*flush_icache_all)(void); 33void (*flush_icache_all)(void);
34 34
35EXPORT_SYMBOL_GPL(local_flush_data_cache_page);
35EXPORT_SYMBOL(flush_data_cache_page); 36EXPORT_SYMBOL(flush_data_cache_page);
36 37
37#ifdef CONFIG_DMA_NONCOHERENT 38#ifdef CONFIG_DMA_NONCOHERENT
diff --git a/arch/mips/mm/init.c b/arch/mips/mm/init.c
index 9e29ba9205f0..ea2d15370bb7 100644
--- a/arch/mips/mm/init.c
+++ b/arch/mips/mm/init.c
@@ -316,7 +316,7 @@ static int __init page_is_ram(unsigned long pagenr)
316void __init paging_init(void) 316void __init paging_init(void)
317{ 317{
318 unsigned long zones_size[MAX_NR_ZONES] = { 0, }; 318 unsigned long zones_size[MAX_NR_ZONES] = { 0, };
319 unsigned long max_dma, high, low; 319 unsigned long max_dma, low;
320#ifndef CONFIG_FLATMEM 320#ifndef CONFIG_FLATMEM
321 unsigned long zholes_size[MAX_NR_ZONES] = { 0, }; 321 unsigned long zholes_size[MAX_NR_ZONES] = { 0, };
322 unsigned long i, j, pfn; 322 unsigned long i, j, pfn;
@@ -331,7 +331,6 @@ void __init paging_init(void)
331 331
332 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; 332 max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT;
333 low = max_low_pfn; 333 low = max_low_pfn;
334 high = highend_pfn;
335 334
336#ifdef CONFIG_ISA 335#ifdef CONFIG_ISA
337 if (low < max_dma) 336 if (low < max_dma)
@@ -344,13 +343,13 @@ void __init paging_init(void)
344 zones_size[ZONE_DMA] = low; 343 zones_size[ZONE_DMA] = low;
345#endif 344#endif
346#ifdef CONFIG_HIGHMEM 345#ifdef CONFIG_HIGHMEM
347 if (cpu_has_dc_aliases) { 346 zones_size[ZONE_HIGHMEM] = highend_pfn - highstart_pfn;
348 printk(KERN_WARNING "This processor doesn't support highmem."); 347
349 if (high - low) 348 if (cpu_has_dc_aliases && zones_size[ZONE_HIGHMEM]) {
350 printk(" %ldk highmem ignored", high - low); 349 printk(KERN_WARNING "This processor doesn't support highmem."
351 printk("\n"); 350 " %ldk highmem ignored\n", zones_size[ZONE_HIGHMEM]);
352 } else 351 zones_size[ZONE_HIGHMEM] = 0;
353 zones_size[ZONE_HIGHMEM] = high - low; 352 }
354#endif 353#endif
355 354
356#ifdef CONFIG_FLATMEM 355#ifdef CONFIG_FLATMEM
diff --git a/arch/mips/mm/ioremap.c b/arch/mips/mm/ioremap.c
index cea7d0ea36e4..fc2c96f0a1fd 100644
--- a/arch/mips/mm/ioremap.c
+++ b/arch/mips/mm/ioremap.c
@@ -6,98 +6,13 @@
6 * (C) Copyright 1995 1996 Linus Torvalds 6 * (C) Copyright 1995 1996 Linus Torvalds
7 * (C) Copyright 2001, 2002 Ralf Baechle 7 * (C) Copyright 2001, 2002 Ralf Baechle
8 */ 8 */
9#include <linux/mm.h>
9#include <linux/module.h> 10#include <linux/module.h>
10#include <asm/addrspace.h> 11#include <asm/addrspace.h>
11#include <asm/byteorder.h> 12#include <asm/byteorder.h>
12 13
13#include <linux/vmalloc.h> 14#include <linux/vmalloc.h>
14#include <asm/cacheflush.h> 15#include <linux/io.h>
15#include <asm/io.h>
16#include <asm/tlbflush.h>
17
18static inline void remap_area_pte(pte_t * pte, unsigned long address,
19 phys_t size, phys_t phys_addr, unsigned long flags)
20{
21 phys_t end;
22 unsigned long pfn;
23 pgprot_t pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE
24 | __WRITEABLE | flags);
25
26 address &= ~PMD_MASK;
27 end = address + size;
28 if (end > PMD_SIZE)
29 end = PMD_SIZE;
30 if (address >= end)
31 BUG();
32 pfn = phys_addr >> PAGE_SHIFT;
33 do {
34 if (!pte_none(*pte)) {
35 printk("remap_area_pte: page already exists\n");
36 BUG();
37 }
38 set_pte(pte, pfn_pte(pfn, pgprot));
39 address += PAGE_SIZE;
40 pfn++;
41 pte++;
42 } while (address && (address < end));
43}
44
45static inline int remap_area_pmd(pmd_t * pmd, unsigned long address,
46 phys_t size, phys_t phys_addr, unsigned long flags)
47{
48 phys_t end;
49
50 address &= ~PGDIR_MASK;
51 end = address + size;
52 if (end > PGDIR_SIZE)
53 end = PGDIR_SIZE;
54 phys_addr -= address;
55 if (address >= end)
56 BUG();
57 do {
58 pte_t * pte = pte_alloc_kernel(pmd, address);
59 if (!pte)
60 return -ENOMEM;
61 remap_area_pte(pte, address, end - address, address + phys_addr, flags);
62 address = (address + PMD_SIZE) & PMD_MASK;
63 pmd++;
64 } while (address && (address < end));
65 return 0;
66}
67
68static int remap_area_pages(unsigned long address, phys_t phys_addr,
69 phys_t size, unsigned long flags)
70{
71 int error;
72 pgd_t * dir;
73 unsigned long end = address + size;
74
75 phys_addr -= address;
76 dir = pgd_offset(&init_mm, address);
77 flush_cache_all();
78 if (address >= end)
79 BUG();
80 do {
81 pud_t *pud;
82 pmd_t *pmd;
83
84 error = -ENOMEM;
85 pud = pud_alloc(&init_mm, dir, address);
86 if (!pud)
87 break;
88 pmd = pmd_alloc(&init_mm, pud, address);
89 if (!pmd)
90 break;
91 if (remap_area_pmd(pmd, address, end - address,
92 phys_addr + address, flags))
93 break;
94 error = 0;
95 address = (address + PGDIR_SIZE) & PGDIR_MASK;
96 dir++;
97 } while (address && (address < end));
98 flush_tlb_all();
99 return error;
100}
101 16
102/* 17/*
103 * Generic mapping function (not visible outside): 18 * Generic mapping function (not visible outside):
@@ -121,6 +36,7 @@ void __iomem * __ioremap(phys_t phys_addr, phys_t size, unsigned long flags)
121 unsigned long offset; 36 unsigned long offset;
122 phys_t last_addr; 37 phys_t last_addr;
123 void * addr; 38 void * addr;
39 pgprot_t pgprot;
124 40
125 phys_addr = fixup_bigphys_addr(phys_addr, size); 41 phys_addr = fixup_bigphys_addr(phys_addr, size);
126 42
@@ -152,6 +68,9 @@ void __iomem * __ioremap(phys_t phys_addr, phys_t size, unsigned long flags)
152 return NULL; 68 return NULL;
153 } 69 }
154 70
71 pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | __READABLE
72 | __WRITEABLE | flags);
73
155 /* 74 /*
156 * Mappings have to be page-aligned 75 * Mappings have to be page-aligned
157 */ 76 */
@@ -166,7 +85,8 @@ void __iomem * __ioremap(phys_t phys_addr, phys_t size, unsigned long flags)
166 if (!area) 85 if (!area)
167 return NULL; 86 return NULL;
168 addr = area->addr; 87 addr = area->addr;
169 if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { 88 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
89 phys_addr, pgprot)) {
170 vunmap(addr); 90 vunmap(addr);
171 return NULL; 91 return NULL;
172 } 92 }
diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile
index 70cb55b89df6..82b20c28bef8 100644
--- a/arch/mips/pci/Makefile
+++ b/arch/mips/pci/Makefile
@@ -43,7 +43,7 @@ obj-$(CONFIG_SGI_IP32) += fixup-ip32.o ops-mace.o pci-ip32.o
43obj-$(CONFIG_SIBYTE_SB1250) += fixup-sb1250.o pci-sb1250.o 43obj-$(CONFIG_SIBYTE_SB1250) += fixup-sb1250.o pci-sb1250.o
44obj-$(CONFIG_SIBYTE_BCM112X) += fixup-sb1250.o pci-sb1250.o 44obj-$(CONFIG_SIBYTE_BCM112X) += fixup-sb1250.o pci-sb1250.o
45obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1480.o pci-bcm1480ht.o 45obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1480.o pci-bcm1480ht.o
46obj-$(CONFIG_SNI_RM200_PCI) += fixup-sni.o ops-sni.o 46obj-$(CONFIG_SNI_RM) += fixup-sni.o ops-sni.o
47obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o 47obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
48obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o 48obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
49obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o 49obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
diff --git a/arch/mips/pci/fixup-pnx8550.c b/arch/mips/pci/fixup-pnx8550.c
index 4256b3b30b77..50546dab6689 100644
--- a/arch/mips/pci/fixup-pnx8550.c
+++ b/arch/mips/pci/fixup-pnx8550.c
@@ -33,7 +33,7 @@
33#define DBG(x...) 33#define DBG(x...)
34#endif 34#endif
35 35
36extern char irq_tab_jbs[][5]; 36extern char pnx8550_irq_tab[][5];
37 37
38void __init pcibios_fixup_resources(struct pci_dev *dev) 38void __init pcibios_fixup_resources(struct pci_dev *dev)
39{ 39{
@@ -47,7 +47,7 @@ void __init pcibios_fixup(void)
47 47
48int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 48int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
49{ 49{
50 return irq_tab_jbs[slot][pin]; 50 return pnx8550_irq_tab[slot][pin];
51} 51}
52 52
53/* Do platform specific device initialization at pci_enable_device() time */ 53/* Do platform specific device initialization at pci_enable_device() time */
diff --git a/arch/mips/philips/pnx8550/common/prom.c b/arch/mips/philips/pnx8550/common/prom.c
index f8952c1359cd..eb6ec11fef07 100644
--- a/arch/mips/philips/pnx8550/common/prom.c
+++ b/arch/mips/philips/pnx8550/common/prom.c
@@ -35,23 +35,15 @@ char * prom_getcmdline(void)
35 return &(arcs_cmdline[0]); 35 return &(arcs_cmdline[0]);
36} 36}
37 37
38void prom_init_cmdline(void) 38void __init prom_init_cmdline(void)
39{ 39{
40 char *cp; 40 int i;
41 int actr;
42
43 actr = 1; /* Always ignore argv[0] */
44 41
45 cp = &(arcs_cmdline[0]); 42 arcs_cmdline[0] = '\0';
46 while(actr < prom_argc) { 43 for (i = 0; i < prom_argc; i++) {
47 strcpy(cp, prom_argv[actr]); 44 strcat(arcs_cmdline, prom_argv[i]);
48 cp += strlen(prom_argv[actr]); 45 strcat(arcs_cmdline, " ");
49 *cp++ = ' ';
50 actr++;
51 } 46 }
52 if (cp != &(arcs_cmdline[0])) /* get rid of trailing space */
53 --cp;
54 *cp = '\0';
55} 47}
56 48
57char *prom_getenv(char *envname) 49char *prom_getenv(char *envname)
diff --git a/arch/mips/philips/pnx8550/jbs/irqmap.c b/arch/mips/philips/pnx8550/jbs/irqmap.c
index f78e0423dc98..98c3429e6e50 100644
--- a/arch/mips/philips/pnx8550/jbs/irqmap.c
+++ b/arch/mips/philips/pnx8550/jbs/irqmap.c
@@ -28,9 +28,9 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <int.h> 29#include <int.h>
30 30
31char irq_tab_jbs[][5] __initdata = { 31char pnx8550_irq_tab[][5] __initdata = {
32 [8] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff}, 32 [8] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
33 [9] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff}, 33 [9] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
34 [17] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff}, 34 [17] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
35}; 35};
36 36
diff --git a/arch/mips/philips/pnx8550/stb810/Makefile b/arch/mips/philips/pnx8550/stb810/Makefile
new file mode 100644
index 000000000000..f14b592af398
--- /dev/null
+++ b/arch/mips/philips/pnx8550/stb810/Makefile
@@ -0,0 +1,4 @@
1
2# Makefile for the Philips STB810 Board.
3
4lib-y := prom_init.o board_setup.o irqmap.o
diff --git a/arch/mips/philips/pnx8550/stb810/board_setup.c b/arch/mips/philips/pnx8550/stb810/board_setup.c
new file mode 100644
index 000000000000..345d71e53cf2
--- /dev/null
+++ b/arch/mips/philips/pnx8550/stb810/board_setup.c
@@ -0,0 +1,49 @@
1/*
2 * STB810 specific board startup routines.
3 *
4 * Based on the arch/mips/philips/pnx8550/jbs/board_setup.c
5 *
6 * Author: MontaVista Software, Inc.
7 * source@mvista.com
8 *
9 * Copyright 2005 MontaVista Software Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
17#include <linux/init.h>
18#include <linux/sched.h>
19#include <linux/ioport.h>
20#include <linux/mm.h>
21#include <linux/console.h>
22#include <linux/mc146818rtc.h>
23#include <linux/delay.h>
24
25#include <asm/cpu.h>
26#include <asm/bootinfo.h>
27#include <asm/irq.h>
28#include <asm/mipsregs.h>
29#include <asm/reboot.h>
30#include <asm/pgtable.h>
31
32#include <glb.h>
33
34void __init board_setup(void)
35{
36 unsigned long config0, configpr;
37
38 config0 = read_c0_config();
39
40 /* clear all three cache coherency fields */
41 config0 &= ~(0x7 | (7<<25) | (7<<28));
42 config0 |= (CONF_CM_DEFAULT | (CONF_CM_DEFAULT<<25) |
43 (CONF_CM_DEFAULT<<28));
44 write_c0_config(config0);
45
46 configpr = read_c0_config7();
47 configpr |= (1<<19); /* enable tlb */
48 write_c0_config7(configpr);
49}
diff --git a/arch/mips/philips/pnx8550/stb810/irqmap.c b/arch/mips/philips/pnx8550/stb810/irqmap.c
new file mode 100644
index 000000000000..5ee11e19975e
--- /dev/null
+++ b/arch/mips/philips/pnx8550/stb810/irqmap.c
@@ -0,0 +1,23 @@
1/*
2 * Philips STB810 board irqmap.
3 *
4 * Author: MontaVista Software, Inc.
5 * source@mvista.com
6 *
7 * Copyright 2005 MontaVista Software Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/init.h>
16#include <int.h>
17
18char pnx8550_irq_tab[][5] __initdata = {
19 [8] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
20 [9] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
21 [10] = { -1, PNX8550_INT_PCI_INTA, 0xff, 0xff, 0xff},
22};
23
diff --git a/arch/mips/philips/pnx8550/stb810/prom_init.c b/arch/mips/philips/pnx8550/stb810/prom_init.c
new file mode 100644
index 000000000000..ea5b4e0fb47d
--- /dev/null
+++ b/arch/mips/philips/pnx8550/stb810/prom_init.c
@@ -0,0 +1,49 @@
1/*
2 * STB810 specific prom routines
3 *
4 * Author: MontaVista Software, Inc.
5 * source@mvista.com
6 *
7 * Copyright 2005 MontaVista Software Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13 */
14
15#include <linux/init.h>
16#include <linux/mm.h>
17#include <linux/sched.h>
18#include <linux/bootmem.h>
19#include <asm/addrspace.h>
20#include <asm/bootinfo.h>
21#include <linux/string.h>
22#include <linux/kernel.h>
23
24int prom_argc;
25char **prom_argv, **prom_envp;
26extern void __init prom_init_cmdline(void);
27extern char *prom_getenv(char *envname);
28
29const char *get_system_type(void)
30{
31 return "Philips PNX8550/STB810";
32}
33
34void __init prom_init(void)
35{
36 unsigned long memsize;
37
38 prom_argc = (int) fw_arg0;
39 prom_argv = (char **) fw_arg1;
40 prom_envp = (char **) fw_arg2;
41
42 prom_init_cmdline();
43
44 mips_machgroup = MACH_GROUP_PHILIPS;
45 mips_machtype = MACH_PHILIPS_STB810;
46
47 memsize = 0x08000000; /* Trimedia uses memory above */
48 add_memory_region(0, memsize, BOOT_MEM_RAM);
49}
diff --git a/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_irq.c b/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_irq.c
index 5a5ea6c0b9f6..b54b529a29f9 100644
--- a/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_irq.c
+++ b/arch/mips/tx4927/toshiba_rbtx4927/toshiba_rbtx4927_irq.c
@@ -158,7 +158,6 @@ JP7 is not bus master -- do NOT use -- only 4 pci bus master's allowed -- SouthB
158#define TOSHIBA_RBTX4927_IRQ_ISA_ENABLE ( 1 << 23 ) 158#define TOSHIBA_RBTX4927_IRQ_ISA_ENABLE ( 1 << 23 )
159#define TOSHIBA_RBTX4927_IRQ_ISA_DISABLE ( 1 << 24 ) 159#define TOSHIBA_RBTX4927_IRQ_ISA_DISABLE ( 1 << 24 )
160#define TOSHIBA_RBTX4927_IRQ_ISA_MASK ( 1 << 25 ) 160#define TOSHIBA_RBTX4927_IRQ_ISA_MASK ( 1 << 25 )
161#define TOSHIBA_RBTX4927_IRQ_ISA_ENDIRQ ( 1 << 26 )
162 161
163#define TOSHIBA_RBTX4927_SETUP_ALL 0xffffffff 162#define TOSHIBA_RBTX4927_SETUP_ALL 0xffffffff
164#endif 163#endif
@@ -175,7 +174,6 @@ static const u32 toshiba_rbtx4927_irq_debug_flag =
175// | TOSHIBA_RBTX4927_IRQ_ISA_ENABLE 174// | TOSHIBA_RBTX4927_IRQ_ISA_ENABLE
176// | TOSHIBA_RBTX4927_IRQ_ISA_DISABLE 175// | TOSHIBA_RBTX4927_IRQ_ISA_DISABLE
177// | TOSHIBA_RBTX4927_IRQ_ISA_MASK 176// | TOSHIBA_RBTX4927_IRQ_ISA_MASK
178// | TOSHIBA_RBTX4927_IRQ_ISA_ENDIRQ
179 ); 177 );
180#endif 178#endif
181 179
@@ -226,7 +224,6 @@ static void toshiba_rbtx4927_irq_ioc_disable(unsigned int irq);
226static void toshiba_rbtx4927_irq_isa_enable(unsigned int irq); 224static void toshiba_rbtx4927_irq_isa_enable(unsigned int irq);
227static void toshiba_rbtx4927_irq_isa_disable(unsigned int irq); 225static void toshiba_rbtx4927_irq_isa_disable(unsigned int irq);
228static void toshiba_rbtx4927_irq_isa_mask_and_ack(unsigned int irq); 226static void toshiba_rbtx4927_irq_isa_mask_and_ack(unsigned int irq);
229static void toshiba_rbtx4927_irq_isa_end(unsigned int irq);
230#endif 227#endif
231 228
232#define TOSHIBA_RBTX4927_IOC_NAME "RBTX4927-IOC" 229#define TOSHIBA_RBTX4927_IOC_NAME "RBTX4927-IOC"
@@ -249,7 +246,6 @@ static struct irq_chip toshiba_rbtx4927_irq_isa_type = {
249 .mask = toshiba_rbtx4927_irq_isa_disable, 246 .mask = toshiba_rbtx4927_irq_isa_disable,
250 .mask_ack = toshiba_rbtx4927_irq_isa_mask_and_ack, 247 .mask_ack = toshiba_rbtx4927_irq_isa_mask_and_ack,
251 .unmask = toshiba_rbtx4927_irq_isa_enable, 248 .unmask = toshiba_rbtx4927_irq_isa_enable,
252 .end = toshiba_rbtx4927_irq_isa_end,
253}; 249};
254#endif 250#endif
255 251
@@ -402,7 +398,8 @@ static void __init toshiba_rbtx4927_irq_isa_init(void)
402 398
403 for (i = TOSHIBA_RBTX4927_IRQ_ISA_BEG; 399 for (i = TOSHIBA_RBTX4927_IRQ_ISA_BEG;
404 i <= TOSHIBA_RBTX4927_IRQ_ISA_END; i++) 400 i <= TOSHIBA_RBTX4927_IRQ_ISA_END; i++)
405 set_irq_chip(i, &toshiba_rbtx4927_irq_isa_type); 401 set_irq_chip_and_handler(i, &toshiba_rbtx4927_irq_isa_type,
402 handle_level_irq);
406 403
407 setup_irq(TOSHIBA_RBTX4927_IRQ_NEST_ISA_ON_IOC, 404 setup_irq(TOSHIBA_RBTX4927_IRQ_NEST_ISA_ON_IOC,
408 &toshiba_rbtx4927_irq_isa_master); 405 &toshiba_rbtx4927_irq_isa_master);
@@ -470,26 +467,6 @@ static void toshiba_rbtx4927_irq_isa_mask_and_ack(unsigned int irq)
470#endif 467#endif
471 468
472 469
473#ifdef CONFIG_TOSHIBA_FPCIB0
474static void toshiba_rbtx4927_irq_isa_end(unsigned int irq)
475{
476 TOSHIBA_RBTX4927_IRQ_DPRINTK(TOSHIBA_RBTX4927_IRQ_ISA_ENDIRQ,
477 "irq=%d\n", irq);
478
479 if (irq < TOSHIBA_RBTX4927_IRQ_ISA_BEG
480 || irq > TOSHIBA_RBTX4927_IRQ_ISA_END) {
481 TOSHIBA_RBTX4927_IRQ_DPRINTK(TOSHIBA_RBTX4927_IRQ_EROR,
482 "bad irq=%d\n", irq);
483 panic("\n");
484 }
485
486 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
487 toshiba_rbtx4927_irq_isa_enable(irq);
488 }
489}
490#endif
491
492
493void __init arch_init_irq(void) 470void __init arch_init_irq(void)
494{ 471{
495 extern void tx4927_irq_init(void); 472 extern void tx4927_irq_init(void);
diff --git a/arch/mips/vr41xx/Kconfig b/arch/mips/vr41xx/Kconfig
index c8dfd8092cab..92f41f6f934a 100644
--- a/arch/mips/vr41xx/Kconfig
+++ b/arch/mips/vr41xx/Kconfig
@@ -6,7 +6,6 @@ config CASIO_E55
6 select ISA 6 select ISA
7 select SYS_SUPPORTS_32BIT_KERNEL 7 select SYS_SUPPORTS_32BIT_KERNEL
8 select SYS_SUPPORTS_LITTLE_ENDIAN 8 select SYS_SUPPORTS_LITTLE_ENDIAN
9 select GENERIC_HARDIRQS_NO__DO_IRQ
10 9
11config IBM_WORKPAD 10config IBM_WORKPAD
12 bool "Support for IBM WorkPad z50" 11 bool "Support for IBM WorkPad z50"
@@ -16,7 +15,6 @@ config IBM_WORKPAD
16 select ISA 15 select ISA
17 select SYS_SUPPORTS_32BIT_KERNEL 16 select SYS_SUPPORTS_32BIT_KERNEL
18 select SYS_SUPPORTS_LITTLE_ENDIAN 17 select SYS_SUPPORTS_LITTLE_ENDIAN
19 select GENERIC_HARDIRQS_NO__DO_IRQ
20 18
21config NEC_CMBVR4133 19config NEC_CMBVR4133
22 bool "Support for NEC CMB-VR4133" 20 bool "Support for NEC CMB-VR4133"
@@ -41,7 +39,6 @@ config TANBAC_TB022X
41 select IRQ_CPU 39 select IRQ_CPU
42 select SYS_SUPPORTS_32BIT_KERNEL 40 select SYS_SUPPORTS_32BIT_KERNEL
43 select SYS_SUPPORTS_LITTLE_ENDIAN 41 select SYS_SUPPORTS_LITTLE_ENDIAN
44 select GENERIC_HARDIRQS_NO__DO_IRQ
45 help 42 help
46 The TANBAC VR4131 multichip module(TB0225) and 43 The TANBAC VR4131 multichip module(TB0225) and
47 the TANBAC VR4131DIMM(TB0229) are MIPS-based platforms 44 the TANBAC VR4131DIMM(TB0229) are MIPS-based platforms
@@ -74,7 +71,6 @@ config VICTOR_MPC30X
74 select IRQ_CPU 71 select IRQ_CPU
75 select SYS_SUPPORTS_32BIT_KERNEL 72 select SYS_SUPPORTS_32BIT_KERNEL
76 select SYS_SUPPORTS_LITTLE_ENDIAN 73 select SYS_SUPPORTS_LITTLE_ENDIAN
77 select GENERIC_HARDIRQS_NO__DO_IRQ
78 74
79config ZAO_CAPCELLA 75config ZAO_CAPCELLA
80 bool "Support for ZAO Networks Capcella" 76 bool "Support for ZAO Networks Capcella"
@@ -84,7 +80,6 @@ config ZAO_CAPCELLA
84 select IRQ_CPU 80 select IRQ_CPU
85 select SYS_SUPPORTS_32BIT_KERNEL 81 select SYS_SUPPORTS_32BIT_KERNEL
86 select SYS_SUPPORTS_LITTLE_ENDIAN 82 select SYS_SUPPORTS_LITTLE_ENDIAN
87 select GENERIC_HARDIRQS_NO__DO_IRQ
88 83
89config PCI_VR41XX 84config PCI_VR41XX
90 bool "Add PCI control unit support of NEC VR4100 series" 85 bool "Add PCI control unit support of NEC VR4100 series"
diff --git a/arch/mips/vr41xx/nec-cmbvr4133/irq.c b/arch/mips/vr41xx/nec-cmbvr4133/irq.c
index a039bb7251ff..128ed8d6f111 100644
--- a/arch/mips/vr41xx/nec-cmbvr4133/irq.c
+++ b/arch/mips/vr41xx/nec-cmbvr4133/irq.c
@@ -45,19 +45,12 @@ static void ack_i8259_irq(unsigned int irq)
45 mask_and_ack_8259A(irq - I8259_IRQ_BASE); 45 mask_and_ack_8259A(irq - I8259_IRQ_BASE);
46} 46}
47 47
48static void end_i8259_irq(unsigned int irq)
49{
50 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
51 enable_8259A_irq(irq - I8259_IRQ_BASE);
52}
53
54static struct irq_chip i8259_irq_type = { 48static struct irq_chip i8259_irq_type = {
55 .typename = "XT-PIC", 49 .typename = "XT-PIC",
56 .ack = ack_i8259_irq, 50 .ack = ack_i8259_irq,
57 .mask = disable_i8259_irq, 51 .mask = disable_i8259_irq,
58 .mask_ack = ack_i8259_irq, 52 .mask_ack = ack_i8259_irq,
59 .unmask = enable_i8259_irq, 53 .unmask = enable_i8259_irq,
60 .end = end_i8259_irq,
61}; 54};
62 55
63static int i8259_get_irq_number(int irq) 56static int i8259_get_irq_number(int irq)
@@ -92,7 +85,7 @@ void __init rockhopper_init_irq(void)
92 } 85 }
93 86
94 for (i = I8259_IRQ_BASE; i <= I8259_IRQ_LAST; i++) 87 for (i = I8259_IRQ_BASE; i <= I8259_IRQ_LAST; i++)
95 set_irq_chip(i, &i8259_irq_type); 88 set_irq_chip_and_handler(i, &i8259_irq_type, handle_level_irq);
96 89
97 setup_irq(I8259_SLAVE_IRQ, &i8259_slave_cascade); 90 setup_irq(I8259_SLAVE_IRQ, &i8259_slave_cascade);
98 91
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index d2101237442e..0f9ff618c6d7 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -25,6 +25,14 @@ config RWSEM_GENERIC_SPINLOCK
25config RWSEM_XCHGADD_ALGORITHM 25config RWSEM_XCHGADD_ALGORITHM
26 bool 26 bool
27 27
28config ARCH_HAS_ILOG2_U32
29 bool
30 default n
31
32config ARCH_HAS_ILOG2_U64
33 bool
34 default n
35
28config GENERIC_FIND_NEXT_BIT 36config GENERIC_FIND_NEXT_BIT
29 bool 37 bool
30 default y 38 default y
diff --git a/arch/parisc/hpux/sys_hpux.c b/arch/parisc/hpux/sys_hpux.c
index 2e2dc4f2c853..d88309209f56 100644
--- a/arch/parisc/hpux/sys_hpux.c
+++ b/arch/parisc/hpux/sys_hpux.c
@@ -237,7 +237,7 @@ asmlinkage long hpux_fstatfs(unsigned int fd, struct hpux_statfs __user * buf)
237 file = fget(fd); 237 file = fget(fd);
238 if (!file) 238 if (!file)
239 goto out; 239 goto out;
240 error = vfs_statfs_hpux(file->f_dentry, &tmp); 240 error = vfs_statfs_hpux(file->f_path.dentry, &tmp);
241 if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) 241 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
242 error = -EFAULT; 242 error = -EFAULT;
243 fput(file); 243 fput(file);
diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c
index 47a1d2ac9419..44b42c7f639d 100644
--- a/arch/parisc/mm/ioremap.c
+++ b/arch/parisc/mm/ioremap.c
@@ -9,110 +9,8 @@
9#include <linux/vmalloc.h> 9#include <linux/vmalloc.h>
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <asm/io.h> 12#include <linux/io.h>
13#include <asm/pgalloc.h> 13#include <asm/pgalloc.h>
14#include <asm/tlbflush.h>
15#include <asm/cacheflush.h>
16
17static inline void
18remap_area_pte(pte_t *pte, unsigned long address, unsigned long size,
19 unsigned long phys_addr, unsigned long flags)
20{
21 unsigned long end, pfn;
22 pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
23 _PAGE_ACCESSED | flags);
24
25 address &= ~PMD_MASK;
26
27 end = address + size;
28 if (end > PMD_SIZE)
29 end = PMD_SIZE;
30
31 BUG_ON(address >= end);
32
33 pfn = phys_addr >> PAGE_SHIFT;
34 do {
35 BUG_ON(!pte_none(*pte));
36
37 set_pte(pte, pfn_pte(pfn, pgprot));
38
39 address += PAGE_SIZE;
40 pfn++;
41 pte++;
42 } while (address && (address < end));
43}
44
45static inline int
46remap_area_pmd(pmd_t *pmd, unsigned long address, unsigned long size,
47 unsigned long phys_addr, unsigned long flags)
48{
49 unsigned long end;
50
51 address &= ~PGDIR_MASK;
52
53 end = address + size;
54 if (end > PGDIR_SIZE)
55 end = PGDIR_SIZE;
56
57 BUG_ON(address >= end);
58
59 phys_addr -= address;
60 do {
61 pte_t *pte = pte_alloc_kernel(pmd, address);
62 if (!pte)
63 return -ENOMEM;
64
65 remap_area_pte(pte, address, end - address,
66 address + phys_addr, flags);
67
68 address = (address + PMD_SIZE) & PMD_MASK;
69 pmd++;
70 } while (address && (address < end));
71
72 return 0;
73}
74
75static int
76remap_area_pages(unsigned long address, unsigned long phys_addr,
77 unsigned long size, unsigned long flags)
78{
79 pgd_t *dir;
80 int error = 0;
81 unsigned long end = address + size;
82
83 BUG_ON(address >= end);
84
85 phys_addr -= address;
86 dir = pgd_offset_k(address);
87
88 flush_cache_all();
89
90 do {
91 pud_t *pud;
92 pmd_t *pmd;
93
94 error = -ENOMEM;
95 pud = pud_alloc(&init_mm, dir, address);
96 if (!pud)
97 break;
98
99 pmd = pmd_alloc(&init_mm, pud, address);
100 if (!pmd)
101 break;
102
103 if (remap_area_pmd(pmd, address, end - address,
104 phys_addr + address, flags))
105 break;
106
107 error = 0;
108 address = (address + PGDIR_SIZE) & PGDIR_MASK;
109 dir++;
110 } while (address && (address < end));
111
112 flush_tlb_all();
113
114 return error;
115}
116 14
117/* 15/*
118 * Generic mapping function (not visible outside): 16 * Generic mapping function (not visible outside):
@@ -131,6 +29,7 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
131 void *addr; 29 void *addr;
132 struct vm_struct *area; 30 struct vm_struct *area;
133 unsigned long offset, last_addr; 31 unsigned long offset, last_addr;
32 pgprot_t pgprot;
134 33
135#ifdef CONFIG_EISA 34#ifdef CONFIG_EISA
136 unsigned long end = phys_addr + size - 1; 35 unsigned long end = phys_addr + size - 1;
@@ -164,6 +63,9 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
164 } 63 }
165 } 64 }
166 65
66 pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY |
67 _PAGE_ACCESSED | flags);
68
167 /* 69 /*
168 * Mappings have to be page-aligned 70 * Mappings have to be page-aligned
169 */ 71 */
@@ -179,7 +81,8 @@ void __iomem * __ioremap(unsigned long phys_addr, unsigned long size, unsigned l
179 return NULL; 81 return NULL;
180 82
181 addr = area->addr; 83 addr = area->addr;
182 if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { 84 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
85 phys_addr, pgprot)) {
183 vfree(addr); 86 vfree(addr);
184 return NULL; 87 return NULL;
185 } 88 }
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 291c95ac4b31..8699dadcd096 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -41,6 +41,14 @@ config RWSEM_XCHGADD_ALGORITHM
41 bool 41 bool
42 default y 42 default y
43 43
44config ARCH_HAS_ILOG2_U32
45 bool
46 default y
47
48config ARCH_HAS_ILOG2_U64
49 bool
50 default y if 64BIT
51
44config GENERIC_HWEIGHT 52config GENERIC_HWEIGHT
45 bool 53 bool
46 default y 54 default y
@@ -99,6 +107,11 @@ config AUDIT_ARCH
99 bool 107 bool
100 default y 108 default y
101 109
110config GENERIC_BUG
111 bool
112 default y
113 depends on BUG
114
102config DEFAULT_UIMAGE 115config DEFAULT_UIMAGE
103 bool 116 bool
104 help 117 help
@@ -470,6 +483,7 @@ config PPC_MAPLE
470 select PPC_UDBG_16550 483 select PPC_UDBG_16550
471 select PPC_970_NAP 484 select PPC_970_NAP
472 select PPC_NATIVE 485 select PPC_NATIVE
486 select PPC_RTAS
473 default n 487 default n
474 help 488 help
475 This option enables support for the Maple 970FX Evaluation Board. 489 This option enables support for the Maple 970FX Evaluation Board.
@@ -706,7 +720,7 @@ config FORCE_MAX_ZONEORDER
706 720
707config MATH_EMULATION 721config MATH_EMULATION
708 bool "Math emulation" 722 bool "Math emulation"
709 depends on 4xx || 8xx || E200 || E500 723 depends on 4xx || 8xx || E200 || PPC_83xx || E500
710 ---help--- 724 ---help---
711 Some PowerPC chips designed for embedded applications do not have 725 Some PowerPC chips designed for embedded applications do not have
712 a floating-point unit and therefore do not implement the 726 a floating-point unit and therefore do not implement the
diff --git a/arch/powerpc/configs/ps3_defconfig b/arch/powerpc/configs/ps3_defconfig
index f2d888e014a9..70ed61337f5c 100644
--- a/arch/powerpc/configs/ps3_defconfig
+++ b/arch/powerpc/configs/ps3_defconfig
@@ -157,6 +157,7 @@ CONFIG_SPU_BASE=y
157CONFIG_PS3_HTAB_SIZE=20 157CONFIG_PS3_HTAB_SIZE=20
158CONFIG_PS3_DYNAMIC_DMA=y 158CONFIG_PS3_DYNAMIC_DMA=y
159CONFIG_PS3_USE_LPAR_ADDR=y 159CONFIG_PS3_USE_LPAR_ADDR=y
160CONFIG_PS3_VUART=y
160 161
161# 162#
162# Kernel options 163# Kernel options
diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index 4fe53d08ab81..d2ded19e4064 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -77,6 +77,7 @@ endif
77 77
78ifeq ($(CONFIG_PPC_ISERIES),y) 78ifeq ($(CONFIG_PPC_ISERIES),y)
79extra-y += lparmap.s 79extra-y += lparmap.s
80$(obj)/head_64.o: $(obj)/lparmap.s
80AFLAGS_head_64.o += -I$(obj) 81AFLAGS_head_64.o += -I$(obj)
81endif 82endif
82 83
diff --git a/arch/powerpc/kernel/cputable.c b/arch/powerpc/kernel/cputable.c
index 9d1614c3ce67..b742013bb9da 100644
--- a/arch/powerpc/kernel/cputable.c
+++ b/arch/powerpc/kernel/cputable.c
@@ -833,7 +833,7 @@ static struct cpu_spec cpu_specs[] = {
833 .pvr_mask = 0x7fff0000, 833 .pvr_mask = 0x7fff0000,
834 .pvr_value = 0x00840000, 834 .pvr_value = 0x00840000,
835 .cpu_name = "e300c2", 835 .cpu_name = "e300c2",
836 .cpu_features = CPU_FTRS_E300, 836 .cpu_features = CPU_FTRS_E300C2,
837 .cpu_user_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU, 837 .cpu_user_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU,
838 .icache_bsize = 32, 838 .icache_bsize = 32,
839 .dcache_bsize = 32, 839 .dcache_bsize = 32,
@@ -1136,8 +1136,7 @@ static struct cpu_spec cpu_specs[] = {
1136 .pvr_mask = 0xff000fff, 1136 .pvr_mask = 0xff000fff,
1137 .pvr_value = 0x53000890, 1137 .pvr_value = 0x53000890,
1138 .cpu_name = "440SPe Rev. A", 1138 .cpu_name = "440SPe Rev. A",
1139 .cpu_features = CPU_FTR_SPLIT_ID_CACHE | 1139 .cpu_features = CPU_FTRS_44X,
1140 CPU_FTR_USE_TB,
1141 .cpu_user_features = COMMON_USER_BOOKE, 1140 .cpu_user_features = COMMON_USER_BOOKE,
1142 .icache_bsize = 32, 1141 .icache_bsize = 32,
1143 .dcache_bsize = 32, 1142 .dcache_bsize = 32,
diff --git a/arch/powerpc/kernel/head_32.S b/arch/powerpc/kernel/head_32.S
index d88e182e40b3..9417cf5b4b7e 100644
--- a/arch/powerpc/kernel/head_32.S
+++ b/arch/powerpc/kernel/head_32.S
@@ -437,6 +437,13 @@ Alignment:
437/* Floating-point unavailable */ 437/* Floating-point unavailable */
438 . = 0x800 438 . = 0x800
439FPUnavailable: 439FPUnavailable:
440BEGIN_FTR_SECTION
441/*
442 * Certain Freescale cores don't have a FPU and treat fp instructions
443 * as a FP Unavailable exception. Redirect to illegal/emulation handling.
444 */
445 b ProgramCheck
446END_FTR_SECTION_IFSET(CPU_FTR_FPU_UNAVAILABLE)
440 EXCEPTION_PROLOG 447 EXCEPTION_PROLOG
441 bne load_up_fpu /* if from user, just load it up */ 448 bne load_up_fpu /* if from user, just load it up */
442 addi r3,r1,STACK_FRAME_OVERHEAD 449 addi r3,r1,STACK_FRAME_OVERHEAD
diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
index e2c3c6a85f33..8339fd609de0 100644
--- a/arch/powerpc/kernel/module_32.c
+++ b/arch/powerpc/kernel/module_32.c
@@ -23,6 +23,7 @@
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/cache.h> 25#include <linux/cache.h>
26#include <linux/bug.h>
26 27
27#include "setup.h" 28#include "setup.h"
28 29
@@ -290,23 +291,11 @@ int module_finalize(const Elf_Ehdr *hdr,
290 struct module *me) 291 struct module *me)
291{ 292{
292 const Elf_Shdr *sect; 293 const Elf_Shdr *sect;
294 int err;
293 295
294 me->arch.bug_table = NULL; 296 err = module_bug_finalize(hdr, sechdrs, me);
295 me->arch.num_bugs = 0; 297 if (err) /* never true, currently */
296 298 return err;
297 /* Find the __bug_table section, if present */
298 sect = find_section(hdr, sechdrs, "__bug_table");
299 if (sect != NULL) {
300 me->arch.bug_table = (void *) sect->sh_addr;
301 me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
302 }
303
304 /*
305 * Strictly speaking this should have a spinlock to protect against
306 * traversals, but since we only traverse on BUG()s, a spinlock
307 * could potentially lead to deadlock and thus be counter-productive.
308 */
309 list_add(&me->arch.bug_list, &module_bug_list);
310 299
311 /* Apply feature fixups */ 300 /* Apply feature fixups */
312 sect = find_section(hdr, sechdrs, "__ftr_fixup"); 301 sect = find_section(hdr, sechdrs, "__ftr_fixup");
@@ -320,7 +309,7 @@ int module_finalize(const Elf_Ehdr *hdr,
320 309
321void module_arch_cleanup(struct module *mod) 310void module_arch_cleanup(struct module *mod)
322{ 311{
323 list_del(&mod->arch.bug_list); 312 module_bug_cleanup(mod);
324} 313}
325 314
326struct bug_entry *module_find_bug(unsigned long bugaddr) 315struct bug_entry *module_find_bug(unsigned long bugaddr)
diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c
index 8dd1f0aae5d6..75c7c4f19280 100644
--- a/arch/powerpc/kernel/module_64.c
+++ b/arch/powerpc/kernel/module_64.c
@@ -20,6 +20,7 @@
20#include <linux/moduleloader.h> 20#include <linux/moduleloader.h>
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
23#include <linux/bug.h>
23#include <asm/module.h> 24#include <asm/module.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
25#include <asm/firmware.h> 26#include <asm/firmware.h>
@@ -439,23 +440,11 @@ int module_finalize(const Elf_Ehdr *hdr,
439 const Elf_Shdr *sechdrs, struct module *me) 440 const Elf_Shdr *sechdrs, struct module *me)
440{ 441{
441 const Elf_Shdr *sect; 442 const Elf_Shdr *sect;
443 int err;
442 444
443 me->arch.bug_table = NULL; 445 err = module_bug_finalize(hdr, sechdrs, me);
444 me->arch.num_bugs = 0; 446 if (err)
445 447 return err;
446 /* Find the __bug_table section, if present */
447 sect = find_section(hdr, sechdrs, "__bug_table");
448 if (sect != NULL) {
449 me->arch.bug_table = (void *) sect->sh_addr;
450 me->arch.num_bugs = sect->sh_size / sizeof(struct bug_entry);
451 }
452
453 /*
454 * Strictly speaking this should have a spinlock to protect against
455 * traversals, but since we only traverse on BUG()s, a spinlock
456 * could potentially lead to deadlock and thus be counter-productive.
457 */
458 list_add(&me->arch.bug_list, &module_bug_list);
459 448
460 /* Apply feature fixups */ 449 /* Apply feature fixups */
461 sect = find_section(hdr, sechdrs, "__ftr_fixup"); 450 sect = find_section(hdr, sechdrs, "__ftr_fixup");
@@ -475,7 +464,7 @@ int module_finalize(const Elf_Ehdr *hdr,
475 464
476void module_arch_cleanup(struct module *mod) 465void module_arch_cleanup(struct module *mod)
477{ 466{
478 list_del(&mod->arch.bug_list); 467 module_bug_cleanup(mod);
479} 468}
480 469
481struct bug_entry *module_find_bug(unsigned long bugaddr) 470struct bug_entry *module_find_bug(unsigned long bugaddr)
diff --git a/arch/powerpc/kernel/of_device.c b/arch/powerpc/kernel/of_device.c
index 8a06724e029e..e921514e655b 100644
--- a/arch/powerpc/kernel/of_device.c
+++ b/arch/powerpc/kernel/of_device.c
@@ -109,9 +109,7 @@ int of_device_register(struct of_device *ofdev)
109 if (rc) 109 if (rc)
110 return rc; 110 return rc;
111 111
112 device_create_file(&ofdev->dev, &dev_attr_devspec); 112 return device_create_file(&ofdev->dev, &dev_attr_devspec);
113
114 return 0;
115} 113}
116 114
117void of_device_unregister(struct of_device *ofdev) 115void of_device_unregister(struct of_device *ofdev)
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index b3189d0161b8..3002ea3a61a2 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -169,7 +169,7 @@ static void of_platform_make_bus_id(struct of_device *dev)
169 char *name = dev->dev.bus_id; 169 char *name = dev->dev.bus_id;
170 const u32 *reg; 170 const u32 *reg;
171 u64 addr; 171 u64 addr;
172 long magic; 172 int magic;
173 173
174 /* 174 /*
175 * If it's a DCR based device, use 'd' for native DCRs 175 * If it's a DCR based device, use 'd' for native DCRs
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c
index 2f54cd81dea5..8336deafc624 100644
--- a/arch/powerpc/kernel/pci_32.c
+++ b/arch/powerpc/kernel/pci_32.c
@@ -736,25 +736,51 @@ scan_OF_pci_childs(struct device_node* node, pci_OF_scan_iterator filter, void*
736 return NULL; 736 return NULL;
737} 737}
738 738
739static int 739static struct device_node *scan_OF_for_pci_dev(struct device_node *parent,
740scan_OF_pci_childs_iterator(struct device_node* node, void* data) 740 unsigned int devfn)
741{ 741{
742 const unsigned int *reg; 742 struct device_node *np = NULL;
743 u8* fdata = (u8*)data; 743 const u32 *reg;
744 744 unsigned int psize;
745 reg = get_property(node, "reg", NULL); 745
746 if (reg && ((reg[0] >> 8) & 0xff) == fdata[1] 746 while ((np = of_get_next_child(parent, np)) != NULL) {
747 && ((reg[0] >> 16) & 0xff) == fdata[0]) 747 reg = get_property(np, "reg", &psize);
748 return 1; 748 if (reg == NULL || psize < 4)
749 return 0; 749 continue;
750 if (((reg[0] >> 8) & 0xff) == devfn)
751 return np;
752 }
753 return NULL;
750} 754}
751 755
752static struct device_node* 756
753scan_OF_childs_for_device(struct device_node* node, u8 bus, u8 dev_fn) 757static struct device_node *scan_OF_for_pci_bus(struct pci_bus *bus)
754{ 758{
755 u8 filter_data[2] = {bus, dev_fn}; 759 struct device_node *parent, *np;
760
761 /* Are we a root bus ? */
762 if (bus->self == NULL || bus->parent == NULL) {
763 struct pci_controller *hose = pci_bus_to_hose(bus->number);
764 if (hose == NULL)
765 return NULL;
766 return of_node_get(hose->arch_data);
767 }
768
769 /* not a root bus, we need to get our parent */
770 parent = scan_OF_for_pci_bus(bus->parent);
771 if (parent == NULL)
772 return NULL;
773
774 /* now iterate for children for a match */
775 np = scan_OF_for_pci_dev(parent, bus->self->devfn);
776 of_node_put(parent);
756 777
757 return scan_OF_pci_childs(node, scan_OF_pci_childs_iterator, filter_data); 778 /* sanity check */
779 if (strcmp(np->type, "pci") != 0)
780 printk(KERN_WARNING "pci: wrong type \"%s\" for bridge %s\n",
781 np->type, np->full_name);
782
783 return np;
758} 784}
759 785
760/* 786/*
@@ -763,43 +789,25 @@ scan_OF_childs_for_device(struct device_node* node, u8 bus, u8 dev_fn)
763struct device_node * 789struct device_node *
764pci_busdev_to_OF_node(struct pci_bus *bus, int devfn) 790pci_busdev_to_OF_node(struct pci_bus *bus, int devfn)
765{ 791{
766 struct pci_controller *hose; 792 struct device_node *parent, *np;
767 struct device_node *node;
768 int busnr;
769 793
770 if (!have_of) 794 if (!have_of)
771 return NULL; 795 return NULL;
772
773 /* Lookup the hose */
774 busnr = bus->number;
775 hose = pci_bus_to_hose(busnr);
776 if (!hose)
777 return NULL;
778 796
779 /* Check it has an OF node associated */ 797 DBG("pci_busdev_to_OF_node(%d,0x%x)\n", bus->number, devfn);
780 node = (struct device_node *) hose->arch_data; 798 parent = scan_OF_for_pci_bus(bus);
781 if (!node) 799 if (parent == NULL)
782 return NULL; 800 return NULL;
783 801 DBG(" parent is %s\n", parent ? parent->full_name : "<NULL>");
784 /* Fixup bus number according to what OF think it is. */ 802 np = scan_OF_for_pci_dev(parent, devfn);
785#ifdef CONFIG_PPC_PMAC 803 of_node_put(parent);
786 /* The G5 need a special case here. Basically, we don't remap all 804 DBG(" result is %s\n", np ? np->full_name : "<NULL>");
787 * busses on it so we don't create the pci-OF-map. However, we do 805
788 * remap the AGP bus and so have to deal with it. A future better 806 /* XXX most callers don't release the returned node
789 * fix has to be done by making the remapping per-host and always 807 * mostly because ppc64 doesn't increase the refcount,
790 * filling the pci_to_OF map. --BenH 808 * we need to fix that.
791 */ 809 */
792 if (machine_is(powermac) && busnr >= 0xf0) 810 return np;
793 busnr -= 0xf0;
794 else
795#endif
796 if (pci_to_OF_bus_map)
797 busnr = pci_to_OF_bus_map[busnr];
798 if (busnr == 0xff)
799 return NULL;
800
801 /* Now, lookup childs of the hose */
802 return scan_OF_childs_for_device(node->child, busnr, devfn);
803} 811}
804EXPORT_SYMBOL(pci_busdev_to_OF_node); 812EXPORT_SYMBOL(pci_busdev_to_OF_node);
805 813
@@ -1544,7 +1552,7 @@ pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
1544 1552
1545 1553
1546static struct resource *__pci_mmap_make_offset(struct pci_dev *dev, 1554static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1547 unsigned long *offset, 1555 resource_size_t *offset,
1548 enum pci_mmap_state mmap_state) 1556 enum pci_mmap_state mmap_state)
1549{ 1557{
1550 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 1558 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
@@ -1556,7 +1564,9 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
1556 1564
1557 /* If memory, add on the PCI bridge address offset */ 1565 /* If memory, add on the PCI bridge address offset */
1558 if (mmap_state == pci_mmap_mem) { 1566 if (mmap_state == pci_mmap_mem) {
1567#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
1559 *offset += hose->pci_mem_offset; 1568 *offset += hose->pci_mem_offset;
1569#endif
1560 res_bit = IORESOURCE_MEM; 1570 res_bit = IORESOURCE_MEM;
1561 } else { 1571 } else {
1562 io_offset = hose->io_base_virt - (void __iomem *)_IO_BASE; 1572 io_offset = hose->io_base_virt - (void __iomem *)_IO_BASE;
@@ -1624,9 +1634,6 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
1624 else 1634 else
1625 prot |= _PAGE_GUARDED; 1635 prot |= _PAGE_GUARDED;
1626 1636
1627 printk("PCI map for %s:%llx, prot: %lx\n", pci_name(dev),
1628 (unsigned long long)rp->start, prot);
1629
1630 return __pgprot(prot); 1637 return __pgprot(prot);
1631} 1638}
1632 1639
@@ -1695,7 +1702,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1695 enum pci_mmap_state mmap_state, 1702 enum pci_mmap_state mmap_state,
1696 int write_combine) 1703 int write_combine)
1697{ 1704{
1698 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 1705 resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
1699 struct resource *rp; 1706 struct resource *rp;
1700 int ret; 1707 int ret;
1701 1708
@@ -1808,22 +1815,42 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
1808 resource_size_t *start, resource_size_t *end) 1815 resource_size_t *start, resource_size_t *end)
1809{ 1816{
1810 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 1817 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
1811 unsigned long offset = 0; 1818 resource_size_t offset = 0;
1812 1819
1813 if (hose == NULL) 1820 if (hose == NULL)
1814 return; 1821 return;
1815 1822
1816 if (rsrc->flags & IORESOURCE_IO) 1823 if (rsrc->flags & IORESOURCE_IO)
1817 offset = (void __iomem *)_IO_BASE - hose->io_base_virt 1824 offset = (unsigned long)hose->io_base_virt - _IO_BASE;
1818 + hose->io_base_phys; 1825
1826 /* We pass a fully fixed up address to userland for MMIO instead of
1827 * a BAR value because X is lame and expects to be able to use that
1828 * to pass to /dev/mem !
1829 *
1830 * That means that we'll have potentially 64 bits values where some
1831 * userland apps only expect 32 (like X itself since it thinks only
1832 * Sparc has 64 bits MMIO) but if we don't do that, we break it on
1833 * 32 bits CHRPs :-(
1834 *
1835 * Hopefully, the sysfs insterface is immune to that gunk. Once X
1836 * has been fixed (and the fix spread enough), we can re-enable the
1837 * 2 lines below and pass down a BAR value to userland. In that case
1838 * we'll also have to re-enable the matching code in
1839 * __pci_mmap_make_offset().
1840 *
1841 * BenH.
1842 */
1843#if 0
1844 else if (rsrc->flags & IORESOURCE_MEM)
1845 offset = hose->pci_mem_offset;
1846#endif
1819 1847
1820 *start = rsrc->start + offset; 1848 *start = rsrc->start - offset;
1821 *end = rsrc->end + offset; 1849 *end = rsrc->end - offset;
1822} 1850}
1823 1851
1824void __init 1852void __init pci_init_resource(struct resource *res, resource_size_t start,
1825pci_init_resource(struct resource *res, unsigned long start, unsigned long end, 1853 resource_size_t end, int flags, char *name)
1826 int flags, char *name)
1827{ 1854{
1828 res->start = start; 1855 res->start = start;
1829 res->end = end; 1856 res->end = end;
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 6fa9a0a5c8db..a6b7692c7269 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -682,7 +682,7 @@ int pci_proc_domain(struct pci_bus *bus)
682 * Returns negative error code on failure, zero on success. 682 * Returns negative error code on failure, zero on success.
683 */ 683 */
684static struct resource *__pci_mmap_make_offset(struct pci_dev *dev, 684static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
685 unsigned long *offset, 685 resource_size_t *offset,
686 enum pci_mmap_state mmap_state) 686 enum pci_mmap_state mmap_state)
687{ 687{
688 struct pci_controller *hose = pci_bus_to_host(dev->bus); 688 struct pci_controller *hose = pci_bus_to_host(dev->bus);
@@ -694,7 +694,9 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
694 694
695 /* If memory, add on the PCI bridge address offset */ 695 /* If memory, add on the PCI bridge address offset */
696 if (mmap_state == pci_mmap_mem) { 696 if (mmap_state == pci_mmap_mem) {
697#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
697 *offset += hose->pci_mem_offset; 698 *offset += hose->pci_mem_offset;
699#endif
698 res_bit = IORESOURCE_MEM; 700 res_bit = IORESOURCE_MEM;
699 } else { 701 } else {
700 io_offset = (unsigned long)hose->io_base_virt - pci_io_base; 702 io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
@@ -762,9 +764,6 @@ static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
762 else 764 else
763 prot |= _PAGE_GUARDED; 765 prot |= _PAGE_GUARDED;
764 766
765 printk(KERN_DEBUG "PCI map for %s:%lx, prot: %lx\n", pci_name(dev), rp->start,
766 prot);
767
768 return __pgprot(prot); 767 return __pgprot(prot);
769} 768}
770 769
@@ -832,7 +831,7 @@ pgprot_t pci_phys_mem_access_prot(struct file *file,
832int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, 831int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
833 enum pci_mmap_state mmap_state, int write_combine) 832 enum pci_mmap_state mmap_state, int write_combine)
834{ 833{
835 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 834 resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
836 struct resource *rp; 835 struct resource *rp;
837 int ret; 836 int ret;
838 837
@@ -1333,20 +1332,41 @@ EXPORT_SYMBOL(pci_read_irq_line);
1333 1332
1334void pci_resource_to_user(const struct pci_dev *dev, int bar, 1333void pci_resource_to_user(const struct pci_dev *dev, int bar,
1335 const struct resource *rsrc, 1334 const struct resource *rsrc,
1336 u64 *start, u64 *end) 1335 resource_size_t *start, resource_size_t *end)
1337{ 1336{
1338 struct pci_controller *hose = pci_bus_to_host(dev->bus); 1337 struct pci_controller *hose = pci_bus_to_host(dev->bus);
1339 unsigned long offset = 0; 1338 resource_size_t offset = 0;
1340 1339
1341 if (hose == NULL) 1340 if (hose == NULL)
1342 return; 1341 return;
1343 1342
1344 if (rsrc->flags & IORESOURCE_IO) 1343 if (rsrc->flags & IORESOURCE_IO)
1345 offset = pci_io_base - (unsigned long)hose->io_base_virt + 1344 offset = (unsigned long)hose->io_base_virt - pci_io_base;
1346 hose->io_base_phys; 1345
1346 /* We pass a fully fixed up address to userland for MMIO instead of
1347 * a BAR value because X is lame and expects to be able to use that
1348 * to pass to /dev/mem !
1349 *
1350 * That means that we'll have potentially 64 bits values where some
1351 * userland apps only expect 32 (like X itself since it thinks only
1352 * Sparc has 64 bits MMIO) but if we don't do that, we break it on
1353 * 32 bits CHRPs :-(
1354 *
1355 * Hopefully, the sysfs insterface is immune to that gunk. Once X
1356 * has been fixed (and the fix spread enough), we can re-enable the
1357 * 2 lines below and pass down a BAR value to userland. In that case
1358 * we'll also have to re-enable the matching code in
1359 * __pci_mmap_make_offset().
1360 *
1361 * BenH.
1362 */
1363#if 0
1364 else if (rsrc->flags & IORESOURCE_MEM)
1365 offset = hose->pci_mem_offset;
1366#endif
1347 1367
1348 *start = rsrc->start + offset; 1368 *start = rsrc->start - offset;
1349 *end = rsrc->end + offset; 1369 *end = rsrc->end - offset;
1350} 1370}
1351 1371
1352struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node) 1372struct pci_controller* pci_find_hose_for_OF_device(struct device_node* node)
diff --git a/arch/powerpc/kernel/ppc_ksyms.c b/arch/powerpc/kernel/ppc_ksyms.c
index 9179f0739ea2..95776b6af4e2 100644
--- a/arch/powerpc/kernel/ppc_ksyms.c
+++ b/arch/powerpc/kernel/ppc_ksyms.c
@@ -208,7 +208,7 @@ EXPORT_SYMBOL(mmu_hash_lock); /* For MOL */
208extern long *intercept_table; 208extern long *intercept_table;
209EXPORT_SYMBOL(intercept_table); 209EXPORT_SYMBOL(intercept_table);
210#endif /* CONFIG_PPC_STD_MMU_32 */ 210#endif /* CONFIG_PPC_STD_MMU_32 */
211#if defined(CONFIG_40x) || defined(CONFIG_BOOKE) 211#ifdef CONFIG_PPC_DCR_NATIVE
212EXPORT_SYMBOL(__mtdcr); 212EXPORT_SYMBOL(__mtdcr);
213EXPORT_SYMBOL(__mfdcr); 213EXPORT_SYMBOL(__mfdcr);
214#endif 214#endif
diff --git a/arch/powerpc/kernel/proc_ppc64.c b/arch/powerpc/kernel/proc_ppc64.c
index f598cb519539..dd7001cacf75 100644
--- a/arch/powerpc/kernel/proc_ppc64.c
+++ b/arch/powerpc/kernel/proc_ppc64.c
@@ -83,7 +83,7 @@ __initcall(proc_ppc64_init);
83static loff_t page_map_seek( struct file *file, loff_t off, int whence) 83static loff_t page_map_seek( struct file *file, loff_t off, int whence)
84{ 84{
85 loff_t new; 85 loff_t new;
86 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 86 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
87 87
88 switch(whence) { 88 switch(whence) {
89 case 0: 89 case 0:
@@ -106,13 +106,13 @@ static loff_t page_map_seek( struct file *file, loff_t off, int whence)
106static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes, 106static ssize_t page_map_read( struct file *file, char __user *buf, size_t nbytes,
107 loff_t *ppos) 107 loff_t *ppos)
108{ 108{
109 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 109 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
110 return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size); 110 return simple_read_from_buffer(buf, nbytes, ppos, dp->data, dp->size);
111} 111}
112 112
113static int page_map_mmap( struct file *file, struct vm_area_struct *vma ) 113static int page_map_mmap( struct file *file, struct vm_area_struct *vma )
114{ 114{
115 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 115 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
116 116
117 if ((vma->vm_end - vma->vm_start) > dp->size) 117 if ((vma->vm_end - vma->vm_start) > dp->size)
118 return -EINVAL; 118 return -EINVAL;
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index c18dbe77fdc2..1fc732a552db 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -804,6 +804,56 @@ static unsigned long __init dt_mem_next_cell(int s, cell_t **cellp)
804 return of_read_ulong(p, s); 804 return of_read_ulong(p, s);
805} 805}
806 806
807#ifdef CONFIG_PPC_PSERIES
808/*
809 * Interpret the ibm,dynamic-memory property in the
810 * /ibm,dynamic-reconfiguration-memory node.
811 * This contains a list of memory blocks along with NUMA affinity
812 * information.
813 */
814static int __init early_init_dt_scan_drconf_memory(unsigned long node)
815{
816 cell_t *dm, *ls;
817 unsigned long l, n;
818 unsigned long base, size, lmb_size, flags;
819
820 ls = (cell_t *)of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
821 if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t))
822 return 0;
823 lmb_size = dt_mem_next_cell(dt_root_size_cells, &ls);
824
825 dm = (cell_t *)of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l);
826 if (dm == NULL || l < sizeof(cell_t))
827 return 0;
828
829 n = *dm++; /* number of entries */
830 if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(cell_t))
831 return 0;
832
833 for (; n != 0; --n) {
834 base = dt_mem_next_cell(dt_root_addr_cells, &dm);
835 flags = dm[3];
836 /* skip DRC index, pad, assoc. list index, flags */
837 dm += 4;
838 /* skip this block if the reserved bit is set in flags (0x80)
839 or if the block is not assigned to this partition (0x8) */
840 if ((flags & 0x80) || !(flags & 0x8))
841 continue;
842 size = lmb_size;
843 if (iommu_is_off) {
844 if (base >= 0x80000000ul)
845 continue;
846 if ((base + size) > 0x80000000ul)
847 size = 0x80000000ul - base;
848 }
849 lmb_add(base, size);
850 }
851 lmb_dump_all();
852 return 0;
853}
854#else
855#define early_init_dt_scan_drconf_memory(node) 0
856#endif /* CONFIG_PPC_PSERIES */
807 857
808static int __init early_init_dt_scan_memory(unsigned long node, 858static int __init early_init_dt_scan_memory(unsigned long node,
809 const char *uname, int depth, void *data) 859 const char *uname, int depth, void *data)
@@ -812,6 +862,11 @@ static int __init early_init_dt_scan_memory(unsigned long node,
812 cell_t *reg, *endp; 862 cell_t *reg, *endp;
813 unsigned long l; 863 unsigned long l;
814 864
865 /* Look for the ibm,dynamic-reconfiguration-memory node */
866 if (depth == 1 &&
867 strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0)
868 return early_init_dt_scan_drconf_memory(node);
869
815 /* We are scanning "memory" nodes only */ 870 /* We are scanning "memory" nodes only */
816 if (type == NULL) { 871 if (type == NULL) {
817 /* 872 /*
diff --git a/arch/powerpc/kernel/prom_init.c b/arch/powerpc/kernel/prom_init.c
index 46cf32670ddb..520ef42f642e 100644
--- a/arch/powerpc/kernel/prom_init.c
+++ b/arch/powerpc/kernel/prom_init.c
@@ -679,7 +679,7 @@ static unsigned char ibm_architecture_vec[] = {
679 /* option vector 5: PAPR/OF options */ 679 /* option vector 5: PAPR/OF options */
680 3 - 2, /* length */ 680 3 - 2, /* length */
681 0, /* don't ignore, don't halt */ 681 0, /* don't ignore, don't halt */
682 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES, 682 OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY,
683}; 683};
684 684
685/* Old method - ELF header with PT_NOTE sections */ 685/* Old method - ELF header with PT_NOTE sections */
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 387ed0d9ad61..76b5d7ebdcc6 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -303,6 +303,12 @@ int rtas_token(const char *service)
303} 303}
304EXPORT_SYMBOL(rtas_token); 304EXPORT_SYMBOL(rtas_token);
305 305
306int rtas_service_present(const char *service)
307{
308 return rtas_token(service) != RTAS_UNKNOWN_SERVICE;
309}
310EXPORT_SYMBOL(rtas_service_present);
311
306#ifdef CONFIG_RTAS_ERROR_LOGGING 312#ifdef CONFIG_RTAS_ERROR_LOGGING
307/* 313/*
308 * Return the firmware-specified size of the error log buffer 314 * Return the firmware-specified size of the error log buffer
@@ -810,32 +816,6 @@ asmlinkage int ppc_rtas(struct rtas_args __user *uargs)
810 return 0; 816 return 0;
811} 817}
812 818
813#ifdef CONFIG_HOTPLUG_CPU
814/* This version can't take the spinlock, because it never returns */
815static struct rtas_args rtas_stop_self_args = {
816 /* The token is initialized for real in setup_system() */
817 .token = RTAS_UNKNOWN_SERVICE,
818 .nargs = 0,
819 .nret = 1,
820 .rets = &rtas_stop_self_args.args[0],
821};
822
823void rtas_stop_self(void)
824{
825 struct rtas_args *rtas_args = &rtas_stop_self_args;
826
827 local_irq_disable();
828
829 BUG_ON(rtas_args->token == RTAS_UNKNOWN_SERVICE);
830
831 printk("cpu %u (hwid %u) Ready to die...\n",
832 smp_processor_id(), hard_smp_processor_id());
833 enter_rtas(__pa(rtas_args));
834
835 panic("Alas, I survived.\n");
836}
837#endif
838
839/* 819/*
840 * Call early during boot, before mem init or bootmem, to retrieve the RTAS 820 * Call early during boot, before mem init or bootmem, to retrieve the RTAS
841 * informations from the device-tree and allocate the RMO buffer for userland 821 * informations from the device-tree and allocate the RMO buffer for userland
@@ -880,9 +860,6 @@ void __init rtas_initialize(void)
880#endif 860#endif
881 rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region); 861 rtas_rmo_buf = lmb_alloc_base(RTAS_RMOBUF_MAX, PAGE_SIZE, rtas_region);
882 862
883#ifdef CONFIG_HOTPLUG_CPU
884 rtas_stop_self_args.token = rtas_token("stop-self");
885#endif /* CONFIG_HOTPLUG_CPU */
886#ifdef CONFIG_RTAS_ERROR_LOGGING 863#ifdef CONFIG_RTAS_ERROR_LOGGING
887 rtas_last_error_token = rtas_token("rtas-last-error"); 864 rtas_last_error_token = rtas_token("rtas-last-error");
888#endif 865#endif
diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
index 7d0f13fecc0e..0c4fcd34bfe5 100644
--- a/arch/powerpc/kernel/rtas_flash.c
+++ b/arch/powerpc/kernel/rtas_flash.c
@@ -193,7 +193,7 @@ static void free_flash_list(struct flash_block_list *f)
193 193
194static int rtas_flash_release(struct inode *inode, struct file *file) 194static int rtas_flash_release(struct inode *inode, struct file *file)
195{ 195{
196 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 196 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
197 struct rtas_update_flash_t *uf; 197 struct rtas_update_flash_t *uf;
198 198
199 uf = (struct rtas_update_flash_t *) dp->data; 199 uf = (struct rtas_update_flash_t *) dp->data;
@@ -255,7 +255,7 @@ static void get_flash_status_msg(int status, char *buf)
255static ssize_t rtas_flash_read(struct file *file, char __user *buf, 255static ssize_t rtas_flash_read(struct file *file, char __user *buf,
256 size_t count, loff_t *ppos) 256 size_t count, loff_t *ppos)
257{ 257{
258 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 258 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
259 struct rtas_update_flash_t *uf; 259 struct rtas_update_flash_t *uf;
260 char msg[RTAS_MSG_MAXLEN]; 260 char msg[RTAS_MSG_MAXLEN];
261 int msglen; 261 int msglen;
@@ -299,7 +299,7 @@ void rtas_block_ctor(void *ptr, struct kmem_cache *cache, unsigned long flags)
299static ssize_t rtas_flash_write(struct file *file, const char __user *buffer, 299static ssize_t rtas_flash_write(struct file *file, const char __user *buffer,
300 size_t count, loff_t *off) 300 size_t count, loff_t *off)
301{ 301{
302 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 302 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
303 struct rtas_update_flash_t *uf; 303 struct rtas_update_flash_t *uf;
304 char *p; 304 char *p;
305 int next_free; 305 int next_free;
@@ -391,7 +391,7 @@ static void manage_flash(struct rtas_manage_flash_t *args_buf)
391static ssize_t manage_flash_read(struct file *file, char __user *buf, 391static ssize_t manage_flash_read(struct file *file, char __user *buf,
392 size_t count, loff_t *ppos) 392 size_t count, loff_t *ppos)
393{ 393{
394 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 394 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
395 struct rtas_manage_flash_t *args_buf; 395 struct rtas_manage_flash_t *args_buf;
396 char msg[RTAS_MSG_MAXLEN]; 396 char msg[RTAS_MSG_MAXLEN];
397 int msglen; 397 int msglen;
@@ -421,7 +421,7 @@ static ssize_t manage_flash_read(struct file *file, char __user *buf,
421static ssize_t manage_flash_write(struct file *file, const char __user *buf, 421static ssize_t manage_flash_write(struct file *file, const char __user *buf,
422 size_t count, loff_t *off) 422 size_t count, loff_t *off)
423{ 423{
424 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 424 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
425 struct rtas_manage_flash_t *args_buf; 425 struct rtas_manage_flash_t *args_buf;
426 const char reject_str[] = "0"; 426 const char reject_str[] = "0";
427 const char commit_str[] = "1"; 427 const char commit_str[] = "1";
@@ -492,7 +492,7 @@ static int get_validate_flash_msg(struct rtas_validate_flash_t *args_buf,
492static ssize_t validate_flash_read(struct file *file, char __user *buf, 492static ssize_t validate_flash_read(struct file *file, char __user *buf,
493 size_t count, loff_t *ppos) 493 size_t count, loff_t *ppos)
494{ 494{
495 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 495 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
496 struct rtas_validate_flash_t *args_buf; 496 struct rtas_validate_flash_t *args_buf;
497 char msg[RTAS_MSG_MAXLEN]; 497 char msg[RTAS_MSG_MAXLEN];
498 int msglen; 498 int msglen;
@@ -520,7 +520,7 @@ static ssize_t validate_flash_read(struct file *file, char __user *buf,
520static ssize_t validate_flash_write(struct file *file, const char __user *buf, 520static ssize_t validate_flash_write(struct file *file, const char __user *buf,
521 size_t count, loff_t *off) 521 size_t count, loff_t *off)
522{ 522{
523 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 523 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
524 struct rtas_validate_flash_t *args_buf; 524 struct rtas_validate_flash_t *args_buf;
525 int rc; 525 int rc;
526 526
@@ -569,7 +569,7 @@ done:
569 569
570static int validate_flash_release(struct inode *inode, struct file *file) 570static int validate_flash_release(struct inode *inode, struct file *file)
571{ 571{
572 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 572 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
573 struct rtas_validate_flash_t *args_buf; 573 struct rtas_validate_flash_t *args_buf;
574 574
575 args_buf = (struct rtas_validate_flash_t *) dp->data; 575 args_buf = (struct rtas_validate_flash_t *) dp->data;
diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
index 63ed265b7f09..400ab2b946e7 100644
--- a/arch/powerpc/kernel/sysfs.c
+++ b/arch/powerpc/kernel/sysfs.c
@@ -181,6 +181,8 @@ SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
181SYSFS_PMCSETUP(pmc7, SPRN_PMC7); 181SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
182SYSFS_PMCSETUP(pmc8, SPRN_PMC8); 182SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
183SYSFS_PMCSETUP(purr, SPRN_PURR); 183SYSFS_PMCSETUP(purr, SPRN_PURR);
184SYSFS_PMCSETUP(spurr, SPRN_SPURR);
185SYSFS_PMCSETUP(dscr, SPRN_DSCR);
184 186
185static SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0); 187static SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0);
186static SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1); 188static SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1);
@@ -194,6 +196,8 @@ static SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6);
194static SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7); 196static SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7);
195static SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8); 197static SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8);
196static SYSDEV_ATTR(purr, 0600, show_purr, NULL); 198static SYSDEV_ATTR(purr, 0600, show_purr, NULL);
199static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL);
200static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr);
197 201
198static void register_cpu_online(unsigned int cpu) 202static void register_cpu_online(unsigned int cpu)
199{ 203{
@@ -231,6 +235,12 @@ static void register_cpu_online(unsigned int cpu)
231 235
232 if (cpu_has_feature(CPU_FTR_PURR)) 236 if (cpu_has_feature(CPU_FTR_PURR))
233 sysdev_create_file(s, &attr_purr); 237 sysdev_create_file(s, &attr_purr);
238
239 if (cpu_has_feature(CPU_FTR_SPURR))
240 sysdev_create_file(s, &attr_spurr);
241
242 if (cpu_has_feature(CPU_FTR_DSCR))
243 sysdev_create_file(s, &attr_dscr);
234} 244}
235 245
236#ifdef CONFIG_HOTPLUG_CPU 246#ifdef CONFIG_HOTPLUG_CPU
@@ -272,6 +282,12 @@ static void unregister_cpu_online(unsigned int cpu)
272 282
273 if (cpu_has_feature(CPU_FTR_PURR)) 283 if (cpu_has_feature(CPU_FTR_PURR))
274 sysdev_remove_file(s, &attr_purr); 284 sysdev_remove_file(s, &attr_purr);
285
286 if (cpu_has_feature(CPU_FTR_SPURR))
287 sysdev_remove_file(s, &attr_spurr);
288
289 if (cpu_has_feature(CPU_FTR_DSCR))
290 sysdev_remove_file(s, &attr_dscr);
275} 291}
276#endif /* CONFIG_HOTPLUG_CPU */ 292#endif /* CONFIG_HOTPLUG_CPU */
277 293
diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
index 0d4e203fa7a0..535f50665647 100644
--- a/arch/powerpc/kernel/traps.c
+++ b/arch/powerpc/kernel/traps.c
@@ -32,6 +32,7 @@
32#include <linux/kprobes.h> 32#include <linux/kprobes.h>
33#include <linux/kexec.h> 33#include <linux/kexec.h>
34#include <linux/backlight.h> 34#include <linux/backlight.h>
35#include <linux/bug.h>
35 36
36#include <asm/kdebug.h> 37#include <asm/kdebug.h>
37#include <asm/pgtable.h> 38#include <asm/pgtable.h>
@@ -727,54 +728,9 @@ static int emulate_instruction(struct pt_regs *regs)
727 return -EINVAL; 728 return -EINVAL;
728} 729}
729 730
730/* 731int is_valid_bugaddr(unsigned long addr)
731 * Look through the list of trap instructions that are used for BUG(),
732 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
733 * that the exception was caused by a trap instruction of some kind.
734 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
735 * otherwise.
736 */
737extern struct bug_entry __start___bug_table[], __stop___bug_table[];
738
739#ifndef CONFIG_MODULES
740#define module_find_bug(x) NULL
741#endif
742
743struct bug_entry *find_bug(unsigned long bugaddr)
744{ 732{
745 struct bug_entry *bug; 733 return is_kernel_addr(addr);
746
747 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
748 if (bugaddr == bug->bug_addr)
749 return bug;
750 return module_find_bug(bugaddr);
751}
752
753static int check_bug_trap(struct pt_regs *regs)
754{
755 struct bug_entry *bug;
756 unsigned long addr;
757
758 if (regs->msr & MSR_PR)
759 return 0; /* not in kernel */
760 addr = regs->nip; /* address of trap instruction */
761 if (addr < PAGE_OFFSET)
762 return 0;
763 bug = find_bug(regs->nip);
764 if (bug == NULL)
765 return 0;
766 if (bug->line & BUG_WARNING_TRAP) {
767 /* this is a WARN_ON rather than BUG/BUG_ON */
768 printk(KERN_ERR "Badness in %s at %s:%ld\n",
769 bug->function, bug->file,
770 bug->line & ~BUG_WARNING_TRAP);
771 dump_stack();
772 return 1;
773 }
774 printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
775 bug->function, bug->file, bug->line);
776
777 return 0;
778} 734}
779 735
780void __kprobes program_check_exception(struct pt_regs *regs) 736void __kprobes program_check_exception(struct pt_regs *regs)
@@ -782,6 +738,8 @@ void __kprobes program_check_exception(struct pt_regs *regs)
782 unsigned int reason = get_reason(regs); 738 unsigned int reason = get_reason(regs);
783 extern int do_mathemu(struct pt_regs *regs); 739 extern int do_mathemu(struct pt_regs *regs);
784 740
741 /* We can now get here via a FP Unavailable exception if the core
742 * has no FPU, in that case no reason flags will be set */
785#ifdef CONFIG_MATH_EMULATION 743#ifdef CONFIG_MATH_EMULATION
786 /* (reason & REASON_ILLEGAL) would be the obvious thing here, 744 /* (reason & REASON_ILLEGAL) would be the obvious thing here,
787 * but there seems to be a hardware bug on the 405GP (RevD) 745 * but there seems to be a hardware bug on the 405GP (RevD)
@@ -808,7 +766,9 @@ void __kprobes program_check_exception(struct pt_regs *regs)
808 return; 766 return;
809 if (debugger_bpt(regs)) 767 if (debugger_bpt(regs))
810 return; 768 return;
811 if (check_bug_trap(regs)) { 769
770 if (!(regs->msr & MSR_PR) && /* not user-mode */
771 report_bug(regs->nip) == BUG_TRAP_TYPE_WARN) {
812 regs->nip += 4; 772 regs->nip += 4;
813 return; 773 return;
814 } 774 }
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 04b98671a060..04b8e71bf5b0 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -62,11 +62,7 @@ SECTIONS
62 __stop___ex_table = .; 62 __stop___ex_table = .;
63 } 63 }
64 64
65 __bug_table : { 65 BUG_TABLE
66 __start___bug_table = .;
67 *(__bug_table)
68 __stop___bug_table = .;
69 }
70 66
71/* 67/*
72 * Init sections discarded at runtime 68 * Init sections discarded at runtime
diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
index 9da01dc8cfd9..262790910ff2 100644
--- a/arch/powerpc/mm/numa.c
+++ b/arch/powerpc/mm/numa.c
@@ -295,6 +295,63 @@ static unsigned long __init numa_enforce_memory_limit(unsigned long start,
295 return lmb_end_of_DRAM() - start; 295 return lmb_end_of_DRAM() - start;
296} 296}
297 297
298/*
299 * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
300 * node. This assumes n_mem_{addr,size}_cells have been set.
301 */
302static void __init parse_drconf_memory(struct device_node *memory)
303{
304 const unsigned int *lm, *dm, *aa;
305 unsigned int ls, ld, la;
306 unsigned int n, aam, aalen;
307 unsigned long lmb_size, size;
308 int nid, default_nid = 0;
309 unsigned int start, ai, flags;
310
311 lm = get_property(memory, "ibm,lmb-size", &ls);
312 dm = get_property(memory, "ibm,dynamic-memory", &ld);
313 aa = get_property(memory, "ibm,associativity-lookup-arrays", &la);
314 if (!lm || !dm || !aa ||
315 ls < sizeof(unsigned int) || ld < sizeof(unsigned int) ||
316 la < 2 * sizeof(unsigned int))
317 return;
318
319 lmb_size = read_n_cells(n_mem_size_cells, &lm);
320 n = *dm++; /* number of LMBs */
321 aam = *aa++; /* number of associativity lists */
322 aalen = *aa++; /* length of each associativity list */
323 if (ld < (n * (n_mem_addr_cells + 4) + 1) * sizeof(unsigned int) ||
324 la < (aam * aalen + 2) * sizeof(unsigned int))
325 return;
326
327 for (; n != 0; --n) {
328 start = read_n_cells(n_mem_addr_cells, &dm);
329 ai = dm[2];
330 flags = dm[3];
331 dm += 4;
332 /* 0x80 == reserved, 0x8 = assigned to us */
333 if ((flags & 0x80) || !(flags & 0x8))
334 continue;
335 nid = default_nid;
336 /* flags & 0x40 means associativity index is invalid */
337 if (min_common_depth > 0 && min_common_depth <= aalen &&
338 (flags & 0x40) == 0 && ai < aam) {
339 /* this is like of_node_to_nid_single */
340 nid = aa[ai * aalen + min_common_depth - 1];
341 if (nid == 0xffff || nid >= MAX_NUMNODES)
342 nid = default_nid;
343 }
344 node_set_online(nid);
345
346 size = numa_enforce_memory_limit(start, lmb_size);
347 if (!size)
348 continue;
349
350 add_active_range(nid, start >> PAGE_SHIFT,
351 (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
352 }
353}
354
298static int __init parse_numa_properties(void) 355static int __init parse_numa_properties(void)
299{ 356{
300 struct device_node *cpu = NULL; 357 struct device_node *cpu = NULL;
@@ -385,6 +442,14 @@ new_range:
385 goto new_range; 442 goto new_range;
386 } 443 }
387 444
445 /*
446 * Now do the same thing for each LMB listed in the ibm,dynamic-memory
447 * property in the ibm,dynamic-reconfiguration-memory node.
448 */
449 memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
450 if (memory)
451 parse_drconf_memory(memory);
452
388 return 0; 453 return 0;
389} 454}
390 455
diff --git a/arch/powerpc/platforms/52xx/lite5200.c b/arch/powerpc/platforms/52xx/lite5200.c
index a375c15b4315..eaff71e74fb0 100644
--- a/arch/powerpc/platforms/52xx/lite5200.c
+++ b/arch/powerpc/platforms/52xx/lite5200.c
@@ -40,8 +40,6 @@
40#include <asm/prom.h> 40#include <asm/prom.h>
41#include <asm/udbg.h> 41#include <asm/udbg.h>
42#include <sysdev/fsl_soc.h> 42#include <sysdev/fsl_soc.h>
43#include <asm/qe.h>
44#include <asm/qe_ic.h>
45#include <asm/of_platform.h> 43#include <asm/of_platform.h>
46 44
47#include <asm/mpc52xx.h> 45#include <asm/mpc52xx.h>
diff --git a/arch/powerpc/platforms/cell/cbe_thermal.c b/arch/powerpc/platforms/cell/cbe_thermal.c
index 616a0a3fd0e2..70e0d968d30f 100644
--- a/arch/powerpc/platforms/cell/cbe_thermal.c
+++ b/arch/powerpc/platforms/cell/cbe_thermal.c
@@ -115,6 +115,7 @@ static struct sysdev_attribute attr_spu_temperature = {
115 115
116static struct attribute *spu_attributes[] = { 116static struct attribute *spu_attributes[] = {
117 &attr_spu_temperature.attr, 117 &attr_spu_temperature.attr,
118 NULL,
118}; 119};
119 120
120static struct attribute_group spu_attribute_group = { 121static struct attribute_group spu_attribute_group = {
@@ -135,6 +136,7 @@ static struct sysdev_attribute attr_ppe_temperature1 = {
135static struct attribute *ppe_attributes[] = { 136static struct attribute *ppe_attributes[] = {
136 &attr_ppe_temperature0.attr, 137 &attr_ppe_temperature0.attr,
137 &attr_ppe_temperature1.attr, 138 &attr_ppe_temperature1.attr,
139 NULL,
138}; 140};
139 141
140static struct attribute_group ppe_attribute_group = { 142static struct attribute_group ppe_attribute_group = {
diff --git a/arch/powerpc/platforms/cell/pmu.c b/arch/powerpc/platforms/cell/pmu.c
index 99c612025e8f..d04ae1671e6c 100644
--- a/arch/powerpc/platforms/cell/pmu.c
+++ b/arch/powerpc/platforms/cell/pmu.c
@@ -382,11 +382,14 @@ static irqreturn_t cbe_pm_irq(int irq, void *dev_id)
382 return IRQ_HANDLED; 382 return IRQ_HANDLED;
383} 383}
384 384
385int __init cbe_init_pm_irq(void) 385static int __init cbe_init_pm_irq(void)
386{ 386{
387 unsigned int irq; 387 unsigned int irq;
388 int rc, node; 388 int rc, node;
389 389
390 if (!machine_is(cell))
391 return 0;
392
390 for_each_node(node) { 393 for_each_node(node) {
391 irq = irq_create_mapping(NULL, IIC_IRQ_IOEX_PMI | 394 irq = irq_create_mapping(NULL, IIC_IRQ_IOEX_PMI |
392 (node << IIC_IRQ_NODE_SHIFT)); 395 (node << IIC_IRQ_NODE_SHIFT));
diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c b/arch/powerpc/platforms/cell/spufs/coredump.c
index 26945c491f6b..725e19561159 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -147,7 +147,7 @@ static int spufs_arch_notes_size(void)
147 struct fdtable *fdt = files_fdtable(current->files); 147 struct fdtable *fdt = files_fdtable(current->files);
148 int size = 0, fd; 148 int size = 0, fd;
149 149
150 for (fd = 0; fd < fdt->max_fdset && fd < fdt->max_fds; fd++) { 150 for (fd = 0; fd < fdt->max_fds; fd++) {
151 if (FD_ISSET(fd, fdt->open_fds)) { 151 if (FD_ISSET(fd, fdt->open_fds)) {
152 struct file *file = fcheck(fd); 152 struct file *file = fcheck(fd);
153 153
diff --git a/arch/powerpc/platforms/cell/spufs/inode.c b/arch/powerpc/platforms/cell/spufs/inode.c
index e3af9112c026..738b9244382f 100644
--- a/arch/powerpc/platforms/cell/spufs/inode.c
+++ b/arch/powerpc/platforms/cell/spufs/inode.c
@@ -205,7 +205,7 @@ static int spufs_dir_close(struct inode *inode, struct file *file)
205 struct dentry *dir; 205 struct dentry *dir;
206 int ret; 206 int ret;
207 207
208 dir = file->f_dentry; 208 dir = file->f_path.dentry;
209 parent = dir->d_parent->d_inode; 209 parent = dir->d_parent->d_inode;
210 ctx = SPUFS_I(dir->d_inode)->i_ctx; 210 ctx = SPUFS_I(dir->d_inode)->i_ctx;
211 211
@@ -363,7 +363,7 @@ static int spufs_gang_close(struct inode *inode, struct file *file)
363 struct dentry *dir; 363 struct dentry *dir;
364 int ret; 364 int ret;
365 365
366 dir = file->f_dentry; 366 dir = file->f_path.dentry;
367 parent = dir->d_parent->d_inode; 367 parent = dir->d_parent->d_inode;
368 368
369 ret = spufs_rmgang(parent, dir); 369 ret = spufs_rmgang(parent, dir);
diff --git a/arch/powerpc/platforms/cell/spufs/syscalls.c b/arch/powerpc/platforms/cell/spufs/syscalls.c
index a6d1ae4dc2a3..8e37bdf4dfda 100644
--- a/arch/powerpc/platforms/cell/spufs/syscalls.c
+++ b/arch/powerpc/platforms/cell/spufs/syscalls.c
@@ -46,7 +46,7 @@ static long do_spu_run(struct file *filp,
46 if (filp->f_op != &spufs_context_fops) 46 if (filp->f_op != &spufs_context_fops)
47 goto out; 47 goto out;
48 48
49 i = SPUFS_I(filp->f_dentry->d_inode); 49 i = SPUFS_I(filp->f_path.dentry->d_inode);
50 ret = spufs_run_spu(filp, i->i_ctx, &npc, &status); 50 ret = spufs_run_spu(filp, i->i_ctx, &npc, &status);
51 51
52 if (put_user(npc, unpc)) 52 if (put_user(npc, unpc))
diff --git a/arch/powerpc/platforms/iseries/mf.c b/arch/powerpc/platforms/iseries/mf.c
index b5737d68d6c4..cff15ae24f6b 100644
--- a/arch/powerpc/platforms/iseries/mf.c
+++ b/arch/powerpc/platforms/iseries/mf.c
@@ -1178,7 +1178,7 @@ static ssize_t proc_mf_change_vmlinux(struct file *file,
1178 const char __user *buf, 1178 const char __user *buf,
1179 size_t count, loff_t *ppos) 1179 size_t count, loff_t *ppos)
1180{ 1180{
1181 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode); 1181 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
1182 ssize_t rc; 1182 ssize_t rc;
1183 dma_addr_t dma_addr; 1183 dma_addr_t dma_addr;
1184 char *page; 1184 char *page;
diff --git a/arch/powerpc/platforms/maple/pci.c b/arch/powerpc/platforms/maple/pci.c
index 3a32deda765d..3f6a69f67195 100644
--- a/arch/powerpc/platforms/maple/pci.c
+++ b/arch/powerpc/platforms/maple/pci.c
@@ -562,7 +562,7 @@ void __init maple_pci_init(void)
562 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) { 562 for (np = NULL; (np = of_get_next_child(root, np)) != NULL;) {
563 if (np->name == NULL) 563 if (np->name == NULL)
564 continue; 564 continue;
565 if (strcmp(np->name, "pci") == 0) { 565 if (!strcmp(np->name, "pci") || !strcmp(np->name, "pcie")) {
566 if (add_bridge(np) == 0) 566 if (add_bridge(np) == 0)
567 of_node_get(np); 567 of_node_get(np);
568 } 568 }
diff --git a/arch/powerpc/platforms/maple/setup.c b/arch/powerpc/platforms/maple/setup.c
index 094989d50bab..f12d5c69e74d 100644
--- a/arch/powerpc/platforms/maple/setup.c
+++ b/arch/powerpc/platforms/maple/setup.c
@@ -60,6 +60,7 @@
60#include <asm/of_device.h> 60#include <asm/of_device.h>
61#include <asm/lmb.h> 61#include <asm/lmb.h>
62#include <asm/mpic.h> 62#include <asm/mpic.h>
63#include <asm/rtas.h>
63#include <asm/udbg.h> 64#include <asm/udbg.h>
64 65
65#include "maple.h" 66#include "maple.h"
@@ -166,6 +167,16 @@ struct smp_ops_t maple_smp_ops = {
166}; 167};
167#endif /* CONFIG_SMP */ 168#endif /* CONFIG_SMP */
168 169
170static void __init maple_use_rtas_reboot_and_halt_if_present(void)
171{
172 if (rtas_service_present("system-reboot") &&
173 rtas_service_present("power-off")) {
174 ppc_md.restart = rtas_restart;
175 ppc_md.power_off = rtas_power_off;
176 ppc_md.halt = rtas_halt;
177 }
178}
179
169void __init maple_setup_arch(void) 180void __init maple_setup_arch(void)
170{ 181{
171 /* init to some ~sane value until calibrate_delay() runs */ 182 /* init to some ~sane value until calibrate_delay() runs */
@@ -181,6 +192,7 @@ void __init maple_setup_arch(void)
181#ifdef CONFIG_DUMMY_CONSOLE 192#ifdef CONFIG_DUMMY_CONSOLE
182 conswitchp = &dummy_con; 193 conswitchp = &dummy_con;
183#endif 194#endif
195 maple_use_rtas_reboot_and_halt_if_present();
184 196
185 printk(KERN_DEBUG "Using native/NAP idle loop\n"); 197 printk(KERN_DEBUG "Using native/NAP idle loop\n");
186} 198}
diff --git a/arch/powerpc/platforms/ps3/Kconfig b/arch/powerpc/platforms/ps3/Kconfig
index 451bfcd5502e..de52ec4e9e58 100644
--- a/arch/powerpc/platforms/ps3/Kconfig
+++ b/arch/powerpc/platforms/ps3/Kconfig
@@ -40,4 +40,15 @@ config PS3_USE_LPAR_ADDR
40 40
41 If you have any doubt, choose the default y. 41 If you have any doubt, choose the default y.
42 42
43config PS3_VUART
44 depends on PPC_PS3
45 bool "PS3 Virtual UART support"
46 default y
47 help
48 Include support for the PS3 Virtual UART.
49
50 This support is required for several system services
51 including the System Manager and AV Settings. In
52 general, all users will say Y.
53
43endmenu 54endmenu
diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile
index 997243a91be8..69590fbf83da 100644
--- a/arch/powerpc/platforms/pseries/Makefile
+++ b/arch/powerpc/platforms/pseries/Makefile
@@ -10,6 +10,8 @@ obj-$(CONFIG_XICS) += xics.o
10obj-$(CONFIG_SCANLOG) += scanlog.o 10obj-$(CONFIG_SCANLOG) += scanlog.o
11obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o 11obj-$(CONFIG_EEH) += eeh.o eeh_cache.o eeh_driver.o eeh_event.o
12 12
13obj-$(CONFIG_HOTPLUG_CPU) += hotplug-cpu.o
14
13obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o 15obj-$(CONFIG_HVC_CONSOLE) += hvconsole.o
14obj-$(CONFIG_HVCS) += hvcserver.o 16obj-$(CONFIG_HVCS) += hvcserver.o
15obj-$(CONFIG_HCALL_STATS) += hvCall_inst.o 17obj-$(CONFIG_HCALL_STATS) += hvCall_inst.o
diff --git a/arch/powerpc/platforms/pseries/eeh.c b/arch/powerpc/platforms/pseries/eeh.c
index 3c2d63ebf787..da6e5362e7cd 100644
--- a/arch/powerpc/platforms/pseries/eeh.c
+++ b/arch/powerpc/platforms/pseries/eeh.c
@@ -337,6 +337,7 @@ int eeh_dn_check_failure(struct device_node *dn, struct pci_dev *dev)
337 printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n", 337 printk (KERN_ERR "EEH: Device driver ignored %d bad reads, panicing\n",
338 pdn->eeh_check_count); 338 pdn->eeh_check_count);
339 dump_stack(); 339 dump_stack();
340 msleep(5000);
340 341
341 /* re-read the slot reset state */ 342 /* re-read the slot reset state */
342 if (read_slot_reset_state(pdn, rets) != 0) 343 if (read_slot_reset_state(pdn, rets) != 0)
diff --git a/arch/powerpc/platforms/pseries/eeh_driver.c b/arch/powerpc/platforms/pseries/eeh_driver.c
index c2bc9904f1cb..cbd6b0711ab4 100644
--- a/arch/powerpc/platforms/pseries/eeh_driver.c
+++ b/arch/powerpc/platforms/pseries/eeh_driver.c
@@ -170,14 +170,19 @@ static void eeh_report_reset(struct pci_dev *dev, void *userdata)
170static void eeh_report_resume(struct pci_dev *dev, void *userdata) 170static void eeh_report_resume(struct pci_dev *dev, void *userdata)
171{ 171{
172 struct pci_driver *driver = dev->driver; 172 struct pci_driver *driver = dev->driver;
173 struct device_node *dn = pci_device_to_OF_node(dev);
173 174
174 dev->error_state = pci_channel_io_normal; 175 dev->error_state = pci_channel_io_normal;
175 176
176 if (!driver) 177 if (!driver)
177 return; 178 return;
178 if (!driver->err_handler) 179
179 return; 180 if ((PCI_DN(dn)->eeh_mode) & EEH_MODE_IRQ_DISABLED) {
180 if (!driver->err_handler->resume) 181 PCI_DN(dn)->eeh_mode &= ~EEH_MODE_IRQ_DISABLED;
182 enable_irq(dev->irq);
183 }
184 if (!driver->err_handler ||
185 !driver->err_handler->resume)
181 return; 186 return;
182 187
183 driver->err_handler->resume(dev); 188 driver->err_handler->resume(dev);
@@ -407,6 +412,8 @@ struct pci_dn * handle_eeh_events (struct eeh_event *event)
407 412
408 if (rc) 413 if (rc)
409 result = PCI_ERS_RESULT_NEED_RESET; 414 result = PCI_ERS_RESULT_NEED_RESET;
415 else
416 result = PCI_ERS_RESULT_RECOVERED;
410 } 417 }
411 418
412 /* If any device has a hard failure, then shut off everything. */ 419 /* If any device has a hard failure, then shut off everything. */
diff --git a/arch/powerpc/platforms/pseries/hotplug-cpu.c b/arch/powerpc/platforms/pseries/hotplug-cpu.c
new file mode 100644
index 000000000000..f460b9cbfd46
--- /dev/null
+++ b/arch/powerpc/platforms/pseries/hotplug-cpu.c
@@ -0,0 +1,275 @@
1/*
2 * pseries CPU Hotplug infrastructure.
3 *
4 * Split out from arch/powerpc/platforms/pseries/setup.c
5 * arch/powerpc/kernel/rtas.c, and arch/powerpc/platforms/pseries/smp.c
6 *
7 * Peter Bergner, IBM March 2001.
8 * Copyright (C) 2001 IBM.
9 * Dave Engebretsen, Peter Bergner, and
10 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
11 * Plus various changes from other IBM teams...
12 *
13 * Copyright (C) 2006 Michael Ellerman, IBM Corporation
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 */
20
21#include <linux/kernel.h>
22#include <linux/delay.h>
23#include <linux/cpu.h>
24#include <asm/system.h>
25#include <asm/prom.h>
26#include <asm/rtas.h>
27#include <asm/firmware.h>
28#include <asm/machdep.h>
29#include <asm/vdso_datapage.h>
30#include <asm/pSeries_reconfig.h>
31#include "xics.h"
32
33/* This version can't take the spinlock, because it never returns */
34static struct rtas_args rtas_stop_self_args = {
35 .token = RTAS_UNKNOWN_SERVICE,
36 .nargs = 0,
37 .nret = 1,
38 .rets = &rtas_stop_self_args.args[0],
39};
40
41static void rtas_stop_self(void)
42{
43 struct rtas_args *args = &rtas_stop_self_args;
44
45 local_irq_disable();
46
47 BUG_ON(args->token == RTAS_UNKNOWN_SERVICE);
48
49 printk("cpu %u (hwid %u) Ready to die...\n",
50 smp_processor_id(), hard_smp_processor_id());
51 enter_rtas(__pa(args));
52
53 panic("Alas, I survived.\n");
54}
55
56static void pseries_mach_cpu_die(void)
57{
58 local_irq_disable();
59 idle_task_exit();
60 xics_teardown_cpu(0);
61 rtas_stop_self();
62 /* Should never get here... */
63 BUG();
64 for(;;);
65}
66
67static int qcss_tok; /* query-cpu-stopped-state token */
68
69/* Get state of physical CPU.
70 * Return codes:
71 * 0 - The processor is in the RTAS stopped state
72 * 1 - stop-self is in progress
73 * 2 - The processor is not in the RTAS stopped state
74 * -1 - Hardware Error
75 * -2 - Hardware Busy, Try again later.
76 */
77static int query_cpu_stopped(unsigned int pcpu)
78{
79 int cpu_status, status;
80
81 status = rtas_call(qcss_tok, 1, 2, &cpu_status, pcpu);
82 if (status != 0) {
83 printk(KERN_ERR
84 "RTAS query-cpu-stopped-state failed: %i\n", status);
85 return status;
86 }
87
88 return cpu_status;
89}
90
91static int pseries_cpu_disable(void)
92{
93 int cpu = smp_processor_id();
94
95 cpu_clear(cpu, cpu_online_map);
96 vdso_data->processorCount--;
97
98 /*fix boot_cpuid here*/
99 if (cpu == boot_cpuid)
100 boot_cpuid = any_online_cpu(cpu_online_map);
101
102 /* FIXME: abstract this to not be platform specific later on */
103 xics_migrate_irqs_away();
104 return 0;
105}
106
107static void pseries_cpu_die(unsigned int cpu)
108{
109 int tries;
110 int cpu_status;
111 unsigned int pcpu = get_hard_smp_processor_id(cpu);
112
113 for (tries = 0; tries < 25; tries++) {
114 cpu_status = query_cpu_stopped(pcpu);
115 if (cpu_status == 0 || cpu_status == -1)
116 break;
117 msleep(200);
118 }
119 if (cpu_status != 0) {
120 printk("Querying DEAD? cpu %i (%i) shows %i\n",
121 cpu, pcpu, cpu_status);
122 }
123
124 /* Isolation and deallocation are definatly done by
125 * drslot_chrp_cpu. If they were not they would be
126 * done here. Change isolate state to Isolate and
127 * change allocation-state to Unusable.
128 */
129 paca[cpu].cpu_start = 0;
130}
131
132/*
133 * Update cpu_present_map and paca(s) for a new cpu node. The wrinkle
134 * here is that a cpu device node may represent up to two logical cpus
135 * in the SMT case. We must honor the assumption in other code that
136 * the logical ids for sibling SMT threads x and y are adjacent, such
137 * that x^1 == y and y^1 == x.
138 */
139static int pseries_add_processor(struct device_node *np)
140{
141 unsigned int cpu;
142 cpumask_t candidate_map, tmp = CPU_MASK_NONE;
143 int err = -ENOSPC, len, nthreads, i;
144 const u32 *intserv;
145
146 intserv = get_property(np, "ibm,ppc-interrupt-server#s", &len);
147 if (!intserv)
148 return 0;
149
150 nthreads = len / sizeof(u32);
151 for (i = 0; i < nthreads; i++)
152 cpu_set(i, tmp);
153
154 lock_cpu_hotplug();
155
156 BUG_ON(!cpus_subset(cpu_present_map, cpu_possible_map));
157
158 /* Get a bitmap of unoccupied slots. */
159 cpus_xor(candidate_map, cpu_possible_map, cpu_present_map);
160 if (cpus_empty(candidate_map)) {
161 /* If we get here, it most likely means that NR_CPUS is
162 * less than the partition's max processors setting.
163 */
164 printk(KERN_ERR "Cannot add cpu %s; this system configuration"
165 " supports %d logical cpus.\n", np->full_name,
166 cpus_weight(cpu_possible_map));
167 goto out_unlock;
168 }
169
170 while (!cpus_empty(tmp))
171 if (cpus_subset(tmp, candidate_map))
172 /* Found a range where we can insert the new cpu(s) */
173 break;
174 else
175 cpus_shift_left(tmp, tmp, nthreads);
176
177 if (cpus_empty(tmp)) {
178 printk(KERN_ERR "Unable to find space in cpu_present_map for"
179 " processor %s with %d thread(s)\n", np->name,
180 nthreads);
181 goto out_unlock;
182 }
183
184 for_each_cpu_mask(cpu, tmp) {
185 BUG_ON(cpu_isset(cpu, cpu_present_map));
186 cpu_set(cpu, cpu_present_map);
187 set_hard_smp_processor_id(cpu, *intserv++);
188 }
189 err = 0;
190out_unlock:
191 unlock_cpu_hotplug();
192 return err;
193}
194
195/*
196 * Update the present map for a cpu node which is going away, and set
197 * the hard id in the paca(s) to -1 to be consistent with boot time
198 * convention for non-present cpus.
199 */
200static void pseries_remove_processor(struct device_node *np)
201{
202 unsigned int cpu;
203 int len, nthreads, i;
204 const u32 *intserv;
205
206 intserv = get_property(np, "ibm,ppc-interrupt-server#s", &len);
207 if (!intserv)
208 return;
209
210 nthreads = len / sizeof(u32);
211
212 lock_cpu_hotplug();
213 for (i = 0; i < nthreads; i++) {
214 for_each_present_cpu(cpu) {
215 if (get_hard_smp_processor_id(cpu) != intserv[i])
216 continue;
217 BUG_ON(cpu_online(cpu));
218 cpu_clear(cpu, cpu_present_map);
219 set_hard_smp_processor_id(cpu, -1);
220 break;
221 }
222 if (cpu == NR_CPUS)
223 printk(KERN_WARNING "Could not find cpu to remove "
224 "with physical id 0x%x\n", intserv[i]);
225 }
226 unlock_cpu_hotplug();
227}
228
229static int pseries_smp_notifier(struct notifier_block *nb,
230 unsigned long action, void *node)
231{
232 int err = NOTIFY_OK;
233
234 switch (action) {
235 case PSERIES_RECONFIG_ADD:
236 if (pseries_add_processor(node))
237 err = NOTIFY_BAD;
238 break;
239 case PSERIES_RECONFIG_REMOVE:
240 pseries_remove_processor(node);
241 break;
242 default:
243 err = NOTIFY_DONE;
244 break;
245 }
246 return err;
247}
248
249static struct notifier_block pseries_smp_nb = {
250 .notifier_call = pseries_smp_notifier,
251};
252
253static int __init pseries_cpu_hotplug_init(void)
254{
255 rtas_stop_self_args.token = rtas_token("stop-self");
256 qcss_tok = rtas_token("query-cpu-stopped-state");
257
258 if (rtas_stop_self_args.token == RTAS_UNKNOWN_SERVICE ||
259 qcss_tok == RTAS_UNKNOWN_SERVICE) {
260 printk(KERN_INFO "CPU Hotplug not supported by firmware "
261 "- disabling.\n");
262 return 0;
263 }
264
265 ppc_md.cpu_die = pseries_mach_cpu_die;
266 smp_ops->cpu_disable = pseries_cpu_disable;
267 smp_ops->cpu_die = pseries_cpu_die;
268
269 /* Processors can be added/removed only on LPAR */
270 if (firmware_has_feature(FW_FEATURE_LPAR))
271 pSeries_reconfig_notifier_register(&pseries_smp_nb);
272
273 return 0;
274}
275arch_initcall(pseries_cpu_hotplug_init);
diff --git a/arch/powerpc/platforms/pseries/hvCall_inst.c b/arch/powerpc/platforms/pseries/hvCall_inst.c
index 446e17d162a5..80181c4c49eb 100644
--- a/arch/powerpc/platforms/pseries/hvCall_inst.c
+++ b/arch/powerpc/platforms/pseries/hvCall_inst.c
@@ -85,7 +85,7 @@ static int hcall_inst_seq_open(struct inode *inode, struct file *file)
85 85
86 rc = seq_open(file, &hcall_inst_seq_ops); 86 rc = seq_open(file, &hcall_inst_seq_ops);
87 seq = file->private_data; 87 seq = file->private_data;
88 seq->private = file->f_dentry->d_inode->i_private; 88 seq->private = file->f_path.dentry->d_inode->i_private;
89 89
90 return rc; 90 return rc;
91} 91}
diff --git a/arch/powerpc/platforms/pseries/scanlog.c b/arch/powerpc/platforms/pseries/scanlog.c
index 77a5bb1d9c30..45368a57d7dd 100644
--- a/arch/powerpc/platforms/pseries/scanlog.c
+++ b/arch/powerpc/platforms/pseries/scanlog.c
@@ -47,7 +47,7 @@ static struct proc_dir_entry *proc_ppc64_scan_log_dump; /* The proc file */
47static ssize_t scanlog_read(struct file *file, char __user *buf, 47static ssize_t scanlog_read(struct file *file, char __user *buf,
48 size_t count, loff_t *ppos) 48 size_t count, loff_t *ppos)
49{ 49{
50 struct inode * inode = file->f_dentry->d_inode; 50 struct inode * inode = file->f_path.dentry->d_inode;
51 struct proc_dir_entry *dp; 51 struct proc_dir_entry *dp;
52 unsigned int *data; 52 unsigned int *data;
53 int status; 53 int status;
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 0dc2548ca9bc..042ecae107ac 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -347,21 +347,6 @@ static int __init pSeries_init_panel(void)
347} 347}
348arch_initcall(pSeries_init_panel); 348arch_initcall(pSeries_init_panel);
349 349
350#ifdef CONFIG_HOTPLUG_CPU
351static void pSeries_mach_cpu_die(void)
352{
353 local_irq_disable();
354 idle_task_exit();
355 xics_teardown_cpu(0);
356 rtas_stop_self();
357 /* Should never get here... */
358 BUG();
359 for(;;);
360}
361#else
362#define pSeries_mach_cpu_die NULL
363#endif
364
365static int pseries_set_dabr(unsigned long dabr) 350static int pseries_set_dabr(unsigned long dabr)
366{ 351{
367 return plpar_hcall_norets(H_SET_DABR, dabr); 352 return plpar_hcall_norets(H_SET_DABR, dabr);
@@ -437,19 +422,14 @@ static int __init pSeries_probe_hypertas(unsigned long node,
437 if (of_get_flat_dt_prop(node, "ibm,hypertas-functions", NULL) != NULL) 422 if (of_get_flat_dt_prop(node, "ibm,hypertas-functions", NULL) != NULL)
438 powerpc_firmware_features |= FW_FEATURE_LPAR; 423 powerpc_firmware_features |= FW_FEATURE_LPAR;
439 424
440 if (firmware_has_feature(FW_FEATURE_LPAR))
441 hpte_init_lpar();
442 else
443 hpte_init_native();
444
445 return 1; 425 return 1;
446} 426}
447 427
448static int __init pSeries_probe(void) 428static int __init pSeries_probe(void)
449{ 429{
450 unsigned long root = of_get_flat_dt_root(); 430 unsigned long root = of_get_flat_dt_root();
451 char *dtype = of_get_flat_dt_prop(of_get_flat_dt_root(), 431 char *dtype = of_get_flat_dt_prop(root, "device_type", NULL);
452 "device_type", NULL); 432
453 if (dtype == NULL) 433 if (dtype == NULL)
454 return 0; 434 return 0;
455 if (strcmp(dtype, "chrp")) 435 if (strcmp(dtype, "chrp"))
@@ -467,6 +447,11 @@ static int __init pSeries_probe(void)
467 /* Now try to figure out if we are running on LPAR */ 447 /* Now try to figure out if we are running on LPAR */
468 of_scan_flat_dt(pSeries_probe_hypertas, NULL); 448 of_scan_flat_dt(pSeries_probe_hypertas, NULL);
469 449
450 if (firmware_has_feature(FW_FEATURE_LPAR))
451 hpte_init_lpar();
452 else
453 hpte_init_native();
454
470 DBG("Machine is%s LPAR !\n", 455 DBG("Machine is%s LPAR !\n",
471 (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not"); 456 (powerpc_firmware_features & FW_FEATURE_LPAR) ? "" : " not");
472 457
@@ -561,7 +546,6 @@ define_machine(pseries) {
561 .power_off = rtas_power_off, 546 .power_off = rtas_power_off,
562 .halt = rtas_halt, 547 .halt = rtas_halt,
563 .panic = rtas_os_term, 548 .panic = rtas_os_term,
564 .cpu_die = pSeries_mach_cpu_die,
565 .get_boot_time = rtas_get_boot_time, 549 .get_boot_time = rtas_get_boot_time,
566 .get_rtc_time = rtas_get_rtc_time, 550 .get_rtc_time = rtas_get_rtc_time,
567 .set_rtc_time = rtas_set_rtc_time, 551 .set_rtc_time = rtas_set_rtc_time,
diff --git a/arch/powerpc/platforms/pseries/smp.c b/arch/powerpc/platforms/pseries/smp.c
index c6624b8a0e77..4408518eaebe 100644
--- a/arch/powerpc/platforms/pseries/smp.c
+++ b/arch/powerpc/platforms/pseries/smp.c
@@ -64,197 +64,6 @@ static cpumask_t of_spin_map;
64 64
65extern void generic_secondary_smp_init(unsigned long); 65extern void generic_secondary_smp_init(unsigned long);
66 66
67#ifdef CONFIG_HOTPLUG_CPU
68
69/* Get state of physical CPU.
70 * Return codes:
71 * 0 - The processor is in the RTAS stopped state
72 * 1 - stop-self is in progress
73 * 2 - The processor is not in the RTAS stopped state
74 * -1 - Hardware Error
75 * -2 - Hardware Busy, Try again later.
76 */
77static int query_cpu_stopped(unsigned int pcpu)
78{
79 int cpu_status;
80 int status, qcss_tok;
81
82 qcss_tok = rtas_token("query-cpu-stopped-state");
83 if (qcss_tok == RTAS_UNKNOWN_SERVICE)
84 return -1;
85 status = rtas_call(qcss_tok, 1, 2, &cpu_status, pcpu);
86 if (status != 0) {
87 printk(KERN_ERR
88 "RTAS query-cpu-stopped-state failed: %i\n", status);
89 return status;
90 }
91
92 return cpu_status;
93}
94
95static int pSeries_cpu_disable(void)
96{
97 int cpu = smp_processor_id();
98
99 cpu_clear(cpu, cpu_online_map);
100 vdso_data->processorCount--;
101
102 /*fix boot_cpuid here*/
103 if (cpu == boot_cpuid)
104 boot_cpuid = any_online_cpu(cpu_online_map);
105
106 /* FIXME: abstract this to not be platform specific later on */
107 xics_migrate_irqs_away();
108 return 0;
109}
110
111static void pSeries_cpu_die(unsigned int cpu)
112{
113 int tries;
114 int cpu_status;
115 unsigned int pcpu = get_hard_smp_processor_id(cpu);
116
117 for (tries = 0; tries < 25; tries++) {
118 cpu_status = query_cpu_stopped(pcpu);
119 if (cpu_status == 0 || cpu_status == -1)
120 break;
121 msleep(200);
122 }
123 if (cpu_status != 0) {
124 printk("Querying DEAD? cpu %i (%i) shows %i\n",
125 cpu, pcpu, cpu_status);
126 }
127
128 /* Isolation and deallocation are definatly done by
129 * drslot_chrp_cpu. If they were not they would be
130 * done here. Change isolate state to Isolate and
131 * change allocation-state to Unusable.
132 */
133 paca[cpu].cpu_start = 0;
134}
135
136/*
137 * Update cpu_present_map and paca(s) for a new cpu node. The wrinkle
138 * here is that a cpu device node may represent up to two logical cpus
139 * in the SMT case. We must honor the assumption in other code that
140 * the logical ids for sibling SMT threads x and y are adjacent, such
141 * that x^1 == y and y^1 == x.
142 */
143static int pSeries_add_processor(struct device_node *np)
144{
145 unsigned int cpu;
146 cpumask_t candidate_map, tmp = CPU_MASK_NONE;
147 int err = -ENOSPC, len, nthreads, i;
148 const u32 *intserv;
149
150 intserv = get_property(np, "ibm,ppc-interrupt-server#s", &len);
151 if (!intserv)
152 return 0;
153
154 nthreads = len / sizeof(u32);
155 for (i = 0; i < nthreads; i++)
156 cpu_set(i, tmp);
157
158 lock_cpu_hotplug();
159
160 BUG_ON(!cpus_subset(cpu_present_map, cpu_possible_map));
161
162 /* Get a bitmap of unoccupied slots. */
163 cpus_xor(candidate_map, cpu_possible_map, cpu_present_map);
164 if (cpus_empty(candidate_map)) {
165 /* If we get here, it most likely means that NR_CPUS is
166 * less than the partition's max processors setting.
167 */
168 printk(KERN_ERR "Cannot add cpu %s; this system configuration"
169 " supports %d logical cpus.\n", np->full_name,
170 cpus_weight(cpu_possible_map));
171 goto out_unlock;
172 }
173
174 while (!cpus_empty(tmp))
175 if (cpus_subset(tmp, candidate_map))
176 /* Found a range where we can insert the new cpu(s) */
177 break;
178 else
179 cpus_shift_left(tmp, tmp, nthreads);
180
181 if (cpus_empty(tmp)) {
182 printk(KERN_ERR "Unable to find space in cpu_present_map for"
183 " processor %s with %d thread(s)\n", np->name,
184 nthreads);
185 goto out_unlock;
186 }
187
188 for_each_cpu_mask(cpu, tmp) {
189 BUG_ON(cpu_isset(cpu, cpu_present_map));
190 cpu_set(cpu, cpu_present_map);
191 set_hard_smp_processor_id(cpu, *intserv++);
192 }
193 err = 0;
194out_unlock:
195 unlock_cpu_hotplug();
196 return err;
197}
198
199/*
200 * Update the present map for a cpu node which is going away, and set
201 * the hard id in the paca(s) to -1 to be consistent with boot time
202 * convention for non-present cpus.
203 */
204static void pSeries_remove_processor(struct device_node *np)
205{
206 unsigned int cpu;
207 int len, nthreads, i;
208 const u32 *intserv;
209
210 intserv = get_property(np, "ibm,ppc-interrupt-server#s", &len);
211 if (!intserv)
212 return;
213
214 nthreads = len / sizeof(u32);
215
216 lock_cpu_hotplug();
217 for (i = 0; i < nthreads; i++) {
218 for_each_present_cpu(cpu) {
219 if (get_hard_smp_processor_id(cpu) != intserv[i])
220 continue;
221 BUG_ON(cpu_online(cpu));
222 cpu_clear(cpu, cpu_present_map);
223 set_hard_smp_processor_id(cpu, -1);
224 break;
225 }
226 if (cpu == NR_CPUS)
227 printk(KERN_WARNING "Could not find cpu to remove "
228 "with physical id 0x%x\n", intserv[i]);
229 }
230 unlock_cpu_hotplug();
231}
232
233static int pSeries_smp_notifier(struct notifier_block *nb, unsigned long action, void *node)
234{
235 int err = NOTIFY_OK;
236
237 switch (action) {
238 case PSERIES_RECONFIG_ADD:
239 if (pSeries_add_processor(node))
240 err = NOTIFY_BAD;
241 break;
242 case PSERIES_RECONFIG_REMOVE:
243 pSeries_remove_processor(node);
244 break;
245 default:
246 err = NOTIFY_DONE;
247 break;
248 }
249 return err;
250}
251
252static struct notifier_block pSeries_smp_nb = {
253 .notifier_call = pSeries_smp_notifier,
254};
255
256#endif /* CONFIG_HOTPLUG_CPU */
257
258/** 67/**
259 * smp_startup_cpu() - start the given cpu 68 * smp_startup_cpu() - start the given cpu
260 * 69 *
@@ -422,15 +231,6 @@ static void __init smp_init_pseries(void)
422 231
423 DBG(" -> smp_init_pSeries()\n"); 232 DBG(" -> smp_init_pSeries()\n");
424 233
425#ifdef CONFIG_HOTPLUG_CPU
426 smp_ops->cpu_disable = pSeries_cpu_disable;
427 smp_ops->cpu_die = pSeries_cpu_die;
428
429 /* Processors can be added/removed only on LPAR */
430 if (firmware_has_feature(FW_FEATURE_LPAR))
431 pSeries_reconfig_notifier_register(&pSeries_smp_nb);
432#endif
433
434 /* Mark threads which are still spinning in hold loops. */ 234 /* Mark threads which are still spinning in hold loops. */
435 if (cpu_has_feature(CPU_FTR_SMT)) { 235 if (cpu_has_feature(CPU_FTR_SMT)) {
436 for_each_present_cpu(i) { 236 for_each_present_cpu(i) {
diff --git a/arch/powerpc/sysdev/Makefile b/arch/powerpc/sysdev/Makefile
index 6cc34597a620..04d4917eb303 100644
--- a/arch/powerpc/sysdev/Makefile
+++ b/arch/powerpc/sysdev/Makefile
@@ -5,7 +5,8 @@ endif
5obj-$(CONFIG_MPIC) += mpic.o 5obj-$(CONFIG_MPIC) += mpic.o
6obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o 6obj-$(CONFIG_PPC_INDIRECT_PCI) += indirect_pci.o
7obj-$(CONFIG_PPC_MPC106) += grackle.o 7obj-$(CONFIG_PPC_MPC106) += grackle.o
8obj-$(CONFIG_PPC_DCR) += dcr.o dcr-low.o 8obj-$(CONFIG_PPC_DCR) += dcr.o
9obj-$(CONFIG_PPC_DCR_NATIVE) += dcr-low.o
9obj-$(CONFIG_U3_DART) += dart_iommu.o 10obj-$(CONFIG_U3_DART) += dart_iommu.o
10obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o 11obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o
11obj-$(CONFIG_FSL_SOC) += fsl_soc.o 12obj-$(CONFIG_FSL_SOC) += fsl_soc.o
diff --git a/arch/powerpc/sysdev/dcr.S b/arch/powerpc/sysdev/dcr.S
deleted file mode 100644
index 2078f39e2f17..000000000000
--- a/arch/powerpc/sysdev/dcr.S
+++ /dev/null
@@ -1,39 +0,0 @@
1/*
2 * "Indirect" DCR access
3 *
4 * Copyright (c) 2004 Eugene Surovegin <ebs@ebshome.net>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <asm/ppc_asm.h>
13#include <asm/processor.h>
14
15#define DCR_ACCESS_PROLOG(table) \
16 rlwinm r3,r3,4,18,27; \
17 lis r5,table@h; \
18 ori r5,r5,table@l; \
19 add r3,r3,r5; \
20 mtctr r3; \
21 bctr
22
23_GLOBAL(__mfdcr)
24 DCR_ACCESS_PROLOG(__mfdcr_table)
25
26_GLOBAL(__mtdcr)
27 DCR_ACCESS_PROLOG(__mtdcr_table)
28
29__mfdcr_table:
30 mfdcr r3,0; blr
31__mtdcr_table:
32 mtdcr 0,r4; blr
33
34dcr = 1
35 .rept 1023
36 mfdcr r3,dcr; blr
37 mtdcr dcr,r4; blr
38 dcr = dcr + 1
39 .endr
diff --git a/arch/powerpc/sysdev/qe_lib/qe_ic.c b/arch/powerpc/sysdev/qe_lib/qe_ic.c
index 6995f51b9488..74e48d94f27c 100644
--- a/arch/powerpc/sysdev/qe_lib/qe_ic.c
+++ b/arch/powerpc/sysdev/qe_lib/qe_ic.c
@@ -223,23 +223,15 @@ static void qe_ic_mask_irq(unsigned int virq)
223 qe_ic_write(qe_ic->regs, qe_ic_info[src].mask_reg, 223 qe_ic_write(qe_ic->regs, qe_ic_info[src].mask_reg,
224 temp & ~qe_ic_info[src].mask); 224 temp & ~qe_ic_info[src].mask);
225 225
226 spin_unlock_irqrestore(&qe_ic_lock, flags); 226 /* Flush the above write before enabling interrupts; otherwise,
227} 227 * spurious interrupts will sometimes happen. To be 100% sure
228 228 * that the write has reached the device before interrupts are
229static void qe_ic_mask_irq_and_ack(unsigned int virq) 229 * enabled, the mask register would have to be read back; however,
230{ 230 * this is not required for correctness, only to avoid wasting
231 struct qe_ic *qe_ic = qe_ic_from_irq(virq); 231 * time on a large number of spurious interrupts. In testing,
232 unsigned int src = virq_to_hw(virq); 232 * a sync reduced the observed spurious interrupts to zero.
233 unsigned long flags; 233 */
234 u32 temp; 234 mb();
235
236 spin_lock_irqsave(&qe_ic_lock, flags);
237
238 temp = qe_ic_read(qe_ic->regs, qe_ic_info[src].mask_reg);
239 qe_ic_write(qe_ic->regs, qe_ic_info[src].mask_reg,
240 temp & ~qe_ic_info[src].mask);
241
242 /* There is nothing to do for ack here, ack is handled in ISR */
243 235
244 spin_unlock_irqrestore(&qe_ic_lock, flags); 236 spin_unlock_irqrestore(&qe_ic_lock, flags);
245} 237}
@@ -248,7 +240,7 @@ static struct irq_chip qe_ic_irq_chip = {
248 .typename = " QEIC ", 240 .typename = " QEIC ",
249 .unmask = qe_ic_unmask_irq, 241 .unmask = qe_ic_unmask_irq,
250 .mask = qe_ic_mask_irq, 242 .mask = qe_ic_mask_irq,
251 .mask_ack = qe_ic_mask_irq_and_ack, 243 .mask_ack = qe_ic_mask_irq,
252}; 244};
253 245
254static int qe_ic_host_match(struct irq_host *h, struct device_node *node) 246static int qe_ic_host_match(struct irq_host *h, struct device_node *node)
@@ -331,34 +323,22 @@ unsigned int qe_ic_get_high_irq(struct qe_ic *qe_ic)
331 return irq_linear_revmap(qe_ic->irqhost, irq); 323 return irq_linear_revmap(qe_ic->irqhost, irq);
332} 324}
333 325
334/* FIXME: We mask all the QE Low interrupts while handling. We should
335 * let other interrupt come in, but BAD interrupts are generated */
336void fastcall qe_ic_cascade_low(unsigned int irq, struct irq_desc *desc) 326void fastcall qe_ic_cascade_low(unsigned int irq, struct irq_desc *desc)
337{ 327{
338 struct qe_ic *qe_ic = desc->handler_data; 328 struct qe_ic *qe_ic = desc->handler_data;
339 struct irq_chip *chip = irq_desc[irq].chip;
340
341 unsigned int cascade_irq = qe_ic_get_low_irq(qe_ic); 329 unsigned int cascade_irq = qe_ic_get_low_irq(qe_ic);
342 330
343 chip->mask_ack(irq);
344 if (cascade_irq != NO_IRQ) 331 if (cascade_irq != NO_IRQ)
345 generic_handle_irq(cascade_irq); 332 generic_handle_irq(cascade_irq);
346 chip->unmask(irq);
347} 333}
348 334
349/* FIXME: We mask all the QE High interrupts while handling. We should
350 * let other interrupt come in, but BAD interrupts are generated */
351void fastcall qe_ic_cascade_high(unsigned int irq, struct irq_desc *desc) 335void fastcall qe_ic_cascade_high(unsigned int irq, struct irq_desc *desc)
352{ 336{
353 struct qe_ic *qe_ic = desc->handler_data; 337 struct qe_ic *qe_ic = desc->handler_data;
354 struct irq_chip *chip = irq_desc[irq].chip;
355
356 unsigned int cascade_irq = qe_ic_get_high_irq(qe_ic); 338 unsigned int cascade_irq = qe_ic_get_high_irq(qe_ic);
357 339
358 chip->mask_ack(irq);
359 if (cascade_irq != NO_IRQ) 340 if (cascade_irq != NO_IRQ)
360 generic_handle_irq(cascade_irq); 341 generic_handle_irq(cascade_irq);
361 chip->unmask(irq);
362} 342}
363 343
364void __init qe_ic_init(struct device_node *node, unsigned int flags) 344void __init qe_ic_init(struct device_node *node, unsigned int flags)
diff --git a/arch/powerpc/sysdev/rom.c b/arch/powerpc/sysdev/rom.c
index bf5b3f10e6c6..c855a3b298a3 100644
--- a/arch/powerpc/sysdev/rom.c
+++ b/arch/powerpc/sysdev/rom.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <asm/of_device.h> 11#include <asm/of_device.h>
12#include <asm/of_platform.h>
12 13
13static int __init powerpc_flash_init(void) 14static int __init powerpc_flash_init(void)
14{ 15{
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index a34ed49e0356..77540a2f7704 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -22,6 +22,7 @@
22#include <linux/sysrq.h> 22#include <linux/sysrq.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/irq.h> 24#include <linux/irq.h>
25#include <linux/bug.h>
25 26
26#include <asm/ptrace.h> 27#include <asm/ptrace.h>
27#include <asm/string.h> 28#include <asm/string.h>
@@ -35,7 +36,6 @@
35#include <asm/cputable.h> 36#include <asm/cputable.h>
36#include <asm/rtas.h> 37#include <asm/rtas.h>
37#include <asm/sstep.h> 38#include <asm/sstep.h>
38#include <asm/bug.h>
39#include <asm/irq_regs.h> 39#include <asm/irq_regs.h>
40#include <asm/spu.h> 40#include <asm/spu.h>
41#include <asm/spu_priv1.h> 41#include <asm/spu_priv1.h>
@@ -1346,7 +1346,7 @@ static void backtrace(struct pt_regs *excp)
1346 1346
1347static void print_bug_trap(struct pt_regs *regs) 1347static void print_bug_trap(struct pt_regs *regs)
1348{ 1348{
1349 struct bug_entry *bug; 1349 const struct bug_entry *bug;
1350 unsigned long addr; 1350 unsigned long addr;
1351 1351
1352 if (regs->msr & MSR_PR) 1352 if (regs->msr & MSR_PR)
@@ -1357,11 +1357,11 @@ static void print_bug_trap(struct pt_regs *regs)
1357 bug = find_bug(regs->nip); 1357 bug = find_bug(regs->nip);
1358 if (bug == NULL) 1358 if (bug == NULL)
1359 return; 1359 return;
1360 if (bug->line & BUG_WARNING_TRAP) 1360 if (is_warning_bug(bug))
1361 return; 1361 return;
1362 1362
1363 printf("kernel BUG in %s at %s:%d!\n", 1363 printf("kernel BUG at %s:%u!\n",
1364 bug->function, bug->file, (unsigned int)bug->line); 1364 bug->file, bug->line);
1365} 1365}
1366 1366
1367void excprint(struct pt_regs *fp) 1367void excprint(struct pt_regs *fp)
diff --git a/arch/ppc/8xx_io/cs4218_tdm.c b/arch/ppc/8xx_io/cs4218_tdm.c
index 959d31c26cbb..c71ef3c2e7bf 100644
--- a/arch/ppc/8xx_io/cs4218_tdm.c
+++ b/arch/ppc/8xx_io/cs4218_tdm.c
@@ -2165,7 +2165,7 @@ static int sq_release(struct inode *inode, struct file *file)
2165 int rc = 0; 2165 int rc = 0;
2166 2166
2167 if (sq.busy) 2167 if (sq.busy)
2168 rc = sq_fsync(file, file->f_dentry); 2168 rc = sq_fsync(file, file->f_path.dentry);
2169 sound.soft = sound.dsp; 2169 sound.soft = sound.dsp;
2170 sound.hard = sound.dsp; 2170 sound.hard = sound.dsp;
2171 sound_silence(); 2171 sound_silence();
@@ -2218,25 +2218,25 @@ static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
2218 return 0; 2218 return 0;
2219 case SNDCTL_DSP_POST: 2219 case SNDCTL_DSP_POST:
2220 case SNDCTL_DSP_SYNC: 2220 case SNDCTL_DSP_SYNC:
2221 return sq_fsync(file, file->f_dentry); 2221 return sq_fsync(file, file->f_path.dentry);
2222 2222
2223 /* ++TeSche: before changing any of these it's 2223 /* ++TeSche: before changing any of these it's
2224 * probably wise to wait until sound playing has 2224 * probably wise to wait until sound playing has
2225 * settled down. */ 2225 * settled down. */
2226 case SNDCTL_DSP_SPEED: 2226 case SNDCTL_DSP_SPEED:
2227 sq_fsync(file, file->f_dentry); 2227 sq_fsync(file, file->f_path.dentry);
2228 IOCTL_IN(arg, data); 2228 IOCTL_IN(arg, data);
2229 return IOCTL_OUT(arg, sound_set_speed(data)); 2229 return IOCTL_OUT(arg, sound_set_speed(data));
2230 case SNDCTL_DSP_STEREO: 2230 case SNDCTL_DSP_STEREO:
2231 sq_fsync(file, file->f_dentry); 2231 sq_fsync(file, file->f_path.dentry);
2232 IOCTL_IN(arg, data); 2232 IOCTL_IN(arg, data);
2233 return IOCTL_OUT(arg, sound_set_stereo(data)); 2233 return IOCTL_OUT(arg, sound_set_stereo(data));
2234 case SOUND_PCM_WRITE_CHANNELS: 2234 case SOUND_PCM_WRITE_CHANNELS:
2235 sq_fsync(file, file->f_dentry); 2235 sq_fsync(file, file->f_path.dentry);
2236 IOCTL_IN(arg, data); 2236 IOCTL_IN(arg, data);
2237 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1); 2237 return IOCTL_OUT(arg, sound_set_stereo(data-1)+1);
2238 case SNDCTL_DSP_SETFMT: 2238 case SNDCTL_DSP_SETFMT:
2239 sq_fsync(file, file->f_dentry); 2239 sq_fsync(file, file->f_path.dentry);
2240 IOCTL_IN(arg, data); 2240 IOCTL_IN(arg, data);
2241 return IOCTL_OUT(arg, sound_set_format(data)); 2241 return IOCTL_OUT(arg, sound_set_format(data));
2242 case SNDCTL_DSP_GETFMTS: 2242 case SNDCTL_DSP_GETFMTS:
diff --git a/arch/ppc/Kconfig b/arch/ppc/Kconfig
index edf71a4ecc95..692b5ba53209 100644
--- a/arch/ppc/Kconfig
+++ b/arch/ppc/Kconfig
@@ -19,6 +19,14 @@ config RWSEM_XCHGADD_ALGORITHM
19 bool 19 bool
20 default y 20 default y
21 21
22config ARCH_HAS_ILOG2_U32
23 bool
24 default y
25
26config ARCH_HAS_ILOG2_U64
27 bool
28 default n
29
22config GENERIC_HWEIGHT 30config GENERIC_HWEIGHT
23 bool 31 bool
24 default y 32 default y
@@ -52,6 +60,11 @@ config ARCH_MAY_HAVE_PC_FDC
52 bool 60 bool
53 default y 61 default y
54 62
63config GENERIC_BUG
64 bool
65 default y
66 depends on BUG
67
55source "init/Kconfig" 68source "init/Kconfig"
56 69
57menu "Processor" 70menu "Processor"
diff --git a/arch/ppc/kernel/pci.c b/arch/ppc/kernel/pci.c
index 63808e01cb0b..5e723c4c2571 100644
--- a/arch/ppc/kernel/pci.c
+++ b/arch/ppc/kernel/pci.c
@@ -879,7 +879,7 @@ pci_resource_to_bus(struct pci_dev *pdev, struct resource *res)
879 879
880 880
881static struct resource *__pci_mmap_make_offset(struct pci_dev *dev, 881static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
882 unsigned long *offset, 882 resource_size_t *offset,
883 enum pci_mmap_state mmap_state) 883 enum pci_mmap_state mmap_state)
884{ 884{
885 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 885 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
@@ -891,7 +891,9 @@ static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
891 891
892 /* If memory, add on the PCI bridge address offset */ 892 /* If memory, add on the PCI bridge address offset */
893 if (mmap_state == pci_mmap_mem) { 893 if (mmap_state == pci_mmap_mem) {
894#if 0 /* See comment in pci_resource_to_user() for why this is disabled */
894 *offset += hose->pci_mem_offset; 895 *offset += hose->pci_mem_offset;
896#endif
895 res_bit = IORESOURCE_MEM; 897 res_bit = IORESOURCE_MEM;
896 } else { 898 } else {
897 io_offset = hose->io_base_virt - ___IO_BASE; 899 io_offset = hose->io_base_virt - ___IO_BASE;
@@ -1030,7 +1032,7 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1030 enum pci_mmap_state mmap_state, 1032 enum pci_mmap_state mmap_state,
1031 int write_combine) 1033 int write_combine)
1032{ 1034{
1033 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 1035 resource_size_t offset = vma->vm_pgoff << PAGE_SHIFT;
1034 struct resource *rp; 1036 struct resource *rp;
1035 int ret; 1037 int ret;
1036 1038
@@ -1132,21 +1134,42 @@ void pci_resource_to_user(const struct pci_dev *dev, int bar,
1132 resource_size_t *start, resource_size_t *end) 1134 resource_size_t *start, resource_size_t *end)
1133{ 1135{
1134 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number); 1136 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
1135 unsigned long offset = 0; 1137 resource_size_t offset = 0;
1136 1138
1137 if (hose == NULL) 1139 if (hose == NULL)
1138 return; 1140 return;
1139 1141
1140 if (rsrc->flags & IORESOURCE_IO) 1142 if (rsrc->flags & IORESOURCE_IO)
1141 offset = ___IO_BASE - hose->io_base_virt + hose->io_base_phys; 1143 offset = (unsigned long)hose->io_base_virt - _IO_BASE;
1144
1145 /* We pass a fully fixed up address to userland for MMIO instead of
1146 * a BAR value because X is lame and expects to be able to use that
1147 * to pass to /dev/mem !
1148 *
1149 * That means that we'll have potentially 64 bits values where some
1150 * userland apps only expect 32 (like X itself since it thinks only
1151 * Sparc has 64 bits MMIO) but if we don't do that, we break it on
1152 * 32 bits CHRPs :-(
1153 *
1154 * Hopefully, the sysfs insterface is immune to that gunk. Once X
1155 * has been fixed (and the fix spread enough), we can re-enable the
1156 * 2 lines below and pass down a BAR value to userland. In that case
1157 * we'll also have to re-enable the matching code in
1158 * __pci_mmap_make_offset().
1159 *
1160 * BenH.
1161 */
1162#if 0
1163 else if (rsrc->flags & IORESOURCE_MEM)
1164 offset = hose->pci_mem_offset;
1165#endif
1142 1166
1143 *start = rsrc->start + offset; 1167 *start = rsrc->start - offset;
1144 *end = rsrc->end + offset; 1168 *end = rsrc->end - offset;
1145} 1169}
1146 1170
1147void __init 1171void __init pci_init_resource(struct resource *res, resource_size_t start,
1148pci_init_resource(struct resource *res, unsigned long start, unsigned long end, 1172 resource_size_t end, int flags, char *name)
1149 int flags, char *name)
1150{ 1173{
1151 res->start = start; 1174 res->start = start;
1152 res->end = end; 1175 res->end = end;
diff --git a/arch/ppc/kernel/traps.c b/arch/ppc/kernel/traps.c
index 2f835b9e95e4..810f7aa72e92 100644
--- a/arch/ppc/kernel/traps.c
+++ b/arch/ppc/kernel/traps.c
@@ -28,6 +28,7 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/prctl.h> 30#include <linux/prctl.h>
31#include <linux/bug.h>
31 32
32#include <asm/pgtable.h> 33#include <asm/pgtable.h>
33#include <asm/uaccess.h> 34#include <asm/uaccess.h>
@@ -559,64 +560,9 @@ static void emulate_single_step(struct pt_regs *regs)
559 } 560 }
560} 561}
561 562
562/* 563int is_valid_bugaddr(unsigned long addr)
563 * Look through the list of trap instructions that are used for BUG(),
564 * BUG_ON() and WARN_ON() and see if we hit one. At this point we know
565 * that the exception was caused by a trap instruction of some kind.
566 * Returns 1 if we should continue (i.e. it was a WARN_ON) or 0
567 * otherwise.
568 */
569extern struct bug_entry __start___bug_table[], __stop___bug_table[];
570
571#ifndef CONFIG_MODULES
572#define module_find_bug(x) NULL
573#endif
574
575struct bug_entry *find_bug(unsigned long bugaddr)
576{
577 struct bug_entry *bug;
578
579 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
580 if (bugaddr == bug->bug_addr)
581 return bug;
582 return module_find_bug(bugaddr);
583}
584
585int check_bug_trap(struct pt_regs *regs)
586{ 564{
587 struct bug_entry *bug; 565 return addr >= PAGE_OFFSET;
588 unsigned long addr;
589
590 if (regs->msr & MSR_PR)
591 return 0; /* not in kernel */
592 addr = regs->nip; /* address of trap instruction */
593 if (addr < PAGE_OFFSET)
594 return 0;
595 bug = find_bug(regs->nip);
596 if (bug == NULL)
597 return 0;
598 if (bug->line & BUG_WARNING_TRAP) {
599 /* this is a WARN_ON rather than BUG/BUG_ON */
600#ifdef CONFIG_XMON
601 xmon_printf(KERN_ERR "Badness in %s at %s:%ld\n",
602 bug->function, bug->file,
603 bug->line & ~BUG_WARNING_TRAP);
604#endif /* CONFIG_XMON */
605 printk(KERN_ERR "Badness in %s at %s:%ld\n",
606 bug->function, bug->file,
607 bug->line & ~BUG_WARNING_TRAP);
608 dump_stack();
609 return 1;
610 }
611#ifdef CONFIG_XMON
612 xmon_printf(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
613 bug->function, bug->file, bug->line);
614 xmon(regs);
615#endif /* CONFIG_XMON */
616 printk(KERN_CRIT "kernel BUG in %s at %s:%ld!\n",
617 bug->function, bug->file, bug->line);
618
619 return 0;
620} 566}
621 567
622void program_check_exception(struct pt_regs *regs) 568void program_check_exception(struct pt_regs *regs)
@@ -671,7 +617,9 @@ void program_check_exception(struct pt_regs *regs)
671 /* trap exception */ 617 /* trap exception */
672 if (debugger_bpt(regs)) 618 if (debugger_bpt(regs))
673 return; 619 return;
674 if (check_bug_trap(regs)) { 620
621 if (!(regs->msr & MSR_PR) && /* not user-mode */
622 report_bug(regs->nip) == BUG_TRAP_TYPE_WARN) {
675 regs->nip += 4; 623 regs->nip += 4;
676 return; 624 return;
677 } 625 }
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 583d9ff0a571..ff690564edbd 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -22,6 +22,14 @@ config RWSEM_XCHGADD_ALGORITHM
22 bool 22 bool
23 default y 23 default y
24 24
25config ARCH_HAS_ILOG2_U32
26 bool
27 default n
28
29config ARCH_HAS_ILOG2_U64
30 bool
31 default n
32
25config GENERIC_HWEIGHT 33config GENERIC_HWEIGHT
26 bool 34 bool
27 default y 35 default y
@@ -233,8 +241,14 @@ config WARN_STACK_SIZE
233 This allows you to specify the maximum frame size a function may 241 This allows you to specify the maximum frame size a function may
234 have without the compiler complaining about it. 242 have without the compiler complaining about it.
235 243
244config ARCH_POPULATES_NODE_MAP
245 def_bool y
246
236source "mm/Kconfig" 247source "mm/Kconfig"
237 248
249config HOLES_IN_ZONE
250 def_bool y
251
238comment "I/O subsystem configuration" 252comment "I/O subsystem configuration"
239 253
240config MACHCHK_WARNING 254config MACHCHK_WARNING
@@ -258,14 +272,6 @@ config QDIO
258 272
259 If unsure, say Y. 273 If unsure, say Y.
260 274
261config QDIO_PERF_STATS
262 bool "Performance statistics in /proc"
263 depends on QDIO
264 help
265 Say Y here to get performance statistics in /proc/qdio_perf
266
267 If unsure, say N.
268
269config QDIO_DEBUG 275config QDIO_DEBUG
270 bool "Extended debugging information" 276 bool "Extended debugging information"
271 depends on QDIO 277 depends on QDIO
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index 7cd51e73e274..a6ec919ba83f 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -134,7 +134,6 @@ CONFIG_RESOURCES_64BIT=y
134# 134#
135CONFIG_MACHCHK_WARNING=y 135CONFIG_MACHCHK_WARNING=y
136CONFIG_QDIO=y 136CONFIG_QDIO=y
137# CONFIG_QDIO_PERF_STATS is not set
138# CONFIG_QDIO_DEBUG is not set 137# CONFIG_QDIO_DEBUG is not set
139 138
140# 139#
diff --git a/arch/s390/hypfs/inode.c b/arch/s390/hypfs/inode.c
index cd702ae45d6d..b6716c4b9934 100644
--- a/arch/s390/hypfs/inode.c
+++ b/arch/s390/hypfs/inode.c
@@ -109,7 +109,7 @@ static void hypfs_drop_inode(struct inode *inode)
109 109
110static int hypfs_open(struct inode *inode, struct file *filp) 110static int hypfs_open(struct inode *inode, struct file *filp)
111{ 111{
112 char *data = filp->f_dentry->d_inode->i_private; 112 char *data = filp->f_path.dentry->d_inode->i_private;
113 struct hypfs_sb_info *fs_info; 113 struct hypfs_sb_info *fs_info;
114 114
115 if (filp->f_mode & FMODE_WRITE) { 115 if (filp->f_mode & FMODE_WRITE) {
@@ -174,7 +174,7 @@ static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
174 struct hypfs_sb_info *fs_info; 174 struct hypfs_sb_info *fs_info;
175 size_t count = iov_length(iov, nr_segs); 175 size_t count = iov_length(iov, nr_segs);
176 176
177 sb = iocb->ki_filp->f_dentry->d_inode->i_sb; 177 sb = iocb->ki_filp->f_path.dentry->d_inode->i_sb;
178 fs_info = sb->s_fs_info; 178 fs_info = sb->s_fs_info;
179 /* 179 /*
180 * Currently we only allow one update per second for two reasons: 180 * Currently we only allow one update per second for two reasons:
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index 43f3d0c7e132..ef5266fbce62 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -603,13 +603,13 @@ debug_open(struct inode *inode, struct file *file)
603 debug_info_t *debug_info, *debug_info_snapshot; 603 debug_info_t *debug_info, *debug_info_snapshot;
604 604
605 down(&debug_lock); 605 down(&debug_lock);
606 debug_info = file->f_dentry->d_inode->i_private; 606 debug_info = file->f_path.dentry->d_inode->i_private;
607 /* find debug view */ 607 /* find debug view */
608 for (i = 0; i < DEBUG_MAX_VIEWS; i++) { 608 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
609 if (!debug_info->views[i]) 609 if (!debug_info->views[i])
610 continue; 610 continue;
611 else if (debug_info->debugfs_entries[i] == 611 else if (debug_info->debugfs_entries[i] ==
612 file->f_dentry) { 612 file->f_path.dentry) {
613 goto found; /* found view ! */ 613 goto found; /* found view ! */
614 } 614 }
615 } 615 }
diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c
index b928fecdc743..49ef206ec880 100644
--- a/arch/s390/kernel/setup.c
+++ b/arch/s390/kernel/setup.c
@@ -64,9 +64,8 @@ unsigned int console_devno = -1;
64unsigned int console_irq = -1; 64unsigned int console_irq = -1;
65unsigned long machine_flags = 0; 65unsigned long machine_flags = 0;
66 66
67struct mem_chunk memory_chunk[MEMORY_CHUNKS]; 67struct mem_chunk __initdata memory_chunk[MEMORY_CHUNKS];
68volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */ 68volatile int __cpu_logical_map[NR_CPUS]; /* logical cpu to cpu address */
69unsigned long __initdata zholes_size[MAX_NR_ZONES];
70static unsigned long __initdata memory_end; 69static unsigned long __initdata memory_end;
71 70
72/* 71/*
@@ -354,21 +353,6 @@ void machine_power_off(void)
354 */ 353 */
355void (*pm_power_off)(void) = machine_power_off; 354void (*pm_power_off)(void) = machine_power_off;
356 355
357static void __init
358add_memory_hole(unsigned long start, unsigned long end)
359{
360 unsigned long dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
361
362 if (end <= dma_pfn)
363 zholes_size[ZONE_DMA] += end - start + 1;
364 else if (start > dma_pfn)
365 zholes_size[ZONE_NORMAL] += end - start + 1;
366 else {
367 zholes_size[ZONE_DMA] += dma_pfn - start + 1;
368 zholes_size[ZONE_NORMAL] += end - dma_pfn;
369 }
370}
371
372static int __init early_parse_mem(char *p) 356static int __init early_parse_mem(char *p)
373{ 357{
374 memory_end = memparse(p, &p); 358 memory_end = memparse(p, &p);
@@ -521,7 +505,6 @@ setup_memory(void)
521{ 505{
522 unsigned long bootmap_size; 506 unsigned long bootmap_size;
523 unsigned long start_pfn, end_pfn, init_pfn; 507 unsigned long start_pfn, end_pfn, init_pfn;
524 unsigned long last_rw_end;
525 int i; 508 int i;
526 509
527 /* 510 /*
@@ -577,39 +560,27 @@ setup_memory(void)
577 /* 560 /*
578 * Register RAM areas with the bootmem allocator. 561 * Register RAM areas with the bootmem allocator.
579 */ 562 */
580 last_rw_end = start_pfn;
581 563
582 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) { 564 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
583 unsigned long start_chunk, end_chunk; 565 unsigned long start_chunk, end_chunk, pfn;
584 566
585 if (memory_chunk[i].type != CHUNK_READ_WRITE) 567 if (memory_chunk[i].type != CHUNK_READ_WRITE)
586 continue; 568 continue;
587 start_chunk = (memory_chunk[i].addr + PAGE_SIZE - 1); 569 start_chunk = PFN_DOWN(memory_chunk[i].addr);
588 start_chunk >>= PAGE_SHIFT; 570 end_chunk = start_chunk + PFN_DOWN(memory_chunk[i].size) - 1;
589 end_chunk = (memory_chunk[i].addr + memory_chunk[i].size); 571 end_chunk = min(end_chunk, end_pfn);
590 end_chunk >>= PAGE_SHIFT; 572 if (start_chunk >= end_chunk)
591 if (start_chunk < start_pfn) 573 continue;
592 start_chunk = start_pfn; 574 add_active_range(0, start_chunk, end_chunk);
593 if (end_chunk > end_pfn) 575 pfn = max(start_chunk, start_pfn);
594 end_chunk = end_pfn; 576 for (; pfn <= end_chunk; pfn++)
595 if (start_chunk < end_chunk) { 577 page_set_storage_key(PFN_PHYS(pfn), PAGE_DEFAULT_KEY);
596 /* Initialize storage key for RAM pages */
597 for (init_pfn = start_chunk ; init_pfn < end_chunk;
598 init_pfn++)
599 page_set_storage_key(init_pfn << PAGE_SHIFT,
600 PAGE_DEFAULT_KEY);
601 free_bootmem(start_chunk << PAGE_SHIFT,
602 (end_chunk - start_chunk) << PAGE_SHIFT);
603 if (last_rw_end < start_chunk)
604 add_memory_hole(last_rw_end, start_chunk - 1);
605 last_rw_end = end_chunk;
606 }
607 } 578 }
608 579
609 psw_set_key(PAGE_DEFAULT_KEY); 580 psw_set_key(PAGE_DEFAULT_KEY);
610 581
611 if (last_rw_end < end_pfn - 1) 582 free_bootmem_with_active_regions(0, max_pfn);
612 add_memory_hole(last_rw_end, end_pfn - 1); 583 reserve_bootmem(0, PFN_PHYS(start_pfn));
613 584
614 /* 585 /*
615 * Reserve the bootmem bitmap itself as well. We do this in two 586 * Reserve the bootmem bitmap itself as well. We do this in two
diff --git a/arch/s390/lib/uaccess_pt.c b/arch/s390/lib/uaccess_pt.c
index 8741bdc09299..633249c3ba91 100644
--- a/arch/s390/lib/uaccess_pt.c
+++ b/arch/s390/lib/uaccess_pt.c
@@ -8,8 +8,8 @@
8 */ 8 */
9 9
10#include <linux/errno.h> 10#include <linux/errno.h>
11#include <asm/uaccess.h>
12#include <linux/mm.h> 11#include <linux/mm.h>
12#include <asm/uaccess.h>
13#include <asm/futex.h> 13#include <asm/futex.h>
14 14
15static inline int __handle_fault(struct mm_struct *mm, unsigned long address, 15static inline int __handle_fault(struct mm_struct *mm, unsigned long address,
@@ -60,8 +60,9 @@ out:
60 60
61out_of_memory: 61out_of_memory:
62 up_read(&mm->mmap_sem); 62 up_read(&mm->mmap_sem);
63 if (current->pid == 1) { 63 if (is_init(current)) {
64 yield(); 64 yield();
65 down_read(&mm->mmap_sem);
65 goto survive; 66 goto survive;
66 } 67 }
67 printk("VM: killing process %s\n", current->comm); 68 printk("VM: killing process %s\n", current->comm);
diff --git a/arch/s390/mm/Makefile b/arch/s390/mm/Makefile
index aa9a42b6e62d..8e09db1edbb9 100644
--- a/arch/s390/mm/Makefile
+++ b/arch/s390/mm/Makefile
@@ -2,6 +2,6 @@
2# Makefile for the linux s390-specific parts of the memory manager. 2# Makefile for the linux s390-specific parts of the memory manager.
3# 3#
4 4
5obj-y := init.o fault.o ioremap.o extmem.o mmap.o 5obj-y := init.o fault.o ioremap.o extmem.o mmap.o vmem.o
6obj-$(CONFIG_CMM) += cmm.o 6obj-$(CONFIG_CMM) += cmm.o
7 7
diff --git a/arch/s390/mm/extmem.c b/arch/s390/mm/extmem.c
index 9e9bc48463a5..775bf19e742b 100644
--- a/arch/s390/mm/extmem.c
+++ b/arch/s390/mm/extmem.c
@@ -16,6 +16,7 @@
16#include <linux/bootmem.h> 16#include <linux/bootmem.h>
17#include <linux/ctype.h> 17#include <linux/ctype.h>
18#include <asm/page.h> 18#include <asm/page.h>
19#include <asm/pgtable.h>
19#include <asm/ebcdic.h> 20#include <asm/ebcdic.h>
20#include <asm/errno.h> 21#include <asm/errno.h>
21#include <asm/extmem.h> 22#include <asm/extmem.h>
@@ -238,65 +239,6 @@ query_segment_type (struct dcss_segment *seg)
238} 239}
239 240
240/* 241/*
241 * check if the given segment collides with guest storage.
242 * returns 1 if this is the case, 0 if no collision was found
243 */
244static int
245segment_overlaps_storage(struct dcss_segment *seg)
246{
247 int i;
248
249 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
250 if (memory_chunk[i].type != CHUNK_READ_WRITE)
251 continue;
252 if ((memory_chunk[i].addr >> 20) > (seg->end >> 20))
253 continue;
254 if (((memory_chunk[i].addr + memory_chunk[i].size - 1) >> 20)
255 < (seg->start_addr >> 20))
256 continue;
257 return 1;
258 }
259 return 0;
260}
261
262/*
263 * check if segment collides with other segments that are currently loaded
264 * returns 1 if this is the case, 0 if no collision was found
265 */
266static int
267segment_overlaps_others (struct dcss_segment *seg)
268{
269 struct list_head *l;
270 struct dcss_segment *tmp;
271
272 BUG_ON(!mutex_is_locked(&dcss_lock));
273 list_for_each(l, &dcss_list) {
274 tmp = list_entry(l, struct dcss_segment, list);
275 if ((tmp->start_addr >> 20) > (seg->end >> 20))
276 continue;
277 if ((tmp->end >> 20) < (seg->start_addr >> 20))
278 continue;
279 if (seg == tmp)
280 continue;
281 return 1;
282 }
283 return 0;
284}
285
286/*
287 * check if segment exceeds the kernel mapping range (detected or set via mem=)
288 * returns 1 if this is the case, 0 if segment fits into the range
289 */
290static inline int
291segment_exceeds_range (struct dcss_segment *seg)
292{
293 int seg_last_pfn = (seg->end) >> PAGE_SHIFT;
294 if (seg_last_pfn > max_pfn)
295 return 1;
296 return 0;
297}
298
299/*
300 * get info about a segment 242 * get info about a segment
301 * possible return values: 243 * possible return values:
302 * -ENOSYS : we are not running on VM 244 * -ENOSYS : we are not running on VM
@@ -341,24 +283,26 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
341 rc = query_segment_type (seg); 283 rc = query_segment_type (seg);
342 if (rc < 0) 284 if (rc < 0)
343 goto out_free; 285 goto out_free;
344 if (segment_exceeds_range(seg)) { 286
345 PRINT_WARN ("segment_load: not loading segment %s - exceeds" 287 rc = add_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1);
346 " kernel mapping range\n",name); 288
347 rc = -ERANGE; 289 switch (rc) {
290 case 0:
291 break;
292 case -ENOSPC:
293 PRINT_WARN("segment_load: not loading segment %s - overlaps "
294 "storage/segment\n", name);
348 goto out_free; 295 goto out_free;
349 } 296 case -ERANGE:
350 if (segment_overlaps_storage(seg)) { 297 PRINT_WARN("segment_load: not loading segment %s - exceeds "
351 PRINT_WARN ("segment_load: not loading segment %s - overlaps" 298 "kernel mapping range\n", name);
352 " storage\n",name);
353 rc = -ENOSPC;
354 goto out_free; 299 goto out_free;
355 } 300 default:
356 if (segment_overlaps_others(seg)) { 301 PRINT_WARN("segment_load: not loading segment %s (rc: %d)\n",
357 PRINT_WARN ("segment_load: not loading segment %s - overlaps" 302 name, rc);
358 " other segments\n",name);
359 rc = -EBUSY;
360 goto out_free; 303 goto out_free;
361 } 304 }
305
362 if (do_nonshared) 306 if (do_nonshared)
363 dcss_command = DCSS_LOADNSR; 307 dcss_command = DCSS_LOADNSR;
364 else 308 else
@@ -372,7 +316,7 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
372 rc = dcss_diag_translate_rc (seg->end); 316 rc = dcss_diag_translate_rc (seg->end);
373 dcss_diag(DCSS_PURGESEG, seg->dcss_name, 317 dcss_diag(DCSS_PURGESEG, seg->dcss_name,
374 &seg->start_addr, &seg->end); 318 &seg->start_addr, &seg->end);
375 goto out_free; 319 goto out_shared;
376 } 320 }
377 seg->do_nonshared = do_nonshared; 321 seg->do_nonshared = do_nonshared;
378 atomic_set(&seg->ref_count, 1); 322 atomic_set(&seg->ref_count, 1);
@@ -391,6 +335,8 @@ __segment_load (char *name, int do_nonshared, unsigned long *addr, unsigned long
391 (void*)seg->start_addr, (void*)seg->end, 335 (void*)seg->start_addr, (void*)seg->end,
392 segtype_string[seg->vm_segtype]); 336 segtype_string[seg->vm_segtype]);
393 goto out; 337 goto out;
338 out_shared:
339 remove_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1);
394 out_free: 340 out_free:
395 kfree(seg); 341 kfree(seg);
396 out: 342 out:
@@ -530,12 +476,12 @@ segment_unload(char *name)
530 "please report to linux390@de.ibm.com\n",name); 476 "please report to linux390@de.ibm.com\n",name);
531 goto out_unlock; 477 goto out_unlock;
532 } 478 }
533 if (atomic_dec_return(&seg->ref_count) == 0) { 479 if (atomic_dec_return(&seg->ref_count) != 0)
534 list_del(&seg->list); 480 goto out_unlock;
535 dcss_diag(DCSS_PURGESEG, seg->dcss_name, 481 remove_shared_memory(seg->start_addr, seg->end - seg->start_addr + 1);
536 &dummy, &dummy); 482 list_del(&seg->list);
537 kfree(seg); 483 dcss_diag(DCSS_PURGESEG, seg->dcss_name, &dummy, &dummy);
538 } 484 kfree(seg);
539out_unlock: 485out_unlock:
540 mutex_unlock(&dcss_lock); 486 mutex_unlock(&dcss_lock);
541} 487}
diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c
index e1881c31b1cb..4bb21be3b007 100644
--- a/arch/s390/mm/init.c
+++ b/arch/s390/mm/init.c
@@ -24,6 +24,7 @@
24#include <linux/pagemap.h> 24#include <linux/pagemap.h>
25#include <linux/bootmem.h> 25#include <linux/bootmem.h>
26#include <linux/pfn.h> 26#include <linux/pfn.h>
27#include <linux/poison.h>
27 28
28#include <asm/processor.h> 29#include <asm/processor.h>
29#include <asm/system.h> 30#include <asm/system.h>
@@ -69,6 +70,8 @@ void show_mem(void)
69 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); 70 printk("Free swap: %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
70 i = max_mapnr; 71 i = max_mapnr;
71 while (i-- > 0) { 72 while (i-- > 0) {
73 if (!pfn_valid(i))
74 continue;
72 page = pfn_to_page(i); 75 page = pfn_to_page(i);
73 total++; 76 total++;
74 if (PageReserved(page)) 77 if (PageReserved(page))
@@ -84,150 +87,52 @@ void show_mem(void)
84 printk("%d pages swap cached\n",cached); 87 printk("%d pages swap cached\n",cached);
85} 88}
86 89
87extern unsigned long __initdata zholes_size[]; 90static void __init setup_ro_region(void)
88/*
89 * paging_init() sets up the page tables
90 */
91
92#ifndef CONFIG_64BIT
93void __init paging_init(void)
94{ 91{
95 pgd_t * pg_dir; 92 pgd_t *pgd;
96 pte_t * pg_table; 93 pmd_t *pmd;
97 pte_t pte; 94 pte_t *pte;
98 int i; 95 pte_t new_pte;
99 unsigned long tmp; 96 unsigned long address, end;
100 unsigned long pfn = 0; 97
101 unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE; 98 address = ((unsigned long)&__start_rodata) & PAGE_MASK;
102 static const int ssm_mask = 0x04000000L; 99 end = PFN_ALIGN((unsigned long)&__end_rodata);
103 unsigned long ro_start_pfn, ro_end_pfn; 100
104 unsigned long zones_size[MAX_NR_ZONES]; 101 for (; address < end; address += PAGE_SIZE) {
105 102 pgd = pgd_offset_k(address);
106 ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata); 103 pmd = pmd_offset(pgd, address);
107 ro_end_pfn = PFN_UP((unsigned long)&__end_rodata); 104 pte = pte_offset_kernel(pmd, address);
108 105 new_pte = mk_pte_phys(address, __pgprot(_PAGE_RO));
109 memset(zones_size, 0, sizeof(zones_size)); 106 set_pte(pte, new_pte);
110 zones_size[ZONE_DMA] = max_low_pfn; 107 }
111 free_area_init_node(0, &contig_page_data, zones_size,
112 __pa(PAGE_OFFSET) >> PAGE_SHIFT,
113 zholes_size);
114
115 /* unmap whole virtual address space */
116
117 pg_dir = swapper_pg_dir;
118
119 for (i = 0; i < PTRS_PER_PGD; i++)
120 pmd_clear((pmd_t *) pg_dir++);
121
122 /*
123 * map whole physical memory to virtual memory (identity mapping)
124 */
125
126 pg_dir = swapper_pg_dir;
127
128 while (pfn < max_low_pfn) {
129 /*
130 * pg_table is physical at this point
131 */
132 pg_table = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
133
134 pmd_populate_kernel(&init_mm, (pmd_t *) pg_dir, pg_table);
135 pg_dir++;
136
137 for (tmp = 0 ; tmp < PTRS_PER_PTE ; tmp++,pg_table++) {
138 if (pfn >= ro_start_pfn && pfn < ro_end_pfn)
139 pte = pfn_pte(pfn, __pgprot(_PAGE_RO));
140 else
141 pte = pfn_pte(pfn, PAGE_KERNEL);
142 if (pfn >= max_low_pfn)
143 pte_val(pte) = _PAGE_TYPE_EMPTY;
144 set_pte(pg_table, pte);
145 pfn++;
146 }
147 }
148
149 S390_lowcore.kernel_asce = pgdir_k;
150
151 /* enable virtual mapping in kernel mode */
152 __ctl_load(pgdir_k, 1, 1);
153 __ctl_load(pgdir_k, 7, 7);
154 __ctl_load(pgdir_k, 13, 13);
155 __raw_local_irq_ssm(ssm_mask);
156
157 local_flush_tlb();
158} 108}
159 109
160#else /* CONFIG_64BIT */ 110extern void vmem_map_init(void);
161 111
112/*
113 * paging_init() sets up the page tables
114 */
162void __init paging_init(void) 115void __init paging_init(void)
163{ 116{
164 pgd_t * pg_dir; 117 pgd_t *pg_dir;
165 pmd_t * pm_dir; 118 int i;
166 pte_t * pt_dir; 119 unsigned long pgdir_k;
167 pte_t pte;
168 int i,j,k;
169 unsigned long pfn = 0;
170 unsigned long pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) |
171 _KERN_REGION_TABLE;
172 static const int ssm_mask = 0x04000000L; 120 static const int ssm_mask = 0x04000000L;
173 unsigned long zones_size[MAX_NR_ZONES]; 121 unsigned long max_zone_pfns[MAX_NR_ZONES];
174 unsigned long dma_pfn, high_pfn;
175 unsigned long ro_start_pfn, ro_end_pfn;
176
177 memset(zones_size, 0, sizeof(zones_size));
178 dma_pfn = MAX_DMA_ADDRESS >> PAGE_SHIFT;
179 high_pfn = max_low_pfn;
180 ro_start_pfn = PFN_DOWN((unsigned long)&__start_rodata);
181 ro_end_pfn = PFN_UP((unsigned long)&__end_rodata);
182
183 if (dma_pfn > high_pfn)
184 zones_size[ZONE_DMA] = high_pfn;
185 else {
186 zones_size[ZONE_DMA] = dma_pfn;
187 zones_size[ZONE_NORMAL] = high_pfn - dma_pfn;
188 }
189
190 /* Initialize mem_map[]. */
191 free_area_init_node(0, &contig_page_data, zones_size,
192 __pa(PAGE_OFFSET) >> PAGE_SHIFT, zholes_size);
193 122
194 /* 123 pg_dir = swapper_pg_dir;
195 * map whole physical memory to virtual memory (identity mapping)
196 */
197
198 pg_dir = swapper_pg_dir;
199
200 for (i = 0 ; i < PTRS_PER_PGD ; i++,pg_dir++) {
201 124
202 if (pfn >= max_low_pfn) { 125#ifdef CONFIG_64BIT
203 pgd_clear(pg_dir); 126 pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERN_REGION_TABLE;
204 continue; 127 for (i = 0; i < PTRS_PER_PGD; i++)
205 } 128 pgd_clear(pg_dir + i);
206 129#else
207 pm_dir = (pmd_t *) alloc_bootmem_pages(PAGE_SIZE * 4); 130 pgdir_k = (__pa(swapper_pg_dir) & PAGE_MASK) | _KERNSEG_TABLE;
208 pgd_populate(&init_mm, pg_dir, pm_dir); 131 for (i = 0; i < PTRS_PER_PGD; i++)
209 132 pmd_clear((pmd_t *)(pg_dir + i));
210 for (j = 0 ; j < PTRS_PER_PMD ; j++,pm_dir++) { 133#endif
211 if (pfn >= max_low_pfn) { 134 vmem_map_init();
212 pmd_clear(pm_dir); 135 setup_ro_region();
213 continue;
214 }
215
216 pt_dir = (pte_t *) alloc_bootmem_pages(PAGE_SIZE);
217 pmd_populate_kernel(&init_mm, pm_dir, pt_dir);
218
219 for (k = 0 ; k < PTRS_PER_PTE ; k++,pt_dir++) {
220 if (pfn >= ro_start_pfn && pfn < ro_end_pfn)
221 pte = pfn_pte(pfn, __pgprot(_PAGE_RO));
222 else
223 pte = pfn_pte(pfn, PAGE_KERNEL);
224 if (pfn >= max_low_pfn)
225 pte_val(pte) = _PAGE_TYPE_EMPTY;
226 set_pte(pt_dir, pte);
227 pfn++;
228 }
229 }
230 }
231 136
232 S390_lowcore.kernel_asce = pgdir_k; 137 S390_lowcore.kernel_asce = pgdir_k;
233 138
@@ -237,9 +142,11 @@ void __init paging_init(void)
237 __ctl_load(pgdir_k, 13, 13); 142 __ctl_load(pgdir_k, 13, 13);
238 __raw_local_irq_ssm(ssm_mask); 143 __raw_local_irq_ssm(ssm_mask);
239 144
240 local_flush_tlb(); 145 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
146 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
147 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
148 free_area_init_nodes(max_zone_pfns);
241} 149}
242#endif /* CONFIG_64BIT */
243 150
244void __init mem_init(void) 151void __init mem_init(void)
245{ 152{
@@ -269,6 +176,8 @@ void __init mem_init(void)
269 printk("Write protected kernel read-only data: %#lx - %#lx\n", 176 printk("Write protected kernel read-only data: %#lx - %#lx\n",
270 (unsigned long)&__start_rodata, 177 (unsigned long)&__start_rodata,
271 PFN_ALIGN((unsigned long)&__end_rodata) - 1); 178 PFN_ALIGN((unsigned long)&__end_rodata) - 1);
179 printk("Virtual memmap size: %ldk\n",
180 (max_pfn * sizeof(struct page)) >> 10);
272} 181}
273 182
274void free_initmem(void) 183void free_initmem(void)
@@ -279,6 +188,7 @@ void free_initmem(void)
279 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) { 188 for (; addr < (unsigned long)(&__init_end); addr += PAGE_SIZE) {
280 ClearPageReserved(virt_to_page(addr)); 189 ClearPageReserved(virt_to_page(addr));
281 init_page_count(virt_to_page(addr)); 190 init_page_count(virt_to_page(addr));
191 memset((void *)addr, POISON_FREE_INITMEM, PAGE_SIZE);
282 free_page(addr); 192 free_page(addr);
283 totalram_pages++; 193 totalram_pages++;
284 } 194 }
diff --git a/arch/s390/mm/ioremap.c b/arch/s390/mm/ioremap.c
index 0f6e9ecbefe2..3d2100a4e209 100644
--- a/arch/s390/mm/ioremap.c
+++ b/arch/s390/mm/ioremap.c
@@ -15,87 +15,8 @@
15 15
16#include <linux/vmalloc.h> 16#include <linux/vmalloc.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <asm/io.h> 18#include <linux/io.h>
19#include <asm/pgalloc.h> 19#include <asm/pgalloc.h>
20#include <asm/cacheflush.h>
21#include <asm/tlbflush.h>
22
23static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
24 unsigned long phys_addr, unsigned long flags)
25{
26 unsigned long end;
27 unsigned long pfn;
28
29 address &= ~PMD_MASK;
30 end = address + size;
31 if (end > PMD_SIZE)
32 end = PMD_SIZE;
33 if (address >= end)
34 BUG();
35 pfn = phys_addr >> PAGE_SHIFT;
36 do {
37 if (!pte_none(*pte)) {
38 printk("remap_area_pte: page already exists\n");
39 BUG();
40 }
41 set_pte(pte, pfn_pte(pfn, __pgprot(flags)));
42 address += PAGE_SIZE;
43 pfn++;
44 pte++;
45 } while (address && (address < end));
46}
47
48static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
49 unsigned long phys_addr, unsigned long flags)
50{
51 unsigned long end;
52
53 address &= ~PGDIR_MASK;
54 end = address + size;
55 if (end > PGDIR_SIZE)
56 end = PGDIR_SIZE;
57 phys_addr -= address;
58 if (address >= end)
59 BUG();
60 do {
61 pte_t * pte = pte_alloc_kernel(pmd, address);
62 if (!pte)
63 return -ENOMEM;
64 remap_area_pte(pte, address, end - address, address + phys_addr, flags);
65 address = (address + PMD_SIZE) & PMD_MASK;
66 pmd++;
67 } while (address && (address < end));
68 return 0;
69}
70
71static int remap_area_pages(unsigned long address, unsigned long phys_addr,
72 unsigned long size, unsigned long flags)
73{
74 int error;
75 pgd_t * dir;
76 unsigned long end = address + size;
77
78 phys_addr -= address;
79 dir = pgd_offset(&init_mm, address);
80 flush_cache_all();
81 if (address >= end)
82 BUG();
83 do {
84 pmd_t *pmd;
85 pmd = pmd_alloc(&init_mm, dir, address);
86 error = -ENOMEM;
87 if (!pmd)
88 break;
89 if (remap_area_pmd(pmd, address, end - address,
90 phys_addr + address, flags))
91 break;
92 error = 0;
93 address = (address + PGDIR_SIZE) & PGDIR_MASK;
94 dir++;
95 } while (address && (address < end));
96 flush_tlb_all();
97 return 0;
98}
99 20
100/* 21/*
101 * Generic mapping function (not visible outside): 22 * Generic mapping function (not visible outside):
@@ -122,7 +43,8 @@ void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flag
122 if (!area) 43 if (!area)
123 return NULL; 44 return NULL;
124 addr = area->addr; 45 addr = area->addr;
125 if (remap_area_pages((unsigned long) addr, phys_addr, size, flags)) { 46 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
47 phys_addr, __pgprot(flags))) {
126 vfree(addr); 48 vfree(addr);
127 return NULL; 49 return NULL;
128 } 50 }
diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c
new file mode 100644
index 000000000000..7f2944d3ec2a
--- /dev/null
+++ b/arch/s390/mm/vmem.c
@@ -0,0 +1,381 @@
1/*
2 * arch/s390/mm/vmem.c
3 *
4 * Copyright IBM Corp. 2006
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
6 */
7
8#include <linux/bootmem.h>
9#include <linux/pfn.h>
10#include <linux/mm.h>
11#include <linux/module.h>
12#include <linux/list.h>
13#include <asm/pgalloc.h>
14#include <asm/pgtable.h>
15#include <asm/setup.h>
16#include <asm/tlbflush.h>
17
18unsigned long vmalloc_end;
19EXPORT_SYMBOL(vmalloc_end);
20
21static struct page *vmem_map;
22static DEFINE_MUTEX(vmem_mutex);
23
24struct memory_segment {
25 struct list_head list;
26 unsigned long start;
27 unsigned long size;
28};
29
30static LIST_HEAD(mem_segs);
31
32void memmap_init(unsigned long size, int nid, unsigned long zone,
33 unsigned long start_pfn)
34{
35 struct page *start, *end;
36 struct page *map_start, *map_end;
37 int i;
38
39 start = pfn_to_page(start_pfn);
40 end = start + size;
41
42 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
43 unsigned long cstart, cend;
44
45 cstart = PFN_DOWN(memory_chunk[i].addr);
46 cend = cstart + PFN_DOWN(memory_chunk[i].size);
47
48 map_start = mem_map + cstart;
49 map_end = mem_map + cend;
50
51 if (map_start < start)
52 map_start = start;
53 if (map_end > end)
54 map_end = end;
55
56 map_start -= ((unsigned long) map_start & (PAGE_SIZE - 1))
57 / sizeof(struct page);
58 map_end += ((PFN_ALIGN((unsigned long) map_end)
59 - (unsigned long) map_end)
60 / sizeof(struct page));
61
62 if (map_start < map_end)
63 memmap_init_zone((unsigned long)(map_end - map_start),
64 nid, zone, page_to_pfn(map_start));
65 }
66}
67
68static inline void *vmem_alloc_pages(unsigned int order)
69{
70 if (slab_is_available())
71 return (void *)__get_free_pages(GFP_KERNEL, order);
72 return alloc_bootmem_pages((1 << order) * PAGE_SIZE);
73}
74
75static inline pmd_t *vmem_pmd_alloc(void)
76{
77 pmd_t *pmd;
78 int i;
79
80 pmd = vmem_alloc_pages(PMD_ALLOC_ORDER);
81 if (!pmd)
82 return NULL;
83 for (i = 0; i < PTRS_PER_PMD; i++)
84 pmd_clear(pmd + i);
85 return pmd;
86}
87
88static inline pte_t *vmem_pte_alloc(void)
89{
90 pte_t *pte;
91 pte_t empty_pte;
92 int i;
93
94 pte = vmem_alloc_pages(PTE_ALLOC_ORDER);
95 if (!pte)
96 return NULL;
97 pte_val(empty_pte) = _PAGE_TYPE_EMPTY;
98 for (i = 0; i < PTRS_PER_PTE; i++)
99 set_pte(pte + i, empty_pte);
100 return pte;
101}
102
103/*
104 * Add a physical memory range to the 1:1 mapping.
105 */
106static int vmem_add_range(unsigned long start, unsigned long size)
107{
108 unsigned long address;
109 pgd_t *pg_dir;
110 pmd_t *pm_dir;
111 pte_t *pt_dir;
112 pte_t pte;
113 int ret = -ENOMEM;
114
115 for (address = start; address < start + size; address += PAGE_SIZE) {
116 pg_dir = pgd_offset_k(address);
117 if (pgd_none(*pg_dir)) {
118 pm_dir = vmem_pmd_alloc();
119 if (!pm_dir)
120 goto out;
121 pgd_populate(&init_mm, pg_dir, pm_dir);
122 }
123
124 pm_dir = pmd_offset(pg_dir, address);
125 if (pmd_none(*pm_dir)) {
126 pt_dir = vmem_pte_alloc();
127 if (!pt_dir)
128 goto out;
129 pmd_populate_kernel(&init_mm, pm_dir, pt_dir);
130 }
131
132 pt_dir = pte_offset_kernel(pm_dir, address);
133 pte = pfn_pte(address >> PAGE_SHIFT, PAGE_KERNEL);
134 set_pte(pt_dir, pte);
135 }
136 ret = 0;
137out:
138 flush_tlb_kernel_range(start, start + size);
139 return ret;
140}
141
142/*
143 * Remove a physical memory range from the 1:1 mapping.
144 * Currently only invalidates page table entries.
145 */
146static void vmem_remove_range(unsigned long start, unsigned long size)
147{
148 unsigned long address;
149 pgd_t *pg_dir;
150 pmd_t *pm_dir;
151 pte_t *pt_dir;
152 pte_t pte;
153
154 pte_val(pte) = _PAGE_TYPE_EMPTY;
155 for (address = start; address < start + size; address += PAGE_SIZE) {
156 pg_dir = pgd_offset_k(address);
157 if (pgd_none(*pg_dir))
158 continue;
159 pm_dir = pmd_offset(pg_dir, address);
160 if (pmd_none(*pm_dir))
161 continue;
162 pt_dir = pte_offset_kernel(pm_dir, address);
163 set_pte(pt_dir, pte);
164 }
165 flush_tlb_kernel_range(start, start + size);
166}
167
168/*
169 * Add a backed mem_map array to the virtual mem_map array.
170 */
171static int vmem_add_mem_map(unsigned long start, unsigned long size)
172{
173 unsigned long address, start_addr, end_addr;
174 struct page *map_start, *map_end;
175 pgd_t *pg_dir;
176 pmd_t *pm_dir;
177 pte_t *pt_dir;
178 pte_t pte;
179 int ret = -ENOMEM;
180
181 map_start = vmem_map + PFN_DOWN(start);
182 map_end = vmem_map + PFN_DOWN(start + size);
183
184 start_addr = (unsigned long) map_start & PAGE_MASK;
185 end_addr = PFN_ALIGN((unsigned long) map_end);
186
187 for (address = start_addr; address < end_addr; address += PAGE_SIZE) {
188 pg_dir = pgd_offset_k(address);
189 if (pgd_none(*pg_dir)) {
190 pm_dir = vmem_pmd_alloc();
191 if (!pm_dir)
192 goto out;
193 pgd_populate(&init_mm, pg_dir, pm_dir);
194 }
195
196 pm_dir = pmd_offset(pg_dir, address);
197 if (pmd_none(*pm_dir)) {
198 pt_dir = vmem_pte_alloc();
199 if (!pt_dir)
200 goto out;
201 pmd_populate_kernel(&init_mm, pm_dir, pt_dir);
202 }
203
204 pt_dir = pte_offset_kernel(pm_dir, address);
205 if (pte_none(*pt_dir)) {
206 unsigned long new_page;
207
208 new_page =__pa(vmem_alloc_pages(0));
209 if (!new_page)
210 goto out;
211 pte = pfn_pte(new_page >> PAGE_SHIFT, PAGE_KERNEL);
212 set_pte(pt_dir, pte);
213 }
214 }
215 ret = 0;
216out:
217 flush_tlb_kernel_range(start_addr, end_addr);
218 return ret;
219}
220
221static int vmem_add_mem(unsigned long start, unsigned long size)
222{
223 int ret;
224
225 ret = vmem_add_range(start, size);
226 if (ret)
227 return ret;
228 return vmem_add_mem_map(start, size);
229}
230
231/*
232 * Add memory segment to the segment list if it doesn't overlap with
233 * an already present segment.
234 */
235static int insert_memory_segment(struct memory_segment *seg)
236{
237 struct memory_segment *tmp;
238
239 if (PFN_DOWN(seg->start + seg->size) > max_pfn ||
240 seg->start + seg->size < seg->start)
241 return -ERANGE;
242
243 list_for_each_entry(tmp, &mem_segs, list) {
244 if (seg->start >= tmp->start + tmp->size)
245 continue;
246 if (seg->start + seg->size <= tmp->start)
247 continue;
248 return -ENOSPC;
249 }
250 list_add(&seg->list, &mem_segs);
251 return 0;
252}
253
254/*
255 * Remove memory segment from the segment list.
256 */
257static void remove_memory_segment(struct memory_segment *seg)
258{
259 list_del(&seg->list);
260}
261
262static void __remove_shared_memory(struct memory_segment *seg)
263{
264 remove_memory_segment(seg);
265 vmem_remove_range(seg->start, seg->size);
266}
267
268int remove_shared_memory(unsigned long start, unsigned long size)
269{
270 struct memory_segment *seg;
271 int ret;
272
273 mutex_lock(&vmem_mutex);
274
275 ret = -ENOENT;
276 list_for_each_entry(seg, &mem_segs, list) {
277 if (seg->start == start && seg->size == size)
278 break;
279 }
280
281 if (seg->start != start || seg->size != size)
282 goto out;
283
284 ret = 0;
285 __remove_shared_memory(seg);
286 kfree(seg);
287out:
288 mutex_unlock(&vmem_mutex);
289 return ret;
290}
291
292int add_shared_memory(unsigned long start, unsigned long size)
293{
294 struct memory_segment *seg;
295 struct page *page;
296 unsigned long pfn, num_pfn, end_pfn;
297 int ret;
298
299 mutex_lock(&vmem_mutex);
300 ret = -ENOMEM;
301 seg = kzalloc(sizeof(*seg), GFP_KERNEL);
302 if (!seg)
303 goto out;
304 seg->start = start;
305 seg->size = size;
306
307 ret = insert_memory_segment(seg);
308 if (ret)
309 goto out_free;
310
311 ret = vmem_add_mem(start, size);
312 if (ret)
313 goto out_remove;
314
315 pfn = PFN_DOWN(start);
316 num_pfn = PFN_DOWN(size);
317 end_pfn = pfn + num_pfn;
318
319 page = pfn_to_page(pfn);
320 memset(page, 0, num_pfn * sizeof(struct page));
321
322 for (; pfn < end_pfn; pfn++) {
323 page = pfn_to_page(pfn);
324 init_page_count(page);
325 reset_page_mapcount(page);
326 SetPageReserved(page);
327 INIT_LIST_HEAD(&page->lru);
328 }
329 goto out;
330
331out_remove:
332 __remove_shared_memory(seg);
333out_free:
334 kfree(seg);
335out:
336 mutex_unlock(&vmem_mutex);
337 return ret;
338}
339
340/*
341 * map whole physical memory to virtual memory (identity mapping)
342 */
343void __init vmem_map_init(void)
344{
345 unsigned long map_size;
346 int i;
347
348 map_size = ALIGN(max_low_pfn, MAX_ORDER_NR_PAGES) * sizeof(struct page);
349 vmalloc_end = PFN_ALIGN(VMALLOC_END_INIT) - PFN_ALIGN(map_size);
350 vmem_map = (struct page *) vmalloc_end;
351 NODE_DATA(0)->node_mem_map = vmem_map;
352
353 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++)
354 vmem_add_mem(memory_chunk[i].addr, memory_chunk[i].size);
355}
356
357/*
358 * Convert memory chunk array to a memory segment list so there is a single
359 * list that contains both r/w memory and shared memory segments.
360 */
361static int __init vmem_convert_memory_chunk(void)
362{
363 struct memory_segment *seg;
364 int i;
365
366 mutex_lock(&vmem_mutex);
367 for (i = 0; i < MEMORY_CHUNKS && memory_chunk[i].size > 0; i++) {
368 if (!memory_chunk[i].size)
369 continue;
370 seg = kzalloc(sizeof(*seg), GFP_KERNEL);
371 if (!seg)
372 panic("Out of memory...\n");
373 seg->start = memory_chunk[i].addr;
374 seg->size = memory_chunk[i].size;
375 insert_memory_segment(seg);
376 }
377 mutex_unlock(&vmem_mutex);
378 return 0;
379}
380
381core_initcall(vmem_convert_memory_chunk);
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index d83d64af31f2..3aa3b885ab36 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -59,6 +59,14 @@ config LOCKDEP_SUPPORT
59 bool 59 bool
60 default y 60 default y
61 61
62config ARCH_HAS_ILOG2_U32
63 bool
64 default n
65
66config ARCH_HAS_ILOG2_U64
67 bool
68 default n
69
62source "init/Kconfig" 70source "init/Kconfig"
63 71
64menu "System type" 72menu "System type"
@@ -471,7 +479,7 @@ config SH_CLK_MD
471 int "CPU Mode Pin Setting" 479 int "CPU Mode Pin Setting"
472 depends on CPU_SUBTYPE_SH7619 || CPU_SUBTYPE_SH7206 480 depends on CPU_SUBTYPE_SH7619 || CPU_SUBTYPE_SH7206
473 help 481 help
474 MD2 - MD0 Setting. 482 MD2 - MD0 pin setting.
475 483
476menu "CPU Frequency scaling" 484menu "CPU Frequency scaling"
477 485
@@ -572,18 +580,6 @@ config NR_CPUS
572 580
573source "kernel/Kconfig.preempt" 581source "kernel/Kconfig.preempt"
574 582
575config CPU_HAS_SR_RB
576 bool "CPU has SR.RB"
577 depends on CPU_SH3 || CPU_SH4
578 default y
579 help
580 This will enable the use of SR.RB register bank usage. Processors
581 that are lacking this bit must have another method in place for
582 accomplishing what is taken care of by the banked registers.
583
584 See <file:Documentation/sh/register-banks.txt> for further
585 information on SR.RB and register banking in the kernel in general.
586
587config NODES_SHIFT 583config NODES_SHIFT
588 int 584 int
589 default "1" 585 default "1"
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug
index 66a25ef4ef1b..87902e0298e2 100644
--- a/arch/sh/Kconfig.debug
+++ b/arch/sh/Kconfig.debug
@@ -31,7 +31,8 @@ config EARLY_SCIF_CONSOLE_PORT
31 hex "SCIF port for early console" 31 hex "SCIF port for early console"
32 depends on EARLY_SCIF_CONSOLE 32 depends on EARLY_SCIF_CONSOLE
33 default "0xffe00000" if CPU_SUBTYPE_SH7780 33 default "0xffe00000" if CPU_SUBTYPE_SH7780
34 default "0xfffe9800" if CPU_SUBTYPE_SH72060 34 default "0xfffe9800" if CPU_SUBTYPE_SH7206
35 default "0xf8420000" if CPU_SUBTYPE_SH7619
35 default "0xffe80000" if CPU_SH4 36 default "0xffe80000" if CPU_SH4
36 37
37config EARLY_PRINTK 38config EARLY_PRINTK
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index d10bba5e1074..c1dbef212634 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -179,7 +179,7 @@ maketools: include/linux/version.h FORCE
179 179
180all: zImage 180all: zImage
181 181
182zImage: vmlinux 182zImage uImage uImage.srec vmlinux.srec: vmlinux
183 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 183 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
184 184
185compressed: zImage 185compressed: zImage
@@ -190,5 +190,8 @@ archclean:
190CLEAN_FILES += include/asm-sh/machtypes.h 190CLEAN_FILES += include/asm-sh/machtypes.h
191 191
192define archhelp 192define archhelp
193 @echo ' zImage - Compressed kernel image (arch/sh/boot/zImage)' 193 @echo '* zImage - Compressed kernel image'
194 @echo ' vmlinux.srec - Create an ELF S-record'
195 @echo ' uImage - Create a bootable image for U-Boot'
196 @echo ' uImage.srec - Create an S-record for U-Boot'
194endef 197endef
diff --git a/arch/sh/boards/landisk/irq.c b/arch/sh/boards/landisk/irq.c
index 8f2e1c68b90f..3eba6d086d7f 100644
--- a/arch/sh/boards/landisk/irq.c
+++ b/arch/sh/boards/landisk/irq.c
@@ -16,8 +16,8 @@
16 */ 16 */
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/irq.h> 18#include <linux/irq.h>
19#include <asm/io.h> 19#include <linux/interrupt.h>
20#include <asm/irq.h> 20#include <linux/io.h>
21#include <asm/landisk/iodata_landisk.h> 21#include <asm/landisk/iodata_landisk.h>
22 22
23static void enable_landisk_irq(unsigned int irq); 23static void enable_landisk_irq(unsigned int irq);
diff --git a/arch/sh/boards/se/7206/irq.c b/arch/sh/boards/se/7206/irq.c
index 3fb0c5f5b23a..27da88486f73 100644
--- a/arch/sh/boards/se/7206/irq.c
+++ b/arch/sh/boards/se/7206/irq.c
@@ -10,6 +10,7 @@
10#include <linux/irq.h> 10#include <linux/irq.h>
11#include <linux/io.h> 11#include <linux/io.h>
12#include <linux/irq.h> 12#include <linux/irq.h>
13#include <linux/interrupt.h>
13#include <asm/se7206.h> 14#include <asm/se7206.h>
14 15
15#define INTSTS0 0x31800000 16#define INTSTS0 0x31800000
@@ -18,6 +19,13 @@
18#define INTMSK1 0x31800006 19#define INTMSK1 0x31800006
19#define INTSEL 0x31800008 20#define INTSEL 0x31800008
20 21
22#define IRQ0_IRQ 64
23#define IRQ1_IRQ 65
24#define IRQ3_IRQ 67
25
26#define INTC_IPR01 0xfffe0818
27#define INTC_ICR1 0xfffe0802
28
21static void disable_se7206_irq(unsigned int irq) 29static void disable_se7206_irq(unsigned int irq)
22{ 30{
23 unsigned short val; 31 unsigned short val;
@@ -39,7 +47,7 @@ static void disable_se7206_irq(unsigned int irq)
39 case IRQ1_IRQ: 47 case IRQ1_IRQ:
40 msk0 |= 0x000f; 48 msk0 |= 0x000f;
41 break; 49 break;
42 case IRQ2_IRQ: 50 case IRQ3_IRQ:
43 msk0 |= 0x0f00; 51 msk0 |= 0x0f00;
44 msk1 |= 0x00ff; 52 msk1 |= 0x00ff;
45 break; 53 break;
@@ -70,7 +78,7 @@ static void enable_se7206_irq(unsigned int irq)
70 case IRQ1_IRQ: 78 case IRQ1_IRQ:
71 msk0 &= ~0x000f; 79 msk0 &= ~0x000f;
72 break; 80 break;
73 case IRQ2_IRQ: 81 case IRQ3_IRQ:
74 msk0 &= ~0x0f00; 82 msk0 &= ~0x0f00;
75 msk1 &= ~0x00ff; 83 msk1 &= ~0x00ff;
76 break; 84 break;
@@ -96,7 +104,7 @@ static void eoi_se7206_irq(unsigned int irq)
96 case IRQ1_IRQ: 104 case IRQ1_IRQ:
97 sts0 &= ~0x000f; 105 sts0 &= ~0x000f;
98 break; 106 break;
99 case IRQ2_IRQ: 107 case IRQ3_IRQ:
100 sts0 &= ~0x0f00; 108 sts0 &= ~0x0f00;
101 sts1 &= ~0x00ff; 109 sts1 &= ~0x00ff;
102 break; 110 break;
@@ -106,7 +114,7 @@ static void eoi_se7206_irq(unsigned int irq)
106} 114}
107 115
108static struct irq_chip se7206_irq_chip __read_mostly = { 116static struct irq_chip se7206_irq_chip __read_mostly = {
109 .name = "SE7206-FPGA-IRQ", 117 .name = "SE7206-FPGA",
110 .mask = disable_se7206_irq, 118 .mask = disable_se7206_irq,
111 .unmask = enable_se7206_irq, 119 .unmask = enable_se7206_irq,
112 .mask_ack = disable_se7206_irq, 120 .mask_ack = disable_se7206_irq,
diff --git a/arch/sh/boards/se/7619/Makefile b/arch/sh/boards/se/7619/Makefile
index 3666eca8a658..d21775c28cda 100644
--- a/arch/sh/boards/se/7619/Makefile
+++ b/arch/sh/boards/se/7619/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the 7619 SolutionEngine specific parts of the kernel 2# Makefile for the 7619 SolutionEngine specific parts of the kernel
3# 3#
4 4
5obj-y := setup.o io.o 5obj-y := setup.o
diff --git a/arch/sh/boards/se/7619/io.c b/arch/sh/boards/se/7619/io.c
deleted file mode 100644
index 176f1f39cd9d..000000000000
--- a/arch/sh/boards/se/7619/io.c
+++ /dev/null
@@ -1,102 +0,0 @@
1/*
2 *
3 * linux/arch/sh/boards/se/7619/io.c
4 *
5 * Copyright (C) 2006 Yoshinori Sato
6 *
7 * I/O routine for Hitachi 7619 SolutionEngine.
8 *
9 */
10
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <asm/io.h>
14#include <asm/se7619.h>
15#include <asm/irq.h>
16
17/* FIXME: M3A-ZAB7 Compact Flash Slot support */
18
19static inline void delay(void)
20{
21 ctrl_inw(0xa0000000); /* Uncached ROM area (P2) */
22}
23
24#define badio(name,port) \
25 printk("bad I/O operation (%s) for port 0x%lx at 0x%08x\n", \
26 #name, (port), (__u32) __builtin_return_address(0))
27
28unsigned char se7619___inb(unsigned long port)
29{
30 badio(inb, port);
31 return 0;
32}
33
34unsigned char se7619___inb_p(unsigned long port)
35{
36 badio(inb_p, port);
37 delay();
38 return 0;
39}
40
41unsigned short se7619___inw(unsigned long port)
42{
43 badio(inw, port);
44 return 0;
45}
46
47unsigned int se7619___inl(unsigned long port)
48{
49 badio(inl, port);
50 return 0;
51}
52
53void se7619___outb(unsigned char value, unsigned long port)
54{
55 badio(outb, port);
56}
57
58void se7619___outb_p(unsigned char value, unsigned long port)
59{
60 badio(outb_p, port);
61 delay();
62}
63
64void se7619___outw(unsigned short value, unsigned long port)
65{
66 badio(outw, port);
67}
68
69void se7619___outl(unsigned int value, unsigned long port)
70{
71 badio(outl, port);
72}
73
74void se7619___insb(unsigned long port, void *addr, unsigned long count)
75{
76 badio(inw, port);
77}
78
79void se7619___insw(unsigned long port, void *addr, unsigned long count)
80{
81 badio(inw, port);
82}
83
84void se7619___insl(unsigned long port, void *addr, unsigned long count)
85{
86 badio(insl, port);
87}
88
89void se7619___outsb(unsigned long port, const void *addr, unsigned long count)
90{
91 badio(insl, port);
92}
93
94void se7619___outsw(unsigned long port, const void *addr, unsigned long count)
95{
96 badio(insl, port);
97}
98
99void se7619___outsl(unsigned long port, const void *addr, unsigned long count)
100{
101 badio(outsw, port);
102}
diff --git a/arch/sh/boards/se/7619/setup.c b/arch/sh/boards/se/7619/setup.c
index e627b26de0d0..52d2c4d5d2fa 100644
--- a/arch/sh/boards/se/7619/setup.c
+++ b/arch/sh/boards/se/7619/setup.c
@@ -9,7 +9,6 @@
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11#include <asm/io.h> 11#include <asm/io.h>
12#include <asm/se7619.h>
13#include <asm/machvec.h> 12#include <asm/machvec.h>
14 13
15/* 14/*
@@ -19,25 +18,5 @@
19struct sh_machine_vector mv_se __initmv = { 18struct sh_machine_vector mv_se __initmv = {
20 .mv_name = "SolutionEngine", 19 .mv_name = "SolutionEngine",
21 .mv_nr_irqs = 108, 20 .mv_nr_irqs = 108,
22 .mv_inb = se7619___inb,
23 .mv_inw = se7619___inw,
24 .mv_inl = se7619___inl,
25 .mv_outb = se7619___outb,
26 .mv_outw = se7619___outw,
27 .mv_outl = se7619___outl,
28
29 .mv_inb_p = se7619___inb_p,
30 .mv_inw_p = se7619___inw,
31 .mv_inl_p = se7619___inl,
32 .mv_outb_p = se7619___outb_p,
33 .mv_outw_p = se7619___outw,
34 .mv_outl_p = se7619___outl,
35
36 .mv_insb = se7619___insb,
37 .mv_insw = se7619___insw,
38 .mv_insl = se7619___insl,
39 .mv_outsb = se7619___outsb,
40 .mv_outsw = se7619___outsw,
41 .mv_outsl = se7619___outsl,
42}; 21};
43ALIAS_MV(se) 22ALIAS_MV(se)
diff --git a/arch/sh/boot/Makefile b/arch/sh/boot/Makefile
index 60797b31089c..11dc272c618e 100644
--- a/arch/sh/boot/Makefile
+++ b/arch/sh/boot/Makefile
@@ -8,13 +8,49 @@
8# Copyright (C) 1999 Stuart Menefy 8# Copyright (C) 1999 Stuart Menefy
9# 9#
10 10
11targets := zImage 11MKIMAGE := $(srctree)/scripts/mkuboot.sh
12
13#
14# Assign safe dummy values if these variables are not defined,
15# in order to suppress error message.
16#
17CONFIG_PAGE_OFFSET ?= 0x80000000
18CONFIG_MEMORY_START ?= 0x0c000000
19CONFIG_BOOT_LINK_OFFSET ?= 0x00800000
20CONFIG_ZERO_PAGE_OFFSET ?= 0x00001000
21
22export CONFIG_PAGE_OFFSET CONFIG_MEMORY_START CONFIG_BOOT_LINK_OFFSET \
23 CONFIG_ZERO_PAGE_OFFSET
24
25targets := zImage vmlinux.srec uImage uImage.srec
12subdir- := compressed 26subdir- := compressed
13 27
14$(obj)/zImage: $(obj)/compressed/vmlinux FORCE 28$(obj)/zImage: $(obj)/compressed/vmlinux FORCE
15 $(call if_changed,objcopy) 29 $(call if_changed,objcopy)
16 @echo 'Kernel: $@ is ready' 30 @echo ' Kernel: $@ is ready'
17 31
18$(obj)/compressed/vmlinux: FORCE 32$(obj)/compressed/vmlinux: FORCE
19 $(Q)$(MAKE) $(build)=$(obj)/compressed $@ 33 $(Q)$(MAKE) $(build)=$(obj)/compressed $@
20 34
35KERNEL_LOAD := $(shell printf "0x%8x" $$[$(CONFIG_PAGE_OFFSET) + \
36 $(CONFIG_MEMORY_START) + \
37 $(CONFIG_ZERO_PAGE_OFFSET)+0x1000])
38
39quiet_cmd_uimage = UIMAGE $@
40 cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A sh -O linux -T kernel \
41 -C gzip -a $(KERNEL_LOAD) -e $(KERNEL_LOAD) \
42 -n 'Linux-$(KERNELRELEASE)' -d $< $@
43
44$(obj)/uImage: $(obj)/zImage FORCE
45 $(call if_changed,uimage)
46 @echo ' Image $@ is ready'
47
48OBJCOPYFLAGS_vmlinux.srec := -I binary -O srec
49$(obj)/vmlinux.srec: $(obj)/compressed/vmlinux
50 $(call if_changed,objcopy)
51
52OBJCOPYFLAGS_uImage.srec := -I binary -O srec
53$(obj)/uImage.srec: $(obj)/uImage
54 $(call if_changed,objcopy)
55
56clean-files += uImage uImage.srec vmlinux.srec
diff --git a/arch/sh/boot/compressed/Makefile b/arch/sh/boot/compressed/Makefile
index e5f443790079..d9512416f885 100644
--- a/arch/sh/boot/compressed/Makefile
+++ b/arch/sh/boot/compressed/Makefile
@@ -15,13 +15,7 @@ endif
15 15
16# 16#
17# IMAGE_OFFSET is the load offset of the compression loader 17# IMAGE_OFFSET is the load offset of the compression loader
18# Assign dummy values if these 2 variables are not defined,
19# in order to suppress error message.
20# 18#
21CONFIG_PAGE_OFFSET ?= 0x80000000
22CONFIG_MEMORY_START ?= 0x0c000000
23CONFIG_BOOT_LINK_OFFSET ?= 0x00800000
24
25IMAGE_OFFSET := $(shell printf "0x%08x" $$[$(CONFIG_PAGE_OFFSET) + \ 19IMAGE_OFFSET := $(shell printf "0x%08x" $$[$(CONFIG_PAGE_OFFSET) + \
26 $(CONFIG_MEMORY_START) + \ 20 $(CONFIG_MEMORY_START) + \
27 $(CONFIG_BOOT_LINK_OFFSET)]) 21 $(CONFIG_BOOT_LINK_OFFSET)])
diff --git a/arch/sh/boot/compressed/head.S b/arch/sh/boot/compressed/head.S
index 4c26a192277d..a8399b013729 100644
--- a/arch/sh/boot/compressed/head.S
+++ b/arch/sh/boot/compressed/head.S
@@ -8,6 +8,7 @@
8.text 8.text
9 9
10#include <linux/linkage.h> 10#include <linux/linkage.h>
11#include <asm/page.h>
11 12
12 .global startup 13 .global startup
13startup: 14startup:
@@ -97,7 +98,7 @@ init_stack_addr:
97decompress_kernel_addr: 98decompress_kernel_addr:
98 .long decompress_kernel 99 .long decompress_kernel
99kernel_start_addr: 100kernel_start_addr:
100 .long _text+0x1000 101 .long _text+PAGE_SIZE
101 102
102 .align 9 103 .align 9
103fake_headers_as_bzImage: 104fake_headers_as_bzImage:
diff --git a/arch/sh/boot/compressed/misc.c b/arch/sh/boot/compressed/misc.c
index 35452d85b7f7..df65e305acf7 100644
--- a/arch/sh/boot/compressed/misc.c
+++ b/arch/sh/boot/compressed/misc.c
@@ -13,6 +13,7 @@
13 13
14#include <asm/uaccess.h> 14#include <asm/uaccess.h>
15#include <asm/addrspace.h> 15#include <asm/addrspace.h>
16#include <asm/page.h>
16#ifdef CONFIG_SH_STANDARD_BIOS 17#ifdef CONFIG_SH_STANDARD_BIOS
17#include <asm/sh_bios.h> 18#include <asm/sh_bios.h>
18#endif 19#endif
@@ -229,7 +230,7 @@ long* stack_start = &user_stack[STACK_SIZE];
229void decompress_kernel(void) 230void decompress_kernel(void)
230{ 231{
231 output_data = 0; 232 output_data = 0;
232 output_ptr = P2SEGADDR((unsigned long)&_text+0x1000); 233 output_ptr = P2SEGADDR((unsigned long)&_text+PAGE_SIZE);
233 free_mem_ptr = (unsigned long)&_end; 234 free_mem_ptr = (unsigned long)&_end;
234 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE; 235 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
235 236
diff --git a/arch/sh/configs/landisk_defconfig b/arch/sh/configs/landisk_defconfig
index 238c0f109907..e7f8ddb0ada4 100644
--- a/arch/sh/configs/landisk_defconfig
+++ b/arch/sh/configs/landisk_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.18 3# Linux kernel version: 2.6.19
4# Tue Oct 3 11:14:13 2006 4# Thu Dec 7 17:13:04 2006
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_RWSEM_GENERIC_SPINLOCK=y 7CONFIG_RWSEM_GENERIC_SPINLOCK=y
@@ -10,6 +10,9 @@ CONFIG_GENERIC_HWEIGHT=y
10CONFIG_GENERIC_HARDIRQS=y 10CONFIG_GENERIC_HARDIRQS=y
11CONFIG_GENERIC_IRQ_PROBE=y 11CONFIG_GENERIC_IRQ_PROBE=y
12CONFIG_GENERIC_CALIBRATE_DELAY=y 12CONFIG_GENERIC_CALIBRATE_DELAY=y
13# CONFIG_GENERIC_TIME is not set
14CONFIG_STACKTRACE_SUPPORT=y
15CONFIG_LOCKDEP_SUPPORT=y
13CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 16CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
14 17
15# 18#
@@ -33,6 +36,7 @@ CONFIG_SYSVIPC=y
33# CONFIG_UTS_NS is not set 36# CONFIG_UTS_NS is not set
34# CONFIG_AUDIT is not set 37# CONFIG_AUDIT is not set
35# CONFIG_IKCONFIG is not set 38# CONFIG_IKCONFIG is not set
39CONFIG_SYSFS_DEPRECATED=y
36# CONFIG_RELAY is not set 40# CONFIG_RELAY is not set
37CONFIG_INITRAMFS_SOURCE="" 41CONFIG_INITRAMFS_SOURCE=""
38CONFIG_CC_OPTIMIZE_FOR_SIZE=y 42CONFIG_CC_OPTIMIZE_FOR_SIZE=y
@@ -114,6 +118,8 @@ CONFIG_DEFAULT_IOSCHED="anticipatory"
114CONFIG_SH_LANDISK=y 118CONFIG_SH_LANDISK=y
115# CONFIG_SH_TITAN is not set 119# CONFIG_SH_TITAN is not set
116# CONFIG_SH_SHMIN is not set 120# CONFIG_SH_SHMIN is not set
121# CONFIG_SH_7206_SOLUTION_ENGINE is not set
122# CONFIG_SH_7619_SOLUTION_ENGINE is not set
117# CONFIG_SH_UNKNOWN is not set 123# CONFIG_SH_UNKNOWN is not set
118 124
119# 125#
@@ -125,6 +131,12 @@ CONFIG_CPU_SH4=y
125# SH-2 Processor Support 131# SH-2 Processor Support
126# 132#
127# CONFIG_CPU_SUBTYPE_SH7604 is not set 133# CONFIG_CPU_SUBTYPE_SH7604 is not set
134# CONFIG_CPU_SUBTYPE_SH7619 is not set
135
136#
137# SH-2A Processor Support
138#
139# CONFIG_CPU_SUBTYPE_SH7206 is not set
128 140
129# 141#
130# SH-3 Processor Support 142# SH-3 Processor Support
@@ -160,6 +172,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
160# 172#
161# CONFIG_CPU_SUBTYPE_SH7770 is not set 173# CONFIG_CPU_SUBTYPE_SH7770 is not set
162# CONFIG_CPU_SUBTYPE_SH7780 is not set 174# CONFIG_CPU_SUBTYPE_SH7780 is not set
175# CONFIG_CPU_SUBTYPE_SH7785 is not set
163 176
164# 177#
165# SH4AL-DSP Processor Support 178# SH4AL-DSP Processor Support
@@ -175,6 +188,9 @@ CONFIG_PAGE_OFFSET=0x80000000
175CONFIG_MEMORY_START=0x0c000000 188CONFIG_MEMORY_START=0x0c000000
176CONFIG_MEMORY_SIZE=0x04000000 189CONFIG_MEMORY_SIZE=0x04000000
177CONFIG_VSYSCALL=y 190CONFIG_VSYSCALL=y
191CONFIG_PAGE_SIZE_4KB=y
192# CONFIG_PAGE_SIZE_8KB is not set
193# CONFIG_PAGE_SIZE_64KB is not set
178CONFIG_SELECT_MEMORY_MODEL=y 194CONFIG_SELECT_MEMORY_MODEL=y
179CONFIG_FLATMEM_MANUAL=y 195CONFIG_FLATMEM_MANUAL=y
180# CONFIG_DISCONTIGMEM_MANUAL is not set 196# CONFIG_DISCONTIGMEM_MANUAL is not set
@@ -196,16 +212,21 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
196# Processor features 212# Processor features
197# 213#
198CONFIG_CPU_LITTLE_ENDIAN=y 214CONFIG_CPU_LITTLE_ENDIAN=y
215# CONFIG_CPU_BIG_ENDIAN is not set
199CONFIG_SH_FPU=y 216CONFIG_SH_FPU=y
200# CONFIG_SH_DSP is not set 217# CONFIG_SH_DSP is not set
201# CONFIG_SH_STORE_QUEUES is not set 218# CONFIG_SH_STORE_QUEUES is not set
202CONFIG_CPU_HAS_INTEVT=y 219CONFIG_CPU_HAS_INTEVT=y
220CONFIG_CPU_HAS_IPR_IRQ=y
203CONFIG_CPU_HAS_SR_RB=y 221CONFIG_CPU_HAS_SR_RB=y
222CONFIG_CPU_HAS_PTEA=y
204 223
205# 224#
206# Timer support 225# Timer support
207# 226#
208CONFIG_SH_TMU=y 227CONFIG_SH_TMU=y
228CONFIG_SH_TIMER_IRQ=16
229# CONFIG_NO_IDLE_HZ is not set
209CONFIG_SH_PCLK_FREQ=33333333 230CONFIG_SH_PCLK_FREQ=33333333
210 231
211# 232#
@@ -216,9 +237,7 @@ CONFIG_SH_PCLK_FREQ=33333333
216# 237#
217# DMA support 238# DMA support
218# 239#
219CONFIG_SH_DMA=y 240# CONFIG_SH_DMA is not set
220CONFIG_NR_ONCHIP_DMA_CHANNELS=4
221# CONFIG_NR_DMA_CHANNELS_BOOL is not set
222 241
223# 242#
224# Companion Chips 243# Companion Chips
@@ -227,6 +246,11 @@ CONFIG_NR_ONCHIP_DMA_CHANNELS=4
227CONFIG_HEARTBEAT=y 246CONFIG_HEARTBEAT=y
228 247
229# 248#
249# Additional SuperH Device Drivers
250#
251# CONFIG_PUSH_SWITCH is not set
252
253#
230# Kernel features 254# Kernel features
231# 255#
232# CONFIG_HZ_100 is not set 256# CONFIG_HZ_100 is not set
@@ -340,11 +364,13 @@ CONFIG_IP_PNP=y
340# CONFIG_INET_TUNNEL is not set 364# CONFIG_INET_TUNNEL is not set
341CONFIG_INET_XFRM_MODE_TRANSPORT=y 365CONFIG_INET_XFRM_MODE_TRANSPORT=y
342CONFIG_INET_XFRM_MODE_TUNNEL=y 366CONFIG_INET_XFRM_MODE_TUNNEL=y
367CONFIG_INET_XFRM_MODE_BEET=y
343CONFIG_INET_DIAG=y 368CONFIG_INET_DIAG=y
344CONFIG_INET_TCP_DIAG=y 369CONFIG_INET_TCP_DIAG=y
345# CONFIG_TCP_CONG_ADVANCED is not set 370# CONFIG_TCP_CONG_ADVANCED is not set
346CONFIG_TCP_CONG_CUBIC=y 371CONFIG_TCP_CONG_CUBIC=y
347CONFIG_DEFAULT_TCP_CONG="cubic" 372CONFIG_DEFAULT_TCP_CONG="cubic"
373# CONFIG_TCP_MD5SIG is not set
348 374
349# 375#
350# IP: Virtual Server Configuration 376# IP: Virtual Server Configuration
@@ -361,24 +387,12 @@ CONFIG_NETFILTER=y
361# Core Netfilter Configuration 387# Core Netfilter Configuration
362# 388#
363# CONFIG_NETFILTER_NETLINK is not set 389# CONFIG_NETFILTER_NETLINK is not set
390# CONFIG_NF_CONNTRACK_ENABLED is not set
364# CONFIG_NETFILTER_XTABLES is not set 391# CONFIG_NETFILTER_XTABLES is not set
365 392
366# 393#
367# IP: Netfilter Configuration 394# IP: Netfilter Configuration
368# 395#
369CONFIG_IP_NF_CONNTRACK=m
370CONFIG_IP_NF_CT_ACCT=y
371CONFIG_IP_NF_CONNTRACK_MARK=y
372# CONFIG_IP_NF_CONNTRACK_EVENTS is not set
373# CONFIG_IP_NF_CT_PROTO_SCTP is not set
374CONFIG_IP_NF_FTP=m
375CONFIG_IP_NF_IRC=m
376# CONFIG_IP_NF_NETBIOS_NS is not set
377CONFIG_IP_NF_TFTP=m
378CONFIG_IP_NF_AMANDA=m
379# CONFIG_IP_NF_PPTP is not set
380# CONFIG_IP_NF_H323 is not set
381# CONFIG_IP_NF_SIP is not set
382CONFIG_IP_NF_QUEUE=m 396CONFIG_IP_NF_QUEUE=m
383 397
384# 398#
@@ -477,6 +491,12 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
477# CONFIG_ATA_OVER_ETH is not set 491# CONFIG_ATA_OVER_ETH is not set
478 492
479# 493#
494# Misc devices
495#
496# CONFIG_SGI_IOC4 is not set
497# CONFIG_TIFM_CORE is not set
498
499#
480# ATA/ATAPI/MFM/RLL support 500# ATA/ATAPI/MFM/RLL support
481# 501#
482CONFIG_IDE=y 502CONFIG_IDE=y
@@ -519,6 +539,7 @@ CONFIG_BLK_DEV_AEC62XX=y
519# CONFIG_BLK_DEV_CS5530 is not set 539# CONFIG_BLK_DEV_CS5530 is not set
520# CONFIG_BLK_DEV_HPT34X is not set 540# CONFIG_BLK_DEV_HPT34X is not set
521# CONFIG_BLK_DEV_HPT366 is not set 541# CONFIG_BLK_DEV_HPT366 is not set
542# CONFIG_BLK_DEV_JMICRON is not set
522# CONFIG_BLK_DEV_SC1200 is not set 543# CONFIG_BLK_DEV_SC1200 is not set
523# CONFIG_BLK_DEV_PIIX is not set 544# CONFIG_BLK_DEV_PIIX is not set
524# CONFIG_BLK_DEV_IT821X is not set 545# CONFIG_BLK_DEV_IT821X is not set
@@ -542,6 +563,7 @@ CONFIG_IDEDMA_AUTO=y
542# 563#
543# CONFIG_RAID_ATTRS is not set 564# CONFIG_RAID_ATTRS is not set
544CONFIG_SCSI=y 565CONFIG_SCSI=y
566# CONFIG_SCSI_TGT is not set
545# CONFIG_SCSI_NETLINK is not set 567# CONFIG_SCSI_NETLINK is not set
546CONFIG_SCSI_PROC_FS=y 568CONFIG_SCSI_PROC_FS=y
547 569
@@ -561,6 +583,7 @@ CONFIG_BLK_DEV_SD=y
561CONFIG_SCSI_MULTI_LUN=y 583CONFIG_SCSI_MULTI_LUN=y
562# CONFIG_SCSI_CONSTANTS is not set 584# CONFIG_SCSI_CONSTANTS is not set
563# CONFIG_SCSI_LOGGING is not set 585# CONFIG_SCSI_LOGGING is not set
586# CONFIG_SCSI_SCAN_ASYNC is not set
564 587
565# 588#
566# SCSI Transports 589# SCSI Transports
@@ -602,12 +625,12 @@ CONFIG_SCSI_MULTI_LUN=y
602# CONFIG_SCSI_NCR53C406A is not set 625# CONFIG_SCSI_NCR53C406A is not set
603# CONFIG_SCSI_STEX is not set 626# CONFIG_SCSI_STEX is not set
604# CONFIG_SCSI_SYM53C8XX_2 is not set 627# CONFIG_SCSI_SYM53C8XX_2 is not set
605# CONFIG_SCSI_IPR is not set
606# CONFIG_SCSI_PAS16 is not set 628# CONFIG_SCSI_PAS16 is not set
607# CONFIG_SCSI_PSI240I is not set 629# CONFIG_SCSI_PSI240I is not set
608# CONFIG_SCSI_QLOGIC_FAS is not set 630# CONFIG_SCSI_QLOGIC_FAS is not set
609# CONFIG_SCSI_QLOGIC_1280 is not set 631# CONFIG_SCSI_QLOGIC_1280 is not set
610# CONFIG_SCSI_QLA_FC is not set 632# CONFIG_SCSI_QLA_FC is not set
633# CONFIG_SCSI_QLA_ISCSI is not set
611# CONFIG_SCSI_LPFC is not set 634# CONFIG_SCSI_LPFC is not set
612# CONFIG_SCSI_SYM53C416 is not set 635# CONFIG_SCSI_SYM53C416 is not set
613# CONFIG_SCSI_DC395x is not set 636# CONFIG_SCSI_DC395x is not set
@@ -615,6 +638,7 @@ CONFIG_SCSI_MULTI_LUN=y
615# CONFIG_SCSI_T128 is not set 638# CONFIG_SCSI_T128 is not set
616# CONFIG_SCSI_NSP32 is not set 639# CONFIG_SCSI_NSP32 is not set
617# CONFIG_SCSI_DEBUG is not set 640# CONFIG_SCSI_DEBUG is not set
641# CONFIG_SCSI_SRP is not set
618 642
619# 643#
620# PCMCIA SCSI adapter support 644# PCMCIA SCSI adapter support
@@ -757,6 +781,7 @@ CONFIG_8139CP=y
757# CONFIG_IXGB is not set 781# CONFIG_IXGB is not set
758# CONFIG_S2IO is not set 782# CONFIG_S2IO is not set
759# CONFIG_MYRI10GE is not set 783# CONFIG_MYRI10GE is not set
784# CONFIG_NETXEN_NIC is not set
760 785
761# 786#
762# Token Ring devices 787# Token Ring devices
@@ -871,10 +896,6 @@ CONFIG_HW_RANDOM=y
871# CONFIG_DTLK is not set 896# CONFIG_DTLK is not set
872# CONFIG_R3964 is not set 897# CONFIG_R3964 is not set
873# CONFIG_APPLICOM is not set 898# CONFIG_APPLICOM is not set
874
875#
876# Ftape, the floppy tape device driver
877#
878# CONFIG_DRM is not set 899# CONFIG_DRM is not set
879 900
880# 901#
@@ -889,7 +910,6 @@ CONFIG_HW_RANDOM=y
889# TPM devices 910# TPM devices
890# 911#
891# CONFIG_TCG_TPM is not set 912# CONFIG_TCG_TPM is not set
892# CONFIG_TELCLOCK is not set
893 913
894# 914#
895# I2C support 915# I2C support
@@ -905,6 +925,7 @@ CONFIG_HW_RANDOM=y
905# 925#
906# Dallas's 1-wire bus 926# Dallas's 1-wire bus
907# 927#
928# CONFIG_W1 is not set
908 929
909# 930#
910# Hardware Monitoring support 931# Hardware Monitoring support
@@ -917,10 +938,6 @@ CONFIG_HWMON=y
917# CONFIG_HWMON_DEBUG_CHIP is not set 938# CONFIG_HWMON_DEBUG_CHIP is not set
918 939
919# 940#
920# Misc devices
921#
922
923#
924# Multimedia devices 941# Multimedia devices
925# 942#
926CONFIG_VIDEO_DEV=m 943CONFIG_VIDEO_DEV=m
@@ -1037,6 +1054,7 @@ CONFIG_USB=y
1037CONFIG_USB_DEVICEFS=y 1054CONFIG_USB_DEVICEFS=y
1038# CONFIG_USB_BANDWIDTH is not set 1055# CONFIG_USB_BANDWIDTH is not set
1039# CONFIG_USB_DYNAMIC_MINORS is not set 1056# CONFIG_USB_DYNAMIC_MINORS is not set
1057# CONFIG_USB_MULTITHREAD_PROBE is not set
1040# CONFIG_USB_OTG is not set 1058# CONFIG_USB_OTG is not set
1041 1059
1042# 1060#
@@ -1106,7 +1124,6 @@ CONFIG_USB_HIDINPUT=y
1106# CONFIG_USB_ATI_REMOTE2 is not set 1124# CONFIG_USB_ATI_REMOTE2 is not set
1107# CONFIG_USB_KEYSPAN_REMOTE is not set 1125# CONFIG_USB_KEYSPAN_REMOTE is not set
1108# CONFIG_USB_APPLETOUCH is not set 1126# CONFIG_USB_APPLETOUCH is not set
1109# CONFIG_USB_TRANCEVIBRATOR is not set
1110 1127
1111# 1128#
1112# USB Imaging devices 1129# USB Imaging devices
@@ -1121,6 +1138,7 @@ CONFIG_USB_HIDINPUT=y
1121# CONFIG_USB_KAWETH is not set 1138# CONFIG_USB_KAWETH is not set
1122CONFIG_USB_PEGASUS=m 1139CONFIG_USB_PEGASUS=m
1123CONFIG_USB_RTL8150=m 1140CONFIG_USB_RTL8150=m
1141# CONFIG_USB_USBNET_MII is not set
1124# CONFIG_USB_USBNET is not set 1142# CONFIG_USB_USBNET is not set
1125CONFIG_USB_MON=y 1143CONFIG_USB_MON=y
1126 1144
@@ -1156,6 +1174,7 @@ CONFIG_USB_SERIAL_FTDI_SIO=m
1156# CONFIG_USB_SERIAL_KLSI is not set 1174# CONFIG_USB_SERIAL_KLSI is not set
1157# CONFIG_USB_SERIAL_KOBIL_SCT is not set 1175# CONFIG_USB_SERIAL_KOBIL_SCT is not set
1158# CONFIG_USB_SERIAL_MCT_U232 is not set 1176# CONFIG_USB_SERIAL_MCT_U232 is not set
1177# CONFIG_USB_SERIAL_MOS7720 is not set
1159# CONFIG_USB_SERIAL_MOS7840 is not set 1178# CONFIG_USB_SERIAL_MOS7840 is not set
1160# CONFIG_USB_SERIAL_NAVMAN is not set 1179# CONFIG_USB_SERIAL_NAVMAN is not set
1161CONFIG_USB_SERIAL_PL2303=m 1180CONFIG_USB_SERIAL_PL2303=m
@@ -1167,6 +1186,7 @@ CONFIG_USB_SERIAL_PL2303=m
1167# CONFIG_USB_SERIAL_XIRCOM is not set 1186# CONFIG_USB_SERIAL_XIRCOM is not set
1168# CONFIG_USB_SERIAL_OPTION is not set 1187# CONFIG_USB_SERIAL_OPTION is not set
1169# CONFIG_USB_SERIAL_OMNINET is not set 1188# CONFIG_USB_SERIAL_OMNINET is not set
1189# CONFIG_USB_SERIAL_DEBUG is not set
1170 1190
1171# 1191#
1172# USB Miscellaneous drivers 1192# USB Miscellaneous drivers
@@ -1188,6 +1208,7 @@ CONFIG_USB_EMI26=m
1188CONFIG_USB_SISUSBVGA=m 1208CONFIG_USB_SISUSBVGA=m
1189CONFIG_USB_SISUSBVGA_CON=y 1209CONFIG_USB_SISUSBVGA_CON=y
1190# CONFIG_USB_LD is not set 1210# CONFIG_USB_LD is not set
1211# CONFIG_USB_TRANCEVIBRATOR is not set
1191# CONFIG_USB_TEST is not set 1212# CONFIG_USB_TEST is not set
1192 1213
1193# 1214#
@@ -1254,6 +1275,7 @@ CONFIG_EXT3_FS=y
1254CONFIG_EXT3_FS_XATTR=y 1275CONFIG_EXT3_FS_XATTR=y
1255# CONFIG_EXT3_FS_POSIX_ACL is not set 1276# CONFIG_EXT3_FS_POSIX_ACL is not set
1256# CONFIG_EXT3_FS_SECURITY is not set 1277# CONFIG_EXT3_FS_SECURITY is not set
1278# CONFIG_EXT4DEV_FS is not set
1257CONFIG_JBD=y 1279CONFIG_JBD=y
1258# CONFIG_JBD_DEBUG is not set 1280# CONFIG_JBD_DEBUG is not set
1259CONFIG_FS_MBCACHE=y 1281CONFIG_FS_MBCACHE=y
@@ -1264,6 +1286,7 @@ CONFIG_REISERFS_FS=y
1264# CONFIG_JFS_FS is not set 1286# CONFIG_JFS_FS is not set
1265# CONFIG_FS_POSIX_ACL is not set 1287# CONFIG_FS_POSIX_ACL is not set
1266# CONFIG_XFS_FS is not set 1288# CONFIG_XFS_FS is not set
1289# CONFIG_GFS2_FS is not set
1267# CONFIG_OCFS2_FS is not set 1290# CONFIG_OCFS2_FS is not set
1268# CONFIG_MINIX_FS is not set 1291# CONFIG_MINIX_FS is not set
1269CONFIG_ROMFS_FS=y 1292CONFIG_ROMFS_FS=y
@@ -1414,6 +1437,7 @@ CONFIG_NLS_CODEPAGE_932=y
1414# 1437#
1415# Kernel hacking 1438# Kernel hacking
1416# 1439#
1440CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1417# CONFIG_PRINTK_TIME is not set 1441# CONFIG_PRINTK_TIME is not set
1418CONFIG_ENABLE_MUST_CHECK=y 1442CONFIG_ENABLE_MUST_CHECK=y
1419# CONFIG_MAGIC_SYSRQ is not set 1443# CONFIG_MAGIC_SYSRQ is not set
@@ -1422,6 +1446,7 @@ CONFIG_ENABLE_MUST_CHECK=y
1422CONFIG_LOG_BUF_SHIFT=14 1446CONFIG_LOG_BUF_SHIFT=14
1423# CONFIG_DEBUG_BUGVERBOSE is not set 1447# CONFIG_DEBUG_BUGVERBOSE is not set
1424# CONFIG_DEBUG_FS is not set 1448# CONFIG_DEBUG_FS is not set
1449# CONFIG_HEADERS_CHECK is not set
1425CONFIG_SH_STANDARD_BIOS=y 1450CONFIG_SH_STANDARD_BIOS=y
1426# CONFIG_EARLY_SCIF_CONSOLE is not set 1451# CONFIG_EARLY_SCIF_CONSOLE is not set
1427# CONFIG_EARLY_PRINTK is not set 1452# CONFIG_EARLY_PRINTK is not set
@@ -1445,6 +1470,4 @@ CONFIG_SH_STANDARD_BIOS=y
1445# CONFIG_CRC16 is not set 1470# CONFIG_CRC16 is not set
1446CONFIG_CRC32=y 1471CONFIG_CRC32=y
1447# CONFIG_LIBCRC32C is not set 1472# CONFIG_LIBCRC32C is not set
1448CONFIG_TEXTSEARCH=y
1449CONFIG_TEXTSEARCH_KMP=m
1450CONFIG_PLIST=y 1473CONFIG_PLIST=y
diff --git a/arch/sh/configs/se7206_defconfig b/arch/sh/configs/se7206_defconfig
index 36cec0b6e7c1..87ab9080fd1d 100644
--- a/arch/sh/configs/se7206_defconfig
+++ b/arch/sh/configs/se7206_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19-rc4 3# Linux kernel version: 2.6.19
4# Sun Nov 5 16:20:10 2006 4# Wed Dec 6 14:40:15 2006
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_RWSEM_GENERIC_SPINLOCK=y 7CONFIG_RWSEM_GENERIC_SPINLOCK=y
@@ -11,6 +11,8 @@ CONFIG_GENERIC_HARDIRQS=y
11CONFIG_GENERIC_IRQ_PROBE=y 11CONFIG_GENERIC_IRQ_PROBE=y
12CONFIG_GENERIC_CALIBRATE_DELAY=y 12CONFIG_GENERIC_CALIBRATE_DELAY=y
13# CONFIG_GENERIC_TIME is not set 13# CONFIG_GENERIC_TIME is not set
14CONFIG_STACKTRACE_SUPPORT=y
15CONFIG_LOCKDEP_SUPPORT=y
14CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 16CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
15 17
16# 18#
@@ -34,24 +36,23 @@ CONFIG_LOCALVERSION=""
34# CONFIG_IKCONFIG is not set 36# CONFIG_IKCONFIG is not set
35# CONFIG_RELAY is not set 37# CONFIG_RELAY is not set
36CONFIG_INITRAMFS_SOURCE="" 38CONFIG_INITRAMFS_SOURCE=""
37# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 39CONFIG_CC_OPTIMIZE_FOR_SIZE=y
38CONFIG_SYSCTL=y 40CONFIG_SYSCTL=y
39CONFIG_EMBEDDED=y 41CONFIG_EMBEDDED=y
40CONFIG_UID16=y 42# CONFIG_UID16 is not set
41# CONFIG_SYSCTL_SYSCALL is not set 43# CONFIG_SYSCTL_SYSCALL is not set
42CONFIG_KALLSYMS=y 44# CONFIG_KALLSYMS is not set
43# CONFIG_KALLSYMS_EXTRA_PASS is not set
44# CONFIG_HOTPLUG is not set 45# CONFIG_HOTPLUG is not set
45CONFIG_PRINTK=y 46CONFIG_PRINTK=y
46CONFIG_BUG=y 47CONFIG_BUG=y
47CONFIG_ELF_CORE=y 48# CONFIG_ELF_CORE is not set
48CONFIG_BASE_FULL=y 49# CONFIG_BASE_FULL is not set
49# CONFIG_FUTEX is not set 50# CONFIG_FUTEX is not set
50# CONFIG_EPOLL is not set 51# CONFIG_EPOLL is not set
51CONFIG_SLAB=y 52CONFIG_SLAB=y
52CONFIG_VM_EVENT_COUNTERS=y 53# CONFIG_VM_EVENT_COUNTERS is not set
53CONFIG_TINY_SHMEM=y 54CONFIG_TINY_SHMEM=y
54CONFIG_BASE_SMALL=0 55CONFIG_BASE_SMALL=1
55# CONFIG_SLOB is not set 56# CONFIG_SLOB is not set
56 57
57# 58#
@@ -160,6 +161,7 @@ CONFIG_CPU_SUBTYPE_SH7206=y
160# 161#
161# CONFIG_CPU_SUBTYPE_SH7770 is not set 162# CONFIG_CPU_SUBTYPE_SH7770 is not set
162# CONFIG_CPU_SUBTYPE_SH7780 is not set 163# CONFIG_CPU_SUBTYPE_SH7780 is not set
164# CONFIG_CPU_SUBTYPE_SH7785 is not set
163 165
164# 166#
165# SH4AL-DSP Processor Support 167# SH4AL-DSP Processor Support
@@ -172,7 +174,10 @@ CONFIG_CPU_SUBTYPE_SH7206=y
172# 174#
173CONFIG_PAGE_OFFSET=0x00000000 175CONFIG_PAGE_OFFSET=0x00000000
174CONFIG_MEMORY_START=0x0c000000 176CONFIG_MEMORY_START=0x0c000000
175CONFIG_MEMORY_SIZE=0x02000000 177CONFIG_MEMORY_SIZE=0x04000000
178CONFIG_PAGE_SIZE_4KB=y
179# CONFIG_PAGE_SIZE_8KB is not set
180# CONFIG_PAGE_SIZE_64KB is not set
176CONFIG_SELECT_MEMORY_MODEL=y 181CONFIG_SELECT_MEMORY_MODEL=y
177CONFIG_FLATMEM_MANUAL=y 182CONFIG_FLATMEM_MANUAL=y
178# CONFIG_DISCONTIGMEM_MANUAL is not set 183# CONFIG_DISCONTIGMEM_MANUAL is not set
@@ -194,6 +199,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
194# Processor features 199# Processor features
195# 200#
196# CONFIG_CPU_LITTLE_ENDIAN is not set 201# CONFIG_CPU_LITTLE_ENDIAN is not set
202CONFIG_CPU_BIG_ENDIAN=y
197# CONFIG_SH_FPU is not set 203# CONFIG_SH_FPU is not set
198# CONFIG_SH_FPU_EMU is not set 204# CONFIG_SH_FPU_EMU is not set
199# CONFIG_SH_DSP is not set 205# CONFIG_SH_DSP is not set
@@ -203,6 +209,8 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
203# 209#
204CONFIG_SH_CMT=y 210CONFIG_SH_CMT=y
205# CONFIG_SH_MTU2 is not set 211# CONFIG_SH_MTU2 is not set
212CONFIG_SH_TIMER_IRQ=140
213# CONFIG_NO_IDLE_HZ is not set
206CONFIG_SH_PCLK_FREQ=33333333 214CONFIG_SH_PCLK_FREQ=33333333
207CONFIG_SH_CLK_MD=6 215CONFIG_SH_CLK_MD=6
208 216
@@ -222,6 +230,11 @@ CONFIG_SH_CLK_MD=6
222# CONFIG_HD6446X_SERIES is not set 230# CONFIG_HD6446X_SERIES is not set
223 231
224# 232#
233# Additional SuperH Device Drivers
234#
235# CONFIG_PUSH_SWITCH is not set
236
237#
225# Kernel features 238# Kernel features
226# 239#
227CONFIG_HZ_100=y 240CONFIG_HZ_100=y
@@ -279,9 +292,6 @@ CONFIG_NET=y
279# CONFIG_NETDEBUG is not set 292# CONFIG_NETDEBUG is not set
280# CONFIG_PACKET is not set 293# CONFIG_PACKET is not set
281# CONFIG_UNIX is not set 294# CONFIG_UNIX is not set
282CONFIG_XFRM=y
283# CONFIG_XFRM_USER is not set
284# CONFIG_XFRM_SUB_POLICY is not set
285# CONFIG_NET_KEY is not set 295# CONFIG_NET_KEY is not set
286CONFIG_INET=y 296CONFIG_INET=y
287# CONFIG_IP_MULTICAST is not set 297# CONFIG_IP_MULTICAST is not set
@@ -297,9 +307,9 @@ CONFIG_IP_FIB_HASH=y
297# CONFIG_INET_IPCOMP is not set 307# CONFIG_INET_IPCOMP is not set
298# CONFIG_INET_XFRM_TUNNEL is not set 308# CONFIG_INET_XFRM_TUNNEL is not set
299# CONFIG_INET_TUNNEL is not set 309# CONFIG_INET_TUNNEL is not set
300CONFIG_INET_XFRM_MODE_TRANSPORT=y 310# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
301CONFIG_INET_XFRM_MODE_TUNNEL=y 311# CONFIG_INET_XFRM_MODE_TUNNEL is not set
302CONFIG_INET_XFRM_MODE_BEET=y 312# CONFIG_INET_XFRM_MODE_BEET is not set
303# CONFIG_INET_DIAG is not set 313# CONFIG_INET_DIAG is not set
304# CONFIG_TCP_CONG_ADVANCED is not set 314# CONFIG_TCP_CONG_ADVANCED is not set
305CONFIG_TCP_CONG_CUBIC=y 315CONFIG_TCP_CONG_CUBIC=y
@@ -371,7 +381,7 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
371# 381#
372CONFIG_MTD=y 382CONFIG_MTD=y
373# CONFIG_MTD_DEBUG is not set 383# CONFIG_MTD_DEBUG is not set
374# CONFIG_MTD_CONCAT is not set 384CONFIG_MTD_CONCAT=y
375CONFIG_MTD_PARTITIONS=y 385CONFIG_MTD_PARTITIONS=y
376CONFIG_MTD_REDBOOT_PARTS=y 386CONFIG_MTD_REDBOOT_PARTS=y
377CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1 387CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
@@ -422,7 +432,7 @@ CONFIG_MTD_CFI_UTIL=y
422# CONFIG_MTD_COMPLEX_MAPPINGS is not set 432# CONFIG_MTD_COMPLEX_MAPPINGS is not set
423CONFIG_MTD_PHYSMAP=y 433CONFIG_MTD_PHYSMAP=y
424CONFIG_MTD_PHYSMAP_START=0x20000000 434CONFIG_MTD_PHYSMAP_START=0x20000000
425CONFIG_MTD_PHYSMAP_LEN=0x1000000 435CONFIG_MTD_PHYSMAP_LEN=0x01000000
426CONFIG_MTD_PHYSMAP_BANKWIDTH=4 436CONFIG_MTD_PHYSMAP_BANKWIDTH=4
427# CONFIG_MTD_SOLUTIONENGINE is not set 437# CONFIG_MTD_SOLUTIONENGINE is not set
428# CONFIG_MTD_UCLINUX is not set 438# CONFIG_MTD_UCLINUX is not set
@@ -468,10 +478,7 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=4
468# CONFIG_BLK_DEV_COW_COMMON is not set 478# CONFIG_BLK_DEV_COW_COMMON is not set
469# CONFIG_BLK_DEV_LOOP is not set 479# CONFIG_BLK_DEV_LOOP is not set
470# CONFIG_BLK_DEV_NBD is not set 480# CONFIG_BLK_DEV_NBD is not set
471CONFIG_BLK_DEV_RAM=y 481# CONFIG_BLK_DEV_RAM is not set
472CONFIG_BLK_DEV_RAM_COUNT=16
473CONFIG_BLK_DEV_RAM_SIZE=4096
474CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
475# CONFIG_BLK_DEV_INITRD is not set 482# CONFIG_BLK_DEV_INITRD is not set
476# CONFIG_CDROM_PKTCDVD is not set 483# CONFIG_CDROM_PKTCDVD is not set
477# CONFIG_ATA_OVER_ETH is not set 484# CONFIG_ATA_OVER_ETH is not set
@@ -519,7 +526,50 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
519# 526#
520# Network device support 527# Network device support
521# 528#
522# CONFIG_NETDEVICES is not set 529CONFIG_NETDEVICES=y
530# CONFIG_DUMMY is not set
531# CONFIG_BONDING is not set
532# CONFIG_EQUALIZER is not set
533# CONFIG_TUN is not set
534
535#
536# PHY device support
537#
538# CONFIG_PHYLIB is not set
539
540#
541# Ethernet (10 or 100Mbit)
542#
543CONFIG_NET_ETHERNET=y
544CONFIG_MII=y
545# CONFIG_STNIC is not set
546CONFIG_SMC91X=y
547
548#
549# Ethernet (1000 Mbit)
550#
551
552#
553# Ethernet (10000 Mbit)
554#
555
556#
557# Token Ring devices
558#
559
560#
561# Wireless LAN (non-hamradio)
562#
563# CONFIG_NET_RADIO is not set
564
565#
566# Wan interfaces
567#
568# CONFIG_WAN is not set
569# CONFIG_PPP is not set
570# CONFIG_SLIP is not set
571# CONFIG_SHAPER is not set
572# CONFIG_NETCONSOLE is not set
523# CONFIG_NETPOLL is not set 573# CONFIG_NETPOLL is not set
524# CONFIG_NET_POLL_CONTROLLER is not set 574# CONFIG_NET_POLL_CONTROLLER is not set
525 575
@@ -536,7 +586,26 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
536# 586#
537# Input device support 587# Input device support
538# 588#
539# CONFIG_INPUT is not set 589CONFIG_INPUT=y
590# CONFIG_INPUT_FF_MEMLESS is not set
591
592#
593# Userland interfaces
594#
595# CONFIG_INPUT_MOUSEDEV is not set
596# CONFIG_INPUT_JOYDEV is not set
597# CONFIG_INPUT_TSDEV is not set
598# CONFIG_INPUT_EVDEV is not set
599# CONFIG_INPUT_EVBUG is not set
600
601#
602# Input Device Drivers
603#
604# CONFIG_INPUT_KEYBOARD is not set
605# CONFIG_INPUT_MOUSE is not set
606# CONFIG_INPUT_JOYSTICK is not set
607# CONFIG_INPUT_TOUCHSCREEN is not set
608# CONFIG_INPUT_MISC is not set
540 609
541# 610#
542# Hardware I/O ports 611# Hardware I/O ports
@@ -564,8 +633,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
564CONFIG_SERIAL_CORE=y 633CONFIG_SERIAL_CORE=y
565CONFIG_SERIAL_CORE_CONSOLE=y 634CONFIG_SERIAL_CORE_CONSOLE=y
566# CONFIG_UNIX98_PTYS is not set 635# CONFIG_UNIX98_PTYS is not set
567CONFIG_LEGACY_PTYS=y 636# CONFIG_LEGACY_PTYS is not set
568CONFIG_LEGACY_PTY_COUNT=256
569 637
570# 638#
571# IPMI 639# IPMI
@@ -576,7 +644,7 @@ CONFIG_LEGACY_PTY_COUNT=256
576# Watchdog Cards 644# Watchdog Cards
577# 645#
578# CONFIG_WATCHDOG is not set 646# CONFIG_WATCHDOG is not set
579CONFIG_HW_RANDOM=y 647# CONFIG_HW_RANDOM is not set
580# CONFIG_GEN_RTC is not set 648# CONFIG_GEN_RTC is not set
581# CONFIG_DTLK is not set 649# CONFIG_DTLK is not set
582# CONFIG_R3964 is not set 650# CONFIG_R3964 is not set
@@ -610,12 +678,8 @@ CONFIG_HW_RANDOM=y
610# 678#
611# Hardware Monitoring support 679# Hardware Monitoring support
612# 680#
613CONFIG_HWMON=y 681# CONFIG_HWMON is not set
614# CONFIG_HWMON_VID is not set 682# CONFIG_HWMON_VID is not set
615# CONFIG_SENSORS_ABITUGURU is not set
616# CONFIG_SENSORS_F71805F is not set
617# CONFIG_SENSORS_VT1211 is not set
618# CONFIG_HWMON_DEBUG_CHIP is not set
619 683
620# 684#
621# Multimedia devices 685# Multimedia devices
@@ -630,7 +694,7 @@ CONFIG_HWMON=y
630# 694#
631# Graphics support 695# Graphics support
632# 696#
633CONFIG_FIRMWARE_EDID=y 697# CONFIG_FIRMWARE_EDID is not set
634# CONFIG_FB is not set 698# CONFIG_FB is not set
635 699
636# 700#
@@ -701,8 +765,7 @@ CONFIG_FIRMWARE_EDID=y
701# 765#
702# File systems 766# File systems
703# 767#
704CONFIG_EXT2_FS=y 768# CONFIG_EXT2_FS is not set
705# CONFIG_EXT2_FS_XATTR is not set
706# CONFIG_EXT3_FS is not set 769# CONFIG_EXT3_FS is not set
707# CONFIG_EXT4DEV_FS is not set 770# CONFIG_EXT4DEV_FS is not set
708# CONFIG_REISERFS_FS is not set 771# CONFIG_REISERFS_FS is not set
@@ -755,7 +818,7 @@ CONFIG_RAMFS=y
755# CONFIG_EFS_FS is not set 818# CONFIG_EFS_FS is not set
756# CONFIG_JFFS_FS is not set 819# CONFIG_JFFS_FS is not set
757# CONFIG_JFFS2_FS is not set 820# CONFIG_JFFS2_FS is not set
758CONFIG_CRAMFS=y 821# CONFIG_CRAMFS is not set
759# CONFIG_VXFS_FS is not set 822# CONFIG_VXFS_FS is not set
760# CONFIG_HPFS_FS is not set 823# CONFIG_HPFS_FS is not set
761# CONFIG_QNX4FS_FS is not set 824# CONFIG_QNX4FS_FS is not set
@@ -793,8 +856,9 @@ CONFIG_MSDOS_PARTITION=y
793# 856#
794# Kernel hacking 857# Kernel hacking
795# 858#
859CONFIG_TRACE_IRQFLAGS_SUPPORT=y
796# CONFIG_PRINTK_TIME is not set 860# CONFIG_PRINTK_TIME is not set
797CONFIG_ENABLE_MUST_CHECK=y 861# CONFIG_ENABLE_MUST_CHECK is not set
798# CONFIG_MAGIC_SYSRQ is not set 862# CONFIG_MAGIC_SYSRQ is not set
799# CONFIG_UNUSED_SYMBOLS is not set 863# CONFIG_UNUSED_SYMBOLS is not set
800# CONFIG_DEBUG_KERNEL is not set 864# CONFIG_DEBUG_KERNEL is not set
@@ -819,7 +883,7 @@ CONFIG_LOG_BUF_SHIFT=14
819# 883#
820# Library routines 884# Library routines
821# 885#
822CONFIG_CRC_CCITT=y 886# CONFIG_CRC_CCITT is not set
823# CONFIG_CRC16 is not set 887# CONFIG_CRC16 is not set
824CONFIG_CRC32=y 888CONFIG_CRC32=y
825# CONFIG_LIBCRC32C is not set 889# CONFIG_LIBCRC32C is not set
diff --git a/arch/sh/configs/se7619_defconfig b/arch/sh/configs/se7619_defconfig
new file mode 100644
index 000000000000..20ac7f4c53fb
--- /dev/null
+++ b/arch/sh/configs/se7619_defconfig
@@ -0,0 +1,744 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19
4# Wed Dec 6 16:35:36 2006
5#
6CONFIG_SUPERH=y
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8CONFIG_GENERIC_FIND_NEXT_BIT=y
9CONFIG_GENERIC_HWEIGHT=y
10CONFIG_GENERIC_HARDIRQS=y
11CONFIG_GENERIC_IRQ_PROBE=y
12CONFIG_GENERIC_CALIBRATE_DELAY=y
13# CONFIG_GENERIC_TIME is not set
14CONFIG_STACKTRACE_SUPPORT=y
15CONFIG_LOCKDEP_SUPPORT=y
16CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
17
18#
19# Code maturity level options
20#
21CONFIG_EXPERIMENTAL=y
22CONFIG_BROKEN_ON_SMP=y
23CONFIG_INIT_ENV_ARG_LIMIT=32
24
25#
26# General setup
27#
28CONFIG_LOCALVERSION=""
29# CONFIG_LOCALVERSION_AUTO is not set
30# CONFIG_SYSVIPC is not set
31# CONFIG_BSD_PROCESS_ACCT is not set
32# CONFIG_UTS_NS is not set
33# CONFIG_IKCONFIG is not set
34# CONFIG_RELAY is not set
35CONFIG_INITRAMFS_SOURCE=""
36CONFIG_CC_OPTIMIZE_FOR_SIZE=y
37CONFIG_SYSCTL=y
38CONFIG_EMBEDDED=y
39# CONFIG_UID16 is not set
40# CONFIG_SYSCTL_SYSCALL is not set
41# CONFIG_KALLSYMS is not set
42# CONFIG_HOTPLUG is not set
43CONFIG_PRINTK=y
44CONFIG_BUG=y
45# CONFIG_ELF_CORE is not set
46# CONFIG_BASE_FULL is not set
47# CONFIG_FUTEX is not set
48# CONFIG_EPOLL is not set
49CONFIG_SLAB=y
50# CONFIG_VM_EVENT_COUNTERS is not set
51CONFIG_TINY_SHMEM=y
52CONFIG_BASE_SMALL=1
53# CONFIG_SLOB is not set
54
55#
56# Loadable module support
57#
58# CONFIG_MODULES is not set
59
60#
61# Block layer
62#
63CONFIG_BLOCK=y
64# CONFIG_LBD is not set
65# CONFIG_LSF is not set
66
67#
68# IO Schedulers
69#
70CONFIG_IOSCHED_NOOP=y
71# CONFIG_IOSCHED_AS is not set
72# CONFIG_IOSCHED_DEADLINE is not set
73# CONFIG_IOSCHED_CFQ is not set
74# CONFIG_DEFAULT_AS is not set
75# CONFIG_DEFAULT_DEADLINE is not set
76# CONFIG_DEFAULT_CFQ is not set
77CONFIG_DEFAULT_NOOP=y
78CONFIG_DEFAULT_IOSCHED="noop"
79
80#
81# System type
82#
83# CONFIG_SH_SOLUTION_ENGINE is not set
84# CONFIG_SH_7751_SOLUTION_ENGINE is not set
85# CONFIG_SH_7300_SOLUTION_ENGINE is not set
86# CONFIG_SH_7343_SOLUTION_ENGINE is not set
87# CONFIG_SH_73180_SOLUTION_ENGINE is not set
88# CONFIG_SH_7751_SYSTEMH is not set
89# CONFIG_SH_HP6XX is not set
90# CONFIG_SH_EC3104 is not set
91# CONFIG_SH_SATURN is not set
92# CONFIG_SH_DREAMCAST is not set
93# CONFIG_SH_BIGSUR is not set
94# CONFIG_SH_MPC1211 is not set
95# CONFIG_SH_SH03 is not set
96# CONFIG_SH_SECUREEDGE5410 is not set
97# CONFIG_SH_HS7751RVOIP is not set
98# CONFIG_SH_7710VOIPGW is not set
99# CONFIG_SH_RTS7751R2D is not set
100# CONFIG_SH_R7780RP is not set
101# CONFIG_SH_EDOSK7705 is not set
102# CONFIG_SH_SH4202_MICRODEV is not set
103# CONFIG_SH_LANDISK is not set
104# CONFIG_SH_TITAN is not set
105# CONFIG_SH_SHMIN is not set
106# CONFIG_SH_7206_SOLUTION_ENGINE is not set
107CONFIG_SH_7619_SOLUTION_ENGINE=y
108# CONFIG_SH_UNKNOWN is not set
109
110#
111# Processor selection
112#
113CONFIG_CPU_SH2=y
114
115#
116# SH-2 Processor Support
117#
118# CONFIG_CPU_SUBTYPE_SH7604 is not set
119CONFIG_CPU_SUBTYPE_SH7619=y
120
121#
122# SH-2A Processor Support
123#
124# CONFIG_CPU_SUBTYPE_SH7206 is not set
125
126#
127# SH-3 Processor Support
128#
129# CONFIG_CPU_SUBTYPE_SH7300 is not set
130# CONFIG_CPU_SUBTYPE_SH7705 is not set
131# CONFIG_CPU_SUBTYPE_SH7706 is not set
132# CONFIG_CPU_SUBTYPE_SH7707 is not set
133# CONFIG_CPU_SUBTYPE_SH7708 is not set
134# CONFIG_CPU_SUBTYPE_SH7709 is not set
135# CONFIG_CPU_SUBTYPE_SH7710 is not set
136
137#
138# SH-4 Processor Support
139#
140# CONFIG_CPU_SUBTYPE_SH7750 is not set
141# CONFIG_CPU_SUBTYPE_SH7091 is not set
142# CONFIG_CPU_SUBTYPE_SH7750R is not set
143# CONFIG_CPU_SUBTYPE_SH7750S is not set
144# CONFIG_CPU_SUBTYPE_SH7751 is not set
145# CONFIG_CPU_SUBTYPE_SH7751R is not set
146# CONFIG_CPU_SUBTYPE_SH7760 is not set
147# CONFIG_CPU_SUBTYPE_SH4_202 is not set
148
149#
150# ST40 Processor Support
151#
152# CONFIG_CPU_SUBTYPE_ST40STB1 is not set
153# CONFIG_CPU_SUBTYPE_ST40GX1 is not set
154
155#
156# SH-4A Processor Support
157#
158# CONFIG_CPU_SUBTYPE_SH7770 is not set
159# CONFIG_CPU_SUBTYPE_SH7780 is not set
160# CONFIG_CPU_SUBTYPE_SH7785 is not set
161
162#
163# SH4AL-DSP Processor Support
164#
165# CONFIG_CPU_SUBTYPE_SH73180 is not set
166# CONFIG_CPU_SUBTYPE_SH7343 is not set
167
168#
169# Memory management options
170#
171CONFIG_PAGE_OFFSET=0x00000000
172CONFIG_MEMORY_START=0x0c000000
173CONFIG_MEMORY_SIZE=0x04000000
174CONFIG_PAGE_SIZE_4KB=y
175# CONFIG_PAGE_SIZE_8KB is not set
176# CONFIG_PAGE_SIZE_64KB is not set
177CONFIG_SELECT_MEMORY_MODEL=y
178CONFIG_FLATMEM_MANUAL=y
179# CONFIG_DISCONTIGMEM_MANUAL is not set
180# CONFIG_SPARSEMEM_MANUAL is not set
181CONFIG_FLATMEM=y
182CONFIG_FLAT_NODE_MEM_MAP=y
183# CONFIG_SPARSEMEM_STATIC is not set
184CONFIG_SPLIT_PTLOCK_CPUS=4
185# CONFIG_RESOURCES_64BIT is not set
186
187#
188# Cache configuration
189#
190# CONFIG_SH_DIRECT_MAPPED is not set
191CONFIG_SH_WRITETHROUGH=y
192# CONFIG_SH_OCRAM is not set
193
194#
195# Processor features
196#
197# CONFIG_CPU_LITTLE_ENDIAN is not set
198CONFIG_CPU_BIG_ENDIAN=y
199# CONFIG_SH_FPU is not set
200# CONFIG_SH_FPU_EMU is not set
201# CONFIG_SH_DSP is not set
202
203#
204# Timer support
205#
206CONFIG_SH_CMT=y
207CONFIG_SH_TIMER_IRQ=86
208# CONFIG_NO_IDLE_HZ is not set
209CONFIG_SH_PCLK_FREQ=31250000
210CONFIG_SH_CLK_MD=5
211
212#
213# CPU Frequency scaling
214#
215# CONFIG_CPU_FREQ is not set
216
217#
218# DMA support
219#
220# CONFIG_SH_DMA is not set
221
222#
223# Companion Chips
224#
225# CONFIG_HD6446X_SERIES is not set
226
227#
228# Additional SuperH Device Drivers
229#
230# CONFIG_PUSH_SWITCH is not set
231
232#
233# Kernel features
234#
235CONFIG_HZ_100=y
236# CONFIG_HZ_250 is not set
237# CONFIG_HZ_1000 is not set
238CONFIG_HZ=100
239# CONFIG_KEXEC is not set
240# CONFIG_SMP is not set
241CONFIG_PREEMPT_NONE=y
242# CONFIG_PREEMPT_VOLUNTARY is not set
243# CONFIG_PREEMPT is not set
244
245#
246# Boot options
247#
248CONFIG_ZERO_PAGE_OFFSET=0x00001000
249CONFIG_BOOT_LINK_OFFSET=0x00800000
250# CONFIG_UBC_WAKEUP is not set
251# CONFIG_CMDLINE_BOOL is not set
252
253#
254# Bus options
255#
256# CONFIG_PCI is not set
257
258#
259# PCCARD (PCMCIA/CardBus) support
260#
261
262#
263# PCI Hotplug Support
264#
265
266#
267# Executable file formats
268#
269CONFIG_BINFMT_FLAT=y
270CONFIG_BINFMT_ZFLAT=y
271# CONFIG_BINFMT_SHARED_FLAT is not set
272# CONFIG_BINFMT_MISC is not set
273
274#
275# Power management options (EXPERIMENTAL)
276#
277# CONFIG_PM is not set
278
279#
280# Networking
281#
282# CONFIG_NET is not set
283
284#
285# Device Drivers
286#
287
288#
289# Generic Driver Options
290#
291# CONFIG_STANDALONE is not set
292# CONFIG_PREVENT_FIRMWARE_BUILD is not set
293# CONFIG_SYS_HYPERVISOR is not set
294
295#
296# Connector - unified userspace <-> kernelspace linker
297#
298
299#
300# Memory Technology Devices (MTD)
301#
302CONFIG_MTD=y
303# CONFIG_MTD_DEBUG is not set
304CONFIG_MTD_CONCAT=y
305CONFIG_MTD_PARTITIONS=y
306CONFIG_MTD_REDBOOT_PARTS=y
307CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
308# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set
309# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
310# CONFIG_MTD_CMDLINE_PARTS is not set
311
312#
313# User Modules And Translation Layers
314#
315CONFIG_MTD_CHAR=y
316CONFIG_MTD_BLOCK=y
317# CONFIG_FTL is not set
318# CONFIG_NFTL is not set
319# CONFIG_INFTL is not set
320# CONFIG_RFD_FTL is not set
321# CONFIG_SSFDC is not set
322
323#
324# RAM/ROM/Flash chip drivers
325#
326CONFIG_MTD_CFI=y
327# CONFIG_MTD_JEDECPROBE is not set
328CONFIG_MTD_GEN_PROBE=y
329# CONFIG_MTD_CFI_ADV_OPTIONS is not set
330CONFIG_MTD_MAP_BANK_WIDTH_1=y
331CONFIG_MTD_MAP_BANK_WIDTH_2=y
332CONFIG_MTD_MAP_BANK_WIDTH_4=y
333# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
334# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
335# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
336CONFIG_MTD_CFI_I1=y
337CONFIG_MTD_CFI_I2=y
338# CONFIG_MTD_CFI_I4 is not set
339# CONFIG_MTD_CFI_I8 is not set
340# CONFIG_MTD_CFI_INTELEXT is not set
341CONFIG_MTD_CFI_AMDSTD=y
342# CONFIG_MTD_CFI_STAA is not set
343CONFIG_MTD_CFI_UTIL=y
344# CONFIG_MTD_RAM is not set
345# CONFIG_MTD_ROM is not set
346# CONFIG_MTD_ABSENT is not set
347# CONFIG_MTD_OBSOLETE_CHIPS is not set
348
349#
350# Mapping drivers for chip access
351#
352# CONFIG_MTD_COMPLEX_MAPPINGS is not set
353CONFIG_MTD_PHYSMAP=y
354CONFIG_MTD_PHYSMAP_START=0xa0000000
355CONFIG_MTD_PHYSMAP_LEN=0x01000000
356CONFIG_MTD_PHYSMAP_BANKWIDTH=2
357# CONFIG_MTD_SOLUTIONENGINE is not set
358# CONFIG_MTD_UCLINUX is not set
359# CONFIG_MTD_PLATRAM is not set
360
361#
362# Self-contained MTD device drivers
363#
364# CONFIG_MTD_SLRAM is not set
365# CONFIG_MTD_PHRAM is not set
366# CONFIG_MTD_MTDRAM is not set
367# CONFIG_MTD_BLOCK2MTD is not set
368
369#
370# Disk-On-Chip Device Drivers
371#
372# CONFIG_MTD_DOC2000 is not set
373# CONFIG_MTD_DOC2001 is not set
374# CONFIG_MTD_DOC2001PLUS is not set
375
376#
377# NAND Flash Device Drivers
378#
379# CONFIG_MTD_NAND is not set
380
381#
382# OneNAND Flash Device Drivers
383#
384# CONFIG_MTD_ONENAND is not set
385
386#
387# Parallel port support
388#
389# CONFIG_PARPORT is not set
390
391#
392# Plug and Play support
393#
394
395#
396# Block devices
397#
398# CONFIG_BLK_DEV_COW_COMMON is not set
399# CONFIG_BLK_DEV_LOOP is not set
400# CONFIG_BLK_DEV_RAM is not set
401# CONFIG_BLK_DEV_INITRD is not set
402# CONFIG_CDROM_PKTCDVD is not set
403
404#
405# Misc devices
406#
407# CONFIG_TIFM_CORE is not set
408
409#
410# ATA/ATAPI/MFM/RLL support
411#
412# CONFIG_IDE is not set
413
414#
415# SCSI device support
416#
417# CONFIG_RAID_ATTRS is not set
418# CONFIG_SCSI is not set
419# CONFIG_SCSI_NETLINK is not set
420
421#
422# Serial ATA (prod) and Parallel ATA (experimental) drivers
423#
424# CONFIG_ATA is not set
425
426#
427# Multi-device support (RAID and LVM)
428#
429# CONFIG_MD is not set
430
431#
432# Fusion MPT device support
433#
434# CONFIG_FUSION is not set
435
436#
437# IEEE 1394 (FireWire) support
438#
439
440#
441# I2O device support
442#
443
444#
445# ISDN subsystem
446#
447
448#
449# Telephony Support
450#
451# CONFIG_PHONE is not set
452
453#
454# Input device support
455#
456CONFIG_INPUT=y
457# CONFIG_INPUT_FF_MEMLESS is not set
458
459#
460# Userland interfaces
461#
462# CONFIG_INPUT_MOUSEDEV is not set
463# CONFIG_INPUT_JOYDEV is not set
464# CONFIG_INPUT_TSDEV is not set
465# CONFIG_INPUT_EVDEV is not set
466# CONFIG_INPUT_EVBUG is not set
467
468#
469# Input Device Drivers
470#
471# CONFIG_INPUT_KEYBOARD is not set
472# CONFIG_INPUT_MOUSE is not set
473# CONFIG_INPUT_JOYSTICK is not set
474# CONFIG_INPUT_TOUCHSCREEN is not set
475# CONFIG_INPUT_MISC is not set
476
477#
478# Hardware I/O ports
479#
480# CONFIG_SERIO is not set
481# CONFIG_GAMEPORT is not set
482
483#
484# Character devices
485#
486# CONFIG_VT is not set
487# CONFIG_SERIAL_NONSTANDARD is not set
488
489#
490# Serial drivers
491#
492# CONFIG_SERIAL_8250 is not set
493
494#
495# Non-8250 serial port support
496#
497CONFIG_SERIAL_SH_SCI=y
498CONFIG_SERIAL_SH_SCI_NR_UARTS=3
499CONFIG_SERIAL_SH_SCI_CONSOLE=y
500CONFIG_SERIAL_CORE=y
501CONFIG_SERIAL_CORE_CONSOLE=y
502# CONFIG_UNIX98_PTYS is not set
503# CONFIG_LEGACY_PTYS is not set
504
505#
506# IPMI
507#
508# CONFIG_IPMI_HANDLER is not set
509
510#
511# Watchdog Cards
512#
513# CONFIG_WATCHDOG is not set
514# CONFIG_HW_RANDOM is not set
515# CONFIG_GEN_RTC is not set
516# CONFIG_DTLK is not set
517# CONFIG_R3964 is not set
518
519#
520# Ftape, the floppy tape device driver
521#
522# CONFIG_RAW_DRIVER is not set
523
524#
525# TPM devices
526#
527# CONFIG_TCG_TPM is not set
528
529#
530# I2C support
531#
532# CONFIG_I2C is not set
533
534#
535# SPI support
536#
537# CONFIG_SPI is not set
538# CONFIG_SPI_MASTER is not set
539
540#
541# Dallas's 1-wire bus
542#
543# CONFIG_W1 is not set
544
545#
546# Hardware Monitoring support
547#
548# CONFIG_HWMON is not set
549# CONFIG_HWMON_VID is not set
550
551#
552# Multimedia devices
553#
554# CONFIG_VIDEO_DEV is not set
555
556#
557# Digital Video Broadcasting Devices
558#
559
560#
561# Graphics support
562#
563# CONFIG_FIRMWARE_EDID is not set
564# CONFIG_FB is not set
565
566#
567# Sound
568#
569# CONFIG_SOUND is not set
570
571#
572# USB support
573#
574# CONFIG_USB_ARCH_HAS_HCD is not set
575# CONFIG_USB_ARCH_HAS_OHCI is not set
576# CONFIG_USB_ARCH_HAS_EHCI is not set
577
578#
579# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
580#
581
582#
583# USB Gadget Support
584#
585# CONFIG_USB_GADGET is not set
586
587#
588# MMC/SD Card support
589#
590# CONFIG_MMC is not set
591
592#
593# LED devices
594#
595# CONFIG_NEW_LEDS is not set
596
597#
598# LED drivers
599#
600
601#
602# LED Triggers
603#
604
605#
606# InfiniBand support
607#
608
609#
610# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
611#
612
613#
614# Real Time Clock
615#
616# CONFIG_RTC_CLASS is not set
617
618#
619# DMA Engine support
620#
621# CONFIG_DMA_ENGINE is not set
622
623#
624# DMA Clients
625#
626
627#
628# DMA Devices
629#
630
631#
632# File systems
633#
634# CONFIG_EXT2_FS is not set
635# CONFIG_EXT3_FS is not set
636# CONFIG_EXT4DEV_FS is not set
637# CONFIG_REISERFS_FS is not set
638# CONFIG_JFS_FS is not set
639# CONFIG_FS_POSIX_ACL is not set
640# CONFIG_XFS_FS is not set
641# CONFIG_GFS2_FS is not set
642# CONFIG_MINIX_FS is not set
643CONFIG_ROMFS_FS=y
644# CONFIG_INOTIFY is not set
645# CONFIG_QUOTA is not set
646# CONFIG_DNOTIFY is not set
647# CONFIG_AUTOFS_FS is not set
648# CONFIG_AUTOFS4_FS is not set
649# CONFIG_FUSE_FS is not set
650
651#
652# CD-ROM/DVD Filesystems
653#
654# CONFIG_ISO9660_FS is not set
655# CONFIG_UDF_FS is not set
656
657#
658# DOS/FAT/NT Filesystems
659#
660# CONFIG_MSDOS_FS is not set
661# CONFIG_VFAT_FS is not set
662# CONFIG_NTFS_FS is not set
663
664#
665# Pseudo filesystems
666#
667CONFIG_PROC_FS=y
668CONFIG_PROC_SYSCTL=y
669# CONFIG_SYSFS is not set
670# CONFIG_TMPFS is not set
671# CONFIG_HUGETLBFS is not set
672# CONFIG_HUGETLB_PAGE is not set
673CONFIG_RAMFS=y
674
675#
676# Miscellaneous filesystems
677#
678# CONFIG_ADFS_FS is not set
679# CONFIG_AFFS_FS is not set
680# CONFIG_HFS_FS is not set
681# CONFIG_HFSPLUS_FS is not set
682# CONFIG_BEFS_FS is not set
683# CONFIG_BFS_FS is not set
684# CONFIG_EFS_FS is not set
685# CONFIG_JFFS_FS is not set
686# CONFIG_JFFS2_FS is not set
687# CONFIG_CRAMFS is not set
688# CONFIG_VXFS_FS is not set
689# CONFIG_HPFS_FS is not set
690# CONFIG_QNX4FS_FS is not set
691# CONFIG_SYSV_FS is not set
692# CONFIG_UFS_FS is not set
693
694#
695# Partition Types
696#
697# CONFIG_PARTITION_ADVANCED is not set
698CONFIG_MSDOS_PARTITION=y
699
700#
701# Native Language Support
702#
703# CONFIG_NLS is not set
704
705#
706# Profiling support
707#
708# CONFIG_PROFILING is not set
709
710#
711# Kernel hacking
712#
713CONFIG_TRACE_IRQFLAGS_SUPPORT=y
714# CONFIG_PRINTK_TIME is not set
715# CONFIG_ENABLE_MUST_CHECK is not set
716# CONFIG_MAGIC_SYSRQ is not set
717# CONFIG_UNUSED_SYMBOLS is not set
718# CONFIG_DEBUG_KERNEL is not set
719CONFIG_LOG_BUF_SHIFT=14
720# CONFIG_DEBUG_BUGVERBOSE is not set
721# CONFIG_UNWIND_INFO is not set
722# CONFIG_HEADERS_CHECK is not set
723# CONFIG_SH_STANDARD_BIOS is not set
724# CONFIG_EARLY_SCIF_CONSOLE is not set
725# CONFIG_KGDB is not set
726
727#
728# Security options
729#
730# CONFIG_KEYS is not set
731
732#
733# Cryptographic options
734#
735# CONFIG_CRYPTO is not set
736
737#
738# Library routines
739#
740# CONFIG_CRC_CCITT is not set
741# CONFIG_CRC16 is not set
742CONFIG_CRC32=y
743# CONFIG_LIBCRC32C is not set
744CONFIG_ZLIB_INFLATE=y
diff --git a/arch/sh/drivers/push-switch.c b/arch/sh/drivers/push-switch.c
index f2b9157c314f..b3d20c0e021f 100644
--- a/arch/sh/drivers/push-switch.c
+++ b/arch/sh/drivers/push-switch.c
@@ -14,7 +14,7 @@
14#include <asm/push-switch.h> 14#include <asm/push-switch.h>
15 15
16#define DRV_NAME "push-switch" 16#define DRV_NAME "push-switch"
17#define DRV_VERSION "0.1.0" 17#define DRV_VERSION "0.1.1"
18 18
19static ssize_t switch_show(struct device *dev, 19static ssize_t switch_show(struct device *dev,
20 struct device_attribute *attr, 20 struct device_attribute *attr,
@@ -32,10 +32,10 @@ static void switch_timer(unsigned long data)
32 schedule_work(&psw->work); 32 schedule_work(&psw->work);
33} 33}
34 34
35static void switch_work_handler(void *data) 35static void switch_work_handler(struct work_struct *work)
36{ 36{
37 struct platform_device *pdev = data; 37 struct push_switch *psw = container_of(work, struct push_switch, work);
38 struct push_switch *psw = platform_get_drvdata(pdev); 38 struct platform_device *pdev = psw->pdev;
39 39
40 psw->state = 0; 40 psw->state = 0;
41 41
@@ -76,12 +76,15 @@ static int switch_drv_probe(struct platform_device *pdev)
76 } 76 }
77 } 77 }
78 78
79 INIT_WORK(&psw->work, switch_work_handler, pdev); 79 INIT_WORK(&psw->work, switch_work_handler);
80 init_timer(&psw->debounce); 80 init_timer(&psw->debounce);
81 81
82 psw->debounce.function = switch_timer; 82 psw->debounce.function = switch_timer;
83 psw->debounce.data = (unsigned long)psw; 83 psw->debounce.data = (unsigned long)psw;
84 84
85 /* Workqueue API brain-damage */
86 psw->pdev = pdev;
87
85 platform_set_drvdata(pdev, psw); 88 platform_set_drvdata(pdev, psw);
86 89
87 return 0; 90 return 0;
diff --git a/arch/sh/kernel/cpu/Makefile b/arch/sh/kernel/cpu/Makefile
index 0582e6712b79..d055a3ea6b4b 100644
--- a/arch/sh/kernel/cpu/Makefile
+++ b/arch/sh/kernel/cpu/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_CPU_SH2) = sh2/
6obj-$(CONFIG_CPU_SH2A) = sh2a/ 6obj-$(CONFIG_CPU_SH2A) = sh2a/
7obj-$(CONFIG_CPU_SH3) = sh3/ 7obj-$(CONFIG_CPU_SH3) = sh3/
8obj-$(CONFIG_CPU_SH4) = sh4/ 8obj-$(CONFIG_CPU_SH4) = sh4/
9obj-$(CONFIG_CPU_SH4A) += sh4a/
9 10
10obj-$(CONFIG_UBC_WAKEUP) += ubc.o 11obj-$(CONFIG_UBC_WAKEUP) += ubc.o
11obj-$(CONFIG_SH_ADC) += adc.o 12obj-$(CONFIG_SH_ADC) += adc.o
diff --git a/arch/sh/kernel/cpu/sh2/entry.S b/arch/sh/kernel/cpu/sh2/entry.S
index 34d51b3745ea..d51fa5e9904a 100644
--- a/arch/sh/kernel/cpu/sh2/entry.S
+++ b/arch/sh/kernel/cpu/sh2/entry.S
@@ -177,15 +177,21 @@ interrupt_entry:
1777: .long do_IRQ 1777: .long do_IRQ
1788: .long do_exception_error 1788: .long do_exception_error
179 179
180trap_entry: 180trap_entry:
181 add #-0x10,r9 181 /* verbose BUG trapa entry check */
182 mov #0x3e,r8
183 cmp/ge r8,r9
184 bf/s 1f
185 add #-0x10,r9
186 add #0x10,r9
1871:
182 shll2 r9 ! TRA 188 shll2 r9 ! TRA
183 mov #OFF_TRA,r8 189 mov #OFF_TRA,r8
184 add r15,r8 190 add r15,r8
185 mov.l r9,@r8 191 mov.l r9,@r8
186 mov r9,r8 192 mov r9,r8
187#ifdef CONFIG_TRACE_IRQFLAGS 193#ifdef CONFIG_TRACE_IRQFLAGS
188 mov.l 5f, r9 194 mov.l 2f, r9
189 jsr @r9 195 jsr @r9
190 nop 196 nop
191#endif 197#endif
@@ -194,12 +200,8 @@ trap_entry:
194 nop 200 nop
195 201
196 .align 2 202 .align 2
1971: .long syscall_exit
1982: .long break_point_trap_software
1993: .long NR_syscalls
2004: .long sys_call_table
201#ifdef CONFIG_TRACE_IRQFLAGS 203#ifdef CONFIG_TRACE_IRQFLAGS
2025: .long trace_hardirqs_on 2042: .long trace_hardirqs_on
203#endif 205#endif
204 206
205#if defined(CONFIG_SH_STANDARD_BIOS) 207#if defined(CONFIG_SH_STANDARD_BIOS)
@@ -264,7 +266,7 @@ ENTRY(address_error_handler)
264restore_all: 266restore_all:
265 cli 267 cli
266#ifdef CONFIG_TRACE_IRQFLAGS 268#ifdef CONFIG_TRACE_IRQFLAGS
267 mov.l 3f, r0 269 mov.l 1f, r0
268 jsr @r0 270 jsr @r0
269 nop 271 nop
270#endif 272#endif
@@ -309,20 +311,14 @@ restore_all:
309 mov.l @r15,r15 311 mov.l @r15,r15
310 rte 312 rte
311 nop 313 nop
3122:
313 mov.l 1f,r8
314 mov.l 2f,r9
315 jmp @r9
316 lds r8,pr
317 314
318 .align 2 315#ifdef CONFIG_TRACE_IRQFLAGS
3161: .long trace_hardirqs_off
317#endif
319$current_thread_info: 318$current_thread_info:
320 .long __current_thread_info 319 .long __current_thread_info
321$cpu_mode: 320$cpu_mode:
322 .long __cpu_mode 321 .long __cpu_mode
323#ifdef CONFIG_TRACE_IRQFLAGS
3243: .long trace_hardirqs_off
325#endif
326 322
327! common exception handler 323! common exception handler
328#include "../../entry-common.S" 324#include "../../entry-common.S"
diff --git a/arch/sh/kernel/cpu/sh2/setup-sh7619.c b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
index 82c2d905152f..79283e6c1d8f 100644
--- a/arch/sh/kernel/cpu/sh2/setup-sh7619.c
+++ b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
@@ -51,3 +51,44 @@ static int __init sh7619_devices_setup(void)
51 ARRAY_SIZE(sh7619_devices)); 51 ARRAY_SIZE(sh7619_devices));
52} 52}
53__initcall(sh7619_devices_setup); 53__initcall(sh7619_devices_setup);
54
55#define INTC_IPRC 0xf8080000UL
56#define INTC_IPRD 0xf8080002UL
57
58#define CMI0_IRQ 86
59
60#define SCIF0_ERI_IRQ 88
61#define SCIF0_RXI_IRQ 89
62#define SCIF0_BRI_IRQ 90
63#define SCIF0_TXI_IRQ 91
64
65#define SCIF1_ERI_IRQ 92
66#define SCIF1_RXI_IRQ 93
67#define SCIF1_BRI_IRQ 94
68#define SCIF1_TXI_IRQ 95
69
70#define SCIF2_BRI_IRQ 96
71#define SCIF2_ERI_IRQ 97
72#define SCIF2_RXI_IRQ 98
73#define SCIF2_TXI_IRQ 99
74
75static struct ipr_data sh7619_ipr_map[] = {
76 { CMI0_IRQ, INTC_IPRC, 1, 2 },
77 { SCIF0_ERI_IRQ, INTC_IPRD, 3, 3 },
78 { SCIF0_RXI_IRQ, INTC_IPRD, 3, 3 },
79 { SCIF0_BRI_IRQ, INTC_IPRD, 3, 3 },
80 { SCIF0_TXI_IRQ, INTC_IPRD, 3, 3 },
81 { SCIF1_ERI_IRQ, INTC_IPRD, 2, 3 },
82 { SCIF1_RXI_IRQ, INTC_IPRD, 2, 3 },
83 { SCIF1_BRI_IRQ, INTC_IPRD, 2, 3 },
84 { SCIF1_TXI_IRQ, INTC_IPRD, 2, 3 },
85 { SCIF2_ERI_IRQ, INTC_IPRD, 1, 3 },
86 { SCIF2_RXI_IRQ, INTC_IPRD, 1, 3 },
87 { SCIF2_BRI_IRQ, INTC_IPRD, 1, 3 },
88 { SCIF2_TXI_IRQ, INTC_IPRD, 1, 3 },
89};
90
91void __init init_IRQ_ipr(void)
92{
93 make_ipr_irq(sh7619_ipr_map, ARRAY_SIZE(sh7619_ipr_map));
94}
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
index cdfeef49e62e..4b60fcc7d667 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
@@ -17,22 +17,22 @@ static struct plat_sci_port sci_platform_data[] = {
17 .mapbase = 0xfffe8000, 17 .mapbase = 0xfffe8000,
18 .flags = UPF_BOOT_AUTOCONF, 18 .flags = UPF_BOOT_AUTOCONF,
19 .type = PORT_SCIF, 19 .type = PORT_SCIF,
20 .irqs = { 240, 241, 242, 243}, 20 .irqs = { 241, 242, 243, 240},
21 }, { 21 }, {
22 .mapbase = 0xfffe8800, 22 .mapbase = 0xfffe8800,
23 .flags = UPF_BOOT_AUTOCONF, 23 .flags = UPF_BOOT_AUTOCONF,
24 .type = PORT_SCIF, 24 .type = PORT_SCIF,
25 .irqs = { 244, 245, 246, 247}, 25 .irqs = { 247, 244, 245, 246},
26 }, { 26 }, {
27 .mapbase = 0xfffe9000, 27 .mapbase = 0xfffe9000,
28 .flags = UPF_BOOT_AUTOCONF, 28 .flags = UPF_BOOT_AUTOCONF,
29 .type = PORT_SCIF, 29 .type = PORT_SCIF,
30 .irqs = { 248, 249, 250, 251}, 30 .irqs = { 249, 250, 251, 248},
31 }, { 31 }, {
32 .mapbase = 0xfffe9800, 32 .mapbase = 0xfffe9800,
33 .flags = UPF_BOOT_AUTOCONF, 33 .flags = UPF_BOOT_AUTOCONF,
34 .type = PORT_SCIF, 34 .type = PORT_SCIF,
35 .irqs = { 252, 253, 254, 255}, 35 .irqs = { 253, 254, 255, 252},
36 }, { 36 }, {
37 .flags = 0, 37 .flags = 0,
38 } 38 }
@@ -56,3 +56,57 @@ static int __init sh7206_devices_setup(void)
56 ARRAY_SIZE(sh7206_devices)); 56 ARRAY_SIZE(sh7206_devices));
57} 57}
58__initcall(sh7206_devices_setup); 58__initcall(sh7206_devices_setup);
59
60#define INTC_IPR08 0xfffe0c04UL
61#define INTC_IPR09 0xfffe0c06UL
62#define INTC_IPR14 0xfffe0c10UL
63
64#define CMI0_IRQ 140
65
66#define MTU1_TGI1A 164
67
68#define SCIF0_BRI_IRQ 240
69#define SCIF0_ERI_IRQ 241
70#define SCIF0_RXI_IRQ 242
71#define SCIF0_TXI_IRQ 243
72
73#define SCIF1_BRI_IRQ 244
74#define SCIF1_ERI_IRQ 245
75#define SCIF1_RXI_IRQ 246
76#define SCIF1_TXI_IRQ 247
77
78#define SCIF2_BRI_IRQ 248
79#define SCIF2_ERI_IRQ 249
80#define SCIF2_RXI_IRQ 250
81#define SCIF2_TXI_IRQ 251
82
83#define SCIF3_BRI_IRQ 252
84#define SCIF3_ERI_IRQ 253
85#define SCIF3_RXI_IRQ 254
86#define SCIF3_TXI_IRQ 255
87
88static struct ipr_data sh7206_ipr_map[] = {
89 { CMI0_IRQ, INTC_IPR08, 3, 2 },
90 { MTU2_TGI1A, INTC_IPR09, 1, 2 },
91 { SCIF0_ERI_IRQ, INTC_IPR14, 3, 3 },
92 { SCIF0_RXI_IRQ, INTC_IPR14, 3, 3 },
93 { SCIF0_BRI_IRQ, INTC_IPR14, 3, 3 },
94 { SCIF0_TXI_IRQ, INTC_IPR14, 3, 3 },
95 { SCIF1_ERI_IRQ, INTC_IPR14, 2, 3 },
96 { SCIF1_RXI_IRQ, INTC_IPR14, 2, 3 },
97 { SCIF1_BRI_IRQ, INTC_IPR14, 2, 3 },
98 { SCIF1_TXI_IRQ, INTC_IPR14, 2, 3 },
99 { SCIF2_ERI_IRQ, INTC_IPR14, 1, 3 },
100 { SCIF2_RXI_IRQ, INTC_IPR14, 1, 3 },
101 { SCIF2_BRI_IRQ, INTC_IPR14, 1, 3 },
102 { SCIF2_TXI_IRQ, INTC_IPR14, 1, 3 },
103 { SCIF3_ERI_IRQ, INTC_IPR14, 0, 3 },
104 { SCIF3_RXI_IRQ, INTC_IPR14, 0, 3 },
105 { SCIF3_BRI_IRQ, INTC_IPR14, 0, 3 },
106 { SCIF3_TXI_IRQ, INTC_IPR14, 0, 3 },
107};
108
109void __init init_IRQ_ipr(void)
110{
111 make_ipr_irq(sh7206_ipr_map, ARRAY_SIZE(sh7206_ipr_map));
112}
diff --git a/arch/sh/kernel/cpu/sh4/Makefile b/arch/sh/kernel/cpu/sh4/Makefile
index 6e415baf04b4..19ca68c71884 100644
--- a/arch/sh/kernel/cpu/sh4/Makefile
+++ b/arch/sh/kernel/cpu/sh4/Makefile
@@ -12,17 +12,12 @@ obj-$(CONFIG_SH_STORE_QUEUES) += sq.o
12obj-$(CONFIG_CPU_SUBTYPE_SH7750) += setup-sh7750.o 12obj-$(CONFIG_CPU_SUBTYPE_SH7750) += setup-sh7750.o
13obj-$(CONFIG_CPU_SUBTYPE_SH7751) += setup-sh7750.o 13obj-$(CONFIG_CPU_SUBTYPE_SH7751) += setup-sh7750.o
14obj-$(CONFIG_CPU_SUBTYPE_SH7760) += setup-sh7760.o 14obj-$(CONFIG_CPU_SUBTYPE_SH7760) += setup-sh7760.o
15obj-$(CONFIG_CPU_SUBTYPE_SH7770) += setup-sh7770.o
16obj-$(CONFIG_CPU_SUBTYPE_SH7780) += setup-sh7780.o
17obj-$(CONFIG_CPU_SUBTYPE_SH73180) += setup-sh73180.o
18obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o
19obj-$(CONFIG_CPU_SUBTYPE_SH4_202) += setup-sh4-202.o 15obj-$(CONFIG_CPU_SUBTYPE_SH4_202) += setup-sh4-202.o
20 16
21# Primary on-chip clocks (common) 17# Primary on-chip clocks (common)
18ifndef CONFIG_CPU_SH4A
22clock-$(CONFIG_CPU_SH4) := clock-sh4.o 19clock-$(CONFIG_CPU_SH4) := clock-sh4.o
23clock-$(CONFIG_CPU_SUBTYPE_SH73180) := clock-sh73180.o 20endif
24clock-$(CONFIG_CPU_SUBTYPE_SH7770) := clock-sh7770.o
25clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o
26 21
27# Additional clocks by subtype 22# Additional clocks by subtype
28clock-$(CONFIG_CPU_SUBTYPE_SH4_202) += clock-sh4-202.o 23clock-$(CONFIG_CPU_SUBTYPE_SH4_202) += clock-sh4-202.o
diff --git a/arch/sh/kernel/cpu/sh4/probe.c b/arch/sh/kernel/cpu/sh4/probe.c
index afe0f1b1c030..9031a22a2ce7 100644
--- a/arch/sh/kernel/cpu/sh4/probe.c
+++ b/arch/sh/kernel/cpu/sh4/probe.c
@@ -119,11 +119,20 @@ int __init detect_cpu_and_cache_system(void)
119 break; 119 break;
120 case 0x3000: 120 case 0x3000:
121 case 0x3003: 121 case 0x3003:
122 case 0x3009:
122 cpu_data->type = CPU_SH7343; 123 cpu_data->type = CPU_SH7343;
123 cpu_data->icache.ways = 4; 124 cpu_data->icache.ways = 4;
124 cpu_data->dcache.ways = 4; 125 cpu_data->dcache.ways = 4;
125 cpu_data->flags |= CPU_HAS_LLSC; 126 cpu_data->flags |= CPU_HAS_LLSC;
126 break; 127 break;
128 case 0x3008:
129 if (prr == 0xa0) {
130 cpu_data->type = CPU_SH7722;
131 cpu_data->icache.ways = 4;
132 cpu_data->dcache.ways = 4;
133 cpu_data->flags |= CPU_HAS_LLSC;
134 }
135 break;
127 case 0x8000: 136 case 0x8000:
128 cpu_data->type = CPU_ST40RA; 137 cpu_data->type = CPU_ST40RA;
129 cpu_data->flags |= CPU_HAS_FPU; 138 cpu_data->flags |= CPU_HAS_FPU;
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7750.c b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
index bbcb06f18b04..cbac27634c0b 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7750.c
+++ b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
@@ -14,6 +14,36 @@
14#include <linux/io.h> 14#include <linux/io.h>
15#include <asm/sci.h> 15#include <asm/sci.h>
16 16
17static struct resource rtc_resources[] = {
18 [0] = {
19 .start = 0xffc80000,
20 .end = 0xffc80000 + 0x58 - 1,
21 .flags = IORESOURCE_IO,
22 },
23 [1] = {
24 /* Period IRQ */
25 .start = 21,
26 .flags = IORESOURCE_IRQ,
27 },
28 [2] = {
29 /* Carry IRQ */
30 .start = 22,
31 .flags = IORESOURCE_IRQ,
32 },
33 [3] = {
34 /* Alarm IRQ */
35 .start = 20,
36 .flags = IORESOURCE_IRQ,
37 },
38};
39
40static struct platform_device rtc_device = {
41 .name = "sh-rtc",
42 .id = -1,
43 .num_resources = ARRAY_SIZE(rtc_resources),
44 .resource = rtc_resources,
45};
46
17static struct plat_sci_port sci_platform_data[] = { 47static struct plat_sci_port sci_platform_data[] = {
18 { 48 {
19 .mapbase = 0xffe00000, 49 .mapbase = 0xffe00000,
@@ -39,6 +69,7 @@ static struct platform_device sci_device = {
39}; 69};
40 70
41static struct platform_device *sh7750_devices[] __initdata = { 71static struct platform_device *sh7750_devices[] __initdata = {
72 &rtc_device,
42 &sci_device, 73 &sci_device,
43}; 74};
44 75
diff --git a/arch/sh/kernel/cpu/sh4/sq.c b/arch/sh/kernel/cpu/sh4/sq.c
index 0c9ea38d2caa..d7fff752e569 100644
--- a/arch/sh/kernel/cpu/sh4/sq.c
+++ b/arch/sh/kernel/cpu/sh4/sq.c
@@ -111,8 +111,9 @@ static int __sq_remap(struct sq_mapping *map, unsigned long flags)
111 111
112 vma->phys_addr = map->addr; 112 vma->phys_addr = map->addr;
113 113
114 if (remap_area_pages((unsigned long)vma->addr, vma->phys_addr, 114 if (ioremap_page_range((unsigned long)vma->addr,
115 map->size, flags)) { 115 (unsigned long)vma->addr + map->size,
116 vma->phys_addr, __pgprot(flags))) {
116 vunmap(vma->addr); 117 vunmap(vma->addr);
117 return -EAGAIN; 118 return -EAGAIN;
118 } 119 }
@@ -176,7 +177,7 @@ unsigned long sq_remap(unsigned long phys, unsigned int size,
176 177
177 map->sq_addr = P4SEG_STORE_QUE + (page << PAGE_SHIFT); 178 map->sq_addr = P4SEG_STORE_QUE + (page << PAGE_SHIFT);
178 179
179 ret = __sq_remap(map, flags); 180 ret = __sq_remap(map, pgprot_val(PAGE_KERNEL_NOCACHE) | flags);
180 if (unlikely(ret != 0)) 181 if (unlikely(ret != 0))
181 goto out; 182 goto out;
182 183
diff --git a/arch/sh/kernel/cpu/sh4a/Makefile b/arch/sh/kernel/cpu/sh4a/Makefile
new file mode 100644
index 000000000000..a8f493f2f21f
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/Makefile
@@ -0,0 +1,19 @@
1#
2# Makefile for the Linux/SuperH SH-4 backends.
3#
4
5# CPU subtype setup
6obj-$(CONFIG_CPU_SUBTYPE_SH7770) += setup-sh7770.o
7obj-$(CONFIG_CPU_SUBTYPE_SH7780) += setup-sh7780.o
8obj-$(CONFIG_CPU_SUBTYPE_SH73180) += setup-sh73180.o
9obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o
10obj-$(CONFIG_CPU_SUBTYPE_SH7722) += setup-sh7722.o
11
12# Primary on-chip clocks (common)
13clock-$(CONFIG_CPU_SUBTYPE_SH73180) := clock-sh73180.o
14clock-$(CONFIG_CPU_SUBTYPE_SH7770) := clock-sh7770.o
15clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o
16clock-$(CONFIG_CPU_SUBTYPE_SH7343) := clock-sh7343.o
17clock-$(CONFIG_CPU_SUBTYPE_SH7722) := clock-sh7343.o
18
19obj-y += $(clock-y)
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh73180.c b/arch/sh/kernel/cpu/sh4a/clock-sh73180.c
index 2fa5cb2ae68d..2fa5cb2ae68d 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh73180.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh73180.c
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
new file mode 100644
index 000000000000..1707a213f0cf
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
@@ -0,0 +1,99 @@
1/*
2 * arch/sh/kernel/cpu/sh4/clock-sh7343.c
3 *
4 * SH7343/SH7722 support for the clock framework
5 *
6 * Copyright (C) 2006 Paul Mundt
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/io.h>
15#include <asm/clock.h>
16#include <asm/freq.h>
17
18/*
19 * SH7343/SH7722 uses a common set of multipliers and divisors, so this
20 * is quite simple..
21 */
22static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
23static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
24
25#define pll_calc() (((ctrl_inl(FRQCR) >> 24) & 0x1f) + 1)
26
27static void master_clk_init(struct clk *clk)
28{
29 clk->parent = clk_get(NULL, "cpu_clk");
30}
31
32static void master_clk_recalc(struct clk *clk)
33{
34 int idx = (ctrl_inl(FRQCR) & 0x000f);
35 clk->rate *= clk->parent->rate * multipliers[idx] / divisors[idx];
36}
37
38static struct clk_ops sh7343_master_clk_ops = {
39 .init = master_clk_init,
40 .recalc = master_clk_recalc,
41};
42
43static void module_clk_init(struct clk *clk)
44{
45 clk->parent = NULL;
46 clk->rate = CONFIG_SH_PCLK_FREQ;
47}
48
49static struct clk_ops sh7343_module_clk_ops = {
50 .init = module_clk_init,
51};
52
53static void bus_clk_init(struct clk *clk)
54{
55 clk->parent = clk_get(NULL, "cpu_clk");
56}
57
58static void bus_clk_recalc(struct clk *clk)
59{
60 int idx = (ctrl_inl(FRQCR) >> 8) & 0x000f;
61 clk->rate = clk->parent->rate * multipliers[idx] / divisors[idx];
62}
63
64static struct clk_ops sh7343_bus_clk_ops = {
65 .init = bus_clk_init,
66 .recalc = bus_clk_recalc,
67};
68
69static void cpu_clk_init(struct clk *clk)
70{
71 clk->parent = clk_get(NULL, "module_clk");
72 clk->flags |= CLK_RATE_PROPAGATES;
73 clk_set_rate(clk, clk_get_rate(clk));
74}
75
76static void cpu_clk_recalc(struct clk *clk)
77{
78 int idx = (ctrl_inl(FRQCR) >> 20) & 0x000f;
79 clk->rate = clk->parent->rate * pll_calc() *
80 multipliers[idx] / divisors[idx];
81}
82
83static struct clk_ops sh7343_cpu_clk_ops = {
84 .init = cpu_clk_init,
85 .recalc = cpu_clk_recalc,
86};
87
88static struct clk_ops *sh7343_clk_ops[] = {
89 &sh7343_master_clk_ops,
90 &sh7343_module_clk_ops,
91 &sh7343_bus_clk_ops,
92 &sh7343_cpu_clk_ops,
93};
94
95void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
96{
97 if (idx < ARRAY_SIZE(sh7343_clk_ops))
98 *ops = sh7343_clk_ops[idx];
99}
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh7770.c b/arch/sh/kernel/cpu/sh4a/clock-sh7770.c
index c8694bac6477..c8694bac6477 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh7770.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7770.c
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh7780.c b/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
index 9e6a216750c8..9e6a216750c8 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh7780.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh73180.c b/arch/sh/kernel/cpu/sh4a/setup-sh73180.c
index cc9ea1e2e5df..cc9ea1e2e5df 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh73180.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh73180.c
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7343.c b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
index 91d61cf91ba1..91d61cf91ba1 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7343.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
new file mode 100644
index 000000000000..1143fbf65faf
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
@@ -0,0 +1,80 @@
1/*
2 * SH7722 Setup
3 *
4 * Copyright (C) 2006 Paul Mundt
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/platform_device.h>
11#include <linux/init.h>
12#include <linux/serial.h>
13#include <asm/sci.h>
14
15static struct plat_sci_port sci_platform_data[] = {
16 {
17 .mapbase = 0xffe00000,
18 .flags = UPF_BOOT_AUTOCONF,
19 .type = PORT_SCIF,
20 .irqs = { 80, 81, 83, 82 },
21 }, {
22 .flags = 0,
23 }
24};
25
26static struct platform_device sci_device = {
27 .name = "sh-sci",
28 .id = -1,
29 .dev = {
30 .platform_data = sci_platform_data,
31 },
32};
33
34static struct platform_device *sh7722_devices[] __initdata = {
35 &sci_device,
36};
37
38static int __init sh7722_devices_setup(void)
39{
40 return platform_add_devices(sh7722_devices,
41 ARRAY_SIZE(sh7722_devices));
42}
43__initcall(sh7722_devices_setup);
44
45static struct ipr_data sh7722_ipr_map[] = {
46 /* IRQ, IPR-idx, shift, prio */
47 { 16, 0, 12, 2 }, /* TMU0 */
48 { 17, 0, 8, 2 }, /* TMU1 */
49 { 80, 6, 12, 3 }, /* SCIF ERI */
50 { 81, 6, 12, 3 }, /* SCIF RXI */
51 { 82, 6, 12, 3 }, /* SCIF BRI */
52 { 83, 6, 12, 3 }, /* SCIF TXI */
53};
54
55static unsigned long ipr_offsets[] = {
56 0xa4080000, /* 0: IPRA */
57 0xa4080004, /* 1: IPRB */
58 0xa4080008, /* 2: IPRC */
59 0xa408000c, /* 3: IPRD */
60 0xa4080010, /* 4: IPRE */
61 0xa4080014, /* 5: IPRF */
62 0xa4080018, /* 6: IPRG */
63 0xa408001c, /* 7: IPRH */
64 0xa4080020, /* 8: IPRI */
65 0xa4080024, /* 9: IPRJ */
66 0xa4080028, /* 10: IPRK */
67 0xa408002c, /* 11: IPRL */
68};
69
70unsigned int map_ipridx_to_addr(int idx)
71{
72 if (unlikely(idx >= ARRAY_SIZE(ipr_offsets)))
73 return 0;
74 return ipr_offsets[idx];
75}
76
77void __init init_IRQ_ipr(void)
78{
79 make_ipr_irq(sh7722_ipr_map, ARRAY_SIZE(sh7722_ipr_map));
80}
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7770.c b/arch/sh/kernel/cpu/sh4a/setup-sh7770.c
index 6a04cc5f5aca..6a04cc5f5aca 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7770.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7770.c
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7780.c b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
index 9aeaa2ddaa28..9aeaa2ddaa28 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7780.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
diff --git a/arch/sh/kernel/early_printk.c b/arch/sh/kernel/early_printk.c
index 60340823798a..560b91cdd15c 100644
--- a/arch/sh/kernel/early_printk.c
+++ b/arch/sh/kernel/early_printk.c
@@ -144,16 +144,16 @@ static struct console *early_console =
144 ; 144 ;
145 145
146static int __initdata keep_early; 146static int __initdata keep_early;
147static int early_console_initialized;
147 148
148int __init setup_early_printk(char *opt) 149int __init setup_early_printk(char *buf)
149{ 150{
150 char *space; 151 if (!buf)
151 char buf[256]; 152 return 0;
152 153
153 strlcpy(buf, opt, sizeof(buf)); 154 if (early_console_initialized)
154 space = strchr(buf, ' '); 155 return 0;
155 if (space) 156 early_console_initialized = 1;
156 *space = 0;
157 157
158 if (strstr(buf, "keep")) 158 if (strstr(buf, "keep"))
159 keep_early = 1; 159 keep_early = 1;
@@ -175,12 +175,14 @@ int __init setup_early_printk(char *opt)
175 if (likely(early_console)) 175 if (likely(early_console))
176 register_console(early_console); 176 register_console(early_console);
177 177
178 return 1; 178 return 0;
179} 179}
180__setup("earlyprintk=", setup_early_printk); 180early_param("earlyprintk", setup_early_printk);
181 181
182void __init disable_early_printk(void) 182void __init disable_early_printk(void)
183{ 183{
184 if (!early_console_initialized || !early_console)
185 return;
184 if (!keep_early) { 186 if (!keep_early) {
185 printk("disabling early console\n"); 187 printk("disabling early console\n");
186 unregister_console(early_console); 188 unregister_console(early_console);
diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S
index 29136a35d7c7..fc279aeb73ab 100644
--- a/arch/sh/kernel/entry-common.S
+++ b/arch/sh/kernel/entry-common.S
@@ -79,18 +79,29 @@ debug_kernel_sw:
79 .align 2 79 .align 2
803: .long kgdb_handle_exception 803: .long kgdb_handle_exception
81#endif /* CONFIG_SH_KGDB */ 81#endif /* CONFIG_SH_KGDB */
82 82#ifdef CONFIG_SH_STANDARD_BIOS
83 bra debug_kernel_fw
84 nop
85#endif
83#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */ 86#endif /* CONFIG_SH_STANDARD_BIOS || CONFIG_SH_KGDB */
84 87
85
86 .align 2 88 .align 2
87debug_trap: 89debug_trap:
88#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB) 90#if defined(CONFIG_SH_STANDARD_BIOS) || defined(CONFIG_SH_KGDB)
91 mov r8, r0
92 shlr2 r0
93 cmp/eq #0x3f, r0 ! sh_bios() trap
94 bf 1f
95#ifdef CONFIG_SH_KGDB
96 cmp/eq #0xff, r0 ! XXX: KGDB trap, fix for SH-2.
97 bf 1f
98#endif
89 mov #OFF_SR, r0 99 mov #OFF_SR, r0
90 mov.l @(r0,r15), r0 ! get status register 100 mov.l @(r0,r15), r0 ! get status register
91 shll r0 101 shll r0
92 shll r0 ! kernel space? 102 shll r0 ! kernel space?
93 bt/s debug_kernel 103 bt/s debug_kernel
1041:
94#endif 105#endif
95 mov.l @r15, r0 ! Restore R0 value 106 mov.l @r15, r0 ! Restore R0 value
96 mov.l 1f, r8 107 mov.l 1f, r8
diff --git a/arch/sh/kernel/head.S b/arch/sh/kernel/head.S
index 6aca4bc6ec5d..71a3ad7d283e 100644
--- a/arch/sh/kernel/head.S
+++ b/arch/sh/kernel/head.S
@@ -33,7 +33,8 @@ ENTRY(empty_zero_page)
33 .long 0x00360000 /* INITRD_START */ 33 .long 0x00360000 /* INITRD_START */
34 .long 0x000a0000 /* INITRD_SIZE */ 34 .long 0x000a0000 /* INITRD_SIZE */
35 .long 0 35 .long 0
36 .balign PAGE_SIZE,0,PAGE_SIZE 361:
37 .skip PAGE_SIZE - empty_zero_page - 1b
37 38
38 .text 39 .text
39/* 40/*
diff --git a/arch/sh/kernel/process.c b/arch/sh/kernel/process.c
index f3e2631be144..486c06e18033 100644
--- a/arch/sh/kernel/process.c
+++ b/arch/sh/kernel/process.c
@@ -470,9 +470,10 @@ unsigned long get_wchan(struct task_struct *p)
470 */ 470 */
471 pc = thread_saved_pc(p); 471 pc = thread_saved_pc(p);
472 if (in_sched_functions(pc)) { 472 if (in_sched_functions(pc)) {
473 schedule_frame = ((unsigned long *)(long)p->thread.sp)[1]; 473 schedule_frame = (unsigned long)p->thread.sp;
474 return (unsigned long)((unsigned long *)schedule_frame)[1]; 474 return ((unsigned long *)schedule_frame)[21];
475 } 475 }
476
476 return pc; 477 return pc;
477} 478}
478 479
@@ -498,6 +499,16 @@ asmlinkage void break_point_trap_software(unsigned long r4, unsigned long r5,
498{ 499{
499 struct pt_regs *regs = RELOC_HIDE(&__regs, 0); 500 struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
500 501
502 /* Rewind */
501 regs->pc -= 2; 503 regs->pc -= 2;
504
505#ifdef CONFIG_BUG
506 if (__kernel_text_address(instruction_pointer(regs))) {
507 u16 insn = *(u16 *)instruction_pointer(regs);
508 if (insn == TRAPA_BUG_OPCODE)
509 handle_BUG(regs);
510 }
511#endif
512
502 force_sig(SIGTRAP, current); 513 force_sig(SIGTRAP, current);
503} 514}
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index f8dd6b7bfab0..225f9ea5cdd7 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -84,8 +84,7 @@ unsigned long memory_start, memory_end;
84 84
85static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE], 85static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
86 struct sh_machine_vector** mvp, 86 struct sh_machine_vector** mvp,
87 unsigned long *mv_io_base, 87 unsigned long *mv_io_base)
88 int *mv_mmio_enable)
89{ 88{
90 char c = ' ', *to = command_line, *from = COMMAND_LINE; 89 char c = ' ', *to = command_line, *from = COMMAND_LINE;
91 int len = 0; 90 int len = 0;
@@ -112,23 +111,6 @@ static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
112 } 111 }
113 } 112 }
114 113
115#ifdef CONFIG_EARLY_PRINTK
116 if (c == ' ' && !memcmp(from, "earlyprintk=", 12)) {
117 char *ep_end;
118
119 if (to != command_line)
120 to--;
121
122 from += 12;
123 ep_end = strchr(from, ' ');
124
125 setup_early_printk(from);
126 printk("early console enabled\n");
127
128 from = ep_end;
129 }
130#endif
131
132 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) { 114 if (c == ' ' && !memcmp(from, "sh_mv=", 6)) {
133 char* mv_end; 115 char* mv_end;
134 char* mv_comma; 116 char* mv_comma;
@@ -145,7 +127,6 @@ static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
145 int ints[3]; 127 int ints[3];
146 get_options(mv_comma+1, ARRAY_SIZE(ints), ints); 128 get_options(mv_comma+1, ARRAY_SIZE(ints), ints);
147 *mv_io_base = ints[1]; 129 *mv_io_base = ints[1];
148 *mv_mmio_enable = ints[2];
149 mv_len = mv_comma - from; 130 mv_len = mv_comma - from;
150 } else { 131 } else {
151 mv_len = mv_end - from; 132 mv_len = mv_end - from;
@@ -158,6 +139,7 @@ static inline void parse_cmdline (char ** cmdline_p, char mv_name[MV_NAME_SIZE],
158 139
159 *mvp = get_mv_byname(mv_name); 140 *mvp = get_mv_byname(mv_name);
160 } 141 }
142
161 c = *(from++); 143 c = *(from++);
162 if (!c) 144 if (!c)
163 break; 145 break;
@@ -177,9 +159,8 @@ static int __init sh_mv_setup(char **cmdline_p)
177 struct sh_machine_vector *mv = NULL; 159 struct sh_machine_vector *mv = NULL;
178 char mv_name[MV_NAME_SIZE] = ""; 160 char mv_name[MV_NAME_SIZE] = "";
179 unsigned long mv_io_base = 0; 161 unsigned long mv_io_base = 0;
180 int mv_mmio_enable = 0;
181 162
182 parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base, &mv_mmio_enable); 163 parse_cmdline(cmdline_p, mv_name, &mv, &mv_io_base);
183 164
184#ifdef CONFIG_SH_UNKNOWN 165#ifdef CONFIG_SH_UNKNOWN
185 if (mv == NULL) { 166 if (mv == NULL) {
@@ -258,6 +239,7 @@ void __init setup_arch(char **cmdline_p)
258 239
259 sh_mv_setup(cmdline_p); 240 sh_mv_setup(cmdline_p);
260 241
242
261 /* 243 /*
262 * Find the highest page frame number we have available 244 * Find the highest page frame number we have available
263 */ 245 */
@@ -305,6 +287,7 @@ void __init setup_arch(char **cmdline_p)
305 PFN_PHYS(pages)); 287 PFN_PHYS(pages));
306 } 288 }
307 289
290
308 /* 291 /*
309 * Reserve the kernel text and 292 * Reserve the kernel text and
310 * Reserve the bootmem bitmap. We do this in two steps (first step 293 * Reserve the bootmem bitmap. We do this in two steps (first step
@@ -325,14 +308,18 @@ void __init setup_arch(char **cmdline_p)
325 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0); 308 ROOT_DEV = MKDEV(RAMDISK_MAJOR, 0);
326 if (&__rd_start != &__rd_end) { 309 if (&__rd_start != &__rd_end) {
327 LOADER_TYPE = 1; 310 LOADER_TYPE = 1;
328 INITRD_START = PHYSADDR((unsigned long)&__rd_start) - __MEMORY_START; 311 INITRD_START = PHYSADDR((unsigned long)&__rd_start) -
329 INITRD_SIZE = (unsigned long)&__rd_end - (unsigned long)&__rd_start; 312 __MEMORY_START;
313 INITRD_SIZE = (unsigned long)&__rd_end -
314 (unsigned long)&__rd_start;
330 } 315 }
331 316
332 if (LOADER_TYPE && INITRD_START) { 317 if (LOADER_TYPE && INITRD_START) {
333 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) { 318 if (INITRD_START + INITRD_SIZE <= (max_low_pfn << PAGE_SHIFT)) {
334 reserve_bootmem_node(NODE_DATA(0), INITRD_START+__MEMORY_START, INITRD_SIZE); 319 reserve_bootmem_node(NODE_DATA(0), INITRD_START +
335 initrd_start = INITRD_START + PAGE_OFFSET + __MEMORY_START; 320 __MEMORY_START, INITRD_SIZE);
321 initrd_start = INITRD_START + PAGE_OFFSET +
322 __MEMORY_START;
336 initrd_end = initrd_start + INITRD_SIZE; 323 initrd_end = initrd_start + INITRD_SIZE;
337 } else { 324 } else {
338 printk("initrd extends beyond end of memory " 325 printk("initrd extends beyond end of memory "
@@ -404,7 +391,7 @@ static const char *cpu_name[] = {
404 [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501", 391 [CPU_SH4_202] = "SH4-202", [CPU_SH4_501] = "SH4-501",
405 [CPU_SH7770] = "SH7770", [CPU_SH7780] = "SH7780", 392 [CPU_SH7770] = "SH7770", [CPU_SH7780] = "SH7780",
406 [CPU_SH7781] = "SH7781", [CPU_SH7343] = "SH7343", 393 [CPU_SH7781] = "SH7781", [CPU_SH7343] = "SH7343",
407 [CPU_SH7785] = "SH7785", 394 [CPU_SH7785] = "SH7785", [CPU_SH7722] = "SH7722",
408 [CPU_SH_NONE] = "Unknown" 395 [CPU_SH_NONE] = "Unknown"
409}; 396};
410 397
diff --git a/arch/sh/kernel/sh_ksyms.c b/arch/sh/kernel/sh_ksyms.c
index ceee79143401..e6106239a0fe 100644
--- a/arch/sh/kernel/sh_ksyms.c
+++ b/arch/sh/kernel/sh_ksyms.c
@@ -70,13 +70,26 @@ DECLARE_EXPORT(__sdivsi3);
70DECLARE_EXPORT(__ashrdi3); 70DECLARE_EXPORT(__ashrdi3);
71DECLARE_EXPORT(__ashldi3); 71DECLARE_EXPORT(__ashldi3);
72DECLARE_EXPORT(__lshrdi3); 72DECLARE_EXPORT(__lshrdi3);
73DECLARE_EXPORT(__movstr);
74DECLARE_EXPORT(__movstrSI16); 73DECLARE_EXPORT(__movstrSI16);
74#if __GNUC__ == 4
75DECLARE_EXPORT(__movmem);
76#else
77DECLARE_EXPORT(__movstr);
78#endif
75 79
76#ifdef CONFIG_CPU_SH4 80#ifdef CONFIG_CPU_SH4
81#if __GNUC__ == 4
82DECLARE_EXPORT(__movmem_i4_even);
83DECLARE_EXPORT(__movmem_i4_odd);
84DECLARE_EXPORT(__movmemSI12_i4);
85DECLARE_EXPORT(__sdivsi3_i4i);
86DECLARE_EXPORT(__udiv_qrnnd_16);
87DECLARE_EXPORT(__udivsi3_i4i);
88#else /* GCC 3.x */
77DECLARE_EXPORT(__movstr_i4_even); 89DECLARE_EXPORT(__movstr_i4_even);
78DECLARE_EXPORT(__movstr_i4_odd); 90DECLARE_EXPORT(__movstr_i4_odd);
79DECLARE_EXPORT(__movstrSI12_i4); 91DECLARE_EXPORT(__movstrSI12_i4);
92#endif /* __GNUC__ == 4 */
80#endif 93#endif
81 94
82#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB) 95#if defined(CONFIG_CPU_SH4) || defined(CONFIG_SH7705_CACHE_32KB)
diff --git a/arch/sh/kernel/signal.c b/arch/sh/kernel/signal.c
index bb1c480a59c7..379c88bf5d9a 100644
--- a/arch/sh/kernel/signal.c
+++ b/arch/sh/kernel/signal.c
@@ -101,7 +101,7 @@ sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
101 */ 101 */
102 102
103#define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */ 103#define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
104#if defined(CONFIG_CPU_SH2) || defined(CONFIG_CPU_SH2A) 104#if defined(CONFIG_CPU_SH2)
105#define TRAP_NOARG 0xc320 /* Syscall w/no args (NR in R3) */ 105#define TRAP_NOARG 0xc320 /* Syscall w/no args (NR in R3) */
106#else 106#else
107#define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) */ 107#define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) */
diff --git a/arch/sh/kernel/sys_sh.c b/arch/sh/kernel/sys_sh.c
index 5083b6ed4b39..e18f183e1035 100644
--- a/arch/sh/kernel/sys_sh.c
+++ b/arch/sh/kernel/sys_sh.c
@@ -314,6 +314,12 @@ asmlinkage int sys_fadvise64_64_wrapper(int fd, u32 offset0, u32 offset1,
314#endif 314#endif
315} 315}
316 316
317#if defined(CONFIG_CPU_SH2) || defined(CONFIG_CPU_SH2A)
318#define SYSCALL_ARG3 "trapa #0x23"
319#else
320#define SYSCALL_ARG3 "trapa #0x13"
321#endif
322
317/* 323/*
318 * Do a system call from kernel instead of calling sys_execve so we 324 * Do a system call from kernel instead of calling sys_execve so we
319 * end up with proper pt_regs. 325 * end up with proper pt_regs.
@@ -324,7 +330,7 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])
324 register long __sc4 __asm__ ("r4") = (long) filename; 330 register long __sc4 __asm__ ("r4") = (long) filename;
325 register long __sc5 __asm__ ("r5") = (long) argv; 331 register long __sc5 __asm__ ("r5") = (long) argv;
326 register long __sc6 __asm__ ("r6") = (long) envp; 332 register long __sc6 __asm__ ("r6") = (long) envp;
327 __asm__ __volatile__ ("trapa #0x13" : "=z" (__sc0) 333 __asm__ __volatile__ (SYSCALL_ARG3 : "=z" (__sc0)
328 : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6) 334 : "0" (__sc0), "r" (__sc4), "r" (__sc5), "r" (__sc6)
329 : "memory"); 335 : "memory");
330 return __sc0; 336 return __sc0;
diff --git a/arch/sh/kernel/traps.c b/arch/sh/kernel/traps.c
index 3762d9dc2046..ec110157992d 100644
--- a/arch/sh/kernel/traps.c
+++ b/arch/sh/kernel/traps.c
@@ -19,6 +19,7 @@
19#include <linux/kallsyms.h> 19#include <linux/kallsyms.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/debug_locks.h> 21#include <linux/debug_locks.h>
22#include <linux/limits.h>
22#include <asm/system.h> 23#include <asm/system.h>
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24 25
@@ -129,6 +130,40 @@ static int die_if_no_fixup(const char * str, struct pt_regs * regs, long err)
129 return -EFAULT; 130 return -EFAULT;
130} 131}
131 132
133#ifdef CONFIG_BUG
134#ifdef CONFIG_DEBUG_BUGVERBOSE
135static inline void do_bug_verbose(struct pt_regs *regs)
136{
137 struct bug_frame f;
138 long len;
139
140 if (__copy_from_user(&f, (const void __user *)regs->pc,
141 sizeof(struct bug_frame)))
142 return;
143
144 len = __strnlen_user(f.file, PATH_MAX) - 1;
145 if (unlikely(len < 0 || len >= PATH_MAX))
146 f.file = "<bad filename>";
147 len = __strnlen_user(f.func, PATH_MAX) - 1;
148 if (unlikely(len < 0 || len >= PATH_MAX))
149 f.func = "<bad function>";
150
151 printk(KERN_ALERT "kernel BUG in %s() at %s:%d!\n",
152 f.func, f.file, f.line);
153}
154#else
155static inline void do_bug_verbose(struct pt_regs *regs)
156{
157}
158#endif /* CONFIG_DEBUG_BUGVERBOSE */
159#endif /* CONFIG_BUG */
160
161void handle_BUG(struct pt_regs *regs)
162{
163 do_bug_verbose(regs);
164 die("Kernel BUG", regs, TRAPA_BUG_OPCODE & 0xff);
165}
166
132/* 167/*
133 * handle an instruction that does an unaligned memory access by emulating the 168 * handle an instruction that does an unaligned memory access by emulating the
134 * desired behaviour 169 * desired behaviour
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S
index 77b4026d5688..f34bdcc33a7d 100644
--- a/arch/sh/kernel/vmlinux.lds.S
+++ b/arch/sh/kernel/vmlinux.lds.S
@@ -51,7 +51,7 @@ SECTIONS
51 } 51 }
52 52
53 . = ALIGN(PAGE_SIZE); 53 . = ALIGN(PAGE_SIZE);
54 .data.page_aligned : { *(.data.idt) } 54 .data.page_aligned : { *(.data.page_aligned) }
55 55
56 . = ALIGN(32); 56 . = ALIGN(32);
57 __per_cpu_start = .; 57 __per_cpu_start = .;
diff --git a/arch/sh/mm/Kconfig b/arch/sh/mm/Kconfig
index 4e0362f50384..29f4ee35c6dc 100644
--- a/arch/sh/mm/Kconfig
+++ b/arch/sh/mm/Kconfig
@@ -35,6 +35,9 @@ config CPU_SUBTYPE_ST40
35 select CPU_SH4 35 select CPU_SH4
36 select CPU_HAS_INTC2_IRQ 36 select CPU_HAS_INTC2_IRQ
37 37
38config CPU_SHX2
39 bool
40
38# 41#
39# Processor subtypes 42# Processor subtypes
40# 43#
@@ -180,6 +183,7 @@ config CPU_SUBTYPE_SH7780
180config CPU_SUBTYPE_SH7785 183config CPU_SUBTYPE_SH7785
181 bool "Support SH7785 processor" 184 bool "Support SH7785 processor"
182 select CPU_SH4A 185 select CPU_SH4A
186 select CPU_SHX2
183 select CPU_HAS_INTC2_IRQ 187 select CPU_HAS_INTC2_IRQ
184 188
185comment "SH4AL-DSP Processor Support" 189comment "SH4AL-DSP Processor Support"
@@ -192,6 +196,12 @@ config CPU_SUBTYPE_SH7343
192 bool "Support SH7343 processor" 196 bool "Support SH7343 processor"
193 select CPU_SH4AL_DSP 197 select CPU_SH4AL_DSP
194 198
199config CPU_SUBTYPE_SH7722
200 bool "Support SH7722 processor"
201 select CPU_SH4AL_DSP
202 select CPU_SHX2
203 select CPU_HAS_IPR_IRQ
204
195endmenu 205endmenu
196 206
197menu "Memory management options" 207menu "Memory management options"
@@ -250,7 +260,7 @@ config 32BIT
250 260
251config X2TLB 261config X2TLB
252 bool "Enable extended TLB mode" 262 bool "Enable extended TLB mode"
253 depends on CPU_SUBTYPE_SH7785 && MMU && EXPERIMENTAL 263 depends on CPU_SHX2 && MMU && EXPERIMENTAL
254 help 264 help
255 Selecting this option will enable the extended mode of the SH-X2 265 Selecting this option will enable the extended mode of the SH-X2
256 TLB. For legacy SH-X behaviour and interoperability, say N. For 266 TLB. For legacy SH-X behaviour and interoperability, say N. For
diff --git a/arch/sh/mm/cache-sh4.c b/arch/sh/mm/cache-sh4.c
index ae531affccbd..c6955157c989 100644
--- a/arch/sh/mm/cache-sh4.c
+++ b/arch/sh/mm/cache-sh4.c
@@ -107,7 +107,7 @@ void __init p3_cache_init(void)
107 107
108 emit_cache_params(); 108 emit_cache_params();
109 109
110 if (remap_area_pages(P3SEG, 0, PAGE_SIZE * 4, _PAGE_CACHABLE)) 110 if (ioremap_page_range(P3SEG, P3SEG + (PAGE_SIZE * 4), 0, PAGE_KERNEL))
111 panic("%s failed.", __FUNCTION__); 111 panic("%s failed.", __FUNCTION__);
112 112
113 for (i = 0; i < cpu_data->dcache.n_aliases; i++) 113 for (i = 0; i < cpu_data->dcache.n_aliases; i++)
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 59f4cc18235b..29bd37b1488e 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -77,6 +77,7 @@ void show_mem(void)
77 printk("%d pages swap cached\n",cached); 77 printk("%d pages swap cached\n",cached);
78} 78}
79 79
80#ifdef CONFIG_MMU
80static void set_pte_phys(unsigned long addr, unsigned long phys, pgprot_t prot) 81static void set_pte_phys(unsigned long addr, unsigned long phys, pgprot_t prot)
81{ 82{
82 pgd_t *pgd; 83 pgd_t *pgd;
@@ -139,6 +140,7 @@ void __set_fixmap(enum fixed_addresses idx, unsigned long phys, pgprot_t prot)
139 140
140 set_pte_phys(address, phys, prot); 141 set_pte_phys(address, phys, prot);
141} 142}
143#endif /* CONFIG_MMU */
142 144
143/* References to section boundaries */ 145/* References to section boundaries */
144 146
diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c
index 11d54c149821..90b494a0cf45 100644
--- a/arch/sh/mm/ioremap.c
+++ b/arch/sh/mm/ioremap.c
@@ -16,97 +16,13 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/mm.h> 17#include <linux/mm.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <asm/io.h> 19#include <linux/io.h>
20#include <asm/page.h> 20#include <asm/page.h>
21#include <asm/pgalloc.h> 21#include <asm/pgalloc.h>
22#include <asm/addrspace.h> 22#include <asm/addrspace.h>
23#include <asm/cacheflush.h> 23#include <asm/cacheflush.h>
24#include <asm/tlbflush.h> 24#include <asm/tlbflush.h>
25 25
26static inline void remap_area_pte(pte_t * pte, unsigned long address,
27 unsigned long size, unsigned long phys_addr, unsigned long flags)
28{
29 unsigned long end;
30 unsigned long pfn;
31 pgprot_t pgprot = __pgprot(pgprot_val(PAGE_KERNEL_NOCACHE) | flags);
32
33 address &= ~PMD_MASK;
34 end = address + size;
35 if (end > PMD_SIZE)
36 end = PMD_SIZE;
37 if (address >= end)
38 BUG();
39 pfn = phys_addr >> PAGE_SHIFT;
40 do {
41 if (!pte_none(*pte)) {
42 printk("remap_area_pte: page already exists\n");
43 BUG();
44 }
45 set_pte(pte, pfn_pte(pfn, pgprot));
46 address += PAGE_SIZE;
47 pfn++;
48 pte++;
49 } while (address && (address < end));
50}
51
52static inline int remap_area_pmd(pmd_t * pmd, unsigned long address,
53 unsigned long size, unsigned long phys_addr, unsigned long flags)
54{
55 unsigned long end;
56
57 address &= ~PGDIR_MASK;
58 end = address + size;
59 if (end > PGDIR_SIZE)
60 end = PGDIR_SIZE;
61 phys_addr -= address;
62 if (address >= end)
63 BUG();
64 do {
65 pte_t * pte = pte_alloc_kernel(pmd, address);
66 if (!pte)
67 return -ENOMEM;
68 remap_area_pte(pte, address, end - address, address + phys_addr, flags);
69 address = (address + PMD_SIZE) & PMD_MASK;
70 pmd++;
71 } while (address && (address < end));
72 return 0;
73}
74
75int remap_area_pages(unsigned long address, unsigned long phys_addr,
76 unsigned long size, unsigned long flags)
77{
78 int error;
79 pgd_t * dir;
80 unsigned long end = address + size;
81
82 phys_addr -= address;
83 dir = pgd_offset_k(address);
84 flush_cache_all();
85 if (address >= end)
86 BUG();
87 do {
88 pud_t *pud;
89 pmd_t *pmd;
90
91 error = -ENOMEM;
92
93 pud = pud_alloc(&init_mm, dir, address);
94 if (!pud)
95 break;
96 pmd = pmd_alloc(&init_mm, pud, address);
97 if (!pmd)
98 break;
99 if (remap_area_pmd(pmd, address, end - address,
100 phys_addr + address, flags))
101 break;
102 error = 0;
103 address = (address + PGDIR_SIZE) & PGDIR_MASK;
104 dir++;
105 } while (address && (address < end));
106 flush_tlb_all();
107 return error;
108}
109
110/* 26/*
111 * Remap an arbitrary physical address space into the kernel virtual 27 * Remap an arbitrary physical address space into the kernel virtual
112 * address space. Needed when the kernel wants to access high addresses 28 * address space. Needed when the kernel wants to access high addresses
@@ -121,6 +37,7 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
121{ 37{
122 struct vm_struct * area; 38 struct vm_struct * area;
123 unsigned long offset, last_addr, addr, orig_addr; 39 unsigned long offset, last_addr, addr, orig_addr;
40 pgprot_t pgprot;
124 41
125 /* Don't allow wraparound or zero size */ 42 /* Don't allow wraparound or zero size */
126 last_addr = phys_addr + size - 1; 43 last_addr = phys_addr + size - 1;
@@ -190,8 +107,9 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
190 } 107 }
191#endif 108#endif
192 109
110 pgprot = __pgprot(pgprot_val(PAGE_KERNEL_NOCACHE) | flags);
193 if (likely(size)) 111 if (likely(size))
194 if (remap_area_pages(addr, phys_addr, size, flags)) { 112 if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) {
195 vunmap((void *)orig_addr); 113 vunmap((void *)orig_addr);
196 return NULL; 114 return NULL;
197 } 115 }
diff --git a/arch/sh/oprofile/op_model_sh7750.c b/arch/sh/oprofile/op_model_sh7750.c
index c265185b22a7..60402eec4b4d 100644
--- a/arch/sh/oprofile/op_model_sh7750.c
+++ b/arch/sh/oprofile/op_model_sh7750.c
@@ -142,7 +142,7 @@ static u64 sh7750_read_counter(int counter)
142 */ 142 */
143static inline int to_counter(struct file *file) 143static inline int to_counter(struct file *file)
144{ 144{
145 const unsigned char *name = file->f_dentry->d_parent->d_name.name; 145 const unsigned char *name = file->f_path.dentry->d_parent->d_name.name;
146 146
147 return (int)simple_strtol(name, NULL, 10); 147 return (int)simple_strtol(name, NULL, 10);
148} 148}
diff --git a/arch/sh64/Kconfig b/arch/sh64/Kconfig
index 58c678e06667..7bc0744b7ab6 100644
--- a/arch/sh64/Kconfig
+++ b/arch/sh64/Kconfig
@@ -39,6 +39,14 @@ config RWSEM_XCHGADD_ALGORITHM
39config GENERIC_ISA_DMA 39config GENERIC_ISA_DMA
40 bool 40 bool
41 41
42config ARCH_HAS_ILOG2_U32
43 bool
44 default n
45
46config ARCH_HAS_ILOG2_U64
47 bool
48 default n
49
42source init/Kconfig 50source init/Kconfig
43 51
44menu "System type" 52menu "System type"
diff --git a/arch/sh64/mm/ioremap.c b/arch/sh64/mm/ioremap.c
index 80c56754f513..ff26c02511aa 100644
--- a/arch/sh64/mm/ioremap.c
+++ b/arch/sh64/mm/ioremap.c
@@ -18,7 +18,7 @@
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/string.h> 20#include <linux/string.h>
21#include <asm/io.h> 21#include <linux/io.h>
22#include <asm/pgalloc.h> 22#include <asm/pgalloc.h>
23#include <asm/tlbflush.h> 23#include <asm/tlbflush.h>
24#include <linux/ioport.h> 24#include <linux/ioport.h>
@@ -28,96 +28,6 @@
28static void shmedia_mapioaddr(unsigned long, unsigned long); 28static void shmedia_mapioaddr(unsigned long, unsigned long);
29static unsigned long shmedia_ioremap(struct resource *, u32, int); 29static unsigned long shmedia_ioremap(struct resource *, u32, int);
30 30
31static inline void remap_area_pte(pte_t * pte, unsigned long address, unsigned long size,
32 unsigned long phys_addr, unsigned long flags)
33{
34 unsigned long end;
35 unsigned long pfn;
36 pgprot_t pgprot = __pgprot(_PAGE_PRESENT | _PAGE_READ |
37 _PAGE_WRITE | _PAGE_DIRTY |
38 _PAGE_ACCESSED | _PAGE_SHARED | flags);
39
40 address &= ~PMD_MASK;
41 end = address + size;
42 if (end > PMD_SIZE)
43 end = PMD_SIZE;
44 if (address >= end)
45 BUG();
46
47 pfn = phys_addr >> PAGE_SHIFT;
48
49 pr_debug(" %s: pte %p address %lx size %lx phys_addr %lx\n",
50 __FUNCTION__,pte,address,size,phys_addr);
51
52 do {
53 if (!pte_none(*pte)) {
54 printk("remap_area_pte: page already exists\n");
55 BUG();
56 }
57
58 set_pte(pte, pfn_pte(pfn, pgprot));
59 address += PAGE_SIZE;
60 pfn++;
61 pte++;
62 } while (address && (address < end));
63}
64
65static inline int remap_area_pmd(pmd_t * pmd, unsigned long address, unsigned long size,
66 unsigned long phys_addr, unsigned long flags)
67{
68 unsigned long end;
69
70 address &= ~PGDIR_MASK;
71 end = address + size;
72
73 if (end > PGDIR_SIZE)
74 end = PGDIR_SIZE;
75
76 phys_addr -= address;
77
78 if (address >= end)
79 BUG();
80
81 do {
82 pte_t * pte = pte_alloc_kernel(pmd, address);
83 if (!pte)
84 return -ENOMEM;
85 remap_area_pte(pte, address, end - address, address + phys_addr, flags);
86 address = (address + PMD_SIZE) & PMD_MASK;
87 pmd++;
88 } while (address && (address < end));
89 return 0;
90}
91
92static int remap_area_pages(unsigned long address, unsigned long phys_addr,
93 unsigned long size, unsigned long flags)
94{
95 int error;
96 pgd_t * dir;
97 unsigned long end = address + size;
98
99 phys_addr -= address;
100 dir = pgd_offset_k(address);
101 flush_cache_all();
102 if (address >= end)
103 BUG();
104 do {
105 pmd_t *pmd = pmd_alloc(&init_mm, dir, address);
106 error = -ENOMEM;
107 if (!pmd)
108 break;
109 if (remap_area_pmd(pmd, address, end - address,
110 phys_addr + address, flags)) {
111 break;
112 }
113 error = 0;
114 address = (address + PGDIR_SIZE) & PGDIR_MASK;
115 dir++;
116 } while (address && (address < end));
117 flush_tlb_all();
118 return 0;
119}
120
121/* 31/*
122 * Generic mapping function (not visible outside): 32 * Generic mapping function (not visible outside):
123 */ 33 */
@@ -136,12 +46,17 @@ void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flag
136 void * addr; 46 void * addr;
137 struct vm_struct * area; 47 struct vm_struct * area;
138 unsigned long offset, last_addr; 48 unsigned long offset, last_addr;
49 pgprot_t pgprot;
139 50
140 /* Don't allow wraparound or zero size */ 51 /* Don't allow wraparound or zero size */
141 last_addr = phys_addr + size - 1; 52 last_addr = phys_addr + size - 1;
142 if (!size || last_addr < phys_addr) 53 if (!size || last_addr < phys_addr)
143 return NULL; 54 return NULL;
144 55
56 pgprot = __pgprot(_PAGE_PRESENT | _PAGE_READ |
57 _PAGE_WRITE | _PAGE_DIRTY |
58 _PAGE_ACCESSED | _PAGE_SHARED | flags);
59
145 /* 60 /*
146 * Mappings have to be page-aligned 61 * Mappings have to be page-aligned
147 */ 62 */
@@ -158,7 +73,8 @@ void * __ioremap(unsigned long phys_addr, unsigned long size, unsigned long flag
158 return NULL; 73 return NULL;
159 area->phys_addr = phys_addr; 74 area->phys_addr = phys_addr;
160 addr = area->addr; 75 addr = area->addr;
161 if (remap_area_pages((unsigned long)addr, phys_addr, size, flags)) { 76 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
77 phys_addr, pgprot)) {
162 vunmap(addr); 78 vunmap(addr);
163 return NULL; 79 return NULL;
164 } 80 }
diff --git a/arch/sparc/Kconfig b/arch/sparc/Kconfig
index 92a7c8a636d3..d0dec1ea2eed 100644
--- a/arch/sparc/Kconfig
+++ b/arch/sparc/Kconfig
@@ -166,6 +166,14 @@ config ARCH_MAY_HAVE_PC_FDC
166 bool 166 bool
167 default y 167 default y
168 168
169config ARCH_HAS_ILOG2_U32
170 bool
171 default n
172
173config ARCH_HAS_ILOG2_U64
174 bool
175 default n
176
169config SUN_PM 177config SUN_PM
170 bool 178 bool
171 default y 179 default y
diff --git a/arch/sparc/kernel/ioport.c b/arch/sparc/kernel/ioport.c
index 54d51b404603..cbbc98846b00 100644
--- a/arch/sparc/kernel/ioport.c
+++ b/arch/sparc/kernel/ioport.c
@@ -317,9 +317,8 @@ void *sbus_alloc_consistent(struct sbus_dev *sdev, long len, u32 *dma_addrp)
317 if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0) 317 if ((va = __get_free_pages(GFP_KERNEL|__GFP_COMP, order)) == 0)
318 goto err_nopages; 318 goto err_nopages;
319 319
320 if ((res = kmalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) 320 if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL)
321 goto err_nomem; 321 goto err_nomem;
322 memset((char*)res, 0, sizeof(struct resource));
323 322
324 if (allocate_resource(&_sparc_dvma, res, len_total, 323 if (allocate_resource(&_sparc_dvma, res, len_total,
325 _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) { 324 _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
@@ -589,12 +588,11 @@ void *pci_alloc_consistent(struct pci_dev *pdev, size_t len, dma_addr_t *pba)
589 return NULL; 588 return NULL;
590 } 589 }
591 590
592 if ((res = kmalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) { 591 if ((res = kzalloc(sizeof(struct resource), GFP_KERNEL)) == NULL) {
593 free_pages(va, order); 592 free_pages(va, order);
594 printk("pci_alloc_consistent: no core\n"); 593 printk("pci_alloc_consistent: no core\n");
595 return NULL; 594 return NULL;
596 } 595 }
597 memset((char*)res, 0, sizeof(struct resource));
598 596
599 if (allocate_resource(&_sparc_dvma, res, len_total, 597 if (allocate_resource(&_sparc_dvma, res, len_total,
600 _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) { 598 _sparc_dvma.start, _sparc_dvma.end, PAGE_SIZE, NULL, NULL) != 0) {
diff --git a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c
index 46200c43ffb1..dab6169e31ca 100644
--- a/arch/sparc/kernel/of_device.c
+++ b/arch/sparc/kernel/of_device.c
@@ -793,10 +793,9 @@ struct of_device* of_platform_device_create(struct device_node *np,
793{ 793{
794 struct of_device *dev; 794 struct of_device *dev;
795 795
796 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 796 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
797 if (!dev) 797 if (!dev)
798 return NULL; 798 return NULL;
799 memset(dev, 0, sizeof(*dev));
800 799
801 dev->dev.parent = parent; 800 dev->dev.parent = parent;
802 dev->dev.bus = bus; 801 dev->dev.bus = bus;
diff --git a/arch/sparc/kernel/ptrace.c b/arch/sparc/kernel/ptrace.c
index 1baf13ed5c3a..003f8eed32f4 100644
--- a/arch/sparc/kernel/ptrace.c
+++ b/arch/sparc/kernel/ptrace.c
@@ -289,7 +289,10 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
289 289
290 if (request == PTRACE_TRACEME) { 290 if (request == PTRACE_TRACEME) {
291 ret = ptrace_traceme(); 291 ret = ptrace_traceme();
292 pt_succ_return(regs, 0); 292 if (ret < 0)
293 pt_error_return(regs, -ret);
294 else
295 pt_succ_return(regs, 0);
293 goto out; 296 goto out;
294 } 297 }
295 298
diff --git a/arch/sparc/kernel/sun4d_irq.c b/arch/sparc/kernel/sun4d_irq.c
index d4f9da8170c5..cf1b8baa57ea 100644
--- a/arch/sparc/kernel/sun4d_irq.c
+++ b/arch/sparc/kernel/sun4d_irq.c
@@ -545,8 +545,11 @@ void __init sun4d_init_sbi_irq(void)
545 nsbi = 0; 545 nsbi = 0;
546 for_each_sbus(sbus) 546 for_each_sbus(sbus)
547 nsbi++; 547 nsbi++;
548 sbus_actions = (struct sbus_action *)kmalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC); 548 sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
549 memset (sbus_actions, 0, (nsbi * 8 * 4 * sizeof(struct sbus_action))); 549 if (!sbus_actions) {
550 prom_printf("SUN4D: Cannot allocate sbus_actions, halting.\n");
551 prom_halt();
552 }
550 for_each_sbus(sbus) { 553 for_each_sbus(sbus) {
551#ifdef CONFIG_SMP 554#ifdef CONFIG_SMP
552 extern unsigned char boot_cpu_id; 555 extern unsigned char boot_cpu_id;
diff --git a/arch/sparc/kernel/sys_sunos.c b/arch/sparc/kernel/sys_sunos.c
index 6f3ac548ee66..0bf8c165fc92 100644
--- a/arch/sparc/kernel/sys_sunos.c
+++ b/arch/sparc/kernel/sys_sunos.c
@@ -94,8 +94,8 @@ asmlinkage unsigned long sunos_mmap(unsigned long addr, unsigned long len,
94 * SunOS is so stupid some times... hmph! 94 * SunOS is so stupid some times... hmph!
95 */ 95 */
96 if (file) { 96 if (file) {
97 if (imajor(file->f_dentry->d_inode) == MEM_MAJOR && 97 if (imajor(file->f_path.dentry->d_inode) == MEM_MAJOR &&
98 iminor(file->f_dentry->d_inode) == 5) { 98 iminor(file->f_path.dentry->d_inode) == 5) {
99 flags |= MAP_ANONYMOUS; 99 flags |= MAP_ANONYMOUS;
100 fput(file); 100 fput(file);
101 file = NULL; 101 file = NULL;
@@ -655,7 +655,7 @@ sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
655 if (!file) 655 if (!file)
656 goto out; 656 goto out;
657 657
658 inode = file->f_dentry->d_inode; 658 inode = file->f_path.dentry->d_inode;
659 659
660 socket = SOCKET_I(inode); 660 socket = SOCKET_I(inode);
661 local.sin_family = AF_INET; 661 local.sin_family = AF_INET;
diff --git a/arch/sparc/mm/io-unit.c b/arch/sparc/mm/io-unit.c
index 2bb1309003dd..4ccda77d08d6 100644
--- a/arch/sparc/mm/io-unit.c
+++ b/arch/sparc/mm/io-unit.c
@@ -22,6 +22,7 @@
22#include <asm/cacheflush.h> 22#include <asm/cacheflush.h>
23#include <asm/tlbflush.h> 23#include <asm/tlbflush.h>
24#include <asm/dma.h> 24#include <asm/dma.h>
25#include <asm/oplib.h>
25 26
26/* #define IOUNIT_DEBUG */ 27/* #define IOUNIT_DEBUG */
27#ifdef IOUNIT_DEBUG 28#ifdef IOUNIT_DEBUG
@@ -41,9 +42,12 @@ iounit_init(int sbi_node, int io_node, struct sbus_bus *sbus)
41 struct linux_prom_registers iommu_promregs[PROMREG_MAX]; 42 struct linux_prom_registers iommu_promregs[PROMREG_MAX];
42 struct resource r; 43 struct resource r;
43 44
44 iounit = kmalloc(sizeof(struct iounit_struct), GFP_ATOMIC); 45 iounit = kzalloc(sizeof(struct iounit_struct), GFP_ATOMIC);
46 if (!iounit) {
47 prom_printf("SUN4D: Cannot alloc iounit, halting.\n");
48 prom_halt();
49 }
45 50
46 memset(iounit, 0, sizeof(*iounit));
47 iounit->limit[0] = IOUNIT_BMAP1_START; 51 iounit->limit[0] = IOUNIT_BMAP1_START;
48 iounit->limit[1] = IOUNIT_BMAP2_START; 52 iounit->limit[1] = IOUNIT_BMAP2_START;
49 iounit->limit[2] = IOUNIT_BMAPM_START; 53 iounit->limit[2] = IOUNIT_BMAPM_START;
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index b627f8dbcaad..d41f66ac7fff 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -26,6 +26,14 @@ config MMU
26 bool 26 bool
27 default y 27 default y
28 28
29config STACKTRACE_SUPPORT
30 bool
31 default y
32
33config LOCKDEP_SUPPORT
34 bool
35 default y
36
29config TIME_INTERPOLATION 37config TIME_INTERPOLATION
30 bool 38 bool
31 default y 39 default y
@@ -34,6 +42,14 @@ config ARCH_MAY_HAVE_PC_FDC
34 bool 42 bool
35 default y 43 default y
36 44
45config ARCH_HAS_ILOG2_U32
46 bool
47 default n
48
49config ARCH_HAS_ILOG2_U64
50 bool
51 default n
52
37config AUDIT_ARCH 53config AUDIT_ARCH
38 bool 54 bool
39 default y 55 default y
diff --git a/arch/sparc64/Kconfig.debug b/arch/sparc64/Kconfig.debug
index afe0a7720a26..1f130f3b6c24 100644
--- a/arch/sparc64/Kconfig.debug
+++ b/arch/sparc64/Kconfig.debug
@@ -1,5 +1,9 @@
1menu "Kernel hacking" 1menu "Kernel hacking"
2 2
3config TRACE_IRQFLAGS_SUPPORT
4 bool
5 default y
6
3source "lib/Kconfig.debug" 7source "lib/Kconfig.debug"
4 8
5config DEBUG_STACK_USAGE 9config DEBUG_STACK_USAGE
diff --git a/arch/sparc64/defconfig b/arch/sparc64/defconfig
index 2f4612fa81f2..0f0d38f6197c 100644
--- a/arch/sparc64/defconfig
+++ b/arch/sparc64/defconfig
@@ -1,24 +1,29 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19-rc2 3# Linux kernel version: 2.6.19
4# Tue Oct 17 19:29:20 2006 4# Sat Dec 9 15:41:30 2006
5# 5#
6CONFIG_SPARC=y 6CONFIG_SPARC=y
7CONFIG_SPARC64=y 7CONFIG_SPARC64=y
8CONFIG_64BIT=y 8CONFIG_64BIT=y
9CONFIG_MMU=y 9CONFIG_MMU=y
10CONFIG_STACKTRACE_SUPPORT=y
11CONFIG_LOCKDEP_SUPPORT=y
10CONFIG_TIME_INTERPOLATION=y 12CONFIG_TIME_INTERPOLATION=y
11CONFIG_ARCH_MAY_HAVE_PC_FDC=y 13CONFIG_ARCH_MAY_HAVE_PC_FDC=y
14# CONFIG_ARCH_HAS_ILOG2_U32 is not set
15# CONFIG_ARCH_HAS_ILOG2_U64 is not set
12CONFIG_AUDIT_ARCH=y 16CONFIG_AUDIT_ARCH=y
13CONFIG_SPARC64_PAGE_SIZE_8KB=y 17CONFIG_SPARC64_PAGE_SIZE_8KB=y
14# CONFIG_SPARC64_PAGE_SIZE_64KB is not set 18# CONFIG_SPARC64_PAGE_SIZE_64KB is not set
15# CONFIG_SPARC64_PAGE_SIZE_512KB is not set 19# CONFIG_SPARC64_PAGE_SIZE_512KB is not set
16# CONFIG_SPARC64_PAGE_SIZE_4MB is not set 20# CONFIG_SPARC64_PAGE_SIZE_4MB is not set
17CONFIG_SECCOMP=y 21CONFIG_SECCOMP=y
18# CONFIG_HZ_100 is not set 22CONFIG_HZ_100=y
19CONFIG_HZ_250=y 23# CONFIG_HZ_250 is not set
24# CONFIG_HZ_300 is not set
20# CONFIG_HZ_1000 is not set 25# CONFIG_HZ_1000 is not set
21CONFIG_HZ=250 26CONFIG_HZ=100
22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 27CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
23 28
24# 29#
@@ -42,13 +47,14 @@ CONFIG_POSIX_MQUEUE=y
42# CONFIG_UTS_NS is not set 47# CONFIG_UTS_NS is not set
43# CONFIG_AUDIT is not set 48# CONFIG_AUDIT is not set
44# CONFIG_IKCONFIG is not set 49# CONFIG_IKCONFIG is not set
50CONFIG_SYSFS_DEPRECATED=y
45CONFIG_RELAY=y 51CONFIG_RELAY=y
46CONFIG_INITRAMFS_SOURCE="" 52CONFIG_INITRAMFS_SOURCE=""
47CONFIG_CC_OPTIMIZE_FOR_SIZE=y 53CONFIG_CC_OPTIMIZE_FOR_SIZE=y
48CONFIG_SYSCTL=y 54CONFIG_SYSCTL=y
49# CONFIG_EMBEDDED is not set 55# CONFIG_EMBEDDED is not set
50CONFIG_UID16=y 56CONFIG_UID16=y
51# CONFIG_SYSCTL_SYSCALL is not set 57CONFIG_SYSCTL_SYSCALL=y
52CONFIG_KALLSYMS=y 58CONFIG_KALLSYMS=y
53# CONFIG_KALLSYMS_ALL is not set 59# CONFIG_KALLSYMS_ALL is not set
54# CONFIG_KALLSYMS_EXTRA_PASS is not set 60# CONFIG_KALLSYMS_EXTRA_PASS is not set
@@ -203,6 +209,7 @@ CONFIG_INET_TCP_DIAG=y
203# CONFIG_TCP_CONG_ADVANCED is not set 209# CONFIG_TCP_CONG_ADVANCED is not set
204CONFIG_TCP_CONG_CUBIC=y 210CONFIG_TCP_CONG_CUBIC=y
205CONFIG_DEFAULT_TCP_CONG="cubic" 211CONFIG_DEFAULT_TCP_CONG="cubic"
212# CONFIG_TCP_MD5SIG is not set
206CONFIG_IPV6=m 213CONFIG_IPV6=m
207CONFIG_IPV6_PRIVACY=y 214CONFIG_IPV6_PRIVACY=y
208CONFIG_IPV6_ROUTER_PREF=y 215CONFIG_IPV6_ROUTER_PREF=y
@@ -219,7 +226,6 @@ CONFIG_INET6_XFRM_MODE_BEET=m
219# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set 226# CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION is not set
220CONFIG_IPV6_SIT=m 227CONFIG_IPV6_SIT=m
221CONFIG_IPV6_TUNNEL=m 228CONFIG_IPV6_TUNNEL=m
222# CONFIG_IPV6_SUBTREES is not set
223# CONFIG_IPV6_MULTIPLE_TABLES is not set 229# CONFIG_IPV6_MULTIPLE_TABLES is not set
224# CONFIG_NETWORK_SECMARK is not set 230# CONFIG_NETWORK_SECMARK is not set
225# CONFIG_NETFILTER is not set 231# CONFIG_NETFILTER is not set
@@ -238,6 +244,8 @@ CONFIG_IP_DCCP_CCID2=m
238# CONFIG_IP_DCCP_CCID2_DEBUG is not set 244# CONFIG_IP_DCCP_CCID2_DEBUG is not set
239CONFIG_IP_DCCP_CCID3=m 245CONFIG_IP_DCCP_CCID3=m
240CONFIG_IP_DCCP_TFRC_LIB=m 246CONFIG_IP_DCCP_TFRC_LIB=m
247# CONFIG_IP_DCCP_CCID3_DEBUG is not set
248CONFIG_IP_DCCP_CCID3_RTO=100
241 249
242# 250#
243# DCCP Kernel Hacking 251# DCCP Kernel Hacking
@@ -405,6 +413,7 @@ CONFIG_IDEDMA_AUTO=y
405# 413#
406CONFIG_RAID_ATTRS=m 414CONFIG_RAID_ATTRS=m
407CONFIG_SCSI=y 415CONFIG_SCSI=y
416# CONFIG_SCSI_TGT is not set
408CONFIG_SCSI_NETLINK=y 417CONFIG_SCSI_NETLINK=y
409CONFIG_SCSI_PROC_FS=y 418CONFIG_SCSI_PROC_FS=y
410 419
@@ -425,6 +434,7 @@ CONFIG_CHR_DEV_SG=m
425CONFIG_SCSI_MULTI_LUN=y 434CONFIG_SCSI_MULTI_LUN=y
426CONFIG_SCSI_CONSTANTS=y 435CONFIG_SCSI_CONSTANTS=y
427# CONFIG_SCSI_LOGGING is not set 436# CONFIG_SCSI_LOGGING is not set
437# CONFIG_SCSI_SCAN_ASYNC is not set
428 438
429# 439#
430# SCSI Transports 440# SCSI Transports
@@ -468,6 +478,7 @@ CONFIG_ISCSI_TCP=m
468# CONFIG_SCSI_DC390T is not set 478# CONFIG_SCSI_DC390T is not set
469# CONFIG_SCSI_DEBUG is not set 479# CONFIG_SCSI_DEBUG is not set
470# CONFIG_SCSI_SUNESP is not set 480# CONFIG_SCSI_SUNESP is not set
481# CONFIG_SCSI_SRP is not set
471 482
472# 483#
473# Serial ATA (prod) and Parallel ATA (experimental) drivers 484# Serial ATA (prod) and Parallel ATA (experimental) drivers
@@ -598,6 +609,7 @@ CONFIG_BNX2=m
598# CONFIG_IXGB is not set 609# CONFIG_IXGB is not set
599# CONFIG_S2IO is not set 610# CONFIG_S2IO is not set
600# CONFIG_MYRI10GE is not set 611# CONFIG_MYRI10GE is not set
612# CONFIG_NETXEN_NIC is not set
601 613
602# 614#
603# Token Ring devices 615# Token Ring devices
@@ -724,10 +736,6 @@ CONFIG_RTC=y
724# CONFIG_DTLK is not set 736# CONFIG_DTLK is not set
725# CONFIG_R3964 is not set 737# CONFIG_R3964 is not set
726# CONFIG_APPLICOM is not set 738# CONFIG_APPLICOM is not set
727
728#
729# Ftape, the floppy tape device driver
730#
731# CONFIG_DRM is not set 739# CONFIG_DRM is not set
732# CONFIG_RAW_DRIVER is not set 740# CONFIG_RAW_DRIVER is not set
733 741
@@ -1039,6 +1047,11 @@ CONFIG_SND_SUN_CS4231=m
1039# CONFIG_SOUND_PRIME is not set 1047# CONFIG_SOUND_PRIME is not set
1040 1048
1041# 1049#
1050# HID Devices
1051#
1052CONFIG_HID=y
1053
1054#
1042# USB support 1055# USB support
1043# 1056#
1044CONFIG_USB_ARCH_HAS_HCD=y 1057CONFIG_USB_ARCH_HAS_HCD=y
@@ -1053,6 +1066,7 @@ CONFIG_USB=y
1053CONFIG_USB_DEVICEFS=y 1066CONFIG_USB_DEVICEFS=y
1054# CONFIG_USB_BANDWIDTH is not set 1067# CONFIG_USB_BANDWIDTH is not set
1055# CONFIG_USB_DYNAMIC_MINORS is not set 1068# CONFIG_USB_DYNAMIC_MINORS is not set
1069# CONFIG_USB_MULTITHREAD_PROBE is not set
1056# CONFIG_USB_OTG is not set 1070# CONFIG_USB_OTG is not set
1057 1071
1058# 1072#
@@ -1089,8 +1103,7 @@ CONFIG_USB_UHCI_HCD=m
1089# USB Input Devices 1103# USB Input Devices
1090# 1104#
1091CONFIG_USB_HID=y 1105CONFIG_USB_HID=y
1092CONFIG_USB_HIDINPUT=y 1106# CONFIG_USB_HID_POWERBOOK is not set
1093# CONFIG_USB_HIDINPUT_POWERBOOK is not set
1094# CONFIG_HID_FF is not set 1107# CONFIG_HID_FF is not set
1095CONFIG_USB_HIDDEV=y 1108CONFIG_USB_HIDDEV=y
1096# CONFIG_USB_AIPTEK is not set 1109# CONFIG_USB_AIPTEK is not set
@@ -1119,6 +1132,7 @@ CONFIG_USB_HIDDEV=y
1119# CONFIG_USB_KAWETH is not set 1132# CONFIG_USB_KAWETH is not set
1120# CONFIG_USB_PEGASUS is not set 1133# CONFIG_USB_PEGASUS is not set
1121# CONFIG_USB_RTL8150 is not set 1134# CONFIG_USB_RTL8150 is not set
1135# CONFIG_USB_USBNET_MII is not set
1122# CONFIG_USB_USBNET is not set 1136# CONFIG_USB_USBNET is not set
1123# CONFIG_USB_MON is not set 1137# CONFIG_USB_MON is not set
1124 1138
@@ -1364,6 +1378,11 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1364# CONFIG_NLS_UTF8 is not set 1378# CONFIG_NLS_UTF8 is not set
1365 1379
1366# 1380#
1381# Distributed Lock Manager
1382#
1383# CONFIG_DLM is not set
1384
1385#
1367# Instrumentation Support 1386# Instrumentation Support
1368# 1387#
1369CONFIG_PROFILING=y 1388CONFIG_PROFILING=y
@@ -1373,6 +1392,7 @@ CONFIG_KPROBES=y
1373# 1392#
1374# Kernel hacking 1393# Kernel hacking
1375# 1394#
1395CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1376CONFIG_PRINTK_TIME=y 1396CONFIG_PRINTK_TIME=y
1377CONFIG_ENABLE_MUST_CHECK=y 1397CONFIG_ENABLE_MUST_CHECK=y
1378CONFIG_MAGIC_SYSRQ=y 1398CONFIG_MAGIC_SYSRQ=y
@@ -1387,6 +1407,8 @@ CONFIG_SCHEDSTATS=y
1387# CONFIG_DEBUG_SPINLOCK is not set 1407# CONFIG_DEBUG_SPINLOCK is not set
1388# CONFIG_DEBUG_MUTEXES is not set 1408# CONFIG_DEBUG_MUTEXES is not set
1389# CONFIG_DEBUG_RWSEMS is not set 1409# CONFIG_DEBUG_RWSEMS is not set
1410# CONFIG_DEBUG_LOCK_ALLOC is not set
1411# CONFIG_PROVE_LOCKING is not set
1390# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 1412# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1391# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set 1413# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1392# CONFIG_DEBUG_KOBJECT is not set 1414# CONFIG_DEBUG_KOBJECT is not set
@@ -1420,8 +1442,9 @@ CONFIG_CRYPTO=y
1420CONFIG_CRYPTO_ALGAPI=y 1442CONFIG_CRYPTO_ALGAPI=y
1421CONFIG_CRYPTO_BLKCIPHER=y 1443CONFIG_CRYPTO_BLKCIPHER=y
1422CONFIG_CRYPTO_HASH=y 1444CONFIG_CRYPTO_HASH=y
1423CONFIG_CRYPTO_MANAGER=m 1445CONFIG_CRYPTO_MANAGER=y
1424CONFIG_CRYPTO_HMAC=y 1446CONFIG_CRYPTO_HMAC=y
1447CONFIG_CRYPTO_XCBC=y
1425CONFIG_CRYPTO_NULL=m 1448CONFIG_CRYPTO_NULL=m
1426CONFIG_CRYPTO_MD4=y 1449CONFIG_CRYPTO_MD4=y
1427CONFIG_CRYPTO_MD5=y 1450CONFIG_CRYPTO_MD5=y
@@ -1430,8 +1453,10 @@ CONFIG_CRYPTO_SHA256=m
1430CONFIG_CRYPTO_SHA512=m 1453CONFIG_CRYPTO_SHA512=m
1431CONFIG_CRYPTO_WP512=m 1454CONFIG_CRYPTO_WP512=m
1432CONFIG_CRYPTO_TGR192=m 1455CONFIG_CRYPTO_TGR192=m
1456CONFIG_CRYPTO_GF128MUL=m
1433CONFIG_CRYPTO_ECB=m 1457CONFIG_CRYPTO_ECB=m
1434CONFIG_CRYPTO_CBC=y 1458CONFIG_CRYPTO_CBC=y
1459CONFIG_CRYPTO_LRW=m
1435CONFIG_CRYPTO_DES=y 1460CONFIG_CRYPTO_DES=y
1436CONFIG_CRYPTO_BLOWFISH=m 1461CONFIG_CRYPTO_BLOWFISH=m
1437CONFIG_CRYPTO_TWOFISH=m 1462CONFIG_CRYPTO_TWOFISH=m
@@ -1456,6 +1481,7 @@ CONFIG_CRYPTO_TEST=m
1456# 1481#
1457# Library routines 1482# Library routines
1458# 1483#
1484CONFIG_BITREVERSE=y
1459CONFIG_CRC_CCITT=m 1485CONFIG_CRC_CCITT=m
1460CONFIG_CRC16=m 1486CONFIG_CRC16=m
1461CONFIG_CRC32=y 1487CONFIG_CRC32=y
diff --git a/arch/sparc64/kernel/Makefile b/arch/sparc64/kernel/Makefile
index e1eabebaed39..eff0c01d3579 100644
--- a/arch/sparc64/kernel/Makefile
+++ b/arch/sparc64/kernel/Makefile
@@ -14,6 +14,7 @@ obj-y := process.o setup.o cpu.o idprom.o \
14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \ 14 power.o sbus.o iommu_common.o sparc64_ksyms.o chmc.o \
15 visemul.o prom.o of_device.o 15 visemul.o prom.o of_device.o
16 16
17obj-$(CONFIG_STACKTRACE) += stacktrace.o
17obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \ 18obj-$(CONFIG_PCI) += ebus.o isa.o pci_common.o pci_iommu.o \
18 pci_psycho.o pci_sabre.o pci_schizo.o \ 19 pci_psycho.o pci_sabre.o pci_schizo.o \
19 pci_sun4v.o pci_sun4v_asm.o 20 pci_sun4v.o pci_sun4v_asm.o
diff --git a/arch/sparc64/kernel/binfmt_aout32.c b/arch/sparc64/kernel/binfmt_aout32.c
index d7caa60a0074..f205fc7cbcd0 100644
--- a/arch/sparc64/kernel/binfmt_aout32.c
+++ b/arch/sparc64/kernel/binfmt_aout32.c
@@ -209,7 +209,7 @@ static int load_aout32_binary(struct linux_binprm * bprm, struct pt_regs * regs)
209 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && 209 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
210 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) || 210 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
211 N_TRSIZE(ex) || N_DRSIZE(ex) || 211 N_TRSIZE(ex) || N_DRSIZE(ex) ||
212 bprm->file->f_dentry->d_inode->i_size < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) { 212 bprm->file->f_path.dentry->d_inode->i_size < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
213 return -ENOEXEC; 213 return -ENOEXEC;
214 } 214 }
215 215
@@ -349,7 +349,7 @@ static int load_aout32_library(struct file *file)
349 int retval; 349 int retval;
350 struct exec ex; 350 struct exec ex;
351 351
352 inode = file->f_dentry->d_inode; 352 inode = file->f_path.dentry->d_inode;
353 353
354 retval = -ENOEXEC; 354 retval = -ENOEXEC;
355 error = kernel_read(file, 0, (char *) &ex, sizeof(ex)); 355 error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
diff --git a/arch/sparc64/kernel/chmc.c b/arch/sparc64/kernel/chmc.c
index 259f37e516f5..9699abeb9907 100644
--- a/arch/sparc64/kernel/chmc.c
+++ b/arch/sparc64/kernel/chmc.c
@@ -341,7 +341,7 @@ static void fetch_decode_regs(struct mctrl_info *mp)
341 341
342static int init_one_mctrl(struct device_node *dp) 342static int init_one_mctrl(struct device_node *dp)
343{ 343{
344 struct mctrl_info *mp = kmalloc(sizeof(*mp), GFP_KERNEL); 344 struct mctrl_info *mp = kzalloc(sizeof(*mp), GFP_KERNEL);
345 int portid = of_getintprop_default(dp, "portid", -1); 345 int portid = of_getintprop_default(dp, "portid", -1);
346 struct linux_prom64_registers *regs; 346 struct linux_prom64_registers *regs;
347 void *pval; 347 void *pval;
@@ -349,7 +349,6 @@ static int init_one_mctrl(struct device_node *dp)
349 349
350 if (!mp) 350 if (!mp)
351 return -1; 351 return -1;
352 memset(mp, 0, sizeof(*mp));
353 if (portid == -1) 352 if (portid == -1)
354 goto fail; 353 goto fail;
355 354
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index 6f28bec0a9bf..c15a3edcb826 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -597,7 +597,12 @@ __spitfire_cee_trap_continue:
5971: ba,pt %xcc, etrap_irq 5971: ba,pt %xcc, etrap_irq
598 rd %pc, %g7 598 rd %pc, %g7
599 599
6002: mov %l4, %o1 6002:
601#ifdef CONFIG_TRACE_IRQFLAGS
602 call trace_hardirqs_off
603 nop
604#endif
605 mov %l4, %o1
601 mov %l5, %o2 606 mov %l5, %o2
602 call spitfire_access_error 607 call spitfire_access_error
603 add %sp, PTREGS_OFF, %o0 608 add %sp, PTREGS_OFF, %o0
@@ -824,6 +829,10 @@ do_cheetah_plus_data_parity:
824 wrpr %g0, 15, %pil 829 wrpr %g0, 15, %pil
825 ba,pt %xcc, etrap_irq 830 ba,pt %xcc, etrap_irq
826 rd %pc, %g7 831 rd %pc, %g7
832#ifdef CONFIG_TRACE_IRQFLAGS
833 call trace_hardirqs_off
834 nop
835#endif
827 mov 0x0, %o0 836 mov 0x0, %o0
828 call cheetah_plus_parity_error 837 call cheetah_plus_parity_error
829 add %sp, PTREGS_OFF, %o1 838 add %sp, PTREGS_OFF, %o1
@@ -855,6 +864,10 @@ do_cheetah_plus_insn_parity:
855 wrpr %g0, 15, %pil 864 wrpr %g0, 15, %pil
856 ba,pt %xcc, etrap_irq 865 ba,pt %xcc, etrap_irq
857 rd %pc, %g7 866 rd %pc, %g7
867#ifdef CONFIG_TRACE_IRQFLAGS
868 call trace_hardirqs_off
869 nop
870#endif
858 mov 0x1, %o0 871 mov 0x1, %o0
859 call cheetah_plus_parity_error 872 call cheetah_plus_parity_error
860 add %sp, PTREGS_OFF, %o1 873 add %sp, PTREGS_OFF, %o1
@@ -1183,6 +1196,10 @@ c_fast_ecc:
1183 wrpr %g0, 15, %pil 1196 wrpr %g0, 15, %pil
1184 ba,pt %xcc, etrap_irq 1197 ba,pt %xcc, etrap_irq
1185 rd %pc, %g7 1198 rd %pc, %g7
1199#ifdef CONFIG_TRACE_IRQFLAGS
1200 call trace_hardirqs_off
1201 nop
1202#endif
1186 mov %l4, %o1 1203 mov %l4, %o1
1187 mov %l5, %o2 1204 mov %l5, %o2
1188 call cheetah_fecc_handler 1205 call cheetah_fecc_handler
@@ -1211,6 +1228,10 @@ c_cee:
1211 wrpr %g0, 15, %pil 1228 wrpr %g0, 15, %pil
1212 ba,pt %xcc, etrap_irq 1229 ba,pt %xcc, etrap_irq
1213 rd %pc, %g7 1230 rd %pc, %g7
1231#ifdef CONFIG_TRACE_IRQFLAGS
1232 call trace_hardirqs_off
1233 nop
1234#endif
1214 mov %l4, %o1 1235 mov %l4, %o1
1215 mov %l5, %o2 1236 mov %l5, %o2
1216 call cheetah_cee_handler 1237 call cheetah_cee_handler
@@ -1239,6 +1260,10 @@ c_deferred:
1239 wrpr %g0, 15, %pil 1260 wrpr %g0, 15, %pil
1240 ba,pt %xcc, etrap_irq 1261 ba,pt %xcc, etrap_irq
1241 rd %pc, %g7 1262 rd %pc, %g7
1263#ifdef CONFIG_TRACE_IRQFLAGS
1264 call trace_hardirqs_off
1265 nop
1266#endif
1242 mov %l4, %o1 1267 mov %l4, %o1
1243 mov %l5, %o2 1268 mov %l5, %o2
1244 call cheetah_deferred_handler 1269 call cheetah_deferred_handler
diff --git a/arch/sparc64/kernel/head.S b/arch/sparc64/kernel/head.S
index c8e9dc9d68a9..03ffaf895a22 100644
--- a/arch/sparc64/kernel/head.S
+++ b/arch/sparc64/kernel/head.S
@@ -489,6 +489,14 @@ tlb_fixup_done:
489 call __bzero 489 call __bzero
490 sub %o1, %o0, %o1 490 sub %o1, %o0, %o1
491 491
492#ifdef CONFIG_LOCKDEP
493 /* We have this call this super early, as even prom_init can grab
494 * spinlocks and thus call into the lockdep code.
495 */
496 call lockdep_init
497 nop
498#endif
499
492 mov %l6, %o1 ! OpenPROM stack 500 mov %l6, %o1 ! OpenPROM stack
493 call prom_init 501 call prom_init
494 mov %l7, %o0 ! OpenPROM cif handler 502 mov %l7, %o0 ! OpenPROM cif handler
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index f028e68b23f2..ad1c4f55420f 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -72,14 +72,12 @@ static void __init isa_fill_children(struct sparc_isa_device *parent_isa_dev)
72 struct linux_prom_registers *regs; 72 struct linux_prom_registers *regs;
73 struct sparc_isa_device *isa_dev; 73 struct sparc_isa_device *isa_dev;
74 74
75 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL); 75 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
76 if (!isa_dev) { 76 if (!isa_dev) {
77 fatal_err("cannot allocate child isa_dev"); 77 fatal_err("cannot allocate child isa_dev");
78 prom_halt(); 78 prom_halt();
79 } 79 }
80 80
81 memset(isa_dev, 0, sizeof(*isa_dev));
82
83 /* Link it in to parent. */ 81 /* Link it in to parent. */
84 isa_dev->next = parent_isa_dev->child; 82 isa_dev->next = parent_isa_dev->child;
85 parent_isa_dev->child = isa_dev; 83 parent_isa_dev->child = isa_dev;
@@ -104,14 +102,12 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
104 struct linux_prom_registers *regs; 102 struct linux_prom_registers *regs;
105 struct sparc_isa_device *isa_dev; 103 struct sparc_isa_device *isa_dev;
106 104
107 isa_dev = kmalloc(sizeof(*isa_dev), GFP_KERNEL); 105 isa_dev = kzalloc(sizeof(*isa_dev), GFP_KERNEL);
108 if (!isa_dev) { 106 if (!isa_dev) {
109 printk(KERN_DEBUG "ISA: cannot allocate isa_dev"); 107 printk(KERN_DEBUG "ISA: cannot allocate isa_dev");
110 return; 108 return;
111 } 109 }
112 110
113 memset(isa_dev, 0, sizeof(*isa_dev));
114
115 isa_dev->ofdev.node = dp; 111 isa_dev->ofdev.node = dp;
116 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; 112 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
117 isa_dev->ofdev.dev.bus = &isa_bus_type; 113 isa_dev->ofdev.dev.bus = &isa_bus_type;
@@ -180,14 +176,12 @@ void __init isa_init(void)
180 pbm = pdev_cookie->pbm; 176 pbm = pdev_cookie->pbm;
181 dp = pdev_cookie->prom_node; 177 dp = pdev_cookie->prom_node;
182 178
183 isa_br = kmalloc(sizeof(*isa_br), GFP_KERNEL); 179 isa_br = kzalloc(sizeof(*isa_br), GFP_KERNEL);
184 if (!isa_br) { 180 if (!isa_br) {
185 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge"); 181 printk(KERN_DEBUG "isa: cannot allocate sparc_isa_bridge");
186 return; 182 return;
187 } 183 }
188 184
189 memset(isa_br, 0, sizeof(*isa_br));
190
191 isa_br->ofdev.node = dp; 185 isa_br->ofdev.node = dp;
192 isa_br->ofdev.dev.parent = &pdev->dev; 186 isa_br->ofdev.dev.parent = &pdev->dev;
193 isa_br->ofdev.dev.bus = &isa_bus_type; 187 isa_br->ofdev.dev.bus = &isa_bus_type;
diff --git a/arch/sparc64/kernel/kprobes.c b/arch/sparc64/kernel/kprobes.c
index 8e75ed762fd8..ae221f0d4a6f 100644
--- a/arch/sparc64/kernel/kprobes.c
+++ b/arch/sparc64/kernel/kprobes.c
@@ -45,7 +45,11 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
45int __kprobes arch_prepare_kprobe(struct kprobe *p) 45int __kprobes arch_prepare_kprobe(struct kprobe *p)
46{ 46{
47 p->ainsn.insn[0] = *p->addr; 47 p->ainsn.insn[0] = *p->addr;
48 flushi(&p->ainsn.insn[0]);
49
48 p->ainsn.insn[1] = BREAKPOINT_INSTRUCTION_2; 50 p->ainsn.insn[1] = BREAKPOINT_INSTRUCTION_2;
51 flushi(&p->ainsn.insn[1]);
52
49 p->opcode = *p->addr; 53 p->opcode = *p->addr;
50 return 0; 54 return 0;
51} 55}
@@ -185,16 +189,19 @@ no_kprobe:
185/* If INSN is a relative control transfer instruction, 189/* If INSN is a relative control transfer instruction,
186 * return the corrected branch destination value. 190 * return the corrected branch destination value.
187 * 191 *
188 * The original INSN location was REAL_PC, it actually 192 * regs->tpc and regs->tnpc still hold the values of the
189 * executed at PC and produced destination address NPC. 193 * program counters at the time of trap due to the execution
194 * of the BREAKPOINT_INSTRUCTION_2 at p->ainsn.insn[1]
195 *
190 */ 196 */
191static unsigned long __kprobes relbranch_fixup(u32 insn, unsigned long real_pc, 197static unsigned long __kprobes relbranch_fixup(u32 insn, struct kprobe *p,
192 unsigned long pc, 198 struct pt_regs *regs)
193 unsigned long npc)
194{ 199{
200 unsigned long real_pc = (unsigned long) p->addr;
201
195 /* Branch not taken, no mods necessary. */ 202 /* Branch not taken, no mods necessary. */
196 if (npc == pc + 0x4UL) 203 if (regs->tnpc == regs->tpc + 0x4UL)
197 return real_pc + 0x4UL; 204 return real_pc + 0x8UL;
198 205
199 /* The three cases are call, branch w/prediction, 206 /* The three cases are call, branch w/prediction,
200 * and traditional branch. 207 * and traditional branch.
@@ -202,14 +209,21 @@ static unsigned long __kprobes relbranch_fixup(u32 insn, unsigned long real_pc,
202 if ((insn & 0xc0000000) == 0x40000000 || 209 if ((insn & 0xc0000000) == 0x40000000 ||
203 (insn & 0xc1c00000) == 0x00400000 || 210 (insn & 0xc1c00000) == 0x00400000 ||
204 (insn & 0xc1c00000) == 0x00800000) { 211 (insn & 0xc1c00000) == 0x00800000) {
212 unsigned long ainsn_addr;
213
214 ainsn_addr = (unsigned long) &p->ainsn.insn[0];
215
205 /* The instruction did all the work for us 216 /* The instruction did all the work for us
206 * already, just apply the offset to the correct 217 * already, just apply the offset to the correct
207 * instruction location. 218 * instruction location.
208 */ 219 */
209 return (real_pc + (npc - pc)); 220 return (real_pc + (regs->tnpc - ainsn_addr));
210 } 221 }
211 222
212 return real_pc + 0x4UL; 223 /* It is jmpl or some other absolute PC modification instruction,
224 * leave NPC as-is.
225 */
226 return regs->tnpc;
213} 227}
214 228
215/* If INSN is an instruction which writes it's PC location 229/* If INSN is an instruction which writes it's PC location
@@ -220,12 +234,12 @@ static void __kprobes retpc_fixup(struct pt_regs *regs, u32 insn,
220{ 234{
221 unsigned long *slot = NULL; 235 unsigned long *slot = NULL;
222 236
223 /* Simplest cast is call, which always uses %o7 */ 237 /* Simplest case is 'call', which always uses %o7 */
224 if ((insn & 0xc0000000) == 0x40000000) { 238 if ((insn & 0xc0000000) == 0x40000000) {
225 slot = &regs->u_regs[UREG_I7]; 239 slot = &regs->u_regs[UREG_I7];
226 } 240 }
227 241
228 /* Jmpl encodes the register inside of the opcode */ 242 /* 'jmpl' encodes the register inside of the opcode */
229 if ((insn & 0xc1f80000) == 0x81c00000) { 243 if ((insn & 0xc1f80000) == 0x81c00000) {
230 unsigned long rd = ((insn >> 25) & 0x1f); 244 unsigned long rd = ((insn >> 25) & 0x1f);
231 245
@@ -247,11 +261,11 @@ static void __kprobes retpc_fixup(struct pt_regs *regs, u32 insn,
247 261
248/* 262/*
249 * Called after single-stepping. p->addr is the address of the 263 * Called after single-stepping. p->addr is the address of the
250 * instruction whose first byte has been replaced by the breakpoint 264 * instruction which has been replaced by the breakpoint
251 * instruction. To avoid the SMP problems that can occur when we 265 * instruction. To avoid the SMP problems that can occur when we
252 * temporarily put back the original opcode to single-step, we 266 * temporarily put back the original opcode to single-step, we
253 * single-stepped a copy of the instruction. The address of this 267 * single-stepped a copy of the instruction. The address of this
254 * copy is p->ainsn.insn. 268 * copy is &p->ainsn.insn[0].
255 * 269 *
256 * This function prepares to return from the post-single-step 270 * This function prepares to return from the post-single-step
257 * breakpoint trap. 271 * breakpoint trap.
@@ -261,11 +275,11 @@ static void __kprobes resume_execution(struct kprobe *p,
261{ 275{
262 u32 insn = p->ainsn.insn[0]; 276 u32 insn = p->ainsn.insn[0];
263 277
278 regs->tnpc = relbranch_fixup(insn, p, regs);
279
280 /* This assignment must occur after relbranch_fixup() */
264 regs->tpc = kcb->kprobe_orig_tnpc; 281 regs->tpc = kcb->kprobe_orig_tnpc;
265 regs->tnpc = relbranch_fixup(insn, 282
266 (unsigned long) p->addr,
267 (unsigned long) &p->ainsn.insn[0],
268 regs->tnpc);
269 retpc_fixup(regs, insn, (unsigned long) p->addr); 283 retpc_fixup(regs, insn, (unsigned long) p->addr);
270 284
271 regs->tstate = ((regs->tstate & ~TSTATE_PIL) | 285 regs->tstate = ((regs->tstate & ~TSTATE_PIL) |
@@ -430,17 +444,8 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
430 struct jprobe *jp = container_of(p, struct jprobe, kp); 444 struct jprobe *jp = container_of(p, struct jprobe, kp);
431 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 445 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
432 446
433 kcb->jprobe_saved_regs_location = regs;
434 memcpy(&(kcb->jprobe_saved_regs), regs, sizeof(*regs)); 447 memcpy(&(kcb->jprobe_saved_regs), regs, sizeof(*regs));
435 448
436 /* Save a whole stack frame, this gets arguments
437 * pushed onto the stack after using up all the
438 * arg registers.
439 */
440 memcpy(&(kcb->jprobe_saved_stack),
441 (char *) (regs->u_regs[UREG_FP] + STACK_BIAS),
442 sizeof(kcb->jprobe_saved_stack));
443
444 regs->tpc = (unsigned long) jp->entry; 449 regs->tpc = (unsigned long) jp->entry;
445 regs->tnpc = ((unsigned long) jp->entry) + 0x4UL; 450 regs->tnpc = ((unsigned long) jp->entry) + 0x4UL;
446 regs->tstate |= TSTATE_PIL; 451 regs->tstate |= TSTATE_PIL;
@@ -450,10 +455,19 @@ int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
450 455
451void __kprobes jprobe_return(void) 456void __kprobes jprobe_return(void)
452{ 457{
453 __asm__ __volatile__( 458 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
454 ".globl jprobe_return_trap_instruction\n" 459 register unsigned long orig_fp asm("g1");
460
461 orig_fp = kcb->jprobe_saved_regs.u_regs[UREG_FP];
462 __asm__ __volatile__("\n"
463"1: cmp %%sp, %0\n\t"
464 "blu,a,pt %%xcc, 1b\n\t"
465 " restore\n\t"
466 ".globl jprobe_return_trap_instruction\n"
455"jprobe_return_trap_instruction:\n\t" 467"jprobe_return_trap_instruction:\n\t"
456 "ta 0x70"); 468 "ta 0x70"
469 : /* no outputs */
470 : "r" (orig_fp));
457} 471}
458 472
459extern void jprobe_return_trap_instruction(void); 473extern void jprobe_return_trap_instruction(void);
@@ -466,26 +480,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
466 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); 480 struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
467 481
468 if (addr == (u32 *) jprobe_return_trap_instruction) { 482 if (addr == (u32 *) jprobe_return_trap_instruction) {
469 if (kcb->jprobe_saved_regs_location != regs) {
470 printk("JPROBE: Current regs (%p) does not match "
471 "saved regs (%p).\n",
472 regs, kcb->jprobe_saved_regs_location);
473 printk("JPROBE: Saved registers\n");
474 __show_regs(kcb->jprobe_saved_regs_location);
475 printk("JPROBE: Current registers\n");
476 __show_regs(regs);
477 BUG();
478 }
479 /* Restore old register state. Do pt_regs
480 * first so that UREG_FP is the original one for
481 * the stack frame restore.
482 */
483 memcpy(regs, &(kcb->jprobe_saved_regs), sizeof(*regs)); 483 memcpy(regs, &(kcb->jprobe_saved_regs), sizeof(*regs));
484
485 memcpy((char *) (regs->u_regs[UREG_FP] + STACK_BIAS),
486 &(kcb->jprobe_saved_stack),
487 sizeof(kcb->jprobe_saved_stack));
488
489 preempt_enable_no_resched(); 484 preempt_enable_no_resched();
490 return 1; 485 return 1;
491 } 486 }
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index 8cc14fc6b6f1..cec0eceae552 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -1007,10 +1007,9 @@ struct of_device* of_platform_device_create(struct device_node *np,
1007{ 1007{
1008 struct of_device *dev; 1008 struct of_device *dev;
1009 1009
1010 dev = kmalloc(sizeof(*dev), GFP_KERNEL); 1010 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1011 if (!dev) 1011 if (!dev)
1012 return NULL; 1012 return NULL;
1013 memset(dev, 0, sizeof(*dev));
1014 1013
1015 dev->dev.parent = parent; 1014 dev->dev.parent = parent;
1016 dev->dev.bus = bus; 1015 dev->dev.bus = bus;
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 03ad4c06758e..6b04794b7a97 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -798,7 +798,7 @@ static struct pci_ops pci_sun4v_ops = {
798static void pbm_scan_bus(struct pci_controller_info *p, 798static void pbm_scan_bus(struct pci_controller_info *p,
799 struct pci_pbm_info *pbm) 799 struct pci_pbm_info *pbm)
800{ 800{
801 struct pcidev_cookie *cookie = kmalloc(sizeof(*cookie), GFP_KERNEL); 801 struct pcidev_cookie *cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
802 802
803 if (!cookie) { 803 if (!cookie) {
804 prom_printf("%s: Critical allocation failure.\n", pbm->name); 804 prom_printf("%s: Critical allocation failure.\n", pbm->name);
@@ -806,7 +806,6 @@ static void pbm_scan_bus(struct pci_controller_info *p,
806 } 806 }
807 807
808 /* All we care about is the PBM. */ 808 /* All we care about is the PBM. */
809 memset(cookie, 0, sizeof(*cookie));
810 cookie->pbm = pbm; 809 cookie->pbm = pbm;
811 810
812 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, p->pci_ops, pbm); 811 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, p->pci_ops, pbm);
@@ -1048,12 +1047,11 @@ static void pci_sun4v_iommu_init(struct pci_pbm_info *pbm)
1048 /* Allocate and initialize the free area map. */ 1047 /* Allocate and initialize the free area map. */
1049 sz = num_tsb_entries / 8; 1048 sz = num_tsb_entries / 8;
1050 sz = (sz + 7UL) & ~7UL; 1049 sz = (sz + 7UL) & ~7UL;
1051 iommu->arena.map = kmalloc(sz, GFP_KERNEL); 1050 iommu->arena.map = kzalloc(sz, GFP_KERNEL);
1052 if (!iommu->arena.map) { 1051 if (!iommu->arena.map) {
1053 prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n"); 1052 prom_printf("PCI_IOMMU: Error, kmalloc(arena.map) failed.\n");
1054 prom_halt(); 1053 prom_halt();
1055 } 1054 }
1056 memset(iommu->arena.map, 0, sz);
1057 iommu->arena.limit = num_tsb_entries; 1055 iommu->arena.limit = num_tsb_entries;
1058 1056
1059 sz = probe_existing_entries(pbm, iommu); 1057 sz = probe_existing_entries(pbm, iommu);
@@ -1164,24 +1162,20 @@ void sun4v_pci_init(struct device_node *dp, char *model_name)
1164 per_cpu(pci_iommu_batch, i).pglist = (u64 *) page; 1162 per_cpu(pci_iommu_batch, i).pglist = (u64 *) page;
1165 } 1163 }
1166 1164
1167 p = kmalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); 1165 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
1168 if (!p) 1166 if (!p)
1169 goto fatal_memory_error; 1167 goto fatal_memory_error;
1170 1168
1171 memset(p, 0, sizeof(*p)); 1169 iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
1172
1173 iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
1174 if (!iommu) 1170 if (!iommu)
1175 goto fatal_memory_error; 1171 goto fatal_memory_error;
1176 1172
1177 memset(iommu, 0, sizeof(*iommu));
1178 p->pbm_A.iommu = iommu; 1173 p->pbm_A.iommu = iommu;
1179 1174
1180 iommu = kmalloc(sizeof(struct pci_iommu), GFP_ATOMIC); 1175 iommu = kzalloc(sizeof(struct pci_iommu), GFP_ATOMIC);
1181 if (!iommu) 1176 if (!iommu)
1182 goto fatal_memory_error; 1177 goto fatal_memory_error;
1183 1178
1184 memset(iommu, 0, sizeof(*iommu));
1185 p->pbm_B.iommu = iommu; 1179 p->pbm_B.iommu = iommu;
1186 1180
1187 p->next = pci_controller_root; 1181 p->next = pci_controller_root;
diff --git a/arch/sparc64/kernel/ptrace.c b/arch/sparc64/kernel/ptrace.c
index d31975e6d6f6..81111a12f0a8 100644
--- a/arch/sparc64/kernel/ptrace.c
+++ b/arch/sparc64/kernel/ptrace.c
@@ -202,7 +202,10 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
202#endif 202#endif
203 if (request == PTRACE_TRACEME) { 203 if (request == PTRACE_TRACEME) {
204 ret = ptrace_traceme(); 204 ret = ptrace_traceme();
205 pt_succ_return(regs, 0); 205 if (ret < 0)
206 pt_error_return(regs, -ret);
207 else
208 pt_succ_return(regs, 0);
206 goto out; 209 goto out;
207 } 210 }
208 211
diff --git a/arch/sparc64/kernel/rtrap.S b/arch/sparc64/kernel/rtrap.S
index 3522cd66f3bb..079d18a11d24 100644
--- a/arch/sparc64/kernel/rtrap.S
+++ b/arch/sparc64/kernel/rtrap.S
@@ -165,14 +165,26 @@ rtrap:
165__handle_softirq_continue: 165__handle_softirq_continue:
166rtrap_xcall: 166rtrap_xcall:
167 sethi %hi(0xf << 20), %l4 167 sethi %hi(0xf << 20), %l4
168 andcc %l1, TSTATE_PRIV, %l3
169 and %l1, %l4, %l4 168 and %l1, %l4, %l4
169 andn %l1, %l4, %l1
170 srl %l4, 20, %l4
171#ifdef CONFIG_TRACE_IRQFLAGS
172 brnz,pn %l4, rtrap_no_irq_enable
173 nop
174 call trace_hardirqs_on
175 nop
176 wrpr %l4, %pil
177rtrap_no_irq_enable:
178#endif
179 andcc %l1, TSTATE_PRIV, %l3
170 bne,pn %icc, to_kernel 180 bne,pn %icc, to_kernel
171 andn %l1, %l4, %l1 181 nop
172 182
173 /* We must hold IRQs off and atomically test schedule+signal 183 /* We must hold IRQs off and atomically test schedule+signal
174 * state, then hold them off all the way back to userspace. 184 * state, then hold them off all the way back to userspace.
175 * If we are returning to kernel, none of this matters. 185 * If we are returning to kernel, none of this matters. Note
186 * that we are disabling interrupts via PSTATE_IE, not using
187 * %pil.
176 * 188 *
177 * If we do not do this, there is a window where we would do 189 * If we do not do this, there is a window where we would do
178 * the tests, later the signal/resched event arrives but we do 190 * the tests, later the signal/resched event arrives but we do
@@ -256,7 +268,6 @@ rt_continue: ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1
256 268
257 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3 269 ld [%sp + PTREGS_OFF + PT_V9_Y], %o3
258 wr %o3, %g0, %y 270 wr %o3, %g0, %y
259 srl %l4, 20, %l4
260 wrpr %l4, 0x0, %pil 271 wrpr %l4, 0x0, %pil
261 wrpr %g0, 0x1, %tl 272 wrpr %g0, 0x1, %tl
262 wrpr %l1, %g0, %tstate 273 wrpr %l1, %g0, %tstate
@@ -374,8 +385,8 @@ to_kernel:
374 ldx [%g6 + TI_FLAGS], %l5 385 ldx [%g6 + TI_FLAGS], %l5
375 andcc %l5, _TIF_NEED_RESCHED, %g0 386 andcc %l5, _TIF_NEED_RESCHED, %g0
376 be,pt %xcc, kern_fpucheck 387 be,pt %xcc, kern_fpucheck
377 srl %l4, 20, %l5 388 nop
378 cmp %l5, 0 389 cmp %l4, 0
379 bne,pn %xcc, kern_fpucheck 390 bne,pn %xcc, kern_fpucheck
380 sethi %hi(PREEMPT_ACTIVE), %l6 391 sethi %hi(PREEMPT_ACTIVE), %l6
381 stw %l6, [%g6 + TI_PRE_COUNT] 392 stw %l6, [%g6 + TI_PRE_COUNT]
diff --git a/arch/sparc64/kernel/stacktrace.c b/arch/sparc64/kernel/stacktrace.c
new file mode 100644
index 000000000000..c4d15f2762b9
--- /dev/null
+++ b/arch/sparc64/kernel/stacktrace.c
@@ -0,0 +1,41 @@
1#include <linux/sched.h>
2#include <linux/stacktrace.h>
3#include <linux/thread_info.h>
4#include <asm/ptrace.h>
5
6void save_stack_trace(struct stack_trace *trace, struct task_struct *task)
7{
8 unsigned long ksp, fp, thread_base;
9 struct thread_info *tp;
10
11 if (!task)
12 task = current;
13 tp = task_thread_info(task);
14 if (task == current) {
15 flushw_all();
16 __asm__ __volatile__(
17 "mov %%fp, %0"
18 : "=r" (ksp)
19 );
20 } else
21 ksp = tp->ksp;
22
23 fp = ksp + STACK_BIAS;
24 thread_base = (unsigned long) tp;
25 do {
26 struct reg_window *rw;
27
28 /* Bogus frame pointer? */
29 if (fp < (thread_base + sizeof(struct thread_info)) ||
30 fp >= (thread_base + THREAD_SIZE))
31 break;
32
33 rw = (struct reg_window *) fp;
34 if (trace->skip > 0)
35 trace->skip--;
36 else
37 trace->entries[trace->nr_entries++] = rw->ins[7];
38
39 fp = rw->ins[6] + STACK_BIAS;
40 } while (trace->nr_entries < trace->max_entries);
41}
diff --git a/arch/sparc64/kernel/sun4v_ivec.S b/arch/sparc64/kernel/sun4v_ivec.S
index 49703c3c5769..405855dd886b 100644
--- a/arch/sparc64/kernel/sun4v_ivec.S
+++ b/arch/sparc64/kernel/sun4v_ivec.S
@@ -190,7 +190,10 @@ sun4v_res_mondo:
190 mov %g1, %g4 190 mov %g1, %g4
191 ba,pt %xcc, etrap_irq 191 ba,pt %xcc, etrap_irq
192 rd %pc, %g7 192 rd %pc, %g7
193 193#ifdef CONFIG_TRACE_IRQFLAGS
194 call trace_hardirqs_off
195 nop
196#endif
194 /* Log the event. */ 197 /* Log the event. */
195 add %sp, PTREGS_OFF, %o0 198 add %sp, PTREGS_OFF, %o0
196 call sun4v_resum_error 199 call sun4v_resum_error
@@ -216,7 +219,10 @@ sun4v_res_mondo_queue_full:
216 wrpr %g0, 15, %pil 219 wrpr %g0, 15, %pil
217 ba,pt %xcc, etrap_irq 220 ba,pt %xcc, etrap_irq
218 rd %pc, %g7 221 rd %pc, %g7
219 222#ifdef CONFIG_TRACE_IRQFLAGS
223 call trace_hardirqs_off
224 nop
225#endif
220 call sun4v_resum_overflow 226 call sun4v_resum_overflow
221 add %sp, PTREGS_OFF, %o0 227 add %sp, PTREGS_OFF, %o0
222 228
@@ -295,7 +301,10 @@ sun4v_nonres_mondo:
295 mov %g1, %g4 301 mov %g1, %g4
296 ba,pt %xcc, etrap_irq 302 ba,pt %xcc, etrap_irq
297 rd %pc, %g7 303 rd %pc, %g7
298 304#ifdef CONFIG_TRACE_IRQFLAGS
305 call trace_hardirqs_off
306 nop
307#endif
299 /* Log the event. */ 308 /* Log the event. */
300 add %sp, PTREGS_OFF, %o0 309 add %sp, PTREGS_OFF, %o0
301 call sun4v_nonresum_error 310 call sun4v_nonresum_error
@@ -321,7 +330,10 @@ sun4v_nonres_mondo_queue_full:
321 wrpr %g0, 15, %pil 330 wrpr %g0, 15, %pil
322 ba,pt %xcc, etrap_irq 331 ba,pt %xcc, etrap_irq
323 rd %pc, %g7 332 rd %pc, %g7
324 333#ifdef CONFIG_TRACE_IRQFLAGS
334 call trace_hardirqs_off
335 nop
336#endif
325 call sun4v_nonresum_overflow 337 call sun4v_nonresum_overflow
326 add %sp, PTREGS_OFF, %o0 338 add %sp, PTREGS_OFF, %o0
327 339
diff --git a/arch/sparc64/kernel/sys_sunos32.c b/arch/sparc64/kernel/sys_sunos32.c
index 7da72d3b322a..4446f66590fa 100644
--- a/arch/sparc64/kernel/sys_sunos32.c
+++ b/arch/sparc64/kernel/sys_sunos32.c
@@ -83,7 +83,7 @@ asmlinkage u32 sunos_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 of
83 file = fget(fd); 83 file = fget(fd);
84 if (!file) 84 if (!file)
85 goto out; 85 goto out;
86 inode = file->f_dentry->d_inode; 86 inode = file->f_path.dentry->d_inode;
87 if (imajor(inode) == MEM_MAJOR && iminor(inode) == 5) { 87 if (imajor(inode) == MEM_MAJOR && iminor(inode) == 5) {
88 flags |= MAP_ANONYMOUS; 88 flags |= MAP_ANONYMOUS;
89 fput(file); 89 fput(file);
@@ -615,7 +615,7 @@ sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
615 if (!file) 615 if (!file)
616 return 0; 616 return 0;
617 617
618 inode = file->f_dentry->d_inode; 618 inode = file->f_path.dentry->d_inode;
619 619
620 socket = SOCKET_I(inode); 620 socket = SOCKET_I(inode);
621 local.sin_family = AF_INET; 621 local.sin_family = AF_INET;
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index fe1796c939c3..ad67784292db 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/sched.h> /* for jiffies */ 13#include <linux/sched.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/kallsyms.h> 15#include <linux/kallsyms.h>
16#include <linux/signal.h> 16#include <linux/signal.h>
@@ -1873,6 +1873,16 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
1873 1873
1874 put_cpu(); 1874 put_cpu();
1875 1875
1876 if (ent->err_type == SUN4V_ERR_TYPE_WARNING_RES) {
1877 /* If err_type is 0x4, it's a powerdown request. Do
1878 * not do the usual resumable error log because that
1879 * makes it look like some abnormal error.
1880 */
1881 printk(KERN_INFO "Power down request...\n");
1882 kill_cad_pid(SIGINT, 1);
1883 return;
1884 }
1885
1876 sun4v_log_error(regs, &local_copy, cpu, 1886 sun4v_log_error(regs, &local_copy, cpu,
1877 KERN_ERR "RESUMABLE ERROR", 1887 KERN_ERR "RESUMABLE ERROR",
1878 &sun4v_resum_oflow_cnt); 1888 &sun4v_resum_oflow_cnt);
@@ -2261,8 +2271,12 @@ void die_if_kernel(char *str, struct pt_regs *regs)
2261 do_exit(SIGSEGV); 2271 do_exit(SIGSEGV);
2262} 2272}
2263 2273
2274#define VIS_OPCODE_MASK ((0x3 << 30) | (0x3f << 19))
2275#define VIS_OPCODE_VAL ((0x2 << 30) | (0x36 << 19))
2276
2264extern int handle_popc(u32 insn, struct pt_regs *regs); 2277extern int handle_popc(u32 insn, struct pt_regs *regs);
2265extern int handle_ldf_stq(u32 insn, struct pt_regs *regs); 2278extern int handle_ldf_stq(u32 insn, struct pt_regs *regs);
2279extern int vis_emul(struct pt_regs *, unsigned int);
2266 2280
2267void do_illegal_instruction(struct pt_regs *regs) 2281void do_illegal_instruction(struct pt_regs *regs)
2268{ 2282{
@@ -2287,10 +2301,18 @@ void do_illegal_instruction(struct pt_regs *regs)
2287 if (handle_ldf_stq(insn, regs)) 2301 if (handle_ldf_stq(insn, regs))
2288 return; 2302 return;
2289 } else if (tlb_type == hypervisor) { 2303 } else if (tlb_type == hypervisor) {
2290 extern int vis_emul(struct pt_regs *, unsigned int); 2304 if ((insn & VIS_OPCODE_MASK) == VIS_OPCODE_VAL) {
2305 if (!vis_emul(regs, insn))
2306 return;
2307 } else {
2308 struct fpustate *f = FPUSTATE;
2291 2309
2292 if (!vis_emul(regs, insn)) 2310 /* XXX maybe verify XFSR bits like
2293 return; 2311 * XXX do_fpother() does?
2312 */
2313 if (do_mathemu(regs, f))
2314 return;
2315 }
2294 } 2316 }
2295 } 2317 }
2296 info.si_signo = SIGILL; 2318 info.si_signo = SIGILL;
diff --git a/arch/sparc64/kernel/unaligned.c b/arch/sparc64/kernel/unaligned.c
index a9b765271b85..bc18d480dd1c 100644
--- a/arch/sparc64/kernel/unaligned.c
+++ b/arch/sparc64/kernel/unaligned.c
@@ -243,7 +243,7 @@ static inline int ok_for_kernel(unsigned int insn)
243 return !floating_point_load_or_store_p(insn); 243 return !floating_point_load_or_store_p(insn);
244} 244}
245 245
246static void kernel_mna_trap_fault(void) 246static void kernel_mna_trap_fault(int fixup_tstate_asi)
247{ 247{
248 struct pt_regs *regs = current_thread_info()->kern_una_regs; 248 struct pt_regs *regs = current_thread_info()->kern_una_regs;
249 unsigned int insn = current_thread_info()->kern_una_insn; 249 unsigned int insn = current_thread_info()->kern_una_insn;
@@ -274,18 +274,15 @@ static void kernel_mna_trap_fault(void)
274 regs->tpc = entry->fixup; 274 regs->tpc = entry->fixup;
275 regs->tnpc = regs->tpc + 4; 275 regs->tnpc = regs->tpc + 4;
276 276
277 regs->tstate &= ~TSTATE_ASI; 277 if (fixup_tstate_asi) {
278 regs->tstate |= (ASI_AIUS << 24UL); 278 regs->tstate &= ~TSTATE_ASI;
279 regs->tstate |= (ASI_AIUS << 24UL);
280 }
279} 281}
280 282
281asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn) 283static void log_unaligned(struct pt_regs *regs)
282{ 284{
283 static unsigned long count, last_time; 285 static unsigned long count, last_time;
284 enum direction dir = decode_direction(insn);
285 int size = decode_access_size(insn);
286
287 current_thread_info()->kern_una_regs = regs;
288 current_thread_info()->kern_una_insn = insn;
289 286
290 if (jiffies - last_time > 5 * HZ) 287 if (jiffies - last_time > 5 * HZ)
291 count = 0; 288 count = 0;
@@ -295,6 +292,28 @@ asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
295 printk("Kernel unaligned access at TPC[%lx] ", regs->tpc); 292 printk("Kernel unaligned access at TPC[%lx] ", regs->tpc);
296 print_symbol("%s\n", regs->tpc); 293 print_symbol("%s\n", regs->tpc);
297 } 294 }
295}
296
297asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
298{
299 enum direction dir = decode_direction(insn);
300 int size = decode_access_size(insn);
301 int orig_asi, asi;
302
303 current_thread_info()->kern_una_regs = regs;
304 current_thread_info()->kern_una_insn = insn;
305
306 orig_asi = asi = decode_asi(insn, regs);
307
308 /* If this is a {get,put}_user() on an unaligned userspace pointer,
309 * just signal a fault and do not log the event.
310 */
311 if (asi == ASI_AIUS) {
312 kernel_mna_trap_fault(0);
313 return;
314 }
315
316 log_unaligned(regs);
298 317
299 if (!ok_for_kernel(insn) || dir == both) { 318 if (!ok_for_kernel(insn) || dir == both) {
300 printk("Unsupported unaligned load/store trap for kernel " 319 printk("Unsupported unaligned load/store trap for kernel "
@@ -302,10 +321,10 @@ asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
302 unaligned_panic("Kernel does fpu/atomic " 321 unaligned_panic("Kernel does fpu/atomic "
303 "unaligned load/store.", regs); 322 "unaligned load/store.", regs);
304 323
305 kernel_mna_trap_fault(); 324 kernel_mna_trap_fault(0);
306 } else { 325 } else {
307 unsigned long addr, *reg_addr; 326 unsigned long addr, *reg_addr;
308 int orig_asi, asi, err; 327 int err;
309 328
310 addr = compute_effective_address(regs, insn, 329 addr = compute_effective_address(regs, insn,
311 ((insn >> 25) & 0x1f)); 330 ((insn >> 25) & 0x1f));
@@ -315,7 +334,6 @@ asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
315 regs->tpc, dirstrings[dir], addr, size, 334 regs->tpc, dirstrings[dir], addr, size,
316 regs->u_regs[UREG_RETPC]); 335 regs->u_regs[UREG_RETPC]);
317#endif 336#endif
318 orig_asi = asi = decode_asi(insn, regs);
319 switch (asi) { 337 switch (asi) {
320 case ASI_NL: 338 case ASI_NL:
321 case ASI_AIUPL: 339 case ASI_AIUPL:
@@ -365,7 +383,7 @@ asmlinkage void kernel_unaligned_trap(struct pt_regs *regs, unsigned int insn)
365 /* Not reached... */ 383 /* Not reached... */
366 } 384 }
367 if (unlikely(err)) 385 if (unlikely(err))
368 kernel_mna_trap_fault(); 386 kernel_mna_trap_fault(1);
369 else 387 else
370 advance(regs); 388 advance(regs);
371 } 389 }
diff --git a/arch/sparc64/kernel/visemul.c b/arch/sparc64/kernel/visemul.c
index 84fedaa38aae..c3fd64706b53 100644
--- a/arch/sparc64/kernel/visemul.c
+++ b/arch/sparc64/kernel/visemul.c
@@ -128,9 +128,6 @@
128/* 001001100 - Permute bytes as specified by GSR.MASK */ 128/* 001001100 - Permute bytes as specified by GSR.MASK */
129#define BSHUFFLE_OPF 0x04c 129#define BSHUFFLE_OPF 0x04c
130 130
131#define VIS_OPCODE_MASK ((0x3 << 30) | (0x3f << 19))
132#define VIS_OPCODE_VAL ((0x2 << 30) | (0x36 << 19))
133
134#define VIS_OPF_SHIFT 5 131#define VIS_OPF_SHIFT 5
135#define VIS_OPF_MASK (0x1ff << VIS_OPF_SHIFT) 132#define VIS_OPF_MASK (0x1ff << VIS_OPF_SHIFT)
136 133
@@ -810,9 +807,6 @@ int vis_emul(struct pt_regs *regs, unsigned int insn)
810 if (get_user(insn, (u32 __user *) pc)) 807 if (get_user(insn, (u32 __user *) pc))
811 return -EFAULT; 808 return -EFAULT;
812 809
813 if ((insn & VIS_OPCODE_MASK) != VIS_OPCODE_VAL)
814 return -EINVAL;
815
816 opf = (insn & VIS_OPF_MASK) >> VIS_OPF_SHIFT; 810 opf = (insn & VIS_OPF_MASK) >> VIS_OPF_SHIFT;
817 switch (opf) { 811 switch (opf) {
818 default: 812 default:
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index d70b60a3bbcc..737c26923c09 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -477,6 +477,10 @@ xcall_sync_tick:
477 sethi %hi(109f), %g7 477 sethi %hi(109f), %g7
478 b,pt %xcc, etrap_irq 478 b,pt %xcc, etrap_irq
479109: or %g7, %lo(109b), %g7 479109: or %g7, %lo(109b), %g7
480#ifdef CONFIG_TRACE_IRQFLAGS
481 call trace_hardirqs_off
482 nop
483#endif
480 call smp_synchronize_tick_client 484 call smp_synchronize_tick_client
481 nop 485 nop
482 clr %l6 486 clr %l6
@@ -508,6 +512,10 @@ xcall_report_regs:
508 sethi %hi(109f), %g7 512 sethi %hi(109f), %g7
509 b,pt %xcc, etrap_irq 513 b,pt %xcc, etrap_irq
510109: or %g7, %lo(109b), %g7 514109: or %g7, %lo(109b), %g7
515#ifdef CONFIG_TRACE_IRQFLAGS
516 call trace_hardirqs_off
517 nop
518#endif
511 call __show_regs 519 call __show_regs
512 add %sp, PTREGS_OFF, %o0 520 add %sp, PTREGS_OFF, %o0
513 clr %l6 521 clr %l6
diff --git a/arch/sparc64/solaris/fs.c b/arch/sparc64/solaris/fs.c
index 12a940cc791f..61be597bf430 100644
--- a/arch/sparc64/solaris/fs.c
+++ b/arch/sparc64/solaris/fs.c
@@ -449,7 +449,7 @@ asmlinkage int solaris_fstatvfs(unsigned int fd, u32 buf)
449 error = -EBADF; 449 error = -EBADF;
450 file = fget(fd); 450 file = fget(fd);
451 if (file) { 451 if (file) {
452 error = report_statvfs(file->f_vfsmnt, file->f_dentry->d_inode, buf); 452 error = report_statvfs(file->f_path.mnt, file->f_path.dentry->d_inode, buf);
453 fput(file); 453 fput(file);
454 } 454 }
455 455
@@ -481,7 +481,7 @@ asmlinkage int solaris_fstatvfs64(unsigned int fd, u32 buf)
481 file = fget(fd); 481 file = fget(fd);
482 if (file) { 482 if (file) {
483 lock_kernel(); 483 lock_kernel();
484 error = report_statvfs64(file->f_vfsmnt, file->f_dentry->d_inode, buf); 484 error = report_statvfs64(file->f_path.mnt, file->f_path.dentry->d_inode, buf);
485 unlock_kernel(); 485 unlock_kernel();
486 fput(file); 486 fput(file);
487 } 487 }
diff --git a/arch/sparc64/solaris/ioctl.c b/arch/sparc64/solaris/ioctl.c
index be0a054e3ed6..330743c5b3d8 100644
--- a/arch/sparc64/solaris/ioctl.c
+++ b/arch/sparc64/solaris/ioctl.c
@@ -299,8 +299,8 @@ static inline int solaris_sockmod(unsigned int fd, unsigned int cmd, u32 arg)
299 rcu_read_lock(); 299 rcu_read_lock();
300 fdt = files_fdtable(current->files); 300 fdt = files_fdtable(current->files);
301 if (! fdt->fd[fd] || 301 if (! fdt->fd[fd] ||
302 ! fdt->fd[fd]->f_dentry || 302 ! fdt->fd[fd]->f_path.dentry ||
303 ! (ino = fdt->fd[fd]->f_dentry->d_inode) || 303 ! (ino = fdt->fd[fd]->f_path.dentry->d_inode) ||
304 ! S_ISSOCK(ino->i_mode)) { 304 ! S_ISSOCK(ino->i_mode)) {
305 rcu_read_unlock(); 305 rcu_read_unlock();
306 return TBADF; 306 return TBADF;
@@ -480,7 +480,7 @@ static inline int solaris_S(struct file *filp, unsigned int fd, unsigned int cmd
480 struct sol_socket_struct *sock; 480 struct sol_socket_struct *sock;
481 struct module_info *mi; 481 struct module_info *mi;
482 482
483 ino = filp->f_dentry->d_inode; 483 ino = filp->f_path.dentry->d_inode;
484 if (!S_ISSOCK(ino->i_mode)) 484 if (!S_ISSOCK(ino->i_mode))
485 return -EBADF; 485 return -EBADF;
486 sock = filp->private_data; 486 sock = filp->private_data;
diff --git a/arch/sparc64/solaris/misc.c b/arch/sparc64/solaris/misc.c
index 9ed997982f8d..bca16e8c95c3 100644
--- a/arch/sparc64/solaris/misc.c
+++ b/arch/sparc64/solaris/misc.c
@@ -77,7 +77,7 @@ static u32 do_solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u64 o
77 if (!file) 77 if (!file)
78 goto out; 78 goto out;
79 else { 79 else {
80 struct inode * inode = file->f_dentry->d_inode; 80 struct inode * inode = file->f_path.dentry->d_inode;
81 if(imajor(inode) == MEM_MAJOR && 81 if(imajor(inode) == MEM_MAJOR &&
82 iminor(inode) == 5) { 82 iminor(inode) == 5) {
83 flags |= MAP_ANONYMOUS; 83 flags |= MAP_ANONYMOUS;
@@ -423,9 +423,7 @@ asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
423 Solaris setpgrp and setsid? */ 423 Solaris setpgrp and setsid? */
424 ret = sys_setpgid(0, 0); 424 ret = sys_setpgid(0, 0);
425 if (ret) return ret; 425 if (ret) return ret;
426 mutex_lock(&tty_mutex); 426 proc_clear_tty(current);
427 current->signal->tty = NULL;
428 mutex_unlock(&tty_mutex);
429 return process_group(current); 427 return process_group(current);
430 } 428 }
431 case 2: /* getsid */ 429 case 2: /* getsid */
diff --git a/arch/sparc64/solaris/socksys.c b/arch/sparc64/solaris/socksys.c
index 7c90e41fd3be..89a4757f192f 100644
--- a/arch/sparc64/solaris/socksys.c
+++ b/arch/sparc64/solaris/socksys.c
@@ -96,13 +96,13 @@ static int socksys_open(struct inode * inode, struct file * filp)
96 * No shit. WTF is it supposed to do, anyway? 96 * No shit. WTF is it supposed to do, anyway?
97 * 97 *
98 * Try instead: 98 * Try instead:
99 * d_delete(filp->f_dentry), then d_instantiate with sock inode 99 * d_delete(filp->f_path.dentry), then d_instantiate with sock inode
100 */ 100 */
101 dentry = filp->f_dentry; 101 dentry = filp->f_path.dentry;
102 filp->f_dentry = dget(fcheck(fd)->f_dentry); 102 filp->f_path.dentry = dget(fcheck(fd)->f_path.dentry);
103 filp->f_dentry->d_inode->i_rdev = inode->i_rdev; 103 filp->f_path.dentry->d_inode->i_rdev = inode->i_rdev;
104 filp->f_dentry->d_inode->i_flock = inode->i_flock; 104 filp->f_path.dentry->d_inode->i_flock = inode->i_flock;
105 SOCKET_I(filp->f_dentry->d_inode)->file = filp; 105 SOCKET_I(filp->f_path.dentry->d_inode)->file = filp;
106 filp->f_op = &socksys_file_ops; 106 filp->f_op = &socksys_file_ops;
107 sock = (struct sol_socket_struct*) 107 sock = (struct sol_socket_struct*)
108 mykmalloc(sizeof(struct sol_socket_struct), GFP_KERNEL); 108 mykmalloc(sizeof(struct sol_socket_struct), GFP_KERNEL);
@@ -148,7 +148,7 @@ static unsigned int socksys_poll(struct file * filp, poll_table * wait)
148 struct inode *ino; 148 struct inode *ino;
149 unsigned int mask = 0; 149 unsigned int mask = 0;
150 150
151 ino=filp->f_dentry->d_inode; 151 ino=filp->f_path.dentry->d_inode;
152 if (ino && S_ISSOCK(ino->i_mode)) { 152 if (ino && S_ISSOCK(ino->i_mode)) {
153 struct sol_socket_struct *sock; 153 struct sol_socket_struct *sock;
154 sock = (struct sol_socket_struct*)filp->private_data; 154 sock = (struct sol_socket_struct*)filp->private_data;
diff --git a/arch/sparc64/solaris/timod.c b/arch/sparc64/solaris/timod.c
index b84e5456b025..a9d32ceabf26 100644
--- a/arch/sparc64/solaris/timod.c
+++ b/arch/sparc64/solaris/timod.c
@@ -147,7 +147,7 @@ static void timod_wake_socket(unsigned int fd)
147 147
148 SOLD("wakeing socket"); 148 SOLD("wakeing socket");
149 fdt = files_fdtable(current->files); 149 fdt = files_fdtable(current->files);
150 sock = SOCKET_I(fdt->fd[fd]->f_dentry->d_inode); 150 sock = SOCKET_I(fdt->fd[fd]->f_path.dentry->d_inode);
151 wake_up_interruptible(&sock->wait); 151 wake_up_interruptible(&sock->wait);
152 read_lock(&sock->sk->sk_callback_lock); 152 read_lock(&sock->sk->sk_callback_lock);
153 if (sock->fasync_list && !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags)) 153 if (sock->fasync_list && !test_bit(SOCK_ASYNC_WAITDATA, &sock->flags))
@@ -361,7 +361,7 @@ int timod_putmsg(unsigned int fd, char __user *ctl_buf, int ctl_len,
361 361
362 fdt = files_fdtable(current->files); 362 fdt = files_fdtable(current->files);
363 filp = fdt->fd[fd]; 363 filp = fdt->fd[fd];
364 ino = filp->f_dentry->d_inode; 364 ino = filp->f_path.dentry->d_inode;
365 sock = (struct sol_socket_struct *)filp->private_data; 365 sock = (struct sol_socket_struct *)filp->private_data;
366 SOLD("entry"); 366 SOLD("entry");
367 if (get_user(ret, (int __user *)A(ctl_buf))) 367 if (get_user(ret, (int __user *)A(ctl_buf)))
@@ -644,7 +644,7 @@ int timod_getmsg(unsigned int fd, char __user *ctl_buf, int ctl_maxlen, s32 __us
644 SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p)); 644 SOLDD(("%u %p %d %p %p %d %p %d\n", fd, ctl_buf, ctl_maxlen, ctl_len, data_buf, data_maxlen, data_len, *flags_p));
645 fdt = files_fdtable(current->files); 645 fdt = files_fdtable(current->files);
646 filp = fdt->fd[fd]; 646 filp = fdt->fd[fd];
647 ino = filp->f_dentry->d_inode; 647 ino = filp->f_path.dentry->d_inode;
648 sock = (struct sol_socket_struct *)filp->private_data; 648 sock = (struct sol_socket_struct *)filp->private_data;
649 SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL)); 649 SOLDD(("%p %p\n", sock->pfirst, sock->pfirst ? sock->pfirst->next : NULL));
650 if ( ctl_maxlen > 0 && !sock->pfirst && SOCKET_I(ino)->type == SOCK_STREAM 650 if ( ctl_maxlen > 0 && !sock->pfirst && SOCKET_I(ino)->type == SOCK_STREAM
@@ -865,7 +865,7 @@ asmlinkage int solaris_getmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
865 filp = fdt->fd[fd]; 865 filp = fdt->fd[fd];
866 if(!filp) goto out; 866 if(!filp) goto out;
867 867
868 ino = filp->f_dentry->d_inode; 868 ino = filp->f_path.dentry->d_inode;
869 if (!ino || !S_ISSOCK(ino->i_mode)) 869 if (!ino || !S_ISSOCK(ino->i_mode))
870 goto out; 870 goto out;
871 871
@@ -933,7 +933,7 @@ asmlinkage int solaris_putmsg(unsigned int fd, u32 arg1, u32 arg2, u32 arg3)
933 filp = fdt->fd[fd]; 933 filp = fdt->fd[fd];
934 if(!filp) goto out; 934 if(!filp) goto out;
935 935
936 ino = filp->f_dentry->d_inode; 936 ino = filp->f_path.dentry->d_inode;
937 if (!ino) goto out; 937 if (!ino) goto out;
938 938
939 if (!S_ISSOCK(ino->i_mode) && 939 if (!S_ISSOCK(ino->i_mode) &&
diff --git a/arch/um/Kconfig b/arch/um/Kconfig
index 5ac1f2963ae3..d32a80e6668c 100644
--- a/arch/um/Kconfig
+++ b/arch/um/Kconfig
@@ -47,6 +47,11 @@ config GENERIC_CALIBRATE_DELAY
47 bool 47 bool
48 default y 48 default y
49 49
50config GENERIC_BUG
51 bool
52 default y
53 depends on BUG
54
50# Used in kernel/irq/manage.c and include/linux/irq.h 55# Used in kernel/irq/manage.c and include/linux/irq.h
51config IRQ_RELEASE_METHOD 56config IRQ_RELEASE_METHOD
52 bool 57 bool
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index aa3090d05a8f..83301e1ef67c 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -246,7 +246,7 @@ out_up:
246 return ret; 246 return ret;
247} 247}
248 248
249void line_set_termios(struct tty_struct *tty, struct termios * old) 249void line_set_termios(struct tty_struct *tty, struct ktermios * old)
250{ 250{
251 /* nothing */ 251 /* nothing */
252} 252}
diff --git a/arch/um/include/line.h b/arch/um/include/line.h
index 214ee76c40df..5f232ae89fbb 100644
--- a/arch/um/include/line.h
+++ b/arch/um/include/line.h
@@ -76,7 +76,7 @@ extern int line_setup(struct line *lines, unsigned int sizeof_lines,
76extern int line_write(struct tty_struct *tty, const unsigned char *buf, 76extern int line_write(struct tty_struct *tty, const unsigned char *buf,
77 int len); 77 int len);
78extern void line_put_char(struct tty_struct *tty, unsigned char ch); 78extern void line_put_char(struct tty_struct *tty, unsigned char ch);
79extern void line_set_termios(struct tty_struct *tty, struct termios * old); 79extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
80extern int line_chars_in_buffer(struct tty_struct *tty); 80extern int line_chars_in_buffer(struct tty_struct *tty);
81extern void line_flush_buffer(struct tty_struct *tty); 81extern void line_flush_buffer(struct tty_struct *tty);
82extern void line_flush_chars(struct tty_struct *tty); 82extern void line_flush_chars(struct tty_struct *tty);
diff --git a/arch/um/kernel/exec.c b/arch/um/kernel/exec.c
index 0561c43b4685..8d56ec6cca79 100644
--- a/arch/um/kernel/exec.c
+++ b/arch/um/kernel/exec.c
@@ -39,12 +39,13 @@ static long execve1(char *file, char __user * __user *argv,
39 char __user *__user *env) 39 char __user *__user *env)
40{ 40{
41 long error; 41 long error;
42 struct tty_struct *tty;
42 43
43#ifdef CONFIG_TTY_LOG 44#ifdef CONFIG_TTY_LOG
44 mutex_lock(&tty_mutex); 45 mutex_lock(&tty_mutex);
45 task_lock(current); /* FIXME: is this needed ? */ 46 tty = get_current_tty();
46 log_exec(argv, current->signal->tty); 47 if (tty)
47 task_unlock(current); 48 log_exec(argv, tty);
48 mutex_unlock(&tty_mutex); 49 mutex_unlock(&tty_mutex);
49#endif 50#endif
50 error = do_execve(file, argv, env, &current->thread.regs); 51 error = do_execve(file, argv, env, &current->thread.regs);
diff --git a/arch/um/sys-i386/Makefile b/arch/um/sys-i386/Makefile
index 0e32adf03be1..098720be019a 100644
--- a/arch/um/sys-i386/Makefile
+++ b/arch/um/sys-i386/Makefile
@@ -1,4 +1,4 @@
1obj-y = bugs.o checksum.o delay.o fault.o ksyms.o ldt.o ptrace.o \ 1obj-y = bug.o bugs.o checksum.o delay.o fault.o ksyms.o ldt.o ptrace.o \
2 ptrace_user.o setjmp.o signal.o sigcontext.o syscalls.o sysrq.o \ 2 ptrace_user.o setjmp.o signal.o sigcontext.o syscalls.o sysrq.o \
3 sys_call_table.o tls.o 3 sys_call_table.o tls.o
4 4
diff --git a/arch/um/sys-i386/bug.c b/arch/um/sys-i386/bug.c
new file mode 100644
index 000000000000..200c8ba2879b
--- /dev/null
+++ b/arch/um/sys-i386/bug.c
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2006 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL V2
4 */
5
6#include <linux/uaccess.h>
7
8/* Mostly copied from i386/x86_86 - eliminated the eip < PAGE_OFFSET because
9 * that's not relevent in skas mode.
10 */
11
12int is_valid_bugaddr(unsigned long eip)
13{
14 unsigned short ud2;
15
16 if (probe_kernel_address((unsigned short __user *)eip, ud2))
17 return 0;
18
19 return ud2 == 0x0b0f;
20}
diff --git a/arch/um/sys-x86_64/Makefile b/arch/um/sys-x86_64/Makefile
index f41768b8e25e..4d9e5efa6fb9 100644
--- a/arch/um/sys-x86_64/Makefile
+++ b/arch/um/sys-x86_64/Makefile
@@ -4,7 +4,7 @@
4# Licensed under the GPL 4# Licensed under the GPL
5# 5#
6 6
7obj-y = bugs.o delay.o fault.o ldt.o mem.o ptrace.o ptrace_user.o \ 7obj-y = bug.o bugs.o delay.o fault.o ldt.o mem.o ptrace.o ptrace_user.o \
8 setjmp.o sigcontext.o signal.o syscalls.o syscall_table.o sysrq.o \ 8 setjmp.o sigcontext.o signal.o syscalls.o syscall_table.o sysrq.o \
9 ksyms.o tls.o 9 ksyms.o tls.o
10 10
diff --git a/arch/um/sys-x86_64/bug.c b/arch/um/sys-x86_64/bug.c
new file mode 100644
index 000000000000..200c8ba2879b
--- /dev/null
+++ b/arch/um/sys-x86_64/bug.c
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2006 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL V2
4 */
5
6#include <linux/uaccess.h>
7
8/* Mostly copied from i386/x86_86 - eliminated the eip < PAGE_OFFSET because
9 * that's not relevent in skas mode.
10 */
11
12int is_valid_bugaddr(unsigned long eip)
13{
14 unsigned short ud2;
15
16 if (probe_kernel_address((unsigned short __user *)eip, ud2))
17 return 0;
18
19 return ud2 == 0x0b0f;
20}
diff --git a/arch/v850/Kconfig b/arch/v850/Kconfig
index 37ec644603ab..bcf825875d17 100644
--- a/arch/v850/Kconfig
+++ b/arch/v850/Kconfig
@@ -38,6 +38,14 @@ config TIME_LOW_RES
38 bool 38 bool
39 default y 39 default y
40 40
41config ARCH_HAS_ILOG2_U32
42 bool
43 default n
44
45config ARCH_HAS_ILOG2_U64
46 bool
47 default n
48
41# Turn off some random 386 crap that can affect device config 49# Turn off some random 386 crap that can affect device config
42config ISA 50config ISA
43 bool 51 bool
diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index bfbb9bcae123..d4275537b25b 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -96,6 +96,19 @@ config AUDIT_ARCH
96 bool 96 bool
97 default y 97 default y
98 98
99config GENERIC_BUG
100 bool
101 default y
102 depends on BUG
103
104config ARCH_HAS_ILOG2_U32
105 bool
106 default n
107
108config ARCH_HAS_ILOG2_U64
109 bool
110 default n
111
99source "init/Kconfig" 112source "init/Kconfig"
100 113
101 114
@@ -571,7 +584,7 @@ config SECCOMP
571 If unsure, say Y. Only embedded should say N here. 584 If unsure, say Y. Only embedded should say N here.
572 585
573config CC_STACKPROTECTOR 586config CC_STACKPROTECTOR
574 bool "Enable -fstack-protector buffer overflow detection (EXPRIMENTAL)" 587 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
575 depends on EXPERIMENTAL 588 depends on EXPERIMENTAL
576 help 589 help
577 This option turns on the -fstack-protector GCC feature. This 590 This option turns on the -fstack-protector GCC feature. This
diff --git a/arch/x86_64/defconfig b/arch/x86_64/defconfig
index 96f226cfb339..1a1c6a1a299b 100644
--- a/arch/x86_64/defconfig
+++ b/arch/x86_64/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.19-git7 3# Linux kernel version: 2.6.19-git14
4# Wed Dec 6 23:50:47 2006 4# Sat Dec 9 21:23:09 2006
5# 5#
6CONFIG_X86_64=y 6CONFIG_X86_64=y
7CONFIG_64BIT=y 7CONFIG_64BIT=y
@@ -22,6 +22,9 @@ CONFIG_ARCH_MAY_HAVE_PC_FDC=y
22CONFIG_ARCH_POPULATES_NODE_MAP=y 22CONFIG_ARCH_POPULATES_NODE_MAP=y
23CONFIG_DMI=y 23CONFIG_DMI=y
24CONFIG_AUDIT_ARCH=y 24CONFIG_AUDIT_ARCH=y
25CONFIG_GENERIC_BUG=y
26# CONFIG_ARCH_HAS_ILOG2_U32 is not set
27# CONFIG_ARCH_HAS_ILOG2_U64 is not set
25CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 28CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
26 29
27# 30#
@@ -170,6 +173,7 @@ CONFIG_SECCOMP=y
170# CONFIG_CC_STACKPROTECTOR is not set 173# CONFIG_CC_STACKPROTECTOR is not set
171# CONFIG_HZ_100 is not set 174# CONFIG_HZ_100 is not set
172CONFIG_HZ_250=y 175CONFIG_HZ_250=y
176# CONFIG_HZ_300 is not set
173# CONFIG_HZ_1000 is not set 177# CONFIG_HZ_1000 is not set
174CONFIG_HZ=250 178CONFIG_HZ=250
175# CONFIG_REORDER is not set 179# CONFIG_REORDER is not set
@@ -514,6 +518,7 @@ CONFIG_IDEDMA_AUTO=y
514# 518#
515# CONFIG_RAID_ATTRS is not set 519# CONFIG_RAID_ATTRS is not set
516CONFIG_SCSI=y 520CONFIG_SCSI=y
521# CONFIG_SCSI_TGT is not set
517CONFIG_SCSI_NETLINK=y 522CONFIG_SCSI_NETLINK=y
518# CONFIG_SCSI_PROC_FS is not set 523# CONFIG_SCSI_PROC_FS is not set
519 524
@@ -534,6 +539,7 @@ CONFIG_CHR_DEV_SG=y
534# CONFIG_SCSI_MULTI_LUN is not set 539# CONFIG_SCSI_MULTI_LUN is not set
535CONFIG_SCSI_CONSTANTS=y 540CONFIG_SCSI_CONSTANTS=y
536# CONFIG_SCSI_LOGGING is not set 541# CONFIG_SCSI_LOGGING is not set
542# CONFIG_SCSI_SCAN_ASYNC is not set
537 543
538# 544#
539# SCSI Transports 545# SCSI Transports
@@ -587,6 +593,7 @@ CONFIG_MEGARAID_SAS=y
587# CONFIG_SCSI_DC395x is not set 593# CONFIG_SCSI_DC395x is not set
588# CONFIG_SCSI_DC390T is not set 594# CONFIG_SCSI_DC390T is not set
589# CONFIG_SCSI_DEBUG is not set 595# CONFIG_SCSI_DEBUG is not set
596# CONFIG_SCSI_SRP is not set
590 597
591# 598#
592# Serial ATA (prod) and Parallel ATA (experimental) drivers 599# Serial ATA (prod) and Parallel ATA (experimental) drivers
@@ -1106,10 +1113,7 @@ CONFIG_SOUND=y
1106# Open Sound System 1113# Open Sound System
1107# 1114#
1108CONFIG_SOUND_PRIME=y 1115CONFIG_SOUND_PRIME=y
1109CONFIG_OSS_OBSOLETE_DRIVER=y
1110# CONFIG_SOUND_BT878 is not set 1116# CONFIG_SOUND_BT878 is not set
1111# CONFIG_SOUND_EMU10K1 is not set
1112# CONFIG_SOUND_FUSION is not set
1113# CONFIG_SOUND_ES1371 is not set 1117# CONFIG_SOUND_ES1371 is not set
1114CONFIG_SOUND_ICH=y 1118CONFIG_SOUND_ICH=y
1115# CONFIG_SOUND_TRIDENT is not set 1119# CONFIG_SOUND_TRIDENT is not set
@@ -1119,6 +1123,11 @@ CONFIG_SOUND_ICH=y
1119# CONFIG_SOUND_OSS is not set 1123# CONFIG_SOUND_OSS is not set
1120 1124
1121# 1125#
1126# HID Devices
1127#
1128CONFIG_HID=y
1129
1130#
1122# USB support 1131# USB support
1123# 1132#
1124CONFIG_USB_ARCH_HAS_HCD=y 1133CONFIG_USB_ARCH_HAS_HCD=y
@@ -1182,8 +1191,7 @@ CONFIG_USB_STORAGE=y
1182# USB Input Devices 1191# USB Input Devices
1183# 1192#
1184CONFIG_USB_HID=y 1193CONFIG_USB_HID=y
1185CONFIG_USB_HIDINPUT=y 1194# CONFIG_USB_HID_POWERBOOK is not set
1186# CONFIG_USB_HIDINPUT_POWERBOOK is not set
1187# CONFIG_HID_FF is not set 1195# CONFIG_HID_FF is not set
1188# CONFIG_USB_HIDDEV is not set 1196# CONFIG_USB_HIDDEV is not set
1189# CONFIG_USB_AIPTEK is not set 1197# CONFIG_USB_AIPTEK is not set
@@ -1475,6 +1483,11 @@ CONFIG_NLS_ISO8859_15=y
1475CONFIG_NLS_UTF8=y 1483CONFIG_NLS_UTF8=y
1476 1484
1477# 1485#
1486# Distributed Lock Manager
1487#
1488# CONFIG_DLM is not set
1489
1490#
1478# Instrumentation Support 1491# Instrumentation Support
1479# 1492#
1480CONFIG_PROFILING=y 1493CONFIG_PROFILING=y
@@ -1504,6 +1517,7 @@ CONFIG_DETECT_SOFTLOCKUP=y
1504# CONFIG_DEBUG_SPINLOCK_SLEEP is not set 1517# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1505# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set 1518# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1506# CONFIG_DEBUG_KOBJECT is not set 1519# CONFIG_DEBUG_KOBJECT is not set
1520CONFIG_DEBUG_BUGVERBOSE=y
1507# CONFIG_DEBUG_INFO is not set 1521# CONFIG_DEBUG_INFO is not set
1508CONFIG_DEBUG_FS=y 1522CONFIG_DEBUG_FS=y
1509# CONFIG_DEBUG_VM is not set 1523# CONFIG_DEBUG_VM is not set
@@ -1534,6 +1548,7 @@ CONFIG_DEBUG_STACKOVERFLOW=y
1534# 1548#
1535# Library routines 1549# Library routines
1536# 1550#
1551CONFIG_BITREVERSE=y
1537# CONFIG_CRC_CCITT is not set 1552# CONFIG_CRC_CCITT is not set
1538# CONFIG_CRC16 is not set 1553# CONFIG_CRC16 is not set
1539CONFIG_CRC32=y 1554CONFIG_CRC32=y
diff --git a/arch/x86_64/ia32/ia32_aout.c b/arch/x86_64/ia32/ia32_aout.c
index 396d3c100011..be87df506f39 100644
--- a/arch/x86_64/ia32/ia32_aout.c
+++ b/arch/x86_64/ia32/ia32_aout.c
@@ -272,7 +272,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
272 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && 272 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
273 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) || 273 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
274 N_TRSIZE(ex) || N_DRSIZE(ex) || 274 N_TRSIZE(ex) || N_DRSIZE(ex) ||
275 i_size_read(bprm->file->f_dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) { 275 i_size_read(bprm->file->f_path.dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
276 return -ENOEXEC; 276 return -ENOEXEC;
277 } 277 }
278 278
@@ -357,7 +357,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
357 { 357 {
358 printk(KERN_WARNING 358 printk(KERN_WARNING
359 "fd_offset is not page aligned. Please convert program: %s\n", 359 "fd_offset is not page aligned. Please convert program: %s\n",
360 bprm->file->f_dentry->d_name.name); 360 bprm->file->f_path.dentry->d_name.name);
361 error_time = jiffies; 361 error_time = jiffies;
362 } 362 }
363#endif 363#endif
@@ -440,7 +440,7 @@ static int load_aout_library(struct file *file)
440 int retval; 440 int retval;
441 struct exec ex; 441 struct exec ex;
442 442
443 inode = file->f_dentry->d_inode; 443 inode = file->f_path.dentry->d_inode;
444 444
445 retval = -ENOEXEC; 445 retval = -ENOEXEC;
446 error = kernel_read(file, 0, (char *) &ex, sizeof(ex)); 446 error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
@@ -471,7 +471,7 @@ static int load_aout_library(struct file *file)
471 { 471 {
472 printk(KERN_WARNING 472 printk(KERN_WARNING
473 "N_TXTOFF is not page aligned. Please convert library: %s\n", 473 "N_TXTOFF is not page aligned. Please convert library: %s\n",
474 file->f_dentry->d_name.name); 474 file->f_path.dentry->d_name.name);
475 error_time = jiffies; 475 error_time = jiffies;
476 } 476 }
477#endif 477#endif
diff --git a/arch/x86_64/kernel/module.c b/arch/x86_64/kernel/module.c
index 9d0958ff547f..a888e67f5874 100644
--- a/arch/x86_64/kernel/module.c
+++ b/arch/x86_64/kernel/module.c
@@ -23,6 +23,7 @@
23#include <linux/string.h> 23#include <linux/string.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/bug.h>
26 27
27#include <asm/system.h> 28#include <asm/system.h>
28#include <asm/page.h> 29#include <asm/page.h>
@@ -173,10 +174,12 @@ int module_finalize(const Elf_Ehdr *hdr,
173 lseg, lseg + locks->sh_size, 174 lseg, lseg + locks->sh_size,
174 tseg, tseg + text->sh_size); 175 tseg, tseg + text->sh_size);
175 } 176 }
176 return 0; 177
178 return module_bug_finalize(hdr, sechdrs, me);
177} 179}
178 180
179void module_arch_cleanup(struct module *mod) 181void module_arch_cleanup(struct module *mod)
180{ 182{
181 alternatives_smp_module_del(mod); 183 alternatives_smp_module_del(mod);
184 module_bug_cleanup(mod);
182} 185}
diff --git a/arch/x86_64/kernel/nmi.c b/arch/x86_64/kernel/nmi.c
index 27e95e7922c1..186aebbae32d 100644
--- a/arch/x86_64/kernel/nmi.c
+++ b/arch/x86_64/kernel/nmi.c
@@ -193,6 +193,8 @@ void nmi_watchdog_default(void)
193 nmi_watchdog = NMI_IO_APIC; 193 nmi_watchdog = NMI_IO_APIC;
194} 194}
195 195
196static int endflag __initdata = 0;
197
196#ifdef CONFIG_SMP 198#ifdef CONFIG_SMP
197/* The performance counters used by NMI_LOCAL_APIC don't trigger when 199/* The performance counters used by NMI_LOCAL_APIC don't trigger when
198 * the CPU is idle. To make sure the NMI watchdog really ticks on all 200 * the CPU is idle. To make sure the NMI watchdog really ticks on all
@@ -200,7 +202,6 @@ void nmi_watchdog_default(void)
200 */ 202 */
201static __init void nmi_cpu_busy(void *data) 203static __init void nmi_cpu_busy(void *data)
202{ 204{
203 volatile int *endflag = data;
204 local_irq_enable_in_hardirq(); 205 local_irq_enable_in_hardirq();
205 /* Intentionally don't use cpu_relax here. This is 206 /* Intentionally don't use cpu_relax here. This is
206 to make sure that the performance counter really ticks, 207 to make sure that the performance counter really ticks,
@@ -208,14 +209,13 @@ static __init void nmi_cpu_busy(void *data)
208 pause instruction. On a real HT machine this is fine because 209 pause instruction. On a real HT machine this is fine because
209 all other CPUs are busy with "useless" delay loops and don't 210 all other CPUs are busy with "useless" delay loops and don't
210 care if they get somewhat less cycles. */ 211 care if they get somewhat less cycles. */
211 while (*endflag == 0) 212 while (endflag == 0)
212 barrier(); 213 mb();
213} 214}
214#endif 215#endif
215 216
216int __init check_nmi_watchdog (void) 217int __init check_nmi_watchdog (void)
217{ 218{
218 volatile int endflag = 0;
219 int *counts; 219 int *counts;
220 int cpu; 220 int cpu;
221 221
@@ -256,6 +256,7 @@ int __init check_nmi_watchdog (void)
256 if (!atomic_read(&nmi_active)) { 256 if (!atomic_read(&nmi_active)) {
257 kfree(counts); 257 kfree(counts);
258 atomic_set(&nmi_active, -1); 258 atomic_set(&nmi_active, -1);
259 endflag = 1;
259 return -1; 260 return -1;
260 } 261 }
261 endflag = 1; 262 endflag = 1;
diff --git a/arch/x86_64/kernel/traps.c b/arch/x86_64/kernel/traps.c
index a1641ffdffcf..b54ccc07f379 100644
--- a/arch/x86_64/kernel/traps.c
+++ b/arch/x86_64/kernel/traps.c
@@ -31,6 +31,7 @@
31#include <linux/kexec.h> 31#include <linux/kexec.h>
32#include <linux/unwind.h> 32#include <linux/unwind.h>
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <linux/bug.h>
34 35
35#include <asm/system.h> 36#include <asm/system.h>
36#include <asm/io.h> 37#include <asm/io.h>
@@ -524,30 +525,15 @@ bad:
524 printk("\n"); 525 printk("\n");
525} 526}
526 527
527void handle_BUG(struct pt_regs *regs) 528int is_valid_bugaddr(unsigned long rip)
528{ 529{
529 struct bug_frame f; 530 unsigned short ud2;
530 long len;
531 const char *prefix = "";
532 531
533 if (user_mode(regs)) 532 if (__copy_from_user(&ud2, (const void __user *) rip, sizeof(ud2)))
534 return; 533 return 0;
535 if (__copy_from_user(&f, (const void __user *) regs->rip, 534
536 sizeof(struct bug_frame))) 535 return ud2 == 0x0b0f;
537 return; 536}
538 if (f.filename >= 0 ||
539 f.ud2[0] != 0x0f || f.ud2[1] != 0x0b)
540 return;
541 len = __strnlen_user((char *)(long)f.filename, PATH_MAX) - 1;
542 if (len < 0 || len >= PATH_MAX)
543 f.filename = (int)(long)"unmapped filename";
544 else if (len > 50) {
545 f.filename += len - 50;
546 prefix = "...";
547 }
548 printk("----------- [cut here ] --------- [please bite here ] ---------\n");
549 printk(KERN_ALERT "Kernel BUG at %s%.50s:%d\n", prefix, (char *)(long)f.filename, f.line);
550}
551 537
552#ifdef CONFIG_BUG 538#ifdef CONFIG_BUG
553void out_of_line_bug(void) 539void out_of_line_bug(void)
@@ -627,7 +613,9 @@ void die(const char * str, struct pt_regs * regs, long err)
627{ 613{
628 unsigned long flags = oops_begin(); 614 unsigned long flags = oops_begin();
629 615
630 handle_BUG(regs); 616 if (!user_mode(regs))
617 report_bug(regs->rip);
618
631 __die(str, regs, err); 619 __die(str, regs, err);
632 oops_end(flags); 620 oops_end(flags);
633 do_exit(SIGSEGV); 621 do_exit(SIGSEGV);
diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S
index 6a1f8f491e5d..514be5dd2303 100644
--- a/arch/x86_64/kernel/vmlinux.lds.S
+++ b/arch/x86_64/kernel/vmlinux.lds.S
@@ -13,6 +13,7 @@ OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64")
13OUTPUT_ARCH(i386:x86-64) 13OUTPUT_ARCH(i386:x86-64)
14ENTRY(phys_startup_64) 14ENTRY(phys_startup_64)
15jiffies_64 = jiffies; 15jiffies_64 = jiffies;
16_proxy_pda = 0;
16PHDRS { 17PHDRS {
17 text PT_LOAD FLAGS(5); /* R_E */ 18 text PT_LOAD FLAGS(5); /* R_E */
18 data PT_LOAD FLAGS(7); /* RWE */ 19 data PT_LOAD FLAGS(7); /* RWE */
@@ -51,6 +52,8 @@ SECTIONS
51 52
52 RODATA 53 RODATA
53 54
55 BUG_TABLE
56
54 . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */ 57 . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
55 /* Data */ 58 /* Data */
56 .data : AT(ADDR(.data) - LOAD_OFFSET) { 59 .data : AT(ADDR(.data) - LOAD_OFFSET) {
diff --git a/arch/x86_64/kernel/vsyscall.c b/arch/x86_64/kernel/vsyscall.c
index 4a673f5397a0..2433d6fc68b1 100644
--- a/arch/x86_64/kernel/vsyscall.c
+++ b/arch/x86_64/kernel/vsyscall.c
@@ -225,8 +225,7 @@ out:
225 225
226static int vsyscall_sysctl_nostrat(ctl_table *t, int __user *name, int nlen, 226static int vsyscall_sysctl_nostrat(ctl_table *t, int __user *name, int nlen,
227 void __user *oldval, size_t __user *oldlenp, 227 void __user *oldval, size_t __user *oldlenp,
228 void __user *newval, size_t newlen, 228 void __user *newval, size_t newlen)
229 void **context)
230{ 229{
231 return -ENOSYS; 230 return -ENOSYS;
232} 231}
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index c1e69a1f92a4..2e74cb0b7807 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -34,31 +34,24 @@ config GENERIC_HARDIRQS
34 bool 34 bool
35 default y 35 default y
36 36
37config ARCH_HAS_ILOG2_U32
38 bool
39 default n
40
41config ARCH_HAS_ILOG2_U64
42 bool
43 default n
44
37source "init/Kconfig" 45source "init/Kconfig"
38 46
39menu "Processor type and features" 47menu "Processor type and features"
40 48
41choice 49choice
42 prompt "Xtensa Processor Configuration" 50 prompt "Xtensa Processor Configuration"
43 default XTENSA_CPU_LINUX_BE 51 default XTENSA_VARIANT_FSF
44 52
45config XTENSA_CPU_LINUX_BE 53config XTENSA_VARIANT_FSF
46 bool "linux_be" 54 bool "fsf"
47 ---help---
48 The linux_be processor configuration is the baseline Xtensa
49 configurations included in this kernel and also used by
50 binutils, gcc, and gdb. It contains no TIE, no coprocessors,
51 and the following configuration options:
52
53 Code Density Option 2 Misc Special Registers
54 NSA/NSAU Instructions 128-bit Data Bus Width
55 Processor ID 8K, 2-way I and D Caches
56 Zero-Overhead Loops 2 Inst Address Break Registers
57 Big Endian 2 Data Address Break Registers
58 64 General-Purpose Registers JTAG Interface and Trace Port
59 17 Interrupts MMU w/ TLBs and Autorefill
60 3 Interrupt Levels 8 Autorefill Ways (I/D TLBs)
61 3 Timers Unaligned Exceptions
62endchoice 55endchoice
63 56
64config MMU 57config MMU
diff --git a/arch/xtensa/Makefile b/arch/xtensa/Makefile
index 3a3a4c66ef87..95f836db38fa 100644
--- a/arch/xtensa/Makefile
+++ b/arch/xtensa/Makefile
@@ -11,13 +11,13 @@
11# this architecture 11# this architecture
12 12
13# Core configuration. 13# Core configuration.
14# (Use CPU=<xtensa_config> to use another default compiler.) 14# (Use VAR=<xtensa_config> to use another default compiler.)
15 15
16cpu-$(CONFIG_XTENSA_CPU_LINUX_BE) := linux_be 16variant-$(CONFIG_XTENSA_VARIANT_FSF) := fsf
17cpu-$(CONFIG_XTENSA_CPU_LINUX_CUSTOM) := linux_custom 17variant-$(CONFIG_XTENSA_VARIANT_LINUX_CUSTOM) := custom
18 18
19CPU = $(cpu-y) 19VARIANT = $(variant-y)
20export CPU 20export VARIANT
21 21
22# Platform configuration 22# Platform configuration
23 23
@@ -27,8 +27,6 @@ platform-$(CONFIG_XTENSA_PLATFORM_ISS) := iss
27PLATFORM = $(platform-y) 27PLATFORM = $(platform-y)
28export PLATFORM 28export PLATFORM
29 29
30CPPFLAGS += $(if $(KBUILD_SRC),-I$(srctree)/include/asm-xtensa/)
31CPPFLAGS += -Iinclude/asm
32CFLAGS += -pipe -mlongcalls 30CFLAGS += -pipe -mlongcalls
33 31
34KBUILD_DEFCONFIG := iss_defconfig 32KBUILD_DEFCONFIG := iss_defconfig
@@ -41,12 +39,12 @@ core-$(CONFIG_EMBEDDED_RAMDISK) += arch/xtensa/boot/ramdisk/
41 39
42# Test for cross compiling 40# Test for cross compiling
43 41
44ifneq ($(CPU),) 42ifneq ($(VARIANT),)
45 COMPILE_ARCH = $(shell uname -m) 43 COMPILE_ARCH = $(shell uname -m)
46 44
47 ifneq ($(COMPILE_ARCH), xtensa) 45 ifneq ($(COMPILE_ARCH), xtensa)
48 ifndef CROSS_COMPILE 46 ifndef CROSS_COMPILE
49 CROSS_COMPILE = xtensa_$(CPU)- 47 CROSS_COMPILE = xtensa_$(VARIANT)-
50 endif 48 endif
51 endif 49 endif
52endif 50endif
@@ -68,14 +66,13 @@ archinc := include/asm-xtensa
68 66
69archprepare: $(archinc)/.platform 67archprepare: $(archinc)/.platform
70 68
71# Update machine cpu and platform symlinks if something which affects 69# Update processor variant and platform symlinks if something which affects
72# them changed. 70# them changed.
73 71
74$(archinc)/.platform: $(wildcard include/config/arch/*.h) include/config/auto.conf 72$(archinc)/.platform: $(wildcard include/config/arch/*.h) include/config/auto.conf
75 @echo ' SYMLINK $(archinc)/xtensa/config -> $(archinc)/xtensa/config-$(CPU)' 73 @echo ' SYMLINK $(archinc)/variant -> $(archinc)/variant-$(VARIANT)'
76 $(Q)mkdir -p $(archinc) 74 $(Q)mkdir -p $(archinc)
77 $(Q)mkdir -p $(archinc)/xtensa 75 $(Q)ln -fsn $(srctree)/$(archinc)/variant-$(VARIANT) $(archinc)/variant
78 $(Q)ln -fsn $(srctree)/$(archinc)/xtensa/config-$(CPU) $(archinc)/xtensa/config
79 @echo ' SYMLINK $(archinc)/platform -> $(archinc)/platform-$(PLATFORM)' 76 @echo ' SYMLINK $(archinc)/platform -> $(archinc)/platform-$(PLATFORM)'
80 $(Q)ln -fsn $(srctree)/$(archinc)/platform-$(PLATFORM) $(archinc)/platform 77 $(Q)ln -fsn $(srctree)/$(archinc)/platform-$(PLATFORM) $(archinc)/platform
81 @touch $@ 78 @touch $@
@@ -89,7 +86,7 @@ zImage zImage.initrd: vmlinux
89 $(Q)$(MAKE) $(build)=$(boot) $@ 86 $(Q)$(MAKE) $(build)=$(boot) $@
90 87
91CLEAN_FILES += arch/xtensa/vmlinux.lds \ 88CLEAN_FILES += arch/xtensa/vmlinux.lds \
92 $(archinc)/platform $(archinc)/xtensa/config \ 89 $(archinc)/platform $(archinc)/variant \
93 $(archinc)/.platform 90 $(archinc)/.platform
94 91
95define archhelp 92define archhelp
diff --git a/arch/xtensa/boot/boot-elf/bootstrap.S b/arch/xtensa/boot/boot-elf/bootstrap.S
index f857fc760aa8..464298bc348b 100644
--- a/arch/xtensa/boot/boot-elf/bootstrap.S
+++ b/arch/xtensa/boot/boot-elf/bootstrap.S
@@ -1,7 +1,4 @@
1 1
2#include <xtensa/config/specreg.h>
3#include <xtensa/config/core.h>
4
5#include <asm/bootparam.h> 2#include <asm/bootparam.h>
6 3
7 4
diff --git a/arch/xtensa/boot/boot-redboot/bootstrap.S b/arch/xtensa/boot/boot-redboot/bootstrap.S
index ee636b0da81c..84848123e2a8 100644
--- a/arch/xtensa/boot/boot-redboot/bootstrap.S
+++ b/arch/xtensa/boot/boot-redboot/bootstrap.S
@@ -1,9 +1,7 @@
1 1#include <asm/variant/core.h>
2#define _ASMLANGUAGE 2#include <asm/regs.h>
3#include <xtensa/config/specreg.h> 3#include <asm/asmmacro.h>
4#include <xtensa/config/core.h> 4#include <asm/cacheasm.h>
5#include <xtensa/cacheasm.h>
6
7 /* 5 /*
8 * RB-Data: RedBoot data/bss 6 * RB-Data: RedBoot data/bss
9 * P: Boot-Parameters 7 * P: Boot-Parameters
@@ -77,8 +75,14 @@ _start:
77 /* Note: The assembler cannot relax "addi a0, a0, ..." to an 75 /* Note: The assembler cannot relax "addi a0, a0, ..." to an
78 l32r, so we load to a4 first. */ 76 l32r, so we load to a4 first. */
79 77
80 addi a4, a0, __start - __start_a0 78 # addi a4, a0, __start - __start_a0
81 mov a0, a4 79 # mov a0, a4
80
81 movi a4, __start
82 movi a5, __start_a0
83 add a4, a0, a4
84 sub a0, a4, a5
85
82 movi a4, __start 86 movi a4, __start
83 movi a5, __reloc_end 87 movi a5, __reloc_end
84 88
@@ -106,9 +110,13 @@ _start:
106 /* We have to flush and invalidate the caches here before we jump. */ 110 /* We have to flush and invalidate the caches here before we jump. */
107 111
108#if XCHAL_DCACHE_IS_WRITEBACK 112#if XCHAL_DCACHE_IS_WRITEBACK
109 dcache_writeback_all a5, a6 113
114 ___flush_dcache_all a5 a6
115
110#endif 116#endif
111 icache_invalidate_all a5, a6 117
118 ___invalidate_icache_all a5 a6
119 isync
112 120
113 movi a11, _reloc 121 movi a11, _reloc
114 jx a11 122 jx a11
@@ -209,9 +217,14 @@ _reloc:
209 /* jump to the kernel */ 217 /* jump to the kernel */
2102: 2182:
211#if XCHAL_DCACHE_IS_WRITEBACK 219#if XCHAL_DCACHE_IS_WRITEBACK
212 dcache_writeback_all a5, a6 220
221 ___flush_dcache_all a5 a6
222
213#endif 223#endif
214 icache_invalidate_all a5, a6 224
225 ___invalidate_icache_all a5 a6
226
227 isync
215 228
216 movi a5, __start 229 movi a5, __start
217 movi a3, boot_initrd_start 230 movi a3, boot_initrd_start
diff --git a/arch/xtensa/configs/iss_defconfig b/arch/xtensa/configs/iss_defconfig
index 802621dd4867..f19854035e61 100644
--- a/arch/xtensa/configs/iss_defconfig
+++ b/arch/xtensa/configs/iss_defconfig
@@ -53,11 +53,7 @@ CONFIG_CC_ALIGN_JUMPS=0
53# 53#
54# Processor type and features 54# Processor type and features
55# 55#
56CONFIG_XTENSA_ARCH_LINUX_BE=y 56CONFIG_XTENSA_VARIANT_FSF=y
57# CONFIG_XTENSA_ARCH_LINUX_LE is not set
58# CONFIG_XTENSA_ARCH_LINUX_TEST is not set
59# CONFIG_XTENSA_ARCH_S5 is not set
60# CONFIG_XTENSA_CUSTOM is not set
61CONFIG_MMU=y 57CONFIG_MMU=y
62# CONFIG_XTENSA_UNALIGNED_USER is not set 58# CONFIG_XTENSA_UNALIGNED_USER is not set
63# CONFIG_PREEMPT is not set 59# CONFIG_PREEMPT is not set
diff --git a/arch/xtensa/kernel/align.S b/arch/xtensa/kernel/align.S
index a4956578a24d..33d6e9d2e83c 100644
--- a/arch/xtensa/kernel/align.S
+++ b/arch/xtensa/kernel/align.S
@@ -16,14 +16,9 @@
16 */ 16 */
17 17
18#include <linux/linkage.h> 18#include <linux/linkage.h>
19#include <asm/ptrace.h>
20#include <asm/ptrace.h>
21#include <asm/current.h> 19#include <asm/current.h>
22#include <asm/asm-offsets.h> 20#include <asm/asm-offsets.h>
23#include <asm/pgtable.h>
24#include <asm/processor.h> 21#include <asm/processor.h>
25#include <asm/page.h>
26#include <asm/thread_info.h>
27 22
28#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION 23#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
29 24
@@ -216,7 +211,7 @@ ENTRY(fast_unaligned)
216 211
217 extui a5, a4, INSN_OP0, 4 # get insn.op0 nibble 212 extui a5, a4, INSN_OP0, 4 # get insn.op0 nibble
218 213
219#if XCHAL_HAVE_NARROW 214#if XCHAL_HAVE_DENSITY
220 _beqi a5, OP0_L32I_N, .Lload # L32I.N, jump 215 _beqi a5, OP0_L32I_N, .Lload # L32I.N, jump
221 addi a6, a5, -OP0_S32I_N 216 addi a6, a5, -OP0_S32I_N
222 _beqz a6, .Lstore # S32I.N, do a store 217 _beqz a6, .Lstore # S32I.N, do a store
@@ -251,7 +246,7 @@ ENTRY(fast_unaligned)
251#endif 246#endif
252 __src_b a3, a5, a6 # a3 has the data word 247 __src_b a3, a5, a6 # a3 has the data word
253 248
254#if XCHAL_HAVE_NARROW 249#if XCHAL_HAVE_DENSITY
255 addi a7, a7, 2 # increment PC (assume 16-bit insn) 250 addi a7, a7, 2 # increment PC (assume 16-bit insn)
256 251
257 extui a5, a4, INSN_OP0, 4 252 extui a5, a4, INSN_OP0, 4
@@ -279,14 +274,14 @@ ENTRY(fast_unaligned)
279 274
2801: 2751:
281 276
282#if XCHAL_HAVE_LOOP 277#if XCHAL_HAVE_LOOPS
283 rsr a3, LEND # check if we reached LEND 278 rsr a5, LEND # check if we reached LEND
284 bne a7, a3, 1f 279 bne a7, a5, 1f
285 rsr a3, LCOUNT # and LCOUNT != 0 280 rsr a5, LCOUNT # and LCOUNT != 0
286 beqz a3, 1f 281 beqz a5, 1f
287 addi a3, a3, -1 # decrement LCOUNT and set 282 addi a5, a5, -1 # decrement LCOUNT and set
288 rsr a7, LBEG # set PC to LBEGIN 283 rsr a7, LBEG # set PC to LBEGIN
289 wsr a3, LCOUNT 284 wsr a5, LCOUNT
290#endif 285#endif
291 286
2921: wsr a7, EPC_1 # skip load instruction 2871: wsr a7, EPC_1 # skip load instruction
@@ -336,7 +331,7 @@ ENTRY(fast_unaligned)
336 331
337 movi a6, 0 # mask: ffffffff:00000000 332 movi a6, 0 # mask: ffffffff:00000000
338 333
339#if XCHAL_HAVE_NARROW 334#if XCHAL_HAVE_DENSITY
340 addi a7, a7, 2 # incr. PC,assume 16-bit instruction 335 addi a7, a7, 2 # incr. PC,assume 16-bit instruction
341 336
342 extui a5, a4, INSN_OP0, 4 # extract OP0 337 extui a5, a4, INSN_OP0, 4 # extract OP0
@@ -359,14 +354,14 @@ ENTRY(fast_unaligned)
359 /* Get memory address */ 354 /* Get memory address */
360 355
3611: 3561:
362#if XCHAL_HAVE_LOOP 357#if XCHAL_HAVE_LOOPS
363 rsr a3, LEND # check if we reached LEND 358 rsr a4, LEND # check if we reached LEND
364 bne a7, a3, 1f 359 bne a7, a4, 1f
365 rsr a3, LCOUNT # and LCOUNT != 0 360 rsr a4, LCOUNT # and LCOUNT != 0
366 beqz a3, 1f 361 beqz a4, 1f
367 addi a3, a3, -1 # decrement LCOUNT and set 362 addi a4, a4, -1 # decrement LCOUNT and set
368 rsr a7, LBEG # set PC to LBEGIN 363 rsr a7, LBEG # set PC to LBEGIN
369 wsr a3, LCOUNT 364 wsr a4, LCOUNT
370#endif 365#endif
371 366
3721: wsr a7, EPC_1 # skip store instruction 3671: wsr a7, EPC_1 # skip store instruction
@@ -416,6 +411,7 @@ ENTRY(fast_unaligned)
416 411
417 /* Restore working register */ 412 /* Restore working register */
418 413
414 l32i a8, a2, PT_AREG8
419 l32i a7, a2, PT_AREG7 415 l32i a7, a2, PT_AREG7
420 l32i a6, a2, PT_AREG6 416 l32i a6, a2, PT_AREG6
421 l32i a5, a2, PT_AREG5 417 l32i a5, a2, PT_AREG5
@@ -446,7 +442,7 @@ ENTRY(fast_unaligned)
446 mov a1, a2 442 mov a1, a2
447 443
448 rsr a0, PS 444 rsr a0, PS
449 bbsi.l a2, PS_UM_SHIFT, 1f # jump if user mode 445 bbsi.l a2, PS_UM_BIT, 1f # jump if user mode
450 446
451 movi a0, _kernel_exception 447 movi a0, _kernel_exception
452 jx a0 448 jx a0
diff --git a/arch/xtensa/kernel/asm-offsets.c b/arch/xtensa/kernel/asm-offsets.c
index 7cd1d7f8f608..b256cfbef344 100644
--- a/arch/xtensa/kernel/asm-offsets.c
+++ b/arch/xtensa/kernel/asm-offsets.c
@@ -87,6 +87,11 @@ int main(void)
87 DEFINE(MM_CONTEXT, offsetof (struct mm_struct, context)); 87 DEFINE(MM_CONTEXT, offsetof (struct mm_struct, context));
88 BLANK(); 88 BLANK();
89 DEFINE(PT_SINGLESTEP_BIT, PT_SINGLESTEP_BIT); 89 DEFINE(PT_SINGLESTEP_BIT, PT_SINGLESTEP_BIT);
90
91 /* constants */
92 DEFINE(_CLONE_VM, CLONE_VM);
93 DEFINE(_CLONE_UNTRACED, CLONE_UNTRACED);
94
90 return 0; 95 return 0;
91} 96}
92 97
diff --git a/arch/xtensa/kernel/coprocessor.S b/arch/xtensa/kernel/coprocessor.S
index cf5a93fb6a2e..01bcb9fcfcbd 100644
--- a/arch/xtensa/kernel/coprocessor.S
+++ b/arch/xtensa/kernel/coprocessor.S
@@ -90,7 +90,6 @@ ENTRY(enable_coprocessor)
90 rsync 90 rsync
91 retw 91 retw
92 92
93#endif
94 93
95ENTRY(save_coprocessor_extra) 94ENTRY(save_coprocessor_extra)
96 entry sp, 16 95 entry sp, 16
@@ -197,4 +196,5 @@ _xtensa_reginfo_tables:
197 XCHAL_CP7_SA_CONTENTS_LIBDB 196 XCHAL_CP7_SA_CONTENTS_LIBDB
198 .word 0xFC000000 /* invalid register number,marks end of table*/ 197 .word 0xFC000000 /* invalid register number,marks end of table*/
199_xtensa_reginfo_table_end: 198_xtensa_reginfo_table_end:
199#endif
200 200
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index 89e409e9e0de..9e271ba009bf 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -24,7 +24,7 @@
24#include <asm/pgtable.h> 24#include <asm/pgtable.h>
25#include <asm/page.h> 25#include <asm/page.h>
26#include <asm/signal.h> 26#include <asm/signal.h>
27#include <xtensa/coreasm.h> 27#include <asm/tlbflush.h>
28 28
29/* Unimplemented features. */ 29/* Unimplemented features. */
30 30
@@ -364,7 +364,7 @@ common_exception:
364 movi a2, 1 364 movi a2, 1
365 extui a3, a3, 0, 1 # a3 = PS.INTLEVEL[0] 365 extui a3, a3, 0, 1 # a3 = PS.INTLEVEL[0]
366 moveqz a3, a2, a0 # a3 = 1 iff interrupt exception 366 moveqz a3, a2, a0 # a3 = 1 iff interrupt exception
367 movi a2, PS_WOE_MASK 367 movi a2, 1 << PS_WOE_BIT
368 or a3, a3, a2 368 or a3, a3, a2
369 rsr a0, EXCCAUSE 369 rsr a0, EXCCAUSE
370 xsr a3, PS 370 xsr a3, PS
@@ -399,7 +399,7 @@ common_exception_return:
399 /* Jump if we are returning from kernel exceptions. */ 399 /* Jump if we are returning from kernel exceptions. */
400 400
4011: l32i a3, a1, PT_PS 4011: l32i a3, a1, PT_PS
402 _bbsi.l a3, PS_UM_SHIFT, 2f 402 _bbsi.l a3, PS_UM_BIT, 2f
403 j kernel_exception_exit 403 j kernel_exception_exit
404 404
405 /* Specific to a user exception exit: 405 /* Specific to a user exception exit:
@@ -422,7 +422,7 @@ common_exception_return:
422 * (Hint: There is only one user exception frame on stack) 422 * (Hint: There is only one user exception frame on stack)
423 */ 423 */
424 424
425 movi a3, PS_WOE_MASK 425 movi a3, 1 << PS_WOE_BIT
426 426
427 _bbsi.l a4, TIF_NEED_RESCHED, 3f 427 _bbsi.l a4, TIF_NEED_RESCHED, 3f
428 _bbci.l a4, TIF_SIGPENDING, 4f 428 _bbci.l a4, TIF_SIGPENDING, 4f
@@ -694,7 +694,7 @@ common_exception_exit:
694ENTRY(debug_exception) 694ENTRY(debug_exception)
695 695
696 rsr a0, EPS + XCHAL_DEBUGLEVEL 696 rsr a0, EPS + XCHAL_DEBUGLEVEL
697 bbsi.l a0, PS_EXCM_SHIFT, 1f # exception mode 697 bbsi.l a0, PS_EXCM_BIT, 1f # exception mode
698 698
699 /* Set EPC_1 and EXCCAUSE */ 699 /* Set EPC_1 and EXCCAUSE */
700 700
@@ -707,7 +707,7 @@ ENTRY(debug_exception)
707 707
708 /* Restore PS to the value before the debug exc but with PS.EXCM set.*/ 708 /* Restore PS to the value before the debug exc but with PS.EXCM set.*/
709 709
710 movi a2, 1 << PS_EXCM_SHIFT 710 movi a2, 1 << PS_EXCM_BIT
711 or a2, a0, a2 711 or a2, a0, a2
712 movi a0, debug_exception # restore a3, debug jump vector 712 movi a0, debug_exception # restore a3, debug jump vector
713 wsr a2, PS 713 wsr a2, PS
@@ -715,7 +715,7 @@ ENTRY(debug_exception)
715 715
716 /* Switch to kernel/user stack, restore jump vector, and save a0 */ 716 /* Switch to kernel/user stack, restore jump vector, and save a0 */
717 717
718 bbsi.l a2, PS_UM_SHIFT, 2f # jump if user mode 718 bbsi.l a2, PS_UM_BIT, 2f # jump if user mode
719 719
720 addi a2, a1, -16-PT_SIZE # assume kernel stack 720 addi a2, a1, -16-PT_SIZE # assume kernel stack
721 s32i a0, a2, PT_AREG0 721 s32i a0, a2, PT_AREG0
@@ -778,7 +778,7 @@ ENTRY(unrecoverable_exception)
778 wsr a1, WINDOWBASE 778 wsr a1, WINDOWBASE
779 rsync 779 rsync
780 780
781 movi a1, PS_WOE_MASK | 1 781 movi a1, (1 << PS_WOE_BIT) | 1
782 wsr a1, PS 782 wsr a1, PS
783 rsync 783 rsync
784 784
@@ -1004,13 +1004,10 @@ ENTRY(fast_syscall_kernel)
1004 1004
1005 rsr a0, DEPC # get syscall-nr 1005 rsr a0, DEPC # get syscall-nr
1006 _beqz a0, fast_syscall_spill_registers 1006 _beqz a0, fast_syscall_spill_registers
1007 1007 _beqi a0, __NR_xtensa, fast_syscall_xtensa
1008 addi a0, a0, -__NR_sysxtensa
1009 _beqz a0, fast_syscall_sysxtensa
1010 1008
1011 j kernel_exception 1009 j kernel_exception
1012 1010
1013
1014ENTRY(fast_syscall_user) 1011ENTRY(fast_syscall_user)
1015 1012
1016 /* Skip syscall. */ 1013 /* Skip syscall. */
@@ -1024,9 +1021,7 @@ ENTRY(fast_syscall_user)
1024 1021
1025 rsr a0, DEPC # get syscall-nr 1022 rsr a0, DEPC # get syscall-nr
1026 _beqz a0, fast_syscall_spill_registers 1023 _beqz a0, fast_syscall_spill_registers
1027 1024 _beqi a0, __NR_xtensa, fast_syscall_xtensa
1028 addi a0, a0, -__NR_sysxtensa
1029 _beqz a0, fast_syscall_sysxtensa
1030 1025
1031 j user_exception 1026 j user_exception
1032 1027
@@ -1047,18 +1042,19 @@ ENTRY(fast_syscall_unrecoverable)
1047/* 1042/*
1048 * sysxtensa syscall handler 1043 * sysxtensa syscall handler
1049 * 1044 *
1050 * int sysxtensa (XTENSA_ATOMIC_SET, ptr, val, unused); 1045 * int sysxtensa (SYS_XTENSA_ATOMIC_SET, ptr, val, unused);
1051 * int sysxtensa (XTENSA_ATOMIC_ADD, ptr, val, unused); 1046 * int sysxtensa (SYS_XTENSA_ATOMIC_ADD, ptr, val, unused);
1052 * int sysxtensa (XTENSA_ATOMIC_EXG_ADD, ptr, val, unused); 1047 * int sysxtensa (SYS_XTENSA_ATOMIC_EXG_ADD, ptr, val, unused);
1053 * int sysxtensa (XTENSA_ATOMIC_CMP_SWP, ptr, oldval, newval); 1048 * int sysxtensa (SYS_XTENSA_ATOMIC_CMP_SWP, ptr, oldval, newval);
1054 * a2 a6 a3 a4 a5 1049 * a2 a6 a3 a4 a5
1055 * 1050 *
1056 * Entry condition: 1051 * Entry condition:
1057 * 1052 *
1058 * a0: trashed, original value saved on stack (PT_AREG0) 1053 * a0: a2 (syscall-nr), original value saved on stack (PT_AREG0)
1059 * a1: a1 1054 * a1: a1
1060 * a2: new stack pointer, original in DEPC 1055 * a2: new stack pointer, original in a0 and DEPC
1061 * a3: dispatch table 1056 * a3: dispatch table, original in excsave_1
1057 * a4..a15: unchanged
1062 * depc: a2, original value saved on stack (PT_DEPC) 1058 * depc: a2, original value saved on stack (PT_DEPC)
1063 * excsave_1: a3 1059 * excsave_1: a3
1064 * 1060 *
@@ -1091,59 +1087,62 @@ ENTRY(fast_syscall_unrecoverable)
1091#define CATCH \ 1087#define CATCH \
109267: 108867:
1093 1089
1094ENTRY(fast_syscall_sysxtensa) 1090ENTRY(fast_syscall_xtensa)
1095
1096 _beqz a6, 1f
1097 _blti a6, SYSXTENSA_COUNT, 2f
1098 1091
10991: j user_exception 1092 xsr a3, EXCSAVE_1 # restore a3, excsave1
1100
11012: xsr a3, EXCSAVE_1 # restore a3, excsave1
1102 s32i a7, a2, PT_AREG7
1103 1093
1094 s32i a7, a2, PT_AREG7 # we need an additional register
1104 movi a7, 4 # sizeof(unsigned int) 1095 movi a7, 4 # sizeof(unsigned int)
1105 access_ok a0, a3, a7, a2, .Leac 1096 access_ok a3, a7, a0, a2, .Leac # a0: scratch reg, a2: sp
1106 1097
1107 _beqi a6, SYSXTENSA_ATOMIC_SET, .Lset 1098 addi a6, a6, -1 # assuming SYS_XTENSA_ATOMIC_SET = 1
1108 _beqi a6, SYSXTENSA_ATOMIC_EXG_ADD, .Lexg 1099 _bgeui a6, SYS_XTENSA_COUNT - 1, .Lill
1109 _beqi a6, SYSXTENSA_ATOMIC_ADD, .Ladd 1100 _bnei a6, SYS_XTENSA_ATOMIC_CMP_SWP - 1, .Lnswp
1110 1101
1111 /* Fall through for SYSXTENSA_ATOMIC_CMP_SWP */ 1102 /* Fall through for ATOMIC_CMP_SWP. */
1112 1103
1113.Lswp: /* Atomic compare and swap */ 1104.Lswp: /* Atomic compare and swap */
1114 1105
1115TRY l32i a7, a3, 0 # read old value 1106TRY l32i a0, a3, 0 # read old value
1116 bne a7, a4, 1f # same as old value? jump 1107 bne a0, a4, 1f # same as old value? jump
1117 s32i a5, a3, 0 # different, modify value 1108TRY s32i a5, a3, 0 # different, modify value
1118 movi a7, 1 # and return 1 1109 l32i a7, a2, PT_AREG7 # restore a7
1119 j .Lret 1110 l32i a0, a2, PT_AREG0 # restore a0
1120 1111 movi a2, 1 # and return 1
11211: movi a7, 0 # same values: return 0 1112 addi a6, a6, 1 # restore a6 (really necessary?)
1122 j .Lret 1113 rfe
1123
1124.Ladd: /* Atomic add */
1125.Lexg: /* Atomic (exchange) add */
1126 1114
1127TRY l32i a7, a3, 0 11151: l32i a7, a2, PT_AREG7 # restore a7
1128 add a4, a4, a7 1116 l32i a0, a2, PT_AREG0 # restore a0
1129 s32i a4, a3, 0 1117 movi a2, 0 # return 0 (note that we cannot set
1130 j .Lret 1118 addi a6, a6, 1 # restore a6 (really necessary?)
1119 rfe
1131 1120
1132.Lset: /* Atomic set */ 1121.Lnswp: /* Atomic set, add, and exg_add. */
1133 1122
1134TRY l32i a7, a3, 0 # read old value as return value 1123TRY l32i a7, a3, 0 # orig
1135 s32i a4, a3, 0 # write new value 1124 add a0, a4, a7 # + arg
1125 moveqz a0, a4, a6 # set
1126TRY s32i a0, a3, 0 # write new value
1136 1127
1137.Lret: mov a0, a2 1128 mov a0, a2
1138 mov a2, a7 1129 mov a2, a7
1139 l32i a7, a0, PT_AREG7 1130 l32i a7, a0, PT_AREG7 # restore a7
1140 l32i a3, a0, PT_AREG3 1131 l32i a0, a0, PT_AREG0 # restore a0
1141 l32i a0, a0, PT_AREG0 1132 addi a6, a6, 1 # restore a6 (really necessary?)
1142 rfe 1133 rfe
1143 1134
1144CATCH 1135CATCH
1145.Leac: movi a7, -EFAULT 1136.Leac: l32i a7, a2, PT_AREG7 # restore a7
1146 j .Lret 1137 l32i a0, a2, PT_AREG0 # restore a0
1138 movi a2, -EFAULT
1139 rfe
1140
1141.Lill: l32i a7, a2, PT_AREG0 # restore a7
1142 l32i a0, a2, PT_AREG0 # restore a0
1143 movi a2, -EINVAL
1144 rfe
1145
1147 1146
1148 1147
1149 1148
@@ -1491,7 +1490,7 @@ ENTRY(_spill_registers)
1491 */ 1490 */
1492 1491
1493 rsr a0, PS 1492 rsr a0, PS
1494 _bbci.l a0, PS_UM_SHIFT, 1f 1493 _bbci.l a0, PS_UM_BIT, 1f
1495 1494
1496 /* User space: Setup a dummy frame and kill application. 1495 /* User space: Setup a dummy frame and kill application.
1497 * Note: We assume EXC_TABLE_KSTK contains a valid stack pointer. 1496 * Note: We assume EXC_TABLE_KSTK contains a valid stack pointer.
@@ -1510,7 +1509,7 @@ ENTRY(_spill_registers)
1510 l32i a1, a3, EXC_TABLE_KSTK 1509 l32i a1, a3, EXC_TABLE_KSTK
1511 wsr a3, EXCSAVE_1 1510 wsr a3, EXCSAVE_1
1512 1511
1513 movi a4, PS_WOE_MASK | 1 1512 movi a4, (1 << PS_WOE_BIT) | 1
1514 wsr a4, PS 1513 wsr a4, PS
1515 rsync 1514 rsync
1516 1515
@@ -1612,7 +1611,7 @@ ENTRY(fast_second_level_miss)
1612 rsr a1, PTEVADDR 1611 rsr a1, PTEVADDR
1613 srli a1, a1, PAGE_SHIFT 1612 srli a1, a1, PAGE_SHIFT
1614 slli a1, a1, PAGE_SHIFT # ptevaddr & PAGE_MASK 1613 slli a1, a1, PAGE_SHIFT # ptevaddr & PAGE_MASK
1615 addi a1, a1, DTLB_WAY_PGTABLE # ... + way_number 1614 addi a1, a1, DTLB_WAY_PGD # ... + way_number
1616 1615
1617 wdtlb a0, a1 1616 wdtlb a0, a1
1618 dsync 1617 dsync
@@ -1654,7 +1653,7 @@ ENTRY(fast_second_level_miss)
1654 mov a1, a2 1653 mov a1, a2
1655 1654
1656 rsr a2, PS 1655 rsr a2, PS
1657 bbsi.l a2, PS_UM_SHIFT, 1f 1656 bbsi.l a2, PS_UM_BIT, 1f
1658 j _kernel_exception 1657 j _kernel_exception
16591: j _user_exception 16581: j _user_exception
1660 1659
@@ -1753,7 +1752,7 @@ ENTRY(fast_store_prohibited)
1753 mov a1, a2 1752 mov a1, a2
1754 1753
1755 rsr a2, PS 1754 rsr a2, PS
1756 bbsi.l a2, PS_UM_SHIFT, 1f 1755 bbsi.l a2, PS_UM_BIT, 1f
1757 j _kernel_exception 1756 j _kernel_exception
17581: j _user_exception 17571: j _user_exception
1759 1758
@@ -1907,6 +1906,103 @@ ENTRY(fast_coprocessor)
1907#endif /* XCHAL_EXTRA_SA_SIZE */ 1906#endif /* XCHAL_EXTRA_SA_SIZE */
1908 1907
1909/* 1908/*
1909 * System Calls.
1910 *
1911 * void system_call (struct pt_regs* regs, int exccause)
1912 * a2 a3
1913 */
1914
1915ENTRY(system_call)
1916 entry a1, 32
1917
1918 /* regs->syscall = regs->areg[2] */
1919
1920 l32i a3, a2, PT_AREG2
1921 mov a6, a2
1922 movi a4, do_syscall_trace_enter
1923 s32i a3, a2, PT_SYSCALL
1924 callx4 a4
1925
1926 /* syscall = sys_call_table[syscall_nr] */
1927
1928 movi a4, sys_call_table;
1929 movi a5, __NR_syscall_count
1930 movi a6, -ENOSYS
1931 bgeu a3, a5, 1f
1932
1933 addx4 a4, a3, a4
1934 l32i a4, a4, 0
1935 movi a5, sys_ni_syscall;
1936 beq a4, a5, 1f
1937
1938 /* Load args: arg0 - arg5 are passed via regs. */
1939
1940 l32i a6, a2, PT_AREG6
1941 l32i a7, a2, PT_AREG3
1942 l32i a8, a2, PT_AREG4
1943 l32i a9, a2, PT_AREG5
1944 l32i a10, a2, PT_AREG8
1945 l32i a11, a2, PT_AREG9
1946
1947 /* Pass one additional argument to the syscall: pt_regs (on stack) */
1948 s32i a2, a1, 0
1949
1950 callx4 a4
1951
19521: /* regs->areg[2] = return_value */
1953
1954 s32i a6, a2, PT_AREG2
1955 movi a4, do_syscall_trace_leave
1956 mov a6, a2
1957 callx4 a4
1958 retw
1959
1960
1961/*
1962 * Create a kernel thread
1963 *
1964 * int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
1965 * a2 a2 a3 a4
1966 */
1967
1968ENTRY(kernel_thread)
1969 entry a1, 16
1970
1971 mov a5, a2 # preserve fn over syscall
1972 mov a7, a3 # preserve args over syscall
1973
1974 movi a3, _CLONE_VM | _CLONE_UNTRACED
1975 movi a2, __NR_clone
1976 or a6, a4, a3 # arg0: flags
1977 mov a3, a1 # arg1: sp
1978 syscall
1979
1980 beq a3, a1, 1f # branch if parent
1981 mov a6, a7 # args
1982 callx4 a5 # fn(args)
1983
1984 movi a2, __NR_exit
1985 syscall # return value of fn(args) still in a6
1986
19871: retw
1988
1989/*
1990 * Do a system call from kernel instead of calling sys_execve, so we end up
1991 * with proper pt_regs.
1992 *
1993 * int kernel_execve(const char *fname, char *const argv[], charg *const envp[])
1994 * a2 a2 a3 a4
1995 */
1996
1997ENTRY(kernel_execve)
1998 entry a1, 16
1999 mov a6, a2 # arg0 is in a6
2000 movi a2, __NR_execve
2001 syscall
2002
2003 retw
2004
2005/*
1910 * Task switch. 2006 * Task switch.
1911 * 2007 *
1912 * struct task* _switch_to (struct task* prev, struct task* next) 2008 * struct task* _switch_to (struct task* prev, struct task* next)
@@ -1924,7 +2020,7 @@ ENTRY(_switch_to)
1924 2020
1925 /* Disable ints while we manipulate the stack pointer; spill regs. */ 2021 /* Disable ints while we manipulate the stack pointer; spill regs. */
1926 2022
1927 movi a5, PS_EXCM_MASK | LOCKLEVEL 2023 movi a5, (1 << PS_EXCM_BIT) | LOCKLEVEL
1928 xsr a5, PS 2024 xsr a5, PS
1929 rsr a3, EXCSAVE_1 2025 rsr a3, EXCSAVE_1
1930 rsync 2026 rsync
@@ -1964,33 +2060,9 @@ ENTRY(ret_from_fork)
1964 movi a4, schedule_tail 2060 movi a4, schedule_tail
1965 callx4 a4 2061 callx4 a4
1966 2062
1967 movi a4, do_syscall_trace 2063 movi a4, do_syscall_trace_leave
2064 mov a6, a1
1968 callx4 a4 2065 callx4 a4
1969 2066
1970 j common_exception_return 2067 j common_exception_return
1971 2068
1972
1973
1974/*
1975 * Table of syscalls
1976 */
1977
1978.data
1979.align 4
1980.global sys_call_table
1981sys_call_table:
1982
1983#define SYSCALL(call, narg) .word call
1984#include "syscalls.h"
1985
1986/*
1987 * Number of arguments of each syscall
1988 */
1989
1990.global sys_narg_table
1991sys_narg_table:
1992
1993#undef SYSCALL
1994#define SYSCALL(call, narg) .byte narg
1995#include "syscalls.h"
1996
diff --git a/arch/xtensa/kernel/head.S b/arch/xtensa/kernel/head.S
index c07cb2522993..ea89910efa44 100644
--- a/arch/xtensa/kernel/head.S
+++ b/arch/xtensa/kernel/head.S
@@ -15,9 +15,9 @@
15 * Kevin Chea 15 * Kevin Chea
16 */ 16 */
17 17
18#include <xtensa/cacheasm.h>
19#include <asm/processor.h> 18#include <asm/processor.h>
20#include <asm/page.h> 19#include <asm/page.h>
20#include <asm/cacheasm.h>
21 21
22/* 22/*
23 * This module contains the entry code for kernel images. It performs the 23 * This module contains the entry code for kernel images. It performs the
@@ -32,13 +32,6 @@
32 * 32 *
33 */ 33 */
34 34
35 .macro iterate from, to , cmd
36 .ifeq ((\to - \from) & ~0xfff)
37 \cmd \from
38 iterate "(\from+1)", \to, \cmd
39 .endif
40 .endm
41
42/* 35/*
43 * _start 36 * _start
44 * 37 *
@@ -64,7 +57,7 @@ _startup:
64 57
65 /* Disable interrupts and exceptions. */ 58 /* Disable interrupts and exceptions. */
66 59
67 movi a0, XCHAL_PS_EXCM_MASK 60 movi a0, LOCKLEVEL
68 wsr a0, PS 61 wsr a0, PS
69 62
70 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */ 63 /* Preserve the pointer to the boot parameter list in EXCSAVE_1 */
@@ -91,11 +84,11 @@ _startup:
91 movi a1, 15 84 movi a1, 15
92 wsr a0, ICOUNTLEVEL 85 wsr a0, ICOUNTLEVEL
93 86
94 .macro reset_dbreak num 87 .set _index, 0
95 wsr a0, DBREAKC + \num 88 .rept XCHAL_NUM_DBREAK - 1
96 .endm 89 wsr a0, DBREAKC + _index
97 90 .set _index, _index + 1
98 iterate 0, XCHAL_NUM_IBREAK-1, reset_dbreak 91 .endr
99#endif 92#endif
100 93
101 /* Clear CCOUNT (not really necessary, but nice) */ 94 /* Clear CCOUNT (not really necessary, but nice) */
@@ -110,10 +103,11 @@ _startup:
110 103
111 /* Disable all timers. */ 104 /* Disable all timers. */
112 105
113 .macro reset_timer num 106 .set _index, 0
114 wsr a0, CCOMPARE_0 + \num 107 .rept XCHAL_NUM_TIMERS - 1
115 .endm 108 wsr a0, CCOMPARE + _index
116 iterate 0, XCHAL_NUM_TIMERS-1, reset_timer 109 .set _index, _index + 1
110 .endr
117 111
118 /* Interrupt initialization. */ 112 /* Interrupt initialization. */
119 113
@@ -139,12 +133,21 @@ _startup:
139 rsync 133 rsync
140 134
141 /* Initialize the caches. 135 /* Initialize the caches.
142 * Does not include flushing writeback d-cache. 136 * a2, a3 are just working registers (clobbered).
143 * a6, a7 are just working registers (clobbered).
144 */ 137 */
145 138
146 icache_reset a2, a3 139#if XCHAL_DCACHE_LINE_LOCKABLE
147 dcache_reset a2, a3 140 ___unlock_dcache_all a2 a3
141#endif
142
143#if XCHAL_ICACHE_LINE_LOCKABLE
144 ___unlock_icache_all a2 a3
145#endif
146
147 ___invalidate_dcache_all a2 a3
148 ___invalidate_icache_all a2 a3
149
150 isync
148 151
149 /* Unpack data sections 152 /* Unpack data sections
150 * 153 *
@@ -181,9 +184,9 @@ _startup:
181 movi a2, _bss_start # start of BSS 184 movi a2, _bss_start # start of BSS
182 movi a3, _bss_end # end of BSS 185 movi a3, _bss_end # end of BSS
183 186
1841: addi a2, a2, 4 187 __loopt a2, a3, a4, 2
185 s32i a0, a2, 0 188 s32i a0, a2, 0
186 blt a2, a3, 1b 189 __endla a2, a4, 4
187 190
188#if XCHAL_DCACHE_IS_WRITEBACK 191#if XCHAL_DCACHE_IS_WRITEBACK
189 192
@@ -191,7 +194,7 @@ _startup:
191 * instructions/data are available. 194 * instructions/data are available.
192 */ 195 */
193 196
194 dcache_writeback_all a2, a3 197 ___flush_dcache_all a2 a3
195#endif 198#endif
196 199
197 /* Setup stack and enable window exceptions (keep irqs disabled) */ 200 /* Setup stack and enable window exceptions (keep irqs disabled) */
diff --git a/arch/xtensa/kernel/irq.c b/arch/xtensa/kernel/irq.c
index 1cf744ee0959..c9ea73b7031b 100644
--- a/arch/xtensa/kernel/irq.c
+++ b/arch/xtensa/kernel/irq.c
@@ -4,7 +4,7 @@
4 * Xtensa built-in interrupt controller and some generic functions copied 4 * Xtensa built-in interrupt controller and some generic functions copied
5 * from i386. 5 * from i386.
6 * 6 *
7 * Copyright (C) 2002 - 2005 Tensilica, Inc. 7 * Copyright (C) 2002 - 2006 Tensilica, Inc.
8 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar 8 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
9 * 9 *
10 * 10 *
@@ -22,11 +22,6 @@
22#include <asm/uaccess.h> 22#include <asm/uaccess.h>
23#include <asm/platform.h> 23#include <asm/platform.h>
24 24
25static void enable_xtensa_irq(unsigned int irq);
26static void disable_xtensa_irq(unsigned int irq);
27static void mask_and_ack_xtensa(unsigned int irq);
28static void end_xtensa_irq(unsigned int irq);
29
30static unsigned int cached_irq_mask; 25static unsigned int cached_irq_mask;
31 26
32atomic_t irq_err_count; 27atomic_t irq_err_count;
@@ -46,8 +41,16 @@ void ack_bad_irq(unsigned int irq)
46 * handlers). 41 * handlers).
47 */ 42 */
48 43
49unsigned int do_IRQ(int irq, struct pt_regs *regs) 44asmlinkage void do_IRQ(int irq, struct pt_regs *regs)
50{ 45{
46 struct pt_regs *old_regs = set_irq_regs(regs);
47 struct irq_desc *desc = irq_desc + irq;
48
49 if (irq >= NR_IRQS) {
50 printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
51 __FUNCTION__, irq);
52 }
53
51 irq_enter(); 54 irq_enter();
52 55
53#ifdef CONFIG_DEBUG_STACKOVERFLOW 56#ifdef CONFIG_DEBUG_STACKOVERFLOW
@@ -63,12 +66,10 @@ unsigned int do_IRQ(int irq, struct pt_regs *regs)
63 sp - sizeof(struct thread_info)); 66 sp - sizeof(struct thread_info));
64 } 67 }
65#endif 68#endif
66 69 desc->handle_irq(irq, desc);
67 __do_IRQ(irq, regs);
68 70
69 irq_exit(); 71 irq_exit();
70 72 set_irq_regs(old_regs);
71 return 1;
72} 73}
73 74
74/* 75/*
@@ -118,72 +119,68 @@ skip:
118 } 119 }
119 return 0; 120 return 0;
120} 121}
121/* shutdown is same as "disable" */
122#define shutdown_xtensa_irq disable_xtensa_irq
123 122
124static unsigned int startup_xtensa_irq(unsigned int irq) 123static void xtensa_irq_mask(unsigned int irq)
125{
126 enable_xtensa_irq(irq);
127 return 0; /* never anything pending */
128}
129
130static struct hw_interrupt_type xtensa_irq_type = {
131 "Xtensa-IRQ",
132 startup_xtensa_irq,
133 shutdown_xtensa_irq,
134 enable_xtensa_irq,
135 disable_xtensa_irq,
136 mask_and_ack_xtensa,
137 end_xtensa_irq
138};
139
140static inline void mask_irq(unsigned int irq)
141{ 124{
142 cached_irq_mask &= ~(1 << irq); 125 cached_irq_mask &= ~(1 << irq);
143 set_sr (cached_irq_mask, INTENABLE); 126 set_sr (cached_irq_mask, INTENABLE);
144} 127}
145 128
146static inline void unmask_irq(unsigned int irq) 129static void xtensa_irq_unmask(unsigned int irq)
147{ 130{
148 cached_irq_mask |= 1 << irq; 131 cached_irq_mask |= 1 << irq;
149 set_sr (cached_irq_mask, INTENABLE); 132 set_sr (cached_irq_mask, INTENABLE);
150} 133}
151 134
152static void disable_xtensa_irq(unsigned int irq) 135static void xtensa_irq_ack(unsigned int irq)
153{ 136{
154 unsigned long flags; 137 set_sr(1 << irq, INTCLEAR);
155 local_save_flags(flags);
156 mask_irq(irq);
157 local_irq_restore(flags);
158} 138}
159 139
160static void enable_xtensa_irq(unsigned int irq) 140static int xtensa_irq_retrigger(unsigned int irq)
161{ 141{
162 unsigned long flags; 142 set_sr (1 << irq, INTSET);
163 local_save_flags(flags); 143 return 1;
164 unmask_irq(irq);
165 local_irq_restore(flags);
166}
167
168static void mask_and_ack_xtensa(unsigned int irq)
169{
170 disable_xtensa_irq(irq);
171} 144}
172 145
173static void end_xtensa_irq(unsigned int irq)
174{
175 enable_xtensa_irq(irq);
176}
177 146
147static struct irq_chip xtensa_irq_chip = {
148 .name = "xtensa",
149 .mask = xtensa_irq_mask,
150 .unmask = xtensa_irq_unmask,
151 .ack = xtensa_irq_ack,
152 .retrigger = xtensa_irq_retrigger,
153};
178 154
179void __init init_IRQ(void) 155void __init init_IRQ(void)
180{ 156{
181 int i; 157 int index;
182 158
183 for (i=0; i < XTENSA_NR_IRQS; i++) 159 for (index = 0; index < XTENSA_NR_IRQS; index++) {
184 irq_desc[i].chip = &xtensa_irq_type; 160 int mask = 1 << index;
185 161
186 cached_irq_mask = 0; 162 if (mask & XCHAL_INTTYPE_MASK_SOFTWARE)
163 set_irq_chip_and_handler(index, &xtensa_irq_chip,
164 handle_simple_irq);
187 165
188 platform_init_irq(); 166 else if (mask & XCHAL_INTTYPE_MASK_EXTERN_EDGE)
167 set_irq_chip_and_handler(index, &xtensa_irq_chip,
168 handle_edge_irq);
169
170 else if (mask & XCHAL_INTTYPE_MASK_EXTERN_LEVEL)
171 set_irq_chip_and_handler(index, &xtensa_irq_chip,
172 handle_level_irq);
173
174 else if (mask & XCHAL_INTTYPE_MASK_TIMER)
175 set_irq_chip_and_handler(index, &xtensa_irq_chip,
176 handle_edge_irq);
177
178 else /* XCHAL_INTTYPE_MASK_WRITE_ERROR */
179 /* XCHAL_INTTYPE_MASK_NMI */
180
181 set_irq_chip_and_handler(index, &xtensa_irq_chip,
182 handle_level_irq);
183 }
184
185 cached_irq_mask = 0;
189} 186}
diff --git a/arch/xtensa/kernel/pci-dma.c b/arch/xtensa/kernel/pci-dma.c
index 6648fa9d9192..ca76f071666e 100644
--- a/arch/xtensa/kernel/pci-dma.c
+++ b/arch/xtensa/kernel/pci-dma.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * arch/xtensa/kernel/pci-dma.c 2 * arch/xtensa/pci-dma.c
3 * 3 *
4 * DMA coherent memory allocation. 4 * DMA coherent memory allocation.
5 * 5 *
@@ -29,28 +29,48 @@
29 */ 29 */
30 30
31void * 31void *
32dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *handle, gfp_t gfp) 32dma_alloc_coherent(struct device *dev,size_t size,dma_addr_t *handle,gfp_t flag)
33{ 33{
34 void *ret; 34 unsigned long ret;
35 unsigned long uncached = 0;
35 36
36 /* ignore region speicifiers */ 37 /* ignore region speicifiers */
37 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
38 38
39 if (dev == NULL || (*dev->dma_mask < 0xffffffff)) 39 flag &= ~(__GFP_DMA | __GFP_HIGHMEM);
40 gfp |= GFP_DMA;
41 ret = (void *)__get_free_pages(gfp, get_order(size));
42 40
43 if (ret != NULL) { 41 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
44 memset(ret, 0, size); 42 flag |= GFP_DMA;
45 *handle = virt_to_bus(ret); 43 ret = (unsigned long)__get_free_pages(flag, get_order(size));
44
45 if (ret == 0)
46 return NULL;
47
48 /* We currently don't support coherent memory outside KSEG */
49
50 if (ret < XCHAL_KSEG_CACHED_VADDR
51 || ret >= XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_SIZE)
52 BUG();
53
54
55 if (ret != 0) {
56 memset((void*) ret, 0, size);
57 uncached = ret+XCHAL_KSEG_BYPASS_VADDR-XCHAL_KSEG_CACHED_VADDR;
58 *handle = virt_to_bus((void*)ret);
59 __flush_invalidate_dcache_range(ret, size);
46 } 60 }
47 return (void*) BYPASS_ADDR((unsigned long)ret); 61
62 return (void*)uncached;
48} 63}
49 64
50void dma_free_coherent(struct device *hwdev, size_t size, 65void dma_free_coherent(struct device *hwdev, size_t size,
51 void *vaddr, dma_addr_t dma_handle) 66 void *vaddr, dma_addr_t dma_handle)
52{ 67{
53 free_pages(CACHED_ADDR((unsigned long)vaddr), get_order(size)); 68 long addr=(long)vaddr+XCHAL_KSEG_CACHED_VADDR-XCHAL_KSEG_BYPASS_VADDR;
69
70 if (addr < 0 || addr >= XCHAL_KSEG_SIZE)
71 BUG();
72
73 free_pages(addr, get_order(size));
54} 74}
55 75
56 76
diff --git a/arch/xtensa/kernel/process.c b/arch/xtensa/kernel/process.c
index a7c4178c2a8c..795bd5ac6f4c 100644
--- a/arch/xtensa/kernel/process.c
+++ b/arch/xtensa/kernel/process.c
@@ -1,4 +1,3 @@
1// TODO verify coprocessor handling
2/* 1/*
3 * arch/xtensa/kernel/process.c 2 * arch/xtensa/kernel/process.c
4 * 3 *
@@ -43,7 +42,7 @@
43#include <asm/irq.h> 42#include <asm/irq.h>
44#include <asm/atomic.h> 43#include <asm/atomic.h>
45#include <asm/asm-offsets.h> 44#include <asm/asm-offsets.h>
46#include <asm/coprocessor.h> 45#include <asm/regs.h>
47 46
48extern void ret_from_fork(void); 47extern void ret_from_fork(void);
49 48
@@ -67,25 +66,6 @@ void (*pm_power_off)(void) = NULL;
67EXPORT_SYMBOL(pm_power_off); 66EXPORT_SYMBOL(pm_power_off);
68 67
69 68
70#if XCHAL_CP_NUM > 0
71
72/*
73 * Coprocessor ownership.
74 */
75
76coprocessor_info_t coprocessor_info[] = {
77 { 0, XTENSA_CPE_CP0_OFFSET },
78 { 0, XTENSA_CPE_CP1_OFFSET },
79 { 0, XTENSA_CPE_CP2_OFFSET },
80 { 0, XTENSA_CPE_CP3_OFFSET },
81 { 0, XTENSA_CPE_CP4_OFFSET },
82 { 0, XTENSA_CPE_CP5_OFFSET },
83 { 0, XTENSA_CPE_CP6_OFFSET },
84 { 0, XTENSA_CPE_CP7_OFFSET },
85};
86
87#endif
88
89/* 69/*
90 * Powermanagement idle function, if any is provided by the platform. 70 * Powermanagement idle function, if any is provided by the platform.
91 */ 71 */
@@ -110,12 +90,10 @@ void cpu_idle(void)
110 90
111void exit_thread(void) 91void exit_thread(void)
112{ 92{
113 release_coprocessors(current); /* Empty macro if no CPs are defined */
114} 93}
115 94
116void flush_thread(void) 95void flush_thread(void)
117{ 96{
118 release_coprocessors(current); /* Empty macro if no CPs are defined */
119} 97}
120 98
121/* 99/*
@@ -183,36 +161,6 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
183 161
184 162
185/* 163/*
186 * Create a kernel thread
187 */
188
189int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
190{
191 long retval;
192 __asm__ __volatile__
193 ("mov a5, %4\n\t" /* preserve fn in a5 */
194 "mov a6, %3\n\t" /* preserve and setup arg in a6 */
195 "movi a2, %1\n\t" /* load __NR_clone for syscall*/
196 "mov a3, sp\n\t" /* sp check and sys_clone */
197 "mov a4, %5\n\t" /* load flags for syscall */
198 "syscall\n\t"
199 "beq a3, sp, 1f\n\t" /* branch if parent */
200 "callx4 a5\n\t" /* call fn */
201 "movi a2, %2\n\t" /* load __NR_exit for syscall */
202 "mov a3, a6\n\t" /* load fn return value */
203 "syscall\n"
204 "1:\n\t"
205 "mov %0, a2\n\t" /* parent returns zero */
206 :"=r" (retval)
207 :"i" (__NR_clone), "i" (__NR_exit),
208 "r" (arg), "r" (fn),
209 "r" (flags | CLONE_VM)
210 : "a2", "a3", "a4", "a5", "a6" );
211 return retval;
212}
213
214
215/*
216 * These bracket the sleeping functions.. 164 * These bracket the sleeping functions..
217 */ 165 */
218 166
@@ -275,7 +223,7 @@ void do_copy_regs (xtensa_gregset_t *elfregs, struct pt_regs *regs,
275 */ 223 */
276 224
277 elfregs->pc = regs->pc; 225 elfregs->pc = regs->pc;
278 elfregs->ps = (regs->ps & ~XCHAL_PS_EXCM_MASK); 226 elfregs->ps = (regs->ps & ~(1 << PS_EXCM_BIT));
279 elfregs->exccause = regs->exccause; 227 elfregs->exccause = regs->exccause;
280 elfregs->excvaddr = regs->excvaddr; 228 elfregs->excvaddr = regs->excvaddr;
281 elfregs->windowbase = regs->windowbase; 229 elfregs->windowbase = regs->windowbase;
@@ -325,7 +273,7 @@ void do_restore_regs (xtensa_gregset_t *elfregs, struct pt_regs *regs,
325 */ 273 */
326 274
327 regs->pc = elfregs->pc; 275 regs->pc = elfregs->pc;
328 regs->ps = (elfregs->ps | XCHAL_PS_EXCM_MASK); 276 regs->ps = (elfregs->ps | (1 << PS_EXCM_BIT));
329 regs->exccause = elfregs->exccause; 277 regs->exccause = elfregs->exccause;
330 regs->excvaddr = elfregs->excvaddr; 278 regs->excvaddr = elfregs->excvaddr;
331 regs->windowbase = elfregs->windowbase; 279 regs->windowbase = elfregs->windowbase;
@@ -459,16 +407,7 @@ int do_restore_fpregs (elf_fpregset_t *fpregs, struct pt_regs *regs,
459int 407int
460dump_task_fpu(struct pt_regs *regs, struct task_struct *task, elf_fpregset_t *r) 408dump_task_fpu(struct pt_regs *regs, struct task_struct *task, elf_fpregset_t *r)
461{ 409{
462/* see asm/coprocessor.h for this magic number 16 */
463#if XTENSA_CP_EXTRA_SIZE > 16
464 do_save_fpregs (r, regs, task);
465
466 /* For now, bit 16 means some extra state may be present: */
467// FIXME!! need to track to return more accurate mask
468 return 0x10000 | XCHAL_CP_MASK;
469#else
470 return 0; /* no coprocessors active on this processor */ 410 return 0; /* no coprocessors active on this processor */
471#endif
472} 411}
473 412
474/* 413/*
@@ -483,3 +422,44 @@ int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
483{ 422{
484 return dump_task_fpu(regs, current, r); 423 return dump_task_fpu(regs, current, r);
485} 424}
425
426asmlinkage
427long xtensa_clone(unsigned long clone_flags, unsigned long newsp,
428 void __user *parent_tid, void *child_tls,
429 void __user *child_tid, long a5,
430 struct pt_regs *regs)
431{
432 if (!newsp)
433 newsp = regs->areg[1];
434 return do_fork(clone_flags, newsp, regs, 0, parent_tid, child_tid);
435}
436
437/*
438 * * xtensa_execve() executes a new program.
439 * */
440
441asmlinkage
442long xtensa_execve(char __user *name, char __user * __user *argv,
443 char __user * __user *envp,
444 long a3, long a4, long a5,
445 struct pt_regs *regs)
446{
447 long error;
448 char * filename;
449
450 filename = getname(name);
451 error = PTR_ERR(filename);
452 if (IS_ERR(filename))
453 goto out;
454 // FIXME: release coprocessor??
455 error = do_execve(filename, argv, envp, regs);
456 if (error == 0) {
457 task_lock(current);
458 current->ptrace &= ~PT_DTRACE;
459 task_unlock(current);
460 }
461 putname(filename);
462out:
463 return error;
464}
465
diff --git a/arch/xtensa/kernel/ptrace.c b/arch/xtensa/kernel/ptrace.c
index 9aea23cc0dc5..8b6d3d0623b6 100644
--- a/arch/xtensa/kernel/ptrace.c
+++ b/arch/xtensa/kernel/ptrace.c
@@ -96,7 +96,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
96 /* Note: PS.EXCM is not set while user task is running; 96 /* Note: PS.EXCM is not set while user task is running;
97 * its being set in regs is for exception handling 97 * its being set in regs is for exception handling
98 * convenience. */ 98 * convenience. */
99 tmp = (regs->ps & ~XCHAL_PS_EXCM_MASK); 99 tmp = (regs->ps & ~(1 << PS_EXCM_BIT));
100 break; 100 break;
101 case REG_WB: 101 case REG_WB:
102 tmp = regs->windowbase; 102 tmp = regs->windowbase;
@@ -332,12 +332,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
332 332
333void do_syscall_trace(void) 333void do_syscall_trace(void)
334{ 334{
335 if (!test_thread_flag(TIF_SYSCALL_TRACE))
336 return;
337
338 if (!(current->ptrace & PT_PTRACED))
339 return;
340
341 /* 335 /*
342 * The 0x80 provides a way for the tracing parent to distinguish 336 * The 0x80 provides a way for the tracing parent to distinguish
343 * between a syscall stop and SIGTRAP delivery 337 * between a syscall stop and SIGTRAP delivery
@@ -354,3 +348,23 @@ void do_syscall_trace(void)
354 current->exit_code = 0; 348 current->exit_code = 0;
355 } 349 }
356} 350}
351
352void do_syscall_trace_enter(struct pt_regs *regs)
353{
354 if (test_thread_flag(TIF_SYSCALL_TRACE)
355 && (current->ptrace & PT_PTRACED))
356 do_syscall_trace();
357
358#if 0
359 if (unlikely(current->audit_context))
360 audit_syscall_entry(current, AUDIT_ARCH_XTENSA..);
361#endif
362}
363
364void do_syscall_trace_leave(struct pt_regs *regs)
365{
366 if ((test_thread_flag(TIF_SYSCALL_TRACE))
367 && (current->ptrace & PT_PTRACED))
368 do_syscall_trace();
369}
370
diff --git a/arch/xtensa/kernel/setup.c b/arch/xtensa/kernel/setup.c
index c99ab72b41b6..b6374c09de20 100644
--- a/arch/xtensa/kernel/setup.c
+++ b/arch/xtensa/kernel/setup.c
@@ -42,8 +42,6 @@
42#include <asm/page.h> 42#include <asm/page.h>
43#include <asm/setup.h> 43#include <asm/setup.h>
44 44
45#include <xtensa/config/system.h>
46
47#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE) 45#if defined(CONFIG_VGA_CONSOLE) || defined(CONFIG_DUMMY_CONSOLE)
48struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16}; 46struct screen_info screen_info = { 0, 24, 0, 0, 0, 80, 0, 0, 0, 24, 1, 16};
49#endif 47#endif
@@ -336,7 +334,7 @@ c_show(struct seq_file *f, void *slot)
336 /* high-level stuff */ 334 /* high-level stuff */
337 seq_printf(f,"processor\t: 0\n" 335 seq_printf(f,"processor\t: 0\n"
338 "vendor_id\t: Tensilica\n" 336 "vendor_id\t: Tensilica\n"
339 "model\t\t: Xtensa " XCHAL_HW_RELEASE_NAME "\n" 337 "model\t\t: Xtensa " XCHAL_HW_VERSION_NAME "\n"
340 "core ID\t\t: " XCHAL_CORE_ID "\n" 338 "core ID\t\t: " XCHAL_CORE_ID "\n"
341 "build ID\t: 0x%x\n" 339 "build ID\t: 0x%x\n"
342 "byte order\t: %s\n" 340 "byte order\t: %s\n"
@@ -420,25 +418,6 @@ c_show(struct seq_file *f, void *slot)
420 XCHAL_NUM_TIMERS, 418 XCHAL_NUM_TIMERS,
421 XCHAL_DEBUGLEVEL); 419 XCHAL_DEBUGLEVEL);
422 420
423 /* Coprocessors */
424#if XCHAL_HAVE_CP
425 seq_printf(f, "coprocessors\t: %d\n", XCHAL_CP_NUM);
426#else
427 seq_printf(f, "coprocessors\t: none\n");
428#endif
429
430 /* {I,D}{RAM,ROM} and XLMI */
431 seq_printf(f,"inst ROMs\t: %d\n"
432 "inst RAMs\t: %d\n"
433 "data ROMs\t: %d\n"
434 "data RAMs\t: %d\n"
435 "XLMI ports\t: %d\n",
436 XCHAL_NUM_IROM,
437 XCHAL_NUM_IRAM,
438 XCHAL_NUM_DROM,
439 XCHAL_NUM_DRAM,
440 XCHAL_NUM_XLMI);
441
442 /* Cache */ 421 /* Cache */
443 seq_printf(f,"icache line size: %d\n" 422 seq_printf(f,"icache line size: %d\n"
444 "icache ways\t: %d\n" 423 "icache ways\t: %d\n"
@@ -466,24 +445,6 @@ c_show(struct seq_file *f, void *slot)
466 XCHAL_DCACHE_WAYS, 445 XCHAL_DCACHE_WAYS,
467 XCHAL_DCACHE_SIZE); 446 XCHAL_DCACHE_SIZE);
468 447
469 /* MMU */
470 seq_printf(f,"ASID bits\t: %d\n"
471 "ASID invalid\t: %d\n"
472 "ASID kernel\t: %d\n"
473 "rings\t\t: %d\n"
474 "itlb ways\t: %d\n"
475 "itlb AR ways\t: %d\n"
476 "dtlb ways\t: %d\n"
477 "dtlb AR ways\t: %d\n",
478 XCHAL_MMU_ASID_BITS,
479 XCHAL_MMU_ASID_INVALID,
480 XCHAL_MMU_ASID_KERNEL,
481 XCHAL_MMU_RINGS,
482 XCHAL_ITLB_WAYS,
483 XCHAL_ITLB_ARF_WAYS,
484 XCHAL_DTLB_WAYS,
485 XCHAL_DTLB_ARF_WAYS);
486
487 return 0; 448 return 0;
488} 449}
489 450
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index c494f0826fc5..c6d9880a4cdb 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -12,8 +12,8 @@
12 * 12 *
13 */ 13 */
14 14
15#include <xtensa/config/core.h> 15#include <asm/variant/core.h>
16#include <xtensa/hal.h> 16#include <asm/coprocessor.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/mm.h> 18#include <linux/mm.h>
19#include <linux/smp.h> 19#include <linux/smp.h>
@@ -46,7 +46,7 @@ extern struct task_struct *coproc_owners[];
46 * Atomically swap in the new signal mask, and wait for a signal. 46 * Atomically swap in the new signal mask, and wait for a signal.
47 */ 47 */
48 48
49int sys_sigsuspend(struct pt_regs *regs) 49int xtensa_sigsuspend(struct pt_regs *regs)
50{ 50{
51 old_sigset_t mask = (old_sigset_t) regs->areg[3]; 51 old_sigset_t mask = (old_sigset_t) regs->areg[3];
52 sigset_t saveset; 52 sigset_t saveset;
@@ -68,7 +68,7 @@ int sys_sigsuspend(struct pt_regs *regs)
68} 68}
69 69
70asmlinkage int 70asmlinkage int
71sys_rt_sigsuspend(struct pt_regs *regs) 71xtensa_rt_sigsuspend(struct pt_regs *regs)
72{ 72{
73 sigset_t *unewset = (sigset_t *) regs->areg[4]; 73 sigset_t *unewset = (sigset_t *) regs->areg[4];
74 size_t sigsetsize = (size_t) regs->areg[3]; 74 size_t sigsetsize = (size_t) regs->areg[3];
@@ -96,7 +96,7 @@ sys_rt_sigsuspend(struct pt_regs *regs)
96} 96}
97 97
98asmlinkage int 98asmlinkage int
99sys_sigaction(int sig, const struct old_sigaction *act, 99xtensa_sigaction(int sig, const struct old_sigaction *act,
100 struct old_sigaction *oact) 100 struct old_sigaction *oact)
101{ 101{
102 struct k_sigaction new_ka, old_ka; 102 struct k_sigaction new_ka, old_ka;
@@ -128,7 +128,7 @@ sys_sigaction(int sig, const struct old_sigaction *act,
128} 128}
129 129
130asmlinkage int 130asmlinkage int
131sys_sigaltstack(struct pt_regs *regs) 131xtensa_sigaltstack(struct pt_regs *regs)
132{ 132{
133 const stack_t *uss = (stack_t *) regs->areg[4]; 133 const stack_t *uss = (stack_t *) regs->areg[4];
134 stack_t *uoss = (stack_t *) regs->areg[3]; 134 stack_t *uoss = (stack_t *) regs->areg[3];
@@ -216,8 +216,8 @@ restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc)
216 * handler, or the user mode value doesn't matter (e.g. PS.OWB). 216 * handler, or the user mode value doesn't matter (e.g. PS.OWB).
217 */ 217 */
218 err |= __get_user(ps, &sc->sc_ps); 218 err |= __get_user(ps, &sc->sc_ps);
219 regs->ps = (regs->ps & ~XCHAL_PS_CALLINC_MASK) 219 regs->ps = (regs->ps & ~PS_CALLINC_MASK)
220 | (ps & XCHAL_PS_CALLINC_MASK); 220 | (ps & PS_CALLINC_MASK);
221 221
222 /* Additional corruption checks */ 222 /* Additional corruption checks */
223 223
@@ -280,7 +280,7 @@ flush_my_cpstate(struct task_struct *tsk)
280static int 280static int
281save_cpextra (struct _cpstate *buf) 281save_cpextra (struct _cpstate *buf)
282{ 282{
283#if (XCHAL_EXTRA_SA_SIZE == 0) && (XCHAL_CP_NUM == 0) 283#if XCHAL_CP_NUM == 0
284 return 0; 284 return 0;
285#else 285#else
286 286
@@ -350,7 +350,7 @@ setup_sigcontext(struct sigcontext *sc, struct _cpstate *cpstate,
350 return err; 350 return err;
351} 351}
352 352
353asmlinkage int sys_sigreturn(struct pt_regs *regs) 353asmlinkage int xtensa_sigreturn(struct pt_regs *regs)
354{ 354{
355 struct sigframe *frame = (struct sigframe *)regs->areg[1]; 355 struct sigframe *frame = (struct sigframe *)regs->areg[1];
356 sigset_t set; 356 sigset_t set;
@@ -382,7 +382,7 @@ badframe:
382 return 0; 382 return 0;
383} 383}
384 384
385asmlinkage int sys_rt_sigreturn(struct pt_regs *regs) 385asmlinkage int xtensa_rt_sigreturn(struct pt_regs *regs)
386{ 386{
387 struct rt_sigframe *frame = (struct rt_sigframe *)regs->areg[1]; 387 struct rt_sigframe *frame = (struct rt_sigframe *)regs->areg[1];
388 sigset_t set; 388 sigset_t set;
@@ -497,8 +497,10 @@ gen_return_code(unsigned char *codemem, unsigned int use_rt_sigreturn)
497 497
498 /* Flush generated code out of the data cache */ 498 /* Flush generated code out of the data cache */
499 499
500 if (err == 0) 500 if (err == 0) {
501 __flush_invalidate_cache_range((unsigned long)codemem, 6UL); 501 __invalidate_icache_range((unsigned long)codemem, 6UL);
502 __flush_invalidate_dcache_range((unsigned long)codemem, 6UL);
503 }
502 504
503 return err; 505 return err;
504} 506}
diff --git a/arch/xtensa/kernel/syscall.c b/arch/xtensa/kernel/syscall.c
new file mode 100644
index 000000000000..418268f49766
--- /dev/null
+++ b/arch/xtensa/kernel/syscall.c
@@ -0,0 +1,95 @@
1/*
2 * arch/xtensa/kernel/syscall.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Copyright (C) 2000 Silicon Graphics, Inc.
10 * Copyright (C) 1995 - 2000 by Ralf Baechle
11 *
12 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
13 * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14 * Chris Zankel <chris@zankel.net>
15 * Kevin Chea
16 *
17 */
18#include <asm/uaccess.h>
19#include <asm/syscalls.h>
20#include <asm/unistd.h>
21#include <linux/linkage.h>
22#include <linux/stringify.h>
23#include <linux/errno.h>
24#include <linux/syscalls.h>
25#include <linux/file.h>
26#include <linux/fs.h>
27#include <linux/mman.h>
28#include <linux/shm.h>
29
30typedef void (*syscall_t)(void);
31
32syscall_t sys_call_table[__NR_syscall_count] /* FIXME __cacheline_aligned */= {
33 [0 ... __NR_syscall_count - 1] = (syscall_t)&sys_ni_syscall,
34
35#undef __SYSCALL
36#define __SYSCALL(nr,symbol,nargs) [ nr ] = (syscall_t)symbol,
37#undef _XTENSA_UNISTD_H
38#undef __KERNEL_SYSCALLS__
39#include <asm/unistd.h>
40};
41
42/*
43 * xtensa_pipe() is the normal C calling standard for creating a pipe. It's not
44 * the way unix traditional does this, though.
45 */
46
47asmlinkage long xtensa_pipe(int __user *userfds)
48{
49 int fd[2];
50 int error;
51
52 error = do_pipe(fd);
53 if (!error) {
54 if (copy_to_user(userfds, fd, 2 * sizeof(int)))
55 error = -EFAULT;
56 }
57 return error;
58}
59
60
61asmlinkage long xtensa_mmap2(unsigned long addr, unsigned long len,
62 unsigned long prot, unsigned long flags,
63 unsigned long fd, unsigned long pgoff)
64{
65 int error = -EBADF;
66 struct file * file = NULL;
67
68 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
69 if (!(flags & MAP_ANONYMOUS)) {
70 file = fget(fd);
71 if (!file)
72 goto out;
73 }
74
75 down_write(&current->mm->mmap_sem);
76 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
77 up_write(&current->mm->mmap_sem);
78
79 if (file)
80 fput(file);
81out:
82 return error;
83}
84
85asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
86{
87 unsigned long ret;
88 long err;
89
90 err = do_shmat(shmid, shmaddr, shmflg, &ret);
91 if (err)
92 return err;
93 return (long)ret;
94}
95
diff --git a/arch/xtensa/kernel/syscalls.c b/arch/xtensa/kernel/syscalls.c
deleted file mode 100644
index f49cb239e603..000000000000
--- a/arch/xtensa/kernel/syscalls.c
+++ /dev/null
@@ -1,288 +0,0 @@
1/*
2 * arch/xtensa/kernel/syscalls.c
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 * Copyright (C) 2000 Silicon Graphics, Inc.
10 * Copyright (C) 1995 - 2000 by Ralf Baechle
11 *
12 * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
13 * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14 * Chris Zankel <chris@zankel.net>
15 * Kevin Chea
16 *
17 */
18
19#define DEBUG 0
20
21#include <linux/linkage.h>
22#include <linux/mm.h>
23#include <linux/smp.h>
24#include <linux/smp_lock.h>
25#include <linux/mman.h>
26#include <linux/sched.h>
27#include <linux/file.h>
28#include <linux/slab.h>
29#include <linux/utsname.h>
30#include <linux/unistd.h>
31#include <linux/stringify.h>
32#include <linux/syscalls.h>
33#include <linux/sem.h>
34#include <linux/msg.h>
35#include <linux/shm.h>
36#include <linux/errno.h>
37#include <asm/ptrace.h>
38#include <asm/signal.h>
39#include <asm/uaccess.h>
40#include <asm/hardirq.h>
41#include <asm/mman.h>
42#include <asm/shmparam.h>
43#include <asm/page.h>
44
45extern void do_syscall_trace(void);
46typedef int (*syscall_t)(void *a0,...);
47extern syscall_t sys_call_table[];
48extern unsigned char sys_narg_table[];
49
50/*
51 * sys_pipe() is the normal C calling standard for creating a pipe. It's not
52 * the way unix traditional does this, though.
53 */
54
55int sys_pipe(int __user *userfds)
56{
57 int fd[2];
58 int error;
59
60 error = do_pipe(fd);
61 if (!error) {
62 if (copy_to_user(userfds, fd, 2 * sizeof(int)))
63 error = -EFAULT;
64 }
65 return error;
66}
67
68/*
69 * Common code for old and new mmaps.
70 */
71long sys_mmap(unsigned long addr, unsigned long len, unsigned long prot,
72 unsigned long flags, unsigned long fd, unsigned long pgoff)
73{
74 int error = -EBADF;
75 struct file * file = NULL;
76
77 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
78 if (!(flags & MAP_ANONYMOUS)) {
79 file = fget(fd);
80 if (!file)
81 goto out;
82 }
83
84 down_write(&current->mm->mmap_sem);
85 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
86 up_write(&current->mm->mmap_sem);
87
88 if (file)
89 fput(file);
90out:
91 return error;
92}
93
94int sys_clone(struct pt_regs *regs)
95{
96 unsigned long clone_flags;
97 unsigned long newsp;
98 int __user *parent_tidptr, *child_tidptr;
99 clone_flags = regs->areg[4];
100 newsp = regs->areg[3];
101 parent_tidptr = (int __user *)regs->areg[5];
102 child_tidptr = (int __user *)regs->areg[6];
103 if (!newsp)
104 newsp = regs->areg[1];
105 return do_fork(clone_flags,newsp,regs,0,parent_tidptr,child_tidptr);
106}
107
108/*
109 * sys_execve() executes a new program.
110 */
111
112int sys_execve(struct pt_regs *regs)
113{
114 int error;
115 char * filename;
116
117 filename = getname((char *) (long)regs->areg[5]);
118 error = PTR_ERR(filename);
119 if (IS_ERR(filename))
120 goto out;
121 error = do_execve(filename, (char **) (long)regs->areg[3],
122 (char **) (long)regs->areg[4], regs);
123 putname(filename);
124
125out:
126 return error;
127}
128
129int sys_uname(struct old_utsname * name)
130{
131 if (name && !copy_to_user(name, utsname(), sizeof (*name)))
132 return 0;
133 return -EFAULT;
134}
135
136/*
137 * Build the string table for the builtin "poor man's strace".
138 */
139
140#if DEBUG
141#define SYSCALL(fun, narg) #fun,
142static char *sfnames[] = {
143#include "syscalls.h"
144};
145#undef SYS
146#endif
147
148void system_call (struct pt_regs *regs)
149{
150 syscall_t syscall;
151 unsigned long parm0, parm1, parm2, parm3, parm4, parm5;
152 int nargs, res;
153 unsigned int syscallnr;
154 int ps;
155
156#if DEBUG
157 int i;
158 unsigned long parms[6];
159 char *sysname;
160#endif
161
162 regs->syscall = regs->areg[2];
163
164 do_syscall_trace();
165
166 /* Have to load after syscall_trace because strace
167 * sometimes changes regs->syscall.
168 */
169 syscallnr = regs->syscall;
170
171 parm0 = parm1 = parm2 = parm3 = parm4 = parm5 = 0;
172
173 /* Restore interrupt level to syscall invoker's.
174 * If this were in assembly, we wouldn't disable
175 * interrupts in the first place:
176 */
177 local_save_flags (ps);
178 local_irq_restore((ps & ~XCHAL_PS_INTLEVEL_MASK) |
179 (regs->ps & XCHAL_PS_INTLEVEL_MASK) );
180
181 if (syscallnr > __NR_Linux_syscalls) {
182 regs->areg[2] = -ENOSYS;
183 return;
184 }
185
186 syscall = sys_call_table[syscallnr];
187 nargs = sys_narg_table[syscallnr];
188
189 if (syscall == NULL) {
190 regs->areg[2] = -ENOSYS;
191 return;
192 }
193
194 /* There shouldn't be more than six arguments in the table! */
195
196 if (nargs > 6)
197 panic("Internal error - too many syscall arguments (%d)!\n",
198 nargs);
199
200 /* Linux takes system-call arguments in registers. The ABI
201 * and Xtensa software conventions require the system-call
202 * number in a2. If an argument exists in a2, we move it to
203 * the next available register. Note that for improved
204 * efficiency, we do NOT shift all parameters down one
205 * register to maintain the original order.
206 *
207 * At best case (zero arguments), we just write the syscall
208 * number to a2. At worst case (1 to 6 arguments), we move
209 * the argument in a2 to the next available register, then
210 * write the syscall number to a2.
211 *
212 * For clarity, the following truth table enumerates all
213 * possibilities.
214 *
215 * arguments syscall number arg0, arg1, arg2, arg3, arg4, arg5
216 * --------- -------------- ----------------------------------
217 * 0 a2
218 * 1 a2 a3
219 * 2 a2 a4, a3
220 * 3 a2 a5, a3, a4
221 * 4 a2 a6, a3, a4, a5
222 * 5 a2 a7, a3, a4, a5, a6
223 * 6 a2 a8, a3, a4, a5, a6, a7
224 */
225 if (nargs) {
226 parm0 = regs->areg[nargs+2];
227 parm1 = regs->areg[3];
228 parm2 = regs->areg[4];
229 parm3 = regs->areg[5];
230 parm4 = regs->areg[6];
231 parm5 = regs->areg[7];
232 } else /* nargs == 0 */
233 parm0 = (unsigned long) regs;
234
235#if DEBUG
236 parms[0] = parm0;
237 parms[1] = parm1;
238 parms[2] = parm2;
239 parms[3] = parm3;
240 parms[4] = parm4;
241 parms[5] = parm5;
242
243 sysname = sfnames[syscallnr];
244 if (strncmp(sysname, "sys_", 4) == 0)
245 sysname = sysname + 4;
246
247 printk("\017SYSCALL:I:%x:%d:%s %s(", regs->pc, current->pid,
248 current->comm, sysname);
249 for (i = 0; i < nargs; i++)
250 printk((i>0) ? ", %#lx" : "%#lx", parms[i]);
251 printk(")\n");
252#endif
253
254 res = syscall((void *)parm0, parm1, parm2, parm3, parm4, parm5);
255
256#if DEBUG
257 printk("\017SYSCALL:O:%d:%s %s(",current->pid, current->comm, sysname);
258 for (i = 0; i < nargs; i++)
259 printk((i>0) ? ", %#lx" : "%#lx", parms[i]);
260 if (res < 4096)
261 printk(") = %d\n", res);
262 else
263 printk(") = %#x\n", res);
264#endif /* DEBUG */
265
266 regs->areg[2] = res;
267 do_syscall_trace();
268}
269
270/*
271 * Do a system call from kernel instead of calling sys_execve so we
272 * end up with proper pt_regs.
273 */
274int kernel_execve(const char *filename, char *const argv[], char *const envp[])
275{
276 long __res;
277 asm volatile (
278 " mov a5, %2 \n"
279 " mov a4, %4 \n"
280 " mov a3, %3 \n"
281 " movi a2, %1 \n"
282 " syscall \n"
283 " mov %0, a2 \n"
284 : "=a" (__res)
285 : "i" (__NR_execve), "a" (filename), "a" (argv), "a" (envp)
286 : "a2", "a3", "a4", "a5");
287 return __res;
288}
diff --git a/arch/xtensa/kernel/syscalls.h b/arch/xtensa/kernel/syscalls.h
deleted file mode 100644
index 216c10a31501..000000000000
--- a/arch/xtensa/kernel/syscalls.h
+++ /dev/null
@@ -1,247 +0,0 @@
1/*
2 * arch/xtensa/kernel/syscalls.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle
9 * Copyright (C) 2001 - 2005 Tensilica Inc.
10 *
11 * Changes by Joe Taylor <joe@tensilica.com>
12 */
13
14/*
15 * This file is being included twice - once to build a list of all
16 * syscalls and once to build a table of how many arguments each syscall
17 * accepts. Syscalls that receive a pointer to the saved registers are
18 * marked as having zero arguments.
19 *
20 * The binary compatibility calls are in a separate list.
21 *
22 * Entry '0' used to be system_call. It's removed to disable indirect
23 * system calls for now so user tasks can't recurse. See mips'
24 * sys_syscall for a comparable example.
25 */
26
27SYSCALL(0, 0) /* 00 */
28SYSCALL(sys_exit, 1)
29SYSCALL(sys_ni_syscall, 0)
30SYSCALL(sys_read, 3)
31SYSCALL(sys_write, 3)
32SYSCALL(sys_open, 3) /* 05 */
33SYSCALL(sys_close, 1)
34SYSCALL(sys_ni_syscall, 3)
35SYSCALL(sys_creat, 2)
36SYSCALL(sys_link, 2)
37SYSCALL(sys_unlink, 1) /* 10 */
38SYSCALL(sys_execve, 0)
39SYSCALL(sys_chdir, 1)
40SYSCALL(sys_ni_syscall, 1)
41SYSCALL(sys_mknod, 3)
42SYSCALL(sys_chmod, 2) /* 15 */
43SYSCALL(sys_lchown, 3)
44SYSCALL(sys_ni_syscall, 0)
45SYSCALL(sys_newstat, 2)
46SYSCALL(sys_lseek, 3)
47SYSCALL(sys_getpid, 0) /* 20 */
48SYSCALL(sys_mount, 5)
49SYSCALL(sys_ni_syscall, 1)
50SYSCALL(sys_setuid, 1)
51SYSCALL(sys_getuid, 0)
52SYSCALL(sys_ni_syscall, 1) /* 25 */
53SYSCALL(sys_ptrace, 4)
54SYSCALL(sys_ni_syscall, 1)
55SYSCALL(sys_newfstat, 2)
56SYSCALL(sys_ni_syscall, 0)
57SYSCALL(sys_utime, 2) /* 30 */
58SYSCALL(sys_ni_syscall, 0)
59SYSCALL(sys_ni_syscall, 0)
60SYSCALL(sys_access, 2)
61SYSCALL(sys_ni_syscall, 1)
62SYSCALL(sys_ni_syscall, 0) /* 35 */
63SYSCALL(sys_sync, 0)
64SYSCALL(sys_kill, 2)
65SYSCALL(sys_rename, 2)
66SYSCALL(sys_mkdir, 2)
67SYSCALL(sys_rmdir, 1) /* 40 */
68SYSCALL(sys_dup, 1)
69SYSCALL(sys_pipe, 1)
70SYSCALL(sys_times, 1)
71SYSCALL(sys_ni_syscall, 0)
72SYSCALL(sys_brk, 1) /* 45 */
73SYSCALL(sys_setgid, 1)
74SYSCALL(sys_getgid, 0)
75SYSCALL(sys_ni_syscall, 0)
76SYSCALL(sys_geteuid, 0)
77SYSCALL(sys_getegid, 0) /* 50 */
78SYSCALL(sys_acct, 1)
79SYSCALL(sys_umount, 2)
80SYSCALL(sys_ni_syscall, 0)
81SYSCALL(sys_ioctl, 3)
82SYSCALL(sys_fcntl, 3) /* 55 */
83SYSCALL(sys_ni_syscall, 2)
84SYSCALL(sys_setpgid, 2)
85SYSCALL(sys_ni_syscall, 0)
86SYSCALL(sys_ni_syscall, 0)
87SYSCALL(sys_umask, 1) /* 60 */
88SYSCALL(sys_chroot, 1)
89SYSCALL(sys_ustat, 2)
90SYSCALL(sys_dup2, 2)
91SYSCALL(sys_getppid, 0)
92SYSCALL(sys_ni_syscall, 0) /* 65 */
93SYSCALL(sys_setsid, 0)
94SYSCALL(sys_sigaction, 3)
95SYSCALL(sys_ni_syscall, 0)
96SYSCALL(sys_ni_syscall, 1)
97SYSCALL(sys_setreuid, 2) /* 70 */
98SYSCALL(sys_setregid, 2)
99SYSCALL(sys_sigsuspend, 0)
100SYSCALL(sys_ni_syscall, 1)
101SYSCALL(sys_sethostname, 2)
102SYSCALL(sys_setrlimit, 2) /* 75 */
103SYSCALL(sys_getrlimit, 2)
104SYSCALL(sys_getrusage, 2)
105SYSCALL(sys_gettimeofday, 2)
106SYSCALL(sys_settimeofday, 2)
107SYSCALL(sys_getgroups, 2) /* 80 */
108SYSCALL(sys_setgroups, 2)
109SYSCALL(sys_ni_syscall, 0)
110SYSCALL(sys_symlink, 2)
111SYSCALL(sys_newlstat, 2)
112SYSCALL(sys_readlink, 3) /* 85 */
113SYSCALL(sys_uselib, 1)
114SYSCALL(sys_swapon, 2)
115SYSCALL(sys_reboot, 3)
116SYSCALL(sys_ni_syscall, 3)
117SYSCALL(sys_ni_syscall, 6) /* 90 */
118SYSCALL(sys_munmap, 2)
119SYSCALL(sys_truncate, 2)
120SYSCALL(sys_ftruncate, 2)
121SYSCALL(sys_fchmod, 2)
122SYSCALL(sys_fchown, 3) /* 95 */
123SYSCALL(sys_getpriority, 2)
124SYSCALL(sys_setpriority, 3)
125SYSCALL(sys_ni_syscall, 0)
126SYSCALL(sys_statfs, 2)
127SYSCALL(sys_fstatfs, 2) /* 100 */
128SYSCALL(sys_ni_syscall, 3)
129SYSCALL(sys_ni_syscall, 2)
130SYSCALL(sys_syslog, 3)
131SYSCALL(sys_setitimer, 3)
132SYSCALL(sys_getitimer, 2) /* 105 */
133SYSCALL(sys_newstat, 2)
134SYSCALL(sys_newlstat, 2)
135SYSCALL(sys_newfstat, 2)
136SYSCALL(sys_uname, 1)
137SYSCALL(sys_ni_syscall, 0) /* 110 */
138SYSCALL(sys_vhangup, 0)
139SYSCALL(sys_ni_syscall, 0)
140SYSCALL(sys_ni_syscall, 0)
141SYSCALL(sys_wait4, 4)
142SYSCALL(sys_swapoff, 1) /* 115 */
143SYSCALL(sys_sysinfo, 1)
144SYSCALL(sys_ni_syscall, 0)
145SYSCALL(sys_fsync, 1)
146SYSCALL(sys_sigreturn, 0)
147SYSCALL(sys_clone, 0) /* 120 */
148SYSCALL(sys_setdomainname, 2)
149SYSCALL(sys_newuname, 1)
150SYSCALL(sys_ni_syscall, 0)
151SYSCALL(sys_adjtimex, 1)
152SYSCALL(sys_mprotect, 3) /* 125 */
153SYSCALL(sys_ni_syscall, 3)
154SYSCALL(sys_ni_syscall, 2)
155SYSCALL(sys_init_module, 2)
156SYSCALL(sys_delete_module, 1)
157SYSCALL(sys_ni_syscall, 1) /* 130 */
158SYSCALL(sys_quotactl, 0)
159SYSCALL(sys_getpgid, 1)
160SYSCALL(sys_fchdir, 1)
161SYSCALL(sys_bdflush, 2)
162SYSCALL(sys_sysfs, 3) /* 135 */
163SYSCALL(sys_personality, 1)
164SYSCALL(sys_ni_syscall, 0)
165SYSCALL(sys_setfsuid, 1)
166SYSCALL(sys_setfsgid, 1)
167SYSCALL(sys_llseek, 5) /* 140 */
168SYSCALL(sys_getdents, 3)
169SYSCALL(sys_select, 5)
170SYSCALL(sys_flock, 2)
171SYSCALL(sys_msync, 3)
172SYSCALL(sys_readv, 3) /* 145 */
173SYSCALL(sys_writev, 3)
174SYSCALL(sys_ni_syscall, 3)
175SYSCALL(sys_ni_syscall, 3)
176SYSCALL(sys_ni_syscall, 4) /* handled in fast syscall handler. */
177SYSCALL(sys_ni_syscall, 0) /* 150 */
178SYSCALL(sys_getsid, 1)
179SYSCALL(sys_fdatasync, 1)
180SYSCALL(sys_sysctl, 1)
181SYSCALL(sys_mlock, 2)
182SYSCALL(sys_munlock, 2) /* 155 */
183SYSCALL(sys_mlockall, 1)
184SYSCALL(sys_munlockall, 0)
185SYSCALL(sys_sched_setparam,2)
186SYSCALL(sys_sched_getparam,2)
187SYSCALL(sys_sched_setscheduler,3) /* 160 */
188SYSCALL(sys_sched_getscheduler,1)
189SYSCALL(sys_sched_yield,0)
190SYSCALL(sys_sched_get_priority_max,1)
191SYSCALL(sys_sched_get_priority_min,1)
192SYSCALL(sys_sched_rr_get_interval,2) /* 165 */
193SYSCALL(sys_nanosleep,2)
194SYSCALL(sys_mremap,4)
195SYSCALL(sys_accept, 3)
196SYSCALL(sys_bind, 3)
197SYSCALL(sys_connect, 3) /* 170 */
198SYSCALL(sys_getpeername, 3)
199SYSCALL(sys_getsockname, 3)
200SYSCALL(sys_getsockopt, 5)
201SYSCALL(sys_listen, 2)
202SYSCALL(sys_recv, 4) /* 175 */
203SYSCALL(sys_recvfrom, 6)
204SYSCALL(sys_recvmsg, 3)
205SYSCALL(sys_send, 4)
206SYSCALL(sys_sendmsg, 3)
207SYSCALL(sys_sendto, 6) /* 180 */
208SYSCALL(sys_setsockopt, 5)
209SYSCALL(sys_shutdown, 2)
210SYSCALL(sys_socket, 3)
211SYSCALL(sys_socketpair, 4)
212SYSCALL(sys_setresuid, 3) /* 185 */
213SYSCALL(sys_getresuid, 3)
214SYSCALL(sys_ni_syscall, 5)
215SYSCALL(sys_poll, 3)
216SYSCALL(sys_nfsservctl, 3)
217SYSCALL(sys_setresgid, 3) /* 190 */
218SYSCALL(sys_getresgid, 3)
219SYSCALL(sys_prctl, 5)
220SYSCALL(sys_rt_sigreturn, 0)
221SYSCALL(sys_rt_sigaction, 4)
222SYSCALL(sys_rt_sigprocmask, 4) /* 195 */
223SYSCALL(sys_rt_sigpending, 2)
224SYSCALL(sys_rt_sigtimedwait, 4)
225SYSCALL(sys_rt_sigqueueinfo, 3)
226SYSCALL(sys_rt_sigsuspend, 0)
227SYSCALL(sys_pread64, 5) /* 200 */
228SYSCALL(sys_pwrite64, 5)
229SYSCALL(sys_chown, 3)
230SYSCALL(sys_getcwd, 2)
231SYSCALL(sys_capget, 2)
232SYSCALL(sys_capset, 2) /* 205 */
233SYSCALL(sys_sigaltstack, 0)
234SYSCALL(sys_sendfile, 4)
235SYSCALL(sys_ni_syscall, 0)
236SYSCALL(sys_ni_syscall, 0)
237SYSCALL(sys_mmap, 6) /* 210 */
238SYSCALL(sys_truncate64, 2)
239SYSCALL(sys_ftruncate64, 2)
240SYSCALL(sys_stat64, 2)
241SYSCALL(sys_lstat64, 2)
242SYSCALL(sys_fstat64, 2) /* 215 */
243SYSCALL(sys_pivot_root, 2)
244SYSCALL(sys_mincore, 3)
245SYSCALL(sys_madvise, 3)
246SYSCALL(sys_getdents64, 3)
247SYSCALL(sys_ni_syscall, 0) /* 220 */
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c
index 37347e369987..a350431363a0 100644
--- a/arch/xtensa/kernel/time.c
+++ b/arch/xtensa/kernel/time.c
@@ -47,7 +47,7 @@ unsigned long long sched_clock(void)
47 return (unsigned long long)jiffies * (1000000000 / HZ); 47 return (unsigned long long)jiffies * (1000000000 / HZ);
48} 48}
49 49
50static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs); 50static irqreturn_t timer_interrupt(int irq, void *dev_id);
51static struct irqaction timer_irqaction = { 51static struct irqaction timer_irqaction = {
52 .handler = timer_interrupt, 52 .handler = timer_interrupt,
53 .flags = IRQF_DISABLED, 53 .flags = IRQF_DISABLED,
@@ -150,7 +150,7 @@ EXPORT_SYMBOL(do_gettimeofday);
150 * The timer interrupt is called HZ times per second. 150 * The timer interrupt is called HZ times per second.
151 */ 151 */
152 152
153irqreturn_t timer_interrupt (int irq, void *dev_id, struct pt_regs *regs) 153irqreturn_t timer_interrupt (int irq, void *dev_id)
154{ 154{
155 155
156 unsigned long next; 156 unsigned long next;
@@ -160,9 +160,9 @@ irqreturn_t timer_interrupt (int irq, void *dev_id, struct pt_regs *regs)
160again: 160again:
161 while ((signed long)(get_ccount() - next) > 0) { 161 while ((signed long)(get_ccount() - next) > 0) {
162 162
163 profile_tick(CPU_PROFILING, regs); 163 profile_tick(CPU_PROFILING);
164#ifndef CONFIG_SMP 164#ifndef CONFIG_SMP
165 update_process_times(user_mode(regs)); 165 update_process_times(user_mode(get_irq_regs()));
166#endif 166#endif
167 167
168 write_seqlock(&xtime_lock); 168 write_seqlock(&xtime_lock);
diff --git a/arch/xtensa/kernel/traps.c b/arch/xtensa/kernel/traps.c
index ce077d6bf3a0..693ab268485e 100644
--- a/arch/xtensa/kernel/traps.c
+++ b/arch/xtensa/kernel/traps.c
@@ -75,7 +75,7 @@ extern void system_call (struct pt_regs*);
75#define USER 0x02 75#define USER 0x02
76 76
77#define COPROCESSOR(x) \ 77#define COPROCESSOR(x) \
78{ XCHAL_EXCCAUSE_COPROCESSOR ## x ## _DISABLED, USER, fast_coprocessor } 78{ EXCCAUSE_COPROCESSOR ## x ## _DISABLED, USER, fast_coprocessor }
79 79
80typedef struct { 80typedef struct {
81 int cause; 81 int cause;
@@ -85,38 +85,38 @@ typedef struct {
85 85
86dispatch_init_table_t __init dispatch_init_table[] = { 86dispatch_init_table_t __init dispatch_init_table[] = {
87 87
88{ XCHAL_EXCCAUSE_ILLEGAL_INSTRUCTION, 0, do_illegal_instruction}, 88{ EXCCAUSE_ILLEGAL_INSTRUCTION, 0, do_illegal_instruction},
89{ XCHAL_EXCCAUSE_SYSTEM_CALL, KRNL, fast_syscall_kernel }, 89{ EXCCAUSE_SYSTEM_CALL, KRNL, fast_syscall_kernel },
90{ XCHAL_EXCCAUSE_SYSTEM_CALL, USER, fast_syscall_user }, 90{ EXCCAUSE_SYSTEM_CALL, USER, fast_syscall_user },
91{ XCHAL_EXCCAUSE_SYSTEM_CALL, 0, system_call }, 91{ EXCCAUSE_SYSTEM_CALL, 0, system_call },
92/* XCHAL_EXCCAUSE_INSTRUCTION_FETCH unhandled */ 92/* EXCCAUSE_INSTRUCTION_FETCH unhandled */
93/* XCHAL_EXCCAUSE_LOAD_STORE_ERROR unhandled*/ 93/* EXCCAUSE_LOAD_STORE_ERROR unhandled*/
94{ XCHAL_EXCCAUSE_LEVEL1_INTERRUPT, 0, do_interrupt }, 94{ EXCCAUSE_LEVEL1_INTERRUPT, 0, do_interrupt },
95{ XCHAL_EXCCAUSE_ALLOCA, USER|KRNL, fast_alloca }, 95{ EXCCAUSE_ALLOCA, USER|KRNL, fast_alloca },
96/* XCHAL_EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */ 96/* EXCCAUSE_INTEGER_DIVIDE_BY_ZERO unhandled */
97/* XCHAL_EXCCAUSE_PRIVILEGED unhandled */ 97/* EXCCAUSE_PRIVILEGED unhandled */
98#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION 98#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
99#ifdef CONFIG_UNALIGNED_USER 99#ifdef CONFIG_UNALIGNED_USER
100{ XCHAL_EXCCAUSE_UNALIGNED, USER, fast_unaligned }, 100{ EXCCAUSE_UNALIGNED, USER, fast_unaligned },
101#else 101#else
102{ XCHAL_EXCCAUSE_UNALIGNED, 0, do_unaligned_user }, 102{ EXCCAUSE_UNALIGNED, 0, do_unaligned_user },
103#endif 103#endif
104{ XCHAL_EXCCAUSE_UNALIGNED, KRNL, fast_unaligned }, 104{ EXCCAUSE_UNALIGNED, KRNL, fast_unaligned },
105#endif 105#endif
106{ XCHAL_EXCCAUSE_ITLB_MISS, 0, do_page_fault }, 106{ EXCCAUSE_ITLB_MISS, 0, do_page_fault },
107{ XCHAL_EXCCAUSE_ITLB_MISS, USER|KRNL, fast_second_level_miss}, 107{ EXCCAUSE_ITLB_MISS, USER|KRNL, fast_second_level_miss},
108{ XCHAL_EXCCAUSE_ITLB_MULTIHIT, 0, do_multihit }, 108{ EXCCAUSE_ITLB_MULTIHIT, 0, do_multihit },
109{ XCHAL_EXCCAUSE_ITLB_PRIVILEGE, 0, do_page_fault }, 109{ EXCCAUSE_ITLB_PRIVILEGE, 0, do_page_fault },
110/* XCHAL_EXCCAUSE_SIZE_RESTRICTION unhandled */ 110/* EXCCAUSE_SIZE_RESTRICTION unhandled */
111{ XCHAL_EXCCAUSE_FETCH_CACHE_ATTRIBUTE, 0, do_page_fault }, 111{ EXCCAUSE_FETCH_CACHE_ATTRIBUTE, 0, do_page_fault },
112{ XCHAL_EXCCAUSE_DTLB_MISS, USER|KRNL, fast_second_level_miss}, 112{ EXCCAUSE_DTLB_MISS, USER|KRNL, fast_second_level_miss},
113{ XCHAL_EXCCAUSE_DTLB_MISS, 0, do_page_fault }, 113{ EXCCAUSE_DTLB_MISS, 0, do_page_fault },
114{ XCHAL_EXCCAUSE_DTLB_MULTIHIT, 0, do_multihit }, 114{ EXCCAUSE_DTLB_MULTIHIT, 0, do_multihit },
115{ XCHAL_EXCCAUSE_DTLB_PRIVILEGE, 0, do_page_fault }, 115{ EXCCAUSE_DTLB_PRIVILEGE, 0, do_page_fault },
116/* XCHAL_EXCCAUSE_DTLB_SIZE_RESTRICTION unhandled */ 116/* EXCCAUSE_DTLB_SIZE_RESTRICTION unhandled */
117{ XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE, USER|KRNL, fast_store_prohibited }, 117{ EXCCAUSE_STORE_CACHE_ATTRIBUTE, USER|KRNL, fast_store_prohibited },
118{ XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE, 0, do_page_fault }, 118{ EXCCAUSE_STORE_CACHE_ATTRIBUTE, 0, do_page_fault },
119{ XCHAL_EXCCAUSE_LOAD_CACHE_ATTRIBUTE, 0, do_page_fault }, 119{ EXCCAUSE_LOAD_CACHE_ATTRIBUTE, 0, do_page_fault },
120/* XCCHAL_EXCCAUSE_FLOATING_POINT unhandled */ 120/* XCCHAL_EXCCAUSE_FLOATING_POINT unhandled */
121#if (XCHAL_CP_MASK & 1) 121#if (XCHAL_CP_MASK & 1)
122COPROCESSOR(0), 122COPROCESSOR(0),
diff --git a/arch/xtensa/kernel/vectors.S b/arch/xtensa/kernel/vectors.S
index 0e74397bfa2b..eb2d7bb69ee0 100644
--- a/arch/xtensa/kernel/vectors.S
+++ b/arch/xtensa/kernel/vectors.S
@@ -53,6 +53,8 @@
53#include <asm/thread_info.h> 53#include <asm/thread_info.h>
54#include <asm/processor.h> 54#include <asm/processor.h>
55 55
56#define WINDOW_VECTORS_SIZE 0x180
57
56 58
57/* 59/*
58 * User exception vector. (Exceptions with PS.UM == 1, PS.EXCM == 0) 60 * User exception vector. (Exceptions with PS.UM == 1, PS.EXCM == 0)
@@ -210,7 +212,7 @@ ENTRY(_DoubleExceptionVector)
210 /* Check for kernel double exception (usually fatal). */ 212 /* Check for kernel double exception (usually fatal). */
211 213
212 rsr a3, PS 214 rsr a3, PS
213 _bbci.l a3, PS_UM_SHIFT, .Lksp 215 _bbci.l a3, PS_UM_BIT, .Lksp
214 216
215 /* Check if we are currently handling a window exception. */ 217 /* Check if we are currently handling a window exception. */
216 /* Note: We don't need to indicate that we enter a critical section. */ 218 /* Note: We don't need to indicate that we enter a critical section. */
@@ -219,7 +221,7 @@ ENTRY(_DoubleExceptionVector)
219 221
220 movi a3, XCHAL_WINDOW_VECTORS_VADDR 222 movi a3, XCHAL_WINDOW_VECTORS_VADDR
221 _bltu a0, a3, .Lfixup 223 _bltu a0, a3, .Lfixup
222 addi a3, a3, XSHAL_WINDOW_VECTORS_SIZE 224 addi a3, a3, WINDOW_VECTORS_SIZE
223 _bgeu a0, a3, .Lfixup 225 _bgeu a0, a3, .Lfixup
224 226
225 /* Window overflow/underflow exception. Get stack pointer. */ 227 /* Window overflow/underflow exception. Get stack pointer. */
@@ -245,7 +247,7 @@ ENTRY(_DoubleExceptionVector)
245 247
246 wsr a2, DEPC # save stack pointer temporarily 248 wsr a2, DEPC # save stack pointer temporarily
247 rsr a0, PS 249 rsr a0, PS
248 extui a0, a0, XCHAL_PS_OWB_SHIFT, XCHAL_PS_OWB_BITS 250 extui a0, a0, PS_OWB_SHIFT, 4
249 wsr a0, WINDOWBASE 251 wsr a0, WINDOWBASE
250 rsync 252 rsync
251 253
@@ -312,8 +314,8 @@ ENTRY(_DoubleExceptionVector)
312.Lksp: /* a0: a0, a1: a1, a2: a2, a3: trashed, depc: depc, excsave: a3 */ 314.Lksp: /* a0: a0, a1: a1, a2: a2, a3: trashed, depc: depc, excsave: a3 */
313 315
314 rsr a3, EXCCAUSE 316 rsr a3, EXCCAUSE
315 beqi a3, XCHAL_EXCCAUSE_ITLB_MISS, 1f 317 beqi a3, EXCCAUSE_ITLB_MISS, 1f
316 addi a3, a3, -XCHAL_EXCCAUSE_DTLB_MISS 318 addi a3, a3, -EXCCAUSE_DTLB_MISS
317 bnez a3, .Lunrecoverable 319 bnez a3, .Lunrecoverable
3181: movi a3, fast_second_level_miss_double_kernel 3201: movi a3, fast_second_level_miss_double_kernel
319 jx a3 321 jx a3
diff --git a/arch/xtensa/kernel/vmlinux.lds.S b/arch/xtensa/kernel/vmlinux.lds.S
index cfe75f528725..a36c104c3a52 100644
--- a/arch/xtensa/kernel/vmlinux.lds.S
+++ b/arch/xtensa/kernel/vmlinux.lds.S
@@ -16,19 +16,17 @@
16 16
17#include <asm-generic/vmlinux.lds.h> 17#include <asm-generic/vmlinux.lds.h>
18 18
19#define _NOCLANGUAGE 19#include <asm/variant/core.h>
20#include <xtensa/config/core.h>
21#include <xtensa/config/system.h>
22OUTPUT_ARCH(xtensa) 20OUTPUT_ARCH(xtensa)
23ENTRY(_start) 21ENTRY(_start)
24 22
25#if XCHAL_MEMORY_ORDER == XTHAL_BIGENDIAN 23#ifdef __XTENSA_EB__
26jiffies = jiffies_64 + 4; 24jiffies = jiffies_64 + 4;
27#else 25#else
28jiffies = jiffies_64; 26jiffies = jiffies_64;
29#endif 27#endif
30 28
31#define KERNELOFFSET 0x1000 29#define KERNELOFFSET 0xd0001000
32 30
33/* Note: In the following macros, it would be nice to specify only the 31/* Note: In the following macros, it would be nice to specify only the
34 vector name and section kind and construct "sym" and "section" using 32 vector name and section kind and construct "sym" and "section" using
@@ -75,7 +73,7 @@ jiffies = jiffies_64;
75 73
76SECTIONS 74SECTIONS
77{ 75{
78 . = XCHAL_KSEG_CACHED_VADDR + KERNELOFFSET; 76 . = KERNELOFFSET;
79 /* .text section */ 77 /* .text section */
80 78
81 _text = .; 79 _text = .;
@@ -159,7 +157,7 @@ SECTIONS
159 157
160 /* Initialization code and data: */ 158 /* Initialization code and data: */
161 159
162 . = ALIGN(1<<XCHAL_MMU_MIN_PTE_PAGE_SIZE); 160 . = ALIGN(1 << 12);
163 __init_begin = .; 161 __init_begin = .;
164 .init.text : { 162 .init.text : {
165 _sinittext = .; 163 _sinittext = .;
@@ -223,32 +221,32 @@ SECTIONS
223 .dummy) 221 .dummy)
224 SECTION_VECTOR (_DebugInterruptVector_literal, 222 SECTION_VECTOR (_DebugInterruptVector_literal,
225 .DebugInterruptVector.literal, 223 .DebugInterruptVector.literal,
226 XCHAL_INTLEVEL_VECTOR_VADDR(XCHAL_DEBUGLEVEL) - 4, 224 XCHAL_DEBUG_VECTOR_VADDR - 4,
227 SIZEOF(.WindowVectors.text), 225 SIZEOF(.WindowVectors.text),
228 .WindowVectors.text) 226 .WindowVectors.text)
229 SECTION_VECTOR (_DebugInterruptVector_text, 227 SECTION_VECTOR (_DebugInterruptVector_text,
230 .DebugInterruptVector.text, 228 .DebugInterruptVector.text,
231 XCHAL_INTLEVEL_VECTOR_VADDR(XCHAL_DEBUGLEVEL), 229 XCHAL_DEBUG_VECTOR_VADDR,
232 4, 230 4,
233 .DebugInterruptVector.literal) 231 .DebugInterruptVector.literal)
234 SECTION_VECTOR (_KernelExceptionVector_literal, 232 SECTION_VECTOR (_KernelExceptionVector_literal,
235 .KernelExceptionVector.literal, 233 .KernelExceptionVector.literal,
236 XCHAL_KERNELEXC_VECTOR_VADDR - 4, 234 XCHAL_KERNEL_VECTOR_VADDR - 4,
237 SIZEOF(.DebugInterruptVector.text), 235 SIZEOF(.DebugInterruptVector.text),
238 .DebugInterruptVector.text) 236 .DebugInterruptVector.text)
239 SECTION_VECTOR (_KernelExceptionVector_text, 237 SECTION_VECTOR (_KernelExceptionVector_text,
240 .KernelExceptionVector.text, 238 .KernelExceptionVector.text,
241 XCHAL_KERNELEXC_VECTOR_VADDR, 239 XCHAL_KERNEL_VECTOR_VADDR,
242 4, 240 4,
243 .KernelExceptionVector.literal) 241 .KernelExceptionVector.literal)
244 SECTION_VECTOR (_UserExceptionVector_literal, 242 SECTION_VECTOR (_UserExceptionVector_literal,
245 .UserExceptionVector.literal, 243 .UserExceptionVector.literal,
246 XCHAL_USEREXC_VECTOR_VADDR - 4, 244 XCHAL_USER_VECTOR_VADDR - 4,
247 SIZEOF(.KernelExceptionVector.text), 245 SIZEOF(.KernelExceptionVector.text),
248 .KernelExceptionVector.text) 246 .KernelExceptionVector.text)
249 SECTION_VECTOR (_UserExceptionVector_text, 247 SECTION_VECTOR (_UserExceptionVector_text,
250 .UserExceptionVector.text, 248 .UserExceptionVector.text,
251 XCHAL_USEREXC_VECTOR_VADDR, 249 XCHAL_USER_VECTOR_VADDR,
252 4, 250 4,
253 .UserExceptionVector.literal) 251 .UserExceptionVector.literal)
254 SECTION_VECTOR (_DoubleExceptionVector_literal, 252 SECTION_VECTOR (_DoubleExceptionVector_literal,
@@ -263,7 +261,7 @@ SECTIONS
263 .DoubleExceptionVector.literal) 261 .DoubleExceptionVector.literal)
264 262
265 . = (LOADADDR( .DoubleExceptionVector.text ) + SIZEOF( .DoubleExceptionVector.text ) + 3) & ~ 3; 263 . = (LOADADDR( .DoubleExceptionVector.text ) + SIZEOF( .DoubleExceptionVector.text ) + 3) & ~ 3;
266 . = ALIGN(1<<XCHAL_MMU_MIN_PTE_PAGE_SIZE); 264 . = ALIGN(1 << 12);
267 265
268 __init_end = .; 266 __init_end = .;
269 267
diff --git a/arch/xtensa/lib/checksum.S b/arch/xtensa/lib/checksum.S
index e2d64dfd530c..9d9cd990afa6 100644
--- a/arch/xtensa/lib/checksum.S
+++ b/arch/xtensa/lib/checksum.S
@@ -16,8 +16,7 @@
16 16
17#include <asm/errno.h> 17#include <asm/errno.h>
18#include <linux/linkage.h> 18#include <linux/linkage.h>
19#define _ASMLANGUAGE 19#include <asm/variant/core.h>
20#include <xtensa/config/core.h>
21 20
22/* 21/*
23 * computes a partial checksum, e.g. for TCP/UDP fragments 22 * computes a partial checksum, e.g. for TCP/UDP fragments
diff --git a/arch/xtensa/lib/memcopy.S b/arch/xtensa/lib/memcopy.S
index e8f6d7eb7222..ddda8f4bc862 100644
--- a/arch/xtensa/lib/memcopy.S
+++ b/arch/xtensa/lib/memcopy.S
@@ -9,7 +9,7 @@
9 * Copyright (C) 2002 - 2005 Tensilica Inc. 9 * Copyright (C) 2002 - 2005 Tensilica Inc.
10 */ 10 */
11 11
12#include <xtensa/coreasm.h> 12#include <asm/variant/core.h>
13 13
14 .macro src_b r, w0, w1 14 .macro src_b r, w0, w1
15#ifdef __XTENSA_EB__ 15#ifdef __XTENSA_EB__
diff --git a/arch/xtensa/lib/memset.S b/arch/xtensa/lib/memset.S
index 4de25134bc62..56a17495b2db 100644
--- a/arch/xtensa/lib/memset.S
+++ b/arch/xtensa/lib/memset.S
@@ -11,7 +11,7 @@
11 * Copyright (C) 2002 Tensilica Inc. 11 * Copyright (C) 2002 Tensilica Inc.
12 */ 12 */
13 13
14#include <xtensa/coreasm.h> 14#include <asm/variant/core.h>
15 15
16/* 16/*
17 * void *memset(void *dst, int c, size_t length) 17 * void *memset(void *dst, int c, size_t length)
diff --git a/arch/xtensa/lib/strncpy_user.S b/arch/xtensa/lib/strncpy_user.S
index 71d55df43893..a834057bda6b 100644
--- a/arch/xtensa/lib/strncpy_user.S
+++ b/arch/xtensa/lib/strncpy_user.S
@@ -11,7 +11,7 @@
11 * Copyright (C) 2002 Tensilica Inc. 11 * Copyright (C) 2002 Tensilica Inc.
12 */ 12 */
13 13
14#include <xtensa/coreasm.h> 14#include <asm/variant/core.h>
15#include <linux/errno.h> 15#include <linux/errno.h>
16 16
17/* Load or store instructions that may cause exceptions use the EX macro. */ 17/* Load or store instructions that may cause exceptions use the EX macro. */
diff --git a/arch/xtensa/lib/strnlen_user.S b/arch/xtensa/lib/strnlen_user.S
index cdff4d670f3b..5e9c1e709b2e 100644
--- a/arch/xtensa/lib/strnlen_user.S
+++ b/arch/xtensa/lib/strnlen_user.S
@@ -11,7 +11,7 @@
11 * Copyright (C) 2002 Tensilica Inc. 11 * Copyright (C) 2002 Tensilica Inc.
12 */ 12 */
13 13
14#include <xtensa/coreasm.h> 14#include <asm/variant/core.h>
15 15
16/* Load or store instructions that may cause exceptions use the EX macro. */ 16/* Load or store instructions that may cause exceptions use the EX macro. */
17 17
diff --git a/arch/xtensa/lib/usercopy.S b/arch/xtensa/lib/usercopy.S
index 4641ef510f0e..a8ab1d4fe0ae 100644
--- a/arch/xtensa/lib/usercopy.S
+++ b/arch/xtensa/lib/usercopy.S
@@ -53,7 +53,7 @@
53 * a11/ original length 53 * a11/ original length
54 */ 54 */
55 55
56#include <xtensa/coreasm.h> 56#include <asm/variant/core.h>
57 57
58#ifdef __XTENSA_EB__ 58#ifdef __XTENSA_EB__
59#define ALIGN(R, W0, W1) src R, W0, W1 59#define ALIGN(R, W0, W1) src R, W0, W1
diff --git a/arch/xtensa/mm/fault.c b/arch/xtensa/mm/fault.c
index dd0dbec2e57e..3dc6f2f07bbe 100644
--- a/arch/xtensa/mm/fault.c
+++ b/arch/xtensa/mm/fault.c
@@ -21,7 +21,7 @@
21#include <asm/system.h> 21#include <asm/system.h>
22#include <asm/pgalloc.h> 22#include <asm/pgalloc.h>
23 23
24unsigned long asid_cache = ASID_FIRST_VERSION; 24unsigned long asid_cache = ASID_USER_FIRST;
25void bad_page_fault(struct pt_regs*, unsigned long, int); 25void bad_page_fault(struct pt_regs*, unsigned long, int);
26 26
27/* 27/*
@@ -58,10 +58,10 @@ void do_page_fault(struct pt_regs *regs)
58 return; 58 return;
59 } 59 }
60 60
61 is_write = (exccause == XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE) ? 1 : 0; 61 is_write = (exccause == EXCCAUSE_STORE_CACHE_ATTRIBUTE) ? 1 : 0;
62 is_exec = (exccause == XCHAL_EXCCAUSE_ITLB_PRIVILEGE || 62 is_exec = (exccause == EXCCAUSE_ITLB_PRIVILEGE ||
63 exccause == XCHAL_EXCCAUSE_ITLB_MISS || 63 exccause == EXCCAUSE_ITLB_MISS ||
64 exccause == XCHAL_EXCCAUSE_FETCH_CACHE_ATTRIBUTE) ? 1 : 0; 64 exccause == EXCCAUSE_FETCH_CACHE_ATTRIBUTE) ? 1 : 0;
65 65
66#if 0 66#if 0
67 printk("[%s:%d:%08x:%d:%08x:%s%s]\n", current->comm, current->pid, 67 printk("[%s:%d:%08x:%d:%08x:%s%s]\n", current->comm, current->pid,
diff --git a/arch/xtensa/mm/init.c b/arch/xtensa/mm/init.c
index 660ef058c149..e1ec2d1e8189 100644
--- a/arch/xtensa/mm/init.c
+++ b/arch/xtensa/mm/init.c
@@ -141,8 +141,8 @@ void __init bootmem_init(void)
141 if (min_low_pfn > max_pfn) 141 if (min_low_pfn > max_pfn)
142 panic("No memory found!\n"); 142 panic("No memory found!\n");
143 143
144 max_low_pfn = max_pfn < MAX_LOW_MEMORY >> PAGE_SHIFT ? 144 max_low_pfn = max_pfn < MAX_MEM_PFN >> PAGE_SHIFT ?
145 max_pfn : MAX_LOW_MEMORY >> PAGE_SHIFT; 145 max_pfn : MAX_MEM_PFN >> PAGE_SHIFT;
146 146
147 /* Find an area to use for the bootmem bitmap. */ 147 /* Find an area to use for the bootmem bitmap. */
148 148
@@ -215,7 +215,7 @@ void __init init_mmu (void)
215 215
216 /* Set rasid register to a known value. */ 216 /* Set rasid register to a known value. */
217 217
218 set_rasid_register (ASID_ALL_RESERVED); 218 set_rasid_register (ASID_USER_FIRST);
219 219
220 /* Set PTEVADDR special register to the start of the page 220 /* Set PTEVADDR special register to the start of the page
221 * table, which is in kernel mappable space (ie. not 221 * table, which is in kernel mappable space (ie. not
diff --git a/arch/xtensa/mm/misc.S b/arch/xtensa/mm/misc.S
index 327c0f17187c..ae085332c607 100644
--- a/arch/xtensa/mm/misc.S
+++ b/arch/xtensa/mm/misc.S
@@ -19,9 +19,8 @@
19#include <linux/linkage.h> 19#include <linux/linkage.h>
20#include <asm/page.h> 20#include <asm/page.h>
21#include <asm/pgtable.h> 21#include <asm/pgtable.h>
22 22#include <asm/asmmacro.h>
23#include <xtensa/cacheasm.h> 23#include <asm/cacheasm.h>
24#include <xtensa/cacheattrasm.h>
25 24
26/* clear_page (page) */ 25/* clear_page (page) */
27 26
@@ -74,104 +73,66 @@ ENTRY(copy_page)
74 73
75 retw 74 retw
76 75
77
78/* 76/*
79 * void __flush_invalidate_cache_all(void) 77 * void __invalidate_icache_page(ulong start)
80 */ 78 */
81 79
82ENTRY(__flush_invalidate_cache_all) 80ENTRY(__invalidate_icache_page)
83 entry sp, 16 81 entry sp, 16
84 dcache_writeback_inv_all a2, a3
85 icache_invalidate_all a2, a3
86 retw
87 82
88/* 83 ___invalidate_icache_page a2 a3
89 * void __invalidate_icache_all(void) 84 isync
90 */
91 85
92ENTRY(__invalidate_icache_all)
93 entry sp, 16
94 icache_invalidate_all a2, a3
95 retw 86 retw
96 87
97/* 88/*
98 * void __flush_invalidate_dcache_all(void) 89 * void __invalidate_dcache_page(ulong start)
99 */ 90 */
100 91
101ENTRY(__flush_invalidate_dcache_all) 92ENTRY(__invalidate_dcache_page)
102 entry sp, 16 93 entry sp, 16
103 dcache_writeback_inv_all a2, a3
104 retw
105
106 94
107/* 95 ___invalidate_dcache_page a2 a3
108 * void __flush_invalidate_cache_range(ulong start, ulong size) 96 dsync
109 */
110 97
111ENTRY(__flush_invalidate_cache_range)
112 entry sp, 16
113 mov a4, a2
114 mov a5, a3
115 dcache_writeback_inv_region a4, a5, a6
116 icache_invalidate_region a2, a3, a4
117 retw 98 retw
118 99
119/* 100/*
120 * void __invalidate_icache_page(ulong start) 101 * void __flush_invalidate_dcache_page(ulong start)
121 */ 102 */
122 103
123ENTRY(__invalidate_icache_page) 104ENTRY(__flush_invalidate_dcache_page)
124 entry sp, 16 105 entry sp, 16
125 movi a3, PAGE_SIZE
126 icache_invalidate_region a2, a3, a4
127 retw
128 106
129/* 107 ___flush_invalidate_dcache_page a2 a3
130 * void __invalidate_dcache_page(ulong start)
131 */
132 108
133ENTRY(__invalidate_dcache_page) 109 dsync
134 entry sp, 16
135 movi a3, PAGE_SIZE
136 dcache_invalidate_region a2, a3, a4
137 retw 110 retw
138 111
139/* 112/*
140 * void __invalidate_icache_range(ulong start, ulong size) 113 * void __flush_dcache_page(ulong start)
141 */ 114 */
142 115
143ENTRY(__invalidate_icache_range) 116ENTRY(__flush_dcache_page)
144 entry sp, 16 117 entry sp, 16
145 icache_invalidate_region a2, a3, a4
146 retw
147 118
148/* 119 ___flush_dcache_page a2 a3
149 * void __invalidate_dcache_range(ulong start, ulong size)
150 */
151 120
152ENTRY(__invalidate_dcache_range) 121 dsync
153 entry sp, 16
154 dcache_invalidate_region a2, a3, a4
155 retw 122 retw
156 123
157/*
158 * void __flush_dcache_page(ulong start)
159 */
160 124
161ENTRY(__flush_dcache_page)
162 entry sp, 16
163 movi a3, PAGE_SIZE
164 dcache_writeback_region a2, a3, a4
165 retw
166 125
167/* 126/*
168 * void __flush_invalidate_dcache_page(ulong start) 127 * void __invalidate_icache_range(ulong start, ulong size)
169 */ 128 */
170 129
171ENTRY(__flush_invalidate_dcache_page) 130ENTRY(__invalidate_icache_range)
172 entry sp, 16 131 entry sp, 16
173 movi a3, PAGE_SIZE 132
174 dcache_writeback_inv_region a2, a3, a4 133 ___invalidate_icache_range a2 a3 a4
134 isync
135
175 retw 136 retw
176 137
177/* 138/*
@@ -180,195 +141,69 @@ ENTRY(__flush_invalidate_dcache_page)
180 141
181ENTRY(__flush_invalidate_dcache_range) 142ENTRY(__flush_invalidate_dcache_range)
182 entry sp, 16 143 entry sp, 16
183 dcache_writeback_inv_region a2, a3, a4
184 retw
185 144
186/* 145 ___flush_invalidate_dcache_range a2 a3 a4
187 * void __invalidate_dcache_all(void) 146 dsync
188 */
189 147
190ENTRY(__invalidate_dcache_all)
191 entry sp, 16
192 dcache_invalidate_all a2, a3
193 retw 148 retw
194 149
195/* 150/*
196 * void __flush_invalidate_dcache_page_phys(ulong start) 151 * void _flush_dcache_range(ulong start, ulong size)
197 */ 152 */
198 153
199ENTRY(__flush_invalidate_dcache_page_phys) 154ENTRY(__flush_dcache_range)
200 entry sp, 16 155 entry sp, 16
201 156
202 movi a3, XCHAL_DCACHE_SIZE 157 ___flush_dcache_range a2 a3 a4
203 movi a4, PAGE_MASK | 1
204 addi a2, a2, 1
205
2061: addi a3, a3, -XCHAL_DCACHE_LINESIZE
207
208 ldct a6, a3
209 dsync 158 dsync
210 and a6, a6, a4
211 beq a6, a2, 2f
212 bgeui a3, 2, 1b
213 retw
214 159
2152: diwbi a3, 0
216 bgeui a3, 2, 1b
217 retw 160 retw
218 161
219ENTRY(check_dcache_low0) 162/*
220 entry sp, 16 163 * void _invalidate_dcache_range(ulong start, ulong size)
221 164 */
222 movi a3, XCHAL_DCACHE_SIZE / 4
223 movi a4, PAGE_MASK | 1
224 addi a2, a2, 1
225
2261: addi a3, a3, -XCHAL_DCACHE_LINESIZE
227
228 ldct a6, a3
229 dsync
230 and a6, a6, a4
231 beq a6, a2, 2f
232 bgeui a3, 2, 1b
233 retw
234
2352: j 2b
236
237ENTRY(check_dcache_high0)
238 entry sp, 16
239
240 movi a5, XCHAL_DCACHE_SIZE / 4
241 movi a3, XCHAL_DCACHE_SIZE / 2
242 movi a4, PAGE_MASK | 1
243 addi a2, a2, 1
244
2451: addi a3, a3, -XCHAL_DCACHE_LINESIZE
246 addi a5, a5, -XCHAL_DCACHE_LINESIZE
247
248 ldct a6, a3
249 dsync
250 and a6, a6, a4
251 beq a6, a2, 2f
252 bgeui a5, 2, 1b
253 retw
254
2552: j 2b
256 165
257ENTRY(check_dcache_low1) 166ENTRY(__invalidate_dcache_range)
258 entry sp, 16 167 entry sp, 16
259 168
260 movi a5, XCHAL_DCACHE_SIZE / 4 169 ___invalidate_dcache_range a2 a3 a4
261 movi a3, XCHAL_DCACHE_SIZE * 3 / 4
262 movi a4, PAGE_MASK | 1
263 addi a2, a2, 1
264 170
2651: addi a3, a3, -XCHAL_DCACHE_LINESIZE
266 addi a5, a5, -XCHAL_DCACHE_LINESIZE
267 171
268 ldct a6, a3
269 dsync
270 and a6, a6, a4
271 beq a6, a2, 2f
272 bgeui a5, 2, 1b
273 retw 172 retw
274 173
2752: j 2b 174/*
175 * void _invalidate_icache_all(void)
176 */
276 177
277ENTRY(check_dcache_high1) 178ENTRY(__invalidate_icache_all)
278 entry sp, 16 179 entry sp, 16
279 180
280 movi a5, XCHAL_DCACHE_SIZE / 4 181 ___invalidate_icache_all a2 a3
281 movi a3, XCHAL_DCACHE_SIZE 182 isync
282 movi a4, PAGE_MASK | 1
283 addi a2, a2, 1
284
2851: addi a3, a3, -XCHAL_DCACHE_LINESIZE
286 addi a5, a5, -XCHAL_DCACHE_LINESIZE
287 183
288 ldct a6, a3
289 dsync
290 and a6, a6, a4
291 beq a6, a2, 2f
292 bgeui a5, 2, 1b
293 retw 184 retw
294 185
2952: j 2b
296
297
298/* 186/*
299 * void __invalidate_icache_page_phys(ulong start) 187 * void _flush_invalidate_dcache_all(void)
300 */ 188 */
301 189
302ENTRY(__invalidate_icache_page_phys) 190ENTRY(__flush_invalidate_dcache_all)
303 entry sp, 16 191 entry sp, 16
304 192
305 movi a3, XCHAL_ICACHE_SIZE 193 ___flush_invalidate_dcache_all a2 a3
306 movi a4, PAGE_MASK | 1 194 dsync
307 addi a2, a2, 1
308
3091: addi a3, a3, -XCHAL_ICACHE_LINESIZE
310
311 lict a6, a3
312 isync
313 and a6, a6, a4
314 beq a6, a2, 2f
315 bgeui a3, 2, 1b
316 retw
317 195
3182: iii a3, 0
319 bgeui a3, 2, 1b
320 retw 196 retw
321 197
198/*
199 * void _invalidate_dcache_all(void)
200 */
322 201
323#if 0 202ENTRY(__invalidate_dcache_all)
324
325 movi a3, XCHAL_DCACHE_WAYS - 1
326 movi a4, PAGE_SIZE
327
3281: mov a5, a2
329 add a6, a2, a4
330
3312: diwbi a5, 0
332 diwbi a5, XCHAL_DCACHE_LINESIZE
333 diwbi a5, XCHAL_DCACHE_LINESIZE * 2
334 diwbi a5, XCHAL_DCACHE_LINESIZE * 3
335
336 addi a5, a5, XCHAL_DCACHE_LINESIZE * 4
337 blt a5, a6, 2b
338
339 addi a3, a3, -1
340 addi a2, a2, XCHAL_DCACHE_SIZE / XCHAL_DCACHE_WAYS
341 bgez a3, 1b
342
343 retw
344
345ENTRY(__invalidate_icache_page_index)
346 entry sp, 16 203 entry sp, 16
347 204
348 movi a3, XCHAL_ICACHE_WAYS - 1 205 ___invalidate_dcache_all a2 a3
349 movi a4, PAGE_SIZE 206 dsync
350
3511: mov a5, a2
352 add a6, a2, a4
353
3542: iii a5, 0
355 iii a5, XCHAL_ICACHE_LINESIZE
356 iii a5, XCHAL_ICACHE_LINESIZE * 2
357 iii a5, XCHAL_ICACHE_LINESIZE * 3
358
359 addi a5, a5, XCHAL_ICACHE_LINESIZE * 4
360 blt a5, a6, 2b
361
362 addi a3, a3, -1
363 addi a2, a2, XCHAL_ICACHE_SIZE / XCHAL_ICACHE_WAYS
364 bgez a3, 2b
365 207
366 retw 208 retw
367 209
368#endif
369
370
371
372
373
374
diff --git a/arch/xtensa/mm/tlb.c b/arch/xtensa/mm/tlb.c
index 0fefb8666874..239461d8ea88 100644
--- a/arch/xtensa/mm/tlb.c
+++ b/arch/xtensa/mm/tlb.c
@@ -24,12 +24,12 @@
24 24
25static inline void __flush_itlb_all (void) 25static inline void __flush_itlb_all (void)
26{ 26{
27 int way, index; 27 int w, i;
28 28
29 for (way = 0; way < XCHAL_ITLB_ARF_WAYS; way++) { 29 for (w = 0; w < ITLB_ARF_WAYS; w++) {
30 for (index = 0; index < ITLB_ENTRIES_PER_ARF_WAY; index++) { 30 for (i = 0; i < (1 << XCHAL_ITLB_ARF_ENTRIES_LOG2); i++) {
31 int entry = way + (index << PAGE_SHIFT); 31 int e = w + (i << PAGE_SHIFT);
32 invalidate_itlb_entry_no_isync (entry); 32 invalidate_itlb_entry_no_isync(e);
33 } 33 }
34 } 34 }
35 asm volatile ("isync\n"); 35 asm volatile ("isync\n");
@@ -37,12 +37,12 @@ static inline void __flush_itlb_all (void)
37 37
38static inline void __flush_dtlb_all (void) 38static inline void __flush_dtlb_all (void)
39{ 39{
40 int way, index; 40 int w, i;
41 41
42 for (way = 0; way < XCHAL_DTLB_ARF_WAYS; way++) { 42 for (w = 0; w < DTLB_ARF_WAYS; w++) {
43 for (index = 0; index < DTLB_ENTRIES_PER_ARF_WAY; index++) { 43 for (i = 0; i < (1 << XCHAL_DTLB_ARF_ENTRIES_LOG2); i++) {
44 int entry = way + (index << PAGE_SHIFT); 44 int e = w + (i << PAGE_SHIFT);
45 invalidate_dtlb_entry_no_isync (entry); 45 invalidate_dtlb_entry_no_isync(e);
46 } 46 }
47 } 47 }
48 asm volatile ("isync\n"); 48 asm volatile ("isync\n");
@@ -63,21 +63,25 @@ void flush_tlb_all (void)
63 63
64void flush_tlb_mm(struct mm_struct *mm) 64void flush_tlb_mm(struct mm_struct *mm)
65{ 65{
66#if 0
67 printk("[tlbmm<%lx>]\n", (unsigned long)mm->context);
68#endif
69
70 if (mm == current->active_mm) { 66 if (mm == current->active_mm) {
71 int flags; 67 int flags;
72 local_save_flags(flags); 68 local_save_flags(flags);
73 get_new_mmu_context(mm, asid_cache); 69 __get_new_mmu_context(mm);
74 set_rasid_register(ASID_INSERT(mm->context)); 70 __load_mmu_context(mm);
75 local_irq_restore(flags); 71 local_irq_restore(flags);
76 } 72 }
77 else 73 else
78 mm->context = 0; 74 mm->context = 0;
79} 75}
80 76
77#define _ITLB_ENTRIES (ITLB_ARF_WAYS << XCHAL_ITLB_ARF_ENTRIES_LOG2)
78#define _DTLB_ENTRIES (DTLB_ARF_WAYS << XCHAL_DTLB_ARF_ENTRIES_LOG2)
79#if _ITLB_ENTRIES > _DTLB_ENTRIES
80# define _TLB_ENTRIES _ITLB_ENTRIES
81#else
82# define _TLB_ENTRIES _DTLB_ENTRIES
83#endif
84
81void flush_tlb_range (struct vm_area_struct *vma, 85void flush_tlb_range (struct vm_area_struct *vma,
82 unsigned long start, unsigned long end) 86 unsigned long start, unsigned long end)
83{ 87{
@@ -93,7 +97,7 @@ void flush_tlb_range (struct vm_area_struct *vma,
93#endif 97#endif
94 local_save_flags(flags); 98 local_save_flags(flags);
95 99
96 if (end-start + (PAGE_SIZE-1) <= SMALLEST_NTLB_ENTRIES << PAGE_SHIFT) { 100 if (end-start + (PAGE_SIZE-1) <= _TLB_ENTRIES << PAGE_SHIFT) {
97 int oldpid = get_rasid_register(); 101 int oldpid = get_rasid_register();
98 set_rasid_register (ASID_INSERT(mm->context)); 102 set_rasid_register (ASID_INSERT(mm->context));
99 start &= PAGE_MASK; 103 start &= PAGE_MASK;
@@ -111,9 +115,7 @@ void flush_tlb_range (struct vm_area_struct *vma,
111 115
112 set_rasid_register(oldpid); 116 set_rasid_register(oldpid);
113 } else { 117 } else {
114 get_new_mmu_context(mm, asid_cache); 118 flush_tlb_mm(mm);
115 if (mm == current->active_mm)
116 set_rasid_register(ASID_INSERT(mm->context));
117 } 119 }
118 local_irq_restore(flags); 120 local_irq_restore(flags);
119} 121}
@@ -123,10 +125,6 @@ void flush_tlb_page (struct vm_area_struct *vma, unsigned long page)
123 struct mm_struct* mm = vma->vm_mm; 125 struct mm_struct* mm = vma->vm_mm;
124 unsigned long flags; 126 unsigned long flags;
125 int oldpid; 127 int oldpid;
126#if 0
127 printk("[tlbpage<%02lx,%08lx>]\n",
128 (unsigned long)mm->context, page);
129#endif
130 128
131 if(mm->context == NO_CONTEXT) 129 if(mm->context == NO_CONTEXT)
132 return; 130 return;
@@ -142,404 +140,5 @@ void flush_tlb_page (struct vm_area_struct *vma, unsigned long page)
142 set_rasid_register(oldpid); 140 set_rasid_register(oldpid);
143 141
144 local_irq_restore(flags); 142 local_irq_restore(flags);
145
146#if 0
147 flush_tlb_all();
148 return;
149#endif
150}
151
152
153#ifdef DEBUG_TLB
154
155#define USE_ITLB 0
156#define USE_DTLB 1
157
158struct way_config_t {
159 int indicies;
160 int indicies_log2;
161 int pgsz_log2;
162 int arf;
163};
164
165static struct way_config_t itlb[XCHAL_ITLB_WAYS] =
166{
167 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY0_SET, ENTRIES),
168 XCHAL_ITLB_SET(XCHAL_ITLB_WAY0_SET, ENTRIES_LOG2),
169 XCHAL_ITLB_SET(XCHAL_ITLB_WAY0_SET, PAGESZ_LOG2_MIN),
170 XCHAL_ITLB_SET(XCHAL_ITLB_WAY0_SET, ARF)
171 },
172 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY1_SET, ENTRIES),
173 XCHAL_ITLB_SET(XCHAL_ITLB_WAY1_SET, ENTRIES_LOG2),
174 XCHAL_ITLB_SET(XCHAL_ITLB_WAY1_SET, PAGESZ_LOG2_MIN),
175 XCHAL_ITLB_SET(XCHAL_ITLB_WAY1_SET, ARF)
176 },
177 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY2_SET, ENTRIES),
178 XCHAL_ITLB_SET(XCHAL_ITLB_WAY2_SET, ENTRIES_LOG2),
179 XCHAL_ITLB_SET(XCHAL_ITLB_WAY2_SET, PAGESZ_LOG2_MIN),
180 XCHAL_ITLB_SET(XCHAL_ITLB_WAY2_SET, ARF)
181 },
182 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY3_SET, ENTRIES),
183 XCHAL_ITLB_SET(XCHAL_ITLB_WAY3_SET, ENTRIES_LOG2),
184 XCHAL_ITLB_SET(XCHAL_ITLB_WAY3_SET, PAGESZ_LOG2_MIN),
185 XCHAL_ITLB_SET(XCHAL_ITLB_WAY3_SET, ARF)
186 },
187 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY4_SET, ENTRIES),
188 XCHAL_ITLB_SET(XCHAL_ITLB_WAY4_SET, ENTRIES_LOG2),
189 XCHAL_ITLB_SET(XCHAL_ITLB_WAY4_SET, PAGESZ_LOG2_MIN),
190 XCHAL_ITLB_SET(XCHAL_ITLB_WAY4_SET, ARF)
191 },
192 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY5_SET, ENTRIES),
193 XCHAL_ITLB_SET(XCHAL_ITLB_WAY5_SET, ENTRIES_LOG2),
194 XCHAL_ITLB_SET(XCHAL_ITLB_WAY5_SET, PAGESZ_LOG2_MIN),
195 XCHAL_ITLB_SET(XCHAL_ITLB_WAY5_SET, ARF)
196 },
197 { XCHAL_ITLB_SET(XCHAL_ITLB_WAY6_SET, ENTRIES),
198 XCHAL_ITLB_SET(XCHAL_ITLB_WAY6_SET, ENTRIES_LOG2),
199 XCHAL_ITLB_SET(XCHAL_ITLB_WAY6_SET, PAGESZ_LOG2_MIN),
200 XCHAL_ITLB_SET(XCHAL_ITLB_WAY6_SET, ARF)
201 }
202};
203
204static struct way_config_t dtlb[XCHAL_DTLB_WAYS] =
205{
206 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY0_SET, ENTRIES),
207 XCHAL_DTLB_SET(XCHAL_DTLB_WAY0_SET, ENTRIES_LOG2),
208 XCHAL_DTLB_SET(XCHAL_DTLB_WAY0_SET, PAGESZ_LOG2_MIN),
209 XCHAL_DTLB_SET(XCHAL_DTLB_WAY0_SET, ARF)
210 },
211 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY1_SET, ENTRIES),
212 XCHAL_DTLB_SET(XCHAL_DTLB_WAY1_SET, ENTRIES_LOG2),
213 XCHAL_DTLB_SET(XCHAL_DTLB_WAY1_SET, PAGESZ_LOG2_MIN),
214 XCHAL_DTLB_SET(XCHAL_DTLB_WAY1_SET, ARF)
215 },
216 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY2_SET, ENTRIES),
217 XCHAL_DTLB_SET(XCHAL_DTLB_WAY2_SET, ENTRIES_LOG2),
218 XCHAL_DTLB_SET(XCHAL_DTLB_WAY2_SET, PAGESZ_LOG2_MIN),
219 XCHAL_DTLB_SET(XCHAL_DTLB_WAY2_SET, ARF)
220 },
221 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY3_SET, ENTRIES),
222 XCHAL_DTLB_SET(XCHAL_DTLB_WAY3_SET, ENTRIES_LOG2),
223 XCHAL_DTLB_SET(XCHAL_DTLB_WAY3_SET, PAGESZ_LOG2_MIN),
224 XCHAL_DTLB_SET(XCHAL_DTLB_WAY3_SET, ARF)
225 },
226 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY4_SET, ENTRIES),
227 XCHAL_DTLB_SET(XCHAL_DTLB_WAY4_SET, ENTRIES_LOG2),
228 XCHAL_DTLB_SET(XCHAL_DTLB_WAY4_SET, PAGESZ_LOG2_MIN),
229 XCHAL_DTLB_SET(XCHAL_DTLB_WAY4_SET, ARF)
230 },
231 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY5_SET, ENTRIES),
232 XCHAL_DTLB_SET(XCHAL_DTLB_WAY5_SET, ENTRIES_LOG2),
233 XCHAL_DTLB_SET(XCHAL_DTLB_WAY5_SET, PAGESZ_LOG2_MIN),
234 XCHAL_DTLB_SET(XCHAL_DTLB_WAY5_SET, ARF)
235 },
236 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY6_SET, ENTRIES),
237 XCHAL_DTLB_SET(XCHAL_DTLB_WAY6_SET, ENTRIES_LOG2),
238 XCHAL_DTLB_SET(XCHAL_DTLB_WAY6_SET, PAGESZ_LOG2_MIN),
239 XCHAL_DTLB_SET(XCHAL_DTLB_WAY6_SET, ARF)
240 },
241 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY7_SET, ENTRIES),
242 XCHAL_DTLB_SET(XCHAL_DTLB_WAY7_SET, ENTRIES_LOG2),
243 XCHAL_DTLB_SET(XCHAL_DTLB_WAY7_SET, PAGESZ_LOG2_MIN),
244 XCHAL_DTLB_SET(XCHAL_DTLB_WAY7_SET, ARF)
245 },
246 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY8_SET, ENTRIES),
247 XCHAL_DTLB_SET(XCHAL_DTLB_WAY8_SET, ENTRIES_LOG2),
248 XCHAL_DTLB_SET(XCHAL_DTLB_WAY8_SET, PAGESZ_LOG2_MIN),
249 XCHAL_DTLB_SET(XCHAL_DTLB_WAY8_SET, ARF)
250 },
251 { XCHAL_DTLB_SET(XCHAL_DTLB_WAY9_SET, ENTRIES),
252 XCHAL_DTLB_SET(XCHAL_DTLB_WAY9_SET, ENTRIES_LOG2),
253 XCHAL_DTLB_SET(XCHAL_DTLB_WAY9_SET, PAGESZ_LOG2_MIN),
254 XCHAL_DTLB_SET(XCHAL_DTLB_WAY9_SET, ARF)
255 }
256};
257
258/* Total number of entries: */
259#define ITLB_TOTAL_ENTRIES \
260 XCHAL_ITLB_SET(XCHAL_ITLB_WAY0_SET, ENTRIES) + \
261 XCHAL_ITLB_SET(XCHAL_ITLB_WAY1_SET, ENTRIES) + \
262 XCHAL_ITLB_SET(XCHAL_ITLB_WAY2_SET, ENTRIES) + \
263 XCHAL_ITLB_SET(XCHAL_ITLB_WAY3_SET, ENTRIES) + \
264 XCHAL_ITLB_SET(XCHAL_ITLB_WAY4_SET, ENTRIES) + \
265 XCHAL_ITLB_SET(XCHAL_ITLB_WAY5_SET, ENTRIES) + \
266 XCHAL_ITLB_SET(XCHAL_ITLB_WAY6_SET, ENTRIES)
267#define DTLB_TOTAL_ENTRIES \
268 XCHAL_DTLB_SET(XCHAL_DTLB_WAY0_SET, ENTRIES) + \
269 XCHAL_DTLB_SET(XCHAL_DTLB_WAY1_SET, ENTRIES) + \
270 XCHAL_DTLB_SET(XCHAL_DTLB_WAY2_SET, ENTRIES) + \
271 XCHAL_DTLB_SET(XCHAL_DTLB_WAY3_SET, ENTRIES) + \
272 XCHAL_DTLB_SET(XCHAL_DTLB_WAY4_SET, ENTRIES) + \
273 XCHAL_DTLB_SET(XCHAL_DTLB_WAY5_SET, ENTRIES) + \
274 XCHAL_DTLB_SET(XCHAL_DTLB_WAY6_SET, ENTRIES) + \
275 XCHAL_DTLB_SET(XCHAL_DTLB_WAY7_SET, ENTRIES) + \
276 XCHAL_DTLB_SET(XCHAL_DTLB_WAY8_SET, ENTRIES) + \
277 XCHAL_DTLB_SET(XCHAL_DTLB_WAY9_SET, ENTRIES)
278
279
280typedef struct {
281 unsigned va;
282 unsigned pa;
283 unsigned char asid;
284 unsigned char ca;
285 unsigned char way;
286 unsigned char index;
287 unsigned char pgsz_log2; /* 0 .. 32 */
288 unsigned char type; /* 0=ITLB 1=DTLB */
289} tlb_dump_entry_t;
290
291/* Return -1 if a precedes b, +1 if a follows b, 0 if same: */
292int cmp_tlb_dump_info( tlb_dump_entry_t *a, tlb_dump_entry_t *b )
293{
294 if (a->asid < b->asid) return -1;
295 if (a->asid > b->asid) return 1;
296 if (a->va < b->va) return -1;
297 if (a->va > b->va) return 1;
298 if (a->pa < b->pa) return -1;
299 if (a->pa > b->pa) return 1;
300 if (a->ca < b->ca) return -1;
301 if (a->ca > b->ca) return 1;
302 if (a->way < b->way) return -1;
303 if (a->way > b->way) return 1;
304 if (a->index < b->index) return -1;
305 if (a->index > b->index) return 1;
306 return 0;
307}
308
309void sort_tlb_dump_info( tlb_dump_entry_t *t, int n )
310{
311 int i, j;
312 /* Simple O(n*n) sort: */
313 for (i = 0; i < n-1; i++)
314 for (j = i+1; j < n; j++)
315 if (cmp_tlb_dump_info(t+i, t+j) > 0) {
316 tlb_dump_entry_t tmp = t[i];
317 t[i] = t[j];
318 t[j] = tmp;
319 }
320}
321
322
323static tlb_dump_entry_t itlb_dump_info[ITLB_TOTAL_ENTRIES];
324static tlb_dump_entry_t dtlb_dump_info[DTLB_TOTAL_ENTRIES];
325
326
327static inline char *way_type (int type)
328{
329 return type ? "autorefill" : "non-autorefill";
330}
331
332void print_entry (struct way_config_t *way_info,
333 unsigned int way,
334 unsigned int index,
335 unsigned int virtual,
336 unsigned int translation)
337{
338 char valid_chr;
339 unsigned int va, pa, asid, ca;
340
341 va = virtual &
342 ~((1 << (way_info->pgsz_log2 + way_info->indicies_log2)) - 1);
343 asid = virtual & ((1 << XCHAL_MMU_ASID_BITS) - 1);
344 pa = translation & ~((1 << way_info->pgsz_log2) - 1);
345 ca = translation & ((1 << XCHAL_MMU_CA_BITS) - 1);
346 valid_chr = asid ? 'V' : 'I';
347
348 /* Compute and incorporate the effect of the index bits on the
349 * va. It's more useful for kernel debugging, since we always
350 * want to know the effective va anyway. */
351
352 va += index << way_info->pgsz_log2;
353
354 printk ("\t[%d,%d] (%c) vpn 0x%.8x ppn 0x%.8x asid 0x%.2x am 0x%x\n",
355 way, index, valid_chr, va, pa, asid, ca);
356}
357
358void print_itlb_entry (struct way_config_t *way_info, int way, int index)
359{
360 print_entry (way_info, way, index,
361 read_itlb_virtual (way + (index << way_info->pgsz_log2)),
362 read_itlb_translation (way + (index << way_info->pgsz_log2)));
363}
364
365void print_dtlb_entry (struct way_config_t *way_info, int way, int index)
366{
367 print_entry (way_info, way, index,
368 read_dtlb_virtual (way + (index << way_info->pgsz_log2)),
369 read_dtlb_translation (way + (index << way_info->pgsz_log2)));
370}
371
372void dump_itlb (void)
373{
374 int way, index;
375
376 printk ("\nITLB: ways = %d\n", XCHAL_ITLB_WAYS);
377
378 for (way = 0; way < XCHAL_ITLB_WAYS; way++) {
379 printk ("\nWay: %d, Entries: %d, MinPageSize: %d, Type: %s\n",
380 way, itlb[way].indicies,
381 itlb[way].pgsz_log2, way_type(itlb[way].arf));
382 for (index = 0; index < itlb[way].indicies; index++) {
383 print_itlb_entry(&itlb[way], way, index);
384 }
385 }
386}
387
388void dump_dtlb (void)
389{
390 int way, index;
391
392 printk ("\nDTLB: ways = %d\n", XCHAL_DTLB_WAYS);
393
394 for (way = 0; way < XCHAL_DTLB_WAYS; way++) {
395 printk ("\nWay: %d, Entries: %d, MinPageSize: %d, Type: %s\n",
396 way, dtlb[way].indicies,
397 dtlb[way].pgsz_log2, way_type(dtlb[way].arf));
398 for (index = 0; index < dtlb[way].indicies; index++) {
399 print_dtlb_entry(&dtlb[way], way, index);
400 }
401 }
402}
403
404void dump_tlb (tlb_dump_entry_t *tinfo, struct way_config_t *config,
405 int entries, int ways, int type, int show_invalid)
406{
407 tlb_dump_entry_t *e = tinfo;
408 int way, i;
409
410 /* Gather all info: */
411 for (way = 0; way < ways; way++) {
412 struct way_config_t *cfg = config + way;
413 for (i = 0; i < cfg->indicies; i++) {
414 unsigned wayindex = way + (i << cfg->pgsz_log2);
415 unsigned vv = (type ? read_dtlb_virtual (wayindex)
416 : read_itlb_virtual (wayindex));
417 unsigned pp = (type ? read_dtlb_translation (wayindex)
418 : read_itlb_translation (wayindex));
419
420 /* Compute and incorporate the effect of the index bits on the
421 * va. It's more useful for kernel debugging, since we always
422 * want to know the effective va anyway. */
423
424 e->va = (vv & ~((1 << (cfg->pgsz_log2 + cfg->indicies_log2)) - 1));
425 e->va += (i << cfg->pgsz_log2);
426 e->pa = (pp & ~((1 << cfg->pgsz_log2) - 1));
427 e->asid = (vv & ((1 << XCHAL_MMU_ASID_BITS) - 1));
428 e->ca = (pp & ((1 << XCHAL_MMU_CA_BITS) - 1));
429 e->way = way;
430 e->index = i;
431 e->pgsz_log2 = cfg->pgsz_log2;
432 e->type = type;
433 e++;
434 }
435 }
436#if 1
437 /* Sort by ASID and VADDR: */
438 sort_tlb_dump_info (tinfo, entries);
439#endif
440
441 /* Display all sorted info: */
442 printk ("\n%cTLB dump:\n", (type ? 'D' : 'I'));
443 for (e = tinfo, i = 0; i < entries; i++, e++) {
444#if 0
445 if (e->asid == 0 && !show_invalid)
446 continue;
447#endif
448 printk ("%c way=%d i=%d ASID=%02X V=%08X -> P=%08X CA=%X (%d %cB)\n",
449 (e->type ? 'D' : 'I'), e->way, e->index,
450 e->asid, e->va, e->pa, e->ca,
451 (1 << (e->pgsz_log2 % 10)),
452 " kMG"[e->pgsz_log2 / 10]
453 );
454 }
455}
456
457void dump_tlbs2 (int showinv)
458{
459 dump_tlb (itlb_dump_info, itlb, ITLB_TOTAL_ENTRIES, XCHAL_ITLB_WAYS, 0, showinv);
460 dump_tlb (dtlb_dump_info, dtlb, DTLB_TOTAL_ENTRIES, XCHAL_DTLB_WAYS, 1, showinv);
461}
462
463void dump_all_tlbs (void)
464{
465 dump_tlbs2 (1);
466}
467
468void dump_valid_tlbs (void)
469{
470 dump_tlbs2 (0);
471} 143}
472 144
473
474void dump_tlbs (void)
475{
476 dump_itlb();
477 dump_dtlb();
478}
479
480void dump_cache_tag(int dcache, int idx)
481{
482 int w, i, s, e;
483 unsigned long tag, index;
484 unsigned long num_lines, num_ways, cache_size, line_size;
485
486 num_ways = dcache ? XCHAL_DCACHE_WAYS : XCHAL_ICACHE_WAYS;
487 cache_size = dcache ? XCHAL_DCACHE_SIZE : XCHAL_ICACHE_SIZE;
488 line_size = dcache ? XCHAL_DCACHE_LINESIZE : XCHAL_ICACHE_LINESIZE;
489
490 num_lines = cache_size / num_ways;
491
492 s = 0; e = num_lines;
493
494 if (idx >= 0)
495 e = (s = idx * line_size) + 1;
496
497 for (i = s; i < e; i+= line_size) {
498 printk("\nline %#08x:", i);
499 for (w = 0; w < num_ways; w++) {
500 index = w * num_lines + i;
501 if (dcache)
502 __asm__ __volatile__("ldct %0, %1\n\t"
503 : "=a"(tag) : "a"(index));
504 else
505 __asm__ __volatile__("lict %0, %1\n\t"
506 : "=a"(tag) : "a"(index));
507
508 printk(" %#010lx", tag);
509 }
510 }
511 printk ("\n");
512}
513
514void dump_icache(int index)
515{
516 unsigned long data, addr;
517 int w, i;
518
519 const unsigned long num_ways = XCHAL_ICACHE_WAYS;
520 const unsigned long cache_size = XCHAL_ICACHE_SIZE;
521 const unsigned long line_size = XCHAL_ICACHE_LINESIZE;
522 const unsigned long num_lines = cache_size / num_ways / line_size;
523
524 for (w = 0; w < num_ways; w++) {
525 printk ("\nWay %d", w);
526
527 for (i = 0; i < line_size; i+= 4) {
528 addr = w * num_lines + index * line_size + i;
529 __asm__ __volatile__("licw %0, %1\n\t"
530 : "=a"(data) : "a"(addr));
531 printk(" %#010lx", data);
532 }
533 }
534 printk ("\n");
535}
536
537void dump_cache_tags(void)
538{
539 printk("Instruction cache\n");
540 dump_cache_tag(0, -1);
541 printk("Data cache\n");
542 dump_cache_tag(1, -1);
543}
544
545#endif
diff --git a/arch/xtensa/platform-iss/console.c b/arch/xtensa/platform-iss/console.c
index 5c947cae7520..2f4f20ffe666 100644
--- a/arch/xtensa/platform-iss/console.c
+++ b/arch/xtensa/platform-iss/console.c
@@ -25,11 +25,15 @@
25#include <asm/uaccess.h> 25#include <asm/uaccess.h>
26#include <asm/irq.h> 26#include <asm/irq.h>
27 27
28#include <xtensa/simcall.h> 28#include <asm/platform/simcall.h>
29 29
30#include <linux/tty.h> 30#include <linux/tty.h>
31#include <linux/tty_flip.h> 31#include <linux/tty_flip.h>
32 32
33#ifdef SERIAL_INLINE
34#define _INLINE_ inline
35#endif
36
33#define SERIAL_MAX_NUM_LINES 1 37#define SERIAL_MAX_NUM_LINES 1
34#define SERIAL_TIMER_VALUE (20 * HZ) 38#define SERIAL_TIMER_VALUE (20 * HZ)
35 39
@@ -191,7 +195,7 @@ static int rs_read_proc(char *page, char **start, off_t off, int count,
191} 195}
192 196
193 197
194static const struct tty_operations serial_ops = { 198static struct tty_operations serial_ops = {
195 .open = rs_open, 199 .open = rs_open,
196 .close = rs_close, 200 .close = rs_close,
197 .write = rs_write, 201 .write = rs_write,
diff --git a/arch/xtensa/platform-iss/network.c b/arch/xtensa/platform-iss/network.c
index 15d64414bd60..8ebfc8761229 100644
--- a/arch/xtensa/platform-iss/network.c
+++ b/arch/xtensa/platform-iss/network.c
@@ -34,7 +34,7 @@
34#include <linux/timer.h> 34#include <linux/timer.h>
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36 36
37#include <xtensa/simcall.h> 37#include <asm/platform/simcall.h>
38 38
39#define DRIVER_NAME "iss-netdev" 39#define DRIVER_NAME "iss-netdev"
40#define ETH_MAX_PACKET 1500 40#define ETH_MAX_PACKET 1500
diff --git a/block/genhd.c b/block/genhd.c
index 653919d50cd4..457fdac4c17d 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -417,6 +417,34 @@ static struct disk_attribute disk_attr_stat = {
417 .show = disk_stats_read 417 .show = disk_stats_read
418}; 418};
419 419
420#ifdef CONFIG_FAIL_MAKE_REQUEST
421
422static ssize_t disk_fail_store(struct gendisk * disk,
423 const char *buf, size_t count)
424{
425 int i;
426
427 if (count > 0 && sscanf(buf, "%d", &i) > 0) {
428 if (i == 0)
429 disk->flags &= ~GENHD_FL_FAIL;
430 else
431 disk->flags |= GENHD_FL_FAIL;
432 }
433
434 return count;
435}
436static ssize_t disk_fail_read(struct gendisk * disk, char *page)
437{
438 return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
439}
440static struct disk_attribute disk_attr_fail = {
441 .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
442 .store = disk_fail_store,
443 .show = disk_fail_read
444};
445
446#endif
447
420static struct attribute * default_attrs[] = { 448static struct attribute * default_attrs[] = {
421 &disk_attr_uevent.attr, 449 &disk_attr_uevent.attr,
422 &disk_attr_dev.attr, 450 &disk_attr_dev.attr,
@@ -424,6 +452,9 @@ static struct attribute * default_attrs[] = {
424 &disk_attr_removable.attr, 452 &disk_attr_removable.attr,
425 &disk_attr_size.attr, 453 &disk_attr_size.attr,
426 &disk_attr_stat.attr, 454 &disk_attr_stat.attr,
455#ifdef CONFIG_FAIL_MAKE_REQUEST
456 &disk_attr_fail.attr,
457#endif
427 NULL, 458 NULL,
428}; 459};
429 460
diff --git a/block/ioctl.c b/block/ioctl.c
index 58aab630dfc1..f6962b64660e 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -72,7 +72,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
72 bdevp = bdget_disk(disk, part); 72 bdevp = bdget_disk(disk, part);
73 if (!bdevp) 73 if (!bdevp)
74 return -ENOMEM; 74 return -ENOMEM;
75 mutex_lock_nested(&bdevp->bd_mutex, BD_MUTEX_PARTITION); 75 mutex_lock(&bdevp->bd_mutex);
76 if (bdevp->bd_openers) { 76 if (bdevp->bd_openers) {
77 mutex_unlock(&bdevp->bd_mutex); 77 mutex_unlock(&bdevp->bd_mutex);
78 bdput(bdevp); 78 bdput(bdevp);
@@ -82,7 +82,7 @@ static int blkpg_ioctl(struct block_device *bdev, struct blkpg_ioctl_arg __user
82 fsync_bdev(bdevp); 82 fsync_bdev(bdevp);
83 invalidate_bdev(bdevp, 0); 83 invalidate_bdev(bdevp, 0);
84 84
85 mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_WHOLE); 85 mutex_lock(&bdev->bd_mutex);
86 delete_partition(disk, part); 86 delete_partition(disk, part);
87 mutex_unlock(&bdev->bd_mutex); 87 mutex_unlock(&bdev->bd_mutex);
88 mutex_unlock(&bdevp->bd_mutex); 88 mutex_unlock(&bdevp->bd_mutex);
@@ -290,7 +290,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
290 ENOIOCTLCMD for unknown ioctls. */ 290 ENOIOCTLCMD for unknown ioctls. */
291long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) 291long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
292{ 292{
293 struct block_device *bdev = file->f_dentry->d_inode->i_bdev; 293 struct block_device *bdev = file->f_path.dentry->d_inode->i_bdev;
294 struct gendisk *disk = bdev->bd_disk; 294 struct gendisk *disk = bdev->bd_disk;
295 int ret = -ENOIOCTLCMD; 295 int ret = -ENOIOCTLCMD;
296 if (disk->fops->compat_ioctl) { 296 if (disk->fops->compat_ioctl) {
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index 31512cd9f3ad..a541b42c08e3 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -25,9 +25,11 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/swap.h> 26#include <linux/swap.h>
27#include <linux/writeback.h> 27#include <linux/writeback.h>
28#include <linux/task_io_accounting_ops.h>
28#include <linux/interrupt.h> 29#include <linux/interrupt.h>
29#include <linux/cpu.h> 30#include <linux/cpu.h>
30#include <linux/blktrace_api.h> 31#include <linux/blktrace_api.h>
32#include <linux/fault-inject.h>
31 33
32/* 34/*
33 * for max sense size 35 * for max sense size
@@ -127,13 +129,6 @@ struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
127} 129}
128EXPORT_SYMBOL(blk_get_backing_dev_info); 130EXPORT_SYMBOL(blk_get_backing_dev_info);
129 131
130void blk_queue_activity_fn(request_queue_t *q, activity_fn *fn, void *data)
131{
132 q->activity_fn = fn;
133 q->activity_data = data;
134}
135EXPORT_SYMBOL(blk_queue_activity_fn);
136
137/** 132/**
138 * blk_queue_prep_rq - set a prepare_request function for queue 133 * blk_queue_prep_rq - set a prepare_request function for queue
139 * @q: queue 134 * @q: queue
@@ -236,8 +231,6 @@ void blk_queue_make_request(request_queue_t * q, make_request_fn * mfn)
236 * by default assume old behaviour and bounce for any highmem page 231 * by default assume old behaviour and bounce for any highmem page
237 */ 232 */
238 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH); 233 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH);
239
240 blk_queue_activity_fn(q, NULL, NULL);
241} 234}
242 235
243EXPORT_SYMBOL(blk_queue_make_request); 236EXPORT_SYMBOL(blk_queue_make_request);
@@ -2694,9 +2687,6 @@ static inline void add_request(request_queue_t * q, struct request * req)
2694{ 2687{
2695 drive_stat_acct(req, req->nr_sectors, 1); 2688 drive_stat_acct(req, req->nr_sectors, 1);
2696 2689
2697 if (q->activity_fn)
2698 q->activity_fn(q->activity_data, rq_data_dir(req));
2699
2700 /* 2690 /*
2701 * elevator indicated where it wants this request to be 2691 * elevator indicated where it wants this request to be
2702 * inserted at elevator_merge time 2692 * inserted at elevator_merge time
@@ -3056,6 +3046,42 @@ static void handle_bad_sector(struct bio *bio)
3056 set_bit(BIO_EOF, &bio->bi_flags); 3046 set_bit(BIO_EOF, &bio->bi_flags);
3057} 3047}
3058 3048
3049#ifdef CONFIG_FAIL_MAKE_REQUEST
3050
3051static DECLARE_FAULT_ATTR(fail_make_request);
3052
3053static int __init setup_fail_make_request(char *str)
3054{
3055 return setup_fault_attr(&fail_make_request, str);
3056}
3057__setup("fail_make_request=", setup_fail_make_request);
3058
3059static int should_fail_request(struct bio *bio)
3060{
3061 if ((bio->bi_bdev->bd_disk->flags & GENHD_FL_FAIL) ||
3062 (bio->bi_bdev->bd_part && bio->bi_bdev->bd_part->make_it_fail))
3063 return should_fail(&fail_make_request, bio->bi_size);
3064
3065 return 0;
3066}
3067
3068static int __init fail_make_request_debugfs(void)
3069{
3070 return init_fault_attr_dentries(&fail_make_request,
3071 "fail_make_request");
3072}
3073
3074late_initcall(fail_make_request_debugfs);
3075
3076#else /* CONFIG_FAIL_MAKE_REQUEST */
3077
3078static inline int should_fail_request(struct bio *bio)
3079{
3080 return 0;
3081}
3082
3083#endif /* CONFIG_FAIL_MAKE_REQUEST */
3084
3059/** 3085/**
3060 * generic_make_request: hand a buffer to its device driver for I/O 3086 * generic_make_request: hand a buffer to its device driver for I/O
3061 * @bio: The bio describing the location in memory and on the device. 3087 * @bio: The bio describing the location in memory and on the device.
@@ -3141,6 +3167,9 @@ end_io:
3141 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags))) 3167 if (unlikely(test_bit(QUEUE_FLAG_DEAD, &q->queue_flags)))
3142 goto end_io; 3168 goto end_io;
3143 3169
3170 if (should_fail_request(bio))
3171 goto end_io;
3172
3144 /* 3173 /*
3145 * If this device has partitions, remap block n 3174 * If this device has partitions, remap block n
3146 * of partition p to block n+start(p) of the disk. 3175 * of partition p to block n+start(p) of the disk.
@@ -3195,10 +3224,12 @@ void submit_bio(int rw, struct bio *bio)
3195 BIO_BUG_ON(!bio->bi_size); 3224 BIO_BUG_ON(!bio->bi_size);
3196 BIO_BUG_ON(!bio->bi_io_vec); 3225 BIO_BUG_ON(!bio->bi_io_vec);
3197 bio->bi_rw |= rw; 3226 bio->bi_rw |= rw;
3198 if (rw & WRITE) 3227 if (rw & WRITE) {
3199 count_vm_events(PGPGOUT, count); 3228 count_vm_events(PGPGOUT, count);
3200 else 3229 } else {
3230 task_io_account_read(bio->bi_size);
3201 count_vm_events(PGPGIN, count); 3231 count_vm_events(PGPGIN, count);
3232 }
3202 3233
3203 if (unlikely(block_dump)) { 3234 if (unlikely(block_dump)) {
3204 char b[BDEVNAME_SIZE]; 3235 char b[BDEVNAME_SIZE];
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index b3e210723a71..f322b6a441d8 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -228,6 +228,7 @@ static int sg_io(struct file *file, request_queue_t *q,
228 struct request *rq; 228 struct request *rq;
229 char sense[SCSI_SENSE_BUFFERSIZE]; 229 char sense[SCSI_SENSE_BUFFERSIZE];
230 unsigned char cmd[BLK_MAX_CDB]; 230 unsigned char cmd[BLK_MAX_CDB];
231 struct bio *bio;
231 232
232 if (hdr->interface_id != 'S') 233 if (hdr->interface_id != 'S')
233 return -EINVAL; 234 return -EINVAL;
@@ -270,13 +271,6 @@ static int sg_io(struct file *file, request_queue_t *q,
270 271
271 rq->cmd_type = REQ_TYPE_BLOCK_PC; 272 rq->cmd_type = REQ_TYPE_BLOCK_PC;
272 273
273 /*
274 * bounce this after holding a reference to the original bio, it's
275 * needed for proper unmapping
276 */
277 if (rq->bio)
278 blk_queue_bounce(q, &rq->bio);
279
280 rq->timeout = jiffies_to_msecs(hdr->timeout); 274 rq->timeout = jiffies_to_msecs(hdr->timeout);
281 if (!rq->timeout) 275 if (!rq->timeout)
282 rq->timeout = q->sg_timeout; 276 rq->timeout = q->sg_timeout;
@@ -308,6 +302,7 @@ static int sg_io(struct file *file, request_queue_t *q,
308 if (ret) 302 if (ret)
309 goto out; 303 goto out;
310 304
305 bio = rq->bio;
311 rq->retries = 0; 306 rq->retries = 0;
312 307
313 start_time = jiffies; 308 start_time = jiffies;
@@ -338,6 +333,7 @@ static int sg_io(struct file *file, request_queue_t *q,
338 hdr->sb_len_wr = len; 333 hdr->sb_len_wr = len;
339 } 334 }
340 335
336 rq->bio = bio;
341 if (blk_rq_unmap_user(rq)) 337 if (blk_rq_unmap_user(rq))
342 ret = -EFAULT; 338 ret = -EFAULT;
343 339
diff --git a/crypto/sha512.c b/crypto/sha512.c
index 2dfe7f170b48..15eab9db9be4 100644
--- a/crypto/sha512.c
+++ b/crypto/sha512.c
@@ -24,7 +24,7 @@
24 24
25#define SHA384_DIGEST_SIZE 48 25#define SHA384_DIGEST_SIZE 48
26#define SHA512_DIGEST_SIZE 64 26#define SHA512_DIGEST_SIZE 64
27#define SHA384_HMAC_BLOCK_SIZE 96 27#define SHA384_HMAC_BLOCK_SIZE 128
28#define SHA512_HMAC_BLOCK_SIZE 128 28#define SHA512_HMAC_BLOCK_SIZE 128
29 29
30struct sha512_ctx { 30struct sha512_ctx {
diff --git a/drivers/Kconfig b/drivers/Kconfig
index f39463418904..e7da9fa724ec 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -64,6 +64,8 @@ source "drivers/video/Kconfig"
64 64
65source "sound/Kconfig" 65source "sound/Kconfig"
66 66
67source "drivers/hid/Kconfig"
68
67source "drivers/usb/Kconfig" 69source "drivers/usb/Kconfig"
68 70
69source "drivers/mmc/Kconfig" 71source "drivers/mmc/Kconfig"
@@ -78,4 +80,6 @@ source "drivers/rtc/Kconfig"
78 80
79source "drivers/dma/Kconfig" 81source "drivers/dma/Kconfig"
80 82
83source "drivers/kvm/Kconfig"
84
81endmenu 85endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index 67711770b1d9..0dd96d1afd39 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_SPI) += spi/
43obj-$(CONFIG_PCCARD) += pcmcia/ 43obj-$(CONFIG_PCCARD) += pcmcia/
44obj-$(CONFIG_DIO) += dio/ 44obj-$(CONFIG_DIO) += dio/
45obj-$(CONFIG_SBUS) += sbus/ 45obj-$(CONFIG_SBUS) += sbus/
46obj-$(CONFIG_KVM) += kvm/
46obj-$(CONFIG_ZORRO) += zorro/ 47obj-$(CONFIG_ZORRO) += zorro/
47obj-$(CONFIG_MAC) += macintosh/ 48obj-$(CONFIG_MAC) += macintosh/
48obj-$(CONFIG_ATA_OVER_ETH) += block/aoe/ 49obj-$(CONFIG_ATA_OVER_ETH) += block/aoe/
@@ -77,4 +78,5 @@ obj-$(CONFIG_CRYPTO) += crypto/
77obj-$(CONFIG_SUPERH) += sh/ 78obj-$(CONFIG_SUPERH) += sh/
78obj-$(CONFIG_GENERIC_TIME) += clocksource/ 79obj-$(CONFIG_GENERIC_TIME) += clocksource/
79obj-$(CONFIG_DMA_ENGINE) += dma/ 80obj-$(CONFIG_DMA_ENGINE) += dma/
81obj-$(CONFIG_HID) += hid/
80obj-$(CONFIG_PPC_PS3) += ps3/ 82obj-$(CONFIG_PPC_PS3) += ps3/
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
index bdb9c8b78ed8..9e584a7af434 100644
--- a/drivers/acorn/char/i2c.c
+++ b/drivers/acorn/char/i2c.c
@@ -360,7 +360,7 @@ static int __init i2c_ioc_init(void)
360 if (ret >= 0){ 360 if (ret >= 0){
361 ret = misc_register(&rtc_dev); 361 ret = misc_register(&rtc_dev);
362 if(ret < 0) 362 if(ret < 0)
363 i2c_bit_del_bus(&ioc_ops); 363 i2c_del_adapter(&ioc_ops);
364 } 364 }
365 365
366 return ret; 366 return ret;
diff --git a/drivers/atm/.gitignore b/drivers/atm/.gitignore
index a165b7167714..fc0ae5eb05d8 100644
--- a/drivers/atm/.gitignore
+++ b/drivers/atm/.gitignore
@@ -2,4 +2,4 @@
2fore200e_mkfirm 2fore200e_mkfirm
3fore200e_pca_fw.c 3fore200e_pca_fw.c
4pca200e.bin 4pca200e.bin
5 5pca200e_ecd.bin2
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index cfa5af883e13..2ddd76fdbc43 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -242,6 +242,7 @@ config ATM_IDT77252_USE_SUNI
242config ATM_AMBASSADOR 242config ATM_AMBASSADOR
243 tristate "Madge Ambassador (Collage PCI 155 Server)" 243 tristate "Madge Ambassador (Collage PCI 155 Server)"
244 depends on PCI && ATM 244 depends on PCI && ATM
245 select BITREVERSE
245 help 246 help
246 This is a driver for ATMizer based ATM card produced by Madge 247 This is a driver for ATMizer based ATM card produced by Madge
247 Networks Ltd. Say Y (or M to compile as a module named ambassador) 248 Networks Ltd. Say Y (or M to compile as a module named ambassador)
diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
index afa7d750a593..3c372e08f77d 100644
--- a/drivers/atm/ambassador.c
+++ b/drivers/atm/ambassador.c
@@ -32,6 +32,7 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/interrupt.h> 33#include <linux/interrupt.h>
34#include <linux/poison.h> 34#include <linux/poison.h>
35#include <linux/bitrev.h>
35 36
36#include <asm/atomic.h> 37#include <asm/atomic.h>
37#include <asm/io.h> 38#include <asm/io.h>
@@ -2068,18 +2069,6 @@ static void __devinit amb_ucode_version (amb_dev * dev) {
2068 PRINTK (KERN_INFO, "microcode version is %u.%u", major, minor); 2069 PRINTK (KERN_INFO, "microcode version is %u.%u", major, minor);
2069} 2070}
2070 2071
2071// swap bits within byte to get Ethernet ordering
2072static u8 bit_swap (u8 byte)
2073{
2074 const u8 swap[] = {
2075 0x0, 0x8, 0x4, 0xc,
2076 0x2, 0xa, 0x6, 0xe,
2077 0x1, 0x9, 0x5, 0xd,
2078 0x3, 0xb, 0x7, 0xf
2079 };
2080 return ((swap[byte & 0xf]<<4) | swap[byte>>4]);
2081}
2082
2083// get end station address 2072// get end station address
2084static void __devinit amb_esi (amb_dev * dev, u8 * esi) { 2073static void __devinit amb_esi (amb_dev * dev, u8 * esi) {
2085 u32 lower4; 2074 u32 lower4;
@@ -2101,9 +2090,9 @@ static void __devinit amb_esi (amb_dev * dev, u8 * esi) {
2101 PRINTDB (DBG_INIT, "ESI:"); 2090 PRINTDB (DBG_INIT, "ESI:");
2102 for (i = 0; i < ESI_LEN; ++i) { 2091 for (i = 0; i < ESI_LEN; ++i) {
2103 if (i < 4) 2092 if (i < 4)
2104 esi[i] = bit_swap (lower4>>(8*i)); 2093 esi[i] = bitrev8(lower4>>(8*i));
2105 else 2094 else
2106 esi[i] = bit_swap (upper2>>(8*(i-4))); 2095 esi[i] = bitrev8(upper2>>(8*(i-4)));
2107 PRINTDM (DBG_INIT, " %02x", esi[i]); 2096 PRINTDM (DBG_INIT, " %02x", esi[i]);
2108 } 2097 }
2109 2098
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 85072446d772..ce9cfcb6071c 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -431,14 +431,18 @@ config CDROM_PKTCDVD
431 tristate "Packet writing on CD/DVD media" 431 tristate "Packet writing on CD/DVD media"
432 depends on !UML 432 depends on !UML
433 help 433 help
434 If you have a CDROM drive that supports packet writing, say Y to 434 If you have a CDROM/DVD drive that supports packet writing, say
435 include preliminary support. It should work with any MMC/Mt Fuji 435 Y to include support. It should work with any MMC/Mt Fuji
436 compliant ATAPI or SCSI drive, which is just about any newer CD 436 compliant ATAPI or SCSI drive, which is just about any newer
437 writer. 437 DVD/CD writer.
438 438
439 Currently only writing to CD-RW, DVD-RW and DVD+RW discs is possible. 439 Currently only writing to CD-RW, DVD-RW, DVD+RW and DVDRAM discs
440 is possible.
440 DVD-RW disks must be in restricted overwrite mode. 441 DVD-RW disks must be in restricted overwrite mode.
441 442
443 See the file <file:Documentation/cdrom/packet-writing.txt>
444 for further information on the use of this driver.
445
442 To compile this driver as a module, choose M here: the 446 To compile this driver as a module, choose M here: the
443 module will be called pktcdvd. 447 module will be called pktcdvd.
444 448
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
index 8e41c87b026e..e04be94d195c 100644
--- a/drivers/block/acsi_slm.c
+++ b/drivers/block/acsi_slm.c
@@ -363,7 +363,7 @@ static ssize_t slm_read( struct file *file, char *buf, size_t count,
363 loff_t *ppos ) 363 loff_t *ppos )
364 364
365{ 365{
366 struct inode *node = file->f_dentry->d_inode; 366 struct inode *node = file->f_path.dentry->d_inode;
367 unsigned long page; 367 unsigned long page;
368 int length; 368 int length;
369 int end; 369 int end;
@@ -618,7 +618,7 @@ static ssize_t slm_write( struct file *file, const char *buf, size_t count,
618 loff_t *ppos ) 618 loff_t *ppos )
619 619
620{ 620{
621 struct inode *node = file->f_dentry->d_inode; 621 struct inode *node = file->f_path.dentry->d_inode;
622 int device = iminor(node); 622 int device = iminor(node);
623 int n, filled, w, h; 623 int n, filled, w, h;
624 624
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 892e092afe9a..ee159edb6b88 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -535,7 +535,7 @@ static int do_ioctl(struct file *f, unsigned cmd, unsigned long arg)
535{ 535{
536 int ret; 536 int ret;
537 lock_kernel(); 537 lock_kernel();
538 ret = cciss_ioctl(f->f_dentry->d_inode, f, cmd, arg); 538 ret = cciss_ioctl(f->f_path.dentry->d_inode, f, cmd, arg);
539 unlock_kernel(); 539 unlock_kernel();
540 return ret; 540 return ret;
541} 541}
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index beab6d2643cb..6b5b64207407 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -1000,7 +1000,7 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info)
1000 1000
1001 if (lo->lo_state != Lo_bound) 1001 if (lo->lo_state != Lo_bound)
1002 return -ENXIO; 1002 return -ENXIO;
1003 error = vfs_getattr(file->f_vfsmnt, file->f_dentry, &stat); 1003 error = vfs_getattr(file->f_path.mnt, file->f_path.dentry, &stat);
1004 if (error) 1004 if (error)
1005 return error; 1005 return error;
1006 memset(info, 0, sizeof(*info)); 1006 memset(info, 0, sizeof(*info));
@@ -1287,7 +1287,7 @@ loop_get_status_compat(struct loop_device *lo,
1287 1287
1288static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1288static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1289{ 1289{
1290 struct inode *inode = file->f_dentry->d_inode; 1290 struct inode *inode = file->f_path.dentry->d_inode;
1291 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1291 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1292 int err; 1292 int err;
1293 1293
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 7bf2cfbd6285..090796bef78f 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -537,7 +537,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
537 error = -EINVAL; 537 error = -EINVAL;
538 file = fget(arg); 538 file = fget(arg);
539 if (file) { 539 if (file) {
540 inode = file->f_dentry->d_inode; 540 inode = file->f_path.dentry->d_inode;
541 if (S_ISSOCK(inode->i_mode)) { 541 if (S_ISSOCK(inode->i_mode)) {
542 lo->file = file; 542 lo->file = file;
543 lo->sock = SOCKET_I(inode); 543 lo->sock = SOCKET_I(inode);
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index e45eaa264119..7c95c762950f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (C) 2000 Jens Axboe <axboe@suse.de> 2 * Copyright (C) 2000 Jens Axboe <axboe@suse.de>
3 * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com> 3 * Copyright (C) 2001-2004 Peter Osterlund <petero2@telia.com>
4 * Copyright (C) 2006 Thomas Maier <balagi@justmail.de>
4 * 5 *
5 * May be copied or modified under the terms of the GNU General Public 6 * May be copied or modified under the terms of the GNU General Public
6 * License. See linux/COPYING for more information. 7 * License. See linux/COPYING for more information.
@@ -59,6 +60,8 @@
59#include <scsi/scsi_cmnd.h> 60#include <scsi/scsi_cmnd.h>
60#include <scsi/scsi_ioctl.h> 61#include <scsi/scsi_ioctl.h>
61#include <scsi/scsi.h> 62#include <scsi/scsi.h>
63#include <linux/debugfs.h>
64#include <linux/device.h>
62 65
63#include <asm/uaccess.h> 66#include <asm/uaccess.h>
64 67
@@ -83,9 +86,424 @@
83static struct pktcdvd_device *pkt_devs[MAX_WRITERS]; 86static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
84static struct proc_dir_entry *pkt_proc; 87static struct proc_dir_entry *pkt_proc;
85static int pktdev_major; 88static int pktdev_major;
89static int write_congestion_on = PKT_WRITE_CONGESTION_ON;
90static int write_congestion_off = PKT_WRITE_CONGESTION_OFF;
86static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */ 91static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */
87static mempool_t *psd_pool; 92static mempool_t *psd_pool;
88 93
94static struct class *class_pktcdvd = NULL; /* /sys/class/pktcdvd */
95static struct dentry *pkt_debugfs_root = NULL; /* /debug/pktcdvd */
96
97/* forward declaration */
98static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev);
99static int pkt_remove_dev(dev_t pkt_dev);
100static int pkt_seq_show(struct seq_file *m, void *p);
101
102
103
104/*
105 * create and register a pktcdvd kernel object.
106 */
107static struct pktcdvd_kobj* pkt_kobj_create(struct pktcdvd_device *pd,
108 const char* name,
109 struct kobject* parent,
110 struct kobj_type* ktype)
111{
112 struct pktcdvd_kobj *p;
113 p = kzalloc(sizeof(*p), GFP_KERNEL);
114 if (!p)
115 return NULL;
116 kobject_set_name(&p->kobj, "%s", name);
117 p->kobj.parent = parent;
118 p->kobj.ktype = ktype;
119 p->pd = pd;
120 if (kobject_register(&p->kobj) != 0)
121 return NULL;
122 return p;
123}
124/*
125 * remove a pktcdvd kernel object.
126 */
127static void pkt_kobj_remove(struct pktcdvd_kobj *p)
128{
129 if (p)
130 kobject_unregister(&p->kobj);
131}
132/*
133 * default release function for pktcdvd kernel objects.
134 */
135static void pkt_kobj_release(struct kobject *kobj)
136{
137 kfree(to_pktcdvdkobj(kobj));
138}
139
140
141/**********************************************************
142 *
143 * sysfs interface for pktcdvd
144 * by (C) 2006 Thomas Maier <balagi@justmail.de>
145 *
146 **********************************************************/
147
148#define DEF_ATTR(_obj,_name,_mode) \
149 static struct attribute _obj = { \
150 .name = _name, .owner = THIS_MODULE, .mode = _mode }
151
152/**********************************************************
153 /sys/class/pktcdvd/pktcdvd[0-7]/
154 stat/reset
155 stat/packets_started
156 stat/packets_finished
157 stat/kb_written
158 stat/kb_read
159 stat/kb_read_gather
160 write_queue/size
161 write_queue/congestion_off
162 write_queue/congestion_on
163 **********************************************************/
164
165DEF_ATTR(kobj_pkt_attr_st1, "reset", 0200);
166DEF_ATTR(kobj_pkt_attr_st2, "packets_started", 0444);
167DEF_ATTR(kobj_pkt_attr_st3, "packets_finished", 0444);
168DEF_ATTR(kobj_pkt_attr_st4, "kb_written", 0444);
169DEF_ATTR(kobj_pkt_attr_st5, "kb_read", 0444);
170DEF_ATTR(kobj_pkt_attr_st6, "kb_read_gather", 0444);
171
172static struct attribute *kobj_pkt_attrs_stat[] = {
173 &kobj_pkt_attr_st1,
174 &kobj_pkt_attr_st2,
175 &kobj_pkt_attr_st3,
176 &kobj_pkt_attr_st4,
177 &kobj_pkt_attr_st5,
178 &kobj_pkt_attr_st6,
179 NULL
180};
181
182DEF_ATTR(kobj_pkt_attr_wq1, "size", 0444);
183DEF_ATTR(kobj_pkt_attr_wq2, "congestion_off", 0644);
184DEF_ATTR(kobj_pkt_attr_wq3, "congestion_on", 0644);
185
186static struct attribute *kobj_pkt_attrs_wqueue[] = {
187 &kobj_pkt_attr_wq1,
188 &kobj_pkt_attr_wq2,
189 &kobj_pkt_attr_wq3,
190 NULL
191};
192
193/* declares a char buffer[64] _dbuf, copies data from
194 * _b with length _l into it and ensures that _dbuf ends
195 * with a \0 character.
196 */
197#define DECLARE_BUF_AS_STRING(_dbuf, _b, _l) \
198 char _dbuf[64]; int dlen = (_l) < 0 ? 0 : (_l); \
199 if (dlen >= sizeof(_dbuf)) dlen = sizeof(_dbuf)-1; \
200 memcpy(_dbuf, _b, dlen); _dbuf[dlen] = 0
201
202static ssize_t kobj_pkt_show(struct kobject *kobj,
203 struct attribute *attr, char *data)
204{
205 struct pktcdvd_device *pd = to_pktcdvdkobj(kobj)->pd;
206 int n = 0;
207 int v;
208 if (strcmp(attr->name, "packets_started") == 0) {
209 n = sprintf(data, "%lu\n", pd->stats.pkt_started);
210
211 } else if (strcmp(attr->name, "packets_finished") == 0) {
212 n = sprintf(data, "%lu\n", pd->stats.pkt_ended);
213
214 } else if (strcmp(attr->name, "kb_written") == 0) {
215 n = sprintf(data, "%lu\n", pd->stats.secs_w >> 1);
216
217 } else if (strcmp(attr->name, "kb_read") == 0) {
218 n = sprintf(data, "%lu\n", pd->stats.secs_r >> 1);
219
220 } else if (strcmp(attr->name, "kb_read_gather") == 0) {
221 n = sprintf(data, "%lu\n", pd->stats.secs_rg >> 1);
222
223 } else if (strcmp(attr->name, "size") == 0) {
224 spin_lock(&pd->lock);
225 v = pd->bio_queue_size;
226 spin_unlock(&pd->lock);
227 n = sprintf(data, "%d\n", v);
228
229 } else if (strcmp(attr->name, "congestion_off") == 0) {
230 spin_lock(&pd->lock);
231 v = pd->write_congestion_off;
232 spin_unlock(&pd->lock);
233 n = sprintf(data, "%d\n", v);
234
235 } else if (strcmp(attr->name, "congestion_on") == 0) {
236 spin_lock(&pd->lock);
237 v = pd->write_congestion_on;
238 spin_unlock(&pd->lock);
239 n = sprintf(data, "%d\n", v);
240 }
241 return n;
242}
243
244static void init_write_congestion_marks(int* lo, int* hi)
245{
246 if (*hi > 0) {
247 *hi = max(*hi, 500);
248 *hi = min(*hi, 1000000);
249 if (*lo <= 0)
250 *lo = *hi - 100;
251 else {
252 *lo = min(*lo, *hi - 100);
253 *lo = max(*lo, 100);
254 }
255 } else {
256 *hi = -1;
257 *lo = -1;
258 }
259}
260
261static ssize_t kobj_pkt_store(struct kobject *kobj,
262 struct attribute *attr,
263 const char *data, size_t len)
264{
265 struct pktcdvd_device *pd = to_pktcdvdkobj(kobj)->pd;
266 int val;
267 DECLARE_BUF_AS_STRING(dbuf, data, len); /* ensure sscanf scans a string */
268
269 if (strcmp(attr->name, "reset") == 0 && dlen > 0) {
270 pd->stats.pkt_started = 0;
271 pd->stats.pkt_ended = 0;
272 pd->stats.secs_w = 0;
273 pd->stats.secs_rg = 0;
274 pd->stats.secs_r = 0;
275
276 } else if (strcmp(attr->name, "congestion_off") == 0
277 && sscanf(dbuf, "%d", &val) == 1) {
278 spin_lock(&pd->lock);
279 pd->write_congestion_off = val;
280 init_write_congestion_marks(&pd->write_congestion_off,
281 &pd->write_congestion_on);
282 spin_unlock(&pd->lock);
283
284 } else if (strcmp(attr->name, "congestion_on") == 0
285 && sscanf(dbuf, "%d", &val) == 1) {
286 spin_lock(&pd->lock);
287 pd->write_congestion_on = val;
288 init_write_congestion_marks(&pd->write_congestion_off,
289 &pd->write_congestion_on);
290 spin_unlock(&pd->lock);
291 }
292 return len;
293}
294
295static struct sysfs_ops kobj_pkt_ops = {
296 .show = kobj_pkt_show,
297 .store = kobj_pkt_store
298};
299static struct kobj_type kobj_pkt_type_stat = {
300 .release = pkt_kobj_release,
301 .sysfs_ops = &kobj_pkt_ops,
302 .default_attrs = kobj_pkt_attrs_stat
303};
304static struct kobj_type kobj_pkt_type_wqueue = {
305 .release = pkt_kobj_release,
306 .sysfs_ops = &kobj_pkt_ops,
307 .default_attrs = kobj_pkt_attrs_wqueue
308};
309
310static void pkt_sysfs_dev_new(struct pktcdvd_device *pd)
311{
312 if (class_pktcdvd) {
313 pd->clsdev = class_device_create(class_pktcdvd,
314 NULL, pd->pkt_dev,
315 NULL, "%s", pd->name);
316 if (IS_ERR(pd->clsdev))
317 pd->clsdev = NULL;
318 }
319 if (pd->clsdev) {
320 pd->kobj_stat = pkt_kobj_create(pd, "stat",
321 &pd->clsdev->kobj,
322 &kobj_pkt_type_stat);
323 pd->kobj_wqueue = pkt_kobj_create(pd, "write_queue",
324 &pd->clsdev->kobj,
325 &kobj_pkt_type_wqueue);
326 }
327}
328
329static void pkt_sysfs_dev_remove(struct pktcdvd_device *pd)
330{
331 pkt_kobj_remove(pd->kobj_stat);
332 pkt_kobj_remove(pd->kobj_wqueue);
333 if (class_pktcdvd)
334 class_device_destroy(class_pktcdvd, pd->pkt_dev);
335}
336
337
338/********************************************************************
339 /sys/class/pktcdvd/
340 add map block device
341 remove unmap packet dev
342 device_map show mappings
343 *******************************************************************/
344
345static void class_pktcdvd_release(struct class *cls)
346{
347 kfree(cls);
348}
349static ssize_t class_pktcdvd_show_map(struct class *c, char *data)
350{
351 int n = 0;
352 int idx;
353 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
354 for (idx = 0; idx < MAX_WRITERS; idx++) {
355 struct pktcdvd_device *pd = pkt_devs[idx];
356 if (!pd)
357 continue;
358 n += sprintf(data+n, "%s %u:%u %u:%u\n",
359 pd->name,
360 MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev),
361 MAJOR(pd->bdev->bd_dev),
362 MINOR(pd->bdev->bd_dev));
363 }
364 mutex_unlock(&ctl_mutex);
365 return n;
366}
367
368static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
369 size_t count)
370{
371 unsigned int major, minor;
372 DECLARE_BUF_AS_STRING(dbuf, buf, count);
373 if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
374 pkt_setup_dev(MKDEV(major, minor), NULL);
375 return count;
376 }
377 return -EINVAL;
378}
379
380static ssize_t class_pktcdvd_store_remove(struct class *c, const char *buf,
381 size_t count)
382{
383 unsigned int major, minor;
384 DECLARE_BUF_AS_STRING(dbuf, buf, count);
385 if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
386 pkt_remove_dev(MKDEV(major, minor));
387 return count;
388 }
389 return -EINVAL;
390}
391
392static struct class_attribute class_pktcdvd_attrs[] = {
393 __ATTR(add, 0200, NULL, class_pktcdvd_store_add),
394 __ATTR(remove, 0200, NULL, class_pktcdvd_store_remove),
395 __ATTR(device_map, 0444, class_pktcdvd_show_map, NULL),
396 __ATTR_NULL
397};
398
399
400static int pkt_sysfs_init(void)
401{
402 int ret = 0;
403
404 /*
405 * create control files in sysfs
406 * /sys/class/pktcdvd/...
407 */
408 class_pktcdvd = kzalloc(sizeof(*class_pktcdvd), GFP_KERNEL);
409 if (!class_pktcdvd)
410 return -ENOMEM;
411 class_pktcdvd->name = DRIVER_NAME;
412 class_pktcdvd->owner = THIS_MODULE;
413 class_pktcdvd->class_release = class_pktcdvd_release;
414 class_pktcdvd->class_attrs = class_pktcdvd_attrs;
415 ret = class_register(class_pktcdvd);
416 if (ret) {
417 kfree(class_pktcdvd);
418 class_pktcdvd = NULL;
419 printk(DRIVER_NAME": failed to create class pktcdvd\n");
420 return ret;
421 }
422 return 0;
423}
424
425static void pkt_sysfs_cleanup(void)
426{
427 if (class_pktcdvd)
428 class_destroy(class_pktcdvd);
429 class_pktcdvd = NULL;
430}
431
432/********************************************************************
433 entries in debugfs
434
435 /debugfs/pktcdvd[0-7]/
436 info
437
438 *******************************************************************/
439
440static int pkt_debugfs_seq_show(struct seq_file *m, void *p)
441{
442 return pkt_seq_show(m, p);
443}
444
445static int pkt_debugfs_fops_open(struct inode *inode, struct file *file)
446{
447 return single_open(file, pkt_debugfs_seq_show, inode->i_private);
448}
449
450static struct file_operations debug_fops = {
451 .open = pkt_debugfs_fops_open,
452 .read = seq_read,
453 .llseek = seq_lseek,
454 .release = single_release,
455 .owner = THIS_MODULE,
456};
457
458static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
459{
460 if (!pkt_debugfs_root)
461 return;
462 pd->dfs_f_info = NULL;
463 pd->dfs_d_root = debugfs_create_dir(pd->name, pkt_debugfs_root);
464 if (IS_ERR(pd->dfs_d_root)) {
465 pd->dfs_d_root = NULL;
466 return;
467 }
468 pd->dfs_f_info = debugfs_create_file("info", S_IRUGO,
469 pd->dfs_d_root, pd, &debug_fops);
470 if (IS_ERR(pd->dfs_f_info)) {
471 pd->dfs_f_info = NULL;
472 return;
473 }
474}
475
476static void pkt_debugfs_dev_remove(struct pktcdvd_device *pd)
477{
478 if (!pkt_debugfs_root)
479 return;
480 if (pd->dfs_f_info)
481 debugfs_remove(pd->dfs_f_info);
482 pd->dfs_f_info = NULL;
483 if (pd->dfs_d_root)
484 debugfs_remove(pd->dfs_d_root);
485 pd->dfs_d_root = NULL;
486}
487
488static void pkt_debugfs_init(void)
489{
490 pkt_debugfs_root = debugfs_create_dir(DRIVER_NAME, NULL);
491 if (IS_ERR(pkt_debugfs_root)) {
492 pkt_debugfs_root = NULL;
493 return;
494 }
495}
496
497static void pkt_debugfs_cleanup(void)
498{
499 if (!pkt_debugfs_root)
500 return;
501 debugfs_remove(pkt_debugfs_root);
502 pkt_debugfs_root = NULL;
503}
504
505/* ----------------------------------------------------------*/
506
89 507
90static void pkt_bio_finished(struct pktcdvd_device *pd) 508static void pkt_bio_finished(struct pktcdvd_device *pd)
91{ 509{
@@ -893,6 +1311,7 @@ static int pkt_handle_queue(struct pktcdvd_device *pd)
893 sector_t zone = 0; /* Suppress gcc warning */ 1311 sector_t zone = 0; /* Suppress gcc warning */
894 struct pkt_rb_node *node, *first_node; 1312 struct pkt_rb_node *node, *first_node;
895 struct rb_node *n; 1313 struct rb_node *n;
1314 int wakeup;
896 1315
897 VPRINTK("handle_queue\n"); 1316 VPRINTK("handle_queue\n");
898 1317
@@ -965,7 +1384,13 @@ try_next_bio:
965 pkt->write_size += bio->bi_size / CD_FRAMESIZE; 1384 pkt->write_size += bio->bi_size / CD_FRAMESIZE;
966 spin_unlock(&pkt->lock); 1385 spin_unlock(&pkt->lock);
967 } 1386 }
1387 /* check write congestion marks, and if bio_queue_size is
1388 below, wake up any waiters */
1389 wakeup = (pd->write_congestion_on > 0
1390 && pd->bio_queue_size <= pd->write_congestion_off);
968 spin_unlock(&pd->lock); 1391 spin_unlock(&pd->lock);
1392 if (wakeup)
1393 blk_clear_queue_congested(pd->disk->queue, WRITE);
969 1394
970 pkt->sleep_time = max(PACKET_WAIT_TIME, 1); 1395 pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
971 pkt_set_state(pkt, PACKET_WAITING_STATE); 1396 pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2178,6 +2603,23 @@ static int pkt_make_request(request_queue_t *q, struct bio *bio)
2178 } 2603 }
2179 spin_unlock(&pd->cdrw.active_list_lock); 2604 spin_unlock(&pd->cdrw.active_list_lock);
2180 2605
2606 /*
2607 * Test if there is enough room left in the bio work queue
2608 * (queue size >= congestion on mark).
2609 * If not, wait till the work queue size is below the congestion off mark.
2610 */
2611 spin_lock(&pd->lock);
2612 if (pd->write_congestion_on > 0
2613 && pd->bio_queue_size >= pd->write_congestion_on) {
2614 blk_set_queue_congested(q, WRITE);
2615 do {
2616 spin_unlock(&pd->lock);
2617 congestion_wait(WRITE, HZ);
2618 spin_lock(&pd->lock);
2619 } while(pd->bio_queue_size > pd->write_congestion_off);
2620 }
2621 spin_unlock(&pd->lock);
2622
2181 /* 2623 /*
2182 * No matching packet found. Store the bio in the work queue. 2624 * No matching packet found. Store the bio in the work queue.
2183 */ 2625 */
@@ -2297,6 +2739,9 @@ static int pkt_seq_show(struct seq_file *m, void *p)
2297 seq_printf(m, "\tstate:\t\t\ti:%d ow:%d rw:%d ww:%d rec:%d fin:%d\n", 2739 seq_printf(m, "\tstate:\t\t\ti:%d ow:%d rw:%d ww:%d rec:%d fin:%d\n",
2298 states[0], states[1], states[2], states[3], states[4], states[5]); 2740 states[0], states[1], states[2], states[3], states[4], states[5]);
2299 2741
2742 seq_printf(m, "\twrite congestion marks:\toff=%d on=%d\n",
2743 pd->write_congestion_off,
2744 pd->write_congestion_on);
2300 return 0; 2745 return 0;
2301} 2746}
2302 2747
@@ -2436,36 +2881,33 @@ static struct block_device_operations pktcdvd_ops = {
2436/* 2881/*
2437 * Set up mapping from pktcdvd device to CD-ROM device. 2882 * Set up mapping from pktcdvd device to CD-ROM device.
2438 */ 2883 */
2439static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd) 2884static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
2440{ 2885{
2441 int idx; 2886 int idx;
2442 int ret = -ENOMEM; 2887 int ret = -ENOMEM;
2443 struct pktcdvd_device *pd; 2888 struct pktcdvd_device *pd;
2444 struct gendisk *disk; 2889 struct gendisk *disk;
2445 dev_t dev = new_decode_dev(ctrl_cmd->dev); 2890
2891 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2446 2892
2447 for (idx = 0; idx < MAX_WRITERS; idx++) 2893 for (idx = 0; idx < MAX_WRITERS; idx++)
2448 if (!pkt_devs[idx]) 2894 if (!pkt_devs[idx])
2449 break; 2895 break;
2450 if (idx == MAX_WRITERS) { 2896 if (idx == MAX_WRITERS) {
2451 printk(DRIVER_NAME": max %d writers supported\n", MAX_WRITERS); 2897 printk(DRIVER_NAME": max %d writers supported\n", MAX_WRITERS);
2452 return -EBUSY; 2898 ret = -EBUSY;
2899 goto out_mutex;
2453 } 2900 }
2454 2901
2455 pd = kzalloc(sizeof(struct pktcdvd_device), GFP_KERNEL); 2902 pd = kzalloc(sizeof(struct pktcdvd_device), GFP_KERNEL);
2456 if (!pd) 2903 if (!pd)
2457 return ret; 2904 goto out_mutex;
2458 2905
2459 pd->rb_pool = mempool_create_kmalloc_pool(PKT_RB_POOL_SIZE, 2906 pd->rb_pool = mempool_create_kmalloc_pool(PKT_RB_POOL_SIZE,
2460 sizeof(struct pkt_rb_node)); 2907 sizeof(struct pkt_rb_node));
2461 if (!pd->rb_pool) 2908 if (!pd->rb_pool)
2462 goto out_mem; 2909 goto out_mem;
2463 2910
2464 disk = alloc_disk(1);
2465 if (!disk)
2466 goto out_mem;
2467 pd->disk = disk;
2468
2469 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list); 2911 INIT_LIST_HEAD(&pd->cdrw.pkt_free_list);
2470 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list); 2912 INIT_LIST_HEAD(&pd->cdrw.pkt_active_list);
2471 spin_lock_init(&pd->cdrw.active_list_lock); 2913 spin_lock_init(&pd->cdrw.active_list_lock);
@@ -2476,11 +2918,18 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
2476 init_waitqueue_head(&pd->wqueue); 2918 init_waitqueue_head(&pd->wqueue);
2477 pd->bio_queue = RB_ROOT; 2919 pd->bio_queue = RB_ROOT;
2478 2920
2921 pd->write_congestion_on = write_congestion_on;
2922 pd->write_congestion_off = write_congestion_off;
2923
2924 disk = alloc_disk(1);
2925 if (!disk)
2926 goto out_mem;
2927 pd->disk = disk;
2479 disk->major = pktdev_major; 2928 disk->major = pktdev_major;
2480 disk->first_minor = idx; 2929 disk->first_minor = idx;
2481 disk->fops = &pktcdvd_ops; 2930 disk->fops = &pktcdvd_ops;
2482 disk->flags = GENHD_FL_REMOVABLE; 2931 disk->flags = GENHD_FL_REMOVABLE;
2483 sprintf(disk->disk_name, DRIVER_NAME"%d", idx); 2932 strcpy(disk->disk_name, pd->name);
2484 disk->private_data = pd; 2933 disk->private_data = pd;
2485 disk->queue = blk_alloc_queue(GFP_KERNEL); 2934 disk->queue = blk_alloc_queue(GFP_KERNEL);
2486 if (!disk->queue) 2935 if (!disk->queue)
@@ -2492,8 +2941,15 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
2492 goto out_new_dev; 2941 goto out_new_dev;
2493 2942
2494 add_disk(disk); 2943 add_disk(disk);
2944
2945 pkt_sysfs_dev_new(pd);
2946 pkt_debugfs_dev_new(pd);
2947
2495 pkt_devs[idx] = pd; 2948 pkt_devs[idx] = pd;
2496 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev); 2949 if (pkt_dev)
2950 *pkt_dev = pd->pkt_dev;
2951
2952 mutex_unlock(&ctl_mutex);
2497 return 0; 2953 return 0;
2498 2954
2499out_new_dev: 2955out_new_dev:
@@ -2504,17 +2960,22 @@ out_mem:
2504 if (pd->rb_pool) 2960 if (pd->rb_pool)
2505 mempool_destroy(pd->rb_pool); 2961 mempool_destroy(pd->rb_pool);
2506 kfree(pd); 2962 kfree(pd);
2963out_mutex:
2964 mutex_unlock(&ctl_mutex);
2965 printk(DRIVER_NAME": setup of pktcdvd device failed\n");
2507 return ret; 2966 return ret;
2508} 2967}
2509 2968
2510/* 2969/*
2511 * Tear down mapping from pktcdvd device to CD-ROM device. 2970 * Tear down mapping from pktcdvd device to CD-ROM device.
2512 */ 2971 */
2513static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd) 2972static int pkt_remove_dev(dev_t pkt_dev)
2514{ 2973{
2515 struct pktcdvd_device *pd; 2974 struct pktcdvd_device *pd;
2516 int idx; 2975 int idx;
2517 dev_t pkt_dev = new_decode_dev(ctrl_cmd->pkt_dev); 2976 int ret = 0;
2977
2978 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2518 2979
2519 for (idx = 0; idx < MAX_WRITERS; idx++) { 2980 for (idx = 0; idx < MAX_WRITERS; idx++) {
2520 pd = pkt_devs[idx]; 2981 pd = pkt_devs[idx];
@@ -2523,15 +2984,22 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd)
2523 } 2984 }
2524 if (idx == MAX_WRITERS) { 2985 if (idx == MAX_WRITERS) {
2525 DPRINTK(DRIVER_NAME": dev not setup\n"); 2986 DPRINTK(DRIVER_NAME": dev not setup\n");
2526 return -ENXIO; 2987 ret = -ENXIO;
2988 goto out;
2527 } 2989 }
2528 2990
2529 if (pd->refcnt > 0) 2991 if (pd->refcnt > 0) {
2530 return -EBUSY; 2992 ret = -EBUSY;
2531 2993 goto out;
2994 }
2532 if (!IS_ERR(pd->cdrw.thread)) 2995 if (!IS_ERR(pd->cdrw.thread))
2533 kthread_stop(pd->cdrw.thread); 2996 kthread_stop(pd->cdrw.thread);
2534 2997
2998 pkt_devs[idx] = NULL;
2999
3000 pkt_debugfs_dev_remove(pd);
3001 pkt_sysfs_dev_remove(pd);
3002
2535 blkdev_put(pd->bdev); 3003 blkdev_put(pd->bdev);
2536 3004
2537 remove_proc_entry(pd->name, pkt_proc); 3005 remove_proc_entry(pd->name, pkt_proc);
@@ -2541,18 +3009,24 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd)
2541 blk_cleanup_queue(pd->disk->queue); 3009 blk_cleanup_queue(pd->disk->queue);
2542 put_disk(pd->disk); 3010 put_disk(pd->disk);
2543 3011
2544 pkt_devs[idx] = NULL;
2545 mempool_destroy(pd->rb_pool); 3012 mempool_destroy(pd->rb_pool);
2546 kfree(pd); 3013 kfree(pd);
2547 3014
2548 /* This is safe: open() is still holding a reference. */ 3015 /* This is safe: open() is still holding a reference. */
2549 module_put(THIS_MODULE); 3016 module_put(THIS_MODULE);
2550 return 0; 3017
3018out:
3019 mutex_unlock(&ctl_mutex);
3020 return ret;
2551} 3021}
2552 3022
2553static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd) 3023static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
2554{ 3024{
2555 struct pktcdvd_device *pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index); 3025 struct pktcdvd_device *pd;
3026
3027 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
3028
3029 pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index);
2556 if (pd) { 3030 if (pd) {
2557 ctrl_cmd->dev = new_encode_dev(pd->bdev->bd_dev); 3031 ctrl_cmd->dev = new_encode_dev(pd->bdev->bd_dev);
2558 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev); 3032 ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev);
@@ -2561,6 +3035,8 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd)
2561 ctrl_cmd->pkt_dev = 0; 3035 ctrl_cmd->pkt_dev = 0;
2562 } 3036 }
2563 ctrl_cmd->num_devices = MAX_WRITERS; 3037 ctrl_cmd->num_devices = MAX_WRITERS;
3038
3039 mutex_unlock(&ctl_mutex);
2564} 3040}
2565 3041
2566static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 3042static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
@@ -2568,6 +3044,7 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
2568 void __user *argp = (void __user *)arg; 3044 void __user *argp = (void __user *)arg;
2569 struct pkt_ctrl_command ctrl_cmd; 3045 struct pkt_ctrl_command ctrl_cmd;
2570 int ret = 0; 3046 int ret = 0;
3047 dev_t pkt_dev = 0;
2571 3048
2572 if (cmd != PACKET_CTRL_CMD) 3049 if (cmd != PACKET_CTRL_CMD)
2573 return -ENOTTY; 3050 return -ENOTTY;
@@ -2579,21 +3056,16 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
2579 case PKT_CTRL_CMD_SETUP: 3056 case PKT_CTRL_CMD_SETUP:
2580 if (!capable(CAP_SYS_ADMIN)) 3057 if (!capable(CAP_SYS_ADMIN))
2581 return -EPERM; 3058 return -EPERM;
2582 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 3059 ret = pkt_setup_dev(new_decode_dev(ctrl_cmd.dev), &pkt_dev);
2583 ret = pkt_setup_dev(&ctrl_cmd); 3060 ctrl_cmd.pkt_dev = new_encode_dev(pkt_dev);
2584 mutex_unlock(&ctl_mutex);
2585 break; 3061 break;
2586 case PKT_CTRL_CMD_TEARDOWN: 3062 case PKT_CTRL_CMD_TEARDOWN:
2587 if (!capable(CAP_SYS_ADMIN)) 3063 if (!capable(CAP_SYS_ADMIN))
2588 return -EPERM; 3064 return -EPERM;
2589 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); 3065 ret = pkt_remove_dev(new_decode_dev(ctrl_cmd.pkt_dev));
2590 ret = pkt_remove_dev(&ctrl_cmd);
2591 mutex_unlock(&ctl_mutex);
2592 break; 3066 break;
2593 case PKT_CTRL_CMD_STATUS: 3067 case PKT_CTRL_CMD_STATUS:
2594 mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
2595 pkt_get_status(&ctrl_cmd); 3068 pkt_get_status(&ctrl_cmd);
2596 mutex_unlock(&ctl_mutex);
2597 break; 3069 break;
2598 default: 3070 default:
2599 return -ENOTTY; 3071 return -ENOTTY;
@@ -2620,6 +3092,8 @@ static int __init pkt_init(void)
2620{ 3092{
2621 int ret; 3093 int ret;
2622 3094
3095 mutex_init(&ctl_mutex);
3096
2623 psd_pool = mempool_create_kmalloc_pool(PSD_POOL_SIZE, 3097 psd_pool = mempool_create_kmalloc_pool(PSD_POOL_SIZE,
2624 sizeof(struct packet_stacked_data)); 3098 sizeof(struct packet_stacked_data));
2625 if (!psd_pool) 3099 if (!psd_pool)
@@ -2633,18 +3107,25 @@ static int __init pkt_init(void)
2633 if (!pktdev_major) 3107 if (!pktdev_major)
2634 pktdev_major = ret; 3108 pktdev_major = ret;
2635 3109
3110 ret = pkt_sysfs_init();
3111 if (ret)
3112 goto out;
3113
3114 pkt_debugfs_init();
3115
2636 ret = misc_register(&pkt_misc); 3116 ret = misc_register(&pkt_misc);
2637 if (ret) { 3117 if (ret) {
2638 printk(DRIVER_NAME": Unable to register misc device\n"); 3118 printk(DRIVER_NAME": Unable to register misc device\n");
2639 goto out; 3119 goto out_misc;
2640 } 3120 }
2641 3121
2642 mutex_init(&ctl_mutex);
2643
2644 pkt_proc = proc_mkdir(DRIVER_NAME, proc_root_driver); 3122 pkt_proc = proc_mkdir(DRIVER_NAME, proc_root_driver);
2645 3123
2646 return 0; 3124 return 0;
2647 3125
3126out_misc:
3127 pkt_debugfs_cleanup();
3128 pkt_sysfs_cleanup();
2648out: 3129out:
2649 unregister_blkdev(pktdev_major, DRIVER_NAME); 3130 unregister_blkdev(pktdev_major, DRIVER_NAME);
2650out2: 3131out2:
@@ -2656,6 +3137,10 @@ static void __exit pkt_exit(void)
2656{ 3137{
2657 remove_proc_entry(DRIVER_NAME, proc_root_driver); 3138 remove_proc_entry(DRIVER_NAME, proc_root_driver);
2658 misc_deregister(&pkt_misc); 3139 misc_deregister(&pkt_misc);
3140
3141 pkt_debugfs_cleanup();
3142 pkt_sysfs_cleanup();
3143
2659 unregister_blkdev(pktdev_major, DRIVER_NAME); 3144 unregister_blkdev(pktdev_major, DRIVER_NAME);
2660 mempool_destroy(psd_pool); 3145 mempool_destroy(psd_pool);
2661} 3146}
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 24f922f12783..b10f4d8fdc7f 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -201,6 +201,21 @@ config MOXA_SMARTIO
201 The module will be called mxser. If you want to do that, say M 201 The module will be called mxser. If you want to do that, say M
202 here. 202 here.
203 203
204config MOXA_SMARTIO_NEW
205 tristate "Moxa SmartIO support v. 2.0 (EXPERIMENTAL)"
206 depends on SERIAL_NONSTANDARD
207 help
208 Say Y here if you have a Moxa SmartIO multiport serial card and/or
209 want to help develop a new version of this driver.
210
211 This is upgraded (1.9.1) driver from original Moxa drivers with
212 changes finally resulting in PCI probing.
213
214 Use at your own risk.
215
216 This driver can also be built as a module. The module will be called
217 mxser_new. If you want to do that, say M here.
218
204config ISI 219config ISI
205 tristate "Multi-Tech multiport card support (EXPERIMENTAL)" 220 tristate "Multi-Tech multiport card support (EXPERIMENTAL)"
206 depends on SERIAL_NONSTANDARD 221 depends on SERIAL_NONSTANDARD
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index b1fcdab90947..fc110637ced6 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_MOXA_INTELLIO) += moxa.o
31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o 31obj-$(CONFIG_A2232) += ser_a2232.o generic_serial.o
32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o 32obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o 33obj-$(CONFIG_MOXA_SMARTIO) += mxser.o
34obj-$(CONFIG_MOXA_SMARTIO_NEW) += mxser_new.o
34obj-$(CONFIG_COMPUTONE) += ip2/ 35obj-$(CONFIG_COMPUTONE) += ip2/
35obj-$(CONFIG_RISCOM8) += riscom8.o 36obj-$(CONFIG_RISCOM8) += riscom8.o
36obj-$(CONFIG_ISI) += isicom.o 37obj-$(CONFIG_ISI) += isicom.o
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 66086fa2d59a..feb4ac802a0d 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -104,7 +104,7 @@ static struct async_struct *IRQ_ports;
104 104
105static unsigned char current_ctl_bits; 105static unsigned char current_ctl_bits;
106 106
107static void change_speed(struct async_struct *info, struct termios *old); 107static void change_speed(struct async_struct *info, struct ktermios *old);
108static void rs_wait_until_sent(struct tty_struct *tty, int timeout); 108static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
109 109
110 110
@@ -694,7 +694,7 @@ static void shutdown(struct async_struct * info)
694 * the specified baud rate for a serial port. 694 * the specified baud rate for a serial port.
695 */ 695 */
696static void change_speed(struct async_struct *info, 696static void change_speed(struct async_struct *info,
697 struct termios *old_termios) 697 struct ktermios *old_termios)
698{ 698{
699 int quot = 0, baud_base, baud; 699 int quot = 0, baud_base, baud;
700 unsigned cflag, cval = 0; 700 unsigned cflag, cval = 0;
@@ -1365,7 +1365,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1365 return 0; 1365 return 0;
1366} 1366}
1367 1367
1368static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1368static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1369{ 1369{
1370 struct async_struct *info = (struct async_struct *)tty->driver_data; 1370 struct async_struct *info = (struct async_struct *)tty->driver_data;
1371 unsigned long flags; 1371 unsigned long flags;
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index 8ce3f34cfc22..c02d9e99e050 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -82,7 +82,7 @@ static inline u32 cs5535_lowhigh_base(int reg)
82static ssize_t cs5535_gpio_write(struct file *file, const char __user *data, 82static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
83 size_t len, loff_t *ppos) 83 size_t len, loff_t *ppos)
84{ 84{
85 u32 m = iminor(file->f_dentry->d_inode); 85 u32 m = iminor(file->f_path.dentry->d_inode);
86 int i, j; 86 int i, j;
87 u32 base = gpio_base + cs5535_lowhigh_base(m); 87 u32 base = gpio_base + cs5535_lowhigh_base(m);
88 u32 m0, m1; 88 u32 m0, m1;
@@ -117,7 +117,7 @@ static ssize_t cs5535_gpio_write(struct file *file, const char __user *data,
117static ssize_t cs5535_gpio_read(struct file *file, char __user *buf, 117static ssize_t cs5535_gpio_read(struct file *file, char __user *buf,
118 size_t len, loff_t *ppos) 118 size_t len, loff_t *ppos)
119{ 119{
120 u32 m = iminor(file->f_dentry->d_inode); 120 u32 m = iminor(file->f_path.dentry->d_inode);
121 u32 base = gpio_base + cs5535_lowhigh_base(m); 121 u32 base = gpio_base + cs5535_lowhigh_base(m);
122 int rd_bit = 1 << (m & 0x0f); 122 int rd_bit = 1 << (m & 0x0f);
123 int i; 123 int i;
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index acb2de5e3a98..3ffa0807754c 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -1,8 +1,6 @@
1#undef BLOCKMOVE 1#undef BLOCKMOVE
2#define Z_WAKE 2#define Z_WAKE
3#undef Z_EXT_CHARS_IN_BUFFER 3#undef Z_EXT_CHARS_IN_BUFFER
4static char rcsid[] =
5"$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
6 4
7/* 5/*
8 * linux/drivers/char/cyclades.c 6 * linux/drivers/char/cyclades.c
@@ -593,18 +591,20 @@ static char rcsid[] =
593 * 591 *
594 */ 592 */
595 593
594#define CY_VERSION "2.4"
595
596/* If you need to install more boards than NR_CARDS, change the constant 596/* If you need to install more boards than NR_CARDS, change the constant
597 in the definition below. No other change is necessary to support up to 597 in the definition below. No other change is necessary to support up to
598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */ 598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
599 599
600#define NR_CARDS 4 600#define NR_CARDS 4
601 601
602/* 602/*
603 If the total number of ports is larger than NR_PORTS, change this 603 If the total number of ports is larger than NR_PORTS, change this
604 constant in the definition below. No other change is necessary to 604 constant in the definition below. No other change is necessary to
605 support more boards/ports. */ 605 support more boards/ports. */
606 606
607#define NR_PORTS 256 607#define NR_PORTS 256
608 608
609#define ZE_V1_NPORTS 64 609#define ZE_V1_NPORTS 64
610#define ZO_V1 0 610#define ZO_V1 0
@@ -625,9 +625,9 @@ static char rcsid[] =
625#undef CY_PCI_DEBUG 625#undef CY_PCI_DEBUG
626 626
627#if 0 627#if 0
628#define PAUSE __asm__("nop"); 628#define PAUSE __asm__("nop")
629#else 629#else
630#define PAUSE ; 630#define PAUSE do {} while (0)
631#endif 631#endif
632 632
633/* 633/*
@@ -663,7 +663,7 @@ static char rcsid[] =
663 do { \ 663 do { \
664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \ 664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
665 } while (0) 665 } while (0)
666 666
667#define CY_UNLOCK(info,flags) \ 667#define CY_UNLOCK(info,flags) \
668 do { \ 668 do { \
669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \ 669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
@@ -676,14 +676,14 @@ static char rcsid[] =
676#include <linux/stat.h> 676#include <linux/stat.h>
677#include <linux/proc_fs.h> 677#include <linux/proc_fs.h>
678 678
679static void cy_throttle (struct tty_struct *tty); 679static void cy_throttle(struct tty_struct *tty);
680static void cy_send_xchar (struct tty_struct *tty, char ch); 680static void cy_send_xchar(struct tty_struct *tty, char ch);
681 681
682#define IS_CYC_Z(card) ((card).num_chips == -1) 682#define IS_CYC_Z(card) ((card).num_chips == -1)
683 683
684#define Z_FPGA_CHECK(card) \ 684#define Z_FPGA_CHECK(card) \
685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \ 685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) 686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
687 687
688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \ 688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
689 ((card).ctl_addr))->mail_box_0)) || \ 689 ((card).ctl_addr))->mail_box_0)) || \
@@ -698,8 +698,6 @@ static void cy_send_xchar (struct tty_struct *tty, char ch);
698 698
699#define STD_COM_FLAGS (0) 699#define STD_COM_FLAGS (0)
700 700
701#define JIFFIES_DIFF(n, j) ((j) - (n))
702
703static struct tty_driver *cy_serial_driver; 701static struct tty_driver *cy_serial_driver;
704 702
705#ifdef CONFIG_ISA 703#ifdef CONFIG_ISA
@@ -713,27 +711,28 @@ static struct tty_driver *cy_serial_driver;
713*/ 711*/
714 712
715static unsigned int cy_isa_addresses[] = { 713static unsigned int cy_isa_addresses[] = {
716 0xD0000, 714 0xD0000,
717 0xD2000, 715 0xD2000,
718 0xD4000, 716 0xD4000,
719 0xD6000, 717 0xD6000,
720 0xD8000, 718 0xD8000,
721 0xDA000, 719 0xDA000,
722 0xDC000, 720 0xDC000,
723 0xDE000, 721 0xDE000,
724 0,0,0,0,0,0,0,0 722 0, 0, 0, 0, 0, 0, 0, 0
725}; 723};
724
726#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) 725#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
727 726
728#ifdef MODULE 727#ifdef MODULE
729static long maddr[NR_CARDS] = { 0, }; 728static long maddr[NR_CARDS] = { 0, };
730static int irq[NR_CARDS] = { 0, }; 729static int irq[NR_CARDS] = { 0, };
731 730
732module_param_array(maddr, long, NULL, 0); 731module_param_array(maddr, long, NULL, 0);
733module_param_array(irq, int, NULL, 0); 732module_param_array(irq, int, NULL, 0);
734#endif 733#endif
735 734
736#endif /* CONFIG_ISA */ 735#endif /* CONFIG_ISA */
737 736
738/* This is the per-card data structure containing address, irq, number of 737/* This is the per-card data structure containing address, irq, number of
739 channels, etc. This driver supports a maximum of NR_CARDS cards. 738 channels, etc. This driver supports a maximum of NR_CARDS cards.
@@ -745,7 +744,7 @@ static struct cyclades_card cy_card[NR_CARDS];
745*/ 744*/
746static struct cyclades_port cy_port[NR_PORTS]; 745static struct cyclades_port cy_port[NR_PORTS];
747 746
748static int cy_next_channel; /* next minor available */ 747static int cy_next_channel; /* next minor available */
749 748
750/* 749/*
751 * This is used to look up the divisor speeds and the timeouts 750 * This is used to look up the divisor speeds and the timeouts
@@ -757,36 +756,42 @@ static int cy_next_channel; /* next minor available */
757 * 20 756 * 20
758 */ 757 */
759static int baud_table[] = { 758static int baud_table[] = {
760 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 759 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
761 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 760 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
762 230400, 0}; 761 230400, 0
763 762};
764static char baud_co_25[] = { /* 25 MHz clock option table */ 763
765 /* value => 00 01 02 03 04 */ 764static char baud_co_25[] = { /* 25 MHz clock option table */
766 /* divide by 8 32 128 512 2048 */ 765 /* value => 00 01 02 03 04 */
767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 766 /* divide by 8 32 128 512 2048 */
768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
769 768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
770static char baud_bpr_25[] = { /* 25 MHz baud rate period table */ 769};
771 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, 770
772 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15}; 771static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
773 772 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
774static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */ 773 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
775 /* value => 00 01 02 03 04 */ 774};
776 /* divide by 8 32 128 512 2048 */ 775
777 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 776static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
778 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 777 /* value => 00 01 02 03 04 */
779 0x00}; 778 /* divide by 8 32 128 512 2048 */
780 779 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
781static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */ 780 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
782 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62, 781 0x00
783 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32, 782};
784 0x21}; 783
785 784static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
786static char baud_cor3[] = { /* receive threshold */ 785 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
787 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 786 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
788 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07, 787 0x21
789 0x07}; 788};
789
790static char baud_cor3[] = { /* receive threshold */
791 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
792 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
793 0x07
794};
790 795
791/* 796/*
792 * The Cyclades driver implements HW flow control as any serial driver. 797 * The Cyclades driver implements HW flow control as any serial driver.
@@ -799,42 +804,42 @@ static char baud_cor3[] = { /* receive threshold */
799 * cables. 804 * cables.
800 */ 805 */
801 806
802static char rflow_thr[] = { /* rflow threshold */ 807static char rflow_thr[] = { /* rflow threshold */
803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
804 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 809 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
805 0x0a}; 810 0x0a
811};
806 812
807/* The Cyclom-Ye has placed the sequential chips in non-sequential 813/* The Cyclom-Ye has placed the sequential chips in non-sequential
808 * address order. This look-up table overcomes that problem. 814 * address order. This look-up table overcomes that problem.
809 */ 815 */
810static int cy_chip_offset [] = 816static int cy_chip_offset[] = { 0x0000,
811 { 0x0000, 817 0x0400,
812 0x0400, 818 0x0800,
813 0x0800, 819 0x0C00,
814 0x0C00, 820 0x0200,
815 0x0200, 821 0x0600,
816 0x0600, 822 0x0A00,
817 0x0A00, 823 0x0E00
818 0x0E00 824};
819 };
820 825
821/* PCI related definitions */ 826/* PCI related definitions */
822 827
823static unsigned short cy_pci_nboard; 828static unsigned short cy_pci_nboard;
824static unsigned short cy_isa_nboard; 829static unsigned short cy_isa_nboard;
825static unsigned short cy_nboard; 830static unsigned short cy_nboard;
826#ifdef CONFIG_PCI 831#ifdef CONFIG_PCI
827static unsigned short cy_pci_dev_id[] = { 832static unsigned short cy_pci_dev_id[] = {
828 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */ 833 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */
829 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */ 834 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */
830 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */ 835 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */
831 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */ 836 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */
832 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */ 837 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */
833 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */ 838 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */
834 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */ 839 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */
835 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */ 840 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */
836 0 /* end of table */ 841 0 /* end of table */
837 }; 842};
838#endif 843#endif
839 844
840static void cy_start(struct tty_struct *); 845static void cy_start(struct tty_struct *);
@@ -842,9 +847,9 @@ static void set_line_char(struct cyclades_port *);
842static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong); 847static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong);
843#ifdef CONFIG_ISA 848#ifdef CONFIG_ISA
844static unsigned detect_isa_irq(void __iomem *); 849static unsigned detect_isa_irq(void __iomem *);
845#endif /* CONFIG_ISA */ 850#endif /* CONFIG_ISA */
846 851
847static int cyclades_get_proc_info(char *, char **, off_t , int , int *, void *); 852static int cyclades_get_proc_info(char *, char **, off_t, int, int *, void *);
848 853
849#ifndef CONFIG_CYZ_INTR 854#ifndef CONFIG_CYZ_INTR
850static void cyz_poll(unsigned long); 855static void cyz_poll(unsigned long);
@@ -855,41 +860,36 @@ static long cyz_polling_cycle = CZ_DEF_POLL;
855static int cyz_timeron = 0; 860static int cyz_timeron = 0;
856static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0); 861static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
857 862
858#else /* CONFIG_CYZ_INTR */ 863#else /* CONFIG_CYZ_INTR */
859static void cyz_rx_restart(unsigned long); 864static void cyz_rx_restart(unsigned long);
860static struct timer_list cyz_rx_full_timer[NR_PORTS]; 865static struct timer_list cyz_rx_full_timer[NR_PORTS];
861#endif /* CONFIG_CYZ_INTR */ 866#endif /* CONFIG_CYZ_INTR */
862 867
863static inline int 868static inline int serial_paranoia_check(struct cyclades_port *info,
864serial_paranoia_check(struct cyclades_port *info, 869 char *name, const char *routine)
865 char *name, const char *routine)
866{ 870{
867#ifdef SERIAL_PARANOIA_CHECK 871#ifdef SERIAL_PARANOIA_CHECK
868 static const char *badmagic = 872 if (!info) {
869 "cyc Warning: bad magic number for serial struct (%s) in %s\n"; 873 printk("cyc Warning: null cyclades_port for (%s) in %s\n",
870 static const char *badinfo = 874 name, routine);
871 "cyc Warning: null cyclades_port for (%s) in %s\n"; 875 return 1;
872 static const char *badrange = 876 }
873 "cyc Warning: cyclades_port out of range for (%s) in %s\n"; 877
874 878 if ((long)info < (long)(&cy_port[0]) ||
875 if (!info) { 879 (long)(&cy_port[NR_PORTS]) < (long)info) {
876 printk(badinfo, name, routine); 880 printk("cyc Warning: cyclades_port out of range for (%s) in "
877 return 1; 881 "%s\n", name, routine);
878 } 882 return 1;
879 883 }
880 if( (long)info < (long)(&cy_port[0]) 884
881 || (long)(&cy_port[NR_PORTS]) < (long)info ){ 885 if (info->magic != CYCLADES_MAGIC) {
882 printk(badrange, name, routine); 886 printk("cyc Warning: bad magic number for serial struct (%s) "
883 return 1; 887 "in %s\n", name, routine);
884 } 888 return 1;
885 889 }
886 if (info->magic != CYCLADES_MAGIC) {
887 printk(badmagic, name, routine);
888 return 1;
889 }
890#endif 890#endif
891 return 0; 891 return 0;
892} /* serial_paranoia_check */ 892} /* serial_paranoia_check */
893 893
894/* 894/*
895 * This routine is used by the interrupt handler to schedule 895 * This routine is used by the interrupt handler to schedule
@@ -897,13 +897,11 @@ serial_paranoia_check(struct cyclades_port *info,
897 * (also known as the "bottom half"). This can be called any 897 * (also known as the "bottom half"). This can be called any
898 * number of times for any channel without harm. 898 * number of times for any channel without harm.
899 */ 899 */
900static inline void 900static inline void cy_sched_event(struct cyclades_port *info, int event)
901cy_sched_event(struct cyclades_port *info, int event)
902{ 901{
903 info->event |= 1 << event; /* remember what kind of event and who */ 902 info->event |= 1 << event; /* remember what kind of event and who */
904 schedule_work(&info->tqueue); 903 schedule_work(&info->tqueue);
905} /* cy_sched_event */ 904} /* cy_sched_event */
906
907 905
908/* 906/*
909 * This routine is used to handle the "bottom half" processing for the 907 * This routine is used to handle the "bottom half" processing for the
@@ -930,41 +928,36 @@ do_softint(struct work_struct *work)
930{ 928{
931 struct cyclades_port *info = 929 struct cyclades_port *info =
932 container_of(work, struct cyclades_port, tqueue); 930 container_of(work, struct cyclades_port, tqueue);
933 struct tty_struct *tty; 931 struct tty_struct *tty;
934 932
935 tty = info->tty; 933 tty = info->tty;
936 if (!tty) 934 if (!tty)
937 return; 935 return;
938 936
939 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) { 937 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
940 tty_hangup(info->tty); 938 tty_hangup(info->tty);
941 wake_up_interruptible(&info->open_wait); 939 wake_up_interruptible(&info->open_wait);
942 info->flags &= ~ASYNC_NORMAL_ACTIVE; 940 info->flags &= ~ASYNC_NORMAL_ACTIVE;
943 } 941 }
944 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) { 942 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
945 wake_up_interruptible(&info->open_wait); 943 wake_up_interruptible(&info->open_wait);
946 }
947#ifdef CONFIG_CYZ_INTR 944#ifdef CONFIG_CYZ_INTR
948 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) { 945 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) {
949 if (cyz_rx_full_timer[info->line].function == NULL) { 946 if (cyz_rx_full_timer[info->line].function == NULL) {
950 cyz_rx_full_timer[info->line].expires = jiffies + 1; 947 cyz_rx_full_timer[info->line].expires = jiffies + 1;
951 cyz_rx_full_timer[info->line].function = cyz_rx_restart; 948 cyz_rx_full_timer[info->line].function = cyz_rx_restart;
952 cyz_rx_full_timer[info->line].data = (unsigned long)info; 949 cyz_rx_full_timer[info->line].data =
953 add_timer(&cyz_rx_full_timer[info->line]); 950 (unsigned long)info;
951 add_timer(&cyz_rx_full_timer[info->line]);
952 }
954 } 953 }
955 }
956#endif 954#endif
957 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event)) { 955 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
958 wake_up_interruptible(&info->delta_msr_wait); 956 wake_up_interruptible(&info->delta_msr_wait);
959 } 957 tty_wakeup(tty);
960 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
961 tty_wakeup(tty);
962 wake_up_interruptible(&tty->write_wait);
963 }
964#ifdef Z_WAKE 958#ifdef Z_WAKE
965 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) { 959 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
966 wake_up_interruptible(&info->shutdown_wait); 960 wake_up_interruptible(&info->shutdown_wait);
967 }
968#endif 961#endif
969} /* do_softint */ 962} /* do_softint */
970 963
@@ -979,341 +972,339 @@ do_softint(struct work_struct *work)
979 972
980 This function is only called from inside spinlock-protected code. 973 This function is only called from inside spinlock-protected code.
981 */ 974 */
982static int 975static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
983cyy_issue_cmd(void __iomem *base_addr, u_char cmd, int index)
984{ 976{
985 volatile int i; 977 volatile int i;
986 978
987 /* Check to see that the previous command has completed */ 979 /* Check to see that the previous command has completed */
988 for(i = 0 ; i < 100 ; i++){ 980 for (i = 0; i < 100; i++) {
989 if (cy_readb(base_addr+(CyCCR<<index)) == 0){ 981 if (cy_readb(base_addr + (CyCCR << index)) == 0) {
990 break; 982 break;
983 }
984 udelay(10L);
991 } 985 }
992 udelay(10L); 986 /* if the CCR never cleared, the previous command
993 } 987 didn't finish within the "reasonable time" */
994 /* if the CCR never cleared, the previous command 988 if (i == 100)
995 didn't finish within the "reasonable time" */ 989 return -1;
996 if (i == 100) return (-1);
997 990
998 /* Issue the new command */ 991 /* Issue the new command */
999 cy_writeb(base_addr+(CyCCR<<index), cmd); 992 cy_writeb(base_addr + (CyCCR << index), cmd);
1000 993
1001 return(0); 994 return 0;
1002} /* cyy_issue_cmd */ 995} /* cyy_issue_cmd */
1003 996
1004#ifdef CONFIG_ISA 997#ifdef CONFIG_ISA
1005/* ISA interrupt detection code */ 998/* ISA interrupt detection code */
1006static unsigned 999static unsigned detect_isa_irq(void __iomem * address)
1007detect_isa_irq(void __iomem *address)
1008{ 1000{
1009 int irq; 1001 int irq;
1010 unsigned long irqs, flags; 1002 unsigned long irqs, flags;
1011 int save_xir, save_car; 1003 int save_xir, save_car;
1012 int index = 0; /* IRQ probing is only for ISA */ 1004 int index = 0; /* IRQ probing is only for ISA */
1013 1005
1014 /* forget possible initially masked and pending IRQ */ 1006 /* forget possible initially masked and pending IRQ */
1015 irq = probe_irq_off(probe_irq_on()); 1007 irq = probe_irq_off(probe_irq_on());
1016 1008
1017 /* Clear interrupts on the board first */ 1009 /* Clear interrupts on the board first */
1018 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1010 cy_writeb(address + (Cy_ClrIntr << index), 0);
1019 /* Cy_ClrIntr is 0x1800 */ 1011 /* Cy_ClrIntr is 0x1800 */
1020 1012
1021 irqs = probe_irq_on(); 1013 irqs = probe_irq_on();
1022 /* Wait ... */ 1014 /* Wait ... */
1023 udelay(5000L); 1015 udelay(5000L);
1024 1016
1025 /* Enable the Tx interrupts on the CD1400 */ 1017 /* Enable the Tx interrupts on the CD1400 */
1026 local_irq_save(flags); 1018 local_irq_save(flags);
1027 cy_writeb(address + (CyCAR<<index), 0); 1019 cy_writeb(address + (CyCAR << index), 0);
1028 cyy_issue_cmd(address, CyCHAN_CTL|CyENB_XMTR, index); 1020 cyy_issue_cmd(address, CyCHAN_CTL | CyENB_XMTR, index);
1029 1021
1030 cy_writeb(address + (CyCAR<<index), 0); 1022 cy_writeb(address + (CyCAR << index), 0);
1031 cy_writeb(address + (CySRER<<index), 1023 cy_writeb(address + (CySRER << index),
1032 cy_readb(address + (CySRER<<index)) | CyTxRdy); 1024 cy_readb(address + (CySRER << index)) | CyTxRdy);
1033 local_irq_restore(flags); 1025 local_irq_restore(flags);
1034 1026
1035 /* Wait ... */ 1027 /* Wait ... */
1036 udelay(5000L); 1028 udelay(5000L);
1037 1029
1038 /* Check which interrupt is in use */ 1030 /* Check which interrupt is in use */
1039 irq = probe_irq_off(irqs); 1031 irq = probe_irq_off(irqs);
1040 1032
1041 /* Clean up */ 1033 /* Clean up */
1042 save_xir = (u_char) cy_readb(address + (CyTIR<<index)); 1034 save_xir = (u_char) cy_readb(address + (CyTIR << index));
1043 save_car = cy_readb(address + (CyCAR<<index)); 1035 save_car = cy_readb(address + (CyCAR << index));
1044 cy_writeb(address + (CyCAR<<index), (save_xir & 0x3)); 1036 cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
1045 cy_writeb(address + (CySRER<<index), 1037 cy_writeb(address + (CySRER << index),
1046 cy_readb(address + (CySRER<<index)) & ~CyTxRdy); 1038 cy_readb(address + (CySRER << index)) & ~CyTxRdy);
1047 cy_writeb(address + (CyTIR<<index), (save_xir & 0x3f)); 1039 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
1048 cy_writeb(address + (CyCAR<<index), (save_car)); 1040 cy_writeb(address + (CyCAR << index), (save_car));
1049 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1041 cy_writeb(address + (Cy_ClrIntr << index), 0);
1050 /* Cy_ClrIntr is 0x1800 */ 1042 /* Cy_ClrIntr is 0x1800 */
1051 1043
1052 return (irq > 0)? irq : 0; 1044 return (irq > 0) ? irq : 0;
1053} 1045}
1054#endif /* CONFIG_ISA */ 1046#endif /* CONFIG_ISA */
1055 1047
1056/* The real interrupt service routine is called 1048static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1057 whenever the card wants its hand held--chars 1049 void __iomem * base_addr, int status, int index)
1058 received, out buffer empty, modem change, etc.
1059 */
1060static irqreturn_t
1061cyy_interrupt(int irq, void *dev_id)
1062{ 1050{
1063 struct tty_struct *tty; 1051 struct cyclades_port *info;
1064 int status; 1052 struct tty_struct *tty;
1065 struct cyclades_card *cinfo; 1053 volatile int char_count;
1066 struct cyclades_port *info; 1054 int i, j, len, mdm_change, mdm_status, outch;
1067 void __iomem *base_addr, *card_base_addr; 1055 int save_xir, channel, save_car;
1068 int chip; 1056 char data;
1069 int save_xir, channel, save_car; 1057
1070 char data; 1058 if (status & CySRReceive) { /* reception interrupt */
1071 volatile int char_count;
1072 int outch;
1073 int i,j,index;
1074 int too_many;
1075 int had_work;
1076 int mdm_change;
1077 int mdm_status;
1078 int len;
1079 if((cinfo = (struct cyclades_card *)dev_id) == 0){
1080#ifdef CY_DEBUG_INTERRUPTS
1081 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1082#endif
1083 return IRQ_NONE; /* spurious interrupt */
1084 }
1085
1086 card_base_addr = cinfo->base_addr;
1087 index = cinfo->bus_index;
1088
1089
1090 /* This loop checks all chips in the card. Make a note whenever
1091 _any_ chip had some work to do, as this is considered an
1092 indication that there will be more to do. Only when no chip
1093 has any work does this outermost loop exit.
1094 */
1095 do{
1096 had_work = 0;
1097 for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) {
1098 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index);
1099 too_many = 0;
1100 while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) {
1101 had_work++;
1102 /* The purpose of the following test is to ensure that
1103 no chip can monopolize the driver. This forces the
1104 chips to be checked in a round-robin fashion (after
1105 draining each of a bunch (1000) of characters).
1106 */
1107 if(1000<too_many++){
1108 break;
1109 }
1110 if (status & CySRReceive) { /* reception interrupt */
1111#ifdef CY_DEBUG_INTERRUPTS 1059#ifdef CY_DEBUG_INTERRUPTS
1112 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip); 1060 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);
1113#endif 1061#endif
1114 /* determine the channel & change to that context */ 1062 /* determine the channel & change to that context */
1115 spin_lock(&cinfo->card_lock); 1063 spin_lock(&cinfo->card_lock);
1116 save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index)); 1064 save_xir = (u_char) cy_readb(base_addr + (CyRIR << index));
1117 channel = (u_short ) (save_xir & CyIRChannel); 1065 channel = (u_short) (save_xir & CyIRChannel);
1118 i = channel + chip * 4 + cinfo->first_line; 1066 i = channel + chip * 4 + cinfo->first_line;
1119 info = &cy_port[i]; 1067 info = &cy_port[i];
1120 info->last_active = jiffies; 1068 info->last_active = jiffies;
1121 save_car = cy_readb(base_addr+(CyCAR<<index)); 1069 save_car = cy_readb(base_addr + (CyCAR << index));
1122 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1070 cy_writeb(base_addr + (CyCAR << index), save_xir);
1123 1071
1124 /* if there is nowhere to put the data, discard it */ 1072 /* if there is nowhere to put the data, discard it */
1125 if(info->tty == 0){ 1073 if (info->tty == 0) {
1126 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); 1074 j = (cy_readb(base_addr + (CyRIVR << index)) &
1127 if ( j == CyIVRRxEx ) { /* exception */ 1075 CyIVRMask);
1128 data = cy_readb(base_addr+(CyRDSR<<index)); 1076 if (j == CyIVRRxEx) { /* exception */
1129 } else { /* normal character reception */ 1077 data = cy_readb(base_addr + (CyRDSR << index));
1130 char_count = cy_readb(base_addr+(CyRDCR<<index)); 1078 } else { /* normal character reception */
1131 while(char_count--){ 1079 char_count = cy_readb(base_addr +
1132 data = cy_readb(base_addr+(CyRDSR<<index)); 1080 (CyRDCR << index));
1133 } 1081 while (char_count--) {
1134 } 1082 data = cy_readb(base_addr +
1135 }else{ /* there is an open port for this data */ 1083 (CyRDSR << index));
1136 tty = info->tty; 1084 }
1137 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); 1085 }
1138 if ( j == CyIVRRxEx ) { /* exception */ 1086 } else { /* there is an open port for this data */
1139 data = cy_readb(base_addr+(CyRDSR<<index)); 1087 tty = info->tty;
1140 1088 j = (cy_readb(base_addr + (CyRIVR << index)) &
1141 /* For statistics only */ 1089 CyIVRMask);
1142 if (data & CyBREAK) 1090 if (j == CyIVRRxEx) { /* exception */
1143 info->icount.brk++; 1091 data = cy_readb(base_addr + (CyRDSR << index));
1144 else if(data & CyFRAME) 1092
1145 info->icount.frame++; 1093 /* For statistics only */
1146 else if(data & CyPARITY) 1094 if (data & CyBREAK)
1147 info->icount.parity++; 1095 info->icount.brk++;
1148 else if(data & CyOVERRUN) 1096 else if (data & CyFRAME)
1149 info->icount.overrun++; 1097 info->icount.frame++;
1150 1098 else if (data & CyPARITY)
1151 if(data & info->ignore_status_mask){ 1099 info->icount.parity++;
1152 info->icount.rx++; 1100 else if (data & CyOVERRUN)
1153 continue; 1101 info->icount.overrun++;
1154 } 1102
1155 if (tty_buffer_request_room(tty, 1)) { 1103 if (data & info->ignore_status_mask) {
1156 if (data & info->read_status_mask){
1157 if(data & CyBREAK){
1158 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_BREAK);
1159 info->icount.rx++;
1160 if (info->flags & ASYNC_SAK){
1161 do_SAK(tty);
1162 }
1163 }else if(data & CyFRAME){
1164 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
1165 info->icount.rx++;
1166 info->idle_stats.frame_errs++;
1167 }else if(data & CyPARITY){
1168 /* Pieces of seven... */
1169 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_PARITY);
1170 info->icount.rx++;
1171 info->idle_stats.parity_errs++;
1172 }else if(data & CyOVERRUN){
1173 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1174 info->icount.rx++; 1104 info->icount.rx++;
1175 /* If the flip buffer itself is 1105 return;
1176 overflowing, we still lose 1106 }
1177 the next incoming character. 1107 if (tty_buffer_request_room(tty, 1)) {
1178 */ 1108 if (data & info->read_status_mask) {
1179 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME); 1109 if (data & CyBREAK) {
1180 info->icount.rx++; 1110 tty_insert_flip_char(
1111 tty,
1112 cy_readb(
1113 base_addr +
1114 (CyRDSR <<
1115 index)),
1116 TTY_BREAK);
1117 info->icount.rx++;
1118 if (info->flags &
1119 ASYNC_SAK) {
1120 do_SAK(tty);
1121 }
1122 } else if (data & CyFRAME) {
1123 tty_insert_flip_char(
1124 tty,
1125 cy_readb(
1126 base_addr +
1127 (CyRDSR <<
1128 index)),
1129 TTY_FRAME);
1130 info->icount.rx++;
1131 info->idle_stats.
1132 frame_errs++;
1133 } else if (data & CyPARITY) {
1134 /* Pieces of seven... */
1135 tty_insert_flip_char(
1136 tty,
1137 cy_readb(
1138 base_addr +
1139 (CyRDSR <<
1140 index)),
1141 TTY_PARITY);
1142 info->icount.rx++;
1143 info->idle_stats.
1144 parity_errs++;
1145 } else if (data & CyOVERRUN) {
1146 tty_insert_flip_char(
1147 tty, 0,
1148 TTY_OVERRUN);
1149 info->icount.rx++;
1150 /* If the flip buffer itself is
1151 overflowing, we still lose
1152 the next incoming character.
1153 */
1154 tty_insert_flip_char(
1155 tty,
1156 cy_readb(
1157 base_addr +
1158 (CyRDSR <<
1159 index)),
1160 TTY_FRAME);
1161 info->icount.rx++;
1162 info->idle_stats.
1163 overruns++;
1164 /* These two conditions may imply */
1165 /* a normal read should be done. */
1166 /* }else if(data & CyTIMEOUT){ */
1167 /* }else if(data & CySPECHAR){ */
1168 } else {
1169 tty_insert_flip_char(
1170 tty, 0,
1171 TTY_NORMAL);
1172 info->icount.rx++;
1173 }
1174 } else {
1175 tty_insert_flip_char(tty, 0,
1176 TTY_NORMAL);
1177 info->icount.rx++;
1178 }
1179 } else {
1180 /* there was a software buffer
1181 overrun and nothing could be
1182 done about it!!! */
1183 info->icount.buf_overrun++;
1181 info->idle_stats.overruns++; 1184 info->idle_stats.overruns++;
1182 /* These two conditions may imply */ 1185 }
1183 /* a normal read should be done. */ 1186 } else { /* normal character reception */
1184 /* }else if(data & CyTIMEOUT){ */ 1187 /* load # chars available from the chip */
1185 /* }else if(data & CySPECHAR){ */ 1188 char_count = cy_readb(base_addr +
1186 }else { 1189 (CyRDCR << index));
1187 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1188 info->icount.rx++;
1189 }
1190 }else{
1191 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1192 info->icount.rx++;
1193 }
1194 }else{
1195 /* there was a software buffer
1196 overrun and nothing could be
1197 done about it!!! */
1198 info->icount.buf_overrun++;
1199 info->idle_stats.overruns++;
1200 }
1201 } else { /* normal character reception */
1202 /* load # chars available from the chip */
1203 char_count = cy_readb(base_addr+(CyRDCR<<index));
1204 1190
1205#ifdef CY_ENABLE_MONITORING 1191#ifdef CY_ENABLE_MONITORING
1206 ++info->mon.int_count; 1192 ++info->mon.int_count;
1207 info->mon.char_count += char_count; 1193 info->mon.char_count += char_count;
1208 if (char_count > info->mon.char_max) 1194 if (char_count > info->mon.char_max)
1209 info->mon.char_max = char_count; 1195 info->mon.char_max = char_count;
1210 info->mon.char_last = char_count; 1196 info->mon.char_last = char_count;
1211#endif 1197#endif
1212 len = tty_buffer_request_room(tty, char_count); 1198 len = tty_buffer_request_room(tty, char_count);
1213 while(len--){ 1199 while (len--) {
1214 data = cy_readb(base_addr+(CyRDSR<<index)); 1200 data = cy_readb(base_addr +
1215 tty_insert_flip_char(tty, data, TTY_NORMAL); 1201 (CyRDSR << index));
1216 info->idle_stats.recv_bytes++; 1202 tty_insert_flip_char(tty, data,
1217 info->icount.rx++; 1203 TTY_NORMAL);
1204 info->idle_stats.recv_bytes++;
1205 info->icount.rx++;
1218#ifdef CY_16Y_HACK 1206#ifdef CY_16Y_HACK
1219 udelay(10L); 1207 udelay(10L);
1220#endif 1208#endif
1221 } 1209 }
1222 info->idle_stats.recv_idle = jiffies; 1210 info->idle_stats.recv_idle = jiffies;
1223 } 1211 }
1224 tty_schedule_flip(tty); 1212 tty_schedule_flip(tty);
1225 } 1213 }
1226 /* end of service */ 1214 /* end of service */
1227 cy_writeb(base_addr+(CyRIR<<index), (save_xir & 0x3f)); 1215 cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
1228 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1216 cy_writeb(base_addr + (CyCAR << index), (save_car));
1229 spin_unlock(&cinfo->card_lock); 1217 spin_unlock(&cinfo->card_lock);
1230 } 1218 }
1231 1219
1232 1220 if (status & CySRTransmit) { /* transmission interrupt */
1233 if (status & CySRTransmit) { /* transmission interrupt */ 1221 /* Since we only get here when the transmit buffer
1234 /* Since we only get here when the transmit buffer 1222 is empty, we know we can always stuff a dozen
1235 is empty, we know we can always stuff a dozen 1223 characters. */
1236 characters. */
1237#ifdef CY_DEBUG_INTERRUPTS 1224#ifdef CY_DEBUG_INTERRUPTS
1238 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip); 1225 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);
1239#endif 1226#endif
1240 1227
1241 /* determine the channel & change to that context */ 1228 /* determine the channel & change to that context */
1242 spin_lock(&cinfo->card_lock); 1229 spin_lock(&cinfo->card_lock);
1243 save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index)); 1230 save_xir = (u_char) cy_readb(base_addr + (CyTIR << index));
1244 channel = (u_short ) (save_xir & CyIRChannel); 1231 channel = (u_short) (save_xir & CyIRChannel);
1245 i = channel + chip * 4 + cinfo->first_line; 1232 i = channel + chip * 4 + cinfo->first_line;
1246 save_car = cy_readb(base_addr+(CyCAR<<index)); 1233 save_car = cy_readb(base_addr + (CyCAR << index));
1247 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1234 cy_writeb(base_addr + (CyCAR << index), save_xir);
1248 1235
1249 /* validate the port# (as configured and open) */ 1236 /* validate the port# (as configured and open) */
1250 if( (i < 0) || (NR_PORTS <= i) ){ 1237 if ((i < 0) || (NR_PORTS <= i)) {
1251 cy_writeb(base_addr+(CySRER<<index), 1238 cy_writeb(base_addr + (CySRER << index),
1252 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1239 cy_readb(base_addr + (CySRER << index)) &
1253 goto txend; 1240 ~CyTxRdy);
1254 } 1241 goto txend;
1255 info = &cy_port[i]; 1242 }
1256 info->last_active = jiffies; 1243 info = &cy_port[i];
1257 if(info->tty == 0){ 1244 info->last_active = jiffies;
1258 cy_writeb(base_addr+(CySRER<<index), 1245 if (info->tty == 0) {
1259 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1246 cy_writeb(base_addr + (CySRER << index),
1260 goto txdone; 1247 cy_readb(base_addr + (CySRER << index)) &
1261 } 1248 ~CyTxRdy);
1262 1249 goto txdone;
1263 /* load the on-chip space for outbound data */ 1250 }
1264 char_count = info->xmit_fifo_size; 1251
1265 1252 /* load the on-chip space for outbound data */
1266 if(info->x_char) { /* send special char */ 1253 char_count = info->xmit_fifo_size;
1267 outch = info->x_char; 1254
1268 cy_writeb(base_addr+(CyTDR<<index), outch); 1255 if (info->x_char) { /* send special char */
1269 char_count--; 1256 outch = info->x_char;
1257 cy_writeb(base_addr + (CyTDR << index), outch);
1258 char_count--;
1270 info->icount.tx++; 1259 info->icount.tx++;
1271 info->x_char = 0; 1260 info->x_char = 0;
1272 } 1261 }
1273 1262
1274 if (info->breakon || info->breakoff) { 1263 if (info->breakon || info->breakoff) {
1275 if (info->breakon) { 1264 if (info->breakon) {
1276 cy_writeb(base_addr + (CyTDR<<index), 0); 1265 cy_writeb(base_addr + (CyTDR << index), 0);
1277 cy_writeb(base_addr + (CyTDR<<index), 0x81); 1266 cy_writeb(base_addr + (CyTDR << index), 0x81);
1278 info->breakon = 0; 1267 info->breakon = 0;
1279 char_count -= 2; 1268 char_count -= 2;
1280 } 1269 }
1281 if (info->breakoff) { 1270 if (info->breakoff) {
1282 cy_writeb(base_addr + (CyTDR<<index), 0); 1271 cy_writeb(base_addr + (CyTDR << index), 0);
1283 cy_writeb(base_addr + (CyTDR<<index), 0x83); 1272 cy_writeb(base_addr + (CyTDR << index), 0x83);
1284 info->breakoff = 0; 1273 info->breakoff = 0;
1285 char_count -= 2; 1274 char_count -= 2;
1286 } 1275 }
1287 } 1276 }
1288 1277
1289 while (char_count-- > 0){ 1278 while (char_count-- > 0) {
1290 if (!info->xmit_cnt){ 1279 if (!info->xmit_cnt) {
1291 if (cy_readb(base_addr+(CySRER<<index))&CyTxMpty) { 1280 if (cy_readb(base_addr + (CySRER << index)) &
1292 cy_writeb(base_addr+(CySRER<<index), 1281 CyTxMpty) {
1293 cy_readb(base_addr+(CySRER<<index)) & 1282 cy_writeb(base_addr + (CySRER << index),
1294 ~CyTxMpty); 1283 cy_readb(base_addr +
1295 } else { 1284 (CySRER << index)) &
1296 cy_writeb(base_addr+(CySRER<<index), 1285 ~CyTxMpty);
1297 ((cy_readb(base_addr+(CySRER<<index)) 1286 } else {
1298 & ~CyTxRdy) 1287 cy_writeb(base_addr + (CySRER << index),
1299 | CyTxMpty)); 1288 (cy_readb(base_addr +
1300 } 1289 (CySRER << index)) &
1301 goto txdone; 1290 ~CyTxRdy) | CyTxMpty);
1291 }
1292 goto txdone;
1302 } 1293 }
1303 if (info->xmit_buf == 0){ 1294 if (info->xmit_buf == 0) {
1304 cy_writeb(base_addr+(CySRER<<index), 1295 cy_writeb(base_addr + (CySRER << index),
1305 cy_readb(base_addr+(CySRER<<index)) & 1296 cy_readb(base_addr + (CySRER << index))&
1306 ~CyTxRdy); 1297 ~CyTxRdy);
1307 goto txdone; 1298 goto txdone;
1308 } 1299 }
1309 if (info->tty->stopped || info->tty->hw_stopped){ 1300 if (info->tty->stopped || info->tty->hw_stopped) {
1310 cy_writeb(base_addr+(CySRER<<index), 1301 cy_writeb(base_addr + (CySRER << index),
1311 cy_readb(base_addr+(CySRER<<index)) & 1302 cy_readb(base_addr + (CySRER << index))&
1312 ~CyTxRdy); 1303 ~CyTxRdy);
1313 goto txdone; 1304 goto txdone;
1314 } 1305 }
1315 /* Because the Embedded Transmit Commands have 1306 /* Because the Embedded Transmit Commands have
1316 been enabled, we must check to see if the 1307 been enabled, we must check to see if the
1317 escape character, NULL, is being sent. If it 1308 escape character, NULL, is being sent. If it
1318 is, we must ensure that there is room for it 1309 is, we must ensure that there is room for it
1319 to be doubled in the output stream. Therefore 1310 to be doubled in the output stream. Therefore
@@ -1322,125 +1313,182 @@ cyy_interrupt(int irq, void *dev_id)
1322 after the check for a NULL output character. 1313 after the check for a NULL output character.
1323 This is necessary because there may not be 1314 This is necessary because there may not be
1324 room for the two chars needed to send a NULL.) 1315 room for the two chars needed to send a NULL.)
1325 */ 1316 */
1326 outch = info->xmit_buf[info->xmit_tail]; 1317 outch = info->xmit_buf[info->xmit_tail];
1327 if( outch ){ 1318 if (outch) {
1328 info->xmit_cnt--; 1319 info->xmit_cnt--;
1329 info->xmit_tail = (info->xmit_tail + 1) 1320 info->xmit_tail = (info->xmit_tail + 1) &
1330 & (SERIAL_XMIT_SIZE - 1); 1321 (SERIAL_XMIT_SIZE - 1);
1331 cy_writeb(base_addr+(CyTDR<<index), outch); 1322 cy_writeb(base_addr + (CyTDR << index), outch);
1332 info->icount.tx++;
1333 }else{
1334 if(char_count > 1){
1335 info->xmit_cnt--;
1336 info->xmit_tail = (info->xmit_tail + 1)
1337 & (SERIAL_XMIT_SIZE - 1);
1338 cy_writeb(base_addr+(CyTDR<<index),
1339 outch);
1340 cy_writeb(base_addr+(CyTDR<<index), 0);
1341 info->icount.tx++; 1323 info->icount.tx++;
1342 char_count--; 1324 } else {
1343 }else{ 1325 if (char_count > 1) {
1344 } 1326 info->xmit_cnt--;
1345 } 1327 info->xmit_tail = (info->xmit_tail + 1)&
1346 } 1328 (SERIAL_XMIT_SIZE - 1);
1347 1329 cy_writeb(base_addr + (CyTDR << index),
1348 txdone: 1330 outch);
1349 if (info->xmit_cnt < WAKEUP_CHARS) { 1331 cy_writeb(base_addr + (CyTDR << index),
1350 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1332 0);
1351 } 1333 info->icount.tx++;
1352 txend: 1334 char_count--;
1353 /* end of service */ 1335 } else {
1354 cy_writeb(base_addr+(CyTIR<<index), 1336 }
1355 (save_xir & 0x3f)); 1337 }
1356 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1338 }
1357 spin_unlock(&cinfo->card_lock); 1339
1358 } 1340txdone:
1359 1341 if (info->xmit_cnt < WAKEUP_CHARS) {
1360 if (status & CySRModem) { /* modem interrupt */ 1342 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1361 1343 }
1362 /* determine the channel & change to that context */ 1344txend:
1363 spin_lock(&cinfo->card_lock); 1345 /* end of service */
1364 save_xir = (u_char) cy_readb(base_addr+(CyMIR<<index)); 1346 cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
1365 channel = (u_short ) (save_xir & CyIRChannel); 1347 cy_writeb(base_addr + (CyCAR << index), (save_car));
1366 info = &cy_port[channel + chip * 4 1348 spin_unlock(&cinfo->card_lock);
1367 + cinfo->first_line]; 1349 }
1368 info->last_active = jiffies; 1350
1369 save_car = cy_readb(base_addr+(CyCAR<<index)); 1351 if (status & CySRModem) { /* modem interrupt */
1370 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1352
1371 1353 /* determine the channel & change to that context */
1372 mdm_change = cy_readb(base_addr+(CyMISR<<index)); 1354 spin_lock(&cinfo->card_lock);
1373 mdm_status = cy_readb(base_addr+(CyMSVR1<<index)); 1355 save_xir = (u_char) cy_readb(base_addr + (CyMIR << index));
1374 1356 channel = (u_short) (save_xir & CyIRChannel);
1375 if(info->tty == 0){/* no place for data, ignore it*/ 1357 info = &cy_port[channel + chip * 4 + cinfo->first_line];
1376 ; 1358 info->last_active = jiffies;
1377 }else{ 1359 save_car = cy_readb(base_addr + (CyCAR << index));
1360 cy_writeb(base_addr + (CyCAR << index), save_xir);
1361
1362 mdm_change = cy_readb(base_addr + (CyMISR << index));
1363 mdm_status = cy_readb(base_addr + (CyMSVR1 << index));
1364
1365 if (info->tty == 0) { /* no place for data, ignore it */
1366 ;
1367 } else {
1378 if (mdm_change & CyANY_DELTA) { 1368 if (mdm_change & CyANY_DELTA) {
1379 /* For statistics only */ 1369 /* For statistics only */
1380 if (mdm_change & CyDCD) info->icount.dcd++; 1370 if (mdm_change & CyDCD)
1381 if (mdm_change & CyCTS) info->icount.cts++; 1371 info->icount.dcd++;
1382 if (mdm_change & CyDSR) info->icount.dsr++; 1372 if (mdm_change & CyCTS)
1383 if (mdm_change & CyRI) info->icount.rng++; 1373 info->icount.cts++;
1374 if (mdm_change & CyDSR)
1375 info->icount.dsr++;
1376 if (mdm_change & CyRI)
1377 info->icount.rng++;
1378
1379 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1380 }
1381
1382 if ((mdm_change & CyDCD) &&
1383 (info->flags & ASYNC_CHECK_CD)) {
1384 if (mdm_status & CyDCD) {
1385 cy_sched_event(info,
1386 Cy_EVENT_OPEN_WAKEUP);
1387 } else {
1388 cy_sched_event(info, Cy_EVENT_HANGUP);
1389 }
1390 }
1391 if ((mdm_change & CyCTS) &&
1392 (info->flags & ASYNC_CTS_FLOW)) {
1393 if (info->tty->hw_stopped) {
1394 if (mdm_status & CyCTS) {
1395 /* cy_start isn't used
1396 because... !!! */
1397 info->tty->hw_stopped = 0;
1398 cy_writeb(base_addr +
1399 (CySRER << index),
1400 cy_readb(base_addr +
1401 (CySRER <<
1402 index))|
1403 CyTxRdy);
1404 cy_sched_event(info,
1405 Cy_EVENT_WRITE_WAKEUP);
1406 }
1407 } else {
1408 if (!(mdm_status & CyCTS)) {
1409 /* cy_stop isn't used
1410 because ... !!! */
1411 info->tty->hw_stopped = 1;
1412 cy_writeb(base_addr +
1413 (CySRER << index),
1414 cy_readb(base_addr +
1415 (CySRER <<
1416 index)) &
1417 ~CyTxRdy);
1418 }
1419 }
1420 }
1421 if (mdm_change & CyDSR) {
1422 }
1423 if (mdm_change & CyRI) {
1424 }
1425 }
1426 /* end of service */
1427 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
1428 cy_writeb(base_addr + (CyCAR << index), save_car);
1429 spin_unlock(&cinfo->card_lock);
1430 }
1431}
1432
1433/* The real interrupt service routine is called
1434 whenever the card wants its hand held--chars
1435 received, out buffer empty, modem change, etc.
1436 */
1437static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1438{
1439 int status;
1440 struct cyclades_card *cinfo;
1441 void __iomem *base_addr, *card_base_addr;
1442 int chip;
1443 int index;
1444 int too_many;
1445 int had_work;
1446
1447 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1448#ifdef CY_DEBUG_INTERRUPTS
1449 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1450#endif
1451 return IRQ_NONE; /* spurious interrupt */
1452 }
1453
1454 card_base_addr = cinfo->base_addr;
1455 index = cinfo->bus_index;
1384 1456
1385 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP); 1457 /* This loop checks all chips in the card. Make a note whenever
1458 _any_ chip had some work to do, as this is considered an
1459 indication that there will be more to do. Only when no chip
1460 has any work does this outermost loop exit.
1461 */
1462 do {
1463 had_work = 0;
1464 for (chip = 0; chip < cinfo->num_chips; chip++) {
1465 base_addr = cinfo->base_addr +
1466 (cy_chip_offset[chip] << index);
1467 too_many = 0;
1468 while ((status = cy_readb(base_addr +
1469 (CySVRR << index))) != 0x00) {
1470 had_work++;
1471 /* The purpose of the following test is to ensure that
1472 no chip can monopolize the driver. This forces the
1473 chips to be checked in a round-robin fashion (after
1474 draining each of a bunch (1000) of characters).
1475 */
1476 if (1000 < too_many++) {
1477 break;
1478 }
1479 cyy_intr_chip(cinfo, chip, base_addr, status,
1480 index);
1386 } 1481 }
1482 }
1483 } while (had_work);
1387 1484
1388 if((mdm_change & CyDCD) 1485 /* clear interrupts */
1389 && (info->flags & ASYNC_CHECK_CD)){ 1486 spin_lock(&cinfo->card_lock);
1390 if(mdm_status & CyDCD){ 1487 cy_writeb(card_base_addr + (Cy_ClrIntr << index), 0);
1391 cy_sched_event(info, 1488 /* Cy_ClrIntr is 0x1800 */
1392 Cy_EVENT_OPEN_WAKEUP); 1489 spin_unlock(&cinfo->card_lock);
1393 }else{ 1490 return IRQ_HANDLED;
1394 cy_sched_event(info, 1491} /* cyy_interrupt */
1395 Cy_EVENT_HANGUP);
1396 }
1397 }
1398 if((mdm_change & CyCTS)
1399 && (info->flags & ASYNC_CTS_FLOW)){
1400 if(info->tty->hw_stopped){
1401 if(mdm_status & CyCTS){
1402 /* cy_start isn't used
1403 because... !!! */
1404 info->tty->hw_stopped = 0;
1405 cy_writeb(base_addr+(CySRER<<index),
1406 cy_readb(base_addr+(CySRER<<index)) |
1407 CyTxRdy);
1408 cy_sched_event(info,
1409 Cy_EVENT_WRITE_WAKEUP);
1410 }
1411 }else{
1412 if(!(mdm_status & CyCTS)){
1413 /* cy_stop isn't used
1414 because ... !!! */
1415 info->tty->hw_stopped = 1;
1416 cy_writeb(base_addr+(CySRER<<index),
1417 cy_readb(base_addr+(CySRER<<index)) &
1418 ~CyTxRdy);
1419 }
1420 }
1421 }
1422 if(mdm_change & CyDSR){
1423 }
1424 if(mdm_change & CyRI){
1425 }
1426 }
1427 /* end of service */
1428 cy_writeb(base_addr+(CyMIR<<index),
1429 (save_xir & 0x3f));
1430 cy_writeb(base_addr+(CyCAR<<index), save_car);
1431 spin_unlock(&cinfo->card_lock);
1432 }
1433 } /* end while status != 0 */
1434 } /* end loop for chips... */
1435 } while(had_work);
1436
1437 /* clear interrupts */
1438 spin_lock(&cinfo->card_lock);
1439 cy_writeb(card_base_addr + (Cy_ClrIntr<<index), 0);
1440 /* Cy_ClrIntr is 0x1800 */
1441 spin_unlock(&cinfo->card_lock);
1442 return IRQ_HANDLED;
1443} /* cyy_interrupt */
1444 1492
1445/***********************************************************/ 1493/***********************************************************/
1446/********* End of block of Cyclom-Y specific code **********/ 1494/********* End of block of Cyclom-Y specific code **********/
@@ -1448,643 +1496,655 @@ cyy_interrupt(int irq, void *dev_id)
1448/***********************************************************/ 1496/***********************************************************/
1449 1497
1450static int 1498static int
1451cyz_fetch_msg( struct cyclades_card *cinfo, 1499cyz_fetch_msg(struct cyclades_card *cinfo,
1452 uclong *channel, ucchar *cmd, uclong *param) 1500 uclong * channel, ucchar * cmd, uclong * param)
1453{ 1501{
1454 struct FIRM_ID __iomem *firm_id; 1502 struct FIRM_ID __iomem *firm_id;
1455 struct ZFW_CTRL __iomem *zfw_ctrl; 1503 struct ZFW_CTRL __iomem *zfw_ctrl;
1456 struct BOARD_CTRL __iomem *board_ctrl; 1504 struct BOARD_CTRL __iomem *board_ctrl;
1457 unsigned long loc_doorbell; 1505 unsigned long loc_doorbell;
1458 1506
1459 firm_id = cinfo->base_addr + ID_ADDRESS; 1507 firm_id = cinfo->base_addr + ID_ADDRESS;
1460 if (!ISZLOADED(*cinfo)){ 1508 if (!ISZLOADED(*cinfo)) {
1461 return (-1); 1509 return -1;
1462 } 1510 }
1463 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1511 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1464 board_ctrl = &zfw_ctrl->board_ctrl; 1512 0xfffff);
1465 1513 board_ctrl = &zfw_ctrl->board_ctrl;
1466 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *) 1514
1467 (cinfo->ctl_addr))->loc_doorbell); 1515 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *)
1468 if (loc_doorbell){ 1516 (cinfo->ctl_addr))->loc_doorbell);
1469 *cmd = (char)(0xff & loc_doorbell); 1517 if (loc_doorbell) {
1470 *channel = cy_readl(&board_ctrl->fwcmd_channel); 1518 *cmd = (char)(0xff & loc_doorbell);
1471 *param = (uclong)cy_readl(&board_ctrl->fwcmd_param); 1519 *channel = cy_readl(&board_ctrl->fwcmd_channel);
1472 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->loc_doorbell, 1520 *param = (uclong) cy_readl(&board_ctrl->fwcmd_param);
1473 0xffffffff); 1521 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1474 return 1; 1522 loc_doorbell, 0xffffffff);
1475 } 1523 return 1;
1476 return 0; 1524 }
1477} /* cyz_fetch_msg */ 1525 return 0;
1526} /* cyz_fetch_msg */
1478 1527
1479static int 1528static int
1480cyz_issue_cmd( struct cyclades_card *cinfo, 1529cyz_issue_cmd(struct cyclades_card *cinfo,
1481 uclong channel, ucchar cmd, uclong param) 1530 uclong channel, ucchar cmd, uclong param)
1482{ 1531{
1483 struct FIRM_ID __iomem *firm_id; 1532 struct FIRM_ID __iomem *firm_id;
1484 struct ZFW_CTRL __iomem *zfw_ctrl; 1533 struct ZFW_CTRL __iomem *zfw_ctrl;
1485 struct BOARD_CTRL __iomem *board_ctrl; 1534 struct BOARD_CTRL __iomem *board_ctrl;
1486 unsigned long __iomem *pci_doorbell; 1535 unsigned long __iomem *pci_doorbell;
1487 int index; 1536 int index;
1488 1537
1489 firm_id = cinfo->base_addr + ID_ADDRESS; 1538 firm_id = cinfo->base_addr + ID_ADDRESS;
1490 if (!ISZLOADED(*cinfo)){ 1539 if (!ISZLOADED(*cinfo)) {
1491 return (-1); 1540 return -1;
1492 } 1541 }
1493 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1542 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1494 board_ctrl = &zfw_ctrl->board_ctrl; 1543 0xfffff);
1495 1544 board_ctrl = &zfw_ctrl->board_ctrl;
1496 index = 0; 1545
1497 pci_doorbell = &((struct RUNTIME_9060 __iomem *) (cinfo->ctl_addr))->pci_doorbell; 1546 index = 0;
1498 while( (cy_readl(pci_doorbell) & 0xff) != 0){ 1547 pci_doorbell =
1499 if (index++ == 1000){ 1548 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1500 return((int)(cy_readl(pci_doorbell) & 0xff)); 1549 while ((cy_readl(pci_doorbell) & 0xff) != 0) {
1501 } 1550 if (index++ == 1000) {
1502 udelay(50L); 1551 return (int)(cy_readl(pci_doorbell) & 0xff);
1503 } 1552 }
1504 cy_writel(&board_ctrl->hcmd_channel, channel); 1553 udelay(50L);
1505 cy_writel(&board_ctrl->hcmd_param , param); 1554 }
1506 cy_writel(pci_doorbell, (long)cmd); 1555 cy_writel(&board_ctrl->hcmd_channel, channel);
1507 1556 cy_writel(&board_ctrl->hcmd_param, param);
1508 return(0); 1557 cy_writel(pci_doorbell, (long)cmd);
1509} /* cyz_issue_cmd */ 1558
1559 return 0;
1560} /* cyz_issue_cmd */
1510 1561
1511static void 1562static void
1512cyz_handle_rx(struct cyclades_port *info, 1563cyz_handle_rx(struct cyclades_port *info,
1513 volatile struct CH_CTRL __iomem *ch_ctrl, 1564 volatile struct CH_CTRL __iomem * ch_ctrl,
1514 volatile struct BUF_CTRL __iomem *buf_ctrl) 1565 volatile struct BUF_CTRL __iomem * buf_ctrl)
1515{ 1566{
1516 struct cyclades_card *cinfo = &cy_card[info->card]; 1567 struct cyclades_card *cinfo = &cy_card[info->card];
1517 struct tty_struct *tty = info->tty; 1568 struct tty_struct *tty = info->tty;
1518 volatile int char_count; 1569 volatile int char_count;
1519 int len; 1570 int len;
1520#ifdef BLOCKMOVE 1571#ifdef BLOCKMOVE
1521 int small_count; 1572 int small_count;
1522#else 1573#else
1523 char data; 1574 char data;
1524#endif 1575#endif
1525 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr; 1576 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
1526 1577
1527 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get); 1578 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get);
1528 rx_put = cy_readl(&buf_ctrl->rx_put); 1579 rx_put = cy_readl(&buf_ctrl->rx_put);
1529 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize); 1580 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
1530 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr); 1581 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr);
1531 if (rx_put >= rx_get) 1582 if (rx_put >= rx_get)
1532 char_count = rx_put - rx_get; 1583 char_count = rx_put - rx_get;
1533 else 1584 else
1534 char_count = rx_put - rx_get + rx_bufsize; 1585 char_count = rx_put - rx_get + rx_bufsize;
1535 1586
1536 if ( char_count ) { 1587 if (char_count) {
1537 info->last_active = jiffies; 1588 info->last_active = jiffies;
1538 info->jiffies[1] = jiffies; 1589 info->jiffies[1] = jiffies;
1539 1590
1540#ifdef CY_ENABLE_MONITORING 1591#ifdef CY_ENABLE_MONITORING
1541 info->mon.int_count++; 1592 info->mon.int_count++;
1542 info->mon.char_count += char_count; 1593 info->mon.char_count += char_count;
1543 if (char_count > info->mon.char_max) 1594 if (char_count > info->mon.char_max)
1544 info->mon.char_max = char_count; 1595 info->mon.char_max = char_count;
1545 info->mon.char_last = char_count; 1596 info->mon.char_last = char_count;
1546#endif 1597#endif
1547 if(tty == 0){ 1598 if (tty == 0) {
1548 /* flush received characters */ 1599 /* flush received characters */
1549 new_rx_get = (new_rx_get + char_count) & (rx_bufsize - 1); 1600 new_rx_get = (new_rx_get + char_count) &
1550 info->rflush_count++; 1601 (rx_bufsize - 1);
1551 }else{ 1602 info->rflush_count++;
1603 } else {
1552#ifdef BLOCKMOVE 1604#ifdef BLOCKMOVE
1553 /* we'd like to use memcpy(t, f, n) and memset(s, c, count) 1605 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1554 for performance, but because of buffer boundaries, there 1606 for performance, but because of buffer boundaries, there
1555 may be several steps to the operation */ 1607 may be several steps to the operation */
1556 while(0 < (small_count = 1608 while (0 < (small_count = min_t(unsigned int,
1557 min_t(unsigned int, (rx_bufsize - new_rx_get), 1609 rx_bufsize - new_rx_get,
1558 min_t(unsigned int, (TTY_FLIPBUF_SIZE - tty->flip.count), char_count)) 1610 min_t(unsigned int, TTY_FLIPBUF_SIZE -
1559 )) { 1611 tty->flip.count, char_count)))){
1560 memcpy_fromio(tty->flip.char_buf_ptr, 1612 memcpy_fromio(tty->flip.char_buf_ptr,
1561 (char *)(cinfo->base_addr 1613 (char *)(cinfo->base_addr + rx_bufaddr +
1562 + rx_bufaddr + new_rx_get), 1614 new_rx_get),
1563 small_count); 1615 small_count);
1564 1616
1565 tty->flip.char_buf_ptr += small_count; 1617 tty->flip.char_buf_ptr += small_count;
1566 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, small_count); 1618 memset(tty->flip.flag_buf_ptr, TTY_NORMAL,
1567 tty->flip.flag_buf_ptr += small_count; 1619 small_count);
1568 new_rx_get = (new_rx_get + small_count) & (rx_bufsize - 1); 1620 tty->flip.flag_buf_ptr += small_count;
1569 char_count -= small_count; 1621 new_rx_get = (new_rx_get + small_count) &
1570 info->icount.rx += small_count; 1622 (rx_bufsize - 1);
1571 info->idle_stats.recv_bytes += small_count; 1623 char_count -= small_count;
1572 tty->flip.count += small_count; 1624 info->icount.rx += small_count;
1573 } 1625 info->idle_stats.recv_bytes += small_count;
1626 tty->flip.count += small_count;
1627 }
1574#else 1628#else
1575 len = tty_buffer_request_room(tty, char_count); 1629 len = tty_buffer_request_room(tty, char_count);
1576 while(len--){ 1630 while (len--) {
1577 data = cy_readb(cinfo->base_addr + rx_bufaddr + new_rx_get); 1631 data = cy_readb(cinfo->base_addr + rx_bufaddr +
1578 new_rx_get = (new_rx_get + 1) & (rx_bufsize - 1); 1632 new_rx_get);
1579 tty_insert_flip_char(tty, data, TTY_NORMAL); 1633 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
1580 info->idle_stats.recv_bytes++; 1634 tty_insert_flip_char(tty, data, TTY_NORMAL);
1581 info->icount.rx++; 1635 info->idle_stats.recv_bytes++;
1582 } 1636 info->icount.rx++;
1637 }
1583#endif 1638#endif
1584#ifdef CONFIG_CYZ_INTR 1639#ifdef CONFIG_CYZ_INTR
1585 /* Recalculate the number of chars in the RX buffer and issue 1640 /* Recalculate the number of chars in the RX buffer and issue
1586 a cmd in case it's higher than the RX high water mark */ 1641 a cmd in case it's higher than the RX high water mark */
1587 rx_put = cy_readl(&buf_ctrl->rx_put); 1642 rx_put = cy_readl(&buf_ctrl->rx_put);
1588 if (rx_put >= rx_get) 1643 if (rx_put >= rx_get)
1589 char_count = rx_put - rx_get; 1644 char_count = rx_put - rx_get;
1590 else 1645 else
1591 char_count = rx_put - rx_get + rx_bufsize; 1646 char_count = rx_put - rx_get + rx_bufsize;
1592 if(char_count >= cy_readl(&buf_ctrl->rx_threshold)) { 1647 if (char_count >= (int)cy_readl(&buf_ctrl->
1593 cy_sched_event(info, Cy_EVENT_Z_RX_FULL); 1648 rx_threshold)) {
1594 } 1649 cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
1650 }
1595#endif 1651#endif
1596 info->idle_stats.recv_idle = jiffies; 1652 info->idle_stats.recv_idle = jiffies;
1597 tty_schedule_flip(tty); 1653 tty_schedule_flip(tty);
1654 }
1655 /* Update rx_get */
1656 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1598 } 1657 }
1599 /* Update rx_get */
1600 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1601 }
1602} 1658}
1603 1659
1604static void 1660static void
1605cyz_handle_tx(struct cyclades_port *info, 1661cyz_handle_tx(struct cyclades_port *info,
1606 volatile struct CH_CTRL __iomem *ch_ctrl, 1662 volatile struct CH_CTRL __iomem * ch_ctrl,
1607 volatile struct BUF_CTRL __iomem *buf_ctrl) 1663 volatile struct BUF_CTRL __iomem * buf_ctrl)
1608{ 1664{
1609 struct cyclades_card *cinfo = &cy_card[info->card]; 1665 struct cyclades_card *cinfo = &cy_card[info->card];
1610 struct tty_struct *tty = info->tty; 1666 struct tty_struct *tty = info->tty;
1611 char data; 1667 char data;
1612 volatile int char_count; 1668 volatile int char_count;
1613#ifdef BLOCKMOVE 1669#ifdef BLOCKMOVE
1614 int small_count; 1670 int small_count;
1615#endif 1671#endif
1616 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr; 1672 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr;
1617 1673
1618 if (info->xmit_cnt <= 0) /* Nothing to transmit */ 1674 if (info->xmit_cnt <= 0) /* Nothing to transmit */
1619 return; 1675 return;
1620 1676
1621 tx_get = cy_readl(&buf_ctrl->tx_get); 1677 tx_get = cy_readl(&buf_ctrl->tx_get);
1622 tx_put = cy_readl(&buf_ctrl->tx_put); 1678 tx_put = cy_readl(&buf_ctrl->tx_put);
1623 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 1679 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
1624 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr); 1680 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr);
1625 if (tx_put >= tx_get) 1681 if (tx_put >= tx_get)
1626 char_count = tx_get - tx_put - 1 + tx_bufsize; 1682 char_count = tx_get - tx_put - 1 + tx_bufsize;
1627 else 1683 else
1628 char_count = tx_get - tx_put - 1; 1684 char_count = tx_get - tx_put - 1;
1629 1685
1630 if ( char_count ) { 1686 if (char_count) {
1631 1687
1632 if( tty == 0 ){ 1688 if (tty == 0) {
1633 goto ztxdone; 1689 goto ztxdone;
1634 } 1690 }
1635 1691
1636 if(info->x_char) { /* send special char */ 1692 if (info->x_char) { /* send special char */
1637 data = info->x_char; 1693 data = info->x_char;
1638 1694
1639 cy_writeb((cinfo->base_addr + tx_bufaddr + tx_put), data); 1695 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1640 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1696 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1641 info->x_char = 0; 1697 info->x_char = 0;
1642 char_count--; 1698 char_count--;
1643 info->icount.tx++; 1699 info->icount.tx++;
1644 info->last_active = jiffies; 1700 info->last_active = jiffies;
1645 info->jiffies[2] = jiffies; 1701 info->jiffies[2] = jiffies;
1646 } 1702 }
1647#ifdef BLOCKMOVE 1703#ifdef BLOCKMOVE
1648 while(0 < (small_count = 1704 while (0 < (small_count = min_t(unsigned int,
1649 min_t(unsigned int, (tx_bufsize - tx_put), 1705 tx_bufsize - tx_put, min_t(unsigned int,
1650 min_t(unsigned int, (SERIAL_XMIT_SIZE - info->xmit_tail), 1706 (SERIAL_XMIT_SIZE - info->xmit_tail),
1651 min_t(unsigned int, info->xmit_cnt, char_count))))) { 1707 min_t(unsigned int, info->xmit_cnt,
1652 1708 char_count))))) {
1653 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr + tx_put), 1709
1654 &info->xmit_buf[info->xmit_tail], 1710 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr +
1655 small_count); 1711 tx_put),
1656 1712 &info->xmit_buf[info->xmit_tail],
1657 tx_put = (tx_put + small_count) & (tx_bufsize - 1); 1713 small_count);
1658 char_count -= small_count; 1714
1659 info->icount.tx += small_count; 1715 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1660 info->xmit_cnt -= small_count; 1716 char_count -= small_count;
1661 info->xmit_tail = 1717 info->icount.tx += small_count;
1662 (info->xmit_tail + small_count) & (SERIAL_XMIT_SIZE - 1); 1718 info->xmit_cnt -= small_count;
1663 info->last_active = jiffies; 1719 info->xmit_tail = (info->xmit_tail + small_count) &
1664 info->jiffies[2] = jiffies; 1720 (SERIAL_XMIT_SIZE - 1);
1665 } 1721 info->last_active = jiffies;
1722 info->jiffies[2] = jiffies;
1723 }
1666#else 1724#else
1667 while (info->xmit_cnt && char_count){ 1725 while (info->xmit_cnt && char_count) {
1668 data = info->xmit_buf[info->xmit_tail]; 1726 data = info->xmit_buf[info->xmit_tail];
1669 info->xmit_cnt--; 1727 info->xmit_cnt--;
1670 info->xmit_tail = (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1); 1728 info->xmit_tail = (info->xmit_tail + 1) &
1671 1729 (SERIAL_XMIT_SIZE - 1);
1672 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data); 1730
1673 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1731 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1674 char_count--; 1732 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1675 info->icount.tx++; 1733 char_count--;
1676 info->last_active = jiffies; 1734 info->icount.tx++;
1677 info->jiffies[2] = jiffies; 1735 info->last_active = jiffies;
1678 } 1736 info->jiffies[2] = jiffies;
1737 }
1679#endif 1738#endif
1680 ztxdone: 1739ztxdone:
1681 if (info->xmit_cnt < WAKEUP_CHARS) { 1740 if (info->xmit_cnt < WAKEUP_CHARS) {
1682 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1741 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1742 }
1743 /* Update tx_put */
1744 cy_writel(&buf_ctrl->tx_put, tx_put);
1683 } 1745 }
1684 /* Update tx_put */
1685 cy_writel(&buf_ctrl->tx_put, tx_put);
1686 }
1687} 1746}
1688 1747
1689static void 1748static void cyz_handle_cmd(struct cyclades_card *cinfo)
1690cyz_handle_cmd(struct cyclades_card *cinfo)
1691{ 1749{
1692 struct tty_struct *tty; 1750 struct tty_struct *tty;
1693 struct cyclades_port *info; 1751 struct cyclades_port *info;
1694 static volatile struct FIRM_ID __iomem *firm_id; 1752 static volatile struct FIRM_ID __iomem *firm_id;
1695 static volatile struct ZFW_CTRL __iomem *zfw_ctrl; 1753 static volatile struct ZFW_CTRL __iomem *zfw_ctrl;
1696 static volatile struct BOARD_CTRL __iomem *board_ctrl; 1754 static volatile struct BOARD_CTRL __iomem *board_ctrl;
1697 static volatile struct CH_CTRL __iomem *ch_ctrl; 1755 static volatile struct CH_CTRL __iomem *ch_ctrl;
1698 static volatile struct BUF_CTRL __iomem *buf_ctrl; 1756 static volatile struct BUF_CTRL __iomem *buf_ctrl;
1699 uclong channel; 1757 uclong channel;
1700 ucchar cmd; 1758 ucchar cmd;
1701 uclong param; 1759 uclong param;
1702 uclong hw_ver, fw_ver; 1760 uclong hw_ver, fw_ver;
1703 int special_count; 1761 int special_count;
1704 int delta_count; 1762 int delta_count;
1705 1763
1706 firm_id = cinfo->base_addr + ID_ADDRESS; 1764 firm_id = cinfo->base_addr + ID_ADDRESS;
1707 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1765 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1708 board_ctrl = &zfw_ctrl->board_ctrl; 1766 0xfffff);
1709 fw_ver = cy_readl(&board_ctrl->fw_version); 1767 board_ctrl = &zfw_ctrl->board_ctrl;
1710 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->mail_box_0); 1768 fw_ver = cy_readl(&board_ctrl->fw_version);
1711 1769 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1712 1770 mail_box_0);
1713 while(cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1771
1714 special_count = 0; 1772 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1715 delta_count = 0; 1773 special_count = 0;
1716 info = &cy_port[channel + cinfo->first_line]; 1774 delta_count = 0;
1717 if((tty = info->tty) == 0) { 1775 info = &cy_port[channel + cinfo->first_line];
1718 continue; 1776 if ((tty = info->tty) == 0) {
1719 } 1777 continue;
1720 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1721 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1722
1723 switch(cmd) {
1724 case C_CM_PR_ERROR:
1725 tty_insert_flip_char(tty, 0, TTY_PARITY);
1726 info->icount.rx++;
1727 special_count++;
1728 break;
1729 case C_CM_FR_ERROR:
1730 tty_insert_flip_char(tty, 0, TTY_FRAME);
1731 info->icount.rx++;
1732 special_count++;
1733 break;
1734 case C_CM_RXBRK:
1735 tty_insert_flip_char(tty, 0, TTY_BREAK);
1736 info->icount.rx++;
1737 special_count++;
1738 break;
1739 case C_CM_MDCD:
1740 info->icount.dcd++;
1741 delta_count++;
1742 if (info->flags & ASYNC_CHECK_CD){
1743 if ((fw_ver > 241 ?
1744 ((u_long)param) :
1745 cy_readl(&ch_ctrl->rs_status)) & C_RS_DCD) {
1746 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
1747 }else{
1748 cy_sched_event(info, Cy_EVENT_HANGUP);
1749 }
1750 } 1778 }
1751 break; 1779 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1752 case C_CM_MCTS: 1780 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1753 info->icount.cts++; 1781
1754 delta_count++; 1782 switch (cmd) {
1755 break; 1783 case C_CM_PR_ERROR:
1756 case C_CM_MRI: 1784 tty_insert_flip_char(tty, 0, TTY_PARITY);
1757 info->icount.rng++; 1785 info->icount.rx++;
1758 delta_count++; 1786 special_count++;
1759 break; 1787 break;
1760 case C_CM_MDSR: 1788 case C_CM_FR_ERROR:
1761 info->icount.dsr++; 1789 tty_insert_flip_char(tty, 0, TTY_FRAME);
1762 delta_count++; 1790 info->icount.rx++;
1763 break; 1791 special_count++;
1792 break;
1793 case C_CM_RXBRK:
1794 tty_insert_flip_char(tty, 0, TTY_BREAK);
1795 info->icount.rx++;
1796 special_count++;
1797 break;
1798 case C_CM_MDCD:
1799 info->icount.dcd++;
1800 delta_count++;
1801 if (info->flags & ASYNC_CHECK_CD) {
1802 if ((fw_ver > 241 ? ((u_long) param) :
1803 cy_readl(&ch_ctrl->rs_status)) &
1804 C_RS_DCD) {
1805 cy_sched_event(info,
1806 Cy_EVENT_OPEN_WAKEUP);
1807 } else {
1808 cy_sched_event(info, Cy_EVENT_HANGUP);
1809 }
1810 }
1811 break;
1812 case C_CM_MCTS:
1813 info->icount.cts++;
1814 delta_count++;
1815 break;
1816 case C_CM_MRI:
1817 info->icount.rng++;
1818 delta_count++;
1819 break;
1820 case C_CM_MDSR:
1821 info->icount.dsr++;
1822 delta_count++;
1823 break;
1764#ifdef Z_WAKE 1824#ifdef Z_WAKE
1765 case C_CM_IOCTLW: 1825 case C_CM_IOCTLW:
1766 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP); 1826 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
1767 break; 1827 break;
1768#endif 1828#endif
1769#ifdef CONFIG_CYZ_INTR 1829#ifdef CONFIG_CYZ_INTR
1770 case C_CM_RXHIWM: 1830 case C_CM_RXHIWM:
1771 case C_CM_RXNNDT: 1831 case C_CM_RXNNDT:
1772 case C_CM_INTBACK2: 1832 case C_CM_INTBACK2:
1773 /* Reception Interrupt */ 1833 /* Reception Interrupt */
1774#ifdef CY_DEBUG_INTERRUPTS 1834#ifdef CY_DEBUG_INTERRUPTS
1775 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r", 1835 printk("cyz_interrupt: rcvd intr, card %d, "
1776 info->card, channel); 1836 "port %ld\n\r", info->card, channel);
1777#endif 1837#endif
1778 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1838 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1779 break; 1839 break;
1780 case C_CM_TXBEMPTY: 1840 case C_CM_TXBEMPTY:
1781 case C_CM_TXLOWWM: 1841 case C_CM_TXLOWWM:
1782 case C_CM_INTBACK: 1842 case C_CM_INTBACK:
1783 /* Transmission Interrupt */ 1843 /* Transmission Interrupt */
1784#ifdef CY_DEBUG_INTERRUPTS 1844#ifdef CY_DEBUG_INTERRUPTS
1785 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r", 1845 printk("cyz_interrupt: xmit intr, card %d, "
1786 info->card, channel); 1846 "port %ld\n\r", info->card, channel);
1787#endif 1847#endif
1788 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1848 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1789 break; 1849 break;
1790#endif /* CONFIG_CYZ_INTR */ 1850#endif /* CONFIG_CYZ_INTR */
1791 case C_CM_FATAL: 1851 case C_CM_FATAL:
1792 /* should do something with this !!! */ 1852 /* should do something with this !!! */
1793 break; 1853 break;
1794 default: 1854 default:
1795 break; 1855 break;
1856 }
1857 if (delta_count)
1858 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1859 if (special_count)
1860 tty_schedule_flip(tty);
1796 } 1861 }
1797 if(delta_count)
1798 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1799 if(special_count)
1800 tty_schedule_flip(tty);
1801 }
1802} 1862}
1803 1863
1804#ifdef CONFIG_CYZ_INTR 1864#ifdef CONFIG_CYZ_INTR
1805static irqreturn_t 1865static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1806cyz_interrupt(int irq, void *dev_id)
1807{ 1866{
1808 struct cyclades_card *cinfo; 1867 struct cyclades_card *cinfo;
1809 1868
1810 if((cinfo = (struct cyclades_card *)dev_id) == 0){ 1869 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1811#ifdef CY_DEBUG_INTERRUPTS 1870#ifdef CY_DEBUG_INTERRUPTS
1812 printk("cyz_interrupt: spurious interrupt %d\n\r", irq); 1871 printk("cyz_interrupt: spurious interrupt %d\n\r", irq);
1813#endif 1872#endif
1814 return IRQ_NONE; /* spurious interrupt */ 1873 return IRQ_NONE; /* spurious interrupt */
1815 } 1874 }
1816 1875
1817 if (!ISZLOADED(*cinfo)) { 1876 if (!ISZLOADED(*cinfo)) {
1818#ifdef CY_DEBUG_INTERRUPTS 1877#ifdef CY_DEBUG_INTERRUPTS
1819 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq); 1878 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq);
1820#endif 1879#endif
1821 return IRQ_NONE; 1880 return IRQ_NONE;
1822 } 1881 }
1823 1882
1824 /* Handle the interrupts */ 1883 /* Handle the interrupts */
1825 cyz_handle_cmd(cinfo); 1884 cyz_handle_cmd(cinfo);
1826 1885
1827 return IRQ_HANDLED; 1886 return IRQ_HANDLED;
1828} /* cyz_interrupt */ 1887} /* cyz_interrupt */
1829 1888
1830static void 1889static void cyz_rx_restart(unsigned long arg)
1831cyz_rx_restart(unsigned long arg)
1832{ 1890{
1833 struct cyclades_port *info = (struct cyclades_port *)arg; 1891 struct cyclades_port *info = (struct cyclades_port *)arg;
1834 int retval; 1892 int retval;
1835 int card = info->card; 1893 int card = info->card;
1836 uclong channel = (info->line) - (cy_card[card].first_line); 1894 uclong channel = (info->line) - (cy_card[card].first_line);
1837 unsigned long flags; 1895 unsigned long flags;
1838 1896
1839 CY_LOCK(info, flags); 1897 CY_LOCK(info, flags);
1840 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L); 1898 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L);
1841 if (retval != 0){ 1899 if (retval != 0) {
1842 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n", 1900 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1843 info->line, retval); 1901 info->line, retval);
1844 } 1902 }
1845 cyz_rx_full_timer[info->line].function = NULL; 1903 cyz_rx_full_timer[info->line].function = NULL;
1846 CY_UNLOCK(info, flags); 1904 CY_UNLOCK(info, flags);
1847} 1905}
1848 1906
1849#else /* CONFIG_CYZ_INTR */ 1907#else /* CONFIG_CYZ_INTR */
1850 1908
1851static void 1909static void cyz_poll(unsigned long arg)
1852cyz_poll(unsigned long arg)
1853{ 1910{
1854 struct cyclades_card *cinfo; 1911 struct cyclades_card *cinfo;
1855 struct cyclades_port *info; 1912 struct cyclades_port *info;
1856 struct tty_struct *tty; 1913 struct tty_struct *tty;
1857 static volatile struct FIRM_ID *firm_id; 1914 static volatile struct FIRM_ID *firm_id;
1858 static volatile struct ZFW_CTRL *zfw_ctrl; 1915 static volatile struct ZFW_CTRL *zfw_ctrl;
1859 static volatile struct BOARD_CTRL *board_ctrl; 1916 static volatile struct BOARD_CTRL *board_ctrl;
1860 static volatile struct CH_CTRL *ch_ctrl; 1917 static volatile struct CH_CTRL *ch_ctrl;
1861 static volatile struct BUF_CTRL *buf_ctrl; 1918 static volatile struct BUF_CTRL *buf_ctrl;
1862 int card, port; 1919 int card, port;
1863
1864 cyz_timerlist.expires = jiffies + (HZ);
1865 for (card = 0 ; card < NR_CARDS ; card++){
1866 cinfo = &cy_card[card];
1867
1868 if (!IS_CYC_Z(*cinfo)) continue;
1869 if (!ISZLOADED(*cinfo)) continue;
1870 1920
1871 firm_id = cinfo->base_addr + ID_ADDRESS; 1921 cyz_timerlist.expires = jiffies + (HZ);
1872 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1922 for (card = 0; card < NR_CARDS; card++) {
1873 board_ctrl = &(zfw_ctrl->board_ctrl); 1923 cinfo = &cy_card[card];
1924
1925 if (!IS_CYC_Z(*cinfo))
1926 continue;
1927 if (!ISZLOADED(*cinfo))
1928 continue;
1929
1930 firm_id = cinfo->base_addr + ID_ADDRESS;
1931 zfw_ctrl = cinfo->base_addr +
1932 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
1933 board_ctrl = &(zfw_ctrl->board_ctrl);
1874 1934
1875 /* Skip first polling cycle to avoid racing conditions with the FW */ 1935 /* Skip first polling cycle to avoid racing conditions with the FW */
1876 if (!cinfo->intr_enabled) { 1936 if (!cinfo->intr_enabled) {
1877 cinfo->nports = (int) cy_readl(&board_ctrl->n_channel); 1937 cinfo->nports = (int)cy_readl(&board_ctrl->n_channel);
1878 cinfo->intr_enabled = 1; 1938 cinfo->intr_enabled = 1;
1879 continue; 1939 continue;
1880 } 1940 }
1881 1941
1882 cyz_handle_cmd(cinfo); 1942 cyz_handle_cmd(cinfo);
1883 1943
1884 for (port = 0 ; port < cinfo->nports ; port++) { 1944 for (port = 0; port < cinfo->nports; port++) {
1885 info = &cy_port[ port + cinfo->first_line ]; 1945 info = &cy_port[port + cinfo->first_line];
1886 tty = info->tty; 1946 tty = info->tty;
1887 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]); 1947 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1888 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]); 1948 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
1889 1949
1890 if (!info->throttle) 1950 if (!info->throttle)
1891 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1951 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1892 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1952 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1953 }
1954 /* poll every 'cyz_polling_cycle' period */
1955 cyz_timerlist.expires = jiffies + cyz_polling_cycle;
1893 } 1956 }
1894 /* poll every 'cyz_polling_cycle' period */ 1957 add_timer(&cyz_timerlist);
1895 cyz_timerlist.expires = jiffies + cyz_polling_cycle; 1958} /* cyz_poll */
1896 }
1897 add_timer(&cyz_timerlist);
1898 1959
1899 return; 1960#endif /* CONFIG_CYZ_INTR */
1900} /* cyz_poll */
1901
1902#endif /* CONFIG_CYZ_INTR */
1903 1961
1904/********** End of block of Cyclades-Z specific code *********/ 1962/********** End of block of Cyclades-Z specific code *********/
1905/***********************************************************/ 1963/***********************************************************/
1906 1964
1907
1908/* This is called whenever a port becomes active; 1965/* This is called whenever a port becomes active;
1909 interrupts are enabled and DTR & RTS are turned on. 1966 interrupts are enabled and DTR & RTS are turned on.
1910 */ 1967 */
1911static int 1968static int startup(struct cyclades_port *info)
1912startup(struct cyclades_port * info)
1913{ 1969{
1914 unsigned long flags; 1970 unsigned long flags;
1915 int retval = 0; 1971 int retval = 0;
1916 void __iomem *base_addr; 1972 void __iomem *base_addr;
1917 int card,chip,channel,index; 1973 int card, chip, channel, index;
1918 unsigned long page; 1974 unsigned long page;
1919 1975
1920 card = info->card; 1976 card = info->card;
1921 channel = (info->line) - (cy_card[card].first_line); 1977 channel = (info->line) - (cy_card[card].first_line);
1922 1978
1923 page = get_zeroed_page(GFP_KERNEL); 1979 page = get_zeroed_page(GFP_KERNEL);
1924 if (!page) 1980 if (!page)
1925 return -ENOMEM; 1981 return -ENOMEM;
1926 1982
1927 CY_LOCK(info, flags); 1983 CY_LOCK(info, flags);
1928 1984
1929 if (info->flags & ASYNC_INITIALIZED){ 1985 if (info->flags & ASYNC_INITIALIZED) {
1930 free_page(page); 1986 free_page(page);
1931 goto errout; 1987 goto errout;
1932 } 1988 }
1933 1989
1934 if (!info->type){ 1990 if (!info->type) {
1935 if (info->tty){ 1991 if (info->tty) {
1936 set_bit(TTY_IO_ERROR, &info->tty->flags); 1992 set_bit(TTY_IO_ERROR, &info->tty->flags);
1937 } 1993 }
1938 free_page(page); 1994 free_page(page);
1939 goto errout; 1995 goto errout;
1940 } 1996 }
1941 1997
1942 if (info->xmit_buf) 1998 if (info->xmit_buf)
1943 free_page(page); 1999 free_page(page);
1944 else 2000 else
1945 info->xmit_buf = (unsigned char *) page; 2001 info->xmit_buf = (unsigned char *)page;
1946 2002
1947 CY_UNLOCK(info, flags); 2003 CY_UNLOCK(info, flags);
1948 2004
1949 set_line_char(info); 2005 set_line_char(info);
1950 2006
1951 if (!IS_CYC_Z(cy_card[card])) { 2007 if (!IS_CYC_Z(cy_card[card])) {
1952 chip = channel>>2; 2008 chip = channel >> 2;
1953 channel &= 0x03; 2009 channel &= 0x03;
1954 index = cy_card[card].bus_index; 2010 index = cy_card[card].bus_index;
1955 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2011 base_addr = cy_card[card].base_addr +
2012 (cy_chip_offset[chip] << index);
1956 2013
1957#ifdef CY_DEBUG_OPEN 2014#ifdef CY_DEBUG_OPEN
1958 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n", 2015 printk("cyc startup card %d, chip %d, channel %d, "
1959 card, chip, channel, (long)base_addr);/**/ 2016 "base_addr %lx\n",
2017 card, chip, channel, (long)base_addr);
2018 /**/
1960#endif 2019#endif
2020 CY_LOCK(info, flags);
1961 2021
1962 CY_LOCK(info, flags); 2022 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1963
1964 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
1965 2023
1966 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 2024 cy_writeb(base_addr + (CyRTPR << index),
1967 ? info->default_timeout : 0x02)); /* 10ms rx timeout */ 2025 (info->default_timeout ? info->default_timeout : 0x02));
2026 /* 10ms rx timeout */
1968 2027
1969 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR,index); 2028 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyENB_RCVR | CyENB_XMTR,
2029 index);
1970 2030
1971 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2031 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1972 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2032 cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
1973 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2033 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
1974 2034
1975#ifdef CY_DEBUG_DTR 2035#ifdef CY_DEBUG_DTR
1976 printk("cyc:startup raising DTR\n"); 2036 printk("cyc:startup raising DTR\n");
1977 printk(" status: 0x%x, 0x%x\n", 2037 printk(" status: 0x%x, 0x%x\n",
1978 cy_readb(base_addr+(CyMSVR1<<index)), 2038 cy_readb(base_addr + (CyMSVR1 << index)),
1979 cy_readb(base_addr+(CyMSVR2<<index))); 2039 cy_readb(base_addr + (CyMSVR2 << index)));
1980#endif 2040#endif
1981 2041
1982 cy_writeb(base_addr+(CySRER<<index), 2042 cy_writeb(base_addr + (CySRER << index),
1983 cy_readb(base_addr+(CySRER<<index)) | CyRxData); 2043 cy_readb(base_addr + (CySRER << index)) | CyRxData);
1984 info->flags |= ASYNC_INITIALIZED; 2044 info->flags |= ASYNC_INITIALIZED;
1985 2045
1986 if (info->tty){ 2046 if (info->tty) {
1987 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2047 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1988 } 2048 }
1989 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2049 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1990 info->breakon = info->breakoff = 0; 2050 info->breakon = info->breakoff = 0;
1991 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2051 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
1992 info->idle_stats.in_use = 2052 info->idle_stats.in_use =
1993 info->idle_stats.recv_idle = 2053 info->idle_stats.recv_idle =
1994 info->idle_stats.xmit_idle = jiffies; 2054 info->idle_stats.xmit_idle = jiffies;
1995 2055
1996 CY_UNLOCK(info, flags); 2056 CY_UNLOCK(info, flags);
1997 2057
1998 } else { 2058 } else {
1999 struct FIRM_ID __iomem *firm_id; 2059 struct FIRM_ID __iomem *firm_id;
2000 struct ZFW_CTRL __iomem *zfw_ctrl; 2060 struct ZFW_CTRL __iomem *zfw_ctrl;
2001 struct BOARD_CTRL __iomem *board_ctrl; 2061 struct BOARD_CTRL __iomem *board_ctrl;
2002 struct CH_CTRL __iomem *ch_ctrl; 2062 struct CH_CTRL __iomem *ch_ctrl;
2003 int retval; 2063 int retval;
2004 2064
2005 base_addr = cy_card[card].base_addr; 2065 base_addr = cy_card[card].base_addr;
2006 2066
2007 firm_id = base_addr + ID_ADDRESS; 2067 firm_id = base_addr + ID_ADDRESS;
2008 if (!ISZLOADED(cy_card[card])){ 2068 if (!ISZLOADED(cy_card[card])) {
2009 return -ENODEV; 2069 return -ENODEV;
2010 } 2070 }
2011 2071
2012 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2072 zfw_ctrl = cy_card[card].base_addr +
2013 board_ctrl = &zfw_ctrl->board_ctrl; 2073 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2014 ch_ctrl = zfw_ctrl->ch_ctrl; 2074 board_ctrl = &zfw_ctrl->board_ctrl;
2075 ch_ctrl = zfw_ctrl->ch_ctrl;
2015 2076
2016#ifdef CY_DEBUG_OPEN 2077#ifdef CY_DEBUG_OPEN
2017 printk("cyc startup Z card %d, channel %d, base_addr %lx\n", 2078 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2018 card, channel, (long)base_addr);/**/ 2079 card, channel, (long)base_addr);
2080 /**/
2019#endif 2081#endif
2082 CY_LOCK(info, flags);
2020 2083
2021 CY_LOCK(info, flags); 2084 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2022
2023 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2024#ifdef Z_WAKE 2085#ifdef Z_WAKE
2025#ifdef CONFIG_CYZ_INTR 2086#ifdef CONFIG_CYZ_INTR
2026 cy_writel(&ch_ctrl[channel].intr_enable, 2087 cy_writel(&ch_ctrl[channel].intr_enable,
2027 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2088 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2028 C_IN_IOCTLW| 2089 C_IN_RXNNDT | C_IN_IOCTLW | C_IN_MDCD);
2029 C_IN_MDCD);
2030#else 2090#else
2031 cy_writel(&ch_ctrl[channel].intr_enable, 2091 cy_writel(&ch_ctrl[channel].intr_enable,
2032 C_IN_IOCTLW| 2092 C_IN_IOCTLW | C_IN_MDCD);
2033 C_IN_MDCD); 2093#endif /* CONFIG_CYZ_INTR */
2034#endif /* CONFIG_CYZ_INTR */
2035#else 2094#else
2036#ifdef CONFIG_CYZ_INTR 2095#ifdef CONFIG_CYZ_INTR
2037 cy_writel(&ch_ctrl[channel].intr_enable, 2096 cy_writel(&ch_ctrl[channel].intr_enable,
2038 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2097 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2039 C_IN_MDCD); 2098 C_IN_RXNNDT | C_IN_MDCD);
2040#else 2099#else
2041 cy_writel(&ch_ctrl[channel].intr_enable, 2100 cy_writel(&ch_ctrl[channel].intr_enable, C_IN_MDCD);
2042 C_IN_MDCD); 2101#endif /* CONFIG_CYZ_INTR */
2043#endif /* CONFIG_CYZ_INTR */ 2102#endif /* Z_WAKE */
2044#endif /* Z_WAKE */ 2103
2045 2104 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
2046 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 2105 if (retval != 0) {
2047 if (retval != 0){ 2106 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2048 printk("cyc:startup(1) retval on ttyC%d was %x\n", 2107 info->line, retval);
2049 info->line, retval); 2108 }
2050 }
2051 2109
2052 /* Flush RX buffers before raising DTR and RTS */ 2110 /* Flush RX buffers before raising DTR and RTS */
2053 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX, 0L); 2111 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX,
2054 if (retval != 0){ 2112 0L);
2055 printk("cyc:startup(2) retval on ttyC%d was %x\n", 2113 if (retval != 0) {
2056 info->line, retval); 2114 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2057 } 2115 info->line, retval);
2116 }
2058 2117
2059 /* set timeout !!! */ 2118 /* set timeout !!! */
2060 /* set RTS and DTR !!! */ 2119 /* set RTS and DTR !!! */
2061 cy_writel(&ch_ctrl[channel].rs_control, 2120 cy_writel(&ch_ctrl[channel].rs_control,
2062 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR) ; 2121 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
2063 retval = cyz_issue_cmd(&cy_card[info->card], 2122 C_RS_DTR);
2064 channel, C_CM_IOCTLM, 0L); 2123 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2065 if (retval != 0){ 2124 C_CM_IOCTLM, 0L);
2066 printk("cyc:startup(3) retval on ttyC%d was %x\n", 2125 if (retval != 0) {
2067 info->line, retval); 2126 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2068 } 2127 info->line, retval);
2128 }
2069#ifdef CY_DEBUG_DTR 2129#ifdef CY_DEBUG_DTR
2070 printk("cyc:startup raising Z DTR\n"); 2130 printk("cyc:startup raising Z DTR\n");
2071#endif 2131#endif
2072 2132
2073 /* enable send, recv, modem !!! */ 2133 /* enable send, recv, modem !!! */
2074 2134
2075 info->flags |= ASYNC_INITIALIZED; 2135 info->flags |= ASYNC_INITIALIZED;
2076 if (info->tty){ 2136 if (info->tty) {
2077 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2137 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2078 } 2138 }
2079 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2139 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2080 info->breakon = info->breakoff = 0; 2140 info->breakon = info->breakoff = 0;
2081 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2141 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2082 info->idle_stats.in_use = 2142 info->idle_stats.in_use =
2083 info->idle_stats.recv_idle = 2143 info->idle_stats.recv_idle =
2084 info->idle_stats.xmit_idle = jiffies; 2144 info->idle_stats.xmit_idle = jiffies;
2085 2145
2086 CY_UNLOCK(info, flags); 2146 CY_UNLOCK(info, flags);
2087 } 2147 }
2088 2148
2089#ifdef CY_DEBUG_OPEN 2149#ifdef CY_DEBUG_OPEN
2090 printk(" cyc startup done\n"); 2150 printk(" cyc startup done\n");
@@ -2094,165 +2154,165 @@ startup(struct cyclades_port * info)
2094errout: 2154errout:
2095 CY_UNLOCK(info, flags); 2155 CY_UNLOCK(info, flags);
2096 return retval; 2156 return retval;
2097} /* startup */ 2157} /* startup */
2098
2099 2158
2100static void 2159static void start_xmit(struct cyclades_port *info)
2101start_xmit( struct cyclades_port *info )
2102{ 2160{
2103 unsigned long flags; 2161 unsigned long flags;
2104 void __iomem *base_addr; 2162 void __iomem *base_addr;
2105 int card,chip,channel,index; 2163 int card, chip, channel, index;
2106
2107 card = info->card;
2108 channel = (info->line) - (cy_card[card].first_line);
2109 if (!IS_CYC_Z(cy_card[card])) {
2110 chip = channel>>2;
2111 channel &= 0x03;
2112 index = cy_card[card].bus_index;
2113 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
2114 2164
2115 CY_LOCK(info, flags); 2165 card = info->card;
2116 cy_writeb(base_addr+(CyCAR<<index), channel); 2166 channel = (info->line) - (cy_card[card].first_line);
2117 cy_writeb(base_addr+(CySRER<<index), 2167 if (!IS_CYC_Z(cy_card[card])) {
2118 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy); 2168 chip = channel >> 2;
2119 CY_UNLOCK(info, flags); 2169 channel &= 0x03;
2120 } else { 2170 index = cy_card[card].bus_index;
2171 base_addr = cy_card[card].base_addr +
2172 (cy_chip_offset[chip] << index);
2173
2174 CY_LOCK(info, flags);
2175 cy_writeb(base_addr + (CyCAR << index), channel);
2176 cy_writeb(base_addr + (CySRER << index),
2177 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
2178 CY_UNLOCK(info, flags);
2179 } else {
2121#ifdef CONFIG_CYZ_INTR 2180#ifdef CONFIG_CYZ_INTR
2122 int retval; 2181 int retval;
2123 2182
2124 CY_LOCK(info, flags); 2183 CY_LOCK(info, flags);
2125 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK, 0L); 2184 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK,
2126 if (retval != 0){ 2185 0L);
2127 printk("cyc:start_xmit retval on ttyC%d was %x\n", 2186 if (retval != 0) {
2128 info->line, retval); 2187 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2129 } 2188 info->line, retval);
2130 CY_UNLOCK(info, flags); 2189 }
2131#else /* CONFIG_CYZ_INTR */ 2190 CY_UNLOCK(info, flags);
2132 /* Don't have to do anything at this time */ 2191#else /* CONFIG_CYZ_INTR */
2133#endif /* CONFIG_CYZ_INTR */ 2192 /* Don't have to do anything at this time */
2134 } 2193#endif /* CONFIG_CYZ_INTR */
2135} /* start_xmit */ 2194 }
2195} /* start_xmit */
2136 2196
2137/* 2197/*
2138 * This routine shuts down a serial port; interrupts are disabled, 2198 * This routine shuts down a serial port; interrupts are disabled,
2139 * and DTR is dropped if the hangup on close termio flag is on. 2199 * and DTR is dropped if the hangup on close termio flag is on.
2140 */ 2200 */
2141static void 2201static void shutdown(struct cyclades_port *info)
2142shutdown(struct cyclades_port * info)
2143{ 2202{
2144 unsigned long flags; 2203 unsigned long flags;
2145 void __iomem *base_addr; 2204 void __iomem *base_addr;
2146 int card,chip,channel,index; 2205 int card, chip, channel, index;
2147 2206
2148 if (!(info->flags & ASYNC_INITIALIZED)){ 2207 if (!(info->flags & ASYNC_INITIALIZED)) {
2149 return; 2208 return;
2150 } 2209 }
2151 2210
2152 card = info->card; 2211 card = info->card;
2153 channel = info->line - cy_card[card].first_line; 2212 channel = info->line - cy_card[card].first_line;
2154 if (!IS_CYC_Z(cy_card[card])) { 2213 if (!IS_CYC_Z(cy_card[card])) {
2155 chip = channel>>2; 2214 chip = channel >> 2;
2156 channel &= 0x03; 2215 channel &= 0x03;
2157 index = cy_card[card].bus_index; 2216 index = cy_card[card].bus_index;
2158 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2217 base_addr = cy_card[card].base_addr +
2218 (cy_chip_offset[chip] << index);
2159 2219
2160#ifdef CY_DEBUG_OPEN 2220#ifdef CY_DEBUG_OPEN
2161 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n", 2221 printk("cyc shutdown Y card %d, chip %d, channel %d, "
2162 card, chip, channel, (long)base_addr); 2222 "base_addr %lx\n",
2223 card, chip, channel, (long)base_addr);
2163#endif 2224#endif
2164 2225
2165 CY_LOCK(info, flags); 2226 CY_LOCK(info, flags);
2166 2227
2167 /* Clear delta_msr_wait queue to avoid mem leaks. */ 2228 /* Clear delta_msr_wait queue to avoid mem leaks. */
2168 wake_up_interruptible(&info->delta_msr_wait); 2229 wake_up_interruptible(&info->delta_msr_wait);
2169 2230
2170 if (info->xmit_buf){ 2231 if (info->xmit_buf) {
2171 unsigned char * temp; 2232 unsigned char *temp;
2172 temp = info->xmit_buf; 2233 temp = info->xmit_buf;
2173 info->xmit_buf = NULL; 2234 info->xmit_buf = NULL;
2174 free_page((unsigned long) temp); 2235 free_page((unsigned long)temp);
2175 } 2236 }
2176 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2237 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2177 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 2238 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2178 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 2239 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
2179 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 2240 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
2180#ifdef CY_DEBUG_DTR 2241#ifdef CY_DEBUG_DTR
2181 printk("cyc shutdown dropping DTR\n"); 2242 printk("cyc shutdown dropping DTR\n");
2182 printk(" status: 0x%x, 0x%x\n", 2243 printk(" status: 0x%x, 0x%x\n",
2183 cy_readb(base_addr+(CyMSVR1<<index)), 2244 cy_readb(base_addr + (CyMSVR1 << index)),
2184 cy_readb(base_addr+(CyMSVR2<<index))); 2245 cy_readb(base_addr + (CyMSVR2 << index)));
2185#endif 2246#endif
2186 } 2247 }
2187 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR,index); 2248 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
2188 /* it may be appropriate to clear _XMIT at 2249 /* it may be appropriate to clear _XMIT at
2189 some later date (after testing)!!! */ 2250 some later date (after testing)!!! */
2190 2251
2191 if (info->tty){ 2252 if (info->tty) {
2192 set_bit(TTY_IO_ERROR, &info->tty->flags); 2253 set_bit(TTY_IO_ERROR, &info->tty->flags);
2193 } 2254 }
2194 info->flags &= ~ASYNC_INITIALIZED; 2255 info->flags &= ~ASYNC_INITIALIZED;
2195 CY_UNLOCK(info, flags); 2256 CY_UNLOCK(info, flags);
2196 } else { 2257 } else {
2197 struct FIRM_ID __iomem *firm_id; 2258 struct FIRM_ID __iomem *firm_id;
2198 struct ZFW_CTRL __iomem *zfw_ctrl; 2259 struct ZFW_CTRL __iomem *zfw_ctrl;
2199 struct BOARD_CTRL __iomem *board_ctrl; 2260 struct BOARD_CTRL __iomem *board_ctrl;
2200 struct CH_CTRL __iomem *ch_ctrl; 2261 struct CH_CTRL __iomem *ch_ctrl;
2201 int retval; 2262 int retval;
2202 2263
2203 base_addr = cy_card[card].base_addr; 2264 base_addr = cy_card[card].base_addr;
2204#ifdef CY_DEBUG_OPEN 2265#ifdef CY_DEBUG_OPEN
2205 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n", 2266 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2206 card, channel, (long)base_addr); 2267 card, channel, (long)base_addr);
2207#endif 2268#endif
2208 2269
2209 firm_id = base_addr + ID_ADDRESS; 2270 firm_id = base_addr + ID_ADDRESS;
2210 if (!ISZLOADED(cy_card[card])) { 2271 if (!ISZLOADED(cy_card[card])) {
2211 return; 2272 return;
2212 } 2273 }
2213 2274
2214 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2275 zfw_ctrl = cy_card[card].base_addr +
2215 board_ctrl = &zfw_ctrl->board_ctrl; 2276 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2216 ch_ctrl = zfw_ctrl->ch_ctrl; 2277 board_ctrl = &zfw_ctrl->board_ctrl;
2278 ch_ctrl = zfw_ctrl->ch_ctrl;
2217 2279
2218 CY_LOCK(info, flags); 2280 CY_LOCK(info, flags);
2219 2281
2220 if (info->xmit_buf){ 2282 if (info->xmit_buf) {
2221 unsigned char * temp; 2283 unsigned char *temp;
2222 temp = info->xmit_buf; 2284 temp = info->xmit_buf;
2223 info->xmit_buf = NULL; 2285 info->xmit_buf = NULL;
2224 free_page((unsigned long) temp); 2286 free_page((unsigned long)temp);
2225 }
2226
2227 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2228 cy_writel(&ch_ctrl[channel].rs_control,
2229 (uclong)(cy_readl(&ch_ctrl[channel].rs_control) &
2230 ~(C_RS_RTS | C_RS_DTR)));
2231 retval = cyz_issue_cmd(&cy_card[info->card],
2232 channel, C_CM_IOCTLM, 0L);
2233 if (retval != 0){
2234 printk("cyc:shutdown retval on ttyC%d was %x\n",
2235 info->line, retval);
2236 } 2287 }
2288
2289 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2290 cy_writel(&ch_ctrl[channel].rs_control,
2291 (uclong)(cy_readl(&ch_ctrl[channel].rs_control)&
2292 ~(C_RS_RTS | C_RS_DTR)));
2293 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2294 C_CM_IOCTLM, 0L);
2295 if (retval != 0) {
2296 printk("cyc:shutdown retval on ttyC%d was %x\n",
2297 info->line, retval);
2298 }
2237#ifdef CY_DEBUG_DTR 2299#ifdef CY_DEBUG_DTR
2238 printk("cyc:shutdown dropping Z DTR\n"); 2300 printk("cyc:shutdown dropping Z DTR\n");
2239#endif 2301#endif
2240 } 2302 }
2241
2242 if (info->tty){
2243 set_bit(TTY_IO_ERROR, &info->tty->flags);
2244 }
2245 info->flags &= ~ASYNC_INITIALIZED;
2246 2303
2247 CY_UNLOCK(info, flags); 2304 if (info->tty) {
2248 } 2305 set_bit(TTY_IO_ERROR, &info->tty->flags);
2306 }
2307 info->flags &= ~ASYNC_INITIALIZED;
2308
2309 CY_UNLOCK(info, flags);
2310 }
2249 2311
2250#ifdef CY_DEBUG_OPEN 2312#ifdef CY_DEBUG_OPEN
2251 printk(" cyc shutdown done\n"); 2313 printk(" cyc shutdown done\n");
2252#endif 2314#endif
2253 return; 2315} /* shutdown */
2254} /* shutdown */
2255
2256 2316
2257/* 2317/*
2258 * ------------------------------------------------------------ 2318 * ------------------------------------------------------------
@@ -2261,527 +2321,546 @@ shutdown(struct cyclades_port * info)
2261 */ 2321 */
2262 2322
2263static int 2323static int
2264block_til_ready(struct tty_struct *tty, struct file * filp, 2324block_til_ready(struct tty_struct *tty, struct file *filp,
2265 struct cyclades_port *info) 2325 struct cyclades_port *info)
2266{ 2326{
2267 DECLARE_WAITQUEUE(wait, current); 2327 DECLARE_WAITQUEUE(wait, current);
2268 struct cyclades_card *cinfo; 2328 struct cyclades_card *cinfo;
2269 unsigned long flags; 2329 unsigned long flags;
2270 int chip, channel,index; 2330 int chip, channel, index;
2271 int retval; 2331 int retval;
2272 void __iomem *base_addr; 2332 void __iomem *base_addr;
2273 2333
2274 cinfo = &cy_card[info->card]; 2334 cinfo = &cy_card[info->card];
2275 channel = info->line - cinfo->first_line; 2335 channel = info->line - cinfo->first_line;
2276 2336
2277 /* 2337 /*
2278 * If the device is in the middle of being closed, then block 2338 * If the device is in the middle of being closed, then block
2279 * until it's done, and then try again. 2339 * until it's done, and then try again.
2280 */ 2340 */
2281 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2341 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2282 if (info->flags & ASYNC_CLOSING) { 2342 if (info->flags & ASYNC_CLOSING) {
2283 interruptible_sleep_on(&info->close_wait); 2343 interruptible_sleep_on(&info->close_wait);
2344 }
2345 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2346 }
2347
2348 /*
2349 * If non-blocking mode is set, then make the check up front
2350 * and then exit.
2351 */
2352 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2353 info->flags |= ASYNC_NORMAL_ACTIVE;
2354 return 0;
2284 } 2355 }
2285 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 2356
2286 } 2357 /*
2287 2358 * Block waiting for the carrier detect and the line to become
2288 /* 2359 * free (i.e., not in use by the callout). While we are in
2289 * If non-blocking mode is set, then make the check up front 2360 * this loop, info->count is dropped by one, so that
2290 * and then exit. 2361 * cy_close() knows when to free things. We restore it upon
2291 */ 2362 * exit, either normal or abnormal.
2292 if ((filp->f_flags & O_NONBLOCK) || 2363 */
2293 (tty->flags & (1 << TTY_IO_ERROR))) { 2364 retval = 0;
2294 info->flags |= ASYNC_NORMAL_ACTIVE; 2365 add_wait_queue(&info->open_wait, &wait);
2295 return 0;
2296 }
2297
2298 /*
2299 * Block waiting for the carrier detect and the line to become
2300 * free (i.e., not in use by the callout). While we are in
2301 * this loop, info->count is dropped by one, so that
2302 * cy_close() knows when to free things. We restore it upon
2303 * exit, either normal or abnormal.
2304 */
2305 retval = 0;
2306 add_wait_queue(&info->open_wait, &wait);
2307#ifdef CY_DEBUG_OPEN 2366#ifdef CY_DEBUG_OPEN
2308 printk("cyc block_til_ready before block: ttyC%d, count = %d\n", 2367 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2309 info->line, info->count);/**/ 2368 info->line, info->count);
2369 /**/
2310#endif 2370#endif
2311 CY_LOCK(info, flags); 2371 CY_LOCK(info, flags);
2312 if (!tty_hung_up_p(filp)) 2372 if (!tty_hung_up_p(filp))
2313 info->count--; 2373 info->count--;
2314 CY_UNLOCK(info, flags); 2374 CY_UNLOCK(info, flags);
2315#ifdef CY_DEBUG_COUNT 2375#ifdef CY_DEBUG_COUNT
2316 printk("cyc block_til_ready: (%d): decrementing count to %d\n", 2376 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2317 current->pid, info->count); 2377 current->pid, info->count);
2318#endif 2378#endif
2319 info->blocked_open++; 2379 info->blocked_open++;
2320 2380
2321 if (!IS_CYC_Z(*cinfo)) { 2381 if (!IS_CYC_Z(*cinfo)) {
2322 chip = channel>>2; 2382 chip = channel >> 2;
2323 channel &= 0x03; 2383 channel &= 0x03;
2324 index = cinfo->bus_index; 2384 index = cinfo->bus_index;
2325 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index); 2385 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
2326 2386
2327 while (1) { 2387 while (1) {
2328 CY_LOCK(info, flags); 2388 CY_LOCK(info, flags);
2329 if ((tty->termios->c_cflag & CBAUD)){ 2389 if ((tty->termios->c_cflag & CBAUD)) {
2330 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2390 cy_writeb(base_addr + (CyCAR << index),
2331 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2391 (u_char) channel);
2332 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2392 cy_writeb(base_addr + (CyMSVR1 << index),
2393 CyRTS);
2394 cy_writeb(base_addr + (CyMSVR2 << index),
2395 CyDTR);
2333#ifdef CY_DEBUG_DTR 2396#ifdef CY_DEBUG_DTR
2334 printk("cyc:block_til_ready raising DTR\n"); 2397 printk("cyc:block_til_ready raising DTR\n");
2335 printk(" status: 0x%x, 0x%x\n", 2398 printk(" status: 0x%x, 0x%x\n",
2336 cy_readb(base_addr+(CyMSVR1<<index)), 2399 cy_readb(base_addr +
2337 cy_readb(base_addr+(CyMSVR2<<index))); 2400 (CyMSVR1 << index)),
2401 cy_readb(base_addr +
2402 (CyMSVR2 << index)));
2338#endif 2403#endif
2339 } 2404 }
2340 CY_UNLOCK(info, flags); 2405 CY_UNLOCK(info, flags);
2341 2406
2342 set_current_state(TASK_INTERRUPTIBLE); 2407 set_current_state(TASK_INTERRUPTIBLE);
2343 if (tty_hung_up_p(filp) 2408 if (tty_hung_up_p(filp) ||
2344 || !(info->flags & ASYNC_INITIALIZED) ){ 2409 !(info->flags & ASYNC_INITIALIZED)) {
2345 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2410 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2346 -EAGAIN : -ERESTARTSYS); 2411 -EAGAIN : -ERESTARTSYS);
2347 break; 2412 break;
2348 } 2413 }
2349 2414
2350 CY_LOCK(info, flags); 2415 CY_LOCK(info, flags);
2351 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2416 cy_writeb(base_addr + (CyCAR << index),
2352 if (!(info->flags & ASYNC_CLOSING) 2417 (u_char) channel);
2353 && (C_CLOCAL(tty) 2418 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2354 || (cy_readb(base_addr+(CyMSVR1<<index)) & CyDCD))) { 2419 (cy_readb(base_addr +
2420 (CyMSVR1 << index)) & CyDCD))) {
2421 CY_UNLOCK(info, flags);
2422 break;
2423 }
2355 CY_UNLOCK(info, flags); 2424 CY_UNLOCK(info, flags);
2356 break;
2357 }
2358 CY_UNLOCK(info, flags);
2359 2425
2360 if (signal_pending(current)) { 2426 if (signal_pending(current)) {
2361 retval = -ERESTARTSYS; 2427 retval = -ERESTARTSYS;
2362 break; 2428 break;
2363 } 2429 }
2364#ifdef CY_DEBUG_OPEN 2430#ifdef CY_DEBUG_OPEN
2365 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2431 printk("cyc block_til_ready blocking: ttyC%d, "
2366 info->line, info->count);/**/ 2432 "count = %d\n",
2433 info->line, info->count);
2434 /**/
2367#endif 2435#endif
2368 schedule(); 2436 schedule();
2369 } 2437 }
2370 } else { 2438 } else {
2371 struct FIRM_ID __iomem *firm_id; 2439 struct FIRM_ID __iomem *firm_id;
2372 struct ZFW_CTRL __iomem *zfw_ctrl; 2440 struct ZFW_CTRL __iomem *zfw_ctrl;
2373 struct BOARD_CTRL __iomem *board_ctrl; 2441 struct BOARD_CTRL __iomem *board_ctrl;
2374 struct CH_CTRL __iomem *ch_ctrl; 2442 struct CH_CTRL __iomem *ch_ctrl;
2375 int retval; 2443 int retval;
2376 2444
2377 base_addr = cinfo->base_addr; 2445 base_addr = cinfo->base_addr;
2378 firm_id = base_addr + ID_ADDRESS; 2446 firm_id = base_addr + ID_ADDRESS;
2379 if (!ISZLOADED(*cinfo)){ 2447 if (!ISZLOADED(*cinfo)) {
2380 current->state = TASK_RUNNING; 2448 current->state = TASK_RUNNING;
2381 remove_wait_queue(&info->open_wait, &wait); 2449 remove_wait_queue(&info->open_wait, &wait);
2382 return -EINVAL; 2450 return -EINVAL;
2383 }
2384
2385 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2386 board_ctrl = &zfw_ctrl->board_ctrl;
2387 ch_ctrl = zfw_ctrl->ch_ctrl;
2388
2389 while (1) {
2390 if ((tty->termios->c_cflag & CBAUD)){
2391 cy_writel(&ch_ctrl[channel].rs_control,
2392 cy_readl(&ch_ctrl[channel].rs_control) |
2393 (C_RS_RTS | C_RS_DTR));
2394 retval = cyz_issue_cmd(&cy_card[info->card],
2395 channel, C_CM_IOCTLM, 0L);
2396 if (retval != 0){
2397 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2398 info->line, retval);
2399 } 2451 }
2452
2453 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
2454 0xfffff);
2455 board_ctrl = &zfw_ctrl->board_ctrl;
2456 ch_ctrl = zfw_ctrl->ch_ctrl;
2457
2458 while (1) {
2459 if ((tty->termios->c_cflag & CBAUD)) {
2460 cy_writel(&ch_ctrl[channel].rs_control,
2461 cy_readl(&ch_ctrl[channel].
2462 rs_control) | (C_RS_RTS |
2463 C_RS_DTR));
2464 retval = cyz_issue_cmd(&cy_card[info->card],
2465 channel, C_CM_IOCTLM, 0L);
2466 if (retval != 0) {
2467 printk("cyc:block_til_ready retval on "
2468 "ttyC%d was %x\n",
2469 info->line, retval);
2470 }
2400#ifdef CY_DEBUG_DTR 2471#ifdef CY_DEBUG_DTR
2401 printk("cyc:block_til_ready raising Z DTR\n"); 2472 printk("cyc:block_til_ready raising Z DTR\n");
2402#endif 2473#endif
2403 } 2474 }
2404 2475
2405 set_current_state(TASK_INTERRUPTIBLE); 2476 set_current_state(TASK_INTERRUPTIBLE);
2406 if (tty_hung_up_p(filp) 2477 if (tty_hung_up_p(filp) ||
2407 || !(info->flags & ASYNC_INITIALIZED) ){ 2478 !(info->flags & ASYNC_INITIALIZED)) {
2408 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2479 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2409 -EAGAIN : -ERESTARTSYS); 2480 -EAGAIN : -ERESTARTSYS);
2410 break; 2481 break;
2411 } 2482 }
2412 if (!(info->flags & ASYNC_CLOSING) 2483 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2413 && (C_CLOCAL(tty) 2484 (cy_readl(&ch_ctrl[channel].rs_status) &
2414 || (cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD))) { 2485 C_RS_DCD))) {
2415 break; 2486 break;
2416 } 2487 }
2417 if (signal_pending(current)) { 2488 if (signal_pending(current)) {
2418 retval = -ERESTARTSYS; 2489 retval = -ERESTARTSYS;
2419 break; 2490 break;
2420 } 2491 }
2421#ifdef CY_DEBUG_OPEN 2492#ifdef CY_DEBUG_OPEN
2422 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2493 printk("cyc block_til_ready blocking: ttyC%d, "
2423 info->line, info->count);/**/ 2494 "count = %d\n",
2495 info->line, info->count);
2496 /**/
2424#endif 2497#endif
2425 schedule(); 2498 schedule();
2499 }
2426 } 2500 }
2427 } 2501 current->state = TASK_RUNNING;
2428 current->state = TASK_RUNNING; 2502 remove_wait_queue(&info->open_wait, &wait);
2429 remove_wait_queue(&info->open_wait, &wait); 2503 if (!tty_hung_up_p(filp)) {
2430 if (!tty_hung_up_p(filp)){ 2504 info->count++;
2431 info->count++;
2432#ifdef CY_DEBUG_COUNT 2505#ifdef CY_DEBUG_COUNT
2433 printk("cyc:block_til_ready (%d): incrementing count to %d\n", 2506 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2434 current->pid, info->count); 2507 current->pid, info->count);
2435#endif 2508#endif
2436 } 2509 }
2437 info->blocked_open--; 2510 info->blocked_open--;
2438#ifdef CY_DEBUG_OPEN 2511#ifdef CY_DEBUG_OPEN
2439 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n", 2512 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2440 info->line, info->count);/**/ 2513 info->line, info->count);
2514 /**/
2441#endif 2515#endif
2442 if (retval) 2516 if (retval)
2443 return retval; 2517 return retval;
2444 info->flags |= ASYNC_NORMAL_ACTIVE; 2518 info->flags |= ASYNC_NORMAL_ACTIVE;
2445 return 0; 2519 return 0;
2446} /* block_til_ready */ 2520} /* block_til_ready */
2447
2448 2521
2449/* 2522/*
2450 * This routine is called whenever a serial port is opened. It 2523 * This routine is called whenever a serial port is opened. It
2451 * performs the serial-specific initialization for the tty structure. 2524 * performs the serial-specific initialization for the tty structure.
2452 */ 2525 */
2453static int 2526static int cy_open(struct tty_struct *tty, struct file *filp)
2454cy_open(struct tty_struct *tty, struct file * filp)
2455{ 2527{
2456 struct cyclades_port *info; 2528 struct cyclades_port *info;
2457 int retval, line; 2529 int retval, line;
2458
2459 line = tty->index;
2460 if ((line < 0) || (NR_PORTS <= line)){
2461 return -ENODEV;
2462 }
2463 info = &cy_port[line];
2464 if (info->line < 0){
2465 return -ENODEV;
2466 }
2467
2468 /* If the card's firmware hasn't been loaded,
2469 treat it as absent from the system. This
2470 will make the user pay attention.
2471 */
2472 if (IS_CYC_Z(cy_card[info->card])) {
2473 struct cyclades_card *cinfo = &cy_card[info->card];
2474 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2475
2476 if (!ISZLOADED(*cinfo)) {
2477 if (((ZE_V1 ==cy_readl(&((struct RUNTIME_9060 __iomem *)
2478 (cinfo->ctl_addr))->mail_box_0)) &&
2479 Z_FPGA_CHECK (*cinfo)) &&
2480 (ZFIRM_HLT == cy_readl (&firm_id->signature)))
2481 {
2482 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2483 } else {
2484 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2485 }
2486 return -ENODEV;
2487 }
2488#ifdef CONFIG_CYZ_INTR
2489 else {
2490 /* In case this Z board is operating in interrupt mode, its
2491 interrupts should be enabled as soon as the first open happens
2492 to one of its ports. */
2493 if (!cinfo->intr_enabled) {
2494 struct ZFW_CTRL __iomem *zfw_ctrl;
2495 struct BOARD_CTRL __iomem *board_ctrl;
2496
2497 zfw_ctrl = cinfo->base_addr + (cy_readl (&firm_id->zfwctrl_addr) & 0xfffff);
2498 2530
2499 board_ctrl = &zfw_ctrl->board_ctrl; 2531 line = tty->index;
2532 if ((line < 0) || (NR_PORTS <= line)) {
2533 return -ENODEV;
2534 }
2535 info = &cy_port[line];
2536 if (info->line < 0) {
2537 return -ENODEV;
2538 }
2500 2539
2501 /* Enable interrupts on the PLX chip */ 2540 /* If the card's firmware hasn't been loaded,
2502 cy_writew(cinfo->ctl_addr+0x68, 2541 treat it as absent from the system. This
2503 cy_readw(cinfo->ctl_addr+0x68)|0x0900); 2542 will make the user pay attention.
2504 /* Enable interrupts on the FW */ 2543 */
2505 retval = cyz_issue_cmd(cinfo, 2544 if (IS_CYC_Z(cy_card[info->card])) {
2506 0, C_CM_IRQ_ENBL, 0L); 2545 struct cyclades_card *cinfo = &cy_card[info->card];
2507 if (retval != 0){ 2546 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2508 printk("cyc:IRQ enable retval was %x\n", retval); 2547
2548 if (!ISZLOADED(*cinfo)) {
2549 if (((ZE_V1 == cy_readl(
2550 &((struct RUNTIME_9060 __iomem *)
2551 (cinfo->ctl_addr))->mail_box_0)) &&
2552 Z_FPGA_CHECK(*cinfo)) &&
2553 (ZFIRM_HLT == cy_readl(
2554 &firm_id->signature))) {
2555 printk("cyc:Cyclades-Z Error: you need an "
2556 "external power supply for this number "
2557 "of ports.\n\rFirmware halted.\r\n");
2558 } else {
2559 printk("cyc:Cyclades-Z firmware not yet "
2560 "loaded\n");
2561 }
2562 return -ENODEV;
2509 } 2563 }
2510 cinfo->nports = (int) cy_readl (&board_ctrl->n_channel); 2564#ifdef CONFIG_CYZ_INTR
2511 cinfo->intr_enabled = 1; 2565 else {
2512 } 2566 /* In case this Z board is operating in interrupt mode, its
2567 interrupts should be enabled as soon as the first open
2568 happens to one of its ports. */
2569 if (!cinfo->intr_enabled) {
2570 struct ZFW_CTRL __iomem *zfw_ctrl;
2571 struct BOARD_CTRL __iomem *board_ctrl;
2572
2573 zfw_ctrl = cinfo->base_addr +
2574 (cy_readl(&firm_id->zfwctrl_addr) &
2575 0xfffff);
2576
2577 board_ctrl = &zfw_ctrl->board_ctrl;
2578
2579 /* Enable interrupts on the PLX chip */
2580 cy_writew(cinfo->ctl_addr + 0x68,
2581 cy_readw(cinfo->ctl_addr +
2582 0x68) | 0x0900);
2583 /* Enable interrupts on the FW */
2584 retval = cyz_issue_cmd(cinfo, 0,
2585 C_CM_IRQ_ENBL, 0L);
2586 if (retval != 0) {
2587 printk("cyc:IRQ enable retval was %x\n",
2588 retval);
2589 }
2590 cinfo->nports =
2591 (int)cy_readl(&board_ctrl->n_channel);
2592 cinfo->intr_enabled = 1;
2593 }
2594 }
2595#endif /* CONFIG_CYZ_INTR */
2596 /* Make sure this Z port really exists in hardware */
2597 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2598 return -ENODEV;
2513 } 2599 }
2514#endif /* CONFIG_CYZ_INTR */
2515 /* Make sure this Z port really exists in hardware */
2516 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2517 return -ENODEV;
2518 }
2519#ifdef CY_DEBUG_OTHER 2600#ifdef CY_DEBUG_OTHER
2520 printk("cyc:cy_open ttyC%d\n", info->line); /* */ 2601 printk("cyc:cy_open ttyC%d\n", info->line); /* */
2521#endif 2602#endif
2522 tty->driver_data = info; 2603 tty->driver_data = info;
2523 info->tty = tty; 2604 info->tty = tty;
2524 if (serial_paranoia_check(info, tty->name, "cy_open")){ 2605 if (serial_paranoia_check(info, tty->name, "cy_open")) {
2525 return -ENODEV; 2606 return -ENODEV;
2526 } 2607 }
2527#ifdef CY_DEBUG_OPEN 2608#ifdef CY_DEBUG_OPEN
2528 printk("cyc:cy_open ttyC%d, count = %d\n", 2609 printk("cyc:cy_open ttyC%d, count = %d\n", info->line, info->count);
2529 info->line, info->count);/**/ 2610 /**/
2530#endif 2611#endif
2531 info->count++; 2612 info->count++;
2532#ifdef CY_DEBUG_COUNT 2613#ifdef CY_DEBUG_COUNT
2533 printk("cyc:cy_open (%d): incrementing count to %d\n", 2614 printk("cyc:cy_open (%d): incrementing count to %d\n",
2534 current->pid, info->count); 2615 current->pid, info->count);
2535#endif 2616#endif
2536 2617
2537 /* 2618 /*
2538 * If the port is the middle of closing, bail out now 2619 * If the port is the middle of closing, bail out now
2539 */ 2620 */
2540 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2621 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2541 if (info->flags & ASYNC_CLOSING) 2622 if (info->flags & ASYNC_CLOSING)
2542 interruptible_sleep_on(&info->close_wait); 2623 interruptible_sleep_on(&info->close_wait);
2543 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 2624 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2544 } 2625 }
2545
2546 /*
2547 * Start up serial port
2548 */
2549 retval = startup(info);
2550 if (retval){
2551 return retval;
2552 }
2553
2554 retval = block_til_ready(tty, filp, info);
2555 if (retval) {
2556#ifdef CY_DEBUG_OPEN
2557 printk("cyc:cy_open returning after block_til_ready with %d\n",
2558 retval);
2559#endif
2560 return retval;
2561 }
2562 2626
2563 info->throttle = 0; 2627 /*
2628 * Start up serial port
2629 */
2630 retval = startup(info);
2631 if (retval) {
2632 return retval;
2633 }
2564 2634
2635 retval = block_til_ready(tty, filp, info);
2636 if (retval) {
2565#ifdef CY_DEBUG_OPEN 2637#ifdef CY_DEBUG_OPEN
2566 printk(" cyc:cy_open done\n");/**/ 2638 printk("cyc:cy_open returning after block_til_ready with %d\n",
2639 retval);
2567#endif 2640#endif
2641 return retval;
2642 }
2568 2643
2569 return 0; 2644 info->throttle = 0;
2570} /* cy_open */
2571 2645
2646#ifdef CY_DEBUG_OPEN
2647 printk(" cyc:cy_open done\n");
2648 /**/
2649#endif
2650 return 0;
2651} /* cy_open */
2572 2652
2573/* 2653/*
2574 * cy_wait_until_sent() --- wait until the transmitter is empty 2654 * cy_wait_until_sent() --- wait until the transmitter is empty
2575 */ 2655 */
2576static void 2656static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2577cy_wait_until_sent(struct tty_struct *tty, int timeout)
2578{ 2657{
2579 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 2658 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2580 void __iomem *base_addr; 2659 void __iomem *base_addr;
2581 int card,chip,channel,index; 2660 int card, chip, channel, index;
2582 unsigned long orig_jiffies; 2661 unsigned long orig_jiffies;
2583 int char_time; 2662 int char_time;
2584 2663
2585 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent")) 2664 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
2586 return; 2665 return;
2587 2666
2588 if (info->xmit_fifo_size == 0) 2667 if (info->xmit_fifo_size == 0)
2589 return; /* Just in case.... */ 2668 return; /* Just in case.... */
2590 2669
2591 2670 orig_jiffies = jiffies;
2592 orig_jiffies = jiffies; 2671 /*
2593 /* 2672 * Set the check interval to be 1/5 of the estimated time to
2594 * Set the check interval to be 1/5 of the estimated time to 2673 * send a single character, and make it at least 1. The check
2595 * send a single character, and make it at least 1. The check 2674 * interval should also be less than the timeout.
2596 * interval should also be less than the timeout. 2675 *
2597 * 2676 * Note: we have to use pretty tight timings here to satisfy
2598 * Note: we have to use pretty tight timings here to satisfy 2677 * the NIST-PCTS.
2599 * the NIST-PCTS. 2678 */
2600 */ 2679 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2601 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size; 2680 char_time = char_time / 5;
2602 char_time = char_time / 5; 2681 if (char_time <= 0)
2603 if (char_time <= 0) 2682 char_time = 1;
2604 char_time = 1; 2683 if (timeout < 0)
2605 if (timeout < 0) 2684 timeout = 0;
2606 timeout = 0; 2685 if (timeout)
2607 if (timeout) 2686 char_time = min(char_time, timeout);
2608 char_time = min(char_time, timeout); 2687 /*
2609 /* 2688 * If the transmitter hasn't cleared in twice the approximate
2610 * If the transmitter hasn't cleared in twice the approximate 2689 * amount of time to send the entire FIFO, it probably won't
2611 * amount of time to send the entire FIFO, it probably won't 2690 * ever clear. This assumes the UART isn't doing flow
2612 * ever clear. This assumes the UART isn't doing flow 2691 * control, which is currently the case. Hence, if it ever
2613 * control, which is currently the case. Hence, if it ever 2692 * takes longer than info->timeout, this is probably due to a
2614 * takes longer than info->timeout, this is probably due to a 2693 * UART bug of some kind. So, we clamp the timeout parameter at
2615 * UART bug of some kind. So, we clamp the timeout parameter at 2694 * 2*info->timeout.
2616 * 2*info->timeout. 2695 */
2617 */ 2696 if (!timeout || timeout > 2 * info->timeout)
2618 if (!timeout || timeout > 2*info->timeout) 2697 timeout = 2 * info->timeout;
2619 timeout = 2*info->timeout;
2620#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2698#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2621 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time); 2699 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
2622 printk("jiff=%lu...", jiffies); 2700 printk("jiff=%lu...", jiffies);
2623#endif 2701#endif
2624 card = info->card; 2702 card = info->card;
2625 channel = (info->line) - (cy_card[card].first_line); 2703 channel = (info->line) - (cy_card[card].first_line);
2626 if (!IS_CYC_Z(cy_card[card])) { 2704 if (!IS_CYC_Z(cy_card[card])) {
2627 chip = channel>>2; 2705 chip = channel >> 2;
2628 channel &= 0x03; 2706 channel &= 0x03;
2629 index = cy_card[card].bus_index; 2707 index = cy_card[card].bus_index;
2630 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2708 base_addr =
2631 while (cy_readb(base_addr+(CySRER<<index)) & CyTxRdy) { 2709 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
2710 while (cy_readb(base_addr + (CySRER << index)) & CyTxRdy) {
2632#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2711#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2633 printk("Not clean (jiff=%lu)...", jiffies); 2712 printk("Not clean (jiff=%lu)...", jiffies);
2634#endif 2713#endif
2635 if (msleep_interruptible(jiffies_to_msecs(char_time))) 2714 if (msleep_interruptible(jiffies_to_msecs(char_time)))
2636 break; 2715 break;
2637 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2716 if (timeout && time_after(jiffies, orig_jiffies +
2638 break; 2717 timeout))
2718 break;
2719 }
2720 } else {
2721 /* Nothing to do! */
2639 } 2722 }
2640 } else { 2723 /* Run one more char cycle */
2641 // Nothing to do! 2724 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2642 }
2643 /* Run one more char cycle */
2644 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2645#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2725#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2646 printk("Clean (jiff=%lu)...done\n", jiffies); 2726 printk("Clean (jiff=%lu)...done\n", jiffies);
2647#endif 2727#endif
2648} 2728}
2649 2729
2650/* 2730/*
2651 * This routine is called when a particular tty device is closed. 2731 * This routine is called when a particular tty device is closed.
2652 */ 2732 */
2653static void 2733static void cy_close(struct tty_struct *tty, struct file *filp)
2654cy_close(struct tty_struct *tty, struct file *filp)
2655{ 2734{
2656 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2735 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2657 unsigned long flags; 2736 unsigned long flags;
2658 2737
2659#ifdef CY_DEBUG_OTHER 2738#ifdef CY_DEBUG_OTHER
2660 printk("cyc:cy_close ttyC%d\n", info->line); 2739 printk("cyc:cy_close ttyC%d\n", info->line);
2661#endif 2740#endif
2662 2741
2663 if (!info || serial_paranoia_check(info, tty->name, "cy_close")){ 2742 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
2664 return; 2743 return;
2665 } 2744 }
2666 2745
2667 CY_LOCK(info, flags); 2746 CY_LOCK(info, flags);
2668 /* If the TTY is being hung up, nothing to do */ 2747 /* If the TTY is being hung up, nothing to do */
2669 if (tty_hung_up_p(filp)) { 2748 if (tty_hung_up_p(filp)) {
2670 CY_UNLOCK(info, flags); 2749 CY_UNLOCK(info, flags);
2671 return; 2750 return;
2672 } 2751 }
2673
2674#ifdef CY_DEBUG_OPEN 2752#ifdef CY_DEBUG_OPEN
2675 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count); 2753 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
2676#endif 2754#endif
2677 if ((tty->count == 1) && (info->count != 1)) { 2755 if ((tty->count == 1) && (info->count != 1)) {
2678 /* 2756 /*
2679 * Uh, oh. tty->count is 1, which means that the tty 2757 * Uh, oh. tty->count is 1, which means that the tty
2680 * structure will be freed. Info->count should always 2758 * structure will be freed. Info->count should always
2681 * be one in these conditions. If it's greater than 2759 * be one in these conditions. If it's greater than
2682 * one, we've got real problems, since it means the 2760 * one, we've got real problems, since it means the
2683 * serial port won't be shutdown. 2761 * serial port won't be shutdown.
2684 */ 2762 */
2685 printk("cyc:cy_close: bad serial port count; tty->count is 1, " 2763 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2686 "info->count is %d\n", info->count); 2764 "info->count is %d\n", info->count);
2687 info->count = 1; 2765 info->count = 1;
2688 } 2766 }
2689#ifdef CY_DEBUG_COUNT 2767#ifdef CY_DEBUG_COUNT
2690 printk("cyc:cy_close at (%d): decrementing count to %d\n", 2768 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2691 current->pid, info->count - 1); 2769 current->pid, info->count - 1);
2692#endif 2770#endif
2693 if (--info->count < 0) { 2771 if (--info->count < 0) {
2694#ifdef CY_DEBUG_COUNT 2772#ifdef CY_DEBUG_COUNT
2695 printk("cyc:cyc_close setting count to 0\n"); 2773 printk("cyc:cyc_close setting count to 0\n");
2696#endif 2774#endif
2697 info->count = 0; 2775 info->count = 0;
2698 }
2699 if (info->count) {
2700 CY_UNLOCK(info, flags);
2701 return;
2702 }
2703 info->flags |= ASYNC_CLOSING;
2704
2705 /*
2706 * Now we wait for the transmit buffer to clear; and we notify
2707 * the line discipline to only process XON/XOFF characters.
2708 */
2709 tty->closing = 1;
2710 CY_UNLOCK(info, flags);
2711 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2712 tty_wait_until_sent(tty, info->closing_wait);
2713 }
2714 CY_LOCK(info, flags);
2715
2716 if (!IS_CYC_Z(cy_card[info->card])) {
2717 int channel = info->line - cy_card[info->card].first_line;
2718 int index = cy_card[info->card].bus_index;
2719 void __iomem *base_addr = cy_card[info->card].base_addr + (cy_chip_offset[channel>>2] << index);
2720 /* Stop accepting input */
2721 channel &= 0x03;
2722 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
2723 cy_writeb(base_addr+(CySRER<<index),
2724 cy_readb(base_addr+(CySRER<<index)) & ~CyRxData);
2725 if (info->flags & ASYNC_INITIALIZED) {
2726 /* Waiting for on-board buffers to be empty before closing
2727 the port */
2728 CY_UNLOCK(info, flags);
2729 cy_wait_until_sent(tty, info->timeout);
2730 CY_LOCK(info, flags);
2731 } 2776 }
2732 } else { 2777 if (info->count) {
2733#ifdef Z_WAKE 2778 CY_UNLOCK(info, flags);
2734 /* Waiting for on-board buffers to be empty before closing the port */ 2779 return;
2735 void __iomem *base_addr = cy_card[info->card].base_addr; 2780 }
2736 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS; 2781 info->flags |= ASYNC_CLOSING;
2737 struct ZFW_CTRL __iomem *zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2738 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2739 int channel = info->line - cy_card[info->card].first_line;
2740 int retval;
2741 2782
2742 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) { 2783 /*
2743 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2784 * Now we wait for the transmit buffer to clear; and we notify
2744 C_CM_IOCTLW, 0L); 2785 * the line discipline to only process XON/XOFF characters.
2745 if (retval != 0){ 2786 */
2746 printk("cyc:cy_close retval on ttyC%d was %x\n", 2787 tty->closing = 1;
2747 info->line, retval); 2788 CY_UNLOCK(info, flags);
2748 } 2789 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2749 CY_UNLOCK(info, flags); 2790 tty_wait_until_sent(tty, info->closing_wait);
2750 interruptible_sleep_on(&info->shutdown_wait);
2751 CY_LOCK(info, flags);
2752 } 2791 }
2792 CY_LOCK(info, flags);
2793
2794 if (!IS_CYC_Z(cy_card[info->card])) {
2795 int channel = info->line - cy_card[info->card].first_line;
2796 int index = cy_card[info->card].bus_index;
2797 void __iomem *base_addr = cy_card[info->card].base_addr +
2798 (cy_chip_offset[channel >> 2] << index);
2799 /* Stop accepting input */
2800 channel &= 0x03;
2801 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2802 cy_writeb(base_addr + (CySRER << index),
2803 cy_readb(base_addr + (CySRER << index)) & ~CyRxData);
2804 if (info->flags & ASYNC_INITIALIZED) {
2805 /* Waiting for on-board buffers to be empty before closing
2806 the port */
2807 CY_UNLOCK(info, flags);
2808 cy_wait_until_sent(tty, info->timeout);
2809 CY_LOCK(info, flags);
2810 }
2811 } else {
2812#ifdef Z_WAKE
2813 /* Waiting for on-board buffers to be empty before closing the port */
2814 void __iomem *base_addr = cy_card[info->card].base_addr;
2815 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2816 struct ZFW_CTRL __iomem *zfw_ctrl =
2817 base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2818 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2819 int channel = info->line - cy_card[info->card].first_line;
2820 int retval;
2821
2822 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2823 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2824 C_CM_IOCTLW, 0L);
2825 if (retval != 0) {
2826 printk("cyc:cy_close retval on ttyC%d was %x\n",
2827 info->line, retval);
2828 }
2829 CY_UNLOCK(info, flags);
2830 interruptible_sleep_on(&info->shutdown_wait);
2831 CY_LOCK(info, flags);
2832 }
2753#endif 2833#endif
2754 } 2834 }
2755 2835
2756 CY_UNLOCK(info, flags);
2757 shutdown(info);
2758 if (tty->driver->flush_buffer)
2759 tty->driver->flush_buffer(tty);
2760 tty_ldisc_flush(tty);
2761 CY_LOCK(info, flags);
2762
2763 tty->closing = 0;
2764 info->event = 0;
2765 info->tty = NULL;
2766 if (info->blocked_open) {
2767 CY_UNLOCK(info, flags); 2836 CY_UNLOCK(info, flags);
2768 if (info->close_delay) { 2837 shutdown(info);
2769 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 2838 if (tty->driver->flush_buffer)
2770 } 2839 tty->driver->flush_buffer(tty);
2771 wake_up_interruptible(&info->open_wait); 2840 tty_ldisc_flush(tty);
2772 CY_LOCK(info, flags); 2841 CY_LOCK(info, flags);
2773 } 2842
2774 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 2843 tty->closing = 0;
2775 wake_up_interruptible(&info->close_wait); 2844 info->event = 0;
2845 info->tty = NULL;
2846 if (info->blocked_open) {
2847 CY_UNLOCK(info, flags);
2848 if (info->close_delay) {
2849 msleep_interruptible(jiffies_to_msecs
2850 (info->close_delay));
2851 }
2852 wake_up_interruptible(&info->open_wait);
2853 CY_LOCK(info, flags);
2854 }
2855 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
2856 wake_up_interruptible(&info->close_wait);
2776 2857
2777#ifdef CY_DEBUG_OTHER 2858#ifdef CY_DEBUG_OTHER
2778 printk(" cyc:cy_close done\n"); 2859 printk(" cyc:cy_close done\n");
2779#endif 2860#endif
2780 2861
2781 CY_UNLOCK(info, flags); 2862 CY_UNLOCK(info, flags);
2782 return; 2863} /* cy_close */
2783} /* cy_close */
2784
2785 2864
2786/* This routine gets called when tty_write has put something into 2865/* This routine gets called when tty_write has put something into
2787 * the write_queue. The characters may come from user space or 2866 * the write_queue. The characters may come from user space or
@@ -2796,50 +2875,49 @@ cy_close(struct tty_struct *tty, struct file *filp)
2796 * If the port is already active, there is no need to kick it. 2875 * If the port is already active, there is no need to kick it.
2797 * 2876 *
2798 */ 2877 */
2799static int 2878static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2800cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2801{ 2879{
2802 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2880 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2803 unsigned long flags; 2881 unsigned long flags;
2804 int c, ret = 0; 2882 int c, ret = 0;
2805 2883
2806#ifdef CY_DEBUG_IO 2884#ifdef CY_DEBUG_IO
2807 printk("cyc:cy_write ttyC%d\n", info->line); /* */ 2885 printk("cyc:cy_write ttyC%d\n", info->line); /* */
2808#endif 2886#endif
2809 2887
2810 if (serial_paranoia_check(info, tty->name, "cy_write")){ 2888 if (serial_paranoia_check(info, tty->name, "cy_write")) {
2811 return 0; 2889 return 0;
2812 } 2890 }
2813
2814 if (!info->xmit_buf)
2815 return 0;
2816 2891
2817 CY_LOCK(info, flags); 2892 if (!info->xmit_buf)
2818 while (1) { 2893 return 0;
2819 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2820 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2821
2822 if (c <= 0)
2823 break;
2824
2825 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2826 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
2827 info->xmit_cnt += c;
2828 buf += c;
2829 count -= c;
2830 ret += c;
2831 }
2832 CY_UNLOCK(info, flags);
2833
2834 info->idle_stats.xmit_bytes += ret;
2835 info->idle_stats.xmit_idle = jiffies;
2836
2837 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2838 start_xmit(info);
2839 }
2840 return ret;
2841} /* cy_write */
2842 2894
2895 CY_LOCK(info, flags);
2896 while (1) {
2897 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2898 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2899
2900 if (c <= 0)
2901 break;
2902
2903 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2904 info->xmit_head = (info->xmit_head + c) &
2905 (SERIAL_XMIT_SIZE - 1);
2906 info->xmit_cnt += c;
2907 buf += c;
2908 count -= c;
2909 ret += c;
2910 }
2911 CY_UNLOCK(info, flags);
2912
2913 info->idle_stats.xmit_bytes += ret;
2914 info->idle_stats.xmit_idle = jiffies;
2915
2916 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2917 start_xmit(info);
2918 }
2919 return ret;
2920} /* cy_write */
2843 2921
2844/* 2922/*
2845 * This routine is called by the kernel to write a single 2923 * This routine is called by the kernel to write a single
@@ -2848,60 +2926,56 @@ cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2848 * done stuffing characters into the driver. If there is no room 2926 * done stuffing characters into the driver. If there is no room
2849 * in the queue, the character is ignored. 2927 * in the queue, the character is ignored.
2850 */ 2928 */
2851static void 2929static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2852cy_put_char(struct tty_struct *tty, unsigned char ch)
2853{ 2930{
2854 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2931 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2855 unsigned long flags; 2932 unsigned long flags;
2856 2933
2857#ifdef CY_DEBUG_IO 2934#ifdef CY_DEBUG_IO
2858 printk("cyc:cy_put_char ttyC%d\n", info->line); 2935 printk("cyc:cy_put_char ttyC%d\n", info->line);
2859#endif 2936#endif
2860 2937
2861 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 2938 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
2862 return; 2939 return;
2863 2940
2864 if (!info->xmit_buf) 2941 if (!info->xmit_buf)
2865 return; 2942 return;
2866 2943
2867 CY_LOCK(info, flags); 2944 CY_LOCK(info, flags);
2868 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 2945 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
2869 CY_UNLOCK(info, flags); 2946 CY_UNLOCK(info, flags);
2870 return; 2947 return;
2871 } 2948 }
2872 2949
2873 info->xmit_buf[info->xmit_head++] = ch; 2950 info->xmit_buf[info->xmit_head++] = ch;
2874 info->xmit_head &= SERIAL_XMIT_SIZE - 1; 2951 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
2875 info->xmit_cnt++; 2952 info->xmit_cnt++;
2876 info->idle_stats.xmit_bytes++; 2953 info->idle_stats.xmit_bytes++;
2877 info->idle_stats.xmit_idle = jiffies; 2954 info->idle_stats.xmit_idle = jiffies;
2878 CY_UNLOCK(info, flags); 2955 CY_UNLOCK(info, flags);
2879} /* cy_put_char */ 2956} /* cy_put_char */
2880
2881 2957
2882/* 2958/*
2883 * This routine is called by the kernel after it has written a 2959 * This routine is called by the kernel after it has written a
2884 * series of characters to the tty device using put_char(). 2960 * series of characters to the tty device using put_char().
2885 */ 2961 */
2886static void 2962static void cy_flush_chars(struct tty_struct *tty)
2887cy_flush_chars(struct tty_struct *tty)
2888{ 2963{
2889 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2964 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2890 2965
2891#ifdef CY_DEBUG_IO 2966#ifdef CY_DEBUG_IO
2892 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */ 2967 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
2893#endif 2968#endif
2894 2969
2895 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 2970 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
2896 return; 2971 return;
2897
2898 if (info->xmit_cnt <= 0 || tty->stopped
2899 || tty->hw_stopped || !info->xmit_buf)
2900 return;
2901 2972
2902 start_xmit(info); 2973 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
2903} /* cy_flush_chars */ 2974 !info->xmit_buf)
2975 return;
2904 2976
2977 start_xmit(info);
2978} /* cy_flush_chars */
2905 2979
2906/* 2980/*
2907 * This routine returns the numbers of characters the tty driver 2981 * This routine returns the numbers of characters the tty driver
@@ -2909,75 +2983,70 @@ cy_flush_chars(struct tty_struct *tty)
2909 * to change as output buffers get emptied, or if the output flow 2983 * to change as output buffers get emptied, or if the output flow
2910 * control is activated. 2984 * control is activated.
2911 */ 2985 */
2912static int 2986static int cy_write_room(struct tty_struct *tty)
2913cy_write_room(struct tty_struct *tty)
2914{ 2987{
2915 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2988 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2916 int ret; 2989 int ret;
2917 2990
2918#ifdef CY_DEBUG_IO 2991#ifdef CY_DEBUG_IO
2919 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */ 2992 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
2920#endif 2993#endif
2921 2994
2922 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 2995 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
2923 return 0; 2996 return 0;
2924 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; 2997 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
2925 if (ret < 0) 2998 if (ret < 0)
2926 ret = 0; 2999 ret = 0;
2927 return ret; 3000 return ret;
2928} /* cy_write_room */ 3001} /* cy_write_room */
2929
2930 3002
2931static int 3003static int cy_chars_in_buffer(struct tty_struct *tty)
2932cy_chars_in_buffer(struct tty_struct *tty)
2933{ 3004{
2934 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3005 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2935 int card, channel; 3006 int card, channel;
2936 3007
2937 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 3008 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
2938 return 0; 3009 return 0;
2939 3010
2940 card = info->card; 3011 card = info->card;
2941 channel = (info->line) - (cy_card[card].first_line); 3012 channel = (info->line) - (cy_card[card].first_line);
2942 3013
2943#ifdef Z_EXT_CHARS_IN_BUFFER 3014#ifdef Z_EXT_CHARS_IN_BUFFER
2944 if (!IS_CYC_Z(cy_card[card])) { 3015 if (!IS_CYC_Z(cy_card[card])) {
2945#endif /* Z_EXT_CHARS_IN_BUFFER */ 3016#endif /* Z_EXT_CHARS_IN_BUFFER */
2946#ifdef CY_DEBUG_IO 3017#ifdef CY_DEBUG_IO
2947 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3018 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt); /* */
2948 info->line, info->xmit_cnt); /* */
2949#endif 3019#endif
2950 return info->xmit_cnt; 3020 return info->xmit_cnt;
2951#ifdef Z_EXT_CHARS_IN_BUFFER 3021#ifdef Z_EXT_CHARS_IN_BUFFER
2952 } else { 3022 } else {
2953 static volatile struct FIRM_ID *firm_id; 3023 static volatile struct FIRM_ID *firm_id;
2954 static volatile struct ZFW_CTRL *zfw_ctrl; 3024 static volatile struct ZFW_CTRL *zfw_ctrl;
2955 static volatile struct CH_CTRL *ch_ctrl; 3025 static volatile struct CH_CTRL *ch_ctrl;
2956 static volatile struct BUF_CTRL *buf_ctrl; 3026 static volatile struct BUF_CTRL *buf_ctrl;
2957 int char_count; 3027 int char_count;
2958 volatile uclong tx_put, tx_get, tx_bufsize; 3028 volatile uclong tx_put, tx_get, tx_bufsize;
2959 3029
2960 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3030 firm_id = cy_card[card].base_addr + ID_ADDRESS;
2961 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3031 zfw_ctrl = cy_card[card].base_addr +
2962 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3032 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2963 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]); 3033 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
2964 3034 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
2965 tx_get = cy_readl(&buf_ctrl->tx_get); 3035
2966 tx_put = cy_readl(&buf_ctrl->tx_put); 3036 tx_get = cy_readl(&buf_ctrl->tx_get);
2967 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 3037 tx_put = cy_readl(&buf_ctrl->tx_put);
2968 if (tx_put >= tx_get) 3038 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
2969 char_count = tx_put - tx_get; 3039 if (tx_put >= tx_get)
2970 else 3040 char_count = tx_put - tx_get;
2971 char_count = tx_put - tx_get + tx_bufsize; 3041 else
3042 char_count = tx_put - tx_get + tx_bufsize;
2972#ifdef CY_DEBUG_IO 3043#ifdef CY_DEBUG_IO
2973 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3044 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt + char_count); /* */
2974 info->line, info->xmit_cnt + char_count); /* */
2975#endif 3045#endif
2976 return (info->xmit_cnt + char_count); 3046 return info->xmit_cnt + char_count;
2977 } 3047 }
2978#endif /* Z_EXT_CHARS_IN_BUFFER */ 3048#endif /* Z_EXT_CHARS_IN_BUFFER */
2979} /* cy_chars_in_buffer */ 3049} /* cy_chars_in_buffer */
2980
2981 3050
2982/* 3051/*
2983 * ------------------------------------------------------------ 3052 * ------------------------------------------------------------
@@ -2985,178 +3054,179 @@ cy_chars_in_buffer(struct tty_struct *tty)
2985 * ------------------------------------------------------------ 3054 * ------------------------------------------------------------
2986 */ 3055 */
2987 3056
2988static void 3057static void cyy_baud_calc(struct cyclades_port *info, uclong baud)
2989cyy_baud_calc(struct cyclades_port *info, uclong baud)
2990{ 3058{
2991 int co, co_val, bpr; 3059 int co, co_val, bpr;
2992 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 : 25000000); 3060 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
2993 3061 25000000);
2994 if (baud == 0) { 3062
2995 info->tbpr = info->tco = info->rbpr = info->rco = 0; 3063 if (baud == 0) {
2996 return; 3064 info->tbpr = info->tco = info->rbpr = info->rco = 0;
2997 } 3065 return;
2998 3066 }
2999 /* determine which prescaler to use */ 3067
3000 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) { 3068 /* determine which prescaler to use */
3001 if (cy_clock / co_val / baud > 63) 3069 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
3002 break; 3070 if (cy_clock / co_val / baud > 63)
3003 } 3071 break;
3004 3072 }
3005 bpr = (cy_clock / co_val * 2 / baud + 1) / 2; 3073
3006 if (bpr > 255) 3074 bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
3007 bpr = 255; 3075 if (bpr > 255)
3008 3076 bpr = 255;
3009 info->tbpr = info->rbpr = bpr; 3077
3010 info->tco = info->rco = co; 3078 info->tbpr = info->rbpr = bpr;
3079 info->tco = info->rco = co;
3011} 3080}
3012 3081
3013/* 3082/*
3014 * This routine finds or computes the various line characteristics. 3083 * This routine finds or computes the various line characteristics.
3015 * It used to be called config_setup 3084 * It used to be called config_setup
3016 */ 3085 */
3017static void 3086static void set_line_char(struct cyclades_port *info)
3018set_line_char(struct cyclades_port * info)
3019{ 3087{
3020 unsigned long flags; 3088 unsigned long flags;
3021 void __iomem *base_addr; 3089 void __iomem *base_addr;
3022 int card,chip,channel,index; 3090 int card, chip, channel, index;
3023 unsigned cflag, iflag; 3091 unsigned cflag, iflag;
3024 unsigned short chip_number; 3092 unsigned short chip_number;
3025 int baud, baud_rate = 0; 3093 int baud, baud_rate = 0;
3026 int i; 3094 int i;
3027 3095
3028 3096 if (!info->tty || !info->tty->termios) {
3029 if (!info->tty || !info->tty->termios){ 3097 return;
3030 return;
3031 }
3032 if (info->line == -1){
3033 return;
3034 }
3035 cflag = info->tty->termios->c_cflag;
3036 iflag = info->tty->termios->c_iflag;
3037
3038 /*
3039 * Set up the tty->alt_speed kludge
3040 */
3041 if (info->tty) {
3042 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3043 info->tty->alt_speed = 57600;
3044 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3045 info->tty->alt_speed = 115200;
3046 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3047 info->tty->alt_speed = 230400;
3048 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3049 info->tty->alt_speed = 460800;
3050 }
3051
3052 card = info->card;
3053 channel = (info->line) - (cy_card[card].first_line);
3054 chip_number = channel / 4;
3055
3056 if (!IS_CYC_Z(cy_card[card])) {
3057
3058 index = cy_card[card].bus_index;
3059
3060 /* baud rate */
3061 baud = tty_get_baud_rate(info->tty);
3062 if ((baud == 38400) &&
3063 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3064 if (info->custom_divisor)
3065 baud_rate = info->baud / info->custom_divisor;
3066 else
3067 baud_rate = info->baud;
3068 } else if (baud > CD1400_MAX_SPEED) {
3069 baud = CD1400_MAX_SPEED;
3070 } 3098 }
3071 /* find the baud index */ 3099 if (info->line == -1) {
3072 for (i = 0; i < 20; i++) { 3100 return;
3073 if (baud == baud_table[i]) {
3074 break;
3075 }
3076 } 3101 }
3077 if (i == 20) { 3102 cflag = info->tty->termios->c_cflag;
3078 i = 19; /* CD1400_MAX_SPEED */ 3103 iflag = info->tty->termios->c_iflag;
3079 }
3080 3104
3081 if ((baud == 38400) && 3105 /*
3082 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) { 3106 * Set up the tty->alt_speed kludge
3083 cyy_baud_calc(info, baud_rate); 3107 */
3084 } else { 3108 if (info->tty) {
3085 if(info->chip_rev >= CD1400_REV_J) { 3109 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3086 /* It is a CD1400 rev. J or later */ 3110 info->tty->alt_speed = 57600;
3087 info->tbpr = baud_bpr_60[i]; /* Tx BPR */ 3111 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3088 info->tco = baud_co_60[i]; /* Tx CO */ 3112 info->tty->alt_speed = 115200;
3089 info->rbpr = baud_bpr_60[i]; /* Rx BPR */ 3113 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3090 info->rco = baud_co_60[i]; /* Rx CO */ 3114 info->tty->alt_speed = 230400;
3091 } else { 3115 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3092 info->tbpr = baud_bpr_25[i]; /* Tx BPR */ 3116 info->tty->alt_speed = 460800;
3093 info->tco = baud_co_25[i]; /* Tx CO */
3094 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3095 info->rco = baud_co_25[i]; /* Rx CO */
3096 }
3097 }
3098 if (baud_table[i] == 134) {
3099 /* get it right for 134.5 baud */
3100 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3101 } else if ((baud == 38400) &&
3102 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3103 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3104 } else if (baud_table[i]) {
3105 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
3106 /* this needs to be propagated into the card info */
3107 } else {
3108 info->timeout = 0;
3109 }
3110 /* By tradition (is it a standard?) a baud rate of zero
3111 implies the line should be/has been closed. A bit
3112 later in this routine such a test is performed. */
3113
3114 /* byte size and parity */
3115 info->cor5 = 0;
3116 info->cor4 = 0;
3117 info->cor3 = (info->default_threshold
3118 ? info->default_threshold
3119 : baud_cor3[i]); /* receive threshold */
3120 info->cor2 = CyETC;
3121 switch(cflag & CSIZE){
3122 case CS5:
3123 info->cor1 = Cy_5_BITS;
3124 break;
3125 case CS6:
3126 info->cor1 = Cy_6_BITS;
3127 break;
3128 case CS7:
3129 info->cor1 = Cy_7_BITS;
3130 break;
3131 case CS8:
3132 info->cor1 = Cy_8_BITS;
3133 break;
3134 }
3135 if(cflag & CSTOPB){
3136 info->cor1 |= Cy_2_STOP;
3137 }
3138 if (cflag & PARENB){
3139 if (cflag & PARODD){
3140 info->cor1 |= CyPARITY_O;
3141 }else{
3142 info->cor1 |= CyPARITY_E;
3143 }
3144 }else{
3145 info->cor1 |= CyPARITY_NONE;
3146 }
3147
3148 /* CTS flow control flag */
3149 if (cflag & CRTSCTS){
3150 info->flags |= ASYNC_CTS_FLOW;
3151 info->cor2 |= CyCtsAE;
3152 }else{
3153 info->flags &= ~ASYNC_CTS_FLOW;
3154 info->cor2 &= ~CyCtsAE;
3155 } 3117 }
3156 if (cflag & CLOCAL) 3118
3157 info->flags &= ~ASYNC_CHECK_CD; 3119 card = info->card;
3158 else 3120 channel = (info->line) - (cy_card[card].first_line);
3159 info->flags |= ASYNC_CHECK_CD; 3121 chip_number = channel / 4;
3122
3123 if (!IS_CYC_Z(cy_card[card])) {
3124
3125 index = cy_card[card].bus_index;
3126
3127 /* baud rate */
3128 baud = tty_get_baud_rate(info->tty);
3129 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3130 ASYNC_SPD_CUST) {
3131 if (info->custom_divisor)
3132 baud_rate = info->baud / info->custom_divisor;
3133 else
3134 baud_rate = info->baud;
3135 } else if (baud > CD1400_MAX_SPEED) {
3136 baud = CD1400_MAX_SPEED;
3137 }
3138 /* find the baud index */
3139 for (i = 0; i < 20; i++) {
3140 if (baud == baud_table[i]) {
3141 break;
3142 }
3143 }
3144 if (i == 20) {
3145 i = 19; /* CD1400_MAX_SPEED */
3146 }
3147
3148 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3149 ASYNC_SPD_CUST) {
3150 cyy_baud_calc(info, baud_rate);
3151 } else {
3152 if (info->chip_rev >= CD1400_REV_J) {
3153 /* It is a CD1400 rev. J or later */
3154 info->tbpr = baud_bpr_60[i]; /* Tx BPR */
3155 info->tco = baud_co_60[i]; /* Tx CO */
3156 info->rbpr = baud_bpr_60[i]; /* Rx BPR */
3157 info->rco = baud_co_60[i]; /* Rx CO */
3158 } else {
3159 info->tbpr = baud_bpr_25[i]; /* Tx BPR */
3160 info->tco = baud_co_25[i]; /* Tx CO */
3161 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3162 info->rco = baud_co_25[i]; /* Rx CO */
3163 }
3164 }
3165 if (baud_table[i] == 134) {
3166 /* get it right for 134.5 baud */
3167 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3168 2;
3169 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3170 ASYNC_SPD_CUST) {
3171 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3172 baud_rate) + 2;
3173 } else if (baud_table[i]) {
3174 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3175 baud_table[i]) + 2;
3176 /* this needs to be propagated into the card info */
3177 } else {
3178 info->timeout = 0;
3179 }
3180 /* By tradition (is it a standard?) a baud rate of zero
3181 implies the line should be/has been closed. A bit
3182 later in this routine such a test is performed. */
3183
3184 /* byte size and parity */
3185 info->cor5 = 0;
3186 info->cor4 = 0;
3187 /* receive threshold */
3188 info->cor3 = (info->default_threshold ?
3189 info->default_threshold : baud_cor3[i]);
3190 info->cor2 = CyETC;
3191 switch (cflag & CSIZE) {
3192 case CS5:
3193 info->cor1 = Cy_5_BITS;
3194 break;
3195 case CS6:
3196 info->cor1 = Cy_6_BITS;
3197 break;
3198 case CS7:
3199 info->cor1 = Cy_7_BITS;
3200 break;
3201 case CS8:
3202 info->cor1 = Cy_8_BITS;
3203 break;
3204 }
3205 if (cflag & CSTOPB) {
3206 info->cor1 |= Cy_2_STOP;
3207 }
3208 if (cflag & PARENB) {
3209 if (cflag & PARODD) {
3210 info->cor1 |= CyPARITY_O;
3211 } else {
3212 info->cor1 |= CyPARITY_E;
3213 }
3214 } else {
3215 info->cor1 |= CyPARITY_NONE;
3216 }
3217
3218 /* CTS flow control flag */
3219 if (cflag & CRTSCTS) {
3220 info->flags |= ASYNC_CTS_FLOW;
3221 info->cor2 |= CyCtsAE;
3222 } else {
3223 info->flags &= ~ASYNC_CTS_FLOW;
3224 info->cor2 &= ~CyCtsAE;
3225 }
3226 if (cflag & CLOCAL)
3227 info->flags &= ~ASYNC_CHECK_CD;
3228 else
3229 info->flags |= ASYNC_CHECK_CD;
3160 3230
3161 /*********************************************** 3231 /***********************************************
3162 The hardware option, CyRtsAO, presents RTS when 3232 The hardware option, CyRtsAO, presents RTS when
@@ -3168,300 +3238,319 @@ set_line_char(struct cyclades_port * info)
3168 cable. Contact Marcio Saito for details. 3238 cable. Contact Marcio Saito for details.
3169 ***********************************************/ 3239 ***********************************************/
3170 3240
3171 chip = channel>>2; 3241 chip = channel >> 2;
3172 channel &= 0x03; 3242 channel &= 0x03;
3173 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3243 base_addr = cy_card[card].base_addr +
3244 (cy_chip_offset[chip] << index);
3174 3245
3175 CY_LOCK(info, flags); 3246 CY_LOCK(info, flags);
3176 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3247 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3177 3248
3178 /* tx and rx baud rate */ 3249 /* tx and rx baud rate */
3179 3250
3180 cy_writeb(base_addr+(CyTCOR<<index), info->tco); 3251 cy_writeb(base_addr + (CyTCOR << index), info->tco);
3181 cy_writeb(base_addr+(CyTBPR<<index), info->tbpr); 3252 cy_writeb(base_addr + (CyTBPR << index), info->tbpr);
3182 cy_writeb(base_addr+(CyRCOR<<index), info->rco); 3253 cy_writeb(base_addr + (CyRCOR << index), info->rco);
3183 cy_writeb(base_addr+(CyRBPR<<index), info->rbpr); 3254 cy_writeb(base_addr + (CyRBPR << index), info->rbpr);
3184 3255
3185 /* set line characteristics according configuration */ 3256 /* set line characteristics according configuration */
3186 3257
3187 cy_writeb(base_addr+(CySCHR1<<index), 3258 cy_writeb(base_addr + (CySCHR1 << index),
3188 START_CHAR(info->tty)); 3259 START_CHAR(info->tty));
3189 cy_writeb(base_addr+(CySCHR2<<index), 3260 cy_writeb(base_addr + (CySCHR2 << index), STOP_CHAR(info->tty));
3190 STOP_CHAR(info->tty)); 3261 cy_writeb(base_addr + (CyCOR1 << index), info->cor1);
3191 cy_writeb(base_addr+(CyCOR1<<index), info->cor1); 3262 cy_writeb(base_addr + (CyCOR2 << index), info->cor2);
3192 cy_writeb(base_addr+(CyCOR2<<index), info->cor2); 3263 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3193 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3264 cy_writeb(base_addr + (CyCOR4 << index), info->cor4);
3194 cy_writeb(base_addr+(CyCOR4<<index), info->cor4); 3265 cy_writeb(base_addr + (CyCOR5 << index), info->cor5);
3195 cy_writeb(base_addr+(CyCOR5<<index), info->cor5); 3266
3196 3267 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
3197 cyy_issue_cmd(base_addr, 3268 CyCOR3ch, index);
3198 CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch,index); 3269
3199 3270 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */
3200 cy_writeb(base_addr+(CyCAR<<index), 3271 cy_writeb(base_addr + (CyRTPR << index),
3201 (u_char)channel); /* !!! Is this needed? */ 3272 (info->default_timeout ? info->default_timeout : 0x02));
3202 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 3273 /* 10ms rx timeout */
3203 ? info->default_timeout 3274
3204 : 0x02)); /* 10ms rx timeout */ 3275 if (C_CLOCAL(info->tty)) {
3205 3276 /* without modem intr */
3206 if (C_CLOCAL(info->tty)) { 3277 cy_writeb(base_addr + (CySRER << index),
3207 /* without modem intr */ 3278 cy_readb(base_addr +
3208 cy_writeb(base_addr+(CySRER<<index), 3279 (CySRER << index)) | CyMdmCh);
3209 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh); 3280 /* act on 1->0 modem transitions */
3210 /* act on 1->0 modem transitions */ 3281 if ((cflag & CRTSCTS) && info->rflow) {
3211 if ((cflag & CRTSCTS) && info->rflow) { 3282 cy_writeb(base_addr + (CyMCOR1 << index),
3212 cy_writeb(base_addr+(CyMCOR1<<index), 3283 (CyCTS | rflow_thr[i]));
3213 (CyCTS|rflow_thr[i])); 3284 } else {
3214 } else { 3285 cy_writeb(base_addr + (CyMCOR1 << index),
3215 cy_writeb(base_addr+(CyMCOR1<<index), CyCTS); 3286 CyCTS);
3216 } 3287 }
3217 /* act on 0->1 modem transitions */ 3288 /* act on 0->1 modem transitions */
3218 cy_writeb(base_addr+(CyMCOR2<<index), CyCTS); 3289 cy_writeb(base_addr + (CyMCOR2 << index), CyCTS);
3219 } else {
3220 /* without modem intr */
3221 cy_writeb(base_addr+(CySRER<<index),
3222 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
3223 /* act on 1->0 modem transitions */
3224 if ((cflag & CRTSCTS) && info->rflow) {
3225 cy_writeb(base_addr+(CyMCOR1<<index),
3226 (CyDSR|CyCTS|CyRI|CyDCD|rflow_thr[i]));
3227 } else {
3228 cy_writeb(base_addr+(CyMCOR1<<index),
3229 CyDSR|CyCTS|CyRI|CyDCD);
3230 }
3231 /* act on 0->1 modem transitions */
3232 cy_writeb(base_addr+(CyMCOR2<<index),
3233 CyDSR|CyCTS|CyRI|CyDCD);
3234 }
3235
3236 if(i == 0){ /* baud rate is zero, turn off line */
3237 if (info->rtsdtr_inv) {
3238 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
3239 } else { 3290 } else {
3240 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3291 /* without modem intr */
3292 cy_writeb(base_addr + (CySRER << index),
3293 cy_readb(base_addr +
3294 (CySRER << index)) | CyMdmCh);
3295 /* act on 1->0 modem transitions */
3296 if ((cflag & CRTSCTS) && info->rflow) {
3297 cy_writeb(base_addr + (CyMCOR1 << index),
3298 (CyDSR | CyCTS | CyRI | CyDCD |
3299 rflow_thr[i]));
3300 } else {
3301 cy_writeb(base_addr + (CyMCOR1 << index),
3302 CyDSR | CyCTS | CyRI | CyDCD);
3303 }
3304 /* act on 0->1 modem transitions */
3305 cy_writeb(base_addr + (CyMCOR2 << index),
3306 CyDSR | CyCTS | CyRI | CyDCD);
3241 } 3307 }
3308
3309 if (i == 0) { /* baud rate is zero, turn off line */
3310 if (info->rtsdtr_inv) {
3311 cy_writeb(base_addr + (CyMSVR1 << index),
3312 ~CyRTS);
3313 } else {
3314 cy_writeb(base_addr + (CyMSVR2 << index),
3315 ~CyDTR);
3316 }
3242#ifdef CY_DEBUG_DTR 3317#ifdef CY_DEBUG_DTR
3243 printk("cyc:set_line_char dropping DTR\n"); 3318 printk("cyc:set_line_char dropping DTR\n");
3244 printk(" status: 0x%x, 0x%x\n", 3319 printk(" status: 0x%x, 0x%x\n",
3245 cy_readb(base_addr+(CyMSVR1<<index)), 3320 cy_readb(base_addr + (CyMSVR1 << index)),
3246 cy_readb(base_addr+(CyMSVR2<<index))); 3321 cy_readb(base_addr + (CyMSVR2 << index)));
3247#endif 3322#endif
3248 }else{ 3323 } else {
3249 if (info->rtsdtr_inv) { 3324 if (info->rtsdtr_inv) {
3250 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3325 cy_writeb(base_addr + (CyMSVR1 << index),
3251 } else { 3326 CyRTS);
3252 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3327 } else {
3253 } 3328 cy_writeb(base_addr + (CyMSVR2 << index),
3329 CyDTR);
3330 }
3254#ifdef CY_DEBUG_DTR 3331#ifdef CY_DEBUG_DTR
3255 printk("cyc:set_line_char raising DTR\n"); 3332 printk("cyc:set_line_char raising DTR\n");
3256 printk(" status: 0x%x, 0x%x\n", 3333 printk(" status: 0x%x, 0x%x\n",
3257 cy_readb(base_addr+(CyMSVR1<<index)), 3334 cy_readb(base_addr + (CyMSVR1 << index)),
3258 cy_readb(base_addr+(CyMSVR2<<index))); 3335 cy_readb(base_addr + (CyMSVR2 << index)));
3259#endif 3336#endif
3260 } 3337 }
3261
3262 if (info->tty){
3263 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3264 }
3265 CY_UNLOCK(info, flags);
3266 3338
3267 } else { 3339 if (info->tty) {
3268 struct FIRM_ID __iomem *firm_id; 3340 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3269 struct ZFW_CTRL __iomem *zfw_ctrl; 3341 }
3270 struct BOARD_CTRL __iomem *board_ctrl; 3342 CY_UNLOCK(info, flags);
3271 struct CH_CTRL __iomem *ch_ctrl;
3272 struct BUF_CTRL __iomem *buf_ctrl;
3273 uclong sw_flow;
3274 int retval;
3275
3276 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3277 if (!ISZLOADED(cy_card[card])) {
3278 return;
3279 }
3280 3343
3281 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3282 board_ctrl = &zfw_ctrl->board_ctrl;
3283 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3284 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3285
3286 /* baud rate */
3287 baud = tty_get_baud_rate(info->tty);
3288 if ((baud == 38400) &&
3289 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3290 if (info->custom_divisor)
3291 baud_rate = info->baud / info->custom_divisor;
3292 else
3293 baud_rate = info->baud;
3294 } else if (baud > CYZ_MAX_SPEED) {
3295 baud = CYZ_MAX_SPEED;
3296 }
3297 cy_writel(&ch_ctrl->comm_baud , baud);
3298
3299 if (baud == 134) {
3300 /* get it right for 134.5 baud */
3301 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3302 } else if ((baud == 38400) &&
3303 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3304 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3305 } else if (baud) {
3306 info->timeout = (info->xmit_fifo_size*HZ*15/baud) + 2;
3307 /* this needs to be propagated into the card info */
3308 } else { 3344 } else {
3309 info->timeout = 0; 3345 struct FIRM_ID __iomem *firm_id;
3310 } 3346 struct ZFW_CTRL __iomem *zfw_ctrl;
3347 struct BOARD_CTRL __iomem *board_ctrl;
3348 struct CH_CTRL __iomem *ch_ctrl;
3349 struct BUF_CTRL __iomem *buf_ctrl;
3350 uclong sw_flow;
3351 int retval;
3352
3353 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3354 if (!ISZLOADED(cy_card[card])) {
3355 return;
3356 }
3311 3357
3312 /* byte size and parity */ 3358 zfw_ctrl = cy_card[card].base_addr +
3313 switch(cflag & CSIZE){ 3359 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3314 case CS5: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS5); break; 3360 board_ctrl = &zfw_ctrl->board_ctrl;
3315 case CS6: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS6); break; 3361 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3316 case CS7: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS7); break; 3362 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3317 case CS8: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS8); break; 3363
3318 } 3364 /* baud rate */
3319 if(cflag & CSTOPB){ 3365 baud = tty_get_baud_rate(info->tty);
3320 cy_writel(&ch_ctrl->comm_data_l, 3366 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3321 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP); 3367 ASYNC_SPD_CUST) {
3322 }else{ 3368 if (info->custom_divisor)
3323 cy_writel(&ch_ctrl->comm_data_l, 3369 baud_rate = info->baud / info->custom_divisor;
3324 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP); 3370 else
3325 } 3371 baud_rate = info->baud;
3326 if (cflag & PARENB){ 3372 } else if (baud > CYZ_MAX_SPEED) {
3327 if (cflag & PARODD){ 3373 baud = CYZ_MAX_SPEED;
3328 cy_writel(&ch_ctrl->comm_parity , C_PR_ODD); 3374 }
3329 }else{ 3375 cy_writel(&ch_ctrl->comm_baud, baud);
3330 cy_writel(&ch_ctrl->comm_parity , C_PR_EVEN); 3376
3331 } 3377 if (baud == 134) {
3332 }else{ 3378 /* get it right for 134.5 baud */
3333 cy_writel(&ch_ctrl->comm_parity , C_PR_NONE); 3379 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3334 } 3380 2;
3381 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3382 ASYNC_SPD_CUST) {
3383 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3384 baud_rate) + 2;
3385 } else if (baud) {
3386 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3387 baud) + 2;
3388 /* this needs to be propagated into the card info */
3389 } else {
3390 info->timeout = 0;
3391 }
3335 3392
3336 /* CTS flow control flag */ 3393 /* byte size and parity */
3337 if (cflag & CRTSCTS){ 3394 switch (cflag & CSIZE) {
3338 cy_writel(&ch_ctrl->hw_flow, 3395 case CS5:
3339 cy_readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS); 3396 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS5);
3340 }else{ 3397 break;
3341 cy_writel(&ch_ctrl->hw_flow, 3398 case CS6:
3342 cy_readl(&ch_ctrl->hw_flow) & ~(C_RS_CTS | C_RS_RTS)); 3399 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS6);
3343 } 3400 break;
3344 /* As the HW flow control is done in firmware, the driver doesn't 3401 case CS7:
3345 need to care about it */ 3402 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS7);
3346 info->flags &= ~ASYNC_CTS_FLOW; 3403 break;
3347 3404 case CS8:
3348 /* XON/XOFF/XANY flow control flags */ 3405 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS8);
3349 sw_flow = 0; 3406 break;
3350 if (iflag & IXON){ 3407 }
3351 sw_flow |= C_FL_OXX; 3408 if (cflag & CSTOPB) {
3352 if (iflag & IXANY) 3409 cy_writel(&ch_ctrl->comm_data_l,
3353 sw_flow |= C_FL_OIXANY; 3410 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3354 } 3411 } else {
3355 cy_writel(&ch_ctrl->sw_flow, sw_flow); 3412 cy_writel(&ch_ctrl->comm_data_l,
3413 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3414 }
3415 if (cflag & PARENB) {
3416 if (cflag & PARODD) {
3417 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
3418 } else {
3419 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
3420 }
3421 } else {
3422 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
3423 }
3356 3424
3357 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 3425 /* CTS flow control flag */
3358 if (retval != 0){ 3426 if (cflag & CRTSCTS) {
3359 printk("cyc:set_line_char retval on ttyC%d was %x\n", 3427 cy_writel(&ch_ctrl->hw_flow,
3360 info->line, retval); 3428 cy_readl(&ch_ctrl->
3361 } 3429 hw_flow) | C_RS_CTS | C_RS_RTS);
3430 } else {
3431 cy_writel(&ch_ctrl->hw_flow,
3432 cy_readl(&ch_ctrl->
3433 hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3434 }
3435 /* As the HW flow control is done in firmware, the driver
3436 doesn't need to care about it */
3437 info->flags &= ~ASYNC_CTS_FLOW;
3438
3439 /* XON/XOFF/XANY flow control flags */
3440 sw_flow = 0;
3441 if (iflag & IXON) {
3442 sw_flow |= C_FL_OXX;
3443 if (iflag & IXANY)
3444 sw_flow |= C_FL_OIXANY;
3445 }
3446 cy_writel(&ch_ctrl->sw_flow, sw_flow);
3362 3447
3363 /* CD sensitivity */ 3448 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
3364 if (cflag & CLOCAL){ 3449 if (retval != 0) {
3365 info->flags &= ~ASYNC_CHECK_CD; 3450 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3366 }else{ 3451 info->line, retval);
3367 info->flags |= ASYNC_CHECK_CD; 3452 }
3368 } 3453
3454 /* CD sensitivity */
3455 if (cflag & CLOCAL) {
3456 info->flags &= ~ASYNC_CHECK_CD;
3457 } else {
3458 info->flags |= ASYNC_CHECK_CD;
3459 }
3369 3460
3370 if(baud == 0){ /* baud rate is zero, turn off line */ 3461 if (baud == 0) { /* baud rate is zero, turn off line */
3371 cy_writel(&ch_ctrl->rs_control, 3462 cy_writel(&ch_ctrl->rs_control,
3372 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR); 3463 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3373#ifdef CY_DEBUG_DTR 3464#ifdef CY_DEBUG_DTR
3374 printk("cyc:set_line_char dropping Z DTR\n"); 3465 printk("cyc:set_line_char dropping Z DTR\n");
3375#endif 3466#endif
3376 }else{ 3467 } else {
3377 cy_writel(&ch_ctrl->rs_control, 3468 cy_writel(&ch_ctrl->rs_control,
3378 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR); 3469 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
3379#ifdef CY_DEBUG_DTR 3470#ifdef CY_DEBUG_DTR
3380 printk("cyc:set_line_char raising Z DTR\n"); 3471 printk("cyc:set_line_char raising Z DTR\n");
3381#endif 3472#endif
3382 } 3473 }
3383 3474
3384 retval = cyz_issue_cmd( &cy_card[card], channel, C_CM_IOCTLM, 0L); 3475 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTLM,0L);
3385 if (retval != 0){ 3476 if (retval != 0) {
3386 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n", 3477 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3387 info->line, retval); 3478 info->line, retval);
3388 } 3479 }
3389 3480
3390 if (info->tty){ 3481 if (info->tty) {
3391 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3482 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3483 }
3392 } 3484 }
3393 } 3485} /* set_line_char */
3394} /* set_line_char */
3395
3396 3486
3397static int 3487static int
3398get_serial_info(struct cyclades_port * info, 3488get_serial_info(struct cyclades_port *info,
3399 struct serial_struct __user * retinfo) 3489 struct serial_struct __user * retinfo)
3400{ 3490{
3401 struct serial_struct tmp; 3491 struct serial_struct tmp;
3402 struct cyclades_card *cinfo = &cy_card[info->card]; 3492 struct cyclades_card *cinfo = &cy_card[info->card];
3403
3404 if (!retinfo)
3405 return -EFAULT;
3406 memset(&tmp, 0, sizeof(tmp));
3407 tmp.type = info->type;
3408 tmp.line = info->line;
3409 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3410 tmp.irq = cinfo->irq;
3411 tmp.flags = info->flags;
3412 tmp.close_delay = info->close_delay;
3413 tmp.baud_base = info->baud;
3414 tmp.custom_divisor = info->custom_divisor;
3415 tmp.hub6 = 0; /*!!!*/
3416 return copy_to_user(retinfo,&tmp,sizeof(*retinfo))?-EFAULT:0;
3417} /* get_serial_info */
3418 3493
3494 if (!retinfo)
3495 return -EFAULT;
3496 memset(&tmp, 0, sizeof(tmp));
3497 tmp.type = info->type;
3498 tmp.line = info->line;
3499 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3500 tmp.irq = cinfo->irq;
3501 tmp.flags = info->flags;
3502 tmp.close_delay = info->close_delay;
3503 tmp.baud_base = info->baud;
3504 tmp.custom_divisor = info->custom_divisor;
3505 tmp.hub6 = 0; /*!!! */
3506 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
3507} /* get_serial_info */
3419 3508
3420static int 3509static int
3421set_serial_info(struct cyclades_port * info, 3510set_serial_info(struct cyclades_port *info,
3422 struct serial_struct __user * new_info) 3511 struct serial_struct __user * new_info)
3423{ 3512{
3424 struct serial_struct new_serial; 3513 struct serial_struct new_serial;
3425 struct cyclades_port old_info; 3514 struct cyclades_port old_info;
3426 3515
3427 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 3516 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
3428 return -EFAULT; 3517 return -EFAULT;
3429 old_info = *info; 3518 old_info = *info;
3430 3519
3431 if (!capable(CAP_SYS_ADMIN)) { 3520 if (!capable(CAP_SYS_ADMIN)) {
3432 if ((new_serial.close_delay != info->close_delay) || 3521 if (new_serial.close_delay != info->close_delay ||
3433 (new_serial.baud_base != info->baud) || 3522 new_serial.baud_base != info->baud ||
3434 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != 3523 (new_serial.flags & ASYNC_FLAGS &
3435 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) 3524 ~ASYNC_USR_MASK) !=
3436 return -EPERM; 3525 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
3437 info->flags = ((info->flags & ~ASYNC_USR_MASK) | 3526 return -EPERM;
3438 (new_serial.flags & ASYNC_USR_MASK)); 3527 info->flags = (info->flags & ~ASYNC_USR_MASK) |
3439 info->baud = new_serial.baud_base; 3528 (new_serial.flags & ASYNC_USR_MASK);
3440 info->custom_divisor = new_serial.custom_divisor; 3529 info->baud = new_serial.baud_base;
3441 goto check_and_exit; 3530 info->custom_divisor = new_serial.custom_divisor;
3442 } 3531 goto check_and_exit;
3443 3532 }
3444 3533
3445 /* 3534 /*
3446 * OK, past this point, all the error checking has been done. 3535 * OK, past this point, all the error checking has been done.
3447 * At this point, we start making changes..... 3536 * At this point, we start making changes.....
3448 */ 3537 */
3449 3538
3450 info->baud = new_serial.baud_base; 3539 info->baud = new_serial.baud_base;
3451 info->custom_divisor = new_serial.custom_divisor; 3540 info->custom_divisor = new_serial.custom_divisor;
3452 info->flags = ((info->flags & ~ASYNC_FLAGS) | 3541 info->flags = (info->flags & ~ASYNC_FLAGS) |
3453 (new_serial.flags & ASYNC_FLAGS)); 3542 (new_serial.flags & ASYNC_FLAGS);
3454 info->close_delay = new_serial.close_delay * HZ/100; 3543 info->close_delay = new_serial.close_delay * HZ / 100;
3455 info->closing_wait = new_serial.closing_wait * HZ/100; 3544 info->closing_wait = new_serial.closing_wait * HZ / 100;
3456 3545
3457check_and_exit: 3546check_and_exit:
3458 if (info->flags & ASYNC_INITIALIZED){ 3547 if (info->flags & ASYNC_INITIALIZED) {
3459 set_line_char(info); 3548 set_line_char(info);
3460 return 0; 3549 return 0;
3461 }else{ 3550 } else {
3462 return startup(info); 3551 return startup(info);
3463 } 3552 }
3464} /* set_serial_info */ 3553} /* set_serial_info */
3465 3554
3466/* 3555/*
3467 * get_lsr_info - get line status register info 3556 * get_lsr_info - get line status register info
@@ -3473,441 +3562,452 @@ check_and_exit:
3473 * transmit holding register is empty. This functionality 3562 * transmit holding register is empty. This functionality
3474 * allows an RS485 driver to be written in user space. 3563 * allows an RS485 driver to be written in user space.
3475 */ 3564 */
3476static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value) 3565static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3477{ 3566{
3478 int card, chip, channel, index; 3567 int card, chip, channel, index;
3479 unsigned char status; 3568 unsigned char status;
3480 unsigned int result; 3569 unsigned int result;
3481 unsigned long flags; 3570 unsigned long flags;
3482 void __iomem *base_addr; 3571 void __iomem *base_addr;
3483
3484 card = info->card;
3485 channel = (info->line) - (cy_card[card].first_line);
3486 if (!IS_CYC_Z(cy_card[card])) {
3487 chip = channel>>2;
3488 channel &= 0x03;
3489 index = cy_card[card].bus_index;
3490 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3491 3572
3492 CY_LOCK(info, flags); 3573 card = info->card;
3493 status = cy_readb(base_addr+(CySRER<<index)) & (CyTxRdy|CyTxMpty); 3574 channel = (info->line) - (cy_card[card].first_line);
3494 CY_UNLOCK(info, flags); 3575 if (!IS_CYC_Z(cy_card[card])) {
3495 result = (status ? 0 : TIOCSER_TEMT); 3576 chip = channel >> 2;
3496 } else { 3577 channel &= 0x03;
3497 /* Not supported yet */ 3578 index = cy_card[card].bus_index;
3498 return -EINVAL; 3579 base_addr =
3499 } 3580 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3500 return put_user(result, (unsigned long __user *) value); 3581
3582 CY_LOCK(info, flags);
3583 status = cy_readb(base_addr + (CySRER << index)) &
3584 (CyTxRdy | CyTxMpty);
3585 CY_UNLOCK(info, flags);
3586 result = (status ? 0 : TIOCSER_TEMT);
3587 } else {
3588 /* Not supported yet */
3589 return -EINVAL;
3590 }
3591 return put_user(result, (unsigned long __user *)value);
3501} 3592}
3502 3593
3503static int 3594static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3504cy_tiocmget(struct tty_struct *tty, struct file *file)
3505{ 3595{
3506 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3596 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3507 int card,chip,channel,index; 3597 int card, chip, channel, index;
3508 void __iomem *base_addr; 3598 void __iomem *base_addr;
3509 unsigned long flags; 3599 unsigned long flags;
3510 unsigned char status; 3600 unsigned char status;
3511 unsigned long lstatus; 3601 unsigned long lstatus;
3512 unsigned int result; 3602 unsigned int result;
3513 struct FIRM_ID __iomem *firm_id; 3603 struct FIRM_ID __iomem *firm_id;
3514 struct ZFW_CTRL __iomem *zfw_ctrl; 3604 struct ZFW_CTRL __iomem *zfw_ctrl;
3515 struct BOARD_CTRL __iomem *board_ctrl; 3605 struct BOARD_CTRL __iomem *board_ctrl;
3516 struct CH_CTRL __iomem *ch_ctrl; 3606 struct CH_CTRL __iomem *ch_ctrl;
3517 3607
3518 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3608 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3519 return -ENODEV; 3609 return -ENODEV;
3520
3521 card = info->card;
3522 channel = (info->line) - (cy_card[card].first_line);
3523 if (!IS_CYC_Z(cy_card[card])) {
3524 chip = channel>>2;
3525 channel &= 0x03;
3526 index = cy_card[card].bus_index;
3527 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3528 3610
3529 CY_LOCK(info, flags); 3611 card = info->card;
3530 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3612 channel = (info->line) - (cy_card[card].first_line);
3531 status = cy_readb(base_addr+(CyMSVR1<<index)); 3613 if (!IS_CYC_Z(cy_card[card])) {
3532 status |= cy_readb(base_addr+(CyMSVR2<<index)); 3614 chip = channel >> 2;
3533 CY_UNLOCK(info, flags); 3615 channel &= 0x03;
3616 index = cy_card[card].bus_index;
3617 base_addr =
3618 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3534 3619
3535 if (info->rtsdtr_inv) { 3620 CY_LOCK(info, flags);
3536 result = ((status & CyRTS) ? TIOCM_DTR : 0) 3621 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3537 | ((status & CyDTR) ? TIOCM_RTS : 0); 3622 status = cy_readb(base_addr + (CyMSVR1 << index));
3623 status |= cy_readb(base_addr + (CyMSVR2 << index));
3624 CY_UNLOCK(info, flags);
3625
3626 if (info->rtsdtr_inv) {
3627 result = ((status & CyRTS) ? TIOCM_DTR : 0) |
3628 ((status & CyDTR) ? TIOCM_RTS : 0);
3629 } else {
3630 result = ((status & CyRTS) ? TIOCM_RTS : 0) |
3631 ((status & CyDTR) ? TIOCM_DTR : 0);
3632 }
3633 result |= ((status & CyDCD) ? TIOCM_CAR : 0) |
3634 ((status & CyRI) ? TIOCM_RNG : 0) |
3635 ((status & CyDSR) ? TIOCM_DSR : 0) |
3636 ((status & CyCTS) ? TIOCM_CTS : 0);
3538 } else { 3637 } else {
3539 result = ((status & CyRTS) ? TIOCM_RTS : 0) 3638 base_addr = cy_card[card].base_addr;
3540 | ((status & CyDTR) ? TIOCM_DTR : 0);
3541 }
3542 result |= ((status & CyDCD) ? TIOCM_CAR : 0)
3543 | ((status & CyRI) ? TIOCM_RNG : 0)
3544 | ((status & CyDSR) ? TIOCM_DSR : 0)
3545 | ((status & CyCTS) ? TIOCM_CTS : 0);
3546 } else {
3547 base_addr = cy_card[card].base_addr;
3548
3549 if (cy_card[card].num_chips != -1){
3550 return -EINVAL;
3551 }
3552 3639
3553 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3640 if (cy_card[card].num_chips != -1) {
3554 if (ISZLOADED(cy_card[card])) { 3641 return -EINVAL;
3555 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3642 }
3556 board_ctrl = &zfw_ctrl->board_ctrl;
3557 ch_ctrl = zfw_ctrl->ch_ctrl;
3558 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3559 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0)
3560 | ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0)
3561 | ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0)
3562 | ((lstatus & C_RS_RI) ? TIOCM_RNG : 0)
3563 | ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0)
3564 | ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3565 }else{
3566 result = 0;
3567 return -ENODEV;
3568 }
3569 3643
3570 } 3644 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3571 return result; 3645 if (ISZLOADED(cy_card[card])) {
3572} /* cy_tiomget */ 3646 zfw_ctrl = cy_card[card].base_addr +
3647 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3648 board_ctrl = &zfw_ctrl->board_ctrl;
3649 ch_ctrl = zfw_ctrl->ch_ctrl;
3650 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3651 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
3652 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
3653 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
3654 ((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
3655 ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
3656 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3657 } else {
3658 result = 0;
3659 return -ENODEV;
3660 }
3573 3661
3662 }
3663 return result;
3664} /* cy_tiomget */
3574 3665
3575static int 3666static int
3576cy_tiocmset(struct tty_struct *tty, struct file *file, 3667cy_tiocmset(struct tty_struct *tty, struct file *file,
3577 unsigned int set, unsigned int clear) 3668 unsigned int set, unsigned int clear)
3578{ 3669{
3579 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3670 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3580 int card,chip,channel,index; 3671 int card, chip, channel, index;
3581 void __iomem *base_addr; 3672 void __iomem *base_addr;
3582 unsigned long flags; 3673 unsigned long flags;
3583 struct FIRM_ID __iomem *firm_id; 3674 struct FIRM_ID __iomem *firm_id;
3584 struct ZFW_CTRL __iomem *zfw_ctrl; 3675 struct ZFW_CTRL __iomem *zfw_ctrl;
3585 struct BOARD_CTRL __iomem *board_ctrl; 3676 struct BOARD_CTRL __iomem *board_ctrl;
3586 struct CH_CTRL __iomem *ch_ctrl; 3677 struct CH_CTRL __iomem *ch_ctrl;
3587 int retval; 3678 int retval;
3588 3679
3589 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3680 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3590 return -ENODEV; 3681 return -ENODEV;
3591 3682
3592 card = info->card; 3683 card = info->card;
3593 channel = (info->line) - (cy_card[card].first_line); 3684 channel = (info->line) - (cy_card[card].first_line);
3594 if (!IS_CYC_Z(cy_card[card])) { 3685 if (!IS_CYC_Z(cy_card[card])) {
3595 chip = channel>>2; 3686 chip = channel >> 2;
3596 channel &= 0x03; 3687 channel &= 0x03;
3597 index = cy_card[card].bus_index; 3688 index = cy_card[card].bus_index;
3598 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3689 base_addr =
3599 3690 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3600 if (set & TIOCM_RTS){ 3691
3601 CY_LOCK(info, flags); 3692 if (set & TIOCM_RTS) {
3602 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3693 CY_LOCK(info, flags);
3603 if (info->rtsdtr_inv) { 3694 cy_writeb(base_addr + (CyCAR << index),
3604 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3695 (u_char) channel);
3605 } else { 3696 if (info->rtsdtr_inv) {
3606 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3697 cy_writeb(base_addr + (CyMSVR2 << index),
3607 } 3698 CyDTR);
3608 CY_UNLOCK(info, flags); 3699 } else {
3609 } 3700 cy_writeb(base_addr + (CyMSVR1 << index),
3610 if (clear & TIOCM_RTS) { 3701 CyRTS);
3611 CY_LOCK(info, flags); 3702 }
3612 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3703 CY_UNLOCK(info, flags);
3613 if (info->rtsdtr_inv) { 3704 }
3614 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3705 if (clear & TIOCM_RTS) {
3615 } else { 3706 CY_LOCK(info, flags);
3616 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3707 cy_writeb(base_addr + (CyCAR << index),
3617 } 3708 (u_char) channel);
3618 CY_UNLOCK(info, flags); 3709 if (info->rtsdtr_inv) {
3619 } 3710 cy_writeb(base_addr + (CyMSVR2 << index),
3620 if (set & TIOCM_DTR){ 3711 ~CyDTR);
3621 CY_LOCK(info, flags); 3712 } else {
3622 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3713 cy_writeb(base_addr + (CyMSVR1 << index),
3623 if (info->rtsdtr_inv) { 3714 ~CyRTS);
3624 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3715 }
3625 } else { 3716 CY_UNLOCK(info, flags);
3626 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3717 }
3627 } 3718 if (set & TIOCM_DTR) {
3719 CY_LOCK(info, flags);
3720 cy_writeb(base_addr + (CyCAR << index),
3721 (u_char) channel);
3722 if (info->rtsdtr_inv) {
3723 cy_writeb(base_addr + (CyMSVR1 << index),
3724 CyRTS);
3725 } else {
3726 cy_writeb(base_addr + (CyMSVR2 << index),
3727 CyDTR);
3728 }
3628#ifdef CY_DEBUG_DTR 3729#ifdef CY_DEBUG_DTR
3629 printk("cyc:set_modem_info raising DTR\n"); 3730 printk("cyc:set_modem_info raising DTR\n");
3630 printk(" status: 0x%x, 0x%x\n", 3731 printk(" status: 0x%x, 0x%x\n",
3631 cy_readb(base_addr+(CyMSVR1<<index)), 3732 cy_readb(base_addr + (CyMSVR1 << index)),
3632 cy_readb(base_addr+(CyMSVR2<<index))); 3733 cy_readb(base_addr + (CyMSVR2 << index)));
3633#endif 3734#endif
3634 CY_UNLOCK(info, flags); 3735 CY_UNLOCK(info, flags);
3635 } 3736 }
3636 if (clear & TIOCM_DTR) { 3737 if (clear & TIOCM_DTR) {
3637 CY_LOCK(info, flags); 3738 CY_LOCK(info, flags);
3638 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3739 cy_writeb(base_addr + (CyCAR << index),
3639 if (info->rtsdtr_inv) { 3740 (u_char) channel);
3640 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3741 if (info->rtsdtr_inv) {
3641 } else { 3742 cy_writeb(base_addr + (CyMSVR1 << index),
3642 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3743 ~CyRTS);
3643 } 3744 } else {
3745 cy_writeb(base_addr + (CyMSVR2 << index),
3746 ~CyDTR);
3747 }
3644 3748
3645#ifdef CY_DEBUG_DTR 3749#ifdef CY_DEBUG_DTR
3646 printk("cyc:set_modem_info dropping DTR\n"); 3750 printk("cyc:set_modem_info dropping DTR\n");
3647 printk(" status: 0x%x, 0x%x\n", 3751 printk(" status: 0x%x, 0x%x\n",
3648 cy_readb(base_addr+(CyMSVR1<<index)), 3752 cy_readb(base_addr + (CyMSVR1 << index)),
3649 cy_readb(base_addr+(CyMSVR2<<index))); 3753 cy_readb(base_addr + (CyMSVR2 << index)));
3650#endif 3754#endif
3651 CY_UNLOCK(info, flags); 3755 CY_UNLOCK(info, flags);
3652 } 3756 }
3653 } else { 3757 } else {
3654 base_addr = cy_card[card].base_addr; 3758 base_addr = cy_card[card].base_addr;
3655 3759
3656 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3760 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3657 if (ISZLOADED(cy_card[card])) { 3761 if (ISZLOADED(cy_card[card])) {
3658 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3762 zfw_ctrl = cy_card[card].base_addr +
3659 board_ctrl = &zfw_ctrl->board_ctrl; 3763 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3660 ch_ctrl = zfw_ctrl->ch_ctrl; 3764 board_ctrl = &zfw_ctrl->board_ctrl;
3661 3765 ch_ctrl = zfw_ctrl->ch_ctrl;
3662 if (set & TIOCM_RTS){ 3766
3663 CY_LOCK(info, flags); 3767 if (set & TIOCM_RTS) {
3664 cy_writel(&ch_ctrl[channel].rs_control, 3768 CY_LOCK(info, flags);
3665 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS); 3769 cy_writel(&ch_ctrl[channel].rs_control,
3666 CY_UNLOCK(info, flags); 3770 cy_readl(&ch_ctrl[channel].
3667 } 3771 rs_control) | C_RS_RTS);
3668 if (clear & TIOCM_RTS) { 3772 CY_UNLOCK(info, flags);
3669 CY_LOCK(info, flags); 3773 }
3670 cy_writel(&ch_ctrl[channel].rs_control, 3774 if (clear & TIOCM_RTS) {
3671 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS); 3775 CY_LOCK(info, flags);
3672 CY_UNLOCK(info, flags); 3776 cy_writel(&ch_ctrl[channel].rs_control,
3673 } 3777 cy_readl(&ch_ctrl[channel].
3674 if (set & TIOCM_DTR){ 3778 rs_control) & ~C_RS_RTS);
3675 CY_LOCK(info, flags); 3779 CY_UNLOCK(info, flags);
3676 cy_writel(&ch_ctrl[channel].rs_control, 3780 }
3677 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR); 3781 if (set & TIOCM_DTR) {
3782 CY_LOCK(info, flags);
3783 cy_writel(&ch_ctrl[channel].rs_control,
3784 cy_readl(&ch_ctrl[channel].
3785 rs_control) | C_RS_DTR);
3678#ifdef CY_DEBUG_DTR 3786#ifdef CY_DEBUG_DTR
3679 printk("cyc:set_modem_info raising Z DTR\n"); 3787 printk("cyc:set_modem_info raising Z DTR\n");
3680#endif 3788#endif
3681 CY_UNLOCK(info, flags); 3789 CY_UNLOCK(info, flags);
3682 } 3790 }
3683 if (clear & TIOCM_DTR) { 3791 if (clear & TIOCM_DTR) {
3684 CY_LOCK(info, flags); 3792 CY_LOCK(info, flags);
3685 cy_writel(&ch_ctrl[channel].rs_control, 3793 cy_writel(&ch_ctrl[channel].rs_control,
3686 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR); 3794 cy_readl(&ch_ctrl[channel].
3795 rs_control) & ~C_RS_DTR);
3687#ifdef CY_DEBUG_DTR 3796#ifdef CY_DEBUG_DTR
3688 printk("cyc:set_modem_info clearing Z DTR\n"); 3797 printk("cyc:set_modem_info clearing Z DTR\n");
3689#endif 3798#endif
3690 CY_UNLOCK(info, flags); 3799 CY_UNLOCK(info, flags);
3691 } 3800 }
3692 }else{ 3801 } else {
3693 return -ENODEV; 3802 return -ENODEV;
3694 } 3803 }
3695 CY_LOCK(info, flags); 3804 CY_LOCK(info, flags);
3696 retval = cyz_issue_cmd(&cy_card[info->card], 3805 retval = cyz_issue_cmd(&cy_card[info->card],
3697 channel, C_CM_IOCTLM,0L); 3806 channel, C_CM_IOCTLM, 0L);
3698 if (retval != 0){ 3807 if (retval != 0) {
3699 printk("cyc:set_modem_info retval on ttyC%d was %x\n", 3808 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3700 info->line, retval); 3809 info->line, retval);
3810 }
3811 CY_UNLOCK(info, flags);
3701 } 3812 }
3702 CY_UNLOCK(info, flags); 3813 return 0;
3703 } 3814} /* cy_tiocmset */
3704 return 0;
3705} /* cy_tiocmset */
3706 3815
3707/* 3816/*
3708 * cy_break() --- routine which turns the break handling on or off 3817 * cy_break() --- routine which turns the break handling on or off
3709 */ 3818 */
3710static void 3819static void cy_break(struct tty_struct *tty, int break_state)
3711cy_break(struct tty_struct *tty, int break_state)
3712{ 3820{
3713 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3821 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3714 unsigned long flags; 3822 unsigned long flags;
3715 3823
3716 if (serial_paranoia_check(info, tty->name, "cy_break")) 3824 if (serial_paranoia_check(info, tty->name, "cy_break"))
3717 return; 3825 return;
3718 3826
3719 CY_LOCK(info, flags); 3827 CY_LOCK(info, flags);
3720 if (!IS_CYC_Z(cy_card[info->card])) { 3828 if (!IS_CYC_Z(cy_card[info->card])) {
3721 /* Let the transmit ISR take care of this (since it 3829 /* Let the transmit ISR take care of this (since it
3722 requires stuffing characters into the output stream). 3830 requires stuffing characters into the output stream).
3723 */ 3831 */
3724 if (break_state == -1) { 3832 if (break_state == -1) {
3725 if (!info->breakon) { 3833 if (!info->breakon) {
3726 info->breakon = 1; 3834 info->breakon = 1;
3727 if (!info->xmit_cnt) { 3835 if (!info->xmit_cnt) {
3728 CY_UNLOCK(info, flags); 3836 CY_UNLOCK(info, flags);
3729 start_xmit(info); 3837 start_xmit(info);
3730 CY_LOCK(info, flags); 3838 CY_LOCK(info, flags);
3839 }
3840 }
3841 } else {
3842 if (!info->breakoff) {
3843 info->breakoff = 1;
3844 if (!info->xmit_cnt) {
3845 CY_UNLOCK(info, flags);
3846 start_xmit(info);
3847 CY_LOCK(info, flags);
3848 }
3849 }
3731 } 3850 }
3732 }
3733 } else { 3851 } else {
3734 if (!info->breakoff) { 3852 int retval;
3735 info->breakoff = 1; 3853
3736 if (!info->xmit_cnt) { 3854 if (break_state == -1) {
3737 CY_UNLOCK(info, flags); 3855 retval = cyz_issue_cmd(&cy_card[info->card],
3738 start_xmit(info); 3856 info->line - cy_card[info->card].first_line,
3739 CY_LOCK(info, flags); 3857 C_CM_SET_BREAK, 0L);
3858 if (retval != 0) {
3859 printk("cyc:cy_break (set) retval on ttyC%d "
3860 "was %x\n", info->line, retval);
3861 }
3862 } else {
3863 retval = cyz_issue_cmd(&cy_card[info->card],
3864 info->line - cy_card[info->card].first_line,
3865 C_CM_CLR_BREAK, 0L);
3866 if (retval != 0) {
3867 printk("cyc:cy_break (clr) retval on ttyC%d "
3868 "was %x\n", info->line, retval);
3869 }
3740 } 3870 }
3741 }
3742 }
3743 } else {
3744 int retval;
3745
3746 if (break_state == -1) {
3747 retval = cyz_issue_cmd(&cy_card[info->card],
3748 (info->line) - (cy_card[info->card].first_line),
3749 C_CM_SET_BREAK, 0L);
3750 if (retval != 0) {
3751 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3752 info->line, retval);
3753 }
3754 } else {
3755 retval = cyz_issue_cmd(&cy_card[info->card],
3756 (info->line) - (cy_card[info->card].first_line),
3757 C_CM_CLR_BREAK, 0L);
3758 if (retval != 0) {
3759 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3760 info->line, retval);
3761 }
3762 } 3871 }
3763 } 3872 CY_UNLOCK(info, flags);
3764 CY_UNLOCK(info, flags); 3873} /* cy_break */
3765} /* cy_break */
3766 3874
3767static int 3875static int
3768get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon) 3876get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
3769{ 3877{
3770 3878
3771 if(copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 3879 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
3772 return -EFAULT; 3880 return -EFAULT;
3773 info->mon.int_count = 0; 3881 info->mon.int_count = 0;
3774 info->mon.char_count = 0; 3882 info->mon.char_count = 0;
3775 info->mon.char_max = 0; 3883 info->mon.char_max = 0;
3776 info->mon.char_last = 0; 3884 info->mon.char_last = 0;
3777 return 0; 3885 return 0;
3778}/* get_mon_info */ 3886} /* get_mon_info */
3779
3780 3887
3781static int 3888static int set_threshold(struct cyclades_port *info, unsigned long value)
3782set_threshold(struct cyclades_port * info, unsigned long value)
3783{ 3889{
3784 void __iomem *base_addr; 3890 void __iomem *base_addr;
3785 int card,channel,chip,index; 3891 int card, channel, chip, index;
3786 unsigned long flags; 3892 unsigned long flags;
3787
3788 card = info->card;
3789 channel = info->line - cy_card[card].first_line;
3790 if (!IS_CYC_Z(cy_card[card])) {
3791 chip = channel>>2;
3792 channel &= 0x03;
3793 index = cy_card[card].bus_index;
3794 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3795
3796 info->cor3 &= ~CyREC_FIFO;
3797 info->cor3 |= value & CyREC_FIFO;
3798 3893
3799 CY_LOCK(info, flags); 3894 card = info->card;
3800 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3895 channel = info->line - cy_card[card].first_line;
3801 cyy_issue_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch,index); 3896 if (!IS_CYC_Z(cy_card[card])) {
3802 CY_UNLOCK(info, flags); 3897 chip = channel >> 2;
3803 } else { 3898 channel &= 0x03;
3804 // Nothing to do! 3899 index = cy_card[card].bus_index;
3805 } 3900 base_addr =
3806 return 0; 3901 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3807}/* set_threshold */
3808 3902
3903 info->cor3 &= ~CyREC_FIFO;
3904 info->cor3 |= value & CyREC_FIFO;
3809 3905
3810static int 3906 CY_LOCK(info, flags);
3811get_threshold(struct cyclades_port * info, unsigned long __user *value) 3907 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3812{ 3908 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
3813 void __iomem *base_addr; 3909 CY_UNLOCK(info, flags);
3814 int card,channel,chip,index; 3910 } else {
3815 unsigned long tmp; 3911 /* Nothing to do! */
3816 3912 }
3817 card = info->card;
3818 channel = info->line - cy_card[card].first_line;
3819 if (!IS_CYC_Z(cy_card[card])) {
3820 chip = channel>>2;
3821 channel &= 0x03;
3822 index = cy_card[card].bus_index;
3823 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3824
3825 tmp = cy_readb(base_addr+(CyCOR3<<index)) & CyREC_FIFO;
3826 return put_user(tmp,value);
3827 } else {
3828 // Nothing to do!
3829 return 0; 3913 return 0;
3830 } 3914} /* set_threshold */
3831}/* get_threshold */
3832
3833 3915
3834static int 3916static int
3835set_default_threshold(struct cyclades_port * info, unsigned long value) 3917get_threshold(struct cyclades_port *info, unsigned long __user * value)
3836{ 3918{
3837 info->default_threshold = value & 0x0f; 3919 void __iomem *base_addr;
3838 return 0; 3920 int card, channel, chip, index;
3839}/* set_default_threshold */ 3921 unsigned long tmp;
3840 3922
3923 card = info->card;
3924 channel = info->line - cy_card[card].first_line;
3925 if (!IS_CYC_Z(cy_card[card])) {
3926 chip = channel >> 2;
3927 channel &= 0x03;
3928 index = cy_card[card].bus_index;
3929 base_addr =
3930 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3931
3932 tmp = cy_readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
3933 return put_user(tmp, value);
3934 } else {
3935 /* Nothing to do! */
3936 return 0;
3937 }
3938} /* get_threshold */
3841 3939
3842static int 3940static int
3843get_default_threshold(struct cyclades_port * info, unsigned long __user *value) 3941set_default_threshold(struct cyclades_port *info, unsigned long value)
3844{ 3942{
3845 return put_user(info->default_threshold,value); 3943 info->default_threshold = value & 0x0f;
3846}/* get_default_threshold */ 3944 return 0;
3847 3945} /* set_default_threshold */
3848 3946
3849static int 3947static int
3850set_timeout(struct cyclades_port * info, unsigned long value) 3948get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
3851{ 3949{
3852 void __iomem *base_addr; 3950 return put_user(info->default_threshold, value);
3853 int card,channel,chip,index; 3951} /* get_default_threshold */
3854 unsigned long flags;
3855
3856 card = info->card;
3857 channel = info->line - cy_card[card].first_line;
3858 if (!IS_CYC_Z(cy_card[card])) {
3859 chip = channel>>2;
3860 channel &= 0x03;
3861 index = cy_card[card].bus_index;
3862 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3863 3952
3864 CY_LOCK(info, flags); 3953static int set_timeout(struct cyclades_port *info, unsigned long value)
3865 cy_writeb(base_addr+(CyRTPR<<index), value & 0xff); 3954{
3866 CY_UNLOCK(info, flags); 3955 void __iomem *base_addr;
3867 } else { 3956 int card, channel, chip, index;
3868 // Nothing to do! 3957 unsigned long flags;
3869 }
3870 return 0;
3871}/* set_timeout */
3872 3958
3959 card = info->card;
3960 channel = info->line - cy_card[card].first_line;
3961 if (!IS_CYC_Z(cy_card[card])) {
3962 chip = channel >> 2;
3963 channel &= 0x03;
3964 index = cy_card[card].bus_index;
3965 base_addr =
3966 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3873 3967
3874static int 3968 CY_LOCK(info, flags);
3875get_timeout(struct cyclades_port * info, unsigned long __user *value) 3969 cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
3876{ 3970 CY_UNLOCK(info, flags);
3877 void __iomem *base_addr; 3971 } else {
3878 int card,channel,chip,index; 3972 /* Nothing to do! */
3879 unsigned long tmp; 3973 }
3880
3881 card = info->card;
3882 channel = info->line - cy_card[card].first_line;
3883 if (!IS_CYC_Z(cy_card[card])) {
3884 chip = channel>>2;
3885 channel &= 0x03;
3886 index = cy_card[card].bus_index;
3887 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3888
3889 tmp = cy_readb(base_addr+(CyRTPR<<index));
3890 return put_user(tmp,value);
3891 } else {
3892 // Nothing to do!
3893 return 0; 3974 return 0;
3894 } 3975} /* set_timeout */
3895}/* get_timeout */
3896
3897 3976
3898static int 3977static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
3899set_default_timeout(struct cyclades_port * info, unsigned long value)
3900{ 3978{
3901 info->default_timeout = value & 0xff; 3979 void __iomem *base_addr;
3902 return 0; 3980 int card, channel, chip, index;
3903}/* set_default_timeout */ 3981 unsigned long tmp;
3904 3982
3983 card = info->card;
3984 channel = info->line - cy_card[card].first_line;
3985 if (!IS_CYC_Z(cy_card[card])) {
3986 chip = channel >> 2;
3987 channel &= 0x03;
3988 index = cy_card[card].bus_index;
3989 base_addr =
3990 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3991
3992 tmp = cy_readb(base_addr + (CyRTPR << index));
3993 return put_user(tmp, value);
3994 } else {
3995 /* Nothing to do! */
3996 return 0;
3997 }
3998} /* get_timeout */
3999
4000static int set_default_timeout(struct cyclades_port *info, unsigned long value)
4001{
4002 info->default_timeout = value & 0xff;
4003 return 0;
4004} /* set_default_timeout */
3905 4005
3906static int 4006static int
3907get_default_timeout(struct cyclades_port * info, unsigned long __user *value) 4007get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
3908{ 4008{
3909 return put_user(info->default_timeout,value); 4009 return put_user(info->default_timeout, value);
3910}/* get_default_timeout */ 4010} /* get_default_timeout */
3911 4011
3912/* 4012/*
3913 * This routine allows the tty driver to implement device- 4013 * This routine allows the tty driver to implement device-
@@ -3915,184 +4015,193 @@ get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
3915 * not recognized by the driver, it should return ENOIOCTLCMD. 4015 * not recognized by the driver, it should return ENOIOCTLCMD.
3916 */ 4016 */
3917static int 4017static int
3918cy_ioctl(struct tty_struct *tty, struct file * file, 4018cy_ioctl(struct tty_struct *tty, struct file *file,
3919 unsigned int cmd, unsigned long arg) 4019 unsigned int cmd, unsigned long arg)
3920{ 4020{
3921 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4021 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3922 struct cyclades_icount cprev, cnow; /* kernel counter temps */ 4022 struct cyclades_icount cprev, cnow; /* kernel counter temps */
3923 struct serial_icounter_struct __user *p_cuser; /* user space */ 4023 struct serial_icounter_struct __user *p_cuser; /* user space */
3924 int ret_val = 0; 4024 int ret_val = 0;
3925 unsigned long flags; 4025 unsigned long flags;
3926 void __user *argp = (void __user *)arg; 4026 void __user *argp = (void __user *)arg;
3927 4027
3928 if (serial_paranoia_check(info, tty->name, "cy_ioctl")) 4028 if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
3929 return -ENODEV; 4029 return -ENODEV;
3930 4030
3931#ifdef CY_DEBUG_OTHER 4031#ifdef CY_DEBUG_OTHER
3932 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", 4032 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */
3933 info->line, cmd, arg); /* */
3934#endif 4033#endif
3935 4034
3936 switch (cmd) { 4035 switch (cmd) {
3937 case CYGETMON: 4036 case CYGETMON:
3938 ret_val = get_mon_info(info, argp); 4037 ret_val = get_mon_info(info, argp);
3939 break; 4038 break;
3940 case CYGETTHRESH: 4039 case CYGETTHRESH:
3941 ret_val = get_threshold(info, argp); 4040 ret_val = get_threshold(info, argp);
3942 break; 4041 break;
3943 case CYSETTHRESH: 4042 case CYSETTHRESH:
3944 ret_val = set_threshold(info, arg); 4043 ret_val = set_threshold(info, arg);
3945 break; 4044 break;
3946 case CYGETDEFTHRESH: 4045 case CYGETDEFTHRESH:
3947 ret_val = get_default_threshold(info, argp); 4046 ret_val = get_default_threshold(info, argp);
3948 break; 4047 break;
3949 case CYSETDEFTHRESH: 4048 case CYSETDEFTHRESH:
3950 ret_val = set_default_threshold(info, arg); 4049 ret_val = set_default_threshold(info, arg);
3951 break; 4050 break;
3952 case CYGETTIMEOUT: 4051 case CYGETTIMEOUT:
3953 ret_val = get_timeout(info, argp); 4052 ret_val = get_timeout(info, argp);
3954 break; 4053 break;
3955 case CYSETTIMEOUT: 4054 case CYSETTIMEOUT:
3956 ret_val = set_timeout(info, arg); 4055 ret_val = set_timeout(info, arg);
3957 break; 4056 break;
3958 case CYGETDEFTIMEOUT: 4057 case CYGETDEFTIMEOUT:
3959 ret_val = get_default_timeout(info, argp); 4058 ret_val = get_default_timeout(info, argp);
3960 break; 4059 break;
3961 case CYSETDEFTIMEOUT: 4060 case CYSETDEFTIMEOUT:
3962 ret_val = set_default_timeout(info, arg); 4061 ret_val = set_default_timeout(info, arg);
3963 break; 4062 break;
3964 case CYSETRFLOW: 4063 case CYSETRFLOW:
3965 info->rflow = (int)arg; 4064 info->rflow = (int)arg;
3966 ret_val = 0; 4065 ret_val = 0;
3967 break; 4066 break;
3968 case CYGETRFLOW: 4067 case CYGETRFLOW:
3969 ret_val = info->rflow; 4068 ret_val = info->rflow;
3970 break; 4069 break;
3971 case CYSETRTSDTR_INV: 4070 case CYSETRTSDTR_INV:
3972 info->rtsdtr_inv = (int)arg; 4071 info->rtsdtr_inv = (int)arg;
3973 ret_val = 0; 4072 ret_val = 0;
3974 break; 4073 break;
3975 case CYGETRTSDTR_INV: 4074 case CYGETRTSDTR_INV:
3976 ret_val = info->rtsdtr_inv; 4075 ret_val = info->rtsdtr_inv;
3977 break; 4076 break;
3978 case CYGETCARDINFO: 4077 case CYGETCARDINFO:
3979 if (copy_to_user(argp, &cy_card[info->card], 4078 if (copy_to_user(argp, &cy_card[info->card],
3980 sizeof (struct cyclades_card))) { 4079 sizeof(struct cyclades_card))) {
3981 ret_val = -EFAULT; 4080 ret_val = -EFAULT;
4081 break;
4082 }
4083 ret_val = 0;
3982 break; 4084 break;
3983 }
3984 ret_val = 0;
3985 break;
3986 case CYGETCD1400VER: 4085 case CYGETCD1400VER:
3987 ret_val = info->chip_rev; 4086 ret_val = info->chip_rev;
3988 break; 4087 break;
3989#ifndef CONFIG_CYZ_INTR 4088#ifndef CONFIG_CYZ_INTR
3990 case CYZSETPOLLCYCLE: 4089 case CYZSETPOLLCYCLE:
3991 cyz_polling_cycle = (arg * HZ) / 1000; 4090 cyz_polling_cycle = (arg * HZ) / 1000;
3992 ret_val = 0; 4091 ret_val = 0;
3993 break; 4092 break;
3994 case CYZGETPOLLCYCLE: 4093 case CYZGETPOLLCYCLE:
3995 ret_val = (cyz_polling_cycle * 1000) / HZ; 4094 ret_val = (cyz_polling_cycle * 1000) / HZ;
3996 break; 4095 break;
3997#endif /* CONFIG_CYZ_INTR */ 4096#endif /* CONFIG_CYZ_INTR */
3998 case CYSETWAIT: 4097 case CYSETWAIT:
3999 info->closing_wait = (unsigned short)arg * HZ/100; 4098 info->closing_wait = (unsigned short)arg *HZ / 100;
4000 ret_val = 0; 4099 ret_val = 0;
4001 break; 4100 break;
4002 case CYGETWAIT: 4101 case CYGETWAIT:
4003 ret_val = info->closing_wait / (HZ/100); 4102 ret_val = info->closing_wait / (HZ / 100);
4004 break; 4103 break;
4005 case TIOCGSERIAL: 4104 case TIOCGSERIAL:
4006 ret_val = get_serial_info(info, argp); 4105 ret_val = get_serial_info(info, argp);
4007 break; 4106 break;
4008 case TIOCSSERIAL: 4107 case TIOCSSERIAL:
4009 ret_val = set_serial_info(info, argp); 4108 ret_val = set_serial_info(info, argp);
4010 break; 4109 break;
4011 case TIOCSERGETLSR: /* Get line status register */ 4110 case TIOCSERGETLSR: /* Get line status register */
4012 ret_val = get_lsr_info(info, argp); 4111 ret_val = get_lsr_info(info, argp);
4013 break; 4112 break;
4014 /* 4113 /*
4015 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 4114 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4016 * - mask passed in arg for lines of interest 4115 * - mask passed in arg for lines of interest
4017 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 4116 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4018 * Caller should use TIOCGICOUNT to see which one it was 4117 * Caller should use TIOCGICOUNT to see which one it was
4019 */ 4118 */
4020 case TIOCMIWAIT: 4119 case TIOCMIWAIT:
4021 CY_LOCK(info, flags);
4022 /* note the counters on entry */
4023 cprev = info->icount;
4024 CY_UNLOCK(info, flags);
4025 while (1) {
4026 interruptible_sleep_on(&info->delta_msr_wait);
4027 /* see if a signal did it */
4028 if (signal_pending(current)) {
4029 return -ERESTARTSYS;
4030 }
4031
4032 CY_LOCK(info, flags); 4120 CY_LOCK(info, flags);
4033 cnow = info->icount; /* atomic copy */ 4121 /* note the counters on entry */
4122 cprev = info->icount;
4034 CY_UNLOCK(info, flags); 4123 CY_UNLOCK(info, flags);
4124 while (1) {
4125 interruptible_sleep_on(&info->delta_msr_wait);
4126 /* see if a signal did it */
4127 if (signal_pending(current)) {
4128 return -ERESTARTSYS;
4129 }
4035 4130
4036 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 4131 CY_LOCK(info, flags);
4037 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) { 4132 cnow = info->icount; /* atomic copy */
4038 return -EIO; /* no change => error */ 4133 CY_UNLOCK(info, flags);
4039 }
4040 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4041 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4042 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4043 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
4044 return 0;
4045 }
4046 cprev = cnow;
4047 }
4048 /* NOTREACHED */
4049 4134
4050 /* 4135 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
4051 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 4136 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
4052 * Return: write counters to the user passed counter struct 4137 return -EIO; /* no change => error */
4053 * NB: both 1->0 and 0->1 transitions are counted except for 4138 }
4054 * RI where only 0->1 is counted. 4139 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4055 */ 4140 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4141 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4142 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
4143 return 0;
4144 }
4145 cprev = cnow;
4146 }
4147 /* NOTREACHED */
4148
4149 /*
4150 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4151 * Return: write counters to the user passed counter struct
4152 * NB: both 1->0 and 0->1 transitions are counted except for
4153 * RI where only 0->1 is counted.
4154 */
4056 case TIOCGICOUNT: 4155 case TIOCGICOUNT:
4057 CY_LOCK(info, flags); 4156 CY_LOCK(info, flags);
4058 cnow = info->icount; 4157 cnow = info->icount;
4059 CY_UNLOCK(info, flags); 4158 CY_UNLOCK(info, flags);
4060 p_cuser = argp; 4159 p_cuser = argp;
4061 ret_val = put_user(cnow.cts, &p_cuser->cts); 4160 ret_val = put_user(cnow.cts, &p_cuser->cts);
4062 if (ret_val) return ret_val; 4161 if (ret_val)
4063 ret_val = put_user(cnow.dsr, &p_cuser->dsr); 4162 return ret_val;
4064 if (ret_val) return ret_val; 4163 ret_val = put_user(cnow.dsr, &p_cuser->dsr);
4065 ret_val = put_user(cnow.rng, &p_cuser->rng); 4164 if (ret_val)
4066 if (ret_val) return ret_val; 4165 return ret_val;
4067 ret_val = put_user(cnow.dcd, &p_cuser->dcd); 4166 ret_val = put_user(cnow.rng, &p_cuser->rng);
4068 if (ret_val) return ret_val; 4167 if (ret_val)
4069 ret_val = put_user(cnow.rx, &p_cuser->rx); 4168 return ret_val;
4070 if (ret_val) return ret_val; 4169 ret_val = put_user(cnow.dcd, &p_cuser->dcd);
4071 ret_val = put_user(cnow.tx, &p_cuser->tx); 4170 if (ret_val)
4072 if (ret_val) return ret_val; 4171 return ret_val;
4073 ret_val = put_user(cnow.frame, &p_cuser->frame); 4172 ret_val = put_user(cnow.rx, &p_cuser->rx);
4074 if (ret_val) return ret_val; 4173 if (ret_val)
4075 ret_val = put_user(cnow.overrun, &p_cuser->overrun); 4174 return ret_val;
4076 if (ret_val) return ret_val; 4175 ret_val = put_user(cnow.tx, &p_cuser->tx);
4077 ret_val = put_user(cnow.parity, &p_cuser->parity); 4176 if (ret_val)
4078 if (ret_val) return ret_val; 4177 return ret_val;
4079 ret_val = put_user(cnow.brk, &p_cuser->brk); 4178 ret_val = put_user(cnow.frame, &p_cuser->frame);
4080 if (ret_val) return ret_val; 4179 if (ret_val)
4081 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun); 4180 return ret_val;
4082 if (ret_val) return ret_val; 4181 ret_val = put_user(cnow.overrun, &p_cuser->overrun);
4083 ret_val = 0; 4182 if (ret_val)
4084 break; 4183 return ret_val;
4085 default: 4184 ret_val = put_user(cnow.parity, &p_cuser->parity);
4086 ret_val = -ENOIOCTLCMD; 4185 if (ret_val)
4087 } 4186 return ret_val;
4187 ret_val = put_user(cnow.brk, &p_cuser->brk);
4188 if (ret_val)
4189 return ret_val;
4190 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
4191 if (ret_val)
4192 return ret_val;
4193 ret_val = 0;
4194 break;
4195 default:
4196 ret_val = -ENOIOCTLCMD;
4197 }
4088 4198
4089#ifdef CY_DEBUG_OTHER 4199#ifdef CY_DEBUG_OTHER
4090 printk(" cyc:cy_ioctl done\n"); 4200 printk(" cyc:cy_ioctl done\n");
4091#endif 4201#endif
4092 4202
4093 return ret_val; 4203 return ret_val;
4094} /* cy_ioctl */ 4204} /* cy_ioctl */
4095
4096 4205
4097/* 4206/*
4098 * This routine allows the tty driver to be notified when 4207 * This routine allows the tty driver to be notified when
@@ -4100,66 +4209,64 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
4100 * well-designed tty driver should be prepared to accept the case 4209 * well-designed tty driver should be prepared to accept the case
4101 * where old == NULL, and try to do something rational. 4210 * where old == NULL, and try to do something rational.
4102 */ 4211 */
4103static void 4212static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4104cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
4105{ 4213{
4106 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4214 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4107 4215
4108#ifdef CY_DEBUG_OTHER 4216#ifdef CY_DEBUG_OTHER
4109 printk("cyc:cy_set_termios ttyC%d\n", info->line); 4217 printk("cyc:cy_set_termios ttyC%d\n", info->line);
4110#endif 4218#endif
4111 4219
4112 if ((tty->termios->c_cflag == old_termios->c_cflag) && 4220 if (tty->termios->c_cflag == old_termios->c_cflag &&
4113 ((tty->termios->c_iflag & (IXON|IXANY)) == 4221 (tty->termios->c_iflag & (IXON | IXANY)) ==
4114 (old_termios->c_iflag & (IXON|IXANY)))) 4222 (old_termios->c_iflag & (IXON | IXANY)))
4115 return; 4223 return;
4116 set_line_char(info); 4224 set_line_char(info);
4117 4225
4118 if ((old_termios->c_cflag & CRTSCTS) && 4226 if ((old_termios->c_cflag & CRTSCTS) &&
4119 !(tty->termios->c_cflag & CRTSCTS)) { 4227 !(tty->termios->c_cflag & CRTSCTS)) {
4120 tty->hw_stopped = 0; 4228 tty->hw_stopped = 0;
4121 cy_start(tty); 4229 cy_start(tty);
4122 } 4230 }
4123#if 0 4231#if 0
4124 /* 4232 /*
4125 * No need to wake up processes in open wait, since they 4233 * No need to wake up processes in open wait, since they
4126 * sample the CLOCAL flag once, and don't recheck it. 4234 * sample the CLOCAL flag once, and don't recheck it.
4127 * XXX It's not clear whether the current behavior is correct 4235 * XXX It's not clear whether the current behavior is correct
4128 * or not. Hence, this may change..... 4236 * or not. Hence, this may change.....
4129 */ 4237 */
4130 if (!(old_termios->c_cflag & CLOCAL) && 4238 if (!(old_termios->c_cflag & CLOCAL) &&
4131 (tty->termios->c_cflag & CLOCAL)) 4239 (tty->termios->c_cflag & CLOCAL))
4132 wake_up_interruptible(&info->open_wait); 4240 wake_up_interruptible(&info->open_wait);
4133#endif 4241#endif
4134 4242} /* cy_set_termios */
4135 return;
4136} /* cy_set_termios */
4137 4243
4138/* This function is used to send a high-priority XON/XOFF character to 4244/* This function is used to send a high-priority XON/XOFF character to
4139 the device. 4245 the device.
4140*/ 4246*/
4141static void 4247static void cy_send_xchar(struct tty_struct *tty, char ch)
4142cy_send_xchar (struct tty_struct *tty, char ch)
4143{ 4248{
4144 struct cyclades_port *info = (struct cyclades_port *) tty->driver_data; 4249 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4145 int card, channel; 4250 int card, channel;
4146 4251
4147 if (serial_paranoia_check (info, tty->name, "cy_send_xchar")) 4252 if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
4148 return; 4253 return;
4149 4254
4150 info->x_char = ch; 4255 info->x_char = ch;
4151 4256
4152 if (ch) 4257 if (ch)
4153 cy_start (tty); 4258 cy_start(tty);
4154 4259
4155 card = info->card; 4260 card = info->card;
4156 channel = info->line - cy_card[card].first_line; 4261 channel = info->line - cy_card[card].first_line;
4157 4262
4158 if (IS_CYC_Z (cy_card[card])) { 4263 if (IS_CYC_Z(cy_card[card])) {
4159 if (ch == STOP_CHAR (tty)) 4264 if (ch == STOP_CHAR(tty))
4160 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXOFF, 0L); 4265 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXOFF,
4161 else if (ch == START_CHAR (tty)) 4266 0L);
4162 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXON, 0L); 4267 else if (ch == START_CHAR(tty))
4268 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXON,
4269 0L);
4163 } 4270 }
4164} 4271}
4165 4272
@@ -4167,260 +4274,248 @@ cy_send_xchar (struct tty_struct *tty, char ch)
4167 that incoming characters should be throttled because the input 4274 that incoming characters should be throttled because the input
4168 buffers are close to full. 4275 buffers are close to full.
4169 */ 4276 */
4170static void 4277static void cy_throttle(struct tty_struct *tty)
4171cy_throttle(struct tty_struct * tty)
4172{ 4278{
4173 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4174 unsigned long flags; 4280 unsigned long flags;
4175 void __iomem *base_addr; 4281 void __iomem *base_addr;
4176 int card,chip,channel,index; 4282 int card, chip, channel, index;
4177 4283
4178#ifdef CY_DEBUG_THROTTLE 4284#ifdef CY_DEBUG_THROTTLE
4179 char buf[64]; 4285 char buf[64];
4180 4286
4181 printk("cyc:throttle %s: %d....ttyC%d\n", 4287 printk("cyc:throttle %s: %d....ttyC%d\n", tty_name(tty, buf),
4182 tty_name(tty, buf), 4288 tty->ldisc.chars_in_buffer(tty), info->line);
4183 tty->ldisc.chars_in_buffer(tty), info->line);
4184#endif 4289#endif
4185 4290
4186 if (serial_paranoia_check(info, tty->name, "cy_throttle")){ 4291 if (serial_paranoia_check(info, tty->name, "cy_throttle")) {
4187 return; 4292 return;
4188 } 4293 }
4189
4190 card = info->card;
4191
4192 if (I_IXOFF(tty)) {
4193 if (!IS_CYC_Z (cy_card[card]))
4194 cy_send_xchar (tty, STOP_CHAR (tty));
4195 else
4196 info->throttle = 1;
4197 }
4198
4199 if (tty->termios->c_cflag & CRTSCTS) {
4200 channel = info->line - cy_card[card].first_line;
4201 if (!IS_CYC_Z(cy_card[card])) {
4202 chip = channel>>2;
4203 channel &= 0x03;
4204 index = cy_card[card].bus_index;
4205 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4206
4207 CY_LOCK(info, flags);
4208 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4209 if (info->rtsdtr_inv) {
4210 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
4211 } else {
4212 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
4213 }
4214 CY_UNLOCK(info, flags);
4215 } else {
4216 info->throttle = 1;
4217 }
4218 }
4219 4294
4220 return; 4295 card = info->card;
4221} /* cy_throttle */ 4296
4297 if (I_IXOFF(tty)) {
4298 if (!IS_CYC_Z(cy_card[card]))
4299 cy_send_xchar(tty, STOP_CHAR(tty));
4300 else
4301 info->throttle = 1;
4302 }
4222 4303
4304 if (tty->termios->c_cflag & CRTSCTS) {
4305 channel = info->line - cy_card[card].first_line;
4306 if (!IS_CYC_Z(cy_card[card])) {
4307 chip = channel >> 2;
4308 channel &= 0x03;
4309 index = cy_card[card].bus_index;
4310 base_addr = cy_card[card].base_addr +
4311 (cy_chip_offset[chip] << index);
4312
4313 CY_LOCK(info, flags);
4314 cy_writeb(base_addr + (CyCAR << index),
4315 (u_char) channel);
4316 if (info->rtsdtr_inv) {
4317 cy_writeb(base_addr + (CyMSVR2 << index),
4318 ~CyDTR);
4319 } else {
4320 cy_writeb(base_addr + (CyMSVR1 << index),
4321 ~CyRTS);
4322 }
4323 CY_UNLOCK(info, flags);
4324 } else {
4325 info->throttle = 1;
4326 }
4327 }
4328} /* cy_throttle */
4223 4329
4224/* 4330/*
4225 * This routine notifies the tty driver that it should signal 4331 * This routine notifies the tty driver that it should signal
4226 * that characters can now be sent to the tty without fear of 4332 * that characters can now be sent to the tty without fear of
4227 * overrunning the input buffers of the line disciplines. 4333 * overrunning the input buffers of the line disciplines.
4228 */ 4334 */
4229static void 4335static void cy_unthrottle(struct tty_struct *tty)
4230cy_unthrottle(struct tty_struct * tty)
4231{ 4336{
4232 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4337 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4233 unsigned long flags; 4338 unsigned long flags;
4234 void __iomem *base_addr; 4339 void __iomem *base_addr;
4235 int card,chip,channel,index; 4340 int card, chip, channel, index;
4236 4341
4237#ifdef CY_DEBUG_THROTTLE 4342#ifdef CY_DEBUG_THROTTLE
4238 char buf[64]; 4343 char buf[64];
4239
4240 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4241 tty_name(tty, buf),
4242 tty->ldisc.chars_in_buffer(tty), info->line);
4243#endif
4244 4344
4245 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")){ 4345 printk("cyc:unthrottle %s: %d....ttyC%d\n", tty_name(tty, buf),
4246 return; 4346 tty->ldisc.chars_in_buffer(tty), info->line);
4247 } 4347#endif
4248 4348
4249 if (I_IXOFF(tty)) { 4349 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
4250 if (info->x_char) 4350 return;
4251 info->x_char = 0;
4252 else
4253 cy_send_xchar (tty, START_CHAR (tty));
4254 }
4255
4256 if (tty->termios->c_cflag & CRTSCTS) {
4257 card = info->card;
4258 channel = info->line - cy_card[card].first_line;
4259 if (!IS_CYC_Z(cy_card[card])) {
4260 chip = channel>>2;
4261 channel &= 0x03;
4262 index = cy_card[card].bus_index;
4263 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4264
4265 CY_LOCK(info, flags);
4266 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4267 if (info->rtsdtr_inv) {
4268 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
4269 } else {
4270 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
4271 }
4272 CY_UNLOCK(info, flags);
4273 } else {
4274 info->throttle = 0;
4275 } 4351 }
4276 }
4277 4352
4278 return; 4353 if (I_IXOFF(tty)) {
4279} /* cy_unthrottle */ 4354 if (info->x_char)
4355 info->x_char = 0;
4356 else
4357 cy_send_xchar(tty, START_CHAR(tty));
4358 }
4280 4359
4360 if (tty->termios->c_cflag & CRTSCTS) {
4361 card = info->card;
4362 channel = info->line - cy_card[card].first_line;
4363 if (!IS_CYC_Z(cy_card[card])) {
4364 chip = channel >> 2;
4365 channel &= 0x03;
4366 index = cy_card[card].bus_index;
4367 base_addr = cy_card[card].base_addr +
4368 (cy_chip_offset[chip] << index);
4369
4370 CY_LOCK(info, flags);
4371 cy_writeb(base_addr + (CyCAR << index),
4372 (u_char) channel);
4373 if (info->rtsdtr_inv) {
4374 cy_writeb(base_addr + (CyMSVR2 << index),
4375 CyDTR);
4376 } else {
4377 cy_writeb(base_addr + (CyMSVR1 << index),
4378 CyRTS);
4379 }
4380 CY_UNLOCK(info, flags);
4381 } else {
4382 info->throttle = 0;
4383 }
4384 }
4385} /* cy_unthrottle */
4281 4386
4282/* cy_start and cy_stop provide software output flow control as a 4387/* cy_start and cy_stop provide software output flow control as a
4283 function of XON/XOFF, software CTS, and other such stuff. 4388 function of XON/XOFF, software CTS, and other such stuff.
4284*/ 4389*/
4285static void 4390static void cy_stop(struct tty_struct *tty)
4286cy_stop(struct tty_struct *tty)
4287{ 4391{
4288 struct cyclades_card *cinfo; 4392 struct cyclades_card *cinfo;
4289 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4393 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4290 void __iomem *base_addr; 4394 void __iomem *base_addr;
4291 int chip,channel,index; 4395 int chip, channel, index;
4292 unsigned long flags; 4396 unsigned long flags;
4293 4397
4294#ifdef CY_DEBUG_OTHER 4398#ifdef CY_DEBUG_OTHER
4295 printk("cyc:cy_stop ttyC%d\n", info->line); /* */ 4399 printk("cyc:cy_stop ttyC%d\n", info->line); /* */
4296#endif 4400#endif
4297 4401
4298 if (serial_paranoia_check(info, tty->name, "cy_stop")) 4402 if (serial_paranoia_check(info, tty->name, "cy_stop"))
4299 return; 4403 return;
4300
4301 cinfo = &cy_card[info->card];
4302 channel = info->line - cinfo->first_line;
4303 if (!IS_CYC_Z(*cinfo)) {
4304 index = cinfo->bus_index;
4305 chip = channel>>2;
4306 channel &= 0x03;
4307 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4308
4309 CY_LOCK(info, flags);
4310 cy_writeb(base_addr+(CyCAR<<index),
4311 (u_char)(channel & 0x0003)); /* index channel */
4312 cy_writeb(base_addr+(CySRER<<index),
4313 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
4314 CY_UNLOCK(info, flags);
4315 } else {
4316 // Nothing to do!
4317 }
4318 4404
4319 return; 4405 cinfo = &cy_card[info->card];
4320} /* cy_stop */ 4406 channel = info->line - cinfo->first_line;
4407 if (!IS_CYC_Z(*cinfo)) {
4408 index = cinfo->bus_index;
4409 chip = channel >> 2;
4410 channel &= 0x03;
4411 base_addr = cy_card[info->card].base_addr +
4412 (cy_chip_offset[chip] << index);
4321 4413
4414 CY_LOCK(info, flags);
4415 cy_writeb(base_addr + (CyCAR << index),
4416 (u_char)(channel & 0x0003)); /* index channel */
4417 cy_writeb(base_addr + (CySRER << index),
4418 cy_readb(base_addr + (CySRER << index)) & ~CyTxRdy);
4419 CY_UNLOCK(info, flags);
4420 } else {
4421 /* Nothing to do! */
4422 }
4423} /* cy_stop */
4322 4424
4323static void 4425static void cy_start(struct tty_struct *tty)
4324cy_start(struct tty_struct *tty)
4325{ 4426{
4326 struct cyclades_card *cinfo; 4427 struct cyclades_card *cinfo;
4327 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4428 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4328 void __iomem *base_addr; 4429 void __iomem *base_addr;
4329 int chip,channel,index; 4430 int chip, channel, index;
4330 unsigned long flags; 4431 unsigned long flags;
4331 4432
4332#ifdef CY_DEBUG_OTHER 4433#ifdef CY_DEBUG_OTHER
4333 printk("cyc:cy_start ttyC%d\n", info->line); /* */ 4434 printk("cyc:cy_start ttyC%d\n", info->line); /* */
4334#endif 4435#endif
4335 4436
4336 if (serial_paranoia_check(info, tty->name, "cy_start")) 4437 if (serial_paranoia_check(info, tty->name, "cy_start"))
4337 return; 4438 return;
4338
4339 cinfo = &cy_card[info->card];
4340 channel = info->line - cinfo->first_line;
4341 index = cinfo->bus_index;
4342 if (!IS_CYC_Z(*cinfo)) {
4343 chip = channel>>2;
4344 channel &= 0x03;
4345 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4346
4347 CY_LOCK(info, flags);
4348 cy_writeb(base_addr+(CyCAR<<index),
4349 (u_char)(channel & 0x0003)); /* index channel */
4350 cy_writeb(base_addr+(CySRER<<index),
4351 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy);
4352 CY_UNLOCK(info, flags);
4353 } else {
4354 // Nothing to do!
4355 }
4356 4439
4357 return; 4440 cinfo = &cy_card[info->card];
4358} /* cy_start */ 4441 channel = info->line - cinfo->first_line;
4442 index = cinfo->bus_index;
4443 if (!IS_CYC_Z(*cinfo)) {
4444 chip = channel >> 2;
4445 channel &= 0x03;
4446 base_addr = cy_card[info->card].base_addr +
4447 (cy_chip_offset[chip] << index);
4359 4448
4449 CY_LOCK(info, flags);
4450 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
4451 cy_writeb(base_addr + (CySRER << index),
4452 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
4453 CY_UNLOCK(info, flags);
4454 } else {
4455 /* Nothing to do! */
4456 }
4457} /* cy_start */
4360 4458
4361static void 4459static void cy_flush_buffer(struct tty_struct *tty)
4362cy_flush_buffer(struct tty_struct *tty)
4363{ 4460{
4364 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4461 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4365 int card, channel, retval; 4462 int card, channel, retval;
4366 unsigned long flags; 4463 unsigned long flags;
4367 4464
4368#ifdef CY_DEBUG_IO 4465#ifdef CY_DEBUG_IO
4369 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */ 4466 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
4370#endif 4467#endif
4371 4468
4372 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 4469 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4373 return; 4470 return;
4374
4375 card = info->card;
4376 channel = (info->line) - (cy_card[card].first_line);
4377 4471
4378 CY_LOCK(info, flags); 4472 card = info->card;
4379 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 4473 channel = (info->line) - (cy_card[card].first_line);
4380 CY_UNLOCK(info, flags);
4381 4474
4382 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4383 buffers as well */
4384 CY_LOCK(info, flags); 4475 CY_LOCK(info, flags);
4385 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L); 4476 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4386 if (retval != 0) {
4387 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4388 info->line, retval);
4389 }
4390 CY_UNLOCK(info, flags); 4477 CY_UNLOCK(info, flags);
4391 }
4392 tty_wakeup(tty);
4393 wake_up_interruptible(&tty->write_wait);
4394} /* cy_flush_buffer */
4395 4478
4479 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4480 buffers as well */
4481 CY_LOCK(info, flags);
4482 retval =
4483 cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
4484 if (retval != 0) {
4485 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4486 info->line, retval);
4487 }
4488 CY_UNLOCK(info, flags);
4489 }
4490 tty_wakeup(tty);
4491 wake_up_interruptible(&tty->write_wait);
4492} /* cy_flush_buffer */
4396 4493
4397/* 4494/*
4398 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 4495 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4399 */ 4496 */
4400static void 4497static void cy_hangup(struct tty_struct *tty)
4401cy_hangup(struct tty_struct *tty)
4402{ 4498{
4403 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4499 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4404 4500
4405#ifdef CY_DEBUG_OTHER 4501#ifdef CY_DEBUG_OTHER
4406 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */ 4502 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
4407#endif 4503#endif
4408 4504
4409 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 4505 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
4410 return; 4506 return;
4411 4507
4412 cy_flush_buffer(tty); 4508 cy_flush_buffer(tty);
4413 shutdown(info); 4509 shutdown(info);
4414 info->event = 0; 4510 info->event = 0;
4415 info->count = 0; 4511 info->count = 0;
4416#ifdef CY_DEBUG_COUNT 4512#ifdef CY_DEBUG_COUNT
4417 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid); 4513 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
4418#endif 4514#endif
4419 info->tty = NULL; 4515 info->tty = NULL;
4420 info->flags &= ~ASYNC_NORMAL_ACTIVE; 4516 info->flags &= ~ASYNC_NORMAL_ACTIVE;
4421 wake_up_interruptible(&info->open_wait); 4517 wake_up_interruptible(&info->open_wait);
4422} /* cy_hangup */ 4518} /* cy_hangup */
4423
4424 4519
4425/* 4520/*
4426 * --------------------------------------------------------------------- 4521 * ---------------------------------------------------------------------
@@ -4433,82 +4528,84 @@ cy_hangup(struct tty_struct *tty)
4433/* initialize chips on Cyclom-Y card -- return number of valid 4528/* initialize chips on Cyclom-Y card -- return number of valid
4434 chips (which is number of ports/4) */ 4529 chips (which is number of ports/4) */
4435static unsigned short __init 4530static unsigned short __init
4436cyy_init_card(void __iomem *true_base_addr,int index) 4531cyy_init_card(void __iomem * true_base_addr, int index)
4437{ 4532{
4438 unsigned int chip_number; 4533 unsigned int chip_number;
4439 void __iomem *base_addr; 4534 void __iomem *base_addr;
4440 4535
4441 cy_writeb(true_base_addr+(Cy_HwReset<<index), 0); 4536 cy_writeb(true_base_addr + (Cy_HwReset << index), 0);
4442 /* Cy_HwReset is 0x1400 */ 4537 /* Cy_HwReset is 0x1400 */
4443 cy_writeb(true_base_addr+(Cy_ClrIntr<<index), 0); 4538 cy_writeb(true_base_addr + (Cy_ClrIntr << index), 0);
4444 /* Cy_ClrIntr is 0x1800 */ 4539 /* Cy_ClrIntr is 0x1800 */
4445 udelay(500L); 4540 udelay(500L);
4446 4541
4447 for(chip_number=0; chip_number<CyMAX_CHIPS_PER_CARD; chip_number++){ 4542 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) {
4448 base_addr = true_base_addr + (cy_chip_offset[chip_number]<<index); 4543 base_addr =
4449 mdelay(1); 4544 true_base_addr + (cy_chip_offset[chip_number] << index);
4450 if(cy_readb(base_addr+(CyCCR<<index)) != 0x00){ 4545 mdelay(1);
4451 /************* 4546 if (cy_readb(base_addr + (CyCCR << index)) != 0x00) {
4452 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n", 4547 /*************
4453 chip_number, (unsigned long)base_addr); 4548 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4454 *************/ 4549 chip_number, (unsigned long)base_addr);
4455 return chip_number; 4550 *************/
4456 } 4551 return chip_number;
4457 4552 }
4458 cy_writeb(base_addr+(CyGFRCR<<index), 0); 4553
4459 udelay(10L); 4554 cy_writeb(base_addr + (CyGFRCR << index), 0);
4460 4555 udelay(10L);
4461 /* The Cyclom-16Y does not decode address bit 9 and therefore 4556
4462 cannot distinguish between references to chip 0 and a non- 4557 /* The Cyclom-16Y does not decode address bit 9 and therefore
4463 existent chip 4. If the preceding clearing of the supposed 4558 cannot distinguish between references to chip 0 and a non-
4464 chip 4 GFRCR register appears at chip 0, there is no chip 4 4559 existent chip 4. If the preceding clearing of the supposed
4465 and this must be a Cyclom-16Y, not a Cyclom-32Ye. 4560 chip 4 GFRCR register appears at chip 0, there is no chip 4
4466 */ 4561 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4467 if (chip_number == 4 4562 */
4468 && cy_readb(true_base_addr 4563 if (chip_number == 4 && cy_readb(true_base_addr +
4469 + (cy_chip_offset[0]<<index) 4564 (cy_chip_offset[0] << index) +
4470 + (CyGFRCR<<index)) == 0){ 4565 (CyGFRCR << index)) == 0) {
4471 return chip_number; 4566 return chip_number;
4472 } 4567 }
4473 4568
4474 cy_writeb(base_addr+(CyCCR<<index), CyCHIP_RESET); 4569 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
4475 mdelay(1); 4570 mdelay(1);
4476 4571
4477 if(cy_readb(base_addr+(CyGFRCR<<index)) == 0x00){ 4572 if (cy_readb(base_addr + (CyGFRCR << index)) == 0x00) {
4478 /* 4573 /*
4479 printk(" chip #%d at %#6lx is not responding ", 4574 printk(" chip #%d at %#6lx is not responding ",
4480 chip_number, (unsigned long)base_addr); 4575 chip_number, (unsigned long)base_addr);
4481 printk("(GFRCR stayed 0)\n", 4576 printk("(GFRCR stayed 0)\n",
4482 */ 4577 */
4483 return chip_number; 4578 return chip_number;
4484 } 4579 }
4485 if((0xf0 & (cy_readb(base_addr+(CyGFRCR<<index)))) != 0x40){ 4580 if ((0xf0 & (cy_readb(base_addr + (CyGFRCR << index)))) !=
4486 /* 4581 0x40) {
4487 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n", 4582 /*
4488 chip_number, (unsigned long)base_addr, 4583 printk(" chip #%d at %#6lx is not valid (GFRCR == "
4489 base_addr[CyGFRCR<<index]); 4584 "%#2x)\n",
4490 */ 4585 chip_number, (unsigned long)base_addr,
4491 return chip_number; 4586 base_addr[CyGFRCR<<index]);
4492 } 4587 */
4493 cy_writeb(base_addr+(CyGCR<<index), CyCH0_SERIAL); 4588 return chip_number;
4494 if (cy_readb(base_addr+(CyGFRCR<<index)) >= CD1400_REV_J){ 4589 }
4495 /* It is a CD1400 rev. J or later */ 4590 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
4496 /* Impossible to reach 5ms with this chip. 4591 if (cy_readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
4497 Changed to 2ms instead (f = 500 Hz). */ 4592 /* It is a CD1400 rev. J or later */
4498 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_60_2MS); 4593 /* Impossible to reach 5ms with this chip.
4499 } else { 4594 Changed to 2ms instead (f = 500 Hz). */
4500 /* f = 200 Hz */ 4595 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_60_2MS);
4501 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_25_5MS); 4596 } else {
4502 } 4597 /* f = 200 Hz */
4598 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_25_5MS);
4599 }
4503 4600
4504 /* 4601 /*
4505 printk(" chip #%d at %#6lx is rev 0x%2x\n", 4602 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4506 chip_number, (unsigned long)base_addr, 4603 chip_number, (unsigned long)base_addr,
4507 cy_readb(base_addr+(CyGFRCR<<index))); 4604 cy_readb(base_addr+(CyGFRCR<<index)));
4508 */ 4605 */
4509 } 4606 }
4510 return chip_number; 4607 return chip_number;
4511} /* cyy_init_card */ 4608} /* cyy_init_card */
4512 4609
4513/* 4610/*
4514 * --------------------------------------------------------------------- 4611 * ---------------------------------------------------------------------
@@ -4516,126 +4613,124 @@ cyy_init_card(void __iomem *true_base_addr,int index)
4516 * sets global variables and return the number of ISA boards found. 4613 * sets global variables and return the number of ISA boards found.
4517 * --------------------------------------------------------------------- 4614 * ---------------------------------------------------------------------
4518 */ 4615 */
4519static int __init 4616static int __init cy_detect_isa(void)
4520cy_detect_isa(void)
4521{ 4617{
4522#ifdef CONFIG_ISA 4618#ifdef CONFIG_ISA
4523 unsigned short cy_isa_irq,nboard; 4619 unsigned short cy_isa_irq, nboard;
4524 void __iomem *cy_isa_address; 4620 void __iomem *cy_isa_address;
4525 unsigned short i,j,cy_isa_nchan; 4621 unsigned short i, j, cy_isa_nchan;
4526#ifdef MODULE 4622#ifdef MODULE
4527 int isparam = 0; 4623 int isparam = 0;
4528#endif 4624#endif
4529 4625
4530 nboard = 0; 4626 nboard = 0;
4531 4627
4532#ifdef MODULE 4628#ifdef MODULE
4533 /* Check for module parameters */ 4629 /* Check for module parameters */
4534 for(i = 0 ; i < NR_CARDS; i++) { 4630 for (i = 0; i < NR_CARDS; i++) {
4535 if (maddr[i] || i) { 4631 if (maddr[i] || i) {
4536 isparam = 1; 4632 isparam = 1;
4537 cy_isa_addresses[i] = maddr[i]; 4633 cy_isa_addresses[i] = maddr[i];
4538 } 4634 }
4539 if (!maddr[i]) 4635 if (!maddr[i])
4540 break; 4636 break;
4541 } 4637 }
4542#endif 4638#endif
4543 4639
4544 /* scan the address table probing for Cyclom-Y/ISA boards */ 4640 /* scan the address table probing for Cyclom-Y/ISA boards */
4545 for (i = 0 ; i < NR_ISA_ADDRS ; i++) { 4641 for (i = 0; i < NR_ISA_ADDRS; i++) {
4546 unsigned int isa_address = cy_isa_addresses[i]; 4642 unsigned int isa_address = cy_isa_addresses[i];
4547 if (isa_address == 0x0000) { 4643 if (isa_address == 0x0000) {
4548 return(nboard); 4644 return nboard;
4549 } 4645 }
4550 4646
4551 /* probe for CD1400... */ 4647 /* probe for CD1400... */
4552 cy_isa_address = ioremap(isa_address, CyISA_Ywin); 4648 cy_isa_address = ioremap(isa_address, CyISA_Ywin);
4553 cy_isa_nchan = CyPORTS_PER_CHIP * 4649 cy_isa_nchan = CyPORTS_PER_CHIP *
4554 cyy_init_card(cy_isa_address,0); 4650 cyy_init_card(cy_isa_address, 0);
4555 if (cy_isa_nchan == 0) { 4651 if (cy_isa_nchan == 0) {
4556 continue; 4652 continue;
4557 } 4653 }
4558
4559#ifdef MODULE 4654#ifdef MODULE
4560 if (isparam && irq[i]) 4655 if (isparam && irq[i])
4561 cy_isa_irq = irq[i]; 4656 cy_isa_irq = irq[i];
4562 else 4657 else
4563#endif 4658#endif
4564 /* find out the board's irq by probing */ 4659 /* find out the board's irq by probing */
4565 cy_isa_irq = detect_isa_irq(cy_isa_address); 4660 cy_isa_irq = detect_isa_irq(cy_isa_address);
4566 if (cy_isa_irq == 0) { 4661 if (cy_isa_irq == 0) {
4567 printk("Cyclom-Y/ISA found at 0x%lx ", 4662 printk("Cyclom-Y/ISA found at 0x%lx ",
4568 (unsigned long) cy_isa_address); 4663 (unsigned long)cy_isa_address);
4569 printk("but the IRQ could not be detected.\n"); 4664 printk("but the IRQ could not be detected.\n");
4570 continue; 4665 continue;
4571 } 4666 }
4572 4667
4573 if((cy_next_channel+cy_isa_nchan) > NR_PORTS) { 4668 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
4574 printk("Cyclom-Y/ISA found at 0x%lx ", 4669 printk("Cyclom-Y/ISA found at 0x%lx ",
4575 (unsigned long) cy_isa_address); 4670 (unsigned long)cy_isa_address);
4576 printk("but no more channels are available.\n"); 4671 printk("but no more channels are available.\n");
4577 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4672 printk("Change NR_PORTS in cyclades.c and recompile "
4578 return(nboard); 4673 "kernel.\n");
4579 } 4674 return nboard;
4580 /* fill the next cy_card structure available */ 4675 }
4581 for (j = 0 ; j < NR_CARDS ; j++) { 4676 /* fill the next cy_card structure available */
4582 if (cy_card[j].base_addr == 0) break; 4677 for (j = 0; j < NR_CARDS; j++) {
4583 } 4678 if (cy_card[j].base_addr == 0)
4584 if (j == NR_CARDS) { /* no more cy_cards available */ 4679 break;
4585 printk("Cyclom-Y/ISA found at 0x%lx ", 4680 }
4586 (unsigned long) cy_isa_address); 4681 if (j == NR_CARDS) { /* no more cy_cards available */
4587 printk("but no more cards can be used .\n"); 4682 printk("Cyclom-Y/ISA found at 0x%lx ",
4588 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4683 (unsigned long)cy_isa_address);
4589 return(nboard); 4684 printk("but no more cards can be used .\n");
4590 } 4685 printk("Change NR_CARDS in cyclades.c and recompile "
4591 4686 "kernel.\n");
4592 /* allocate IRQ */ 4687 return nboard;
4593 if(request_irq(cy_isa_irq, cyy_interrupt, 4688 }
4594 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) 4689
4595 { 4690 /* allocate IRQ */
4596 printk("Cyclom-Y/ISA found at 0x%lx ", 4691 if (request_irq(cy_isa_irq, cyy_interrupt,
4597 (unsigned long) cy_isa_address); 4692 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
4598 printk("but could not allocate IRQ#%d.\n", 4693 printk("Cyclom-Y/ISA found at 0x%lx ",
4599 cy_isa_irq); 4694 (unsigned long)cy_isa_address);
4600 return(nboard); 4695 printk("but could not allocate IRQ#%d.\n", cy_isa_irq);
4601 } 4696 return nboard;
4602 4697 }
4603 /* set cy_card */ 4698
4604 cy_card[j].base_addr = cy_isa_address; 4699 /* set cy_card */
4605 cy_card[j].ctl_addr = NULL; 4700 cy_card[j].base_addr = cy_isa_address;
4606 cy_card[j].irq = (int) cy_isa_irq; 4701 cy_card[j].ctl_addr = NULL;
4607 cy_card[j].bus_index = 0; 4702 cy_card[j].irq = (int)cy_isa_irq;
4608 cy_card[j].first_line = cy_next_channel; 4703 cy_card[j].bus_index = 0;
4609 cy_card[j].num_chips = cy_isa_nchan/4; 4704 cy_card[j].first_line = cy_next_channel;
4610 nboard++; 4705 cy_card[j].num_chips = cy_isa_nchan / 4;
4611 4706 nboard++;
4612 /* print message */ 4707
4613 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ", 4708 /* print message */
4614 j+1, (unsigned long) cy_isa_address, 4709 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4615 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)), 4710 j + 1, (unsigned long)cy_isa_address,
4616 cy_isa_irq); 4711 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4617 printk("%d channels starting from port %d.\n", 4712 cy_isa_irq);
4618 cy_isa_nchan, cy_next_channel); 4713 printk("%d channels starting from port %d.\n",
4619 cy_next_channel += cy_isa_nchan; 4714 cy_isa_nchan, cy_next_channel);
4620 } 4715 cy_next_channel += cy_isa_nchan;
4621 return(nboard); 4716 }
4717 return nboard;
4622#else 4718#else
4623 return(0); 4719 return 0;
4624#endif /* CONFIG_ISA */ 4720#endif /* CONFIG_ISA */
4625} /* cy_detect_isa */ 4721} /* cy_detect_isa */
4626 4722
4627static void 4723static void plx_init(void __iomem * addr, uclong initctl)
4628plx_init(void __iomem *addr, uclong initctl)
4629{ 4724{
4630 /* Reset PLX */ 4725 /* Reset PLX */
4631 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000); 4726 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000);
4632 udelay(100L); 4727 udelay(100L);
4633 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000); 4728 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000);
4634 4729
4635 /* Reload Config. Registers from EEPROM */ 4730 /* Reload Config. Registers from EEPROM */
4636 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000); 4731 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000);
4637 udelay(100L); 4732 udelay(100L);
4638 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000); 4733 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000);
4639} 4734}
4640 4735
4641/* 4736/*
@@ -4644,43 +4739,42 @@ plx_init(void __iomem *addr, uclong initctl)
4644 * sets global variables and return the number of PCI boards found. 4739 * sets global variables and return the number of PCI boards found.
4645 * --------------------------------------------------------------------- 4740 * ---------------------------------------------------------------------
4646 */ 4741 */
4647static int __init 4742static int __init cy_detect_pci(void)
4648cy_detect_pci(void)
4649{ 4743{
4650#ifdef CONFIG_PCI 4744#ifdef CONFIG_PCI
4651 4745
4652 struct pci_dev *pdev = NULL; 4746 struct pci_dev *pdev = NULL;
4653 unsigned char cyy_rev_id; 4747 unsigned char cyy_rev_id;
4654 unsigned char cy_pci_irq = 0; 4748 unsigned char cy_pci_irq = 0;
4655 uclong cy_pci_phys0, cy_pci_phys2; 4749 uclong cy_pci_phys0, cy_pci_phys2;
4656 void __iomem *cy_pci_addr0, *cy_pci_addr2; 4750 void __iomem *cy_pci_addr0, *cy_pci_addr2;
4657 unsigned short i,j,cy_pci_nchan, plx_ver; 4751 unsigned short i, j, cy_pci_nchan, plx_ver;
4658 unsigned short device_id,dev_index = 0; 4752 unsigned short device_id, dev_index = 0;
4659 uclong mailbox; 4753 uclong mailbox;
4660 uclong ZeIndex = 0; 4754 uclong ZeIndex = 0;
4661 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS]; 4755 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS];
4662 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS]; 4756 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
4663 unsigned char Ze_irq[NR_CARDS]; 4757 unsigned char Ze_irq[NR_CARDS];
4664 struct pci_dev *Ze_pdev[NR_CARDS]; 4758 struct pci_dev *Ze_pdev[NR_CARDS];
4665 4759
4666 for (i = 0; i < NR_CARDS; i++) { 4760 for (i = 0; i < NR_CARDS; i++) {
4667 /* look for a Cyclades card by vendor and device id */ 4761 /* look for a Cyclades card by vendor and device id */
4668 while((device_id = cy_pci_dev_id[dev_index]) != 0) { 4762 while ((device_id = cy_pci_dev_id[dev_index]) != 0) {
4669 if((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES, 4763 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4670 device_id, pdev)) == NULL) { 4764 device_id, pdev)) == NULL) {
4671 dev_index++; /* try next device id */ 4765 dev_index++; /* try next device id */
4672 } else { 4766 } else {
4673 break; /* found a board */ 4767 break; /* found a board */
4674 } 4768 }
4675 } 4769 }
4676 4770
4677 if (device_id == 0) 4771 if (device_id == 0)
4678 break; 4772 break;
4679 4773
4680 if (pci_enable_device(pdev)) 4774 if (pci_enable_device(pdev))
4681 continue; 4775 continue;
4682 4776
4683 /* read PCI configuration area */ 4777 /* read PCI configuration area */
4684 cy_pci_irq = pdev->irq; 4778 cy_pci_irq = pdev->irq;
4685 cy_pci_phys0 = pci_resource_start(pdev, 0); 4779 cy_pci_phys0 = pci_resource_start(pdev, 0);
4686 cy_pci_phys2 = pci_resource_start(pdev, 2); 4780 cy_pci_phys2 = pci_resource_start(pdev, 2);
@@ -4688,482 +4782,497 @@ cy_detect_pci(void)
4688 4782
4689 device_id &= ~PCI_DEVICE_ID_MASK; 4783 device_id &= ~PCI_DEVICE_ID_MASK;
4690 4784
4691 if ((device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) 4785 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
4692 || (device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi)){ 4786 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4693#ifdef CY_PCI_DEBUG 4787#ifdef CY_PCI_DEBUG
4694 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4788 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4695 pdev->bus->number, pdev->devfn); 4789 pdev->bus->number, pdev->devfn);
4696 printk("rev_id=%d) IRQ%d\n", 4790 printk("rev_id=%d) IRQ%d\n",
4697 cyy_rev_id, (int)cy_pci_irq); 4791 cyy_rev_id, (int)cy_pci_irq);
4698 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4792 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4699 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4793 "ctladdr=0x%lx\n",
4794 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4700#endif 4795#endif
4701 4796
4702 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4797 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4703 printk(" Warning: PCI I/O bit incorrectly set. " 4798 printk(" Warning: PCI I/O bit incorrectly "
4704 "Ignoring it...\n"); 4799 "set. Ignoring it...\n");
4705 pdev->resource[2].flags &= ~IORESOURCE_IO; 4800 pdev->resource[2].flags &= ~IORESOURCE_IO;
4706 } 4801 }
4707
4708 /* Although we don't use this I/O region, we should
4709 request it from the kernel anyway, to avoid problems
4710 with other drivers accessing it. */
4711 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4712 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n");
4713 continue;
4714 }
4715 4802
4803 /* Although we don't use this I/O region, we should
4804 request it from the kernel anyway, to avoid problems
4805 with other drivers accessing it. */
4806 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4807 printk(KERN_ERR "cyclades: failed to reserve "
4808 "PCI resources\n");
4809 continue;
4810 }
4716#if defined(__alpha__) 4811#if defined(__alpha__)
4717 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */ 4812 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4718 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4813 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4719 pdev->bus->number, pdev->devfn); 4814 pdev->bus->number, pdev->devfn);
4720 printk("rev_id=%d) IRQ%d\n", 4815 printk("rev_id=%d) IRQ%d\n",
4721 cyy_rev_id, (int)cy_pci_irq); 4816 cyy_rev_id, (int)cy_pci_irq);
4722 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4817 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4723 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4818 "ctladdr=0x%lx\n",
4724 printk("Cyclom-Y/PCI not supported for low addresses in " 4819 (ulong)cy_pci_phys2,
4725 "Alpha systems.\n"); 4820 (ulong)cy_pci_phys0);
4726 i--; 4821 printk("Cyclom-Y/PCI not supported for low "
4727 continue; 4822 "addresses in Alpha systems.\n");
4728 } 4823 i--;
4824 continue;
4825 }
4729#endif 4826#endif
4730 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl); 4827 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
4731 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin); 4828 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
4732 4829
4733#ifdef CY_PCI_DEBUG 4830#ifdef CY_PCI_DEBUG
4734 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 4831 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx "
4735 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0); 4832 "ctladdr=0x%lx\n",
4833 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0);
4736#endif 4834#endif
4737 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP * 4835 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4738 cyy_init_card(cy_pci_addr2, 1)); 4836 cyy_init_card(cy_pci_addr2, 1));
4739 if(cy_pci_nchan == 0) { 4837 if (cy_pci_nchan == 0) {
4740 printk("Cyclom-Y PCI host card with "); 4838 printk("Cyclom-Y PCI host card with ");
4741 printk("no Serial-Modules at 0x%lx.\n", 4839 printk("no Serial-Modules at 0x%lx.\n",
4742 (ulong) cy_pci_phys2); 4840 (ulong) cy_pci_phys2);
4743 i--; 4841 i--;
4744 continue; 4842 continue;
4745 } 4843 }
4746 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 4844 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4747 printk("Cyclom-Y/PCI found at 0x%lx ", 4845 printk("Cyclom-Y/PCI found at 0x%lx ",
4748 (ulong) cy_pci_phys2); 4846 (ulong) cy_pci_phys2);
4749 printk("but no channels are available.\n"); 4847 printk("but no channels are available.\n");
4750 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4848 printk("Change NR_PORTS in cyclades.c and "
4751 return(i); 4849 "recompile kernel.\n");
4752 } 4850 return i;
4753 /* fill the next cy_card structure available */ 4851 }
4754 for (j = 0 ; j < NR_CARDS ; j++) { 4852 /* fill the next cy_card structure available */
4755 if (cy_card[j].base_addr == 0) break; 4853 for (j = 0; j < NR_CARDS; j++) {
4756 } 4854 if (cy_card[j].base_addr == 0)
4757 if (j == NR_CARDS) { /* no more cy_cards available */ 4855 break;
4758 printk("Cyclom-Y/PCI found at 0x%lx ", 4856 }
4759 (ulong) cy_pci_phys2); 4857 if (j == NR_CARDS) { /* no more cy_cards available */
4760 printk("but no more cards can be used.\n"); 4858 printk("Cyclom-Y/PCI found at 0x%lx ",
4761 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4859 (ulong) cy_pci_phys2);
4762 return(i); 4860 printk("but no more cards can be used.\n");
4763 } 4861 printk("Change NR_CARDS in cyclades.c and "
4764 4862 "recompile kernel.\n");
4765 /* allocate IRQ */ 4863 return i;
4766 if(request_irq(cy_pci_irq, cyy_interrupt, 4864 }
4767 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) 4865
4768 { 4866 /* allocate IRQ */
4769 printk("Cyclom-Y/PCI found at 0x%lx ", 4867 if (request_irq(cy_pci_irq, cyy_interrupt,
4770 (ulong) cy_pci_phys2); 4868 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) {
4771 printk("but could not allocate IRQ%d.\n", 4869 printk("Cyclom-Y/PCI found at 0x%lx ",
4772 cy_pci_irq); 4870 (ulong) cy_pci_phys2);
4773 return(i); 4871 printk("but could not allocate IRQ%d.\n",
4774 } 4872 cy_pci_irq);
4775 4873 return i;
4776 /* set cy_card */ 4874 }
4777 cy_card[j].base_phys = (ulong)cy_pci_phys2;
4778 cy_card[j].ctl_phys = (ulong)cy_pci_phys0;
4779 cy_card[j].base_addr = cy_pci_addr2;
4780 cy_card[j].ctl_addr = cy_pci_addr0;
4781 cy_card[j].irq = (int) cy_pci_irq;
4782 cy_card[j].bus_index = 1;
4783 cy_card[j].first_line = cy_next_channel;
4784 cy_card[j].num_chips = cy_pci_nchan/4;
4785 cy_card[j].pdev = pdev;
4786
4787 /* enable interrupts in the PCI interface */
4788 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4789 switch (plx_ver) {
4790 case PLX_9050:
4791
4792 cy_writeb(cy_pci_addr0+0x4c, 0x43);
4793 break;
4794
4795 case PLX_9060:
4796 case PLX_9080:
4797 default: /* Old boards, use PLX_9060 */
4798
4799 plx_init(cy_pci_addr0, 0x6c);
4800 /* For some yet unknown reason, once the PLX9060 reloads
4801 the EEPROM, the IRQ is lost and, thus, we have to
4802 re-write it to the PCI config. registers.
4803 This will remain here until we find a permanent fix. */
4804 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq);
4805
4806 cy_writew(cy_pci_addr0+0x68,
4807 cy_readw(cy_pci_addr0+0x68)|0x0900);
4808 break;
4809 }
4810 4875
4811 /* print message */ 4876 /* set cy_card */
4812 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 4877 cy_card[j].base_phys = (ulong) cy_pci_phys2;
4813 j+1, 4878 cy_card[j].ctl_phys = (ulong) cy_pci_phys0;
4814 (ulong)cy_pci_phys2, 4879 cy_card[j].base_addr = cy_pci_addr2;
4815 (ulong)(cy_pci_phys2 + CyPCI_Ywin - 1), 4880 cy_card[j].ctl_addr = cy_pci_addr0;
4816 (int)cy_pci_irq); 4881 cy_card[j].irq = (int)cy_pci_irq;
4817 printk("%d channels starting from port %d.\n", 4882 cy_card[j].bus_index = 1;
4818 cy_pci_nchan, cy_next_channel); 4883 cy_card[j].first_line = cy_next_channel;
4819 4884 cy_card[j].num_chips = cy_pci_nchan / 4;
4820 cy_next_channel += cy_pci_nchan; 4885 cy_card[j].pdev = pdev;
4821 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo){ 4886
4822 /* print message */ 4887 /* enable interrupts in the PCI interface */
4823 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4888 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4824 pdev->bus->number, pdev->devfn); 4889 switch (plx_ver) {
4825 printk("rev_id=%d) IRQ%d\n", 4890 case PLX_9050:
4826 cyy_rev_id, (int)cy_pci_irq); 4891
4827 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4892 cy_writeb(cy_pci_addr0 + 0x4c, 0x43);
4828 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4893 break;
4829 printk("Cyclades-Z/PCI not supported for low addresses\n"); 4894
4830 break; 4895 case PLX_9060:
4831 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi){ 4896 case PLX_9080:
4897 default: /* Old boards, use PLX_9060 */
4898
4899 plx_init(cy_pci_addr0, 0x6c);
4900 /* For some yet unknown reason, once the PLX9060 reloads
4901 the EEPROM, the IRQ is lost and, thus, we have to
4902 re-write it to the PCI config. registers.
4903 This will remain here until we find a permanent
4904 fix. */
4905 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4906 cy_pci_irq);
4907
4908 cy_writew(cy_pci_addr0 + 0x68,
4909 cy_readw(cy_pci_addr0 +
4910 0x68) | 0x0900);
4911 break;
4912 }
4913
4914 /* print message */
4915 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4916 j + 1, (ulong)cy_pci_phys2,
4917 (ulong) (cy_pci_phys2 + CyPCI_Ywin - 1),
4918 (int)cy_pci_irq);
4919 printk("%d channels starting from port %d.\n",
4920 cy_pci_nchan, cy_next_channel);
4921
4922 cy_next_channel += cy_pci_nchan;
4923 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
4924 /* print message */
4925 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4926 pdev->bus->number, pdev->devfn);
4927 printk("rev_id=%d) IRQ%d\n",
4928 cyy_rev_id, (int)cy_pci_irq);
4929 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4930 "ctladdr=0x%lx\n",
4931 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4932 printk("Cyclades-Z/PCI not supported for low "
4933 "addresses\n");
4934 break;
4935 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4832#ifdef CY_PCI_DEBUG 4936#ifdef CY_PCI_DEBUG
4833 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4937 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4834 pdev->bus->number, pdev->devfn); 4938 pdev->bus->number, pdev->devfn);
4835 printk("rev_id=%d) IRQ%d\n", 4939 printk("rev_id=%d) IRQ%d\n",
4836 cyy_rev_id, (int)cy_pci_irq); 4940 cyy_rev_id, (int)cy_pci_irq);
4837 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4941 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4838 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4942 "ctladdr=0x%lx\n",
4943 (ulong) cy_pci_phys2, (ulong) cy_pci_phys0);
4839#endif 4944#endif
4840 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl); 4945 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
4841 4946
4842 /* Disable interrupts on the PLX before resetting it */ 4947 /* Disable interrupts on the PLX before resetting it */
4843 cy_writew(cy_pci_addr0+0x68, 4948 cy_writew(cy_pci_addr0 + 0x68,
4844 cy_readw(cy_pci_addr0+0x68) & ~0x0900); 4949 cy_readw(cy_pci_addr0 + 0x68) & ~0x0900);
4845 4950
4846 plx_init(cy_pci_addr0, 0x6c); 4951 plx_init(cy_pci_addr0, 0x6c);
4847 /* For some yet unknown reason, once the PLX9060 reloads 4952 /* For some yet unknown reason, once the PLX9060 reloads
4848 the EEPROM, the IRQ is lost and, thus, we have to 4953 the EEPROM, the IRQ is lost and, thus, we have to
4849 re-write it to the PCI config. registers. 4954 re-write it to the PCI config. registers.
4850 This will remain here until we find a permanent fix. */ 4955 This will remain here until we find a permanent
4851 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq); 4956 fix. */
4852 4957 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4853 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *) 4958 cy_pci_irq);
4854 cy_pci_addr0)->mail_box_0); 4959
4855 4960 mailbox =
4856 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4961 (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4857 printk(" Warning: PCI I/O bit incorrectly set. " 4962 cy_pci_addr0)->mail_box_0);
4858 "Ignoring it...\n"); 4963
4859 pdev->resource[2].flags &= ~IORESOURCE_IO; 4964 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4860 } 4965 printk(" Warning: PCI I/O bit incorrectly "
4966 "set. Ignoring it...\n");
4967 pdev->resource[2].flags &= ~IORESOURCE_IO;
4968 }
4861 4969
4862 /* Although we don't use this I/O region, we should 4970 /* Although we don't use this I/O region, we should
4863 request it from the kernel anyway, to avoid problems 4971 request it from the kernel anyway, to avoid problems
4864 with other drivers accessing it. */ 4972 with other drivers accessing it. */
4865 if (pci_request_regions(pdev, "Cyclades-Z") != 0) { 4973 if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
4866 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n"); 4974 printk(KERN_ERR "cyclades: failed to reserve "
4867 continue; 4975 "PCI resources\n");
4868 } 4976 continue;
4869 4977 }
4870 if (mailbox == ZE_V1) { 4978
4871 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ze_win); 4979 if (mailbox == ZE_V1) {
4872 if (ZeIndex == NR_CARDS) { 4980 cy_pci_addr2 = ioremap(cy_pci_phys2,
4873 printk("Cyclades-Ze/PCI found at 0x%lx ", 4981 CyPCI_Ze_win);
4874 (ulong)cy_pci_phys2); 4982 if (ZeIndex == NR_CARDS) {
4875 printk("but no more cards can be used.\n"); 4983 printk("Cyclades-Ze/PCI found at "
4876 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4984 "0x%lx but no more cards can "
4877 } else { 4985 "be used.\nChange NR_CARDS in "
4878 Ze_phys0[ZeIndex] = cy_pci_phys0; 4986 "cyclades.c and recompile "
4879 Ze_phys2[ZeIndex] = cy_pci_phys2; 4987 "kernel.\n",
4880 Ze_addr0[ZeIndex] = cy_pci_addr0; 4988 (ulong)cy_pci_phys2);
4881 Ze_addr2[ZeIndex] = cy_pci_addr2; 4989 } else {
4882 Ze_irq[ZeIndex] = cy_pci_irq; 4990 Ze_phys0[ZeIndex] = cy_pci_phys0;
4883 Ze_pdev[ZeIndex] = pdev; 4991 Ze_phys2[ZeIndex] = cy_pci_phys2;
4884 ZeIndex++; 4992 Ze_addr0[ZeIndex] = cy_pci_addr0;
4885 } 4993 Ze_addr2[ZeIndex] = cy_pci_addr2;
4886 i--; 4994 Ze_irq[ZeIndex] = cy_pci_irq;
4887 continue; 4995 Ze_pdev[ZeIndex] = pdev;
4888 } else { 4996 ZeIndex++;
4889 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Zwin); 4997 }
4890 } 4998 i--;
4999 continue;
5000 } else {
5001 cy_pci_addr2 = ioremap(cy_pci_phys2,CyPCI_Zwin);
5002 }
4891 5003
4892#ifdef CY_PCI_DEBUG 5004#ifdef CY_PCI_DEBUG
4893 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5005 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx "
4894 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5006 "ctladdr=0x%lx\n",
4895 if (mailbox == ZO_V1) { 5007 (ulong) cy_pci_addr2, (ulong) cy_pci_addr0);
4896 cy_writel(&((struct RUNTIME_9060 *) 5008 if (mailbox == ZO_V1) {
4897 (cy_pci_addr0))->loc_addr_base, WIN_CREG); 5009 cy_writel(&((struct RUNTIME_9060 *)
4898 PAUSE 5010 (cy_pci_addr0))->loc_addr_base,
4899 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n", 5011 WIN_CREG);
4900 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5012 PAUSE;
4901 (cy_pci_addr2))->fpga_id)), 5013 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver "
4902 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5014 "%lx\n", (ulong) (0xff &
4903 (cy_pci_addr2))->fpga_version))); 5015 cy_readl(&((struct CUSTOM_REG *)
4904 cy_writel(&((struct RUNTIME_9060 *) 5016 (cy_pci_addr2))->fpga_id)),
4905 (cy_pci_addr0))->loc_addr_base, WIN_RAM); 5017 (ulong)(0xff &
4906 } else { 5018 cy_readl(&((struct CUSTOM_REG *)
4907 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5019 (cy_pci_addr2))->
4908 } 5020 fpga_version)));
5021 cy_writel(&((struct RUNTIME_9060 *)
5022 (cy_pci_addr0))->loc_addr_base,
5023 WIN_RAM);
5024 } else {
5025 printk("Cyclades-Z/PCI: New Cyclades-Z board. "
5026 "FPGA not loaded\n");
5027 }
4909#endif 5028#endif
4910 /* The following clears the firmware id word. This ensures 5029 /* The following clears the firmware id word. This
4911 that the driver will not attempt to talk to the board 5030 ensures that the driver will not attempt to talk to
4912 until it has been properly initialized. 5031 the board until it has been properly initialized.
4913 */ 5032 */
4914 PAUSE 5033 PAUSE;
4915 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 5034 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
4916 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L); 5035 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L);
4917 5036
4918 /* This must be a Cyclades-8Zo/PCI. The extendable 5037 /* This must be a Cyclades-8Zo/PCI. The extendable
4919 version will have a different device_id and will 5038 version will have a different device_id and will
4920 be allocated its maximum number of ports. */ 5039 be allocated its maximum number of ports. */
4921 cy_pci_nchan = 8; 5040 cy_pci_nchan = 8;
4922 5041
4923 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5042 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4924 printk("Cyclades-8Zo/PCI found at 0x%lx ", 5043 printk("Cyclades-8Zo/PCI found at 0x%lx but"
4925 (ulong)cy_pci_phys2); 5044 "no channels are available.\nChange "
4926 printk("but no channels are available.\n"); 5045 "NR_PORTS in cyclades.c and recompile "
4927 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5046 "kernel.\n", (ulong)cy_pci_phys2);
4928 return(i); 5047 return i;
4929 } 5048 }
4930
4931 /* fill the next cy_card structure available */
4932 for (j = 0 ; j < NR_CARDS ; j++) {
4933 if (cy_card[j].base_addr == 0) break;
4934 }
4935 if (j == NR_CARDS) { /* no more cy_cards available */
4936 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4937 (ulong)cy_pci_phys2);
4938 printk("but no more cards can be used.\n");
4939 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4940 return(i);
4941 }
4942 5049
5050 /* fill the next cy_card structure available */
5051 for (j = 0; j < NR_CARDS; j++) {
5052 if (cy_card[j].base_addr == 0)
5053 break;
5054 }
5055 if (j == NR_CARDS) { /* no more cy_cards available */
5056 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5057 "no more cards can be used.\nChange "
5058 "NR_CARDS in cyclades.c and recompile "
5059 "kernel.\n", (ulong)cy_pci_phys2);
5060 return i;
5061 }
5062#ifdef CONFIG_CYZ_INTR
5063 /* allocate IRQ only if board has an IRQ */
5064 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5065 if (request_irq(cy_pci_irq, cyz_interrupt,
5066 IRQF_SHARED, "Cyclades-Z",
5067 &cy_card[j])) {
5068 printk("Cyclom-8Zo/PCI found at 0x%lx "
5069 "but could not allocate "
5070 "IRQ%d.\n", (ulong)cy_pci_phys2,
5071 cy_pci_irq);
5072 return i;
5073 }
5074 }
5075#endif /* CONFIG_CYZ_INTR */
5076
5077 /* set cy_card */
5078 cy_card[j].base_phys = cy_pci_phys2;
5079 cy_card[j].ctl_phys = cy_pci_phys0;
5080 cy_card[j].base_addr = cy_pci_addr2;
5081 cy_card[j].ctl_addr = cy_pci_addr0;
5082 cy_card[j].irq = (int)cy_pci_irq;
5083 cy_card[j].bus_index = 1;
5084 cy_card[j].first_line = cy_next_channel;
5085 cy_card[j].num_chips = -1;
5086 cy_card[j].pdev = pdev;
5087
5088 /* print message */
4943#ifdef CONFIG_CYZ_INTR 5089#ifdef CONFIG_CYZ_INTR
4944 /* allocate IRQ only if board has an IRQ */ 5090 /* don't report IRQ if board is no IRQ */
4945 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5091 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
4946 if(request_irq(cy_pci_irq, cyz_interrupt, 5092 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, "
4947 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5093 "IRQ%d, ", j + 1, (ulong)cy_pci_phys2,
4948 { 5094 (ulong) (cy_pci_phys2 + CyPCI_Zwin - 1),
4949 printk("Cyclom-8Zo/PCI found at 0x%lx ", 5095 (int)cy_pci_irq);
4950 (ulong) cy_pci_phys2); 5096 else
4951 printk("but could not allocate IRQ%d.\n", 5097#endif /* CONFIG_CYZ_INTR */
4952 cy_pci_irq); 5098 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
4953 return(i); 5099 j + 1, (ulong)cy_pci_phys2,
4954 } 5100 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
5101
5102 printk("%d channels starting from port %d.\n",
5103 cy_pci_nchan, cy_next_channel);
5104 cy_next_channel += cy_pci_nchan;
4955 } 5105 }
4956#endif /* CONFIG_CYZ_INTR */ 5106 }
4957
4958
4959 /* set cy_card */
4960 cy_card[j].base_phys = cy_pci_phys2;
4961 cy_card[j].ctl_phys = cy_pci_phys0;
4962 cy_card[j].base_addr = cy_pci_addr2;
4963 cy_card[j].ctl_addr = cy_pci_addr0;
4964 cy_card[j].irq = (int) cy_pci_irq;
4965 cy_card[j].bus_index = 1;
4966 cy_card[j].first_line = cy_next_channel;
4967 cy_card[j].num_chips = -1;
4968 cy_card[j].pdev = pdev;
4969 5107
4970 /* print message */ 5108 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4971#ifdef CONFIG_CYZ_INTR 5109 cy_pci_phys0 = Ze_phys0[0];
4972 /* don't report IRQ if board is no IRQ */ 5110 cy_pci_phys2 = Ze_phys2[0];
4973 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5111 cy_pci_addr0 = Ze_addr0[0];
4974 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5112 cy_pci_addr2 = Ze_addr2[0];
4975 j+1,(ulong)cy_pci_phys2, 5113 cy_pci_irq = Ze_irq[0];
4976 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1), 5114 pdev = Ze_pdev[0];
4977 (int)cy_pci_irq); 5115 for (j = 0; j < ZeIndex - 1; j++) {
4978 else 5116 Ze_phys0[j] = Ze_phys0[j + 1];
4979#endif /* CONFIG_CYZ_INTR */ 5117 Ze_phys2[j] = Ze_phys2[j + 1];
4980 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ", 5118 Ze_addr0[j] = Ze_addr0[j + 1];
4981 j+1,(ulong)cy_pci_phys2, 5119 Ze_addr2[j] = Ze_addr2[j + 1];
4982 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1)); 5120 Ze_irq[j] = Ze_irq[j + 1];
4983 5121 Ze_pdev[j] = Ze_pdev[j + 1];
4984 printk("%d channels starting from port %d.\n", 5122 }
4985 cy_pci_nchan,cy_next_channel); 5123 ZeIndex--;
4986 cy_next_channel += cy_pci_nchan; 5124 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4987 } 5125 cy_pci_addr0)->mail_box_0);
4988 }
4989
4990 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4991 cy_pci_phys0 = Ze_phys0[0];
4992 cy_pci_phys2 = Ze_phys2[0];
4993 cy_pci_addr0 = Ze_addr0[0];
4994 cy_pci_addr2 = Ze_addr2[0];
4995 cy_pci_irq = Ze_irq[0];
4996 pdev = Ze_pdev[0];
4997 for (j = 0 ; j < ZeIndex-1 ; j++) {
4998 Ze_phys0[j] = Ze_phys0[j+1];
4999 Ze_phys2[j] = Ze_phys2[j+1];
5000 Ze_addr0[j] = Ze_addr0[j+1];
5001 Ze_addr2[j] = Ze_addr2[j+1];
5002 Ze_irq[j] = Ze_irq[j+1];
5003 Ze_pdev[j] = Ze_pdev[j+1];
5004 }
5005 ZeIndex--;
5006 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
5007 cy_pci_addr0)->mail_box_0);
5008#ifdef CY_PCI_DEBUG 5126#ifdef CY_PCI_DEBUG
5009 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5127 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5010 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5128 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
5011 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5129 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not "
5130 "loaded\n");
5012#endif 5131#endif
5013 PAUSE 5132 PAUSE;
5014 /* This must be the new Cyclades-Ze/PCI. */ 5133 /* This must be the new Cyclades-Ze/PCI. */
5015 cy_pci_nchan = ZE_V1_NPORTS; 5134 cy_pci_nchan = ZE_V1_NPORTS;
5016 5135
5017 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5136 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5018 printk("Cyclades-Ze/PCI found at 0x%lx ", 5137 printk("Cyclades-Ze/PCI found at 0x%lx but no channels "
5019 (ulong)cy_pci_phys2); 5138 "are available.\nChange NR_PORTS in cyclades.c "
5020 printk("but no channels are available.\n"); 5139 "and recompile kernel.\n",
5021 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5140 (ulong) cy_pci_phys2);
5022 return(i); 5141 return i;
5023 } 5142 }
5024
5025 /* fill the next cy_card structure available */
5026 for (j = 0 ; j < NR_CARDS ; j++) {
5027 if (cy_card[j].base_addr == 0) break;
5028 }
5029 if (j == NR_CARDS) { /* no more cy_cards available */
5030 printk("Cyclades-Ze/PCI found at 0x%lx ",
5031 (ulong)cy_pci_phys2);
5032 printk("but no more cards can be used.\n");
5033 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5034 return(i);
5035 }
5036 5143
5144 /* fill the next cy_card structure available */
5145 for (j = 0; j < NR_CARDS; j++) {
5146 if (cy_card[j].base_addr == 0)
5147 break;
5148 }
5149 if (j == NR_CARDS) { /* no more cy_cards available */
5150 printk("Cyclades-Ze/PCI found at 0x%lx but no more "
5151 "cards can be used.\nChange NR_CARDS in "
5152 "cyclades.c and recompile kernel.\n",
5153 (ulong) cy_pci_phys2);
5154 return i;
5155 }
5037#ifdef CONFIG_CYZ_INTR 5156#ifdef CONFIG_CYZ_INTR
5038 /* allocate IRQ only if board has an IRQ */ 5157 /* allocate IRQ only if board has an IRQ */
5039 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5158 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5040 if(request_irq(cy_pci_irq, cyz_interrupt, 5159 if (request_irq(cy_pci_irq, cyz_interrupt,
5041 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5160 IRQF_SHARED, "Cyclades-Z",
5042 { 5161 &cy_card[j])) {
5043 printk("Cyclom-Ze/PCI found at 0x%lx ", 5162 printk("Cyclom-Ze/PCI found at 0x%lx ",
5044 (ulong) cy_pci_phys2); 5163 (ulong) cy_pci_phys2);
5045 printk("but could not allocate IRQ%d.\n", 5164 printk("but could not allocate IRQ%d.\n",
5046 cy_pci_irq); 5165 cy_pci_irq);
5047 return(i); 5166 return i;
5048 } 5167 }
5049 } 5168 }
5050#endif /* CONFIG_CYZ_INTR */ 5169#endif /* CONFIG_CYZ_INTR */
5051 5170
5052 /* set cy_card */ 5171 /* set cy_card */
5053 cy_card[j].base_phys = cy_pci_phys2; 5172 cy_card[j].base_phys = cy_pci_phys2;
5054 cy_card[j].ctl_phys = cy_pci_phys0; 5173 cy_card[j].ctl_phys = cy_pci_phys0;
5055 cy_card[j].base_addr = cy_pci_addr2; 5174 cy_card[j].base_addr = cy_pci_addr2;
5056 cy_card[j].ctl_addr = cy_pci_addr0; 5175 cy_card[j].ctl_addr = cy_pci_addr0;
5057 cy_card[j].irq = (int) cy_pci_irq; 5176 cy_card[j].irq = (int)cy_pci_irq;
5058 cy_card[j].bus_index = 1; 5177 cy_card[j].bus_index = 1;
5059 cy_card[j].first_line = cy_next_channel; 5178 cy_card[j].first_line = cy_next_channel;
5060 cy_card[j].num_chips = -1; 5179 cy_card[j].num_chips = -1;
5061 cy_card[j].pdev = pdev; 5180 cy_card[j].pdev = pdev;
5062 5181
5063 /* print message */ 5182 /* print message */
5064#ifdef CONFIG_CYZ_INTR 5183#ifdef CONFIG_CYZ_INTR
5065 /* don't report IRQ if board is no IRQ */ 5184 /* don't report IRQ if board is no IRQ */
5066 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5185 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5067 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5186 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5068 j+1,(ulong)cy_pci_phys2, 5187 j + 1, (ulong) cy_pci_phys2,
5069 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1), 5188 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1),
5070 (int)cy_pci_irq); 5189 (int)cy_pci_irq);
5071 else 5190 else
5072#endif /* CONFIG_CYZ_INTR */ 5191#endif /* CONFIG_CYZ_INTR */
5073 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ", 5192 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5074 j+1,(ulong)cy_pci_phys2, 5193 j + 1, (ulong) cy_pci_phys2,
5075 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1)); 5194 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1));
5076 5195
5077 printk("%d channels starting from port %d.\n", 5196 printk("%d channels starting from port %d.\n",
5078 cy_pci_nchan,cy_next_channel); 5197 cy_pci_nchan, cy_next_channel);
5079 cy_next_channel += cy_pci_nchan; 5198 cy_next_channel += cy_pci_nchan;
5080 } 5199 }
5081 if (ZeIndex != 0) { 5200 if (ZeIndex != 0) {
5082 printk("Cyclades-Ze/PCI found at 0x%x ", 5201 printk("Cyclades-Ze/PCI found at 0x%x but no more cards can be "
5083 (unsigned int) Ze_phys2[0]); 5202 "used.\nChange NR_CARDS in cyclades.c and recompile "
5084 printk("but no more cards can be used.\n"); 5203 "kernel.\n", (unsigned int)Ze_phys2[0]);
5085 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5086 } 5204 }
5087 return(i); 5205 return i;
5088#else 5206#else
5089 return(0); 5207 return 0;
5090#endif /* ifdef CONFIG_PCI */ 5208#endif /* ifdef CONFIG_PCI */
5091} /* cy_detect_pci */ 5209} /* cy_detect_pci */
5092
5093 5210
5094/* 5211/*
5095 * This routine prints out the appropriate serial driver version number 5212 * This routine prints out the appropriate serial driver version number
5096 * and identifies which options were configured into this driver. 5213 * and identifies which options were configured into this driver.
5097 */ 5214 */
5098static inline void 5215static inline void show_version(void)
5099show_version(void)
5100{ 5216{
5101 char *rcsvers, *rcsdate, *tmp; 5217 printk("Cyclades driver " CY_VERSION "\n");
5102 rcsvers = strchr(rcsid, ' '); rcsvers++; 5218 printk(" built %s %s\n", __DATE__, __TIME__);
5103 tmp = strchr(rcsvers, ' '); *tmp++ = '\0'; 5219} /* show_version */
5104 rcsdate = strchr(tmp, ' '); rcsdate++; 5220
5105 tmp = strrchr(rcsdate, ' '); *tmp = '\0'; 5221static int
5106 printk("Cyclades driver %s %s\n",
5107 rcsvers, rcsdate);
5108 printk(" built %s %s\n",
5109 __DATE__, __TIME__);
5110} /* show_version */
5111
5112static int
5113cyclades_get_proc_info(char *buf, char **start, off_t offset, int length, 5222cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5114 int *eof, void *data) 5223 int *eof, void *data)
5115{ 5224{
5116 struct cyclades_port *info; 5225 struct cyclades_port *info;
5117 int i; 5226 int i;
5118 int len=0; 5227 int len = 0;
5119 off_t begin=0; 5228 off_t begin = 0;
5120 off_t pos=0; 5229 off_t pos = 0;
5121 int size; 5230 int size;
5122 __u32 cur_jifs = jiffies; 5231 __u32 cur_jifs = jiffies;
5123 5232
5124 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n"); 5233 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn "
5125 5234 "IdleIn Overruns Ldisc\n");
5126 pos += size; 5235
5127 len += size; 5236 pos += size;
5128
5129 /* Output one line for each known port */
5130 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5131 info = &cy_port[i];
5132
5133 if (info->count)
5134 size = sprintf(buf+len,
5135 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5136 info->line,
5137 JIFFIES_DIFF(info->idle_stats.in_use, cur_jifs) / HZ,
5138 info->idle_stats.xmit_bytes,
5139 JIFFIES_DIFF(info->idle_stats.xmit_idle, cur_jifs) / HZ,
5140 info->idle_stats.recv_bytes,
5141 JIFFIES_DIFF(info->idle_stats.recv_idle, cur_jifs) / HZ,
5142 info->idle_stats.overruns,
5143 (long) info->tty->ldisc.num);
5144 else
5145 size = sprintf(buf+len,
5146 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5147 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5148 len += size; 5237 len += size;
5149 pos = begin + len;
5150 5238
5151 if (pos < offset) { 5239 /* Output one line for each known port */
5152 len = 0; 5240 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5153 begin = pos; 5241 info = &cy_port[i];
5242
5243 if (info->count)
5244 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5245 "%8lu %9lu %6ld\n", info->line,
5246 (cur_jifs - info->idle_stats.in_use) / HZ,
5247 info->idle_stats.xmit_bytes,
5248 (cur_jifs - info->idle_stats.xmit_idle) / HZ,
5249 info->idle_stats.recv_bytes,
5250 (cur_jifs - info->idle_stats.recv_idle) / HZ,
5251 info->idle_stats.overruns,
5252 (long)info->tty->ldisc.num);
5253 else
5254 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5255 "%8lu %9lu %6ld\n",
5256 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5257 len += size;
5258 pos = begin + len;
5259
5260 if (pos < offset) {
5261 len = 0;
5262 begin = pos;
5263 }
5264 if (pos > offset + length)
5265 goto done;
5154 } 5266 }
5155 if (pos > offset + length) 5267 *eof = 1;
5156 goto done;
5157 }
5158 *eof = 1;
5159done: 5268done:
5160 *start = buf + (offset - begin); /* Start of wanted data */ 5269 *start = buf + (offset - begin); /* Start of wanted data */
5161 len -= (offset - begin); /* Start slop */ 5270 len -= (offset - begin); /* Start slop */
5162 if (len > length) 5271 if (len > length)
5163 len = length; /* Ending slop */ 5272 len = length; /* Ending slop */
5164 if (len < 0) 5273 if (len < 0)
5165 len = 0; 5274 len = 0;
5166 return len; 5275 return len;
5167} 5276}
5168 5277
5169/* The serial driver boot-time initialization code! 5278/* The serial driver boot-time initialization code!
@@ -5185,290 +5294,288 @@ done:
5185 */ 5294 */
5186 5295
5187static const struct tty_operations cy_ops = { 5296static const struct tty_operations cy_ops = {
5188 .open = cy_open, 5297 .open = cy_open,
5189 .close = cy_close, 5298 .close = cy_close,
5190 .write = cy_write, 5299 .write = cy_write,
5191 .put_char = cy_put_char, 5300 .put_char = cy_put_char,
5192 .flush_chars = cy_flush_chars, 5301 .flush_chars = cy_flush_chars,
5193 .write_room = cy_write_room, 5302 .write_room = cy_write_room,
5194 .chars_in_buffer = cy_chars_in_buffer, 5303 .chars_in_buffer = cy_chars_in_buffer,
5195 .flush_buffer = cy_flush_buffer, 5304 .flush_buffer = cy_flush_buffer,
5196 .ioctl = cy_ioctl, 5305 .ioctl = cy_ioctl,
5197 .throttle = cy_throttle, 5306 .throttle = cy_throttle,
5198 .unthrottle = cy_unthrottle, 5307 .unthrottle = cy_unthrottle,
5199 .set_termios = cy_set_termios, 5308 .set_termios = cy_set_termios,
5200 .stop = cy_stop, 5309 .stop = cy_stop,
5201 .start = cy_start, 5310 .start = cy_start,
5202 .hangup = cy_hangup, 5311 .hangup = cy_hangup,
5203 .break_ctl = cy_break, 5312 .break_ctl = cy_break,
5204 .wait_until_sent = cy_wait_until_sent, 5313 .wait_until_sent = cy_wait_until_sent,
5205 .read_proc = cyclades_get_proc_info, 5314 .read_proc = cyclades_get_proc_info,
5206 .tiocmget = cy_tiocmget, 5315 .tiocmget = cy_tiocmget,
5207 .tiocmset = cy_tiocmset, 5316 .tiocmset = cy_tiocmset,
5208}; 5317};
5209 5318
5210static int __init 5319static int __init cy_init(void)
5211cy_init(void)
5212{ 5320{
5213 struct cyclades_port *info; 5321 struct cyclades_port *info;
5214 struct cyclades_card *cinfo; 5322 struct cyclades_card *cinfo;
5215 int number_z_boards = 0; 5323 int number_z_boards = 0;
5216 int board,port,i,index; 5324 int board, port, i, index;
5217 unsigned long mailbox; 5325 unsigned long mailbox;
5218 unsigned short chip_number; 5326 unsigned short chip_number;
5219 int nports; 5327 int nports;
5220 5328
5221 cy_serial_driver = alloc_tty_driver(NR_PORTS); 5329 cy_serial_driver = alloc_tty_driver(NR_PORTS);
5222 if (!cy_serial_driver) 5330 if (!cy_serial_driver)
5223 return -ENOMEM; 5331 return -ENOMEM;
5224 show_version(); 5332 show_version();
5225 5333
5226 /* Initialize the tty_driver structure */ 5334 /* Initialize the tty_driver structure */
5227 5335
5228 cy_serial_driver->owner = THIS_MODULE; 5336 cy_serial_driver->owner = THIS_MODULE;
5229 cy_serial_driver->driver_name = "cyclades"; 5337 cy_serial_driver->driver_name = "cyclades";
5230 cy_serial_driver->name = "ttyC"; 5338 cy_serial_driver->name = "ttyC";
5231 cy_serial_driver->major = CYCLADES_MAJOR; 5339 cy_serial_driver->major = CYCLADES_MAJOR;
5232 cy_serial_driver->minor_start = 0; 5340 cy_serial_driver->minor_start = 0;
5233 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL; 5341 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5234 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL; 5342 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
5235 cy_serial_driver->init_termios = tty_std_termios; 5343 cy_serial_driver->init_termios = tty_std_termios;
5236 cy_serial_driver->init_termios.c_cflag = 5344 cy_serial_driver->init_termios.c_cflag =
5237 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 5345 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5238 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW; 5346 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
5239 tty_set_operations(cy_serial_driver, &cy_ops); 5347 tty_set_operations(cy_serial_driver, &cy_ops);
5240 5348
5241 if (tty_register_driver(cy_serial_driver)) 5349 if (tty_register_driver(cy_serial_driver))
5242 panic("Couldn't register Cyclades serial driver\n"); 5350 panic("Couldn't register Cyclades serial driver\n");
5243 5351
5244 for (i = 0; i < NR_CARDS; i++) { 5352 for (i = 0; i < NR_CARDS; i++) {
5245 /* base_addr=0 indicates board not found */ 5353 /* base_addr=0 indicates board not found */
5246 cy_card[i].base_addr = NULL; 5354 cy_card[i].base_addr = NULL;
5247 } 5355 }
5248 5356
5249 /* the code below is responsible to find the boards. Each different 5357 /* the code below is responsible to find the boards. Each different
5250 type of board has its own detection routine. If a board is found, 5358 type of board has its own detection routine. If a board is found,
5251 the next cy_card structure available is set by the detection 5359 the next cy_card structure available is set by the detection
5252 routine. These functions are responsible for checking the 5360 routine. These functions are responsible for checking the
5253 availability of cy_card and cy_port data structures and updating 5361 availability of cy_card and cy_port data structures and updating
5254 the cy_next_channel. */ 5362 the cy_next_channel. */
5255 5363
5256 /* look for isa boards */ 5364 /* look for isa boards */
5257 cy_isa_nboard = cy_detect_isa(); 5365 cy_isa_nboard = cy_detect_isa();
5258 5366
5259 /* look for pci boards */ 5367 /* look for pci boards */
5260 cy_pci_nboard = cy_detect_pci(); 5368 cy_pci_nboard = cy_detect_pci();
5261 5369
5262 cy_nboard = cy_isa_nboard + cy_pci_nboard; 5370 cy_nboard = cy_isa_nboard + cy_pci_nboard;
5263 5371
5264 /* invalidate remaining cy_card structures */ 5372 /* invalidate remaining cy_card structures */
5265 for (i = 0 ; i < NR_CARDS ; i++) { 5373 for (i = 0; i < NR_CARDS; i++) {
5266 if (cy_card[i].base_addr == 0) { 5374 if (cy_card[i].base_addr == 0) {
5267 cy_card[i].first_line = -1; 5375 cy_card[i].first_line = -1;
5268 cy_card[i].ctl_addr = NULL; 5376 cy_card[i].ctl_addr = NULL;
5269 cy_card[i].irq = 0; 5377 cy_card[i].irq = 0;
5270 cy_card[i].bus_index = 0; 5378 cy_card[i].bus_index = 0;
5271 cy_card[i].first_line = 0; 5379 cy_card[i].first_line = 0;
5272 cy_card[i].num_chips = 0; 5380 cy_card[i].num_chips = 0;
5273 } 5381 }
5274 } 5382 }
5275 /* invalidate remaining cy_port structures */ 5383 /* invalidate remaining cy_port structures */
5276 for (i = cy_next_channel ; i < NR_PORTS ; i++) { 5384 for (i = cy_next_channel; i < NR_PORTS; i++) {
5277 cy_port[i].line = -1; 5385 cy_port[i].line = -1;
5278 cy_port[i].magic = -1; 5386 cy_port[i].magic = -1;
5279 } 5387 }
5280 5388
5281 /* initialize per-port data structures for each valid board found */ 5389 /* initialize per-port data structures for each valid board found */
5282 for (board = 0 ; board < cy_nboard ; board++) { 5390 for (board = 0; board < cy_nboard; board++) {
5283 cinfo = &cy_card[board]; 5391 cinfo = &cy_card[board];
5284 if (cinfo->num_chips == -1) { /* Cyclades-Z */ 5392 if (cinfo->num_chips == -1) { /* Cyclades-Z */
5285 number_z_boards++; 5393 number_z_boards++;
5286 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *) 5394 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
5287 cy_card[board].ctl_addr)->mail_box_0); 5395 cy_card[board].ctl_addr)->
5288 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8; 5396 mail_box_0);
5289 cinfo->intr_enabled = 0; 5397 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5290 cinfo->nports = 0; /* Will be correctly set later, after 5398 cinfo->intr_enabled = 0;
5291 Z FW is loaded */ 5399 cinfo->nports = 0; /* Will be correctly set later, after
5292 spin_lock_init(&cinfo->card_lock); 5400 Z FW is loaded */
5293 for (port = cinfo->first_line ; 5401 spin_lock_init(&cinfo->card_lock);
5294 port < cinfo->first_line + nports; 5402 for (port = cinfo->first_line;
5295 port++) 5403 port < cinfo->first_line + nports; port++) {
5296 { 5404 info = &cy_port[port];
5297 info = &cy_port[port]; 5405 info->magic = CYCLADES_MAGIC;
5298 info->magic = CYCLADES_MAGIC; 5406 info->type = PORT_STARTECH;
5299 info->type = PORT_STARTECH; 5407 info->card = board;
5300 info->card = board; 5408 info->line = port;
5301 info->line = port; 5409 info->chip_rev = 0;
5302 info->chip_rev = 0; 5410 info->flags = STD_COM_FLAGS;
5303 info->flags = STD_COM_FLAGS; 5411 info->tty = NULL;
5304 info->tty = NULL; 5412 if (mailbox == ZO_V1)
5305 if (mailbox == ZO_V1) 5413 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5306 info->xmit_fifo_size = CYZ_FIFO_SIZE; 5414 else
5307 else 5415 info->xmit_fifo_size =
5308 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; 5416 4 * CYZ_FIFO_SIZE;
5309 info->cor1 = 0; 5417 info->cor1 = 0;
5310 info->cor2 = 0; 5418 info->cor2 = 0;
5311 info->cor3 = 0; 5419 info->cor3 = 0;
5312 info->cor4 = 0; 5420 info->cor4 = 0;
5313 info->cor5 = 0; 5421 info->cor5 = 0;
5314 info->tbpr = 0; 5422 info->tbpr = 0;
5315 info->tco = 0; 5423 info->tco = 0;
5316 info->rbpr = 0; 5424 info->rbpr = 0;
5317 info->rco = 0; 5425 info->rco = 0;
5318 info->custom_divisor = 0; 5426 info->custom_divisor = 0;
5319 info->close_delay = 5*HZ/10; 5427 info->close_delay = 5 * HZ / 10;
5320 info->closing_wait = CLOSING_WAIT_DELAY; 5428 info->closing_wait = CLOSING_WAIT_DELAY;
5321 info->icount.cts = info->icount.dsr = 5429 info->icount.cts = info->icount.dsr =
5322 info->icount.rng = info->icount.dcd = 0; 5430 info->icount.rng = info->icount.dcd = 0;
5323 info->icount.rx = info->icount.tx = 0; 5431 info->icount.rx = info->icount.tx = 0;
5324 info->icount.frame = info->icount.parity = 0; 5432 info->icount.frame = info->icount.parity = 0;
5325 info->icount.overrun = info->icount.brk = 0; 5433 info->icount.overrun = info->icount.brk = 0;
5326 info->x_char = 0; 5434 info->x_char = 0;
5327 info->event = 0; 5435 info->event = 0;
5328 info->count = 0; 5436 info->count = 0;
5329 info->blocked_open = 0; 5437 info->blocked_open = 0;
5330 info->default_threshold = 0; 5438 info->default_threshold = 0;
5331 info->default_timeout = 0; 5439 info->default_timeout = 0;
5332 INIT_WORK(&info->tqueue, do_softint); 5440 INIT_WORK(&info->tqueue, do_softint);
5333 init_waitqueue_head(&info->open_wait); 5441 init_waitqueue_head(&info->open_wait);
5334 init_waitqueue_head(&info->close_wait); 5442 init_waitqueue_head(&info->close_wait);
5335 init_waitqueue_head(&info->shutdown_wait); 5443 init_waitqueue_head(&info->shutdown_wait);
5336 init_waitqueue_head(&info->delta_msr_wait); 5444 init_waitqueue_head(&info->delta_msr_wait);
5337 /* info->session */ 5445 /* info->session */
5338 /* info->pgrp */ 5446 /* info->pgrp */
5339 info->read_status_mask = 0; 5447 info->read_status_mask = 0;
5340 /* info->timeout */ 5448 /* info->timeout */
5341 /* Bentson's vars */ 5449 /* Bentson's vars */
5342 info->jiffies[0] = 0; 5450 info->jiffies[0] = 0;
5343 info->jiffies[1] = 0; 5451 info->jiffies[1] = 0;
5344 info->jiffies[2] = 0; 5452 info->jiffies[2] = 0;
5345 info->rflush_count = 0; 5453 info->rflush_count = 0;
5346#ifdef CONFIG_CYZ_INTR 5454#ifdef CONFIG_CYZ_INTR
5347 init_timer(&cyz_rx_full_timer[port]); 5455 init_timer(&cyz_rx_full_timer[port]);
5348 cyz_rx_full_timer[port].function = NULL; 5456 cyz_rx_full_timer[port].function = NULL;
5349#endif 5457#endif
5350 } 5458 }
5351 continue; 5459 continue;
5352 }else{ /* Cyclom-Y of some kind*/ 5460 } else { /* Cyclom-Y of some kind */
5353 index = cinfo->bus_index; 5461 index = cinfo->bus_index;
5354 spin_lock_init(&cinfo->card_lock); 5462 spin_lock_init(&cinfo->card_lock);
5355 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips; 5463 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
5356 for (port = cinfo->first_line ; 5464 for (port = cinfo->first_line;
5357 port < cinfo->first_line + cinfo->nports ; 5465 port < cinfo->first_line + cinfo->nports; port++) {
5358 port++) 5466 info = &cy_port[port];
5359 { 5467 info->magic = CYCLADES_MAGIC;
5360 info = &cy_port[port]; 5468 info->type = PORT_CIRRUS;
5361 info->magic = CYCLADES_MAGIC; 5469 info->card = board;
5362 info->type = PORT_CIRRUS; 5470 info->line = port;
5363 info->card = board; 5471 info->flags = STD_COM_FLAGS;
5364 info->line = port; 5472 info->tty = NULL;
5365 info->flags = STD_COM_FLAGS; 5473 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5366 info->tty = NULL; 5474 info->cor1 =
5367 info->xmit_fifo_size = CyMAX_CHAR_FIFO; 5475 CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
5368 info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS; 5476 info->cor2 = CyETC;
5369 info->cor2 = CyETC; 5477 info->cor3 = 0x08; /* _very_ small rcv threshold */
5370 info->cor3 = 0x08; /* _very_ small rcv threshold */ 5478 info->cor4 = 0;
5371 info->cor4 = 0; 5479 info->cor5 = 0;
5372 info->cor5 = 0; 5480 info->custom_divisor = 0;
5373 info->custom_divisor = 0; 5481 info->close_delay = 5 * HZ / 10;
5374 info->close_delay = 5*HZ/10; 5482 info->closing_wait = CLOSING_WAIT_DELAY;
5375 info->closing_wait = CLOSING_WAIT_DELAY; 5483 info->icount.cts = info->icount.dsr =
5376 info->icount.cts = info->icount.dsr = 5484 info->icount.rng = info->icount.dcd = 0;
5377 info->icount.rng = info->icount.dcd = 0; 5485 info->icount.rx = info->icount.tx = 0;
5378 info->icount.rx = info->icount.tx = 0; 5486 info->icount.frame = info->icount.parity = 0;
5379 info->icount.frame = info->icount.parity = 0; 5487 info->icount.overrun = info->icount.brk = 0;
5380 info->icount.overrun = info->icount.brk = 0; 5488 chip_number = (port - cinfo->first_line) / 4;
5381 chip_number = (port - cinfo->first_line) / 4; 5489 if ((info->chip_rev =
5382 if ((info->chip_rev = 5490 cy_readb(cinfo->base_addr +
5383 cy_readb(cinfo->base_addr + 5491 (cy_chip_offset[chip_number] <<
5384 (cy_chip_offset[chip_number]<<index) + 5492 index) + (CyGFRCR << index))) >=
5385 (CyGFRCR<<index))) >= CD1400_REV_J) { 5493 CD1400_REV_J) {
5386 /* It is a CD1400 rev. J or later */ 5494 /* It is a CD1400 rev. J or later */
5387 info->tbpr = baud_bpr_60[13]; /* Tx BPR */ 5495 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5388 info->tco = baud_co_60[13]; /* Tx CO */ 5496 info->tco = baud_co_60[13]; /* Tx CO */
5389 info->rbpr = baud_bpr_60[13]; /* Rx BPR */ 5497 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5390 info->rco = baud_co_60[13]; /* Rx CO */ 5498 info->rco = baud_co_60[13]; /* Rx CO */
5391 info->rflow = 0; 5499 info->rflow = 0;
5392 info->rtsdtr_inv = 1; 5500 info->rtsdtr_inv = 1;
5393 } else { 5501 } else {
5394 info->tbpr = baud_bpr_25[13]; /* Tx BPR */ 5502 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5395 info->tco = baud_co_25[13]; /* Tx CO */ 5503 info->tco = baud_co_25[13]; /* Tx CO */
5396 info->rbpr = baud_bpr_25[13]; /* Rx BPR */ 5504 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5397 info->rco = baud_co_25[13]; /* Rx CO */ 5505 info->rco = baud_co_25[13]; /* Rx CO */
5398 info->rflow = 0; 5506 info->rflow = 0;
5399 info->rtsdtr_inv = 0; 5507 info->rtsdtr_inv = 0;
5400 } 5508 }
5401 info->x_char = 0; 5509 info->x_char = 0;
5402 info->event = 0; 5510 info->event = 0;
5403 info->count = 0; 5511 info->count = 0;
5404 info->blocked_open = 0; 5512 info->blocked_open = 0;
5405 info->default_threshold = 0; 5513 info->default_threshold = 0;
5406 info->default_timeout = 0; 5514 info->default_timeout = 0;
5407 INIT_WORK(&info->tqueue, do_softint); 5515 INIT_WORK(&info->tqueue, do_softint);
5408 init_waitqueue_head(&info->open_wait); 5516 init_waitqueue_head(&info->open_wait);
5409 init_waitqueue_head(&info->close_wait); 5517 init_waitqueue_head(&info->close_wait);
5410 init_waitqueue_head(&info->shutdown_wait); 5518 init_waitqueue_head(&info->shutdown_wait);
5411 init_waitqueue_head(&info->delta_msr_wait); 5519 init_waitqueue_head(&info->delta_msr_wait);
5412 /* info->session */ 5520 /* info->session */
5413 /* info->pgrp */ 5521 /* info->pgrp */
5414 info->read_status_mask = 5522 info->read_status_mask =
5415 CyTIMEOUT| CySPECHAR| CyBREAK 5523 CyTIMEOUT | CySPECHAR | CyBREAK
5416 | CyPARITY| CyFRAME| CyOVERRUN; 5524 | CyPARITY | CyFRAME | CyOVERRUN;
5417 /* info->timeout */ 5525 /* info->timeout */
5418 } 5526 }
5419 } 5527 }
5420 } 5528 }
5421 5529
5422#ifndef CONFIG_CYZ_INTR 5530#ifndef CONFIG_CYZ_INTR
5423 if (number_z_boards && !cyz_timeron){ 5531 if (number_z_boards && !cyz_timeron) {
5424 cyz_timeron++; 5532 cyz_timeron++;
5425 cyz_timerlist.expires = jiffies + 1; 5533 cyz_timerlist.expires = jiffies + 1;
5426 add_timer(&cyz_timerlist); 5534 add_timer(&cyz_timerlist);
5427#ifdef CY_PCI_DEBUG 5535#ifdef CY_PCI_DEBUG
5428 printk("Cyclades-Z polling initialized\n"); 5536 printk("Cyclades-Z polling initialized\n");
5429#endif 5537#endif
5430 } 5538 }
5431#endif /* CONFIG_CYZ_INTR */ 5539#endif /* CONFIG_CYZ_INTR */
5540
5541 return 0;
5432 5542
5433 return 0; 5543} /* cy_init */
5434
5435} /* cy_init */
5436 5544
5437static void __exit 5545static void __exit cy_cleanup_module(void)
5438cy_cleanup_module(void)
5439{ 5546{
5440 int i, e1; 5547 int i, e1;
5441 5548
5442#ifndef CONFIG_CYZ_INTR 5549#ifndef CONFIG_CYZ_INTR
5443 if (cyz_timeron){ 5550 if (cyz_timeron){
5444 cyz_timeron = 0; 5551 cyz_timeron = 0;
5445 del_timer(&cyz_timerlist); 5552 del_timer(&cyz_timerlist);
5446 } 5553 }
5447#endif /* CONFIG_CYZ_INTR */ 5554#endif /* CONFIG_CYZ_INTR */
5448 5555
5449 if ((e1 = tty_unregister_driver(cy_serial_driver))) 5556 if ((e1 = tty_unregister_driver(cy_serial_driver)))
5450 printk("cyc: failed to unregister Cyclades serial driver(%d)\n", 5557 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5451 e1); 5558 e1);
5452 5559
5453 put_tty_driver(cy_serial_driver); 5560 put_tty_driver(cy_serial_driver);
5454 5561
5455 for (i = 0; i < NR_CARDS; i++) { 5562 for (i = 0; i < NR_CARDS; i++) {
5456 if (cy_card[i].base_addr) { 5563 if (cy_card[i].base_addr) {
5457 iounmap(cy_card[i].base_addr); 5564 iounmap(cy_card[i].base_addr);
5458 if (cy_card[i].ctl_addr) 5565 if (cy_card[i].ctl_addr)
5459 iounmap(cy_card[i].ctl_addr); 5566 iounmap(cy_card[i].ctl_addr);
5460 if (cy_card[i].irq 5567 if (cy_card[i].irq
5461#ifndef CONFIG_CYZ_INTR 5568#ifndef CONFIG_CYZ_INTR
5462 && cy_card[i].num_chips != -1 /* not a Z card */ 5569 && cy_card[i].num_chips != -1 /* not a Z card */
5463#endif /* CONFIG_CYZ_INTR */ 5570#endif /* CONFIG_CYZ_INTR */
5464 ) 5571 )
5465 free_irq(cy_card[i].irq, &cy_card[i]); 5572 free_irq(cy_card[i].irq, &cy_card[i]);
5466#ifdef CONFIG_PCI 5573#ifdef CONFIG_PCI
5467 if (cy_card[i].pdev) 5574 if (cy_card[i].pdev)
5468 pci_release_regions(cy_card[i].pdev); 5575 pci_release_regions(cy_card[i].pdev);
5469#endif 5576#endif
5470 } 5577 }
5471 } 5578 }
5472} /* cy_cleanup_module */ 5579} /* cy_cleanup_module */
5473 5580
5474module_init(cy_init); 5581module_init(cy_init);
diff --git a/drivers/char/drm/drm.h b/drivers/char/drm/drm.h
index 5642ac43e0f5..8db9041e306c 100644
--- a/drivers/char/drm/drm.h
+++ b/drivers/char/drm/drm.h
@@ -117,6 +117,14 @@ typedef struct drm_clip_rect {
117} drm_clip_rect_t; 117} drm_clip_rect_t;
118 118
119/** 119/**
120 * Drawable information.
121 */
122typedef struct drm_drawable_info {
123 unsigned int num_rects;
124 drm_clip_rect_t *rects;
125} drm_drawable_info_t;
126
127/**
120 * Texture region, 128 * Texture region,
121 */ 129 */
122typedef struct drm_tex_region { 130typedef struct drm_tex_region {
@@ -348,7 +356,8 @@ typedef struct drm_buf_desc {
348 _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */ 356 _DRM_PAGE_ALIGN = 0x01, /**< Align on page boundaries for DMA */
349 _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */ 357 _DRM_AGP_BUFFER = 0x02, /**< Buffer is in AGP space */
350 _DRM_SG_BUFFER = 0x04, /**< Scatter/gather memory buffer */ 358 _DRM_SG_BUFFER = 0x04, /**< Scatter/gather memory buffer */
351 _DRM_FB_BUFFER = 0x08 /**< Buffer is in frame buffer */ 359 _DRM_FB_BUFFER = 0x08, /**< Buffer is in frame buffer */
360 _DRM_PCI_BUFFER_RO = 0x10 /**< Map PCI DMA buffer read-only */
352 } flags; 361 } flags;
353 unsigned long agp_start; /**< 362 unsigned long agp_start; /**<
354 * Start address of where the AGP buffers are 363 * Start address of where the AGP buffers are
@@ -444,6 +453,20 @@ typedef struct drm_draw {
444} drm_draw_t; 453} drm_draw_t;
445 454
446/** 455/**
456 * DRM_IOCTL_UPDATE_DRAW ioctl argument type.
457 */
458typedef enum {
459 DRM_DRAWABLE_CLIPRECTS,
460} drm_drawable_info_type_t;
461
462typedef struct drm_update_draw {
463 drm_drawable_t handle;
464 unsigned int type;
465 unsigned int num;
466 unsigned long long data;
467} drm_update_draw_t;
468
469/**
447 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type. 470 * DRM_IOCTL_GET_MAGIC and DRM_IOCTL_AUTH_MAGIC ioctl argument type.
448 */ 471 */
449typedef struct drm_auth { 472typedef struct drm_auth {
@@ -465,10 +488,14 @@ typedef struct drm_irq_busid {
465typedef enum { 488typedef enum {
466 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */ 489 _DRM_VBLANK_ABSOLUTE = 0x0, /**< Wait for specific vblank sequence number */
467 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */ 490 _DRM_VBLANK_RELATIVE = 0x1, /**< Wait for given number of vblanks */
491 _DRM_VBLANK_NEXTONMISS = 0x10000000, /**< If missed, wait for next vblank */
492 _DRM_VBLANK_SECONDARY = 0x20000000, /**< Secondary display controller */
468 _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */ 493 _DRM_VBLANK_SIGNAL = 0x40000000 /**< Send signal instead of blocking */
469} drm_vblank_seq_type_t; 494} drm_vblank_seq_type_t;
470 495
471#define _DRM_VBLANK_FLAGS_MASK _DRM_VBLANK_SIGNAL 496#define _DRM_VBLANK_TYPES_MASK (_DRM_VBLANK_ABSOLUTE | _DRM_VBLANK_RELATIVE)
497#define _DRM_VBLANK_FLAGS_MASK (_DRM_VBLANK_SIGNAL | _DRM_VBLANK_SECONDARY | \
498 _DRM_VBLANK_NEXTONMISS)
472 499
473struct drm_wait_vblank_request { 500struct drm_wait_vblank_request {
474 drm_vblank_seq_type_t type; 501 drm_vblank_seq_type_t type;
@@ -623,6 +650,8 @@ typedef struct drm_set_version {
623 650
624#define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, drm_wait_vblank_t) 651#define DRM_IOCTL_WAIT_VBLANK DRM_IOWR(0x3a, drm_wait_vblank_t)
625 652
653#define DRM_IOCTL_UPDATE_DRAW DRM_IOW(0x3f, drm_update_draw_t)
654
626/** 655/**
627 * Device specific ioctls should only be in their respective headers 656 * Device specific ioctls should only be in their respective headers
628 * The device specific ioctl range is from 0x40 to 0x79. 657 * The device specific ioctl range is from 0x40 to 0x79.
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 7690a59ace04..0bbb04f2390f 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -97,6 +97,7 @@
97#define DRIVER_IRQ_VBL 0x100 97#define DRIVER_IRQ_VBL 0x100
98#define DRIVER_DMA_QUEUE 0x200 98#define DRIVER_DMA_QUEUE 0x200
99#define DRIVER_FB_DMA 0x400 99#define DRIVER_FB_DMA 0x400
100#define DRIVER_IRQ_VBL2 0x800
100 101
101/***********************************************************************/ 102/***********************************************************************/
102/** \name Begin the DRM... */ 103/** \name Begin the DRM... */
@@ -430,7 +431,8 @@ typedef struct drm_device_dma {
430 enum { 431 enum {
431 _DRM_DMA_USE_AGP = 0x01, 432 _DRM_DMA_USE_AGP = 0x01,
432 _DRM_DMA_USE_SG = 0x02, 433 _DRM_DMA_USE_SG = 0x02,
433 _DRM_DMA_USE_FB = 0x04 434 _DRM_DMA_USE_FB = 0x04,
435 _DRM_DMA_USE_PCI_RO = 0x08
434 } flags; 436 } flags;
435 437
436} drm_device_dma_t; 438} drm_device_dma_t;
@@ -562,6 +564,7 @@ struct drm_driver {
562 void (*kernel_context_switch_unlock) (struct drm_device * dev, 564 void (*kernel_context_switch_unlock) (struct drm_device * dev,
563 drm_lock_t *lock); 565 drm_lock_t *lock);
564 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence); 566 int (*vblank_wait) (struct drm_device * dev, unsigned int *sequence);
567 int (*vblank_wait2) (struct drm_device * dev, unsigned int *sequence);
565 int (*dri_library_name) (struct drm_device *dev, char *buf); 568 int (*dri_library_name) (struct drm_device *dev, char *buf);
566 569
567 /** 570 /**
@@ -708,9 +711,13 @@ typedef struct drm_device {
708 711
709 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */ 712 wait_queue_head_t vbl_queue; /**< VBLANK wait queue */
710 atomic_t vbl_received; 713 atomic_t vbl_received;
714 atomic_t vbl_received2; /**< number of secondary VBLANK interrupts */
711 spinlock_t vbl_lock; 715 spinlock_t vbl_lock;
712 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */ 716 drm_vbl_sig_t vbl_sigs; /**< signal list to send on VBLANK */
717 drm_vbl_sig_t vbl_sigs2; /**< signals to send on secondary VBLANK */
713 unsigned int vbl_pending; 718 unsigned int vbl_pending;
719 spinlock_t tasklet_lock; /**< For drm_locked_tasklet */
720 void (*locked_tasklet_func)(struct drm_device *dev);
714 721
715 /*@} */ 722 /*@} */
716 cycles_t ctx_start; 723 cycles_t ctx_start;
@@ -738,6 +745,15 @@ typedef struct drm_device {
738 drm_local_map_t *agp_buffer_map; 745 drm_local_map_t *agp_buffer_map;
739 unsigned int agp_buffer_token; 746 unsigned int agp_buffer_token;
740 drm_head_t primary; /**< primary screen head */ 747 drm_head_t primary; /**< primary screen head */
748
749 /** \name Drawable information */
750 /*@{ */
751 spinlock_t drw_lock;
752 unsigned int drw_bitfield_length;
753 u32 *drw_bitfield;
754 unsigned int drw_info_length;
755 drm_drawable_info_t **drw_info;
756 /*@} */
741} drm_device_t; 757} drm_device_t;
742 758
743static __inline__ int drm_core_check_feature(struct drm_device *dev, 759static __inline__ int drm_core_check_feature(struct drm_device *dev,
@@ -885,6 +901,10 @@ extern int drm_adddraw(struct inode *inode, struct file *filp,
885 unsigned int cmd, unsigned long arg); 901 unsigned int cmd, unsigned long arg);
886extern int drm_rmdraw(struct inode *inode, struct file *filp, 902extern int drm_rmdraw(struct inode *inode, struct file *filp,
887 unsigned int cmd, unsigned long arg); 903 unsigned int cmd, unsigned long arg);
904extern int drm_update_drawable_info(struct inode *inode, struct file *filp,
905 unsigned int cmd, unsigned long arg);
906extern drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev,
907 drm_drawable_t id);
888 908
889 /* Authentication IOCTL support (drm_auth.h) */ 909 /* Authentication IOCTL support (drm_auth.h) */
890extern int drm_getmagic(struct inode *inode, struct file *filp, 910extern int drm_getmagic(struct inode *inode, struct file *filp,
@@ -949,6 +969,7 @@ extern int drm_wait_vblank(struct inode *inode, struct file *filp,
949 unsigned int cmd, unsigned long arg); 969 unsigned int cmd, unsigned long arg);
950extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq); 970extern int drm_vblank_wait(drm_device_t * dev, unsigned int *vbl_seq);
951extern void drm_vbl_send_signals(drm_device_t * dev); 971extern void drm_vbl_send_signals(drm_device_t * dev);
972extern void drm_locked_tasklet(drm_device_t *dev, void(*func)(drm_device_t*));
952 973
953 /* AGP/GART support (drm_agpsupport.h) */ 974 /* AGP/GART support (drm_agpsupport.h) */
954extern drm_agp_head_t *drm_agp_init(drm_device_t * dev); 975extern drm_agp_head_t *drm_agp_init(drm_device_t * dev);
diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c
index 6eafff13dab6..9f65f5697ba8 100644
--- a/drivers/char/drm/drm_bufs.c
+++ b/drivers/char/drm/drm_bufs.c
@@ -887,6 +887,9 @@ int drm_addbufs_pci(drm_device_t * dev, drm_buf_desc_t * request)
887 request->count = entry->buf_count; 887 request->count = entry->buf_count;
888 request->size = size; 888 request->size = size;
889 889
890 if (request->flags & _DRM_PCI_BUFFER_RO)
891 dma->flags = _DRM_DMA_USE_PCI_RO;
892
890 atomic_dec(&dev->buf_alloc); 893 atomic_dec(&dev->buf_alloc);
891 return 0; 894 return 0;
892 895
@@ -1471,9 +1474,10 @@ int drm_freebufs(struct inode *inode, struct file *filp,
1471 * \param arg pointer to a drm_buf_map structure. 1474 * \param arg pointer to a drm_buf_map structure.
1472 * \return zero on success or a negative number on failure. 1475 * \return zero on success or a negative number on failure.
1473 * 1476 *
1474 * Maps the AGP or SG buffer region with do_mmap(), and copies information 1477 * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information
1475 * about each buffer into user space. The PCI buffers are already mapped on the 1478 * about each buffer into user space. For PCI buffers, it calls do_mmap() with
1476 * addbufs_pci() call. 1479 * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls
1480 * drm_mmap_dma().
1477 */ 1481 */
1478int drm_mapbufs(struct inode *inode, struct file *filp, 1482int drm_mapbufs(struct inode *inode, struct file *filp,
1479 unsigned int cmd, unsigned long arg) 1483 unsigned int cmd, unsigned long arg)
diff --git a/drivers/char/drm/drm_core.h b/drivers/char/drm/drm_core.h
index f4f9db6c7ed4..316739036079 100644
--- a/drivers/char/drm/drm_core.h
+++ b/drivers/char/drm/drm_core.h
@@ -24,11 +24,11 @@
24 24
25#define CORE_NAME "drm" 25#define CORE_NAME "drm"
26#define CORE_DESC "DRM shared core routines" 26#define CORE_DESC "DRM shared core routines"
27#define CORE_DATE "20051102" 27#define CORE_DATE "20060810"
28 28
29#define DRM_IF_MAJOR 1 29#define DRM_IF_MAJOR 1
30#define DRM_IF_MINOR 2 30#define DRM_IF_MINOR 3
31 31
32#define CORE_MAJOR 1 32#define CORE_MAJOR 1
33#define CORE_MINOR 0 33#define CORE_MINOR 1
34#define CORE_PATCHLEVEL 1 34#define CORE_PATCHLEVEL 0
diff --git a/drivers/char/drm/drm_drawable.c b/drivers/char/drm/drm_drawable.c
index 7857453c4f48..de37d5f74563 100644
--- a/drivers/char/drm/drm_drawable.c
+++ b/drivers/char/drm/drm_drawable.c
@@ -4,6 +4,7 @@
4 * 4 *
5 * \author Rickard E. (Rik) Faith <faith@valinux.com> 5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com> 6 * \author Gareth Hughes <gareth@valinux.com>
7 * \author Michel Dänzer <michel@tungstengraphics.com>
7 */ 8 */
8 9
9/* 10/*
@@ -11,6 +12,7 @@
11 * 12 *
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 13 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 14 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
15 * Copyright 2006 Tungsten Graphics, Inc., Bismarck, North Dakota.
14 * All Rights Reserved. 16 * All Rights Reserved.
15 * 17 *
16 * Permission is hereby granted, free of charge, to any person obtaining a 18 * Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,22 +37,294 @@
35 37
36#include "drmP.h" 38#include "drmP.h"
37 39
38/** No-op. */ 40/**
39int drm_adddraw(struct inode *inode, struct file *filp, 41 * Allocate drawable ID and memory to store information about it.
40 unsigned int cmd, unsigned long arg) 42 */
43int drm_adddraw(DRM_IOCTL_ARGS)
41{ 44{
45 DRM_DEVICE;
46 unsigned long irqflags;
47 int i, j;
48 u32 *bitfield = dev->drw_bitfield;
49 unsigned int bitfield_length = dev->drw_bitfield_length;
50 drm_drawable_info_t **info = dev->drw_info;
51 unsigned int info_length = dev->drw_info_length;
42 drm_draw_t draw; 52 drm_draw_t draw;
43 53
44 draw.handle = 0; /* NOOP */ 54 for (i = 0, j = 0; i < bitfield_length; i++) {
55 if (bitfield[i] == ~0)
56 continue;
57
58 for (; j < 8 * sizeof(*bitfield); j++)
59 if (!(bitfield[i] & (1 << j)))
60 goto done;
61 }
62done:
63
64 if (i == bitfield_length) {
65 bitfield_length++;
66
67 bitfield = drm_alloc(bitfield_length * sizeof(*bitfield),
68 DRM_MEM_BUFS);
69
70 if (!bitfield) {
71 DRM_ERROR("Failed to allocate new drawable bitfield\n");
72 return DRM_ERR(ENOMEM);
73 }
74
75 if (8 * sizeof(*bitfield) * bitfield_length > info_length) {
76 info_length += 8 * sizeof(*bitfield);
77
78 info = drm_alloc(info_length * sizeof(*info),
79 DRM_MEM_BUFS);
80
81 if (!info) {
82 DRM_ERROR("Failed to allocate new drawable info"
83 " array\n");
84
85 drm_free(bitfield,
86 bitfield_length * sizeof(*bitfield),
87 DRM_MEM_BUFS);
88 return DRM_ERR(ENOMEM);
89 }
90 }
91
92 bitfield[i] = 0;
93 }
94
95 draw.handle = i * 8 * sizeof(*bitfield) + j + 1;
45 DRM_DEBUG("%d\n", draw.handle); 96 DRM_DEBUG("%d\n", draw.handle);
46 if (copy_to_user((drm_draw_t __user *) arg, &draw, sizeof(draw))) 97
47 return -EFAULT; 98 spin_lock_irqsave(&dev->drw_lock, irqflags);
99
100 bitfield[i] |= 1 << j;
101 info[draw.handle - 1] = NULL;
102
103 if (bitfield != dev->drw_bitfield) {
104 memcpy(bitfield, dev->drw_bitfield, dev->drw_bitfield_length *
105 sizeof(*bitfield));
106 drm_free(dev->drw_bitfield, sizeof(*bitfield) *
107 dev->drw_bitfield_length, DRM_MEM_BUFS);
108 dev->drw_bitfield = bitfield;
109 dev->drw_bitfield_length = bitfield_length;
110 }
111
112 if (info != dev->drw_info) {
113 memcpy(info, dev->drw_info, dev->drw_info_length *
114 sizeof(*info));
115 drm_free(dev->drw_info, sizeof(*info) * dev->drw_info_length,
116 DRM_MEM_BUFS);
117 dev->drw_info = info;
118 dev->drw_info_length = info_length;
119 }
120
121 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
122
123 DRM_COPY_TO_USER_IOCTL((drm_draw_t __user *)data, draw, sizeof(draw));
124
48 return 0; 125 return 0;
49} 126}
50 127
51/** No-op. */ 128/**
52int drm_rmdraw(struct inode *inode, struct file *filp, 129 * Free drawable ID and memory to store information about it.
53 unsigned int cmd, unsigned long arg) 130 */
131int drm_rmdraw(DRM_IOCTL_ARGS)
54{ 132{
55 return 0; /* NOOP */ 133 DRM_DEVICE;
134 drm_draw_t draw;
135 int id, idx;
136 unsigned int shift;
137 unsigned long irqflags;
138 u32 *bitfield = dev->drw_bitfield;
139 unsigned int bitfield_length = dev->drw_bitfield_length;
140 drm_drawable_info_t **info = dev->drw_info;
141 unsigned int info_length = dev->drw_info_length;
142
143 DRM_COPY_FROM_USER_IOCTL(draw, (drm_draw_t __user *) data,
144 sizeof(draw));
145
146 id = draw.handle - 1;
147 idx = id / (8 * sizeof(*bitfield));
148 shift = id % (8 * sizeof(*bitfield));
149
150 if (idx < 0 || idx >= bitfield_length ||
151 !(bitfield[idx] & (1 << shift))) {
152 DRM_DEBUG("No such drawable %d\n", draw.handle);
153 return 0;
154 }
155
156 spin_lock_irqsave(&dev->drw_lock, irqflags);
157
158 bitfield[idx] &= ~(1 << shift);
159
160 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
161
162 if (info[id]) {
163 drm_free(info[id]->rects, info[id]->num_rects *
164 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
165 drm_free(info[id], sizeof(**info), DRM_MEM_BUFS);
166 }
167
168 /* Can we shrink the arrays? */
169 if (idx == bitfield_length - 1) {
170 while (idx >= 0 && !bitfield[idx])
171 --idx;
172
173 bitfield_length = idx + 1;
174
175 if (idx != id / (8 * sizeof(*bitfield)))
176 bitfield = drm_alloc(bitfield_length *
177 sizeof(*bitfield), DRM_MEM_BUFS);
178
179 if (!bitfield && bitfield_length) {
180 bitfield = dev->drw_bitfield;
181 bitfield_length = dev->drw_bitfield_length;
182 }
183 }
184
185 if (bitfield != dev->drw_bitfield) {
186 info_length = 8 * sizeof(*bitfield) * bitfield_length;
187
188 info = drm_alloc(info_length * sizeof(*info), DRM_MEM_BUFS);
189
190 if (!info && info_length) {
191 info = dev->drw_info;
192 info_length = dev->drw_info_length;
193 }
194
195 spin_lock_irqsave(&dev->drw_lock, irqflags);
196
197 memcpy(bitfield, dev->drw_bitfield, bitfield_length *
198 sizeof(*bitfield));
199 drm_free(dev->drw_bitfield, sizeof(*bitfield) *
200 dev->drw_bitfield_length, DRM_MEM_BUFS);
201 dev->drw_bitfield = bitfield;
202 dev->drw_bitfield_length = bitfield_length;
203
204 if (info != dev->drw_info) {
205 memcpy(info, dev->drw_info, info_length *
206 sizeof(*info));
207 drm_free(dev->drw_info, sizeof(*info) *
208 dev->drw_info_length, DRM_MEM_BUFS);
209 dev->drw_info = info;
210 dev->drw_info_length = info_length;
211 }
212
213 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
214 }
215
216 DRM_DEBUG("%d\n", draw.handle);
217 return 0;
218}
219
220int drm_update_drawable_info(DRM_IOCTL_ARGS) {
221 DRM_DEVICE;
222 drm_update_draw_t update;
223 unsigned int id, idx, shift;
224 u32 *bitfield = dev->drw_bitfield;
225 unsigned long irqflags, bitfield_length = dev->drw_bitfield_length;
226 drm_drawable_info_t *info;
227 drm_clip_rect_t *rects;
228 int err;
229
230 DRM_COPY_FROM_USER_IOCTL(update, (drm_update_draw_t __user *) data,
231 sizeof(update));
232
233 id = update.handle - 1;
234 idx = id / (8 * sizeof(*bitfield));
235 shift = id % (8 * sizeof(*bitfield));
236
237 if (idx < 0 || idx >= bitfield_length ||
238 !(bitfield[idx] & (1 << shift))) {
239 DRM_ERROR("No such drawable %d\n", update.handle);
240 return DRM_ERR(EINVAL);
241 }
242
243 info = dev->drw_info[id];
244
245 if (!info) {
246 info = drm_calloc(1, sizeof(drm_drawable_info_t), DRM_MEM_BUFS);
247
248 if (!info) {
249 DRM_ERROR("Failed to allocate drawable info memory\n");
250 return DRM_ERR(ENOMEM);
251 }
252 }
253
254 switch (update.type) {
255 case DRM_DRAWABLE_CLIPRECTS:
256 if (update.num != info->num_rects) {
257 rects = drm_alloc(update.num * sizeof(drm_clip_rect_t),
258 DRM_MEM_BUFS);
259 } else
260 rects = info->rects;
261
262 if (update.num && !rects) {
263 DRM_ERROR("Failed to allocate cliprect memory\n");
264 err = DRM_ERR(ENOMEM);
265 goto error;
266 }
267
268 if (update.num && DRM_COPY_FROM_USER(rects,
269 (drm_clip_rect_t __user *)
270 (unsigned long)update.data,
271 update.num *
272 sizeof(*rects))) {
273 DRM_ERROR("Failed to copy cliprects from userspace\n");
274 err = DRM_ERR(EFAULT);
275 goto error;
276 }
277
278 spin_lock_irqsave(&dev->drw_lock, irqflags);
279
280 if (rects != info->rects) {
281 drm_free(info->rects, info->num_rects *
282 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
283 }
284
285 info->rects = rects;
286 info->num_rects = update.num;
287 dev->drw_info[id] = info;
288
289 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
290
291 DRM_DEBUG("Updated %d cliprects for drawable %d\n",
292 info->num_rects, id);
293 break;
294 default:
295 DRM_ERROR("Invalid update type %d\n", update.type);
296 return DRM_ERR(EINVAL);
297 }
298
299 return 0;
300
301error:
302 if (!dev->drw_info[id])
303 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
304 else if (rects != dev->drw_info[id]->rects)
305 drm_free(rects, update.num *
306 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
307
308 return err;
309}
310
311/**
312 * Caller must hold the drawable spinlock!
313 */
314drm_drawable_info_t *drm_get_drawable_info(drm_device_t *dev, drm_drawable_t id) {
315 u32 *bitfield = dev->drw_bitfield;
316 unsigned int idx, shift;
317
318 id--;
319 idx = id / (8 * sizeof(*bitfield));
320 shift = id % (8 * sizeof(*bitfield));
321
322 if (idx < 0 || idx >= dev->drw_bitfield_length ||
323 !(bitfield[idx] & (1 << shift))) {
324 DRM_DEBUG("No such drawable %d\n", id);
325 return NULL;
326 }
327
328 return dev->drw_info[id];
56} 329}
330EXPORT_SYMBOL(drm_get_drawable_info);
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index b366c5b1bd16..a70af0de4453 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -116,6 +116,8 @@ static drm_ioctl_desc_t drm_ioctls[] = {
116 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 116 [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
117 117
118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0}, 118 [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0},
119
120 [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
119}; 121};
120 122
121#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) 123#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
@@ -151,6 +153,18 @@ int drm_lastclose(drm_device_t * dev)
151 if (dev->irq_enabled) 153 if (dev->irq_enabled)
152 drm_irq_uninstall(dev); 154 drm_irq_uninstall(dev);
153 155
156 /* Free drawable information memory */
157 for (i = 0; i < dev->drw_bitfield_length / sizeof(*dev->drw_bitfield);
158 i++) {
159 drm_drawable_info_t *info = drm_get_drawable_info(dev, i);
160
161 if (info) {
162 drm_free(info->rects, info->num_rects *
163 sizeof(drm_clip_rect_t), DRM_MEM_BUFS);
164 drm_free(info, sizeof(*info), DRM_MEM_BUFS);
165 }
166 }
167
154 mutex_lock(&dev->struct_mutex); 168 mutex_lock(&dev->struct_mutex);
155 del_timer(&dev->timer); 169 del_timer(&dev->timer);
156 170
diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c
index d4f874520082..fafeb34f89d5 100644
--- a/drivers/char/drm/drm_ioc32.c
+++ b/drivers/char/drm/drm_ioc32.c
@@ -102,7 +102,7 @@ static int compat_drm_version(struct file *file, unsigned int cmd,
102 &version->desc)) 102 &version->desc))
103 return -EFAULT; 103 return -EFAULT;
104 104
105 err = drm_ioctl(file->f_dentry->d_inode, file, 105 err = drm_ioctl(file->f_path.dentry->d_inode, file,
106 DRM_IOCTL_VERSION, (unsigned long)version); 106 DRM_IOCTL_VERSION, (unsigned long)version);
107 if (err) 107 if (err)
108 return err; 108 return err;
@@ -143,7 +143,7 @@ static int compat_drm_getunique(struct file *file, unsigned int cmd,
143 &u->unique)) 143 &u->unique))
144 return -EFAULT; 144 return -EFAULT;
145 145
146 err = drm_ioctl(file->f_dentry->d_inode, file, 146 err = drm_ioctl(file->f_path.dentry->d_inode, file,
147 DRM_IOCTL_GET_UNIQUE, (unsigned long)u); 147 DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
148 if (err) 148 if (err)
149 return err; 149 return err;
@@ -172,7 +172,7 @@ static int compat_drm_setunique(struct file *file, unsigned int cmd,
172 &u->unique)) 172 &u->unique))
173 return -EFAULT; 173 return -EFAULT;
174 174
175 return drm_ioctl(file->f_dentry->d_inode, file, 175 return drm_ioctl(file->f_path.dentry->d_inode, file,
176 DRM_IOCTL_SET_UNIQUE, (unsigned long)u); 176 DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
177} 177}
178 178
@@ -203,7 +203,7 @@ static int compat_drm_getmap(struct file *file, unsigned int cmd,
203 if (__put_user(idx, &map->offset)) 203 if (__put_user(idx, &map->offset))
204 return -EFAULT; 204 return -EFAULT;
205 205
206 err = drm_ioctl(file->f_dentry->d_inode, file, 206 err = drm_ioctl(file->f_path.dentry->d_inode, file,
207 DRM_IOCTL_GET_MAP, (unsigned long)map); 207 DRM_IOCTL_GET_MAP, (unsigned long)map);
208 if (err) 208 if (err)
209 return err; 209 return err;
@@ -244,7 +244,7 @@ static int compat_drm_addmap(struct file *file, unsigned int cmd,
244 || __put_user(m32.flags, &map->flags)) 244 || __put_user(m32.flags, &map->flags))
245 return -EFAULT; 245 return -EFAULT;
246 246
247 err = drm_ioctl(file->f_dentry->d_inode, file, 247 err = drm_ioctl(file->f_path.dentry->d_inode, file,
248 DRM_IOCTL_ADD_MAP, (unsigned long)map); 248 DRM_IOCTL_ADD_MAP, (unsigned long)map);
249 if (err) 249 if (err)
250 return err; 250 return err;
@@ -282,7 +282,7 @@ static int compat_drm_rmmap(struct file *file, unsigned int cmd,
282 if (__put_user((void *)(unsigned long)handle, &map->handle)) 282 if (__put_user((void *)(unsigned long)handle, &map->handle))
283 return -EFAULT; 283 return -EFAULT;
284 284
285 return drm_ioctl(file->f_dentry->d_inode, file, 285 return drm_ioctl(file->f_path.dentry->d_inode, file,
286 DRM_IOCTL_RM_MAP, (unsigned long)map); 286 DRM_IOCTL_RM_MAP, (unsigned long)map);
287} 287}
288 288
@@ -312,7 +312,7 @@ static int compat_drm_getclient(struct file *file, unsigned int cmd,
312 if (__put_user(idx, &client->idx)) 312 if (__put_user(idx, &client->idx))
313 return -EFAULT; 313 return -EFAULT;
314 314
315 err = drm_ioctl(file->f_dentry->d_inode, file, 315 err = drm_ioctl(file->f_path.dentry->d_inode, file,
316 DRM_IOCTL_GET_CLIENT, (unsigned long)client); 316 DRM_IOCTL_GET_CLIENT, (unsigned long)client);
317 if (err) 317 if (err)
318 return err; 318 return err;
@@ -349,7 +349,7 @@ static int compat_drm_getstats(struct file *file, unsigned int cmd,
349 if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats))) 349 if (!access_ok(VERIFY_WRITE, stats, sizeof(*stats)))
350 return -EFAULT; 350 return -EFAULT;
351 351
352 err = drm_ioctl(file->f_dentry->d_inode, file, 352 err = drm_ioctl(file->f_path.dentry->d_inode, file,
353 DRM_IOCTL_GET_STATS, (unsigned long)stats); 353 DRM_IOCTL_GET_STATS, (unsigned long)stats);
354 if (err) 354 if (err)
355 return err; 355 return err;
@@ -393,7 +393,7 @@ static int compat_drm_addbufs(struct file *file, unsigned int cmd,
393 || __put_user(agp_start, &buf->agp_start)) 393 || __put_user(agp_start, &buf->agp_start))
394 return -EFAULT; 394 return -EFAULT;
395 395
396 err = drm_ioctl(file->f_dentry->d_inode, file, 396 err = drm_ioctl(file->f_path.dentry->d_inode, file,
397 DRM_IOCTL_ADD_BUFS, (unsigned long)buf); 397 DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
398 if (err) 398 if (err)
399 return err; 399 return err;
@@ -425,7 +425,7 @@ static int compat_drm_markbufs(struct file *file, unsigned int cmd,
425 || __put_user(b32.high_mark, &buf->high_mark)) 425 || __put_user(b32.high_mark, &buf->high_mark))
426 return -EFAULT; 426 return -EFAULT;
427 427
428 return drm_ioctl(file->f_dentry->d_inode, file, 428 return drm_ioctl(file->f_path.dentry->d_inode, file,
429 DRM_IOCTL_MARK_BUFS, (unsigned long)buf); 429 DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
430} 430}
431 431
@@ -467,7 +467,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
467 || __put_user(list, &request->list)) 467 || __put_user(list, &request->list))
468 return -EFAULT; 468 return -EFAULT;
469 469
470 err = drm_ioctl(file->f_dentry->d_inode, file, 470 err = drm_ioctl(file->f_path.dentry->d_inode, file,
471 DRM_IOCTL_INFO_BUFS, (unsigned long)request); 471 DRM_IOCTL_INFO_BUFS, (unsigned long)request);
472 if (err) 472 if (err)
473 return err; 473 return err;
@@ -529,7 +529,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
529 || __put_user(list, &request->list)) 529 || __put_user(list, &request->list))
530 return -EFAULT; 530 return -EFAULT;
531 531
532 err = drm_ioctl(file->f_dentry->d_inode, file, 532 err = drm_ioctl(file->f_path.dentry->d_inode, file,
533 DRM_IOCTL_MAP_BUFS, (unsigned long)request); 533 DRM_IOCTL_MAP_BUFS, (unsigned long)request);
534 if (err) 534 if (err)
535 return err; 535 return err;
@@ -576,7 +576,7 @@ static int compat_drm_freebufs(struct file *file, unsigned int cmd,
576 &request->list)) 576 &request->list))
577 return -EFAULT; 577 return -EFAULT;
578 578
579 return drm_ioctl(file->f_dentry->d_inode, file, 579 return drm_ioctl(file->f_path.dentry->d_inode, file,
580 DRM_IOCTL_FREE_BUFS, (unsigned long)request); 580 DRM_IOCTL_FREE_BUFS, (unsigned long)request);
581} 581}
582 582
@@ -603,7 +603,7 @@ static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
603 &request->handle)) 603 &request->handle))
604 return -EFAULT; 604 return -EFAULT;
605 605
606 return drm_ioctl(file->f_dentry->d_inode, file, 606 return drm_ioctl(file->f_path.dentry->d_inode, file,
607 DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request); 607 DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
608} 608}
609 609
@@ -626,7 +626,7 @@ static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
626 if (__put_user(ctx_id, &request->ctx_id)) 626 if (__put_user(ctx_id, &request->ctx_id))
627 return -EFAULT; 627 return -EFAULT;
628 628
629 err = drm_ioctl(file->f_dentry->d_inode, file, 629 err = drm_ioctl(file->f_path.dentry->d_inode, file,
630 DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request); 630 DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
631 if (err) 631 if (err)
632 return err; 632 return err;
@@ -662,7 +662,7 @@ static int compat_drm_resctx(struct file *file, unsigned int cmd,
662 &res->contexts)) 662 &res->contexts))
663 return -EFAULT; 663 return -EFAULT;
664 664
665 err = drm_ioctl(file->f_dentry->d_inode, file, 665 err = drm_ioctl(file->f_path.dentry->d_inode, file,
666 DRM_IOCTL_RES_CTX, (unsigned long)res); 666 DRM_IOCTL_RES_CTX, (unsigned long)res);
667 if (err) 667 if (err)
668 return err; 668 return err;
@@ -716,7 +716,7 @@ static int compat_drm_dma(struct file *file, unsigned int cmd,
716 &d->request_sizes)) 716 &d->request_sizes))
717 return -EFAULT; 717 return -EFAULT;
718 718
719 err = drm_ioctl(file->f_dentry->d_inode, file, 719 err = drm_ioctl(file->f_path.dentry->d_inode, file,
720 DRM_IOCTL_DMA, (unsigned long)d); 720 DRM_IOCTL_DMA, (unsigned long)d);
721 if (err) 721 if (err)
722 return err; 722 return err;
@@ -749,7 +749,7 @@ static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
749 if (put_user(m32.mode, &mode->mode)) 749 if (put_user(m32.mode, &mode->mode))
750 return -EFAULT; 750 return -EFAULT;
751 751
752 return drm_ioctl(file->f_dentry->d_inode, file, 752 return drm_ioctl(file->f_path.dentry->d_inode, file,
753 DRM_IOCTL_AGP_ENABLE, (unsigned long)mode); 753 DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
754} 754}
755 755
@@ -779,7 +779,7 @@ static int compat_drm_agp_info(struct file *file, unsigned int cmd,
779 if (!access_ok(VERIFY_WRITE, info, sizeof(*info))) 779 if (!access_ok(VERIFY_WRITE, info, sizeof(*info)))
780 return -EFAULT; 780 return -EFAULT;
781 781
782 err = drm_ioctl(file->f_dentry->d_inode, file, 782 err = drm_ioctl(file->f_path.dentry->d_inode, file,
783 DRM_IOCTL_AGP_INFO, (unsigned long)info); 783 DRM_IOCTL_AGP_INFO, (unsigned long)info);
784 if (err) 784 if (err)
785 return err; 785 return err;
@@ -825,7 +825,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
825 || __put_user(req32.type, &request->type)) 825 || __put_user(req32.type, &request->type))
826 return -EFAULT; 826 return -EFAULT;
827 827
828 err = drm_ioctl(file->f_dentry->d_inode, file, 828 err = drm_ioctl(file->f_path.dentry->d_inode, file,
829 DRM_IOCTL_AGP_ALLOC, (unsigned long)request); 829 DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
830 if (err) 830 if (err)
831 return err; 831 return err;
@@ -833,7 +833,7 @@ static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
833 if (__get_user(req32.handle, &request->handle) 833 if (__get_user(req32.handle, &request->handle)
834 || __get_user(req32.physical, &request->physical) 834 || __get_user(req32.physical, &request->physical)
835 || copy_to_user(argp, &req32, sizeof(req32))) { 835 || copy_to_user(argp, &req32, sizeof(req32))) {
836 drm_ioctl(file->f_dentry->d_inode, file, 836 drm_ioctl(file->f_path.dentry->d_inode, file,
837 DRM_IOCTL_AGP_FREE, (unsigned long)request); 837 DRM_IOCTL_AGP_FREE, (unsigned long)request);
838 return -EFAULT; 838 return -EFAULT;
839 } 839 }
@@ -854,7 +854,7 @@ static int compat_drm_agp_free(struct file *file, unsigned int cmd,
854 || __put_user(handle, &request->handle)) 854 || __put_user(handle, &request->handle))
855 return -EFAULT; 855 return -EFAULT;
856 856
857 return drm_ioctl(file->f_dentry->d_inode, file, 857 return drm_ioctl(file->f_path.dentry->d_inode, file,
858 DRM_IOCTL_AGP_FREE, (unsigned long)request); 858 DRM_IOCTL_AGP_FREE, (unsigned long)request);
859} 859}
860 860
@@ -879,7 +879,7 @@ static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
879 || __put_user(req32.offset, &request->offset)) 879 || __put_user(req32.offset, &request->offset))
880 return -EFAULT; 880 return -EFAULT;
881 881
882 return drm_ioctl(file->f_dentry->d_inode, file, 882 return drm_ioctl(file->f_path.dentry->d_inode, file,
883 DRM_IOCTL_AGP_BIND, (unsigned long)request); 883 DRM_IOCTL_AGP_BIND, (unsigned long)request);
884} 884}
885 885
@@ -896,7 +896,7 @@ static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
896 || __put_user(handle, &request->handle)) 896 || __put_user(handle, &request->handle))
897 return -EFAULT; 897 return -EFAULT;
898 898
899 return drm_ioctl(file->f_dentry->d_inode, file, 899 return drm_ioctl(file->f_path.dentry->d_inode, file,
900 DRM_IOCTL_AGP_UNBIND, (unsigned long)request); 900 DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
901} 901}
902#endif /* __OS_HAS_AGP */ 902#endif /* __OS_HAS_AGP */
@@ -921,7 +921,7 @@ static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
921 || __put_user(x, &request->size)) 921 || __put_user(x, &request->size))
922 return -EFAULT; 922 return -EFAULT;
923 923
924 err = drm_ioctl(file->f_dentry->d_inode, file, 924 err = drm_ioctl(file->f_path.dentry->d_inode, file,
925 DRM_IOCTL_SG_ALLOC, (unsigned long)request); 925 DRM_IOCTL_SG_ALLOC, (unsigned long)request);
926 if (err) 926 if (err)
927 return err; 927 return err;
@@ -948,7 +948,7 @@ static int compat_drm_sg_free(struct file *file, unsigned int cmd,
948 || __put_user(x << PAGE_SHIFT, &request->handle)) 948 || __put_user(x << PAGE_SHIFT, &request->handle))
949 return -EFAULT; 949 return -EFAULT;
950 950
951 return drm_ioctl(file->f_dentry->d_inode, file, 951 return drm_ioctl(file->f_path.dentry->d_inode, file,
952 DRM_IOCTL_SG_FREE, (unsigned long)request); 952 DRM_IOCTL_SG_FREE, (unsigned long)request);
953} 953}
954 954
@@ -988,7 +988,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
988 || __put_user(req32.request.signal, &request->request.signal)) 988 || __put_user(req32.request.signal, &request->request.signal))
989 return -EFAULT; 989 return -EFAULT;
990 990
991 err = drm_ioctl(file->f_dentry->d_inode, file, 991 err = drm_ioctl(file->f_path.dentry->d_inode, file,
992 DRM_IOCTL_WAIT_VBLANK, (unsigned long)request); 992 DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
993 if (err) 993 if (err)
994 return err; 994 return err;
@@ -1060,7 +1060,7 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1060 if (fn != NULL) 1060 if (fn != NULL)
1061 ret = (*fn) (filp, cmd, arg); 1061 ret = (*fn) (filp, cmd, arg);
1062 else 1062 else
1063 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 1063 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
1064 unlock_kernel(); 1064 unlock_kernel();
1065 1065
1066 return ret; 1066 return ret;
diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c
index 4553a3a1e496..9d00c51fe2c4 100644
--- a/drivers/char/drm/drm_irq.c
+++ b/drivers/char/drm/drm_irq.c
@@ -121,6 +121,7 @@ static int drm_irq_install(drm_device_t * dev)
121 spin_lock_init(&dev->vbl_lock); 121 spin_lock_init(&dev->vbl_lock);
122 122
123 INIT_LIST_HEAD(&dev->vbl_sigs.head); 123 INIT_LIST_HEAD(&dev->vbl_sigs.head);
124 INIT_LIST_HEAD(&dev->vbl_sigs2.head);
124 125
125 dev->vbl_pending = 0; 126 dev->vbl_pending = 0;
126 } 127 }
@@ -175,6 +176,8 @@ int drm_irq_uninstall(drm_device_t * dev)
175 176
176 free_irq(dev->irq, dev); 177 free_irq(dev->irq, dev);
177 178
179 dev->locked_tasklet_func = NULL;
180
178 return 0; 181 return 0;
179} 182}
180 183
@@ -247,10 +250,7 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
247 drm_wait_vblank_t vblwait; 250 drm_wait_vblank_t vblwait;
248 struct timeval now; 251 struct timeval now;
249 int ret = 0; 252 int ret = 0;
250 unsigned int flags; 253 unsigned int flags, seq;
251
252 if (!drm_core_check_feature(dev, DRIVER_IRQ_VBL))
253 return -EINVAL;
254 254
255 if (!dev->irq) 255 if (!dev->irq)
256 return -EINVAL; 256 return -EINVAL;
@@ -258,9 +258,26 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
258 if (copy_from_user(&vblwait, argp, sizeof(vblwait))) 258 if (copy_from_user(&vblwait, argp, sizeof(vblwait)))
259 return -EFAULT; 259 return -EFAULT;
260 260
261 switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) { 261 if (vblwait.request.type &
262 ~(_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK)) {
263 DRM_ERROR("Unsupported type value 0x%x, supported mask 0x%x\n",
264 vblwait.request.type,
265 (_DRM_VBLANK_TYPES_MASK | _DRM_VBLANK_FLAGS_MASK));
266 return -EINVAL;
267 }
268
269 flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK;
270
271 if (!drm_core_check_feature(dev, (flags & _DRM_VBLANK_SECONDARY) ?
272 DRIVER_IRQ_VBL2 : DRIVER_IRQ_VBL))
273 return -EINVAL;
274
275 seq = atomic_read((flags & _DRM_VBLANK_SECONDARY) ? &dev->vbl_received2
276 : &dev->vbl_received);
277
278 switch (vblwait.request.type & _DRM_VBLANK_TYPES_MASK) {
262 case _DRM_VBLANK_RELATIVE: 279 case _DRM_VBLANK_RELATIVE:
263 vblwait.request.sequence += atomic_read(&dev->vbl_received); 280 vblwait.request.sequence += seq;
264 vblwait.request.type &= ~_DRM_VBLANK_RELATIVE; 281 vblwait.request.type &= ~_DRM_VBLANK_RELATIVE;
265 case _DRM_VBLANK_ABSOLUTE: 282 case _DRM_VBLANK_ABSOLUTE:
266 break; 283 break;
@@ -268,26 +285,30 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
268 return -EINVAL; 285 return -EINVAL;
269 } 286 }
270 287
271 flags = vblwait.request.type & _DRM_VBLANK_FLAGS_MASK; 288 if ((flags & _DRM_VBLANK_NEXTONMISS) &&
289 (seq - vblwait.request.sequence) <= (1<<23)) {
290 vblwait.request.sequence = seq + 1;
291 }
272 292
273 if (flags & _DRM_VBLANK_SIGNAL) { 293 if (flags & _DRM_VBLANK_SIGNAL) {
274 unsigned long irqflags; 294 unsigned long irqflags;
295 drm_vbl_sig_t *vbl_sigs = (flags & _DRM_VBLANK_SECONDARY)
296 ? &dev->vbl_sigs2 : &dev->vbl_sigs;
275 drm_vbl_sig_t *vbl_sig; 297 drm_vbl_sig_t *vbl_sig;
276 298
277 vblwait.reply.sequence = atomic_read(&dev->vbl_received);
278
279 spin_lock_irqsave(&dev->vbl_lock, irqflags); 299 spin_lock_irqsave(&dev->vbl_lock, irqflags);
280 300
281 /* Check if this task has already scheduled the same signal 301 /* Check if this task has already scheduled the same signal
282 * for the same vblank sequence number; nothing to be done in 302 * for the same vblank sequence number; nothing to be done in
283 * that case 303 * that case
284 */ 304 */
285 list_for_each_entry(vbl_sig, &dev->vbl_sigs.head, head) { 305 list_for_each_entry(vbl_sig, &vbl_sigs->head, head) {
286 if (vbl_sig->sequence == vblwait.request.sequence 306 if (vbl_sig->sequence == vblwait.request.sequence
287 && vbl_sig->info.si_signo == vblwait.request.signal 307 && vbl_sig->info.si_signo == vblwait.request.signal
288 && vbl_sig->task == current) { 308 && vbl_sig->task == current) {
289 spin_unlock_irqrestore(&dev->vbl_lock, 309 spin_unlock_irqrestore(&dev->vbl_lock,
290 irqflags); 310 irqflags);
311 vblwait.reply.sequence = seq;
291 goto done; 312 goto done;
292 } 313 }
293 } 314 }
@@ -315,11 +336,16 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
315 336
316 spin_lock_irqsave(&dev->vbl_lock, irqflags); 337 spin_lock_irqsave(&dev->vbl_lock, irqflags);
317 338
318 list_add_tail((struct list_head *)vbl_sig, &dev->vbl_sigs.head); 339 list_add_tail((struct list_head *)vbl_sig, &vbl_sigs->head);
319 340
320 spin_unlock_irqrestore(&dev->vbl_lock, irqflags); 341 spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
342
343 vblwait.reply.sequence = seq;
321 } else { 344 } else {
322 if (dev->driver->vblank_wait) 345 if (flags & _DRM_VBLANK_SECONDARY) {
346 if (dev->driver->vblank_wait2)
347 ret = dev->driver->vblank_wait2(dev, &vblwait.request.sequence);
348 } else if (dev->driver->vblank_wait)
323 ret = 349 ret =
324 dev->driver->vblank_wait(dev, 350 dev->driver->vblank_wait(dev,
325 &vblwait.request.sequence); 351 &vblwait.request.sequence);
@@ -347,25 +373,32 @@ int drm_wait_vblank(DRM_IOCTL_ARGS)
347 */ 373 */
348void drm_vbl_send_signals(drm_device_t * dev) 374void drm_vbl_send_signals(drm_device_t * dev)
349{ 375{
350 struct list_head *list, *tmp;
351 drm_vbl_sig_t *vbl_sig;
352 unsigned int vbl_seq = atomic_read(&dev->vbl_received);
353 unsigned long flags; 376 unsigned long flags;
377 int i;
354 378
355 spin_lock_irqsave(&dev->vbl_lock, flags); 379 spin_lock_irqsave(&dev->vbl_lock, flags);
356 380
357 list_for_each_safe(list, tmp, &dev->vbl_sigs.head) { 381 for (i = 0; i < 2; i++) {
358 vbl_sig = list_entry(list, drm_vbl_sig_t, head); 382 struct list_head *list, *tmp;
359 if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) { 383 drm_vbl_sig_t *vbl_sig;
360 vbl_sig->info.si_code = vbl_seq; 384 drm_vbl_sig_t *vbl_sigs = i ? &dev->vbl_sigs2 : &dev->vbl_sigs;
361 send_sig_info(vbl_sig->info.si_signo, &vbl_sig->info, 385 unsigned int vbl_seq = atomic_read(i ? &dev->vbl_received2 :
362 vbl_sig->task); 386 &dev->vbl_received);
387
388 list_for_each_safe(list, tmp, &vbl_sigs->head) {
389 vbl_sig = list_entry(list, drm_vbl_sig_t, head);
390 if ((vbl_seq - vbl_sig->sequence) <= (1 << 23)) {
391 vbl_sig->info.si_code = vbl_seq;
392 send_sig_info(vbl_sig->info.si_signo,
393 &vbl_sig->info, vbl_sig->task);
363 394
364 list_del(list); 395 list_del(list);
365 396
366 drm_free(vbl_sig, sizeof(*vbl_sig), DRM_MEM_DRIVER); 397 drm_free(vbl_sig, sizeof(*vbl_sig),
398 DRM_MEM_DRIVER);
367 399
368 dev->vbl_pending--; 400 dev->vbl_pending--;
401 }
369 } 402 }
370 } 403 }
371 404
@@ -373,3 +406,77 @@ void drm_vbl_send_signals(drm_device_t * dev)
373} 406}
374 407
375EXPORT_SYMBOL(drm_vbl_send_signals); 408EXPORT_SYMBOL(drm_vbl_send_signals);
409
410/**
411 * Tasklet wrapper function.
412 *
413 * \param data DRM device in disguise.
414 *
415 * Attempts to grab the HW lock and calls the driver callback on success. On
416 * failure, leave the lock marked as contended so the callback can be called
417 * from drm_unlock().
418 */
419static void drm_locked_tasklet_func(unsigned long data)
420{
421 drm_device_t *dev = (drm_device_t*)data;
422 unsigned long irqflags;
423
424 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
425
426 if (!dev->locked_tasklet_func ||
427 !drm_lock_take(&dev->lock.hw_lock->lock,
428 DRM_KERNEL_CONTEXT)) {
429 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
430 return;
431 }
432
433 dev->lock.lock_time = jiffies;
434 atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
435
436 dev->locked_tasklet_func(dev);
437
438 drm_lock_free(dev, &dev->lock.hw_lock->lock,
439 DRM_KERNEL_CONTEXT);
440
441 dev->locked_tasklet_func = NULL;
442
443 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
444}
445
446/**
447 * Schedule a tasklet to call back a driver hook with the HW lock held.
448 *
449 * \param dev DRM device.
450 * \param func Driver callback.
451 *
452 * This is intended for triggering actions that require the HW lock from an
453 * interrupt handler. The lock will be grabbed ASAP after the interrupt handler
454 * completes. Note that the callback may be called from interrupt or process
455 * context, it must not make any assumptions about this. Also, the HW lock will
456 * be held with the kernel context or any client context.
457 */
458void drm_locked_tasklet(drm_device_t *dev, void (*func)(drm_device_t*))
459{
460 unsigned long irqflags;
461 static DECLARE_TASKLET(drm_tasklet, drm_locked_tasklet_func, 0);
462
463 if (!drm_core_check_feature(dev, DRIVER_HAVE_IRQ) ||
464 test_bit(TASKLET_STATE_SCHED, &drm_tasklet.state))
465 return;
466
467 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
468
469 if (dev->locked_tasklet_func) {
470 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
471 return;
472 }
473
474 dev->locked_tasklet_func = func;
475
476 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
477
478 drm_tasklet.data = (unsigned long)dev;
479
480 tasklet_hi_schedule(&drm_tasklet);
481}
482EXPORT_SYMBOL(drm_locked_tasklet);
diff --git a/drivers/char/drm/drm_lock.c b/drivers/char/drm/drm_lock.c
index f9e45303498d..116ed0f2ac09 100644
--- a/drivers/char/drm/drm_lock.c
+++ b/drivers/char/drm/drm_lock.c
@@ -155,6 +155,7 @@ int drm_unlock(struct inode *inode, struct file *filp,
155 drm_file_t *priv = filp->private_data; 155 drm_file_t *priv = filp->private_data;
156 drm_device_t *dev = priv->head->dev; 156 drm_device_t *dev = priv->head->dev;
157 drm_lock_t lock; 157 drm_lock_t lock;
158 unsigned long irqflags;
158 159
159 if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock))) 160 if (copy_from_user(&lock, (drm_lock_t __user *) arg, sizeof(lock)))
160 return -EFAULT; 161 return -EFAULT;
@@ -165,6 +166,16 @@ int drm_unlock(struct inode *inode, struct file *filp,
165 return -EINVAL; 166 return -EINVAL;
166 } 167 }
167 168
169 spin_lock_irqsave(&dev->tasklet_lock, irqflags);
170
171 if (dev->locked_tasklet_func) {
172 dev->locked_tasklet_func(dev);
173
174 dev->locked_tasklet_func = NULL;
175 }
176
177 spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
178
168 atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]); 179 atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
169 180
170 /* kernel_context_switch isn't used by any of the x86 drm 181 /* kernel_context_switch isn't used by any of the x86 drm
diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c
index 7b1d4e8659ba..5fd6dc0870cf 100644
--- a/drivers/char/drm/drm_stub.c
+++ b/drivers/char/drm/drm_stub.c
@@ -60,6 +60,8 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev,
60 int retcode; 60 int retcode;
61 61
62 spin_lock_init(&dev->count_lock); 62 spin_lock_init(&dev->count_lock);
63 spin_lock_init(&dev->drw_lock);
64 spin_lock_init(&dev->tasklet_lock);
63 init_timer(&dev->timer); 65 init_timer(&dev->timer);
64 mutex_init(&dev->struct_mutex); 66 mutex_init(&dev->struct_mutex);
65 mutex_init(&dev->ctxlist_mutex); 67 mutex_init(&dev->ctxlist_mutex);
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index ae2691942ddb..b9cfc077f6bc 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -473,6 +473,22 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma)
473 } 473 }
474 unlock_kernel(); 474 unlock_kernel();
475 475
476 if (!capable(CAP_SYS_ADMIN) &&
477 (dma->flags & _DRM_DMA_USE_PCI_RO)) {
478 vma->vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
479#if defined(__i386__) || defined(__x86_64__)
480 pgprot_val(vma->vm_page_prot) &= ~_PAGE_RW;
481#else
482 /* Ye gads this is ugly. With more thought
483 we could move this up higher and use
484 `protection_map' instead. */
485 vma->vm_page_prot =
486 __pgprot(pte_val
487 (pte_wrprotect
488 (__pte(pgprot_val(vma->vm_page_prot)))));
489#endif
490 }
491
476 vma->vm_ops = &drm_vm_dma_ops; 492 vma->vm_ops = &drm_vm_dma_ops;
477 493
478 vma->vm_flags |= VM_RESERVED; /* Don't swap */ 494 vma->vm_flags |= VM_RESERVED; /* Don't swap */
diff --git a/drivers/char/drm/i915_dma.c b/drivers/char/drm/i915_dma.c
index fb7913ff5286..9354ce3b0093 100644
--- a/drivers/char/drm/i915_dma.c
+++ b/drivers/char/drm/i915_dma.c
@@ -162,6 +162,7 @@ static int i915_initialize(drm_device_t * dev,
162 162
163 dev_priv->ring.virtual_start = dev_priv->ring.map.handle; 163 dev_priv->ring.virtual_start = dev_priv->ring.map.handle;
164 164
165 dev_priv->cpp = init->cpp;
165 dev_priv->back_offset = init->back_offset; 166 dev_priv->back_offset = init->back_offset;
166 dev_priv->front_offset = init->front_offset; 167 dev_priv->front_offset = init->front_offset;
167 dev_priv->current_page = 0; 168 dev_priv->current_page = 0;
@@ -782,6 +783,7 @@ drm_ioctl_desc_t i915_ioctls[] = {
782 [DRM_IOCTL_NR(DRM_I915_DESTROY_HEAP)] = { i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY }, 783 [DRM_IOCTL_NR(DRM_I915_DESTROY_HEAP)] = { i915_mem_destroy_heap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY },
783 [DRM_IOCTL_NR(DRM_I915_SET_VBLANK_PIPE)] = { i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY }, 784 [DRM_IOCTL_NR(DRM_I915_SET_VBLANK_PIPE)] = { i915_vblank_pipe_set, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY },
784 [DRM_IOCTL_NR(DRM_I915_GET_VBLANK_PIPE)] = { i915_vblank_pipe_get, DRM_AUTH }, 785 [DRM_IOCTL_NR(DRM_I915_GET_VBLANK_PIPE)] = { i915_vblank_pipe_get, DRM_AUTH },
786 [DRM_IOCTL_NR(DRM_I915_VBLANK_SWAP)] = {i915_vblank_swap, DRM_AUTH},
785}; 787};
786 788
787int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); 789int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls);
diff --git a/drivers/char/drm/i915_drm.h b/drivers/char/drm/i915_drm.h
index 6af83e613f27..96a468886a7a 100644
--- a/drivers/char/drm/i915_drm.h
+++ b/drivers/char/drm/i915_drm.h
@@ -104,6 +104,15 @@ typedef struct _drm_i915_sarea {
104 unsigned int depth_tiled; 104 unsigned int depth_tiled;
105 unsigned int rotated_tiled; 105 unsigned int rotated_tiled;
106 unsigned int rotated2_tiled; 106 unsigned int rotated2_tiled;
107
108 int pipeA_x;
109 int pipeA_y;
110 int pipeA_w;
111 int pipeA_h;
112 int pipeB_x;
113 int pipeB_y;
114 int pipeB_w;
115 int pipeB_h;
107} drm_i915_sarea_t; 116} drm_i915_sarea_t;
108 117
109/* Flags for perf_boxes 118/* Flags for perf_boxes
@@ -132,6 +141,7 @@ typedef struct _drm_i915_sarea {
132#define DRM_I915_DESTROY_HEAP 0x0c 141#define DRM_I915_DESTROY_HEAP 0x0c
133#define DRM_I915_SET_VBLANK_PIPE 0x0d 142#define DRM_I915_SET_VBLANK_PIPE 0x0d
134#define DRM_I915_GET_VBLANK_PIPE 0x0e 143#define DRM_I915_GET_VBLANK_PIPE 0x0e
144#define DRM_I915_VBLANK_SWAP 0x0f
135 145
136#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t) 146#define DRM_IOCTL_I915_INIT DRM_IOW( DRM_COMMAND_BASE + DRM_I915_INIT, drm_i915_init_t)
137#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH) 147#define DRM_IOCTL_I915_FLUSH DRM_IO ( DRM_COMMAND_BASE + DRM_I915_FLUSH)
@@ -148,6 +158,7 @@ typedef struct _drm_i915_sarea {
148#define DRM_IOCTL_I915_DESTROY_HEAP DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t) 158#define DRM_IOCTL_I915_DESTROY_HEAP DRM_IOW( DRM_COMMAND_BASE + DRM_I915_DESTROY_HEAP, drm_i915_mem_destroy_heap_t)
149#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t) 159#define DRM_IOCTL_I915_SET_VBLANK_PIPE DRM_IOW( DRM_COMMAND_BASE + DRM_I915_SET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
150#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t) 160#define DRM_IOCTL_I915_GET_VBLANK_PIPE DRM_IOR( DRM_COMMAND_BASE + DRM_I915_GET_VBLANK_PIPE, drm_i915_vblank_pipe_t)
161#define DRM_IOCTL_I915_VBLANK_SWAP DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_VBLANK_SWAP, drm_i915_vblank_swap_t)
151 162
152/* Allow drivers to submit batchbuffers directly to hardware, relying 163/* Allow drivers to submit batchbuffers directly to hardware, relying
153 * on the security mechanisms provided by hardware. 164 * on the security mechanisms provided by hardware.
@@ -243,4 +254,12 @@ typedef struct drm_i915_vblank_pipe {
243 int pipe; 254 int pipe;
244} drm_i915_vblank_pipe_t; 255} drm_i915_vblank_pipe_t;
245 256
257/* Schedule buffer swap at given vertical blank:
258 */
259typedef struct drm_i915_vblank_swap {
260 drm_drawable_t drawable;
261 drm_vblank_seq_type_t seqtype;
262 unsigned int sequence;
263} drm_i915_vblank_swap_t;
264
246#endif /* _I915_DRM_H_ */ 265#endif /* _I915_DRM_H_ */
diff --git a/drivers/char/drm/i915_drv.c b/drivers/char/drm/i915_drv.c
index 8e2e6095c4b3..85bcc276f804 100644
--- a/drivers/char/drm/i915_drv.c
+++ b/drivers/char/drm/i915_drv.c
@@ -44,12 +44,14 @@ static struct drm_driver driver = {
44 */ 44 */
45 .driver_features = 45 .driver_features =
46 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/ 46 DRIVER_USE_AGP | DRIVER_REQUIRE_AGP | /* DRIVER_USE_MTRR |*/
47 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL, 47 DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_IRQ_VBL |
48 DRIVER_IRQ_VBL2,
48 .load = i915_driver_load, 49 .load = i915_driver_load,
49 .lastclose = i915_driver_lastclose, 50 .lastclose = i915_driver_lastclose,
50 .preclose = i915_driver_preclose, 51 .preclose = i915_driver_preclose,
51 .device_is_agp = i915_driver_device_is_agp, 52 .device_is_agp = i915_driver_device_is_agp,
52 .vblank_wait = i915_driver_vblank_wait, 53 .vblank_wait = i915_driver_vblank_wait,
54 .vblank_wait2 = i915_driver_vblank_wait2,
53 .irq_preinstall = i915_driver_irq_preinstall, 55 .irq_preinstall = i915_driver_irq_preinstall,
54 .irq_postinstall = i915_driver_irq_postinstall, 56 .irq_postinstall = i915_driver_irq_postinstall,
55 .irq_uninstall = i915_driver_irq_uninstall, 57 .irq_uninstall = i915_driver_irq_uninstall,
diff --git a/drivers/char/drm/i915_drv.h b/drivers/char/drm/i915_drv.h
index fdc2bf192714..93cdcfe6aa84 100644
--- a/drivers/char/drm/i915_drv.h
+++ b/drivers/char/drm/i915_drv.h
@@ -46,9 +46,11 @@
46 * 1.3: Add vblank support 46 * 1.3: Add vblank support
47 * 1.4: Fix cmdbuffer path, add heap destroy 47 * 1.4: Fix cmdbuffer path, add heap destroy
48 * 1.5: Add vblank pipe configuration 48 * 1.5: Add vblank pipe configuration
49 * 1.6: - New ioctl for scheduling buffer swaps on vertical blank
50 * - Support vertical blank on secondary display pipe
49 */ 51 */
50#define DRIVER_MAJOR 1 52#define DRIVER_MAJOR 1
51#define DRIVER_MINOR 5 53#define DRIVER_MINOR 6
52#define DRIVER_PATCHLEVEL 0 54#define DRIVER_PATCHLEVEL 0
53 55
54typedef struct _drm_i915_ring_buffer { 56typedef struct _drm_i915_ring_buffer {
@@ -71,6 +73,13 @@ struct mem_block {
71 DRMFILE filp; /* 0: free, -1: heap, other: real files */ 73 DRMFILE filp; /* 0: free, -1: heap, other: real files */
72}; 74};
73 75
76typedef struct _drm_i915_vbl_swap {
77 struct list_head head;
78 drm_drawable_t drw_id;
79 unsigned int pipe;
80 unsigned int sequence;
81} drm_i915_vbl_swap_t;
82
74typedef struct drm_i915_private { 83typedef struct drm_i915_private {
75 drm_local_map_t *sarea; 84 drm_local_map_t *sarea;
76 drm_local_map_t *mmio_map; 85 drm_local_map_t *mmio_map;
@@ -83,6 +92,7 @@ typedef struct drm_i915_private {
83 dma_addr_t dma_status_page; 92 dma_addr_t dma_status_page;
84 unsigned long counter; 93 unsigned long counter;
85 94
95 unsigned int cpp;
86 int back_offset; 96 int back_offset;
87 int front_offset; 97 int front_offset;
88 int current_page; 98 int current_page;
@@ -98,6 +108,10 @@ typedef struct drm_i915_private {
98 struct mem_block *agp_heap; 108 struct mem_block *agp_heap;
99 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds; 109 unsigned int sr01, adpa, ppcr, dvob, dvoc, lvds;
100 int vblank_pipe; 110 int vblank_pipe;
111
112 spinlock_t swaps_lock;
113 drm_i915_vbl_swap_t vbl_swaps;
114 unsigned int swaps_pending;
101} drm_i915_private_t; 115} drm_i915_private_t;
102 116
103extern drm_ioctl_desc_t i915_ioctls[]; 117extern drm_ioctl_desc_t i915_ioctls[];
@@ -117,12 +131,14 @@ extern int i915_irq_emit(DRM_IOCTL_ARGS);
117extern int i915_irq_wait(DRM_IOCTL_ARGS); 131extern int i915_irq_wait(DRM_IOCTL_ARGS);
118 132
119extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence); 133extern int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence);
134extern int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence);
120extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS); 135extern irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS);
121extern void i915_driver_irq_preinstall(drm_device_t * dev); 136extern void i915_driver_irq_preinstall(drm_device_t * dev);
122extern void i915_driver_irq_postinstall(drm_device_t * dev); 137extern void i915_driver_irq_postinstall(drm_device_t * dev);
123extern void i915_driver_irq_uninstall(drm_device_t * dev); 138extern void i915_driver_irq_uninstall(drm_device_t * dev);
124extern int i915_vblank_pipe_set(DRM_IOCTL_ARGS); 139extern int i915_vblank_pipe_set(DRM_IOCTL_ARGS);
125extern int i915_vblank_pipe_get(DRM_IOCTL_ARGS); 140extern int i915_vblank_pipe_get(DRM_IOCTL_ARGS);
141extern int i915_vblank_swap(DRM_IOCTL_ARGS);
126 142
127/* i915_mem.c */ 143/* i915_mem.c */
128extern int i915_mem_alloc(DRM_IOCTL_ARGS); 144extern int i915_mem_alloc(DRM_IOCTL_ARGS);
@@ -256,6 +272,10 @@ extern int i915_wait_ring(drm_device_t * dev, int n, const char *caller);
256 272
257#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2) 273#define GFX_OP_DRAWRECT_INFO_I965 ((0x7900<<16)|0x2)
258 274
275#define XY_SRC_COPY_BLT_CMD ((2<<29)|(0x53<<22)|6)
276#define XY_SRC_COPY_BLT_WRITE_ALPHA (1<<21)
277#define XY_SRC_COPY_BLT_WRITE_RGB (1<<20)
278
259#define MI_BATCH_BUFFER ((0x30<<23)|1) 279#define MI_BATCH_BUFFER ((0x30<<23)|1)
260#define MI_BATCH_BUFFER_START (0x31<<23) 280#define MI_BATCH_BUFFER_START (0x31<<23)
261#define MI_BATCH_BUFFER_END (0xA<<23) 281#define MI_BATCH_BUFFER_END (0xA<<23)
diff --git a/drivers/char/drm/i915_ioc32.c b/drivers/char/drm/i915_ioc32.c
index 296248cdc767..1fe68a251b75 100644
--- a/drivers/char/drm/i915_ioc32.c
+++ b/drivers/char/drm/i915_ioc32.c
@@ -66,7 +66,7 @@ static int compat_i915_batchbuffer(struct file *file, unsigned int cmd,
66 &batchbuffer->cliprects)) 66 &batchbuffer->cliprects))
67 return -EFAULT; 67 return -EFAULT;
68 68
69 return drm_ioctl(file->f_dentry->d_inode, file, 69 return drm_ioctl(file->f_path.dentry->d_inode, file,
70 DRM_IOCTL_I915_BATCHBUFFER, 70 DRM_IOCTL_I915_BATCHBUFFER,
71 (unsigned long)batchbuffer); 71 (unsigned long)batchbuffer);
72} 72}
@@ -102,7 +102,7 @@ static int compat_i915_cmdbuffer(struct file *file, unsigned int cmd,
102 &cmdbuffer->cliprects)) 102 &cmdbuffer->cliprects))
103 return -EFAULT; 103 return -EFAULT;
104 104
105 return drm_ioctl(file->f_dentry->d_inode, file, 105 return drm_ioctl(file->f_path.dentry->d_inode, file,
106 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer); 106 DRM_IOCTL_I915_CMDBUFFER, (unsigned long)cmdbuffer);
107} 107}
108 108
@@ -125,7 +125,7 @@ static int compat_i915_irq_emit(struct file *file, unsigned int cmd,
125 &request->irq_seq)) 125 &request->irq_seq))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request); 129 DRM_IOCTL_I915_IRQ_EMIT, (unsigned long)request);
130} 130}
131typedef struct drm_i915_getparam32 { 131typedef struct drm_i915_getparam32 {
@@ -149,7 +149,7 @@ static int compat_i915_getparam(struct file *file, unsigned int cmd,
149 &request->value)) 149 &request->value))
150 return -EFAULT; 150 return -EFAULT;
151 151
152 return drm_ioctl(file->f_dentry->d_inode, file, 152 return drm_ioctl(file->f_path.dentry->d_inode, file,
153 DRM_IOCTL_I915_GETPARAM, (unsigned long)request); 153 DRM_IOCTL_I915_GETPARAM, (unsigned long)request);
154} 154}
155 155
@@ -178,7 +178,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
178 &request->region_offset)) 178 &request->region_offset))
179 return -EFAULT; 179 return -EFAULT;
180 180
181 return drm_ioctl(file->f_dentry->d_inode, file, 181 return drm_ioctl(file->f_path.dentry->d_inode, file,
182 DRM_IOCTL_I915_ALLOC, (unsigned long)request); 182 DRM_IOCTL_I915_ALLOC, (unsigned long)request);
183} 183}
184 184
@@ -215,7 +215,7 @@ long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
215 if (fn != NULL) 215 if (fn != NULL)
216 ret = (*fn) (filp, cmd, arg); 216 ret = (*fn) (filp, cmd, arg);
217 else 217 else
218 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 218 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
219 unlock_kernel(); 219 unlock_kernel();
220 220
221 return ret; 221 return ret;
diff --git a/drivers/char/drm/i915_irq.c b/drivers/char/drm/i915_irq.c
index 0d4a162aa385..e5463b111fc0 100644
--- a/drivers/char/drm/i915_irq.c
+++ b/drivers/char/drm/i915_irq.c
@@ -37,6 +37,99 @@
37 37
38#define MAX_NOPID ((u32)~0) 38#define MAX_NOPID ((u32)~0)
39 39
40/**
41 * Emit blits for scheduled buffer swaps.
42 *
43 * This function will be called with the HW lock held.
44 */
45static void i915_vblank_tasklet(drm_device_t *dev)
46{
47 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
48 unsigned long irqflags;
49 struct list_head *list, *tmp;
50
51 DRM_DEBUG("\n");
52
53 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
54
55 list_for_each_safe(list, tmp, &dev_priv->vbl_swaps.head) {
56 drm_i915_vbl_swap_t *vbl_swap =
57 list_entry(list, drm_i915_vbl_swap_t, head);
58 atomic_t *counter = vbl_swap->pipe ? &dev->vbl_received2 :
59 &dev->vbl_received;
60
61 if ((atomic_read(counter) - vbl_swap->sequence) <= (1<<23)) {
62 drm_drawable_info_t *drw;
63
64 spin_unlock(&dev_priv->swaps_lock);
65
66 spin_lock(&dev->drw_lock);
67
68 drw = drm_get_drawable_info(dev, vbl_swap->drw_id);
69
70 if (drw) {
71 int i, num_rects = drw->num_rects;
72 drm_clip_rect_t *rect = drw->rects;
73 drm_i915_sarea_t *sarea_priv =
74 dev_priv->sarea_priv;
75 u32 cpp = dev_priv->cpp;
76 u32 cmd = (cpp == 4) ? (XY_SRC_COPY_BLT_CMD |
77 XY_SRC_COPY_BLT_WRITE_ALPHA |
78 XY_SRC_COPY_BLT_WRITE_RGB)
79 : XY_SRC_COPY_BLT_CMD;
80 u32 pitchropcpp = (sarea_priv->pitch * cpp) |
81 (0xcc << 16) | (cpp << 23) |
82 (1 << 24);
83 RING_LOCALS;
84
85 i915_kernel_lost_context(dev);
86
87 BEGIN_LP_RING(6);
88
89 OUT_RING(GFX_OP_DRAWRECT_INFO);
90 OUT_RING(0);
91 OUT_RING(0);
92 OUT_RING(sarea_priv->width |
93 sarea_priv->height << 16);
94 OUT_RING(sarea_priv->width |
95 sarea_priv->height << 16);
96 OUT_RING(0);
97
98 ADVANCE_LP_RING();
99
100 sarea_priv->ctxOwner = DRM_KERNEL_CONTEXT;
101
102 for (i = 0; i < num_rects; i++, rect++) {
103 BEGIN_LP_RING(8);
104
105 OUT_RING(cmd);
106 OUT_RING(pitchropcpp);
107 OUT_RING((rect->y1 << 16) | rect->x1);
108 OUT_RING((rect->y2 << 16) | rect->x2);
109 OUT_RING(sarea_priv->front_offset);
110 OUT_RING((rect->y1 << 16) | rect->x1);
111 OUT_RING(pitchropcpp & 0xffff);
112 OUT_RING(sarea_priv->back_offset);
113
114 ADVANCE_LP_RING();
115 }
116 }
117
118 spin_unlock(&dev->drw_lock);
119
120 spin_lock(&dev_priv->swaps_lock);
121
122 list_del(list);
123
124 drm_free(vbl_swap, sizeof(*vbl_swap), DRM_MEM_DRIVER);
125
126 dev_priv->swaps_pending--;
127 }
128 }
129
130 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
131}
132
40irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) 133irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
41{ 134{
42 drm_device_t *dev = (drm_device_t *) arg; 135 drm_device_t *dev = (drm_device_t *) arg;
@@ -60,9 +153,26 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
60 DRM_WAKEUP(&dev_priv->irq_queue); 153 DRM_WAKEUP(&dev_priv->irq_queue);
61 154
62 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) { 155 if (temp & (VSYNC_PIPEA_FLAG | VSYNC_PIPEB_FLAG)) {
63 atomic_inc(&dev->vbl_received); 156 int vblank_pipe = dev_priv->vblank_pipe;
157
158 if ((vblank_pipe &
159 (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B))
160 == (DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B)) {
161 if (temp & VSYNC_PIPEA_FLAG)
162 atomic_inc(&dev->vbl_received);
163 if (temp & VSYNC_PIPEB_FLAG)
164 atomic_inc(&dev->vbl_received2);
165 } else if (((temp & VSYNC_PIPEA_FLAG) &&
166 (vblank_pipe & DRM_I915_VBLANK_PIPE_A)) ||
167 ((temp & VSYNC_PIPEB_FLAG) &&
168 (vblank_pipe & DRM_I915_VBLANK_PIPE_B)))
169 atomic_inc(&dev->vbl_received);
170
64 DRM_WAKEUP(&dev->vbl_queue); 171 DRM_WAKEUP(&dev->vbl_queue);
65 drm_vbl_send_signals(dev); 172 drm_vbl_send_signals(dev);
173
174 if (dev_priv->swaps_pending > 0)
175 drm_locked_tasklet(dev, i915_vblank_tasklet);
66 } 176 }
67 177
68 return IRQ_HANDLED; 178 return IRQ_HANDLED;
@@ -120,7 +230,8 @@ static int i915_wait_irq(drm_device_t * dev, int irq_nr)
120 return ret; 230 return ret;
121} 231}
122 232
123int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence) 233static int i915_driver_vblank_do_wait(drm_device_t *dev, unsigned int *sequence,
234 atomic_t *counter)
124{ 235{
125 drm_i915_private_t *dev_priv = dev->dev_private; 236 drm_i915_private_t *dev_priv = dev->dev_private;
126 unsigned int cur_vblank; 237 unsigned int cur_vblank;
@@ -132,7 +243,7 @@ int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
132 } 243 }
133 244
134 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ, 245 DRM_WAIT_ON(ret, dev->vbl_queue, 3 * DRM_HZ,
135 (((cur_vblank = atomic_read(&dev->vbl_received)) 246 (((cur_vblank = atomic_read(counter))
136 - *sequence) <= (1<<23))); 247 - *sequence) <= (1<<23)));
137 248
138 *sequence = cur_vblank; 249 *sequence = cur_vblank;
@@ -141,6 +252,16 @@ int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
141} 252}
142 253
143 254
255int i915_driver_vblank_wait(drm_device_t *dev, unsigned int *sequence)
256{
257 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received);
258}
259
260int i915_driver_vblank_wait2(drm_device_t *dev, unsigned int *sequence)
261{
262 return i915_driver_vblank_do_wait(dev, sequence, &dev->vbl_received2);
263}
264
144/* Needs the lock as it touches the ring. 265/* Needs the lock as it touches the ring.
145 */ 266 */
146int i915_irq_emit(DRM_IOCTL_ARGS) 267int i915_irq_emit(DRM_IOCTL_ARGS)
@@ -189,7 +310,7 @@ int i915_irq_wait(DRM_IOCTL_ARGS)
189 return i915_wait_irq(dev, irqwait.irq_seq); 310 return i915_wait_irq(dev, irqwait.irq_seq);
190} 311}
191 312
192static int i915_enable_interrupt (drm_device_t *dev) 313static void i915_enable_interrupt (drm_device_t *dev)
193{ 314{
194 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 315 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
195 u16 flag; 316 u16 flag;
@@ -199,13 +320,8 @@ static int i915_enable_interrupt (drm_device_t *dev)
199 flag |= VSYNC_PIPEA_FLAG; 320 flag |= VSYNC_PIPEA_FLAG;
200 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B) 321 if (dev_priv->vblank_pipe & DRM_I915_VBLANK_PIPE_B)
201 flag |= VSYNC_PIPEB_FLAG; 322 flag |= VSYNC_PIPEB_FLAG;
202 if (dev_priv->vblank_pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) { 323
203 DRM_ERROR("%s called with invalid pipe 0x%x\n",
204 __FUNCTION__, dev_priv->vblank_pipe);
205 return DRM_ERR(EINVAL);
206 }
207 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag); 324 I915_WRITE16(I915REG_INT_ENABLE_R, USER_INT_FLAG | flag);
208 return 0;
209} 325}
210 326
211/* Set the vblank monitor pipe 327/* Set the vblank monitor pipe
@@ -224,8 +340,17 @@ int i915_vblank_pipe_set(DRM_IOCTL_ARGS)
224 DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data, 340 DRM_COPY_FROM_USER_IOCTL(pipe, (drm_i915_vblank_pipe_t __user *) data,
225 sizeof(pipe)); 341 sizeof(pipe));
226 342
343 if (pipe.pipe & ~(DRM_I915_VBLANK_PIPE_A|DRM_I915_VBLANK_PIPE_B)) {
344 DRM_ERROR("%s called with invalid pipe 0x%x\n",
345 __FUNCTION__, pipe.pipe);
346 return DRM_ERR(EINVAL);
347 }
348
227 dev_priv->vblank_pipe = pipe.pipe; 349 dev_priv->vblank_pipe = pipe.pipe;
228 return i915_enable_interrupt (dev); 350
351 i915_enable_interrupt (dev);
352
353 return 0;
229} 354}
230 355
231int i915_vblank_pipe_get(DRM_IOCTL_ARGS) 356int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
@@ -251,6 +376,118 @@ int i915_vblank_pipe_get(DRM_IOCTL_ARGS)
251 return 0; 376 return 0;
252} 377}
253 378
379/**
380 * Schedule buffer swap at given vertical blank.
381 */
382int i915_vblank_swap(DRM_IOCTL_ARGS)
383{
384 DRM_DEVICE;
385 drm_i915_private_t *dev_priv = dev->dev_private;
386 drm_i915_vblank_swap_t swap;
387 drm_i915_vbl_swap_t *vbl_swap;
388 unsigned int pipe, seqtype, curseq;
389 unsigned long irqflags;
390 struct list_head *list;
391
392 if (!dev_priv) {
393 DRM_ERROR("%s called with no initialization\n", __func__);
394 return DRM_ERR(EINVAL);
395 }
396
397 if (dev_priv->sarea_priv->rotation) {
398 DRM_DEBUG("Rotation not supported\n");
399 return DRM_ERR(EINVAL);
400 }
401
402 DRM_COPY_FROM_USER_IOCTL(swap, (drm_i915_vblank_swap_t __user *) data,
403 sizeof(swap));
404
405 if (swap.seqtype & ~(_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE |
406 _DRM_VBLANK_SECONDARY | _DRM_VBLANK_NEXTONMISS)) {
407 DRM_ERROR("Invalid sequence type 0x%x\n", swap.seqtype);
408 return DRM_ERR(EINVAL);
409 }
410
411 pipe = (swap.seqtype & _DRM_VBLANK_SECONDARY) ? 1 : 0;
412
413 seqtype = swap.seqtype & (_DRM_VBLANK_RELATIVE | _DRM_VBLANK_ABSOLUTE);
414
415 if (!(dev_priv->vblank_pipe & (1 << pipe))) {
416 DRM_ERROR("Invalid pipe %d\n", pipe);
417 return DRM_ERR(EINVAL);
418 }
419
420 spin_lock_irqsave(&dev->drw_lock, irqflags);
421
422 if (!drm_get_drawable_info(dev, swap.drawable)) {
423 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
424 DRM_ERROR("Invalid drawable ID %d\n", swap.drawable);
425 return DRM_ERR(EINVAL);
426 }
427
428 spin_unlock_irqrestore(&dev->drw_lock, irqflags);
429
430 curseq = atomic_read(pipe ? &dev->vbl_received2 : &dev->vbl_received);
431
432 if (seqtype == _DRM_VBLANK_RELATIVE)
433 swap.sequence += curseq;
434
435 if ((curseq - swap.sequence) <= (1<<23)) {
436 if (swap.seqtype & _DRM_VBLANK_NEXTONMISS) {
437 swap.sequence = curseq + 1;
438 } else {
439 DRM_DEBUG("Missed target sequence\n");
440 return DRM_ERR(EINVAL);
441 }
442 }
443
444 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
445
446 list_for_each(list, &dev_priv->vbl_swaps.head) {
447 vbl_swap = list_entry(list, drm_i915_vbl_swap_t, head);
448
449 if (vbl_swap->drw_id == swap.drawable &&
450 vbl_swap->pipe == pipe &&
451 vbl_swap->sequence == swap.sequence) {
452 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
453 DRM_DEBUG("Already scheduled\n");
454 return 0;
455 }
456 }
457
458 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
459
460 if (dev_priv->swaps_pending >= 100) {
461 DRM_DEBUG("Too many swaps queued\n");
462 return DRM_ERR(EBUSY);
463 }
464
465 vbl_swap = drm_calloc(1, sizeof(vbl_swap), DRM_MEM_DRIVER);
466
467 if (!vbl_swap) {
468 DRM_ERROR("Failed to allocate memory to queue swap\n");
469 return DRM_ERR(ENOMEM);
470 }
471
472 DRM_DEBUG("\n");
473
474 vbl_swap->drw_id = swap.drawable;
475 vbl_swap->pipe = pipe;
476 vbl_swap->sequence = swap.sequence;
477
478 spin_lock_irqsave(&dev_priv->swaps_lock, irqflags);
479
480 list_add_tail((struct list_head *)vbl_swap, &dev_priv->vbl_swaps.head);
481 dev_priv->swaps_pending++;
482
483 spin_unlock_irqrestore(&dev_priv->swaps_lock, irqflags);
484
485 DRM_COPY_TO_USER_IOCTL((drm_i915_vblank_swap_t __user *) data, swap,
486 sizeof(swap));
487
488 return 0;
489}
490
254/* drm_dma.h hooks 491/* drm_dma.h hooks
255*/ 492*/
256void i915_driver_irq_preinstall(drm_device_t * dev) 493void i915_driver_irq_preinstall(drm_device_t * dev)
@@ -266,6 +503,12 @@ void i915_driver_irq_postinstall(drm_device_t * dev)
266{ 503{
267 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; 504 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
268 505
506 dev_priv->swaps_lock = SPIN_LOCK_UNLOCKED;
507 INIT_LIST_HEAD(&dev_priv->vbl_swaps.head);
508 dev_priv->swaps_pending = 0;
509
510 if (!dev_priv->vblank_pipe)
511 dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A;
269 i915_enable_interrupt(dev); 512 i915_enable_interrupt(dev);
270 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue); 513 DRM_INIT_WAITQUEUE(&dev_priv->irq_queue);
271} 514}
diff --git a/drivers/char/drm/mga_ioc32.c b/drivers/char/drm/mga_ioc32.c
index 54a18eb2fc04..30d00478ddee 100644
--- a/drivers/char/drm/mga_ioc32.c
+++ b/drivers/char/drm/mga_ioc32.c
@@ -100,7 +100,7 @@ static int compat_mga_init(struct file *file, unsigned int cmd,
100 if (err) 100 if (err)
101 return -EFAULT; 101 return -EFAULT;
102 102
103 return drm_ioctl(file->f_dentry->d_inode, file, 103 return drm_ioctl(file->f_path.dentry->d_inode, file,
104 DRM_IOCTL_MGA_INIT, (unsigned long)init); 104 DRM_IOCTL_MGA_INIT, (unsigned long)init);
105} 105}
106 106
@@ -125,7 +125,7 @@ static int compat_mga_getparam(struct file *file, unsigned int cmd,
125 &getparam->value)) 125 &getparam->value))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam); 129 DRM_IOCTL_MGA_GETPARAM, (unsigned long)getparam);
130} 130}
131 131
@@ -166,7 +166,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
166 || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size)) 166 || __put_user(dma_bootstrap32.agp_size, &dma_bootstrap->agp_size))
167 return -EFAULT; 167 return -EFAULT;
168 168
169 err = drm_ioctl(file->f_dentry->d_inode, file, 169 err = drm_ioctl(file->f_path.dentry->d_inode, file,
170 DRM_IOCTL_MGA_DMA_BOOTSTRAP, 170 DRM_IOCTL_MGA_DMA_BOOTSTRAP,
171 (unsigned long)dma_bootstrap); 171 (unsigned long)dma_bootstrap);
172 if (err) 172 if (err)
@@ -224,7 +224,7 @@ long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
224 if (fn != NULL) 224 if (fn != NULL)
225 ret = (*fn) (filp, cmd, arg); 225 ret = (*fn) (filp, cmd, arg);
226 else 226 else
227 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 227 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
228 unlock_kernel(); 228 unlock_kernel();
229 229
230 return ret; 230 return ret;
diff --git a/drivers/char/drm/r128_ioc32.c b/drivers/char/drm/r128_ioc32.c
index 9dd6d4116e47..d3cb676eee84 100644
--- a/drivers/char/drm/r128_ioc32.c
+++ b/drivers/char/drm/r128_ioc32.c
@@ -95,7 +95,7 @@ static int compat_r128_init(struct file *file, unsigned int cmd,
95 &init->agp_textures_offset)) 95 &init->agp_textures_offset))
96 return -EFAULT; 96 return -EFAULT;
97 97
98 return drm_ioctl(file->f_dentry->d_inode, file, 98 return drm_ioctl(file->f_path.dentry->d_inode, file,
99 DRM_IOCTL_R128_INIT, (unsigned long)init); 99 DRM_IOCTL_R128_INIT, (unsigned long)init);
100} 100}
101 101
@@ -129,7 +129,7 @@ static int compat_r128_depth(struct file *file, unsigned int cmd,
129 &depth->mask)) 129 &depth->mask))
130 return -EFAULT; 130 return -EFAULT;
131 131
132 return drm_ioctl(file->f_dentry->d_inode, file, 132 return drm_ioctl(file->f_path.dentry->d_inode, file,
133 DRM_IOCTL_R128_DEPTH, (unsigned long)depth); 133 DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
134 134
135} 135}
@@ -153,7 +153,7 @@ static int compat_r128_stipple(struct file *file, unsigned int cmd,
153 &stipple->mask)) 153 &stipple->mask))
154 return -EFAULT; 154 return -EFAULT;
155 155
156 return drm_ioctl(file->f_dentry->d_inode, file, 156 return drm_ioctl(file->f_path.dentry->d_inode, file,
157 DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple); 157 DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
158} 158}
159 159
@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
178 &getparam->value)) 178 &getparam->value))
179 return -EFAULT; 179 return -EFAULT;
180 180
181 return drm_ioctl(file->f_dentry->d_inode, file, 181 return drm_ioctl(file->f_path.dentry->d_inode, file,
182 DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam); 182 DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
183} 183}
184 184
@@ -214,7 +214,7 @@ long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
214 if (fn != NULL) 214 if (fn != NULL)
215 ret = (*fn) (filp, cmd, arg); 215 ret = (*fn) (filp, cmd, arg);
216 else 216 else
217 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 217 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
218 unlock_kernel(); 218 unlock_kernel();
219 219
220 return ret; 220 return ret;
diff --git a/drivers/char/drm/radeon_ioc32.c b/drivers/char/drm/radeon_ioc32.c
index 0ccfd3618ff1..1f1f9cc055a4 100644
--- a/drivers/char/drm/radeon_ioc32.c
+++ b/drivers/char/drm/radeon_ioc32.c
@@ -92,7 +92,7 @@ static int compat_radeon_cp_init(struct file *file, unsigned int cmd,
92 &init->gart_textures_offset)) 92 &init->gart_textures_offset))
93 return -EFAULT; 93 return -EFAULT;
94 94
95 return drm_ioctl(file->f_dentry->d_inode, file, 95 return drm_ioctl(file->f_path.dentry->d_inode, file,
96 DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init); 96 DRM_IOCTL_RADEON_CP_INIT, (unsigned long)init);
97} 97}
98 98
@@ -125,7 +125,7 @@ static int compat_radeon_cp_clear(struct file *file, unsigned int cmd,
125 &clr->depth_boxes)) 125 &clr->depth_boxes))
126 return -EFAULT; 126 return -EFAULT;
127 127
128 return drm_ioctl(file->f_dentry->d_inode, file, 128 return drm_ioctl(file->f_path.dentry->d_inode, file,
129 DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr); 129 DRM_IOCTL_RADEON_CLEAR, (unsigned long)clr);
130} 130}
131 131
@@ -149,7 +149,7 @@ static int compat_radeon_cp_stipple(struct file *file, unsigned int cmd,
149 &request->mask)) 149 &request->mask))
150 return -EFAULT; 150 return -EFAULT;
151 151
152 return drm_ioctl(file->f_dentry->d_inode, file, 152 return drm_ioctl(file->f_path.dentry->d_inode, file,
153 DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request); 153 DRM_IOCTL_RADEON_STIPPLE, (unsigned long)request);
154} 154}
155 155
@@ -204,7 +204,7 @@ static int compat_radeon_cp_texture(struct file *file, unsigned int cmd,
204 &image->data)) 204 &image->data))
205 return -EFAULT; 205 return -EFAULT;
206 206
207 return drm_ioctl(file->f_dentry->d_inode, file, 207 return drm_ioctl(file->f_path.dentry->d_inode, file,
208 DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request); 208 DRM_IOCTL_RADEON_TEXTURE, (unsigned long)request);
209} 209}
210 210
@@ -238,7 +238,7 @@ static int compat_radeon_cp_vertex2(struct file *file, unsigned int cmd,
238 &request->prim)) 238 &request->prim))
239 return -EFAULT; 239 return -EFAULT;
240 240
241 return drm_ioctl(file->f_dentry->d_inode, file, 241 return drm_ioctl(file->f_path.dentry->d_inode, file,
242 DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request); 242 DRM_IOCTL_RADEON_VERTEX2, (unsigned long)request);
243} 243}
244 244
@@ -268,7 +268,7 @@ static int compat_radeon_cp_cmdbuf(struct file *file, unsigned int cmd,
268 &request->boxes)) 268 &request->boxes))
269 return -EFAULT; 269 return -EFAULT;
270 270
271 return drm_ioctl(file->f_dentry->d_inode, file, 271 return drm_ioctl(file->f_path.dentry->d_inode, file,
272 DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request); 272 DRM_IOCTL_RADEON_CMDBUF, (unsigned long)request);
273} 273}
274 274
@@ -293,7 +293,7 @@ static int compat_radeon_cp_getparam(struct file *file, unsigned int cmd,
293 &request->value)) 293 &request->value))
294 return -EFAULT; 294 return -EFAULT;
295 295
296 return drm_ioctl(file->f_dentry->d_inode, file, 296 return drm_ioctl(file->f_path.dentry->d_inode, file,
297 DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request); 297 DRM_IOCTL_RADEON_GETPARAM, (unsigned long)request);
298} 298}
299 299
@@ -322,7 +322,7 @@ static int compat_radeon_mem_alloc(struct file *file, unsigned int cmd,
322 &request->region_offset)) 322 &request->region_offset))
323 return -EFAULT; 323 return -EFAULT;
324 324
325 return drm_ioctl(file->f_dentry->d_inode, file, 325 return drm_ioctl(file->f_path.dentry->d_inode, file,
326 DRM_IOCTL_RADEON_ALLOC, (unsigned long)request); 326 DRM_IOCTL_RADEON_ALLOC, (unsigned long)request);
327} 327}
328 328
@@ -345,7 +345,7 @@ static int compat_radeon_irq_emit(struct file *file, unsigned int cmd,
345 &request->irq_seq)) 345 &request->irq_seq))
346 return -EFAULT; 346 return -EFAULT;
347 347
348 return drm_ioctl(file->f_dentry->d_inode, file, 348 return drm_ioctl(file->f_path.dentry->d_inode, file,
349 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request); 349 DRM_IOCTL_RADEON_IRQ_EMIT, (unsigned long)request);
350} 350}
351 351
@@ -386,7 +386,7 @@ long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
386 if (fn != NULL) 386 if (fn != NULL)
387 ret = (*fn) (filp, cmd, arg); 387 ret = (*fn) (filp, cmd, arg);
388 else 388 else
389 ret = drm_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 389 ret = drm_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
390 unlock_kernel(); 390 unlock_kernel();
391 391
392 return ret; 392 return ret;
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index 9b1bf60ffbe7..06f2dbf17710 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -201,7 +201,7 @@ static int dsp56k_upload(u_char __user *bin, int len)
201static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count, 201static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
202 loff_t *ppos) 202 loff_t *ppos)
203{ 203{
204 struct inode *inode = file->f_dentry->d_inode; 204 struct inode *inode = file->f_path.dentry->d_inode;
205 int dev = iminor(inode) & 0x0f; 205 int dev = iminor(inode) & 0x0f;
206 206
207 switch(dev) 207 switch(dev)
@@ -264,7 +264,7 @@ static ssize_t dsp56k_read(struct file *file, char __user *buf, size_t count,
264static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count, 264static ssize_t dsp56k_write(struct file *file, const char __user *buf, size_t count,
265 loff_t *ppos) 265 loff_t *ppos)
266{ 266{
267 struct inode *inode = file->f_dentry->d_inode; 267 struct inode *inode = file->f_path.dentry->d_inode;
268 int dev = iminor(inode) & 0x0f; 268 int dev = iminor(inode) & 0x0f;
269 269
270 switch(dev) 270 switch(dev)
@@ -420,7 +420,7 @@ static int dsp56k_ioctl(struct inode *inode, struct file *file,
420#if 0 420#if 0
421static unsigned int dsp56k_poll(struct file *file, poll_table *wait) 421static unsigned int dsp56k_poll(struct file *file, poll_table *wait)
422{ 422{
423 int dev = iminor(file->f_dentry->d_inode) & 0x0f; 423 int dev = iminor(file->f_path.dentry->d_inode) & 0x0f;
424 424
425 switch(dev) 425 switch(dev)
426 { 426 {
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index 5e82c3bad2e3..d4005e94fe5f 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -122,7 +122,7 @@ static void dtlk_timer_tick(unsigned long data);
122static ssize_t dtlk_read(struct file *file, char __user *buf, 122static ssize_t dtlk_read(struct file *file, char __user *buf,
123 size_t count, loff_t * ppos) 123 size_t count, loff_t * ppos)
124{ 124{
125 unsigned int minor = iminor(file->f_dentry->d_inode); 125 unsigned int minor = iminor(file->f_path.dentry->d_inode);
126 char ch; 126 char ch;
127 int i = 0, retries; 127 int i = 0, retries;
128 128
@@ -174,7 +174,7 @@ static ssize_t dtlk_write(struct file *file, const char __user *buf,
174 } 174 }
175#endif 175#endif
176 176
177 if (iminor(file->f_dentry->d_inode) != DTLK_MINOR) 177 if (iminor(file->f_path.dentry->d_inode) != DTLK_MINOR)
178 return -EINVAL; 178 return -EINVAL;
179 179
180 while (1) { 180 while (1) {
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 7c71eb779802..a0f822c9d74d 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -199,7 +199,7 @@ static int pc_ioctl(struct tty_struct *, struct file *,
199 unsigned int, unsigned long); 199 unsigned int, unsigned long);
200static int info_ioctl(struct tty_struct *, struct file *, 200static int info_ioctl(struct tty_struct *, struct file *,
201 unsigned int, unsigned long); 201 unsigned int, unsigned long);
202static void pc_set_termios(struct tty_struct *, struct termios *); 202static void pc_set_termios(struct tty_struct *, struct ktermios *);
203static void do_softint(struct work_struct *work); 203static void do_softint(struct work_struct *work);
204static void pc_stop(struct tty_struct *); 204static void pc_stop(struct tty_struct *);
205static void pc_start(struct tty_struct *); 205static void pc_start(struct tty_struct *);
@@ -1236,6 +1236,8 @@ static int __init pc_init(void)
1236 pc_driver->init_termios.c_oflag = 0; 1236 pc_driver->init_termios.c_oflag = 0;
1237 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 1237 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1238 pc_driver->init_termios.c_lflag = 0; 1238 pc_driver->init_termios.c_lflag = 0;
1239 pc_driver->init_termios.c_ispeed = 9600;
1240 pc_driver->init_termios.c_ospeed = 9600;
1239 pc_driver->flags = TTY_DRIVER_REAL_RAW; 1241 pc_driver->flags = TTY_DRIVER_REAL_RAW;
1240 tty_set_operations(pc_driver, &pc_ops); 1242 tty_set_operations(pc_driver, &pc_ops);
1241 1243
@@ -1250,6 +1252,8 @@ static int __init pc_init(void)
1250 pc_info->init_termios.c_oflag = 0; 1252 pc_info->init_termios.c_oflag = 0;
1251 pc_info->init_termios.c_lflag = 0; 1253 pc_info->init_termios.c_lflag = 0;
1252 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; 1254 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1255 pc_info->init_termios.c_ispeed = 9600;
1256 pc_info->init_termios.c_ospeed = 9600;
1253 pc_info->flags = TTY_DRIVER_REAL_RAW; 1257 pc_info->flags = TTY_DRIVER_REAL_RAW;
1254 tty_set_operations(pc_info, &info_ops); 1258 tty_set_operations(pc_info, &info_ops);
1255 1259
@@ -1999,7 +2003,7 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1999{ /* Begin epcaparam */ 2003{ /* Begin epcaparam */
2000 2004
2001 unsigned int cmdHead; 2005 unsigned int cmdHead;
2002 struct termios *ts; 2006 struct ktermios *ts;
2003 struct board_chan __iomem *bc; 2007 struct board_chan __iomem *bc;
2004 unsigned mval, hflow, cflag, iflag; 2008 unsigned mval, hflow, cflag, iflag;
2005 2009
@@ -2114,7 +2118,7 @@ static void receive_data(struct channel *ch)
2114{ /* Begin receive_data */ 2118{ /* Begin receive_data */
2115 2119
2116 unchar *rptr; 2120 unchar *rptr;
2117 struct termios *ts = NULL; 2121 struct ktermios *ts = NULL;
2118 struct tty_struct *tty; 2122 struct tty_struct *tty;
2119 struct board_chan __iomem *bc; 2123 struct board_chan __iomem *bc;
2120 int dataToRead, wrapgap, bytesAvailable; 2124 int dataToRead, wrapgap, bytesAvailable;
@@ -2362,12 +2366,14 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2362 switch (cmd) 2366 switch (cmd)
2363 { /* Begin switch cmd */ 2367 { /* Begin switch cmd */
2364 2368
2369#if 0 /* Handled by calling layer properly */
2365 case TCGETS: 2370 case TCGETS:
2366 if (copy_to_user(argp, tty->termios, sizeof(struct termios))) 2371 if (copy_to_user(argp, tty->termios, sizeof(struct ktermios)))
2367 return -EFAULT; 2372 return -EFAULT;
2368 return 0; 2373 return 0;
2369 case TCGETA: 2374 case TCGETA:
2370 return get_termio(tty, argp); 2375 return get_termio(tty, argp);
2376#endif
2371 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2377 case TCSBRK: /* SVID version: non-zero arg --> no break */
2372 retval = tty_check_change(tty); 2378 retval = tty_check_change(tty);
2373 if (retval) 2379 if (retval)
@@ -2536,7 +2542,7 @@ static int pc_ioctl(struct tty_struct *tty, struct file * file,
2536 2542
2537/* --------------------- Begin pc_set_termios ----------------------- */ 2543/* --------------------- Begin pc_set_termios ----------------------- */
2538 2544
2539static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios) 2545static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2540{ /* Begin pc_set_termios */ 2546{ /* Begin pc_set_termios */
2541 2547
2542 struct channel *ch; 2548 struct channel *ch;
diff --git a/drivers/char/esp.c b/drivers/char/esp.c
index 93b551962513..d1bfbaa2aa02 100644
--- a/drivers/char/esp.c
+++ b/drivers/char/esp.c
@@ -1915,7 +1915,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1915 return 0; 1915 return 0;
1916} 1916}
1917 1917
1918static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1918static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1919{ 1919{
1920 struct esp_struct *info = (struct esp_struct *)tty->driver_data; 1920 struct esp_struct *info = (struct esp_struct *)tty->driver_data;
1921 unsigned long flags; 1921 unsigned long flags;
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 87127e49c0db..e769811e7417 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -718,11 +718,11 @@ static unsigned int gs_baudrates[] = {
718 718
719 719
720void gs_set_termios (struct tty_struct * tty, 720void gs_set_termios (struct tty_struct * tty,
721 struct termios * old_termios) 721 struct ktermios * old_termios)
722{ 722{
723 struct gs_port *port; 723 struct gs_port *port;
724 int baudrate, tmp, rv; 724 int baudrate, tmp, rv;
725 struct termios *tiosp; 725 struct ktermios *tiosp;
726 726
727 func_enter(); 727 func_enter();
728 728
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index d090622f1dea..207f7343ba60 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -192,11 +192,13 @@ MODULE_VERSION(HVCS_DRIVER_VERSION);
192 * that will cause echoing or we'll go into recursive loop echoing chars back 192 * that will cause echoing or we'll go into recursive loop echoing chars back
193 * and forth with the console drivers. 193 * and forth with the console drivers.
194 */ 194 */
195static struct termios hvcs_tty_termios = { 195static struct ktermios hvcs_tty_termios = {
196 .c_iflag = IGNBRK | IGNPAR, 196 .c_iflag = IGNBRK | IGNPAR,
197 .c_oflag = OPOST, 197 .c_oflag = OPOST,
198 .c_cflag = B38400 | CS8 | CREAD | HUPCL, 198 .c_cflag = B38400 | CS8 | CREAD | HUPCL,
199 .c_cc = INIT_C_CC 199 .c_cc = INIT_C_CC,
200 .c_ispeed = 38400,
201 .c_ospeed = 38400
200}; 202};
201 203
202/* 204/*
diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c
index 82a41d5b4ed0..d7806834fc17 100644
--- a/drivers/char/hvsi.c
+++ b/drivers/char/hvsi.c
@@ -1161,6 +1161,8 @@ static int __init hvsi_init(void)
1161 hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM; 1161 hvsi_driver->type = TTY_DRIVER_TYPE_SYSTEM;
1162 hvsi_driver->init_termios = tty_std_termios; 1162 hvsi_driver->init_termios = tty_std_termios;
1163 hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; 1163 hvsi_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1164 hvsi_driver->init_termios.c_ispeed = 9600;
1165 hvsi_driver->init_termios.c_ospeed = 9600;
1164 hvsi_driver->flags = TTY_DRIVER_REAL_RAW; 1166 hvsi_driver->flags = TTY_DRIVER_REAL_RAW;
1165 tty_set_operations(hvsi_driver, &hvsi_ops); 1167 tty_set_operations(hvsi_driver, &hvsi_ops);
1166 1168
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index cda2459c1d60..7c70310a49b5 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -177,7 +177,7 @@ static int ip2_write_room(PTTY);
177static int ip2_chars_in_buf(PTTY); 177static int ip2_chars_in_buf(PTTY);
178static void ip2_flush_buffer(PTTY); 178static void ip2_flush_buffer(PTTY);
179static int ip2_ioctl(PTTY, struct file *, UINT, ULONG); 179static int ip2_ioctl(PTTY, struct file *, UINT, ULONG);
180static void ip2_set_termios(PTTY, struct termios *); 180static void ip2_set_termios(PTTY, struct ktermios *);
181static void ip2_set_line_discipline(PTTY); 181static void ip2_set_line_discipline(PTTY);
182static void ip2_throttle(PTTY); 182static void ip2_throttle(PTTY);
183static void ip2_unthrottle(PTTY); 183static void ip2_unthrottle(PTTY);
@@ -198,7 +198,7 @@ static void do_status(struct work_struct *);
198 198
199static void ip2_wait_until_sent(PTTY,int); 199static void ip2_wait_until_sent(PTTY,int);
200 200
201static void set_params (i2ChanStrPtr, struct termios *); 201static void set_params (i2ChanStrPtr, struct ktermios *);
202static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *); 202static int get_serial_info(i2ChanStrPtr, struct serial_struct __user *);
203static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *); 203static int set_serial_info(i2ChanStrPtr, struct serial_struct __user *);
204 204
@@ -2398,7 +2398,7 @@ set_serial_info( i2ChanStrPtr pCh, struct serial_struct __user *new_info )
2398/* */ 2398/* */
2399/******************************************************************************/ 2399/******************************************************************************/
2400static void 2400static void
2401ip2_set_termios( PTTY tty, struct termios *old_termios ) 2401ip2_set_termios( PTTY tty, struct ktermios *old_termios )
2402{ 2402{
2403 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data; 2403 i2ChanStrPtr pCh = (i2ChanStrPtr)tty->driver_data;
2404 2404
@@ -2440,11 +2440,11 @@ ip2_set_line_discipline ( PTTY tty )
2440/* change. */ 2440/* change. */
2441/******************************************************************************/ 2441/******************************************************************************/
2442static void 2442static void
2443set_params( i2ChanStrPtr pCh, struct termios *o_tios ) 2443set_params( i2ChanStrPtr pCh, struct ktermios *o_tios )
2444{ 2444{
2445 tcflag_t cflag, iflag, lflag; 2445 tcflag_t cflag, iflag, lflag;
2446 char stop_char, start_char; 2446 char stop_char, start_char;
2447 struct termios dummy; 2447 struct ktermios dummy;
2448 2448
2449 lflag = pCh->pTTY->termios->c_lflag; 2449 lflag = pCh->pTTY->termios->c_lflag;
2450 cflag = pCh->pTTY->termios->c_cflag; 2450 cflag = pCh->pTTY->termios->c_cflag;
@@ -2700,7 +2700,7 @@ static
2700ssize_t 2700ssize_t
2701ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off ) 2701ip2_ipl_read(struct file *pFile, char __user *pData, size_t count, loff_t *off )
2702{ 2702{
2703 unsigned int minor = iminor(pFile->f_dentry->d_inode); 2703 unsigned int minor = iminor(pFile->f_path.dentry->d_inode);
2704 int rc = 0; 2704 int rc = 0;
2705 2705
2706#ifdef IP2DEBUG_IPL 2706#ifdef IP2DEBUG_IPL
diff --git a/drivers/char/ipmi/ipmi_bt_sm.c b/drivers/char/ipmi/ipmi_bt_sm.c
index 6c59baa887a8..e736119b6497 100644
--- a/drivers/char/ipmi/ipmi_bt_sm.c
+++ b/drivers/char/ipmi/ipmi_bt_sm.c
@@ -37,8 +37,10 @@
37#define BT_DEBUG_ENABLE 1 /* Generic messages */ 37#define BT_DEBUG_ENABLE 1 /* Generic messages */
38#define BT_DEBUG_MSG 2 /* Prints all request/response buffers */ 38#define BT_DEBUG_MSG 2 /* Prints all request/response buffers */
39#define BT_DEBUG_STATES 4 /* Verbose look at state changes */ 39#define BT_DEBUG_STATES 4 /* Verbose look at state changes */
40/* BT_DEBUG_OFF must be zero to correspond to the default uninitialized
41 value */
40 42
41static int bt_debug = BT_DEBUG_OFF; 43static int bt_debug; /* 0 == BT_DEBUG_OFF */
42 44
43module_param(bt_debug, int, 0644); 45module_param(bt_debug, int, 0644);
44MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states"); 46MODULE_PARM_DESC(bt_debug, "debug bitmask, 1=enable, 2=messages, 4=states");
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 375d3378eecd..ff2d052177cb 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -798,7 +798,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
798 if (copy_to_user(precv64, &recv64, sizeof(recv64))) 798 if (copy_to_user(precv64, &recv64, sizeof(recv64)))
799 return -EFAULT; 799 return -EFAULT;
800 800
801 rc = ipmi_ioctl(filep->f_dentry->d_inode, filep, 801 rc = ipmi_ioctl(filep->f_path.dentry->d_inode, filep,
802 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG) 802 ((cmd == COMPAT_IPMICTL_RECEIVE_MSG)
803 ? IPMICTL_RECEIVE_MSG 803 ? IPMICTL_RECEIVE_MSG
804 : IPMICTL_RECEIVE_MSG_TRUNC), 804 : IPMICTL_RECEIVE_MSG_TRUNC),
@@ -815,7 +815,7 @@ static long compat_ipmi_ioctl(struct file *filep, unsigned int cmd,
815 return rc; 815 return rc;
816 } 816 }
817 default: 817 default:
818 return ipmi_ioctl(filep->f_dentry->d_inode, filep, cmd, arg); 818 return ipmi_ioctl(filep->f_path.dentry->d_inode, filep, cmd, arg);
819 } 819 }
820} 820}
821#endif 821#endif
@@ -834,7 +834,7 @@ static const struct file_operations ipmi_fops = {
834 834
835#define DEVICE_NAME "ipmidev" 835#define DEVICE_NAME "ipmidev"
836 836
837static int ipmi_major = 0; 837static int ipmi_major;
838module_param(ipmi_major, int, 0); 838module_param(ipmi_major, int, 0);
839MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By" 839MODULE_PARM_DESC(ipmi_major, "Sets the major number of the IPMI device. By"
840 " default, or if you set it to zero, it will choose the next" 840 " default, or if you set it to zero, it will choose the next"
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 5703ee28e1cc..4e4691a53890 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -53,10 +53,10 @@
53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); 53static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
54static int ipmi_init_msghandler(void); 54static int ipmi_init_msghandler(void);
55 55
56static int initialized = 0; 56static int initialized;
57 57
58#ifdef CONFIG_PROC_FS 58#ifdef CONFIG_PROC_FS
59static struct proc_dir_entry *proc_ipmi_root = NULL; 59static struct proc_dir_entry *proc_ipmi_root;
60#endif /* CONFIG_PROC_FS */ 60#endif /* CONFIG_PROC_FS */
61 61
62/* Remain in auto-maintenance mode for this amount of time (in ms). */ 62/* Remain in auto-maintenance mode for this amount of time (in ms). */
@@ -2142,8 +2142,7 @@ cleanup_bmc_device(struct kref *ref)
2142 bmc = container_of(ref, struct bmc_device, refcount); 2142 bmc = container_of(ref, struct bmc_device, refcount);
2143 2143
2144 remove_files(bmc); 2144 remove_files(bmc);
2145 if (bmc->dev) 2145 platform_device_unregister(bmc->dev);
2146 platform_device_unregister(bmc->dev);
2147 kfree(bmc); 2146 kfree(bmc);
2148} 2147}
2149 2148
@@ -2341,8 +2340,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
2341 2340
2342 while (ipmi_find_bmc_prod_dev_id(&ipmidriver, 2341 while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
2343 bmc->id.product_id, 2342 bmc->id.product_id,
2344 bmc->id.device_id)) 2343 bmc->id.device_id)) {
2345 {
2346 if (!warn_printed) { 2344 if (!warn_printed) {
2347 printk(KERN_WARNING PFX 2345 printk(KERN_WARNING PFX
2348 "This machine has two different BMCs" 2346 "This machine has two different BMCs"
@@ -4043,7 +4041,7 @@ static void send_panic_events(char *str)
4043} 4041}
4044#endif /* CONFIG_IPMI_PANIC_EVENT */ 4042#endif /* CONFIG_IPMI_PANIC_EVENT */
4045 4043
4046static int has_panicked = 0; 4044static int has_panicked;
4047 4045
4048static int panic_event(struct notifier_block *this, 4046static int panic_event(struct notifier_block *this,
4049 unsigned long event, 4047 unsigned long event,
diff --git a/drivers/char/ipmi/ipmi_poweroff.c b/drivers/char/ipmi/ipmi_poweroff.c
index 597eb4f88b84..9d23136e598a 100644
--- a/drivers/char/ipmi/ipmi_poweroff.c
+++ b/drivers/char/ipmi/ipmi_poweroff.c
@@ -58,10 +58,10 @@ static int poweroff_powercycle;
58static int ifnum_to_use = -1; 58static int ifnum_to_use = -1;
59 59
60/* Our local state. */ 60/* Our local state. */
61static int ready = 0; 61static int ready;
62static ipmi_user_t ipmi_user; 62static ipmi_user_t ipmi_user;
63static int ipmi_ifnum; 63static int ipmi_ifnum;
64static void (*specific_poweroff_func)(ipmi_user_t user) = NULL; 64static void (*specific_poweroff_func)(ipmi_user_t user);
65 65
66/* Holds the old poweroff function so we can restore it on removal. */ 66/* Holds the old poweroff function so we can restore it on removal. */
67static void (*old_poweroff_func)(void); 67static void (*old_poweroff_func)(void);
@@ -182,7 +182,7 @@ static int ipmi_request_in_rc_mode(ipmi_user_t user,
182#define IPMI_MOTOROLA_MANUFACTURER_ID 0x0000A1 182#define IPMI_MOTOROLA_MANUFACTURER_ID 0x0000A1
183#define IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID 0x0051 183#define IPMI_MOTOROLA_PPS_IPMC_PRODUCT_ID 0x0051
184 184
185static void (*atca_oem_poweroff_hook)(ipmi_user_t user) = NULL; 185static void (*atca_oem_poweroff_hook)(ipmi_user_t user);
186 186
187static void pps_poweroff_atca (ipmi_user_t user) 187static void pps_poweroff_atca (ipmi_user_t user)
188{ 188{
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 81a0c89598e7..f1afd26a509f 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -845,7 +845,7 @@ static void request_events(void *send_info)
845 atomic_set(&smi_info->req_events, 1); 845 atomic_set(&smi_info->req_events, 1);
846} 846}
847 847
848static int initialized = 0; 848static int initialized;
849 849
850static void smi_timeout(unsigned long data) 850static void smi_timeout(unsigned long data)
851{ 851{
@@ -1018,17 +1018,17 @@ static int num_ports;
1018static int irqs[SI_MAX_PARMS]; 1018static int irqs[SI_MAX_PARMS];
1019static int num_irqs; 1019static int num_irqs;
1020static int regspacings[SI_MAX_PARMS]; 1020static int regspacings[SI_MAX_PARMS];
1021static int num_regspacings = 0; 1021static int num_regspacings;
1022static int regsizes[SI_MAX_PARMS]; 1022static int regsizes[SI_MAX_PARMS];
1023static int num_regsizes = 0; 1023static int num_regsizes;
1024static int regshifts[SI_MAX_PARMS]; 1024static int regshifts[SI_MAX_PARMS];
1025static int num_regshifts = 0; 1025static int num_regshifts;
1026static int slave_addrs[SI_MAX_PARMS]; 1026static int slave_addrs[SI_MAX_PARMS];
1027static int num_slave_addrs = 0; 1027static int num_slave_addrs;
1028 1028
1029#define IPMI_IO_ADDR_SPACE 0 1029#define IPMI_IO_ADDR_SPACE 0
1030#define IPMI_MEM_ADDR_SPACE 1 1030#define IPMI_MEM_ADDR_SPACE 1
1031static char *addr_space_to_str[] = { "I/O", "mem" }; 1031static char *addr_space_to_str[] = { "i/o", "mem" };
1032 1032
1033static int hotmod_handler(const char *val, struct kernel_param *kp); 1033static int hotmod_handler(const char *val, struct kernel_param *kp);
1034 1034
@@ -1397,20 +1397,7 @@ static struct hotmod_vals hotmod_as[] = {
1397 { "i/o", IPMI_IO_ADDR_SPACE }, 1397 { "i/o", IPMI_IO_ADDR_SPACE },
1398 { NULL } 1398 { NULL }
1399}; 1399};
1400static int ipmi_strcasecmp(const char *s1, const char *s2) 1400
1401{
1402 while (*s1 || *s2) {
1403 if (!*s1)
1404 return -1;
1405 if (!*s2)
1406 return 1;
1407 if (*s1 != *s2)
1408 return *s1 - *s2;
1409 s1++;
1410 s2++;
1411 }
1412 return 0;
1413}
1414static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr) 1401static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
1415{ 1402{
1416 char *s; 1403 char *s;
@@ -1424,7 +1411,7 @@ static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
1424 *s = '\0'; 1411 *s = '\0';
1425 s++; 1412 s++;
1426 for (i = 0; hotmod_ops[i].name; i++) { 1413 for (i = 0; hotmod_ops[i].name; i++) {
1427 if (ipmi_strcasecmp(*curr, v[i].name) == 0) { 1414 if (strcmp(*curr, v[i].name) == 0) {
1428 *val = v[i].val; 1415 *val = v[i].val;
1429 *curr = s; 1416 *curr = s;
1430 return 0; 1417 return 0;
@@ -1435,10 +1422,34 @@ static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr)
1435 return -EINVAL; 1422 return -EINVAL;
1436} 1423}
1437 1424
1425static int check_hotmod_int_op(const char *curr, const char *option,
1426 const char *name, int *val)
1427{
1428 char *n;
1429
1430 if (strcmp(curr, name) == 0) {
1431 if (!option) {
1432 printk(KERN_WARNING PFX
1433 "No option given for '%s'\n",
1434 curr);
1435 return -EINVAL;
1436 }
1437 *val = simple_strtoul(option, &n, 0);
1438 if ((*n != '\0') || (*option == '\0')) {
1439 printk(KERN_WARNING PFX
1440 "Bad option given for '%s'\n",
1441 curr);
1442 return -EINVAL;
1443 }
1444 return 1;
1445 }
1446 return 0;
1447}
1448
1438static int hotmod_handler(const char *val, struct kernel_param *kp) 1449static int hotmod_handler(const char *val, struct kernel_param *kp)
1439{ 1450{
1440 char *str = kstrdup(val, GFP_KERNEL); 1451 char *str = kstrdup(val, GFP_KERNEL);
1441 int rv = -EINVAL; 1452 int rv;
1442 char *next, *curr, *s, *n, *o; 1453 char *next, *curr, *s, *n, *o;
1443 enum hotmod_op op; 1454 enum hotmod_op op;
1444 enum si_type si_type; 1455 enum si_type si_type;
@@ -1450,13 +1461,15 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1450 int irq; 1461 int irq;
1451 int ipmb; 1462 int ipmb;
1452 int ival; 1463 int ival;
1464 int len;
1453 struct smi_info *info; 1465 struct smi_info *info;
1454 1466
1455 if (!str) 1467 if (!str)
1456 return -ENOMEM; 1468 return -ENOMEM;
1457 1469
1458 /* Kill any trailing spaces, as we can get a "\n" from echo. */ 1470 /* Kill any trailing spaces, as we can get a "\n" from echo. */
1459 ival = strlen(str) - 1; 1471 len = strlen(str);
1472 ival = len - 1;
1460 while ((ival >= 0) && isspace(str[ival])) { 1473 while ((ival >= 0) && isspace(str[ival])) {
1461 str[ival] = '\0'; 1474 str[ival] = '\0';
1462 ival--; 1475 ival--;
@@ -1513,35 +1526,37 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1513 *o = '\0'; 1526 *o = '\0';
1514 o++; 1527 o++;
1515 } 1528 }
1516#define HOTMOD_INT_OPT(name, val) \ 1529 rv = check_hotmod_int_op(curr, o, "rsp", &regspacing);
1517 if (ipmi_strcasecmp(curr, name) == 0) { \ 1530 if (rv < 0)
1518 if (!o) { \
1519 printk(KERN_WARNING PFX \
1520 "No option given for '%s'\n", \
1521 curr); \
1522 goto out; \
1523 } \
1524 val = simple_strtoul(o, &n, 0); \
1525 if ((*n != '\0') || (*o == '\0')) { \
1526 printk(KERN_WARNING PFX \
1527 "Bad option given for '%s'\n", \
1528 curr); \
1529 goto out; \
1530 } \
1531 }
1532
1533 HOTMOD_INT_OPT("rsp", regspacing)
1534 else HOTMOD_INT_OPT("rsi", regsize)
1535 else HOTMOD_INT_OPT("rsh", regshift)
1536 else HOTMOD_INT_OPT("irq", irq)
1537 else HOTMOD_INT_OPT("ipmb", ipmb)
1538 else {
1539 printk(KERN_WARNING PFX
1540 "Invalid hotmod option '%s'\n",
1541 curr);
1542 goto out; 1531 goto out;
1543 } 1532 else if (rv)
1544#undef HOTMOD_INT_OPT 1533 continue;
1534 rv = check_hotmod_int_op(curr, o, "rsi", &regsize);
1535 if (rv < 0)
1536 goto out;
1537 else if (rv)
1538 continue;
1539 rv = check_hotmod_int_op(curr, o, "rsh", &regshift);
1540 if (rv < 0)
1541 goto out;
1542 else if (rv)
1543 continue;
1544 rv = check_hotmod_int_op(curr, o, "irq", &irq);
1545 if (rv < 0)
1546 goto out;
1547 else if (rv)
1548 continue;
1549 rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb);
1550 if (rv < 0)
1551 goto out;
1552 else if (rv)
1553 continue;
1554
1555 rv = -EINVAL;
1556 printk(KERN_WARNING PFX
1557 "Invalid hotmod option '%s'\n",
1558 curr);
1559 goto out;
1545 } 1560 }
1546 1561
1547 if (op == HM_ADD) { 1562 if (op == HM_ADD) {
@@ -1590,6 +1605,7 @@ static int hotmod_handler(const char *val, struct kernel_param *kp)
1590 mutex_unlock(&smi_infos_lock); 1605 mutex_unlock(&smi_infos_lock);
1591 } 1606 }
1592 } 1607 }
1608 rv = len;
1593 out: 1609 out:
1594 kfree(str); 1610 kfree(str);
1595 return rv; 1611 return rv;
@@ -1610,11 +1626,11 @@ static __devinit void hardcode_find_bmc(void)
1610 1626
1611 info->addr_source = "hardcoded"; 1627 info->addr_source = "hardcoded";
1612 1628
1613 if (!si_type[i] || ipmi_strcasecmp(si_type[i], "kcs") == 0) { 1629 if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
1614 info->si_type = SI_KCS; 1630 info->si_type = SI_KCS;
1615 } else if (ipmi_strcasecmp(si_type[i], "smic") == 0) { 1631 } else if (strcmp(si_type[i], "smic") == 0) {
1616 info->si_type = SI_SMIC; 1632 info->si_type = SI_SMIC;
1617 } else if (ipmi_strcasecmp(si_type[i], "bt") == 0) { 1633 } else if (strcmp(si_type[i], "bt") == 0) {
1618 info->si_type = SI_BT; 1634 info->si_type = SI_BT;
1619 } else { 1635 } else {
1620 printk(KERN_WARNING 1636 printk(KERN_WARNING
@@ -1668,7 +1684,7 @@ static __devinit void hardcode_find_bmc(void)
1668/* Once we get an ACPI failure, we don't try any more, because we go 1684/* Once we get an ACPI failure, we don't try any more, because we go
1669 through the tables sequentially. Once we don't find a table, there 1685 through the tables sequentially. Once we don't find a table, there
1670 are no more. */ 1686 are no more. */
1671static int acpi_failure = 0; 1687static int acpi_failure;
1672 1688
1673/* For GPE-type interrupts. */ 1689/* For GPE-type interrupts. */
1674static u32 ipmi_acpi_gpe(void *context) 1690static u32 ipmi_acpi_gpe(void *context)
@@ -1779,7 +1795,6 @@ struct SPMITable {
1779static __devinit int try_init_acpi(struct SPMITable *spmi) 1795static __devinit int try_init_acpi(struct SPMITable *spmi)
1780{ 1796{
1781 struct smi_info *info; 1797 struct smi_info *info;
1782 char *io_type;
1783 u8 addr_space; 1798 u8 addr_space;
1784 1799
1785 if (spmi->IPMIlegacy != 1) { 1800 if (spmi->IPMIlegacy != 1) {
@@ -1843,11 +1858,9 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1843 info->io.regshift = spmi->addr.register_bit_offset; 1858 info->io.regshift = spmi->addr.register_bit_offset;
1844 1859
1845 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1860 if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1846 io_type = "memory";
1847 info->io_setup = mem_setup; 1861 info->io_setup = mem_setup;
1848 info->io.addr_type = IPMI_IO_ADDR_SPACE; 1862 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1849 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1863 } else if (spmi->addr.address_space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1850 io_type = "I/O";
1851 info->io_setup = port_setup; 1864 info->io_setup = port_setup;
1852 info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1853 } else { 1866 } else {
@@ -2773,8 +2786,7 @@ static __devinit int init_ipmi_si(void)
2773#endif 2786#endif
2774 2787
2775#ifdef CONFIG_ACPI 2788#ifdef CONFIG_ACPI
2776 if (si_trydefaults) 2789 acpi_find_bmc();
2777 acpi_find_bmc();
2778#endif 2790#endif
2779 2791
2780#ifdef CONFIG_PCI 2792#ifdef CONFIG_PCI
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 90fb2a541916..78280380a905 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -134,14 +134,14 @@
134 134
135static int nowayout = WATCHDOG_NOWAYOUT; 135static int nowayout = WATCHDOG_NOWAYOUT;
136 136
137static ipmi_user_t watchdog_user = NULL; 137static ipmi_user_t watchdog_user;
138static int watchdog_ifnum; 138static int watchdog_ifnum;
139 139
140/* Default the timeout to 10 seconds. */ 140/* Default the timeout to 10 seconds. */
141static int timeout = 10; 141static int timeout = 10;
142 142
143/* The pre-timeout is disabled by default. */ 143/* The pre-timeout is disabled by default. */
144static int pretimeout = 0; 144static int pretimeout;
145 145
146/* Default action is to reset the board on a timeout. */ 146/* Default action is to reset the board on a timeout. */
147static unsigned char action_val = WDOG_TIMEOUT_RESET; 147static unsigned char action_val = WDOG_TIMEOUT_RESET;
@@ -156,10 +156,10 @@ static unsigned char preop_val = WDOG_PREOP_NONE;
156 156
157static char preop[16] = "preop_none"; 157static char preop[16] = "preop_none";
158static DEFINE_SPINLOCK(ipmi_read_lock); 158static DEFINE_SPINLOCK(ipmi_read_lock);
159static char data_to_read = 0; 159static char data_to_read;
160static DECLARE_WAIT_QUEUE_HEAD(read_q); 160static DECLARE_WAIT_QUEUE_HEAD(read_q);
161static struct fasync_struct *fasync_q = NULL; 161static struct fasync_struct *fasync_q;
162static char pretimeout_since_last_heartbeat = 0; 162static char pretimeout_since_last_heartbeat;
163static char expect_close; 163static char expect_close;
164 164
165static int ifnum_to_use = -1; 165static int ifnum_to_use = -1;
@@ -177,7 +177,7 @@ static void ipmi_unregister_watchdog(int ipmi_intf);
177 177
178/* If true, the driver will start running as soon as it is configured 178/* If true, the driver will start running as soon as it is configured
179 and ready. */ 179 and ready. */
180static int start_now = 0; 180static int start_now;
181 181
182static int set_param_int(const char *val, struct kernel_param *kp) 182static int set_param_int(const char *val, struct kernel_param *kp)
183{ 183{
@@ -300,16 +300,16 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
300static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 300static unsigned char ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
301 301
302/* If shutting down via IPMI, we ignore the heartbeat. */ 302/* If shutting down via IPMI, we ignore the heartbeat. */
303static int ipmi_ignore_heartbeat = 0; 303static int ipmi_ignore_heartbeat;
304 304
305/* Is someone using the watchdog? Only one user is allowed. */ 305/* Is someone using the watchdog? Only one user is allowed. */
306static unsigned long ipmi_wdog_open = 0; 306static unsigned long ipmi_wdog_open;
307 307
308/* If set to 1, the heartbeat command will set the state to reset and 308/* If set to 1, the heartbeat command will set the state to reset and
309 start the timer. The timer doesn't normally run when the driver is 309 start the timer. The timer doesn't normally run when the driver is
310 first opened until the heartbeat is set the first time, this 310 first opened until the heartbeat is set the first time, this
311 variable is used to accomplish this. */ 311 variable is used to accomplish this. */
312static int ipmi_start_timer_on_heartbeat = 0; 312static int ipmi_start_timer_on_heartbeat;
313 313
314/* IPMI version of the BMC. */ 314/* IPMI version of the BMC. */
315static unsigned char ipmi_version_major; 315static unsigned char ipmi_version_major;
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 1637c1d9a4ba..5a747e685993 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -172,12 +172,14 @@ static struct pci_driver isicom_driver = {
172static int prev_card = 3; /* start servicing isi_card[0] */ 172static int prev_card = 3; /* start servicing isi_card[0] */
173static struct tty_driver *isicom_normal; 173static struct tty_driver *isicom_normal;
174 174
175static struct timer_list tx; 175static DECLARE_COMPLETION(isi_timerdone);
176static char re_schedule = 1; 176static char re_schedule = 1;
177 177
178static void isicom_tx(unsigned long _data); 178static void isicom_tx(unsigned long _data);
179static void isicom_start(struct tty_struct *tty); 179static void isicom_start(struct tty_struct *tty);
180 180
181static DEFINE_TIMER(tx, isicom_tx, 0, 0);
182
181/* baud index mappings from linux defns to isi */ 183/* baud index mappings from linux defns to isi */
182 184
183static signed char linuxb_to_isib[] = { 185static signed char linuxb_to_isib[] = {
@@ -193,9 +195,9 @@ struct isi_board {
193 unsigned short shift_count; 195 unsigned short shift_count;
194 struct isi_port * ports; 196 struct isi_port * ports;
195 signed char count; 197 signed char count;
196 unsigned char isa;
197 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */ 198 spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */
198 unsigned long flags; 199 unsigned long flags;
200 unsigned int index;
199}; 201};
200 202
201struct isi_port { 203struct isi_port {
@@ -514,17 +516,11 @@ static void isicom_tx(unsigned long _data)
514 /* schedule another tx for hopefully in about 10ms */ 516 /* schedule another tx for hopefully in about 10ms */
515sched_again: 517sched_again:
516 if (!re_schedule) { 518 if (!re_schedule) {
517 re_schedule = 2; 519 complete(&isi_timerdone);
518 return; 520 return;
519 } 521 }
520 522
521 init_timer(&tx); 523 mod_timer(&tx, jiffies + msecs_to_jiffies(10));
522 tx.expires = jiffies + HZ/100;
523 tx.data = 0;
524 tx.function = isicom_tx;
525 add_timer(&tx);
526
527 return;
528} 524}
529 525
530/* Interrupt handlers */ 526/* Interrupt handlers */
@@ -562,14 +558,12 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
562 base = card->base; 558 base = card->base;
563 spin_lock(&card->card_lock); 559 spin_lock(&card->card_lock);
564 560
565 if (card->isa == NO) { 561 /*
566 /* 562 * disable any interrupts from the PCI card and lower the
567 * disable any interrupts from the PCI card and lower the 563 * interrupt line
568 * interrupt line 564 */
569 */ 565 outw(0x8000, base+0x04);
570 outw(0x8000, base+0x04); 566 ClearInterrupt(base);
571 ClearInterrupt(base);
572 }
573 567
574 inw(base); /* get the dummy word out */ 568 inw(base); /* get the dummy word out */
575 header = inw(base); 569 header = inw(base);
@@ -579,19 +573,13 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
579 if (channel + 1 > card->port_count) { 573 if (channel + 1 > card->port_count) {
580 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): " 574 printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%lx): "
581 "%d(channel) > port_count.\n", base, channel+1); 575 "%d(channel) > port_count.\n", base, channel+1);
582 if (card->isa) 576 outw(0x0000, base+0x04); /* enable interrupts */
583 ClearInterrupt(base);
584 else
585 outw(0x0000, base+0x04); /* enable interrupts */
586 spin_unlock(&card->card_lock); 577 spin_unlock(&card->card_lock);
587 return IRQ_HANDLED; 578 return IRQ_HANDLED;
588 } 579 }
589 port = card->ports + channel; 580 port = card->ports + channel;
590 if (!(port->flags & ASYNC_INITIALIZED)) { 581 if (!(port->flags & ASYNC_INITIALIZED)) {
591 if (card->isa) 582 outw(0x0000, base+0x04); /* enable interrupts */
592 ClearInterrupt(base);
593 else
594 outw(0x0000, base+0x04); /* enable interrupts */
595 return IRQ_HANDLED; 583 return IRQ_HANDLED;
596 } 584 }
597 585
@@ -604,10 +592,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
604 } 592 }
605 if (byte_count & 0x01) 593 if (byte_count & 0x01)
606 inw(base); 594 inw(base);
607 if (card->isa == YES) 595 outw(0x0000, base+0x04); /* enable interrupts */
608 ClearInterrupt(base);
609 else
610 outw(0x0000, base+0x04); /* enable interrupts */
611 spin_unlock(&card->card_lock); 596 spin_unlock(&card->card_lock);
612 return IRQ_HANDLED; 597 return IRQ_HANDLED;
613 } 598 }
@@ -708,10 +693,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
708 } 693 }
709 tty_flip_buffer_push(tty); 694 tty_flip_buffer_push(tty);
710 } 695 }
711 if (card->isa == YES) 696 outw(0x0000, base+0x04); /* enable interrupts */
712 ClearInterrupt(base);
713 else
714 outw(0x0000, base+0x04); /* enable interrupts */
715 697
716 return IRQ_HANDLED; 698 return IRQ_HANDLED;
717} 699}
@@ -964,8 +946,8 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
964{ 946{
965 struct isi_port *port; 947 struct isi_port *port;
966 struct isi_board *card; 948 struct isi_board *card;
967 unsigned int line, board; 949 unsigned int board;
968 int error; 950 int error, line;
969 951
970 line = tty->index; 952 line = tty->index;
971 if (line < 0 || line > PORT_COUNT-1) 953 if (line < 0 || line > PORT_COUNT-1)
@@ -1399,7 +1381,7 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1399 1381
1400/* set_termios et all */ 1382/* set_termios et all */
1401static void isicom_set_termios(struct tty_struct *tty, 1383static void isicom_set_termios(struct tty_struct *tty,
1402 struct termios *old_termios) 1384 struct ktermios *old_termios)
1403{ 1385{
1404 struct isi_port *port = tty->driver_data; 1386 struct isi_port *port = tty->driver_data;
1405 1387
@@ -1520,37 +1502,6 @@ static void isicom_flush_buffer(struct tty_struct *tty)
1520 * Driver init and deinit functions 1502 * Driver init and deinit functions
1521 */ 1503 */
1522 1504
1523static int __devinit isicom_register_ioregion(struct pci_dev *pdev,
1524 const unsigned int index)
1525{
1526 struct isi_board *board = pci_get_drvdata(pdev);
1527
1528 if (!board->base)
1529 return -EINVAL;
1530
1531 if (!request_region(board->base, 16, ISICOM_NAME)) {
1532 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
1533 "will be disabled.\n", board->base, board->base + 15,
1534 index + 1);
1535 return -EBUSY;
1536 }
1537
1538 return 0;
1539}
1540
1541static void isicom_unregister_ioregion(struct pci_dev *pdev)
1542{
1543 struct isi_board *board = pci_get_drvdata(pdev);
1544
1545 if (!board->base)
1546 return;
1547
1548 release_region(board->base, 16);
1549 dev_dbg(&pdev->dev, "I/O Region 0x%lx-0x%lx released.\n",
1550 board->base, board->base + 15);
1551 board->base = 0;
1552}
1553
1554static const struct tty_operations isicom_ops = { 1505static const struct tty_operations isicom_ops = {
1555 .open = isicom_open, 1506 .open = isicom_open,
1556 .close = isicom_close, 1507 .close = isicom_close,
@@ -1571,70 +1522,6 @@ static const struct tty_operations isicom_ops = {
1571 .tiocmset = isicom_tiocmset, 1522 .tiocmset = isicom_tiocmset,
1572}; 1523};
1573 1524
1574static int __devinit isicom_register_tty_driver(void)
1575{
1576 int error = -ENOMEM;
1577
1578 /* tty driver structure initialization */
1579 isicom_normal = alloc_tty_driver(PORT_COUNT);
1580 if (!isicom_normal)
1581 goto end;
1582
1583 isicom_normal->owner = THIS_MODULE;
1584 isicom_normal->name = "ttyM";
1585 isicom_normal->major = ISICOM_NMAJOR;
1586 isicom_normal->minor_start = 0;
1587 isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
1588 isicom_normal->subtype = SERIAL_TYPE_NORMAL;
1589 isicom_normal->init_termios = tty_std_termios;
1590 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1591 CLOCAL;
1592 isicom_normal->flags = TTY_DRIVER_REAL_RAW;
1593 tty_set_operations(isicom_normal, &isicom_ops);
1594
1595 if ((error = tty_register_driver(isicom_normal))) {
1596 pr_dbg("Couldn't register the dialin driver, error=%d\n",
1597 error);
1598 put_tty_driver(isicom_normal);
1599 }
1600end:
1601 return error;
1602}
1603
1604static void isicom_unregister_tty_driver(void)
1605{
1606 int error;
1607
1608 if ((error = tty_unregister_driver(isicom_normal)))
1609 pr_dbg("couldn't unregister normal driver, error=%d.\n", error);
1610
1611 put_tty_driver(isicom_normal);
1612}
1613
1614static int __devinit isicom_register_isr(struct pci_dev *pdev,
1615 const unsigned int index)
1616{
1617 struct isi_board *board = pci_get_drvdata(pdev);
1618 unsigned long irqflags = IRQF_DISABLED;
1619 int retval = -EINVAL;
1620
1621 if (!board->base)
1622 goto end;
1623
1624 if (board->isa == NO)
1625 irqflags |= IRQF_SHARED;
1626
1627 retval = request_irq(board->irq, isicom_interrupt, irqflags,
1628 ISICOM_NAME, board);
1629 if (retval < 0)
1630 dev_warn(&pdev->dev, "Could not install handler at Irq %d. "
1631 "Card%d will be disabled.\n", board->irq, index + 1);
1632 else
1633 retval = 0;
1634end:
1635 return retval;
1636}
1637
1638static int __devinit reset_card(struct pci_dev *pdev, 1525static int __devinit reset_card(struct pci_dev *pdev,
1639 const unsigned int card, unsigned int *signature) 1526 const unsigned int card, unsigned int *signature)
1640{ 1527{
@@ -1656,36 +1543,23 @@ static int __devinit reset_card(struct pci_dev *pdev,
1656 1543
1657 *signature = inw(base + 0x4) & 0xff; 1544 *signature = inw(base + 0x4) & 0xff;
1658 1545
1659 if (board->isa == YES) { 1546 portcount = inw(base + 0x2);
1660 if (!(inw(base + 0xe) & 0x1) || (inw(base + 0x2))) { 1547 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
1661 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n", 1548 (portcount != 4) && (portcount != 8))) {
1662 inw(base + 0x2), inw(base + 0xe)); 1549 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1663 dev_err(&pdev->dev, "ISILoad:ISA Card%d reset failure " 1550 inw(base + 0x2), inw(base + 0xe));
1664 "(Possible bad I/O Port Address 0x%lx).\n", 1551 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1665 card + 1, base); 1552 "(Possible bad I/O Port Address 0x%lx).\n",
1666 retval = -EIO; 1553 card + 1, base);
1667 goto end; 1554 retval = -EIO;
1668 } 1555 goto end;
1669 } else {
1670 portcount = inw(base + 0x2);
1671 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) &&
1672 (portcount != 4) && (portcount != 8))) {
1673 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n",
1674 inw(base + 0x2), inw(base + 0xe));
1675 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1676 "(Possible bad I/O Port Address 0x%lx).\n",
1677 card + 1, base);
1678 retval = -EIO;
1679 goto end;
1680 }
1681 } 1556 }
1682 1557
1683 switch (*signature) { 1558 switch (*signature) {
1684 case 0xa5: 1559 case 0xa5:
1685 case 0xbb: 1560 case 0xbb:
1686 case 0xdd: 1561 case 0xdd:
1687 board->port_count = (board->isa == NO && portcount == 4) ? 4 : 1562 board->port_count = (portcount == 4) ? 4 : 8;
1688 8;
1689 board->shift_count = 12; 1563 board->shift_count = 12;
1690 break; 1564 break;
1691 case 0xcc: 1565 case 0xcc:
@@ -1831,6 +1705,11 @@ static int __devinit load_firmware(struct pci_dev *pdev,
1831 } 1705 }
1832 1706
1833 data = kmalloc(word_count * 2, GFP_KERNEL); 1707 data = kmalloc(word_count * 2, GFP_KERNEL);
1708 if (data == NULL) {
1709 dev_err(&pdev->dev, "Card%d, firmware upload "
1710 "failed, not enough memory\n", index + 1);
1711 goto errrelfw;
1712 }
1834 inw(base); 1713 inw(base);
1835 insw(base, data, word_count); 1714 insw(base, data, word_count);
1836 InterruptTheCard(base); 1715 InterruptTheCard(base);
@@ -1879,8 +1758,6 @@ end:
1879/* 1758/*
1880 * Insmod can set static symbols so keep these static 1759 * Insmod can set static symbols so keep these static
1881 */ 1760 */
1882static int io[4];
1883static int irq[4];
1884static int card; 1761static int card;
1885 1762
1886static int __devinit isicom_probe(struct pci_dev *pdev, 1763static int __devinit isicom_probe(struct pci_dev *pdev,
@@ -1906,20 +1783,29 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1906 break; 1783 break;
1907 } 1784 }
1908 1785
1786 board->index = index;
1909 board->base = ioaddr; 1787 board->base = ioaddr;
1910 board->irq = pciirq; 1788 board->irq = pciirq;
1911 board->isa = NO;
1912 card++; 1789 card++;
1913 1790
1914 pci_set_drvdata(pdev, board); 1791 pci_set_drvdata(pdev, board);
1915 1792
1916 retval = isicom_register_ioregion(pdev, index); 1793 retval = pci_request_region(pdev, 3, ISICOM_NAME);
1917 if (retval < 0) 1794 if (retval) {
1795 dev_err(&pdev->dev, "I/O Region 0x%lx-0x%lx is busy. Card%d "
1796 "will be disabled.\n", board->base, board->base + 15,
1797 index + 1);
1798 retval = -EBUSY;
1918 goto err; 1799 goto err;
1800 }
1919 1801
1920 retval = isicom_register_isr(pdev, index); 1802 retval = request_irq(board->irq, isicom_interrupt,
1921 if (retval < 0) 1803 IRQF_SHARED | IRQF_DISABLED, ISICOM_NAME, board);
1804 if (retval < 0) {
1805 dev_err(&pdev->dev, "Could not install handler at Irq %d. "
1806 "Card%d will be disabled.\n", board->irq, index + 1);
1922 goto errunrr; 1807 goto errunrr;
1808 }
1923 1809
1924 retval = reset_card(pdev, index, &signature); 1810 retval = reset_card(pdev, index, &signature);
1925 if (retval < 0) 1811 if (retval < 0)
@@ -1929,12 +1815,16 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1929 if (retval < 0) 1815 if (retval < 0)
1930 goto errunri; 1816 goto errunri;
1931 1817
1818 for (index = 0; index < board->port_count; index++)
1819 tty_register_device(isicom_normal, board->index * 16 + index,
1820 &pdev->dev);
1821
1932 return 0; 1822 return 0;
1933 1823
1934errunri: 1824errunri:
1935 free_irq(board->irq, board); 1825 free_irq(board->irq, board);
1936errunrr: 1826errunrr:
1937 isicom_unregister_ioregion(pdev); 1827 pci_release_region(pdev, 3);
1938err: 1828err:
1939 board->base = 0; 1829 board->base = 0;
1940 return retval; 1830 return retval;
@@ -1943,18 +1833,21 @@ err:
1943static void __devexit isicom_remove(struct pci_dev *pdev) 1833static void __devexit isicom_remove(struct pci_dev *pdev)
1944{ 1834{
1945 struct isi_board *board = pci_get_drvdata(pdev); 1835 struct isi_board *board = pci_get_drvdata(pdev);
1836 unsigned int i;
1837
1838 for (i = 0; i < board->port_count; i++)
1839 tty_unregister_device(isicom_normal, board->index * 16 + i);
1946 1840
1947 free_irq(board->irq, board); 1841 free_irq(board->irq, board);
1948 isicom_unregister_ioregion(pdev); 1842 pci_release_region(pdev, 3);
1949} 1843}
1950 1844
1951static int __devinit isicom_setup(void) 1845static int __init isicom_init(void)
1952{ 1846{
1953 int retval, idx, channel; 1847 int retval, idx, channel;
1954 struct isi_port *port; 1848 struct isi_port *port;
1955 1849
1956 card = 0; 1850 card = 0;
1957 memset(isi_ports, 0, sizeof(isi_ports));
1958 1851
1959 for(idx = 0; idx < BOARD_COUNT; idx++) { 1852 for(idx = 0; idx < BOARD_COUNT; idx++) {
1960 port = &isi_ports[idx * 16]; 1853 port = &isi_ports[idx * 16];
@@ -1975,66 +1868,65 @@ static int __devinit isicom_setup(void)
1975 } 1868 }
1976 isi_card[idx].base = 0; 1869 isi_card[idx].base = 0;
1977 isi_card[idx].irq = 0; 1870 isi_card[idx].irq = 0;
1978
1979 if (!io[idx])
1980 continue;
1981
1982 if (irq[idx] == 2 || irq[idx] == 3 || irq[idx] == 4 ||
1983 irq[idx] == 5 || irq[idx] == 7 ||
1984 irq[idx] == 10 || irq[idx] == 11 ||
1985 irq[idx] == 12 || irq[idx] == 15) {
1986 printk(KERN_ERR "ISICOM: ISA not supported yet.\n");
1987 retval = -EINVAL;
1988 goto error;
1989 } else
1990 printk(KERN_ERR "ISICOM: Irq %d unsupported. "
1991 "Disabling Card%d...\n", irq[idx], idx + 1);
1992 } 1871 }
1993 1872
1994 retval = isicom_register_tty_driver(); 1873 /* tty driver structure initialization */
1995 if (retval < 0) 1874 isicom_normal = alloc_tty_driver(PORT_COUNT);
1875 if (!isicom_normal) {
1876 retval = -ENOMEM;
1996 goto error; 1877 goto error;
1878 }
1879
1880 isicom_normal->owner = THIS_MODULE;
1881 isicom_normal->name = "ttyM";
1882 isicom_normal->major = ISICOM_NMAJOR;
1883 isicom_normal->minor_start = 0;
1884 isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
1885 isicom_normal->subtype = SERIAL_TYPE_NORMAL;
1886 isicom_normal->init_termios = tty_std_termios;
1887 isicom_normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL |
1888 CLOCAL;
1889 isicom_normal->flags = TTY_DRIVER_REAL_RAW |
1890 TTY_DRIVER_DYNAMIC_DEV;
1891 tty_set_operations(isicom_normal, &isicom_ops);
1892
1893 retval = tty_register_driver(isicom_normal);
1894 if (retval) {
1895 pr_dbg("Couldn't register the dialin driver\n");
1896 goto err_puttty;
1897 }
1997 1898
1998 retval = pci_register_driver(&isicom_driver); 1899 retval = pci_register_driver(&isicom_driver);
1999 if (retval < 0) { 1900 if (retval < 0) {
2000 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n"); 1901 printk(KERN_ERR "ISICOM: Unable to register pci driver.\n");
2001 goto errtty; 1902 goto err_unrtty;
2002 } 1903 }
2003 1904
2004 init_timer(&tx); 1905 mod_timer(&tx, jiffies + 1);
2005 tx.expires = jiffies + 1;
2006 tx.data = 0;
2007 tx.function = isicom_tx;
2008 re_schedule = 1;
2009 add_timer(&tx);
2010 1906
2011 return 0; 1907 return 0;
2012errtty: 1908err_unrtty:
2013 isicom_unregister_tty_driver(); 1909 tty_unregister_driver(isicom_normal);
1910err_puttty:
1911 put_tty_driver(isicom_normal);
2014error: 1912error:
2015 return retval; 1913 return retval;
2016} 1914}
2017 1915
2018static void __exit isicom_exit(void) 1916static void __exit isicom_exit(void)
2019{ 1917{
2020 unsigned int index = 0;
2021
2022 re_schedule = 0; 1918 re_schedule = 0;
2023 1919
2024 while (re_schedule != 2 && index++ < 100) 1920 wait_for_completion_timeout(&isi_timerdone, HZ);
2025 msleep(10);
2026 1921
2027 pci_unregister_driver(&isicom_driver); 1922 pci_unregister_driver(&isicom_driver);
2028 isicom_unregister_tty_driver(); 1923 tty_unregister_driver(isicom_normal);
1924 put_tty_driver(isicom_normal);
2029} 1925}
2030 1926
2031module_init(isicom_setup); 1927module_init(isicom_init);
2032module_exit(isicom_exit); 1928module_exit(isicom_exit);
2033 1929
2034MODULE_AUTHOR("MultiTech"); 1930MODULE_AUTHOR("MultiTech");
2035MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech"); 1931MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
2036MODULE_LICENSE("GPL"); 1932MODULE_LICENSE("GPL");
2037module_param_array(io, int, NULL, 0);
2038MODULE_PARM_DESC(io, "I/O ports for the cards");
2039module_param_array(irq, int, NULL, 0);
2040MODULE_PARM_DESC(irq, "Interrupts for the cards");
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 8f591945ebd9..68645d351873 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -14,14 +14,6 @@
14 * the Free Software Foundation; either version 2 of the License, or 14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version. 15 * (at your option) any later version.
16 * 16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 17 */
26 18
27/*****************************************************************************/ 19/*****************************************************************************/
@@ -41,6 +33,7 @@
41#include <linux/device.h> 33#include <linux/device.h>
42#include <linux/wait.h> 34#include <linux/wait.h>
43#include <linux/eisa.h> 35#include <linux/eisa.h>
36#include <linux/ctype.h>
44 37
45#include <asm/io.h> 38#include <asm/io.h>
46#include <asm/uaccess.h> 39#include <asm/uaccess.h>
@@ -61,21 +54,10 @@
61#define BRD_BRUMBY4 2 54#define BRD_BRUMBY4 2
62#define BRD_ONBOARD2 3 55#define BRD_ONBOARD2 3
63#define BRD_ONBOARD 4 56#define BRD_ONBOARD 4
64#define BRD_BRUMBY8 5
65#define BRD_BRUMBY16 6
66#define BRD_ONBOARDE 7 57#define BRD_ONBOARDE 7
67#define BRD_ONBOARD32 9
68#define BRD_ONBOARD2_32 10
69#define BRD_ONBOARDRS 11
70#define BRD_EASYIO 20
71#define BRD_ECH 21
72#define BRD_ECHMC 22
73#define BRD_ECP 23 58#define BRD_ECP 23
74#define BRD_ECPE 24 59#define BRD_ECPE 24
75#define BRD_ECPMC 25 60#define BRD_ECPMC 25
76#define BRD_ECHPCI 26
77#define BRD_ECH64PCI 27
78#define BRD_EASYIOPCI 28
79#define BRD_ECPPCI 29 61#define BRD_ECPPCI 29
80 62
81#define BRD_BRUMBY BRD_BRUMBY4 63#define BRD_BRUMBY BRD_BRUMBY4
@@ -119,20 +101,16 @@
119 * interrupt is required. 101 * interrupt is required.
120 */ 102 */
121 103
122typedef struct { 104struct stlconf {
123 int brdtype; 105 int brdtype;
124 int ioaddr1; 106 int ioaddr1;
125 int ioaddr2; 107 int ioaddr2;
126 unsigned long memaddr; 108 unsigned long memaddr;
127 int irq; 109 int irq;
128 int irqtype; 110 int irqtype;
129} stlconf_t;
130
131static stlconf_t stli_brdconf[] = {
132 /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
133}; 111};
134 112
135static int stli_nrbrds = ARRAY_SIZE(stli_brdconf); 113static unsigned int stli_nrbrds;
136 114
137/* stli_lock must NOT be taken holding brd_lock */ 115/* stli_lock must NOT be taken holding brd_lock */
138static spinlock_t stli_lock; /* TTY logic lock */ 116static spinlock_t stli_lock; /* TTY logic lock */
@@ -194,9 +172,11 @@ static struct tty_struct *stli_txcooktty;
194 * with this termios initially. Basically all it defines is a raw port 172 * with this termios initially. Basically all it defines is a raw port
195 * at 9600 baud, 8 data bits, no parity, 1 stop bit. 173 * at 9600 baud, 8 data bits, no parity, 1 stop bit.
196 */ 174 */
197static struct termios stli_deftermios = { 175static struct ktermios stli_deftermios = {
198 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), 176 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
199 .c_cc = INIT_C_CC, 177 .c_cc = INIT_C_CC,
178 .c_ispeed = 9600,
179 .c_ospeed = 9600,
200}; 180};
201 181
202/* 182/*
@@ -205,13 +185,12 @@ static struct termios stli_deftermios = {
205 */ 185 */
206static comstats_t stli_comstats; 186static comstats_t stli_comstats;
207static combrd_t stli_brdstats; 187static combrd_t stli_brdstats;
208static asystats_t stli_cdkstats; 188static struct asystats stli_cdkstats;
209static stlibrd_t stli_dummybrd;
210static stliport_t stli_dummyport;
211 189
212/*****************************************************************************/ 190/*****************************************************************************/
213 191
214static stlibrd_t *stli_brds[STL_MAXBRDS]; 192static DEFINE_MUTEX(stli_brdslock);
193static struct stlibrd *stli_brds[STL_MAXBRDS];
215 194
216static int stli_shared; 195static int stli_shared;
217 196
@@ -223,6 +202,7 @@ static int stli_shared;
223 */ 202 */
224#define BST_FOUND 0x1 203#define BST_FOUND 0x1
225#define BST_STARTED 0x2 204#define BST_STARTED 0x2
205#define BST_PROBED 0x4
226 206
227/* 207/*
228 * Define the set of port state flags. These are marked for internal 208 * Define the set of port state flags. These are marked for internal
@@ -255,18 +235,18 @@ static char *stli_brdnames[] = {
255 "Brumby", 235 "Brumby",
256 "Brumby", 236 "Brumby",
257 "ONboard-EI", 237 "ONboard-EI",
258 (char *) NULL, 238 NULL,
259 "ONboard", 239 "ONboard",
260 "ONboard-MC", 240 "ONboard-MC",
261 "ONboard-MC", 241 "ONboard-MC",
262 (char *) NULL, 242 NULL,
263 (char *) NULL, 243 NULL,
264 (char *) NULL, 244 NULL,
265 (char *) NULL, 245 NULL,
266 (char *) NULL, 246 NULL,
267 (char *) NULL, 247 NULL,
268 (char *) NULL, 248 NULL,
269 (char *) NULL, 249 NULL,
270 "EasyIO", 250 "EasyIO",
271 "EC8/32-AT", 251 "EC8/32-AT",
272 "EC8/32-MC", 252 "EC8/32-MC",
@@ -304,12 +284,10 @@ static char **stli_brdsp[] = {
304 * parse any module arguments. 284 * parse any module arguments.
305 */ 285 */
306 286
307typedef struct stlibrdtype { 287static struct stlibrdtype {
308 char *name; 288 char *name;
309 int type; 289 int type;
310} stlibrdtype_t; 290} stli_brdstr[] = {
311
312static stlibrdtype_t stli_brdstr[] = {
313 { "stallion", BRD_STALLION }, 291 { "stallion", BRD_STALLION },
314 { "1", BRD_STALLION }, 292 { "1", BRD_STALLION },
315 { "brumby", BRD_BRUMBY }, 293 { "brumby", BRD_BRUMBY },
@@ -379,6 +357,7 @@ MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
379module_param_array(board3, charp, NULL, 0); 357module_param_array(board3, charp, NULL, 0);
380MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]"); 358MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
381 359
360#if STLI_EISAPROBE != 0
382/* 361/*
383 * Set up a default memory address table for EISA board probing. 362 * Set up a default memory address table for EISA board probing.
384 * The default addresses are all bellow 1Mbyte, which has to be the 363 * The default addresses are all bellow 1Mbyte, which has to be the
@@ -396,14 +375,11 @@ static unsigned long stli_eisamemprobeaddrs[] = {
396}; 375};
397 376
398static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs); 377static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
378#endif
399 379
400/* 380/*
401 * Define the Stallion PCI vendor and device IDs. 381 * Define the Stallion PCI vendor and device IDs.
402 */ 382 */
403#ifdef CONFIG_PCI
404#ifndef PCI_VENDOR_ID_STALLION
405#define PCI_VENDOR_ID_STALLION 0x124d
406#endif
407#ifndef PCI_DEVICE_ID_ECRA 383#ifndef PCI_DEVICE_ID_ECRA
408#define PCI_DEVICE_ID_ECRA 0x0004 384#define PCI_DEVICE_ID_ECRA 0x0004
409#endif 385#endif
@@ -414,7 +390,7 @@ static struct pci_device_id istallion_pci_tbl[] = {
414}; 390};
415MODULE_DEVICE_TABLE(pci, istallion_pci_tbl); 391MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
416 392
417#endif /* CONFIG_PCI */ 393static struct pci_driver stli_pcidriver;
418 394
419/*****************************************************************************/ 395/*****************************************************************************/
420 396
@@ -615,22 +591,10 @@ MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
615/*****************************************************************************/ 591/*****************************************************************************/
616 592
617/* 593/*
618 * Define some handy local macros...
619 */
620#undef MIN
621#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
622
623#undef TOLOWER
624#define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
625
626/*****************************************************************************/
627
628/*
629 * Prototype all functions in this driver! 594 * Prototype all functions in this driver!
630 */ 595 */
631 596
632static int stli_parsebrd(stlconf_t *confp, char **argp); 597static int stli_parsebrd(struct stlconf *confp, char **argp);
633static int stli_init(void);
634static int stli_open(struct tty_struct *tty, struct file *filp); 598static int stli_open(struct tty_struct *tty, struct file *filp);
635static void stli_close(struct tty_struct *tty, struct file *filp); 599static void stli_close(struct tty_struct *tty, struct file *filp);
636static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count); 600static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
@@ -639,7 +603,7 @@ static void stli_flushchars(struct tty_struct *tty);
639static int stli_writeroom(struct tty_struct *tty); 603static int stli_writeroom(struct tty_struct *tty);
640static int stli_charsinbuffer(struct tty_struct *tty); 604static int stli_charsinbuffer(struct tty_struct *tty);
641static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg); 605static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
642static void stli_settermios(struct tty_struct *tty, struct termios *old); 606static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
643static void stli_throttle(struct tty_struct *tty); 607static void stli_throttle(struct tty_struct *tty);
644static void stli_unthrottle(struct tty_struct *tty); 608static void stli_unthrottle(struct tty_struct *tty);
645static void stli_stop(struct tty_struct *tty); 609static void stli_stop(struct tty_struct *tty);
@@ -649,86 +613,84 @@ static void stli_breakctl(struct tty_struct *tty, int state);
649static void stli_waituntilsent(struct tty_struct *tty, int timeout); 613static void stli_waituntilsent(struct tty_struct *tty, int timeout);
650static void stli_sendxchar(struct tty_struct *tty, char ch); 614static void stli_sendxchar(struct tty_struct *tty, char ch);
651static void stli_hangup(struct tty_struct *tty); 615static void stli_hangup(struct tty_struct *tty);
652static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos); 616static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos);
653 617
654static int stli_brdinit(stlibrd_t *brdp); 618static int stli_brdinit(struct stlibrd *brdp);
655static int stli_startbrd(stlibrd_t *brdp); 619static int stli_startbrd(struct stlibrd *brdp);
656static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); 620static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
657static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); 621static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
658static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 622static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
659static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp); 623static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
660static void stli_poll(unsigned long arg); 624static void stli_poll(unsigned long arg);
661static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp); 625static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
662static int stli_initopen(stlibrd_t *brdp, stliport_t *portp); 626static int stli_initopen(struct stlibrd *brdp, struct stliport *portp);
663static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait); 627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
664static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait); 628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
665static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp); 629static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp);
666static void stli_dohangup(struct work_struct *); 630static void stli_dohangup(struct work_struct *);
667static int stli_setport(stliport_t *portp); 631static int stli_setport(struct stliport *portp);
668static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 632static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
669static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 633static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
670static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 634static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
671static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp); 635static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
672static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp); 636static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
673static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); 637static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
674static long stli_mktiocm(unsigned long sigvalue); 638static long stli_mktiocm(unsigned long sigvalue);
675static void stli_read(stlibrd_t *brdp, stliport_t *portp); 639static void stli_read(struct stlibrd *brdp, struct stliport *portp);
676static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp); 640static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
677static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp); 641static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp);
678static int stli_getbrdstats(combrd_t __user *bp); 642static int stli_getbrdstats(combrd_t __user *bp);
679static int stli_getportstats(stliport_t *portp, comstats_t __user *cp); 643static int stli_getportstats(struct stliport *portp, comstats_t __user *cp);
680static int stli_portcmdstats(stliport_t *portp); 644static int stli_portcmdstats(struct stliport *portp);
681static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp); 645static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
682static int stli_getportstruct(stliport_t __user *arg); 646static int stli_getportstruct(struct stliport __user *arg);
683static int stli_getbrdstruct(stlibrd_t __user *arg); 647static int stli_getbrdstruct(struct stlibrd __user *arg);
684static stlibrd_t *stli_allocbrd(void); 648static struct stlibrd *stli_allocbrd(void);
685 649
686static void stli_ecpinit(stlibrd_t *brdp); 650static void stli_ecpinit(struct stlibrd *brdp);
687static void stli_ecpenable(stlibrd_t *brdp); 651static void stli_ecpenable(struct stlibrd *brdp);
688static void stli_ecpdisable(stlibrd_t *brdp); 652static void stli_ecpdisable(struct stlibrd *brdp);
689static void __iomem *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 653static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
690static void stli_ecpreset(stlibrd_t *brdp); 654static void stli_ecpreset(struct stlibrd *brdp);
691static void stli_ecpintr(stlibrd_t *brdp); 655static void stli_ecpintr(struct stlibrd *brdp);
692static void stli_ecpeiinit(stlibrd_t *brdp); 656static void stli_ecpeiinit(struct stlibrd *brdp);
693static void stli_ecpeienable(stlibrd_t *brdp); 657static void stli_ecpeienable(struct stlibrd *brdp);
694static void stli_ecpeidisable(stlibrd_t *brdp); 658static void stli_ecpeidisable(struct stlibrd *brdp);
695static void __iomem *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 659static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
696static void stli_ecpeireset(stlibrd_t *brdp); 660static void stli_ecpeireset(struct stlibrd *brdp);
697static void stli_ecpmcenable(stlibrd_t *brdp); 661static void stli_ecpmcenable(struct stlibrd *brdp);
698static void stli_ecpmcdisable(stlibrd_t *brdp); 662static void stli_ecpmcdisable(struct stlibrd *brdp);
699static void __iomem *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 663static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
700static void stli_ecpmcreset(stlibrd_t *brdp); 664static void stli_ecpmcreset(struct stlibrd *brdp);
701static void stli_ecppciinit(stlibrd_t *brdp); 665static void stli_ecppciinit(struct stlibrd *brdp);
702static void __iomem *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 666static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
703static void stli_ecppcireset(stlibrd_t *brdp); 667static void stli_ecppcireset(struct stlibrd *brdp);
704 668
705static void stli_onbinit(stlibrd_t *brdp); 669static void stli_onbinit(struct stlibrd *brdp);
706static void stli_onbenable(stlibrd_t *brdp); 670static void stli_onbenable(struct stlibrd *brdp);
707static void stli_onbdisable(stlibrd_t *brdp); 671static void stli_onbdisable(struct stlibrd *brdp);
708static void __iomem *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 672static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
709static void stli_onbreset(stlibrd_t *brdp); 673static void stli_onbreset(struct stlibrd *brdp);
710static void stli_onbeinit(stlibrd_t *brdp); 674static void stli_onbeinit(struct stlibrd *brdp);
711static void stli_onbeenable(stlibrd_t *brdp); 675static void stli_onbeenable(struct stlibrd *brdp);
712static void stli_onbedisable(stlibrd_t *brdp); 676static void stli_onbedisable(struct stlibrd *brdp);
713static void __iomem *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 677static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
714static void stli_onbereset(stlibrd_t *brdp); 678static void stli_onbereset(struct stlibrd *brdp);
715static void stli_bbyinit(stlibrd_t *brdp); 679static void stli_bbyinit(struct stlibrd *brdp);
716static void __iomem *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 680static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
717static void stli_bbyreset(stlibrd_t *brdp); 681static void stli_bbyreset(struct stlibrd *brdp);
718static void stli_stalinit(stlibrd_t *brdp); 682static void stli_stalinit(struct stlibrd *brdp);
719static void __iomem *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line); 683static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
720static void stli_stalreset(stlibrd_t *brdp); 684static void stli_stalreset(struct stlibrd *brdp);
721 685
722static stliport_t *stli_getport(int brdnr, int panelnr, int portnr); 686static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
723 687
724static int stli_initecp(stlibrd_t *brdp); 688static int stli_initecp(struct stlibrd *brdp);
725static int stli_initonb(stlibrd_t *brdp); 689static int stli_initonb(struct stlibrd *brdp);
726static int stli_eisamemprobe(stlibrd_t *brdp); 690#if STLI_EISAPROBE != 0
727static int stli_initports(stlibrd_t *brdp); 691static int stli_eisamemprobe(struct stlibrd *brdp);
728
729#ifdef CONFIG_PCI
730static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
731#endif 692#endif
693static int stli_initports(struct stlibrd *brdp);
732 694
733/*****************************************************************************/ 695/*****************************************************************************/
734 696
@@ -766,136 +728,19 @@ static int stli_timeron;
766 728
767static struct class *istallion_class; 729static struct class *istallion_class;
768 730
769/* 731static void stli_cleanup_ports(struct stlibrd *brdp)
770 * Loadable module initialization stuff.
771 */
772
773static int __init istallion_module_init(void)
774{
775 stli_init();
776 return 0;
777}
778
779/*****************************************************************************/
780
781static void __exit istallion_module_exit(void)
782{
783 stlibrd_t *brdp;
784 stliport_t *portp;
785 int i, j;
786
787 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
788 stli_drvversion);
789
790 /*
791 * Free up all allocated resources used by the ports. This includes
792 * memory and interrupts.
793 */
794 if (stli_timeron) {
795 stli_timeron = 0;
796 del_timer_sync(&stli_timerlist);
797 }
798
799 i = tty_unregister_driver(stli_serial);
800 if (i) {
801 printk("STALLION: failed to un-register tty driver, "
802 "errno=%d\n", -i);
803 return;
804 }
805 put_tty_driver(stli_serial);
806 for (i = 0; i < 4; i++)
807 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
808 class_destroy(istallion_class);
809 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
810 printk("STALLION: failed to un-register serial memory device, "
811 "errno=%d\n", -i);
812
813 kfree(stli_txcookbuf);
814
815 for (i = 0; (i < stli_nrbrds); i++) {
816 if ((brdp = stli_brds[i]) == NULL)
817 continue;
818 for (j = 0; (j < STL_MAXPORTS); j++) {
819 portp = brdp->ports[j];
820 if (portp != NULL) {
821 if (portp->tty != NULL)
822 tty_hangup(portp->tty);
823 kfree(portp);
824 }
825 }
826
827 iounmap(brdp->membase);
828 if (brdp->iosize > 0)
829 release_region(brdp->iobase, brdp->iosize);
830 kfree(brdp);
831 stli_brds[i] = NULL;
832 }
833}
834
835module_init(istallion_module_init);
836module_exit(istallion_module_exit);
837
838/*****************************************************************************/
839
840/*
841 * Check for any arguments passed in on the module load command line.
842 */
843
844static void stli_argbrds(void)
845{ 732{
846 stlconf_t conf; 733 struct stliport *portp;
847 stlibrd_t *brdp; 734 unsigned int j;
848 int i; 735
849 736 for (j = 0; j < STL_MAXPORTS; j++) {
850 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) { 737 portp = brdp->ports[j];
851 memset(&conf, 0, sizeof(conf)); 738 if (portp != NULL) {
852 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0) 739 if (portp->tty != NULL)
853 continue; 740 tty_hangup(portp->tty);
854 if ((brdp = stli_allocbrd()) == NULL) 741 kfree(portp);
855 continue;
856 stli_nrbrds = i + 1;
857 brdp->brdnr = i;
858 brdp->brdtype = conf.brdtype;
859 brdp->iobase = conf.ioaddr1;
860 brdp->memaddr = conf.memaddr;
861 stli_brdinit(brdp);
862 }
863}
864
865/*****************************************************************************/
866
867/*
868 * Convert an ascii string number into an unsigned long.
869 */
870
871static unsigned long stli_atol(char *str)
872{
873 unsigned long val;
874 int base, c;
875 char *sp;
876
877 val = 0;
878 sp = str;
879 if ((*sp == '0') && (*(sp+1) == 'x')) {
880 base = 16;
881 sp += 2;
882 } else if (*sp == '0') {
883 base = 8;
884 sp++;
885 } else {
886 base = 10;
887 }
888
889 for (; (*sp != 0); sp++) {
890 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
891 if ((c < 0) || (c >= base)) {
892 printk("STALLION: invalid argument %s\n", str);
893 val = 0;
894 break;
895 } 742 }
896 val = (val * base) + c;
897 } 743 }
898 return(val);
899} 744}
900 745
901/*****************************************************************************/ 746/*****************************************************************************/
@@ -904,16 +749,16 @@ static unsigned long stli_atol(char *str)
904 * Parse the supplied argument string, into the board conf struct. 749 * Parse the supplied argument string, into the board conf struct.
905 */ 750 */
906 751
907static int stli_parsebrd(stlconf_t *confp, char **argp) 752static int stli_parsebrd(struct stlconf *confp, char **argp)
908{ 753{
754 unsigned int i;
909 char *sp; 755 char *sp;
910 int i;
911 756
912 if (argp[0] == NULL || *argp[0] == 0) 757 if (argp[0] == NULL || *argp[0] == 0)
913 return 0; 758 return 0;
914 759
915 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 760 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
916 *sp = TOLOWER(*sp); 761 *sp = tolower(*sp);
917 762
918 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) { 763 for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
919 if (strcmp(stli_brdstr[i].name, argp[0]) == 0) 764 if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
@@ -926,9 +771,9 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
926 771
927 confp->brdtype = stli_brdstr[i].type; 772 confp->brdtype = stli_brdstr[i].type;
928 if (argp[1] != NULL && *argp[1] != 0) 773 if (argp[1] != NULL && *argp[1] != 0)
929 confp->ioaddr1 = stli_atol(argp[1]); 774 confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
930 if (argp[2] != NULL && *argp[2] != 0) 775 if (argp[2] != NULL && *argp[2] != 0)
931 confp->memaddr = stli_atol(argp[2]); 776 confp->memaddr = simple_strtoul(argp[2], NULL, 0);
932 return(1); 777 return(1);
933} 778}
934 779
@@ -936,10 +781,10 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
936 781
937static int stli_open(struct tty_struct *tty, struct file *filp) 782static int stli_open(struct tty_struct *tty, struct file *filp)
938{ 783{
939 stlibrd_t *brdp; 784 struct stlibrd *brdp;
940 stliport_t *portp; 785 struct stliport *portp;
941 unsigned int minordev; 786 unsigned int minordev, brdnr, portnr;
942 int brdnr, portnr, rc; 787 int rc;
943 788
944 minordev = tty->index; 789 minordev = tty->index;
945 brdnr = MINOR2BRD(minordev); 790 brdnr = MINOR2BRD(minordev);
@@ -951,7 +796,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
951 if ((brdp->state & BST_STARTED) == 0) 796 if ((brdp->state & BST_STARTED) == 0)
952 return -ENODEV; 797 return -ENODEV;
953 portnr = MINOR2PORT(minordev); 798 portnr = MINOR2PORT(minordev);
954 if ((portnr < 0) || (portnr > brdp->nrports)) 799 if (portnr > brdp->nrports)
955 return -ENODEV; 800 return -ENODEV;
956 801
957 portp = brdp->ports[portnr]; 802 portp = brdp->ports[portnr];
@@ -1031,8 +876,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1031 876
1032static void stli_close(struct tty_struct *tty, struct file *filp) 877static void stli_close(struct tty_struct *tty, struct file *filp)
1033{ 878{
1034 stlibrd_t *brdp; 879 struct stlibrd *brdp;
1035 stliport_t *portp; 880 struct stliport *portp;
1036 unsigned long flags; 881 unsigned long flags;
1037 882
1038 portp = tty->driver_data; 883 portp = tty->driver_data;
@@ -1109,7 +954,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1109 * this still all happens pretty quickly. 954 * this still all happens pretty quickly.
1110 */ 955 */
1111 956
1112static int stli_initopen(stlibrd_t *brdp, stliport_t *portp) 957static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
1113{ 958{
1114 struct tty_struct *tty; 959 struct tty_struct *tty;
1115 asynotify_t nt; 960 asynotify_t nt;
@@ -1157,7 +1002,7 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1157 * to overlap. 1002 * to overlap.
1158 */ 1003 */
1159 1004
1160static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1005static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1161{ 1006{
1162 cdkhdr_t __iomem *hdrp; 1007 cdkhdr_t __iomem *hdrp;
1163 cdkctrl_t __iomem *cp; 1008 cdkctrl_t __iomem *cp;
@@ -1228,7 +1073,7 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1228 * wait is true then must have user context (to sleep). 1073 * wait is true then must have user context (to sleep).
1229 */ 1074 */
1230 1075
1231static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1076static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
1232{ 1077{
1233 cdkhdr_t __iomem *hdrp; 1078 cdkhdr_t __iomem *hdrp;
1234 cdkctrl_t __iomem *cp; 1079 cdkctrl_t __iomem *cp;
@@ -1292,7 +1137,7 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1292 * to complete (as opposed to initiating the command then returning). 1137 * to complete (as opposed to initiating the command then returning).
1293 */ 1138 */
1294 1139
1295static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 1140static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
1296{ 1141{
1297 wait_event_interruptible(portp->raw_wait, 1142 wait_event_interruptible(portp->raw_wait,
1298 !test_bit(ST_CMDING, &portp->state)); 1143 !test_bit(ST_CMDING, &portp->state));
@@ -1318,16 +1163,16 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
1318 * waiting for the command to complete - so must have user context. 1163 * waiting for the command to complete - so must have user context.
1319 */ 1164 */
1320 1165
1321static int stli_setport(stliport_t *portp) 1166static int stli_setport(struct stliport *portp)
1322{ 1167{
1323 stlibrd_t *brdp; 1168 struct stlibrd *brdp;
1324 asyport_t aport; 1169 asyport_t aport;
1325 1170
1326 if (portp == NULL) 1171 if (portp == NULL)
1327 return -ENODEV; 1172 return -ENODEV;
1328 if (portp->tty == NULL) 1173 if (portp->tty == NULL)
1329 return -ENODEV; 1174 return -ENODEV;
1330 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds) 1175 if (portp->brdnr >= stli_nrbrds)
1331 return -ENODEV; 1176 return -ENODEV;
1332 brdp = stli_brds[portp->brdnr]; 1177 brdp = stli_brds[portp->brdnr];
1333 if (brdp == NULL) 1178 if (brdp == NULL)
@@ -1344,7 +1189,7 @@ static int stli_setport(stliport_t *portp)
1344 * maybe because if we are clocal then we don't need to wait... 1189 * maybe because if we are clocal then we don't need to wait...
1345 */ 1190 */
1346 1191
1347static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp) 1192static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp)
1348{ 1193{
1349 unsigned long flags; 1194 unsigned long flags;
1350 int rc, doclocal; 1195 int rc, doclocal;
@@ -1409,8 +1254,8 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1409 unsigned char __iomem *bits; 1254 unsigned char __iomem *bits;
1410 unsigned char __iomem *shbuf; 1255 unsigned char __iomem *shbuf;
1411 unsigned char *chbuf; 1256 unsigned char *chbuf;
1412 stliport_t *portp; 1257 struct stliport *portp;
1413 stlibrd_t *brdp; 1258 struct stlibrd *brdp;
1414 unsigned int len, stlen, head, tail, size; 1259 unsigned int len, stlen, head, tail, size;
1415 unsigned long flags; 1260 unsigned long flags;
1416 1261
@@ -1419,7 +1264,7 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1419 portp = tty->driver_data; 1264 portp = tty->driver_data;
1420 if (portp == NULL) 1265 if (portp == NULL)
1421 return 0; 1266 return 0;
1422 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1267 if (portp->brdnr >= stli_nrbrds)
1423 return 0; 1268 return 0;
1424 brdp = stli_brds[portp->brdnr]; 1269 brdp = stli_brds[portp->brdnr];
1425 if (brdp == NULL) 1270 if (brdp == NULL)
@@ -1445,12 +1290,12 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1445 stlen = len; 1290 stlen = len;
1446 } 1291 }
1447 1292
1448 len = MIN(len, count); 1293 len = min(len, (unsigned int)count);
1449 count = 0; 1294 count = 0;
1450 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset); 1295 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1451 1296
1452 while (len > 0) { 1297 while (len > 0) {
1453 stlen = MIN(len, stlen); 1298 stlen = min(len, stlen);
1454 memcpy_toio(shbuf + head, chbuf, stlen); 1299 memcpy_toio(shbuf + head, chbuf, stlen);
1455 chbuf += stlen; 1300 chbuf += stlen;
1456 len -= stlen; 1301 len -= stlen;
@@ -1516,8 +1361,8 @@ static void stli_flushchars(struct tty_struct *tty)
1516 unsigned char __iomem *bits; 1361 unsigned char __iomem *bits;
1517 cdkasy_t __iomem *ap; 1362 cdkasy_t __iomem *ap;
1518 struct tty_struct *cooktty; 1363 struct tty_struct *cooktty;
1519 stliport_t *portp; 1364 struct stliport *portp;
1520 stlibrd_t *brdp; 1365 struct stlibrd *brdp;
1521 unsigned int len, stlen, head, tail, size, count, cooksize; 1366 unsigned int len, stlen, head, tail, size, count, cooksize;
1522 unsigned char *buf; 1367 unsigned char *buf;
1523 unsigned char __iomem *shbuf; 1368 unsigned char __iomem *shbuf;
@@ -1541,7 +1386,7 @@ static void stli_flushchars(struct tty_struct *tty)
1541 portp = tty->driver_data; 1386 portp = tty->driver_data;
1542 if (portp == NULL) 1387 if (portp == NULL)
1543 return; 1388 return;
1544 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1389 if (portp->brdnr >= stli_nrbrds)
1545 return; 1390 return;
1546 brdp = stli_brds[portp->brdnr]; 1391 brdp = stli_brds[portp->brdnr];
1547 if (brdp == NULL) 1392 if (brdp == NULL)
@@ -1564,13 +1409,13 @@ static void stli_flushchars(struct tty_struct *tty)
1564 stlen = len; 1409 stlen = len;
1565 } 1410 }
1566 1411
1567 len = MIN(len, cooksize); 1412 len = min(len, cooksize);
1568 count = 0; 1413 count = 0;
1569 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset); 1414 shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
1570 buf = stli_txcookbuf; 1415 buf = stli_txcookbuf;
1571 1416
1572 while (len > 0) { 1417 while (len > 0) {
1573 stlen = MIN(len, stlen); 1418 stlen = min(len, stlen);
1574 memcpy_toio(shbuf + head, buf, stlen); 1419 memcpy_toio(shbuf + head, buf, stlen);
1575 buf += stlen; 1420 buf += stlen;
1576 len -= stlen; 1421 len -= stlen;
@@ -1604,8 +1449,8 @@ static void stli_flushchars(struct tty_struct *tty)
1604static int stli_writeroom(struct tty_struct *tty) 1449static int stli_writeroom(struct tty_struct *tty)
1605{ 1450{
1606 cdkasyrq_t __iomem *rp; 1451 cdkasyrq_t __iomem *rp;
1607 stliport_t *portp; 1452 struct stliport *portp;
1608 stlibrd_t *brdp; 1453 struct stlibrd *brdp;
1609 unsigned int head, tail, len; 1454 unsigned int head, tail, len;
1610 unsigned long flags; 1455 unsigned long flags;
1611 1456
@@ -1619,7 +1464,7 @@ static int stli_writeroom(struct tty_struct *tty)
1619 portp = tty->driver_data; 1464 portp = tty->driver_data;
1620 if (portp == NULL) 1465 if (portp == NULL)
1621 return 0; 1466 return 0;
1622 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1467 if (portp->brdnr >= stli_nrbrds)
1623 return 0; 1468 return 0;
1624 brdp = stli_brds[portp->brdnr]; 1469 brdp = stli_brds[portp->brdnr];
1625 if (brdp == NULL) 1470 if (brdp == NULL)
@@ -1657,8 +1502,8 @@ static int stli_writeroom(struct tty_struct *tty)
1657static int stli_charsinbuffer(struct tty_struct *tty) 1502static int stli_charsinbuffer(struct tty_struct *tty)
1658{ 1503{
1659 cdkasyrq_t __iomem *rp; 1504 cdkasyrq_t __iomem *rp;
1660 stliport_t *portp; 1505 struct stliport *portp;
1661 stlibrd_t *brdp; 1506 struct stlibrd *brdp;
1662 unsigned int head, tail, len; 1507 unsigned int head, tail, len;
1663 unsigned long flags; 1508 unsigned long flags;
1664 1509
@@ -1667,7 +1512,7 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1667 portp = tty->driver_data; 1512 portp = tty->driver_data;
1668 if (portp == NULL) 1513 if (portp == NULL)
1669 return 0; 1514 return 0;
1670 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1515 if (portp->brdnr >= stli_nrbrds)
1671 return 0; 1516 return 0;
1672 brdp = stli_brds[portp->brdnr]; 1517 brdp = stli_brds[portp->brdnr];
1673 if (brdp == NULL) 1518 if (brdp == NULL)
@@ -1695,10 +1540,10 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1695 * Generate the serial struct info. 1540 * Generate the serial struct info.
1696 */ 1541 */
1697 1542
1698static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp) 1543static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
1699{ 1544{
1700 struct serial_struct sio; 1545 struct serial_struct sio;
1701 stlibrd_t *brdp; 1546 struct stlibrd *brdp;
1702 1547
1703 memset(&sio, 0, sizeof(struct serial_struct)); 1548 memset(&sio, 0, sizeof(struct serial_struct));
1704 sio.type = PORT_UNKNOWN; 1549 sio.type = PORT_UNKNOWN;
@@ -1728,7 +1573,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1728 * just quietly ignore any requests to change irq, etc. 1573 * just quietly ignore any requests to change irq, etc.
1729 */ 1574 */
1730 1575
1731static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp) 1576static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp)
1732{ 1577{
1733 struct serial_struct sio; 1578 struct serial_struct sio;
1734 int rc; 1579 int rc;
@@ -1759,13 +1604,13 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1759 1604
1760static int stli_tiocmget(struct tty_struct *tty, struct file *file) 1605static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1761{ 1606{
1762 stliport_t *portp = tty->driver_data; 1607 struct stliport *portp = tty->driver_data;
1763 stlibrd_t *brdp; 1608 struct stlibrd *brdp;
1764 int rc; 1609 int rc;
1765 1610
1766 if (portp == NULL) 1611 if (portp == NULL)
1767 return -ENODEV; 1612 return -ENODEV;
1768 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1613 if (portp->brdnr >= stli_nrbrds)
1769 return 0; 1614 return 0;
1770 brdp = stli_brds[portp->brdnr]; 1615 brdp = stli_brds[portp->brdnr];
1771 if (brdp == NULL) 1616 if (brdp == NULL)
@@ -1783,13 +1628,13 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1783static int stli_tiocmset(struct tty_struct *tty, struct file *file, 1628static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1784 unsigned int set, unsigned int clear) 1629 unsigned int set, unsigned int clear)
1785{ 1630{
1786 stliport_t *portp = tty->driver_data; 1631 struct stliport *portp = tty->driver_data;
1787 stlibrd_t *brdp; 1632 struct stlibrd *brdp;
1788 int rts = -1, dtr = -1; 1633 int rts = -1, dtr = -1;
1789 1634
1790 if (portp == NULL) 1635 if (portp == NULL)
1791 return -ENODEV; 1636 return -ENODEV;
1792 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1637 if (portp->brdnr >= stli_nrbrds)
1793 return 0; 1638 return 0;
1794 brdp = stli_brds[portp->brdnr]; 1639 brdp = stli_brds[portp->brdnr];
1795 if (brdp == NULL) 1640 if (brdp == NULL)
@@ -1814,8 +1659,8 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1814 1659
1815static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1660static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1816{ 1661{
1817 stliport_t *portp; 1662 struct stliport *portp;
1818 stlibrd_t *brdp; 1663 struct stlibrd *brdp;
1819 unsigned int ival; 1664 unsigned int ival;
1820 int rc; 1665 int rc;
1821 void __user *argp = (void __user *)arg; 1666 void __user *argp = (void __user *)arg;
@@ -1823,7 +1668,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1823 portp = tty->driver_data; 1668 portp = tty->driver_data;
1824 if (portp == NULL) 1669 if (portp == NULL)
1825 return -ENODEV; 1670 return -ENODEV;
1826 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1671 if (portp->brdnr >= stli_nrbrds)
1827 return 0; 1672 return 0;
1828 brdp = stli_brds[portp->brdnr]; 1673 brdp = stli_brds[portp->brdnr];
1829 if (brdp == NULL) 1674 if (brdp == NULL)
@@ -1889,11 +1734,11 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1889 * Looks like it is true for the current ttys implementation..!! 1734 * Looks like it is true for the current ttys implementation..!!
1890 */ 1735 */
1891 1736
1892static void stli_settermios(struct tty_struct *tty, struct termios *old) 1737static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1893{ 1738{
1894 stliport_t *portp; 1739 struct stliport *portp;
1895 stlibrd_t *brdp; 1740 struct stlibrd *brdp;
1896 struct termios *tiosp; 1741 struct ktermios *tiosp;
1897 asyport_t aport; 1742 asyport_t aport;
1898 1743
1899 if (tty == NULL) 1744 if (tty == NULL)
@@ -1901,7 +1746,7 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
1901 portp = tty->driver_data; 1746 portp = tty->driver_data;
1902 if (portp == NULL) 1747 if (portp == NULL)
1903 return; 1748 return;
1904 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1749 if (portp->brdnr >= stli_nrbrds)
1905 return; 1750 return;
1906 brdp = stli_brds[portp->brdnr]; 1751 brdp = stli_brds[portp->brdnr];
1907 if (brdp == NULL) 1752 if (brdp == NULL)
@@ -1937,7 +1782,7 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
1937 1782
1938static void stli_throttle(struct tty_struct *tty) 1783static void stli_throttle(struct tty_struct *tty)
1939{ 1784{
1940 stliport_t *portp = tty->driver_data; 1785 struct stliport *portp = tty->driver_data;
1941 if (portp == NULL) 1786 if (portp == NULL)
1942 return; 1787 return;
1943 set_bit(ST_RXSTOP, &portp->state); 1788 set_bit(ST_RXSTOP, &portp->state);
@@ -1953,7 +1798,7 @@ static void stli_throttle(struct tty_struct *tty)
1953 1798
1954static void stli_unthrottle(struct tty_struct *tty) 1799static void stli_unthrottle(struct tty_struct *tty)
1955{ 1800{
1956 stliport_t *portp = tty->driver_data; 1801 struct stliport *portp = tty->driver_data;
1957 if (portp == NULL) 1802 if (portp == NULL)
1958 return; 1803 return;
1959 clear_bit(ST_RXSTOP, &portp->state); 1804 clear_bit(ST_RXSTOP, &portp->state);
@@ -1992,7 +1837,7 @@ static void stli_start(struct tty_struct *tty)
1992 1837
1993static void stli_dohangup(struct work_struct *ugly_api) 1838static void stli_dohangup(struct work_struct *ugly_api)
1994{ 1839{
1995 stliport_t *portp = container_of(ugly_api, stliport_t, tqhangup); 1840 struct stliport *portp = container_of(ugly_api, struct stliport, tqhangup);
1996 if (portp->tty != NULL) { 1841 if (portp->tty != NULL) {
1997 tty_hangup(portp->tty); 1842 tty_hangup(portp->tty);
1998 } 1843 }
@@ -2009,14 +1854,14 @@ static void stli_dohangup(struct work_struct *ugly_api)
2009 1854
2010static void stli_hangup(struct tty_struct *tty) 1855static void stli_hangup(struct tty_struct *tty)
2011{ 1856{
2012 stliport_t *portp; 1857 struct stliport *portp;
2013 stlibrd_t *brdp; 1858 struct stlibrd *brdp;
2014 unsigned long flags; 1859 unsigned long flags;
2015 1860
2016 portp = tty->driver_data; 1861 portp = tty->driver_data;
2017 if (portp == NULL) 1862 if (portp == NULL)
2018 return; 1863 return;
2019 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1864 if (portp->brdnr >= stli_nrbrds)
2020 return; 1865 return;
2021 brdp = stli_brds[portp->brdnr]; 1866 brdp = stli_brds[portp->brdnr];
2022 if (brdp == NULL) 1867 if (brdp == NULL)
@@ -2062,14 +1907,14 @@ static void stli_hangup(struct tty_struct *tty)
2062 1907
2063static void stli_flushbuffer(struct tty_struct *tty) 1908static void stli_flushbuffer(struct tty_struct *tty)
2064{ 1909{
2065 stliport_t *portp; 1910 struct stliport *portp;
2066 stlibrd_t *brdp; 1911 struct stlibrd *brdp;
2067 unsigned long ftype, flags; 1912 unsigned long ftype, flags;
2068 1913
2069 portp = tty->driver_data; 1914 portp = tty->driver_data;
2070 if (portp == NULL) 1915 if (portp == NULL)
2071 return; 1916 return;
2072 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1917 if (portp->brdnr >= stli_nrbrds)
2073 return; 1918 return;
2074 brdp = stli_brds[portp->brdnr]; 1919 brdp = stli_brds[portp->brdnr];
2075 if (brdp == NULL) 1920 if (brdp == NULL)
@@ -2099,14 +1944,14 @@ static void stli_flushbuffer(struct tty_struct *tty)
2099 1944
2100static void stli_breakctl(struct tty_struct *tty, int state) 1945static void stli_breakctl(struct tty_struct *tty, int state)
2101{ 1946{
2102 stlibrd_t *brdp; 1947 struct stlibrd *brdp;
2103 stliport_t *portp; 1948 struct stliport *portp;
2104 long arg; 1949 long arg;
2105 1950
2106 portp = tty->driver_data; 1951 portp = tty->driver_data;
2107 if (portp == NULL) 1952 if (portp == NULL)
2108 return; 1953 return;
2109 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 1954 if (portp->brdnr >= stli_nrbrds)
2110 return; 1955 return;
2111 brdp = stli_brds[portp->brdnr]; 1956 brdp = stli_brds[portp->brdnr];
2112 if (brdp == NULL) 1957 if (brdp == NULL)
@@ -2120,7 +1965,7 @@ static void stli_breakctl(struct tty_struct *tty, int state)
2120 1965
2121static void stli_waituntilsent(struct tty_struct *tty, int timeout) 1966static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2122{ 1967{
2123 stliport_t *portp; 1968 struct stliport *portp;
2124 unsigned long tend; 1969 unsigned long tend;
2125 1970
2126 if (tty == NULL) 1971 if (tty == NULL)
@@ -2146,14 +1991,14 @@ static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2146 1991
2147static void stli_sendxchar(struct tty_struct *tty, char ch) 1992static void stli_sendxchar(struct tty_struct *tty, char ch)
2148{ 1993{
2149 stlibrd_t *brdp; 1994 struct stlibrd *brdp;
2150 stliport_t *portp; 1995 struct stliport *portp;
2151 asyctrl_t actrl; 1996 asyctrl_t actrl;
2152 1997
2153 portp = tty->driver_data; 1998 portp = tty->driver_data;
2154 if (portp == NULL) 1999 if (portp == NULL)
2155 return; 2000 return;
2156 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds) 2001 if (portp->brdnr >= stli_nrbrds)
2157 return; 2002 return;
2158 brdp = stli_brds[portp->brdnr]; 2003 brdp = stli_brds[portp->brdnr];
2159 if (brdp == NULL) 2004 if (brdp == NULL)
@@ -2181,7 +2026,7 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2181 * short then padded with spaces). 2026 * short then padded with spaces).
2182 */ 2027 */
2183 2028
2184static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos) 2029static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portnr, char *pos)
2185{ 2030{
2186 char *sp, *uart; 2031 char *sp, *uart;
2187 int rc, cnt; 2032 int rc, cnt;
@@ -2244,9 +2089,9 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
2244 2089
2245static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 2090static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2246{ 2091{
2247 stlibrd_t *brdp; 2092 struct stlibrd *brdp;
2248 stliport_t *portp; 2093 struct stliport *portp;
2249 int brdnr, portnr, totalport; 2094 unsigned int brdnr, portnr, totalport;
2250 int curoff, maxoff; 2095 int curoff, maxoff;
2251 char *pos; 2096 char *pos;
2252 2097
@@ -2316,7 +2161,7 @@ stli_readdone:
2316 * entry point) 2161 * entry point)
2317 */ 2162 */
2318 2163
2319static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2164static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2320{ 2165{
2321 cdkhdr_t __iomem *hdrp; 2166 cdkhdr_t __iomem *hdrp;
2322 cdkctrl_t __iomem *cp; 2167 cdkctrl_t __iomem *cp;
@@ -2352,7 +2197,7 @@ static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd
2352 spin_unlock_irqrestore(&brd_lock, flags); 2197 spin_unlock_irqrestore(&brd_lock, flags);
2353} 2198}
2354 2199
2355static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2200static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
2356{ 2201{
2357 unsigned long flags; 2202 unsigned long flags;
2358 2203
@@ -2371,7 +2216,7 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
2371 * more chars to unload. 2216 * more chars to unload.
2372 */ 2217 */
2373 2218
2374static void stli_read(stlibrd_t *brdp, stliport_t *portp) 2219static void stli_read(struct stlibrd *brdp, struct stliport *portp)
2375{ 2220{
2376 cdkasyrq_t __iomem *rp; 2221 cdkasyrq_t __iomem *rp;
2377 char __iomem *shbuf; 2222 char __iomem *shbuf;
@@ -2406,7 +2251,7 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2406 while (len > 0) { 2251 while (len > 0) {
2407 unsigned char *cptr; 2252 unsigned char *cptr;
2408 2253
2409 stlen = MIN(len, stlen); 2254 stlen = min(len, stlen);
2410 tty_prepare_flip_string(tty, &cptr, stlen); 2255 tty_prepare_flip_string(tty, &cptr, stlen);
2411 memcpy_fromio(cptr, shbuf + tail, stlen); 2256 memcpy_fromio(cptr, shbuf + tail, stlen);
2412 len -= stlen; 2257 len -= stlen;
@@ -2433,7 +2278,7 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2433 * difficult to deal with them here. 2278 * difficult to deal with them here.
2434 */ 2279 */
2435 2280
2436static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp) 2281static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
2437{ 2282{
2438 int cmd; 2283 int cmd;
2439 2284
@@ -2481,7 +2326,7 @@ static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2481 * then port is still busy, otherwise no longer busy. 2326 * then port is still busy, otherwise no longer busy.
2482 */ 2327 */
2483 2328
2484static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp) 2329static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2485{ 2330{
2486 cdkasy_t __iomem *ap; 2331 cdkasy_t __iomem *ap;
2487 cdkctrl_t __iomem *cp; 2332 cdkctrl_t __iomem *cp;
@@ -2628,9 +2473,9 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2628 * at the cdk header structure. 2473 * at the cdk header structure.
2629 */ 2474 */
2630 2475
2631static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp) 2476static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
2632{ 2477{
2633 stliport_t *portp; 2478 struct stliport *portp;
2634 unsigned char hostbits[(STL_MAXCHANS / 8) + 1]; 2479 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2635 unsigned char slavebits[(STL_MAXCHANS / 8) + 1]; 2480 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2636 unsigned char __iomem *slavep; 2481 unsigned char __iomem *slavep;
@@ -2697,11 +2542,10 @@ static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2697static void stli_poll(unsigned long arg) 2542static void stli_poll(unsigned long arg)
2698{ 2543{
2699 cdkhdr_t __iomem *hdrp; 2544 cdkhdr_t __iomem *hdrp;
2700 stlibrd_t *brdp; 2545 struct stlibrd *brdp;
2701 int brdnr; 2546 unsigned int brdnr;
2702 2547
2703 stli_timerlist.expires = STLI_TIMEOUT; 2548 mod_timer(&stli_timerlist, STLI_TIMEOUT);
2704 add_timer(&stli_timerlist);
2705 2549
2706/* 2550/*
2707 * Check each board and do any servicing required. 2551 * Check each board and do any servicing required.
@@ -2730,7 +2574,7 @@ static void stli_poll(unsigned long arg)
2730 * the slave. 2574 * the slave.
2731 */ 2575 */
2732 2576
2733static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp) 2577static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp)
2734{ 2578{
2735 memset(pp, 0, sizeof(asyport_t)); 2579 memset(pp, 0, sizeof(asyport_t));
2736 2580
@@ -2879,13 +2723,13 @@ static long stli_mktiocm(unsigned long sigvalue)
2879 * we need to do here is set up the appropriate per port data structures. 2723 * we need to do here is set up the appropriate per port data structures.
2880 */ 2724 */
2881 2725
2882static int stli_initports(stlibrd_t *brdp) 2726static int stli_initports(struct stlibrd *brdp)
2883{ 2727{
2884 stliport_t *portp; 2728 struct stliport *portp;
2885 int i, panelnr, panelport; 2729 unsigned int i, panelnr, panelport;
2886 2730
2887 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2731 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
2888 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL); 2732 portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
2889 if (!portp) { 2733 if (!portp) {
2890 printk("STALLION: failed to allocate port structure\n"); 2734 printk("STALLION: failed to allocate port structure\n");
2891 continue; 2735 continue;
@@ -2919,7 +2763,7 @@ static int stli_initports(stlibrd_t *brdp)
2919 * All the following routines are board specific hardware operations. 2763 * All the following routines are board specific hardware operations.
2920 */ 2764 */
2921 2765
2922static void stli_ecpinit(stlibrd_t *brdp) 2766static void stli_ecpinit(struct stlibrd *brdp)
2923{ 2767{
2924 unsigned long memconf; 2768 unsigned long memconf;
2925 2769
@@ -2934,21 +2778,21 @@ static void stli_ecpinit(stlibrd_t *brdp)
2934 2778
2935/*****************************************************************************/ 2779/*****************************************************************************/
2936 2780
2937static void stli_ecpenable(stlibrd_t *brdp) 2781static void stli_ecpenable(struct stlibrd *brdp)
2938{ 2782{
2939 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR)); 2783 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
2940} 2784}
2941 2785
2942/*****************************************************************************/ 2786/*****************************************************************************/
2943 2787
2944static void stli_ecpdisable(stlibrd_t *brdp) 2788static void stli_ecpdisable(struct stlibrd *brdp)
2945{ 2789{
2946 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2790 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
2947} 2791}
2948 2792
2949/*****************************************************************************/ 2793/*****************************************************************************/
2950 2794
2951static void __iomem *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2795static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
2952{ 2796{
2953 void __iomem *ptr; 2797 void __iomem *ptr;
2954 unsigned char val; 2798 unsigned char val;
@@ -2969,7 +2813,7 @@ static void __iomem *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, in
2969 2813
2970/*****************************************************************************/ 2814/*****************************************************************************/
2971 2815
2972static void stli_ecpreset(stlibrd_t *brdp) 2816static void stli_ecpreset(struct stlibrd *brdp)
2973{ 2817{
2974 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 2818 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
2975 udelay(10); 2819 udelay(10);
@@ -2979,7 +2823,7 @@ static void stli_ecpreset(stlibrd_t *brdp)
2979 2823
2980/*****************************************************************************/ 2824/*****************************************************************************/
2981 2825
2982static void stli_ecpintr(stlibrd_t *brdp) 2826static void stli_ecpintr(struct stlibrd *brdp)
2983{ 2827{
2984 outb(0x1, brdp->iobase); 2828 outb(0x1, brdp->iobase);
2985} 2829}
@@ -2990,7 +2834,7 @@ static void stli_ecpintr(stlibrd_t *brdp)
2990 * The following set of functions act on ECP EISA boards. 2834 * The following set of functions act on ECP EISA boards.
2991 */ 2835 */
2992 2836
2993static void stli_ecpeiinit(stlibrd_t *brdp) 2837static void stli_ecpeiinit(struct stlibrd *brdp)
2994{ 2838{
2995 unsigned long memconf; 2839 unsigned long memconf;
2996 2840
@@ -3008,21 +2852,21 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
3008 2852
3009/*****************************************************************************/ 2853/*****************************************************************************/
3010 2854
3011static void stli_ecpeienable(stlibrd_t *brdp) 2855static void stli_ecpeienable(struct stlibrd *brdp)
3012{ 2856{
3013 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR)); 2857 outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
3014} 2858}
3015 2859
3016/*****************************************************************************/ 2860/*****************************************************************************/
3017 2861
3018static void stli_ecpeidisable(stlibrd_t *brdp) 2862static void stli_ecpeidisable(struct stlibrd *brdp)
3019{ 2863{
3020 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR)); 2864 outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
3021} 2865}
3022 2866
3023/*****************************************************************************/ 2867/*****************************************************************************/
3024 2868
3025static void __iomem *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2869static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3026{ 2870{
3027 void __iomem *ptr; 2871 void __iomem *ptr;
3028 unsigned char val; 2872 unsigned char val;
@@ -3046,7 +2890,7 @@ static void __iomem *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset,
3046 2890
3047/*****************************************************************************/ 2891/*****************************************************************************/
3048 2892
3049static void stli_ecpeireset(stlibrd_t *brdp) 2893static void stli_ecpeireset(struct stlibrd *brdp)
3050{ 2894{
3051 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); 2895 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3052 udelay(10); 2896 udelay(10);
@@ -3060,21 +2904,21 @@ static void stli_ecpeireset(stlibrd_t *brdp)
3060 * The following set of functions act on ECP MCA boards. 2904 * The following set of functions act on ECP MCA boards.
3061 */ 2905 */
3062 2906
3063static void stli_ecpmcenable(stlibrd_t *brdp) 2907static void stli_ecpmcenable(struct stlibrd *brdp)
3064{ 2908{
3065 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR)); 2909 outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
3066} 2910}
3067 2911
3068/*****************************************************************************/ 2912/*****************************************************************************/
3069 2913
3070static void stli_ecpmcdisable(stlibrd_t *brdp) 2914static void stli_ecpmcdisable(struct stlibrd *brdp)
3071{ 2915{
3072 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR)); 2916 outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
3073} 2917}
3074 2918
3075/*****************************************************************************/ 2919/*****************************************************************************/
3076 2920
3077static void __iomem *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2921static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3078{ 2922{
3079 void __iomem *ptr; 2923 void __iomem *ptr;
3080 unsigned char val; 2924 unsigned char val;
@@ -3095,7 +2939,7 @@ static void __iomem *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset,
3095 2939
3096/*****************************************************************************/ 2940/*****************************************************************************/
3097 2941
3098static void stli_ecpmcreset(stlibrd_t *brdp) 2942static void stli_ecpmcreset(struct stlibrd *brdp)
3099{ 2943{
3100 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR)); 2944 outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
3101 udelay(10); 2945 udelay(10);
@@ -3109,7 +2953,7 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
3109 * The following set of functions act on ECP PCI boards. 2953 * The following set of functions act on ECP PCI boards.
3110 */ 2954 */
3111 2955
3112static void stli_ecppciinit(stlibrd_t *brdp) 2956static void stli_ecppciinit(struct stlibrd *brdp)
3113{ 2957{
3114 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 2958 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3115 udelay(10); 2959 udelay(10);
@@ -3119,7 +2963,7 @@ static void stli_ecppciinit(stlibrd_t *brdp)
3119 2963
3120/*****************************************************************************/ 2964/*****************************************************************************/
3121 2965
3122static void __iomem *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2966static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3123{ 2967{
3124 void __iomem *ptr; 2968 void __iomem *ptr;
3125 unsigned char val; 2969 unsigned char val;
@@ -3140,7 +2984,7 @@ static void __iomem *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset,
3140 2984
3141/*****************************************************************************/ 2985/*****************************************************************************/
3142 2986
3143static void stli_ecppcireset(stlibrd_t *brdp) 2987static void stli_ecppcireset(struct stlibrd *brdp)
3144{ 2988{
3145 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 2989 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3146 udelay(10); 2990 udelay(10);
@@ -3154,7 +2998,7 @@ static void stli_ecppcireset(stlibrd_t *brdp)
3154 * The following routines act on ONboards. 2998 * The following routines act on ONboards.
3155 */ 2999 */
3156 3000
3157static void stli_onbinit(stlibrd_t *brdp) 3001static void stli_onbinit(struct stlibrd *brdp)
3158{ 3002{
3159 unsigned long memconf; 3003 unsigned long memconf;
3160 3004
@@ -3171,21 +3015,21 @@ static void stli_onbinit(stlibrd_t *brdp)
3171 3015
3172/*****************************************************************************/ 3016/*****************************************************************************/
3173 3017
3174static void stli_onbenable(stlibrd_t *brdp) 3018static void stli_onbenable(struct stlibrd *brdp)
3175{ 3019{
3176 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR)); 3020 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3177} 3021}
3178 3022
3179/*****************************************************************************/ 3023/*****************************************************************************/
3180 3024
3181static void stli_onbdisable(stlibrd_t *brdp) 3025static void stli_onbdisable(struct stlibrd *brdp)
3182{ 3026{
3183 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR)); 3027 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3184} 3028}
3185 3029
3186/*****************************************************************************/ 3030/*****************************************************************************/
3187 3031
3188static void __iomem *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3032static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3189{ 3033{
3190 void __iomem *ptr; 3034 void __iomem *ptr;
3191 3035
@@ -3202,7 +3046,7 @@ static void __iomem *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, in
3202 3046
3203/*****************************************************************************/ 3047/*****************************************************************************/
3204 3048
3205static void stli_onbreset(stlibrd_t *brdp) 3049static void stli_onbreset(struct stlibrd *brdp)
3206{ 3050{
3207 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3051 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3208 udelay(10); 3052 udelay(10);
@@ -3216,7 +3060,7 @@ static void stli_onbreset(stlibrd_t *brdp)
3216 * The following routines act on ONboard EISA. 3060 * The following routines act on ONboard EISA.
3217 */ 3061 */
3218 3062
3219static void stli_onbeinit(stlibrd_t *brdp) 3063static void stli_onbeinit(struct stlibrd *brdp)
3220{ 3064{
3221 unsigned long memconf; 3065 unsigned long memconf;
3222 3066
@@ -3236,21 +3080,21 @@ static void stli_onbeinit(stlibrd_t *brdp)
3236 3080
3237/*****************************************************************************/ 3081/*****************************************************************************/
3238 3082
3239static void stli_onbeenable(stlibrd_t *brdp) 3083static void stli_onbeenable(struct stlibrd *brdp)
3240{ 3084{
3241 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR)); 3085 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3242} 3086}
3243 3087
3244/*****************************************************************************/ 3088/*****************************************************************************/
3245 3089
3246static void stli_onbedisable(stlibrd_t *brdp) 3090static void stli_onbedisable(struct stlibrd *brdp)
3247{ 3091{
3248 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3092 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3249} 3093}
3250 3094
3251/*****************************************************************************/ 3095/*****************************************************************************/
3252 3096
3253static void __iomem *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3097static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3254{ 3098{
3255 void __iomem *ptr; 3099 void __iomem *ptr;
3256 unsigned char val; 3100 unsigned char val;
@@ -3274,7 +3118,7 @@ static void __iomem *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, i
3274 3118
3275/*****************************************************************************/ 3119/*****************************************************************************/
3276 3120
3277static void stli_onbereset(stlibrd_t *brdp) 3121static void stli_onbereset(struct stlibrd *brdp)
3278{ 3122{
3279 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3123 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3280 udelay(10); 3124 udelay(10);
@@ -3288,7 +3132,7 @@ static void stli_onbereset(stlibrd_t *brdp)
3288 * The following routines act on Brumby boards. 3132 * The following routines act on Brumby boards.
3289 */ 3133 */
3290 3134
3291static void stli_bbyinit(stlibrd_t *brdp) 3135static void stli_bbyinit(struct stlibrd *brdp)
3292{ 3136{
3293 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3137 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3294 udelay(10); 3138 udelay(10);
@@ -3300,7 +3144,7 @@ static void stli_bbyinit(stlibrd_t *brdp)
3300 3144
3301/*****************************************************************************/ 3145/*****************************************************************************/
3302 3146
3303static void __iomem *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3147static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3304{ 3148{
3305 void __iomem *ptr; 3149 void __iomem *ptr;
3306 unsigned char val; 3150 unsigned char val;
@@ -3315,7 +3159,7 @@ static void __iomem *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, in
3315 3159
3316/*****************************************************************************/ 3160/*****************************************************************************/
3317 3161
3318static void stli_bbyreset(stlibrd_t *brdp) 3162static void stli_bbyreset(struct stlibrd *brdp)
3319{ 3163{
3320 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3164 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3321 udelay(10); 3165 udelay(10);
@@ -3329,7 +3173,7 @@ static void stli_bbyreset(stlibrd_t *brdp)
3329 * The following routines act on original old Stallion boards. 3173 * The following routines act on original old Stallion boards.
3330 */ 3174 */
3331 3175
3332static void stli_stalinit(stlibrd_t *brdp) 3176static void stli_stalinit(struct stlibrd *brdp)
3333{ 3177{
3334 outb(0x1, brdp->iobase); 3178 outb(0x1, brdp->iobase);
3335 mdelay(1000); 3179 mdelay(1000);
@@ -3337,7 +3181,7 @@ static void stli_stalinit(stlibrd_t *brdp)
3337 3181
3338/*****************************************************************************/ 3182/*****************************************************************************/
3339 3183
3340static void __iomem *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3184static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
3341{ 3185{
3342 BUG_ON(offset > brdp->memsize); 3186 BUG_ON(offset > brdp->memsize);
3343 return brdp->membase + (offset % STAL_PAGESIZE); 3187 return brdp->membase + (offset % STAL_PAGESIZE);
@@ -3345,7 +3189,7 @@ static void __iomem *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, i
3345 3189
3346/*****************************************************************************/ 3190/*****************************************************************************/
3347 3191
3348static void stli_stalreset(stlibrd_t *brdp) 3192static void stli_stalreset(struct stlibrd *brdp)
3349{ 3193{
3350 u32 __iomem *vecp; 3194 u32 __iomem *vecp;
3351 3195
@@ -3362,21 +3206,22 @@ static void stli_stalreset(stlibrd_t *brdp)
3362 * board types. 3206 * board types.
3363 */ 3207 */
3364 3208
3365static int stli_initecp(stlibrd_t *brdp) 3209static int stli_initecp(struct stlibrd *brdp)
3366{ 3210{
3367 cdkecpsig_t sig; 3211 cdkecpsig_t sig;
3368 cdkecpsig_t __iomem *sigsp; 3212 cdkecpsig_t __iomem *sigsp;
3369 unsigned int status, nxtid; 3213 unsigned int status, nxtid;
3370 char *name; 3214 char *name;
3371 int panelnr, nrports; 3215 int retval, panelnr, nrports;
3372 3216
3373 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3217 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) {
3374 return -EIO; 3218 retval = -ENODEV;
3375 3219 goto err;
3376 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3220 }
3377 { 3221
3378 release_region(brdp->iobase, brdp->iosize); 3222 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
3379 return -ENODEV; 3223 retval = -EIO;
3224 goto err;
3380 } 3225 }
3381 3226
3382 brdp->iosize = ECP_IOSIZE; 3227 brdp->iosize = ECP_IOSIZE;
@@ -3388,7 +3233,6 @@ static int stli_initecp(stlibrd_t *brdp)
3388 */ 3233 */
3389 switch (brdp->brdtype) { 3234 switch (brdp->brdtype) {
3390 case BRD_ECP: 3235 case BRD_ECP:
3391 brdp->membase = (void *) brdp->memaddr;
3392 brdp->memsize = ECP_MEMSIZE; 3236 brdp->memsize = ECP_MEMSIZE;
3393 brdp->pagesize = ECP_ATPAGESIZE; 3237 brdp->pagesize = ECP_ATPAGESIZE;
3394 brdp->init = stli_ecpinit; 3238 brdp->init = stli_ecpinit;
@@ -3402,7 +3246,6 @@ static int stli_initecp(stlibrd_t *brdp)
3402 break; 3246 break;
3403 3247
3404 case BRD_ECPE: 3248 case BRD_ECPE:
3405 brdp->membase = (void *) brdp->memaddr;
3406 brdp->memsize = ECP_MEMSIZE; 3249 brdp->memsize = ECP_MEMSIZE;
3407 brdp->pagesize = ECP_EIPAGESIZE; 3250 brdp->pagesize = ECP_EIPAGESIZE;
3408 brdp->init = stli_ecpeiinit; 3251 brdp->init = stli_ecpeiinit;
@@ -3416,7 +3259,6 @@ static int stli_initecp(stlibrd_t *brdp)
3416 break; 3259 break;
3417 3260
3418 case BRD_ECPMC: 3261 case BRD_ECPMC:
3419 brdp->membase = (void *) brdp->memaddr;
3420 brdp->memsize = ECP_MEMSIZE; 3262 brdp->memsize = ECP_MEMSIZE;
3421 brdp->pagesize = ECP_MCPAGESIZE; 3263 brdp->pagesize = ECP_MCPAGESIZE;
3422 brdp->init = NULL; 3264 brdp->init = NULL;
@@ -3430,7 +3272,6 @@ static int stli_initecp(stlibrd_t *brdp)
3430 break; 3272 break;
3431 3273
3432 case BRD_ECPPCI: 3274 case BRD_ECPPCI:
3433 brdp->membase = (void *) brdp->memaddr;
3434 brdp->memsize = ECP_PCIMEMSIZE; 3275 brdp->memsize = ECP_PCIMEMSIZE;
3435 brdp->pagesize = ECP_PCIPAGESIZE; 3276 brdp->pagesize = ECP_PCIPAGESIZE;
3436 brdp->init = stli_ecppciinit; 3277 brdp->init = stli_ecppciinit;
@@ -3444,8 +3285,8 @@ static int stli_initecp(stlibrd_t *brdp)
3444 break; 3285 break;
3445 3286
3446 default: 3287 default:
3447 release_region(brdp->iobase, brdp->iosize); 3288 retval = -EINVAL;
3448 return -EINVAL; 3289 goto err_reg;
3449 } 3290 }
3450 3291
3451/* 3292/*
@@ -3457,10 +3298,9 @@ static int stli_initecp(stlibrd_t *brdp)
3457 EBRDINIT(brdp); 3298 EBRDINIT(brdp);
3458 3299
3459 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3300 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3460 if (brdp->membase == NULL) 3301 if (brdp->membase == NULL) {
3461 { 3302 retval = -ENOMEM;
3462 release_region(brdp->iobase, brdp->iosize); 3303 goto err_reg;
3463 return -ENOMEM;
3464 } 3304 }
3465 3305
3466/* 3306/*
@@ -3473,12 +3313,9 @@ static int stli_initecp(stlibrd_t *brdp)
3473 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t)); 3313 memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
3474 EBRDDISABLE(brdp); 3314 EBRDDISABLE(brdp);
3475 3315
3476 if (sig.magic != cpu_to_le32(ECP_MAGIC)) 3316 if (sig.magic != cpu_to_le32(ECP_MAGIC)) {
3477 { 3317 retval = -ENODEV;
3478 release_region(brdp->iobase, brdp->iosize); 3318 goto err_unmap;
3479 iounmap(brdp->membase);
3480 brdp->membase = NULL;
3481 return -ENODEV;
3482 } 3319 }
3483 3320
3484/* 3321/*
@@ -3503,6 +3340,13 @@ static int stli_initecp(stlibrd_t *brdp)
3503 3340
3504 brdp->state |= BST_FOUND; 3341 brdp->state |= BST_FOUND;
3505 return 0; 3342 return 0;
3343err_unmap:
3344 iounmap(brdp->membase);
3345 brdp->membase = NULL;
3346err_reg:
3347 release_region(brdp->iobase, brdp->iosize);
3348err:
3349 return retval;
3506} 3350}
3507 3351
3508/*****************************************************************************/ 3352/*****************************************************************************/
@@ -3512,23 +3356,27 @@ static int stli_initecp(stlibrd_t *brdp)
3512 * This handles only these board types. 3356 * This handles only these board types.
3513 */ 3357 */
3514 3358
3515static int stli_initonb(stlibrd_t *brdp) 3359static int stli_initonb(struct stlibrd *brdp)
3516{ 3360{
3517 cdkonbsig_t sig; 3361 cdkonbsig_t sig;
3518 cdkonbsig_t __iomem *sigsp; 3362 cdkonbsig_t __iomem *sigsp;
3519 char *name; 3363 char *name;
3520 int i; 3364 int i, retval;
3521 3365
3522/* 3366/*
3523 * Do a basic sanity check on the IO and memory addresses. 3367 * Do a basic sanity check on the IO and memory addresses.
3524 */ 3368 */
3525 if (brdp->iobase == 0 || brdp->memaddr == 0) 3369 if (brdp->iobase == 0 || brdp->memaddr == 0) {
3526 return -ENODEV; 3370 retval = -ENODEV;
3371 goto err;
3372 }
3527 3373
3528 brdp->iosize = ONB_IOSIZE; 3374 brdp->iosize = ONB_IOSIZE;
3529 3375
3530 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3376 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
3531 return -EIO; 3377 retval = -EIO;
3378 goto err;
3379 }
3532 3380
3533/* 3381/*
3534 * Based on the specific board type setup the common vars to access 3382 * Based on the specific board type setup the common vars to access
@@ -3537,10 +3385,7 @@ static int stli_initonb(stlibrd_t *brdp)
3537 */ 3385 */
3538 switch (brdp->brdtype) { 3386 switch (brdp->brdtype) {
3539 case BRD_ONBOARD: 3387 case BRD_ONBOARD:
3540 case BRD_ONBOARD32:
3541 case BRD_ONBOARD2: 3388 case BRD_ONBOARD2:
3542 case BRD_ONBOARD2_32:
3543 case BRD_ONBOARDRS:
3544 brdp->memsize = ONB_MEMSIZE; 3389 brdp->memsize = ONB_MEMSIZE;
3545 brdp->pagesize = ONB_ATPAGESIZE; 3390 brdp->pagesize = ONB_ATPAGESIZE;
3546 brdp->init = stli_onbinit; 3391 brdp->init = stli_onbinit;
@@ -3571,8 +3416,6 @@ static int stli_initonb(stlibrd_t *brdp)
3571 break; 3416 break;
3572 3417
3573 case BRD_BRUMBY4: 3418 case BRD_BRUMBY4:
3574 case BRD_BRUMBY8:
3575 case BRD_BRUMBY16:
3576 brdp->memsize = BBY_MEMSIZE; 3419 brdp->memsize = BBY_MEMSIZE;
3577 brdp->pagesize = BBY_PAGESIZE; 3420 brdp->pagesize = BBY_PAGESIZE;
3578 brdp->init = stli_bbyinit; 3421 brdp->init = stli_bbyinit;
@@ -3599,8 +3442,8 @@ static int stli_initonb(stlibrd_t *brdp)
3599 break; 3442 break;
3600 3443
3601 default: 3444 default:
3602 release_region(brdp->iobase, brdp->iosize); 3445 retval = -EINVAL;
3603 return -EINVAL; 3446 goto err_reg;
3604 } 3447 }
3605 3448
3606/* 3449/*
@@ -3612,10 +3455,9 @@ static int stli_initonb(stlibrd_t *brdp)
3612 EBRDINIT(brdp); 3455 EBRDINIT(brdp);
3613 3456
3614 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3457 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3615 if (brdp->membase == NULL) 3458 if (brdp->membase == NULL) {
3616 { 3459 retval = -ENOMEM;
3617 release_region(brdp->iobase, brdp->iosize); 3460 goto err_reg;
3618 return -ENOMEM;
3619 } 3461 }
3620 3462
3621/* 3463/*
@@ -3631,12 +3473,9 @@ static int stli_initonb(stlibrd_t *brdp)
3631 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) || 3473 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
3632 sig.magic1 != cpu_to_le16(ONB_MAGIC1) || 3474 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
3633 sig.magic2 != cpu_to_le16(ONB_MAGIC2) || 3475 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
3634 sig.magic3 != cpu_to_le16(ONB_MAGIC3)) 3476 sig.magic3 != cpu_to_le16(ONB_MAGIC3)) {
3635 { 3477 retval = -ENODEV;
3636 release_region(brdp->iobase, brdp->iosize); 3478 goto err_unmap;
3637 iounmap(brdp->membase);
3638 brdp->membase = NULL;
3639 return -ENODEV;
3640 } 3479 }
3641 3480
3642/* 3481/*
@@ -3658,6 +3497,13 @@ static int stli_initonb(stlibrd_t *brdp)
3658 3497
3659 brdp->state |= BST_FOUND; 3498 brdp->state |= BST_FOUND;
3660 return 0; 3499 return 0;
3500err_unmap:
3501 iounmap(brdp->membase);
3502 brdp->membase = NULL;
3503err_reg:
3504 release_region(brdp->iobase, brdp->iosize);
3505err:
3506 return retval;
3661} 3507}
3662 3508
3663/*****************************************************************************/ 3509/*****************************************************************************/
@@ -3668,14 +3514,15 @@ static int stli_initonb(stlibrd_t *brdp)
3668 * read in the memory map, and get the show on the road... 3514 * read in the memory map, and get the show on the road...
3669 */ 3515 */
3670 3516
3671static int stli_startbrd(stlibrd_t *brdp) 3517static int stli_startbrd(struct stlibrd *brdp)
3672{ 3518{
3673 cdkhdr_t __iomem *hdrp; 3519 cdkhdr_t __iomem *hdrp;
3674 cdkmem_t __iomem *memp; 3520 cdkmem_t __iomem *memp;
3675 cdkasy_t __iomem *ap; 3521 cdkasy_t __iomem *ap;
3676 unsigned long flags; 3522 unsigned long flags;
3677 stliport_t *portp; 3523 unsigned int portnr, nrdevs, i;
3678 int portnr, nrdevs, i, rc = 0; 3524 struct stliport *portp;
3525 int rc = 0;
3679 u32 memoff; 3526 u32 memoff;
3680 3527
3681 spin_lock_irqsave(&brd_lock, flags); 3528 spin_lock_irqsave(&brd_lock, flags);
@@ -3762,8 +3609,7 @@ stli_donestartup:
3762 3609
3763 if (! stli_timeron) { 3610 if (! stli_timeron) {
3764 stli_timeron++; 3611 stli_timeron++;
3765 stli_timerlist.expires = STLI_TIMEOUT; 3612 mod_timer(&stli_timerlist, STLI_TIMEOUT);
3766 add_timer(&stli_timerlist);
3767 } 3613 }
3768 3614
3769 return rc; 3615 return rc;
@@ -3775,49 +3621,32 @@ stli_donestartup:
3775 * Probe and initialize the specified board. 3621 * Probe and initialize the specified board.
3776 */ 3622 */
3777 3623
3778static int __init stli_brdinit(stlibrd_t *brdp) 3624static int __devinit stli_brdinit(struct stlibrd *brdp)
3779{ 3625{
3780 stli_brds[brdp->brdnr] = brdp; 3626 int retval;
3781 3627
3782 switch (brdp->brdtype) { 3628 switch (brdp->brdtype) {
3783 case BRD_ECP: 3629 case BRD_ECP:
3784 case BRD_ECPE: 3630 case BRD_ECPE:
3785 case BRD_ECPMC: 3631 case BRD_ECPMC:
3786 case BRD_ECPPCI: 3632 case BRD_ECPPCI:
3787 stli_initecp(brdp); 3633 retval = stli_initecp(brdp);
3788 break; 3634 break;
3789 case BRD_ONBOARD: 3635 case BRD_ONBOARD:
3790 case BRD_ONBOARDE: 3636 case BRD_ONBOARDE:
3791 case BRD_ONBOARD2: 3637 case BRD_ONBOARD2:
3792 case BRD_ONBOARD32:
3793 case BRD_ONBOARD2_32:
3794 case BRD_ONBOARDRS:
3795 case BRD_BRUMBY4: 3638 case BRD_BRUMBY4:
3796 case BRD_BRUMBY8:
3797 case BRD_BRUMBY16:
3798 case BRD_STALLION: 3639 case BRD_STALLION:
3799 stli_initonb(brdp); 3640 retval = stli_initonb(brdp);
3800 break; 3641 break;
3801 case BRD_EASYIO:
3802 case BRD_ECH:
3803 case BRD_ECHMC:
3804 case BRD_ECHPCI:
3805 printk(KERN_ERR "STALLION: %s board type not supported in "
3806 "this driver\n", stli_brdnames[brdp->brdtype]);
3807 return -ENODEV;
3808 default: 3642 default:
3809 printk(KERN_ERR "STALLION: board=%d is unknown board " 3643 printk(KERN_ERR "STALLION: board=%d is unknown board "
3810 "type=%d\n", brdp->brdnr, brdp->brdtype); 3644 "type=%d\n", brdp->brdnr, brdp->brdtype);
3811 return -ENODEV; 3645 retval = -ENODEV;
3812 } 3646 }
3813 3647
3814 if ((brdp->state & BST_FOUND) == 0) { 3648 if (retval)
3815 printk(KERN_ERR "STALLION: %s board not found, board=%d " 3649 return retval;
3816 "io=%x mem=%x\n",
3817 stli_brdnames[brdp->brdtype], brdp->brdnr,
3818 brdp->iobase, (int) brdp->memaddr);
3819 return -ENODEV;
3820 }
3821 3650
3822 stli_initports(brdp); 3651 stli_initports(brdp);
3823 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x " 3652 printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
@@ -3827,6 +3656,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
3827 return 0; 3656 return 0;
3828} 3657}
3829 3658
3659#if STLI_EISAPROBE != 0
3830/*****************************************************************************/ 3660/*****************************************************************************/
3831 3661
3832/* 3662/*
@@ -3834,7 +3664,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
3834 * might be. This is a bit if hack, but it is the best we can do. 3664 * might be. This is a bit if hack, but it is the best we can do.
3835 */ 3665 */
3836 3666
3837static int stli_eisamemprobe(stlibrd_t *brdp) 3667static int stli_eisamemprobe(struct stlibrd *brdp)
3838{ 3668{
3839 cdkecpsig_t ecpsig, __iomem *ecpsigp; 3669 cdkecpsig_t ecpsig, __iomem *ecpsigp;
3840 cdkonbsig_t onbsig, __iomem *onbsigp; 3670 cdkonbsig_t onbsig, __iomem *onbsigp;
@@ -3920,10 +3750,11 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
3920 } 3750 }
3921 return 0; 3751 return 0;
3922} 3752}
3753#endif
3923 3754
3924static int stli_getbrdnr(void) 3755static int stli_getbrdnr(void)
3925{ 3756{
3926 int i; 3757 unsigned int i;
3927 3758
3928 for (i = 0; i < STL_MAXBRDS; i++) { 3759 for (i = 0; i < STL_MAXBRDS; i++) {
3929 if (!stli_brds[i]) { 3760 if (!stli_brds[i]) {
@@ -3935,6 +3766,7 @@ static int stli_getbrdnr(void)
3935 return -1; 3766 return -1;
3936} 3767}
3937 3768
3769#if STLI_EISAPROBE != 0
3938/*****************************************************************************/ 3770/*****************************************************************************/
3939 3771
3940/* 3772/*
@@ -3949,9 +3781,9 @@ static int stli_getbrdnr(void)
3949 3781
3950static int stli_findeisabrds(void) 3782static int stli_findeisabrds(void)
3951{ 3783{
3952 stlibrd_t *brdp; 3784 struct stlibrd *brdp;
3953 unsigned int iobase, eid; 3785 unsigned int iobase, eid, i;
3954 int i; 3786 int brdnr, found = 0;
3955 3787
3956/* 3788/*
3957 * Firstly check if this is an EISA system. If this is not an EISA system then 3789 * Firstly check if this is an EISA system. If this is not an EISA system then
@@ -3989,9 +3821,11 @@ static int stli_findeisabrds(void)
3989 * Allocate a board structure and initialize it. 3821 * Allocate a board structure and initialize it.
3990 */ 3822 */
3991 if ((brdp = stli_allocbrd()) == NULL) 3823 if ((brdp = stli_allocbrd()) == NULL)
3992 return -ENOMEM; 3824 return found ? : -ENOMEM;
3993 if ((brdp->brdnr = stli_getbrdnr()) < 0) 3825 brdnr = stli_getbrdnr();
3994 return -ENOMEM; 3826 if (brdnr < 0)
3827 return found ? : -ENOMEM;
3828 brdp->brdnr = (unsigned int)brdnr;
3995 eid = inb(iobase + 0xc82); 3829 eid = inb(iobase + 0xc82);
3996 if (eid == ECP_EISAID) 3830 if (eid == ECP_EISAID)
3997 brdp->brdtype = BRD_ECPE; 3831 brdp->brdtype = BRD_ECPE;
@@ -4003,11 +3837,24 @@ static int stli_findeisabrds(void)
4003 outb(0x1, (iobase + 0xc84)); 3837 outb(0x1, (iobase + 0xc84));
4004 if (stli_eisamemprobe(brdp)) 3838 if (stli_eisamemprobe(brdp))
4005 outb(0, (iobase + 0xc84)); 3839 outb(0, (iobase + 0xc84));
4006 stli_brdinit(brdp); 3840 if (stli_brdinit(brdp) < 0) {
3841 kfree(brdp);
3842 continue;
3843 }
3844
3845 stli_brds[brdp->brdnr] = brdp;
3846 found++;
3847
3848 for (i = 0; i < brdp->nrports; i++)
3849 tty_register_device(stli_serial,
3850 brdp->brdnr * STL_MAXPORTS + i, NULL);
4007 } 3851 }
4008 3852
4009 return 0; 3853 return found;
4010} 3854}
3855#else
3856static inline int stli_findeisabrds(void) { return 0; }
3857#endif
4011 3858
4012/*****************************************************************************/ 3859/*****************************************************************************/
4013 3860
@@ -4017,72 +3864,104 @@ static int stli_findeisabrds(void)
4017 3864
4018/*****************************************************************************/ 3865/*****************************************************************************/
4019 3866
4020#ifdef CONFIG_PCI
4021
4022/* 3867/*
4023 * We have a Stallion board. Allocate a board structure and 3868 * We have a Stallion board. Allocate a board structure and
4024 * initialize it. Read its IO and MEMORY resources from PCI 3869 * initialize it. Read its IO and MEMORY resources from PCI
4025 * configuration space. 3870 * configuration space.
4026 */ 3871 */
4027 3872
4028static int stli_initpcibrd(int brdtype, struct pci_dev *devp) 3873static int __devinit stli_pciprobe(struct pci_dev *pdev,
3874 const struct pci_device_id *ent)
4029{ 3875{
4030 stlibrd_t *brdp; 3876 struct stlibrd *brdp;
4031 3877 unsigned int i;
4032 if (pci_enable_device(devp)) 3878 int brdnr, retval = -EIO;
4033 return -EIO; 3879
4034 if ((brdp = stli_allocbrd()) == NULL) 3880 retval = pci_enable_device(pdev);
4035 return -ENOMEM; 3881 if (retval)
4036 if ((brdp->brdnr = stli_getbrdnr()) < 0) { 3882 goto err;
3883 brdp = stli_allocbrd();
3884 if (brdp == NULL) {
3885 retval = -ENOMEM;
3886 goto err;
3887 }
3888 mutex_lock(&stli_brdslock);
3889 brdnr = stli_getbrdnr();
3890 if (brdnr < 0) {
4037 printk(KERN_INFO "STALLION: too many boards found, " 3891 printk(KERN_INFO "STALLION: too many boards found, "
4038 "maximum supported %d\n", STL_MAXBRDS); 3892 "maximum supported %d\n", STL_MAXBRDS);
4039 return 0; 3893 mutex_unlock(&stli_brdslock);
3894 retval = -EIO;
3895 goto err_fr;
4040 } 3896 }
4041 brdp->brdtype = brdtype; 3897 brdp->brdnr = (unsigned int)brdnr;
3898 stli_brds[brdp->brdnr] = brdp;
3899 mutex_unlock(&stli_brdslock);
3900 brdp->brdtype = BRD_ECPPCI;
4042/* 3901/*
4043 * We have all resources from the board, so lets setup the actual 3902 * We have all resources from the board, so lets setup the actual
4044 * board structure now. 3903 * board structure now.
4045 */ 3904 */
4046 brdp->iobase = pci_resource_start(devp, 3); 3905 brdp->iobase = pci_resource_start(pdev, 3);
4047 brdp->memaddr = pci_resource_start(devp, 2); 3906 brdp->memaddr = pci_resource_start(pdev, 2);
4048 stli_brdinit(brdp); 3907 retval = stli_brdinit(brdp);
3908 if (retval)
3909 goto err_null;
3910
3911 brdp->state |= BST_PROBED;
3912 pci_set_drvdata(pdev, brdp);
3913
3914 EBRDENABLE(brdp);
3915 brdp->enable = NULL;
3916 brdp->disable = NULL;
3917
3918 for (i = 0; i < brdp->nrports; i++)
3919 tty_register_device(stli_serial, brdp->brdnr * STL_MAXPORTS + i,
3920 &pdev->dev);
4049 3921
4050 return 0; 3922 return 0;
3923err_null:
3924 stli_brds[brdp->brdnr] = NULL;
3925err_fr:
3926 kfree(brdp);
3927err:
3928 return retval;
4051} 3929}
4052 3930
4053/*****************************************************************************/ 3931static void stli_pciremove(struct pci_dev *pdev)
3932{
3933 struct stlibrd *brdp = pci_get_drvdata(pdev);
4054 3934
4055/* 3935 stli_cleanup_ports(brdp);
4056 * Find all Stallion PCI boards that might be installed. Initialize each
4057 * one as it is found.
4058 */
4059 3936
4060static int stli_findpcibrds(void) 3937 iounmap(brdp->membase);
4061{ 3938 if (brdp->iosize > 0)
4062 struct pci_dev *dev = NULL; 3939 release_region(brdp->iobase, brdp->iosize);
4063 3940
4064 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) { 3941 stli_brds[brdp->brdnr] = NULL;
4065 stli_initpcibrd(BRD_ECPPCI, dev); 3942 kfree(brdp);
4066 }
4067 return 0;
4068} 3943}
4069 3944
4070#endif 3945static struct pci_driver stli_pcidriver = {
4071 3946 .name = "istallion",
3947 .id_table = istallion_pci_tbl,
3948 .probe = stli_pciprobe,
3949 .remove = __devexit_p(stli_pciremove)
3950};
4072/*****************************************************************************/ 3951/*****************************************************************************/
4073 3952
4074/* 3953/*
4075 * Allocate a new board structure. Fill out the basic info in it. 3954 * Allocate a new board structure. Fill out the basic info in it.
4076 */ 3955 */
4077 3956
4078static stlibrd_t *stli_allocbrd(void) 3957static struct stlibrd *stli_allocbrd(void)
4079{ 3958{
4080 stlibrd_t *brdp; 3959 struct stlibrd *brdp;
4081 3960
4082 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL); 3961 brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
4083 if (!brdp) { 3962 if (!brdp) {
4084 printk(KERN_ERR "STALLION: failed to allocate memory " 3963 printk(KERN_ERR "STALLION: failed to allocate memory "
4085 "(size=%Zd)\n", sizeof(stlibrd_t)); 3964 "(size=%Zd)\n", sizeof(struct stlibrd));
4086 return NULL; 3965 return NULL;
4087 } 3966 }
4088 brdp->magic = STLI_BOARDMAGIC; 3967 brdp->magic = STLI_BOARDMAGIC;
@@ -4098,43 +3977,37 @@ static stlibrd_t *stli_allocbrd(void)
4098 3977
4099static int stli_initbrds(void) 3978static int stli_initbrds(void)
4100{ 3979{
4101 stlibrd_t *brdp, *nxtbrdp; 3980 struct stlibrd *brdp, *nxtbrdp;
4102 stlconf_t *confp; 3981 struct stlconf conf;
4103 int i, j; 3982 unsigned int i, j, found = 0;
4104 3983 int retval;
4105 if (stli_nrbrds > STL_MAXBRDS) {
4106 printk(KERN_INFO "STALLION: too many boards in configuration "
4107 "table, truncating to %d\n", STL_MAXBRDS);
4108 stli_nrbrds = STL_MAXBRDS;
4109 }
4110 3984
4111/* 3985 for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
4112 * Firstly scan the list of static boards configured. Allocate 3986 stli_nrbrds++) {
4113 * resources and initialize the boards as found. If this is a 3987 memset(&conf, 0, sizeof(conf));
4114 * module then let the module args override static configuration. 3988 if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
4115 */ 3989 continue;
4116 for (i = 0; (i < stli_nrbrds); i++) {
4117 confp = &stli_brdconf[i];
4118 stli_parsebrd(confp, stli_brdsp[i]);
4119 if ((brdp = stli_allocbrd()) == NULL) 3990 if ((brdp = stli_allocbrd()) == NULL)
4120 return -ENOMEM; 3991 continue;
4121 brdp->brdnr = i; 3992 brdp->brdnr = stli_nrbrds;
4122 brdp->brdtype = confp->brdtype; 3993 brdp->brdtype = conf.brdtype;
4123 brdp->iobase = confp->ioaddr1; 3994 brdp->iobase = conf.ioaddr1;
4124 brdp->memaddr = confp->memaddr; 3995 brdp->memaddr = conf.memaddr;
4125 stli_brdinit(brdp); 3996 if (stli_brdinit(brdp) < 0) {
3997 kfree(brdp);
3998 continue;
3999 }
4000 stli_brds[brdp->brdnr] = brdp;
4001 found++;
4002
4003 for (i = 0; i < brdp->nrports; i++)
4004 tty_register_device(stli_serial,
4005 brdp->brdnr * STL_MAXPORTS + i, NULL);
4126 } 4006 }
4127 4007
4128/* 4008 retval = stli_findeisabrds();
4129 * Static configuration table done, so now use dynamic methods to 4009 if (retval > 0)
4130 * see if any more boards should be configured. 4010 found += retval;
4131 */
4132 stli_argbrds();
4133 if (STLI_EISAPROBE)
4134 stli_findeisabrds();
4135#ifdef CONFIG_PCI
4136 stli_findpcibrds();
4137#endif
4138 4011
4139/* 4012/*
4140 * All found boards are initialized. Now for a little optimization, if 4013 * All found boards are initialized. Now for a little optimization, if
@@ -4174,7 +4047,16 @@ static int stli_initbrds(void)
4174 } 4047 }
4175 } 4048 }
4176 4049
4050 retval = pci_register_driver(&stli_pcidriver);
4051 if (retval && found == 0) {
4052 printk(KERN_ERR "Neither isa nor eisa cards found nor pci "
4053 "driver can be registered!\n");
4054 goto err;
4055 }
4056
4177 return 0; 4057 return 0;
4058err:
4059 return retval;
4178} 4060}
4179 4061
4180/*****************************************************************************/ 4062/*****************************************************************************/
@@ -4189,12 +4071,13 @@ static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, lof
4189{ 4071{
4190 unsigned long flags; 4072 unsigned long flags;
4191 void __iomem *memptr; 4073 void __iomem *memptr;
4192 stlibrd_t *brdp; 4074 struct stlibrd *brdp;
4193 int brdnr, size, n; 4075 unsigned int brdnr;
4076 int size, n;
4194 void *p; 4077 void *p;
4195 loff_t off = *offp; 4078 loff_t off = *offp;
4196 4079
4197 brdnr = iminor(fp->f_dentry->d_inode); 4080 brdnr = iminor(fp->f_path.dentry->d_inode);
4198 if (brdnr >= stli_nrbrds) 4081 if (brdnr >= stli_nrbrds)
4199 return -ENODEV; 4082 return -ENODEV;
4200 brdp = stli_brds[brdnr]; 4083 brdp = stli_brds[brdnr];
@@ -4205,7 +4088,7 @@ static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, lof
4205 if (off >= brdp->memsize || off + count < off) 4088 if (off >= brdp->memsize || off + count < off)
4206 return 0; 4089 return 0;
4207 4090
4208 size = MIN(count, (brdp->memsize - off)); 4091 size = min(count, (size_t)(brdp->memsize - off));
4209 4092
4210 /* 4093 /*
4211 * Copy the data a page at a time 4094 * Copy the data a page at a time
@@ -4219,8 +4102,8 @@ static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, lof
4219 spin_lock_irqsave(&brd_lock, flags); 4102 spin_lock_irqsave(&brd_lock, flags);
4220 EBRDENABLE(brdp); 4103 EBRDENABLE(brdp);
4221 memptr = EBRDGETMEMPTR(brdp, off); 4104 memptr = EBRDGETMEMPTR(brdp, off);
4222 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); 4105 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4223 n = MIN(n, PAGE_SIZE); 4106 n = min(n, (int)PAGE_SIZE);
4224 memcpy_fromio(p, memptr, n); 4107 memcpy_fromio(p, memptr, n);
4225 EBRDDISABLE(brdp); 4108 EBRDDISABLE(brdp);
4226 spin_unlock_irqrestore(&brd_lock, flags); 4109 spin_unlock_irqrestore(&brd_lock, flags);
@@ -4252,13 +4135,14 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4252{ 4135{
4253 unsigned long flags; 4136 unsigned long flags;
4254 void __iomem *memptr; 4137 void __iomem *memptr;
4255 stlibrd_t *brdp; 4138 struct stlibrd *brdp;
4256 char __user *chbuf; 4139 char __user *chbuf;
4257 int brdnr, size, n; 4140 unsigned int brdnr;
4141 int size, n;
4258 void *p; 4142 void *p;
4259 loff_t off = *offp; 4143 loff_t off = *offp;
4260 4144
4261 brdnr = iminor(fp->f_dentry->d_inode); 4145 brdnr = iminor(fp->f_path.dentry->d_inode);
4262 4146
4263 if (brdnr >= stli_nrbrds) 4147 if (brdnr >= stli_nrbrds)
4264 return -ENODEV; 4148 return -ENODEV;
@@ -4271,7 +4155,7 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4271 return 0; 4155 return 0;
4272 4156
4273 chbuf = (char __user *) buf; 4157 chbuf = (char __user *) buf;
4274 size = MIN(count, (brdp->memsize - off)); 4158 size = min(count, (size_t)(brdp->memsize - off));
4275 4159
4276 /* 4160 /*
4277 * Copy the data a page at a time 4161 * Copy the data a page at a time
@@ -4282,8 +4166,8 @@ static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t cou
4282 return -ENOMEM; 4166 return -ENOMEM;
4283 4167
4284 while (size > 0) { 4168 while (size > 0) {
4285 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize))); 4169 n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4286 n = MIN(n, PAGE_SIZE); 4170 n = min(n, (int)PAGE_SIZE);
4287 if (copy_from_user(p, chbuf, n)) { 4171 if (copy_from_user(p, chbuf, n)) {
4288 if (count == 0) 4172 if (count == 0)
4289 count = -EFAULT; 4173 count = -EFAULT;
@@ -4313,8 +4197,8 @@ out:
4313 4197
4314static int stli_getbrdstats(combrd_t __user *bp) 4198static int stli_getbrdstats(combrd_t __user *bp)
4315{ 4199{
4316 stlibrd_t *brdp; 4200 struct stlibrd *brdp;
4317 int i; 4201 unsigned int i;
4318 4202
4319 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) 4203 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4320 return -EFAULT; 4204 return -EFAULT;
@@ -4350,19 +4234,20 @@ static int stli_getbrdstats(combrd_t __user *bp)
4350 * Resolve the referenced port number into a port struct pointer. 4234 * Resolve the referenced port number into a port struct pointer.
4351 */ 4235 */
4352 4236
4353static stliport_t *stli_getport(int brdnr, int panelnr, int portnr) 4237static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4238 unsigned int portnr)
4354{ 4239{
4355 stlibrd_t *brdp; 4240 struct stlibrd *brdp;
4356 int i; 4241 unsigned int i;
4357 4242
4358 if (brdnr < 0 || brdnr >= STL_MAXBRDS) 4243 if (brdnr >= STL_MAXBRDS)
4359 return NULL; 4244 return NULL;
4360 brdp = stli_brds[brdnr]; 4245 brdp = stli_brds[brdnr];
4361 if (brdp == NULL) 4246 if (brdp == NULL)
4362 return NULL; 4247 return NULL;
4363 for (i = 0; (i < panelnr); i++) 4248 for (i = 0; (i < panelnr); i++)
4364 portnr += brdp->panels[i]; 4249 portnr += brdp->panels[i];
4365 if ((portnr < 0) || (portnr >= brdp->nrports)) 4250 if (portnr >= brdp->nrports)
4366 return NULL; 4251 return NULL;
4367 return brdp->ports[portnr]; 4252 return brdp->ports[portnr];
4368} 4253}
@@ -4375,10 +4260,10 @@ static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4375 * what port to get stats for (used through board control device). 4260 * what port to get stats for (used through board control device).
4376 */ 4261 */
4377 4262
4378static int stli_portcmdstats(stliport_t *portp) 4263static int stli_portcmdstats(struct stliport *portp)
4379{ 4264{
4380 unsigned long flags; 4265 unsigned long flags;
4381 stlibrd_t *brdp; 4266 struct stlibrd *brdp;
4382 int rc; 4267 int rc;
4383 4268
4384 memset(&stli_comstats, 0, sizeof(comstats_t)); 4269 memset(&stli_comstats, 0, sizeof(comstats_t));
@@ -4449,9 +4334,9 @@ static int stli_portcmdstats(stliport_t *portp)
4449 * what port to get stats for (used through board control device). 4334 * what port to get stats for (used through board control device).
4450 */ 4335 */
4451 4336
4452static int stli_getportstats(stliport_t *portp, comstats_t __user *cp) 4337static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
4453{ 4338{
4454 stlibrd_t *brdp; 4339 struct stlibrd *brdp;
4455 int rc; 4340 int rc;
4456 4341
4457 if (!portp) { 4342 if (!portp) {
@@ -4480,9 +4365,9 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4480 * Clear the port stats structure. We also return it zeroed out... 4365 * Clear the port stats structure. We also return it zeroed out...
4481 */ 4366 */
4482 4367
4483static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp) 4368static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
4484{ 4369{
4485 stlibrd_t *brdp; 4370 struct stlibrd *brdp;
4486 int rc; 4371 int rc;
4487 4372
4488 if (!portp) { 4373 if (!portp) {
@@ -4519,17 +4404,18 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4519 * Return the entire driver ports structure to a user app. 4404 * Return the entire driver ports structure to a user app.
4520 */ 4405 */
4521 4406
4522static int stli_getportstruct(stliport_t __user *arg) 4407static int stli_getportstruct(struct stliport __user *arg)
4523{ 4408{
4524 stliport_t *portp; 4409 struct stliport stli_dummyport;
4410 struct stliport *portp;
4525 4411
4526 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t))) 4412 if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
4527 return -EFAULT; 4413 return -EFAULT;
4528 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr, 4414 portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
4529 stli_dummyport.portnr); 4415 stli_dummyport.portnr);
4530 if (!portp) 4416 if (!portp)
4531 return -ENODEV; 4417 return -ENODEV;
4532 if (copy_to_user(arg, portp, sizeof(stliport_t))) 4418 if (copy_to_user(arg, portp, sizeof(struct stliport)))
4533 return -EFAULT; 4419 return -EFAULT;
4534 return 0; 4420 return 0;
4535} 4421}
@@ -4540,18 +4426,19 @@ static int stli_getportstruct(stliport_t __user *arg)
4540 * Return the entire driver board structure to a user app. 4426 * Return the entire driver board structure to a user app.
4541 */ 4427 */
4542 4428
4543static int stli_getbrdstruct(stlibrd_t __user *arg) 4429static int stli_getbrdstruct(struct stlibrd __user *arg)
4544{ 4430{
4545 stlibrd_t *brdp; 4431 struct stlibrd stli_dummybrd;
4432 struct stlibrd *brdp;
4546 4433
4547 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t))) 4434 if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
4548 return -EFAULT; 4435 return -EFAULT;
4549 if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS)) 4436 if (stli_dummybrd.brdnr >= STL_MAXBRDS)
4550 return -ENODEV; 4437 return -ENODEV;
4551 brdp = stli_brds[stli_dummybrd.brdnr]; 4438 brdp = stli_brds[stli_dummybrd.brdnr];
4552 if (!brdp) 4439 if (!brdp)
4553 return -ENODEV; 4440 return -ENODEV;
4554 if (copy_to_user(arg, brdp, sizeof(stlibrd_t))) 4441 if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
4555 return -EFAULT; 4442 return -EFAULT;
4556 return 0; 4443 return 0;
4557} 4444}
@@ -4566,7 +4453,7 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
4566 4453
4567static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 4454static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
4568{ 4455{
4569 stlibrd_t *brdp; 4456 struct stlibrd *brdp;
4570 int brdnr, rc, done; 4457 int brdnr, rc, done;
4571 void __user *argp = (void __user *)arg; 4458 void __user *argp = (void __user *)arg;
4572 4459
@@ -4665,46 +4552,53 @@ static const struct tty_operations stli_ops = {
4665}; 4552};
4666 4553
4667/*****************************************************************************/ 4554/*****************************************************************************/
4555/*
4556 * Loadable module initialization stuff.
4557 */
4558
4559static void istallion_cleanup_isa(void)
4560{
4561 struct stlibrd *brdp;
4562 unsigned int j;
4563
4564 for (j = 0; (j < stli_nrbrds); j++) {
4565 if ((brdp = stli_brds[j]) == NULL || (brdp->state & BST_PROBED))
4566 continue;
4567
4568 stli_cleanup_ports(brdp);
4668 4569
4669static int __init stli_init(void) 4570 iounmap(brdp->membase);
4571 if (brdp->iosize > 0)
4572 release_region(brdp->iobase, brdp->iosize);
4573 kfree(brdp);
4574 stli_brds[j] = NULL;
4575 }
4576}
4577
4578static int __init istallion_module_init(void)
4670{ 4579{
4671 int i; 4580 unsigned int i;
4581 int retval;
4582
4672 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion); 4583 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
4673 4584
4674 spin_lock_init(&stli_lock); 4585 spin_lock_init(&stli_lock);
4675 spin_lock_init(&brd_lock); 4586 spin_lock_init(&brd_lock);
4676 4587
4677 stli_initbrds();
4678
4679 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4680 if (!stli_serial)
4681 return -ENOMEM;
4682
4683/*
4684 * Allocate a temporary write buffer.
4685 */
4686 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4588 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
4687 if (!stli_txcookbuf) 4589 if (!stli_txcookbuf) {
4688 printk(KERN_ERR "STALLION: failed to allocate memory " 4590 printk(KERN_ERR "STALLION: failed to allocate memory "
4689 "(size=%d)\n", STLI_TXBUFSIZE); 4591 "(size=%d)\n", STLI_TXBUFSIZE);
4592 retval = -ENOMEM;
4593 goto err;
4594 }
4690 4595
4691/* 4596 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4692 * Set up a character driver for the shared memory region. We need this 4597 if (!stli_serial) {
4693 * to down load the slave code image. Also it is a useful debugging tool. 4598 retval = -ENOMEM;
4694 */ 4599 goto err_free;
4695 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem)) 4600 }
4696 printk(KERN_ERR "STALLION: failed to register serial memory "
4697 "device\n");
4698
4699 istallion_class = class_create(THIS_MODULE, "staliomem");
4700 for (i = 0; i < 4; i++)
4701 class_device_create(istallion_class, NULL,
4702 MKDEV(STL_SIOMEMMAJOR, i),
4703 NULL, "staliomem%d", i);
4704 4601
4705/*
4706 * Set up the tty driver structure and register us as a driver.
4707 */
4708 stli_serial->owner = THIS_MODULE; 4602 stli_serial->owner = THIS_MODULE;
4709 stli_serial->driver_name = stli_drvname; 4603 stli_serial->driver_name = stli_drvname;
4710 stli_serial->name = stli_serialname; 4604 stli_serial->name = stli_serialname;
@@ -4713,15 +4607,79 @@ static int __init stli_init(void)
4713 stli_serial->type = TTY_DRIVER_TYPE_SERIAL; 4607 stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
4714 stli_serial->subtype = SERIAL_TYPE_NORMAL; 4608 stli_serial->subtype = SERIAL_TYPE_NORMAL;
4715 stli_serial->init_termios = stli_deftermios; 4609 stli_serial->init_termios = stli_deftermios;
4716 stli_serial->flags = TTY_DRIVER_REAL_RAW; 4610 stli_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4717 tty_set_operations(stli_serial, &stli_ops); 4611 tty_set_operations(stli_serial, &stli_ops);
4718 4612
4719 if (tty_register_driver(stli_serial)) { 4613 retval = tty_register_driver(stli_serial);
4720 put_tty_driver(stli_serial); 4614 if (retval) {
4721 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4615 printk(KERN_ERR "STALLION: failed to register serial driver\n");
4722 return -EBUSY; 4616 goto err_ttyput;
4723 } 4617 }
4618
4619 retval = stli_initbrds();
4620 if (retval)
4621 goto err_ttyunr;
4622
4623/*
4624 * Set up a character driver for the shared memory region. We need this
4625 * to down load the slave code image. Also it is a useful debugging tool.
4626 */
4627 retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
4628 if (retval) {
4629 printk(KERN_ERR "STALLION: failed to register serial memory "
4630 "device\n");
4631 goto err_deinit;
4632 }
4633
4634 istallion_class = class_create(THIS_MODULE, "staliomem");
4635 for (i = 0; i < 4; i++)
4636 class_device_create(istallion_class, NULL,
4637 MKDEV(STL_SIOMEMMAJOR, i),
4638 NULL, "staliomem%d", i);
4639
4724 return 0; 4640 return 0;
4641err_deinit:
4642 pci_unregister_driver(&stli_pcidriver);
4643 istallion_cleanup_isa();
4644err_ttyunr:
4645 tty_unregister_driver(stli_serial);
4646err_ttyput:
4647 put_tty_driver(stli_serial);
4648err_free:
4649 kfree(stli_txcookbuf);
4650err:
4651 return retval;
4725} 4652}
4726 4653
4727/*****************************************************************************/ 4654/*****************************************************************************/
4655
4656static void __exit istallion_module_exit(void)
4657{
4658 unsigned int j;
4659
4660 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
4661 stli_drvversion);
4662
4663 if (stli_timeron) {
4664 stli_timeron = 0;
4665 del_timer_sync(&stli_timerlist);
4666 }
4667
4668 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4669
4670 for (j = 0; j < 4; j++)
4671 class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR,
4672 j));
4673 class_destroy(istallion_class);
4674
4675 pci_unregister_driver(&stli_pcidriver);
4676 istallion_cleanup_isa();
4677
4678 tty_unregister_driver(stli_serial);
4679 put_tty_driver(stli_serial);
4680
4681 kfree(stli_txcookbuf);
4682}
4683
4684module_init(istallion_module_init);
4685module_exit(istallion_module_exit);
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 20b6c8b30248..7a6c1c0b7a95 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -710,7 +710,7 @@ static void k_fn(struct vc_data *vc, unsigned char value, char up_flag)
710 710
711static void k_cur(struct vc_data *vc, unsigned char value, char up_flag) 711static void k_cur(struct vc_data *vc, unsigned char value, char up_flag)
712{ 712{
713 static const char *cur_chars = "BDCA"; 713 static const char cur_chars[] = "BDCA";
714 714
715 if (up_flag) 715 if (up_flag)
716 return; 716 return;
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 1ecea7d448f1..b70b5388b5a8 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -296,7 +296,7 @@ static int lp_wait_ready(int minor, int nonblock)
296static ssize_t lp_write(struct file * file, const char __user * buf, 296static ssize_t lp_write(struct file * file, const char __user * buf,
297 size_t count, loff_t *ppos) 297 size_t count, loff_t *ppos)
298{ 298{
299 unsigned int minor = iminor(file->f_dentry->d_inode); 299 unsigned int minor = iminor(file->f_path.dentry->d_inode);
300 struct parport *port = lp_table[minor].dev->port; 300 struct parport *port = lp_table[minor].dev->port;
301 char *kbuf = lp_table[minor].lp_buffer; 301 char *kbuf = lp_table[minor].lp_buffer;
302 ssize_t retv = 0; 302 ssize_t retv = 0;
@@ -415,7 +415,7 @@ static ssize_t lp_read(struct file * file, char __user * buf,
415 size_t count, loff_t *ppos) 415 size_t count, loff_t *ppos)
416{ 416{
417 DEFINE_WAIT(wait); 417 DEFINE_WAIT(wait);
418 unsigned int minor=iminor(file->f_dentry->d_inode); 418 unsigned int minor=iminor(file->f_path.dentry->d_inode);
419 struct parport *port = lp_table[minor].dev->port; 419 struct parport *port = lp_table[minor].dev->port;
420 ssize_t retval = 0; 420 ssize_t retval = 0;
421 char *kbuf = lp_table[minor].lp_buffer; 421 char *kbuf = lp_table[minor].lp_buffer;
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index e67eef4867ba..4f1813e04754 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -646,7 +646,8 @@ static inline size_t read_zero_pagealigned(char __user * buf, size_t size)
646 count = size; 646 count = size;
647 647
648 zap_page_range(vma, addr, count, NULL); 648 zap_page_range(vma, addr, count, NULL);
649 zeromap_page_range(vma, addr, count, PAGE_COPY); 649 if (zeromap_page_range(vma, addr, count, PAGE_COPY))
650 break;
650 651
651 size -= count; 652 size -= count;
652 buf += count; 653 buf += count;
@@ -713,11 +714,14 @@ out:
713 714
714static int mmap_zero(struct file * file, struct vm_area_struct * vma) 715static int mmap_zero(struct file * file, struct vm_area_struct * vma)
715{ 716{
717 int err;
718
716 if (vma->vm_flags & VM_SHARED) 719 if (vma->vm_flags & VM_SHARED)
717 return shmem_zero_setup(vma); 720 return shmem_zero_setup(vma);
718 if (zeromap_page_range(vma, vma->vm_start, vma->vm_end - vma->vm_start, vma->vm_page_prot)) 721 err = zeromap_page_range(vma, vma->vm_start,
719 return -EAGAIN; 722 vma->vm_end - vma->vm_start, vma->vm_page_prot);
720 return 0; 723 BUG_ON(err == -EEXIST);
724 return err;
721} 725}
722#else /* CONFIG_MMU */ 726#else /* CONFIG_MMU */
723static ssize_t read_zero(struct file * file, char * buf, 727static ssize_t read_zero(struct file * file, char * buf,
@@ -774,7 +778,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
774{ 778{
775 loff_t ret; 779 loff_t ret;
776 780
777 mutex_lock(&file->f_dentry->d_inode->i_mutex); 781 mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
778 switch (orig) { 782 switch (orig) {
779 case 0: 783 case 0:
780 file->f_pos = offset; 784 file->f_pos = offset;
@@ -789,7 +793,7 @@ static loff_t memory_lseek(struct file * file, loff_t offset, int orig)
789 default: 793 default:
790 ret = -EINVAL; 794 ret = -EINVAL;
791 } 795 }
792 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 796 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
793 return ret; 797 return ret;
794} 798}
795 799
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 8b316953173d..f391a24a1b44 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -234,7 +234,7 @@ static void moxa_put_char(struct tty_struct *, unsigned char);
234static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long); 234static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long);
235static void moxa_throttle(struct tty_struct *); 235static void moxa_throttle(struct tty_struct *);
236static void moxa_unthrottle(struct tty_struct *); 236static void moxa_unthrottle(struct tty_struct *);
237static void moxa_set_termios(struct tty_struct *, struct termios *); 237static void moxa_set_termios(struct tty_struct *, struct ktermios *);
238static void moxa_stop(struct tty_struct *); 238static void moxa_stop(struct tty_struct *);
239static void moxa_start(struct tty_struct *); 239static void moxa_start(struct tty_struct *);
240static void moxa_hangup(struct tty_struct *); 240static void moxa_hangup(struct tty_struct *);
@@ -261,7 +261,7 @@ static void MoxaPortEnable(int);
261static void MoxaPortDisable(int); 261static void MoxaPortDisable(int);
262static long MoxaPortGetMaxBaud(int); 262static long MoxaPortGetMaxBaud(int);
263static long MoxaPortSetBaud(int, long); 263static long MoxaPortSetBaud(int, long);
264static int MoxaPortSetTermio(int, struct termios *, speed_t); 264static int MoxaPortSetTermio(int, struct ktermios *, speed_t);
265static int MoxaPortGetLineOut(int, int *, int *); 265static int MoxaPortGetLineOut(int, int *, int *);
266static void MoxaPortLineCtrl(int, int, int); 266static void MoxaPortLineCtrl(int, int, int);
267static void MoxaPortFlowCtrl(int, int, int, int, int, int); 267static void MoxaPortFlowCtrl(int, int, int, int, int, int);
@@ -355,6 +355,8 @@ static int __init moxa_init(void)
355 moxaDriver->init_termios.c_oflag = 0; 355 moxaDriver->init_termios.c_oflag = 0;
356 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 356 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
357 moxaDriver->init_termios.c_lflag = 0; 357 moxaDriver->init_termios.c_lflag = 0;
358 moxaDriver->init_termios.c_ispeed = 9600;
359 moxaDriver->init_termios.c_ospeed = 9600;
358 moxaDriver->flags = TTY_DRIVER_REAL_RAW; 360 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
359 tty_set_operations(moxaDriver, &moxa_ops); 361 tty_set_operations(moxaDriver, &moxa_ops);
360 362
@@ -864,7 +866,7 @@ static void moxa_unthrottle(struct tty_struct *tty)
864} 866}
865 867
866static void moxa_set_termios(struct tty_struct *tty, 868static void moxa_set_termios(struct tty_struct *tty,
867 struct termios *old_termios) 869 struct ktermios *old_termios)
868{ 870{
869 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 871 struct moxa_str *ch = (struct moxa_str *) tty->driver_data;
870 872
@@ -978,7 +980,7 @@ static void moxa_poll(unsigned long ignored)
978 980
979static void set_tty_param(struct tty_struct *tty) 981static void set_tty_param(struct tty_struct *tty)
980{ 982{
981 register struct termios *ts; 983 register struct ktermios *ts;
982 struct moxa_str *ch; 984 struct moxa_str *ch;
983 int rts, cts, txflow, rxflow, xany; 985 int rts, cts, txflow, rxflow, xany;
984 986
@@ -1149,7 +1151,7 @@ static void shut_down(struct moxa_str *ch)
1149static void receive_data(struct moxa_str *ch) 1151static void receive_data(struct moxa_str *ch)
1150{ 1152{
1151 struct tty_struct *tp; 1153 struct tty_struct *tp;
1152 struct termios *ts; 1154 struct ktermios *ts;
1153 unsigned long flags; 1155 unsigned long flags;
1154 1156
1155 ts = NULL; 1157 ts = NULL;
@@ -1912,9 +1914,9 @@ int MoxaPortsOfCard(int cardno)
1912 * 1914 *
1913 * Function 12: Configure the port. 1915 * Function 12: Configure the port.
1914 * Syntax: 1916 * Syntax:
1915 * int MoxaPortSetTermio(int port, struct termios *termio, speed_t baud); 1917 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
1916 * int port : port number (0 - 127) 1918 * int port : port number (0 - 127)
1917 * struct termios * termio : termio structure pointer 1919 * struct ktermios * termio : termio structure pointer
1918 * speed_t baud : baud rate 1920 * speed_t baud : baud rate
1919 * 1921 *
1920 * return: -1 : this port is invalid or termio == NULL 1922 * return: -1 : this port is invalid or termio == NULL
@@ -2195,7 +2197,7 @@ long MoxaPortSetBaud(int port, long baud)
2195 return (baud); 2197 return (baud);
2196} 2198}
2197 2199
2198int MoxaPortSetTermio(int port, struct termios *termio, speed_t baud) 2200int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2199{ 2201{
2200 void __iomem *ofsAddr; 2202 void __iomem *ofsAddr;
2201 tcflag_t cflag; 2203 tcflag_t cflag;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 5ed2486b7581..c063359baf78 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -328,8 +328,8 @@ struct mxser_struct {
328 int xmit_tail; 328 int xmit_tail;
329 int xmit_cnt; 329 int xmit_cnt;
330 struct work_struct tqueue; 330 struct work_struct tqueue;
331 struct termios normal_termios; 331 struct ktermios normal_termios;
332 struct termios callout_termios; 332 struct ktermios callout_termios;
333 wait_queue_head_t open_wait; 333 wait_queue_head_t open_wait;
334 wait_queue_head_t close_wait; 334 wait_queue_head_t close_wait;
335 wait_queue_head_t delta_msr_wait; 335 wait_queue_head_t delta_msr_wait;
@@ -364,8 +364,8 @@ static int mxserBoardCAP[MXSER_BOARDS] = {
364static struct tty_driver *mxvar_sdriver; 364static struct tty_driver *mxvar_sdriver;
365static struct mxser_struct mxvar_table[MXSER_PORTS]; 365static struct mxser_struct mxvar_table[MXSER_PORTS];
366static struct tty_struct *mxvar_tty[MXSER_PORTS + 1]; 366static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
367static struct termios *mxvar_termios[MXSER_PORTS + 1]; 367static struct ktermios *mxvar_termios[MXSER_PORTS + 1];
368static struct termios *mxvar_termios_locked[MXSER_PORTS + 1]; 368static struct ktermios *mxvar_termios_locked[MXSER_PORTS + 1];
369static struct mxser_log mxvar_log; 369static struct mxser_log mxvar_log;
370static int mxvar_diagflag; 370static int mxvar_diagflag;
371static unsigned char mxser_msr[MXSER_PORTS + 1]; 371static unsigned char mxser_msr[MXSER_PORTS + 1];
@@ -402,7 +402,7 @@ static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
402static int mxser_ioctl_special(unsigned int, void __user *); 402static int mxser_ioctl_special(unsigned int, void __user *);
403static void mxser_throttle(struct tty_struct *); 403static void mxser_throttle(struct tty_struct *);
404static void mxser_unthrottle(struct tty_struct *); 404static void mxser_unthrottle(struct tty_struct *);
405static void mxser_set_termios(struct tty_struct *, struct termios *); 405static void mxser_set_termios(struct tty_struct *, struct ktermios *);
406static void mxser_stop(struct tty_struct *); 406static void mxser_stop(struct tty_struct *);
407static void mxser_start(struct tty_struct *); 407static void mxser_start(struct tty_struct *);
408static void mxser_hangup(struct tty_struct *); 408static void mxser_hangup(struct tty_struct *);
@@ -414,7 +414,7 @@ static void mxser_check_modem_status(struct mxser_struct *, int);
414static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *); 414static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
415static int mxser_startup(struct mxser_struct *); 415static int mxser_startup(struct mxser_struct *);
416static void mxser_shutdown(struct mxser_struct *); 416static void mxser_shutdown(struct mxser_struct *);
417static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios); 417static int mxser_change_speed(struct mxser_struct *, struct ktermios *old_termios);
418static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *); 418static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
419static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *); 419static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
420static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *); 420static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
@@ -515,6 +515,7 @@ static void __exit mxser_module_exit(void)
515 if (pdev != NULL) { /* PCI */ 515 if (pdev != NULL) { /* PCI */
516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2)); 516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3)); 517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
518 pci_dev_put(pdev);
518 } else { 519 } else {
519 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports); 520 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
520 release_region(mxsercfg[i].vector, 1); 521 release_region(mxsercfg[i].vector, 1);
@@ -556,7 +557,7 @@ static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
556 n = board * MXSER_PORTS_PER_BOARD; 557 n = board * MXSER_PORTS_PER_BOARD;
557 info = &mxvar_table[n]; 558 info = &mxvar_table[n];
558 /*if (verbose) */ { 559 /*if (verbose) */ {
559 printk(KERN_DEBUG " ttyM%d - ttyM%d ", 560 printk(KERN_DEBUG " ttyMI%d - ttyMI%d ",
560 n, n + hwconf->ports - 1); 561 n, n + hwconf->ports - 1);
561 printk(" max. baud rate = %d bps.\n", 562 printk(" max. baud rate = %d bps.\n",
562 hwconf->MaxCanSetBaudRate[0]); 563 hwconf->MaxCanSetBaudRate[0]);
@@ -717,7 +718,7 @@ static int mxser_init(void)
717 /* Initialize the tty_driver structure */ 718 /* Initialize the tty_driver structure */
718 memset(mxvar_sdriver, 0, sizeof(struct tty_driver)); 719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
719 mxvar_sdriver->magic = TTY_DRIVER_MAGIC; 720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
720 mxvar_sdriver->name = "ttyM"; 721 mxvar_sdriver->name = "ttyMI";
721 mxvar_sdriver->major = ttymajor; 722 mxvar_sdriver->major = ttymajor;
722 mxvar_sdriver->minor_start = 0; 723 mxvar_sdriver->minor_start = 0;
723 mxvar_sdriver->num = MXSER_PORTS + 1; 724 mxvar_sdriver->num = MXSER_PORTS + 1;
@@ -725,6 +726,8 @@ static int mxser_init(void)
725 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; 726 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
726 mxvar_sdriver->init_termios = tty_std_termios; 727 mxvar_sdriver->init_termios = tty_std_termios;
727 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; 728 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
729 mxvar_sdriver->init_termios.c_ispeed = 9600;
730 mxvar_sdriver->init_termios.c_ospeed = 9600;
728 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW; 731 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
729 tty_set_operations(mxvar_sdriver, &mxser_ops); 732 tty_set_operations(mxvar_sdriver, &mxser_ops);
730 mxvar_sdriver->ttys = mxvar_tty; 733 mxvar_sdriver->ttys = mxvar_tty;
@@ -839,9 +842,9 @@ static int mxser_init(void)
839 index = 0; 842 index = 0;
840 b = 0; 843 b = 0;
841 while (b < n) { 844 while (b < n) {
842 pdev = pci_find_device(mxser_pcibrds[b].vendor, 845 pdev = pci_get_device(mxser_pcibrds[b].vendor,
843 mxser_pcibrds[b].device, pdev); 846 mxser_pcibrds[b].device, pdev);
844 if (pdev == NULL) { 847 if (pdev == NULL) {
845 b++; 848 b++;
846 continue; 849 continue;
847 } 850 }
@@ -893,6 +896,9 @@ static int mxser_init(void)
893 if (mxser_initbrd(m, &hwconf) < 0) 896 if (mxser_initbrd(m, &hwconf) < 0)
894 continue; 897 continue;
895 m++; 898 m++;
899 /* Keep an extra reference if we succeeded. It will
900 be returned at unload time */
901 pci_dev_get(pdev);
896 } 902 }
897 } 903 }
898#endif 904#endif
@@ -994,7 +1000,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
994 mxser_change_speed(info, NULL); 1000 mxser_change_speed(info, NULL);
995 } 1001 }
996 1002
997 info->session = current->signal->session; 1003 info->session = process_session(current);
998 info->pgrp = process_group(current); 1004 info->pgrp = process_group(current);
999 1005
1000 /* 1006 /*
@@ -1745,7 +1751,7 @@ static void mxser_unthrottle(struct tty_struct *tty)
1745 /* MX_UNLOCK(&info->slock); */ 1751 /* MX_UNLOCK(&info->slock); */
1746} 1752}
1747 1753
1748static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios) 1754static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1749{ 1755{
1750 struct mxser_struct *info = tty->driver_data; 1756 struct mxser_struct *info = tty->driver_data;
1751 unsigned long flags; 1757 unsigned long flags;
@@ -2537,7 +2543,7 @@ static void mxser_shutdown(struct mxser_struct *info)
2537 * This routine is called to set the UART divisor registers to match 2543 * This routine is called to set the UART divisor registers to match
2538 * the specified baud rate for a serial port. 2544 * the specified baud rate for a serial port.
2539 */ 2545 */
2540static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios) 2546static int mxser_change_speed(struct mxser_struct *info, struct ktermios *old_termios)
2541{ 2547{
2542 unsigned cflag, cval, fcr; 2548 unsigned cflag, cval, fcr;
2543 int ret = 0; 2549 int ret = 0;
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
new file mode 100644
index 000000000000..efa8076c33e0
--- /dev/null
+++ b/drivers/char/mxser_new.c
@@ -0,0 +1,2804 @@
1/*
2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
3 *
4 * Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com.tw).
5 * Copyright (C) 2006 Jiri Slaby <jirislaby@gmail.com>
6 *
7 * This code is loosely based on the 1.8 moxa driver which is based on
8 * Linux serial driver, written by Linus Torvalds, Theodore T'so and
9 * others.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
18 * - Fixed x86_64 cleanness
19 * - Fixed sleep with spinlock held in mxser_send_break
20 */
21
22#include <linux/module.h>
23#include <linux/autoconf.h>
24#include <linux/errno.h>
25#include <linux/signal.h>
26#include <linux/sched.h>
27#include <linux/timer.h>
28#include <linux/interrupt.h>
29#include <linux/tty.h>
30#include <linux/tty_flip.h>
31#include <linux/serial.h>
32#include <linux/serial_reg.h>
33#include <linux/major.h>
34#include <linux/string.h>
35#include <linux/fcntl.h>
36#include <linux/ptrace.h>
37#include <linux/gfp.h>
38#include <linux/ioport.h>
39#include <linux/mm.h>
40#include <linux/smp_lock.h>
41#include <linux/delay.h>
42#include <linux/pci.h>
43
44#include <asm/system.h>
45#include <asm/io.h>
46#include <asm/irq.h>
47#include <asm/bitops.h>
48#include <asm/uaccess.h>
49
50#include "mxser_new.h"
51
52#define MXSER_VERSION "2.0"
53#define MXSERMAJOR 174
54#define MXSERCUMAJOR 175
55
56#define MXSER_EVENT_TXLOW 1
57
58#define MXSER_BOARDS 4 /* Max. boards */
59#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
60#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
61#define MXSER_ISR_PASS_LIMIT 99999L
62
63#define MXSER_ERR_IOADDR -1
64#define MXSER_ERR_IRQ -2
65#define MXSER_ERR_IRQ_CONFLIT -3
66#define MXSER_ERR_VECTOR -4
67
68#define WAKEUP_CHARS 256
69
70#define UART_MCR_AFE 0x20
71#define UART_LSR_SPECIAL 0x1E
72
73#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|\
74 IXON|IXOFF))
75
76#define C168_ASIC_ID 1
77#define C104_ASIC_ID 2
78#define C102_ASIC_ID 0xB
79#define CI132_ASIC_ID 4
80#define CI134_ASIC_ID 3
81#define CI104J_ASIC_ID 5
82
83#define MXSER_HIGHBAUD 1
84#define MXSER_HAS2 2
85
86/* This is only for PCI */
87static const struct {
88 int type;
89 int tx_fifo;
90 int rx_fifo;
91 int xmit_fifo_size;
92 int rx_high_water;
93 int rx_trigger;
94 int rx_low_water;
95 long max_baud;
96} Gpci_uart_info[] = {
97 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
98 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
99 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
100};
101#define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
102
103struct mxser_cardinfo {
104 unsigned int nports;
105 char *name;
106 unsigned int flags;
107};
108
109static const struct mxser_cardinfo mxser_cards[] = {
110 { 8, "C168 series", }, /* C168-ISA */
111 { 4, "C104 series", }, /* C104-ISA */
112 { 4, "CI-104J series", }, /* CI104J */
113 { 8, "C168H/PCI series", }, /* C168-PCI */
114 { 4, "C104H/PCI series", }, /* C104-PCI */
115 { 4, "C102 series", MXSER_HAS2 }, /* C102-ISA */
116 { 4, "CI-132 series", MXSER_HAS2 }, /* CI132 */
117 { 4, "CI-134 series", }, /* CI134 */
118 { 2, "CP-132 series", }, /* CP132 */
119 { 4, "CP-114 series", }, /* CP114 */
120 { 4, "CT-114 series", }, /* CT114 */
121 { 2, "CP-102 series", MXSER_HIGHBAUD }, /* CP102 */
122 { 4, "CP-104U series", }, /* CP104U */
123 { 8, "CP-168U series", }, /* CP168U */
124 { 2, "CP-132U series", }, /* CP132U */
125 { 4, "CP-134U series", }, /* CP134U */
126 { 4, "CP-104JU series", }, /* CP104JU */
127 { 8, "Moxa UC7000 Serial", }, /* RC7000 */
128 { 8, "CP-118U series", }, /* CP118U */
129 { 2, "CP-102UL series", }, /* CP102UL */
130 { 2, "CP-102U series", }, /* CP102U */
131 { 8, "CP-118EL series", }, /* CP118EL */
132 { 8, "CP-168EL series", }, /* CP168EL */
133 { 4, "CP-104EL series", } /* CP104EL */
134};
135
136/* driver_data correspond to the lines in the structure above
137 see also ISA probe function before you change something */
138static struct pci_device_id mxser_pcibrds[] = {
139 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168),
140 .driver_data = 3 },
141 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104),
142 .driver_data = 4 },
143 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132),
144 .driver_data = 8 },
145 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114),
146 .driver_data = 9 },
147 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114),
148 .driver_data = 10 },
149 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102),
150 .driver_data = 11 },
151 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U),
152 .driver_data = 12 },
153 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U),
154 .driver_data = 13 },
155 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U),
156 .driver_data = 14 },
157 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U),
158 .driver_data = 15 },
159 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU),
160 .driver_data = 16 },
161 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000),
162 .driver_data = 17 },
163 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U),
164 .driver_data = 18 },
165 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
166 .driver_data = 19 },
167 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U),
168 .driver_data = 20 },
169 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL),
170 .driver_data = 21 },
171 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL),
172 .driver_data = 22 },
173 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL),
174 .driver_data = 23 },
175 { }
176};
177MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
178
179static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
180static int ttymajor = MXSERMAJOR;
181static int calloutmajor = MXSERCUMAJOR;
182
183/* Variables for insmod */
184
185MODULE_AUTHOR("Casper Yang");
186MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
187module_param_array(ioaddr, int, NULL, 0);
188module_param(ttymajor, int, 0);
189MODULE_LICENSE("GPL");
190
191struct mxser_log {
192 int tick;
193 unsigned long rxcnt[MXSER_PORTS];
194 unsigned long txcnt[MXSER_PORTS];
195};
196
197
198struct mxser_mon {
199 unsigned long rxcnt;
200 unsigned long txcnt;
201 unsigned long up_rxcnt;
202 unsigned long up_txcnt;
203 int modem_status;
204 unsigned char hold_reason;
205};
206
207struct mxser_mon_ext {
208 unsigned long rx_cnt[32];
209 unsigned long tx_cnt[32];
210 unsigned long up_rxcnt[32];
211 unsigned long up_txcnt[32];
212 int modem_status[32];
213
214 long baudrate[32];
215 int databits[32];
216 int stopbits[32];
217 int parity[32];
218 int flowctrl[32];
219 int fifo[32];
220 int iftype[32];
221};
222
223struct mxser_board;
224
225struct mxser_port {
226 struct mxser_board *board;
227 struct tty_struct *tty;
228
229 unsigned long ioaddr;
230 unsigned long opmode_ioaddr;
231 int max_baud;
232
233 int rx_high_water;
234 int rx_trigger; /* Rx fifo trigger level */
235 int rx_low_water;
236 int baud_base; /* max. speed */
237 long realbaud;
238 int type; /* UART type */
239 int flags; /* defined in tty.h */
240 long session; /* Session of opening process */
241 long pgrp; /* pgrp of opening process */
242
243 int x_char; /* xon/xoff character */
244 int IER; /* Interrupt Enable Register */
245 int MCR; /* Modem control register */
246
247 unsigned char stop_rx;
248 unsigned char ldisc_stop_rx;
249
250 int custom_divisor;
251 int close_delay;
252 unsigned short closing_wait;
253 unsigned char err_shadow;
254 unsigned long event;
255
256 int count; /* # of fd on device */
257 int blocked_open; /* # of blocked opens */
258 struct async_icount icount; /* kernel counters for 4 input interrupts */
259 int timeout;
260
261 int read_status_mask;
262 int ignore_status_mask;
263 int xmit_fifo_size;
264 unsigned char *xmit_buf;
265 int xmit_head;
266 int xmit_tail;
267 int xmit_cnt;
268
269 struct ktermios normal_termios;
270 struct ktermios callout_termios;
271
272 struct mxser_mon mon_data;
273
274 spinlock_t slock;
275 struct work_struct tqueue;
276 wait_queue_head_t open_wait;
277 wait_queue_head_t close_wait;
278 wait_queue_head_t delta_msr_wait;
279};
280
281struct mxser_board {
282 unsigned int idx;
283 int irq;
284 const struct mxser_cardinfo *info;
285 unsigned long vector;
286 unsigned long vector_mask;
287
288 int chip_flag;
289 int uart_type;
290
291 struct mxser_port ports[MXSER_PORTS_PER_BOARD];
292};
293
294struct mxser_mstatus {
295 tcflag_t cflag;
296 int cts;
297 int dsr;
298 int ri;
299 int dcd;
300};
301
302static struct mxser_mstatus GMStatus[MXSER_PORTS];
303
304static int mxserBoardCAP[MXSER_BOARDS] = {
305 0, 0, 0, 0
306 /* 0x180, 0x280, 0x200, 0x320 */
307};
308
309static struct mxser_board mxser_boards[MXSER_BOARDS];
310static struct tty_driver *mxvar_sdriver;
311static struct mxser_log mxvar_log;
312static int mxvar_diagflag;
313static unsigned char mxser_msr[MXSER_PORTS + 1];
314static struct mxser_mon_ext mon_data_ext;
315static int mxser_set_baud_method[MXSER_PORTS + 1];
316static spinlock_t gm_lock;
317
318static int CheckIsMoxaMust(int io)
319{
320 u8 oldmcr, hwid;
321 int i;
322
323 outb(0, io + UART_LCR);
324 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
325 oldmcr = inb(io + UART_MCR);
326 outb(0, io + UART_MCR);
327 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
328 if ((hwid = inb(io + UART_MCR)) != 0) {
329 outb(oldmcr, io + UART_MCR);
330 return MOXA_OTHER_UART;
331 }
332
333 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
334 for (i = 1; i < UART_INFO_NUM; i++) { /* 0 = OTHER_UART */
335 if (hwid == Gpci_uart_info[i].type)
336 return (int)hwid;
337 }
338 return MOXA_OTHER_UART;
339}
340
341static void process_txrx_fifo(struct mxser_port *info)
342{
343 int i;
344
345 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
346 info->rx_trigger = 1;
347 info->rx_high_water = 1;
348 info->rx_low_water = 1;
349 info->xmit_fifo_size = 1;
350 } else
351 for (i = 0; i < UART_INFO_NUM; i++)
352 if (info->board->chip_flag == Gpci_uart_info[i].type) {
353 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
354 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
355 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
356 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
357 break;
358 }
359}
360
361static void mxser_do_softint(struct work_struct *work)
362{
363 struct mxser_port *info = container_of(work, struct mxser_port, tqueue);
364 struct tty_struct *tty = info->tty;
365
366 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
367 tty_wakeup(tty);
368}
369
370static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
371{
372 unsigned char status = 0;
373
374 status = inb(baseaddr + UART_MSR);
375
376 mxser_msr[port] &= 0x0F;
377 mxser_msr[port] |= status;
378 status = mxser_msr[port];
379 if (mode)
380 mxser_msr[port] = 0;
381
382 return status;
383}
384
385static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
386 struct mxser_port *port)
387{
388 DECLARE_WAITQUEUE(wait, current);
389 int retval;
390 int do_clocal = 0;
391 unsigned long flags;
392
393 /*
394 * If non-blocking mode is set, or the port is not enabled,
395 * then make the check up front and then exit.
396 */
397 if ((filp->f_flags & O_NONBLOCK) ||
398 test_bit(TTY_IO_ERROR, &tty->flags)) {
399 port->flags |= ASYNC_NORMAL_ACTIVE;
400 return 0;
401 }
402
403 if (tty->termios->c_cflag & CLOCAL)
404 do_clocal = 1;
405
406 /*
407 * Block waiting for the carrier detect and the line to become
408 * free (i.e., not in use by the callout). While we are in
409 * this loop, port->count is dropped by one, so that
410 * mxser_close() knows when to free things. We restore it upon
411 * exit, either normal or abnormal.
412 */
413 retval = 0;
414 add_wait_queue(&port->open_wait, &wait);
415
416 spin_lock_irqsave(&port->slock, flags);
417 if (!tty_hung_up_p(filp))
418 port->count--;
419 spin_unlock_irqrestore(&port->slock, flags);
420 port->blocked_open++;
421 while (1) {
422 spin_lock_irqsave(&port->slock, flags);
423 outb(inb(port->ioaddr + UART_MCR) |
424 UART_MCR_DTR | UART_MCR_RTS, port->ioaddr + UART_MCR);
425 spin_unlock_irqrestore(&port->slock, flags);
426 set_current_state(TASK_INTERRUPTIBLE);
427 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
428 if (port->flags & ASYNC_HUP_NOTIFY)
429 retval = -EAGAIN;
430 else
431 retval = -ERESTARTSYS;
432 break;
433 }
434 if (!(port->flags & ASYNC_CLOSING) &&
435 (do_clocal ||
436 (inb(port->ioaddr + UART_MSR) & UART_MSR_DCD)))
437 break;
438 if (signal_pending(current)) {
439 retval = -ERESTARTSYS;
440 break;
441 }
442 schedule();
443 }
444 set_current_state(TASK_RUNNING);
445 remove_wait_queue(&port->open_wait, &wait);
446 if (!tty_hung_up_p(filp))
447 port->count++;
448 port->blocked_open--;
449 if (retval)
450 return retval;
451 port->flags |= ASYNC_NORMAL_ACTIVE;
452 return 0;
453}
454
455static int mxser_set_baud(struct mxser_port *info, long newspd)
456{
457 int quot = 0;
458 unsigned char cval;
459 int ret = 0;
460 unsigned long flags;
461
462 if (!info->tty || !info->tty->termios)
463 return ret;
464
465 if (!(info->ioaddr))
466 return ret;
467
468 if (newspd > info->max_baud)
469 return 0;
470
471 info->realbaud = newspd;
472 if (newspd == 134) {
473 quot = (2 * info->baud_base / 269);
474 } else if (newspd) {
475 quot = info->baud_base / newspd;
476 if (quot == 0)
477 quot = 1;
478 } else {
479 quot = 0;
480 }
481
482 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
483 info->timeout += HZ / 50; /* Add .02 seconds of slop */
484
485 if (quot) {
486 spin_lock_irqsave(&info->slock, flags);
487 info->MCR |= UART_MCR_DTR;
488 outb(info->MCR, info->ioaddr + UART_MCR);
489 spin_unlock_irqrestore(&info->slock, flags);
490 } else {
491 spin_lock_irqsave(&info->slock, flags);
492 info->MCR &= ~UART_MCR_DTR;
493 outb(info->MCR, info->ioaddr + UART_MCR);
494 spin_unlock_irqrestore(&info->slock, flags);
495 return ret;
496 }
497
498 cval = inb(info->ioaddr + UART_LCR);
499
500 outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */
501
502 outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */
503 outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
504 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
505
506
507 return ret;
508}
509
510/*
511 * This routine is called to set the UART divisor registers to match
512 * the specified baud rate for a serial port.
513 */
514static int mxser_change_speed(struct mxser_port *info,
515 struct ktermios *old_termios)
516{
517 unsigned cflag, cval, fcr;
518 int ret = 0;
519 unsigned char status;
520 long baud;
521 unsigned long flags;
522
523 if (!info->tty || !info->tty->termios)
524 return ret;
525 cflag = info->tty->termios->c_cflag;
526 if (!(info->ioaddr))
527 return ret;
528
529 if (mxser_set_baud_method[info->tty->index] == 0) {
530 baud = tty_get_baud_rate(info->tty);
531 mxser_set_baud(info, baud);
532 }
533
534 /* byte size and parity */
535 switch (cflag & CSIZE) {
536 case CS5:
537 cval = 0x00;
538 break;
539 case CS6:
540 cval = 0x01;
541 break;
542 case CS7:
543 cval = 0x02;
544 break;
545 case CS8:
546 cval = 0x03;
547 break;
548 default:
549 cval = 0x00;
550 break; /* too keep GCC shut... */
551 }
552 if (cflag & CSTOPB)
553 cval |= 0x04;
554 if (cflag & PARENB)
555 cval |= UART_LCR_PARITY;
556 if (!(cflag & PARODD))
557 cval |= UART_LCR_EPAR;
558 if (cflag & CMSPAR)
559 cval |= UART_LCR_SPAR;
560
561 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
562 if (info->board->chip_flag) {
563 fcr = UART_FCR_ENABLE_FIFO;
564 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
565 SET_MOXA_MUST_FIFO_VALUE(info);
566 } else
567 fcr = 0;
568 } else {
569 fcr = UART_FCR_ENABLE_FIFO;
570 if (info->board->chip_flag) {
571 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
572 SET_MOXA_MUST_FIFO_VALUE(info);
573 } else {
574 switch (info->rx_trigger) {
575 case 1:
576 fcr |= UART_FCR_TRIGGER_1;
577 break;
578 case 4:
579 fcr |= UART_FCR_TRIGGER_4;
580 break;
581 case 8:
582 fcr |= UART_FCR_TRIGGER_8;
583 break;
584 default:
585 fcr |= UART_FCR_TRIGGER_14;
586 break;
587 }
588 }
589 }
590
591 /* CTS flow control flag and modem status interrupts */
592 info->IER &= ~UART_IER_MSI;
593 info->MCR &= ~UART_MCR_AFE;
594 if (cflag & CRTSCTS) {
595 info->flags |= ASYNC_CTS_FLOW;
596 info->IER |= UART_IER_MSI;
597 if ((info->type == PORT_16550A) || (info->board->chip_flag)) {
598 info->MCR |= UART_MCR_AFE;
599 } else {
600 status = inb(info->ioaddr + UART_MSR);
601 if (info->tty->hw_stopped) {
602 if (status & UART_MSR_CTS) {
603 info->tty->hw_stopped = 0;
604 if (info->type != PORT_16550A &&
605 !info->board->chip_flag) {
606 outb(info->IER & ~UART_IER_THRI,
607 info->ioaddr +
608 UART_IER);
609 info->IER |= UART_IER_THRI;
610 outb(info->IER, info->ioaddr +
611 UART_IER);
612 }
613 set_bit(MXSER_EVENT_TXLOW, &info->event);
614 schedule_work(&info->tqueue); }
615 } else {
616 if (!(status & UART_MSR_CTS)) {
617 info->tty->hw_stopped = 1;
618 if ((info->type != PORT_16550A) &&
619 (!info->board->chip_flag)) {
620 info->IER &= ~UART_IER_THRI;
621 outb(info->IER, info->ioaddr +
622 UART_IER);
623 }
624 }
625 }
626 }
627 } else {
628 info->flags &= ~ASYNC_CTS_FLOW;
629 }
630 outb(info->MCR, info->ioaddr + UART_MCR);
631 if (cflag & CLOCAL) {
632 info->flags &= ~ASYNC_CHECK_CD;
633 } else {
634 info->flags |= ASYNC_CHECK_CD;
635 info->IER |= UART_IER_MSI;
636 }
637 outb(info->IER, info->ioaddr + UART_IER);
638
639 /*
640 * Set up parity check flag
641 */
642 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
643 if (I_INPCK(info->tty))
644 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
645 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
646 info->read_status_mask |= UART_LSR_BI;
647
648 info->ignore_status_mask = 0;
649
650 if (I_IGNBRK(info->tty)) {
651 info->ignore_status_mask |= UART_LSR_BI;
652 info->read_status_mask |= UART_LSR_BI;
653 /*
654 * If we're ignore parity and break indicators, ignore
655 * overruns too. (For real raw support).
656 */
657 if (I_IGNPAR(info->tty)) {
658 info->ignore_status_mask |=
659 UART_LSR_OE |
660 UART_LSR_PE |
661 UART_LSR_FE;
662 info->read_status_mask |=
663 UART_LSR_OE |
664 UART_LSR_PE |
665 UART_LSR_FE;
666 }
667 }
668 if (info->board->chip_flag) {
669 spin_lock_irqsave(&info->slock, flags);
670 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty));
671 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty));
672 if (I_IXON(info->tty)) {
673 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
674 } else {
675 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
676 }
677 if (I_IXOFF(info->tty)) {
678 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
679 } else {
680 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
681 }
682 spin_unlock_irqrestore(&info->slock, flags);
683 }
684
685
686 outb(fcr, info->ioaddr + UART_FCR); /* set fcr */
687 outb(cval, info->ioaddr + UART_LCR);
688
689 return ret;
690}
691
692static void mxser_check_modem_status(struct mxser_port *port, int status)
693{
694 /* update input line counters */
695 if (status & UART_MSR_TERI)
696 port->icount.rng++;
697 if (status & UART_MSR_DDSR)
698 port->icount.dsr++;
699 if (status & UART_MSR_DDCD)
700 port->icount.dcd++;
701 if (status & UART_MSR_DCTS)
702 port->icount.cts++;
703 port->mon_data.modem_status = status;
704 wake_up_interruptible(&port->delta_msr_wait);
705
706 if ((port->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
707 if (status & UART_MSR_DCD)
708 wake_up_interruptible(&port->open_wait);
709 schedule_work(&port->tqueue);
710 }
711
712 if (port->flags & ASYNC_CTS_FLOW) {
713 if (port->tty->hw_stopped) {
714 if (status & UART_MSR_CTS) {
715 port->tty->hw_stopped = 0;
716
717 if ((port->type != PORT_16550A) &&
718 (!port->board->chip_flag)) {
719 outb(port->IER & ~UART_IER_THRI,
720 port->ioaddr + UART_IER);
721 port->IER |= UART_IER_THRI;
722 outb(port->IER, port->ioaddr +
723 UART_IER);
724 }
725 set_bit(MXSER_EVENT_TXLOW, &port->event);
726 schedule_work(&port->tqueue);
727 }
728 } else {
729 if (!(status & UART_MSR_CTS)) {
730 port->tty->hw_stopped = 1;
731 if (port->type != PORT_16550A &&
732 !port->board->chip_flag) {
733 port->IER &= ~UART_IER_THRI;
734 outb(port->IER, port->ioaddr +
735 UART_IER);
736 }
737 }
738 }
739 }
740}
741
742static int mxser_startup(struct mxser_port *info)
743{
744 unsigned long page;
745 unsigned long flags;
746
747 page = __get_free_page(GFP_KERNEL);
748 if (!page)
749 return -ENOMEM;
750
751 spin_lock_irqsave(&info->slock, flags);
752
753 if (info->flags & ASYNC_INITIALIZED) {
754 free_page(page);
755 spin_unlock_irqrestore(&info->slock, flags);
756 return 0;
757 }
758
759 if (!info->ioaddr || !info->type) {
760 if (info->tty)
761 set_bit(TTY_IO_ERROR, &info->tty->flags);
762 free_page(page);
763 spin_unlock_irqrestore(&info->slock, flags);
764 return 0;
765 }
766 if (info->xmit_buf)
767 free_page(page);
768 else
769 info->xmit_buf = (unsigned char *) page;
770
771 /*
772 * Clear the FIFO buffers and disable them
773 * (they will be reenabled in mxser_change_speed())
774 */
775 if (info->board->chip_flag)
776 outb((UART_FCR_CLEAR_RCVR |
777 UART_FCR_CLEAR_XMIT |
778 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->ioaddr + UART_FCR);
779 else
780 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
781 info->ioaddr + UART_FCR);
782
783 /*
784 * At this point there's no way the LSR could still be 0xFF;
785 * if it is, then bail out, because there's likely no UART
786 * here.
787 */
788 if (inb(info->ioaddr + UART_LSR) == 0xff) {
789 spin_unlock_irqrestore(&info->slock, flags);
790 if (capable(CAP_SYS_ADMIN)) {
791 if (info->tty)
792 set_bit(TTY_IO_ERROR, &info->tty->flags);
793 return 0;
794 } else
795 return -ENODEV;
796 }
797
798 /*
799 * Clear the interrupt registers.
800 */
801 (void) inb(info->ioaddr + UART_LSR);
802 (void) inb(info->ioaddr + UART_RX);
803 (void) inb(info->ioaddr + UART_IIR);
804 (void) inb(info->ioaddr + UART_MSR);
805
806 /*
807 * Now, initialize the UART
808 */
809 outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */
810 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
811 outb(info->MCR, info->ioaddr + UART_MCR);
812
813 /*
814 * Finally, enable interrupts
815 */
816 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
817
818 if (info->board->chip_flag)
819 info->IER |= MOXA_MUST_IER_EGDAI;
820 outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */
821
822 /*
823 * And clear the interrupt registers again for luck.
824 */
825 (void) inb(info->ioaddr + UART_LSR);
826 (void) inb(info->ioaddr + UART_RX);
827 (void) inb(info->ioaddr + UART_IIR);
828 (void) inb(info->ioaddr + UART_MSR);
829
830 if (info->tty)
831 clear_bit(TTY_IO_ERROR, &info->tty->flags);
832 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
833
834 /*
835 * and set the speed of the serial port
836 */
837 spin_unlock_irqrestore(&info->slock, flags);
838 mxser_change_speed(info, NULL);
839
840 info->flags |= ASYNC_INITIALIZED;
841 return 0;
842}
843
844/*
845 * This routine will shutdown a serial port; interrupts maybe disabled, and
846 * DTR is dropped if the hangup on close termio flag is on.
847 */
848static void mxser_shutdown(struct mxser_port *info)
849{
850 unsigned long flags;
851
852 if (!(info->flags & ASYNC_INITIALIZED))
853 return;
854
855 spin_lock_irqsave(&info->slock, flags);
856
857 /*
858 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
859 * here so the queue might never be waken up
860 */
861 wake_up_interruptible(&info->delta_msr_wait);
862
863 /*
864 * Free the IRQ, if necessary
865 */
866 if (info->xmit_buf) {
867 free_page((unsigned long) info->xmit_buf);
868 info->xmit_buf = NULL;
869 }
870
871 info->IER = 0;
872 outb(0x00, info->ioaddr + UART_IER);
873
874 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
875 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
876 outb(info->MCR, info->ioaddr + UART_MCR);
877
878 /* clear Rx/Tx FIFO's */
879 if (info->board->chip_flag)
880 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
881 MOXA_MUST_FCR_GDA_MODE_ENABLE,
882 info->ioaddr + UART_FCR);
883 else
884 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
885 info->ioaddr + UART_FCR);
886
887 /* read data port to reset things */
888 (void) inb(info->ioaddr + UART_RX);
889
890 if (info->tty)
891 set_bit(TTY_IO_ERROR, &info->tty->flags);
892
893 info->flags &= ~ASYNC_INITIALIZED;
894
895 if (info->board->chip_flag)
896 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr);
897
898 spin_unlock_irqrestore(&info->slock, flags);
899}
900
901/*
902 * This routine is called whenever a serial port is opened. It
903 * enables interrupts for a serial port, linking in its async structure into
904 * the IRQ chain. It also performs the serial-specific
905 * initialization for the tty structure.
906 */
907static int mxser_open(struct tty_struct *tty, struct file *filp)
908{
909 struct mxser_port *info;
910 int retval, line;
911
912 /* initialize driver_data in case something fails */
913 tty->driver_data = NULL;
914
915 line = tty->index;
916 if (line == MXSER_PORTS)
917 return 0;
918 if (line < 0 || line > MXSER_PORTS)
919 return -ENODEV;
920 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
921 if (!info->ioaddr)
922 return -ENODEV;
923
924 tty->driver_data = info;
925 info->tty = tty;
926 /*
927 * Start up serial port
928 */
929 info->count++;
930 retval = mxser_startup(info);
931 if (retval)
932 return retval;
933
934 retval = mxser_block_til_ready(tty, filp, info);
935 if (retval)
936 return retval;
937
938 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
939 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
940 *tty->termios = info->normal_termios;
941 else
942 *tty->termios = info->callout_termios;
943 mxser_change_speed(info, NULL);
944 }
945
946 info->session = process_session(current);
947 info->pgrp = process_group(current);
948
949 /* unmark here for very high baud rate (ex. 921600 bps) used */
950 tty->low_latency = 1;
951 return 0;
952}
953
954/*
955 * This routine is called when the serial port gets closed. First, we
956 * wait for the last remaining data to be sent. Then, we unlink its
957 * async structure from the interrupt chain if necessary, and we free
958 * that IRQ if nothing is left in the chain.
959 */
960static void mxser_close(struct tty_struct *tty, struct file *filp)
961{
962 struct mxser_port *info = tty->driver_data;
963
964 unsigned long timeout;
965 unsigned long flags;
966
967 if (tty->index == MXSER_PORTS)
968 return;
969 if (!info)
970 return;
971
972 spin_lock_irqsave(&info->slock, flags);
973
974 if (tty_hung_up_p(filp)) {
975 spin_unlock_irqrestore(&info->slock, flags);
976 return;
977 }
978 if ((tty->count == 1) && (info->count != 1)) {
979 /*
980 * Uh, oh. tty->count is 1, which means that the tty
981 * structure will be freed. Info->count should always
982 * be one in these conditions. If it's greater than
983 * one, we've got real problems, since it means the
984 * serial port won't be shutdown.
985 */
986 printk(KERN_ERR "mxser_close: bad serial port count; "
987 "tty->count is 1, info->count is %d\n", info->count);
988 info->count = 1;
989 }
990 if (--info->count < 0) {
991 printk(KERN_ERR "mxser_close: bad serial port count for "
992 "ttys%d: %d\n", tty->index, info->count);
993 info->count = 0;
994 }
995 if (info->count) {
996 spin_unlock_irqrestore(&info->slock, flags);
997 return;
998 }
999 info->flags |= ASYNC_CLOSING;
1000 spin_unlock_irqrestore(&info->slock, flags);
1001 /*
1002 * Save the termios structure, since this port may have
1003 * separate termios for callout and dialin.
1004 */
1005 if (info->flags & ASYNC_NORMAL_ACTIVE)
1006 info->normal_termios = *tty->termios;
1007 /*
1008 * Now we wait for the transmit buffer to clear; and we notify
1009 * the line discipline to only process XON/XOFF characters.
1010 */
1011 tty->closing = 1;
1012 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1013 tty_wait_until_sent(tty, info->closing_wait);
1014 /*
1015 * At this point we stop accepting input. To do this, we
1016 * disable the receive line status interrupts, and tell the
1017 * interrupt driver to stop checking the data ready bit in the
1018 * line status register.
1019 */
1020 info->IER &= ~UART_IER_RLSI;
1021 if (info->board->chip_flag)
1022 info->IER &= ~MOXA_MUST_RECV_ISR;
1023
1024 if (info->flags & ASYNC_INITIALIZED) {
1025 outb(info->IER, info->ioaddr + UART_IER);
1026 /*
1027 * Before we drop DTR, make sure the UART transmitter
1028 * has completely drained; this is especially
1029 * important if there is a transmit FIFO!
1030 */
1031 timeout = jiffies + HZ;
1032 while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
1033 schedule_timeout_interruptible(5);
1034 if (time_after(jiffies, timeout))
1035 break;
1036 }
1037 }
1038 mxser_shutdown(info);
1039
1040 if (tty->driver->flush_buffer)
1041 tty->driver->flush_buffer(tty);
1042
1043 tty_ldisc_flush(tty);
1044
1045 tty->closing = 0;
1046 info->event = 0;
1047 info->tty = NULL;
1048 if (info->blocked_open) {
1049 if (info->close_delay)
1050 schedule_timeout_interruptible(info->close_delay);
1051 wake_up_interruptible(&info->open_wait);
1052 }
1053
1054 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1055 wake_up_interruptible(&info->close_wait);
1056
1057}
1058
1059static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1060{
1061 int c, total = 0;
1062 struct mxser_port *info = tty->driver_data;
1063 unsigned long flags;
1064
1065 if (!info->xmit_buf)
1066 return 0;
1067
1068 while (1) {
1069 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1070 SERIAL_XMIT_SIZE - info->xmit_head));
1071 if (c <= 0)
1072 break;
1073
1074 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1075 spin_lock_irqsave(&info->slock, flags);
1076 info->xmit_head = (info->xmit_head + c) &
1077 (SERIAL_XMIT_SIZE - 1);
1078 info->xmit_cnt += c;
1079 spin_unlock_irqrestore(&info->slock, flags);
1080
1081 buf += c;
1082 count -= c;
1083 total += c;
1084 }
1085
1086 if (info->xmit_cnt && !tty->stopped) {
1087 if (!tty->hw_stopped ||
1088 (info->type == PORT_16550A) ||
1089 (info->board->chip_flag)) {
1090 spin_lock_irqsave(&info->slock, flags);
1091 outb(info->IER & ~UART_IER_THRI, info->ioaddr +
1092 UART_IER);
1093 info->IER |= UART_IER_THRI;
1094 outb(info->IER, info->ioaddr + UART_IER);
1095 spin_unlock_irqrestore(&info->slock, flags);
1096 }
1097 }
1098 return total;
1099}
1100
1101static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1102{
1103 struct mxser_port *info = tty->driver_data;
1104 unsigned long flags;
1105
1106 if (!info->xmit_buf)
1107 return;
1108
1109 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1110 return;
1111
1112 spin_lock_irqsave(&info->slock, flags);
1113 info->xmit_buf[info->xmit_head++] = ch;
1114 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1115 info->xmit_cnt++;
1116 spin_unlock_irqrestore(&info->slock, flags);
1117 if (!tty->stopped) {
1118 if (!tty->hw_stopped ||
1119 (info->type == PORT_16550A) ||
1120 info->board->chip_flag) {
1121 spin_lock_irqsave(&info->slock, flags);
1122 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1123 info->IER |= UART_IER_THRI;
1124 outb(info->IER, info->ioaddr + UART_IER);
1125 spin_unlock_irqrestore(&info->slock, flags);
1126 }
1127 }
1128}
1129
1130
1131static void mxser_flush_chars(struct tty_struct *tty)
1132{
1133 struct mxser_port *info = tty->driver_data;
1134 unsigned long flags;
1135
1136 if (info->xmit_cnt <= 0 ||
1137 tty->stopped ||
1138 !info->xmit_buf ||
1139 (tty->hw_stopped &&
1140 (info->type != PORT_16550A) &&
1141 (!info->board->chip_flag)
1142 ))
1143 return;
1144
1145 spin_lock_irqsave(&info->slock, flags);
1146
1147 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1148 info->IER |= UART_IER_THRI;
1149 outb(info->IER, info->ioaddr + UART_IER);
1150
1151 spin_unlock_irqrestore(&info->slock, flags);
1152}
1153
1154static int mxser_write_room(struct tty_struct *tty)
1155{
1156 struct mxser_port *info = tty->driver_data;
1157 int ret;
1158
1159 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1160 if (ret < 0)
1161 ret = 0;
1162 return ret;
1163}
1164
1165static int mxser_chars_in_buffer(struct tty_struct *tty)
1166{
1167 struct mxser_port *info = tty->driver_data;
1168 return info->xmit_cnt;
1169}
1170
1171static void mxser_flush_buffer(struct tty_struct *tty)
1172{
1173 struct mxser_port *info = tty->driver_data;
1174 char fcr;
1175 unsigned long flags;
1176
1177
1178 spin_lock_irqsave(&info->slock, flags);
1179 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1180
1181 fcr = inb(info->ioaddr + UART_FCR);
1182 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1183 info->ioaddr + UART_FCR);
1184 outb(fcr, info->ioaddr + UART_FCR);
1185
1186 spin_unlock_irqrestore(&info->slock, flags);
1187
1188 tty_wakeup(tty);
1189}
1190
1191/*
1192 * ------------------------------------------------------------
1193 * friends of mxser_ioctl()
1194 * ------------------------------------------------------------
1195 */
1196static int mxser_get_serial_info(struct mxser_port *info,
1197 struct serial_struct __user *retinfo)
1198{
1199 struct serial_struct tmp;
1200
1201 if (!retinfo)
1202 return -EFAULT;
1203 memset(&tmp, 0, sizeof(tmp));
1204 tmp.type = info->type;
1205 tmp.line = info->tty->index;
1206 tmp.port = info->ioaddr;
1207 tmp.irq = info->board->irq;
1208 tmp.flags = info->flags;
1209 tmp.baud_base = info->baud_base;
1210 tmp.close_delay = info->close_delay;
1211 tmp.closing_wait = info->closing_wait;
1212 tmp.custom_divisor = info->custom_divisor;
1213 tmp.hub6 = 0;
1214 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1215 return -EFAULT;
1216 return 0;
1217}
1218
1219static int mxser_set_serial_info(struct mxser_port *info,
1220 struct serial_struct __user *new_info)
1221{
1222 struct serial_struct new_serial;
1223 unsigned int flags;
1224 int retval = 0;
1225
1226 if (!new_info || !info->ioaddr)
1227 return -EFAULT;
1228 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1229 return -EFAULT;
1230
1231 if ((new_serial.irq != info->board->irq) ||
1232 (new_serial.port != info->ioaddr) ||
1233 (new_serial.custom_divisor != info->custom_divisor) ||
1234 (new_serial.baud_base != info->baud_base))
1235 return -EPERM;
1236
1237 flags = info->flags & ASYNC_SPD_MASK;
1238
1239 if (!capable(CAP_SYS_ADMIN)) {
1240 if ((new_serial.baud_base != info->baud_base) ||
1241 (new_serial.close_delay != info->close_delay) ||
1242 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
1243 return -EPERM;
1244 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1245 (new_serial.flags & ASYNC_USR_MASK));
1246 } else {
1247 /*
1248 * OK, past this point, all the error checking has been done.
1249 * At this point, we start making changes.....
1250 */
1251 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1252 (new_serial.flags & ASYNC_FLAGS));
1253 info->close_delay = new_serial.close_delay * HZ / 100;
1254 info->closing_wait = new_serial.closing_wait * HZ / 100;
1255 info->tty->low_latency =
1256 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1257 info->tty->low_latency = 0;
1258 }
1259
1260 info->type = new_serial.type;
1261
1262 process_txrx_fifo(info);
1263
1264 if (info->flags & ASYNC_INITIALIZED) {
1265 if (flags != (info->flags & ASYNC_SPD_MASK))
1266 mxser_change_speed(info, NULL);
1267 } else
1268 retval = mxser_startup(info);
1269
1270 return retval;
1271}
1272
1273/*
1274 * mxser_get_lsr_info - get line status register info
1275 *
1276 * Purpose: Let user call ioctl() to get info when the UART physically
1277 * is emptied. On bus types like RS485, the transmitter must
1278 * release the bus after transmitting. This must be done when
1279 * the transmit shift register is empty, not be done when the
1280 * transmit holding register is empty. This functionality
1281 * allows an RS485 driver to be written in user space.
1282 */
1283static int mxser_get_lsr_info(struct mxser_port *info,
1284 unsigned int __user *value)
1285{
1286 unsigned char status;
1287 unsigned int result;
1288 unsigned long flags;
1289
1290 spin_lock_irqsave(&info->slock, flags);
1291 status = inb(info->ioaddr + UART_LSR);
1292 spin_unlock_irqrestore(&info->slock, flags);
1293 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1294 return put_user(result, value);
1295}
1296
1297/*
1298 * This routine sends a break character out the serial port.
1299 */
1300static void mxser_send_break(struct mxser_port *info, int duration)
1301{
1302 unsigned long flags;
1303
1304 if (!info->ioaddr)
1305 return;
1306 set_current_state(TASK_INTERRUPTIBLE);
1307 spin_lock_irqsave(&info->slock, flags);
1308 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
1309 info->ioaddr + UART_LCR);
1310 spin_unlock_irqrestore(&info->slock, flags);
1311 schedule_timeout(duration);
1312 spin_lock_irqsave(&info->slock, flags);
1313 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
1314 info->ioaddr + UART_LCR);
1315 spin_unlock_irqrestore(&info->slock, flags);
1316}
1317
1318static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1319{
1320 struct mxser_port *info = tty->driver_data;
1321 unsigned char control, status;
1322 unsigned long flags;
1323
1324
1325 if (tty->index == MXSER_PORTS)
1326 return -ENOIOCTLCMD;
1327 if (test_bit(TTY_IO_ERROR, &tty->flags))
1328 return -EIO;
1329
1330 control = info->MCR;
1331
1332 spin_lock_irqsave(&info->slock, flags);
1333 status = inb(info->ioaddr + UART_MSR);
1334 if (status & UART_MSR_ANY_DELTA)
1335 mxser_check_modem_status(info, status);
1336 spin_unlock_irqrestore(&info->slock, flags);
1337 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
1338 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
1339 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
1340 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
1341 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
1342 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1343}
1344
1345static int mxser_tiocmset(struct tty_struct *tty, struct file *file,
1346 unsigned int set, unsigned int clear)
1347{
1348 struct mxser_port *info = tty->driver_data;
1349 unsigned long flags;
1350
1351
1352 if (tty->index == MXSER_PORTS)
1353 return -ENOIOCTLCMD;
1354 if (test_bit(TTY_IO_ERROR, &tty->flags))
1355 return -EIO;
1356
1357 spin_lock_irqsave(&info->slock, flags);
1358
1359 if (set & TIOCM_RTS)
1360 info->MCR |= UART_MCR_RTS;
1361 if (set & TIOCM_DTR)
1362 info->MCR |= UART_MCR_DTR;
1363
1364 if (clear & TIOCM_RTS)
1365 info->MCR &= ~UART_MCR_RTS;
1366 if (clear & TIOCM_DTR)
1367 info->MCR &= ~UART_MCR_DTR;
1368
1369 outb(info->MCR, info->ioaddr + UART_MCR);
1370 spin_unlock_irqrestore(&info->slock, flags);
1371 return 0;
1372}
1373
1374static int mxser_program_mode(int port)
1375{
1376 int id, i, j, n;
1377
1378 spin_lock(&gm_lock);
1379 outb(0, port);
1380 outb(0, port);
1381 outb(0, port);
1382 (void)inb(port);
1383 (void)inb(port);
1384 outb(0, port);
1385 (void)inb(port);
1386 spin_unlock(&gm_lock);
1387
1388 id = inb(port + 1) & 0x1F;
1389 if ((id != C168_ASIC_ID) &&
1390 (id != C104_ASIC_ID) &&
1391 (id != C102_ASIC_ID) &&
1392 (id != CI132_ASIC_ID) &&
1393 (id != CI134_ASIC_ID) &&
1394 (id != CI104J_ASIC_ID))
1395 return -1;
1396 for (i = 0, j = 0; i < 4; i++) {
1397 n = inb(port + 2);
1398 if (n == 'M') {
1399 j = 1;
1400 } else if ((j == 1) && (n == 1)) {
1401 j = 2;
1402 break;
1403 } else
1404 j = 0;
1405 }
1406 if (j != 2)
1407 id = -2;
1408 return id;
1409}
1410
1411static void mxser_normal_mode(int port)
1412{
1413 int i, n;
1414
1415 outb(0xA5, port + 1);
1416 outb(0x80, port + 3);
1417 outb(12, port + 0); /* 9600 bps */
1418 outb(0, port + 1);
1419 outb(0x03, port + 3); /* 8 data bits */
1420 outb(0x13, port + 4); /* loop back mode */
1421 for (i = 0; i < 16; i++) {
1422 n = inb(port + 5);
1423 if ((n & 0x61) == 0x60)
1424 break;
1425 if ((n & 1) == 1)
1426 (void)inb(port);
1427 }
1428 outb(0x00, port + 4);
1429}
1430
1431#define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
1432#define CHIP_DO 0x02 /* Serial Data Output in Eprom */
1433#define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
1434#define CHIP_DI 0x08 /* Serial Data Input in Eprom */
1435#define EN_CCMD 0x000 /* Chip's command register */
1436#define EN0_RSARLO 0x008 /* Remote start address reg 0 */
1437#define EN0_RSARHI 0x009 /* Remote start address reg 1 */
1438#define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
1439#define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
1440#define EN0_DCFG 0x00E /* Data configuration reg WR */
1441#define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1442#define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1443#define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1444static int mxser_read_register(int port, unsigned short *regs)
1445{
1446 int i, k, value, id;
1447 unsigned int j;
1448
1449 id = mxser_program_mode(port);
1450 if (id < 0)
1451 return id;
1452 for (i = 0; i < 14; i++) {
1453 k = (i & 0x3F) | 0x180;
1454 for (j = 0x100; j > 0; j >>= 1) {
1455 outb(CHIP_CS, port);
1456 if (k & j) {
1457 outb(CHIP_CS | CHIP_DO, port);
1458 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
1459 } else {
1460 outb(CHIP_CS, port);
1461 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
1462 }
1463 }
1464 (void)inb(port);
1465 value = 0;
1466 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
1467 outb(CHIP_CS, port);
1468 outb(CHIP_CS | CHIP_SK, port);
1469 if (inb(port) & CHIP_DI)
1470 value |= j;
1471 }
1472 regs[i] = value;
1473 outb(0, port);
1474 }
1475 mxser_normal_mode(port);
1476 return id;
1477}
1478
1479static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1480{
1481 struct mxser_port *port;
1482 int result, status;
1483 unsigned int i, j;
1484
1485 switch (cmd) {
1486 case MOXA_GET_CONF:
1487/* if (copy_to_user(argp, mxsercfg,
1488 sizeof(struct mxser_hwconf) * 4))
1489 return -EFAULT;
1490 return 0;*/
1491 return -ENXIO;
1492 case MOXA_GET_MAJOR:
1493 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1494 return -EFAULT;
1495 return 0;
1496
1497 case MOXA_GET_CUMAJOR:
1498 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1499 return -EFAULT;
1500 return 0;
1501
1502 case MOXA_CHKPORTENABLE:
1503 result = 0;
1504
1505 for (i = 0; i < MXSER_BOARDS; i++)
1506 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++)
1507 if (mxser_boards[i].ports[j].ioaddr)
1508 result |= (1 << i);
1509
1510 return put_user(result, (unsigned long __user *)argp);
1511 case MOXA_GETDATACOUNT:
1512 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1513 return -EFAULT;
1514 return 0;
1515 case MOXA_GETMSTATUS:
1516 for (i = 0; i < MXSER_BOARDS; i++)
1517 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1518 port = &mxser_boards[i].ports[j];
1519
1520 GMStatus[i].ri = 0;
1521 if (!port->ioaddr) {
1522 GMStatus[i].dcd = 0;
1523 GMStatus[i].dsr = 0;
1524 GMStatus[i].cts = 0;
1525 continue;
1526 }
1527
1528 if (!port->tty || !port->tty->termios)
1529 GMStatus[i].cflag =
1530 port->normal_termios.c_cflag;
1531 else
1532 GMStatus[i].cflag =
1533 port->tty->termios->c_cflag;
1534
1535 status = inb(port->ioaddr + UART_MSR);
1536 if (status & 0x80 /*UART_MSR_DCD */ )
1537 GMStatus[i].dcd = 1;
1538 else
1539 GMStatus[i].dcd = 0;
1540
1541 if (status & 0x20 /*UART_MSR_DSR */ )
1542 GMStatus[i].dsr = 1;
1543 else
1544 GMStatus[i].dsr = 0;
1545
1546
1547 if (status & 0x10 /*UART_MSR_CTS */ )
1548 GMStatus[i].cts = 1;
1549 else
1550 GMStatus[i].cts = 0;
1551 }
1552 if (copy_to_user(argp, GMStatus,
1553 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1554 return -EFAULT;
1555 return 0;
1556 case MOXA_ASPP_MON_EXT: {
1557 int status, p, shiftbit;
1558 unsigned long opmode;
1559 unsigned cflag, iflag;
1560
1561 for (i = 0; i < MXSER_BOARDS; i++)
1562 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1563 port = &mxser_boards[i].ports[j];
1564 if (!port->ioaddr)
1565 continue;
1566
1567 status = mxser_get_msr(port->ioaddr, 0, i);
1568
1569 if (status & UART_MSR_TERI)
1570 port->icount.rng++;
1571 if (status & UART_MSR_DDSR)
1572 port->icount.dsr++;
1573 if (status & UART_MSR_DDCD)
1574 port->icount.dcd++;
1575 if (status & UART_MSR_DCTS)
1576 port->icount.cts++;
1577
1578 port->mon_data.modem_status = status;
1579 mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt;
1580 mon_data_ext.tx_cnt[i] = port->mon_data.txcnt;
1581 mon_data_ext.up_rxcnt[i] =
1582 port->mon_data.up_rxcnt;
1583 mon_data_ext.up_txcnt[i] =
1584 port->mon_data.up_txcnt;
1585 mon_data_ext.modem_status[i] =
1586 port->mon_data.modem_status;
1587 mon_data_ext.baudrate[i] = port->realbaud;
1588
1589 if (!port->tty || !port->tty->termios) {
1590 cflag = port->normal_termios.c_cflag;
1591 iflag = port->normal_termios.c_iflag;
1592 } else {
1593 cflag = port->tty->termios->c_cflag;
1594 iflag = port->tty->termios->c_iflag;
1595 }
1596
1597 mon_data_ext.databits[i] = cflag & CSIZE;
1598
1599 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1600
1601 mon_data_ext.parity[i] =
1602 cflag & (PARENB | PARODD | CMSPAR);
1603
1604 mon_data_ext.flowctrl[i] = 0x00;
1605
1606 if (cflag & CRTSCTS)
1607 mon_data_ext.flowctrl[i] |= 0x03;
1608
1609 if (iflag & (IXON | IXOFF))
1610 mon_data_ext.flowctrl[i] |= 0x0C;
1611
1612 if (port->type == PORT_16550A)
1613 mon_data_ext.fifo[i] = 1;
1614 else
1615 mon_data_ext.fifo[i] = 0;
1616
1617 p = i % 4;
1618 shiftbit = p * 2;
1619 opmode = inb(port->opmode_ioaddr) >> shiftbit;
1620 opmode &= OP_MODE_MASK;
1621
1622 mon_data_ext.iftype[i] = opmode;
1623
1624 }
1625 if (copy_to_user(argp, &mon_data_ext,
1626 sizeof(mon_data_ext)))
1627 return -EFAULT;
1628
1629 return 0;
1630
1631 } default:
1632 return -ENOIOCTLCMD;
1633 }
1634 return 0;
1635}
1636
1637static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1638 unsigned int cmd, unsigned long arg)
1639{
1640 struct mxser_port *info = tty->driver_data;
1641 struct async_icount cprev, cnow; /* kernel counter temps */
1642 struct serial_icounter_struct __user *p_cuser;
1643 unsigned long templ;
1644 unsigned long flags;
1645 void __user *argp = (void __user *)arg;
1646 int retval;
1647
1648 if (tty->index == MXSER_PORTS)
1649 return mxser_ioctl_special(cmd, argp);
1650
1651 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1652 int p;
1653 unsigned long opmode;
1654 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1655 int shiftbit;
1656 unsigned char val, mask;
1657
1658 p = tty->index % 4;
1659 if (cmd == MOXA_SET_OP_MODE) {
1660 if (get_user(opmode, (int __user *) argp))
1661 return -EFAULT;
1662 if (opmode != RS232_MODE &&
1663 opmode != RS485_2WIRE_MODE &&
1664 opmode != RS422_MODE &&
1665 opmode != RS485_4WIRE_MODE)
1666 return -EFAULT;
1667 mask = ModeMask[p];
1668 shiftbit = p * 2;
1669 val = inb(info->opmode_ioaddr);
1670 val &= mask;
1671 val |= (opmode << shiftbit);
1672 outb(val, info->opmode_ioaddr);
1673 } else {
1674 shiftbit = p * 2;
1675 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1676 opmode &= OP_MODE_MASK;
1677 if (copy_to_user(argp, &opmode, sizeof(int)))
1678 return -EFAULT;
1679 }
1680 return 0;
1681 }
1682
1683 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT &&
1684 test_bit(TTY_IO_ERROR, &tty->flags))
1685 return -EIO;
1686
1687 switch (cmd) {
1688 case TCSBRK: /* SVID version: non-zero arg --> no break */
1689 retval = tty_check_change(tty);
1690 if (retval)
1691 return retval;
1692 tty_wait_until_sent(tty, 0);
1693 if (!arg)
1694 mxser_send_break(info, HZ / 4); /* 1/4 second */
1695 return 0;
1696 case TCSBRKP: /* support for POSIX tcsendbreak() */
1697 retval = tty_check_change(tty);
1698 if (retval)
1699 return retval;
1700 tty_wait_until_sent(tty, 0);
1701 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1702 return 0;
1703 case TIOCGSOFTCAR:
1704 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1705 case TIOCSSOFTCAR:
1706 if (get_user(templ, (unsigned long __user *) argp))
1707 return -EFAULT;
1708 arg = templ;
1709 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1710 return 0;
1711 case TIOCGSERIAL:
1712 return mxser_get_serial_info(info, argp);
1713 case TIOCSSERIAL:
1714 return mxser_set_serial_info(info, argp);
1715 case TIOCSERGETLSR: /* Get line status register */
1716 return mxser_get_lsr_info(info, argp);
1717 /*
1718 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1719 * - mask passed in arg for lines of interest
1720 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1721 * Caller should use TIOCGICOUNT to see which one it was
1722 */
1723 case TIOCMIWAIT: {
1724 DECLARE_WAITQUEUE(wait, current);
1725 int ret;
1726 spin_lock_irqsave(&info->slock, flags);
1727 cprev = info->icount; /* note the counters on entry */
1728 spin_unlock_irqrestore(&info->slock, flags);
1729
1730 add_wait_queue(&info->delta_msr_wait, &wait);
1731 while (1) {
1732 spin_lock_irqsave(&info->slock, flags);
1733 cnow = info->icount; /* atomic copy */
1734 spin_unlock_irqrestore(&info->slock, flags);
1735
1736 set_current_state(TASK_INTERRUPTIBLE);
1737 if (((arg & TIOCM_RNG) &&
1738 (cnow.rng != cprev.rng)) ||
1739 ((arg & TIOCM_DSR) &&
1740 (cnow.dsr != cprev.dsr)) ||
1741 ((arg & TIOCM_CD) &&
1742 (cnow.dcd != cprev.dcd)) ||
1743 ((arg & TIOCM_CTS) &&
1744 (cnow.cts != cprev.cts))) {
1745 ret = 0;
1746 break;
1747 }
1748 /* see if a signal did it */
1749 if (signal_pending(current)) {
1750 ret = -ERESTARTSYS;
1751 break;
1752 }
1753 cprev = cnow;
1754 }
1755 current->state = TASK_RUNNING;
1756 remove_wait_queue(&info->delta_msr_wait, &wait);
1757 break;
1758 }
1759 /* NOTREACHED */
1760 /*
1761 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1762 * Return: write counters to the user passed counter struct
1763 * NB: both 1->0 and 0->1 transitions are counted except for
1764 * RI where only 0->1 is counted.
1765 */
1766 case TIOCGICOUNT:
1767 spin_lock_irqsave(&info->slock, flags);
1768 cnow = info->icount;
1769 spin_unlock_irqrestore(&info->slock, flags);
1770 p_cuser = argp;
1771 if (put_user(cnow.frame, &p_cuser->frame))
1772 return -EFAULT;
1773 if (put_user(cnow.brk, &p_cuser->brk))
1774 return -EFAULT;
1775 if (put_user(cnow.overrun, &p_cuser->overrun))
1776 return -EFAULT;
1777 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1778 return -EFAULT;
1779 if (put_user(cnow.parity, &p_cuser->parity))
1780 return -EFAULT;
1781 if (put_user(cnow.rx, &p_cuser->rx))
1782 return -EFAULT;
1783 if (put_user(cnow.tx, &p_cuser->tx))
1784 return -EFAULT;
1785 put_user(cnow.cts, &p_cuser->cts);
1786 put_user(cnow.dsr, &p_cuser->dsr);
1787 put_user(cnow.rng, &p_cuser->rng);
1788 put_user(cnow.dcd, &p_cuser->dcd);
1789 return 0;
1790 case MOXA_HighSpeedOn:
1791 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1792 case MOXA_SDS_RSTICOUNTER:
1793 info->mon_data.rxcnt = 0;
1794 info->mon_data.txcnt = 0;
1795 return 0;
1796 case MOXA_ASPP_SETBAUD:{
1797 long baud;
1798 if (get_user(baud, (long __user *)argp))
1799 return -EFAULT;
1800 mxser_set_baud(info, baud);
1801 return 0;
1802 }
1803 case MOXA_ASPP_GETBAUD:
1804 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1805 return -EFAULT;
1806
1807 return 0;
1808
1809 case MOXA_ASPP_OQUEUE:{
1810 int len, lsr;
1811
1812 len = mxser_chars_in_buffer(tty);
1813
1814 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT;
1815
1816 len += (lsr ? 0 : 1);
1817
1818 if (copy_to_user(argp, &len, sizeof(int)))
1819 return -EFAULT;
1820
1821 return 0;
1822 }
1823 case MOXA_ASPP_MON: {
1824 int mcr, status;
1825
1826 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1827 mxser_check_modem_status(info, status);
1828
1829 mcr = inb(info->ioaddr + UART_MCR);
1830 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1831 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1832 else
1833 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1834
1835 if (mcr & MOXA_MUST_MCR_TX_XON)
1836 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1837 else
1838 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1839
1840 if (info->tty->hw_stopped)
1841 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1842 else
1843 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1844
1845 if (copy_to_user(argp, &info->mon_data,
1846 sizeof(struct mxser_mon)))
1847 return -EFAULT;
1848
1849 return 0;
1850 }
1851 case MOXA_ASPP_LSTATUS: {
1852 if (copy_to_user(argp, &info->err_shadow,
1853 sizeof(unsigned char)))
1854 return -EFAULT;
1855
1856 info->err_shadow = 0;
1857 return 0;
1858 }
1859 case MOXA_SET_BAUD_METHOD: {
1860 int method;
1861
1862 if (get_user(method, (int __user *)argp))
1863 return -EFAULT;
1864 mxser_set_baud_method[tty->index] = method;
1865 if (copy_to_user(argp, &method, sizeof(int)))
1866 return -EFAULT;
1867
1868 return 0;
1869 }
1870 default:
1871 return -ENOIOCTLCMD;
1872 }
1873 return 0;
1874}
1875
1876static void mxser_stoprx(struct tty_struct *tty)
1877{
1878 struct mxser_port *info = tty->driver_data;
1879
1880 info->ldisc_stop_rx = 1;
1881 if (I_IXOFF(tty)) {
1882 if (info->board->chip_flag) {
1883 info->IER &= ~MOXA_MUST_RECV_ISR;
1884 outb(info->IER, info->ioaddr + UART_IER);
1885 } else {
1886 info->x_char = STOP_CHAR(tty);
1887 outb(0, info->ioaddr + UART_IER);
1888 info->IER |= UART_IER_THRI;
1889 outb(info->IER, info->ioaddr + UART_IER);
1890 }
1891 }
1892
1893 if (info->tty->termios->c_cflag & CRTSCTS) {
1894 info->MCR &= ~UART_MCR_RTS;
1895 outb(info->MCR, info->ioaddr + UART_MCR);
1896 }
1897}
1898
1899/*
1900 * This routine is called by the upper-layer tty layer to signal that
1901 * incoming characters should be throttled.
1902 */
1903static void mxser_throttle(struct tty_struct *tty)
1904{
1905 mxser_stoprx(tty);
1906}
1907
1908static void mxser_unthrottle(struct tty_struct *tty)
1909{
1910 struct mxser_port *info = tty->driver_data;
1911
1912 /* startrx */
1913 info->ldisc_stop_rx = 0;
1914 if (I_IXOFF(tty)) {
1915 if (info->x_char)
1916 info->x_char = 0;
1917 else {
1918 if (info->board->chip_flag) {
1919 info->IER |= MOXA_MUST_RECV_ISR;
1920 outb(info->IER, info->ioaddr + UART_IER);
1921 } else {
1922 info->x_char = START_CHAR(tty);
1923 outb(0, info->ioaddr + UART_IER);
1924 info->IER |= UART_IER_THRI;
1925 outb(info->IER, info->ioaddr + UART_IER);
1926 }
1927 }
1928 }
1929
1930 if (info->tty->termios->c_cflag & CRTSCTS) {
1931 info->MCR |= UART_MCR_RTS;
1932 outb(info->MCR, info->ioaddr + UART_MCR);
1933 }
1934}
1935
1936/*
1937 * mxser_stop() and mxser_start()
1938 *
1939 * This routines are called before setting or resetting tty->stopped.
1940 * They enable or disable transmitter interrupts, as necessary.
1941 */
1942static void mxser_stop(struct tty_struct *tty)
1943{
1944 struct mxser_port *info = tty->driver_data;
1945 unsigned long flags;
1946
1947 spin_lock_irqsave(&info->slock, flags);
1948 if (info->IER & UART_IER_THRI) {
1949 info->IER &= ~UART_IER_THRI;
1950 outb(info->IER, info->ioaddr + UART_IER);
1951 }
1952 spin_unlock_irqrestore(&info->slock, flags);
1953}
1954
1955static void mxser_start(struct tty_struct *tty)
1956{
1957 struct mxser_port *info = tty->driver_data;
1958 unsigned long flags;
1959
1960 spin_lock_irqsave(&info->slock, flags);
1961 if (info->xmit_cnt && info->xmit_buf) {
1962 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1963 info->IER |= UART_IER_THRI;
1964 outb(info->IER, info->ioaddr + UART_IER);
1965 }
1966 spin_unlock_irqrestore(&info->slock, flags);
1967}
1968
1969static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1970{
1971 struct mxser_port *info = tty->driver_data;
1972 unsigned long flags;
1973
1974 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1975 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1976
1977 mxser_change_speed(info, old_termios);
1978
1979 if ((old_termios->c_cflag & CRTSCTS) &&
1980 !(tty->termios->c_cflag & CRTSCTS)) {
1981 tty->hw_stopped = 0;
1982 mxser_start(tty);
1983 }
1984 }
1985
1986 /* Handle sw stopped */
1987 if ((old_termios->c_iflag & IXON) &&
1988 !(tty->termios->c_iflag & IXON)) {
1989 tty->stopped = 0;
1990
1991 if (info->board->chip_flag) {
1992 spin_lock_irqsave(&info->slock, flags);
1993 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
1994 spin_unlock_irqrestore(&info->slock, flags);
1995 }
1996
1997 mxser_start(tty);
1998 }
1999}
2000
2001/*
2002 * mxser_wait_until_sent() --- wait until the transmitter is empty
2003 */
2004static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2005{
2006 struct mxser_port *info = tty->driver_data;
2007 unsigned long orig_jiffies, char_time;
2008 int lsr;
2009
2010 if (info->type == PORT_UNKNOWN)
2011 return;
2012
2013 if (info->xmit_fifo_size == 0)
2014 return; /* Just in case.... */
2015
2016 orig_jiffies = jiffies;
2017 /*
2018 * Set the check interval to be 1/5 of the estimated time to
2019 * send a single character, and make it at least 1. The check
2020 * interval should also be less than the timeout.
2021 *
2022 * Note: we have to use pretty tight timings here to satisfy
2023 * the NIST-PCTS.
2024 */
2025 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2026 char_time = char_time / 5;
2027 if (char_time == 0)
2028 char_time = 1;
2029 if (timeout && timeout < char_time)
2030 char_time = timeout;
2031 /*
2032 * If the transmitter hasn't cleared in twice the approximate
2033 * amount of time to send the entire FIFO, it probably won't
2034 * ever clear. This assumes the UART isn't doing flow
2035 * control, which is currently the case. Hence, if it ever
2036 * takes longer than info->timeout, this is probably due to a
2037 * UART bug of some kind. So, we clamp the timeout parameter at
2038 * 2*info->timeout.
2039 */
2040 if (!timeout || timeout > 2 * info->timeout)
2041 timeout = 2 * info->timeout;
2042#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2043 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
2044 timeout, char_time);
2045 printk("jiff=%lu...", jiffies);
2046#endif
2047 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
2048#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2049 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2050#endif
2051 schedule_timeout_interruptible(char_time);
2052 if (signal_pending(current))
2053 break;
2054 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2055 break;
2056 }
2057 set_current_state(TASK_RUNNING);
2058
2059#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2060 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2061#endif
2062}
2063
2064/*
2065 * This routine is called by tty_hangup() when a hangup is signaled.
2066 */
2067void mxser_hangup(struct tty_struct *tty)
2068{
2069 struct mxser_port *info = tty->driver_data;
2070
2071 mxser_flush_buffer(tty);
2072 mxser_shutdown(info);
2073 info->event = 0;
2074 info->count = 0;
2075 info->flags &= ~ASYNC_NORMAL_ACTIVE;
2076 info->tty = NULL;
2077 wake_up_interruptible(&info->open_wait);
2078}
2079
2080/*
2081 * mxser_rs_break() --- routine which turns the break handling on or off
2082 */
2083static void mxser_rs_break(struct tty_struct *tty, int break_state)
2084{
2085 struct mxser_port *info = tty->driver_data;
2086 unsigned long flags;
2087
2088 spin_lock_irqsave(&info->slock, flags);
2089 if (break_state == -1)
2090 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
2091 info->ioaddr + UART_LCR);
2092 else
2093 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
2094 info->ioaddr + UART_LCR);
2095 spin_unlock_irqrestore(&info->slock, flags);
2096}
2097
2098static void mxser_receive_chars(struct mxser_port *port, int *status)
2099{
2100 struct tty_struct *tty = port->tty;
2101 unsigned char ch, gdl;
2102 int ignored = 0;
2103 int cnt = 0;
2104 int recv_room;
2105 int max = 256;
2106 unsigned long flags;
2107
2108 spin_lock_irqsave(&port->slock, flags);
2109
2110 recv_room = tty->receive_room;
2111 if ((recv_room == 0) && (!port->ldisc_stop_rx))
2112 mxser_stoprx(tty);
2113
2114 if (port->board->chip_flag != MOXA_OTHER_UART) {
2115
2116 if (*status & UART_LSR_SPECIAL)
2117 goto intr_old;
2118 if (port->board->chip_flag == MOXA_MUST_MU860_HWID &&
2119 (*status & MOXA_MUST_LSR_RERR))
2120 goto intr_old;
2121 if (*status & MOXA_MUST_LSR_RERR)
2122 goto intr_old;
2123
2124 gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER);
2125
2126 if (port->board->chip_flag == MOXA_MUST_MU150_HWID)
2127 gdl &= MOXA_MUST_GDL_MASK;
2128 if (gdl >= recv_room) {
2129 if (!port->ldisc_stop_rx)
2130 mxser_stoprx(tty);
2131 }
2132 while (gdl--) {
2133 ch = inb(port->ioaddr + UART_RX);
2134 tty_insert_flip_char(tty, ch, 0);
2135 cnt++;
2136 }
2137 goto end_intr;
2138 }
2139intr_old:
2140
2141 do {
2142 if (max-- < 0)
2143 break;
2144
2145 ch = inb(port->ioaddr + UART_RX);
2146 if (port->board->chip_flag && (*status & UART_LSR_OE))
2147 outb(0x23, port->ioaddr + UART_FCR);
2148 *status &= port->read_status_mask;
2149 if (*status & port->ignore_status_mask) {
2150 if (++ignored > 100)
2151 break;
2152 } else {
2153 char flag = 0;
2154 if (*status & UART_LSR_SPECIAL) {
2155 if (*status & UART_LSR_BI) {
2156 flag = TTY_BREAK;
2157 port->icount.brk++;
2158
2159 if (port->flags & ASYNC_SAK)
2160 do_SAK(tty);
2161 } else if (*status & UART_LSR_PE) {
2162 flag = TTY_PARITY;
2163 port->icount.parity++;
2164 } else if (*status & UART_LSR_FE) {
2165 flag = TTY_FRAME;
2166 port->icount.frame++;
2167 } else if (*status & UART_LSR_OE) {
2168 flag = TTY_OVERRUN;
2169 port->icount.overrun++;
2170 }
2171 }
2172 tty_insert_flip_char(tty, ch, flag);
2173 cnt++;
2174 if (cnt >= recv_room) {
2175 if (!port->ldisc_stop_rx)
2176 mxser_stoprx(tty);
2177 break;
2178 }
2179
2180 }
2181
2182 if (port->board->chip_flag)
2183 break;
2184
2185 *status = inb(port->ioaddr + UART_LSR);
2186 } while (*status & UART_LSR_DR);
2187
2188end_intr:
2189 mxvar_log.rxcnt[port->tty->index] += cnt;
2190 port->mon_data.rxcnt += cnt;
2191 port->mon_data.up_rxcnt += cnt;
2192 spin_unlock_irqrestore(&port->slock, flags);
2193
2194 tty_flip_buffer_push(tty);
2195}
2196
2197static void mxser_transmit_chars(struct mxser_port *port)
2198{
2199 int count, cnt;
2200 unsigned long flags;
2201
2202 spin_lock_irqsave(&port->slock, flags);
2203
2204 if (port->x_char) {
2205 outb(port->x_char, port->ioaddr + UART_TX);
2206 port->x_char = 0;
2207 mxvar_log.txcnt[port->tty->index]++;
2208 port->mon_data.txcnt++;
2209 port->mon_data.up_txcnt++;
2210 port->icount.tx++;
2211 goto unlock;
2212 }
2213
2214 if (port->xmit_buf == 0)
2215 goto unlock;
2216
2217 if ((port->xmit_cnt <= 0) || port->tty->stopped ||
2218 (port->tty->hw_stopped &&
2219 (port->type != PORT_16550A) &&
2220 (!port->board->chip_flag))) {
2221 port->IER &= ~UART_IER_THRI;
2222 outb(port->IER, port->ioaddr + UART_IER);
2223 goto unlock;
2224 }
2225
2226 cnt = port->xmit_cnt;
2227 count = port->xmit_fifo_size;
2228 do {
2229 outb(port->xmit_buf[port->xmit_tail++],
2230 port->ioaddr + UART_TX);
2231 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2232 if (--port->xmit_cnt <= 0)
2233 break;
2234 } while (--count > 0);
2235 mxvar_log.txcnt[port->tty->index] += (cnt - port->xmit_cnt);
2236
2237 port->mon_data.txcnt += (cnt - port->xmit_cnt);
2238 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2239 port->icount.tx += (cnt - port->xmit_cnt);
2240
2241 if (port->xmit_cnt < WAKEUP_CHARS) {
2242 set_bit(MXSER_EVENT_TXLOW, &port->event);
2243 schedule_work(&port->tqueue);
2244 }
2245 if (port->xmit_cnt <= 0) {
2246 port->IER &= ~UART_IER_THRI;
2247 outb(port->IER, port->ioaddr + UART_IER);
2248 }
2249unlock:
2250 spin_unlock_irqrestore(&port->slock, flags);
2251}
2252
2253/*
2254 * This is the serial driver's generic interrupt routine
2255 */
2256static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2257{
2258 int status, iir, i;
2259 struct mxser_board *brd = NULL;
2260 struct mxser_port *port;
2261 int max, irqbits, bits, msr;
2262 int pass_counter = 0;
2263 unsigned int int_cnt;
2264 int handled = IRQ_NONE;
2265
2266 for (i = 0; i < MXSER_BOARDS; i++)
2267 if (dev_id == &mxser_boards[i]) {
2268 brd = dev_id;
2269 break;
2270 }
2271
2272 if (i == MXSER_BOARDS)
2273 goto irq_stop;
2274 if (brd == NULL)
2275 goto irq_stop;
2276 max = brd->info->nports;
2277 while (1) {
2278 irqbits = inb(brd->vector) & brd->vector_mask;
2279 if (irqbits == brd->vector_mask)
2280 break;
2281
2282 handled = IRQ_HANDLED;
2283 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
2284 if (irqbits == brd->vector_mask)
2285 break;
2286 if (bits & irqbits)
2287 continue;
2288 port = &brd->ports[i];
2289
2290 int_cnt = 0;
2291 do {
2292 iir = inb(port->ioaddr + UART_IIR);
2293 if (iir & UART_IIR_NO_INT)
2294 break;
2295 iir &= MOXA_MUST_IIR_MASK;
2296 if (!port->tty) {
2297 status = inb(port->ioaddr + UART_LSR);
2298 outb(0x27, port->ioaddr + UART_FCR);
2299 inb(port->ioaddr + UART_MSR);
2300 break;
2301 }
2302
2303 status = inb(port->ioaddr + UART_LSR);
2304
2305 if (status & UART_LSR_PE)
2306 port->err_shadow |= NPPI_NOTIFY_PARITY;
2307 if (status & UART_LSR_FE)
2308 port->err_shadow |= NPPI_NOTIFY_FRAMING;
2309 if (status & UART_LSR_OE)
2310 port->err_shadow |=
2311 NPPI_NOTIFY_HW_OVERRUN;
2312 if (status & UART_LSR_BI)
2313 port->err_shadow |= NPPI_NOTIFY_BREAK;
2314
2315 if (port->board->chip_flag) {
2316 if (iir == MOXA_MUST_IIR_GDA ||
2317 iir == MOXA_MUST_IIR_RDA ||
2318 iir == MOXA_MUST_IIR_RTO ||
2319 iir == MOXA_MUST_IIR_LSR)
2320 mxser_receive_chars(port,
2321 &status);
2322
2323 } else {
2324 status &= port->read_status_mask;
2325 if (status & UART_LSR_DR)
2326 mxser_receive_chars(port,
2327 &status);
2328 }
2329 msr = inb(port->ioaddr + UART_MSR);
2330 if (msr & UART_MSR_ANY_DELTA)
2331 mxser_check_modem_status(port, msr);
2332
2333 if (port->board->chip_flag) {
2334 if (iir == 0x02 && (status &
2335 UART_LSR_THRE))
2336 mxser_transmit_chars(port);
2337 } else {
2338 if (status & UART_LSR_THRE)
2339 mxser_transmit_chars(port);
2340 }
2341 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
2342 }
2343 if (pass_counter++ > MXSER_ISR_PASS_LIMIT)
2344 break; /* Prevent infinite loops */
2345 }
2346
2347irq_stop:
2348 return handled;
2349}
2350
2351static const struct tty_operations mxser_ops = {
2352 .open = mxser_open,
2353 .close = mxser_close,
2354 .write = mxser_write,
2355 .put_char = mxser_put_char,
2356 .flush_chars = mxser_flush_chars,
2357 .write_room = mxser_write_room,
2358 .chars_in_buffer = mxser_chars_in_buffer,
2359 .flush_buffer = mxser_flush_buffer,
2360 .ioctl = mxser_ioctl,
2361 .throttle = mxser_throttle,
2362 .unthrottle = mxser_unthrottle,
2363 .set_termios = mxser_set_termios,
2364 .stop = mxser_stop,
2365 .start = mxser_start,
2366 .hangup = mxser_hangup,
2367 .break_ctl = mxser_rs_break,
2368 .wait_until_sent = mxser_wait_until_sent,
2369 .tiocmget = mxser_tiocmget,
2370 .tiocmset = mxser_tiocmset,
2371};
2372
2373/*
2374 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2375 */
2376
2377static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev,
2378 unsigned int irq)
2379{
2380 if (irq)
2381 free_irq(brd->irq, brd);
2382 if (pdev != NULL) { /* PCI */
2383 pci_release_region(pdev, 2);
2384 pci_release_region(pdev, 3);
2385 pci_dev_put(pdev);
2386 } else {
2387 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2388 release_region(brd->vector, 1);
2389 }
2390}
2391
2392static int __devinit mxser_initbrd(struct mxser_board *brd,
2393 struct pci_dev *pdev)
2394{
2395 struct mxser_port *info;
2396 unsigned int i;
2397 int retval;
2398
2399 printk(KERN_INFO "max. baud rate = %d bps.\n", brd->ports[0].max_baud);
2400
2401 for (i = 0; i < brd->info->nports; i++) {
2402 info = &brd->ports[i];
2403 info->board = brd;
2404 info->stop_rx = 0;
2405 info->ldisc_stop_rx = 0;
2406
2407 /* Enhance mode enabled here */
2408 if (brd->chip_flag != MOXA_OTHER_UART)
2409 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->ioaddr);
2410
2411 info->flags = ASYNC_SHARE_IRQ;
2412 info->type = brd->uart_type;
2413
2414 process_txrx_fifo(info);
2415
2416 info->custom_divisor = info->baud_base * 16;
2417 info->close_delay = 5 * HZ / 10;
2418 info->closing_wait = 30 * HZ;
2419 INIT_WORK(&info->tqueue, mxser_do_softint);
2420 info->normal_termios = mxvar_sdriver->init_termios;
2421 init_waitqueue_head(&info->open_wait);
2422 init_waitqueue_head(&info->close_wait);
2423 init_waitqueue_head(&info->delta_msr_wait);
2424 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
2425 info->err_shadow = 0;
2426 spin_lock_init(&info->slock);
2427
2428 /* before set INT ISR, disable all int */
2429 outb(inb(info->ioaddr + UART_IER) & 0xf0,
2430 info->ioaddr + UART_IER);
2431 }
2432 /*
2433 * Allocate the IRQ if necessary
2434 */
2435
2436 retval = request_irq(brd->irq, mxser_interrupt,
2437 (brd->ports[0].flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED :
2438 IRQF_DISABLED, "mxser", brd);
2439 if (retval) {
2440 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2441 "conflict with another device.\n",
2442 brd->info->name, brd->irq);
2443 /* We hold resources, we need to release them. */
2444 mxser_release_res(brd, pdev, 0);
2445 return retval;
2446 }
2447 return 0;
2448}
2449
2450static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2451{
2452 int id, i, bits;
2453 unsigned short regs[16], irq;
2454 unsigned char scratch, scratch2;
2455
2456 brd->chip_flag = MOXA_OTHER_UART;
2457
2458 id = mxser_read_register(cap, regs);
2459 switch (id) {
2460 case C168_ASIC_ID:
2461 brd->info = &mxser_cards[0];
2462 break;
2463 case C104_ASIC_ID:
2464 brd->info = &mxser_cards[1];
2465 break;
2466 case CI104J_ASIC_ID:
2467 brd->info = &mxser_cards[2];
2468 break;
2469 case C102_ASIC_ID:
2470 brd->info = &mxser_cards[5];
2471 break;
2472 case CI132_ASIC_ID:
2473 brd->info = &mxser_cards[6];
2474 break;
2475 case CI134_ASIC_ID:
2476 brd->info = &mxser_cards[7];
2477 break;
2478 default:
2479 return 0;
2480 }
2481
2482 irq = 0;
2483 /* some ISA cards have 2 ports, but we want to see them as 4-port (why?)
2484 Flag-hack checks if configuration should be read as 2-port here. */
2485 if (brd->info->nports == 2 || (brd->info->flags & MXSER_HAS2)) {
2486 irq = regs[9] & 0xF000;
2487 irq = irq | (irq >> 4);
2488 if (irq != (regs[9] & 0xFF00))
2489 return MXSER_ERR_IRQ_CONFLIT;
2490 } else if (brd->info->nports == 4) {
2491 irq = regs[9] & 0xF000;
2492 irq = irq | (irq >> 4);
2493 irq = irq | (irq >> 8);
2494 if (irq != regs[9])
2495 return MXSER_ERR_IRQ_CONFLIT;
2496 } else if (brd->info->nports == 8) {
2497 irq = regs[9] & 0xF000;
2498 irq = irq | (irq >> 4);
2499 irq = irq | (irq >> 8);
2500 if ((irq != regs[9]) || (irq != regs[10]))
2501 return MXSER_ERR_IRQ_CONFLIT;
2502 }
2503
2504 if (!irq)
2505 return MXSER_ERR_IRQ;
2506 brd->irq = ((int)(irq & 0xF000) >> 12);
2507 for (i = 0; i < 8; i++)
2508 brd->ports[i].ioaddr = (int) regs[i + 1] & 0xFFF8;
2509 if ((regs[12] & 0x80) == 0)
2510 return MXSER_ERR_VECTOR;
2511 brd->vector = (int)regs[11]; /* interrupt vector */
2512 if (id == 1)
2513 brd->vector_mask = 0x00FF;
2514 else
2515 brd->vector_mask = 0x000F;
2516 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
2517 if (regs[12] & bits) {
2518 brd->ports[i].baud_base = 921600;
2519 brd->ports[i].max_baud = 921600;
2520 } else {
2521 brd->ports[i].baud_base = 115200;
2522 brd->ports[i].max_baud = 115200;
2523 }
2524 }
2525 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
2526 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
2527 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
2528 outb(scratch2, cap + UART_LCR);
2529 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
2530 scratch = inb(cap + UART_IIR);
2531
2532 if (scratch & 0xC0)
2533 brd->uart_type = PORT_16550A;
2534 else
2535 brd->uart_type = PORT_16450;
2536 if (!request_region(brd->ports[0].ioaddr, 8 * brd->info->nports,
2537 "mxser(IO)"))
2538 return MXSER_ERR_IOADDR;
2539 if (!request_region(brd->vector, 1, "mxser(vector)")) {
2540 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2541 return MXSER_ERR_VECTOR;
2542 }
2543 return brd->info->nports;
2544}
2545
2546static int __devinit mxser_probe(struct pci_dev *pdev,
2547 const struct pci_device_id *ent)
2548{
2549 struct mxser_board *brd;
2550 unsigned int i, j;
2551 unsigned long ioaddress;
2552 int retval = -EINVAL;
2553
2554 for (i = 0; i < MXSER_BOARDS; i++)
2555 if (mxser_boards[i].info == NULL)
2556 break;
2557
2558 if (i >= MXSER_BOARDS) {
2559 printk(KERN_ERR "Too many Smartio/Industio family boards found "
2560 "(maximum %d), board not configured\n", MXSER_BOARDS);
2561 goto err;
2562 }
2563
2564 brd = &mxser_boards[i];
2565 brd->idx = i * MXSER_PORTS_PER_BOARD;
2566 printk(KERN_INFO "Found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2567 mxser_cards[ent->driver_data].name,
2568 pdev->bus->number, PCI_SLOT(pdev->devfn));
2569
2570 retval = pci_enable_device(pdev);
2571 if (retval) {
2572 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
2573 goto err;
2574 }
2575
2576 /* io address */
2577 ioaddress = pci_resource_start(pdev, 2);
2578 retval = pci_request_region(pdev, 2, "mxser(IO)");
2579 if (retval)
2580 goto err;
2581
2582 brd->info = &mxser_cards[ent->driver_data];
2583 for (i = 0; i < brd->info->nports; i++)
2584 brd->ports[i].ioaddr = ioaddress + 8 * i;
2585
2586 /* vector */
2587 ioaddress = pci_resource_start(pdev, 3);
2588 retval = pci_request_region(pdev, 3, "mxser(vector)");
2589 if (retval)
2590 goto err_relio;
2591 brd->vector = ioaddress;
2592
2593 /* irq */
2594 brd->irq = pdev->irq;
2595
2596 brd->chip_flag = CheckIsMoxaMust(brd->ports[0].ioaddr);
2597 brd->uart_type = PORT_16550A;
2598 brd->vector_mask = 0;
2599
2600 for (i = 0; i < brd->info->nports; i++) {
2601 for (j = 0; j < UART_INFO_NUM; j++) {
2602 if (Gpci_uart_info[j].type == brd->chip_flag) {
2603 brd->ports[i].max_baud =
2604 Gpci_uart_info[j].max_baud;
2605
2606 /* exception....CP-102 */
2607 if (brd->info->flags & MXSER_HIGHBAUD)
2608 brd->ports[i].max_baud = 921600;
2609 break;
2610 }
2611 }
2612 }
2613
2614 if (brd->chip_flag == MOXA_MUST_MU860_HWID) {
2615 for (i = 0; i < brd->info->nports; i++) {
2616 if (i < 4)
2617 brd->ports[i].opmode_ioaddr = ioaddress + 4;
2618 else
2619 brd->ports[i].opmode_ioaddr = ioaddress + 0x0c;
2620 }
2621 outb(0, ioaddress + 4); /* default set to RS232 mode */
2622 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
2623 }
2624
2625 for (i = 0; i < brd->info->nports; i++) {
2626 brd->vector_mask |= (1 << i);
2627 brd->ports[i].baud_base = 921600;
2628 }
2629
2630 /* mxser_initbrd will hook ISR. */
2631 if (mxser_initbrd(brd, pdev) < 0)
2632 goto err_relvec;
2633
2634 for (i = 0; i < brd->info->nports; i++)
2635 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
2636
2637 pci_set_drvdata(pdev, brd);
2638
2639 return 0;
2640err_relvec:
2641 pci_release_region(pdev, 3);
2642err_relio:
2643 pci_release_region(pdev, 2);
2644 brd->info = NULL;
2645err:
2646 return retval;
2647}
2648
2649static void __devexit mxser_remove(struct pci_dev *pdev)
2650{
2651 struct mxser_board *brd = pci_get_drvdata(pdev);
2652 unsigned int i;
2653
2654 for (i = 0; i < brd->info->nports; i++)
2655 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2656
2657 mxser_release_res(brd, pdev, 1);
2658}
2659
2660static struct pci_driver mxser_driver = {
2661 .name = "mxser",
2662 .id_table = mxser_pcibrds,
2663 .probe = mxser_probe,
2664 .remove = __devexit_p(mxser_remove)
2665};
2666
2667static int __init mxser_module_init(void)
2668{
2669 struct mxser_board *brd;
2670 unsigned long cap;
2671 unsigned int i, m, isaloop;
2672 int retval, b;
2673
2674 pr_debug("Loading module mxser ...\n");
2675
2676 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
2677 if (!mxvar_sdriver)
2678 return -ENOMEM;
2679 spin_lock_init(&gm_lock);
2680
2681 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
2682 MXSER_VERSION);
2683
2684 /* Initialize the tty_driver structure */
2685 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2686 mxvar_sdriver->name = "ttyMI";
2687 mxvar_sdriver->major = ttymajor;
2688 mxvar_sdriver->minor_start = 0;
2689 mxvar_sdriver->num = MXSER_PORTS + 1;
2690 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
2691 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
2692 mxvar_sdriver->init_termios = tty_std_termios;
2693 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
2694 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
2695 tty_set_operations(mxvar_sdriver, &mxser_ops);
2696
2697 retval = tty_register_driver(mxvar_sdriver);
2698 if (retval) {
2699 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family "
2700 "tty driver !\n");
2701 goto err_put;
2702 }
2703
2704 mxvar_diagflag = 0;
2705
2706 m = 0;
2707 /* Start finding ISA boards here */
2708 for (isaloop = 0; isaloop < 2; isaloop++)
2709 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
2710 if (!isaloop)
2711 cap = mxserBoardCAP[b]; /* predefined */
2712 else
2713 cap = ioaddr[b]; /* module param */
2714
2715 if (!cap)
2716 continue;
2717
2718 brd = &mxser_boards[m];
2719 retval = mxser_get_ISA_conf(cap, brd);
2720
2721 if (retval != 0)
2722 printk(KERN_INFO "Found MOXA %s board "
2723 "(CAP=0x%x)\n",
2724 brd->info->name, ioaddr[b]);
2725
2726 if (retval <= 0) {
2727 if (retval == MXSER_ERR_IRQ)
2728 printk(KERN_ERR "Invalid interrupt "
2729 "number, board not "
2730 "configured\n");
2731 else if (retval == MXSER_ERR_IRQ_CONFLIT)
2732 printk(KERN_ERR "Invalid interrupt "
2733 "number, board not "
2734 "configured\n");
2735 else if (retval == MXSER_ERR_VECTOR)
2736 printk(KERN_ERR "Invalid interrupt "
2737 "vector, board not "
2738 "configured\n");
2739 else if (retval == MXSER_ERR_IOADDR)
2740 printk(KERN_ERR "Invalid I/O address, "
2741 "board not configured\n");
2742
2743 brd->info = NULL;
2744 continue;
2745 }
2746
2747 /* mxser_initbrd will hook ISR. */
2748 if (mxser_initbrd(brd, NULL) < 0) {
2749 brd->info = NULL;
2750 continue;
2751 }
2752
2753 brd->idx = m * MXSER_PORTS_PER_BOARD;
2754 for (i = 0; i < brd->info->nports; i++)
2755 tty_register_device(mxvar_sdriver, brd->idx + i,
2756 NULL);
2757
2758 m++;
2759 }
2760
2761 retval = pci_register_driver(&mxser_driver);
2762 if (retval) {
2763 printk(KERN_ERR "Can't register pci driver\n");
2764 if (!m) {
2765 retval = -ENODEV;
2766 goto err_unr;
2767 } /* else: we have some ISA cards under control */
2768 }
2769
2770 pr_debug("Done.\n");
2771
2772 return 0;
2773err_unr:
2774 tty_unregister_driver(mxvar_sdriver);
2775err_put:
2776 put_tty_driver(mxvar_sdriver);
2777 return retval;
2778}
2779
2780static void __exit mxser_module_exit(void)
2781{
2782 unsigned int i, j;
2783
2784 pr_debug("Unloading module mxser ...\n");
2785
2786 pci_unregister_driver(&mxser_driver);
2787
2788 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */
2789 if (mxser_boards[i].info != NULL)
2790 for (j = 0; j < mxser_boards[i].info->nports; j++)
2791 tty_unregister_device(mxvar_sdriver,
2792 mxser_boards[i].idx + j);
2793 tty_unregister_driver(mxvar_sdriver);
2794 put_tty_driver(mxvar_sdriver);
2795
2796 for (i = 0; i < MXSER_BOARDS; i++)
2797 if (mxser_boards[i].info != NULL)
2798 mxser_release_res(&mxser_boards[i], NULL, 1);
2799
2800 pr_debug("Done.\n");
2801}
2802
2803module_init(mxser_module_init);
2804module_exit(mxser_module_exit);
diff --git a/drivers/char/mxser_new.h b/drivers/char/mxser_new.h
new file mode 100644
index 000000000000..a08f0ecb09ba
--- /dev/null
+++ b/drivers/char/mxser_new.h
@@ -0,0 +1,450 @@
1#ifndef _MXSER_H
2#define _MXSER_H
3
4/*
5 * Semi-public control interfaces
6 */
7
8/*
9 * MOXA ioctls
10 */
11
12#define MOXA 0x400
13#define MOXA_GETDATACOUNT (MOXA + 23)
14#define MOXA_GET_CONF (MOXA + 35)
15#define MOXA_DIAGNOSE (MOXA + 50)
16#define MOXA_CHKPORTENABLE (MOXA + 60)
17#define MOXA_HighSpeedOn (MOXA + 61)
18#define MOXA_GET_MAJOR (MOXA + 63)
19#define MOXA_GET_CUMAJOR (MOXA + 64)
20#define MOXA_GETMSTATUS (MOXA + 65)
21#define MOXA_SET_OP_MODE (MOXA + 66)
22#define MOXA_GET_OP_MODE (MOXA + 67)
23
24#define RS232_MODE 0
25#define RS485_2WIRE_MODE 1
26#define RS422_MODE 2
27#define RS485_4WIRE_MODE 3
28#define OP_MODE_MASK 3
29// above add by Victor Yu. 01-05-2004
30
31#define TTY_THRESHOLD_THROTTLE 128
32
33#define LO_WATER (TTY_FLIPBUF_SIZE)
34#define HI_WATER (TTY_FLIPBUF_SIZE*2*3/4)
35
36// added by James. 03-11-2004.
37#define MOXA_SDS_GETICOUNTER (MOXA + 68)
38#define MOXA_SDS_RSTICOUNTER (MOXA + 69)
39// (above) added by James.
40
41#define MOXA_ASPP_OQUEUE (MOXA + 70)
42#define MOXA_ASPP_SETBAUD (MOXA + 71)
43#define MOXA_ASPP_GETBAUD (MOXA + 72)
44#define MOXA_ASPP_MON (MOXA + 73)
45#define MOXA_ASPP_LSTATUS (MOXA + 74)
46#define MOXA_ASPP_MON_EXT (MOXA + 75)
47#define MOXA_SET_BAUD_METHOD (MOXA + 76)
48
49
50/* --------------------------------------------------- */
51
52#define NPPI_NOTIFY_PARITY 0x01
53#define NPPI_NOTIFY_FRAMING 0x02
54#define NPPI_NOTIFY_HW_OVERRUN 0x04
55#define NPPI_NOTIFY_SW_OVERRUN 0x08
56#define NPPI_NOTIFY_BREAK 0x10
57
58#define NPPI_NOTIFY_CTSHOLD 0x01 // Tx hold by CTS low
59#define NPPI_NOTIFY_DSRHOLD 0x02 // Tx hold by DSR low
60#define NPPI_NOTIFY_XOFFHOLD 0x08 // Tx hold by Xoff received
61#define NPPI_NOTIFY_XOFFXENT 0x10 // Xoff Sent
62
63//CheckIsMoxaMust return value
64#define MOXA_OTHER_UART 0x00
65#define MOXA_MUST_MU150_HWID 0x01
66#define MOXA_MUST_MU860_HWID 0x02
67
68// follow just for Moxa Must chip define.
69//
70// when LCR register (offset 0x03) write following value,
71// the Must chip will enter enchance mode. And write value
72// on EFR (offset 0x02) bit 6,7 to change bank.
73#define MOXA_MUST_ENTER_ENCHANCE 0xBF
74
75// when enhance mode enable, access on general bank register
76#define MOXA_MUST_GDL_REGISTER 0x07
77#define MOXA_MUST_GDL_MASK 0x7F
78#define MOXA_MUST_GDL_HAS_BAD_DATA 0x80
79
80#define MOXA_MUST_LSR_RERR 0x80 // error in receive FIFO
81// enchance register bank select and enchance mode setting register
82// when LCR register equal to 0xBF
83#define MOXA_MUST_EFR_REGISTER 0x02
84// enchance mode enable
85#define MOXA_MUST_EFR_EFRB_ENABLE 0x10
86// enchance reister bank set 0, 1, 2
87#define MOXA_MUST_EFR_BANK0 0x00
88#define MOXA_MUST_EFR_BANK1 0x40
89#define MOXA_MUST_EFR_BANK2 0x80
90#define MOXA_MUST_EFR_BANK3 0xC0
91#define MOXA_MUST_EFR_BANK_MASK 0xC0
92
93// set XON1 value register, when LCR=0xBF and change to bank0
94#define MOXA_MUST_XON1_REGISTER 0x04
95
96// set XON2 value register, when LCR=0xBF and change to bank0
97#define MOXA_MUST_XON2_REGISTER 0x05
98
99// set XOFF1 value register, when LCR=0xBF and change to bank0
100#define MOXA_MUST_XOFF1_REGISTER 0x06
101
102// set XOFF2 value register, when LCR=0xBF and change to bank0
103#define MOXA_MUST_XOFF2_REGISTER 0x07
104
105#define MOXA_MUST_RBRTL_REGISTER 0x04
106#define MOXA_MUST_RBRTH_REGISTER 0x05
107#define MOXA_MUST_RBRTI_REGISTER 0x06
108#define MOXA_MUST_THRTL_REGISTER 0x07
109#define MOXA_MUST_ENUM_REGISTER 0x04
110#define MOXA_MUST_HWID_REGISTER 0x05
111#define MOXA_MUST_ECR_REGISTER 0x06
112#define MOXA_MUST_CSR_REGISTER 0x07
113
114// good data mode enable
115#define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20
116// only good data put into RxFIFO
117#define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10
118
119// enable CTS interrupt
120#define MOXA_MUST_IER_ECTSI 0x80
121// enable RTS interrupt
122#define MOXA_MUST_IER_ERTSI 0x40
123// enable Xon/Xoff interrupt
124#define MOXA_MUST_IER_XINT 0x20
125// enable GDA interrupt
126#define MOXA_MUST_IER_EGDAI 0x10
127
128#define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI)
129
130// GDA interrupt pending
131#define MOXA_MUST_IIR_GDA 0x1C
132#define MOXA_MUST_IIR_RDA 0x04
133#define MOXA_MUST_IIR_RTO 0x0C
134#define MOXA_MUST_IIR_LSR 0x06
135
136// recieved Xon/Xoff or specical interrupt pending
137#define MOXA_MUST_IIR_XSC 0x10
138
139// RTS/CTS change state interrupt pending
140#define MOXA_MUST_IIR_RTSCTS 0x20
141#define MOXA_MUST_IIR_MASK 0x3E
142
143#define MOXA_MUST_MCR_XON_FLAG 0x40
144#define MOXA_MUST_MCR_XON_ANY 0x80
145#define MOXA_MUST_MCR_TX_XON 0x08
146
147
148// software flow control on chip mask value
149#define MOXA_MUST_EFR_SF_MASK 0x0F
150// send Xon1/Xoff1
151#define MOXA_MUST_EFR_SF_TX1 0x08
152// send Xon2/Xoff2
153#define MOXA_MUST_EFR_SF_TX2 0x04
154// send Xon1,Xon2/Xoff1,Xoff2
155#define MOXA_MUST_EFR_SF_TX12 0x0C
156// don't send Xon/Xoff
157#define MOXA_MUST_EFR_SF_TX_NO 0x00
158// Tx software flow control mask
159#define MOXA_MUST_EFR_SF_TX_MASK 0x0C
160// don't receive Xon/Xoff
161#define MOXA_MUST_EFR_SF_RX_NO 0x00
162// receive Xon1/Xoff1
163#define MOXA_MUST_EFR_SF_RX1 0x02
164// receive Xon2/Xoff2
165#define MOXA_MUST_EFR_SF_RX2 0x01
166// receive Xon1,Xon2/Xoff1,Xoff2
167#define MOXA_MUST_EFR_SF_RX12 0x03
168// Rx software flow control mask
169#define MOXA_MUST_EFR_SF_RX_MASK 0x03
170
171//#define MOXA_MUST_MIN_XOFFLIMIT 66
172//#define MOXA_MUST_MIN_XONLIMIT 20
173//#define ID1_RX_TRIG 120
174
175
176#define CHECK_MOXA_MUST_XOFFLIMIT(info) { \
177 if ( (info)->IsMoxaMustChipFlag && \
178 (info)->HandFlow.XoffLimit < MOXA_MUST_MIN_XOFFLIMIT ) { \
179 (info)->HandFlow.XoffLimit = MOXA_MUST_MIN_XOFFLIMIT; \
180 (info)->HandFlow.XonLimit = MOXA_MUST_MIN_XONLIMIT; \
181 } \
182}
183
184#define ENABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \
185 u8 __oldlcr, __efr; \
186 __oldlcr = inb((baseio)+UART_LCR); \
187 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
188 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
189 __efr |= MOXA_MUST_EFR_EFRB_ENABLE; \
190 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
191 outb(__oldlcr, (baseio)+UART_LCR); \
192}
193
194#define DISABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \
195 u8 __oldlcr, __efr; \
196 __oldlcr = inb((baseio)+UART_LCR); \
197 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
198 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
199 __efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; \
200 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
201 outb(__oldlcr, (baseio)+UART_LCR); \
202}
203
204#define SET_MOXA_MUST_XON1_VALUE(baseio, Value) { \
205 u8 __oldlcr, __efr; \
206 __oldlcr = inb((baseio)+UART_LCR); \
207 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
208 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
209 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
210 __efr |= MOXA_MUST_EFR_BANK0; \
211 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
212 outb((u8)(Value), (baseio)+MOXA_MUST_XON1_REGISTER); \
213 outb(__oldlcr, (baseio)+UART_LCR); \
214}
215
216#define SET_MOXA_MUST_XON2_VALUE(baseio, Value) { \
217 u8 __oldlcr, __efr; \
218 __oldlcr = inb((baseio)+UART_LCR); \
219 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
220 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
221 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
222 __efr |= MOXA_MUST_EFR_BANK0; \
223 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
224 outb((u8)(Value), (baseio)+MOXA_MUST_XON2_REGISTER); \
225 outb(__oldlcr, (baseio)+UART_LCR); \
226}
227
228#define SET_MOXA_MUST_XOFF1_VALUE(baseio, Value) { \
229 u8 __oldlcr, __efr; \
230 __oldlcr = inb((baseio)+UART_LCR); \
231 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
232 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
233 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
234 __efr |= MOXA_MUST_EFR_BANK0; \
235 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
236 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF1_REGISTER); \
237 outb(__oldlcr, (baseio)+UART_LCR); \
238}
239
240#define SET_MOXA_MUST_XOFF2_VALUE(baseio, Value) { \
241 u8 __oldlcr, __efr; \
242 __oldlcr = inb((baseio)+UART_LCR); \
243 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
244 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
245 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
246 __efr |= MOXA_MUST_EFR_BANK0; \
247 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
248 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF2_REGISTER); \
249 outb(__oldlcr, (baseio)+UART_LCR); \
250}
251
252#define SET_MOXA_MUST_RBRTL_VALUE(baseio, Value) { \
253 u8 __oldlcr, __efr; \
254 __oldlcr = inb((baseio)+UART_LCR); \
255 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
256 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
257 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
258 __efr |= MOXA_MUST_EFR_BANK1; \
259 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
260 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTL_REGISTER); \
261 outb(__oldlcr, (baseio)+UART_LCR); \
262}
263
264#define SET_MOXA_MUST_RBRTH_VALUE(baseio, Value) { \
265 u8 __oldlcr, __efr; \
266 __oldlcr = inb((baseio)+UART_LCR); \
267 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
268 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
269 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
270 __efr |= MOXA_MUST_EFR_BANK1; \
271 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
272 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTH_REGISTER); \
273 outb(__oldlcr, (baseio)+UART_LCR); \
274}
275
276#define SET_MOXA_MUST_RBRTI_VALUE(baseio, Value) { \
277 u8 __oldlcr, __efr; \
278 __oldlcr = inb((baseio)+UART_LCR); \
279 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
280 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
281 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
282 __efr |= MOXA_MUST_EFR_BANK1; \
283 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
284 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTI_REGISTER); \
285 outb(__oldlcr, (baseio)+UART_LCR); \
286}
287
288#define SET_MOXA_MUST_THRTL_VALUE(baseio, Value) { \
289 u8 __oldlcr, __efr; \
290 __oldlcr = inb((baseio)+UART_LCR); \
291 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
292 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
293 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
294 __efr |= MOXA_MUST_EFR_BANK1; \
295 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
296 outb((u8)(Value), (baseio)+MOXA_MUST_THRTL_REGISTER); \
297 outb(__oldlcr, (baseio)+UART_LCR); \
298}
299
300//#define MOXA_MUST_RBRL_VALUE 4
301#define SET_MOXA_MUST_FIFO_VALUE(info) { \
302 u8 __oldlcr, __efr; \
303 __oldlcr = inb((info)->ioaddr+UART_LCR); \
304 outb(MOXA_MUST_ENTER_ENCHANCE, (info)->ioaddr+UART_LCR); \
305 __efr = inb((info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
306 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
307 __efr |= MOXA_MUST_EFR_BANK1; \
308 outb(__efr, (info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
309 outb((u8)((info)->rx_high_water), (info)->ioaddr+MOXA_MUST_RBRTH_REGISTER); \
310 outb((u8)((info)->rx_trigger), (info)->ioaddr+MOXA_MUST_RBRTI_REGISTER); \
311 outb((u8)((info)->rx_low_water), (info)->ioaddr+MOXA_MUST_RBRTL_REGISTER); \
312 outb(__oldlcr, (info)->ioaddr+UART_LCR); \
313}
314
315
316
317#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) { \
318 u8 __oldlcr, __efr; \
319 __oldlcr = inb((baseio)+UART_LCR); \
320 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
321 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
322 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
323 __efr |= MOXA_MUST_EFR_BANK2; \
324 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
325 outb((u8)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER); \
326 outb(__oldlcr, (baseio)+UART_LCR); \
327}
328
329#define GET_MOXA_MUST_HARDWARE_ID(baseio, pId) { \
330 u8 __oldlcr, __efr; \
331 __oldlcr = inb((baseio)+UART_LCR); \
332 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
333 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
334 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
335 __efr |= MOXA_MUST_EFR_BANK2; \
336 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
337 *pId = inb((baseio)+MOXA_MUST_HWID_REGISTER); \
338 outb(__oldlcr, (baseio)+UART_LCR); \
339}
340
341#define SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(baseio) { \
342 u8 __oldlcr, __efr; \
343 __oldlcr = inb((baseio)+UART_LCR); \
344 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
345 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
346 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
347 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
348 outb(__oldlcr, (baseio)+UART_LCR); \
349}
350
351#define SET_MOXA_MUST_JUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
352 u8 __oldlcr, __efr; \
353 __oldlcr = inb((baseio)+UART_LCR); \
354 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
355 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
356 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
357 __efr |= MOXA_MUST_EFR_SF_TX1; \
358 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
359 outb(__oldlcr, (baseio)+UART_LCR); \
360}
361
362#define ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
363 u8 __oldlcr, __efr; \
364 __oldlcr = inb((baseio)+UART_LCR); \
365 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
366 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
367 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
368 __efr |= MOXA_MUST_EFR_SF_TX1; \
369 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
370 outb(__oldlcr, (baseio)+UART_LCR); \
371}
372
373#define DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
374 u8 __oldlcr, __efr; \
375 __oldlcr = inb((baseio)+UART_LCR); \
376 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
377 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
378 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
379 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
380 outb(__oldlcr, (baseio)+UART_LCR); \
381}
382
383#define SET_MOXA_MUST_JUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
384 u8 __oldlcr, __efr; \
385 __oldlcr = inb((baseio)+UART_LCR); \
386 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
387 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
388 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
389 __efr |= MOXA_MUST_EFR_SF_RX1; \
390 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
391 outb(__oldlcr, (baseio)+UART_LCR); \
392}
393
394#define ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
395 u8 __oldlcr, __efr; \
396 __oldlcr = inb((baseio)+UART_LCR); \
397 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
398 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
399 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
400 __efr |= MOXA_MUST_EFR_SF_RX1; \
401 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
402 outb(__oldlcr, (baseio)+UART_LCR); \
403}
404
405#define DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
406 u8 __oldlcr, __efr; \
407 __oldlcr = inb((baseio)+UART_LCR); \
408 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
409 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
410 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
411 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
412 outb(__oldlcr, (baseio)+UART_LCR); \
413}
414
415#define ENABLE_MOXA_MUST_TX_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
416 u8 __oldlcr, __efr; \
417 __oldlcr = inb((baseio)+UART_LCR); \
418 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
419 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
420 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
421 __efr |= (MOXA_MUST_EFR_SF_RX1|MOXA_MUST_EFR_SF_TX1); \
422 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
423 outb(__oldlcr, (baseio)+UART_LCR); \
424}
425
426#define ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
427 u8 __oldmcr; \
428 __oldmcr = inb((baseio)+UART_MCR); \
429 __oldmcr |= MOXA_MUST_MCR_XON_ANY; \
430 outb(__oldmcr, (baseio)+UART_MCR); \
431}
432
433#define DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
434 u8 __oldmcr; \
435 __oldmcr = inb((baseio)+UART_MCR); \
436 __oldmcr &= ~MOXA_MUST_MCR_XON_ANY; \
437 outb(__oldmcr, (baseio)+UART_MCR); \
438}
439
440#define READ_MOXA_MUST_GDL(baseio) inb((baseio)+MOXA_MUST_GDL_REGISTER)
441
442
443#ifndef INIT_WORK
444#define INIT_WORK(_work, _func, _data){ \
445 _data->tqueue.routine = _func;\
446 _data->tqueue.data = _data;\
447 }
448#endif
449
450#endif
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 203dc2b661d5..103d338f21e2 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -142,7 +142,7 @@ static ssize_t r3964_write(struct tty_struct * tty, struct file * file,
142 const unsigned char * buf, size_t nr); 142 const unsigned char * buf, size_t nr);
143static int r3964_ioctl(struct tty_struct * tty, struct file * file, 143static int r3964_ioctl(struct tty_struct * tty, struct file * file,
144 unsigned int cmd, unsigned long arg); 144 unsigned int cmd, unsigned long arg);
145static void r3964_set_termios(struct tty_struct *tty, struct termios * old); 145static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old);
146static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, 146static unsigned int r3964_poll(struct tty_struct * tty, struct file * file,
147 struct poll_table_struct *wait); 147 struct poll_table_struct *wait);
148static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 148static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
@@ -1347,7 +1347,7 @@ static int r3964_ioctl(struct tty_struct * tty, struct file * file,
1347 } 1347 }
1348} 1348}
1349 1349
1350static void r3964_set_termios(struct tty_struct *tty, struct termios * old) 1350static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old)
1351{ 1351{
1352 TRACE_L("set_termios"); 1352 TRACE_L("set_termios");
1353} 1353}
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 603b9ade5eb0..e96a00fe1389 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -994,7 +994,7 @@ int is_ignored(int sig)
994 * when the ldisc is closed. 994 * when the ldisc is closed.
995 */ 995 */
996 996
997static void n_tty_set_termios(struct tty_struct *tty, struct termios * old) 997static void n_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
998{ 998{
999 if (!tty) 999 if (!tty)
1000 return; 1000 return;
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
index 4d47d79bcea7..808d44e9a32a 100644
--- a/drivers/char/nsc_gpio.c
+++ b/drivers/char/nsc_gpio.c
@@ -41,7 +41,7 @@ void nsc_gpio_dump(struct nsc_gpio_ops *amp, unsigned index)
41ssize_t nsc_gpio_write(struct file *file, const char __user *data, 41ssize_t nsc_gpio_write(struct file *file, const char __user *data,
42 size_t len, loff_t *ppos) 42 size_t len, loff_t *ppos)
43{ 43{
44 unsigned m = iminor(file->f_dentry->d_inode); 44 unsigned m = iminor(file->f_path.dentry->d_inode);
45 struct nsc_gpio_ops *amp = file->private_data; 45 struct nsc_gpio_ops *amp = file->private_data;
46 struct device *dev = amp->dev; 46 struct device *dev = amp->dev;
47 size_t i; 47 size_t i;
@@ -104,7 +104,7 @@ ssize_t nsc_gpio_write(struct file *file, const char __user *data,
104ssize_t nsc_gpio_read(struct file *file, char __user * buf, 104ssize_t nsc_gpio_read(struct file *file, char __user * buf,
105 size_t len, loff_t * ppos) 105 size_t len, loff_t * ppos)
106{ 106{
107 unsigned m = iminor(file->f_dentry->d_inode); 107 unsigned m = iminor(file->f_path.dentry->d_inode);
108 int value; 108 int value;
109 struct nsc_gpio_ops *amp = file->private_data; 109 struct nsc_gpio_ops *amp = file->private_data;
110 110
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 74d21c1c104f..5152cedd8878 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -2375,7 +2375,7 @@ static int ioctl_common(MGSLPC_INFO *info, unsigned int cmd, unsigned long arg)
2375 * tty pointer to tty structure 2375 * tty pointer to tty structure
2376 * termios pointer to buffer to hold returned old termios 2376 * termios pointer to buffer to hold returned old termios
2377 */ 2377 */
2378static void mgslpc_set_termios(struct tty_struct *tty, struct termios *old_termios) 2378static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2379{ 2379{
2380 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; 2380 MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
2381 unsigned long flags; 2381 unsigned long flags;
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index c1e3dd837fc8..4abd1eff61d6 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -106,7 +106,7 @@ static inline void pp_enable_irq (struct pp_struct *pp)
106static ssize_t pp_read (struct file * file, char __user * buf, size_t count, 106static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
107 loff_t * ppos) 107 loff_t * ppos)
108{ 108{
109 unsigned int minor = iminor(file->f_dentry->d_inode); 109 unsigned int minor = iminor(file->f_path.dentry->d_inode);
110 struct pp_struct *pp = file->private_data; 110 struct pp_struct *pp = file->private_data;
111 char * kbuffer; 111 char * kbuffer;
112 ssize_t bytes_read = 0; 112 ssize_t bytes_read = 0;
@@ -189,7 +189,7 @@ static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
189static ssize_t pp_write (struct file * file, const char __user * buf, 189static ssize_t pp_write (struct file * file, const char __user * buf,
190 size_t count, loff_t * ppos) 190 size_t count, loff_t * ppos)
191{ 191{
192 unsigned int minor = iminor(file->f_dentry->d_inode); 192 unsigned int minor = iminor(file->f_path.dentry->d_inode);
193 struct pp_struct *pp = file->private_data; 193 struct pp_struct *pp = file->private_data;
194 char * kbuffer; 194 char * kbuffer;
195 ssize_t bytes_written = 0; 195 ssize_t bytes_written = 0;
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 80d3eedd7f96..c07a1b5cd05d 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -218,7 +218,7 @@ out:
218 return retval; 218 return retval;
219} 219}
220 220
221static void pty_set_termios(struct tty_struct *tty, struct termios *old_termios) 221static void pty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
222{ 222{
223 tty->termios->c_cflag &= ~(CSIZE | PARENB); 223 tty->termios->c_cflag &= ~(CSIZE | PARENB);
224 tty->termios->c_cflag |= (CS8 | CREAD); 224 tty->termios->c_cflag |= (CS8 | CREAD);
@@ -272,6 +272,8 @@ static void __init legacy_pty_init(void)
272 pty_driver->init_termios.c_oflag = 0; 272 pty_driver->init_termios.c_oflag = 0;
273 pty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 273 pty_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
274 pty_driver->init_termios.c_lflag = 0; 274 pty_driver->init_termios.c_lflag = 0;
275 pty_driver->init_termios.c_ispeed = 38400;
276 pty_driver->init_termios.c_ospeed = 38400;
275 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW; 277 pty_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW;
276 pty_driver->other = pty_slave_driver; 278 pty_driver->other = pty_slave_driver;
277 tty_set_operations(pty_driver, &pty_ops); 279 tty_set_operations(pty_driver, &pty_ops);
@@ -286,6 +288,8 @@ static void __init legacy_pty_init(void)
286 pty_slave_driver->subtype = PTY_TYPE_SLAVE; 288 pty_slave_driver->subtype = PTY_TYPE_SLAVE;
287 pty_slave_driver->init_termios = tty_std_termios; 289 pty_slave_driver->init_termios = tty_std_termios;
288 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 290 pty_slave_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
291 pty_slave_driver->init_termios.c_ispeed = 38400;
292 pty_slave_driver->init_termios.c_ospeed = 38400;
289 pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS | 293 pty_slave_driver->flags = TTY_DRIVER_RESET_TERMIOS |
290 TTY_DRIVER_REAL_RAW; 294 TTY_DRIVER_REAL_RAW;
291 pty_slave_driver->other = pty_driver; 295 pty_slave_driver->other = pty_driver;
@@ -366,6 +370,8 @@ static void __init unix98_pty_init(void)
366 ptm_driver->init_termios.c_oflag = 0; 370 ptm_driver->init_termios.c_oflag = 0;
367 ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 371 ptm_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
368 ptm_driver->init_termios.c_lflag = 0; 372 ptm_driver->init_termios.c_lflag = 0;
373 ptm_driver->init_termios.c_ispeed = 38400;
374 ptm_driver->init_termios.c_ospeed = 38400;
369 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 375 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
370 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 376 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
371 ptm_driver->other = pts_driver; 377 ptm_driver->other = pts_driver;
@@ -381,6 +387,8 @@ static void __init unix98_pty_init(void)
381 pts_driver->subtype = PTY_TYPE_SLAVE; 387 pts_driver->subtype = PTY_TYPE_SLAVE;
382 pts_driver->init_termios = tty_std_termios; 388 pts_driver->init_termios = tty_std_termios;
383 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD; 389 pts_driver->init_termios.c_cflag = B38400 | CS8 | CREAD;
390 pts_driver->init_termios.c_ispeed = 38400;
391 pts_driver->init_termios.c_ospeed = 38400;
384 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 392 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
385 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 393 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
386 pts_driver->other = ptm_driver; 394 pts_driver->other = ptm_driver;
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4c6782a1ecdb..13d0b1350a62 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1048,7 +1048,7 @@ random_write(struct file * file, const char __user * buffer,
1048 if (p == buffer) { 1048 if (p == buffer) {
1049 return (ssize_t)ret; 1049 return (ssize_t)ret;
1050 } else { 1050 } else {
1051 struct inode *inode = file->f_dentry->d_inode; 1051 struct inode *inode = file->f_path.dentry->d_inode;
1052 inode->i_mtime = current_fs_time(inode->i_sb); 1052 inode->i_mtime = current_fs_time(inode->i_sb);
1053 mark_inode_dirty(inode); 1053 mark_inode_dirty(inode);
1054 return (ssize_t)(p - buffer); 1054 return (ssize_t)(p - buffer);
@@ -1203,7 +1203,7 @@ static int proc_do_uuid(ctl_table *table, int write, struct file *filp,
1203 1203
1204static int uuid_strategy(ctl_table *table, int __user *name, int nlen, 1204static int uuid_strategy(ctl_table *table, int __user *name, int nlen,
1205 void __user *oldval, size_t __user *oldlenp, 1205 void __user *oldval, size_t __user *oldlenp,
1206 void __user *newval, size_t newlen, void **context) 1206 void __user *newval, size_t newlen)
1207{ 1207{
1208 unsigned char tmp_uuid[16], *uuid; 1208 unsigned char tmp_uuid[16], *uuid;
1209 unsigned int len; 1209 unsigned int len;
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 3b32313f6eb4..645e20a06ece 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -75,7 +75,7 @@ static int raw_open(struct inode *inode, struct file *filp)
75 filp->f_flags |= O_DIRECT; 75 filp->f_flags |= O_DIRECT;
76 filp->f_mapping = bdev->bd_inode->i_mapping; 76 filp->f_mapping = bdev->bd_inode->i_mapping;
77 if (++raw_devices[minor].inuse == 1) 77 if (++raw_devices[minor].inuse == 1)
78 filp->f_dentry->d_inode->i_mapping = 78 filp->f_path.dentry->d_inode->i_mapping =
79 bdev->bd_inode->i_mapping; 79 bdev->bd_inode->i_mapping;
80 filp->private_data = bdev; 80 filp->private_data = bdev;
81 mutex_unlock(&raw_mutex); 81 mutex_unlock(&raw_mutex);
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 0a77bfcd5b5e..e2a94bfb2a43 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -1539,7 +1539,7 @@ static void rc_hangup(struct tty_struct * tty)
1539 wake_up_interruptible(&port->open_wait); 1539 wake_up_interruptible(&port->open_wait);
1540} 1540}
1541 1541
1542static void rc_set_termios(struct tty_struct * tty, struct termios * old_termios) 1542static void rc_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
1543{ 1543{
1544 struct riscom_port *port = (struct riscom_port *)tty->driver_data; 1544 struct riscom_port *port = (struct riscom_port *)tty->driver_data;
1545 unsigned long flags; 1545 unsigned long flags;
@@ -1614,6 +1614,8 @@ static inline int rc_init_drivers(void)
1614 riscom_driver->init_termios = tty_std_termios; 1614 riscom_driver->init_termios = tty_std_termios;
1615 riscom_driver->init_termios.c_cflag = 1615 riscom_driver->init_termios.c_cflag =
1616 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1616 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
1617 riscom_driver->init_termios.c_ispeed = 9600;
1618 riscom_driver->init_termios.c_ospeed = 9600;
1617 riscom_driver->flags = TTY_DRIVER_REAL_RAW; 1619 riscom_driver->flags = TTY_DRIVER_REAL_RAW;
1618 tty_set_operations(riscom_driver, &riscom_ops); 1620 tty_set_operations(riscom_driver, &riscom_ops);
1619 if ((error = tty_register_driver(riscom_driver))) { 1621 if ((error = tty_register_driver(riscom_driver))) {
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index bac80056f7e0..e94a62e30fc4 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -712,7 +712,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
712 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected. 712 * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
713 */ 713 */
714static void configure_r_port(struct r_port *info, 714static void configure_r_port(struct r_port *info,
715 struct termios *old_termios) 715 struct ktermios *old_termios)
716{ 716{
717 unsigned cflag; 717 unsigned cflag;
718 unsigned long flags; 718 unsigned long flags;
@@ -1017,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1017 /* 1017 /*
1018 * Info->count is now 1; so it's safe to sleep now. 1018 * Info->count is now 1; so it's safe to sleep now.
1019 */ 1019 */
1020 info->session = current->signal->session; 1020 info->session = process_session(current);
1021 info->pgrp = process_group(current); 1021 info->pgrp = process_group(current);
1022 1022
1023 if ((info->flags & ROCKET_INITIALIZED) == 0) { 1023 if ((info->flags & ROCKET_INITIALIZED) == 0) {
@@ -1194,7 +1194,7 @@ static void rp_close(struct tty_struct *tty, struct file *filp)
1194} 1194}
1195 1195
1196static void rp_set_termios(struct tty_struct *tty, 1196static void rp_set_termios(struct tty_struct *tty,
1197 struct termios *old_termios) 1197 struct ktermios *old_termios)
1198{ 1198{
1199 struct r_port *info = (struct r_port *) tty->driver_data; 1199 struct r_port *info = (struct r_port *) tty->driver_data;
1200 CHANNEL_t *cp; 1200 CHANNEL_t *cp;
@@ -2214,7 +2214,7 @@ static int __init init_PCI(int boards_found)
2214 int count = 0; 2214 int count = 0;
2215 2215
2216 /* Work through the PCI device list, pulling out ours */ 2216 /* Work through the PCI device list, pulling out ours */
2217 while ((dev = pci_find_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) { 2217 while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
2218 if (register_PCI(count + boards_found, dev)) 2218 if (register_PCI(count + boards_found, dev))
2219 count++; 2219 count++;
2220 } 2220 }
@@ -2436,6 +2436,8 @@ static int __init rp_init(void)
2436 rocket_driver->init_termios = tty_std_termios; 2436 rocket_driver->init_termios = tty_std_termios;
2437 rocket_driver->init_termios.c_cflag = 2437 rocket_driver->init_termios.c_cflag =
2438 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2438 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2439 rocket_driver->init_termios.c_ispeed = 9600;
2440 rocket_driver->init_termios.c_ospeed = 9600;
2439#ifdef ROCKET_SOFT_FLOW 2441#ifdef ROCKET_SOFT_FLOW
2440 rocket_driver->flags |= TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 2442 rocket_driver->flags |= TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2441#endif 2443#endif
diff --git a/drivers/char/ser_a2232.c b/drivers/char/ser_a2232.c
index 4217d38caef9..75de5f66517a 100644
--- a/drivers/char/ser_a2232.c
+++ b/drivers/char/ser_a2232.c
@@ -695,6 +695,8 @@ static int a2232_init_drivers(void)
695 a2232_driver->init_termios = tty_std_termios; 695 a2232_driver->init_termios = tty_std_termios;
696 a2232_driver->init_termios.c_cflag = 696 a2232_driver->init_termios.c_cflag =
697 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 697 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
698 a2232_driver->init_termios.c_ispeed = 9600;
699 a2232_driver->init_termios.c_ospeed = 9600;
698 a2232_driver->flags = TTY_DRIVER_REAL_RAW; 700 a2232_driver->flags = TTY_DRIVER_REAL_RAW;
699 tty_set_operations(a2232_driver, &a2232_ops); 701 tty_set_operations(a2232_driver, &a2232_ops);
700 if ((error = tty_register_driver(a2232_driver))) { 702 if ((error = tty_register_driver(a2232_driver))) {
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 9ba13af234be..af50d32ae2c7 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -1695,7 +1695,7 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
1695 1695
1696 1696
1697static void 1697static void
1698cy_set_termios(struct tty_struct *tty, struct termios * old_termios) 1698cy_set_termios(struct tty_struct *tty, struct ktermios * old_termios)
1699{ 1699{
1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1701 1701
diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
index fc87070f1866..17d54e1331b2 100644
--- a/drivers/char/sonypi.c
+++ b/drivers/char/sonypi.c
@@ -979,7 +979,7 @@ static ssize_t sonypi_misc_read(struct file *file, char __user *buf,
979 } 979 }
980 980
981 if (ret > 0) { 981 if (ret > 0) {
982 struct inode *inode = file->f_dentry->d_inode; 982 struct inode *inode = file->f_path.dentry->d_inode;
983 inode->i_atime = current_fs_time(inode->i_sb); 983 inode->i_atime = current_fs_time(inode->i_sb);
984 } 984 }
985 985
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 99137ab66b62..20946f5127e0 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -2311,7 +2311,7 @@ static void sx_hangup(struct tty_struct * tty)
2311} 2311}
2312 2312
2313 2313
2314static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios) 2314static void sx_set_termios(struct tty_struct * tty, struct ktermios * old_termios)
2315{ 2315{
2316 struct specialix_port *port = (struct specialix_port *)tty->driver_data; 2316 struct specialix_port *port = (struct specialix_port *)tty->driver_data;
2317 unsigned long flags; 2317 unsigned long flags;
@@ -2400,6 +2400,8 @@ static int sx_init_drivers(void)
2400 specialix_driver->init_termios = tty_std_termios; 2400 specialix_driver->init_termios = tty_std_termios;
2401 specialix_driver->init_termios.c_cflag = 2401 specialix_driver->init_termios.c_cflag =
2402 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2402 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2403 specialix_driver->init_termios.c_ispeed = 9600;
2404 specialix_driver->init_termios.c_ospeed = 9600;
2403 specialix_driver->flags = TTY_DRIVER_REAL_RAW; 2405 specialix_driver->flags = TTY_DRIVER_REAL_RAW;
2404 tty_set_operations(specialix_driver, &sx_ops); 2406 tty_set_operations(specialix_driver, &sx_ops);
2405 2407
@@ -2475,7 +2477,7 @@ static int __init specialix_init(void)
2475 i++; 2477 i++;
2476 continue; 2478 continue;
2477 } 2479 }
2478 pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX, 2480 pdev = pci_get_device (PCI_VENDOR_ID_SPECIALIX,
2479 PCI_DEVICE_ID_SPECIALIX_IO8, 2481 PCI_DEVICE_ID_SPECIALIX_IO8,
2480 pdev); 2482 pdev);
2481 if (!pdev) break; 2483 if (!pdev) break;
@@ -2491,6 +2493,9 @@ static int __init specialix_init(void)
2491 if (!sx_probe(&sx_board[i])) 2493 if (!sx_probe(&sx_board[i]))
2492 found ++; 2494 found ++;
2493 } 2495 }
2496 /* May exit pci_get sequence early with lots of boards */
2497 if (pdev != NULL)
2498 pci_dev_put(pdev);
2494 } 2499 }
2495#endif 2500#endif
2496 2501
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 5e2de62bce70..e45113a7a472 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -41,13 +41,12 @@
41#include <linux/smp_lock.h> 41#include <linux/smp_lock.h>
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/ctype.h>
44 45
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47 48
48#ifdef CONFIG_PCI
49#include <linux/pci.h> 49#include <linux/pci.h>
50#endif
51 50
52/*****************************************************************************/ 51/*****************************************************************************/
53 52
@@ -63,45 +62,16 @@
63#define BRD_ECH64PCI 27 62#define BRD_ECH64PCI 27
64#define BRD_EASYIOPCI 28 63#define BRD_EASYIOPCI 28
65 64
66/* 65struct stlconf {
67 * Define a configuration structure to hold the board configuration. 66 unsigned int brdtype;
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
73 * Some examples:
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
77 * Another example:
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
85 *
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
89 */
90
91typedef struct {
92 int brdtype;
93 int ioaddr1; 67 int ioaddr1;
94 int ioaddr2; 68 int ioaddr2;
95 unsigned long memaddr; 69 unsigned long memaddr;
96 int irq; 70 int irq;
97 int irqtype; 71 int irqtype;
98} stlconf_t;
99
100static stlconf_t stl_brdconf[] = {
101 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
102}; 72};
103 73
104static int stl_nrbrds = ARRAY_SIZE(stl_brdconf); 74static unsigned int stl_nrbrds;
105 75
106/*****************************************************************************/ 76/*****************************************************************************/
107 77
@@ -143,34 +113,30 @@ static struct tty_driver *stl_serial;
143 * with this termios initially. Basically all it defines is a raw port 113 * with this termios initially. Basically all it defines is a raw port
144 * at 9600, 8 data bits, 1 stop bit. 114 * at 9600, 8 data bits, 1 stop bit.
145 */ 115 */
146static struct termios stl_deftermios = { 116static struct ktermios stl_deftermios = {
147 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL), 117 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
148 .c_cc = INIT_C_CC, 118 .c_cc = INIT_C_CC,
119 .c_ispeed = 9600,
120 .c_ospeed = 9600,
149}; 121};
150 122
151/* 123/*
152 * Define global stats structures. Not used often, and can be
153 * re-used for each stats call.
154 */
155static comstats_t stl_comstats;
156static combrd_t stl_brdstats;
157static stlbrd_t stl_dummybrd;
158static stlport_t stl_dummyport;
159
160/*
161 * Define global place to put buffer overflow characters. 124 * Define global place to put buffer overflow characters.
162 */ 125 */
163static char stl_unwanted[SC26198_RXFIFOSIZE]; 126static char stl_unwanted[SC26198_RXFIFOSIZE];
164 127
165/*****************************************************************************/ 128/*****************************************************************************/
166 129
167static stlbrd_t *stl_brds[STL_MAXBRDS]; 130static DEFINE_MUTEX(stl_brdslock);
131static struct stlbrd *stl_brds[STL_MAXBRDS];
168 132
169/* 133/*
170 * Per board state flags. Used with the state field of the board struct. 134 * Per board state flags. Used with the state field of the board struct.
171 * Not really much here! 135 * Not really much here!
172 */ 136 */
173#define BRD_FOUND 0x1 137#define BRD_FOUND 0x1
138#define STL_PROBED 0x2
139
174 140
175/* 141/*
176 * Define the port structure istate flags. These set of flags are 142 * Define the port structure istate flags. These set of flags are
@@ -187,32 +153,32 @@ static stlbrd_t *stl_brds[STL_MAXBRDS];
187 * referencing boards when printing trace and stuff. 153 * referencing boards when printing trace and stuff.
188 */ 154 */
189static char *stl_brdnames[] = { 155static char *stl_brdnames[] = {
190 (char *) NULL, 156 NULL,
191 (char *) NULL, 157 NULL,
192 (char *) NULL, 158 NULL,
193 (char *) NULL, 159 NULL,
194 (char *) NULL, 160 NULL,
195 (char *) NULL, 161 NULL,
196 (char *) NULL, 162 NULL,
197 (char *) NULL, 163 NULL,
198 (char *) NULL, 164 NULL,
199 (char *) NULL, 165 NULL,
200 (char *) NULL, 166 NULL,
201 (char *) NULL, 167 NULL,
202 (char *) NULL, 168 NULL,
203 (char *) NULL, 169 NULL,
204 (char *) NULL, 170 NULL,
205 (char *) NULL, 171 NULL,
206 (char *) NULL, 172 NULL,
207 (char *) NULL, 173 NULL,
208 (char *) NULL, 174 NULL,
209 (char *) NULL, 175 NULL,
210 "EasyIO", 176 "EasyIO",
211 "EC8/32-AT", 177 "EC8/32-AT",
212 "EC8/32-MC", 178 "EC8/32-MC",
213 (char *) NULL, 179 NULL,
214 (char *) NULL, 180 NULL,
215 (char *) NULL, 181 NULL,
216 "EC8/32-PCI", 182 "EC8/32-PCI",
217 "EC8/64-PCI", 183 "EC8/64-PCI",
218 "EasyIO-PCI", 184 "EasyIO-PCI",
@@ -225,7 +191,7 @@ static char *stl_brdnames[] = {
225 * load line. These allow for easy board definitions, and easy 191 * load line. These allow for easy board definitions, and easy
226 * modification of the io, memory and irq resoucres. 192 * modification of the io, memory and irq resoucres.
227 */ 193 */
228static int stl_nargs = 0; 194static unsigned int stl_nargs;
229static char *board0[4]; 195static char *board0[4];
230static char *board1[4]; 196static char *board1[4];
231static char *board2[4]; 197static char *board2[4];
@@ -243,12 +209,10 @@ static char **stl_brdsp[] = {
243 * parse any module arguments. 209 * parse any module arguments.
244 */ 210 */
245 211
246typedef struct stlbrdtype { 212static struct {
247 char *name; 213 char *name;
248 int type; 214 int type;
249} stlbrdtype_t; 215} stl_brdstr[] = {
250
251static stlbrdtype_t stl_brdstr[] = {
252 { "easyio", BRD_EASYIO }, 216 { "easyio", BRD_EASYIO },
253 { "eio", BRD_EASYIO }, 217 { "eio", BRD_EASYIO },
254 { "20", BRD_EASYIO }, 218 { "20", BRD_EASYIO },
@@ -282,9 +246,6 @@ static stlbrdtype_t stl_brdstr[] = {
282/* 246/*
283 * Define the module agruments. 247 * Define the module agruments.
284 */ 248 */
285MODULE_AUTHOR("Greg Ungerer");
286MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
287MODULE_LICENSE("GPL");
288 249
289module_param_array(board0, charp, &stl_nargs, 0); 250module_param_array(board0, charp, &stl_nargs, 0);
290MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]"); 251MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
@@ -386,8 +347,6 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
386 347
387/*****************************************************************************/ 348/*****************************************************************************/
388 349
389#ifdef CONFIG_PCI
390
391/* 350/*
392 * Define the Stallion PCI vendor and device IDs. 351 * Define the Stallion PCI vendor and device IDs.
393 */ 352 */
@@ -407,22 +366,19 @@ static spinlock_t stallion_lock; /* Guard the tty driver */
407/* 366/*
408 * Define structure to hold all Stallion PCI boards. 367 * Define structure to hold all Stallion PCI boards.
409 */ 368 */
410typedef struct stlpcibrd {
411 unsigned short vendid;
412 unsigned short devid;
413 int brdtype;
414} stlpcibrd_t;
415
416static stlpcibrd_t stl_pcibrds[] = {
417 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
418 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
419 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
420 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
421};
422
423static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
424 369
425#endif 370static struct pci_device_id stl_pcibrds[] = {
371 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
372 .driver_data = BRD_ECH64PCI },
373 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
374 .driver_data = BRD_EASYIOPCI },
375 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
376 .driver_data = BRD_ECHPCI },
377 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
378 .driver_data = BRD_ECHPCI },
379 { }
380};
381MODULE_DEVICE_TABLE(pci, stl_pcibrds);
426 382
427/*****************************************************************************/ 383/*****************************************************************************/
428 384
@@ -442,134 +398,74 @@ static unsigned int stl_baudrates[] = {
442 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600 398 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
443}; 399};
444 400
445/*
446 * Define some handy local macros...
447 */
448#undef MIN
449#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
450
451#undef TOLOWER
452#define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
453
454/*****************************************************************************/ 401/*****************************************************************************/
455 402
456/* 403/*
457 * Declare all those functions in this driver! 404 * Declare all those functions in this driver!
458 */ 405 */
459 406
460static void stl_argbrds(void);
461static int stl_parsebrd(stlconf_t *confp, char **argp);
462
463static unsigned long stl_atol(char *str);
464
465static int stl_init(void);
466static int stl_open(struct tty_struct *tty, struct file *filp);
467static void stl_close(struct tty_struct *tty, struct file *filp);
468static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
469static void stl_putchar(struct tty_struct *tty, unsigned char ch);
470static void stl_flushchars(struct tty_struct *tty);
471static int stl_writeroom(struct tty_struct *tty);
472static int stl_charsinbuffer(struct tty_struct *tty);
473static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
474static void stl_settermios(struct tty_struct *tty, struct termios *old);
475static void stl_throttle(struct tty_struct *tty);
476static void stl_unthrottle(struct tty_struct *tty);
477static void stl_stop(struct tty_struct *tty);
478static void stl_start(struct tty_struct *tty);
479static void stl_flushbuffer(struct tty_struct *tty);
480static void stl_breakctl(struct tty_struct *tty, int state);
481static void stl_waituntilsent(struct tty_struct *tty, int timeout);
482static void stl_sendxchar(struct tty_struct *tty, char ch);
483static void stl_hangup(struct tty_struct *tty);
484static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 407static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
485static int stl_portinfo(stlport_t *portp, int portnr, char *pos); 408static int stl_brdinit(struct stlbrd *brdp);
486static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data); 409static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
487 410static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
488static int stl_brdinit(stlbrd_t *brdp); 411static int stl_waitcarrier(struct stlport *portp, struct file *filp);
489static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
490static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
491static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
492static int stl_getbrdstats(combrd_t __user *bp);
493static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
494static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
495static int stl_getportstruct(stlport_t __user *arg);
496static int stl_getbrdstruct(stlbrd_t __user *arg);
497static int stl_waitcarrier(stlport_t *portp, struct file *filp);
498static int stl_eiointr(stlbrd_t *brdp);
499static int stl_echatintr(stlbrd_t *brdp);
500static int stl_echmcaintr(stlbrd_t *brdp);
501static int stl_echpciintr(stlbrd_t *brdp);
502static int stl_echpci64intr(stlbrd_t *brdp);
503static void stl_offintr(struct work_struct *);
504static stlbrd_t *stl_allocbrd(void);
505static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
506
507static inline int stl_initbrds(void);
508static inline int stl_initeio(stlbrd_t *brdp);
509static inline int stl_initech(stlbrd_t *brdp);
510static inline int stl_getbrdnr(void);
511
512#ifdef CONFIG_PCI
513static inline int stl_findpcibrds(void);
514static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
515#endif
516 412
517/* 413/*
518 * CD1400 uart specific handling functions. 414 * CD1400 uart specific handling functions.
519 */ 415 */
520static void stl_cd1400setreg(stlport_t *portp, int regnr, int value); 416static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
521static int stl_cd1400getreg(stlport_t *portp, int regnr); 417static int stl_cd1400getreg(struct stlport *portp, int regnr);
522static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value); 418static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
523static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp); 419static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
524static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 420static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
525static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp); 421static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
526static int stl_cd1400getsignals(stlport_t *portp); 422static int stl_cd1400getsignals(struct stlport *portp);
527static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts); 423static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
528static void stl_cd1400ccrwait(stlport_t *portp); 424static void stl_cd1400ccrwait(struct stlport *portp);
529static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx); 425static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
530static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx); 426static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
531static void stl_cd1400disableintrs(stlport_t *portp); 427static void stl_cd1400disableintrs(struct stlport *portp);
532static void stl_cd1400sendbreak(stlport_t *portp, int len); 428static void stl_cd1400sendbreak(struct stlport *portp, int len);
533static void stl_cd1400flowctrl(stlport_t *portp, int state); 429static void stl_cd1400flowctrl(struct stlport *portp, int state);
534static void stl_cd1400sendflow(stlport_t *portp, int state); 430static void stl_cd1400sendflow(struct stlport *portp, int state);
535static void stl_cd1400flush(stlport_t *portp); 431static void stl_cd1400flush(struct stlport *portp);
536static int stl_cd1400datastate(stlport_t *portp); 432static int stl_cd1400datastate(struct stlport *portp);
537static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase); 433static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
538static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase); 434static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
539static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr); 435static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
540static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr); 436static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
541static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr); 437static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
542 438
543static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr); 439static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
544 440
545/* 441/*
546 * SC26198 uart specific handling functions. 442 * SC26198 uart specific handling functions.
547 */ 443 */
548static void stl_sc26198setreg(stlport_t *portp, int regnr, int value); 444static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
549static int stl_sc26198getreg(stlport_t *portp, int regnr); 445static int stl_sc26198getreg(struct stlport *portp, int regnr);
550static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value); 446static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
551static int stl_sc26198getglobreg(stlport_t *portp, int regnr); 447static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
552static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp); 448static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
553static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 449static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
554static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp); 450static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
555static int stl_sc26198getsignals(stlport_t *portp); 451static int stl_sc26198getsignals(struct stlport *portp);
556static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts); 452static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
557static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx); 453static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
558static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx); 454static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
559static void stl_sc26198disableintrs(stlport_t *portp); 455static void stl_sc26198disableintrs(struct stlport *portp);
560static void stl_sc26198sendbreak(stlport_t *portp, int len); 456static void stl_sc26198sendbreak(struct stlport *portp, int len);
561static void stl_sc26198flowctrl(stlport_t *portp, int state); 457static void stl_sc26198flowctrl(struct stlport *portp, int state);
562static void stl_sc26198sendflow(stlport_t *portp, int state); 458static void stl_sc26198sendflow(struct stlport *portp, int state);
563static void stl_sc26198flush(stlport_t *portp); 459static void stl_sc26198flush(struct stlport *portp);
564static int stl_sc26198datastate(stlport_t *portp); 460static int stl_sc26198datastate(struct stlport *portp);
565static void stl_sc26198wait(stlport_t *portp); 461static void stl_sc26198wait(struct stlport *portp);
566static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty); 462static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
567static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase); 463static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
568static void stl_sc26198txisr(stlport_t *port); 464static void stl_sc26198txisr(struct stlport *port);
569static void stl_sc26198rxisr(stlport_t *port, unsigned int iack); 465static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
570static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch); 466static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
571static void stl_sc26198rxbadchars(stlport_t *portp); 467static void stl_sc26198rxbadchars(struct stlport *portp);
572static void stl_sc26198otherisr(stlport_t *port, unsigned int iack); 468static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
573 469
574/*****************************************************************************/ 470/*****************************************************************************/
575 471
@@ -577,20 +473,20 @@ static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
577 * Generic UART support structure. 473 * Generic UART support structure.
578 */ 474 */
579typedef struct uart { 475typedef struct uart {
580 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp); 476 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
581 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp); 477 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
582 void (*setport)(stlport_t *portp, struct termios *tiosp); 478 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
583 int (*getsignals)(stlport_t *portp); 479 int (*getsignals)(struct stlport *portp);
584 void (*setsignals)(stlport_t *portp, int dtr, int rts); 480 void (*setsignals)(struct stlport *portp, int dtr, int rts);
585 void (*enablerxtx)(stlport_t *portp, int rx, int tx); 481 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
586 void (*startrxtx)(stlport_t *portp, int rx, int tx); 482 void (*startrxtx)(struct stlport *portp, int rx, int tx);
587 void (*disableintrs)(stlport_t *portp); 483 void (*disableintrs)(struct stlport *portp);
588 void (*sendbreak)(stlport_t *portp, int len); 484 void (*sendbreak)(struct stlport *portp, int len);
589 void (*flowctrl)(stlport_t *portp, int state); 485 void (*flowctrl)(struct stlport *portp, int state);
590 void (*sendflow)(stlport_t *portp, int state); 486 void (*sendflow)(struct stlport *portp, int state);
591 void (*flush)(stlport_t *portp); 487 void (*flush)(struct stlport *portp);
592 int (*datastate)(stlport_t *portp); 488 int (*datastate)(struct stlport *portp);
593 void (*intr)(stlpanel_t *panelp, unsigned int iobase); 489 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
594} uart_t; 490} uart_t;
595 491
596/* 492/*
@@ -712,184 +608,35 @@ static const struct file_operations stl_fsiomem = {
712 .ioctl = stl_memioctl, 608 .ioctl = stl_memioctl,
713}; 609};
714 610
715/*****************************************************************************/
716
717static struct class *stallion_class; 611static struct class *stallion_class;
718 612
719/* 613/*
720 * Loadable module initialization stuff.
721 */
722
723static int __init stallion_module_init(void)
724{
725 stl_init();
726 return 0;
727}
728
729/*****************************************************************************/
730
731static void __exit stallion_module_exit(void)
732{
733 stlbrd_t *brdp;
734 stlpanel_t *panelp;
735 stlport_t *portp;
736 int i, j, k;
737
738#ifdef DEBUG
739 printk("cleanup_module()\n");
740#endif
741
742 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
743 stl_drvversion);
744
745/*
746 * Free up all allocated resources used by the ports. This includes
747 * memory and interrupts. As part of this process we will also do
748 * a hangup on every open port - to try to flush out any processes
749 * hanging onto ports.
750 */
751 i = tty_unregister_driver(stl_serial);
752 put_tty_driver(stl_serial);
753 if (i) {
754 printk("STALLION: failed to un-register tty driver, "
755 "errno=%d\n", -i);
756 return;
757 }
758 for (i = 0; i < 4; i++)
759 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
760 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
761 printk("STALLION: failed to un-register serial memory device, "
762 "errno=%d\n", -i);
763 class_destroy(stallion_class);
764
765 for (i = 0; (i < stl_nrbrds); i++) {
766 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
767 continue;
768
769 free_irq(brdp->irq, brdp);
770
771 for (j = 0; (j < STL_MAXPANELS); j++) {
772 panelp = brdp->panels[j];
773 if (panelp == (stlpanel_t *) NULL)
774 continue;
775 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
776 portp = panelp->ports[k];
777 if (portp == (stlport_t *) NULL)
778 continue;
779 if (portp->tty != (struct tty_struct *) NULL)
780 stl_hangup(portp->tty);
781 kfree(portp->tx.buf);
782 kfree(portp);
783 }
784 kfree(panelp);
785 }
786
787 release_region(brdp->ioaddr1, brdp->iosize1);
788 if (brdp->iosize2 > 0)
789 release_region(brdp->ioaddr2, brdp->iosize2);
790
791 kfree(brdp);
792 stl_brds[i] = (stlbrd_t *) NULL;
793 }
794}
795
796module_init(stallion_module_init);
797module_exit(stallion_module_exit);
798
799/*****************************************************************************/
800
801/*
802 * Check for any arguments passed in on the module load command line. 614 * Check for any arguments passed in on the module load command line.
803 */ 615 */
804 616
805static void stl_argbrds(void)
806{
807 stlconf_t conf;
808 stlbrd_t *brdp;
809 int i;
810
811#ifdef DEBUG
812 printk("stl_argbrds()\n");
813#endif
814
815 for (i = stl_nrbrds; (i < stl_nargs); i++) {
816 memset(&conf, 0, sizeof(conf));
817 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
818 continue;
819 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
820 continue;
821 stl_nrbrds = i + 1;
822 brdp->brdnr = i;
823 brdp->brdtype = conf.brdtype;
824 brdp->ioaddr1 = conf.ioaddr1;
825 brdp->ioaddr2 = conf.ioaddr2;
826 brdp->irq = conf.irq;
827 brdp->irqtype = conf.irqtype;
828 stl_brdinit(brdp);
829 }
830}
831
832/*****************************************************************************/
833
834/*
835 * Convert an ascii string number into an unsigned long.
836 */
837
838static unsigned long stl_atol(char *str)
839{
840 unsigned long val;
841 int base, c;
842 char *sp;
843
844 val = 0;
845 sp = str;
846 if ((*sp == '0') && (*(sp+1) == 'x')) {
847 base = 16;
848 sp += 2;
849 } else if (*sp == '0') {
850 base = 8;
851 sp++;
852 } else {
853 base = 10;
854 }
855
856 for (; (*sp != 0); sp++) {
857 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
858 if ((c < 0) || (c >= base)) {
859 printk("STALLION: invalid argument %s\n", str);
860 val = 0;
861 break;
862 }
863 val = (val * base) + c;
864 }
865 return val;
866}
867
868/*****************************************************************************/ 617/*****************************************************************************/
869 618
870/* 619/*
871 * Parse the supplied argument string, into the board conf struct. 620 * Parse the supplied argument string, into the board conf struct.
872 */ 621 */
873 622
874static int stl_parsebrd(stlconf_t *confp, char **argp) 623static int __init stl_parsebrd(struct stlconf *confp, char **argp)
875{ 624{
876 char *sp; 625 char *sp;
877 int i; 626 unsigned int i;
878 627
879#ifdef DEBUG 628 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
880 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
881#endif
882 629
883 if ((argp[0] == (char *) NULL) || (*argp[0] == 0)) 630 if ((argp[0] == NULL) || (*argp[0] == 0))
884 return 0; 631 return 0;
885 632
886 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 633 for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
887 *sp = TOLOWER(*sp); 634 *sp = tolower(*sp);
888 635
889 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) { 636 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
890 if (strcmp(stl_brdstr[i].name, argp[0]) == 0) 637 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
891 break; 638 break;
892 } 639
893 if (i == ARRAY_SIZE(stl_brdstr)) { 640 if (i == ARRAY_SIZE(stl_brdstr)) {
894 printk("STALLION: unknown board name, %s?\n", argp[0]); 641 printk("STALLION: unknown board name, %s?\n", argp[0]);
895 return 0; 642 return 0;
@@ -898,16 +645,16 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
898 confp->brdtype = stl_brdstr[i].type; 645 confp->brdtype = stl_brdstr[i].type;
899 646
900 i = 1; 647 i = 1;
901 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 648 if ((argp[i] != NULL) && (*argp[i] != 0))
902 confp->ioaddr1 = stl_atol(argp[i]); 649 confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
903 i++; 650 i++;
904 if (confp->brdtype == BRD_ECH) { 651 if (confp->brdtype == BRD_ECH) {
905 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 652 if ((argp[i] != NULL) && (*argp[i] != 0))
906 confp->ioaddr2 = stl_atol(argp[i]); 653 confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
907 i++; 654 i++;
908 } 655 }
909 if ((argp[i] != (char *) NULL) && (*argp[i] != 0)) 656 if ((argp[i] != NULL) && (*argp[i] != 0))
910 confp->irq = stl_atol(argp[i]); 657 confp->irq = simple_strtoul(argp[i], NULL, 0);
911 return 1; 658 return 1;
912} 659}
913 660
@@ -917,14 +664,14 @@ static int stl_parsebrd(stlconf_t *confp, char **argp)
917 * Allocate a new board structure. Fill out the basic info in it. 664 * Allocate a new board structure. Fill out the basic info in it.
918 */ 665 */
919 666
920static stlbrd_t *stl_allocbrd(void) 667static struct stlbrd *stl_allocbrd(void)
921{ 668{
922 stlbrd_t *brdp; 669 struct stlbrd *brdp;
923 670
924 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL); 671 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
925 if (!brdp) { 672 if (!brdp) {
926 printk("STALLION: failed to allocate memory (size=%Zd)\n", 673 printk("STALLION: failed to allocate memory (size=%Zd)\n",
927 sizeof(stlbrd_t)); 674 sizeof(struct stlbrd));
928 return NULL; 675 return NULL;
929 } 676 }
930 677
@@ -936,26 +683,23 @@ static stlbrd_t *stl_allocbrd(void)
936 683
937static int stl_open(struct tty_struct *tty, struct file *filp) 684static int stl_open(struct tty_struct *tty, struct file *filp)
938{ 685{
939 stlport_t *portp; 686 struct stlport *portp;
940 stlbrd_t *brdp; 687 struct stlbrd *brdp;
941 unsigned int minordev; 688 unsigned int minordev, brdnr, panelnr;
942 int brdnr, panelnr, portnr, rc; 689 int portnr, rc;
943 690
944#ifdef DEBUG 691 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
945 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
946 (int) filp, tty->name);
947#endif
948 692
949 minordev = tty->index; 693 minordev = tty->index;
950 brdnr = MINOR2BRD(minordev); 694 brdnr = MINOR2BRD(minordev);
951 if (brdnr >= stl_nrbrds) 695 if (brdnr >= stl_nrbrds)
952 return -ENODEV; 696 return -ENODEV;
953 brdp = stl_brds[brdnr]; 697 brdp = stl_brds[brdnr];
954 if (brdp == (stlbrd_t *) NULL) 698 if (brdp == NULL)
955 return -ENODEV; 699 return -ENODEV;
956 minordev = MINOR2PORT(minordev); 700 minordev = MINOR2PORT(minordev);
957 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) { 701 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
958 if (brdp->panels[panelnr] == (stlpanel_t *) NULL) 702 if (brdp->panels[panelnr] == NULL)
959 break; 703 break;
960 if (minordev < brdp->panels[panelnr]->nrports) { 704 if (minordev < brdp->panels[panelnr]->nrports) {
961 portnr = minordev; 705 portnr = minordev;
@@ -967,7 +711,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
967 return -ENODEV; 711 return -ENODEV;
968 712
969 portp = brdp->panels[panelnr]->ports[portnr]; 713 portp = brdp->panels[panelnr]->ports[portnr];
970 if (portp == (stlport_t *) NULL) 714 if (portp == NULL)
971 return -ENODEV; 715 return -ENODEV;
972 716
973/* 717/*
@@ -1013,10 +757,10 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
1013 * previous opens still in effect. If we are a normal serial device 757 * previous opens still in effect. If we are a normal serial device
1014 * then also we might have to wait for carrier. 758 * then also we might have to wait for carrier.
1015 */ 759 */
1016 if (!(filp->f_flags & O_NONBLOCK)) { 760 if (!(filp->f_flags & O_NONBLOCK))
1017 if ((rc = stl_waitcarrier(portp, filp)) != 0) 761 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1018 return rc; 762 return rc;
1019 } 763
1020 portp->flags |= ASYNC_NORMAL_ACTIVE; 764 portp->flags |= ASYNC_NORMAL_ACTIVE;
1021 765
1022 return 0; 766 return 0;
@@ -1029,14 +773,12 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
1029 * maybe because if we are clocal then we don't need to wait... 773 * maybe because if we are clocal then we don't need to wait...
1030 */ 774 */
1031 775
1032static int stl_waitcarrier(stlport_t *portp, struct file *filp) 776static int stl_waitcarrier(struct stlport *portp, struct file *filp)
1033{ 777{
1034 unsigned long flags; 778 unsigned long flags;
1035 int rc, doclocal; 779 int rc, doclocal;
1036 780
1037#ifdef DEBUG 781 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
1038 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1039#endif
1040 782
1041 rc = 0; 783 rc = 0;
1042 doclocal = 0; 784 doclocal = 0;
@@ -1062,9 +804,8 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1062 break; 804 break;
1063 } 805 }
1064 if (((portp->flags & ASYNC_CLOSING) == 0) && 806 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1065 (doclocal || (portp->sigs & TIOCM_CD))) { 807 (doclocal || (portp->sigs & TIOCM_CD)))
1066 break; 808 break;
1067 }
1068 if (signal_pending(current)) { 809 if (signal_pending(current)) {
1069 rc = -ERESTARTSYS; 810 rc = -ERESTARTSYS;
1070 break; 811 break;
@@ -1083,17 +824,61 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1083 824
1084/*****************************************************************************/ 825/*****************************************************************************/
1085 826
827static void stl_flushbuffer(struct tty_struct *tty)
828{
829 struct stlport *portp;
830
831 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
832
833 if (tty == NULL)
834 return;
835 portp = tty->driver_data;
836 if (portp == NULL)
837 return;
838
839 stl_flush(portp);
840 tty_wakeup(tty);
841}
842
843/*****************************************************************************/
844
845static void stl_waituntilsent(struct tty_struct *tty, int timeout)
846{
847 struct stlport *portp;
848 unsigned long tend;
849
850 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
851
852 if (tty == NULL)
853 return;
854 portp = tty->driver_data;
855 if (portp == NULL)
856 return;
857
858 if (timeout == 0)
859 timeout = HZ;
860 tend = jiffies + timeout;
861
862 while (stl_datastate(portp)) {
863 if (signal_pending(current))
864 break;
865 msleep_interruptible(20);
866 if (time_after_eq(jiffies, tend))
867 break;
868 }
869}
870
871/*****************************************************************************/
872
1086static void stl_close(struct tty_struct *tty, struct file *filp) 873static void stl_close(struct tty_struct *tty, struct file *filp)
1087{ 874{
1088 stlport_t *portp; 875 struct stlport *portp;
1089 unsigned long flags; 876 unsigned long flags;
1090 877
1091#ifdef DEBUG 878 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
1092 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1093#endif
1094 879
1095 portp = tty->driver_data; 880 portp = tty->driver_data;
1096 if (portp == (stlport_t *) NULL) 881 if (portp == NULL)
1097 return; 882 return;
1098 883
1099 spin_lock_irqsave(&stallion_lock, flags); 884 spin_lock_irqsave(&stallion_lock, flags);
@@ -1136,17 +921,17 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1136 stl_enablerxtx(portp, 0, 0); 921 stl_enablerxtx(portp, 0, 0);
1137 stl_flushbuffer(tty); 922 stl_flushbuffer(tty);
1138 portp->istate = 0; 923 portp->istate = 0;
1139 if (portp->tx.buf != (char *) NULL) { 924 if (portp->tx.buf != NULL) {
1140 kfree(portp->tx.buf); 925 kfree(portp->tx.buf);
1141 portp->tx.buf = (char *) NULL; 926 portp->tx.buf = NULL;
1142 portp->tx.head = (char *) NULL; 927 portp->tx.head = NULL;
1143 portp->tx.tail = (char *) NULL; 928 portp->tx.tail = NULL;
1144 } 929 }
1145 set_bit(TTY_IO_ERROR, &tty->flags); 930 set_bit(TTY_IO_ERROR, &tty->flags);
1146 tty_ldisc_flush(tty); 931 tty_ldisc_flush(tty);
1147 932
1148 tty->closing = 0; 933 tty->closing = 0;
1149 portp->tty = (struct tty_struct *) NULL; 934 portp->tty = NULL;
1150 935
1151 if (portp->openwaitcnt) { 936 if (portp->openwaitcnt) {
1152 if (portp->close_delay) 937 if (portp->close_delay)
@@ -1167,20 +952,17 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1167 952
1168static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count) 953static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1169{ 954{
1170 stlport_t *portp; 955 struct stlport *portp;
1171 unsigned int len, stlen; 956 unsigned int len, stlen;
1172 unsigned char *chbuf; 957 unsigned char *chbuf;
1173 char *head, *tail; 958 char *head, *tail;
1174 959
1175#ifdef DEBUG 960 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1176 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1177 (int) tty, (int) buf, count);
1178#endif
1179 961
1180 portp = tty->driver_data; 962 portp = tty->driver_data;
1181 if (portp == (stlport_t *) NULL) 963 if (portp == NULL)
1182 return 0; 964 return 0;
1183 if (portp->tx.buf == (char *) NULL) 965 if (portp->tx.buf == NULL)
1184 return 0; 966 return 0;
1185 967
1186/* 968/*
@@ -1201,10 +983,10 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1201 stlen = len; 983 stlen = len;
1202 } 984 }
1203 985
1204 len = MIN(len, count); 986 len = min(len, (unsigned int)count);
1205 count = 0; 987 count = 0;
1206 while (len > 0) { 988 while (len > 0) {
1207 stlen = MIN(len, stlen); 989 stlen = min(len, stlen);
1208 memcpy(head, chbuf, stlen); 990 memcpy(head, chbuf, stlen);
1209 len -= stlen; 991 len -= stlen;
1210 chbuf += stlen; 992 chbuf += stlen;
@@ -1227,20 +1009,18 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1227 1009
1228static void stl_putchar(struct tty_struct *tty, unsigned char ch) 1010static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1229{ 1011{
1230 stlport_t *portp; 1012 struct stlport *portp;
1231 unsigned int len; 1013 unsigned int len;
1232 char *head, *tail; 1014 char *head, *tail;
1233 1015
1234#ifdef DEBUG 1016 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1235 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1236#endif
1237 1017
1238 if (tty == (struct tty_struct *) NULL) 1018 if (tty == NULL)
1239 return; 1019 return;
1240 portp = tty->driver_data; 1020 portp = tty->driver_data;
1241 if (portp == (stlport_t *) NULL) 1021 if (portp == NULL)
1242 return; 1022 return;
1243 if (portp->tx.buf == (char *) NULL) 1023 if (portp->tx.buf == NULL)
1244 return; 1024 return;
1245 1025
1246 head = portp->tx.head; 1026 head = portp->tx.head;
@@ -1267,18 +1047,16 @@ static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1267 1047
1268static void stl_flushchars(struct tty_struct *tty) 1048static void stl_flushchars(struct tty_struct *tty)
1269{ 1049{
1270 stlport_t *portp; 1050 struct stlport *portp;
1271 1051
1272#ifdef DEBUG 1052 pr_debug("stl_flushchars(tty=%p)\n", tty);
1273 printk("stl_flushchars(tty=%x)\n", (int) tty);
1274#endif
1275 1053
1276 if (tty == (struct tty_struct *) NULL) 1054 if (tty == NULL)
1277 return; 1055 return;
1278 portp = tty->driver_data; 1056 portp = tty->driver_data;
1279 if (portp == (stlport_t *) NULL) 1057 if (portp == NULL)
1280 return; 1058 return;
1281 if (portp->tx.buf == (char *) NULL) 1059 if (portp->tx.buf == NULL)
1282 return; 1060 return;
1283 1061
1284 stl_startrxtx(portp, -1, 1); 1062 stl_startrxtx(portp, -1, 1);
@@ -1288,24 +1066,22 @@ static void stl_flushchars(struct tty_struct *tty)
1288 1066
1289static int stl_writeroom(struct tty_struct *tty) 1067static int stl_writeroom(struct tty_struct *tty)
1290{ 1068{
1291 stlport_t *portp; 1069 struct stlport *portp;
1292 char *head, *tail; 1070 char *head, *tail;
1293 1071
1294#ifdef DEBUG 1072 pr_debug("stl_writeroom(tty=%p)\n", tty);
1295 printk("stl_writeroom(tty=%x)\n", (int) tty);
1296#endif
1297 1073
1298 if (tty == (struct tty_struct *) NULL) 1074 if (tty == NULL)
1299 return 0; 1075 return 0;
1300 portp = tty->driver_data; 1076 portp = tty->driver_data;
1301 if (portp == (stlport_t *) NULL) 1077 if (portp == NULL)
1302 return 0; 1078 return 0;
1303 if (portp->tx.buf == (char *) NULL) 1079 if (portp->tx.buf == NULL)
1304 return 0; 1080 return 0;
1305 1081
1306 head = portp->tx.head; 1082 head = portp->tx.head;
1307 tail = portp->tx.tail; 1083 tail = portp->tx.tail;
1308 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1)); 1084 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
1309} 1085}
1310 1086
1311/*****************************************************************************/ 1087/*****************************************************************************/
@@ -1321,20 +1097,18 @@ static int stl_writeroom(struct tty_struct *tty)
1321 1097
1322static int stl_charsinbuffer(struct tty_struct *tty) 1098static int stl_charsinbuffer(struct tty_struct *tty)
1323{ 1099{
1324 stlport_t *portp; 1100 struct stlport *portp;
1325 unsigned int size; 1101 unsigned int size;
1326 char *head, *tail; 1102 char *head, *tail;
1327 1103
1328#ifdef DEBUG 1104 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1329 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1330#endif
1331 1105
1332 if (tty == (struct tty_struct *) NULL) 1106 if (tty == NULL)
1333 return 0; 1107 return 0;
1334 portp = tty->driver_data; 1108 portp = tty->driver_data;
1335 if (portp == (stlport_t *) NULL) 1109 if (portp == NULL)
1336 return 0; 1110 return 0;
1337 if (portp->tx.buf == (char *) NULL) 1111 if (portp->tx.buf == NULL)
1338 return 0; 1112 return 0;
1339 1113
1340 head = portp->tx.head; 1114 head = portp->tx.head;
@@ -1351,14 +1125,12 @@ static int stl_charsinbuffer(struct tty_struct *tty)
1351 * Generate the serial struct info. 1125 * Generate the serial struct info.
1352 */ 1126 */
1353 1127
1354static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp) 1128static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1355{ 1129{
1356 struct serial_struct sio; 1130 struct serial_struct sio;
1357 stlbrd_t *brdp; 1131 struct stlbrd *brdp;
1358 1132
1359#ifdef DEBUG 1133 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1360 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1361#endif
1362 1134
1363 memset(&sio, 0, sizeof(struct serial_struct)); 1135 memset(&sio, 0, sizeof(struct serial_struct));
1364 sio.line = portp->portnr; 1136 sio.line = portp->portnr;
@@ -1378,7 +1150,7 @@ static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1378 } 1150 }
1379 1151
1380 brdp = stl_brds[portp->brdnr]; 1152 brdp = stl_brds[portp->brdnr];
1381 if (brdp != (stlbrd_t *) NULL) 1153 if (brdp != NULL)
1382 sio.irq = brdp->irq; 1154 sio.irq = brdp->irq;
1383 1155
1384 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0; 1156 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
@@ -1392,13 +1164,11 @@ static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1392 * just quietly ignore any requests to change irq, etc. 1164 * just quietly ignore any requests to change irq, etc.
1393 */ 1165 */
1394 1166
1395static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp) 1167static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1396{ 1168{
1397 struct serial_struct sio; 1169 struct serial_struct sio;
1398 1170
1399#ifdef DEBUG 1171 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1400 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1401#endif
1402 1172
1403 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1173 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1404 return -EFAULT; 1174 return -EFAULT;
@@ -1424,12 +1194,12 @@ static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1424 1194
1425static int stl_tiocmget(struct tty_struct *tty, struct file *file) 1195static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1426{ 1196{
1427 stlport_t *portp; 1197 struct stlport *portp;
1428 1198
1429 if (tty == (struct tty_struct *) NULL) 1199 if (tty == NULL)
1430 return -ENODEV; 1200 return -ENODEV;
1431 portp = tty->driver_data; 1201 portp = tty->driver_data;
1432 if (portp == (stlport_t *) NULL) 1202 if (portp == NULL)
1433 return -ENODEV; 1203 return -ENODEV;
1434 if (tty->flags & (1 << TTY_IO_ERROR)) 1204 if (tty->flags & (1 << TTY_IO_ERROR))
1435 return -EIO; 1205 return -EIO;
@@ -1440,13 +1210,13 @@ static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1440static int stl_tiocmset(struct tty_struct *tty, struct file *file, 1210static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1441 unsigned int set, unsigned int clear) 1211 unsigned int set, unsigned int clear)
1442{ 1212{
1443 stlport_t *portp; 1213 struct stlport *portp;
1444 int rts = -1, dtr = -1; 1214 int rts = -1, dtr = -1;
1445 1215
1446 if (tty == (struct tty_struct *) NULL) 1216 if (tty == NULL)
1447 return -ENODEV; 1217 return -ENODEV;
1448 portp = tty->driver_data; 1218 portp = tty->driver_data;
1449 if (portp == (stlport_t *) NULL) 1219 if (portp == NULL)
1450 return -ENODEV; 1220 return -ENODEV;
1451 if (tty->flags & (1 << TTY_IO_ERROR)) 1221 if (tty->flags & (1 << TTY_IO_ERROR))
1452 return -EIO; 1222 return -EIO;
@@ -1466,27 +1236,24 @@ static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1466 1236
1467static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1237static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1468{ 1238{
1469 stlport_t *portp; 1239 struct stlport *portp;
1470 unsigned int ival; 1240 unsigned int ival;
1471 int rc; 1241 int rc;
1472 void __user *argp = (void __user *)arg; 1242 void __user *argp = (void __user *)arg;
1473 1243
1474#ifdef DEBUG 1244 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1475 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n", 1245 arg);
1476 (int) tty, (int) file, cmd, (int) arg);
1477#endif
1478 1246
1479 if (tty == (struct tty_struct *) NULL) 1247 if (tty == NULL)
1480 return -ENODEV; 1248 return -ENODEV;
1481 portp = tty->driver_data; 1249 portp = tty->driver_data;
1482 if (portp == (stlport_t *) NULL) 1250 if (portp == NULL)
1483 return -ENODEV; 1251 return -ENODEV;
1484 1252
1485 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1253 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1486 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { 1254 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1487 if (tty->flags & (1 << TTY_IO_ERROR)) 1255 if (tty->flags & (1 << TTY_IO_ERROR))
1488 return -EIO; 1256 return -EIO;
1489 }
1490 1257
1491 rc = 0; 1258 rc = 0;
1492 1259
@@ -1531,19 +1298,37 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1531 1298
1532/*****************************************************************************/ 1299/*****************************************************************************/
1533 1300
1534static void stl_settermios(struct tty_struct *tty, struct termios *old) 1301/*
1302 * Start the transmitter again. Just turn TX interrupts back on.
1303 */
1304
1305static void stl_start(struct tty_struct *tty)
1535{ 1306{
1536 stlport_t *portp; 1307 struct stlport *portp;
1537 struct termios *tiosp;
1538 1308
1539#ifdef DEBUG 1309 pr_debug("stl_start(tty=%p)\n", tty);
1540 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1541#endif
1542 1310
1543 if (tty == (struct tty_struct *) NULL) 1311 if (tty == NULL)
1544 return; 1312 return;
1545 portp = tty->driver_data; 1313 portp = tty->driver_data;
1546 if (portp == (stlport_t *) NULL) 1314 if (portp == NULL)
1315 return;
1316 stl_startrxtx(portp, -1, 1);
1317}
1318
1319/*****************************************************************************/
1320
1321static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1322{
1323 struct stlport *portp;
1324 struct ktermios *tiosp;
1325
1326 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1327
1328 if (tty == NULL)
1329 return;
1330 portp = tty->driver_data;
1331 if (portp == NULL)
1547 return; 1332 return;
1548 1333
1549 tiosp = tty->termios; 1334 tiosp = tty->termios;
@@ -1571,16 +1356,14 @@ static void stl_settermios(struct tty_struct *tty, struct termios *old)
1571 1356
1572static void stl_throttle(struct tty_struct *tty) 1357static void stl_throttle(struct tty_struct *tty)
1573{ 1358{
1574 stlport_t *portp; 1359 struct stlport *portp;
1575 1360
1576#ifdef DEBUG 1361 pr_debug("stl_throttle(tty=%p)\n", tty);
1577 printk("stl_throttle(tty=%x)\n", (int) tty);
1578#endif
1579 1362
1580 if (tty == (struct tty_struct *) NULL) 1363 if (tty == NULL)
1581 return; 1364 return;
1582 portp = tty->driver_data; 1365 portp = tty->driver_data;
1583 if (portp == (stlport_t *) NULL) 1366 if (portp == NULL)
1584 return; 1367 return;
1585 stl_flowctrl(portp, 0); 1368 stl_flowctrl(portp, 0);
1586} 1369}
@@ -1593,16 +1376,14 @@ static void stl_throttle(struct tty_struct *tty)
1593 1376
1594static void stl_unthrottle(struct tty_struct *tty) 1377static void stl_unthrottle(struct tty_struct *tty)
1595{ 1378{
1596 stlport_t *portp; 1379 struct stlport *portp;
1597 1380
1598#ifdef DEBUG 1381 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1599 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1600#endif
1601 1382
1602 if (tty == (struct tty_struct *) NULL) 1383 if (tty == NULL)
1603 return; 1384 return;
1604 portp = tty->driver_data; 1385 portp = tty->driver_data;
1605 if (portp == (stlport_t *) NULL) 1386 if (portp == NULL)
1606 return; 1387 return;
1607 stl_flowctrl(portp, 1); 1388 stl_flowctrl(portp, 1);
1608} 1389}
@@ -1616,16 +1397,14 @@ static void stl_unthrottle(struct tty_struct *tty)
1616 1397
1617static void stl_stop(struct tty_struct *tty) 1398static void stl_stop(struct tty_struct *tty)
1618{ 1399{
1619 stlport_t *portp; 1400 struct stlport *portp;
1620 1401
1621#ifdef DEBUG 1402 pr_debug("stl_stop(tty=%p)\n", tty);
1622 printk("stl_stop(tty=%x)\n", (int) tty);
1623#endif
1624 1403
1625 if (tty == (struct tty_struct *) NULL) 1404 if (tty == NULL)
1626 return; 1405 return;
1627 portp = tty->driver_data; 1406 portp = tty->driver_data;
1628 if (portp == (stlport_t *) NULL) 1407 if (portp == NULL)
1629 return; 1408 return;
1630 stl_startrxtx(portp, -1, 0); 1409 stl_startrxtx(portp, -1, 0);
1631} 1410}
@@ -1633,28 +1412,6 @@ static void stl_stop(struct tty_struct *tty)
1633/*****************************************************************************/ 1412/*****************************************************************************/
1634 1413
1635/* 1414/*
1636 * Start the transmitter again. Just turn TX interrupts back on.
1637 */
1638
1639static void stl_start(struct tty_struct *tty)
1640{
1641 stlport_t *portp;
1642
1643#ifdef DEBUG
1644 printk("stl_start(tty=%x)\n", (int) tty);
1645#endif
1646
1647 if (tty == (struct tty_struct *) NULL)
1648 return;
1649 portp = tty->driver_data;
1650 if (portp == (stlport_t *) NULL)
1651 return;
1652 stl_startrxtx(portp, -1, 1);
1653}
1654
1655/*****************************************************************************/
1656
1657/*
1658 * Hangup this port. This is pretty much like closing the port, only 1415 * Hangup this port. This is pretty much like closing the port, only
1659 * a little more brutal. No waiting for data to drain. Shutdown the 1416 * a little more brutal. No waiting for data to drain. Shutdown the
1660 * port and maybe drop signals. 1417 * port and maybe drop signals.
@@ -1662,16 +1419,14 @@ static void stl_start(struct tty_struct *tty)
1662 1419
1663static void stl_hangup(struct tty_struct *tty) 1420static void stl_hangup(struct tty_struct *tty)
1664{ 1421{
1665 stlport_t *portp; 1422 struct stlport *portp;
1666 1423
1667#ifdef DEBUG 1424 pr_debug("stl_hangup(tty=%p)\n", tty);
1668 printk("stl_hangup(tty=%x)\n", (int) tty);
1669#endif
1670 1425
1671 if (tty == (struct tty_struct *) NULL) 1426 if (tty == NULL)
1672 return; 1427 return;
1673 portp = tty->driver_data; 1428 portp = tty->driver_data;
1674 if (portp == (stlport_t *) NULL) 1429 if (portp == NULL)
1675 return; 1430 return;
1676 1431
1677 portp->flags &= ~ASYNC_INITIALIZED; 1432 portp->flags &= ~ASYNC_INITIALIZED;
@@ -1682,13 +1437,13 @@ static void stl_hangup(struct tty_struct *tty)
1682 stl_flushbuffer(tty); 1437 stl_flushbuffer(tty);
1683 portp->istate = 0; 1438 portp->istate = 0;
1684 set_bit(TTY_IO_ERROR, &tty->flags); 1439 set_bit(TTY_IO_ERROR, &tty->flags);
1685 if (portp->tx.buf != (char *) NULL) { 1440 if (portp->tx.buf != NULL) {
1686 kfree(portp->tx.buf); 1441 kfree(portp->tx.buf);
1687 portp->tx.buf = (char *) NULL; 1442 portp->tx.buf = NULL;
1688 portp->tx.head = (char *) NULL; 1443 portp->tx.head = NULL;
1689 portp->tx.tail = (char *) NULL; 1444 portp->tx.tail = NULL;
1690 } 1445 }
1691 portp->tty = (struct tty_struct *) NULL; 1446 portp->tty = NULL;
1692 portp->flags &= ~ASYNC_NORMAL_ACTIVE; 1447 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1693 portp->refcount = 0; 1448 portp->refcount = 0;
1694 wake_up_interruptible(&portp->open_wait); 1449 wake_up_interruptible(&portp->open_wait);
@@ -1696,38 +1451,16 @@ static void stl_hangup(struct tty_struct *tty)
1696 1451
1697/*****************************************************************************/ 1452/*****************************************************************************/
1698 1453
1699static void stl_flushbuffer(struct tty_struct *tty)
1700{
1701 stlport_t *portp;
1702
1703#ifdef DEBUG
1704 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1705#endif
1706
1707 if (tty == (struct tty_struct *) NULL)
1708 return;
1709 portp = tty->driver_data;
1710 if (portp == (stlport_t *) NULL)
1711 return;
1712
1713 stl_flush(portp);
1714 tty_wakeup(tty);
1715}
1716
1717/*****************************************************************************/
1718
1719static void stl_breakctl(struct tty_struct *tty, int state) 1454static void stl_breakctl(struct tty_struct *tty, int state)
1720{ 1455{
1721 stlport_t *portp; 1456 struct stlport *portp;
1722 1457
1723#ifdef DEBUG 1458 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1724 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1725#endif
1726 1459
1727 if (tty == (struct tty_struct *) NULL) 1460 if (tty == NULL)
1728 return; 1461 return;
1729 portp = tty->driver_data; 1462 portp = tty->driver_data;
1730 if (portp == (stlport_t *) NULL) 1463 if (portp == NULL)
1731 return; 1464 return;
1732 1465
1733 stl_sendbreak(portp, ((state == -1) ? 1 : 2)); 1466 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
@@ -1735,48 +1468,16 @@ static void stl_breakctl(struct tty_struct *tty, int state)
1735 1468
1736/*****************************************************************************/ 1469/*****************************************************************************/
1737 1470
1738static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1739{
1740 stlport_t *portp;
1741 unsigned long tend;
1742
1743#ifdef DEBUG
1744 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1745#endif
1746
1747 if (tty == (struct tty_struct *) NULL)
1748 return;
1749 portp = tty->driver_data;
1750 if (portp == (stlport_t *) NULL)
1751 return;
1752
1753 if (timeout == 0)
1754 timeout = HZ;
1755 tend = jiffies + timeout;
1756
1757 while (stl_datastate(portp)) {
1758 if (signal_pending(current))
1759 break;
1760 msleep_interruptible(20);
1761 if (time_after_eq(jiffies, tend))
1762 break;
1763 }
1764}
1765
1766/*****************************************************************************/
1767
1768static void stl_sendxchar(struct tty_struct *tty, char ch) 1471static void stl_sendxchar(struct tty_struct *tty, char ch)
1769{ 1472{
1770 stlport_t *portp; 1473 struct stlport *portp;
1771 1474
1772#ifdef DEBUG 1475 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1773 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1774#endif
1775 1476
1776 if (tty == (struct tty_struct *) NULL) 1477 if (tty == NULL)
1777 return; 1478 return;
1778 portp = tty->driver_data; 1479 portp = tty->driver_data;
1779 if (portp == (stlport_t *) NULL) 1480 if (portp == NULL)
1780 return; 1481 return;
1781 1482
1782 if (ch == STOP_CHAR(tty)) 1483 if (ch == STOP_CHAR(tty))
@@ -1797,7 +1498,7 @@ static void stl_sendxchar(struct tty_struct *tty, char ch)
1797 * short then padded with spaces). 1498 * short then padded with spaces).
1798 */ 1499 */
1799 1500
1800static int stl_portinfo(stlport_t *portp, int portnr, char *pos) 1501static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1801{ 1502{
1802 char *sp; 1503 char *sp;
1803 int sigs, cnt; 1504 int sigs, cnt;
@@ -1826,7 +1527,7 @@ static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1826 *sp = ' '; 1527 *sp = ' ';
1827 sp += cnt; 1528 sp += cnt;
1828 1529
1829 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++) 1530 for (cnt = sp - pos; cnt < (MAXLINE - 1); cnt++)
1830 *sp++ = ' '; 1531 *sp++ = ' ';
1831 if (cnt >= MAXLINE) 1532 if (cnt >= MAXLINE)
1832 pos[(MAXLINE - 2)] = '+'; 1533 pos[(MAXLINE - 2)] = '+';
@@ -1843,18 +1544,15 @@ static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1843 1544
1844static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 1545static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1845{ 1546{
1846 stlbrd_t *brdp; 1547 struct stlbrd *brdp;
1847 stlpanel_t *panelp; 1548 struct stlpanel *panelp;
1848 stlport_t *portp; 1549 struct stlport *portp;
1849 int brdnr, panelnr, portnr, totalport; 1550 unsigned int brdnr, panelnr, portnr;
1850 int curoff, maxoff; 1551 int totalport, curoff, maxoff;
1851 char *pos; 1552 char *pos;
1852 1553
1853#ifdef DEBUG 1554 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1854 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x," 1555 "data=%p\n", page, start, off, count, eof, data);
1855 "data=%x\n", (int) page, (int) start, (int) off, count,
1856 (int) eof, (int) data);
1857#endif
1858 1556
1859 pos = page; 1557 pos = page;
1860 totalport = 0; 1558 totalport = 0;
@@ -1873,9 +1571,9 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1873 * We scan through for each board, panel and port. The offset is 1571 * We scan through for each board, panel and port. The offset is
1874 * calculated on the fly, and irrelevant ports are skipped. 1572 * calculated on the fly, and irrelevant ports are skipped.
1875 */ 1573 */
1876 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) { 1574 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1877 brdp = stl_brds[brdnr]; 1575 brdp = stl_brds[brdnr];
1878 if (brdp == (stlbrd_t *) NULL) 1576 if (brdp == NULL)
1879 continue; 1577 continue;
1880 if (brdp->state == 0) 1578 if (brdp->state == 0)
1881 continue; 1579 continue;
@@ -1887,9 +1585,9 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1887 } 1585 }
1888 1586
1889 totalport = brdnr * STL_MAXPORTS; 1587 totalport = brdnr * STL_MAXPORTS;
1890 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) { 1588 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1891 panelp = brdp->panels[panelnr]; 1589 panelp = brdp->panels[panelnr];
1892 if (panelp == (stlpanel_t *) NULL) 1590 if (panelp == NULL)
1893 continue; 1591 continue;
1894 1592
1895 maxoff = curoff + (panelp->nrports * MAXLINE); 1593 maxoff = curoff + (panelp->nrports * MAXLINE);
@@ -1899,10 +1597,10 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1899 continue; 1597 continue;
1900 } 1598 }
1901 1599
1902 for (portnr = 0; (portnr < panelp->nrports); portnr++, 1600 for (portnr = 0; portnr < panelp->nrports; portnr++,
1903 totalport++) { 1601 totalport++) {
1904 portp = panelp->ports[portnr]; 1602 portp = panelp->ports[portnr];
1905 if (portp == (stlport_t *) NULL) 1603 if (portp == NULL)
1906 continue; 1604 continue;
1907 if (off >= (curoff += MAXLINE)) 1605 if (off >= (curoff += MAXLINE))
1908 continue; 1606 continue;
@@ -1917,7 +1615,7 @@ static int stl_readproc(char *page, char **start, off_t off, int count, int *eof
1917 1615
1918stl_readdone: 1616stl_readdone:
1919 *start = page; 1617 *start = page;
1920 return (pos - page); 1618 return pos - page;
1921} 1619}
1922 1620
1923/*****************************************************************************/ 1621/*****************************************************************************/
@@ -1929,11 +1627,9 @@ stl_readdone:
1929 1627
1930static irqreturn_t stl_intr(int irq, void *dev_id) 1628static irqreturn_t stl_intr(int irq, void *dev_id)
1931{ 1629{
1932 stlbrd_t *brdp = (stlbrd_t *) dev_id; 1630 struct stlbrd *brdp = dev_id;
1933 1631
1934#ifdef DEBUG 1632 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1935 printk("stl_intr(brdp=%x,irq=%d)\n", (int) brdp, irq);
1936#endif
1937 1633
1938 return IRQ_RETVAL((* brdp->isr)(brdp)); 1634 return IRQ_RETVAL((* brdp->isr)(brdp));
1939} 1635}
@@ -1944,9 +1640,9 @@ static irqreturn_t stl_intr(int irq, void *dev_id)
1944 * Interrupt service routine for EasyIO board types. 1640 * Interrupt service routine for EasyIO board types.
1945 */ 1641 */
1946 1642
1947static int stl_eiointr(stlbrd_t *brdp) 1643static int stl_eiointr(struct stlbrd *brdp)
1948{ 1644{
1949 stlpanel_t *panelp; 1645 struct stlpanel *panelp;
1950 unsigned int iobase; 1646 unsigned int iobase;
1951 int handled = 0; 1647 int handled = 0;
1952 1648
@@ -1967,18 +1663,17 @@ static int stl_eiointr(stlbrd_t *brdp)
1967 * Interrupt service routine for ECH-AT board types. 1663 * Interrupt service routine for ECH-AT board types.
1968 */ 1664 */
1969 1665
1970static int stl_echatintr(stlbrd_t *brdp) 1666static int stl_echatintr(struct stlbrd *brdp)
1971{ 1667{
1972 stlpanel_t *panelp; 1668 struct stlpanel *panelp;
1973 unsigned int ioaddr; 1669 unsigned int ioaddr, bnknr;
1974 int bnknr;
1975 int handled = 0; 1670 int handled = 0;
1976 1671
1977 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); 1672 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1978 1673
1979 while (inb(brdp->iostatus) & ECH_INTRPEND) { 1674 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1980 handled = 1; 1675 handled = 1;
1981 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1676 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1982 ioaddr = brdp->bnkstataddr[bnknr]; 1677 ioaddr = brdp->bnkstataddr[bnknr];
1983 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1678 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1984 panelp = brdp->bnk2panel[bnknr]; 1679 panelp = brdp->bnk2panel[bnknr];
@@ -1998,16 +1693,15 @@ static int stl_echatintr(stlbrd_t *brdp)
1998 * Interrupt service routine for ECH-MCA board types. 1693 * Interrupt service routine for ECH-MCA board types.
1999 */ 1694 */
2000 1695
2001static int stl_echmcaintr(stlbrd_t *brdp) 1696static int stl_echmcaintr(struct stlbrd *brdp)
2002{ 1697{
2003 stlpanel_t *panelp; 1698 struct stlpanel *panelp;
2004 unsigned int ioaddr; 1699 unsigned int ioaddr, bnknr;
2005 int bnknr;
2006 int handled = 0; 1700 int handled = 0;
2007 1701
2008 while (inb(brdp->iostatus) & ECH_INTRPEND) { 1702 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2009 handled = 1; 1703 handled = 1;
2010 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1704 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2011 ioaddr = brdp->bnkstataddr[bnknr]; 1705 ioaddr = brdp->bnkstataddr[bnknr];
2012 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1706 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2013 panelp = brdp->bnk2panel[bnknr]; 1707 panelp = brdp->bnk2panel[bnknr];
@@ -2024,16 +1718,15 @@ static int stl_echmcaintr(stlbrd_t *brdp)
2024 * Interrupt service routine for ECH-PCI board types. 1718 * Interrupt service routine for ECH-PCI board types.
2025 */ 1719 */
2026 1720
2027static int stl_echpciintr(stlbrd_t *brdp) 1721static int stl_echpciintr(struct stlbrd *brdp)
2028{ 1722{
2029 stlpanel_t *panelp; 1723 struct stlpanel *panelp;
2030 unsigned int ioaddr; 1724 unsigned int ioaddr, bnknr, recheck;
2031 int bnknr, recheck;
2032 int handled = 0; 1725 int handled = 0;
2033 1726
2034 while (1) { 1727 while (1) {
2035 recheck = 0; 1728 recheck = 0;
2036 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1729 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2037 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl); 1730 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2038 ioaddr = brdp->bnkstataddr[bnknr]; 1731 ioaddr = brdp->bnkstataddr[bnknr];
2039 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1732 if (inb(ioaddr) & ECH_PNLINTRPEND) {
@@ -2055,16 +1748,15 @@ static int stl_echpciintr(stlbrd_t *brdp)
2055 * Interrupt service routine for ECH-8/64-PCI board types. 1748 * Interrupt service routine for ECH-8/64-PCI board types.
2056 */ 1749 */
2057 1750
2058static int stl_echpci64intr(stlbrd_t *brdp) 1751static int stl_echpci64intr(struct stlbrd *brdp)
2059{ 1752{
2060 stlpanel_t *panelp; 1753 struct stlpanel *panelp;
2061 unsigned int ioaddr; 1754 unsigned int ioaddr, bnknr;
2062 int bnknr;
2063 int handled = 0; 1755 int handled = 0;
2064 1756
2065 while (inb(brdp->ioctrl) & 0x1) { 1757 while (inb(brdp->ioctrl) & 0x1) {
2066 handled = 1; 1758 handled = 1;
2067 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) { 1759 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
2068 ioaddr = brdp->bnkstataddr[bnknr]; 1760 ioaddr = brdp->bnkstataddr[bnknr];
2069 if (inb(ioaddr) & ECH_PNLINTRPEND) { 1761 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2070 panelp = brdp->bnk2panel[bnknr]; 1762 panelp = brdp->bnk2panel[bnknr];
@@ -2083,35 +1775,32 @@ static int stl_echpci64intr(stlbrd_t *brdp)
2083 */ 1775 */
2084static void stl_offintr(struct work_struct *work) 1776static void stl_offintr(struct work_struct *work)
2085{ 1777{
2086 stlport_t *portp = container_of(work, stlport_t, tqueue); 1778 struct stlport *portp = container_of(work, struct stlport, tqueue);
2087 struct tty_struct *tty; 1779 struct tty_struct *tty;
2088 unsigned int oldsigs; 1780 unsigned int oldsigs;
2089 1781
2090#ifdef DEBUG 1782 pr_debug("stl_offintr(portp=%p)\n", portp);
2091 printk("stl_offintr(portp=%x)\n", (int) portp);
2092#endif
2093 1783
2094 if (portp == (stlport_t *) NULL) 1784 if (portp == NULL)
2095 return; 1785 return;
2096 1786
2097 tty = portp->tty; 1787 tty = portp->tty;
2098 if (tty == (struct tty_struct *) NULL) 1788 if (tty == NULL)
2099 return; 1789 return;
2100 1790
2101 lock_kernel(); 1791 lock_kernel();
2102 if (test_bit(ASYI_TXLOW, &portp->istate)) { 1792 if (test_bit(ASYI_TXLOW, &portp->istate))
2103 tty_wakeup(tty); 1793 tty_wakeup(tty);
2104 } 1794
2105 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) { 1795 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2106 clear_bit(ASYI_DCDCHANGE, &portp->istate); 1796 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2107 oldsigs = portp->sigs; 1797 oldsigs = portp->sigs;
2108 portp->sigs = stl_getsignals(portp); 1798 portp->sigs = stl_getsignals(portp);
2109 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0)) 1799 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2110 wake_up_interruptible(&portp->open_wait); 1800 wake_up_interruptible(&portp->open_wait);
2111 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) { 1801 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
2112 if (portp->flags & ASYNC_CHECK_CD) 1802 if (portp->flags & ASYNC_CHECK_CD)
2113 tty_hangup(tty); /* FIXME: module removal race here - AKPM */ 1803 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2114 }
2115 } 1804 }
2116 unlock_kernel(); 1805 unlock_kernel();
2117} 1806}
@@ -2122,14 +1811,13 @@ static void stl_offintr(struct work_struct *work)
2122 * Initialize all the ports on a panel. 1811 * Initialize all the ports on a panel.
2123 */ 1812 */
2124 1813
2125static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp) 1814static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
2126{ 1815{
2127 stlport_t *portp; 1816 struct stlport *portp;
2128 int chipmask, i; 1817 unsigned int i;
1818 int chipmask;
2129 1819
2130#ifdef DEBUG 1820 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
2131 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2132#endif
2133 1821
2134 chipmask = stl_panelinit(brdp, panelp); 1822 chipmask = stl_panelinit(brdp, panelp);
2135 1823
@@ -2137,11 +1825,11 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2137 * All UART's are initialized (if found!). Now go through and setup 1825 * All UART's are initialized (if found!). Now go through and setup
2138 * each ports data structures. 1826 * each ports data structures.
2139 */ 1827 */
2140 for (i = 0; (i < panelp->nrports); i++) { 1828 for (i = 0; i < panelp->nrports; i++) {
2141 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL); 1829 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
2142 if (!portp) { 1830 if (!portp) {
2143 printk("STALLION: failed to allocate memory " 1831 printk("STALLION: failed to allocate memory "
2144 "(size=%Zd)\n", sizeof(stlport_t)); 1832 "(size=%Zd)\n", sizeof(struct stlport));
2145 break; 1833 break;
2146 } 1834 }
2147 1835
@@ -2164,7 +1852,30 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2164 stl_portinit(brdp, panelp, portp); 1852 stl_portinit(brdp, panelp, portp);
2165 } 1853 }
2166 1854
2167 return(0); 1855 return 0;
1856}
1857
1858static void stl_cleanup_panels(struct stlbrd *brdp)
1859{
1860 struct stlpanel *panelp;
1861 struct stlport *portp;
1862 unsigned int j, k;
1863
1864 for (j = 0; j < STL_MAXPANELS; j++) {
1865 panelp = brdp->panels[j];
1866 if (panelp == NULL)
1867 continue;
1868 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1869 portp = panelp->ports[k];
1870 if (portp == NULL)
1871 continue;
1872 if (portp->tty != NULL)
1873 stl_hangup(portp->tty);
1874 kfree(portp->tx.buf);
1875 kfree(portp);
1876 }
1877 kfree(panelp);
1878 }
2168} 1879}
2169 1880
2170/*****************************************************************************/ 1881/*****************************************************************************/
@@ -2173,16 +1884,14 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2173 * Try to find and initialize an EasyIO board. 1884 * Try to find and initialize an EasyIO board.
2174 */ 1885 */
2175 1886
2176static inline int stl_initeio(stlbrd_t *brdp) 1887static int __devinit stl_initeio(struct stlbrd *brdp)
2177{ 1888{
2178 stlpanel_t *panelp; 1889 struct stlpanel *panelp;
2179 unsigned int status; 1890 unsigned int status;
2180 char *name; 1891 char *name;
2181 int rc; 1892 int retval;
2182 1893
2183#ifdef DEBUG 1894 pr_debug("stl_initeio(brdp=%p)\n", brdp);
2184 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2185#endif
2186 1895
2187 brdp->ioctrl = brdp->ioaddr1 + 1; 1896 brdp->ioctrl = brdp->ioaddr1 + 1;
2188 brdp->iostatus = brdp->ioaddr1 + 2; 1897 brdp->iostatus = brdp->ioaddr1 + 2;
@@ -2207,18 +1916,20 @@ static inline int stl_initeio(stlbrd_t *brdp)
2207 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 1916 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2208 printk("STALLION: invalid irq=%d for brd=%d\n", 1917 printk("STALLION: invalid irq=%d for brd=%d\n",
2209 brdp->irq, brdp->brdnr); 1918 brdp->irq, brdp->brdnr);
2210 return(-EINVAL); 1919 retval = -EINVAL;
1920 goto err;
2211 } 1921 }
2212 outb((stl_vecmap[brdp->irq] | EIO_0WS | 1922 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2213 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)), 1923 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2214 brdp->ioctrl); 1924 brdp->ioctrl);
2215 } 1925 }
2216 1926
1927 retval = -EBUSY;
2217 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { 1928 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2218 printk(KERN_WARNING "STALLION: Warning, board %d I/O address " 1929 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2219 "%x conflicts with another device\n", brdp->brdnr, 1930 "%x conflicts with another device\n", brdp->brdnr,
2220 brdp->ioaddr1); 1931 brdp->ioaddr1);
2221 return(-EBUSY); 1932 goto err;
2222 } 1933 }
2223 1934
2224 if (brdp->iosize2 > 0) 1935 if (brdp->iosize2 > 0)
@@ -2229,8 +1940,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2229 printk(KERN_WARNING "STALLION: Warning, also " 1940 printk(KERN_WARNING "STALLION: Warning, also "
2230 "releasing board %d I/O address %x \n", 1941 "releasing board %d I/O address %x \n",
2231 brdp->brdnr, brdp->ioaddr1); 1942 brdp->brdnr, brdp->ioaddr1);
2232 release_region(brdp->ioaddr1, brdp->iosize1); 1943 goto err_rel1;
2233 return(-EBUSY);
2234 } 1944 }
2235 1945
2236/* 1946/*
@@ -2239,6 +1949,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2239 brdp->clk = CD1400_CLK; 1949 brdp->clk = CD1400_CLK;
2240 brdp->isr = stl_eiointr; 1950 brdp->isr = stl_eiointr;
2241 1951
1952 retval = -ENODEV;
2242 switch (status & EIO_IDBITMASK) { 1953 switch (status & EIO_IDBITMASK) {
2243 case EIO_8PORTM: 1954 case EIO_8PORTM:
2244 brdp->clk = CD1400_CLK8M; 1955 brdp->clk = CD1400_CLK8M;
@@ -2262,11 +1973,11 @@ static inline int stl_initeio(stlbrd_t *brdp)
2262 brdp->nrports = 16; 1973 brdp->nrports = 16;
2263 break; 1974 break;
2264 default: 1975 default:
2265 return(-ENODEV); 1976 goto err_rel2;
2266 } 1977 }
2267 break; 1978 break;
2268 default: 1979 default:
2269 return(-ENODEV); 1980 goto err_rel2;
2270 } 1981 }
2271 1982
2272/* 1983/*
@@ -2274,11 +1985,12 @@ static inline int stl_initeio(stlbrd_t *brdp)
2274 * can complete the setup. 1985 * can complete the setup.
2275 */ 1986 */
2276 1987
2277 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 1988 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2278 if (!panelp) { 1989 if (!panelp) {
2279 printk(KERN_WARNING "STALLION: failed to allocate memory " 1990 printk(KERN_WARNING "STALLION: failed to allocate memory "
2280 "(size=%Zd)\n", sizeof(stlpanel_t)); 1991 "(size=%Zd)\n", sizeof(struct stlpanel));
2281 return -ENOMEM; 1992 retval = -ENOMEM;
1993 goto err_rel2;
2282 } 1994 }
2283 1995
2284 panelp->magic = STL_PANELMAGIC; 1996 panelp->magic = STL_PANELMAGIC;
@@ -2288,10 +2000,10 @@ static inline int stl_initeio(stlbrd_t *brdp)
2288 panelp->iobase = brdp->ioaddr1; 2000 panelp->iobase = brdp->ioaddr1;
2289 panelp->hwid = status; 2001 panelp->hwid = status;
2290 if ((status & EIO_IDBITMASK) == EIO_MK3) { 2002 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2291 panelp->uartp = (void *) &stl_sc26198uart; 2003 panelp->uartp = &stl_sc26198uart;
2292 panelp->isr = stl_sc26198intr; 2004 panelp->isr = stl_sc26198intr;
2293 } else { 2005 } else {
2294 panelp->uartp = (void *) &stl_cd1400uart; 2006 panelp->uartp = &stl_cd1400uart;
2295 panelp->isr = stl_cd1400eiointr; 2007 panelp->isr = stl_cd1400eiointr;
2296 } 2008 }
2297 2009
@@ -2302,11 +2014,20 @@ static inline int stl_initeio(stlbrd_t *brdp)
2302 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { 2014 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2303 printk("STALLION: failed to register interrupt " 2015 printk("STALLION: failed to register interrupt "
2304 "routine for %s irq=%d\n", name, brdp->irq); 2016 "routine for %s irq=%d\n", name, brdp->irq);
2305 rc = -ENODEV; 2017 retval = -ENODEV;
2306 } else { 2018 goto err_fr;
2307 rc = 0;
2308 } 2019 }
2309 return rc; 2020
2021 return 0;
2022err_fr:
2023 stl_cleanup_panels(brdp);
2024err_rel2:
2025 if (brdp->iosize2 > 0)
2026 release_region(brdp->ioaddr2, brdp->iosize2);
2027err_rel1:
2028 release_region(brdp->ioaddr1, brdp->iosize1);
2029err:
2030 return retval;
2310} 2031}
2311 2032
2312/*****************************************************************************/ 2033/*****************************************************************************/
@@ -2316,16 +2037,14 @@ static inline int stl_initeio(stlbrd_t *brdp)
2316 * dealing with all types of ECH board. 2037 * dealing with all types of ECH board.
2317 */ 2038 */
2318 2039
2319static inline int stl_initech(stlbrd_t *brdp) 2040static int __devinit stl_initech(struct stlbrd *brdp)
2320{ 2041{
2321 stlpanel_t *panelp; 2042 struct stlpanel *panelp;
2322 unsigned int status, nxtid, ioaddr, conflict; 2043 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
2323 int panelnr, banknr, i; 2044 int retval;
2324 char *name; 2045 char *name;
2325 2046
2326#ifdef DEBUG 2047 pr_debug("stl_initech(brdp=%p)\n", brdp);
2327 printk("stl_initech(brdp=%x)\n", (int) brdp);
2328#endif
2329 2048
2330 status = 0; 2049 status = 0;
2331 conflict = 0; 2050 conflict = 0;
@@ -2342,20 +2061,23 @@ static inline int stl_initech(stlbrd_t *brdp)
2342 brdp->ioctrl = brdp->ioaddr1 + 1; 2061 brdp->ioctrl = brdp->ioaddr1 + 1;
2343 brdp->iostatus = brdp->ioaddr1 + 1; 2062 brdp->iostatus = brdp->ioaddr1 + 1;
2344 status = inb(brdp->iostatus); 2063 status = inb(brdp->iostatus);
2345 if ((status & ECH_IDBITMASK) != ECH_ID) 2064 if ((status & ECH_IDBITMASK) != ECH_ID) {
2346 return(-ENODEV); 2065 retval = -ENODEV;
2066 goto err;
2067 }
2347 if ((brdp->irq < 0) || (brdp->irq > 15) || 2068 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2348 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 2069 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2349 printk("STALLION: invalid irq=%d for brd=%d\n", 2070 printk("STALLION: invalid irq=%d for brd=%d\n",
2350 brdp->irq, brdp->brdnr); 2071 brdp->irq, brdp->brdnr);
2351 return(-EINVAL); 2072 retval = -EINVAL;
2073 goto err;
2352 } 2074 }
2353 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1); 2075 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2354 status |= (stl_vecmap[brdp->irq] << 1); 2076 status |= (stl_vecmap[brdp->irq] << 1);
2355 outb((status | ECH_BRDRESET), brdp->ioaddr1); 2077 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2356 brdp->ioctrlval = ECH_INTENABLE | 2078 brdp->ioctrlval = ECH_INTENABLE |
2357 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE); 2079 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2358 for (i = 0; (i < 10); i++) 2080 for (i = 0; i < 10; i++)
2359 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl); 2081 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2360 brdp->iosize1 = 2; 2082 brdp->iosize1 = 2;
2361 brdp->iosize2 = 32; 2083 brdp->iosize2 = 32;
@@ -2368,13 +2090,16 @@ static inline int stl_initech(stlbrd_t *brdp)
2368 brdp->ioctrl = brdp->ioaddr1 + 0x20; 2090 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2369 brdp->iostatus = brdp->ioctrl; 2091 brdp->iostatus = brdp->ioctrl;
2370 status = inb(brdp->iostatus); 2092 status = inb(brdp->iostatus);
2371 if ((status & ECH_IDBITMASK) != ECH_ID) 2093 if ((status & ECH_IDBITMASK) != ECH_ID) {
2372 return(-ENODEV); 2094 retval = -ENODEV;
2095 goto err;
2096 }
2373 if ((brdp->irq < 0) || (brdp->irq > 15) || 2097 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2374 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) { 2098 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2375 printk("STALLION: invalid irq=%d for brd=%d\n", 2099 printk("STALLION: invalid irq=%d for brd=%d\n",
2376 brdp->irq, brdp->brdnr); 2100 brdp->irq, brdp->brdnr);
2377 return(-EINVAL); 2101 retval = -EINVAL;
2102 goto err;
2378 } 2103 }
2379 outb(ECHMC_BRDRESET, brdp->ioctrl); 2104 outb(ECHMC_BRDRESET, brdp->ioctrl);
2380 outb(ECHMC_INTENABLE, brdp->ioctrl); 2105 outb(ECHMC_INTENABLE, brdp->ioctrl);
@@ -2401,19 +2126,20 @@ static inline int stl_initech(stlbrd_t *brdp)
2401 2126
2402 default: 2127 default:
2403 printk("STALLION: unknown board type=%d\n", brdp->brdtype); 2128 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2404 return(-EINVAL); 2129 retval = -EINVAL;
2405 break; 2130 goto err;
2406 } 2131 }
2407 2132
2408/* 2133/*
2409 * Check boards for possible IO address conflicts and return fail status 2134 * Check boards for possible IO address conflicts and return fail status
2410 * if an IO conflict found. 2135 * if an IO conflict found.
2411 */ 2136 */
2137 retval = -EBUSY;
2412 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) { 2138 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2413 printk(KERN_WARNING "STALLION: Warning, board %d I/O address " 2139 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2414 "%x conflicts with another device\n", brdp->brdnr, 2140 "%x conflicts with another device\n", brdp->brdnr,
2415 brdp->ioaddr1); 2141 brdp->ioaddr1);
2416 return(-EBUSY); 2142 goto err;
2417 } 2143 }
2418 2144
2419 if (brdp->iosize2 > 0) 2145 if (brdp->iosize2 > 0)
@@ -2424,8 +2150,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2424 printk(KERN_WARNING "STALLION: Warning, also " 2150 printk(KERN_WARNING "STALLION: Warning, also "
2425 "releasing board %d I/O address %x \n", 2151 "releasing board %d I/O address %x \n",
2426 brdp->brdnr, brdp->ioaddr1); 2152 brdp->brdnr, brdp->ioaddr1);
2427 release_region(brdp->ioaddr1, brdp->iosize1); 2153 goto err_rel1;
2428 return(-EBUSY);
2429 } 2154 }
2430 2155
2431/* 2156/*
@@ -2440,19 +2165,19 @@ static inline int stl_initech(stlbrd_t *brdp)
2440 panelnr = 0; 2165 panelnr = 0;
2441 nxtid = 0; 2166 nxtid = 0;
2442 2167
2443 for (i = 0; (i < STL_MAXPANELS); i++) { 2168 for (i = 0; i < STL_MAXPANELS; i++) {
2444 if (brdp->brdtype == BRD_ECHPCI) { 2169 if (brdp->brdtype == BRD_ECHPCI) {
2445 outb(nxtid, brdp->ioctrl); 2170 outb(nxtid, brdp->ioctrl);
2446 ioaddr = brdp->ioaddr2; 2171 ioaddr = brdp->ioaddr2;
2447 } 2172 }
2448 status = inb(ioaddr + ECH_PNLSTATUS); 2173 status = inb(ioaddr + ECH_PNLSTATUS);
2449 if ((status & ECH_PNLIDMASK) != nxtid) 2174 if ((status & ECH_PNLIDMASK) != nxtid)
2450 break; 2175 goto err_fr;
2451 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2176 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2452 if (!panelp) { 2177 if (!panelp) {
2453 printk("STALLION: failed to allocate memory " 2178 printk("STALLION: failed to allocate memory "
2454 "(size=%Zd)\n", sizeof(stlpanel_t)); 2179 "(size=%Zd)\n", sizeof(struct stlpanel));
2455 break; 2180 goto err_fr;
2456 } 2181 }
2457 panelp->magic = STL_PANELMAGIC; 2182 panelp->magic = STL_PANELMAGIC;
2458 panelp->brdnr = brdp->brdnr; 2183 panelp->brdnr = brdp->brdnr;
@@ -2465,7 +2190,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2465 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS; 2190 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2466 2191
2467 if (status & ECH_PNLXPID) { 2192 if (status & ECH_PNLXPID) {
2468 panelp->uartp = (void *) &stl_sc26198uart; 2193 panelp->uartp = &stl_sc26198uart;
2469 panelp->isr = stl_sc26198intr; 2194 panelp->isr = stl_sc26198intr;
2470 if (status & ECH_PNL16PORT) { 2195 if (status & ECH_PNL16PORT) {
2471 panelp->nrports = 16; 2196 panelp->nrports = 16;
@@ -2473,11 +2198,10 @@ static inline int stl_initech(stlbrd_t *brdp)
2473 brdp->bnkpageaddr[banknr] = nxtid; 2198 brdp->bnkpageaddr[banknr] = nxtid;
2474 brdp->bnkstataddr[banknr++] = ioaddr + 4 + 2199 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2475 ECH_PNLSTATUS; 2200 ECH_PNLSTATUS;
2476 } else { 2201 } else
2477 panelp->nrports = 8; 2202 panelp->nrports = 8;
2478 }
2479 } else { 2203 } else {
2480 panelp->uartp = (void *) &stl_cd1400uart; 2204 panelp->uartp = &stl_cd1400uart;
2481 panelp->isr = stl_cd1400echintr; 2205 panelp->isr = stl_cd1400echintr;
2482 if (status & ECH_PNL16PORT) { 2206 if (status & ECH_PNL16PORT) {
2483 panelp->nrports = 16; 2207 panelp->nrports = 16;
@@ -2500,7 +2224,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2500 brdp->panels[panelnr++] = panelp; 2224 brdp->panels[panelnr++] = panelp;
2501 if ((brdp->brdtype != BRD_ECHPCI) && 2225 if ((brdp->brdtype != BRD_ECHPCI) &&
2502 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) 2226 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2503 break; 2227 goto err_fr;
2504 } 2228 }
2505 2229
2506 brdp->nrpanels = panelnr; 2230 brdp->nrpanels = panelnr;
@@ -2512,12 +2236,19 @@ static inline int stl_initech(stlbrd_t *brdp)
2512 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) { 2236 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2513 printk("STALLION: failed to register interrupt " 2237 printk("STALLION: failed to register interrupt "
2514 "routine for %s irq=%d\n", name, brdp->irq); 2238 "routine for %s irq=%d\n", name, brdp->irq);
2515 i = -ENODEV; 2239 retval = -ENODEV;
2516 } else { 2240 goto err_fr;
2517 i = 0;
2518 } 2241 }
2519 2242
2520 return(i); 2243 return 0;
2244err_fr:
2245 stl_cleanup_panels(brdp);
2246 if (brdp->iosize2 > 0)
2247 release_region(brdp->ioaddr2, brdp->iosize2);
2248err_rel1:
2249 release_region(brdp->ioaddr1, brdp->iosize1);
2250err:
2251 return retval;
2521} 2252}
2522 2253
2523/*****************************************************************************/ 2254/*****************************************************************************/
@@ -2529,48 +2260,61 @@ static inline int stl_initech(stlbrd_t *brdp)
2529 * since the initial search and setup is very different. 2260 * since the initial search and setup is very different.
2530 */ 2261 */
2531 2262
2532static int __init stl_brdinit(stlbrd_t *brdp) 2263static int __devinit stl_brdinit(struct stlbrd *brdp)
2533{ 2264{
2534 int i; 2265 int i, retval;
2535 2266
2536#ifdef DEBUG 2267 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2537 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2538#endif
2539 2268
2540 switch (brdp->brdtype) { 2269 switch (brdp->brdtype) {
2541 case BRD_EASYIO: 2270 case BRD_EASYIO:
2542 case BRD_EASYIOPCI: 2271 case BRD_EASYIOPCI:
2543 stl_initeio(brdp); 2272 retval = stl_initeio(brdp);
2273 if (retval)
2274 goto err;
2544 break; 2275 break;
2545 case BRD_ECH: 2276 case BRD_ECH:
2546 case BRD_ECHMC: 2277 case BRD_ECHMC:
2547 case BRD_ECHPCI: 2278 case BRD_ECHPCI:
2548 case BRD_ECH64PCI: 2279 case BRD_ECH64PCI:
2549 stl_initech(brdp); 2280 retval = stl_initech(brdp);
2281 if (retval)
2282 goto err;
2550 break; 2283 break;
2551 default: 2284 default:
2552 printk("STALLION: board=%d is unknown board type=%d\n", 2285 printk("STALLION: board=%d is unknown board type=%d\n",
2553 brdp->brdnr, brdp->brdtype); 2286 brdp->brdnr, brdp->brdtype);
2554 return(ENODEV); 2287 retval = -ENODEV;
2288 goto err;
2555 } 2289 }
2556 2290
2557 stl_brds[brdp->brdnr] = brdp;
2558 if ((brdp->state & BRD_FOUND) == 0) { 2291 if ((brdp->state & BRD_FOUND) == 0) {
2559 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n", 2292 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2560 stl_brdnames[brdp->brdtype], brdp->brdnr, 2293 stl_brdnames[brdp->brdtype], brdp->brdnr,
2561 brdp->ioaddr1, brdp->irq); 2294 brdp->ioaddr1, brdp->irq);
2562 return(ENODEV); 2295 goto err_free;
2563 } 2296 }
2564 2297
2565 for (i = 0; (i < STL_MAXPANELS); i++) 2298 for (i = 0; i < STL_MAXPANELS; i++)
2566 if (brdp->panels[i] != (stlpanel_t *) NULL) 2299 if (brdp->panels[i] != NULL)
2567 stl_initports(brdp, brdp->panels[i]); 2300 stl_initports(brdp, brdp->panels[i]);
2568 2301
2569 printk("STALLION: %s found, board=%d io=%x irq=%d " 2302 printk("STALLION: %s found, board=%d io=%x irq=%d "
2570 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype], 2303 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2571 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels, 2304 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2572 brdp->nrports); 2305 brdp->nrports);
2573 return(0); 2306
2307 return 0;
2308err_free:
2309 free_irq(brdp->irq, brdp);
2310
2311 stl_cleanup_panels(brdp);
2312
2313 release_region(brdp->ioaddr1, brdp->iosize1);
2314 if (brdp->iosize2 > 0)
2315 release_region(brdp->ioaddr2, brdp->iosize2);
2316err:
2317 return retval;
2574} 2318}
2575 2319
2576/*****************************************************************************/ 2320/*****************************************************************************/
@@ -2579,59 +2323,62 @@ static int __init stl_brdinit(stlbrd_t *brdp)
2579 * Find the next available board number that is free. 2323 * Find the next available board number that is free.
2580 */ 2324 */
2581 2325
2582static inline int stl_getbrdnr(void) 2326static int __devinit stl_getbrdnr(void)
2583{ 2327{
2584 int i; 2328 unsigned int i;
2585 2329
2586 for (i = 0; (i < STL_MAXBRDS); i++) { 2330 for (i = 0; i < STL_MAXBRDS; i++)
2587 if (stl_brds[i] == (stlbrd_t *) NULL) { 2331 if (stl_brds[i] == NULL) {
2588 if (i >= stl_nrbrds) 2332 if (i >= stl_nrbrds)
2589 stl_nrbrds = i + 1; 2333 stl_nrbrds = i + 1;
2590 return(i); 2334 return i;
2591 } 2335 }
2592 } 2336
2593 return(-1); 2337 return -1;
2594} 2338}
2595 2339
2596/*****************************************************************************/ 2340/*****************************************************************************/
2597
2598#ifdef CONFIG_PCI
2599
2600/* 2341/*
2601 * We have a Stallion board. Allocate a board structure and 2342 * We have a Stallion board. Allocate a board structure and
2602 * initialize it. Read its IO and IRQ resources from PCI 2343 * initialize it. Read its IO and IRQ resources from PCI
2603 * configuration space. 2344 * configuration space.
2604 */ 2345 */
2605 2346
2606static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp) 2347static int __devinit stl_pciprobe(struct pci_dev *pdev,
2348 const struct pci_device_id *ent)
2607{ 2349{
2608 stlbrd_t *brdp; 2350 struct stlbrd *brdp;
2609 2351 unsigned int i, brdtype = ent->driver_data;
2610#ifdef DEBUG 2352 int brdnr, retval = -ENODEV;
2611 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype, 2353
2612 devp->bus->number, devp->devfn); 2354 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2613#endif 2355 goto err;
2614 2356
2615 if (pci_enable_device(devp)) 2357 dev_info(&pdev->dev, "please, report this to LKML: %x/%x/%x\n",
2616 return(-EIO); 2358 pdev->vendor, pdev->device, pdev->class);
2617 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL) 2359
2618 return(-ENOMEM); 2360 retval = pci_enable_device(pdev);
2619 if ((brdp->brdnr = stl_getbrdnr()) < 0) { 2361 if (retval)
2620 printk("STALLION: too many boards found, " 2362 goto err;
2363 brdp = stl_allocbrd();
2364 if (brdp == NULL) {
2365 retval = -ENOMEM;
2366 goto err;
2367 }
2368 mutex_lock(&stl_brdslock);
2369 brdnr = stl_getbrdnr();
2370 if (brdnr < 0) {
2371 dev_err(&pdev->dev, "too many boards found, "
2621 "maximum supported %d\n", STL_MAXBRDS); 2372 "maximum supported %d\n", STL_MAXBRDS);
2622 return(0); 2373 mutex_unlock(&stl_brdslock);
2374 goto err_fr;
2623 } 2375 }
2624 brdp->brdtype = brdtype; 2376 brdp->brdnr = (unsigned int)brdnr;
2377 stl_brds[brdp->brdnr] = brdp;
2378 mutex_unlock(&stl_brdslock);
2625 2379
2626/* 2380 brdp->brdtype = brdtype;
2627 * Different Stallion boards use the BAR registers in different ways, 2381 brdp->state |= STL_PROBED;
2628 * so set up io addresses based on board type.
2629 */
2630#ifdef DEBUG
2631 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2632 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2633 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2634#endif
2635 2382
2636/* 2383/*
2637 * We have all resources from the board, so let's setup the actual 2384 * We have all resources from the board, so let's setup the actual
@@ -2639,120 +2386,70 @@ static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2639 */ 2386 */
2640 switch (brdtype) { 2387 switch (brdtype) {
2641 case BRD_ECHPCI: 2388 case BRD_ECHPCI:
2642 brdp->ioaddr2 = pci_resource_start(devp, 0); 2389 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2643 brdp->ioaddr1 = pci_resource_start(devp, 1); 2390 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2644 break; 2391 break;
2645 case BRD_ECH64PCI: 2392 case BRD_ECH64PCI:
2646 brdp->ioaddr2 = pci_resource_start(devp, 2); 2393 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2647 brdp->ioaddr1 = pci_resource_start(devp, 1); 2394 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2648 break; 2395 break;
2649 case BRD_EASYIOPCI: 2396 case BRD_EASYIOPCI:
2650 brdp->ioaddr1 = pci_resource_start(devp, 2); 2397 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2651 brdp->ioaddr2 = pci_resource_start(devp, 1); 2398 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2652 break; 2399 break;
2653 default: 2400 default:
2654 printk("STALLION: unknown PCI board type=%d\n", brdtype); 2401 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2655 break; 2402 break;
2656 } 2403 }
2657 2404
2658 brdp->irq = devp->irq; 2405 brdp->irq = pdev->irq;
2659 stl_brdinit(brdp); 2406 retval = stl_brdinit(brdp);
2660 2407 if (retval)
2661 return(0); 2408 goto err_null;
2662}
2663
2664/*****************************************************************************/
2665
2666/*
2667 * Find all Stallion PCI boards that might be installed. Initialize each
2668 * one as it is found.
2669 */
2670
2671 2409
2672static inline int stl_findpcibrds(void) 2410 pci_set_drvdata(pdev, brdp);
2673{
2674 struct pci_dev *dev = NULL;
2675 int i, rc;
2676
2677#ifdef DEBUG
2678 printk("stl_findpcibrds()\n");
2679#endif
2680 2411
2681 for (i = 0; (i < stl_nrpcibrds); i++) 2412 for (i = 0; i < brdp->nrports; i++)
2682 while ((dev = pci_find_device(stl_pcibrds[i].vendid, 2413 tty_register_device(stl_serial,
2683 stl_pcibrds[i].devid, dev))) { 2414 brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2684
2685/*
2686 * Found a device on the PCI bus that has our vendor and
2687 * device ID. Need to check now that it is really us.
2688 */
2689 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2690 continue;
2691
2692 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2693 if (rc)
2694 return(rc);
2695 }
2696 2415
2697 return(0); 2416 return 0;
2417err_null:
2418 stl_brds[brdp->brdnr] = NULL;
2419err_fr:
2420 kfree(brdp);
2421err:
2422 return retval;
2698} 2423}
2699 2424
2700#endif 2425static void __devexit stl_pciremove(struct pci_dev *pdev)
2701
2702/*****************************************************************************/
2703
2704/*
2705 * Scan through all the boards in the configuration and see what we
2706 * can find. Handle EIO and the ECH boards a little differently here
2707 * since the initial search and setup is too different.
2708 */
2709
2710static inline int stl_initbrds(void)
2711{ 2426{
2712 stlbrd_t *brdp; 2427 struct stlbrd *brdp = pci_get_drvdata(pdev);
2713 stlconf_t *confp; 2428 unsigned int i;
2714 int i;
2715 2429
2716#ifdef DEBUG 2430 free_irq(brdp->irq, brdp);
2717 printk("stl_initbrds()\n");
2718#endif
2719 2431
2720 if (stl_nrbrds > STL_MAXBRDS) { 2432 stl_cleanup_panels(brdp);
2721 printk("STALLION: too many boards in configuration table, "
2722 "truncating to %d\n", STL_MAXBRDS);
2723 stl_nrbrds = STL_MAXBRDS;
2724 }
2725 2433
2726/* 2434 release_region(brdp->ioaddr1, brdp->iosize1);
2727 * Firstly scan the list of static boards configured. Allocate 2435 if (brdp->iosize2 > 0)
2728 * resources and initialize the boards as found. 2436 release_region(brdp->ioaddr2, brdp->iosize2);
2729 */
2730 for (i = 0; (i < stl_nrbrds); i++) {
2731 confp = &stl_brdconf[i];
2732 stl_parsebrd(confp, stl_brdsp[i]);
2733 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2734 return(-ENOMEM);
2735 brdp->brdnr = i;
2736 brdp->brdtype = confp->brdtype;
2737 brdp->ioaddr1 = confp->ioaddr1;
2738 brdp->ioaddr2 = confp->ioaddr2;
2739 brdp->irq = confp->irq;
2740 brdp->irqtype = confp->irqtype;
2741 stl_brdinit(brdp);
2742 }
2743 2437
2744/* 2438 for (i = 0; i < brdp->nrports; i++)
2745 * Find any dynamically supported boards. That is via module load 2439 tty_unregister_device(stl_serial,
2746 * line options or auto-detected on the PCI bus. 2440 brdp->brdnr * STL_MAXPORTS + i);
2747 */
2748 stl_argbrds();
2749#ifdef CONFIG_PCI
2750 stl_findpcibrds();
2751#endif
2752 2441
2753 return(0); 2442 stl_brds[brdp->brdnr] = NULL;
2443 kfree(brdp);
2754} 2444}
2755 2445
2446static struct pci_driver stl_pcidriver = {
2447 .name = "stallion",
2448 .id_table = stl_pcibrds,
2449 .probe = stl_pciprobe,
2450 .remove = __devexit_p(stl_pciremove)
2451};
2452
2756/*****************************************************************************/ 2453/*****************************************************************************/
2757 2454
2758/* 2455/*
@@ -2761,17 +2458,18 @@ static inline int stl_initbrds(void)
2761 2458
2762static int stl_getbrdstats(combrd_t __user *bp) 2459static int stl_getbrdstats(combrd_t __user *bp)
2763{ 2460{
2764 stlbrd_t *brdp; 2461 combrd_t stl_brdstats;
2765 stlpanel_t *panelp; 2462 struct stlbrd *brdp;
2766 int i; 2463 struct stlpanel *panelp;
2464 unsigned int i;
2767 2465
2768 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t))) 2466 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2769 return -EFAULT; 2467 return -EFAULT;
2770 if (stl_brdstats.brd >= STL_MAXBRDS) 2468 if (stl_brdstats.brd >= STL_MAXBRDS)
2771 return(-ENODEV); 2469 return -ENODEV;
2772 brdp = stl_brds[stl_brdstats.brd]; 2470 brdp = stl_brds[stl_brdstats.brd];
2773 if (brdp == (stlbrd_t *) NULL) 2471 if (brdp == NULL)
2774 return(-ENODEV); 2472 return -ENODEV;
2775 2473
2776 memset(&stl_brdstats, 0, sizeof(combrd_t)); 2474 memset(&stl_brdstats, 0, sizeof(combrd_t));
2777 stl_brdstats.brd = brdp->brdnr; 2475 stl_brdstats.brd = brdp->brdnr;
@@ -2783,7 +2481,7 @@ static int stl_getbrdstats(combrd_t __user *bp)
2783 stl_brdstats.irq = brdp->irq; 2481 stl_brdstats.irq = brdp->irq;
2784 stl_brdstats.nrpanels = brdp->nrpanels; 2482 stl_brdstats.nrpanels = brdp->nrpanels;
2785 stl_brdstats.nrports = brdp->nrports; 2483 stl_brdstats.nrports = brdp->nrports;
2786 for (i = 0; (i < brdp->nrpanels); i++) { 2484 for (i = 0; i < brdp->nrpanels; i++) {
2787 panelp = brdp->panels[i]; 2485 panelp = brdp->panels[i];
2788 stl_brdstats.panels[i].panel = i; 2486 stl_brdstats.panels[i].panel = i;
2789 stl_brdstats.panels[i].hwid = panelp->hwid; 2487 stl_brdstats.panels[i].hwid = panelp->hwid;
@@ -2799,24 +2497,24 @@ static int stl_getbrdstats(combrd_t __user *bp)
2799 * Resolve the referenced port number into a port struct pointer. 2497 * Resolve the referenced port number into a port struct pointer.
2800 */ 2498 */
2801 2499
2802static stlport_t *stl_getport(int brdnr, int panelnr, int portnr) 2500static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2803{ 2501{
2804 stlbrd_t *brdp; 2502 struct stlbrd *brdp;
2805 stlpanel_t *panelp; 2503 struct stlpanel *panelp;
2806 2504
2807 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS)) 2505 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2808 return((stlport_t *) NULL); 2506 return NULL;
2809 brdp = stl_brds[brdnr]; 2507 brdp = stl_brds[brdnr];
2810 if (brdp == (stlbrd_t *) NULL) 2508 if (brdp == NULL)
2811 return((stlport_t *) NULL); 2509 return NULL;
2812 if ((panelnr < 0) || (panelnr >= brdp->nrpanels)) 2510 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2813 return((stlport_t *) NULL); 2511 return NULL;
2814 panelp = brdp->panels[panelnr]; 2512 panelp = brdp->panels[panelnr];
2815 if (panelp == (stlpanel_t *) NULL) 2513 if (panelp == NULL)
2816 return((stlport_t *) NULL); 2514 return NULL;
2817 if ((portnr < 0) || (portnr >= panelp->nrports)) 2515 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2818 return((stlport_t *) NULL); 2516 return NULL;
2819 return(panelp->ports[portnr]); 2517 return panelp->ports[portnr];
2820} 2518}
2821 2519
2822/*****************************************************************************/ 2520/*****************************************************************************/
@@ -2827,8 +2525,9 @@ static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2827 * what port to get stats for (used through board control device). 2525 * what port to get stats for (used through board control device).
2828 */ 2526 */
2829 2527
2830static int stl_getportstats(stlport_t *portp, comstats_t __user *cp) 2528static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2831{ 2529{
2530 comstats_t stl_comstats;
2832 unsigned char *head, *tail; 2531 unsigned char *head, *tail;
2833 unsigned long flags; 2532 unsigned long flags;
2834 2533
@@ -2837,8 +2536,8 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2837 return -EFAULT; 2536 return -EFAULT;
2838 portp = stl_getport(stl_comstats.brd, stl_comstats.panel, 2537 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2839 stl_comstats.port); 2538 stl_comstats.port);
2840 if (portp == (stlport_t *) NULL) 2539 if (portp == NULL)
2841 return(-ENODEV); 2540 return -ENODEV;
2842 } 2541 }
2843 2542
2844 portp->stats.state = portp->istate; 2543 portp->stats.state = portp->istate;
@@ -2853,25 +2552,24 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2853 portp->stats.rxbuffered = 0; 2552 portp->stats.rxbuffered = 0;
2854 2553
2855 spin_lock_irqsave(&stallion_lock, flags); 2554 spin_lock_irqsave(&stallion_lock, flags);
2856 if (portp->tty != (struct tty_struct *) NULL) { 2555 if (portp->tty != NULL)
2857 if (portp->tty->driver_data == portp) { 2556 if (portp->tty->driver_data == portp) {
2858 portp->stats.ttystate = portp->tty->flags; 2557 portp->stats.ttystate = portp->tty->flags;
2859 /* No longer available as a statistic */ 2558 /* No longer available as a statistic */
2860 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */ 2559 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2861 if (portp->tty->termios != (struct termios *) NULL) { 2560 if (portp->tty->termios != NULL) {
2862 portp->stats.cflags = portp->tty->termios->c_cflag; 2561 portp->stats.cflags = portp->tty->termios->c_cflag;
2863 portp->stats.iflags = portp->tty->termios->c_iflag; 2562 portp->stats.iflags = portp->tty->termios->c_iflag;
2864 portp->stats.oflags = portp->tty->termios->c_oflag; 2563 portp->stats.oflags = portp->tty->termios->c_oflag;
2865 portp->stats.lflags = portp->tty->termios->c_lflag; 2564 portp->stats.lflags = portp->tty->termios->c_lflag;
2866 } 2565 }
2867 } 2566 }
2868 }
2869 spin_unlock_irqrestore(&stallion_lock, flags); 2567 spin_unlock_irqrestore(&stallion_lock, flags);
2870 2568
2871 head = portp->tx.head; 2569 head = portp->tx.head;
2872 tail = portp->tx.tail; 2570 tail = portp->tx.tail;
2873 portp->stats.txbuffered = ((head >= tail) ? (head - tail) : 2571 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2874 (STL_TXBUFSIZE - (tail - head))); 2572 (STL_TXBUFSIZE - (tail - head));
2875 2573
2876 portp->stats.signals = (unsigned long) stl_getsignals(portp); 2574 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2877 2575
@@ -2885,15 +2583,17 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2885 * Clear the port stats structure. We also return it zeroed out... 2583 * Clear the port stats structure. We also return it zeroed out...
2886 */ 2584 */
2887 2585
2888static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp) 2586static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2889{ 2587{
2588 comstats_t stl_comstats;
2589
2890 if (!portp) { 2590 if (!portp) {
2891 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t))) 2591 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2892 return -EFAULT; 2592 return -EFAULT;
2893 portp = stl_getport(stl_comstats.brd, stl_comstats.panel, 2593 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2894 stl_comstats.port); 2594 stl_comstats.port);
2895 if (portp == (stlport_t *) NULL) 2595 if (portp == NULL)
2896 return(-ENODEV); 2596 return -ENODEV;
2897 } 2597 }
2898 2598
2899 memset(&portp->stats, 0, sizeof(comstats_t)); 2599 memset(&portp->stats, 0, sizeof(comstats_t));
@@ -2910,17 +2610,18 @@ static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2910 * Return the entire driver ports structure to a user app. 2610 * Return the entire driver ports structure to a user app.
2911 */ 2611 */
2912 2612
2913static int stl_getportstruct(stlport_t __user *arg) 2613static int stl_getportstruct(struct stlport __user *arg)
2914{ 2614{
2915 stlport_t *portp; 2615 struct stlport stl_dummyport;
2616 struct stlport *portp;
2916 2617
2917 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t))) 2618 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2918 return -EFAULT; 2619 return -EFAULT;
2919 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr, 2620 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2920 stl_dummyport.portnr); 2621 stl_dummyport.portnr);
2921 if (!portp) 2622 if (!portp)
2922 return -ENODEV; 2623 return -ENODEV;
2923 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0; 2624 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2924} 2625}
2925 2626
2926/*****************************************************************************/ 2627/*****************************************************************************/
@@ -2929,18 +2630,19 @@ static int stl_getportstruct(stlport_t __user *arg)
2929 * Return the entire driver board structure to a user app. 2630 * Return the entire driver board structure to a user app.
2930 */ 2631 */
2931 2632
2932static int stl_getbrdstruct(stlbrd_t __user *arg) 2633static int stl_getbrdstruct(struct stlbrd __user *arg)
2933{ 2634{
2934 stlbrd_t *brdp; 2635 struct stlbrd stl_dummybrd;
2636 struct stlbrd *brdp;
2935 2637
2936 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t))) 2638 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2937 return -EFAULT; 2639 return -EFAULT;
2938 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS)) 2640 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2939 return -ENODEV; 2641 return -ENODEV;
2940 brdp = stl_brds[stl_dummybrd.brdnr]; 2642 brdp = stl_brds[stl_dummybrd.brdnr];
2941 if (!brdp) 2643 if (!brdp)
2942 return(-ENODEV); 2644 return -ENODEV;
2943 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0; 2645 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2944} 2646}
2945 2647
2946/*****************************************************************************/ 2648/*****************************************************************************/
@@ -2956,14 +2658,11 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2956 int brdnr, rc; 2658 int brdnr, rc;
2957 void __user *argp = (void __user *)arg; 2659 void __user *argp = (void __user *)arg;
2958 2660
2959#ifdef DEBUG 2661 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2960 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2961 (int) fp, cmd, (int) arg);
2962#endif
2963 2662
2964 brdnr = iminor(ip); 2663 brdnr = iminor(ip);
2965 if (brdnr >= STL_MAXBRDS) 2664 if (brdnr >= STL_MAXBRDS)
2966 return(-ENODEV); 2665 return -ENODEV;
2967 rc = 0; 2666 rc = 0;
2968 2667
2969 switch (cmd) { 2668 switch (cmd) {
@@ -2987,7 +2686,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2987 break; 2686 break;
2988 } 2687 }
2989 2688
2990 return(rc); 2689 return rc;
2991} 2690}
2992 2691
2993static const struct tty_operations stl_ops = { 2692static const struct tty_operations stl_ops = {
@@ -3015,55 +2714,6 @@ static const struct tty_operations stl_ops = {
3015}; 2714};
3016 2715
3017/*****************************************************************************/ 2716/*****************************************************************************/
3018
3019static int __init stl_init(void)
3020{
3021 int i;
3022 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3023
3024 spin_lock_init(&stallion_lock);
3025 spin_lock_init(&brd_lock);
3026
3027 stl_initbrds();
3028
3029 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3030 if (!stl_serial)
3031 return -1;
3032
3033/*
3034 * Set up a character driver for per board stuff. This is mainly used
3035 * to do stats ioctls on the ports.
3036 */
3037 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3038 printk("STALLION: failed to register serial board device\n");
3039
3040 stallion_class = class_create(THIS_MODULE, "staliomem");
3041 for (i = 0; i < 4; i++)
3042 class_device_create(stallion_class, NULL,
3043 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3044 "staliomem%d", i);
3045
3046 stl_serial->owner = THIS_MODULE;
3047 stl_serial->driver_name = stl_drvname;
3048 stl_serial->name = "ttyE";
3049 stl_serial->major = STL_SERIALMAJOR;
3050 stl_serial->minor_start = 0;
3051 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3052 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3053 stl_serial->init_termios = stl_deftermios;
3054 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3055 tty_set_operations(stl_serial, &stl_ops);
3056
3057 if (tty_register_driver(stl_serial)) {
3058 put_tty_driver(stl_serial);
3059 printk("STALLION: failed to register serial driver\n");
3060 return -1;
3061 }
3062
3063 return 0;
3064}
3065
3066/*****************************************************************************/
3067/* CD1400 HARDWARE FUNCTIONS */ 2717/* CD1400 HARDWARE FUNCTIONS */
3068/*****************************************************************************/ 2718/*****************************************************************************/
3069 2719
@@ -3073,21 +2723,21 @@ static int __init stl_init(void)
3073 * (Maybe should make this inline...) 2723 * (Maybe should make this inline...)
3074 */ 2724 */
3075 2725
3076static int stl_cd1400getreg(stlport_t *portp, int regnr) 2726static int stl_cd1400getreg(struct stlport *portp, int regnr)
3077{ 2727{
3078 outb((regnr + portp->uartaddr), portp->ioaddr); 2728 outb((regnr + portp->uartaddr), portp->ioaddr);
3079 return inb(portp->ioaddr + EREG_DATA); 2729 return inb(portp->ioaddr + EREG_DATA);
3080} 2730}
3081 2731
3082static void stl_cd1400setreg(stlport_t *portp, int regnr, int value) 2732static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
3083{ 2733{
3084 outb((regnr + portp->uartaddr), portp->ioaddr); 2734 outb(regnr + portp->uartaddr, portp->ioaddr);
3085 outb(value, portp->ioaddr + EREG_DATA); 2735 outb(value, portp->ioaddr + EREG_DATA);
3086} 2736}
3087 2737
3088static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value) 2738static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
3089{ 2739{
3090 outb((regnr + portp->uartaddr), portp->ioaddr); 2740 outb(regnr + portp->uartaddr, portp->ioaddr);
3091 if (inb(portp->ioaddr + EREG_DATA) != value) { 2741 if (inb(portp->ioaddr + EREG_DATA) != value) {
3092 outb(value, portp->ioaddr + EREG_DATA); 2742 outb(value, portp->ioaddr + EREG_DATA);
3093 return 1; 2743 return 1;
@@ -3103,16 +2753,14 @@ static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3103 * identical when dealing with ports. 2753 * identical when dealing with ports.
3104 */ 2754 */
3105 2755
3106static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp) 2756static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3107{ 2757{
3108 unsigned int gfrcr; 2758 unsigned int gfrcr;
3109 int chipmask, i, j; 2759 int chipmask, i, j;
3110 int nrchips, uartaddr, ioaddr; 2760 int nrchips, uartaddr, ioaddr;
3111 unsigned long flags; 2761 unsigned long flags;
3112 2762
3113#ifdef DEBUG 2763 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3114 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3115#endif
3116 2764
3117 spin_lock_irqsave(&brd_lock, flags); 2765 spin_lock_irqsave(&brd_lock, flags);
3118 BRDENABLE(panelp->brdnr, panelp->pagenr); 2766 BRDENABLE(panelp->brdnr, panelp->pagenr);
@@ -3122,13 +2770,12 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3122 */ 2770 */
3123 chipmask = 0; 2771 chipmask = 0;
3124 nrchips = panelp->nrports / CD1400_PORTS; 2772 nrchips = panelp->nrports / CD1400_PORTS;
3125 for (i = 0; (i < nrchips); i++) { 2773 for (i = 0; i < nrchips; i++) {
3126 if (brdp->brdtype == BRD_ECHPCI) { 2774 if (brdp->brdtype == BRD_ECHPCI) {
3127 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl); 2775 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3128 ioaddr = panelp->iobase; 2776 ioaddr = panelp->iobase;
3129 } else { 2777 } else
3130 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1)); 2778 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3131 }
3132 uartaddr = (i & 0x01) ? 0x080 : 0; 2779 uartaddr = (i & 0x01) ? 0x080 : 0;
3133 outb((GFRCR + uartaddr), ioaddr); 2780 outb((GFRCR + uartaddr), ioaddr);
3134 outb(0, (ioaddr + EREG_DATA)); 2781 outb(0, (ioaddr + EREG_DATA));
@@ -3136,10 +2783,10 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3136 outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); 2783 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3137 outb(CCR_RESETFULL, (ioaddr + EREG_DATA)); 2784 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3138 outb((GFRCR + uartaddr), ioaddr); 2785 outb((GFRCR + uartaddr), ioaddr);
3139 for (j = 0; (j < CCR_MAXWAIT); j++) { 2786 for (j = 0; j < CCR_MAXWAIT; j++)
3140 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0) 2787 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3141 break; 2788 break;
3142 } 2789
3143 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) { 2790 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3144 printk("STALLION: cd1400 not responding, " 2791 printk("STALLION: cd1400 not responding, "
3145 "brd=%d panel=%d chip=%d\n", 2792 "brd=%d panel=%d chip=%d\n",
@@ -3162,16 +2809,14 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3162 * Initialize hardware specific port registers. 2809 * Initialize hardware specific port registers.
3163 */ 2810 */
3164 2811
3165static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 2812static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3166{ 2813{
3167 unsigned long flags; 2814 unsigned long flags;
3168#ifdef DEBUG 2815 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3169 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n", 2816 panelp, portp);
3170 (int) brdp, (int) panelp, (int) portp);
3171#endif
3172 2817
3173 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) || 2818 if ((brdp == NULL) || (panelp == NULL) ||
3174 (portp == (stlport_t *) NULL)) 2819 (portp == NULL))
3175 return; 2820 return;
3176 2821
3177 spin_lock_irqsave(&brd_lock, flags); 2822 spin_lock_irqsave(&brd_lock, flags);
@@ -3195,15 +2840,13 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3195 * since it won't usually take too long to be ready. 2840 * since it won't usually take too long to be ready.
3196 */ 2841 */
3197 2842
3198static void stl_cd1400ccrwait(stlport_t *portp) 2843static void stl_cd1400ccrwait(struct stlport *portp)
3199{ 2844{
3200 int i; 2845 int i;
3201 2846
3202 for (i = 0; (i < CCR_MAXWAIT); i++) { 2847 for (i = 0; i < CCR_MAXWAIT; i++)
3203 if (stl_cd1400getreg(portp, CCR) == 0) { 2848 if (stl_cd1400getreg(portp, CCR) == 0)
3204 return; 2849 return;
3205 }
3206 }
3207 2850
3208 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n", 2851 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3209 portp->portnr, portp->panelnr, portp->brdnr); 2852 portp->portnr, portp->panelnr, portp->brdnr);
@@ -3216,9 +2859,9 @@ static void stl_cd1400ccrwait(stlport_t *portp)
3216 * settings. 2859 * settings.
3217 */ 2860 */
3218 2861
3219static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp) 2862static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
3220{ 2863{
3221 stlbrd_t *brdp; 2864 struct stlbrd *brdp;
3222 unsigned long flags; 2865 unsigned long flags;
3223 unsigned int clkdiv, baudrate; 2866 unsigned int clkdiv, baudrate;
3224 unsigned char cor1, cor2, cor3; 2867 unsigned char cor1, cor2, cor3;
@@ -3242,7 +2885,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3242 sreroff = 0; 2885 sreroff = 0;
3243 2886
3244 brdp = stl_brds[portp->brdnr]; 2887 brdp = stl_brds[portp->brdnr];
3245 if (brdp == (stlbrd_t *) NULL) 2888 if (brdp == NULL)
3246 return; 2889 return;
3247 2890
3248/* 2891/*
@@ -3339,8 +2982,8 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3339 baudrate = STL_CD1400MAXBAUD; 2982 baudrate = STL_CD1400MAXBAUD;
3340 2983
3341 if (baudrate > 0) { 2984 if (baudrate > 0) {
3342 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) { 2985 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
3343 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate); 2986 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
3344 if (clkdiv < 0x100) 2987 if (clkdiv < 0x100)
3345 break; 2988 break;
3346 } 2989 }
@@ -3355,9 +2998,8 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3355 mcor2 |= MCOR2_DCD; 2998 mcor2 |= MCOR2_DCD;
3356 sreron |= SRER_MODEM; 2999 sreron |= SRER_MODEM;
3357 portp->flags |= ASYNC_CHECK_CD; 3000 portp->flags |= ASYNC_CHECK_CD;
3358 } else { 3001 } else
3359 portp->flags &= ~ASYNC_CHECK_CD; 3002 portp->flags &= ~ASYNC_CHECK_CD;
3360 }
3361 3003
3362/* 3004/*
3363 * Setup cd1400 enhanced modes if we can. In particular we want to 3005 * Setup cd1400 enhanced modes if we can. In particular we want to
@@ -3382,18 +3024,16 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3382 * them all up. 3024 * them all up.
3383 */ 3025 */
3384 3026
3385#ifdef DEBUG 3027 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3386 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3387 portp->portnr, portp->panelnr, portp->brdnr); 3028 portp->portnr, portp->panelnr, portp->brdnr);
3388 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", 3029 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3389 cor1, cor2, cor3, cor4, cor5); 3030 cor1, cor2, cor3, cor4, cor5);
3390 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n", 3031 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3391 mcor1, mcor2, rtpr, sreron, sreroff); 3032 mcor1, mcor2, rtpr, sreron, sreroff);
3392 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div); 3033 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3393 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n", 3034 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3394 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], 3035 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3395 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3036 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3396#endif
3397 3037
3398 spin_lock_irqsave(&brd_lock, flags); 3038 spin_lock_irqsave(&brd_lock, flags);
3399 BRDENABLE(portp->brdnr, portp->pagenr); 3039 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3441,15 +3081,13 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3441 * Set the state of the DTR and RTS signals. 3081 * Set the state of the DTR and RTS signals.
3442 */ 3082 */
3443 3083
3444static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts) 3084static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3445{ 3085{
3446 unsigned char msvr1, msvr2; 3086 unsigned char msvr1, msvr2;
3447 unsigned long flags; 3087 unsigned long flags;
3448 3088
3449#ifdef DEBUG 3089 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3450 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", 3090 portp, dtr, rts);
3451 (int) portp, dtr, rts);
3452#endif
3453 3091
3454 msvr1 = 0; 3092 msvr1 = 0;
3455 msvr2 = 0; 3093 msvr2 = 0;
@@ -3475,15 +3113,13 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3475 * Return the state of the signals. 3113 * Return the state of the signals.
3476 */ 3114 */
3477 3115
3478static int stl_cd1400getsignals(stlport_t *portp) 3116static int stl_cd1400getsignals(struct stlport *portp)
3479{ 3117{
3480 unsigned char msvr1, msvr2; 3118 unsigned char msvr1, msvr2;
3481 unsigned long flags; 3119 unsigned long flags;
3482 int sigs; 3120 int sigs;
3483 3121
3484#ifdef DEBUG 3122 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3485 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3486#endif
3487 3123
3488 spin_lock_irqsave(&brd_lock, flags); 3124 spin_lock_irqsave(&brd_lock, flags);
3489 BRDENABLE(portp->brdnr, portp->pagenr); 3125 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3513,15 +3149,13 @@ static int stl_cd1400getsignals(stlport_t *portp)
3513 * Enable/Disable the Transmitter and/or Receiver. 3149 * Enable/Disable the Transmitter and/or Receiver.
3514 */ 3150 */
3515 3151
3516static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx) 3152static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3517{ 3153{
3518 unsigned char ccr; 3154 unsigned char ccr;
3519 unsigned long flags; 3155 unsigned long flags;
3520 3156
3521#ifdef DEBUG 3157 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3522 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n", 3158
3523 (int) portp, rx, tx);
3524#endif
3525 ccr = 0; 3159 ccr = 0;
3526 3160
3527 if (tx == 0) 3161 if (tx == 0)
@@ -3549,15 +3183,12 @@ static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3549 * Start/stop the Transmitter and/or Receiver. 3183 * Start/stop the Transmitter and/or Receiver.
3550 */ 3184 */
3551 3185
3552static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx) 3186static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3553{ 3187{
3554 unsigned char sreron, sreroff; 3188 unsigned char sreron, sreroff;
3555 unsigned long flags; 3189 unsigned long flags;
3556 3190
3557#ifdef DEBUG 3191 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3558 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3559 (int) portp, rx, tx);
3560#endif
3561 3192
3562 sreron = 0; 3193 sreron = 0;
3563 sreroff = 0; 3194 sreroff = 0;
@@ -3589,13 +3220,12 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3589 * Disable all interrupts from this port. 3220 * Disable all interrupts from this port.
3590 */ 3221 */
3591 3222
3592static void stl_cd1400disableintrs(stlport_t *portp) 3223static void stl_cd1400disableintrs(struct stlport *portp)
3593{ 3224{
3594 unsigned long flags; 3225 unsigned long flags;
3595 3226
3596#ifdef DEBUG 3227 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3597 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp); 3228
3598#endif
3599 spin_lock_irqsave(&brd_lock, flags); 3229 spin_lock_irqsave(&brd_lock, flags);
3600 BRDENABLE(portp->brdnr, portp->pagenr); 3230 BRDENABLE(portp->brdnr, portp->pagenr);
3601 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3231 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
@@ -3606,13 +3236,11 @@ static void stl_cd1400disableintrs(stlport_t *portp)
3606 3236
3607/*****************************************************************************/ 3237/*****************************************************************************/
3608 3238
3609static void stl_cd1400sendbreak(stlport_t *portp, int len) 3239static void stl_cd1400sendbreak(struct stlport *portp, int len)
3610{ 3240{
3611 unsigned long flags; 3241 unsigned long flags;
3612 3242
3613#ifdef DEBUG 3243 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3614 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3615#endif
3616 3244
3617 spin_lock_irqsave(&brd_lock, flags); 3245 spin_lock_irqsave(&brd_lock, flags);
3618 BRDENABLE(portp->brdnr, portp->pagenr); 3246 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -3633,19 +3261,17 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3633 * Take flow control actions... 3261 * Take flow control actions...
3634 */ 3262 */
3635 3263
3636static void stl_cd1400flowctrl(stlport_t *portp, int state) 3264static void stl_cd1400flowctrl(struct stlport *portp, int state)
3637{ 3265{
3638 struct tty_struct *tty; 3266 struct tty_struct *tty;
3639 unsigned long flags; 3267 unsigned long flags;
3640 3268
3641#ifdef DEBUG 3269 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3642 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3643#endif
3644 3270
3645 if (portp == (stlport_t *) NULL) 3271 if (portp == NULL)
3646 return; 3272 return;
3647 tty = portp->tty; 3273 tty = portp->tty;
3648 if (tty == (struct tty_struct *) NULL) 3274 if (tty == NULL)
3649 return; 3275 return;
3650 3276
3651 spin_lock_irqsave(&brd_lock, flags); 3277 spin_lock_irqsave(&brd_lock, flags);
@@ -3697,19 +3323,17 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3697 * Send a flow control character... 3323 * Send a flow control character...
3698 */ 3324 */
3699 3325
3700static void stl_cd1400sendflow(stlport_t *portp, int state) 3326static void stl_cd1400sendflow(struct stlport *portp, int state)
3701{ 3327{
3702 struct tty_struct *tty; 3328 struct tty_struct *tty;
3703 unsigned long flags; 3329 unsigned long flags;
3704 3330
3705#ifdef DEBUG 3331 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3706 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3707#endif
3708 3332
3709 if (portp == (stlport_t *) NULL) 3333 if (portp == NULL)
3710 return; 3334 return;
3711 tty = portp->tty; 3335 tty = portp->tty;
3712 if (tty == (struct tty_struct *) NULL) 3336 if (tty == NULL)
3713 return; 3337 return;
3714 3338
3715 spin_lock_irqsave(&brd_lock, flags); 3339 spin_lock_irqsave(&brd_lock, flags);
@@ -3732,15 +3356,13 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3732 3356
3733/*****************************************************************************/ 3357/*****************************************************************************/
3734 3358
3735static void stl_cd1400flush(stlport_t *portp) 3359static void stl_cd1400flush(struct stlport *portp)
3736{ 3360{
3737 unsigned long flags; 3361 unsigned long flags;
3738 3362
3739#ifdef DEBUG 3363 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3740 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3741#endif
3742 3364
3743 if (portp == (stlport_t *) NULL) 3365 if (portp == NULL)
3744 return; 3366 return;
3745 3367
3746 spin_lock_irqsave(&brd_lock, flags); 3368 spin_lock_irqsave(&brd_lock, flags);
@@ -3763,13 +3385,11 @@ static void stl_cd1400flush(stlport_t *portp)
3763 * maintains the busy port flag. 3385 * maintains the busy port flag.
3764 */ 3386 */
3765 3387
3766static int stl_cd1400datastate(stlport_t *portp) 3388static int stl_cd1400datastate(struct stlport *portp)
3767{ 3389{
3768#ifdef DEBUG 3390 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3769 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3770#endif
3771 3391
3772 if (portp == (stlport_t *) NULL) 3392 if (portp == NULL)
3773 return 0; 3393 return 0;
3774 3394
3775 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0; 3395 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
@@ -3781,14 +3401,11 @@ static int stl_cd1400datastate(stlport_t *portp)
3781 * Interrupt service routine for cd1400 EasyIO boards. 3401 * Interrupt service routine for cd1400 EasyIO boards.
3782 */ 3402 */
3783 3403
3784static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase) 3404static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3785{ 3405{
3786 unsigned char svrtype; 3406 unsigned char svrtype;
3787 3407
3788#ifdef DEBUG 3408 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3789 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3790 (int) panelp, iobase);
3791#endif
3792 3409
3793 spin_lock(&brd_lock); 3410 spin_lock(&brd_lock);
3794 outb(SVRR, iobase); 3411 outb(SVRR, iobase);
@@ -3814,14 +3431,11 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3814 * Interrupt service routine for cd1400 panels. 3431 * Interrupt service routine for cd1400 panels.
3815 */ 3432 */
3816 3433
3817static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase) 3434static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3818{ 3435{
3819 unsigned char svrtype; 3436 unsigned char svrtype;
3820 3437
3821#ifdef DEBUG 3438 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3822 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3823 iobase);
3824#endif
3825 3439
3826 outb(SVRR, iobase); 3440 outb(SVRR, iobase);
3827 svrtype = inb(iobase + EREG_DATA); 3441 svrtype = inb(iobase + EREG_DATA);
@@ -3843,7 +3457,7 @@ static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3843 * this is the only way to generate them on the cd1400. 3457 * this is the only way to generate them on the cd1400.
3844 */ 3458 */
3845 3459
3846static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr) 3460static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3847{ 3461{
3848 if (portp->brklen == 1) { 3462 if (portp->brklen == 1) {
3849 outb((COR2 + portp->uartaddr), ioaddr); 3463 outb((COR2 + portp->uartaddr), ioaddr);
@@ -3885,16 +3499,14 @@ static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3885 * be NULL if the buffer has been freed. 3499 * be NULL if the buffer has been freed.
3886 */ 3500 */
3887 3501
3888static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr) 3502static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3889{ 3503{
3890 stlport_t *portp; 3504 struct stlport *portp;
3891 int len, stlen; 3505 int len, stlen;
3892 char *head, *tail; 3506 char *head, *tail;
3893 unsigned char ioack, srer; 3507 unsigned char ioack, srer;
3894 3508
3895#ifdef DEBUG 3509 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3896 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3897#endif
3898 3510
3899 ioack = inb(ioaddr + EREG_TXACK); 3511 ioack = inb(ioaddr + EREG_TXACK);
3900 if (((ioack & panelp->ackmask) != 0) || 3512 if (((ioack & panelp->ackmask) != 0) ||
@@ -3933,9 +3545,9 @@ static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3933 } 3545 }
3934 outb(srer, (ioaddr + EREG_DATA)); 3546 outb(srer, (ioaddr + EREG_DATA));
3935 } else { 3547 } else {
3936 len = MIN(len, CD1400_TXFIFOSIZE); 3548 len = min(len, CD1400_TXFIFOSIZE);
3937 portp->stats.txtotal += len; 3549 portp->stats.txtotal += len;
3938 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail)); 3550 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3939 outb((TDR + portp->uartaddr), ioaddr); 3551 outb((TDR + portp->uartaddr), ioaddr);
3940 outsb((ioaddr + EREG_DATA), tail, stlen); 3552 outsb((ioaddr + EREG_DATA), tail, stlen);
3941 len -= stlen; 3553 len -= stlen;
@@ -3966,17 +3578,15 @@ stl_txalldone:
3966 * shutdown a port not in user context. Need to handle this case. 3578 * shutdown a port not in user context. Need to handle this case.
3967 */ 3579 */
3968 3580
3969static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr) 3581static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3970{ 3582{
3971 stlport_t *portp; 3583 struct stlport *portp;
3972 struct tty_struct *tty; 3584 struct tty_struct *tty;
3973 unsigned int ioack, len, buflen; 3585 unsigned int ioack, len, buflen;
3974 unsigned char status; 3586 unsigned char status;
3975 char ch; 3587 char ch;
3976 3588
3977#ifdef DEBUG 3589 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3978 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3979#endif
3980 3590
3981 ioack = inb(ioaddr + EREG_RXACK); 3591 ioack = inb(ioaddr + EREG_RXACK);
3982 if ((ioack & panelp->ackmask) != 0) { 3592 if ((ioack & panelp->ackmask) != 0) {
@@ -3990,13 +3600,13 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
3990 outb((RDCR + portp->uartaddr), ioaddr); 3600 outb((RDCR + portp->uartaddr), ioaddr);
3991 len = inb(ioaddr + EREG_DATA); 3601 len = inb(ioaddr + EREG_DATA);
3992 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { 3602 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3993 len = MIN(len, sizeof(stl_unwanted)); 3603 len = min(len, sizeof(stl_unwanted));
3994 outb((RDSR + portp->uartaddr), ioaddr); 3604 outb((RDSR + portp->uartaddr), ioaddr);
3995 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len); 3605 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3996 portp->stats.rxlost += len; 3606 portp->stats.rxlost += len;
3997 portp->stats.rxtotal += len; 3607 portp->stats.rxtotal += len;
3998 } else { 3608 } else {
3999 len = MIN(len, buflen); 3609 len = min(len, buflen);
4000 if (len > 0) { 3610 if (len > 0) {
4001 unsigned char *ptr; 3611 unsigned char *ptr;
4002 outb((RDSR + portp->uartaddr), ioaddr); 3612 outb((RDSR + portp->uartaddr), ioaddr);
@@ -4033,18 +3643,16 @@ static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4033 do_SAK(tty); 3643 do_SAK(tty);
4034 BRDENABLE(portp->brdnr, portp->pagenr); 3644 BRDENABLE(portp->brdnr, portp->pagenr);
4035 } 3645 }
4036 } else if (status & ST_PARITY) { 3646 } else if (status & ST_PARITY)
4037 status = TTY_PARITY; 3647 status = TTY_PARITY;
4038 } else if (status & ST_FRAMING) { 3648 else if (status & ST_FRAMING)
4039 status = TTY_FRAME; 3649 status = TTY_FRAME;
4040 } else if(status & ST_OVERRUN) { 3650 else if(status & ST_OVERRUN)
4041 status = TTY_OVERRUN; 3651 status = TTY_OVERRUN;
4042 } else { 3652 else
4043 status = 0; 3653 status = 0;
4044 } 3654 } else
4045 } else {
4046 status = 0; 3655 status = 0;
4047 }
4048 tty_insert_flip_char(tty, ch, status); 3656 tty_insert_flip_char(tty, ch, status);
4049 tty_schedule_flip(tty); 3657 tty_schedule_flip(tty);
4050 } 3658 }
@@ -4066,15 +3674,13 @@ stl_rxalldone:
4066 * processing routine. 3674 * processing routine.
4067 */ 3675 */
4068 3676
4069static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr) 3677static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
4070{ 3678{
4071 stlport_t *portp; 3679 struct stlport *portp;
4072 unsigned int ioack; 3680 unsigned int ioack;
4073 unsigned char misr; 3681 unsigned char misr;
4074 3682
4075#ifdef DEBUG 3683 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
4076 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4077#endif
4078 3684
4079 ioack = inb(ioaddr + EREG_MDACK); 3685 ioack = inb(ioaddr + EREG_MDACK);
4080 if (((ioack & panelp->ackmask) != 0) || 3686 if (((ioack & panelp->ackmask) != 0) ||
@@ -4106,19 +3712,19 @@ static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4106 * (Maybe should make this inline...) 3712 * (Maybe should make this inline...)
4107 */ 3713 */
4108 3714
4109static int stl_sc26198getreg(stlport_t *portp, int regnr) 3715static int stl_sc26198getreg(struct stlport *portp, int regnr)
4110{ 3716{
4111 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3717 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4112 return inb(portp->ioaddr + XP_DATA); 3718 return inb(portp->ioaddr + XP_DATA);
4113} 3719}
4114 3720
4115static void stl_sc26198setreg(stlport_t *portp, int regnr, int value) 3721static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
4116{ 3722{
4117 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3723 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4118 outb(value, (portp->ioaddr + XP_DATA)); 3724 outb(value, (portp->ioaddr + XP_DATA));
4119} 3725}
4120 3726
4121static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value) 3727static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
4122{ 3728{
4123 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR)); 3729 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4124 if (inb(portp->ioaddr + XP_DATA) != value) { 3730 if (inb(portp->ioaddr + XP_DATA) != value) {
@@ -4134,14 +3740,14 @@ static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4134 * Functions to get and set the sc26198 global registers. 3740 * Functions to get and set the sc26198 global registers.
4135 */ 3741 */
4136 3742
4137static int stl_sc26198getglobreg(stlport_t *portp, int regnr) 3743static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
4138{ 3744{
4139 outb(regnr, (portp->ioaddr + XP_ADDR)); 3745 outb(regnr, (portp->ioaddr + XP_ADDR));
4140 return inb(portp->ioaddr + XP_DATA); 3746 return inb(portp->ioaddr + XP_DATA);
4141} 3747}
4142 3748
4143#if 0 3749#if 0
4144static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value) 3750static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
4145{ 3751{
4146 outb(regnr, (portp->ioaddr + XP_ADDR)); 3752 outb(regnr, (portp->ioaddr + XP_ADDR));
4147 outb(value, (portp->ioaddr + XP_DATA)); 3753 outb(value, (portp->ioaddr + XP_DATA));
@@ -4156,15 +3762,12 @@ static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4156 * identical when dealing with ports. 3762 * identical when dealing with ports.
4157 */ 3763 */
4158 3764
4159static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp) 3765static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
4160{ 3766{
4161 int chipmask, i; 3767 int chipmask, i;
4162 int nrchips, ioaddr; 3768 int nrchips, ioaddr;
4163 3769
4164#ifdef DEBUG 3770 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
4165 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4166 (int) brdp, (int) panelp);
4167#endif
4168 3771
4169 BRDENABLE(panelp->brdnr, panelp->pagenr); 3772 BRDENABLE(panelp->brdnr, panelp->pagenr);
4170 3773
@@ -4176,7 +3779,7 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4176 if (brdp->brdtype == BRD_ECHPCI) 3779 if (brdp->brdtype == BRD_ECHPCI)
4177 outb(panelp->pagenr, brdp->ioctrl); 3780 outb(panelp->pagenr, brdp->ioctrl);
4178 3781
4179 for (i = 0; (i < nrchips); i++) { 3782 for (i = 0; i < nrchips; i++) {
4180 ioaddr = panelp->iobase + (i * 4); 3783 ioaddr = panelp->iobase + (i * 4);
4181 outb(SCCR, (ioaddr + XP_ADDR)); 3784 outb(SCCR, (ioaddr + XP_ADDR));
4182 outb(CR_RESETALL, (ioaddr + XP_DATA)); 3785 outb(CR_RESETALL, (ioaddr + XP_DATA));
@@ -4204,15 +3807,13 @@ static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4204 * Initialize hardware specific port registers. 3807 * Initialize hardware specific port registers.
4205 */ 3808 */
4206 3809
4207static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 3810static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
4208{ 3811{
4209#ifdef DEBUG 3812 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
4210 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n", 3813 panelp, portp);
4211 (int) brdp, (int) panelp, (int) portp);
4212#endif
4213 3814
4214 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) || 3815 if ((brdp == NULL) || (panelp == NULL) ||
4215 (portp == (stlport_t *) NULL)) 3816 (portp == NULL))
4216 return; 3817 return;
4217 3818
4218 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4); 3819 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
@@ -4232,9 +3833,9 @@ static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *p
4232 * settings. 3833 * settings.
4233 */ 3834 */
4234 3835
4235static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp) 3836static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
4236{ 3837{
4237 stlbrd_t *brdp; 3838 struct stlbrd *brdp;
4238 unsigned long flags; 3839 unsigned long flags;
4239 unsigned int baudrate; 3840 unsigned int baudrate;
4240 unsigned char mr0, mr1, mr2, clk; 3841 unsigned char mr0, mr1, mr2, clk;
@@ -4249,7 +3850,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4249 imroff = 0; 3850 imroff = 0;
4250 3851
4251 brdp = stl_brds[portp->brdnr]; 3852 brdp = stl_brds[portp->brdnr];
4252 if (brdp == (stlbrd_t *) NULL) 3853 if (brdp == NULL)
4253 return; 3854 return;
4254 3855
4255/* 3856/*
@@ -4298,9 +3899,8 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4298 mr1 |= (MR1_PARENB | MR1_PARODD); 3899 mr1 |= (MR1_PARENB | MR1_PARODD);
4299 else 3900 else
4300 mr1 |= (MR1_PARENB | MR1_PAREVEN); 3901 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4301 } else { 3902 } else
4302 mr1 |= MR1_PARNONE; 3903 mr1 |= MR1_PARNONE;
4303 }
4304 3904
4305 mr1 |= MR1_ERRBLOCK; 3905 mr1 |= MR1_ERRBLOCK;
4306 3906
@@ -4340,12 +3940,10 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4340 if (baudrate > STL_SC26198MAXBAUD) 3940 if (baudrate > STL_SC26198MAXBAUD)
4341 baudrate = STL_SC26198MAXBAUD; 3941 baudrate = STL_SC26198MAXBAUD;
4342 3942
4343 if (baudrate > 0) { 3943 if (baudrate > 0)
4344 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) { 3944 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
4345 if (baudrate <= sc26198_baudtable[clk]) 3945 if (baudrate <= sc26198_baudtable[clk])
4346 break; 3946 break;
4347 }
4348 }
4349 3947
4350/* 3948/*
4351 * Check what form of modem signaling is required and set it up. 3949 * Check what form of modem signaling is required and set it up.
@@ -4367,9 +3965,9 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4367 if (tiosp->c_iflag & IXON) { 3965 if (tiosp->c_iflag & IXON) {
4368 mr0 |= MR0_SWFTX | MR0_SWFT; 3966 mr0 |= MR0_SWFTX | MR0_SWFT;
4369 imron |= IR_XONXOFF; 3967 imron |= IR_XONXOFF;
4370 } else { 3968 } else
4371 imroff |= IR_XONXOFF; 3969 imroff |= IR_XONXOFF;
4372 } 3970
4373 if (tiosp->c_iflag & IXOFF) 3971 if (tiosp->c_iflag & IXOFF)
4374 mr0 |= MR0_SWFRX; 3972 mr0 |= MR0_SWFRX;
4375 3973
@@ -4383,15 +3981,13 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4383 * them all up. 3981 * them all up.
4384 */ 3982 */
4385 3983
4386#ifdef DEBUG 3984 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4387 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4388 portp->portnr, portp->panelnr, portp->brdnr); 3985 portp->portnr, portp->panelnr, portp->brdnr);
4389 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk); 3986 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4390 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff); 3987 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4391 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n", 3988 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4392 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], 3989 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4393 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3990 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4394#endif
4395 3991
4396 spin_lock_irqsave(&brd_lock, flags); 3992 spin_lock_irqsave(&brd_lock, flags);
4397 BRDENABLE(portp->brdnr, portp->pagenr); 3993 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4429,15 +4025,13 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4429 * Set the state of the DTR and RTS signals. 4025 * Set the state of the DTR and RTS signals.
4430 */ 4026 */
4431 4027
4432static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts) 4028static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4433{ 4029{
4434 unsigned char iopioron, iopioroff; 4030 unsigned char iopioron, iopioroff;
4435 unsigned long flags; 4031 unsigned long flags;
4436 4032
4437#ifdef DEBUG 4033 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4438 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n", 4034 dtr, rts);
4439 (int) portp, dtr, rts);
4440#endif
4441 4035
4442 iopioron = 0; 4036 iopioron = 0;
4443 iopioroff = 0; 4037 iopioroff = 0;
@@ -4464,15 +4058,13 @@ static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4464 * Return the state of the signals. 4058 * Return the state of the signals.
4465 */ 4059 */
4466 4060
4467static int stl_sc26198getsignals(stlport_t *portp) 4061static int stl_sc26198getsignals(struct stlport *portp)
4468{ 4062{
4469 unsigned char ipr; 4063 unsigned char ipr;
4470 unsigned long flags; 4064 unsigned long flags;
4471 int sigs; 4065 int sigs;
4472 4066
4473#ifdef DEBUG 4067 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4474 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4475#endif
4476 4068
4477 spin_lock_irqsave(&brd_lock, flags); 4069 spin_lock_irqsave(&brd_lock, flags);
4478 BRDENABLE(portp->brdnr, portp->pagenr); 4070 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4495,15 +4087,12 @@ static int stl_sc26198getsignals(stlport_t *portp)
4495 * Enable/Disable the Transmitter and/or Receiver. 4087 * Enable/Disable the Transmitter and/or Receiver.
4496 */ 4088 */
4497 4089
4498static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx) 4090static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4499{ 4091{
4500 unsigned char ccr; 4092 unsigned char ccr;
4501 unsigned long flags; 4093 unsigned long flags;
4502 4094
4503#ifdef DEBUG 4095 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4504 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4505 (int) portp, rx, tx);
4506#endif
4507 4096
4508 ccr = portp->crenable; 4097 ccr = portp->crenable;
4509 if (tx == 0) 4098 if (tx == 0)
@@ -4529,15 +4118,12 @@ static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4529 * Start/stop the Transmitter and/or Receiver. 4118 * Start/stop the Transmitter and/or Receiver.
4530 */ 4119 */
4531 4120
4532static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx) 4121static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4533{ 4122{
4534 unsigned char imr; 4123 unsigned char imr;
4535 unsigned long flags; 4124 unsigned long flags;
4536 4125
4537#ifdef DEBUG 4126 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4538 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4539 (int) portp, rx, tx);
4540#endif
4541 4127
4542 imr = portp->imr; 4128 imr = portp->imr;
4543 if (tx == 0) 4129 if (tx == 0)
@@ -4565,13 +4151,11 @@ static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4565 * Disable all interrupts from this port. 4151 * Disable all interrupts from this port.
4566 */ 4152 */
4567 4153
4568static void stl_sc26198disableintrs(stlport_t *portp) 4154static void stl_sc26198disableintrs(struct stlport *portp)
4569{ 4155{
4570 unsigned long flags; 4156 unsigned long flags;
4571 4157
4572#ifdef DEBUG 4158 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4573 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4574#endif
4575 4159
4576 spin_lock_irqsave(&brd_lock, flags); 4160 spin_lock_irqsave(&brd_lock, flags);
4577 BRDENABLE(portp->brdnr, portp->pagenr); 4161 BRDENABLE(portp->brdnr, portp->pagenr);
@@ -4583,22 +4167,20 @@ static void stl_sc26198disableintrs(stlport_t *portp)
4583 4167
4584/*****************************************************************************/ 4168/*****************************************************************************/
4585 4169
4586static void stl_sc26198sendbreak(stlport_t *portp, int len) 4170static void stl_sc26198sendbreak(struct stlport *portp, int len)
4587{ 4171{
4588 unsigned long flags; 4172 unsigned long flags;
4589 4173
4590#ifdef DEBUG 4174 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4591 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4592#endif
4593 4175
4594 spin_lock_irqsave(&brd_lock, flags); 4176 spin_lock_irqsave(&brd_lock, flags);
4595 BRDENABLE(portp->brdnr, portp->pagenr); 4177 BRDENABLE(portp->brdnr, portp->pagenr);
4596 if (len == 1) { 4178 if (len == 1) {
4597 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK); 4179 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4598 portp->stats.txbreaks++; 4180 portp->stats.txbreaks++;
4599 } else { 4181 } else
4600 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK); 4182 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4601 } 4183
4602 BRDDISABLE(portp->brdnr); 4184 BRDDISABLE(portp->brdnr);
4603 spin_unlock_irqrestore(&brd_lock, flags); 4185 spin_unlock_irqrestore(&brd_lock, flags);
4604} 4186}
@@ -4609,20 +4191,18 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4609 * Take flow control actions... 4191 * Take flow control actions...
4610 */ 4192 */
4611 4193
4612static void stl_sc26198flowctrl(stlport_t *portp, int state) 4194static void stl_sc26198flowctrl(struct stlport *portp, int state)
4613{ 4195{
4614 struct tty_struct *tty; 4196 struct tty_struct *tty;
4615 unsigned long flags; 4197 unsigned long flags;
4616 unsigned char mr0; 4198 unsigned char mr0;
4617 4199
4618#ifdef DEBUG 4200 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4619 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4620#endif
4621 4201
4622 if (portp == (stlport_t *) NULL) 4202 if (portp == NULL)
4623 return; 4203 return;
4624 tty = portp->tty; 4204 tty = portp->tty;
4625 if (tty == (struct tty_struct *) NULL) 4205 if (tty == NULL)
4626 return; 4206 return;
4627 4207
4628 spin_lock_irqsave(&brd_lock, flags); 4208 spin_lock_irqsave(&brd_lock, flags);
@@ -4680,20 +4260,18 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4680 * Send a flow control character. 4260 * Send a flow control character.
4681 */ 4261 */
4682 4262
4683static void stl_sc26198sendflow(stlport_t *portp, int state) 4263static void stl_sc26198sendflow(struct stlport *portp, int state)
4684{ 4264{
4685 struct tty_struct *tty; 4265 struct tty_struct *tty;
4686 unsigned long flags; 4266 unsigned long flags;
4687 unsigned char mr0; 4267 unsigned char mr0;
4688 4268
4689#ifdef DEBUG 4269 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4690 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4691#endif
4692 4270
4693 if (portp == (stlport_t *) NULL) 4271 if (portp == NULL)
4694 return; 4272 return;
4695 tty = portp->tty; 4273 tty = portp->tty;
4696 if (tty == (struct tty_struct *) NULL) 4274 if (tty == NULL)
4697 return; 4275 return;
4698 4276
4699 spin_lock_irqsave(&brd_lock, flags); 4277 spin_lock_irqsave(&brd_lock, flags);
@@ -4721,15 +4299,13 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4721 4299
4722/*****************************************************************************/ 4300/*****************************************************************************/
4723 4301
4724static void stl_sc26198flush(stlport_t *portp) 4302static void stl_sc26198flush(struct stlport *portp)
4725{ 4303{
4726 unsigned long flags; 4304 unsigned long flags;
4727 4305
4728#ifdef DEBUG 4306 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4729 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4730#endif
4731 4307
4732 if (portp == (stlport_t *) NULL) 4308 if (portp == NULL)
4733 return; 4309 return;
4734 4310
4735 spin_lock_irqsave(&brd_lock, flags); 4311 spin_lock_irqsave(&brd_lock, flags);
@@ -4751,16 +4327,14 @@ static void stl_sc26198flush(stlport_t *portp)
4751 * check the port statusy register to be sure. 4327 * check the port statusy register to be sure.
4752 */ 4328 */
4753 4329
4754static int stl_sc26198datastate(stlport_t *portp) 4330static int stl_sc26198datastate(struct stlport *portp)
4755{ 4331{
4756 unsigned long flags; 4332 unsigned long flags;
4757 unsigned char sr; 4333 unsigned char sr;
4758 4334
4759#ifdef DEBUG 4335 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4760 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4761#endif
4762 4336
4763 if (portp == (stlport_t *) NULL) 4337 if (portp == NULL)
4764 return 0; 4338 return 0;
4765 if (test_bit(ASYI_TXBUSY, &portp->istate)) 4339 if (test_bit(ASYI_TXBUSY, &portp->istate))
4766 return 1; 4340 return 1;
@@ -4781,18 +4355,16 @@ static int stl_sc26198datastate(stlport_t *portp)
4781 * to process a command... 4355 * to process a command...
4782 */ 4356 */
4783 4357
4784static void stl_sc26198wait(stlport_t *portp) 4358static void stl_sc26198wait(struct stlport *portp)
4785{ 4359{
4786 int i; 4360 int i;
4787 4361
4788#ifdef DEBUG 4362 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4789 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4790#endif
4791 4363
4792 if (portp == (stlport_t *) NULL) 4364 if (portp == NULL)
4793 return; 4365 return;
4794 4366
4795 for (i = 0; (i < 20); i++) 4367 for (i = 0; i < 20; i++)
4796 stl_sc26198getglobreg(portp, TSTR); 4368 stl_sc26198getglobreg(portp, TSTR);
4797} 4369}
4798 4370
@@ -4804,7 +4376,7 @@ static void stl_sc26198wait(stlport_t *portp)
4804 * automatic flow control modes of the sc26198. 4376 * automatic flow control modes of the sc26198.
4805 */ 4377 */
4806 4378
4807static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty) 4379static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4808{ 4380{
4809 unsigned char mr0; 4381 unsigned char mr0;
4810 4382
@@ -4822,9 +4394,9 @@ static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4822 * Interrupt service routine for sc26198 panels. 4394 * Interrupt service routine for sc26198 panels.
4823 */ 4395 */
4824 4396
4825static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase) 4397static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4826{ 4398{
4827 stlport_t *portp; 4399 struct stlport *portp;
4828 unsigned int iack; 4400 unsigned int iack;
4829 4401
4830 spin_lock(&brd_lock); 4402 spin_lock(&brd_lock);
@@ -4860,16 +4432,14 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4860 * be NULL if the buffer has been freed. 4432 * be NULL if the buffer has been freed.
4861 */ 4433 */
4862 4434
4863static void stl_sc26198txisr(stlport_t *portp) 4435static void stl_sc26198txisr(struct stlport *portp)
4864{ 4436{
4865 unsigned int ioaddr; 4437 unsigned int ioaddr;
4866 unsigned char mr0; 4438 unsigned char mr0;
4867 int len, stlen; 4439 int len, stlen;
4868 char *head, *tail; 4440 char *head, *tail;
4869 4441
4870#ifdef DEBUG 4442 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4871 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4872#endif
4873 4443
4874 ioaddr = portp->ioaddr; 4444 ioaddr = portp->ioaddr;
4875 head = portp->tx.head; 4445 head = portp->tx.head;
@@ -4894,9 +4464,9 @@ static void stl_sc26198txisr(stlport_t *portp)
4894 outb(mr0, (ioaddr + XP_DATA)); 4464 outb(mr0, (ioaddr + XP_DATA));
4895 } 4465 }
4896 } else { 4466 } else {
4897 len = MIN(len, SC26198_TXFIFOSIZE); 4467 len = min(len, SC26198_TXFIFOSIZE);
4898 portp->stats.txtotal += len; 4468 portp->stats.txtotal += len;
4899 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail)); 4469 stlen = min(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4900 outb(GTXFIFO, (ioaddr + XP_ADDR)); 4470 outb(GTXFIFO, (ioaddr + XP_ADDR));
4901 outsb((ioaddr + XP_DATA), tail, stlen); 4471 outsb((ioaddr + XP_DATA), tail, stlen);
4902 len -= stlen; 4472 len -= stlen;
@@ -4923,14 +4493,12 @@ static void stl_sc26198txisr(stlport_t *portp)
4923 * shutdown a port not in user context. Need to handle this case. 4493 * shutdown a port not in user context. Need to handle this case.
4924 */ 4494 */
4925 4495
4926static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack) 4496static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4927{ 4497{
4928 struct tty_struct *tty; 4498 struct tty_struct *tty;
4929 unsigned int len, buflen, ioaddr; 4499 unsigned int len, buflen, ioaddr;
4930 4500
4931#ifdef DEBUG 4501 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4932 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4933#endif
4934 4502
4935 tty = portp->tty; 4503 tty = portp->tty;
4936 ioaddr = portp->ioaddr; 4504 ioaddr = portp->ioaddr;
@@ -4939,13 +4507,13 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4939 4507
4940 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) { 4508 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4941 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) { 4509 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4942 len = MIN(len, sizeof(stl_unwanted)); 4510 len = min(len, sizeof(stl_unwanted));
4943 outb(GRXFIFO, (ioaddr + XP_ADDR)); 4511 outb(GRXFIFO, (ioaddr + XP_ADDR));
4944 insb((ioaddr + XP_DATA), &stl_unwanted[0], len); 4512 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4945 portp->stats.rxlost += len; 4513 portp->stats.rxlost += len;
4946 portp->stats.rxtotal += len; 4514 portp->stats.rxtotal += len;
4947 } else { 4515 } else {
4948 len = MIN(len, buflen); 4516 len = min(len, buflen);
4949 if (len > 0) { 4517 if (len > 0) {
4950 unsigned char *ptr; 4518 unsigned char *ptr;
4951 outb(GRXFIFO, (ioaddr + XP_ADDR)); 4519 outb(GRXFIFO, (ioaddr + XP_ADDR));
@@ -4965,8 +4533,8 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4965 * flow control modes of the sc26198. 4533 * flow control modes of the sc26198.
4966 */ 4534 */
4967 if (test_bit(ASYI_TXFLOWED, &portp->istate)) { 4535 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4968 if ((tty != (struct tty_struct *) NULL) && 4536 if ((tty != NULL) &&
4969 (tty->termios != (struct termios *) NULL) && 4537 (tty->termios != NULL) &&
4970 (tty->termios->c_iflag & IXANY)) { 4538 (tty->termios->c_iflag & IXANY)) {
4971 stl_sc26198txunflow(portp, tty); 4539 stl_sc26198txunflow(portp, tty);
4972 } 4540 }
@@ -4979,7 +4547,7 @@ static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4979 * Process an RX bad character. 4547 * Process an RX bad character.
4980 */ 4548 */
4981 4549
4982static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch) 4550static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4983{ 4551{
4984 struct tty_struct *tty; 4552 struct tty_struct *tty;
4985 unsigned int ioaddr; 4553 unsigned int ioaddr;
@@ -4996,7 +4564,7 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
4996 if (status & SR_RXBREAK) 4564 if (status & SR_RXBREAK)
4997 portp->stats.rxbreaks++; 4565 portp->stats.rxbreaks++;
4998 4566
4999 if ((tty != (struct tty_struct *) NULL) && 4567 if ((tty != NULL) &&
5000 ((portp->rxignoremsk & status) == 0)) { 4568 ((portp->rxignoremsk & status) == 0)) {
5001 if (portp->rxmarkmsk & status) { 4569 if (portp->rxmarkmsk & status) {
5002 if (status & SR_RXBREAK) { 4570 if (status & SR_RXBREAK) {
@@ -5005,18 +4573,16 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
5005 do_SAK(tty); 4573 do_SAK(tty);
5006 BRDENABLE(portp->brdnr, portp->pagenr); 4574 BRDENABLE(portp->brdnr, portp->pagenr);
5007 } 4575 }
5008 } else if (status & SR_RXPARITY) { 4576 } else if (status & SR_RXPARITY)
5009 status = TTY_PARITY; 4577 status = TTY_PARITY;
5010 } else if (status & SR_RXFRAMING) { 4578 else if (status & SR_RXFRAMING)
5011 status = TTY_FRAME; 4579 status = TTY_FRAME;
5012 } else if(status & SR_RXOVERRUN) { 4580 else if(status & SR_RXOVERRUN)
5013 status = TTY_OVERRUN; 4581 status = TTY_OVERRUN;
5014 } else { 4582 else
5015 status = 0; 4583 status = 0;
5016 } 4584 } else
5017 } else {
5018 status = 0; 4585 status = 0;
5019 }
5020 4586
5021 tty_insert_flip_char(tty, ch, status); 4587 tty_insert_flip_char(tty, ch, status);
5022 tty_schedule_flip(tty); 4588 tty_schedule_flip(tty);
@@ -5037,7 +4603,7 @@ static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, ch
5037 * the FIFO). 4603 * the FIFO).
5038 */ 4604 */
5039 4605
5040static void stl_sc26198rxbadchars(stlport_t *portp) 4606static void stl_sc26198rxbadchars(struct stlport *portp)
5041{ 4607{
5042 unsigned char status, mr1; 4608 unsigned char status, mr1;
5043 char ch; 4609 char ch;
@@ -5070,13 +4636,11 @@ static void stl_sc26198rxbadchars(stlport_t *portp)
5070 * processing time. 4636 * processing time.
5071 */ 4637 */
5072 4638
5073static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack) 4639static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
5074{ 4640{
5075 unsigned char cir, ipr, xisr; 4641 unsigned char cir, ipr, xisr;
5076 4642
5077#ifdef DEBUG 4643 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
5078 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5079#endif
5080 4644
5081 cir = stl_sc26198getglobreg(portp, CIR); 4645 cir = stl_sc26198getglobreg(portp, CIR);
5082 4646
@@ -5109,4 +4673,172 @@ static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5109 } 4673 }
5110} 4674}
5111 4675
5112/*****************************************************************************/ 4676static void stl_free_isabrds(void)
4677{
4678 struct stlbrd *brdp;
4679 unsigned int i;
4680
4681 for (i = 0; i < stl_nrbrds; i++) {
4682 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4683 continue;
4684
4685 free_irq(brdp->irq, brdp);
4686
4687 stl_cleanup_panels(brdp);
4688
4689 release_region(brdp->ioaddr1, brdp->iosize1);
4690 if (brdp->iosize2 > 0)
4691 release_region(brdp->ioaddr2, brdp->iosize2);
4692
4693 kfree(brdp);
4694 stl_brds[i] = NULL;
4695 }
4696}
4697
4698/*
4699 * Loadable module initialization stuff.
4700 */
4701static int __init stallion_module_init(void)
4702{
4703 struct stlbrd *brdp;
4704 struct stlconf conf;
4705 unsigned int i, j;
4706 int retval;
4707
4708 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4709
4710 spin_lock_init(&stallion_lock);
4711 spin_lock_init(&brd_lock);
4712
4713/*
4714 * Find any dynamically supported boards. That is via module load
4715 * line options.
4716 */
4717 for (i = stl_nrbrds; i < stl_nargs; i++) {
4718 memset(&conf, 0, sizeof(conf));
4719 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4720 continue;
4721 if ((brdp = stl_allocbrd()) == NULL)
4722 continue;
4723 brdp->brdnr = i;
4724 brdp->brdtype = conf.brdtype;
4725 brdp->ioaddr1 = conf.ioaddr1;
4726 brdp->ioaddr2 = conf.ioaddr2;
4727 brdp->irq = conf.irq;
4728 brdp->irqtype = conf.irqtype;
4729 if (stl_brdinit(brdp))
4730 kfree(brdp);
4731 else {
4732 for (j = 0; j < brdp->nrports; j++)
4733 tty_register_device(stl_serial,
4734 brdp->brdnr * STL_MAXPORTS + j, NULL);
4735 stl_brds[brdp->brdnr] = brdp;
4736 stl_nrbrds = i + 1;
4737 }
4738 }
4739
4740 /* this has to be _after_ isa finding because of locking */
4741 retval = pci_register_driver(&stl_pcidriver);
4742 if (retval && stl_nrbrds == 0)
4743 goto err;
4744
4745 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4746 if (!stl_serial) {
4747 retval = -ENOMEM;
4748 goto err_pcidr;
4749 }
4750
4751/*
4752 * Set up a character driver for per board stuff. This is mainly used
4753 * to do stats ioctls on the ports.
4754 */
4755 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4756 printk("STALLION: failed to register serial board device\n");
4757
4758 stallion_class = class_create(THIS_MODULE, "staliomem");
4759 if (IS_ERR(stallion_class)) {
4760 retval = PTR_ERR(stallion_class);
4761 goto err_reg;
4762 }
4763 for (i = 0; i < 4; i++)
4764 class_device_create(stallion_class, NULL,
4765 MKDEV(STL_SIOMEMMAJOR, i), NULL,
4766 "staliomem%d", i);
4767
4768 stl_serial->owner = THIS_MODULE;
4769 stl_serial->driver_name = stl_drvname;
4770 stl_serial->name = "ttyE";
4771 stl_serial->major = STL_SERIALMAJOR;
4772 stl_serial->minor_start = 0;
4773 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4774 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4775 stl_serial->init_termios = stl_deftermios;
4776 stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4777 tty_set_operations(stl_serial, &stl_ops);
4778
4779 retval = tty_register_driver(stl_serial);
4780 if (retval) {
4781 printk("STALLION: failed to register serial driver\n");
4782 goto err_clsdev;
4783 }
4784
4785 return 0;
4786err_clsdev:
4787 for (i = 0; i < 4; i++)
4788 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4789 class_destroy(stallion_class);
4790err_reg:
4791 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4792 put_tty_driver(stl_serial);
4793err_pcidr:
4794 pci_unregister_driver(&stl_pcidriver);
4795 stl_free_isabrds();
4796err:
4797 return retval;
4798}
4799
4800static void __exit stallion_module_exit(void)
4801{
4802 struct stlbrd *brdp;
4803 unsigned int i, j;
4804 int retval;
4805
4806 pr_debug("cleanup_module()\n");
4807
4808 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4809 stl_drvversion);
4810
4811/*
4812 * Free up all allocated resources used by the ports. This includes
4813 * memory and interrupts. As part of this process we will also do
4814 * a hangup on every open port - to try to flush out any processes
4815 * hanging onto ports.
4816 */
4817 for (i = 0; i < stl_nrbrds; i++) {
4818 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4819 continue;
4820 for (j = 0; j < brdp->nrports; j++)
4821 tty_unregister_device(stl_serial,
4822 brdp->brdnr * STL_MAXPORTS + j);
4823 }
4824 tty_unregister_driver(stl_serial);
4825 put_tty_driver(stl_serial);
4826
4827 for (i = 0; i < 4; i++)
4828 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4829 if ((retval = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
4830 printk("STALLION: failed to un-register serial memory device, "
4831 "errno=%d\n", -retval);
4832 class_destroy(stallion_class);
4833
4834 pci_unregister_driver(&stl_pcidriver);
4835
4836 stl_free_isabrds();
4837}
4838
4839module_init(stallion_module_init);
4840module_exit(stallion_module_exit);
4841
4842MODULE_AUTHOR("Greg Ungerer");
4843MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4844MODULE_LICENSE("GPL");
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index cc10af08cb05..a3008ce13015 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -32,7 +32,6 @@
32 * USA. 32 * USA.
33 * 33 *
34 * Revision history: 34 * Revision history:
35 * $Log: sx.c,v $
36 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff 35 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
37 * - Fixed module and port counting 36 * - Fixed module and port counting
38 * - Fixed signal handling 37 * - Fixed signal handling
@@ -199,9 +198,7 @@
199 * 198 *
200 * */ 199 * */
201 200
202 201#define SX_VERSION 1.33
203#define RCS_ID "$Id: sx.c,v 1.33 2000/03/08 10:01:02 wolff, pvdl Exp $"
204#define RCS_REV "$Revision: 1.33 $"
205 202
206#include <linux/module.h> 203#include <linux/module.h>
207#include <linux/kdev_t.h> 204#include <linux/kdev_t.h>
@@ -217,6 +214,7 @@
217#include <linux/fcntl.h> 214#include <linux/fcntl.h>
218#include <linux/major.h> 215#include <linux/major.h>
219#include <linux/delay.h> 216#include <linux/delay.h>
217#include <linux/eisa.h>
220#include <linux/pci.h> 218#include <linux/pci.h>
221#include <linux/slab.h> 219#include <linux/slab.h>
222#include <linux/init.h> 220#include <linux/init.h>
@@ -240,7 +238,6 @@
240#include <linux/generic_serial.h> 238#include <linux/generic_serial.h>
241#include "sx.h" 239#include "sx.h"
242 240
243
244/* I don't think that this driver can handle more than 256 ports on 241/* I don't think that this driver can handle more than 256 ports on
245 one machine. You'll have to increase the number of boards in sx.h 242 one machine. You'll have to increase the number of boards in sx.h
246 if you want more than 4 boards. */ 243 if you want more than 4 boards. */
@@ -249,21 +246,12 @@
249#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000 246#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
250#endif 247#endif
251 248
252#ifdef CONFIG_PCI
253static struct pci_device_id sx_pci_tbl[] = {
254 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, PCI_ANY_ID, PCI_ANY_ID },
255 { 0 }
256};
257MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
258#endif /* CONFIG_PCI */
259
260/* Configurable options: 249/* Configurable options:
261 (Don't be too sure that it'll work if you toggle them) */ 250 (Don't be too sure that it'll work if you toggle them) */
262 251
263/* Am I paranoid or not ? ;-) */ 252/* Am I paranoid or not ? ;-) */
264#undef SX_PARANOIA_CHECK 253#undef SX_PARANOIA_CHECK
265 254
266
267/* 20 -> 2000 per second. The card should rate-limit interrupts at 100 255/* 20 -> 2000 per second. The card should rate-limit interrupts at 100
268 Hz, but it is user configurable. I don't recommend going above 1000 256 Hz, but it is user configurable. I don't recommend going above 1000
269 Hz. The interrupt ratelimit might trigger if the interrupt is 257 Hz. The interrupt ratelimit might trigger if the interrupt is
@@ -277,7 +265,6 @@ MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
277 interrupt. Use polling. */ 265 interrupt. Use polling. */
278#undef IRQ_RATE_LIMIT 266#undef IRQ_RATE_LIMIT
279 267
280
281#if 0 268#if 0
282/* Not implemented */ 269/* Not implemented */
283/* 270/*
@@ -286,35 +273,33 @@ MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
286 */ 273 */
287#define SX_REPORT_FIFO 274#define SX_REPORT_FIFO
288#define SX_REPORT_OVERRUN 275#define SX_REPORT_OVERRUN
289#endif 276#endif
290
291 277
292/* Function prototypes */ 278/* Function prototypes */
293static void sx_disable_tx_interrupts (void * ptr); 279static void sx_disable_tx_interrupts(void *ptr);
294static void sx_enable_tx_interrupts (void * ptr); 280static void sx_enable_tx_interrupts(void *ptr);
295static void sx_disable_rx_interrupts (void * ptr); 281static void sx_disable_rx_interrupts(void *ptr);
296static void sx_enable_rx_interrupts (void * ptr); 282static void sx_enable_rx_interrupts(void *ptr);
297static int sx_get_CD (void * ptr); 283static int sx_get_CD(void *ptr);
298static void sx_shutdown_port (void * ptr); 284static void sx_shutdown_port(void *ptr);
299static int sx_set_real_termios (void *ptr); 285static int sx_set_real_termios(void *ptr);
300static void sx_close (void *ptr); 286static void sx_close(void *ptr);
301static int sx_chars_in_buffer (void * ptr); 287static int sx_chars_in_buffer(void *ptr);
302static int sx_init_board (struct sx_board *board); 288static int sx_init_board(struct sx_board *board);
303static int sx_init_portstructs (int nboards, int nports); 289static int sx_init_portstructs(int nboards, int nports);
304static int sx_fw_ioctl (struct inode *inode, struct file *filp, 290static int sx_fw_ioctl(struct inode *inode, struct file *filp,
305 unsigned int cmd, unsigned long arg); 291 unsigned int cmd, unsigned long arg);
306static int sx_init_drivers(void); 292static int sx_init_drivers(void);
307 293
308
309static struct tty_driver *sx_driver; 294static struct tty_driver *sx_driver;
310 295
296static DEFINE_MUTEX(sx_boards_lock);
311static struct sx_board boards[SX_NBOARDS]; 297static struct sx_board boards[SX_NBOARDS];
312static struct sx_port *sx_ports; 298static struct sx_port *sx_ports;
313static int sx_initialized; 299static int sx_initialized;
314static int sx_nports; 300static int sx_nports;
315static int sx_debug; 301static int sx_debug;
316 302
317
318/* You can have the driver poll your card. 303/* You can have the driver poll your card.
319 - Set sx_poll to 1 to poll every timer tick (10ms on Intel). 304 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
320 This is used when the card cannot use an interrupt for some reason. 305 This is used when the card cannot use an interrupt for some reason.
@@ -333,27 +318,36 @@ static int sx_slowpoll;
333 318
334static int sx_maxints = 100; 319static int sx_maxints = 100;
335 320
321#ifdef CONFIG_ISA
322
336/* These are the only open spaces in my computer. Yours may have more 323/* These are the only open spaces in my computer. Yours may have more
337 or less.... -- REW 324 or less.... -- REW
338 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl 325 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
339*/ 326*/
340static int sx_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000, 327static int sx_probe_addrs[] = {
341 0xc8000, 0xd8000, 0xe8000}; 328 0xc0000, 0xd0000, 0xe0000,
342static int si_probe_addrs[]= {0xc0000, 0xd0000, 0xe0000, 329 0xc8000, 0xd8000, 0xe8000
343 0xc8000, 0xd8000, 0xe8000, 0xa0000}; 330};
344static int si1_probe_addrs[]= { 0xd0000}; 331static int si_probe_addrs[] = {
332 0xc0000, 0xd0000, 0xe0000,
333 0xc8000, 0xd8000, 0xe8000, 0xa0000
334};
335static int si1_probe_addrs[] = {
336 0xd0000
337};
345 338
346#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs) 339#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs)
347#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs) 340#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs)
348#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs) 341#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs)
349 342
343module_param_array(sx_probe_addrs, int, NULL, 0);
344module_param_array(si_probe_addrs, int, NULL, 0);
345#endif
350 346
351/* Set the mask to all-ones. This alas, only supports 32 interrupts. 347/* Set the mask to all-ones. This alas, only supports 32 interrupts.
352 Some architectures may need more. */ 348 Some architectures may need more. */
353static int sx_irqmask = -1; 349static int sx_irqmask = -1;
354 350
355module_param_array(sx_probe_addrs, int, NULL, 0);
356module_param_array(si_probe_addrs, int, NULL, 0);
357module_param(sx_poll, int, 0); 351module_param(sx_poll, int, 0);
358module_param(sx_slowpoll, int, 0); 352module_param(sx_slowpoll, int, 0);
359module_param(sx_maxints, int, 0); 353module_param(sx_maxints, int, 0);
@@ -368,13 +362,12 @@ static struct real_driver sx_real_driver = {
368 sx_disable_rx_interrupts, 362 sx_disable_rx_interrupts,
369 sx_enable_rx_interrupts, 363 sx_enable_rx_interrupts,
370 sx_get_CD, 364 sx_get_CD,
371 sx_shutdown_port, 365 sx_shutdown_port,
372 sx_set_real_termios, 366 sx_set_real_termios,
373 sx_chars_in_buffer, 367 sx_chars_in_buffer,
374 sx_close, 368 sx_close,
375}; 369};
376 370
377
378/* 371/*
379 This driver can spew a whole lot of debugging output at you. If you 372 This driver can spew a whole lot of debugging output at you. If you
380 need maximum performance, you should disable the DEBUG define. To 373 need maximum performance, you should disable the DEBUG define. To
@@ -385,23 +378,17 @@ static struct real_driver sx_real_driver = {
385*/ 378*/
386#define DEBUG 379#define DEBUG
387 380
388
389#ifdef DEBUG 381#ifdef DEBUG
390#define sx_dprintk(f, str...) if (sx_debug & f) printk (str) 382#define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
391#else 383#else
392#define sx_dprintk(f, str...) /* nothing */ 384#define sx_dprintk(f, str...) /* nothing */
393#endif 385#endif
394 386
387#define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__)
388#define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__FUNCTION__)
395 389
396 390#define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
397#define func_enter() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s\n",__FUNCTION__) 391 __FUNCTION__, port->line)
398#define func_exit() sx_dprintk (SX_DEBUG_FLOW, "sx: exit %s\n", __FUNCTION__)
399
400#define func_enter2() sx_dprintk (SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
401 __FUNCTION__, port->line)
402
403
404
405 392
406/* 393/*
407 * Firmware loader driver specific routines 394 * Firmware loader driver specific routines
@@ -409,31 +396,26 @@ static struct real_driver sx_real_driver = {
409 */ 396 */
410 397
411static const struct file_operations sx_fw_fops = { 398static const struct file_operations sx_fw_fops = {
412 .owner = THIS_MODULE, 399 .owner = THIS_MODULE,
413 .ioctl = sx_fw_ioctl, 400 .ioctl = sx_fw_ioctl,
414}; 401};
415 402
416static struct miscdevice sx_fw_device = { 403static struct miscdevice sx_fw_device = {
417 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops 404 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
418}; 405};
419 406
420
421
422
423
424#ifdef SX_PARANOIA_CHECK 407#ifdef SX_PARANOIA_CHECK
425 408
426/* This doesn't work. Who's paranoid around here? Not me! */ 409/* This doesn't work. Who's paranoid around here? Not me! */
427 410
428static inline int sx_paranoia_check(struct sx_port const * port, 411static inline int sx_paranoia_check(struct sx_port const *port,
429 char *name, const char *routine) 412 char *name, const char *routine)
430{ 413{
414 static const char *badmagic = KERN_ERR "sx: Warning: bad sx port magic "
415 "number for device %s in %s\n";
416 static const char *badinfo = KERN_ERR "sx: Warning: null sx port for "
417 "device %s in %s\n";
431 418
432 static const char *badmagic =
433 KERN_ERR "sx: Warning: bad sx port magic number for device %s in %s\n";
434 static const char *badinfo =
435 KERN_ERR "sx: Warning: null sx port for device %s in %s\n";
436
437 if (!port) { 419 if (!port) {
438 printk(badinfo, name, routine); 420 printk(badinfo, name, routine);
439 return 1; 421 return 1;
@@ -456,23 +438,24 @@ static inline int sx_paranoia_check(struct sx_port const * port,
456#define TIMEOUT_1 30 438#define TIMEOUT_1 30
457#define TIMEOUT_2 1000000 439#define TIMEOUT_2 1000000
458 440
459
460#ifdef DEBUG 441#ifdef DEBUG
461static void my_hd_io(void __iomem *p, int len) 442static void my_hd_io(void __iomem *p, int len)
462{ 443{
463 int i, j, ch; 444 int i, j, ch;
464 unsigned char __iomem *addr = p; 445 unsigned char __iomem *addr = p;
465 446
466 for (i=0;i<len;i+=16) { 447 for (i = 0; i < len; i += 16) {
467 printk ("%p ", addr+i); 448 printk("%p ", addr + i);
468 for (j=0;j<16;j++) { 449 for (j = 0; j < 16; j++) {
469 printk ("%02x %s", readb(addr+j+i), (j==7)?" ":""); 450 printk("%02x %s", readb(addr + j + i),
451 (j == 7) ? " " : "");
470 } 452 }
471 for (j=0;j<16;j++) { 453 for (j = 0; j < 16; j++) {
472 ch = readb(addr+j+i); 454 ch = readb(addr + j + i);
473 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); 455 printk("%c", (ch < 0x20) ? '.' :
456 ((ch > 0x7f) ? '.' : ch));
474 } 457 }
475 printk ("\n"); 458 printk("\n");
476 } 459 }
477} 460}
478static void my_hd(void *p, int len) 461static void my_hd(void *p, int len)
@@ -480,419 +463,468 @@ static void my_hd(void *p, int len)
480 int i, j, ch; 463 int i, j, ch;
481 unsigned char *addr = p; 464 unsigned char *addr = p;
482 465
483 for (i=0;i<len;i+=16) { 466 for (i = 0; i < len; i += 16) {
484 printk ("%p ", addr+i); 467 printk("%p ", addr + i);
485 for (j=0;j<16;j++) { 468 for (j = 0; j < 16; j++) {
486 printk ("%02x %s", addr[j+i], (j==7)?" ":""); 469 printk("%02x %s", addr[j + i], (j == 7) ? " " : "");
487 } 470 }
488 for (j=0;j<16;j++) { 471 for (j = 0; j < 16; j++) {
489 ch = addr[j+i]; 472 ch = addr[j + i];
490 printk ("%c", (ch < 0x20)?'.':((ch > 0x7f)?'.':ch)); 473 printk("%c", (ch < 0x20) ? '.' :
474 ((ch > 0x7f) ? '.' : ch));
491 } 475 }
492 printk ("\n"); 476 printk("\n");
493 } 477 }
494} 478}
495#endif 479#endif
496 480
497
498
499/* This needs redoing for Alpha -- REW -- Done. */ 481/* This needs redoing for Alpha -- REW -- Done. */
500 482
501static inline void write_sx_byte (struct sx_board *board, int offset, u8 byte) 483static inline void write_sx_byte(struct sx_board *board, int offset, u8 byte)
502{ 484{
503 writeb (byte, board->base+offset); 485 writeb(byte, board->base + offset);
504} 486}
505 487
506static inline u8 read_sx_byte (struct sx_board *board, int offset) 488static inline u8 read_sx_byte(struct sx_board *board, int offset)
507{ 489{
508 return readb (board->base+offset); 490 return readb(board->base + offset);
509} 491}
510 492
511 493static inline void write_sx_word(struct sx_board *board, int offset, u16 word)
512static inline void write_sx_word (struct sx_board *board, int offset, u16 word)
513{ 494{
514 writew (word, board->base+offset); 495 writew(word, board->base + offset);
515} 496}
516 497
517static inline u16 read_sx_word (struct sx_board *board, int offset) 498static inline u16 read_sx_word(struct sx_board *board, int offset)
518{ 499{
519 return readw (board->base + offset); 500 return readw(board->base + offset);
520} 501}
521 502
522 503static int sx_busy_wait_eq(struct sx_board *board,
523static int sx_busy_wait_eq (struct sx_board *board, 504 int offset, int mask, int correctval)
524 int offset, int mask, int correctval)
525{ 505{
526 int i; 506 int i;
527 507
528 func_enter (); 508 func_enter();
529 509
530 for (i=0; i < TIMEOUT_1 ;i++) 510 for (i = 0; i < TIMEOUT_1; i++)
531 if ((read_sx_byte (board, offset) & mask) == correctval) { 511 if ((read_sx_byte(board, offset) & mask) == correctval) {
532 func_exit (); 512 func_exit();
533 return 1; 513 return 1;
534 } 514 }
535 515
536 for (i=0; i < TIMEOUT_2 ;i++) { 516 for (i = 0; i < TIMEOUT_2; i++) {
537 if ((read_sx_byte (board, offset) & mask) == correctval) { 517 if ((read_sx_byte(board, offset) & mask) == correctval) {
538 func_exit (); 518 func_exit();
539 return 1; 519 return 1;
540 } 520 }
541 udelay (1); 521 udelay(1);
542 } 522 }
543 523
544 func_exit (); 524 func_exit();
545 return 0; 525 return 0;
546} 526}
547 527
548 528static int sx_busy_wait_neq(struct sx_board *board,
549static int sx_busy_wait_neq (struct sx_board *board, 529 int offset, int mask, int badval)
550 int offset, int mask, int badval)
551{ 530{
552 int i; 531 int i;
553 532
554 func_enter (); 533 func_enter();
555 534
556 for (i=0; i < TIMEOUT_1 ;i++) 535 for (i = 0; i < TIMEOUT_1; i++)
557 if ((read_sx_byte (board, offset) & mask) != badval) { 536 if ((read_sx_byte(board, offset) & mask) != badval) {
558 func_exit (); 537 func_exit();
559 return 1; 538 return 1;
560 } 539 }
561 540
562 for (i=0; i < TIMEOUT_2 ;i++) { 541 for (i = 0; i < TIMEOUT_2; i++) {
563 if ((read_sx_byte (board, offset) & mask) != badval) { 542 if ((read_sx_byte(board, offset) & mask) != badval) {
564 func_exit (); 543 func_exit();
565 return 1; 544 return 1;
566 } 545 }
567 udelay (1); 546 udelay(1);
568 } 547 }
569 548
570 func_exit (); 549 func_exit();
571 return 0; 550 return 0;
572} 551}
573 552
574
575
576/* 5.6.4 of 6210028 r2.3 */ 553/* 5.6.4 of 6210028 r2.3 */
577static int sx_reset (struct sx_board *board) 554static int sx_reset(struct sx_board *board)
578{ 555{
579 func_enter (); 556 func_enter();
580 557
581 if (IS_SX_BOARD (board)) { 558 if (IS_SX_BOARD(board)) {
582 559
583 write_sx_byte (board, SX_CONFIG, 0); 560 write_sx_byte(board, SX_CONFIG, 0);
584 write_sx_byte (board, SX_RESET, 1); /* Value doesn't matter */ 561 write_sx_byte(board, SX_RESET, 1); /* Value doesn't matter */
585 562
586 if (!sx_busy_wait_eq (board, SX_RESET_STATUS, 1, 0)) { 563 if (!sx_busy_wait_eq(board, SX_RESET_STATUS, 1, 0)) {
587 printk (KERN_INFO "sx: Card doesn't respond to reset....\n"); 564 printk(KERN_INFO "sx: Card doesn't respond to "
565 "reset...\n");
588 return 0; 566 return 0;
589 } 567 }
590 } else if (IS_EISA_BOARD(board)) { 568 } else if (IS_EISA_BOARD(board)) {
591 outb(board->irq<<4, board->eisa_base+0xc02); 569 outb(board->irq << 4, board->eisa_base + 0xc02);
592 } else if (IS_SI1_BOARD(board)) { 570 } else if (IS_SI1_BOARD(board)) {
593 write_sx_byte (board, SI1_ISA_RESET, 0); // value does not matter 571 write_sx_byte(board, SI1_ISA_RESET, 0); /*value doesn't matter*/
594 } else { 572 } else {
595 /* Gory details of the SI/ISA board */ 573 /* Gory details of the SI/ISA board */
596 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_SET); 574 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
597 write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR); 575 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
598 write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR); 576 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
599 write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR); 577 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
600 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR); 578 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
601 write_sx_byte (board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR); 579 write_sx_byte(board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
602 } 580 }
603 581
604 func_exit (); 582 func_exit();
605 return 1; 583 return 1;
606} 584}
607 585
608
609/* This doesn't work on machines where "NULL" isn't 0 */ 586/* This doesn't work on machines where "NULL" isn't 0 */
610/* If you have one of those, someone will need to write 587/* If you have one of those, someone will need to write
611 the equivalent of this, which will amount to about 3 lines. I don't 588 the equivalent of this, which will amount to about 3 lines. I don't
612 want to complicate this right now. -- REW 589 want to complicate this right now. -- REW
613 (See, I do write comments every now and then :-) */ 590 (See, I do write comments every now and then :-) */
614#define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem)) 591#define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
615
616
617#define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
618#define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
619#define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
620 592
593#define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
594#define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
595#define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
621 596
622#define sx_write_channel_byte(port, elem, val) \ 597#define sx_write_channel_byte(port, elem, val) \
623 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val) 598 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
624 599
625#define sx_read_channel_byte(port, elem) \ 600#define sx_read_channel_byte(port, elem) \
626 read_sx_byte (port->board, CHAN_OFFSET (port, elem)) 601 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
627 602
628#define sx_write_channel_word(port, elem, val) \ 603#define sx_write_channel_word(port, elem, val) \
629 write_sx_word (port->board, CHAN_OFFSET (port, elem), val) 604 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
630 605
631#define sx_read_channel_word(port, elem) \ 606#define sx_read_channel_word(port, elem) \
632 read_sx_word (port->board, CHAN_OFFSET (port, elem)) 607 read_sx_word (port->board, CHAN_OFFSET (port, elem))
633
634 608
635#define sx_write_module_byte(board, addr, elem, val) \ 609#define sx_write_module_byte(board, addr, elem, val) \
636 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val) 610 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
637 611
638#define sx_read_module_byte(board, addr, elem) \ 612#define sx_read_module_byte(board, addr, elem) \
639 read_sx_byte (board, MODU_OFFSET (board, addr, elem)) 613 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
640 614
641#define sx_write_module_word(board, addr, elem, val) \ 615#define sx_write_module_word(board, addr, elem, val) \
642 write_sx_word (board, MODU_OFFSET (board, addr, elem), val) 616 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
643 617
644#define sx_read_module_word(board, addr, elem) \ 618#define sx_read_module_word(board, addr, elem) \
645 read_sx_word (board, MODU_OFFSET (board, addr, elem)) 619 read_sx_word (board, MODU_OFFSET (board, addr, elem))
646
647 620
648#define sx_write_board_byte(board, elem, val) \ 621#define sx_write_board_byte(board, elem, val) \
649 write_sx_byte (board, BRD_OFFSET (board, elem), val) 622 write_sx_byte (board, BRD_OFFSET (board, elem), val)
650 623
651#define sx_read_board_byte(board, elem) \ 624#define sx_read_board_byte(board, elem) \
652 read_sx_byte (board, BRD_OFFSET (board, elem)) 625 read_sx_byte (board, BRD_OFFSET (board, elem))
653 626
654#define sx_write_board_word(board, elem, val) \ 627#define sx_write_board_word(board, elem, val) \
655 write_sx_word (board, BRD_OFFSET (board, elem), val) 628 write_sx_word (board, BRD_OFFSET (board, elem), val)
656 629
657#define sx_read_board_word(board, elem) \ 630#define sx_read_board_word(board, elem) \
658 read_sx_word (board, BRD_OFFSET (board, elem)) 631 read_sx_word (board, BRD_OFFSET (board, elem))
659
660 632
661static int sx_start_board (struct sx_board *board) 633static int sx_start_board(struct sx_board *board)
662{ 634{
663 if (IS_SX_BOARD (board)) { 635 if (IS_SX_BOARD(board)) {
664 write_sx_byte (board, SX_CONFIG, SX_CONF_BUSEN); 636 write_sx_byte(board, SX_CONFIG, SX_CONF_BUSEN);
665 } else if (IS_EISA_BOARD(board)) { 637 } else if (IS_EISA_BOARD(board)) {
666 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL); 638 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
667 outb((board->irq<<4)|4, board->eisa_base+0xc02); 639 outb((board->irq << 4) | 4, board->eisa_base + 0xc02);
668 } else if (IS_SI1_BOARD(board)) { 640 } else if (IS_SI1_BOARD(board)) {
669 write_sx_byte (board, SI1_ISA_RESET_CLEAR, 0); 641 write_sx_byte(board, SI1_ISA_RESET_CLEAR, 0);
670 write_sx_byte (board, SI1_ISA_INTCL, 0); 642 write_sx_byte(board, SI1_ISA_INTCL, 0);
671 } else { 643 } else {
672 /* Don't bug me about the clear_set. 644 /* Don't bug me about the clear_set.
673 I haven't the foggiest idea what it's about -- REW */ 645 I haven't the foggiest idea what it's about -- REW */
674 write_sx_byte (board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR); 646 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
675 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 647 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
676 } 648 }
677 return 1; 649 return 1;
678} 650}
679 651
680#define SX_IRQ_REG_VAL(board) \ 652#define SX_IRQ_REG_VAL(board) \
681 ((board->flags & SX_ISA_BOARD)?(board->irq << 4):0) 653 ((board->flags & SX_ISA_BOARD) ? (board->irq << 4) : 0)
682 654
683/* Note. The SX register is write-only. Therefore, we have to enable the 655/* Note. The SX register is write-only. Therefore, we have to enable the
684 bus too. This is a no-op, if you don't mess with this driver... */ 656 bus too. This is a no-op, if you don't mess with this driver... */
685static int sx_start_interrupts (struct sx_board *board) 657static int sx_start_interrupts(struct sx_board *board)
686{ 658{
687 659
688 /* Don't call this with board->irq == 0 */ 660 /* Don't call this with board->irq == 0 */
689 661
690 if (IS_SX_BOARD(board)) { 662 if (IS_SX_BOARD(board)) {
691 write_sx_byte (board, SX_CONFIG, SX_IRQ_REG_VAL (board) | 663 write_sx_byte(board, SX_CONFIG, SX_IRQ_REG_VAL(board) |
692 SX_CONF_BUSEN | 664 SX_CONF_BUSEN | SX_CONF_HOSTIRQ);
693 SX_CONF_HOSTIRQ);
694 } else if (IS_EISA_BOARD(board)) { 665 } else if (IS_EISA_BOARD(board)) {
695 inb(board->eisa_base+0xc03); 666 inb(board->eisa_base + 0xc03);
696 } else if (IS_SI1_BOARD(board)) { 667 } else if (IS_SI1_BOARD(board)) {
697 write_sx_byte (board, SI1_ISA_INTCL,0); 668 write_sx_byte(board, SI1_ISA_INTCL, 0);
698 write_sx_byte (board, SI1_ISA_INTCL_CLEAR,0); 669 write_sx_byte(board, SI1_ISA_INTCL_CLEAR, 0);
699 } else { 670 } else {
700 switch (board->irq) { 671 switch (board->irq) {
701 case 11:write_sx_byte (board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);break; 672 case 11:
702 case 12:write_sx_byte (board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);break; 673 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);
703 case 15:write_sx_byte (board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);break; 674 break;
704 default:printk (KERN_INFO "sx: SI/XIO card doesn't support interrupt %d.\n", 675 case 12:
705 board->irq); 676 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);
706 return 0; 677 break;
678 case 15:
679 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);
680 break;
681 default:
682 printk(KERN_INFO "sx: SI/XIO card doesn't support "
683 "interrupt %d.\n", board->irq);
684 return 0;
707 } 685 }
708 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 686 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
709 } 687 }
710 688
711 return 1; 689 return 1;
712} 690}
713 691
714 692static int sx_send_command(struct sx_port *port,
715static int sx_send_command (struct sx_port *port, 693 int command, int mask, int newstat)
716 int command, int mask, int newstat)
717{ 694{
718 func_enter2 (); 695 func_enter2();
719 write_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat), command); 696 write_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat), command);
720 func_exit (); 697 func_exit();
721 return sx_busy_wait_eq (port->board, CHAN_OFFSET (port, hi_hstat), mask, newstat); 698 return sx_busy_wait_eq(port->board, CHAN_OFFSET(port, hi_hstat), mask,
699 newstat);
722} 700}
723 701
724 702static char *mod_type_s(int module_type)
725static char *mod_type_s (int module_type)
726{ 703{
727 switch (module_type) { 704 switch (module_type) {
728 case TA4: return "TA4"; 705 case TA4:
729 case TA8: return "TA8"; 706 return "TA4";
730 case TA4_ASIC: return "TA4_ASIC"; 707 case TA8:
731 case TA8_ASIC: return "TA8_ASIC"; 708 return "TA8";
732 case MTA_CD1400:return "MTA_CD1400"; 709 case TA4_ASIC:
733 case SXDC: return "SXDC"; 710 return "TA4_ASIC";
734 default:return "Unknown/invalid"; 711 case TA8_ASIC:
712 return "TA8_ASIC";
713 case MTA_CD1400:
714 return "MTA_CD1400";
715 case SXDC:
716 return "SXDC";
717 default:
718 return "Unknown/invalid";
735 } 719 }
736} 720}
737 721
738 722static char *pan_type_s(int pan_type)
739static char *pan_type_s (int pan_type)
740{ 723{
741 switch (pan_type) { 724 switch (pan_type) {
742 case MOD_RS232DB25: return "MOD_RS232DB25"; 725 case MOD_RS232DB25:
743 case MOD_RS232RJ45: return "MOD_RS232RJ45"; 726 return "MOD_RS232DB25";
744 case MOD_RS422DB25: return "MOD_RS422DB25"; 727 case MOD_RS232RJ45:
745 case MOD_PARALLEL: return "MOD_PARALLEL"; 728 return "MOD_RS232RJ45";
746 case MOD_2_RS232DB25: return "MOD_2_RS232DB25"; 729 case MOD_RS422DB25:
747 case MOD_2_RS232RJ45: return "MOD_2_RS232RJ45"; 730 return "MOD_RS422DB25";
748 case MOD_2_RS422DB25: return "MOD_2_RS422DB25"; 731 case MOD_PARALLEL:
749 case MOD_RS232DB25MALE: return "MOD_RS232DB25MALE"; 732 return "MOD_PARALLEL";
750 case MOD_2_PARALLEL: return "MOD_2_PARALLEL"; 733 case MOD_2_RS232DB25:
751 case MOD_BLANK: return "empty"; 734 return "MOD_2_RS232DB25";
752 default:return "invalid"; 735 case MOD_2_RS232RJ45:
736 return "MOD_2_RS232RJ45";
737 case MOD_2_RS422DB25:
738 return "MOD_2_RS422DB25";
739 case MOD_RS232DB25MALE:
740 return "MOD_RS232DB25MALE";
741 case MOD_2_PARALLEL:
742 return "MOD_2_PARALLEL";
743 case MOD_BLANK:
744 return "empty";
745 default:
746 return "invalid";
753 } 747 }
754} 748}
755 749
756 750static int mod_compat_type(int module_type)
757static int mod_compat_type (int module_type)
758{ 751{
759 return module_type >> 4; 752 return module_type >> 4;
760} 753}
761 754
762static void sx_reconfigure_port(struct sx_port *port) 755static void sx_reconfigure_port(struct sx_port *port)
763{ 756{
764 if (sx_read_channel_byte (port, hi_hstat) == HS_IDLE_OPEN) { 757 if (sx_read_channel_byte(port, hi_hstat) == HS_IDLE_OPEN) {
765 if (sx_send_command (port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) { 758 if (sx_send_command(port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
766 printk (KERN_WARNING "sx: Sent reconfigure command, but card didn't react.\n"); 759 printk(KERN_WARNING "sx: Sent reconfigure command, but "
760 "card didn't react.\n");
767 } 761 }
768 } else { 762 } else {
769 sx_dprintk (SX_DEBUG_TERMIOS, 763 sx_dprintk(SX_DEBUG_TERMIOS, "sx: Not sending reconfigure: "
770 "sx: Not sending reconfigure: port isn't open (%02x).\n", 764 "port isn't open (%02x).\n",
771 sx_read_channel_byte (port, hi_hstat)); 765 sx_read_channel_byte(port, hi_hstat));
772 } 766 }
773} 767}
774 768
775static void sx_setsignals (struct sx_port *port, int dtr, int rts) 769static void sx_setsignals(struct sx_port *port, int dtr, int rts)
776{ 770{
777 int t; 771 int t;
778 func_enter2 (); 772 func_enter2();
779 773
780 t = sx_read_channel_byte (port, hi_op); 774 t = sx_read_channel_byte(port, hi_op);
781 if (dtr >= 0) t = dtr? (t | OP_DTR): (t & ~OP_DTR); 775 if (dtr >= 0)
782 if (rts >= 0) t = rts? (t | OP_RTS): (t & ~OP_RTS); 776 t = dtr ? (t | OP_DTR) : (t & ~OP_DTR);
783 sx_write_channel_byte (port, hi_op, t); 777 if (rts >= 0)
784 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts); 778 t = rts ? (t | OP_RTS) : (t & ~OP_RTS);
779 sx_write_channel_byte(port, hi_op, t);
780 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
785 781
786 func_exit (); 782 func_exit();
787} 783}
788 784
789 785static int sx_getsignals(struct sx_port *port)
790
791static int sx_getsignals (struct sx_port *port)
792{ 786{
793 int i_stat,o_stat; 787 int i_stat, o_stat;
794 788
795 o_stat = sx_read_channel_byte (port, hi_op); 789 o_stat = sx_read_channel_byte(port, hi_op);
796 i_stat = sx_read_channel_byte (port, hi_ip); 790 i_stat = sx_read_channel_byte(port, hi_ip);
797 791
798 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) %02x/%02x\n", 792 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) "
799 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0, 793 "%02x/%02x\n",
800 port->c_dcd, sx_get_CD (port), 794 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
801 sx_read_channel_byte (port, hi_ip), 795 port->c_dcd, sx_get_CD(port),
802 sx_read_channel_byte (port, hi_state)); 796 sx_read_channel_byte(port, hi_ip),
803 797 sx_read_channel_byte(port, hi_state));
804 return (((o_stat & OP_DTR)?TIOCM_DTR:0) | 798
805 ((o_stat & OP_RTS)?TIOCM_RTS:0) | 799 return (((o_stat & OP_DTR) ? TIOCM_DTR : 0) |
806 ((i_stat & IP_CTS)?TIOCM_CTS:0) | 800 ((o_stat & OP_RTS) ? TIOCM_RTS : 0) |
807 ((i_stat & IP_DCD)?TIOCM_CAR:0) | 801 ((i_stat & IP_CTS) ? TIOCM_CTS : 0) |
808 ((i_stat & IP_DSR)?TIOCM_DSR:0) | 802 ((i_stat & IP_DCD) ? TIOCM_CAR : 0) |
809 ((i_stat & IP_RI)?TIOCM_RNG:0) 803 ((i_stat & IP_DSR) ? TIOCM_DSR : 0) |
810 ); 804 ((i_stat & IP_RI) ? TIOCM_RNG : 0));
811} 805}
812 806
813 807static void sx_set_baud(struct sx_port *port)
814static void sx_set_baud (struct sx_port *port)
815{ 808{
816 int t; 809 int t;
817 810
818 if (port->board->ta_type == MOD_SXDC) { 811 if (port->board->ta_type == MOD_SXDC) {
819 switch (port->gs.baud) { 812 switch (port->gs.baud) {
820 /* Save some typing work... */ 813 /* Save some typing work... */
821#define e(x) case x:t= BAUD_ ## x ; break 814#define e(x) case x: t = BAUD_ ## x; break
822 e(50);e(75);e(110);e(150);e(200);e(300);e(600); 815 e(50);
823 e(1200);e(1800);e(2000);e(2400);e(4800);e(7200); 816 e(75);
824 e(9600);e(14400);e(19200);e(28800);e(38400); 817 e(110);
825 e(56000);e(57600);e(64000);e(76800);e(115200); 818 e(150);
826 e(128000);e(150000);e(230400);e(256000);e(460800); 819 e(200);
827 e(921600); 820 e(300);
828 case 134 :t = BAUD_134_5; break; 821 e(600);
829 case 0 :t = -1; 822 e(1200);
830 break; 823 e(1800);
824 e(2000);
825 e(2400);
826 e(4800);
827 e(7200);
828 e(9600);
829 e(14400);
830 e(19200);
831 e(28800);
832 e(38400);
833 e(56000);
834 e(57600);
835 e(64000);
836 e(76800);
837 e(115200);
838 e(128000);
839 e(150000);
840 e(230400);
841 e(256000);
842 e(460800);
843 e(921600);
844 case 134:
845 t = BAUD_134_5;
846 break;
847 case 0:
848 t = -1;
849 break;
831 default: 850 default:
832 /* Can I return "invalid"? */ 851 /* Can I return "invalid"? */
833 t = BAUD_9600; 852 t = BAUD_9600;
834 printk (KERN_INFO "sx: unsupported baud rate: %d.\n", port->gs.baud); 853 printk(KERN_INFO "sx: unsupported baud rate: %d.\n",
854 port->gs.baud);
835 break; 855 break;
836 } 856 }
837#undef e 857#undef e
838 if (t > 0) { 858 if (t > 0) {
839 /* The baud rate is not set to 0, so we're enabeling DTR... -- REW */ 859/* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
840 sx_setsignals (port, 1, -1); 860 sx_setsignals(port, 1, -1);
841 /* XXX This is not TA & MTA compatible */ 861 /* XXX This is not TA & MTA compatible */
842 sx_write_channel_byte (port, hi_csr, 0xff); 862 sx_write_channel_byte(port, hi_csr, 0xff);
843 863
844 sx_write_channel_byte (port, hi_txbaud, t); 864 sx_write_channel_byte(port, hi_txbaud, t);
845 sx_write_channel_byte (port, hi_rxbaud, t); 865 sx_write_channel_byte(port, hi_rxbaud, t);
846 } else { 866 } else {
847 sx_setsignals (port, 0, -1); 867 sx_setsignals(port, 0, -1);
848 } 868 }
849 } else { 869 } else {
850 switch (port->gs.baud) { 870 switch (port->gs.baud) {
851#define e(x) case x:t= CSR_ ## x ; break 871#define e(x) case x: t = CSR_ ## x; break
852 e(75);e(150);e(300);e(600);e(1200);e(2400);e(4800); 872 e(75);
853 e(1800);e(9600); 873 e(150);
854 e(19200);e(57600);e(38400); 874 e(300);
855 /* TA supports 110, but not 115200, MTA supports 115200, but not 110 */ 875 e(600);
856 case 110: 876 e(1200);
877 e(2400);
878 e(4800);
879 e(1800);
880 e(9600);
881 e(19200);
882 e(57600);
883 e(38400);
884/* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
885 case 110:
857 if (port->board->ta_type == MOD_TA) { 886 if (port->board->ta_type == MOD_TA) {
858 t = CSR_110; 887 t = CSR_110;
859 break; 888 break;
860 } else { 889 } else {
861 t = CSR_9600; 890 t = CSR_9600;
862 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 891 printk(KERN_INFO "sx: Unsupported baud rate: "
892 "%d.\n", port->gs.baud);
863 break; 893 break;
864 } 894 }
865 case 115200: 895 case 115200:
866 if (port->board->ta_type == MOD_TA) { 896 if (port->board->ta_type == MOD_TA) {
867 t = CSR_9600; 897 t = CSR_9600;
868 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 898 printk(KERN_INFO "sx: Unsupported baud rate: "
899 "%d.\n", port->gs.baud);
869 break; 900 break;
870 } else { 901 } else {
871 t = CSR_110; 902 t = CSR_110;
872 break; 903 break;
873 } 904 }
874 case 0 :t = -1; 905 case 0:
875 break; 906 t = -1;
907 break;
876 default: 908 default:
877 t = CSR_9600; 909 t = CSR_9600;
878 printk (KERN_INFO "sx: Unsupported baud rate: %d.\n", port->gs.baud); 910 printk(KERN_INFO "sx: Unsupported baud rate: %d.\n",
911 port->gs.baud);
879 break; 912 break;
880 } 913 }
881#undef e 914#undef e
882 if (t >= 0) { 915 if (t >= 0) {
883 sx_setsignals (port, 1, -1); 916 sx_setsignals(port, 1, -1);
884 sx_write_channel_byte (port, hi_csr, t * 0x11); 917 sx_write_channel_byte(port, hi_csr, t * 0x11);
885 } else { 918 } else {
886 sx_setsignals (port, 0, -1); 919 sx_setsignals(port, 0, -1);
887 } 920 }
888 } 921 }
889} 922}
890 923
891
892/* Simon Allen's version of this routine was 225 lines long. 85 is a lot 924/* Simon Allen's version of this routine was 225 lines long. 85 is a lot
893 better. -- REW */ 925 better. -- REW */
894 926
895static int sx_set_real_termios (void *ptr) 927static int sx_set_real_termios(void *ptr)
896{ 928{
897 struct sx_port *port = ptr; 929 struct sx_port *port = ptr;
898 930
@@ -907,80 +939,83 @@ static int sx_set_real_termios (void *ptr)
907 belongs (next to the drop dtr if baud == 0) -- REW */ 939 belongs (next to the drop dtr if baud == 0) -- REW */
908 /* sx_setsignals (port, 1, -1); */ 940 /* sx_setsignals (port, 1, -1); */
909 941
910 sx_set_baud (port); 942 sx_set_baud(port);
911 943
912#define CFLAG port->gs.tty->termios->c_cflag 944#define CFLAG port->gs.tty->termios->c_cflag
913 sx_write_channel_byte (port, hi_mr1, 945 sx_write_channel_byte(port, hi_mr1,
914 (C_PARENB (port->gs.tty)? MR1_WITH:MR1_NONE) | 946 (C_PARENB(port->gs.tty) ? MR1_WITH : MR1_NONE) |
915 (C_PARODD (port->gs.tty)? MR1_ODD:MR1_EVEN) | 947 (C_PARODD(port->gs.tty) ? MR1_ODD : MR1_EVEN) |
916 (C_CRTSCTS(port->gs.tty)? MR1_RTS_RXFLOW:0) | 948 (C_CRTSCTS(port->gs.tty) ? MR1_RTS_RXFLOW : 0) |
917 (((CFLAG & CSIZE)==CS8) ? MR1_8_BITS:0) | 949 (((CFLAG & CSIZE) == CS8) ? MR1_8_BITS : 0) |
918 (((CFLAG & CSIZE)==CS7) ? MR1_7_BITS:0) | 950 (((CFLAG & CSIZE) == CS7) ? MR1_7_BITS : 0) |
919 (((CFLAG & CSIZE)==CS6) ? MR1_6_BITS:0) | 951 (((CFLAG & CSIZE) == CS6) ? MR1_6_BITS : 0) |
920 (((CFLAG & CSIZE)==CS5) ? MR1_5_BITS:0) ); 952 (((CFLAG & CSIZE) == CS5) ? MR1_5_BITS : 0));
921 953
922 sx_write_channel_byte (port, hi_mr2, 954 sx_write_channel_byte(port, hi_mr2,
923 (C_CRTSCTS(port->gs.tty)?MR2_CTS_TXFLOW:0) | 955 (C_CRTSCTS(port->gs.tty) ? MR2_CTS_TXFLOW : 0) |
924 (C_CSTOPB (port->gs.tty)?MR2_2_STOP:MR2_1_STOP)); 956 (C_CSTOPB(port->gs.tty) ? MR2_2_STOP :
957 MR2_1_STOP));
925 958
926 switch (CFLAG & CSIZE) { 959 switch (CFLAG & CSIZE) {
927 case CS8:sx_write_channel_byte (port, hi_mask, 0xff);break; 960 case CS8:
928 case CS7:sx_write_channel_byte (port, hi_mask, 0x7f);break; 961 sx_write_channel_byte(port, hi_mask, 0xff);
929 case CS6:sx_write_channel_byte (port, hi_mask, 0x3f);break; 962 break;
930 case CS5:sx_write_channel_byte (port, hi_mask, 0x1f);break; 963 case CS7:
964 sx_write_channel_byte(port, hi_mask, 0x7f);
965 break;
966 case CS6:
967 sx_write_channel_byte(port, hi_mask, 0x3f);
968 break;
969 case CS5:
970 sx_write_channel_byte(port, hi_mask, 0x1f);
971 break;
931 default: 972 default:
932 printk (KERN_INFO "sx: Invalid wordsize: %u\n", CFLAG & CSIZE); 973 printk(KERN_INFO "sx: Invalid wordsize: %u\n", CFLAG & CSIZE);
933 break; 974 break;
934 } 975 }
935 976
936 sx_write_channel_byte (port, hi_prtcl, 977 sx_write_channel_byte(port, hi_prtcl,
937 (I_IXON (port->gs.tty)?SP_TXEN:0) | 978 (I_IXON(port->gs.tty) ? SP_TXEN : 0) |
938 (I_IXOFF (port->gs.tty)?SP_RXEN:0) | 979 (I_IXOFF(port->gs.tty) ? SP_RXEN : 0) |
939 (I_IXANY (port->gs.tty)?SP_TANY:0) | 980 (I_IXANY(port->gs.tty) ? SP_TANY : 0) | SP_DCEN);
940 SP_DCEN);
941 981
942 sx_write_channel_byte (port, hi_break, 982 sx_write_channel_byte(port, hi_break,
943 (I_IGNBRK(port->gs.tty)?BR_IGN:0 | 983 (I_IGNBRK(port->gs.tty) ? BR_IGN : 0 |
944 I_BRKINT(port->gs.tty)?BR_INT:0)); 984 I_BRKINT(port->gs.tty) ? BR_INT : 0));
945 985
946 sx_write_channel_byte (port, hi_txon, START_CHAR (port->gs.tty)); 986 sx_write_channel_byte(port, hi_txon, START_CHAR(port->gs.tty));
947 sx_write_channel_byte (port, hi_rxon, START_CHAR (port->gs.tty)); 987 sx_write_channel_byte(port, hi_rxon, START_CHAR(port->gs.tty));
948 sx_write_channel_byte (port, hi_txoff, STOP_CHAR (port->gs.tty)); 988 sx_write_channel_byte(port, hi_txoff, STOP_CHAR(port->gs.tty));
949 sx_write_channel_byte (port, hi_rxoff, STOP_CHAR (port->gs.tty)); 989 sx_write_channel_byte(port, hi_rxoff, STOP_CHAR(port->gs.tty));
950 990
951 sx_reconfigure_port(port); 991 sx_reconfigure_port(port);
952 992
953 /* Tell line discipline whether we will do input cooking */ 993 /* Tell line discipline whether we will do input cooking */
954 if(I_OTHER(port->gs.tty)) { 994 if (I_OTHER(port->gs.tty)) {
955 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags); 995 clear_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
956 } else { 996 } else {
957 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags); 997 set_bit(TTY_HW_COOK_IN, &port->gs.tty->flags);
958 } 998 }
959 sx_dprintk (SX_DEBUG_TERMIOS, "iflags: %x(%d) ", 999 sx_dprintk(SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
960 port->gs.tty->termios->c_iflag, 1000 port->gs.tty->termios->c_iflag, I_OTHER(port->gs.tty));
961 I_OTHER(port->gs.tty));
962
963 1001
964/* Tell line discipline whether we will do output cooking. 1002/* Tell line discipline whether we will do output cooking.
965 * If OPOST is set and no other output flags are set then we can do output 1003 * If OPOST is set and no other output flags are set then we can do output
966 * processing. Even if only *one* other flag in the O_OTHER group is set 1004 * processing. Even if only *one* other flag in the O_OTHER group is set
967 * we do cooking in software. 1005 * we do cooking in software.
968 */ 1006 */
969 if(O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) { 1007 if (O_OPOST(port->gs.tty) && !O_OTHER(port->gs.tty)) {
970 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags); 1008 set_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
971 } else { 1009 } else {
972 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags); 1010 clear_bit(TTY_HW_COOK_OUT, &port->gs.tty->flags);
973 } 1011 }
974 sx_dprintk (SX_DEBUG_TERMIOS, "oflags: %x(%d)\n", 1012 sx_dprintk(SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
975 port->gs.tty->termios->c_oflag, 1013 port->gs.tty->termios->c_oflag, O_OTHER(port->gs.tty));
976 O_OTHER(port->gs.tty));
977 /* port->c_dcd = sx_get_CD (port); */ 1014 /* port->c_dcd = sx_get_CD (port); */
978 func_exit (); 1015 func_exit();
979 return 0; 1016 return 0;
980} 1017}
981 1018
982
983
984/* ********************************************************************** * 1019/* ********************************************************************** *
985 * the interrupt related routines * 1020 * the interrupt related routines *
986 * ********************************************************************** */ 1021 * ********************************************************************** */
@@ -996,245 +1031,260 @@ static int sx_set_real_termios (void *ptr)
996 know I'm dead against that, but I think it is required in this 1031 know I'm dead against that, but I think it is required in this
997 case. */ 1032 case. */
998 1033
999 1034static void sx_transmit_chars(struct sx_port *port)
1000static void sx_transmit_chars (struct sx_port *port)
1001{ 1035{
1002 int c; 1036 int c;
1003 int tx_ip; 1037 int tx_ip;
1004 int txroom; 1038 int txroom;
1005 1039
1006 func_enter2 (); 1040 func_enter2();
1007 sx_dprintk (SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n", 1041 sx_dprintk(SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
1008 port, port->gs.xmit_cnt); 1042 port, port->gs.xmit_cnt);
1009 1043
1010 if (test_and_set_bit (SX_PORT_TRANSMIT_LOCK, &port->locks)) { 1044 if (test_and_set_bit(SX_PORT_TRANSMIT_LOCK, &port->locks)) {
1011 return; 1045 return;
1012 } 1046 }
1013 1047
1014 while (1) { 1048 while (1) {
1015 c = port->gs.xmit_cnt; 1049 c = port->gs.xmit_cnt;
1016 1050
1017 sx_dprintk (SX_DEBUG_TRANSMIT, "Copying %d ", c); 1051 sx_dprintk(SX_DEBUG_TRANSMIT, "Copying %d ", c);
1018 tx_ip = sx_read_channel_byte (port, hi_txipos); 1052 tx_ip = sx_read_channel_byte(port, hi_txipos);
1019 1053
1020 /* Took me 5 minutes to deduce this formula. 1054 /* Took me 5 minutes to deduce this formula.
1021 Luckily it is literally in the manual in section 6.5.4.3.5 */ 1055 Luckily it is literally in the manual in section 6.5.4.3.5 */
1022 txroom = (sx_read_channel_byte (port, hi_txopos) - tx_ip - 1) & 0xff; 1056 txroom = (sx_read_channel_byte(port, hi_txopos) - tx_ip - 1) &
1057 0xff;
1023 1058
1024 /* Don't copy more bytes than there is room for in the buffer */ 1059 /* Don't copy more bytes than there is room for in the buffer */
1025 if (c > txroom) 1060 if (c > txroom)
1026 c = txroom; 1061 c = txroom;
1027 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom ); 1062 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom);
1028 1063
1029 /* Don't copy past the end of the hardware transmit buffer */ 1064 /* Don't copy past the end of the hardware transmit buffer */
1030 if (c > 0x100 - tx_ip) 1065 if (c > 0x100 - tx_ip)
1031 c = 0x100 - tx_ip; 1066 c = 0x100 - tx_ip;
1032 1067
1033 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100-tx_ip ); 1068 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100 - tx_ip);
1034 1069
1035 /* Don't copy pas the end of the source buffer */ 1070 /* Don't copy pas the end of the source buffer */
1036 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail) 1071 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
1037 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail; 1072 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1038 1073
1039 sx_dprintk (SX_DEBUG_TRANSMIT, " %d(%ld) \n", 1074 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%ld) \n",
1040 c, SERIAL_XMIT_SIZE- port->gs.xmit_tail); 1075 c, SERIAL_XMIT_SIZE - port->gs.xmit_tail);
1041
1042 /* If for one reason or another, we can't copy more data, we're done! */
1043 if (c == 0) break;
1044 1076
1077 /* If for one reason or another, we can't copy more data, we're
1078 done! */
1079 if (c == 0)
1080 break;
1045 1081
1046 memcpy_toio (port->board->base + CHAN_OFFSET(port,hi_txbuf) + tx_ip, 1082 memcpy_toio(port->board->base + CHAN_OFFSET(port, hi_txbuf) +
1047 port->gs.xmit_buf + port->gs.xmit_tail, c); 1083 tx_ip, port->gs.xmit_buf + port->gs.xmit_tail, c);
1048 1084
1049 /* Update the pointer in the card */ 1085 /* Update the pointer in the card */
1050 sx_write_channel_byte (port, hi_txipos, (tx_ip+c) & 0xff); 1086 sx_write_channel_byte(port, hi_txipos, (tx_ip + c) & 0xff);
1051 1087
1052 /* Update the kernel buffer end */ 1088 /* Update the kernel buffer end */
1053 port->gs.xmit_tail = (port->gs.xmit_tail + c) & (SERIAL_XMIT_SIZE-1); 1089 port->gs.xmit_tail = (port->gs.xmit_tail + c) &
1090 (SERIAL_XMIT_SIZE - 1);
1054 1091
1055 /* This one last. (this is essential) 1092 /* This one last. (this is essential)
1056 It would allow others to start putting more data into the buffer! */ 1093 It would allow others to start putting more data into the
1094 buffer! */
1057 port->gs.xmit_cnt -= c; 1095 port->gs.xmit_cnt -= c;
1058 } 1096 }
1059 1097
1060 if (port->gs.xmit_cnt == 0) { 1098 if (port->gs.xmit_cnt == 0) {
1061 sx_disable_tx_interrupts (port); 1099 sx_disable_tx_interrupts(port);
1062 } 1100 }
1063 1101
1064 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) { 1102 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
1065 tty_wakeup(port->gs.tty); 1103 tty_wakeup(port->gs.tty);
1066 sx_dprintk (SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n", 1104 sx_dprintk(SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1067 port->gs.wakeup_chars); 1105 port->gs.wakeup_chars);
1068 } 1106 }
1069 1107
1070 clear_bit (SX_PORT_TRANSMIT_LOCK, &port->locks); 1108 clear_bit(SX_PORT_TRANSMIT_LOCK, &port->locks);
1071 func_exit (); 1109 func_exit();
1072} 1110}
1073 1111
1074
1075/* Note the symmetry between receiving chars and transmitting them! 1112/* Note the symmetry between receiving chars and transmitting them!
1076 Note: The kernel should have implemented both a receive buffer and 1113 Note: The kernel should have implemented both a receive buffer and
1077 a transmit buffer. */ 1114 a transmit buffer. */
1078 1115
1079/* Inlined: Called only once. Remove the inline when you add another call */ 1116/* Inlined: Called only once. Remove the inline when you add another call */
1080static inline void sx_receive_chars (struct sx_port *port) 1117static inline void sx_receive_chars(struct sx_port *port)
1081{ 1118{
1082 int c; 1119 int c;
1083 int rx_op; 1120 int rx_op;
1084 struct tty_struct *tty; 1121 struct tty_struct *tty;
1085 int copied=0; 1122 int copied = 0;
1086 unsigned char *rp; 1123 unsigned char *rp;
1087 1124
1088 func_enter2 (); 1125 func_enter2();
1089 tty = port->gs.tty; 1126 tty = port->gs.tty;
1090 while (1) { 1127 while (1) {
1091 rx_op = sx_read_channel_byte (port, hi_rxopos); 1128 rx_op = sx_read_channel_byte(port, hi_rxopos);
1092 c = (sx_read_channel_byte (port, hi_rxipos) - rx_op) & 0xff; 1129 c = (sx_read_channel_byte(port, hi_rxipos) - rx_op) & 0xff;
1093 1130
1094 sx_dprintk (SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c); 1131 sx_dprintk(SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
1095 1132
1096 /* Don't copy past the end of the hardware receive buffer */ 1133 /* Don't copy past the end of the hardware receive buffer */
1097 if (rx_op + c > 0x100) c = 0x100 - rx_op; 1134 if (rx_op + c > 0x100)
1135 c = 0x100 - rx_op;
1098 1136
1099 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c); 1137 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
1100 1138
1101 /* Don't copy more bytes than there is room for in the buffer */ 1139 /* Don't copy more bytes than there is room for in the buffer */
1102 1140
1103 c = tty_prepare_flip_string(tty, &rp, c); 1141 c = tty_prepare_flip_string(tty, &rp, c);
1104 1142
1105 sx_dprintk (SX_DEBUG_RECEIVE, "c = %d.\n", c); 1143 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
1106 1144
1107 /* If for one reason or another, we can't copy more data, we're done! */ 1145 /* If for one reason or another, we can't copy more data, we're done! */
1108 if (c == 0) break; 1146 if (c == 0)
1147 break;
1109 1148
1110 sx_dprintk (SX_DEBUG_RECEIVE , "Copying over %d chars. First is %d at %lx\n", c, 1149 sx_dprintk(SX_DEBUG_RECEIVE, "Copying over %d chars. First is "
1111 read_sx_byte (port->board, CHAN_OFFSET(port,hi_rxbuf) + rx_op), 1150 "%d at %lx\n", c, read_sx_byte(port->board,
1112 CHAN_OFFSET(port, hi_rxbuf)); 1151 CHAN_OFFSET(port, hi_rxbuf) + rx_op),
1113 memcpy_fromio (rp, 1152 CHAN_OFFSET(port, hi_rxbuf));
1114 port->board->base + CHAN_OFFSET(port,hi_rxbuf) + rx_op, c); 1153 memcpy_fromio(rp, port->board->base +
1154 CHAN_OFFSET(port, hi_rxbuf) + rx_op, c);
1115 1155
1116 /* This one last. ( Not essential.) 1156 /* This one last. ( Not essential.)
1117 It allows the card to start putting more data into the buffer! 1157 It allows the card to start putting more data into the
1158 buffer!
1118 Update the pointer in the card */ 1159 Update the pointer in the card */
1119 sx_write_channel_byte (port, hi_rxopos, (rx_op + c) & 0xff); 1160 sx_write_channel_byte(port, hi_rxopos, (rx_op + c) & 0xff);
1120 1161
1121 copied += c; 1162 copied += c;
1122 } 1163 }
1123 if (copied) { 1164 if (copied) {
1124 struct timeval tv; 1165 struct timeval tv;
1125 1166
1126 do_gettimeofday (&tv); 1167 do_gettimeofday(&tv);
1127 sx_dprintk (SX_DEBUG_RECEIVE, 1168 sx_dprintk(SX_DEBUG_RECEIVE, "pushing flipq port %d (%3d "
1128 "pushing flipq port %d (%3d chars): %d.%06d (%d/%d)\n", 1169 "chars): %d.%06d (%d/%d)\n", port->line,
1129 port->line, copied, 1170 copied, (int)(tv.tv_sec % 60), (int)tv.tv_usec,
1130 (int) (tv.tv_sec % 60), (int)tv.tv_usec, tty->raw, tty->real_raw); 1171 tty->raw, tty->real_raw);
1131 1172
1132 /* Tell the rest of the system the news. Great news. New characters! */ 1173 /* Tell the rest of the system the news. Great news. New
1133 tty_flip_buffer_push (tty); 1174 characters! */
1175 tty_flip_buffer_push(tty);
1134 /* tty_schedule_flip (tty); */ 1176 /* tty_schedule_flip (tty); */
1135 } 1177 }
1136 1178
1137 func_exit (); 1179 func_exit();
1138} 1180}
1139 1181
1140/* Inlined: it is called only once. Remove the inline if you add another 1182/* Inlined: it is called only once. Remove the inline if you add another
1141 call */ 1183 call */
1142static inline void sx_check_modem_signals (struct sx_port *port) 1184static inline void sx_check_modem_signals(struct sx_port *port)
1143{ 1185{
1144 int hi_state; 1186 int hi_state;
1145 int c_dcd; 1187 int c_dcd;
1146 1188
1147 hi_state = sx_read_channel_byte (port, hi_state); 1189 hi_state = sx_read_channel_byte(port, hi_state);
1148 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n", 1190 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1149 port->c_dcd, sx_get_CD (port)); 1191 port->c_dcd, sx_get_CD(port));
1150 1192
1151 if (hi_state & ST_BREAK) { 1193 if (hi_state & ST_BREAK) {
1152 hi_state &= ~ST_BREAK; 1194 hi_state &= ~ST_BREAK;
1153 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a break.\n"); 1195 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1154 sx_write_channel_byte (port, hi_state, hi_state); 1196 sx_write_channel_byte(port, hi_state, hi_state);
1155 gs_got_break (&port->gs); 1197 gs_got_break(&port->gs);
1156 } 1198 }
1157 if (hi_state & ST_DCD) { 1199 if (hi_state & ST_DCD) {
1158 hi_state &= ~ST_DCD; 1200 hi_state &= ~ST_DCD;
1159 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n"); 1201 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1160 sx_write_channel_byte (port, hi_state, hi_state); 1202 sx_write_channel_byte(port, hi_state, hi_state);
1161 c_dcd = sx_get_CD (port); 1203 c_dcd = sx_get_CD(port);
1162 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd); 1204 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
1163 if (c_dcd != port->c_dcd) { 1205 if (c_dcd != port->c_dcd) {
1164 port->c_dcd = c_dcd; 1206 port->c_dcd = c_dcd;
1165 if (sx_get_CD (port)) { 1207 if (sx_get_CD(port)) {
1166 /* DCD went UP */ 1208 /* DCD went UP */
1167 if ((sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) && 1209 if ((sx_read_channel_byte(port, hi_hstat) !=
1168 !(port->gs.tty->termios->c_cflag & CLOCAL) ) { 1210 HS_IDLE_CLOSED) &&
1169 /* Are we blocking in open?*/ 1211 !(port->gs.tty->termios->
1170 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD active, unblocking open\n"); 1212 c_cflag & CLOCAL)) {
1171 wake_up_interruptible(&port->gs.open_wait); 1213 /* Are we blocking in open? */
1214 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1215 "active, unblocking open\n");
1216 wake_up_interruptible(&port->gs.
1217 open_wait);
1172 } else { 1218 } else {
1173 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD raised. Ignoring.\n"); 1219 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1220 "raised. Ignoring.\n");
1174 } 1221 }
1175 } else { 1222 } else {
1176 /* DCD went down! */ 1223 /* DCD went down! */
1177 if (!(port->gs.tty->termios->c_cflag & CLOCAL) ) { 1224 if (!(port->gs.tty->termios->c_cflag & CLOCAL)){
1178 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. hanging up....\n"); 1225 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1179 tty_hangup (port->gs.tty); 1226 "dropped. hanging up....\n");
1227 tty_hangup(port->gs.tty);
1180 } else { 1228 } else {
1181 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "DCD dropped. ignoring.\n"); 1229 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1230 "dropped. ignoring.\n");
1182 } 1231 }
1183 } 1232 }
1184 } else { 1233 } else {
1185 sx_dprintk (SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us DCD changed, but it didn't.\n"); 1234 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us "
1235 "DCD changed, but it didn't.\n");
1186 } 1236 }
1187 } 1237 }
1188} 1238}
1189 1239
1190
1191/* This is what an interrupt routine should look like. 1240/* This is what an interrupt routine should look like.
1192 * Small, elegant, clear. 1241 * Small, elegant, clear.
1193 */ 1242 */
1194 1243
1195static irqreturn_t sx_interrupt (int irq, void *ptr) 1244static irqreturn_t sx_interrupt(int irq, void *ptr)
1196{ 1245{
1197 struct sx_board *board = ptr; 1246 struct sx_board *board = ptr;
1198 struct sx_port *port; 1247 struct sx_port *port;
1199 int i; 1248 int i;
1200 1249
1201 func_enter (); 1250 func_enter();
1202 sx_dprintk (SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq, board->irq); 1251 sx_dprintk(SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq,
1252 board->irq);
1203 1253
1204 /* AAargh! The order in which to do these things is essential and 1254 /* AAargh! The order in which to do these things is essential and
1205 not trivial. 1255 not trivial.
1206 1256
1207 - Rate limit goes before "recursive". Otherwise a series of 1257 - Rate limit goes before "recursive". Otherwise a series of
1208 recursive calls will hang the machine in the interrupt routine. 1258 recursive calls will hang the machine in the interrupt routine.
1209 1259
1210 - hardware twiddling goes before "recursive". Otherwise when we 1260 - hardware twiddling goes before "recursive". Otherwise when we
1211 poll the card, and a recursive interrupt happens, we won't 1261 poll the card, and a recursive interrupt happens, we won't
1212 ack the card, so it might keep on interrupting us. (especially 1262 ack the card, so it might keep on interrupting us. (especially
1213 level sensitive interrupt systems like PCI). 1263 level sensitive interrupt systems like PCI).
1214 1264
1215 - Rate limit goes before hardware twiddling. Otherwise we won't 1265 - Rate limit goes before hardware twiddling. Otherwise we won't
1216 catch a card that has gone bonkers. 1266 catch a card that has gone bonkers.
1217 1267
1218 - The "initialized" test goes after the hardware twiddling. Otherwise 1268 - The "initialized" test goes after the hardware twiddling. Otherwise
1219 the card will stick us in the interrupt routine again. 1269 the card will stick us in the interrupt routine again.
1220 1270
1221 - The initialized test goes before recursive. 1271 - The initialized test goes before recursive.
1222 */ 1272 */
1223
1224
1225 1273
1226#ifdef IRQ_RATE_LIMIT 1274#ifdef IRQ_RATE_LIMIT
1227 /* Aaargh! I'm ashamed. This costs more lines-of-code than the 1275 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
1228 actual interrupt routine!. (Well, used to when I wrote that comment) */ 1276 actual interrupt routine!. (Well, used to when I wrote that
1277 comment) */
1229 { 1278 {
1230 static int lastjif; 1279 static int lastjif;
1231 static int nintr=0; 1280 static int nintr = 0;
1232 1281
1233 if (lastjif == jiffies) { 1282 if (lastjif == jiffies) {
1234 if (++nintr > IRQ_RATE_LIMIT) { 1283 if (++nintr > IRQ_RATE_LIMIT) {
1235 free_irq (board->irq, board); 1284 free_irq(board->irq, board);
1236 printk (KERN_ERR "sx: Too many interrupts. Turning off interrupt %d.\n", 1285 printk(KERN_ERR "sx: Too many interrupts. "
1237 board->irq); 1286 "Turning off interrupt %d.\n",
1287 board->irq);
1238 } 1288 }
1239 } else { 1289 } else {
1240 lastjif = jiffies; 1290 lastjif = jiffies;
@@ -1243,19 +1293,20 @@ static irqreturn_t sx_interrupt (int irq, void *ptr)
1243 } 1293 }
1244#endif 1294#endif
1245 1295
1246
1247 if (board->irq == irq) { 1296 if (board->irq == irq) {
1248 /* Tell the card we've noticed the interrupt. */ 1297 /* Tell the card we've noticed the interrupt. */
1249 1298
1250 sx_write_board_word (board, cc_int_pending, 0); 1299 sx_write_board_word(board, cc_int_pending, 0);
1251 if (IS_SX_BOARD (board)) { 1300 if (IS_SX_BOARD(board)) {
1252 write_sx_byte (board, SX_RESET_IRQ, 1); 1301 write_sx_byte(board, SX_RESET_IRQ, 1);
1253 } else if (IS_EISA_BOARD(board)) { 1302 } else if (IS_EISA_BOARD(board)) {
1254 inb(board->eisa_base+0xc03); 1303 inb(board->eisa_base + 0xc03);
1255 write_sx_word(board, 8, 0); 1304 write_sx_word(board, 8, 0);
1256 } else { 1305 } else {
1257 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR); 1306 write_sx_byte(board, SI2_ISA_INTCLEAR,
1258 write_sx_byte (board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET); 1307 SI2_ISA_INTCLEAR_CLEAR);
1308 write_sx_byte(board, SI2_ISA_INTCLEAR,
1309 SI2_ISA_INTCLEAR_SET);
1259 } 1310 }
1260 } 1311 }
1261 1312
@@ -1264,53 +1315,48 @@ static irqreturn_t sx_interrupt (int irq, void *ptr)
1264 if (!(board->flags & SX_BOARD_INITIALIZED)) 1315 if (!(board->flags & SX_BOARD_INITIALIZED))
1265 return IRQ_HANDLED; 1316 return IRQ_HANDLED;
1266 1317
1267 if (test_and_set_bit (SX_BOARD_INTR_LOCK, &board->locks)) { 1318 if (test_and_set_bit(SX_BOARD_INTR_LOCK, &board->locks)) {
1268 printk (KERN_ERR "Recursive interrupt! (%d)\n", board->irq); 1319 printk(KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
1269 return IRQ_HANDLED; 1320 return IRQ_HANDLED;
1270 } 1321 }
1271 1322
1272 for (i=0;i<board->nports;i++) { 1323 for (i = 0; i < board->nports; i++) {
1273 port = &board->ports[i]; 1324 port = &board->ports[i];
1274 if (port->gs.flags & GS_ACTIVE) { 1325 if (port->gs.flags & GS_ACTIVE) {
1275 if (sx_read_channel_byte (port, hi_state)) { 1326 if (sx_read_channel_byte(port, hi_state)) {
1276 sx_dprintk (SX_DEBUG_INTERRUPTS, 1327 sx_dprintk(SX_DEBUG_INTERRUPTS, "Port %d: "
1277 "Port %d: modem signal change?... \n", i); 1328 "modem signal change?... \n",i);
1278 sx_check_modem_signals (port); 1329 sx_check_modem_signals(port);
1279 } 1330 }
1280 if (port->gs.xmit_cnt) { 1331 if (port->gs.xmit_cnt) {
1281 sx_transmit_chars (port); 1332 sx_transmit_chars(port);
1282 } 1333 }
1283 if (!(port->gs.flags & SX_RX_THROTTLE)) { 1334 if (!(port->gs.flags & SX_RX_THROTTLE)) {
1284 sx_receive_chars (port); 1335 sx_receive_chars(port);
1285 } 1336 }
1286 } 1337 }
1287 } 1338 }
1288 1339
1289 clear_bit (SX_BOARD_INTR_LOCK, &board->locks); 1340 clear_bit(SX_BOARD_INTR_LOCK, &board->locks);
1290 1341
1291 sx_dprintk (SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq, board->irq); 1342 sx_dprintk(SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq,
1292 func_exit (); 1343 board->irq);
1344 func_exit();
1293 return IRQ_HANDLED; 1345 return IRQ_HANDLED;
1294} 1346}
1295 1347
1296 1348static void sx_pollfunc(unsigned long data)
1297static void sx_pollfunc (unsigned long data)
1298{ 1349{
1299 struct sx_board *board = (struct sx_board *) data; 1350 struct sx_board *board = (struct sx_board *)data;
1300
1301 func_enter ();
1302 1351
1303 sx_interrupt (0, board); 1352 func_enter();
1304 1353
1305 init_timer(&board->timer); 1354 sx_interrupt(0, board);
1306 1355
1307 board->timer.expires = jiffies + sx_poll; 1356 mod_timer(&board->timer, jiffies + sx_poll);
1308 add_timer (&board->timer); 1357 func_exit();
1309 func_exit ();
1310} 1358}
1311 1359
1312
1313
1314/* ********************************************************************** * 1360/* ********************************************************************** *
1315 * Here are the routines that actually * 1361 * Here are the routines that actually *
1316 * interface with the generic_serial driver * 1362 * interface with the generic_serial driver *
@@ -1319,9 +1365,9 @@ static void sx_pollfunc (unsigned long data)
1319/* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */ 1365/* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1320/* Hmm. Ok I figured it out. You don't. */ 1366/* Hmm. Ok I figured it out. You don't. */
1321 1367
1322static void sx_disable_tx_interrupts (void * ptr) 1368static void sx_disable_tx_interrupts(void *ptr)
1323{ 1369{
1324 struct sx_port *port = ptr; 1370 struct sx_port *port = ptr;
1325 func_enter2(); 1371 func_enter2();
1326 1372
1327 port->gs.flags &= ~GS_TX_INTEN; 1373 port->gs.flags &= ~GS_TX_INTEN;
@@ -1329,30 +1375,28 @@ static void sx_disable_tx_interrupts (void * ptr)
1329 func_exit(); 1375 func_exit();
1330} 1376}
1331 1377
1332 1378static void sx_enable_tx_interrupts(void *ptr)
1333static void sx_enable_tx_interrupts (void * ptr)
1334{ 1379{
1335 struct sx_port *port = ptr; 1380 struct sx_port *port = ptr;
1336 int data_in_buffer; 1381 int data_in_buffer;
1337 func_enter2(); 1382 func_enter2();
1338 1383
1339 /* First transmit the characters that we're supposed to */ 1384 /* First transmit the characters that we're supposed to */
1340 sx_transmit_chars (port); 1385 sx_transmit_chars(port);
1341 1386
1342 /* The sx card will never interrupt us if we don't fill the buffer 1387 /* The sx card will never interrupt us if we don't fill the buffer
1343 past 25%. So we keep considering interrupts off if that's the case. */ 1388 past 25%. So we keep considering interrupts off if that's the case. */
1344 data_in_buffer = (sx_read_channel_byte (port, hi_txipos) - 1389 data_in_buffer = (sx_read_channel_byte(port, hi_txipos) -
1345 sx_read_channel_byte (port, hi_txopos)) & 0xff; 1390 sx_read_channel_byte(port, hi_txopos)) & 0xff;
1346 1391
1347 /* XXX Must be "HIGH_WATER" for SI card according to doc. */ 1392 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
1348 if (data_in_buffer < LOW_WATER) 1393 if (data_in_buffer < LOW_WATER)
1349 port->gs.flags &= ~GS_TX_INTEN; 1394 port->gs.flags &= ~GS_TX_INTEN;
1350 1395
1351 func_exit(); 1396 func_exit();
1352} 1397}
1353 1398
1354 1399static void sx_disable_rx_interrupts(void *ptr)
1355static void sx_disable_rx_interrupts (void * ptr)
1356{ 1400{
1357 /* struct sx_port *port = ptr; */ 1401 /* struct sx_port *port = ptr; */
1358 func_enter(); 1402 func_enter();
@@ -1360,7 +1404,7 @@ static void sx_disable_rx_interrupts (void * ptr)
1360 func_exit(); 1404 func_exit();
1361} 1405}
1362 1406
1363static void sx_enable_rx_interrupts (void * ptr) 1407static void sx_enable_rx_interrupts(void *ptr)
1364{ 1408{
1365 /* struct sx_port *port = ptr; */ 1409 /* struct sx_port *port = ptr; */
1366 func_enter(); 1410 func_enter();
@@ -1368,55 +1412,48 @@ static void sx_enable_rx_interrupts (void * ptr)
1368 func_exit(); 1412 func_exit();
1369} 1413}
1370 1414
1371
1372/* Jeez. Isn't this simple? */ 1415/* Jeez. Isn't this simple? */
1373static int sx_get_CD (void * ptr) 1416static int sx_get_CD(void *ptr)
1374{ 1417{
1375 struct sx_port *port = ptr; 1418 struct sx_port *port = ptr;
1376 func_enter2(); 1419 func_enter2();
1377 1420
1378 func_exit(); 1421 func_exit();
1379 return ((sx_read_channel_byte (port, hi_ip) & IP_DCD) != 0); 1422 return ((sx_read_channel_byte(port, hi_ip) & IP_DCD) != 0);
1380} 1423}
1381 1424
1382
1383/* Jeez. Isn't this simple? */ 1425/* Jeez. Isn't this simple? */
1384static int sx_chars_in_buffer (void * ptr) 1426static int sx_chars_in_buffer(void *ptr)
1385{ 1427{
1386 struct sx_port *port = ptr; 1428 struct sx_port *port = ptr;
1387 func_enter2(); 1429 func_enter2();
1388 1430
1389 func_exit(); 1431 func_exit();
1390 return ((sx_read_channel_byte (port, hi_txipos) - 1432 return ((sx_read_channel_byte(port, hi_txipos) -
1391 sx_read_channel_byte (port, hi_txopos)) & 0xff); 1433 sx_read_channel_byte(port, hi_txopos)) & 0xff);
1392} 1434}
1393 1435
1394 1436static void sx_shutdown_port(void *ptr)
1395static void sx_shutdown_port (void * ptr)
1396{ 1437{
1397 struct sx_port *port = ptr; 1438 struct sx_port *port = ptr;
1398 1439
1399 func_enter(); 1440 func_enter();
1400 1441
1401 port->gs.flags &= ~ GS_ACTIVE; 1442 port->gs.flags &= ~GS_ACTIVE;
1402 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) { 1443 if (port->gs.tty && (port->gs.tty->termios->c_cflag & HUPCL)) {
1403 sx_setsignals (port, 0, 0); 1444 sx_setsignals(port, 0, 0);
1404 sx_reconfigure_port(port); 1445 sx_reconfigure_port(port);
1405 } 1446 }
1406 1447
1407 func_exit(); 1448 func_exit();
1408} 1449}
1409 1450
1410
1411
1412
1413
1414/* ********************************************************************** * 1451/* ********************************************************************** *
1415 * Here are the routines that actually * 1452 * Here are the routines that actually *
1416 * interface with the rest of the system * 1453 * interface with the rest of the system *
1417 * ********************************************************************** */ 1454 * ********************************************************************** */
1418 1455
1419static int sx_open (struct tty_struct * tty, struct file * filp) 1456static int sx_open(struct tty_struct *tty, struct file *filp)
1420{ 1457{
1421 struct sx_port *port; 1458 struct sx_port *port;
1422 int retval, line; 1459 int retval, line;
@@ -1429,18 +1466,18 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1429 } 1466 }
1430 1467
1431 line = tty->index; 1468 line = tty->index;
1432 sx_dprintk (SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, np=%d)\n", 1469 sx_dprintk(SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, "
1433 current->pid, line, tty, current->signal->tty, sx_nports); 1470 "np=%d)\n", current->pid, line, tty,
1471 current->signal->tty, sx_nports);
1434 1472
1435 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports)) 1473 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1436 return -ENODEV; 1474 return -ENODEV;
1437 1475
1438 port = & sx_ports[line]; 1476 port = &sx_ports[line];
1439 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a 1477 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
1440 1 -> 0 transition. */ 1478 1 -> 0 transition. */
1441 1479
1442 1480 sx_dprintk(SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1443 sx_dprintk (SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
1444 1481
1445 spin_lock_irqsave(&port->gs.driver_lock, flags); 1482 spin_lock_irqsave(&port->gs.driver_lock, flags);
1446 1483
@@ -1449,13 +1486,13 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1449 port->gs.count++; 1486 port->gs.count++;
1450 spin_unlock_irqrestore(&port->gs.driver_lock, flags); 1487 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1451 1488
1452 sx_dprintk (SX_DEBUG_OPEN, "starting port\n"); 1489 sx_dprintk(SX_DEBUG_OPEN, "starting port\n");
1453 1490
1454 /* 1491 /*
1455 * Start up serial port 1492 * Start up serial port
1456 */ 1493 */
1457 retval = gs_init_port(&port->gs); 1494 retval = gs_init_port(&port->gs);
1458 sx_dprintk (SX_DEBUG_OPEN, "done gs_init\n"); 1495 sx_dprintk(SX_DEBUG_OPEN, "done gs_init\n");
1459 if (retval) { 1496 if (retval) {
1460 port->gs.count--; 1497 port->gs.count--;
1461 return retval; 1498 return retval;
@@ -1463,19 +1500,20 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1463 1500
1464 port->gs.flags |= GS_ACTIVE; 1501 port->gs.flags |= GS_ACTIVE;
1465 if (port->gs.count <= 1) 1502 if (port->gs.count <= 1)
1466 sx_setsignals (port, 1,1); 1503 sx_setsignals(port, 1, 1);
1467 1504
1468#if 0 1505#if 0
1469 if (sx_debug & SX_DEBUG_OPEN) 1506 if (sx_debug & SX_DEBUG_OPEN)
1470 my_hd (port, sizeof (*port)); 1507 my_hd(port, sizeof(*port));
1471#else 1508#else
1472 if (sx_debug & SX_DEBUG_OPEN) 1509 if (sx_debug & SX_DEBUG_OPEN)
1473 my_hd_io (port->board->base + port->ch_base, sizeof (*port)); 1510 my_hd_io(port->board->base + port->ch_base, sizeof(*port));
1474#endif 1511#endif
1475 1512
1476 if (port->gs.count <= 1) { 1513 if (port->gs.count <= 1) {
1477 if (sx_send_command (port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) { 1514 if (sx_send_command(port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1478 printk (KERN_ERR "sx: Card didn't respond to LOPEN command.\n"); 1515 printk(KERN_ERR "sx: Card didn't respond to LOPEN "
1516 "command.\n");
1479 spin_lock_irqsave(&port->gs.driver_lock, flags); 1517 spin_lock_irqsave(&port->gs.driver_lock, flags);
1480 port->gs.count--; 1518 port->gs.count--;
1481 spin_unlock_irqrestore(&port->gs.driver_lock, flags); 1519 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
@@ -1484,75 +1522,76 @@ static int sx_open (struct tty_struct * tty, struct file * filp)
1484 } 1522 }
1485 1523
1486 retval = gs_block_til_ready(port, filp); 1524 retval = gs_block_til_ready(port, filp);
1487 sx_dprintk (SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n", 1525 sx_dprintk(SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
1488 retval, port->gs.count); 1526 retval, port->gs.count);
1489 1527
1490 if (retval) { 1528 if (retval) {
1491 /* 1529/*
1492 * Don't lower gs.count here because sx_close() will be called later 1530 * Don't lower gs.count here because sx_close() will be called later
1493 */ 1531 */
1494 1532
1495 return retval; 1533 return retval;
1496 } 1534 }
1497 /* tty->low_latency = 1; */ 1535 /* tty->low_latency = 1; */
1498 1536
1499 port->c_dcd = sx_get_CD (port); 1537 port->c_dcd = sx_get_CD(port);
1500 sx_dprintk (SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd); 1538 sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
1501 1539
1502 func_exit(); 1540 func_exit();
1503 return 0; 1541 return 0;
1504 1542
1505} 1543}
1506 1544
1507 1545static void sx_close(void *ptr)
1508static void sx_close (void *ptr)
1509{ 1546{
1510 struct sx_port *port = ptr; 1547 struct sx_port *port = ptr;
1511 /* Give the port 5 seconds to close down. */ 1548 /* Give the port 5 seconds to close down. */
1512 int to = 5 * HZ; 1549 int to = 5 * HZ;
1513 1550
1514 func_enter (); 1551 func_enter();
1515 1552
1516 sx_setsignals (port, 0, 0); 1553 sx_setsignals(port, 0, 0);
1517 sx_reconfigure_port(port); 1554 sx_reconfigure_port(port);
1518 sx_send_command (port, HS_CLOSE, 0, 0); 1555 sx_send_command(port, HS_CLOSE, 0, 0);
1519 1556
1520 while (to-- && (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED)) 1557 while (to-- && (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED))
1521 if (msleep_interruptible(10)) 1558 if (msleep_interruptible(10))
1522 break; 1559 break;
1523 if (sx_read_channel_byte (port, hi_hstat) != HS_IDLE_CLOSED) { 1560 if (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) {
1524 if (sx_send_command (port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED) != 1) { 1561 if (sx_send_command(port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED)
1525 printk (KERN_ERR 1562 != 1) {
1526 "sx: sent the force_close command, but card didn't react\n"); 1563 printk(KERN_ERR "sx: sent the force_close command, but "
1564 "card didn't react\n");
1527 } else 1565 } else
1528 sx_dprintk (SX_DEBUG_CLOSE, "sent the force_close command.\n"); 1566 sx_dprintk(SX_DEBUG_CLOSE, "sent the force_close "
1567 "command.\n");
1529 } 1568 }
1530 1569
1531 sx_dprintk (SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n", 1570 sx_dprintk(SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
1532 5 * HZ - to - 1, port->gs.count); 1571 5 * HZ - to - 1, port->gs.count);
1533 1572
1534 if(port->gs.count) { 1573 if (port->gs.count) {
1535 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n", port->gs.count); 1574 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n",
1536 //printk ("%s SETTING port count to zero: %p count: %d\n", __FUNCTION__, port, port->gs.count); 1575 port->gs.count);
1537 //port->gs.count = 0; 1576 /*printk("%s SETTING port count to zero: %p count: %d\n",
1577 __FUNCTION__, port, port->gs.count);
1578 port->gs.count = 0;*/
1538 } 1579 }
1539 1580
1540 func_exit (); 1581 func_exit();
1541} 1582}
1542 1583
1543
1544
1545/* This is relatively thorough. But then again it is only 20 lines. */ 1584/* This is relatively thorough. But then again it is only 20 lines. */
1546#define MARCHUP for (i=min;i<max;i++) 1585#define MARCHUP for (i = min; i < max; i++)
1547#define MARCHDOWN for (i=max-1;i>=min;i--) 1586#define MARCHDOWN for (i = max - 1; i >= min; i--)
1548#define W0 write_sx_byte (board, i, 0x55) 1587#define W0 write_sx_byte(board, i, 0x55)
1549#define W1 write_sx_byte (board, i, 0xaa) 1588#define W1 write_sx_byte(board, i, 0xaa)
1550#define R0 if (read_sx_byte (board, i) != 0x55) return 1 1589#define R0 if (read_sx_byte(board, i) != 0x55) return 1
1551#define R1 if (read_sx_byte (board, i) != 0xaa) return 1 1590#define R1 if (read_sx_byte(board, i) != 0xaa) return 1
1552 1591
1553/* This memtest takes a human-noticable time. You normally only do it 1592/* This memtest takes a human-noticable time. You normally only do it
1554 once a boot, so I guess that it is worth it. */ 1593 once a boot, so I guess that it is worth it. */
1555static int do_memtest (struct sx_board *board, int min, int max) 1594static int do_memtest(struct sx_board *board, int min, int max)
1556{ 1595{
1557 int i; 1596 int i;
1558 1597
@@ -1561,16 +1600,37 @@ static int do_memtest (struct sx_board *board, int min, int max)
1561 intermittent errors. -- REW 1600 intermittent errors. -- REW
1562 (For the theory behind memory testing see: 1601 (For the theory behind memory testing see:
1563 Testing Semiconductor Memories by A.J. van de Goor.) */ 1602 Testing Semiconductor Memories by A.J. van de Goor.) */
1564 MARCHUP {W0;} 1603 MARCHUP {
1565 MARCHUP {R0;W1;R1;W0;R0;W1;} 1604 W0;
1566 MARCHUP {R1;W0;W1;} 1605 }
1567 MARCHDOWN {R1;W0;W1;W0;} 1606 MARCHUP {
1568 MARCHDOWN {R0;W1;W0;} 1607 R0;
1608 W1;
1609 R1;
1610 W0;
1611 R0;
1612 W1;
1613 }
1614 MARCHUP {
1615 R1;
1616 W0;
1617 W1;
1618 }
1619 MARCHDOWN {
1620 R1;
1621 W0;
1622 W1;
1623 W0;
1624 }
1625 MARCHDOWN {
1626 R0;
1627 W1;
1628 W0;
1629 }
1569 1630
1570 return 0; 1631 return 0;
1571} 1632}
1572 1633
1573
1574#undef MARCHUP 1634#undef MARCHUP
1575#undef MARCHDOWN 1635#undef MARCHDOWN
1576#undef W0 1636#undef W0
@@ -1578,33 +1638,54 @@ static int do_memtest (struct sx_board *board, int min, int max)
1578#undef R0 1638#undef R0
1579#undef R1 1639#undef R1
1580 1640
1581#define MARCHUP for (i=min;i<max;i+=2) 1641#define MARCHUP for (i = min; i < max; i += 2)
1582#define MARCHDOWN for (i=max-1;i>=min;i-=2) 1642#define MARCHDOWN for (i = max - 1; i >= min; i -= 2)
1583#define W0 write_sx_word (board, i, 0x55aa) 1643#define W0 write_sx_word(board, i, 0x55aa)
1584#define W1 write_sx_word (board, i, 0xaa55) 1644#define W1 write_sx_word(board, i, 0xaa55)
1585#define R0 if (read_sx_word (board, i) != 0x55aa) return 1 1645#define R0 if (read_sx_word(board, i) != 0x55aa) return 1
1586#define R1 if (read_sx_word (board, i) != 0xaa55) return 1 1646#define R1 if (read_sx_word(board, i) != 0xaa55) return 1
1587 1647
1588#if 0 1648#if 0
1589/* This memtest takes a human-noticable time. You normally only do it 1649/* This memtest takes a human-noticable time. You normally only do it
1590 once a boot, so I guess that it is worth it. */ 1650 once a boot, so I guess that it is worth it. */
1591static int do_memtest_w (struct sx_board *board, int min, int max) 1651static int do_memtest_w(struct sx_board *board, int min, int max)
1592{ 1652{
1593 int i; 1653 int i;
1594 1654
1595 MARCHUP {W0;} 1655 MARCHUP {
1596 MARCHUP {R0;W1;R1;W0;R0;W1;} 1656 W0;
1597 MARCHUP {R1;W0;W1;} 1657 }
1598 MARCHDOWN {R1;W0;W1;W0;} 1658 MARCHUP {
1599 MARCHDOWN {R0;W1;W0;} 1659 R0;
1660 W1;
1661 R1;
1662 W0;
1663 R0;
1664 W1;
1665 }
1666 MARCHUP {
1667 R1;
1668 W0;
1669 W1;
1670 }
1671 MARCHDOWN {
1672 R1;
1673 W0;
1674 W1;
1675 W0;
1676 }
1677 MARCHDOWN {
1678 R0;
1679 W1;
1680 W0;
1681 }
1600 1682
1601 return 0; 1683 return 0;
1602} 1684}
1603#endif 1685#endif
1604 1686
1605 1687static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1606static int sx_fw_ioctl (struct inode *inode, struct file *filp, 1688 unsigned int cmd, unsigned long arg)
1607 unsigned int cmd, unsigned long arg)
1608{ 1689{
1609 int rc = 0; 1690 int rc = 0;
1610 int __user *descr = (int __user *)arg; 1691 int __user *descr = (int __user *)arg;
@@ -1616,7 +1697,7 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1616 1697
1617 func_enter(); 1698 func_enter();
1618 1699
1619#if 0 1700#if 0
1620 /* Removed superuser check: Sysops can use the permissions on the device 1701 /* Removed superuser check: Sysops can use the permissions on the device
1621 file to restrict access. Recommendation: Root only. (root.root 600) */ 1702 file to restrict access. Recommendation: Root only. (root.root 600) */
1622 if (!capable(CAP_SYS_ADMIN)) { 1703 if (!capable(CAP_SYS_ADMIN)) {
@@ -1624,103 +1705,115 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1624 } 1705 }
1625#endif 1706#endif
1626 1707
1627 sx_dprintk (SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg); 1708 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
1628 1709
1629 if (!board) board = &boards[0]; 1710 if (!board)
1711 board = &boards[0];
1630 if (board->flags & SX_BOARD_PRESENT) { 1712 if (board->flags & SX_BOARD_PRESENT) {
1631 sx_dprintk (SX_DEBUG_FIRMWARE, "Board present! (%x)\n", 1713 sx_dprintk(SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1632 board->flags); 1714 board->flags);
1633 } else { 1715 } else {
1634 sx_dprintk (SX_DEBUG_FIRMWARE, "Board not present! (%x) all:", 1716 sx_dprintk(SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1635 board->flags); 1717 board->flags);
1636 for (i=0;i< SX_NBOARDS;i++) 1718 for (i = 0; i < SX_NBOARDS; i++)
1637 sx_dprintk (SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags); 1719 sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1638 sx_dprintk (SX_DEBUG_FIRMWARE, "\n"); 1720 sx_dprintk(SX_DEBUG_FIRMWARE, "\n");
1639 return -EIO; 1721 return -EIO;
1640 } 1722 }
1641 1723
1642 switch (cmd) { 1724 switch (cmd) {
1643 case SXIO_SET_BOARD: 1725 case SXIO_SET_BOARD:
1644 sx_dprintk (SX_DEBUG_FIRMWARE, "set board to %ld\n", arg); 1726 sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1645 if (arg >= SX_NBOARDS) return -EIO; 1727 if (arg >= SX_NBOARDS)
1646 sx_dprintk (SX_DEBUG_FIRMWARE, "not out of range\n"); 1728 return -EIO;
1647 if (!(boards[arg].flags & SX_BOARD_PRESENT)) return -EIO; 1729 sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n");
1648 sx_dprintk (SX_DEBUG_FIRMWARE, ".. and present!\n"); 1730 if (!(boards[arg].flags & SX_BOARD_PRESENT))
1731 return -EIO;
1732 sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n");
1649 board = &boards[arg]; 1733 board = &boards[arg];
1650 break; 1734 break;
1651 case SXIO_GET_TYPE: 1735 case SXIO_GET_TYPE:
1652 rc = -ENOENT; /* If we manage to miss one, return error. */ 1736 rc = -ENOENT; /* If we manage to miss one, return error. */
1653 if (IS_SX_BOARD (board)) rc = SX_TYPE_SX; 1737 if (IS_SX_BOARD(board))
1654 if (IS_CF_BOARD (board)) rc = SX_TYPE_CF; 1738 rc = SX_TYPE_SX;
1655 if (IS_SI_BOARD (board)) rc = SX_TYPE_SI; 1739 if (IS_CF_BOARD(board))
1656 if (IS_SI1_BOARD (board)) rc = SX_TYPE_SI; 1740 rc = SX_TYPE_CF;
1657 if (IS_EISA_BOARD (board)) rc = SX_TYPE_SI; 1741 if (IS_SI_BOARD(board))
1658 sx_dprintk (SX_DEBUG_FIRMWARE, "returning type= %d\n", rc); 1742 rc = SX_TYPE_SI;
1743 if (IS_SI1_BOARD(board))
1744 rc = SX_TYPE_SI;
1745 if (IS_EISA_BOARD(board))
1746 rc = SX_TYPE_SI;
1747 sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
1659 break; 1748 break;
1660 case SXIO_DO_RAMTEST: 1749 case SXIO_DO_RAMTEST:
1661 if (sx_initialized) /* Already initialized: better not ramtest the board. */ 1750 if (sx_initialized) /* Already initialized: better not ramtest the board. */
1662 return -EPERM; 1751 return -EPERM;
1663 if (IS_SX_BOARD (board)) { 1752 if (IS_SX_BOARD(board)) {
1664 rc = do_memtest (board, 0, 0x7000); 1753 rc = do_memtest(board, 0, 0x7000);
1665 if (!rc) rc = do_memtest (board, 0, 0x7000); 1754 if (!rc)
1666 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000);*/ 1755 rc = do_memtest(board, 0, 0x7000);
1756 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000); */
1667 } else { 1757 } else {
1668 rc = do_memtest (board, 0, 0x7ff8); 1758 rc = do_memtest(board, 0, 0x7ff8);
1669 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */ 1759 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1670 } 1760 }
1671 sx_dprintk (SX_DEBUG_FIRMWARE, "returning memtest result= %d\n", rc); 1761 sx_dprintk(SX_DEBUG_FIRMWARE, "returning memtest result= %d\n",
1762 rc);
1672 break; 1763 break;
1673 case SXIO_DOWNLOAD: 1764 case SXIO_DOWNLOAD:
1674 if (sx_initialized) /* Already initialized */ 1765 if (sx_initialized) /* Already initialized */
1675 return -EEXIST; 1766 return -EEXIST;
1676 if (!sx_reset (board)) 1767 if (!sx_reset(board))
1677 return -EIO; 1768 return -EIO;
1678 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 1769 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
1679 1770
1680 tmp = kmalloc (SX_CHUNK_SIZE, GFP_USER); 1771 tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER);
1681 if (!tmp) return -ENOMEM; 1772 if (!tmp)
1682 get_user (nbytes, descr++); 1773 return -ENOMEM;
1683 get_user (offset, descr++); 1774 get_user(nbytes, descr++);
1684 get_user (data, descr++); 1775 get_user(offset, descr++);
1776 get_user(data, descr++);
1685 while (nbytes && data) { 1777 while (nbytes && data) {
1686 for (i=0;i<nbytes;i += SX_CHUNK_SIZE) { 1778 for (i = 0; i < nbytes; i += SX_CHUNK_SIZE) {
1687 if (copy_from_user(tmp, (char __user *)data+i, 1779 if (copy_from_user(tmp, (char __user *)data + i,
1688 (i + SX_CHUNK_SIZE > 1780 (i + SX_CHUNK_SIZE > nbytes) ?
1689 nbytes) ? nbytes - i : 1781 nbytes - i : SX_CHUNK_SIZE)) {
1690 SX_CHUNK_SIZE)) { 1782 kfree(tmp);
1691 kfree (tmp);
1692 return -EFAULT; 1783 return -EFAULT;
1693 } 1784 }
1694 memcpy_toio(board->base2 + offset + i, tmp, 1785 memcpy_toio(board->base2 + offset + i, tmp,
1695 (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE); 1786 (i + SX_CHUNK_SIZE > nbytes) ?
1787 nbytes - i : SX_CHUNK_SIZE);
1696 } 1788 }
1697 1789
1698 get_user (nbytes, descr++); 1790 get_user(nbytes, descr++);
1699 get_user (offset, descr++); 1791 get_user(offset, descr++);
1700 get_user (data, descr++); 1792 get_user(data, descr++);
1701 } 1793 }
1702 kfree (tmp); 1794 kfree(tmp);
1703 sx_nports += sx_init_board (board); 1795 sx_nports += sx_init_board(board);
1704 rc = sx_nports; 1796 rc = sx_nports;
1705 break; 1797 break;
1706 case SXIO_INIT: 1798 case SXIO_INIT:
1707 if (sx_initialized) /* Already initialized */ 1799 if (sx_initialized) /* Already initialized */
1708 return -EEXIST; 1800 return -EEXIST;
1709 /* This is not allowed until all boards are initialized... */ 1801 /* This is not allowed until all boards are initialized... */
1710 for (i=0;i<SX_NBOARDS;i++) { 1802 for (i = 0; i < SX_NBOARDS; i++) {
1711 if ( (boards[i].flags & SX_BOARD_PRESENT) && 1803 if ((boards[i].flags & SX_BOARD_PRESENT) &&
1712 !(boards[i].flags & SX_BOARD_INITIALIZED)) 1804 !(boards[i].flags & SX_BOARD_INITIALIZED))
1713 return -EIO; 1805 return -EIO;
1714 } 1806 }
1715 for (i=0;i<SX_NBOARDS;i++) 1807 for (i = 0; i < SX_NBOARDS; i++)
1716 if (!(boards[i].flags & SX_BOARD_PRESENT)) break; 1808 if (!(boards[i].flags & SX_BOARD_PRESENT))
1717 1809 break;
1718 sx_dprintk (SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, " 1810
1719 "%d channels, first board: %d ports\n", 1811 sx_dprintk(SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1720 i, sx_nports, boards[0].nports); 1812 "%d channels, first board: %d ports\n",
1721 rc = sx_init_portstructs (i, sx_nports); 1813 i, sx_nports, boards[0].nports);
1722 sx_init_drivers (); 1814 rc = sx_init_portstructs(i, sx_nports);
1723 if (rc >= 0) 1815 sx_init_drivers();
1816 if (rc >= 0)
1724 sx_initialized++; 1817 sx_initialized++;
1725 break; 1818 break;
1726 case SXIO_SETDEBUG: 1819 case SXIO_SETDEBUG:
@@ -1737,32 +1830,32 @@ static int sx_fw_ioctl (struct inode *inode, struct file *filp,
1737 rc = sx_nports; 1830 rc = sx_nports;
1738 break; 1831 break;
1739 default: 1832 default:
1740 printk (KERN_WARNING "Unknown ioctl on firmware device (%x).\n", cmd); 1833 printk(KERN_WARNING "Unknown ioctl on firmware device (%x).\n",
1834 cmd);
1741 break; 1835 break;
1742 } 1836 }
1743 func_exit (); 1837 func_exit();
1744 return rc; 1838 return rc;
1745} 1839}
1746 1840
1747 1841static void sx_break(struct tty_struct *tty, int flag)
1748static void sx_break (struct tty_struct * tty, int flag)
1749{ 1842{
1750 struct sx_port *port = tty->driver_data; 1843 struct sx_port *port = tty->driver_data;
1751 int rv; 1844 int rv;
1752 1845
1753 func_enter (); 1846 func_enter();
1754 1847
1755 if (flag) 1848 if (flag)
1756 rv = sx_send_command (port, HS_START, -1, HS_IDLE_BREAK); 1849 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
1757 else 1850 else
1758 rv = sx_send_command (port, HS_STOP, -1, HS_IDLE_OPEN); 1851 rv = sx_send_command(port, HS_STOP, -1, HS_IDLE_OPEN);
1759 if (rv != 1) printk (KERN_ERR "sx: couldn't send break (%x).\n", 1852 if (rv != 1)
1760 read_sx_byte (port->board, CHAN_OFFSET (port, hi_hstat))); 1853 printk(KERN_ERR "sx: couldn't send break (%x).\n",
1854 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
1761 1855
1762 func_exit (); 1856 func_exit();
1763} 1857}
1764 1858
1765
1766static int sx_tiocmget(struct tty_struct *tty, struct file *file) 1859static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1767{ 1860{
1768 struct sx_port *port = tty->driver_data; 1861 struct sx_port *port = tty->driver_data;
@@ -1770,7 +1863,7 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1770} 1863}
1771 1864
1772static int sx_tiocmset(struct tty_struct *tty, struct file *file, 1865static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1773 unsigned int set, unsigned int clear) 1866 unsigned int set, unsigned int clear)
1774{ 1867{
1775 struct sx_port *port = tty->driver_data; 1868 struct sx_port *port = tty->driver_data;
1776 int rts = -1, dtr = -1; 1869 int rts = -1, dtr = -1;
@@ -1789,8 +1882,8 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file,
1789 return 0; 1882 return 0;
1790} 1883}
1791 1884
1792static int sx_ioctl (struct tty_struct * tty, struct file * filp, 1885static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1793 unsigned int cmd, unsigned long arg) 1886 unsigned int cmd, unsigned long arg)
1794{ 1887{
1795 int rc; 1888 int rc;
1796 struct sx_port *port = tty->driver_data; 1889 struct sx_port *port = tty->driver_data;
@@ -1803,10 +1896,10 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1803 switch (cmd) { 1896 switch (cmd) {
1804 case TIOCGSOFTCAR: 1897 case TIOCGSOFTCAR:
1805 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0), 1898 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1806 (unsigned __user *) argp); 1899 (unsigned __user *)argp);
1807 break; 1900 break;
1808 case TIOCSSOFTCAR: 1901 case TIOCSSOFTCAR:
1809 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) { 1902 if ((rc = get_user(ival, (unsigned __user *)argp)) == 0) {
1810 tty->termios->c_cflag = 1903 tty->termios->c_cflag =
1811 (tty->termios->c_cflag & ~CLOCAL) | 1904 (tty->termios->c_cflag & ~CLOCAL) |
1812 (ival ? CLOCAL : 0); 1905 (ival ? CLOCAL : 0);
@@ -1827,7 +1920,6 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1827 return rc; 1920 return rc;
1828} 1921}
1829 1922
1830
1831/* The throttle/unthrottle scheme for the Specialix card is different 1923/* The throttle/unthrottle scheme for the Specialix card is different
1832 * from other drivers and deserves some explanation. 1924 * from other drivers and deserves some explanation.
1833 * The Specialix hardware takes care of XON/XOFF 1925 * The Specialix hardware takes care of XON/XOFF
@@ -1844,7 +1936,7 @@ static int sx_ioctl (struct tty_struct * tty, struct file * filp,
1844 * flow control scheme is in use for that port. -- Simon Allen 1936 * flow control scheme is in use for that port. -- Simon Allen
1845 */ 1937 */
1846 1938
1847static void sx_throttle (struct tty_struct * tty) 1939static void sx_throttle(struct tty_struct *tty)
1848{ 1940{
1849 struct sx_port *port = (struct sx_port *)tty->driver_data; 1941 struct sx_port *port = (struct sx_port *)tty->driver_data;
1850 1942
@@ -1852,14 +1944,13 @@ static void sx_throttle (struct tty_struct * tty)
1852 /* If the port is using any type of input flow 1944 /* If the port is using any type of input flow
1853 * control then throttle the port. 1945 * control then throttle the port.
1854 */ 1946 */
1855 if((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty)) ) { 1947 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
1856 port->gs.flags |= SX_RX_THROTTLE; 1948 port->gs.flags |= SX_RX_THROTTLE;
1857 } 1949 }
1858 func_exit(); 1950 func_exit();
1859} 1951}
1860 1952
1861 1953static void sx_unthrottle(struct tty_struct *tty)
1862static void sx_unthrottle (struct tty_struct * tty)
1863{ 1954{
1864 struct sx_port *port = (struct sx_port *)tty->driver_data; 1955 struct sx_port *port = (struct sx_port *)tty->driver_data;
1865 1956
@@ -1873,15 +1964,11 @@ static void sx_unthrottle (struct tty_struct * tty)
1873 return; 1964 return;
1874} 1965}
1875 1966
1876
1877/* ********************************************************************** * 1967/* ********************************************************************** *
1878 * Here are the initialization routines. * 1968 * Here are the initialization routines. *
1879 * ********************************************************************** */ 1969 * ********************************************************************** */
1880 1970
1881 1971static int sx_init_board(struct sx_board *board)
1882
1883
1884static int sx_init_board (struct sx_board *board)
1885{ 1972{
1886 int addr; 1973 int addr;
1887 int chans; 1974 int chans;
@@ -1893,36 +1980,38 @@ static int sx_init_board (struct sx_board *board)
1893 1980
1894 board->flags |= SX_BOARD_INITIALIZED; 1981 board->flags |= SX_BOARD_INITIALIZED;
1895 1982
1896 if (read_sx_byte (board, 0)) 1983 if (read_sx_byte(board, 0))
1897 /* CF boards may need this. */ 1984 /* CF boards may need this. */
1898 write_sx_byte(board,0, 0); 1985 write_sx_byte(board, 0, 0);
1899 1986
1900 /* This resets the processor again, to make sure it didn't do any 1987 /* This resets the processor again, to make sure it didn't do any
1901 foolish things while we were downloading the image */ 1988 foolish things while we were downloading the image */
1902 if (!sx_reset (board)) 1989 if (!sx_reset(board))
1903 return 0; 1990 return 0;
1904 1991
1905 sx_start_board (board); 1992 sx_start_board(board);
1906 udelay (10); 1993 udelay(10);
1907 if (!sx_busy_wait_neq (board, 0, 0xff, 0)) { 1994 if (!sx_busy_wait_neq(board, 0, 0xff, 0)) {
1908 printk (KERN_ERR "sx: Ooops. Board won't initialize.\n"); 1995 printk(KERN_ERR "sx: Ooops. Board won't initialize.\n");
1909 return 0; 1996 return 0;
1910 } 1997 }
1911 1998
1912 /* Ok. So now the processor on the card is running. It gathered 1999 /* Ok. So now the processor on the card is running. It gathered
1913 some info for us... */ 2000 some info for us... */
1914 sx_dprintk (SX_DEBUG_INIT, "The sxcard structure:\n"); 2001 sx_dprintk(SX_DEBUG_INIT, "The sxcard structure:\n");
1915 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base, 0x10); 2002 if (sx_debug & SX_DEBUG_INIT)
1916 sx_dprintk (SX_DEBUG_INIT, "the first sx_module structure:\n"); 2003 my_hd_io(board->base, 0x10);
1917 if (sx_debug & SX_DEBUG_INIT) my_hd_io (board->base + 0x80, 0x30); 2004 sx_dprintk(SX_DEBUG_INIT, "the first sx_module structure:\n");
1918 2005 if (sx_debug & SX_DEBUG_INIT)
1919 sx_dprintk (SX_DEBUG_INIT, 2006 my_hd_io(board->base + 0x80, 0x30);
1920 "init_status: %x, %dk memory, firmware V%x.%02x,\n", 2007
1921 read_sx_byte (board, 0), read_sx_byte(board, 1), 2008 sx_dprintk(SX_DEBUG_INIT, "init_status: %x, %dk memory, firmware "
1922 read_sx_byte (board, 5), read_sx_byte(board, 4)); 2009 "V%x.%02x,\n",
1923 2010 read_sx_byte(board, 0), read_sx_byte(board, 1),
1924 if (read_sx_byte (board, 0) == 0xff) { 2011 read_sx_byte(board, 5), read_sx_byte(board, 4));
1925 printk (KERN_INFO "sx: No modules found. Sorry.\n"); 2012
2013 if (read_sx_byte(board, 0) == 0xff) {
2014 printk(KERN_INFO "sx: No modules found. Sorry.\n");
1926 board->nports = 0; 2015 board->nports = 0;
1927 return 0; 2016 return 0;
1928 } 2017 }
@@ -1930,82 +2019,97 @@ static int sx_init_board (struct sx_board *board)
1930 chans = 0; 2019 chans = 0;
1931 2020
1932 if (IS_SX_BOARD(board)) { 2021 if (IS_SX_BOARD(board)) {
1933 sx_write_board_word (board, cc_int_count, sx_maxints); 2022 sx_write_board_word(board, cc_int_count, sx_maxints);
1934 } else { 2023 } else {
1935 if (sx_maxints) 2024 if (sx_maxints)
1936 sx_write_board_word (board, cc_int_count, SI_PROCESSOR_CLOCK/8/sx_maxints); 2025 sx_write_board_word(board, cc_int_count,
2026 SI_PROCESSOR_CLOCK / 8 / sx_maxints);
1937 } 2027 }
1938 2028
1939 /* grab the first module type... */ 2029 /* grab the first module type... */
1940 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */ 2030 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
1941 board->ta_type = mod_compat_type (sx_read_module_byte (board, 0x80, mc_chip)); 2031 board->ta_type = mod_compat_type(sx_read_module_byte(board, 0x80,
2032 mc_chip));
1942 2033
1943 /* XXX byteorder */ 2034 /* XXX byteorder */
1944 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) { 2035 for (addr = 0x80; addr != 0; addr = read_sx_word(board, addr) & 0x7fff){
1945 type = sx_read_module_byte (board, addr, mc_chip); 2036 type = sx_read_module_byte(board, addr, mc_chip);
1946 sx_dprintk (SX_DEBUG_INIT, "Module at %x: %d channels\n", 2037 sx_dprintk(SX_DEBUG_INIT, "Module at %x: %d channels\n",
1947 addr, read_sx_byte (board, addr + 2)); 2038 addr, read_sx_byte(board, addr + 2));
1948 2039
1949 chans += sx_read_module_byte (board, addr, mc_type); 2040 chans += sx_read_module_byte(board, addr, mc_type);
1950 2041
1951 sx_dprintk (SX_DEBUG_INIT, "module is an %s, which has %s/%s panels\n", 2042 sx_dprintk(SX_DEBUG_INIT, "module is an %s, which has %s/%s "
1952 mod_type_s (type), 2043 "panels\n",
1953 pan_type_s (sx_read_module_byte (board, addr, mc_mods) & 0xf), 2044 mod_type_s(type),
1954 pan_type_s (sx_read_module_byte (board, addr, mc_mods) >> 4)); 2045 pan_type_s(sx_read_module_byte(board, addr,
1955 2046 mc_mods) & 0xf),
1956 sx_dprintk (SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC version: %x\n", 2047 pan_type_s(sx_read_module_byte(board, addr,
1957 sx_read_module_byte (board, addr, mc_rev1), 2048 mc_mods) >> 4));
1958 sx_read_module_byte (board, addr, mc_rev2), 2049
1959 sx_read_module_byte (board, addr, mc_mtaasic_rev)); 2050 sx_dprintk(SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC "
2051 "version: %x\n",
2052 sx_read_module_byte(board, addr, mc_rev1),
2053 sx_read_module_byte(board, addr, mc_rev2),
2054 sx_read_module_byte(board, addr, mc_mtaasic_rev));
1960 2055
1961 /* The following combinations are illegal: It should theoretically 2056 /* The following combinations are illegal: It should theoretically
1962 work, but timing problems make the bus HANG. */ 2057 work, but timing problems make the bus HANG. */
1963 2058
1964 if (mod_compat_type (type) != board->ta_type) { 2059 if (mod_compat_type(type) != board->ta_type) {
1965 printk (KERN_ERR "sx: This is an invalid configuration.\n" 2060 printk(KERN_ERR "sx: This is an invalid "
1966 "Don't mix TA/MTA/SXDC on the same hostadapter.\n"); 2061 "configuration.\nDon't mix TA/MTA/SXDC on the "
1967 chans=0; 2062 "same hostadapter.\n");
2063 chans = 0;
1968 break; 2064 break;
1969 } 2065 }
1970 if ((IS_EISA_BOARD(board) || 2066 if ((IS_EISA_BOARD(board) ||
1971 IS_SI_BOARD(board)) && (mod_compat_type(type) == 4)) { 2067 IS_SI_BOARD(board)) &&
1972 printk (KERN_ERR "sx: This is an invalid configuration.\n" 2068 (mod_compat_type(type) == 4)) {
1973 "Don't use SXDCs on an SI/XIO adapter.\n"); 2069 printk(KERN_ERR "sx: This is an invalid "
1974 chans=0; 2070 "configuration.\nDon't use SXDCs on an SI/XIO "
2071 "adapter.\n");
2072 chans = 0;
1975 break; 2073 break;
1976 } 2074 }
1977#if 0 /* Problem fixed: firmware 3.05 */ 2075#if 0 /* Problem fixed: firmware 3.05 */
1978 if (IS_SX_BOARD(board) && (type == TA8)) { 2076 if (IS_SX_BOARD(board) && (type == TA8)) {
1979 /* There are some issues with the firmware and the DCD/RTS 2077 /* There are some issues with the firmware and the DCD/RTS
1980 lines. It might work if you tie them together or something. 2078 lines. It might work if you tie them together or something.
1981 It might also work if you get a newer sx_firmware. Therefore 2079 It might also work if you get a newer sx_firmware. Therefore
1982 this is just a warning. */ 2080 this is just a warning. */
1983 printk (KERN_WARNING "sx: The SX host doesn't work too well " 2081 printk(KERN_WARNING
1984 "with the TA8 adapters.\nSpecialix is working on it.\n"); 2082 "sx: The SX host doesn't work too well "
2083 "with the TA8 adapters.\nSpecialix is working on it.\n");
1985 } 2084 }
1986#endif 2085#endif
1987 } 2086 }
1988 2087
1989 if (chans) { 2088 if (chans) {
1990 /* board->flags |= SX_BOARD_PRESENT; */ 2089 if (board->irq > 0) {
1991 if(board->irq > 0) {
1992 /* fixed irq, probably PCI */ 2090 /* fixed irq, probably PCI */
1993 if(sx_irqmask & (1 << board->irq)) { /* may we use this irq? */ 2091 if (sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
1994 if(request_irq(board->irq, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board)) { 2092 if (request_irq(board->irq, sx_interrupt,
1995 printk(KERN_ERR "sx: Cannot allocate irq %d.\n", board->irq); 2093 IRQF_SHARED | IRQF_DISABLED,
2094 "sx", board)) {
2095 printk(KERN_ERR "sx: Cannot allocate "
2096 "irq %d.\n", board->irq);
1996 board->irq = 0; 2097 board->irq = 0;
1997 } 2098 }
1998 } else 2099 } else
1999 board->irq = 0; 2100 board->irq = 0;
2000 } else if(board->irq < 0 && sx_irqmask) { 2101 } else if (board->irq < 0 && sx_irqmask) {
2001 /* auto-allocate irq */ 2102 /* auto-allocate irq */
2002 int irqnr; 2103 int irqnr;
2003 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ? SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK); 2104 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ?
2004 for(irqnr = 15; irqnr > 0; irqnr--) 2105 SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
2005 if(irqmask & (1 << irqnr)) 2106 for (irqnr = 15; irqnr > 0; irqnr--)
2006 if(! request_irq(irqnr, sx_interrupt, IRQF_SHARED | IRQF_DISABLED, "sx", board)) 2107 if (irqmask & (1 << irqnr))
2108 if (!request_irq(irqnr, sx_interrupt,
2109 IRQF_SHARED | IRQF_DISABLED,
2110 "sx", board))
2007 break; 2111 break;
2008 if(! irqnr) 2112 if (!irqnr)
2009 printk(KERN_ERR "sx: Cannot allocate IRQ.\n"); 2113 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2010 board->irq = irqnr; 2114 board->irq = irqnr;
2011 } else 2115 } else
@@ -2013,52 +2117,48 @@ static int sx_init_board (struct sx_board *board)
2013 2117
2014 if (board->irq) { 2118 if (board->irq) {
2015 /* Found a valid interrupt, start up interrupts! */ 2119 /* Found a valid interrupt, start up interrupts! */
2016 sx_dprintk (SX_DEBUG_INIT, "Using irq %d.\n", board->irq); 2120 sx_dprintk(SX_DEBUG_INIT, "Using irq %d.\n",
2017 sx_start_interrupts (board); 2121 board->irq);
2122 sx_start_interrupts(board);
2018 board->poll = sx_slowpoll; 2123 board->poll = sx_slowpoll;
2019 board->flags |= SX_IRQ_ALLOCATED; 2124 board->flags |= SX_IRQ_ALLOCATED;
2020 } else { 2125 } else {
2021 /* no irq: setup board for polled operation */ 2126 /* no irq: setup board for polled operation */
2022 board->poll = sx_poll; 2127 board->poll = sx_poll;
2023 sx_dprintk (SX_DEBUG_INIT, "Using poll-interval %d.\n", board->poll); 2128 sx_dprintk(SX_DEBUG_INIT, "Using poll-interval %d.\n",
2129 board->poll);
2024 } 2130 }
2025 2131
2026 /* The timer should be initialized anyway: That way we can safely 2132 /* The timer should be initialized anyway: That way we can
2027 del_timer it when the module is unloaded. */ 2133 safely del_timer it when the module is unloaded. */
2028 init_timer (&board->timer); 2134 setup_timer(&board->timer, sx_pollfunc, (unsigned long)board);
2029 2135
2030 if (board->poll) { 2136 if (board->poll)
2031 board->timer.data = (unsigned long) board; 2137 mod_timer(&board->timer, jiffies + board->poll);
2032 board->timer.function = sx_pollfunc;
2033 board->timer.expires = jiffies + board->poll;
2034 add_timer (&board->timer);
2035 }
2036 } else { 2138 } else {
2037 board->irq = 0; 2139 board->irq = 0;
2038 } 2140 }
2039 2141
2040 board->nports = chans; 2142 board->nports = chans;
2041 sx_dprintk (SX_DEBUG_INIT, "returning %d ports.", board->nports); 2143 sx_dprintk(SX_DEBUG_INIT, "returning %d ports.", board->nports);
2042 2144
2043 func_exit(); 2145 func_exit();
2044 return chans; 2146 return chans;
2045} 2147}
2046 2148
2047 2149static void __devinit printheader(void)
2048static void printheader(void)
2049{ 2150{
2050 static int header_printed; 2151 static int header_printed;
2051 2152
2052 if (!header_printed) { 2153 if (!header_printed) {
2053 printk (KERN_INFO "Specialix SX driver " 2154 printk(KERN_INFO "Specialix SX driver "
2054 "(C) 1998/1999 R.E.Wolff@BitWizard.nl \n"); 2155 "(C) 1998/1999 R.E.Wolff@BitWizard.nl\n");
2055 printk (KERN_INFO "sx: version %s\n", RCS_ID); 2156 printk(KERN_INFO "sx: version " __stringify(SX_VERSION) "\n");
2056 header_printed = 1; 2157 header_printed = 1;
2057 } 2158 }
2058} 2159}
2059 2160
2060 2161static int __devinit probe_sx(struct sx_board *board)
2061static int probe_sx (struct sx_board *board)
2062{ 2162{
2063 struct vpd_prom vpdp; 2163 struct vpd_prom vpdp;
2064 char *p; 2164 char *p;
@@ -2066,51 +2166,57 @@ static int probe_sx (struct sx_board *board)
2066 2166
2067 func_enter(); 2167 func_enter();
2068 2168
2069 if (!IS_CF_BOARD (board)) { 2169 if (!IS_CF_BOARD(board)) {
2070 sx_dprintk (SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", 2170 sx_dprintk(SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
2071 board->base + SX_VPD_ROM); 2171 board->base + SX_VPD_ROM);
2072 2172
2073 if (sx_debug & SX_DEBUG_PROBE) 2173 if (sx_debug & SX_DEBUG_PROBE)
2074 my_hd_io(board->base + SX_VPD_ROM, 0x40); 2174 my_hd_io(board->base + SX_VPD_ROM, 0x40);
2075 2175
2076 p = (char *) &vpdp; 2176 p = (char *)&vpdp;
2077 for (i=0;i< sizeof (struct vpd_prom);i++) 2177 for (i = 0; i < sizeof(struct vpd_prom); i++)
2078 *p++ = read_sx_byte (board, SX_VPD_ROM + i*2); 2178 *p++ = read_sx_byte(board, SX_VPD_ROM + i * 2);
2079 2179
2080 if (sx_debug & SX_DEBUG_PROBE) 2180 if (sx_debug & SX_DEBUG_PROBE)
2081 my_hd (&vpdp, 0x20); 2181 my_hd(&vpdp, 0x20);
2082 2182
2083 sx_dprintk (SX_DEBUG_PROBE, "checking identifier...\n"); 2183 sx_dprintk(SX_DEBUG_PROBE, "checking identifier...\n");
2084 2184
2085 if (strncmp (vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) { 2185 if (strncmp(vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2086 sx_dprintk (SX_DEBUG_PROBE, "Got non-SX identifier: '%s'\n", 2186 sx_dprintk(SX_DEBUG_PROBE, "Got non-SX identifier: "
2087 vpdp.identifier); 2187 "'%s'\n", vpdp.identifier);
2088 return 0; 2188 return 0;
2089 } 2189 }
2090 } 2190 }
2091 2191
2092 printheader (); 2192 printheader();
2093
2094 if (!IS_CF_BOARD (board)) {
2095 printk (KERN_DEBUG "sx: Found an SX board at %lx\n", board->hw_base);
2096 printk (KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, uniq ID:%08x, ",
2097 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2098 printk ( "Manufactured: %d/%d\n",
2099 1970 + vpdp.myear, vpdp.mweek);
2100 2193
2194 if (!IS_CF_BOARD(board)) {
2195 printk(KERN_DEBUG "sx: Found an SX board at %lx\n",
2196 board->hw_base);
2197 printk(KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, "
2198 "uniq ID:%08x, ",
2199 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2200 printk("Manufactured: %d/%d\n", 1970 + vpdp.myear, vpdp.mweek);
2101 2201
2102 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_PCI_UNIQUEID1) && 2202 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) !=
2103 (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) { 2203 SX_PCI_UNIQUEID1) && (((vpdp.uniqid >> 24) &
2104 /* This might be a bit harsh. This was the primary reason the 2204 SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2105 SX/ISA card didn't work at first... */ 2205 /* This might be a bit harsh. This was the primary
2106 printk (KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA card. Sorry: giving up.\n"); 2206 reason the SX/ISA card didn't work at first... */
2207 printk(KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA "
2208 "card. Sorry: giving up.\n");
2107 return (0); 2209 return (0);
2108 } 2210 }
2109 2211
2110 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) == SX_ISA_UNIQUEID1) { 2212 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) ==
2213 SX_ISA_UNIQUEID1) {
2111 if (((unsigned long)board->hw_base) & 0x8000) { 2214 if (((unsigned long)board->hw_base) & 0x8000) {
2112 printk (KERN_WARNING "sx: Warning: There may be hardware problems with the card at %lx.\n", board->hw_base); 2215 printk(KERN_WARNING "sx: Warning: There may be "
2113 printk (KERN_WARNING "sx: Read sx.txt for more info.\n"); 2216 "hardware problems with the card at "
2217 "%lx.\n", board->hw_base);
2218 printk(KERN_WARNING "sx: Read sx.txt for more "
2219 "info.\n");
2114 } 2220 }
2115 } 2221 }
2116 } 2222 }
@@ -2118,17 +2224,15 @@ static int probe_sx (struct sx_board *board)
2118 board->nports = -1; 2224 board->nports = -1;
2119 2225
2120 /* This resets the processor, and keeps it off the bus. */ 2226 /* This resets the processor, and keeps it off the bus. */
2121 if (!sx_reset (board)) 2227 if (!sx_reset(board))
2122 return 0; 2228 return 0;
2123 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 2229 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
2124
2125 board->flags |= SX_BOARD_PRESENT;
2126 2230
2127 func_exit(); 2231 func_exit();
2128 return 1; 2232 return 1;
2129} 2233}
2130 2234
2131 2235#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
2132 2236
2133/* Specialix probes for this card at 32k increments from 640k to 16M. 2237/* Specialix probes for this card at 32k increments from 640k to 16M.
2134 I consider machines with less than 16M unlikely nowadays, so I'm 2238 I consider machines with less than 16M unlikely nowadays, so I'm
@@ -2136,28 +2240,27 @@ static int probe_sx (struct sx_board *board)
2136 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves 2240 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2137 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */ 2241 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2138 2242
2139static int probe_si (struct sx_board *board) 2243static int __devinit probe_si(struct sx_board *board)
2140{ 2244{
2141 int i; 2245 int i;
2142 2246
2143 func_enter(); 2247 func_enter();
2144 sx_dprintk (SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at %p.\n", board->hw_base, 2248 sx_dprintk(SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at "
2145 board->base + SI2_ISA_ID_BASE); 2249 "%p.\n", board->hw_base, board->base + SI2_ISA_ID_BASE);
2146 2250
2147 if (sx_debug & SX_DEBUG_PROBE) 2251 if (sx_debug & SX_DEBUG_PROBE)
2148 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8); 2252 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8);
2149 2253
2150 if (!IS_EISA_BOARD(board)) { 2254 if (!IS_EISA_BOARD(board)) {
2151 if( IS_SI1_BOARD(board) ) 2255 if (IS_SI1_BOARD(board)) {
2152 { 2256 for (i = 0; i < 8; i++) {
2153 for (i=0;i<8;i++) { 2257 write_sx_byte(board, SI2_ISA_ID_BASE + 7 - i,i);
2154 write_sx_byte (board, SI2_ISA_ID_BASE+7-i,i); 2258 }
2155
2156 } 2259 }
2157 } 2260 for (i = 0; i < 8; i++) {
2158 for (i=0;i<8;i++) { 2261 if ((read_sx_byte(board, SI2_ISA_ID_BASE + 7 - i) & 7)
2159 if ((read_sx_byte (board, SI2_ISA_ID_BASE+7-i) & 7) != i) { 2262 != i) {
2160 func_exit (); 2263 func_exit();
2161 return 0; 2264 return 0;
2162 } 2265 }
2163 } 2266 }
@@ -2167,20 +2270,20 @@ static int probe_si (struct sx_board *board)
2167 but to prevent trouble, we'd better double check that we don't 2270 but to prevent trouble, we'd better double check that we don't
2168 have an SI1 board when we're probing for an SI2 board.... */ 2271 have an SI1 board when we're probing for an SI2 board.... */
2169 2272
2170 write_sx_byte (board, SI2_ISA_ID_BASE,0x10); 2273 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2171 if ( IS_SI1_BOARD(board)) { 2274 if (IS_SI1_BOARD(board)) {
2172 /* This should be an SI1 board, which has this 2275 /* This should be an SI1 board, which has this
2173 location writable... */ 2276 location writable... */
2174 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) { 2277 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
2175 func_exit (); 2278 func_exit();
2176 return 0; 2279 return 0;
2177 } 2280 }
2178 } else { 2281 } else {
2179 /* This should be an SI2 board, which has the bottom 2282 /* This should be an SI2 board, which has the bottom
2180 3 bits non-writable... */ 2283 3 bits non-writable... */
2181 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) { 2284 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2182 func_exit (); 2285 func_exit();
2183 return 0; 2286 return 0;
2184 } 2287 }
2185 } 2288 }
2186 2289
@@ -2188,45 +2291,44 @@ static int probe_si (struct sx_board *board)
2188 but to prevent trouble, we'd better double check that we don't 2291 but to prevent trouble, we'd better double check that we don't
2189 have an SI1 board when we're probing for an SI2 board.... */ 2292 have an SI1 board when we're probing for an SI2 board.... */
2190 2293
2191 write_sx_byte (board, SI2_ISA_ID_BASE,0x10); 2294 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2192 if ( IS_SI1_BOARD(board)) { 2295 if (IS_SI1_BOARD(board)) {
2193 /* This should be an SI1 board, which has this 2296 /* This should be an SI1 board, which has this
2194 location writable... */ 2297 location writable... */
2195 if (read_sx_byte (board, SI2_ISA_ID_BASE) != 0x10) { 2298 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
2196 func_exit(); 2299 func_exit();
2197 return 0; 2300 return 0;
2198 } 2301 }
2199 } else { 2302 } else {
2200 /* This should be an SI2 board, which has the bottom 2303 /* This should be an SI2 board, which has the bottom
2201 3 bits non-writable... */ 2304 3 bits non-writable... */
2202 if (read_sx_byte (board, SI2_ISA_ID_BASE) == 0x10) { 2305 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2203 func_exit (); 2306 func_exit();
2204 return 0; 2307 return 0;
2205 } 2308 }
2206 } 2309 }
2207 2310
2208 printheader (); 2311 printheader();
2209 2312
2210 printk (KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base); 2313 printk(KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
2211 /* Compared to the SX boards, it is a complete guess as to what 2314 /* Compared to the SX boards, it is a complete guess as to what
2212 this card is up to... */ 2315 this card is up to... */
2213 2316
2214 board->nports = -1; 2317 board->nports = -1;
2215 2318
2216 /* This resets the processor, and keeps it off the bus. */ 2319 /* This resets the processor, and keeps it off the bus. */
2217 if (!sx_reset (board)) 2320 if (!sx_reset(board))
2218 return 0; 2321 return 0;
2219 sx_dprintk (SX_DEBUG_INIT, "reset the board...\n"); 2322 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
2220
2221 board->flags |= SX_BOARD_PRESENT;
2222 2323
2223 func_exit(); 2324 func_exit();
2224 return 1; 2325 return 1;
2225} 2326}
2327#endif
2226 2328
2227static const struct tty_operations sx_ops = { 2329static const struct tty_operations sx_ops = {
2228 .break_ctl = sx_break, 2330 .break_ctl = sx_break,
2229 .open = sx_open, 2331 .open = sx_open,
2230 .close = gs_close, 2332 .close = gs_close,
2231 .write = gs_write, 2333 .write = gs_write,
2232 .put_char = gs_put_char, 2334 .put_char = gs_put_char,
@@ -2261,34 +2363,23 @@ static int sx_init_drivers(void)
2261 sx_driver->type = TTY_DRIVER_TYPE_SERIAL; 2363 sx_driver->type = TTY_DRIVER_TYPE_SERIAL;
2262 sx_driver->subtype = SERIAL_TYPE_NORMAL; 2364 sx_driver->subtype = SERIAL_TYPE_NORMAL;
2263 sx_driver->init_termios = tty_std_termios; 2365 sx_driver->init_termios = tty_std_termios;
2264 sx_driver->init_termios.c_cflag = 2366 sx_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2265 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2367 sx_driver->init_termios.c_ispeed = 9600;
2368 sx_driver->init_termios.c_ospeed = 9600;
2266 sx_driver->flags = TTY_DRIVER_REAL_RAW; 2369 sx_driver->flags = TTY_DRIVER_REAL_RAW;
2267 tty_set_operations(sx_driver, &sx_ops); 2370 tty_set_operations(sx_driver, &sx_ops);
2268 2371
2269 if ((error = tty_register_driver(sx_driver))) { 2372 if ((error = tty_register_driver(sx_driver))) {
2270 put_tty_driver(sx_driver); 2373 put_tty_driver(sx_driver);
2271 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n", 2374 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
2272 error); 2375 error);
2273 return 1; 2376 return 1;
2274 } 2377 }
2275 func_exit(); 2378 func_exit();
2276 return 0; 2379 return 0;
2277} 2380}
2278 2381
2279 2382static int sx_init_portstructs(int nboards, int nports)
2280static void * ckmalloc (int size)
2281{
2282 void *p;
2283
2284 p = kmalloc(size, GFP_KERNEL);
2285 if (p)
2286 memset(p, 0, size);
2287 return p;
2288}
2289
2290
2291static int sx_init_portstructs (int nboards, int nports)
2292{ 2383{
2293 struct sx_board *board; 2384 struct sx_board *board;
2294 struct sx_port *port; 2385 struct sx_port *port;
@@ -2299,8 +2390,9 @@ static int sx_init_portstructs (int nboards, int nports)
2299 func_enter(); 2390 func_enter();
2300 2391
2301 /* Many drivers statically allocate the maximum number of ports 2392 /* Many drivers statically allocate the maximum number of ports
2302 There is no reason not to allocate them dynamically. Is there? -- REW */ 2393 There is no reason not to allocate them dynamically.
2303 sx_ports = ckmalloc(nports * sizeof (struct sx_port)); 2394 Is there? -- REW */
2395 sx_ports = kcalloc(nports, sizeof(struct sx_port), GFP_KERNEL);
2304 if (!sx_ports) 2396 if (!sx_ports)
2305 return -ENOMEM; 2397 return -ENOMEM;
2306 2398
@@ -2308,10 +2400,10 @@ static int sx_init_portstructs (int nboards, int nports)
2308 for (i = 0; i < nboards; i++) { 2400 for (i = 0; i < nboards; i++) {
2309 board = &boards[i]; 2401 board = &boards[i];
2310 board->ports = port; 2402 board->ports = port;
2311 for (j=0; j < boards[i].nports;j++) { 2403 for (j = 0; j < boards[i].nports; j++) {
2312 sx_dprintk (SX_DEBUG_INIT, "initing port %d\n", j); 2404 sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j);
2313 port->gs.magic = SX_MAGIC; 2405 port->gs.magic = SX_MAGIC;
2314 port->gs.close_delay = HZ/2; 2406 port->gs.close_delay = HZ / 2;
2315 port->gs.closing_wait = 30 * HZ; 2407 port->gs.closing_wait = 30 * HZ;
2316 port->board = board; 2408 port->board = board;
2317 port->gs.rd = &sx_real_driver; 2409 port->gs.rd = &sx_real_driver;
@@ -2323,8 +2415,8 @@ static int sx_init_portstructs (int nboards, int nports)
2323 * Initializing wait queue 2415 * Initializing wait queue
2324 */ 2416 */
2325 init_waitqueue_head(&port->gs.open_wait); 2417 init_waitqueue_head(&port->gs.open_wait);
2326 init_waitqueue_head(&port->gs.close_wait); 2418 init_waitqueue_head(&port->gs.close_wait);
2327 2419
2328 port++; 2420 port++;
2329 } 2421 }
2330 } 2422 }
@@ -2335,28 +2427,36 @@ static int sx_init_portstructs (int nboards, int nports)
2335 board = &boards[i]; 2427 board = &boards[i];
2336 board->port_base = portno; 2428 board->port_base = portno;
2337 /* Possibly the configuration was rejected. */ 2429 /* Possibly the configuration was rejected. */
2338 sx_dprintk (SX_DEBUG_PROBE, "Board has %d channels\n", board->nports); 2430 sx_dprintk(SX_DEBUG_PROBE, "Board has %d channels\n",
2339 if (board->nports <= 0) continue; 2431 board->nports);
2432 if (board->nports <= 0)
2433 continue;
2340 /* XXX byteorder ?? */ 2434 /* XXX byteorder ?? */
2341 for (addr = 0x80;addr != 0;addr = read_sx_word (board, addr) & 0x7fff) { 2435 for (addr = 0x80; addr != 0;
2342 chans = sx_read_module_byte (board, addr, mc_type); 2436 addr = read_sx_word(board, addr) & 0x7fff) {
2343 sx_dprintk (SX_DEBUG_PROBE, "Module at %x: %d channels\n", addr, chans); 2437 chans = sx_read_module_byte(board, addr, mc_type);
2344 sx_dprintk (SX_DEBUG_PROBE, "Port at"); 2438 sx_dprintk(SX_DEBUG_PROBE, "Module at %x: %d "
2345 for (j=0;j<chans;j++) { 2439 "channels\n", addr, chans);
2346 /* The "sx-way" is the way it SHOULD be done. That way in the 2440 sx_dprintk(SX_DEBUG_PROBE, "Port at");
2347 future, the firmware may for example pack the structures a bit 2441 for (j = 0; j < chans; j++) {
2348 more efficient. Neil tells me it isn't going to happen anytime 2442 /* The "sx-way" is the way it SHOULD be done.
2349 soon though. */ 2443 That way in the future, the firmware may for
2444 example pack the structures a bit more
2445 efficient. Neil tells me it isn't going to
2446 happen anytime soon though. */
2350 if (IS_SX_BOARD(board)) 2447 if (IS_SX_BOARD(board))
2351 port->ch_base = sx_read_module_word (board, addr+j*2, mc_chan_pointer); 2448 port->ch_base = sx_read_module_word(
2449 board, addr + j * 2,
2450 mc_chan_pointer);
2352 else 2451 else
2353 port->ch_base = addr + 0x100 + 0x300*j; 2452 port->ch_base = addr + 0x100 + 0x300 *j;
2354 2453
2355 sx_dprintk (SX_DEBUG_PROBE, " %x", port->ch_base); 2454 sx_dprintk(SX_DEBUG_PROBE, " %x",
2455 port->ch_base);
2356 port->line = portno++; 2456 port->line = portno++;
2357 port++; 2457 port++;
2358 } 2458 }
2359 sx_dprintk (SX_DEBUG_PROBE, "\n"); 2459 sx_dprintk(SX_DEBUG_PROBE, "\n");
2360 } 2460 }
2361 /* This has to be done earlier. */ 2461 /* This has to be done earlier. */
2362 /* board->flags |= SX_BOARD_INITIALIZED; */ 2462 /* board->flags |= SX_BOARD_INITIALIZED; */
@@ -2366,6 +2466,17 @@ static int sx_init_portstructs (int nboards, int nports)
2366 return 0; 2466 return 0;
2367} 2467}
2368 2468
2469static unsigned int sx_find_free_board(void)
2470{
2471 unsigned int i;
2472
2473 for (i = 0; i < SX_NBOARDS; i++)
2474 if (!(boards[i].flags & SX_BOARD_PRESENT))
2475 break;
2476
2477 return i;
2478}
2479
2369static void __exit sx_release_drivers(void) 2480static void __exit sx_release_drivers(void)
2370{ 2481{
2371 func_enter(); 2482 func_enter();
@@ -2374,7 +2485,122 @@ static void __exit sx_release_drivers(void)
2374 func_exit(); 2485 func_exit();
2375} 2486}
2376 2487
2377#ifdef CONFIG_PCI 2488static void __devexit sx_remove_card(struct sx_board *board,
2489 struct pci_dev *pdev)
2490{
2491 if (board->flags & SX_BOARD_INITIALIZED) {
2492 /* The board should stop messing with us. (actually I mean the
2493 interrupt) */
2494 sx_reset(board);
2495 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2496 free_irq(board->irq, board);
2497
2498 /* It is safe/allowed to del_timer a non-active timer */
2499 del_timer(&board->timer);
2500 if (pdev) {
2501 pci_iounmap(pdev, board->base);
2502 pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
2503 } else {
2504 iounmap(board->base);
2505 release_region(board->hw_base, board->hw_len);
2506 }
2507
2508 board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT);
2509 }
2510}
2511
2512#ifdef CONFIG_EISA
2513
2514static int __devinit sx_eisa_probe(struct device *dev)
2515{
2516 struct eisa_device *edev = to_eisa_device(dev);
2517 struct sx_board *board;
2518 unsigned long eisa_slot = edev->base_addr;
2519 unsigned int i;
2520 int retval = -EIO;
2521
2522 mutex_lock(&sx_boards_lock);
2523 i = sx_find_free_board();
2524 if (i == SX_NBOARDS) {
2525 mutex_unlock(&sx_boards_lock);
2526 goto err;
2527 }
2528 board = &boards[i];
2529 board->flags |= SX_BOARD_PRESENT;
2530 mutex_unlock(&sx_boards_lock);
2531
2532 dev_info(dev, "XIO : Signature found in EISA slot %lu, "
2533 "Product %d Rev %d (REPORT THIS TO LKLM)\n",
2534 eisa_slot >> 12,
2535 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 2),
2536 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 3));
2537
2538 board->eisa_base = eisa_slot;
2539 board->flags &= ~SX_BOARD_TYPE;
2540 board->flags |= SI_EISA_BOARD;
2541
2542 board->hw_base = ((inb(eisa_slot + 0xc01) << 8) +
2543 inb(eisa_slot + 0xc00)) << 16;
2544 board->hw_len = SI2_EISA_WINDOW_LEN;
2545 if (!request_region(board->hw_base, board->hw_len, "sx")) {
2546 dev_err(dev, "can't request region\n");
2547 goto err_flag;
2548 }
2549 board->base2 =
2550 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2551 if (!board->base) {
2552 dev_err(dev, "can't remap memory\n");
2553 goto err_reg;
2554 }
2555
2556 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2557 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2558 board->irq = inb(eisa_slot + 0xc02) >> 4;
2559 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2560
2561 if (!probe_si(board))
2562 goto err_unmap;
2563
2564 dev_set_drvdata(dev, board);
2565
2566 return 0;
2567err_unmap:
2568 iounmap(board->base);
2569err_reg:
2570 release_region(board->hw_base, board->hw_len);
2571err_flag:
2572 board->flags &= ~SX_BOARD_PRESENT;
2573err:
2574 return retval;
2575}
2576
2577static int __devexit sx_eisa_remove(struct device *dev)
2578{
2579 struct sx_board *board = dev_get_drvdata(dev);
2580
2581 sx_remove_card(board, NULL);
2582
2583 return 0;
2584}
2585
2586static struct eisa_device_id sx_eisa_tbl[] = {
2587 { "SLX" },
2588 { "" }
2589};
2590
2591MODULE_DEVICE_TABLE(eisa, sx_eisa_tbl);
2592
2593static struct eisa_driver sx_eisadriver = {
2594 .id_table = sx_eisa_tbl,
2595 .driver = {
2596 .name = "sx",
2597 .probe = sx_eisa_probe,
2598 .remove = __devexit_p(sx_eisa_remove),
2599 }
2600};
2601
2602#endif
2603
2378 /******************************************************** 2604 /********************************************************
2379 * Setting bit 17 in the CNTRL register of the PLX 9050 * 2605 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2380 * chip forces a retry on writes while a read is pending.* 2606 * chip forces a retry on writes while a read is pending.*
@@ -2386,233 +2612,265 @@ static void __exit sx_release_drivers(void)
2386 EEprom. As the bit is read/write for the CPU, we can fix it here, 2612 EEprom. As the bit is read/write for the CPU, we can fix it here,
2387 if we detect that it isn't set correctly. -- REW */ 2613 if we detect that it isn't set correctly. -- REW */
2388 2614
2389static void fix_sx_pci (struct pci_dev *pdev, struct sx_board *board) 2615static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
2390{ 2616{
2391 unsigned int hwbase; 2617 unsigned int hwbase;
2392 void __iomem *rebase; 2618 void __iomem *rebase;
2393 unsigned int t; 2619 unsigned int t;
2394 2620
2395#define CNTRL_REG_OFFSET 0x50 2621#define CNTRL_REG_OFFSET 0x50
2396#define CNTRL_REG_GOODVALUE 0x18260000 2622#define CNTRL_REG_GOODVALUE 0x18260000
2397 2623
2398 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase); 2624 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2399 hwbase &= PCI_BASE_ADDRESS_MEM_MASK; 2625 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
2400 rebase = ioremap(hwbase, 0x80); 2626 rebase = ioremap(hwbase, 0x80);
2401 t = readl (rebase + CNTRL_REG_OFFSET); 2627 t = readl(rebase + CNTRL_REG_OFFSET);
2402 if (t != CNTRL_REG_GOODVALUE) { 2628 if (t != CNTRL_REG_GOODVALUE) {
2403 printk (KERN_DEBUG "sx: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE); 2629 printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> "
2404 writel (CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET); 2630 "%08x\n", t, CNTRL_REG_GOODVALUE);
2631 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
2405 } 2632 }
2406 iounmap(rebase); 2633 iounmap(rebase);
2407} 2634}
2408#endif
2409
2410 2635
2411static int __init sx_init(void) 2636static int __devinit sx_pci_probe(struct pci_dev *pdev,
2637 const struct pci_device_id *ent)
2412{ 2638{
2413 int i;
2414 int found = 0;
2415 int eisa_slot;
2416 struct sx_board *board; 2639 struct sx_board *board;
2640 unsigned int i, reg;
2641 int retval = -EIO;
2417 2642
2418#ifdef CONFIG_PCI 2643 mutex_lock(&sx_boards_lock);
2419 struct pci_dev *pdev = NULL; 2644 i = sx_find_free_board();
2420 unsigned int tint; 2645 if (i == SX_NBOARDS) {
2421 unsigned short tshort; 2646 mutex_unlock(&sx_boards_lock);
2422#endif 2647 goto err;
2648 }
2649 board = &boards[i];
2650 board->flags |= SX_BOARD_PRESENT;
2651 mutex_unlock(&sx_boards_lock);
2423 2652
2424 func_enter(); 2653 retval = pci_enable_device(pdev);
2425 sx_dprintk (SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n", sx_debug); 2654 if (retval)
2426 if (abs ((long) (&sx_debug) - sx_debug) < 0x10000) { 2655 goto err_flag;
2427 printk (KERN_WARNING "sx: sx_debug is an address, instead of a value. " 2656
2428 "Assuming -1.\n"); 2657 board->flags &= ~SX_BOARD_TYPE;
2429 printk ("(%p)\n", &sx_debug); 2658 board->flags |= (pdev->subsystem_vendor == 0x200) ? SX_PCI_BOARD :
2430 sx_debug=-1; 2659 SX_CFPCI_BOARD;
2660
2661 /* CF boards use base address 3.... */
2662 reg = IS_CF_BOARD(board) ? 3 : 2;
2663 retval = pci_request_region(pdev, reg, "sx");
2664 if (retval) {
2665 dev_err(&pdev->dev, "can't request region\n");
2666 goto err_flag;
2667 }
2668 board->hw_base = pci_resource_start(pdev, reg);
2669 board->base2 =
2670 board->base = pci_iomap(pdev, reg, WINDOW_LEN(board));
2671 if (!board->base) {
2672 dev_err(&pdev->dev, "ioremap failed\n");
2673 goto err_reg;
2431 } 2674 }
2432 2675
2433 if (misc_register(&sx_fw_device) < 0) { 2676 /* Most of the stuff on the CF board is offset by 0x18000 .... */
2434 printk(KERN_ERR "SX: Unable to register firmware loader driver.\n"); 2677 if (IS_CF_BOARD(board))
2435 return -EIO; 2678 board->base += 0x18000;
2679
2680 board->irq = pdev->irq;
2681
2682 dev_info(&pdev->dev, "Got a specialix card: %p(%d) %x.\n", board->base,
2683 board->irq, board->flags);
2684
2685 if (!probe_sx(board)) {
2686 retval = -EIO;
2687 goto err_unmap;
2436 } 2688 }
2437 2689
2438#ifdef CONFIG_PCI 2690 fix_sx_pci(pdev, board);
2439 while ((pdev = pci_find_device (PCI_VENDOR_ID_SPECIALIX,
2440 PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2441 pdev))) {
2442 if (pci_enable_device(pdev))
2443 continue;
2444 2691
2445 /* Specialix has a whole bunch of cards with 2692 pci_set_drvdata(pdev, board);
2446 0x2000 as the device ID. They say its because
2447 the standard requires it. Stupid standard. */
2448 /* It seems that reading a word doesn't work reliably on 2.0.
2449 Also, reading a non-aligned dword doesn't work. So we read the
2450 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
2451 ourselves */
2452 /* I don't know why the define doesn't work, constant 0x2c does --REW */
2453 pci_read_config_dword (pdev, 0x2c, &tint);
2454 tshort = (tint >> 16) & 0xffff;
2455 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
2456 /* sx_dprintk (SX_DEBUG_PROBE, "pdev = %d/%d (%x)\n", pdev, tint); */
2457 if ((tshort != 0x0200) && (tshort != 0x0300)) {
2458 sx_dprintk (SX_DEBUG_PROBE, "But it's not an SX card (%d)...\n",
2459 tshort);
2460 continue;
2461 }
2462 board = &boards[found];
2463 2693
2464 board->flags &= ~SX_BOARD_TYPE; 2694 return 0;
2465 board->flags |= (tshort == 0x200)?SX_PCI_BOARD: 2695err_unmap:
2466 SX_CFPCI_BOARD; 2696 pci_iounmap(pdev, board->base);
2467 2697err_reg:
2468 /* CF boards use base address 3.... */ 2698 pci_release_region(pdev, reg);
2469 if (IS_CF_BOARD (board)) 2699err_flag:
2470 board->hw_base = pci_resource_start (pdev, 3); 2700 board->flags &= ~SX_BOARD_PRESENT;
2471 else 2701err:
2472 board->hw_base = pci_resource_start (pdev, 2); 2702 return retval;
2473 board->base2 = 2703}
2474 board->base = ioremap(board->hw_base, WINDOW_LEN (board));
2475 if (!board->base) {
2476 printk(KERN_ERR "ioremap failed\n");
2477 /* XXX handle error */
2478 }
2479 2704
2480 /* Most of the stuff on the CF board is offset by 2705static void __devexit sx_pci_remove(struct pci_dev *pdev)
2481 0x18000 .... */ 2706{
2482 if (IS_CF_BOARD (board)) board->base += 0x18000; 2707 struct sx_board *board = pci_get_drvdata(pdev);
2483 2708
2484 board->irq = pdev->irq; 2709 sx_remove_card(board, pdev);
2710}
2485 2711
2486 sx_dprintk (SX_DEBUG_PROBE, "Got a specialix card: %x/%p(%d) %x.\n", 2712/* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
2487 tint, boards[found].base, board->irq, board->flags); 2713 its because the standard requires it. So check for SUBVENDOR_ID. */
2714static struct pci_device_id sx_pci_tbl[] = {
2715 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2716 .subvendor = 0x0200,.subdevice = PCI_ANY_ID },
2717 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
2718 .subvendor = 0x0300,.subdevice = PCI_ANY_ID },
2719 { 0 }
2720};
2488 2721
2489 if (probe_sx (board)) { 2722MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
2490 found++; 2723
2491 fix_sx_pci (pdev, board); 2724static struct pci_driver sx_pcidriver = {
2492 } else 2725 .name = "sx",
2493 iounmap(board->base2); 2726 .id_table = sx_pci_tbl,
2494 } 2727 .probe = sx_pci_probe,
2728 .remove = __devexit_p(sx_pci_remove)
2729};
2730
2731static int __init sx_init(void)
2732{
2733#ifdef CONFIG_EISA
2734 int retval1;
2495#endif 2735#endif
2736#ifdef CONFIG_ISA
2737 struct sx_board *board;
2738 unsigned int i;
2739#endif
2740 unsigned int found = 0;
2741 int retval;
2742
2743 func_enter();
2744 sx_dprintk(SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n",
2745 sx_debug);
2746 if (abs((long)(&sx_debug) - sx_debug) < 0x10000) {
2747 printk(KERN_WARNING "sx: sx_debug is an address, instead of a "
2748 "value. Assuming -1.\n(%p)\n", &sx_debug);
2749 sx_debug = -1;
2750 }
2496 2751
2497 for (i=0;i<NR_SX_ADDRS;i++) { 2752 if (misc_register(&sx_fw_device) < 0) {
2753 printk(KERN_ERR "SX: Unable to register firmware loader "
2754 "driver.\n");
2755 return -EIO;
2756 }
2757#ifdef CONFIG_ISA
2758 for (i = 0; i < NR_SX_ADDRS; i++) {
2498 board = &boards[found]; 2759 board = &boards[found];
2499 board->hw_base = sx_probe_addrs[i]; 2760 board->hw_base = sx_probe_addrs[i];
2761 board->hw_len = SX_WINDOW_LEN;
2762 if (!request_region(board->hw_base, board->hw_len, "sx"))
2763 continue;
2500 board->base2 = 2764 board->base2 =
2501 board->base = ioremap(board->hw_base, SX_WINDOW_LEN); 2765 board->base = ioremap(board->hw_base, board->hw_len);
2766 if (!board->base)
2767 goto err_sx_reg;
2502 board->flags &= ~SX_BOARD_TYPE; 2768 board->flags &= ~SX_BOARD_TYPE;
2503 board->flags |= SX_ISA_BOARD; 2769 board->flags |= SX_ISA_BOARD;
2504 board->irq = sx_irqmask?-1:0; 2770 board->irq = sx_irqmask ? -1 : 0;
2505 2771
2506 if (probe_sx (board)) { 2772 if (probe_sx(board)) {
2773 board->flags |= SX_BOARD_PRESENT;
2507 found++; 2774 found++;
2508 } else { 2775 } else {
2509 iounmap(board->base); 2776 iounmap(board->base);
2777err_sx_reg:
2778 release_region(board->hw_base, board->hw_len);
2510 } 2779 }
2511 } 2780 }
2512 2781
2513 for (i=0;i<NR_SI_ADDRS;i++) { 2782 for (i = 0; i < NR_SI_ADDRS; i++) {
2514 board = &boards[found]; 2783 board = &boards[found];
2515 board->hw_base = si_probe_addrs[i]; 2784 board->hw_base = si_probe_addrs[i];
2785 board->hw_len = SI2_ISA_WINDOW_LEN;
2786 if (!request_region(board->hw_base, board->hw_len, "sx"))
2787 continue;
2516 board->base2 = 2788 board->base2 =
2517 board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN); 2789 board->base = ioremap(board->hw_base, board->hw_len);
2790 if (!board->base)
2791 goto err_si_reg;
2518 board->flags &= ~SX_BOARD_TYPE; 2792 board->flags &= ~SX_BOARD_TYPE;
2519 board->flags |= SI_ISA_BOARD; 2793 board->flags |= SI_ISA_BOARD;
2520 board->irq = sx_irqmask ?-1:0; 2794 board->irq = sx_irqmask ? -1 : 0;
2521 2795
2522 if (probe_si (board)) { 2796 if (probe_si(board)) {
2797 board->flags |= SX_BOARD_PRESENT;
2523 found++; 2798 found++;
2524 } else { 2799 } else {
2525 iounmap (board->base); 2800 iounmap(board->base);
2801err_si_reg:
2802 release_region(board->hw_base, board->hw_len);
2526 } 2803 }
2527 } 2804 }
2528 for (i=0;i<NR_SI1_ADDRS;i++) { 2805 for (i = 0; i < NR_SI1_ADDRS; i++) {
2529 board = &boards[found]; 2806 board = &boards[found];
2530 board->hw_base = si1_probe_addrs[i]; 2807 board->hw_base = si1_probe_addrs[i];
2808 board->hw_len = SI1_ISA_WINDOW_LEN;
2809 if (!request_region(board->hw_base, board->hw_len, "sx"))
2810 continue;
2531 board->base2 = 2811 board->base2 =
2532 board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN); 2812 board->base = ioremap(board->hw_base, board->hw_len);
2813 if (!board->base)
2814 goto err_si1_reg;
2533 board->flags &= ~SX_BOARD_TYPE; 2815 board->flags &= ~SX_BOARD_TYPE;
2534 board->flags |= SI1_ISA_BOARD; 2816 board->flags |= SI1_ISA_BOARD;
2535 board->irq = sx_irqmask ?-1:0; 2817 board->irq = sx_irqmask ? -1 : 0;
2536 2818
2537 if (probe_si (board)) { 2819 if (probe_si(board)) {
2820 board->flags |= SX_BOARD_PRESENT;
2538 found++; 2821 found++;
2539 } else { 2822 } else {
2540 iounmap (board->base); 2823 iounmap(board->base);
2824err_si1_reg:
2825 release_region(board->hw_base, board->hw_len);
2541 } 2826 }
2542 } 2827 }
2828#endif
2829#ifdef CONFIG_EISA
2830 retval1 = eisa_driver_register(&sx_eisadriver);
2831#endif
2832 retval = pci_register_driver(&sx_pcidriver);
2543 2833
2544 sx_dprintk(SX_DEBUG_PROBE, "Probing for EISA cards\n");
2545 for(eisa_slot=0x1000; eisa_slot<0x10000; eisa_slot+=0x1000)
2546 {
2547 if((inb(eisa_slot+0xc80)==0x4d) &&
2548 (inb(eisa_slot+0xc81)==0x98))
2549 {
2550 sx_dprintk(SX_DEBUG_PROBE, "%s : Signature found in EISA slot %d, Product %d Rev %d\n",
2551 "XIO", (eisa_slot>>12), inb(eisa_slot+0xc82), inb(eisa_slot+0xc83));
2552
2553 board = &boards[found];
2554 board->eisa_base = eisa_slot;
2555 board->flags &= ~SX_BOARD_TYPE;
2556 board->flags |= SI_EISA_BOARD;
2557
2558 board->hw_base = (((inb(0xc01+eisa_slot) << 8) + inb(0xc00+eisa_slot)) << 16);
2559 board->base2 =
2560 board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
2561
2562 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2563 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2564 board->irq = inb(board->eisa_base+0xc02)>>4;
2565 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2566
2567 probe_si(board);
2568
2569 found++;
2570 }
2571 }
2572 if (found) { 2834 if (found) {
2573 printk (KERN_INFO "sx: total of %d boards detected.\n", found); 2835 printk(KERN_INFO "sx: total of %d boards detected.\n", found);
2574 } else { 2836 retval = 0;
2575 misc_deregister(&sx_fw_device); 2837 } else if (retval) {
2838#ifdef CONFIG_EISA
2839 retval = retval1;
2840 if (retval1)
2841#endif
2842 misc_deregister(&sx_fw_device);
2576 } 2843 }
2577 2844
2578 func_exit(); 2845 func_exit();
2579 return found?0:-EIO; 2846 return retval;
2580} 2847}
2581 2848
2582 2849static void __exit sx_exit(void)
2583static void __exit sx_exit (void)
2584{ 2850{
2585 int i; 2851 int i;
2586 struct sx_board *board;
2587 2852
2588 func_enter(); 2853 func_enter();
2589 for (i = 0; i < SX_NBOARDS; i++) { 2854#ifdef CONFIG_EISA
2590 board = &boards[i]; 2855 eisa_driver_unregister(&sx_eisadriver);
2591 if (board->flags & SX_BOARD_INITIALIZED) { 2856#endif
2592 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up board at %p\n", board->base); 2857 pci_unregister_driver(&sx_pcidriver);
2593 /* The board should stop messing with us. 2858
2594 (actually I mean the interrupt) */ 2859 for (i = 0; i < SX_NBOARDS; i++)
2595 sx_reset (board); 2860 sx_remove_card(&boards[i], NULL);
2596 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED)) 2861
2597 free_irq (board->irq, board);
2598
2599 /* It is safe/allowed to del_timer a non-active timer */
2600 del_timer (& board->timer);
2601 iounmap(board->base);
2602 }
2603 }
2604 if (misc_deregister(&sx_fw_device) < 0) { 2862 if (misc_deregister(&sx_fw_device) < 0) {
2605 printk (KERN_INFO "sx: couldn't deregister firmware loader device\n"); 2863 printk(KERN_INFO "sx: couldn't deregister firmware loader "
2864 "device\n");
2606 } 2865 }
2607 sx_dprintk (SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n", sx_initialized); 2866 sx_dprintk(SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n",
2867 sx_initialized);
2608 if (sx_initialized) 2868 if (sx_initialized)
2609 sx_release_drivers (); 2869 sx_release_drivers();
2610 2870
2611 kfree (sx_ports); 2871 kfree(sx_ports);
2612 func_exit(); 2872 func_exit();
2613} 2873}
2614 2874
2615module_init(sx_init); 2875module_init(sx_init);
2616module_exit(sx_exit); 2876module_exit(sx_exit);
2617
2618
diff --git a/drivers/char/sx.h b/drivers/char/sx.h
index e01f83cbe299..432aad0a2ddd 100644
--- a/drivers/char/sx.h
+++ b/drivers/char/sx.h
@@ -35,6 +35,7 @@ struct sx_board {
35 void __iomem *base; 35 void __iomem *base;
36 void __iomem *base2; 36 void __iomem *base2;
37 unsigned long hw_base; 37 unsigned long hw_base;
38 resource_size_t hw_len;
38 int eisa_base; 39 int eisa_base;
39 int port_base; /* Number of the first port */ 40 int port_base; /* Number of the first port */
40 struct sx_port *ports; 41 struct sx_port *ports;
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 645187b9141e..acc6fab601cc 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -3060,7 +3060,7 @@ static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigne
3060 * 3060 *
3061 * Return Value: None 3061 * Return Value: None
3062 */ 3062 */
3063static void mgsl_set_termios(struct tty_struct *tty, struct termios *old_termios) 3063static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3064{ 3064{
3065 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data; 3065 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
3066 unsigned long flags; 3066 unsigned long flags;
@@ -4405,6 +4405,8 @@ static int mgsl_init_tty(void)
4405 serial_driver->init_termios = tty_std_termios; 4405 serial_driver->init_termios = tty_std_termios;
4406 serial_driver->init_termios.c_cflag = 4406 serial_driver->init_termios.c_cflag =
4407 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 4407 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4408 serial_driver->init_termios.c_ispeed = 9600;
4409 serial_driver->init_termios.c_ospeed = 9600;
4408 serial_driver->flags = TTY_DRIVER_REAL_RAW; 4410 serial_driver->flags = TTY_DRIVER_REAL_RAW;
4409 tty_set_operations(serial_driver, &mgsl_ops); 4411 tty_set_operations(serial_driver, &mgsl_ops);
4410 if ((rc = tty_register_driver(serial_driver)) < 0) { 4412 if ((rc = tty_register_driver(serial_driver)) < 0) {
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index e4730a7312b5..792c79c315e0 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -151,7 +151,7 @@ static struct tty_driver *serial_driver;
151static int open(struct tty_struct *tty, struct file * filp); 151static int open(struct tty_struct *tty, struct file * filp);
152static void close(struct tty_struct *tty, struct file * filp); 152static void close(struct tty_struct *tty, struct file * filp);
153static void hangup(struct tty_struct *tty); 153static void hangup(struct tty_struct *tty);
154static void set_termios(struct tty_struct *tty, struct termios *old_termios); 154static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
155 155
156static int write(struct tty_struct *tty, const unsigned char *buf, int count); 156static int write(struct tty_struct *tty, const unsigned char *buf, int count);
157static void put_char(struct tty_struct *tty, unsigned char ch); 157static void put_char(struct tty_struct *tty, unsigned char ch);
@@ -816,7 +816,7 @@ static void hangup(struct tty_struct *tty)
816 wake_up_interruptible(&info->open_wait); 816 wake_up_interruptible(&info->open_wait);
817} 817}
818 818
819static void set_termios(struct tty_struct *tty, struct termios *old_termios) 819static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
820{ 820{
821 struct slgt_info *info = tty->driver_data; 821 struct slgt_info *info = tty->driver_data;
822 unsigned long flags; 822 unsigned long flags;
@@ -3546,6 +3546,8 @@ static int __init slgt_init(void)
3546 serial_driver->init_termios = tty_std_termios; 3546 serial_driver->init_termios = tty_std_termios;
3547 serial_driver->init_termios.c_cflag = 3547 serial_driver->init_termios.c_cflag =
3548 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 3548 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
3549 serial_driver->init_termios.c_ispeed = 9600;
3550 serial_driver->init_termios.c_ospeed = 9600;
3549 serial_driver->flags = TTY_DRIVER_REAL_RAW; 3551 serial_driver->flags = TTY_DRIVER_REAL_RAW;
3550 tty_set_operations(serial_driver, &ops); 3552 tty_set_operations(serial_driver, &ops);
3551 if ((rc = tty_register_driver(serial_driver)) < 0) { 3553 if ((rc = tty_register_driver(serial_driver)) < 0) {
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 20a96ef250be..53e8ccf94fe3 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -519,7 +519,7 @@ static struct tty_driver *serial_driver;
519static int open(struct tty_struct *tty, struct file * filp); 519static int open(struct tty_struct *tty, struct file * filp);
520static void close(struct tty_struct *tty, struct file * filp); 520static void close(struct tty_struct *tty, struct file * filp);
521static void hangup(struct tty_struct *tty); 521static void hangup(struct tty_struct *tty);
522static void set_termios(struct tty_struct *tty, struct termios *old_termios); 522static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
523 523
524static int write(struct tty_struct *tty, const unsigned char *buf, int count); 524static int write(struct tty_struct *tty, const unsigned char *buf, int count);
525static void put_char(struct tty_struct *tty, unsigned char ch); 525static void put_char(struct tty_struct *tty, unsigned char ch);
@@ -918,7 +918,7 @@ static void hangup(struct tty_struct *tty)
918 918
919/* Set new termios settings 919/* Set new termios settings
920 */ 920 */
921static void set_termios(struct tty_struct *tty, struct termios *old_termios) 921static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
922{ 922{
923 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data; 923 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
924 unsigned long flags; 924 unsigned long flags;
@@ -4034,6 +4034,8 @@ static int __init synclinkmp_init(void)
4034 serial_driver->init_termios = tty_std_termios; 4034 serial_driver->init_termios = tty_std_termios;
4035 serial_driver->init_termios.c_cflag = 4035 serial_driver->init_termios.c_cflag =
4036 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 4036 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4037 serial_driver->init_termios.c_ispeed = 9600;
4038 serial_driver->init_termios.c_ospeed = 9600;
4037 serial_driver->flags = TTY_DRIVER_REAL_RAW; 4039 serial_driver->flags = TTY_DRIVER_REAL_RAW;
4038 tty_set_operations(serial_driver, &ops); 4040 tty_set_operations(serial_driver, &ops);
4039 if ((rc = tty_register_driver(serial_driver)) < 0) { 4041 if ((rc = tty_register_driver(serial_driver)) < 0) {
diff --git a/drivers/char/tb0219.c b/drivers/char/tb0219.c
index bb1bad4c18f9..4c431cb7cf1b 100644
--- a/drivers/char/tb0219.c
+++ b/drivers/char/tb0219.c
@@ -164,7 +164,7 @@ static ssize_t tanbac_tb0219_read(struct file *file, char __user *buf, size_t le
164 unsigned int minor; 164 unsigned int minor;
165 char value; 165 char value;
166 166
167 minor = iminor(file->f_dentry->d_inode); 167 minor = iminor(file->f_path.dentry->d_inode);
168 switch (minor) { 168 switch (minor) {
169 case 0: 169 case 0:
170 value = get_led(); 170 value = get_led();
@@ -200,7 +200,7 @@ static ssize_t tanbac_tb0219_write(struct file *file, const char __user *data,
200 int retval = 0; 200 int retval = 0;
201 char c; 201 char c;
202 202
203 minor = iminor(file->f_dentry->d_inode); 203 minor = iminor(file->f_path.dentry->d_inode);
204 switch (minor) { 204 switch (minor) {
205 case 0: 205 case 0:
206 type = TYPE_LED; 206 type = TYPE_LED;
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index 9df0ca1be0e3..47fb20f69695 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -285,7 +285,7 @@ static ssize_t
285tipar_write (struct file *file, const char __user *buf, size_t count, 285tipar_write (struct file *file, const char __user *buf, size_t count,
286 loff_t * ppos) 286 loff_t * ppos)
287{ 287{
288 unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR; 288 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
289 ssize_t n; 289 ssize_t n;
290 290
291 parport_claim_or_block(table[minor].dev); 291 parport_claim_or_block(table[minor].dev);
@@ -313,7 +313,7 @@ static ssize_t
313tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos) 313tipar_read(struct file *file, char __user *buf, size_t count, loff_t * ppos)
314{ 314{
315 int b = 0; 315 int b = 0;
316 unsigned int minor = iminor(file->f_dentry->d_inode) - TIPAR_MINOR; 316 unsigned int minor = iminor(file->f_path.dentry->d_inode) - TIPAR_MINOR;
317 ssize_t retval = 0; 317 ssize_t retval = 0;
318 ssize_t n = 0; 318 ssize_t n = 0;
319 319
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index b3cfc8bc613c..4044c864fdd4 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -109,13 +109,15 @@
109#define TTY_PARANOIA_CHECK 1 109#define TTY_PARANOIA_CHECK 1
110#define CHECK_TTY_COUNT 1 110#define CHECK_TTY_COUNT 1
111 111
112struct termios tty_std_termios = { /* for the benefit of tty drivers */ 112struct ktermios tty_std_termios = { /* for the benefit of tty drivers */
113 .c_iflag = ICRNL | IXON, 113 .c_iflag = ICRNL | IXON,
114 .c_oflag = OPOST | ONLCR, 114 .c_oflag = OPOST | ONLCR,
115 .c_cflag = B38400 | CS8 | CREAD | HUPCL, 115 .c_cflag = B38400 | CS8 | CREAD | HUPCL,
116 .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK | 116 .c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK |
117 ECHOCTL | ECHOKE | IEXTEN, 117 ECHOCTL | ECHOKE | IEXTEN,
118 .c_cc = INIT_C_CC 118 .c_cc = INIT_C_CC,
119 .c_ispeed = 38400,
120 .c_ospeed = 38400
119}; 121};
120 122
121EXPORT_SYMBOL(tty_std_termios); 123EXPORT_SYMBOL(tty_std_termios);
@@ -126,7 +128,7 @@ EXPORT_SYMBOL(tty_std_termios);
126 128
127LIST_HEAD(tty_drivers); /* linked list of tty drivers */ 129LIST_HEAD(tty_drivers); /* linked list of tty drivers */
128 130
129/* Semaphore to protect creating and releasing a tty. This is shared with 131/* Mutex to protect creating and releasing a tty. This is shared with
130 vt.c for deeply disgusting hack reasons */ 132 vt.c for deeply disgusting hack reasons */
131DEFINE_MUTEX(tty_mutex); 133DEFINE_MUTEX(tty_mutex);
132EXPORT_SYMBOL(tty_mutex); 134EXPORT_SYMBOL(tty_mutex);
@@ -250,7 +252,7 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
250 "!= #fd's(%d) in %s\n", 252 "!= #fd's(%d) in %s\n",
251 tty->name, tty->count, count, routine); 253 tty->name, tty->count, count, routine);
252 return count; 254 return count;
253 } 255 }
254#endif 256#endif
255 return 0; 257 return 0;
256} 258}
@@ -259,18 +261,6 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
259 * Tty buffer allocation management 261 * Tty buffer allocation management
260 */ 262 */
261 263
262
263/**
264 * tty_buffer_free_all - free buffers used by a tty
265 * @tty: tty to free from
266 *
267 * Remove all the buffers pending on a tty whether queued with data
268 * or in the free ring. Must be called when the tty is no longer in use
269 *
270 * Locking: none
271 */
272
273
274/** 264/**
275 * tty_buffer_free_all - free buffers used by a tty 265 * tty_buffer_free_all - free buffers used by a tty
276 * @tty: tty to free from 266 * @tty: tty to free from
@@ -614,7 +604,7 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
614 * they are not on hot paths so a little discipline won't do 604 * they are not on hot paths so a little discipline won't do
615 * any harm. 605 * any harm.
616 * 606 *
617 * Locking: takes termios_sem 607 * Locking: takes termios_mutex
618 */ 608 */
619 609
620static void tty_set_termios_ldisc(struct tty_struct *tty, int num) 610static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
@@ -915,7 +905,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
915 * context. 905 * context.
916 * 906 *
917 * Locking: takes tty_ldisc_lock. 907 * Locking: takes tty_ldisc_lock.
918 * called functions take termios_sem 908 * called functions take termios_mutex
919 */ 909 */
920 910
921static int tty_set_ldisc(struct tty_struct *tty, int ldisc) 911static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
@@ -1251,6 +1241,22 @@ void tty_ldisc_flush(struct tty_struct *tty)
1251} 1241}
1252 1242
1253EXPORT_SYMBOL_GPL(tty_ldisc_flush); 1243EXPORT_SYMBOL_GPL(tty_ldisc_flush);
1244
1245/**
1246 * tty_reset_termios - reset terminal state
1247 * @tty: tty to reset
1248 *
1249 * Restore a terminal to the driver default state
1250 */
1251
1252static void tty_reset_termios(struct tty_struct *tty)
1253{
1254 mutex_lock(&tty->termios_mutex);
1255 *tty->termios = tty->driver->init_termios;
1256 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
1257 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1258 mutex_unlock(&tty->termios_mutex);
1259}
1254 1260
1255/** 1261/**
1256 * do_tty_hangup - actual handler for hangup events 1262 * do_tty_hangup - actual handler for hangup events
@@ -1267,12 +1273,12 @@ EXPORT_SYMBOL_GPL(tty_ldisc_flush);
1267 * 1273 *
1268 * Locking: 1274 * Locking:
1269 * BKL 1275 * BKL
1270 * redirect lock for undoing redirection 1276 * redirect lock for undoing redirection
1271 * file list lock for manipulating list of ttys 1277 * file list lock for manipulating list of ttys
1272 * tty_ldisc_lock from called functions 1278 * tty_ldisc_lock from called functions
1273 * termios_sem resetting termios data 1279 * termios_mutex resetting termios data
1274 * tasklist_lock to walk task list for hangup event 1280 * tasklist_lock to walk task list for hangup event
1275 * 1281 * ->siglock to protect ->signal/->sighand
1276 */ 1282 */
1277static void do_tty_hangup(struct work_struct *work) 1283static void do_tty_hangup(struct work_struct *work)
1278{ 1284{
@@ -1339,11 +1345,7 @@ static void do_tty_hangup(struct work_struct *work)
1339 * N_TTY. 1345 * N_TTY.
1340 */ 1346 */
1341 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) 1347 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
1342 { 1348 tty_reset_termios(tty);
1343 mutex_lock(&tty->termios_mutex);
1344 *tty->termios = tty->driver->init_termios;
1345 mutex_unlock(&tty->termios_mutex);
1346 }
1347 1349
1348 /* Defer ldisc switch */ 1350 /* Defer ldisc switch */
1349 /* tty_deferred_ldisc_switch(N_TTY); 1351 /* tty_deferred_ldisc_switch(N_TTY);
@@ -1354,14 +1356,18 @@ static void do_tty_hangup(struct work_struct *work)
1354 read_lock(&tasklist_lock); 1356 read_lock(&tasklist_lock);
1355 if (tty->session > 0) { 1357 if (tty->session > 0) {
1356 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 1358 do_each_task_pid(tty->session, PIDTYPE_SID, p) {
1359 spin_lock_irq(&p->sighand->siglock);
1357 if (p->signal->tty == tty) 1360 if (p->signal->tty == tty)
1358 p->signal->tty = NULL; 1361 p->signal->tty = NULL;
1359 if (!p->signal->leader) 1362 if (!p->signal->leader) {
1363 spin_unlock_irq(&p->sighand->siglock);
1360 continue; 1364 continue;
1361 group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p); 1365 }
1362 group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p); 1366 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
1367 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
1363 if (tty->pgrp > 0) 1368 if (tty->pgrp > 0)
1364 p->signal->tty_old_pgrp = tty->pgrp; 1369 p->signal->tty_old_pgrp = tty->pgrp;
1370 spin_unlock_irq(&p->sighand->siglock);
1365 } while_each_task_pid(tty->session, PIDTYPE_SID, p); 1371 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
1366 } 1372 }
1367 read_unlock(&tasklist_lock); 1373 read_unlock(&tasklist_lock);
@@ -1453,6 +1459,14 @@ int tty_hung_up_p(struct file * filp)
1453 1459
1454EXPORT_SYMBOL(tty_hung_up_p); 1460EXPORT_SYMBOL(tty_hung_up_p);
1455 1461
1462static void session_clear_tty(pid_t session)
1463{
1464 struct task_struct *p;
1465 do_each_task_pid(session, PIDTYPE_SID, p) {
1466 proc_clear_tty(p);
1467 } while_each_task_pid(session, PIDTYPE_SID, p);
1468}
1469
1456/** 1470/**
1457 * disassociate_ctty - disconnect controlling tty 1471 * disassociate_ctty - disconnect controlling tty
1458 * @on_exit: true if exiting so need to "hang up" the session 1472 * @on_exit: true if exiting so need to "hang up" the session
@@ -1469,31 +1483,35 @@ EXPORT_SYMBOL(tty_hung_up_p);
1469 * The argument on_exit is set to 1 if called when a process is 1483 * The argument on_exit is set to 1 if called when a process is
1470 * exiting; it is 0 if called by the ioctl TIOCNOTTY. 1484 * exiting; it is 0 if called by the ioctl TIOCNOTTY.
1471 * 1485 *
1472 * Locking: tty_mutex is taken to protect current->signal->tty 1486 * Locking:
1473 * BKL is taken for hysterical raisins 1487 * BKL is taken for hysterical raisins
1474 * Tasklist lock is taken (under tty_mutex) to walk process 1488 * tty_mutex is taken to protect tty
1475 * lists for the session. 1489 * ->siglock is taken to protect ->signal/->sighand
1490 * tasklist_lock is taken to walk process list for sessions
1491 * ->siglock is taken to protect ->signal/->sighand
1476 */ 1492 */
1477 1493
1478void disassociate_ctty(int on_exit) 1494void disassociate_ctty(int on_exit)
1479{ 1495{
1480 struct tty_struct *tty; 1496 struct tty_struct *tty;
1481 struct task_struct *p;
1482 int tty_pgrp = -1; 1497 int tty_pgrp = -1;
1498 int session;
1483 1499
1484 lock_kernel(); 1500 lock_kernel();
1485 1501
1486 mutex_lock(&tty_mutex); 1502 mutex_lock(&tty_mutex);
1487 tty = current->signal->tty; 1503 tty = get_current_tty();
1488 if (tty) { 1504 if (tty) {
1489 tty_pgrp = tty->pgrp; 1505 tty_pgrp = tty->pgrp;
1490 mutex_unlock(&tty_mutex); 1506 mutex_unlock(&tty_mutex);
1507 /* XXX: here we race, there is nothing protecting tty */
1491 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 1508 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1492 tty_vhangup(tty); 1509 tty_vhangup(tty);
1493 } else { 1510 } else {
1494 if (current->signal->tty_old_pgrp) { 1511 pid_t old_pgrp = current->signal->tty_old_pgrp;
1495 kill_pg(current->signal->tty_old_pgrp, SIGHUP, on_exit); 1512 if (old_pgrp) {
1496 kill_pg(current->signal->tty_old_pgrp, SIGCONT, on_exit); 1513 kill_pg(old_pgrp, SIGHUP, on_exit);
1514 kill_pg(old_pgrp, SIGCONT, on_exit);
1497 } 1515 }
1498 mutex_unlock(&tty_mutex); 1516 mutex_unlock(&tty_mutex);
1499 unlock_kernel(); 1517 unlock_kernel();
@@ -1505,19 +1523,29 @@ void disassociate_ctty(int on_exit)
1505 kill_pg(tty_pgrp, SIGCONT, on_exit); 1523 kill_pg(tty_pgrp, SIGCONT, on_exit);
1506 } 1524 }
1507 1525
1508 /* Must lock changes to tty_old_pgrp */ 1526 spin_lock_irq(&current->sighand->siglock);
1509 mutex_lock(&tty_mutex);
1510 current->signal->tty_old_pgrp = 0; 1527 current->signal->tty_old_pgrp = 0;
1511 tty->session = 0; 1528 session = process_session(current);
1512 tty->pgrp = -1; 1529 spin_unlock_irq(&current->sighand->siglock);
1530
1531 mutex_lock(&tty_mutex);
1532 /* It is possible that do_tty_hangup has free'd this tty */
1533 tty = get_current_tty();
1534 if (tty) {
1535 tty->session = 0;
1536 tty->pgrp = 0;
1537 } else {
1538#ifdef TTY_DEBUG_HANGUP
1539 printk(KERN_DEBUG "error attempted to write to tty [0x%p]"
1540 " = NULL", tty);
1541#endif
1542 }
1543 mutex_unlock(&tty_mutex);
1513 1544
1514 /* Now clear signal->tty under the lock */ 1545 /* Now clear signal->tty under the lock */
1515 read_lock(&tasklist_lock); 1546 read_lock(&tasklist_lock);
1516 do_each_task_pid(current->signal->session, PIDTYPE_SID, p) { 1547 session_clear_tty(session);
1517 p->signal->tty = NULL;
1518 } while_each_task_pid(current->signal->session, PIDTYPE_SID, p);
1519 read_unlock(&tasklist_lock); 1548 read_unlock(&tasklist_lock);
1520 mutex_unlock(&tty_mutex);
1521 unlock_kernel(); 1549 unlock_kernel();
1522} 1550}
1523 1551
@@ -1615,7 +1643,7 @@ static ssize_t tty_read(struct file * file, char __user * buf, size_t count,
1615 struct tty_ldisc *ld; 1643 struct tty_ldisc *ld;
1616 1644
1617 tty = (struct tty_struct *)file->private_data; 1645 tty = (struct tty_struct *)file->private_data;
1618 inode = file->f_dentry->d_inode; 1646 inode = file->f_path.dentry->d_inode;
1619 if (tty_paranoia_check(tty, inode, "tty_read")) 1647 if (tty_paranoia_check(tty, inode, "tty_read"))
1620 return -EIO; 1648 return -EIO;
1621 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) 1649 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
@@ -1718,7 +1746,7 @@ static inline ssize_t do_tty_write(
1718 cond_resched(); 1746 cond_resched();
1719 } 1747 }
1720 if (written) { 1748 if (written) {
1721 struct inode *inode = file->f_dentry->d_inode; 1749 struct inode *inode = file->f_path.dentry->d_inode;
1722 inode->i_mtime = current_fs_time(inode->i_sb); 1750 inode->i_mtime = current_fs_time(inode->i_sb);
1723 ret = written; 1751 ret = written;
1724 } 1752 }
@@ -1749,7 +1777,7 @@ static ssize_t tty_write(struct file * file, const char __user * buf, size_t cou
1749 loff_t *ppos) 1777 loff_t *ppos)
1750{ 1778{
1751 struct tty_struct * tty; 1779 struct tty_struct * tty;
1752 struct inode *inode = file->f_dentry->d_inode; 1780 struct inode *inode = file->f_path.dentry->d_inode;
1753 ssize_t ret; 1781 ssize_t ret;
1754 struct tty_ldisc *ld; 1782 struct tty_ldisc *ld;
1755 1783
@@ -1856,8 +1884,8 @@ static int init_dev(struct tty_driver *driver, int idx,
1856 struct tty_struct **ret_tty) 1884 struct tty_struct **ret_tty)
1857{ 1885{
1858 struct tty_struct *tty, *o_tty; 1886 struct tty_struct *tty, *o_tty;
1859 struct termios *tp, **tp_loc, *o_tp, **o_tp_loc; 1887 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
1860 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; 1888 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1861 int retval = 0; 1889 int retval = 0;
1862 1890
1863 /* check whether we're reopening an existing tty */ 1891 /* check whether we're reopening an existing tty */
@@ -1904,7 +1932,7 @@ static int init_dev(struct tty_driver *driver, int idx,
1904 } 1932 }
1905 1933
1906 if (!*tp_loc) { 1934 if (!*tp_loc) {
1907 tp = (struct termios *) kmalloc(sizeof(struct termios), 1935 tp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
1908 GFP_KERNEL); 1936 GFP_KERNEL);
1909 if (!tp) 1937 if (!tp)
1910 goto free_mem_out; 1938 goto free_mem_out;
@@ -1912,11 +1940,11 @@ static int init_dev(struct tty_driver *driver, int idx,
1912 } 1940 }
1913 1941
1914 if (!*ltp_loc) { 1942 if (!*ltp_loc) {
1915 ltp = (struct termios *) kmalloc(sizeof(struct termios), 1943 ltp = (struct ktermios *) kmalloc(sizeof(struct ktermios),
1916 GFP_KERNEL); 1944 GFP_KERNEL);
1917 if (!ltp) 1945 if (!ltp)
1918 goto free_mem_out; 1946 goto free_mem_out;
1919 memset(ltp, 0, sizeof(struct termios)); 1947 memset(ltp, 0, sizeof(struct ktermios));
1920 } 1948 }
1921 1949
1922 if (driver->type == TTY_DRIVER_TYPE_PTY) { 1950 if (driver->type == TTY_DRIVER_TYPE_PTY) {
@@ -1937,19 +1965,19 @@ static int init_dev(struct tty_driver *driver, int idx,
1937 } 1965 }
1938 1966
1939 if (!*o_tp_loc) { 1967 if (!*o_tp_loc) {
1940 o_tp = (struct termios *) 1968 o_tp = (struct ktermios *)
1941 kmalloc(sizeof(struct termios), GFP_KERNEL); 1969 kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1942 if (!o_tp) 1970 if (!o_tp)
1943 goto free_mem_out; 1971 goto free_mem_out;
1944 *o_tp = driver->other->init_termios; 1972 *o_tp = driver->other->init_termios;
1945 } 1973 }
1946 1974
1947 if (!*o_ltp_loc) { 1975 if (!*o_ltp_loc) {
1948 o_ltp = (struct termios *) 1976 o_ltp = (struct ktermios *)
1949 kmalloc(sizeof(struct termios), GFP_KERNEL); 1977 kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1950 if (!o_ltp) 1978 if (!o_ltp)
1951 goto free_mem_out; 1979 goto free_mem_out;
1952 memset(o_ltp, 0, sizeof(struct termios)); 1980 memset(o_ltp, 0, sizeof(struct ktermios));
1953 } 1981 }
1954 1982
1955 /* 1983 /*
@@ -1988,6 +2016,9 @@ static int init_dev(struct tty_driver *driver, int idx,
1988 *ltp_loc = ltp; 2016 *ltp_loc = ltp;
1989 tty->termios = *tp_loc; 2017 tty->termios = *tp_loc;
1990 tty->termios_locked = *ltp_loc; 2018 tty->termios_locked = *ltp_loc;
2019 /* Compatibility until drivers always set this */
2020 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
2021 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1991 driver->refcount++; 2022 driver->refcount++;
1992 tty->count++; 2023 tty->count++;
1993 2024
@@ -2090,7 +2121,7 @@ release_mem_out:
2090static void release_mem(struct tty_struct *tty, int idx) 2121static void release_mem(struct tty_struct *tty, int idx)
2091{ 2122{
2092 struct tty_struct *o_tty; 2123 struct tty_struct *o_tty;
2093 struct termios *tp; 2124 struct ktermios *tp;
2094 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; 2125 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM;
2095 2126
2096 if ((o_tty = tty->link) != NULL) { 2127 if ((o_tty = tty->link) != NULL) {
@@ -2156,7 +2187,7 @@ static void release_dev(struct file * filp)
2156 unsigned long flags; 2187 unsigned long flags;
2157 2188
2158 tty = (struct tty_struct *)filp->private_data; 2189 tty = (struct tty_struct *)filp->private_data;
2159 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "release_dev")) 2190 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "release_dev"))
2160 return; 2191 return;
2161 2192
2162 check_tty_count(tty, "release_dev"); 2193 check_tty_count(tty, "release_dev");
@@ -2337,16 +2368,10 @@ static void release_dev(struct file * filp)
2337 * tty. 2368 * tty.
2338 */ 2369 */
2339 if (tty_closing || o_tty_closing) { 2370 if (tty_closing || o_tty_closing) {
2340 struct task_struct *p;
2341
2342 read_lock(&tasklist_lock); 2371 read_lock(&tasklist_lock);
2343 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 2372 session_clear_tty(tty->session);
2344 p->signal->tty = NULL;
2345 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
2346 if (o_tty) 2373 if (o_tty)
2347 do_each_task_pid(o_tty->session, PIDTYPE_SID, p) { 2374 session_clear_tty(o_tty->session);
2348 p->signal->tty = NULL;
2349 } while_each_task_pid(o_tty->session, PIDTYPE_SID, p);
2350 read_unlock(&tasklist_lock); 2375 read_unlock(&tasklist_lock);
2351 } 2376 }
2352 2377
@@ -2443,9 +2468,9 @@ static void release_dev(struct file * filp)
2443 * The termios state of a pty is reset on first open so that 2468 * The termios state of a pty is reset on first open so that
2444 * settings don't persist across reuse. 2469 * settings don't persist across reuse.
2445 * 2470 *
2446 * Locking: tty_mutex protects current->signal->tty, get_tty_driver and 2471 * Locking: tty_mutex protects tty, get_tty_driver and init_dev work.
2447 * init_dev work. tty->count should protect the rest. 2472 * tty->count should protect the rest.
2448 * task_lock is held to update task details for sessions 2473 * ->siglock protects ->signal/->sighand
2449 */ 2474 */
2450 2475
2451static int tty_open(struct inode * inode, struct file * filp) 2476static int tty_open(struct inode * inode, struct file * filp)
@@ -2467,12 +2492,13 @@ retry_open:
2467 mutex_lock(&tty_mutex); 2492 mutex_lock(&tty_mutex);
2468 2493
2469 if (device == MKDEV(TTYAUX_MAJOR,0)) { 2494 if (device == MKDEV(TTYAUX_MAJOR,0)) {
2470 if (!current->signal->tty) { 2495 tty = get_current_tty();
2496 if (!tty) {
2471 mutex_unlock(&tty_mutex); 2497 mutex_unlock(&tty_mutex);
2472 return -ENXIO; 2498 return -ENXIO;
2473 } 2499 }
2474 driver = current->signal->tty->driver; 2500 driver = tty->driver;
2475 index = current->signal->tty->index; 2501 index = tty->index;
2476 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ 2502 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
2477 /* noctty = 1; */ 2503 /* noctty = 1; */
2478 goto got_driver; 2504 goto got_driver;
@@ -2547,17 +2573,16 @@ got_driver:
2547 filp->f_op = &tty_fops; 2573 filp->f_op = &tty_fops;
2548 goto retry_open; 2574 goto retry_open;
2549 } 2575 }
2576
2577 mutex_lock(&tty_mutex);
2578 spin_lock_irq(&current->sighand->siglock);
2550 if (!noctty && 2579 if (!noctty &&
2551 current->signal->leader && 2580 current->signal->leader &&
2552 !current->signal->tty && 2581 !current->signal->tty &&
2553 tty->session == 0) { 2582 tty->session == 0)
2554 task_lock(current); 2583 __proc_set_tty(current, tty);
2555 current->signal->tty = tty; 2584 spin_unlock_irq(&current->sighand->siglock);
2556 task_unlock(current); 2585 mutex_unlock(&tty_mutex);
2557 current->signal->tty_old_pgrp = 0;
2558 tty->session = current->signal->session;
2559 tty->pgrp = process_group(current);
2560 }
2561 return 0; 2586 return 0;
2562} 2587}
2563 2588
@@ -2672,7 +2697,7 @@ static unsigned int tty_poll(struct file * filp, poll_table * wait)
2672 int ret = 0; 2697 int ret = 0;
2673 2698
2674 tty = (struct tty_struct *)filp->private_data; 2699 tty = (struct tty_struct *)filp->private_data;
2675 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_poll")) 2700 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
2676 return 0; 2701 return 0;
2677 2702
2678 ld = tty_ldisc_ref_wait(tty); 2703 ld = tty_ldisc_ref_wait(tty);
@@ -2688,7 +2713,7 @@ static int tty_fasync(int fd, struct file * filp, int on)
2688 int retval; 2713 int retval;
2689 2714
2690 tty = (struct tty_struct *)filp->private_data; 2715 tty = (struct tty_struct *)filp->private_data;
2691 if (tty_paranoia_check(tty, filp->f_dentry->d_inode, "tty_fasync")) 2716 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
2692 return 0; 2717 return 0;
2693 2718
2694 retval = fasync_helper(fd, filp, on, &tty->fasync); 2719 retval = fasync_helper(fd, filp, on, &tty->fasync);
@@ -2747,7 +2772,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
2747 * 2772 *
2748 * Copies the kernel idea of the window size into the user buffer. 2773 * Copies the kernel idea of the window size into the user buffer.
2749 * 2774 *
2750 * Locking: tty->termios_sem is taken to ensure the winsize data 2775 * Locking: tty->termios_mutex is taken to ensure the winsize data
2751 * is consistent. 2776 * is consistent.
2752 */ 2777 */
2753 2778
@@ -2774,8 +2799,8 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
2774 * Locking: 2799 * Locking:
2775 * Called function use the console_sem is used to ensure we do 2800 * Called function use the console_sem is used to ensure we do
2776 * not try and resize the console twice at once. 2801 * not try and resize the console twice at once.
2777 * The tty->termios_sem is used to ensure we don't double 2802 * The tty->termios_mutex is used to ensure we don't double
2778 * resize and get confused. Lock order - tty->termios.sem before 2803 * resize and get confused. Lock order - tty->termios_mutex before
2779 * console sem 2804 * console sem
2780 */ 2805 */
2781 2806
@@ -2880,25 +2905,28 @@ static int fionbio(struct file *file, int __user *p)
2880 * leader to set this tty as the controlling tty for the session. 2905 * leader to set this tty as the controlling tty for the session.
2881 * 2906 *
2882 * Locking: 2907 * Locking:
2883 * Takes tasklist lock internally to walk sessions
2884 * Takes task_lock() when updating signal->tty
2885 * Takes tty_mutex() to protect tty instance 2908 * Takes tty_mutex() to protect tty instance
2886 * 2909 * Takes tasklist_lock internally to walk sessions
2910 * Takes ->siglock() when updating signal->tty
2887 */ 2911 */
2888 2912
2889static int tiocsctty(struct tty_struct *tty, int arg) 2913static int tiocsctty(struct tty_struct *tty, int arg)
2890{ 2914{
2891 struct task_struct *p; 2915 int ret = 0;
2892
2893 if (current->signal->leader && 2916 if (current->signal->leader &&
2894 (current->signal->session == tty->session)) 2917 (process_session(current) == tty->session))
2895 return 0; 2918 return ret;
2919
2920 mutex_lock(&tty_mutex);
2896 /* 2921 /*
2897 * The process must be a session leader and 2922 * The process must be a session leader and
2898 * not have a controlling tty already. 2923 * not have a controlling tty already.
2899 */ 2924 */
2900 if (!current->signal->leader || current->signal->tty) 2925 if (!current->signal->leader || current->signal->tty) {
2901 return -EPERM; 2926 ret = -EPERM;
2927 goto unlock;
2928 }
2929
2902 if (tty->session > 0) { 2930 if (tty->session > 0) {
2903 /* 2931 /*
2904 * This tty is already the controlling 2932 * This tty is already the controlling
@@ -2908,24 +2936,18 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2908 /* 2936 /*
2909 * Steal it away 2937 * Steal it away
2910 */ 2938 */
2911
2912 read_lock(&tasklist_lock); 2939 read_lock(&tasklist_lock);
2913 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 2940 session_clear_tty(tty->session);
2914 p->signal->tty = NULL;
2915 } while_each_task_pid(tty->session, PIDTYPE_SID, p);
2916 read_unlock(&tasklist_lock); 2941 read_unlock(&tasklist_lock);
2917 } else 2942 } else {
2918 return -EPERM; 2943 ret = -EPERM;
2944 goto unlock;
2945 }
2919 } 2946 }
2920 mutex_lock(&tty_mutex); 2947 proc_set_tty(current, tty);
2921 task_lock(current); 2948unlock:
2922 current->signal->tty = tty;
2923 task_unlock(current);
2924 mutex_unlock(&tty_mutex); 2949 mutex_unlock(&tty_mutex);
2925 current->signal->tty_old_pgrp = 0; 2950 return ret;
2926 tty->session = current->signal->session;
2927 tty->pgrp = process_group(current);
2928 return 0;
2929} 2951}
2930 2952
2931/** 2953/**
@@ -2937,7 +2959,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2937 * Obtain the process group of the tty. If there is no process group 2959 * Obtain the process group of the tty. If there is no process group
2938 * return an error. 2960 * return an error.
2939 * 2961 *
2940 * Locking: none. Reference to ->signal->tty is safe. 2962 * Locking: none. Reference to current->signal->tty is safe.
2941 */ 2963 */
2942 2964
2943static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 2965static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -2974,13 +2996,13 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2974 return retval; 2996 return retval;
2975 if (!current->signal->tty || 2997 if (!current->signal->tty ||
2976 (current->signal->tty != real_tty) || 2998 (current->signal->tty != real_tty) ||
2977 (real_tty->session != current->signal->session)) 2999 (real_tty->session != process_session(current)))
2978 return -ENOTTY; 3000 return -ENOTTY;
2979 if (get_user(pgrp, p)) 3001 if (get_user(pgrp, p))
2980 return -EFAULT; 3002 return -EFAULT;
2981 if (pgrp < 0) 3003 if (pgrp < 0)
2982 return -EINVAL; 3004 return -EINVAL;
2983 if (session_of_pgrp(pgrp) != current->signal->session) 3005 if (session_of_pgrp(pgrp) != process_session(current))
2984 return -EPERM; 3006 return -EPERM;
2985 real_tty->pgrp = pgrp; 3007 real_tty->pgrp = pgrp;
2986 return 0; 3008 return 0;
@@ -2995,7 +3017,7 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2995 * Obtain the session id of the tty. If there is no session 3017 * Obtain the session id of the tty. If there is no session
2996 * return an error. 3018 * return an error.
2997 * 3019 *
2998 * Locking: none. Reference to ->signal->tty is safe. 3020 * Locking: none. Reference to current->signal->tty is safe.
2999 */ 3021 */
3000 3022
3001static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3023static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
@@ -3214,14 +3236,11 @@ int tty_ioctl(struct inode * inode, struct file * file,
3214 clear_bit(TTY_EXCLUSIVE, &tty->flags); 3236 clear_bit(TTY_EXCLUSIVE, &tty->flags);
3215 return 0; 3237 return 0;
3216 case TIOCNOTTY: 3238 case TIOCNOTTY:
3217 /* FIXME: taks lock or tty_mutex ? */
3218 if (current->signal->tty != tty) 3239 if (current->signal->tty != tty)
3219 return -ENOTTY; 3240 return -ENOTTY;
3220 if (current->signal->leader) 3241 if (current->signal->leader)
3221 disassociate_ctty(0); 3242 disassociate_ctty(0);
3222 task_lock(current); 3243 proc_clear_tty(current);
3223 current->signal->tty = NULL;
3224 task_unlock(current);
3225 return 0; 3244 return 0;
3226 case TIOCSCTTY: 3245 case TIOCSCTTY:
3227 return tiocsctty(tty, arg); 3246 return tiocsctty(tty, arg);
@@ -3321,7 +3340,7 @@ static void __do_SAK(struct work_struct *work)
3321 3340
3322 if (!tty) 3341 if (!tty)
3323 return; 3342 return;
3324 session = tty->session; 3343 session = tty->session;
3325 3344
3326 /* We don't want an ldisc switch during this */ 3345 /* We don't want an ldisc switch during this */
3327 disc = tty_ldisc_ref(tty); 3346 disc = tty_ldisc_ref(tty);
@@ -3336,7 +3355,7 @@ static void __do_SAK(struct work_struct *work)
3336 /* Kill the entire session */ 3355 /* Kill the entire session */
3337 do_each_task_pid(session, PIDTYPE_SID, p) { 3356 do_each_task_pid(session, PIDTYPE_SID, p) {
3338 printk(KERN_NOTICE "SAK: killed process %d" 3357 printk(KERN_NOTICE "SAK: killed process %d"
3339 " (%s): p->signal->session==tty->session\n", 3358 " (%s): process_session(p)==tty->session\n",
3340 p->pid, p->comm); 3359 p->pid, p->comm);
3341 send_sig(SIGKILL, p, 1); 3360 send_sig(SIGKILL, p, 1);
3342 } while_each_task_pid(session, PIDTYPE_SID, p); 3361 } while_each_task_pid(session, PIDTYPE_SID, p);
@@ -3346,7 +3365,7 @@ static void __do_SAK(struct work_struct *work)
3346 do_each_thread(g, p) { 3365 do_each_thread(g, p) {
3347 if (p->signal->tty == tty) { 3366 if (p->signal->tty == tty) {
3348 printk(KERN_NOTICE "SAK: killed process %d" 3367 printk(KERN_NOTICE "SAK: killed process %d"
3349 " (%s): p->signal->session==tty->session\n", 3368 " (%s): process_session(p)==tty->session\n",
3350 p->pid, p->comm); 3369 p->pid, p->comm);
3351 send_sig(SIGKILL, p, 1); 3370 send_sig(SIGKILL, p, 1);
3352 continue; 3371 continue;
@@ -3456,84 +3475,6 @@ static void flush_to_ldisc(struct work_struct *work)
3456 tty_ldisc_deref(disc); 3475 tty_ldisc_deref(disc);
3457} 3476}
3458 3477
3459/*
3460 * Routine which returns the baud rate of the tty
3461 *
3462 * Note that the baud_table needs to be kept in sync with the
3463 * include/asm/termbits.h file.
3464 */
3465static int baud_table[] = {
3466 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
3467 9600, 19200, 38400, 57600, 115200, 230400, 460800,
3468#ifdef __sparc__
3469 76800, 153600, 307200, 614400, 921600
3470#else
3471 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
3472 2500000, 3000000, 3500000, 4000000
3473#endif
3474};
3475
3476static int n_baud_table = ARRAY_SIZE(baud_table);
3477
3478/**
3479 * tty_termios_baud_rate
3480 * @termios: termios structure
3481 *
3482 * Convert termios baud rate data into a speed. This should be called
3483 * with the termios lock held if this termios is a terminal termios
3484 * structure. May change the termios data.
3485 *
3486 * Locking: none
3487 */
3488
3489int tty_termios_baud_rate(struct termios *termios)
3490{
3491 unsigned int cbaud;
3492
3493 cbaud = termios->c_cflag & CBAUD;
3494
3495 if (cbaud & CBAUDEX) {
3496 cbaud &= ~CBAUDEX;
3497
3498 if (cbaud < 1 || cbaud + 15 > n_baud_table)
3499 termios->c_cflag &= ~CBAUDEX;
3500 else
3501 cbaud += 15;
3502 }
3503 return baud_table[cbaud];
3504}
3505
3506EXPORT_SYMBOL(tty_termios_baud_rate);
3507
3508/**
3509 * tty_get_baud_rate - get tty bit rates
3510 * @tty: tty to query
3511 *
3512 * Returns the baud rate as an integer for this terminal. The
3513 * termios lock must be held by the caller and the terminal bit
3514 * flags may be updated.
3515 *
3516 * Locking: none
3517 */
3518
3519int tty_get_baud_rate(struct tty_struct *tty)
3520{
3521 int baud = tty_termios_baud_rate(tty->termios);
3522
3523 if (baud == 38400 && tty->alt_speed) {
3524 if (!tty->warned) {
3525 printk(KERN_WARNING "Use of setserial/setrocket to "
3526 "set SPD_* flags is deprecated\n");
3527 tty->warned = 1;
3528 }
3529 baud = tty->alt_speed;
3530 }
3531
3532 return baud;
3533}
3534
3535EXPORT_SYMBOL(tty_get_baud_rate);
3536
3537/** 3478/**
3538 * tty_flip_buffer_push - terminal 3479 * tty_flip_buffer_push - terminal
3539 * @tty: tty to push 3480 * @tty: tty to push
@@ -3756,8 +3697,8 @@ int tty_register_driver(struct tty_driver *driver)
3756 3697
3757 if (p) { 3698 if (p) {
3758 driver->ttys = (struct tty_struct **)p; 3699 driver->ttys = (struct tty_struct **)p;
3759 driver->termios = (struct termios **)(p + driver->num); 3700 driver->termios = (struct ktermios **)(p + driver->num);
3760 driver->termios_locked = (struct termios **)(p + driver->num * 2); 3701 driver->termios_locked = (struct ktermios **)(p + driver->num * 2);
3761 } else { 3702 } else {
3762 driver->ttys = NULL; 3703 driver->ttys = NULL;
3763 driver->termios = NULL; 3704 driver->termios = NULL;
@@ -3796,7 +3737,7 @@ EXPORT_SYMBOL(tty_register_driver);
3796int tty_unregister_driver(struct tty_driver *driver) 3737int tty_unregister_driver(struct tty_driver *driver)
3797{ 3738{
3798 int i; 3739 int i;
3799 struct termios *tp; 3740 struct ktermios *tp;
3800 void *p; 3741 void *p;
3801 3742
3802 if (driver->refcount) 3743 if (driver->refcount)
@@ -3834,9 +3775,52 @@ int tty_unregister_driver(struct tty_driver *driver)
3834 cdev_del(&driver->cdev); 3775 cdev_del(&driver->cdev);
3835 return 0; 3776 return 0;
3836} 3777}
3837
3838EXPORT_SYMBOL(tty_unregister_driver); 3778EXPORT_SYMBOL(tty_unregister_driver);
3839 3779
3780dev_t tty_devnum(struct tty_struct *tty)
3781{
3782 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
3783}
3784EXPORT_SYMBOL(tty_devnum);
3785
3786void proc_clear_tty(struct task_struct *p)
3787{
3788 spin_lock_irq(&p->sighand->siglock);
3789 p->signal->tty = NULL;
3790 spin_unlock_irq(&p->sighand->siglock);
3791}
3792EXPORT_SYMBOL(proc_clear_tty);
3793
3794void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3795{
3796 if (tty) {
3797 tty->session = process_session(tsk);
3798 tty->pgrp = process_group(tsk);
3799 }
3800 tsk->signal->tty = tty;
3801 tsk->signal->tty_old_pgrp = 0;
3802}
3803
3804void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3805{
3806 spin_lock_irq(&tsk->sighand->siglock);
3807 __proc_set_tty(tsk, tty);
3808 spin_unlock_irq(&tsk->sighand->siglock);
3809}
3810
3811struct tty_struct *get_current_tty(void)
3812{
3813 struct tty_struct *tty;
3814 WARN_ON_ONCE(!mutex_is_locked(&tty_mutex));
3815 tty = current->signal->tty;
3816 /*
3817 * session->tty can be changed/cleared from under us, make sure we
3818 * issue the load. The obtained pointer, when not NULL, is valid as
3819 * long as we hold tty_mutex.
3820 */
3821 barrier();
3822 return tty;
3823}
3840 3824
3841/* 3825/*
3842 * Initialize the console device. This is called *early*, so 3826 * Initialize the console device. This is called *early*, so
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 3b6fa7b0be8b..dee47f40c6a3 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -36,6 +36,7 @@
36#define TERMIOS_FLUSH 1 36#define TERMIOS_FLUSH 1
37#define TERMIOS_WAIT 2 37#define TERMIOS_WAIT 2
38#define TERMIOS_TERMIO 4 38#define TERMIOS_TERMIO 4
39#define TERMIOS_OLD 8
39 40
40 41
41/** 42/**
@@ -84,9 +85,9 @@ stop_waiting:
84 85
85EXPORT_SYMBOL(tty_wait_until_sent); 86EXPORT_SYMBOL(tty_wait_until_sent);
86 87
87static void unset_locked_termios(struct termios *termios, 88static void unset_locked_termios(struct ktermios *termios,
88 struct termios *old, 89 struct ktermios *old,
89 struct termios *locked) 90 struct ktermios *locked)
90{ 91{
91 int i; 92 int i;
92 93
@@ -105,8 +106,204 @@ static void unset_locked_termios(struct termios *termios,
105 for (i=0; i < NCCS; i++) 106 for (i=0; i < NCCS; i++)
106 termios->c_cc[i] = locked->c_cc[i] ? 107 termios->c_cc[i] = locked->c_cc[i] ?
107 old->c_cc[i] : termios->c_cc[i]; 108 old->c_cc[i] : termios->c_cc[i];
109 /* FIXME: What should we do for i/ospeed */
108} 110}
109 111
112/*
113 * Routine which returns the baud rate of the tty
114 *
115 * Note that the baud_table needs to be kept in sync with the
116 * include/asm/termbits.h file.
117 */
118static const speed_t baud_table[] = {
119 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
120 9600, 19200, 38400, 57600, 115200, 230400, 460800,
121#ifdef __sparc__
122 76800, 153600, 307200, 614400, 921600
123#else
124 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
125 2500000, 3000000, 3500000, 4000000
126#endif
127};
128
129#ifndef __sparc__
130static const tcflag_t baud_bits[] = {
131 B0, B50, B75, B110, B134, B150, B200, B300, B600,
132 B1200, B1800, B2400, B4800, B9600, B19200, B38400,
133 B57600, B115200, B230400, B460800, B500000, B576000,
134 B921600, B1000000, B1152000, B1500000, B2000000, B2500000,
135 B3000000, B3500000, B4000000
136};
137#else
138static const tcflag_t baud_bits[] = {
139 B0, B50, B75, B110, B134, B150, B200, B300, B600,
140 B1200, B1800, B2400, B4800, B9600, B19200, B38400,
141 B57600, B115200, B230400, B460800, B76800, B153600,
142 B307200, B614400, B921600
143};
144#endif
145
146static int n_baud_table = ARRAY_SIZE(baud_table);
147
148/**
149 * tty_termios_baud_rate
150 * @termios: termios structure
151 *
152 * Convert termios baud rate data into a speed. This should be called
153 * with the termios lock held if this termios is a terminal termios
154 * structure. May change the termios data. Device drivers can call this
155 * function but should use ->c_[io]speed directly as they are updated.
156 *
157 * Locking: none
158 */
159
160speed_t tty_termios_baud_rate(struct ktermios *termios)
161{
162 unsigned int cbaud;
163
164 cbaud = termios->c_cflag & CBAUD;
165
166#ifdef BOTHER
167 /* Magic token for arbitary speed via c_ispeed/c_ospeed */
168 if (cbaud == BOTHER)
169 return termios->c_ospeed;
170#endif
171 if (cbaud & CBAUDEX) {
172 cbaud &= ~CBAUDEX;
173
174 if (cbaud < 1 || cbaud + 15 > n_baud_table)
175 termios->c_cflag &= ~CBAUDEX;
176 else
177 cbaud += 15;
178 }
179 return baud_table[cbaud];
180}
181
182EXPORT_SYMBOL(tty_termios_baud_rate);
183
184/**
185 * tty_termios_input_baud_rate
186 * @termios: termios structure
187 *
188 * Convert termios baud rate data into a speed. This should be called
189 * with the termios lock held if this termios is a terminal termios
190 * structure. May change the termios data. Device drivers can call this
191 * function but should use ->c_[io]speed directly as they are updated.
192 *
193 * Locking: none
194 */
195
196speed_t tty_termios_input_baud_rate(struct ktermios *termios)
197{
198#ifdef IBSHIFT
199 unsigned int cbaud = (termios->c_cflag >> IBSHIFT) & CBAUD;
200
201 if (cbaud == B0)
202 return tty_termios_baud_rate(termios);
203
204 /* Magic token for arbitary speed via c_ispeed*/
205 if (cbaud == BOTHER)
206 return termios->c_ispeed;
207
208 if (cbaud & CBAUDEX) {
209 cbaud &= ~CBAUDEX;
210
211 if (cbaud < 1 || cbaud + 15 > n_baud_table)
212 termios->c_cflag &= ~(CBAUDEX << IBSHIFT);
213 else
214 cbaud += 15;
215 }
216 return baud_table[cbaud];
217#else
218 return tty_termios_baud_rate(termios);
219#endif
220}
221
222EXPORT_SYMBOL(tty_termios_input_baud_rate);
223
224#ifdef BOTHER
225
226/**
227 * tty_termios_encode_baud_rate
228 * @termios: termios structure
229 * @ispeed: input speed
230 * @ospeed: output speed
231 *
232 * Encode the speeds set into the passed termios structure. This is
233 * used as a library helper for drivers os that they can report back
234 * the actual speed selected when it differs from the speed requested
235 *
236 * For now input and output speed must agree.
237 *
238 * Locking: Caller should hold termios lock. This is already held
239 * when calling this function from the driver termios handler.
240 */
241
242void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud, speed_t obaud)
243{
244 int i = 0;
245 int ifound = 0, ofound = 0;
246
247 termios->c_ispeed = ibaud;
248 termios->c_ospeed = obaud;
249
250 termios->c_cflag &= ~CBAUD;
251 /* Identical speed means no input encoding (ie B0 << IBSHIFT)*/
252 if (termios->c_ispeed == termios->c_ospeed)
253 ifound = 1;
254
255 do {
256 if (obaud == baud_table[i]) {
257 termios->c_cflag |= baud_bits[i];
258 ofound = 1;
259 /* So that if ibaud == obaud we don't set it */
260 continue;
261 }
262 if (ibaud == baud_table[i]) {
263 termios->c_cflag |= (baud_bits[i] << IBSHIFT);
264 ifound = 1;
265 }
266 }
267 while(++i < n_baud_table);
268 if (!ofound)
269 termios->c_cflag |= BOTHER;
270 if (!ifound)
271 termios->c_cflag |= (BOTHER << IBSHIFT);
272}
273
274EXPORT_SYMBOL_GPL(tty_termios_encode_baud_rate);
275
276#endif
277
278/**
279 * tty_get_baud_rate - get tty bit rates
280 * @tty: tty to query
281 *
282 * Returns the baud rate as an integer for this terminal. The
283 * termios lock must be held by the caller and the terminal bit
284 * flags may be updated.
285 *
286 * Locking: none
287 */
288
289speed_t tty_get_baud_rate(struct tty_struct *tty)
290{
291 speed_t baud = tty_termios_baud_rate(tty->termios);
292
293 if (baud == 38400 && tty->alt_speed) {
294 if (!tty->warned) {
295 printk(KERN_WARNING "Use of setserial/setrocket to "
296 "set SPD_* flags is deprecated\n");
297 tty->warned = 1;
298 }
299 baud = tty->alt_speed;
300 }
301
302 return baud;
303}
304
305EXPORT_SYMBOL(tty_get_baud_rate);
306
110/** 307/**
111 * change_termios - update termios values 308 * change_termios - update termios values
112 * @tty: tty to update 309 * @tty: tty to update
@@ -119,10 +316,10 @@ static void unset_locked_termios(struct termios *termios,
119 * Locking: termios_sem 316 * Locking: termios_sem
120 */ 317 */
121 318
122static void change_termios(struct tty_struct * tty, struct termios * new_termios) 319static void change_termios(struct tty_struct * tty, struct ktermios * new_termios)
123{ 320{
124 int canon_change; 321 int canon_change;
125 struct termios old_termios = *tty->termios; 322 struct ktermios old_termios = *tty->termios;
126 struct tty_ldisc *ld; 323 struct tty_ldisc *ld;
127 324
128 /* 325 /*
@@ -195,23 +392,39 @@ static void change_termios(struct tty_struct * tty, struct termios * new_termios
195 392
196static int set_termios(struct tty_struct * tty, void __user *arg, int opt) 393static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
197{ 394{
198 struct termios tmp_termios; 395 struct ktermios tmp_termios;
199 struct tty_ldisc *ld; 396 struct tty_ldisc *ld;
200 int retval = tty_check_change(tty); 397 int retval = tty_check_change(tty);
201 398
202 if (retval) 399 if (retval)
203 return retval; 400 return retval;
204 401
402 memcpy(&tmp_termios, tty->termios, sizeof(struct ktermios));
403
205 if (opt & TERMIOS_TERMIO) { 404 if (opt & TERMIOS_TERMIO) {
206 memcpy(&tmp_termios, tty->termios, sizeof(struct termios));
207 if (user_termio_to_kernel_termios(&tmp_termios, 405 if (user_termio_to_kernel_termios(&tmp_termios,
208 (struct termio __user *)arg)) 406 (struct termio __user *)arg))
209 return -EFAULT; 407 return -EFAULT;
408#ifdef TCGETS2
409 } else if (opt & TERMIOS_OLD) {
410 if (user_termios_to_kernel_termios_1(&tmp_termios,
411 (struct termios __user *)arg))
412 return -EFAULT;
210 } else { 413 } else {
211 if (user_termios_to_kernel_termios(&tmp_termios, 414 if (user_termios_to_kernel_termios(&tmp_termios,
212 (struct termios __user *)arg)) 415 (struct termios2 __user *)arg))
213 return -EFAULT; 416 return -EFAULT;
214 } 417 }
418#else
419 } else if (user_termios_to_kernel_termios(&tmp_termios,
420 (struct termios __user *)arg))
421 return -EFAULT;
422#endif
423
424 /* If old style Bfoo values are used then load c_ispeed/c_ospeed with the real speed
425 so its unconditionally usable */
426 tmp_termios.c_ispeed = tty_termios_input_baud_rate(&tmp_termios);
427 tmp_termios.c_ospeed = tty_termios_baud_rate(&tmp_termios);
215 428
216 ld = tty_ldisc_ref(tty); 429 ld = tty_ldisc_ref(tty);
217 430
@@ -286,8 +499,8 @@ static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
286 struct sgttyb tmp; 499 struct sgttyb tmp;
287 500
288 mutex_lock(&tty->termios_mutex); 501 mutex_lock(&tty->termios_mutex);
289 tmp.sg_ispeed = 0; 502 tmp.sg_ispeed = tty->termios->c_ispeed;
290 tmp.sg_ospeed = 0; 503 tmp.sg_ospeed = tty->termios->c_ospeed;
291 tmp.sg_erase = tty->termios->c_cc[VERASE]; 504 tmp.sg_erase = tty->termios->c_cc[VERASE];
292 tmp.sg_kill = tty->termios->c_cc[VKILL]; 505 tmp.sg_kill = tty->termios->c_cc[VKILL];
293 tmp.sg_flags = get_sgflags(tty); 506 tmp.sg_flags = get_sgflags(tty);
@@ -296,7 +509,7 @@ static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
296 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0; 509 return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0;
297} 510}
298 511
299static void set_sgflags(struct termios * termios, int flags) 512static void set_sgflags(struct ktermios * termios, int flags)
300{ 513{
301 termios->c_iflag = ICRNL | IXON; 514 termios->c_iflag = ICRNL | IXON;
302 termios->c_oflag = 0; 515 termios->c_oflag = 0;
@@ -337,7 +550,7 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
337{ 550{
338 int retval; 551 int retval;
339 struct sgttyb tmp; 552 struct sgttyb tmp;
340 struct termios termios; 553 struct ktermios termios;
341 554
342 retval = tty_check_change(tty); 555 retval = tty_check_change(tty);
343 if (retval) 556 if (retval)
@@ -351,6 +564,10 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
351 termios.c_cc[VERASE] = tmp.sg_erase; 564 termios.c_cc[VERASE] = tmp.sg_erase;
352 termios.c_cc[VKILL] = tmp.sg_kill; 565 termios.c_cc[VKILL] = tmp.sg_kill;
353 set_sgflags(&termios, tmp.sg_flags); 566 set_sgflags(&termios, tmp.sg_flags);
567 /* Try and encode into Bfoo format */
568#ifdef BOTHER
569 tty_termios_encode_baud_rate(&termios, termios.c_ispeed, termios.c_ospeed);
570#endif
354 mutex_unlock(&tty->termios_mutex); 571 mutex_unlock(&tty->termios_mutex);
355 change_termios(tty, &termios); 572 change_termios(tty, &termios);
356 return 0; 573 return 0;
@@ -481,16 +698,33 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
481 case TIOCSLTC: 698 case TIOCSLTC:
482 return set_ltchars(real_tty, p); 699 return set_ltchars(real_tty, p);
483#endif 700#endif
701 case TCSETSF:
702 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
703 case TCSETSW:
704 return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
705 case TCSETS:
706 return set_termios(real_tty, p, TERMIOS_OLD);
707#ifndef TCGETS2
484 case TCGETS: 708 case TCGETS:
485 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) 709 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios))
486 return -EFAULT; 710 return -EFAULT;
487 return 0; 711 return 0;
488 case TCSETSF: 712#else
713 case TCGETS:
714 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios))
715 return -EFAULT;
716 return 0;
717 case TCGETS2:
718 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios))
719 return -EFAULT;
720 return 0;
721 case TCSETSF2:
489 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); 722 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
490 case TCSETSW: 723 case TCSETSW2:
491 return set_termios(real_tty, p, TERMIOS_WAIT); 724 return set_termios(real_tty, p, TERMIOS_WAIT);
492 case TCSETS: 725 case TCSETS2:
493 return set_termios(real_tty, p, 0); 726 return set_termios(real_tty, p, 0);
727#endif
494 case TCGETA: 728 case TCGETA:
495 return get_termio(real_tty, p); 729 return get_termio(real_tty, p);
496 case TCSETAF: 730 case TCSETAF:
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index f442b574b44a..26776517f04c 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -72,7 +72,7 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
72 int size; 72 int size;
73 73
74 down(&con_buf_sem); 74 down(&con_buf_sem);
75 size = vcs_size(file->f_dentry->d_inode); 75 size = vcs_size(file->f_path.dentry->d_inode);
76 switch (orig) { 76 switch (orig) {
77 default: 77 default:
78 up(&con_buf_sem); 78 up(&con_buf_sem);
@@ -98,7 +98,7 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
98static ssize_t 98static ssize_t
99vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 99vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
100{ 100{
101 struct inode *inode = file->f_dentry->d_inode; 101 struct inode *inode = file->f_path.dentry->d_inode;
102 unsigned int currcons = iminor(inode); 102 unsigned int currcons = iminor(inode);
103 struct vc_data *vc; 103 struct vc_data *vc;
104 long pos; 104 long pos;
@@ -271,7 +271,7 @@ unlock_out:
271static ssize_t 271static ssize_t
272vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 272vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
273{ 273{
274 struct inode *inode = file->f_dentry->d_inode; 274 struct inode *inode = file->f_path.dentry->d_inode;
275 unsigned int currcons = iminor(inode); 275 unsigned int currcons = iminor(inode);
276 struct vc_data *vc; 276 struct vc_data *vc;
277 long pos; 277 long pos;
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 73c78bf75d7f..94d79cb8ce8d 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -442,7 +442,7 @@ static ssize_t viotap_write(struct file *file, const char *buf,
442 if (op == NULL) 442 if (op == NULL)
443 return -ENOMEM; 443 return -ENOMEM;
444 444
445 get_dev_info(file->f_dentry->d_inode, &devi); 445 get_dev_info(file->f_path.dentry->d_inode, &devi);
446 446
447 /* 447 /*
448 * We need to make sure we can send a request. We use 448 * We need to make sure we can send a request. We use
@@ -532,7 +532,7 @@ static ssize_t viotap_read(struct file *file, char *buf, size_t count,
532 if (op == NULL) 532 if (op == NULL)
533 return -ENOMEM; 533 return -ENOMEM;
534 534
535 get_dev_info(file->f_dentry->d_inode, &devi); 535 get_dev_info(file->f_path.dentry->d_inode, &devi);
536 536
537 /* 537 /*
538 * We need to make sure we can send a request. We use 538 * We need to make sure we can send a request. We use
@@ -612,7 +612,7 @@ static int viotap_ioctl(struct inode *inode, struct file *file,
612 if (op == NULL) 612 if (op == NULL)
613 return -ENOMEM; 613 return -ENOMEM;
614 614
615 get_dev_info(file->f_dentry->d_inode, &devi); 615 get_dev_info(file->f_path.dentry->d_inode, &devi);
616 616
617 down(&reqSem); 617 down(&reqSem);
618 618
@@ -777,7 +777,7 @@ static int viotap_open(struct inode *inode, struct file *file)
777 if (op == NULL) 777 if (op == NULL)
778 return -ENOMEM; 778 return -ENOMEM;
779 779
780 get_dev_info(file->f_dentry->d_inode, &devi); 780 get_dev_info(file->f_path.dentry->d_inode, &devi);
781 781
782 /* Note: We currently only support one mode! */ 782 /* Note: We currently only support one mode! */
783 if ((devi.devno >= viotape_numdev) || (devi.mode)) { 783 if ((devi.devno >= viotape_numdev) || (devi.mode)) {
@@ -822,7 +822,7 @@ static int viotap_release(struct inode *inode, struct file *file)
822 return -ENOMEM; 822 return -ENOMEM;
823 init_completion(&op->com); 823 init_completion(&op->com);
824 824
825 get_dev_info(file->f_dentry->d_inode, &devi); 825 get_dev_info(file->f_path.dentry->d_inode, &devi);
826 826
827 if (devi.devno >= viotape_numdev) { 827 if (devi.devno >= viotape_numdev) {
828 ret = -ENODEV; 828 ret = -ENODEV;
diff --git a/drivers/char/vme_scc.c b/drivers/char/vme_scc.c
index d0b94dd1af6d..e01317cb1a0e 100644
--- a/drivers/char/vme_scc.c
+++ b/drivers/char/vme_scc.c
@@ -153,6 +153,8 @@ static int scc_init_drivers(void)
153 scc_driver->init_termios = tty_std_termios; 153 scc_driver->init_termios = tty_std_termios;
154 scc_driver->init_termios.c_cflag = 154 scc_driver->init_termios.c_cflag =
155 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 155 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
156 scc_driver->init_termios.c_ispeed = 9600;
157 scc_driver->init_termios.c_ospeed = 9600;
156 scc_driver->flags = TTY_DRIVER_REAL_RAW; 158 scc_driver->flags = TTY_DRIVER_REAL_RAW;
157 tty_set_operations(scc_driver, &scc_ops); 159 tty_set_operations(scc_driver, &scc_ops);
158 160
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 8e7949305171..a744dad9cf45 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -506,7 +506,7 @@ static ssize_t gpio_read(struct file *file, char __user *buf, size_t len,
506 unsigned int pin; 506 unsigned int pin;
507 char value = '0'; 507 char value = '0';
508 508
509 pin = iminor(file->f_dentry->d_inode); 509 pin = iminor(file->f_path.dentry->d_inode);
510 if (pin >= giu_nr_pins) 510 if (pin >= giu_nr_pins)
511 return -EBADF; 511 return -EBADF;
512 512
@@ -530,7 +530,7 @@ static ssize_t gpio_write(struct file *file, const char __user *data,
530 char c; 530 char c;
531 int retval = 0; 531 int retval = 0;
532 532
533 pin = iminor(file->f_dentry->d_inode); 533 pin = iminor(file->f_path.dentry->d_inode);
534 if (pin >= giu_nr_pins) 534 if (pin >= giu_nr_pins)
535 return -EBADF; 535 return -EBADF;
536 536
diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index 7fcb77a9d011..b6bcdbbf57b3 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -77,11 +77,11 @@ static struct clocksource clocksource_acpi_pm = {
77 77
78 78
79#ifdef CONFIG_PCI 79#ifdef CONFIG_PCI
80static int acpi_pm_good; 80static int __devinitdata acpi_pm_good;
81static int __init acpi_pm_good_setup(char *__str) 81static int __init acpi_pm_good_setup(char *__str)
82{ 82{
83 acpi_pm_good = 1; 83 acpi_pm_good = 1;
84 return 1; 84 return 1;
85} 85}
86__setup("acpi_pm_good", acpi_pm_good_setup); 86__setup("acpi_pm_good", acpi_pm_good_setup);
87 87
@@ -142,6 +142,39 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_LE,
142 acpi_pm_check_graylist); 142 acpi_pm_check_graylist);
143#endif 143#endif
144 144
145#ifndef CONFIG_X86_64
146#include "mach_timer.h"
147#define PMTMR_EXPECTED_RATE \
148 ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
149/*
150 * Some boards have the PMTMR running way too fast. We check
151 * the PMTMR rate against PIT channel 2 to catch these cases.
152 */
153static int verify_pmtmr_rate(void)
154{
155 u32 value1, value2;
156 unsigned long count, delta;
157
158 mach_prepare_counter();
159 value1 = read_pmtmr();
160 mach_countup(&count);
161 value2 = read_pmtmr();
162 delta = (value2 - value1) & ACPI_PM_MASK;
163
164 /* Check that the PMTMR delta is within 5% of what we expect */
165 if (delta < (PMTMR_EXPECTED_RATE * 19) / 20 ||
166 delta > (PMTMR_EXPECTED_RATE * 21) / 20) {
167 printk(KERN_INFO "PM-Timer running at invalid rate: %lu%% "
168 "of normal - aborting.\n",
169 100UL * delta / PMTMR_EXPECTED_RATE);
170 return -1;
171 }
172
173 return 0;
174}
175#else
176#define verify_pmtmr_rate() (0)
177#endif
145 178
146static int __init init_acpi_pm_clocksource(void) 179static int __init init_acpi_pm_clocksource(void)
147{ 180{
@@ -173,6 +206,9 @@ static int __init init_acpi_pm_clocksource(void)
173 return -ENODEV; 206 return -ENODEV;
174 207
175pm_good: 208pm_good:
209 if (verify_pmtmr_rate() != 0)
210 return -ENODEV;
211
176 return clocksource_register(&clocksource_acpi_pm); 212 return clocksource_register(&clocksource_acpi_pm);
177} 213}
178 214
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index e816535ab305..879250d3d069 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -53,7 +53,7 @@ config CRYPTO_DEV_PADLOCK_SHA
53 53
54config CRYPTO_DEV_GEODE 54config CRYPTO_DEV_GEODE
55 tristate "Support for the Geode LX AES engine" 55 tristate "Support for the Geode LX AES engine"
56 depends on CRYPTO && X86_32 56 depends on CRYPTO && X86_32 && PCI
57 select CRYPTO_ALGAPI 57 select CRYPTO_ALGAPI
58 select CRYPTO_BLKCIPHER 58 select CRYPTO_BLKCIPHER
59 default m 59 default m
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
new file mode 100644
index 000000000000..96d4a0bb2203
--- /dev/null
+++ b/drivers/hid/Kconfig
@@ -0,0 +1,18 @@
1#
2# HID driver configuration
3#
4menu "HID Devices"
5 depends on INPUT
6
7config HID
8 tristate "Generic HID support"
9 default y
10 ---help---
11 Say Y here if you want generic HID support to connect keyboards,
12 mice, joysticks, graphic tablets, or any other HID based devices
13 to your computer. You also need to select particular types of
14 HID devices you want to compile support for, in the particular
15 driver menu (USB, Bluetooth)
16
17endmenu
18
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
new file mode 100644
index 000000000000..6432392110bf
--- /dev/null
+++ b/drivers/hid/Makefile
@@ -0,0 +1,15 @@
1#
2# Makefile for the HID driver
3#
4
5# Multipart objects.
6hid-objs := hid-core.o hid-input.o
7
8# Optional parts of multipart objects.
9
10obj-$(CONFIG_HID) += hid.o
11
12ifeq ($(CONFIG_INPUT_DEBUG),y)
13EXTRA_CFLAGS += -DDEBUG
14endif
15
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
new file mode 100644
index 000000000000..18c2b3cf6bcc
--- /dev/null
+++ b/drivers/hid/hid-core.c
@@ -0,0 +1,1003 @@
1/*
2 * HID support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006 Jiri Kosina
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 */
16
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/init.h>
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/list.h>
23#include <linux/mm.h>
24#include <linux/smp_lock.h>
25#include <linux/spinlock.h>
26#include <asm/unaligned.h>
27#include <asm/byteorder.h>
28#include <linux/input.h>
29#include <linux/wait.h>
30
31#undef DEBUG
32#undef DEBUG_DATA
33
34#include <linux/hid.h>
35#include <linux/hiddev.h>
36
37/*
38 * Version Information
39 */
40
41#define DRIVER_VERSION "v2.6"
42#define DRIVER_AUTHOR "Andreas Gal, Vojtech Pavlik"
43#define DRIVER_DESC "USB HID core driver"
44#define DRIVER_LICENSE "GPL"
45
46/*
47 * Module parameters.
48 */
49
50static unsigned int hid_mousepoll_interval;
51module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
52MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
53
54/*
55 * Register a new report for a device.
56 */
57
58static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
59{
60 struct hid_report_enum *report_enum = device->report_enum + type;
61 struct hid_report *report;
62
63 if (report_enum->report_id_hash[id])
64 return report_enum->report_id_hash[id];
65
66 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
67 return NULL;
68
69 if (id != 0)
70 report_enum->numbered = 1;
71
72 report->id = id;
73 report->type = type;
74 report->size = 0;
75 report->device = device;
76 report_enum->report_id_hash[id] = report;
77
78 list_add_tail(&report->list, &report_enum->report_list);
79
80 return report;
81}
82
83/*
84 * Register a new field for this report.
85 */
86
87static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
88{
89 struct hid_field *field;
90
91 if (report->maxfield == HID_MAX_FIELDS) {
92 dbg("too many fields in report");
93 return NULL;
94 }
95
96 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
97 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
98
99 field->index = report->maxfield++;
100 report->field[field->index] = field;
101 field->usage = (struct hid_usage *)(field + 1);
102 field->value = (unsigned *)(field->usage + usages);
103 field->report = report;
104
105 return field;
106}
107
108/*
109 * Open a collection. The type/usage is pushed on the stack.
110 */
111
112static int open_collection(struct hid_parser *parser, unsigned type)
113{
114 struct hid_collection *collection;
115 unsigned usage;
116
117 usage = parser->local.usage[0];
118
119 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
120 dbg("collection stack overflow");
121 return -1;
122 }
123
124 if (parser->device->maxcollection == parser->device->collection_size) {
125 collection = kmalloc(sizeof(struct hid_collection) *
126 parser->device->collection_size * 2, GFP_KERNEL);
127 if (collection == NULL) {
128 dbg("failed to reallocate collection array");
129 return -1;
130 }
131 memcpy(collection, parser->device->collection,
132 sizeof(struct hid_collection) *
133 parser->device->collection_size);
134 memset(collection + parser->device->collection_size, 0,
135 sizeof(struct hid_collection) *
136 parser->device->collection_size);
137 kfree(parser->device->collection);
138 parser->device->collection = collection;
139 parser->device->collection_size *= 2;
140 }
141
142 parser->collection_stack[parser->collection_stack_ptr++] =
143 parser->device->maxcollection;
144
145 collection = parser->device->collection +
146 parser->device->maxcollection++;
147 collection->type = type;
148 collection->usage = usage;
149 collection->level = parser->collection_stack_ptr - 1;
150
151 if (type == HID_COLLECTION_APPLICATION)
152 parser->device->maxapplication++;
153
154 return 0;
155}
156
157/*
158 * Close a collection.
159 */
160
161static int close_collection(struct hid_parser *parser)
162{
163 if (!parser->collection_stack_ptr) {
164 dbg("collection stack underflow");
165 return -1;
166 }
167 parser->collection_stack_ptr--;
168 return 0;
169}
170
171/*
172 * Climb up the stack, search for the specified collection type
173 * and return the usage.
174 */
175
176static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
177{
178 int n;
179 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
180 if (parser->device->collection[parser->collection_stack[n]].type == type)
181 return parser->device->collection[parser->collection_stack[n]].usage;
182 return 0; /* we know nothing about this usage type */
183}
184
185/*
186 * Add a usage to the temporary parser table.
187 */
188
189static int hid_add_usage(struct hid_parser *parser, unsigned usage)
190{
191 if (parser->local.usage_index >= HID_MAX_USAGES) {
192 dbg("usage index exceeded");
193 return -1;
194 }
195 parser->local.usage[parser->local.usage_index] = usage;
196 parser->local.collection_index[parser->local.usage_index] =
197 parser->collection_stack_ptr ?
198 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
199 parser->local.usage_index++;
200 return 0;
201}
202
203/*
204 * Register a new field for this report.
205 */
206
207static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
208{
209 struct hid_report *report;
210 struct hid_field *field;
211 int usages;
212 unsigned offset;
213 int i;
214
215 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
216 dbg("hid_register_report failed");
217 return -1;
218 }
219
220 if (parser->global.logical_maximum < parser->global.logical_minimum) {
221 dbg("logical range invalid %d %d", parser->global.logical_minimum, parser->global.logical_maximum);
222 return -1;
223 }
224
225 offset = report->size;
226 report->size += parser->global.report_size * parser->global.report_count;
227
228 if (!parser->local.usage_index) /* Ignore padding fields */
229 return 0;
230
231 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
232
233 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
234 return 0;
235
236 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
237 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
238 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
239
240 for (i = 0; i < usages; i++) {
241 int j = i;
242 /* Duplicate the last usage we parsed if we have excess values */
243 if (i >= parser->local.usage_index)
244 j = parser->local.usage_index - 1;
245 field->usage[i].hid = parser->local.usage[j];
246 field->usage[i].collection_index =
247 parser->local.collection_index[j];
248 }
249
250 field->maxusage = usages;
251 field->flags = flags;
252 field->report_offset = offset;
253 field->report_type = report_type;
254 field->report_size = parser->global.report_size;
255 field->report_count = parser->global.report_count;
256 field->logical_minimum = parser->global.logical_minimum;
257 field->logical_maximum = parser->global.logical_maximum;
258 field->physical_minimum = parser->global.physical_minimum;
259 field->physical_maximum = parser->global.physical_maximum;
260 field->unit_exponent = parser->global.unit_exponent;
261 field->unit = parser->global.unit;
262
263 return 0;
264}
265
266/*
267 * Read data value from item.
268 */
269
270static u32 item_udata(struct hid_item *item)
271{
272 switch (item->size) {
273 case 1: return item->data.u8;
274 case 2: return item->data.u16;
275 case 4: return item->data.u32;
276 }
277 return 0;
278}
279
280static s32 item_sdata(struct hid_item *item)
281{
282 switch (item->size) {
283 case 1: return item->data.s8;
284 case 2: return item->data.s16;
285 case 4: return item->data.s32;
286 }
287 return 0;
288}
289
290/*
291 * Process a global item.
292 */
293
294static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
295{
296 switch (item->tag) {
297
298 case HID_GLOBAL_ITEM_TAG_PUSH:
299
300 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
301 dbg("global enviroment stack overflow");
302 return -1;
303 }
304
305 memcpy(parser->global_stack + parser->global_stack_ptr++,
306 &parser->global, sizeof(struct hid_global));
307 return 0;
308
309 case HID_GLOBAL_ITEM_TAG_POP:
310
311 if (!parser->global_stack_ptr) {
312 dbg("global enviroment stack underflow");
313 return -1;
314 }
315
316 memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr,
317 sizeof(struct hid_global));
318 return 0;
319
320 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
321 parser->global.usage_page = item_udata(item);
322 return 0;
323
324 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
325 parser->global.logical_minimum = item_sdata(item);
326 return 0;
327
328 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
329 if (parser->global.logical_minimum < 0)
330 parser->global.logical_maximum = item_sdata(item);
331 else
332 parser->global.logical_maximum = item_udata(item);
333 return 0;
334
335 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
336 parser->global.physical_minimum = item_sdata(item);
337 return 0;
338
339 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
340 if (parser->global.physical_minimum < 0)
341 parser->global.physical_maximum = item_sdata(item);
342 else
343 parser->global.physical_maximum = item_udata(item);
344 return 0;
345
346 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
347 parser->global.unit_exponent = item_sdata(item);
348 return 0;
349
350 case HID_GLOBAL_ITEM_TAG_UNIT:
351 parser->global.unit = item_udata(item);
352 return 0;
353
354 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
355 if ((parser->global.report_size = item_udata(item)) > 32) {
356 dbg("invalid report_size %d", parser->global.report_size);
357 return -1;
358 }
359 return 0;
360
361 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
362 if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) {
363 dbg("invalid report_count %d", parser->global.report_count);
364 return -1;
365 }
366 return 0;
367
368 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
369 if ((parser->global.report_id = item_udata(item)) == 0) {
370 dbg("report_id 0 is invalid");
371 return -1;
372 }
373 return 0;
374
375 default:
376 dbg("unknown global tag 0x%x", item->tag);
377 return -1;
378 }
379}
380
381/*
382 * Process a local item.
383 */
384
385static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
386{
387 __u32 data;
388 unsigned n;
389
390 if (item->size == 0) {
391 dbg("item data expected for local item");
392 return -1;
393 }
394
395 data = item_udata(item);
396
397 switch (item->tag) {
398
399 case HID_LOCAL_ITEM_TAG_DELIMITER:
400
401 if (data) {
402 /*
403 * We treat items before the first delimiter
404 * as global to all usage sets (branch 0).
405 * In the moment we process only these global
406 * items and the first delimiter set.
407 */
408 if (parser->local.delimiter_depth != 0) {
409 dbg("nested delimiters");
410 return -1;
411 }
412 parser->local.delimiter_depth++;
413 parser->local.delimiter_branch++;
414 } else {
415 if (parser->local.delimiter_depth < 1) {
416 dbg("bogus close delimiter");
417 return -1;
418 }
419 parser->local.delimiter_depth--;
420 }
421 return 1;
422
423 case HID_LOCAL_ITEM_TAG_USAGE:
424
425 if (parser->local.delimiter_branch > 1) {
426 dbg("alternative usage ignored");
427 return 0;
428 }
429
430 if (item->size <= 2)
431 data = (parser->global.usage_page << 16) + data;
432
433 return hid_add_usage(parser, data);
434
435 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
436
437 if (parser->local.delimiter_branch > 1) {
438 dbg("alternative usage ignored");
439 return 0;
440 }
441
442 if (item->size <= 2)
443 data = (parser->global.usage_page << 16) + data;
444
445 parser->local.usage_minimum = data;
446 return 0;
447
448 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
449
450 if (parser->local.delimiter_branch > 1) {
451 dbg("alternative usage ignored");
452 return 0;
453 }
454
455 if (item->size <= 2)
456 data = (parser->global.usage_page << 16) + data;
457
458 for (n = parser->local.usage_minimum; n <= data; n++)
459 if (hid_add_usage(parser, n)) {
460 dbg("hid_add_usage failed\n");
461 return -1;
462 }
463 return 0;
464
465 default:
466
467 dbg("unknown local item tag 0x%x", item->tag);
468 return 0;
469 }
470 return 0;
471}
472
473/*
474 * Process a main item.
475 */
476
477static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
478{
479 __u32 data;
480 int ret;
481
482 data = item_udata(item);
483
484 switch (item->tag) {
485 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
486 ret = open_collection(parser, data & 0xff);
487 break;
488 case HID_MAIN_ITEM_TAG_END_COLLECTION:
489 ret = close_collection(parser);
490 break;
491 case HID_MAIN_ITEM_TAG_INPUT:
492 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
493 break;
494 case HID_MAIN_ITEM_TAG_OUTPUT:
495 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
496 break;
497 case HID_MAIN_ITEM_TAG_FEATURE:
498 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
499 break;
500 default:
501 dbg("unknown main item tag 0x%x", item->tag);
502 ret = 0;
503 }
504
505 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
506
507 return ret;
508}
509
510/*
511 * Process a reserved item.
512 */
513
514static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
515{
516 dbg("reserved item type, tag 0x%x", item->tag);
517 return 0;
518}
519
520/*
521 * Free a report and all registered fields. The field->usage and
522 * field->value table's are allocated behind the field, so we need
523 * only to free(field) itself.
524 */
525
526static void hid_free_report(struct hid_report *report)
527{
528 unsigned n;
529
530 for (n = 0; n < report->maxfield; n++)
531 kfree(report->field[n]);
532 kfree(report);
533}
534
535/*
536 * Free a device structure, all reports, and all fields.
537 */
538
539void hid_free_device(struct hid_device *device)
540{
541 unsigned i,j;
542
543 for (i = 0; i < HID_REPORT_TYPES; i++) {
544 struct hid_report_enum *report_enum = device->report_enum + i;
545
546 for (j = 0; j < 256; j++) {
547 struct hid_report *report = report_enum->report_id_hash[j];
548 if (report)
549 hid_free_report(report);
550 }
551 }
552
553 kfree(device->rdesc);
554 kfree(device);
555}
556EXPORT_SYMBOL_GPL(hid_free_device);
557
558/*
559 * Fetch a report description item from the data stream. We support long
560 * items, though they are not used yet.
561 */
562
563static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
564{
565 u8 b;
566
567 if ((end - start) <= 0)
568 return NULL;
569
570 b = *start++;
571
572 item->type = (b >> 2) & 3;
573 item->tag = (b >> 4) & 15;
574
575 if (item->tag == HID_ITEM_TAG_LONG) {
576
577 item->format = HID_ITEM_FORMAT_LONG;
578
579 if ((end - start) < 2)
580 return NULL;
581
582 item->size = *start++;
583 item->tag = *start++;
584
585 if ((end - start) < item->size)
586 return NULL;
587
588 item->data.longdata = start;
589 start += item->size;
590 return start;
591 }
592
593 item->format = HID_ITEM_FORMAT_SHORT;
594 item->size = b & 3;
595
596 switch (item->size) {
597
598 case 0:
599 return start;
600
601 case 1:
602 if ((end - start) < 1)
603 return NULL;
604 item->data.u8 = *start++;
605 return start;
606
607 case 2:
608 if ((end - start) < 2)
609 return NULL;
610 item->data.u16 = le16_to_cpu(get_unaligned((__le16*)start));
611 start = (__u8 *)((__le16 *)start + 1);
612 return start;
613
614 case 3:
615 item->size++;
616 if ((end - start) < 4)
617 return NULL;
618 item->data.u32 = le32_to_cpu(get_unaligned((__le32*)start));
619 start = (__u8 *)((__le32 *)start + 1);
620 return start;
621 }
622
623 return NULL;
624}
625
626/*
627 * Parse a report description into a hid_device structure. Reports are
628 * enumerated, fields are attached to these reports.
629 */
630
631struct hid_device *hid_parse_report(__u8 *start, unsigned size)
632{
633 struct hid_device *device;
634 struct hid_parser *parser;
635 struct hid_item item;
636 __u8 *end;
637 unsigned i;
638 static int (*dispatch_type[])(struct hid_parser *parser,
639 struct hid_item *item) = {
640 hid_parser_main,
641 hid_parser_global,
642 hid_parser_local,
643 hid_parser_reserved
644 };
645
646 if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL)))
647 return NULL;
648
649 if (!(device->collection = kzalloc(sizeof(struct hid_collection) *
650 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
651 kfree(device);
652 return NULL;
653 }
654 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
655
656 for (i = 0; i < HID_REPORT_TYPES; i++)
657 INIT_LIST_HEAD(&device->report_enum[i].report_list);
658
659 if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
660 kfree(device->collection);
661 kfree(device);
662 return NULL;
663 }
664 memcpy(device->rdesc, start, size);
665 device->rsize = size;
666
667 if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
668 kfree(device->rdesc);
669 kfree(device->collection);
670 kfree(device);
671 return NULL;
672 }
673 parser->device = device;
674
675 end = start + size;
676 while ((start = fetch_item(start, end, &item)) != NULL) {
677
678 if (item.format != HID_ITEM_FORMAT_SHORT) {
679 dbg("unexpected long global item");
680 kfree(device->collection);
681 hid_free_device(device);
682 kfree(parser);
683 return NULL;
684 }
685
686 if (dispatch_type[item.type](parser, &item)) {
687 dbg("item %u %u %u %u parsing failed\n",
688 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
689 kfree(device->collection);
690 hid_free_device(device);
691 kfree(parser);
692 return NULL;
693 }
694
695 if (start == end) {
696 if (parser->collection_stack_ptr) {
697 dbg("unbalanced collection at end of report description");
698 kfree(device->collection);
699 hid_free_device(device);
700 kfree(parser);
701 return NULL;
702 }
703 if (parser->local.delimiter_depth) {
704 dbg("unbalanced delimiter at end of report description");
705 kfree(device->collection);
706 hid_free_device(device);
707 kfree(parser);
708 return NULL;
709 }
710 kfree(parser);
711 return device;
712 }
713 }
714
715 dbg("item fetching failed at offset %d\n", (int)(end - start));
716 kfree(device->collection);
717 hid_free_device(device);
718 kfree(parser);
719 return NULL;
720}
721EXPORT_SYMBOL_GPL(hid_parse_report);
722
723/*
724 * Convert a signed n-bit integer to signed 32-bit integer. Common
725 * cases are done through the compiler, the screwed things has to be
726 * done by hand.
727 */
728
729static s32 snto32(__u32 value, unsigned n)
730{
731 switch (n) {
732 case 8: return ((__s8)value);
733 case 16: return ((__s16)value);
734 case 32: return ((__s32)value);
735 }
736 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
737}
738
739/*
740 * Convert a signed 32-bit integer to a signed n-bit integer.
741 */
742
743static u32 s32ton(__s32 value, unsigned n)
744{
745 s32 a = value >> (n - 1);
746 if (a && a != -1)
747 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
748 return value & ((1 << n) - 1);
749}
750
751/*
752 * Extract/implement a data field from/to a little endian report (bit array).
753 *
754 * Code sort-of follows HID spec:
755 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
756 *
757 * While the USB HID spec allows unlimited length bit fields in "report
758 * descriptors", most devices never use more than 16 bits.
759 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
760 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
761 */
762
763static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
764{
765 u64 x;
766
767 WARN_ON(n > 32);
768
769 report += offset >> 3; /* adjust byte index */
770 offset &= 7; /* now only need bit offset into one byte */
771 x = get_unaligned((u64 *) report);
772 x = le64_to_cpu(x);
773 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
774 return (u32) x;
775}
776
777/*
778 * "implement" : set bits in a little endian bit stream.
779 * Same concepts as "extract" (see comments above).
780 * The data mangled in the bit stream remains in little endian
781 * order the whole time. It make more sense to talk about
782 * endianness of register values by considering a register
783 * a "cached" copy of the little endiad bit stream.
784 */
785static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
786{
787 u64 x;
788 u64 m = (1ULL << n) - 1;
789
790 WARN_ON(n > 32);
791
792 WARN_ON(value > m);
793 value &= m;
794
795 report += offset >> 3;
796 offset &= 7;
797
798 x = get_unaligned((u64 *)report);
799 x &= cpu_to_le64(~(m << offset));
800 x |= cpu_to_le64(((u64) value) << offset);
801 put_unaligned(x, (u64 *) report);
802}
803
804/*
805 * Search an array for a value.
806 */
807
808static __inline__ int search(__s32 *array, __s32 value, unsigned n)
809{
810 while (n--) {
811 if (*array++ == value)
812 return 0;
813 }
814 return -1;
815}
816
817static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt)
818{
819 hid_dump_input(usage, value);
820 if (hid->claimed & HID_CLAIMED_INPUT)
821 hidinput_hid_event(hid, field, usage, value);
822 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
823 hid->hiddev_hid_event(hid, field, usage, value);
824}
825
826/*
827 * Analyse a received field, and fetch the data from it. The field
828 * content is stored for next report processing (we do differential
829 * reporting to the layer).
830 */
831
832void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt)
833{
834 unsigned n;
835 unsigned count = field->report_count;
836 unsigned offset = field->report_offset;
837 unsigned size = field->report_size;
838 __s32 min = field->logical_minimum;
839 __s32 max = field->logical_maximum;
840 __s32 *value;
841
842 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
843 return;
844
845 for (n = 0; n < count; n++) {
846
847 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
848 extract(data, offset + n * size, size);
849
850 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
851 && value[n] >= min && value[n] <= max
852 && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
853 goto exit;
854 }
855
856 for (n = 0; n < count; n++) {
857
858 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
859 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
860 continue;
861 }
862
863 if (field->value[n] >= min && field->value[n] <= max
864 && field->usage[field->value[n] - min].hid
865 && search(value, field->value[n], count))
866 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
867
868 if (value[n] >= min && value[n] <= max
869 && field->usage[value[n] - min].hid
870 && search(field->value, value[n], count))
871 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
872 }
873
874 memcpy(field->value, value, count * sizeof(__s32));
875exit:
876 kfree(value);
877}
878EXPORT_SYMBOL_GPL(hid_input_field);
879
880/*
881 * Output the field into the report.
882 */
883
884static void hid_output_field(struct hid_field *field, __u8 *data)
885{
886 unsigned count = field->report_count;
887 unsigned offset = field->report_offset;
888 unsigned size = field->report_size;
889 unsigned n;
890
891 for (n = 0; n < count; n++) {
892 if (field->logical_minimum < 0) /* signed values */
893 implement(data, offset + n * size, size, s32ton(field->value[n], size));
894 else /* unsigned values */
895 implement(data, offset + n * size, size, field->value[n]);
896 }
897}
898
899/*
900 * Create a report.
901 */
902
903void hid_output_report(struct hid_report *report, __u8 *data)
904{
905 unsigned n;
906
907 if (report->id > 0)
908 *data++ = report->id;
909
910 for (n = 0; n < report->maxfield; n++)
911 hid_output_field(report->field[n], data);
912}
913EXPORT_SYMBOL_GPL(hid_output_report);
914
915/*
916 * Set a field value. The report this field belongs to has to be
917 * created and transferred to the device, to set this value in the
918 * device.
919 */
920
921int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
922{
923 unsigned size = field->report_size;
924
925 hid_dump_input(field->usage + offset, value);
926
927 if (offset >= field->report_count) {
928 dbg("offset (%d) exceeds report_count (%d)", offset, field->report_count);
929 hid_dump_field(field, 8);
930 return -1;
931 }
932 if (field->logical_minimum < 0) {
933 if (value != snto32(s32ton(value, size), size)) {
934 dbg("value %d is out of range", value);
935 return -1;
936 }
937 }
938 field->value[offset] = value;
939 return 0;
940}
941EXPORT_SYMBOL_GPL(hid_set_field);
942
943int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
944{
945 struct hid_report_enum *report_enum = hid->report_enum + type;
946 struct hid_report *report;
947 int n, rsize;
948
949 if (!hid)
950 return -ENODEV;
951
952 if (!size) {
953 dbg("empty report");
954 return -1;
955 }
956
957#ifdef DEBUG_DATA
958 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un");
959#endif
960
961 n = 0; /* Normally report number is 0 */
962 if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */
963 n = *data++;
964 size--;
965 }
966
967#ifdef DEBUG_DATA
968 {
969 int i;
970 printk(KERN_DEBUG __FILE__ ": report %d (size %u) = ", n, size);
971 for (i = 0; i < size; i++)
972 printk(" %02x", data[i]);
973 printk("\n");
974 }
975#endif
976
977 if (!(report = report_enum->report_id_hash[n])) {
978 dbg("undefined report_id %d received", n);
979 return -1;
980 }
981
982 rsize = ((report->size - 1) >> 3) + 1;
983
984 if (size < rsize) {
985 dbg("report %d is too short, (%d < %d)", report->id, size, rsize);
986 return -1;
987 }
988
989 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
990 hid->hiddev_report_event(hid, report);
991
992 for (n = 0; n < report->maxfield; n++)
993 hid_input_field(hid, report->field[n], data, interrupt);
994
995 if (hid->claimed & HID_CLAIMED_INPUT)
996 hidinput_report_event(hid, report);
997
998 return 0;
999}
1000EXPORT_SYMBOL_GPL(hid_input_report);
1001
1002MODULE_LICENSE(DRIVER_LICENSE);
1003
diff --git a/drivers/usb/input/hid-input.c b/drivers/hid/hid-input.c
index 68e7ebb978a9..14cdf09316ce 100644
--- a/drivers/usb/input/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -2,8 +2,9 @@
2 * $Id: hid-input.c,v 1.2 2002/04/23 00:59:25 rdamazio Exp $ 2 * $Id: hid-input.c,v 1.2 2002/04/23 00:59:25 rdamazio Exp $
3 * 3 *
4 * Copyright (c) 2000-2001 Vojtech Pavlik 4 * Copyright (c) 2000-2001 Vojtech Pavlik
5 * Copyright (c) 2006 Jiri Kosina
5 * 6 *
6 * USB HID to Linux Input mapping 7 * HID to Linux Input mapping
7 */ 8 */
8 9
9/* 10/*
@@ -33,7 +34,7 @@
33 34
34#undef DEBUG 35#undef DEBUG
35 36
36#include "hid.h" 37#include <linux/hid.h>
37 38
38#define unk KEY_UNKNOWN 39#define unk KEY_UNKNOWN
39 40
@@ -81,42 +82,42 @@ struct hidinput_key_translation {
81 82
82static struct hidinput_key_translation powerbook_fn_keys[] = { 83static struct hidinput_key_translation powerbook_fn_keys[] = {
83 { KEY_BACKSPACE, KEY_DELETE }, 84 { KEY_BACKSPACE, KEY_DELETE },
84 { KEY_F1, KEY_BRIGHTNESSDOWN, POWERBOOK_FLAG_FKEY }, 85 { KEY_F1, KEY_BRIGHTNESSDOWN, POWERBOOK_FLAG_FKEY },
85 { KEY_F2, KEY_BRIGHTNESSUP, POWERBOOK_FLAG_FKEY }, 86 { KEY_F2, KEY_BRIGHTNESSUP, POWERBOOK_FLAG_FKEY },
86 { KEY_F3, KEY_MUTE, POWERBOOK_FLAG_FKEY }, 87 { KEY_F3, KEY_MUTE, POWERBOOK_FLAG_FKEY },
87 { KEY_F4, KEY_VOLUMEDOWN, POWERBOOK_FLAG_FKEY }, 88 { KEY_F4, KEY_VOLUMEDOWN, POWERBOOK_FLAG_FKEY },
88 { KEY_F5, KEY_VOLUMEUP, POWERBOOK_FLAG_FKEY }, 89 { KEY_F5, KEY_VOLUMEUP, POWERBOOK_FLAG_FKEY },
89 { KEY_F6, KEY_NUMLOCK, POWERBOOK_FLAG_FKEY }, 90 { KEY_F6, KEY_NUMLOCK, POWERBOOK_FLAG_FKEY },
90 { KEY_F7, KEY_SWITCHVIDEOMODE, POWERBOOK_FLAG_FKEY }, 91 { KEY_F7, KEY_SWITCHVIDEOMODE, POWERBOOK_FLAG_FKEY },
91 { KEY_F8, KEY_KBDILLUMTOGGLE, POWERBOOK_FLAG_FKEY }, 92 { KEY_F8, KEY_KBDILLUMTOGGLE, POWERBOOK_FLAG_FKEY },
92 { KEY_F9, KEY_KBDILLUMDOWN, POWERBOOK_FLAG_FKEY }, 93 { KEY_F9, KEY_KBDILLUMDOWN, POWERBOOK_FLAG_FKEY },
93 { KEY_F10, KEY_KBDILLUMUP, POWERBOOK_FLAG_FKEY }, 94 { KEY_F10, KEY_KBDILLUMUP, POWERBOOK_FLAG_FKEY },
94 { KEY_UP, KEY_PAGEUP }, 95 { KEY_UP, KEY_PAGEUP },
95 { KEY_DOWN, KEY_PAGEDOWN }, 96 { KEY_DOWN, KEY_PAGEDOWN },
96 { KEY_LEFT, KEY_HOME }, 97 { KEY_LEFT, KEY_HOME },
97 { KEY_RIGHT, KEY_END }, 98 { KEY_RIGHT, KEY_END },
98 { } 99 { }
99}; 100};
100 101
101static struct hidinput_key_translation powerbook_numlock_keys[] = { 102static struct hidinput_key_translation powerbook_numlock_keys[] = {
102 { KEY_J, KEY_KP1 }, 103 { KEY_J, KEY_KP1 },
103 { KEY_K, KEY_KP2 }, 104 { KEY_K, KEY_KP2 },
104 { KEY_L, KEY_KP3 }, 105 { KEY_L, KEY_KP3 },
105 { KEY_U, KEY_KP4 }, 106 { KEY_U, KEY_KP4 },
106 { KEY_I, KEY_KP5 }, 107 { KEY_I, KEY_KP5 },
107 { KEY_O, KEY_KP6 }, 108 { KEY_O, KEY_KP6 },
108 { KEY_7, KEY_KP7 }, 109 { KEY_7, KEY_KP7 },
109 { KEY_8, KEY_KP8 }, 110 { KEY_8, KEY_KP8 },
110 { KEY_9, KEY_KP9 }, 111 { KEY_9, KEY_KP9 },
111 { KEY_M, KEY_KP0 }, 112 { KEY_M, KEY_KP0 },
112 { KEY_DOT, KEY_KPDOT }, 113 { KEY_DOT, KEY_KPDOT },
113 { KEY_SLASH, KEY_KPPLUS }, 114 { KEY_SLASH, KEY_KPPLUS },
114 { KEY_SEMICOLON, KEY_KPMINUS }, 115 { KEY_SEMICOLON, KEY_KPMINUS },
115 { KEY_P, KEY_KPASTERISK }, 116 { KEY_P, KEY_KPASTERISK },
116 { KEY_MINUS, KEY_KPEQUAL }, 117 { KEY_MINUS, KEY_KPEQUAL },
117 { KEY_0, KEY_KPSLASH }, 118 { KEY_0, KEY_KPSLASH },
118 { KEY_F6, KEY_NUMLOCK }, 119 { KEY_F6, KEY_NUMLOCK },
119 { KEY_KPENTER, KEY_KPENTER }, 120 { KEY_KPENTER, KEY_KPENTER },
120 { KEY_BACKSPACE, KEY_BACKSPACE }, 121 { KEY_BACKSPACE, KEY_BACKSPACE },
121 { } 122 { }
122}; 123};
@@ -127,11 +128,6 @@ static struct hidinput_key_translation powerbook_iso_keyboard[] = {
127 { } 128 { }
128}; 129};
129 130
130static int usbhid_pb_fnmode = 1;
131module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
132MODULE_PARM_DESC(pb_fnmode,
133 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
134
135static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from) 131static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from)
136{ 132{
137 struct hidinput_key_translation *trans; 133 struct hidinput_key_translation *trans;
@@ -145,7 +141,7 @@ static struct hidinput_key_translation *find_translation(struct hidinput_key_tra
145} 141}
146 142
147static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input, 143static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
148 struct hid_usage *usage, __s32 value) 144 struct hid_usage *usage, __s32 value)
149{ 145{
150 struct hidinput_key_translation *trans; 146 struct hidinput_key_translation *trans;
151 147
@@ -158,7 +154,7 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
158 return 1; 154 return 1;
159 } 155 }
160 156
161 if (usbhid_pb_fnmode) { 157 if (hid->pb_fnmode) {
162 int do_translate; 158 int do_translate;
163 159
164 trans = find_translation(powerbook_fn_keys, usage->code); 160 trans = find_translation(powerbook_fn_keys, usage->code);
@@ -167,8 +163,8 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
167 do_translate = 1; 163 do_translate = 1;
168 else if (trans->flags & POWERBOOK_FLAG_FKEY) 164 else if (trans->flags & POWERBOOK_FLAG_FKEY)
169 do_translate = 165 do_translate =
170 (usbhid_pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) || 166 (hid->pb_fnmode == 2 && (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)) ||
171 (usbhid_pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON)); 167 (hid->pb_fnmode == 1 && !(hid->quirks & HID_QUIRK_POWERBOOK_FN_ON));
172 else 168 else
173 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON); 169 do_translate = (hid->quirks & HID_QUIRK_POWERBOOK_FN_ON);
174 170
@@ -185,7 +181,7 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
185 } 181 }
186 182
187 if (test_bit(usage->code, hid->pb_pressed_numlock) || 183 if (test_bit(usage->code, hid->pb_pressed_numlock) ||
188 test_bit(LED_NUML, input->led)) { 184 test_bit(LED_NUML, input->led)) {
189 trans = find_translation(powerbook_numlock_keys, usage->code); 185 trans = find_translation(powerbook_numlock_keys, usage->code);
190 186
191 if (trans) { 187 if (trans) {
@@ -227,10 +223,11 @@ static void hidinput_pb_setup(struct input_dev *input)
227 223
228 for (trans = powerbook_iso_keyboard; trans->from; trans++) 224 for (trans = powerbook_iso_keyboard; trans->from; trans++)
229 set_bit(trans->to, input->keybit); 225 set_bit(trans->to, input->keybit);
226
230} 227}
231#else 228#else
232static inline int hidinput_pb_event(struct hid_device *hid, struct input_dev *input, 229static inline int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
233 struct hid_usage *usage, __s32 value) 230 struct hid_usage *usage, __s32 value)
234{ 231{
235 return 0; 232 return 0;
236} 233}
@@ -581,6 +578,10 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
581 || ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) 578 || ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007)))
582 goto ignore; 579 goto ignore;
583 580
581 if ((device->quirks & HID_QUIRK_BAD_RELATIVE_KEYS) &&
582 usage->type == EV_KEY && (field->flags & HID_MAIN_ITEM_RELATIVE))
583 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
584
584 set_bit(usage->type, input->evbit); 585 set_bit(usage->type, input->evbit);
585 586
586 while (usage->code <= max && test_and_set_bit(usage->code, bit)) 587 while (usage->code <= max && test_and_set_bit(usage->code, bit))
@@ -720,8 +721,9 @@ void hidinput_report_event(struct hid_device *hid, struct hid_report *report)
720 list_for_each_entry(hidinput, &hid->inputs, list) 721 list_for_each_entry(hidinput, &hid->inputs, list)
721 input_sync(hidinput->input); 722 input_sync(hidinput->input);
722} 723}
724EXPORT_SYMBOL_GPL(hidinput_report_event);
723 725
724static int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field) 726int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field)
725{ 727{
726 struct hid_report *report; 728 struct hid_report *report;
727 int i, j; 729 int i, j;
@@ -736,41 +738,7 @@ static int hidinput_find_field(struct hid_device *hid, unsigned int type, unsign
736 } 738 }
737 return -1; 739 return -1;
738} 740}
739 741EXPORT_SYMBOL_GPL(hidinput_find_field);
740static int hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
741{
742 struct hid_device *hid = dev->private;
743 struct hid_field *field;
744 int offset;
745
746 if (type == EV_FF)
747 return input_ff_event(dev, type, code, value);
748
749 if (type != EV_LED)
750 return -1;
751
752 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
753 warn("event field not found");
754 return -1;
755 }
756
757 hid_set_field(field, offset, value);
758 hid_submit_report(hid, field->report, USB_DIR_OUT);
759
760 return 0;
761}
762
763static int hidinput_open(struct input_dev *dev)
764{
765 struct hid_device *hid = dev->private;
766 return hid_open(hid);
767}
768
769static void hidinput_close(struct input_dev *dev)
770{
771 struct hid_device *hid = dev->private;
772 hid_close(hid);
773}
774 742
775/* 743/*
776 * Register the input device; print a message. 744 * Register the input device; print a message.
@@ -780,7 +748,6 @@ static void hidinput_close(struct input_dev *dev)
780 748
781int hidinput_connect(struct hid_device *hid) 749int hidinput_connect(struct hid_device *hid)
782{ 750{
783 struct usb_device *dev = hid->dev;
784 struct hid_report *report; 751 struct hid_report *report;
785 struct hid_input *hidinput = NULL; 752 struct hid_input *hidinput = NULL;
786 struct input_dev *input_dev; 753 struct input_dev *input_dev;
@@ -814,16 +781,18 @@ int hidinput_connect(struct hid_device *hid)
814 } 781 }
815 782
816 input_dev->private = hid; 783 input_dev->private = hid;
817 input_dev->event = hidinput_input_event; 784 input_dev->event = hid->hidinput_input_event;
818 input_dev->open = hidinput_open; 785 input_dev->open = hid->hidinput_open;
819 input_dev->close = hidinput_close; 786 input_dev->close = hid->hidinput_close;
820 787
821 input_dev->name = hid->name; 788 input_dev->name = hid->name;
822 input_dev->phys = hid->phys; 789 input_dev->phys = hid->phys;
823 input_dev->uniq = hid->uniq; 790 input_dev->uniq = hid->uniq;
824 usb_to_input_id(dev, &input_dev->id); 791 input_dev->id.bustype = hid->bus;
825 input_dev->cdev.dev = &hid->intf->dev; 792 input_dev->id.vendor = hid->vendor;
826 793 input_dev->id.product = hid->product;
794 input_dev->id.version = hid->version;
795 input_dev->cdev.dev = hid->dev;
827 hidinput->input = input_dev; 796 hidinput->input = input_dev;
828 list_add_tail(&hidinput->list, &hid->inputs); 797 list_add_tail(&hidinput->list, &hid->inputs);
829 } 798 }
@@ -845,16 +814,12 @@ int hidinput_connect(struct hid_device *hid)
845 } 814 }
846 } 815 }
847 816
848 /* This only gets called when we are a single-input (most of the 817 if (hidinput)
849 * time). IOW, not a HID_QUIRK_MULTI_INPUT. The hid_ff_init() is
850 * only useful in this case, and not for multi-input quirks. */
851 if (hidinput) {
852 hid_ff_init(hid);
853 input_register_device(hidinput->input); 818 input_register_device(hidinput->input);
854 }
855 819
856 return 0; 820 return 0;
857} 821}
822EXPORT_SYMBOL_GPL(hidinput_connect);
858 823
859void hidinput_disconnect(struct hid_device *hid) 824void hidinput_disconnect(struct hid_device *hid)
860{ 825{
@@ -866,3 +831,5 @@ void hidinput_disconnect(struct hid_device *hid)
866 kfree(hidinput); 831 kfree(hidinput);
867 } 832 }
868} 833}
834EXPORT_SYMBOL_GPL(hidinput_disconnect);
835
diff --git a/drivers/i2c/algos/Kconfig b/drivers/i2c/algos/Kconfig
index c034820615bb..af0203409dd1 100644
--- a/drivers/i2c/algos/Kconfig
+++ b/drivers/i2c/algos/Kconfig
@@ -38,17 +38,6 @@ config I2C_ALGOPCA
38 This support is also available as a module. If so, the module 38 This support is also available as a module. If so, the module
39 will be called i2c-algo-pca. 39 will be called i2c-algo-pca.
40 40
41config I2C_ALGOITE
42 tristate "ITE I2C Algorithm"
43 depends on MIPS_ITE8172 && I2C
44 help
45 This supports the use of the ITE8172 I2C interface found on some MIPS
46 systems. Say Y if you have one of these. You should also say Y for
47 the ITE I2C peripheral driver support below.
48
49 This support is also available as a module. If so, the module
50 will be called i2c-algo-ite.
51
52config I2C_ALGO8XX 41config I2C_ALGO8XX
53 tristate "MPC8xx CPM I2C interface" 42 tristate "MPC8xx CPM I2C interface"
54 depends on 8xx && I2C 43 depends on 8xx && I2C
diff --git a/drivers/i2c/algos/Makefile b/drivers/i2c/algos/Makefile
index 208be04a3dbd..cac1051bd4f1 100644
--- a/drivers/i2c/algos/Makefile
+++ b/drivers/i2c/algos/Makefile
@@ -5,7 +5,6 @@
5obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o 5obj-$(CONFIG_I2C_ALGOBIT) += i2c-algo-bit.o
6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o 6obj-$(CONFIG_I2C_ALGOPCF) += i2c-algo-pcf.o
7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o 7obj-$(CONFIG_I2C_ALGOPCA) += i2c-algo-pca.o
8obj-$(CONFIG_I2C_ALGOITE) += i2c-algo-ite.o
9obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o 8obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o
10 9
11ifeq ($(CONFIG_I2C_DEBUG_ALGO),y) 10ifeq ($(CONFIG_I2C_DEBUG_ALGO),y)
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 21c36bfb5e6b..95aa5395a5be 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -540,15 +540,7 @@ int i2c_bit_add_bus(struct i2c_adapter *adap)
540 540
541 return i2c_add_adapter(adap); 541 return i2c_add_adapter(adap);
542} 542}
543
544
545int i2c_bit_del_bus(struct i2c_adapter *adap)
546{
547 return i2c_del_adapter(adap);
548}
549
550EXPORT_SYMBOL(i2c_bit_add_bus); 543EXPORT_SYMBOL(i2c_bit_add_bus);
551EXPORT_SYMBOL(i2c_bit_del_bus);
552 544
553MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); 545MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
554MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); 546MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm");
diff --git a/drivers/i2c/algos/i2c-algo-ite.c b/drivers/i2c/algos/i2c-algo-ite.c
deleted file mode 100644
index 70d8eefb5efc..000000000000
--- a/drivers/i2c/algos/i2c-algo-ite.c
+++ /dev/null
@@ -1,806 +0,0 @@
1/*
2 -------------------------------------------------------------------------
3 i2c-algo-ite.c i2c driver algorithms for ITE adapters
4
5 Hai-Pao Fan, MontaVista Software, Inc.
6 hpfan@mvista.com or source@mvista.com
7
8 Copyright 2000 MontaVista Software Inc.
9
10 ---------------------------------------------------------------------------
11 This file was highly leveraged from i2c-algo-pcf.c, which was created
12 by Simon G. Vogl and Hans Berglund:
13
14
15 Copyright (C) 1995-1997 Simon G. Vogl
16 1998-2000 Hans Berglund
17
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
22
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31/* ------------------------------------------------------------------------- */
32
33/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
34 Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey
35 <mbailey@littlefeet-inc.com> */
36
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/delay.h>
40#include <linux/slab.h>
41#include <linux/init.h>
42#include <asm/uaccess.h>
43#include <linux/ioport.h>
44#include <linux/errno.h>
45#include <linux/sched.h>
46
47#include <linux/i2c.h>
48#include <linux/i2c-algo-ite.h>
49#include "i2c-algo-ite.h"
50
51#define PM_DSR IT8172_PCI_IO_BASE + IT_PM_DSR
52#define PM_IBSR IT8172_PCI_IO_BASE + IT_PM_DSR + 0x04
53#define GPIO_CCR IT8172_PCI_IO_BASE + IT_GPCCR
54
55#define DEB2(x) if (i2c_debug>=2) x
56#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/
57#define DEF_TIMEOUT 16
58
59
60/* module parameters:
61 */
62static int i2c_debug;
63static int iic_test; /* see if the line-setting functions work */
64
65/* --- setting states on the bus with the right timing: --------------- */
66
67#define get_clock(adap) adap->getclock(adap->data)
68#define iic_outw(adap, reg, val) adap->setiic(adap->data, reg, val)
69#define iic_inw(adap, reg) adap->getiic(adap->data, reg)
70
71
72/* --- other auxiliary functions -------------------------------------- */
73
74static void iic_start(struct i2c_algo_iic_data *adap)
75{
76 iic_outw(adap,ITE_I2CHCR,ITE_CMD);
77}
78
79static void iic_stop(struct i2c_algo_iic_data *adap)
80{
81 iic_outw(adap,ITE_I2CHCR,0);
82 iic_outw(adap,ITE_I2CHSR,ITE_I2CHSR_TDI);
83}
84
85static void iic_reset(struct i2c_algo_iic_data *adap)
86{
87 iic_outw(adap, PM_IBSR, iic_inw(adap, PM_IBSR) | 0x80);
88}
89
90
91static int wait_for_bb(struct i2c_algo_iic_data *adap)
92{
93 int timeout = DEF_TIMEOUT;
94 short status;
95
96 status = iic_inw(adap, ITE_I2CHSR);
97#ifndef STUB_I2C
98 while (timeout-- && (status & ITE_I2CHSR_HB)) {
99 udelay(1000); /* How much is this? */
100 status = iic_inw(adap, ITE_I2CHSR);
101 }
102#endif
103 if (timeout<=0) {
104 printk(KERN_ERR "Timeout, host is busy\n");
105 iic_reset(adap);
106 }
107 return(timeout<=0);
108}
109
110/* After we issue a transaction on the IIC bus, this function
111 * is called. It puts this process to sleep until we get an interrupt from
112 * from the controller telling us that the transaction we requested in complete.
113 */
114static int wait_for_pin(struct i2c_algo_iic_data *adap, short *status) {
115
116 int timeout = DEF_TIMEOUT;
117
118 timeout = wait_for_bb(adap);
119 if (timeout) {
120 DEB2(printk("Timeout waiting for host not busy\n");)
121 return -EIO;
122 }
123 timeout = DEF_TIMEOUT;
124
125 *status = iic_inw(adap, ITE_I2CHSR);
126#ifndef STUB_I2C
127 while (timeout-- && !(*status & ITE_I2CHSR_TDI)) {
128 adap->waitforpin();
129 *status = iic_inw(adap, ITE_I2CHSR);
130 }
131#endif
132 if (timeout <= 0)
133 return(-1);
134 else
135 return(0);
136}
137
138static int wait_for_fe(struct i2c_algo_iic_data *adap, short *status)
139{
140 int timeout = DEF_TIMEOUT;
141
142 *status = iic_inw(adap, ITE_I2CFSR);
143#ifndef STUB_I2C
144 while (timeout-- && (*status & ITE_I2CFSR_FE)) {
145 udelay(1000);
146 iic_inw(adap, ITE_I2CFSR);
147 }
148#endif
149 if (timeout <= 0)
150 return(-1);
151 else
152 return(0);
153}
154
155static int iic_init (struct i2c_algo_iic_data *adap)
156{
157 short i;
158
159 /* Clear bit 7 to set I2C to normal operation mode */
160 i=iic_inw(adap, PM_DSR)& 0xff7f;
161 iic_outw(adap, PM_DSR, i);
162
163 /* set IT_GPCCR port C bit 2&3 as function 2 */
164 i = iic_inw(adap, GPIO_CCR) & 0xfc0f;
165 iic_outw(adap,GPIO_CCR,i);
166
167 /* Clear slave address/sub-address */
168 iic_outw(adap,ITE_I2CSAR, 0);
169 iic_outw(adap,ITE_I2CSSAR, 0);
170
171 /* Set clock counter register */
172 iic_outw(adap,ITE_I2CCKCNT, get_clock(adap));
173
174 /* Set START/reSTART/STOP time registers */
175 iic_outw(adap,ITE_I2CSHDR, 0x0a);
176 iic_outw(adap,ITE_I2CRSUR, 0x0a);
177 iic_outw(adap,ITE_I2CPSUR, 0x0a);
178
179 /* Enable interrupts on completing the current transaction */
180 iic_outw(adap,ITE_I2CHCR, ITE_I2CHCR_IE | ITE_I2CHCR_HCE);
181
182 /* Clear transfer count */
183 iic_outw(adap,ITE_I2CFBCR, 0x0);
184
185 DEB2(printk("iic_init: Initialized IIC on ITE 0x%x\n",
186 iic_inw(adap, ITE_I2CHSR)));
187 return 0;
188}
189
190
191/*
192 * Sanity check for the adapter hardware - check the reaction of
193 * the bus lines only if it seems to be idle.
194 */
195static int test_bus(struct i2c_algo_iic_data *adap, char *name) {
196#if 0
197 int scl,sda;
198 sda=getsda(adap);
199 if (adap->getscl==NULL) {
200 printk("test_bus: Warning: Adapter can't read from clock line - skipping test.\n");
201 return 0;
202 }
203 scl=getscl(adap);
204 printk("test_bus: Adapter: %s scl: %d sda: %d -- testing...\n",
205 name,getscl(adap),getsda(adap));
206 if (!scl || !sda ) {
207 printk("test_bus: %s seems to be busy.\n",adap->name);
208 goto bailout;
209 }
210 sdalo(adap);
211 printk("test_bus:1 scl: %d sda: %d\n", getscl(adap),
212 getsda(adap));
213 if ( 0 != getsda(adap) ) {
214 printk("test_bus: %s SDA stuck high!\n",name);
215 sdahi(adap);
216 goto bailout;
217 }
218 if ( 0 == getscl(adap) ) {
219 printk("test_bus: %s SCL unexpected low while pulling SDA low!\n",
220 name);
221 goto bailout;
222 }
223 sdahi(adap);
224 printk("test_bus:2 scl: %d sda: %d\n", getscl(adap),
225 getsda(adap));
226 if ( 0 == getsda(adap) ) {
227 printk("test_bus: %s SDA stuck low!\n",name);
228 sdahi(adap);
229 goto bailout;
230 }
231 if ( 0 == getscl(adap) ) {
232 printk("test_bus: %s SCL unexpected low while SDA high!\n",
233 adap->name);
234 goto bailout;
235 }
236 scllo(adap);
237 printk("test_bus:3 scl: %d sda: %d\n", getscl(adap),
238 getsda(adap));
239 if ( 0 != getscl(adap) ) {
240
241 sclhi(adap);
242 goto bailout;
243 }
244 if ( 0 == getsda(adap) ) {
245 printk("test_bus: %s SDA unexpected low while pulling SCL low!\n",
246 name);
247 goto bailout;
248 }
249 sclhi(adap);
250 printk("test_bus:4 scl: %d sda: %d\n", getscl(adap),
251 getsda(adap));
252 if ( 0 == getscl(adap) ) {
253 printk("test_bus: %s SCL stuck low!\n",name);
254 sclhi(adap);
255 goto bailout;
256 }
257 if ( 0 == getsda(adap) ) {
258 printk("test_bus: %s SDA unexpected low while SCL high!\n",
259 name);
260 goto bailout;
261 }
262 printk("test_bus: %s passed test.\n",name);
263 return 0;
264bailout:
265 sdahi(adap);
266 sclhi(adap);
267 return -ENODEV;
268#endif
269 return (0);
270}
271
272/* ----- Utility functions
273 */
274
275
276/* Verify the device we want to talk to on the IIC bus really exists. */
277static inline int try_address(struct i2c_algo_iic_data *adap,
278 unsigned int addr, int retries)
279{
280 int i, ret = -1;
281 short status;
282
283 for (i=0;i<retries;i++) {
284 iic_outw(adap, ITE_I2CSAR, addr);
285 iic_start(adap);
286 if (wait_for_pin(adap, &status) == 0) {
287 if ((status & ITE_I2CHSR_DNE) == 0) {
288 iic_stop(adap);
289 iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH);
290 ret=1;
291 break; /* success! */
292 }
293 }
294 iic_stop(adap);
295 udelay(adap->udelay);
296 }
297 DEB2(if (i) printk("try_address: needed %d retries for 0x%x\n",i,
298 addr));
299 return ret;
300}
301
302
303static int iic_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
304 int count)
305{
306 struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
307 int wrcount=0, timeout;
308 short status;
309 int loops, remainder, i, j;
310 union {
311 char byte[2];
312 unsigned short word;
313 } tmp;
314
315 iic_outw(adap, ITE_I2CSSAR, (unsigned short)buf[wrcount++]);
316 count--;
317 if (count == 0)
318 return -EIO;
319
320 loops = count / 32; /* 32-byte FIFO */
321 remainder = count % 32;
322
323 if(loops) {
324 for(i=0; i<loops; i++) {
325
326 iic_outw(adap, ITE_I2CFBCR, 32);
327 for(j=0; j<32/2; j++) {
328 tmp.byte[1] = buf[wrcount++];
329 tmp.byte[0] = buf[wrcount++];
330 iic_outw(adap, ITE_I2CFDR, tmp.word);
331 }
332
333 /* status FIFO overrun */
334 iic_inw(adap, ITE_I2CFSR);
335 iic_inw(adap, ITE_I2CFBCR);
336
337 iic_outw(adap, ITE_I2CHCR, ITE_WRITE); /* Issue WRITE command */
338
339 /* Wait for transmission to complete */
340 timeout = wait_for_pin(adap, &status);
341 if(timeout) {
342 iic_stop(adap);
343 printk("iic_sendbytes: %s write timeout.\n", i2c_adap->name);
344 return -EREMOTEIO; /* got a better one ?? */
345 }
346 if (status & ITE_I2CHSR_DB) {
347 iic_stop(adap);
348 printk("iic_sendbytes: %s write error - no ack.\n", i2c_adap->name);
349 return -EREMOTEIO; /* got a better one ?? */
350 }
351 }
352 }
353 if(remainder) {
354 iic_outw(adap, ITE_I2CFBCR, remainder);
355 for(i=0; i<remainder/2; i++) {
356 tmp.byte[1] = buf[wrcount++];
357 tmp.byte[0] = buf[wrcount++];
358 iic_outw(adap, ITE_I2CFDR, tmp.word);
359 }
360
361 /* status FIFO overrun */
362 iic_inw(adap, ITE_I2CFSR);
363 iic_inw(adap, ITE_I2CFBCR);
364
365 iic_outw(adap, ITE_I2CHCR, ITE_WRITE); /* Issue WRITE command */
366
367 timeout = wait_for_pin(adap, &status);
368 if(timeout) {
369 iic_stop(adap);
370 printk("iic_sendbytes: %s write timeout.\n", i2c_adap->name);
371 return -EREMOTEIO; /* got a better one ?? */
372 }
373#ifndef STUB_I2C
374 if (status & ITE_I2CHSR_DB) {
375 iic_stop(adap);
376 printk("iic_sendbytes: %s write error - no ack.\n", i2c_adap->name);
377 return -EREMOTEIO; /* got a better one ?? */
378 }
379#endif
380 }
381 iic_stop(adap);
382 return wrcount;
383}
384
385
386static int iic_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count,
387 int sread)
388{
389 int rdcount=0, i, timeout;
390 short status;
391 struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
392 int loops, remainder, j;
393 union {
394 char byte[2];
395 unsigned short word;
396 } tmp;
397
398 loops = count / 32; /* 32-byte FIFO */
399 remainder = count % 32;
400
401 if(loops) {
402 for(i=0; i<loops; i++) {
403 iic_outw(adap, ITE_I2CFBCR, 32);
404 if (sread)
405 iic_outw(adap, ITE_I2CHCR, ITE_SREAD);
406 else
407 iic_outw(adap, ITE_I2CHCR, ITE_READ); /* Issue READ command */
408
409 timeout = wait_for_pin(adap, &status);
410 if(timeout) {
411 iic_stop(adap);
412 printk("iic_readbytes: %s read timeout.\n", i2c_adap->name);
413 return (-1);
414 }
415#ifndef STUB_I2C
416 if (status & ITE_I2CHSR_DB) {
417 iic_stop(adap);
418 printk("iic_readbytes: %s read error - no ack.\n", i2c_adap->name);
419 return (-1);
420 }
421#endif
422
423 timeout = wait_for_fe(adap, &status);
424 if(timeout) {
425 iic_stop(adap);
426 printk("iic_readbytes: %s FIFO is empty\n", i2c_adap->name);
427 return (-1);
428 }
429
430 for(j=0; j<32/2; j++) {
431 tmp.word = iic_inw(adap, ITE_I2CFDR);
432 buf[rdcount++] = tmp.byte[1];
433 buf[rdcount++] = tmp.byte[0];
434 }
435
436 /* status FIFO underrun */
437 iic_inw(adap, ITE_I2CFSR);
438
439 }
440 }
441
442
443 if(remainder) {
444 remainder=(remainder+1)/2 * 2;
445 iic_outw(adap, ITE_I2CFBCR, remainder);
446 if (sread)
447 iic_outw(adap, ITE_I2CHCR, ITE_SREAD);
448 else
449 iic_outw(adap, ITE_I2CHCR, ITE_READ); /* Issue READ command */
450
451 timeout = wait_for_pin(adap, &status);
452 if(timeout) {
453 iic_stop(adap);
454 printk("iic_readbytes: %s read timeout.\n", i2c_adap->name);
455 return (-1);
456 }
457#ifndef STUB_I2C
458 if (status & ITE_I2CHSR_DB) {
459 iic_stop(adap);
460 printk("iic_readbytes: %s read error - no ack.\n", i2c_adap->name);
461 return (-1);
462 }
463#endif
464 timeout = wait_for_fe(adap, &status);
465 if(timeout) {
466 iic_stop(adap);
467 printk("iic_readbytes: %s FIFO is empty\n", i2c_adap->name);
468 return (-1);
469 }
470
471 for(i=0; i<(remainder+1)/2; i++) {
472 tmp.word = iic_inw(adap, ITE_I2CFDR);
473 buf[rdcount++] = tmp.byte[1];
474 buf[rdcount++] = tmp.byte[0];
475 }
476
477 /* status FIFO underrun */
478 iic_inw(adap, ITE_I2CFSR);
479
480 }
481
482 iic_stop(adap);
483 return rdcount;
484}
485
486
487/* This function implements combined transactions. Combined
488 * transactions consist of combinations of reading and writing blocks of data.
489 * Each transfer (i.e. a read or a write) is separated by a repeated start
490 * condition.
491 */
492#if 0
493static int iic_combined_transaction(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
494{
495 int i;
496 struct i2c_msg *pmsg;
497 int ret;
498
499 DEB2(printk("Beginning combined transaction\n"));
500
501 for(i=0; i<(num-1); i++) {
502 pmsg = &msgs[i];
503 if(pmsg->flags & I2C_M_RD) {
504 DEB2(printk(" This one is a read\n"));
505 ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_COMBINED_XFER);
506 }
507 else if(!(pmsg->flags & I2C_M_RD)) {
508 DEB2(printk("This one is a write\n"));
509 ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_COMBINED_XFER);
510 }
511 }
512 /* Last read or write segment needs to be terminated with a stop */
513 pmsg = &msgs[i];
514
515 if(pmsg->flags & I2C_M_RD) {
516 DEB2(printk("Doing the last read\n"));
517 ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
518 }
519 else if(!(pmsg->flags & I2C_M_RD)) {
520 DEB2(printk("Doing the last write\n"));
521 ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len, IIC_SINGLE_XFER);
522 }
523
524 return ret;
525}
526#endif
527
528
529/* Whenever we initiate a transaction, the first byte clocked
530 * onto the bus after the start condition is the address (7 bit) of the
531 * device we want to talk to. This function manipulates the address specified
532 * so that it makes sense to the hardware when written to the IIC peripheral.
533 *
534 * Note: 10 bit addresses are not supported in this driver, although they are
535 * supported by the hardware. This functionality needs to be implemented.
536 */
537static inline int iic_doAddress(struct i2c_algo_iic_data *adap,
538 struct i2c_msg *msg, int retries)
539{
540 unsigned short flags = msg->flags;
541 unsigned int addr;
542 int ret;
543
544/* Ten bit addresses not supported right now */
545 if ( (flags & I2C_M_TEN) ) {
546#if 0
547 addr = 0xf0 | (( msg->addr >> 7) & 0x03);
548 DEB2(printk("addr0: %d\n",addr));
549 ret = try_address(adap, addr, retries);
550 if (ret!=1) {
551 printk("iic_doAddress: died at extended address code.\n");
552 return -EREMOTEIO;
553 }
554 iic_outw(adap,msg->addr & 0x7f);
555 if (ret != 1) {
556 printk("iic_doAddress: died at 2nd address code.\n");
557 return -EREMOTEIO;
558 }
559 if ( flags & I2C_M_RD ) {
560 i2c_repstart(adap);
561 addr |= 0x01;
562 ret = try_address(adap, addr, retries);
563 if (ret!=1) {
564 printk("iic_doAddress: died at extended address code.\n");
565 return -EREMOTEIO;
566 }
567 }
568#endif
569 } else {
570
571 addr = ( msg->addr << 1 );
572
573#if 0
574 if (flags & I2C_M_RD )
575 addr |= 1;
576 if (flags & I2C_M_REV_DIR_ADDR )
577 addr ^= 1;
578#endif
579
580 if (iic_inw(adap, ITE_I2CSAR) != addr) {
581 iic_outw(adap, ITE_I2CSAR, addr);
582 ret = try_address(adap, addr, retries);
583 if (ret!=1) {
584 printk("iic_doAddress: died at address code.\n");
585 return -EREMOTEIO;
586 }
587 }
588
589 }
590
591 return 0;
592}
593
594
595/* Description: Prepares the controller for a transaction (clearing status
596 * registers, data buffers, etc), and then calls either iic_readbytes or
597 * iic_sendbytes to do the actual transaction.
598 *
599 * still to be done: Before we issue a transaction, we should
600 * verify that the bus is not busy or in some unknown state.
601 */
602static int iic_xfer(struct i2c_adapter *i2c_adap,
603 struct i2c_msg *msgs,
604 int num)
605{
606 struct i2c_algo_iic_data *adap = i2c_adap->algo_data;
607 struct i2c_msg *pmsg;
608 int i = 0;
609 int ret, timeout;
610
611 pmsg = &msgs[i];
612
613 if(!pmsg->len) {
614 DEB2(printk("iic_xfer: read/write length is 0\n");)
615 return -EIO;
616 }
617 if(!(pmsg->flags & I2C_M_RD) && (!(pmsg->len)%2) ) {
618 DEB2(printk("iic_xfer: write buffer length is not odd\n");)
619 return -EIO;
620 }
621
622 /* Wait for any pending transfers to complete */
623 timeout = wait_for_bb(adap);
624 if (timeout) {
625 DEB2(printk("iic_xfer: Timeout waiting for host not busy\n");)
626 return -EIO;
627 }
628
629 /* Flush FIFO */
630 iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH);
631
632 /* Load address */
633 ret = iic_doAddress(adap, pmsg, i2c_adap->retries);
634 if (ret)
635 return -EIO;
636
637#if 0
638 /* Combined transaction (read and write) */
639 if(num > 1) {
640 DEB2(printk("iic_xfer: Call combined transaction\n"));
641 ret = iic_combined_transaction(i2c_adap, msgs, num);
642 }
643#endif
644
645 DEB3(printk("iic_xfer: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
646 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
647
648 if(pmsg->flags & I2C_M_RD) /* Read */
649 ret = iic_readbytes(i2c_adap, pmsg->buf, pmsg->len, 0);
650 else { /* Write */
651 udelay(1000);
652 ret = iic_sendbytes(i2c_adap, pmsg->buf, pmsg->len);
653 }
654
655 if (ret != pmsg->len)
656 DEB3(printk("iic_xfer: error or fail on read/write %d bytes.\n",ret));
657 else
658 DEB3(printk("iic_xfer: read/write %d bytes.\n",ret));
659
660 return ret;
661}
662
663
664/* Implements device specific ioctls. Higher level ioctls can
665 * be found in i2c-core.c and are typical of any i2c controller (specifying
666 * slave address, timeouts, etc). These ioctls take advantage of any hardware
667 * features built into the controller for which this algorithm-adapter set
668 * was written. These ioctls allow you to take control of the data and clock
669 * lines and set the either high or low,
670 * similar to a GPIO pin.
671 */
672static int algo_control(struct i2c_adapter *adapter,
673 unsigned int cmd, unsigned long arg)
674{
675
676 struct i2c_algo_iic_data *adap = adapter->algo_data;
677 struct i2c_iic_msg s_msg;
678 char *buf;
679 int ret;
680
681 if (cmd == I2C_SREAD) {
682 if(copy_from_user(&s_msg, (struct i2c_iic_msg *)arg,
683 sizeof(struct i2c_iic_msg)))
684 return -EFAULT;
685 buf = kmalloc(s_msg.len, GFP_KERNEL);
686 if (buf== NULL)
687 return -ENOMEM;
688
689 /* Flush FIFO */
690 iic_outw(adap, ITE_I2CFCR, ITE_I2CFCR_FLUSH);
691
692 /* Load address */
693 iic_outw(adap, ITE_I2CSAR,s_msg.addr<<1);
694 iic_outw(adap, ITE_I2CSSAR,s_msg.waddr & 0xff);
695
696 ret = iic_readbytes(adapter, buf, s_msg.len, 1);
697 if (ret>=0) {
698 if(copy_to_user( s_msg.buf, buf, s_msg.len) )
699 ret = -EFAULT;
700 }
701 kfree(buf);
702 }
703 return 0;
704}
705
706
707static u32 iic_func(struct i2c_adapter *adap)
708{
709 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
710 I2C_FUNC_PROTOCOL_MANGLING;
711}
712
713/* -----exported algorithm data: ------------------------------------- */
714
715static struct i2c_algorithm iic_algo = {
716 .master_xfer = iic_xfer,
717 .algo_control = algo_control, /* ioctl */
718 .functionality = iic_func,
719};
720
721
722/*
723 * registering functions to load algorithms at runtime
724 */
725int i2c_iic_add_bus(struct i2c_adapter *adap)
726{
727 struct i2c_algo_iic_data *iic_adap = adap->algo_data;
728
729 if (iic_test) {
730 int ret = test_bus(iic_adap, adap->name);
731 if (ret<0)
732 return -ENODEV;
733 }
734
735 DEB2(printk("i2c-algo-ite: hw routines for %s registered.\n",
736 adap->name));
737
738 /* register new adapter to i2c module... */
739 adap->algo = &iic_algo;
740
741 adap->timeout = 100; /* default values, should */
742 adap->retries = 3; /* be replaced by defines */
743 adap->flags = 0;
744
745 iic_init(iic_adap);
746 return i2c_add_adapter(adap);
747}
748
749
750int i2c_iic_del_bus(struct i2c_adapter *adap)
751{
752 int res;
753 if ((res = i2c_del_adapter(adap)) < 0)
754 return res;
755 DEB2(printk("i2c-algo-ite: adapter unregistered: %s\n",adap->name));
756
757 return 0;
758}
759
760
761int __init i2c_algo_iic_init (void)
762{
763 printk(KERN_INFO "ITE iic (i2c) algorithm module\n");
764 return 0;
765}
766
767
768void i2c_algo_iic_exit(void)
769{
770 return;
771}
772
773
774EXPORT_SYMBOL(i2c_iic_add_bus);
775EXPORT_SYMBOL(i2c_iic_del_bus);
776
777/* The MODULE_* macros resolve to nothing if MODULES is not defined
778 * when this file is compiled.
779 */
780MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
781MODULE_DESCRIPTION("ITE iic algorithm");
782MODULE_LICENSE("GPL");
783
784module_param(iic_test, bool, 0);
785module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
786
787MODULE_PARM_DESC(iic_test, "Test if the I2C bus is available");
788MODULE_PARM_DESC(i2c_debug,
789 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 iic-protocol");
790
791
792/* This function resolves to init_module (the function invoked when a module
793 * is loaded via insmod) when this file is compiled with MODULES defined.
794 * Otherwise (i.e. if you want this driver statically linked to the kernel),
795 * a pointer to this function is stored in a table and called
796 * during the initialization of the kernel (in do_basic_setup in /init/main.c)
797 *
798 * All this functionality is complements of the macros defined in linux/init.h
799 */
800module_init(i2c_algo_iic_init);
801
802
803/* If MODULES is defined when this file is compiled, then this function will
804 * resolved to cleanup_module.
805 */
806module_exit(i2c_algo_iic_exit);
diff --git a/drivers/i2c/algos/i2c-algo-ite.h b/drivers/i2c/algos/i2c-algo-ite.h
deleted file mode 100644
index a8ca3c9b546a..000000000000
--- a/drivers/i2c/algos/i2c-algo-ite.h
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 --------------------------------------------------------------------
3 i2c-ite.h: Global defines for the I2C controller on board the
4 ITE MIPS processor.
5 --------------------------------------------------------------------
6 Hai-Pao Fan, MontaVista Software, Inc.
7 hpfan@mvista.com or source@mvista.com
8
9 Copyright 2001 MontaVista Software Inc.
10
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
19 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 675 Mass Ave, Cambridge, MA 02139, USA.
30
31 */
32
33#ifndef I2C_ITE_H
34#define I2C_ITE_H 1
35
36#include <asm/it8172/it8172.h>
37
38/* I2C Registers */
39#define ITE_I2CHCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x30
40#define ITE_I2CHSR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x34
41#define ITE_I2CSAR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x38
42#define ITE_I2CSSAR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x3c
43#define ITE_I2CCKCNT IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x48
44#define ITE_I2CSHDR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x4c
45#define ITE_I2CRSUR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x50
46#define ITE_I2CPSUR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x54
47
48#define ITE_I2CFDR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x70
49#define ITE_I2CFBCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x74
50#define ITE_I2CFCR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x78
51#define ITE_I2CFSR IT8172_PCI_IO_BASE + IT_I2C_BASE + 0x7c
52
53
54/* Host Control Register ITE_I2CHCR */
55#define ITE_I2CHCR_HCE 0x01 /* Enable I2C Host Controller */
56#define ITE_I2CHCR_IE 0x02 /* Enable the interrupt after completing
57 the current transaction */
58#define ITE_I2CHCR_CP_W 0x00 /* bit2-4 000 - Write */
59#define ITE_I2CHCR_CP_R 0x08 /* 010 - Current address read */
60#define ITE_I2CHCR_CP_S 0x10 /* 100 - Sequential read */
61#define ITE_I2CHCR_ST 0x20 /* Initiates the I2C host controller to execute
62 the command and send the data programmed in
63 all required registers to I2C bus */
64#define ITE_CMD ITE_I2CHCR_HCE | ITE_I2CHCR_IE | ITE_I2CHCR_ST
65#define ITE_WRITE ITE_CMD | ITE_I2CHCR_CP_W
66#define ITE_READ ITE_CMD | ITE_I2CHCR_CP_R
67#define ITE_SREAD ITE_CMD | ITE_I2CHCR_CP_S
68
69/* Host Status Register ITE_I2CHSR */
70#define ITE_I2CHSR_DB 0x01 /* Device is busy, receives NACK response except
71 in the first and last bytes */
72#define ITE_I2CHSR_DNE 0x02 /* Target address on I2C bus does not exist */
73#define ITE_I2CHSR_TDI 0x04 /* R/W Transaction on I2C bus was completed */
74#define ITE_I2CHSR_HB 0x08 /* Host controller is processing transactions */
75#define ITE_I2CHSR_FER 0x10 /* Error occurs in the FIFO */
76
77/* Slave Address Register ITE_I2CSAR */
78#define ITE_I2CSAR_SA_MASK 0xfe /* Target I2C device address */
79#define ITE_I2CSAR_ASO 0x0100 /* Output 1/0 to I2CAS port when the
80 next slave address is addressed */
81
82/* Slave Sub-address Register ITE_I2CSSAR */
83#define ITE_I2CSSAR_SUBA_MASK 0xff /* Target I2C device sub-address */
84
85/* Clock Counter Register ITE_I2CCKCNT */
86#define ITE_I2CCKCNT_STOP 0x00 /* stop I2C clock */
87#define ITE_I2CCKCNT_HPCC_MASK 0x7f /* SCL high period counter */
88#define ITE_I2CCKCNT_LPCC_MASK 0x7f00 /* SCL low period counter */
89
90/* START Hold Time Register ITE_I2CSHDR */
91/* value is counted based on 16 MHz internal clock */
92#define ITE_I2CSHDR_FM 0x0a /* START condition at fast mode */
93#define ITE_I2CSHDR_SM 0x47 /* START contition at standard mode */
94
95/* (Repeated) START Setup Time Register ITE_I2CRSUR */
96/* value is counted based on 16 MHz internal clock */
97#define ITE_I2CRSUR_FM 0x0a /* repeated START condition at fast mode */
98#define ITE_I2CRSUR_SM 0x50 /* repeated START condition at standard mode */
99
100/* STOP setup Time Register ITE_I2CPSUR */
101
102/* FIFO Data Register ITE_I2CFDR */
103#define ITE_I2CFDR_MASK 0xff
104
105/* FIFO Byte Count Register ITE_I2CFBCR */
106#define ITE_I2CFBCR_MASK 0x3f
107
108/* FIFO Control Register ITE_I2CFCR */
109#define ITE_I2CFCR_FLUSH 0x01 /* Flush FIFO and reset the FIFO point
110 and I2CFSR */
111/* FIFO Status Register ITE_I2CFSR */
112#define ITE_I2CFSR_FO 0x01 /* FIFO is overrun when write */
113#define ITE_I2CFSR_FU 0x02 /* FIFO is underrun when read */
114#define ITE_I2CFSR_FF 0x04 /* FIFO is full when write */
115#define ITE_I2CFSR_FE 0x08 /* FIFO is empty when read */
116
117#endif /* I2C_ITE_H */
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 9081c9fbcd29..36fdf971f080 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -381,14 +381,7 @@ int i2c_pca_add_bus(struct i2c_adapter *adap)
381 381
382 return rval; 382 return rval;
383} 383}
384
385int i2c_pca_del_bus(struct i2c_adapter *adap)
386{
387 return i2c_del_adapter(adap);
388}
389
390EXPORT_SYMBOL(i2c_pca_add_bus); 384EXPORT_SYMBOL(i2c_pca_add_bus);
391EXPORT_SYMBOL(i2c_pca_del_bus);
392 385
393MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 386MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
394MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm"); 387MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm");
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 3b2003398966..ecb2c2d7d540 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -486,15 +486,7 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
486 486
487 return rval; 487 return rval;
488} 488}
489
490
491int i2c_pcf_del_bus(struct i2c_adapter *adap)
492{
493 return i2c_del_adapter(adap);
494}
495
496EXPORT_SYMBOL(i2c_pcf_add_bus); 489EXPORT_SYMBOL(i2c_pcf_add_bus);
497EXPORT_SYMBOL(i2c_pcf_del_bus);
498 490
499MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 491MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
500MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm"); 492MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm");
diff --git a/drivers/i2c/algos/i2c-algo-sgi.c b/drivers/i2c/algos/i2c-algo-sgi.c
index 490d99997fd0..ac2d5053078a 100644
--- a/drivers/i2c/algos/i2c-algo-sgi.c
+++ b/drivers/i2c/algos/i2c-algo-sgi.c
@@ -171,15 +171,7 @@ int i2c_sgi_add_bus(struct i2c_adapter *adap)
171 171
172 return i2c_add_adapter(adap); 172 return i2c_add_adapter(adap);
173} 173}
174
175
176int i2c_sgi_del_bus(struct i2c_adapter *adap)
177{
178 return i2c_del_adapter(adap);
179}
180
181EXPORT_SYMBOL(i2c_sgi_add_bus); 174EXPORT_SYMBOL(i2c_sgi_add_bus);
182EXPORT_SYMBOL(i2c_sgi_del_bus);
183 175
184MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>"); 176MODULE_AUTHOR("Ladislav Michl <ladis@linux-mips.org>");
185MODULE_DESCRIPTION("I2C-Bus SGI algorithm"); 177MODULE_DESCRIPTION("I2C-Bus SGI algorithm");
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 90f91d039ee2..e1989f3a2684 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -74,6 +74,13 @@ config I2C_AMD8111
74 This driver can also be built as a module. If so, the module 74 This driver can also be built as a module. If so, the module
75 will be called i2c-amd8111. 75 will be called i2c-amd8111.
76 76
77config I2C_AT91
78 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
79 depends on I2C && ARCH_AT91 && EXPERIMENTAL
80 help
81 This supports the use of the I2C interface on Atmel AT91
82 processors.
83
77config I2C_AU1550 84config I2C_AU1550
78 tristate "Au1550/Au1200 SMBus interface" 85 tristate "Au1550/Au1200 SMBus interface"
79 depends on I2C && (SOC_AU1550 || SOC_AU1200) 86 depends on I2C && (SOC_AU1550 || SOC_AU1200)
@@ -209,18 +216,6 @@ config I2C_ISA
209 tristate 216 tristate
210 depends on I2C 217 depends on I2C
211 218
212config I2C_ITE
213 tristate "ITE I2C Adapter"
214 depends on I2C && MIPS_ITE8172
215 select I2C_ALGOITE
216 help
217 This supports the ITE8172 I2C peripheral found on some MIPS
218 systems. Say Y if you have one of these. You should also say Y for
219 the ITE I2C driver algorithm support above.
220
221 This support is also available as a module. If so, the module
222 will be called i2c-ite.
223
224config I2C_IXP4XX 219config I2C_IXP4XX
225 tristate "IXP4xx GPIO-Based I2C Interface" 220 tristate "IXP4xx GPIO-Based I2C Interface"
226 depends on I2C && ARCH_IXP4XX 221 depends on I2C && ARCH_IXP4XX
@@ -481,6 +476,17 @@ config I2C_STUB
481 476
482 If you don't know what to do here, definitely say N. 477 If you don't know what to do here, definitely say N.
483 478
479config I2C_VERSATILE
480 tristate "ARM Versatile/Realview I2C bus support"
481 depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW)
482 select I2C_ALGOBIT
483 help
484 Say yes if you want to support the I2C serial bus on ARMs Versatile
485 range of platforms.
486
487 This driver can also be built as a module. If so, the module
488 will be called i2c-versatile.
489
484config I2C_VIA 490config I2C_VIA
485 tristate "VIA 82C586B" 491 tristate "VIA 82C586B"
486 depends on I2C && PCI && EXPERIMENTAL 492 depends on I2C && PCI && EXPERIMENTAL
@@ -548,4 +554,23 @@ config I2C_MV64XXX
548 This driver can also be built as a module. If so, the module 554 This driver can also be built as a module. If so, the module
549 will be called i2c-mv64xxx. 555 will be called i2c-mv64xxx.
550 556
557config I2C_PNX
558 tristate "I2C bus support for Philips PNX targets"
559 depends on ARCH_PNX4008 && I2C
560 help
561 This driver supports the Philips IP3204 I2C IP block master and/or
562 slave controller
563
564 This driver can also be built as a module. If so, the module
565 will be called i2c-pnx.
566
567config I2C_PNX_EARLY
568 bool "Early initialization for I2C on PNXxxxx"
569 depends on I2C_PNX=y
570 help
571 Under certain circumstances one may need to make sure I2C on PNXxxxx
572 is initialized earlier than some other driver that depends on it
573 (for instance, that might be USB in case of PNX4008). With this
574 option turned on you can guarantee that.
575
551endmenu 576endmenu
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 493c87289b62..37196c1d0794 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -8,6 +8,7 @@ obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o
8obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o 8obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o
9obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o 9obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o
10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
11obj-$(CONFIG_I2C_AT91) += i2c-at91.o
11obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
12obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 13obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
13obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o 14obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
@@ -16,7 +17,6 @@ obj-$(CONFIG_I2C_I810) += i2c-i810.o
16obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 17obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
17obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 18obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
18obj-$(CONFIG_I2C_ISA) += i2c-isa.o 19obj-$(CONFIG_I2C_ISA) += i2c-isa.o
19obj-$(CONFIG_I2C_ITE) += i2c-ite.o
20obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 20obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
21obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o 21obj-$(CONFIG_I2C_IXP4XX) += i2c-ixp4xx.o
22obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o 22obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
@@ -29,6 +29,7 @@ obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
29obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 29obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
30obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 30obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
31obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o 31obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
32obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
32obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o 33obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o
33obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 34obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
34obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o 35obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
@@ -39,6 +40,7 @@ obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
39obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 40obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
40obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 41obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
41obj-$(CONFIG_I2C_STUB) += i2c-stub.o 42obj-$(CONFIG_I2C_STUB) += i2c-stub.o
43obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
42obj-$(CONFIG_I2C_VIA) += i2c-via.o 44obj-$(CONFIG_I2C_VIA) += i2c-via.o
43obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o 45obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
44obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o 46obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
new file mode 100644
index 000000000000..67f91bdda089
--- /dev/null
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -0,0 +1,325 @@
1/*
2 i2c Support for Atmel's AT91 Two-Wire Interface (TWI)
3
4 Copyright (C) 2004 Rick Bronson
5 Converted to 2.6 by Andrew Victor <andrew@sanpeople.com>
6
7 Borrowed heavily from original work by:
8 Copyright (C) 2000 Philip Edelbrock <phil@stimpy.netroedge.com>
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 as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14*/
15
16#include <linux/module.h>
17#include <linux/version.h>
18#include <linux/kernel.h>
19#include <linux/slab.h>
20#include <linux/pci.h>
21#include <linux/types.h>
22#include <linux/delay.h>
23#include <linux/i2c.h>
24#include <linux/init.h>
25#include <linux/clk.h>
26#include <linux/platform_device.h>
27
28#include <asm/io.h>
29
30#include <asm/arch/at91_twi.h>
31#include <asm/arch/board.h>
32#include <asm/arch/cpu.h>
33
34#define TWI_CLOCK 100000 /* Hz. max 400 Kbits/sec */
35
36
37static struct clk *twi_clk;
38static void __iomem *twi_base;
39
40#define at91_twi_read(reg) __raw_readl(twi_base + (reg))
41#define at91_twi_write(reg, val) __raw_writel((val), twi_base + (reg))
42
43
44/*
45 * Initialize the TWI hardware registers.
46 */
47static void __devinit at91_twi_hwinit(void)
48{
49 unsigned long cdiv, ckdiv;
50
51 at91_twi_write(AT91_TWI_IDR, 0xffffffff); /* Disable all interrupts */
52 at91_twi_write(AT91_TWI_CR, AT91_TWI_SWRST); /* Reset peripheral */
53 at91_twi_write(AT91_TWI_CR, AT91_TWI_MSEN); /* Set Master mode */
54
55 /* Calcuate clock dividers */
56 cdiv = (clk_get_rate(twi_clk) / (2 * TWI_CLOCK)) - 3;
57 cdiv = cdiv + 1; /* round up */
58 ckdiv = 0;
59 while (cdiv > 255) {
60 ckdiv++;
61 cdiv = cdiv >> 1;
62 }
63
64 if (cpu_is_at91rm9200()) { /* AT91RM9200 Errata #22 */
65 if (ckdiv > 5) {
66 printk(KERN_ERR "AT91 I2C: Invalid TWI_CLOCK value!\n");
67 ckdiv = 5;
68 }
69 }
70
71 at91_twi_write(AT91_TWI_CWGR, (ckdiv << 16) | (cdiv << 8) | cdiv);
72}
73
74/*
75 * Poll the i2c status register until the specified bit is set.
76 * Returns 0 if timed out (100 msec).
77 */
78static short at91_poll_status(unsigned long bit)
79{
80 int loop_cntr = 10000;
81
82 do {
83 udelay(10);
84 } while (!(at91_twi_read(AT91_TWI_SR) & bit) && (--loop_cntr > 0));
85
86 return (loop_cntr > 0);
87}
88
89static int xfer_read(struct i2c_adapter *adap, unsigned char *buf, int length)
90{
91 /* Send Start */
92 at91_twi_write(AT91_TWI_CR, AT91_TWI_START);
93
94 /* Read data */
95 while (length--) {
96 if (!length) /* need to send Stop before reading last byte */
97 at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP);
98 if (!at91_poll_status(AT91_TWI_RXRDY)) {
99 dev_dbg(&adap->dev, "RXRDY timeout\n");
100 return -ETIMEDOUT;
101 }
102 *buf++ = (at91_twi_read(AT91_TWI_RHR) & 0xff);
103 }
104
105 return 0;
106}
107
108static int xfer_write(struct i2c_adapter *adap, unsigned char *buf, int length)
109{
110 /* Load first byte into transmitter */
111 at91_twi_write(AT91_TWI_THR, *buf++);
112
113 /* Send Start */
114 at91_twi_write(AT91_TWI_CR, AT91_TWI_START);
115
116 do {
117 if (!at91_poll_status(AT91_TWI_TXRDY)) {
118 dev_dbg(&adap->dev, "TXRDY timeout\n");
119 return -ETIMEDOUT;
120 }
121
122 length--; /* byte was transmitted */
123
124 if (length > 0) /* more data to send? */
125 at91_twi_write(AT91_TWI_THR, *buf++);
126 } while (length);
127
128 /* Send Stop */
129 at91_twi_write(AT91_TWI_CR, AT91_TWI_STOP);
130
131 return 0;
132}
133
134/*
135 * Generic i2c master transfer entrypoint.
136 *
137 * Note: We do not use Atmel's feature of storing the "internal device address".
138 * Instead the "internal device address" has to be written using a seperate
139 * i2c message.
140 * http://lists.arm.linux.org.uk/pipermail/linux-arm-kernel/2004-September/024411.html
141 */
142static int at91_xfer(struct i2c_adapter *adap, struct i2c_msg *pmsg, int num)
143{
144 int i, ret;
145
146 dev_dbg(&adap->dev, "at91_xfer: processing %d messages:\n", num);
147
148 for (i = 0; i < num; i++) {
149 dev_dbg(&adap->dev, " #%d: %sing %d byte%s %s 0x%02x\n", i,
150 pmsg->flags & I2C_M_RD ? "read" : "writ",
151 pmsg->len, pmsg->len > 1 ? "s" : "",
152 pmsg->flags & I2C_M_RD ? "from" : "to", pmsg->addr);
153
154 at91_twi_write(AT91_TWI_MMR, (pmsg->addr << 16)
155 | ((pmsg->flags & I2C_M_RD) ? AT91_TWI_MREAD : 0));
156
157 if (pmsg->len && pmsg->buf) { /* sanity check */
158 if (pmsg->flags & I2C_M_RD)
159 ret = xfer_read(adap, pmsg->buf, pmsg->len);
160 else
161 ret = xfer_write(adap, pmsg->buf, pmsg->len);
162
163 if (ret)
164 return ret;
165
166 /* Wait until transfer is finished */
167 if (!at91_poll_status(AT91_TWI_TXCOMP)) {
168 dev_dbg(&adap->dev, "TXCOMP timeout\n");
169 return -ETIMEDOUT;
170 }
171 }
172 dev_dbg(&adap->dev, "transfer complete\n");
173 pmsg++; /* next message */
174 }
175 return i;
176}
177
178/*
179 * Return list of supported functionality.
180 */
181static u32 at91_func(struct i2c_adapter *adapter)
182{
183 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
184}
185
186static struct i2c_algorithm at91_algorithm = {
187 .master_xfer = at91_xfer,
188 .functionality = at91_func,
189};
190
191/*
192 * Main initialization routine.
193 */
194static int __devinit at91_i2c_probe(struct platform_device *pdev)
195{
196 struct i2c_adapter *adapter;
197 struct resource *res;
198 int rc;
199
200 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
201 if (!res)
202 return -ENXIO;
203
204 if (!request_mem_region(res->start, res->end - res->start + 1, "at91_i2c"))
205 return -EBUSY;
206
207 twi_base = ioremap(res->start, res->end - res->start + 1);
208 if (!twi_base) {
209 rc = -ENOMEM;
210 goto fail0;
211 }
212
213 twi_clk = clk_get(NULL, "twi_clk");
214 if (IS_ERR(twi_clk)) {
215 dev_err(&pdev->dev, "no clock defined\n");
216 rc = -ENODEV;
217 goto fail1;
218 }
219
220 adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
221 if (adapter == NULL) {
222 dev_err(&pdev->dev, "can't allocate inteface!\n");
223 rc = -ENOMEM;
224 goto fail2;
225 }
226 sprintf(adapter->name, "AT91");
227 adapter->algo = &at91_algorithm;
228 adapter->class = I2C_CLASS_HWMON;
229 adapter->dev.parent = &pdev->dev;
230
231 platform_set_drvdata(pdev, adapter);
232
233 clk_enable(twi_clk); /* enable peripheral clock */
234 at91_twi_hwinit(); /* initialize TWI controller */
235
236 rc = i2c_add_adapter(adapter);
237 if (rc) {
238 dev_err(&pdev->dev, "Adapter %s registration failed\n",
239 adapter->name);
240 goto fail3;
241 }
242
243 dev_info(&pdev->dev, "AT91 i2c bus driver.\n");
244 return 0;
245
246fail3:
247 platform_set_drvdata(pdev, NULL);
248 kfree(adapter);
249 clk_disable(twi_clk);
250fail2:
251 clk_put(twi_clk);
252fail1:
253 iounmap(twi_base);
254fail0:
255 release_mem_region(res->start, res->end - res->start + 1);
256
257 return rc;
258}
259
260static int __devexit at91_i2c_remove(struct platform_device *pdev)
261{
262 struct i2c_adapter *adapter = platform_get_drvdata(pdev);
263 struct resource *res;
264 int rc;
265
266 rc = i2c_del_adapter(adapter);
267 platform_set_drvdata(pdev, NULL);
268
269 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
270 iounmap(twi_base);
271 release_mem_region(res->start, res->end - res->start + 1);
272
273 clk_disable(twi_clk); /* disable peripheral clock */
274 clk_put(twi_clk);
275
276 return rc;
277}
278
279#ifdef CONFIG_PM
280
281/* NOTE: could save a few mA by keeping clock off outside of at91_xfer... */
282
283static int at91_i2c_suspend(struct platform_device *pdev, pm_message_t mesg)
284{
285 clk_disable(twi_clk);
286 return 0;
287}
288
289static int at91_i2c_resume(struct platform_device *pdev)
290{
291 return clk_enable(twi_clk);
292}
293
294#else
295#define at91_i2c_suspend NULL
296#define at91_i2c_resume NULL
297#endif
298
299static struct platform_driver at91_i2c_driver = {
300 .probe = at91_i2c_probe,
301 .remove = __devexit_p(at91_i2c_remove),
302 .suspend = at91_i2c_suspend,
303 .resume = at91_i2c_resume,
304 .driver = {
305 .name = "at91_i2c",
306 .owner = THIS_MODULE,
307 },
308};
309
310static int __init at91_i2c_init(void)
311{
312 return platform_driver_register(&at91_i2c_driver);
313}
314
315static void __exit at91_i2c_exit(void)
316{
317 platform_driver_unregister(&at91_i2c_driver);
318}
319
320module_init(at91_i2c_init);
321module_exit(at91_i2c_exit);
322
323MODULE_AUTHOR("Rick Bronson");
324MODULE_DESCRIPTION("I2C (TWI) driver for Atmel AT91");
325MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index a591fe685f06..834967464814 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -293,7 +293,7 @@ static int __init i2c_pcfisa_init(void)
293 293
294static void i2c_pcfisa_exit(void) 294static void i2c_pcfisa_exit(void)
295{ 295{
296 i2c_pcf_del_bus(&pcf_isa_ops); 296 i2c_del_adapter(&pcf_isa_ops);
297 297
298 if (irq > 0) { 298 if (irq > 0) {
299 disable_irq(irq); 299 disable_irq(irq);
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index 457d48a0ab9d..9832f773651d 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -146,7 +146,7 @@ static int __devinit hydra_probe(struct pci_dev *dev,
146static void __devexit hydra_remove(struct pci_dev *dev) 146static void __devexit hydra_remove(struct pci_dev *dev)
147{ 147{
148 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */ 148 pdregw(hydra_bit_data.data, 0); /* clear SCLK_OE and SDAT_OE */
149 i2c_bit_del_bus(&hydra_adap); 149 i2c_del_adapter(&hydra_adap);
150 iounmap(hydra_bit_data.data); 150 iounmap(hydra_bit_data.data);
151 release_mem_region(pci_resource_start(dev, 0)+ 151 release_mem_region(pci_resource_start(dev, 0)+
152 offsetof(struct Hydra, CachePD), 4); 152 offsetof(struct Hydra, CachePD), 4);
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index c7be2fdbd86b..ae625b854470 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -470,12 +470,20 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
470 int err; 470 int err;
471 471
472 I801_dev = dev; 472 I801_dev = dev;
473 if ((dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) || 473 switch (dev->device) {
474 (dev->device == PCI_DEVICE_ID_INTEL_82801EB_3) || 474 case PCI_DEVICE_ID_INTEL_82801DB_3:
475 (dev->device == PCI_DEVICE_ID_INTEL_ESB_4)) 475 case PCI_DEVICE_ID_INTEL_82801EB_3:
476 case PCI_DEVICE_ID_INTEL_ESB_4:
477 case PCI_DEVICE_ID_INTEL_ICH6_16:
478 case PCI_DEVICE_ID_INTEL_ICH7_17:
479 case PCI_DEVICE_ID_INTEL_ESB2_17:
480 case PCI_DEVICE_ID_INTEL_ICH8_5:
481 case PCI_DEVICE_ID_INTEL_ICH9_6:
476 isich4 = 1; 482 isich4 = 1;
477 else 483 break;
484 default:
478 isich4 = 0; 485 isich4 = 0;
486 }
479 487
480 err = pci_enable_device(dev); 488 err = pci_enable_device(dev);
481 if (err) { 489 if (err) {
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index b66fb6bb1870..10c98bc88aa6 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -219,14 +219,14 @@ static int __devinit i810_probe(struct pci_dev *dev, const struct pci_device_id
219 return retval; 219 return retval;
220 retval = i2c_bit_add_bus(&i810_ddc_adapter); 220 retval = i2c_bit_add_bus(&i810_ddc_adapter);
221 if (retval) 221 if (retval)
222 i2c_bit_del_bus(&i810_i2c_adapter); 222 i2c_del_adapter(&i810_i2c_adapter);
223 return retval; 223 return retval;
224} 224}
225 225
226static void __devexit i810_remove(struct pci_dev *dev) 226static void __devexit i810_remove(struct pci_dev *dev)
227{ 227{
228 i2c_bit_del_bus(&i810_ddc_adapter); 228 i2c_del_adapter(&i810_ddc_adapter);
229 i2c_bit_del_bus(&i810_i2c_adapter); 229 i2c_del_adapter(&i810_i2c_adapter);
230 iounmap(ioaddr); 230 iounmap(ioaddr);
231} 231}
232 232
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 781a99c1647a..1898e9987021 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -680,6 +680,12 @@ static int __devinit iic_probe(struct ocp_device *ocp){
680 dev->idx = ocp->def->index; 680 dev->idx = ocp->def->index;
681 ocp_set_drvdata(ocp, dev); 681 ocp_set_drvdata(ocp, dev);
682 682
683 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs),
684 "ibm_iic")) {
685 ret = -EBUSY;
686 goto fail1;
687 }
688
683 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){ 689 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){
684 printk(KERN_CRIT "ibm-iic%d: failed to ioremap device registers\n", 690 printk(KERN_CRIT "ibm-iic%d: failed to ioremap device registers\n",
685 dev->idx); 691 dev->idx);
@@ -750,6 +756,8 @@ fail:
750 756
751 iounmap(dev->vaddr); 757 iounmap(dev->vaddr);
752fail2: 758fail2:
759 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
760fail1:
753 ocp_set_drvdata(ocp, NULL); 761 ocp_set_drvdata(ocp, NULL);
754 kfree(dev); 762 kfree(dev);
755 return ret; 763 return ret;
@@ -777,6 +785,7 @@ static void __devexit iic_remove(struct ocp_device *ocp)
777 free_irq(dev->irq, dev); 785 free_irq(dev->irq, dev);
778 } 786 }
779 iounmap(dev->vaddr); 787 iounmap(dev->vaddr);
788 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
780 kfree(dev); 789 kfree(dev);
781 } 790 }
782} 791}
diff --git a/drivers/i2c/busses/i2c-ite.c b/drivers/i2c/busses/i2c-ite.c
deleted file mode 100644
index f7d71869b3b9..000000000000
--- a/drivers/i2c/busses/i2c-ite.c
+++ /dev/null
@@ -1,278 +0,0 @@
1/*
2 -------------------------------------------------------------------------
3 i2c-adap-ite.c i2c-hw access for the IIC peripheral on the ITE MIPS system
4 -------------------------------------------------------------------------
5 Hai-Pao Fan, MontaVista Software, Inc.
6 hpfan@mvista.com or source@mvista.com
7
8 Copyright 2001 MontaVista Software Inc.
9
10 ----------------------------------------------------------------------------
11 This file was highly leveraged from i2c-elektor.c, which was created
12 by Simon G. Vogl and Hans Berglund:
13
14
15 Copyright (C) 1995-97 Simon G. Vogl
16 1998-99 Hans Berglund
17
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 2 of the License, or
21 (at your option) any later version.
22
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
27
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
31/* ------------------------------------------------------------------------- */
32
33/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
34 Frodo Looijaard <frodol@dds.nl> */
35
36#include <linux/kernel.h>
37#include <linux/ioport.h>
38#include <linux/module.h>
39#include <linux/delay.h>
40#include <linux/slab.h>
41#include <linux/init.h>
42#include <linux/wait.h>
43#include <asm/irq.h>
44#include <asm/io.h>
45
46#include <linux/i2c.h>
47#include <linux/i2c-algo-ite.h>
48#include <linux/i2c-adap-ite.h>
49#include "../i2c-ite.h"
50
51#define DEFAULT_BASE 0x14014030
52#define ITE_IIC_IO_SIZE 0x40
53#define DEFAULT_IRQ 0
54#define DEFAULT_CLOCK 0x1b0e /* default 16MHz/(27+14) = 400KHz */
55#define DEFAULT_OWN 0x55
56
57static int base;
58static int irq;
59static int clock;
60static int own;
61
62static struct iic_ite gpi;
63static wait_queue_head_t iic_wait;
64static int iic_pending;
65static spinlock_t lock;
66
67/* ----- local functions ---------------------------------------------- */
68
69static void iic_ite_setiic(void *data, int ctl, short val)
70{
71 unsigned long j = jiffies + 10;
72
73 pr_debug(" Write 0x%02x to 0x%x\n",(unsigned short)val, ctl&0xff);
74#ifdef DEBUG
75 while (time_before(jiffies, j))
76 schedule();
77#endif
78 outw(val,ctl);
79}
80
81static short iic_ite_getiic(void *data, int ctl)
82{
83 short val;
84
85 val = inw(ctl);
86 pr_debug("Read 0x%02x from 0x%x\n",(unsigned short)val, ctl&0xff);
87 return (val);
88}
89
90/* Return our slave address. This is the address
91 * put on the I2C bus when another master on the bus wants to address us
92 * as a slave
93 */
94static int iic_ite_getown(void *data)
95{
96 return (gpi.iic_own);
97}
98
99
100static int iic_ite_getclock(void *data)
101{
102 return (gpi.iic_clock);
103}
104
105
106/* Put this process to sleep. We will wake up when the
107 * IIC controller interrupts.
108 */
109static void iic_ite_waitforpin(void) {
110 DEFINE_WAIT(wait);
111 int timeout = 2;
112 unsigned long flags;
113
114 /* If interrupts are enabled (which they are), then put the process to
115 * sleep. This process will be awakened by two events -- either the
116 * the IIC peripheral interrupts or the timeout expires.
117 * If interrupts are not enabled then delay for a reasonable amount
118 * of time and return.
119 */
120 if (gpi.iic_irq > 0) {
121 spin_lock_irqsave(&lock, flags);
122 if (iic_pending == 0) {
123 spin_unlock_irqrestore(&lock, flags);
124 prepare_to_wait(&iic_wait, &wait, TASK_INTERRUPTIBLE);
125 if (schedule_timeout(timeout*HZ)) {
126 spin_lock_irqsave(&lock, flags);
127 if (iic_pending == 1) {
128 iic_pending = 0;
129 }
130 spin_unlock_irqrestore(&lock, flags);
131 }
132 finish_wait(&iic_wait, &wait);
133 } else {
134 iic_pending = 0;
135 spin_unlock_irqrestore(&lock, flags);
136 }
137 } else {
138 udelay(100);
139 }
140}
141
142
143static irqreturn_t iic_ite_handler(int this_irq, void *dev_id)
144{
145 spin_lock(&lock);
146 iic_pending = 1;
147 spin_unlock(&lock);
148
149 wake_up_interruptible(&iic_wait);
150
151 return IRQ_HANDLED;
152}
153
154
155/* Lock the region of memory where I/O registers exist. Request our
156 * interrupt line and register its associated handler.
157 */
158static int iic_hw_resrc_init(void)
159{
160 if (!request_region(gpi.iic_base, ITE_IIC_IO_SIZE, "i2c"))
161 return -ENODEV;
162
163 if (gpi.iic_irq <= 0)
164 return 0;
165
166 if (request_irq(gpi.iic_irq, iic_ite_handler, 0, "ITE IIC", 0) < 0)
167 gpi.iic_irq = 0;
168 else
169 enable_irq(gpi.iic_irq);
170
171 return 0;
172}
173
174
175static void iic_ite_release(void)
176{
177 if (gpi.iic_irq > 0) {
178 disable_irq(gpi.iic_irq);
179 free_irq(gpi.iic_irq, 0);
180 }
181 release_region(gpi.iic_base , 2);
182}
183
184/* ------------------------------------------------------------------------
185 * Encapsulate the above functions in the correct operations structure.
186 * This is only done when more than one hardware adapter is supported.
187 */
188static struct i2c_algo_iic_data iic_ite_data = {
189 NULL,
190 iic_ite_setiic,
191 iic_ite_getiic,
192 iic_ite_getown,
193 iic_ite_getclock,
194 iic_ite_waitforpin,
195 80, 80, 100, /* waits, timeout */
196};
197
198static struct i2c_adapter iic_ite_ops = {
199 .owner = THIS_MODULE,
200 .id = I2C_HW_I_IIC,
201 .algo_data = &iic_ite_data,
202 .name = "ITE IIC adapter",
203};
204
205/* Called when the module is loaded. This function starts the
206 * cascade of calls up through the hierarchy of i2c modules (i.e. up to the
207 * algorithm layer and into to the core layer)
208 */
209static int __init iic_ite_init(void)
210{
211
212 struct iic_ite *piic = &gpi;
213
214 printk(KERN_INFO "Initialize ITE IIC adapter module\n");
215 if (base == 0)
216 piic->iic_base = DEFAULT_BASE;
217 else
218 piic->iic_base = base;
219
220 if (irq == 0)
221 piic->iic_irq = DEFAULT_IRQ;
222 else
223 piic->iic_irq = irq;
224
225 if (clock == 0)
226 piic->iic_clock = DEFAULT_CLOCK;
227 else
228 piic->iic_clock = clock;
229
230 if (own == 0)
231 piic->iic_own = DEFAULT_OWN;
232 else
233 piic->iic_own = own;
234
235 iic_ite_data.data = (void *)piic;
236 init_waitqueue_head(&iic_wait);
237 spin_lock_init(&lock);
238 if (iic_hw_resrc_init() == 0) {
239 if (i2c_iic_add_bus(&iic_ite_ops) < 0)
240 return -ENODEV;
241 } else {
242 return -ENODEV;
243 }
244 printk(KERN_INFO " found device at %#x irq %d.\n",
245 piic->iic_base, piic->iic_irq);
246 return 0;
247}
248
249
250static void iic_ite_exit(void)
251{
252 i2c_iic_del_bus(&iic_ite_ops);
253 iic_ite_release();
254}
255
256/* If modules is NOT defined when this file is compiled, then the MODULE_*
257 * macros will resolve to nothing
258 */
259MODULE_AUTHOR("MontaVista Software <www.mvista.com>");
260MODULE_DESCRIPTION("I2C-Bus adapter routines for ITE IIC bus adapter");
261MODULE_LICENSE("GPL");
262
263module_param(base, int, 0);
264module_param(irq, int, 0);
265module_param(clock, int, 0);
266module_param(own, int, 0);
267
268
269/* Called when module is loaded or when kernel is initialized.
270 * If MODULES is defined when this file is compiled, then this function will
271 * resolve to init_module (the function called when insmod is invoked for a
272 * module). Otherwise, this function is called early in the boot, when the
273 * kernel is intialized. Check out /include/init.h to see how this works.
274 */
275module_init(iic_ite_init);
276
277/* Resolves to module_cleanup when MODULES is defined. */
278module_exit(iic_ite_exit);
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index dd3f4cd3aa68..efa3ecc5522a 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -90,7 +90,7 @@ static int ixp2000_i2c_remove(struct platform_device *plat_dev)
90 90
91 platform_set_drvdata(plat_dev, NULL); 91 platform_set_drvdata(plat_dev, NULL);
92 92
93 i2c_bit_del_bus(&drv_data->adapter); 93 i2c_del_adapter(&drv_data->adapter);
94 94
95 kfree(drv_data); 95 kfree(drv_data);
96 96
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 68fe863f9d54..08e89b83984a 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -91,7 +91,7 @@ static int ixp4xx_i2c_remove(struct platform_device *plat_dev)
91 91
92 platform_set_drvdata(plat_dev, NULL); 92 platform_set_drvdata(plat_dev, NULL);
93 93
94 i2c_bit_del_bus(&drv_data->adapter); 94 i2c_del_adapter(&drv_data->adapter);
95 95
96 kfree(drv_data); 96 kfree(drv_data);
97 97
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index e0292e414ab2..ad37c10e7fec 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -35,7 +35,7 @@
35 nForce4 MCP55 0368 35 nForce4 MCP55 0368
36 36
37 This driver supports the 2 SMBuses that are included in the MCP of the 37 This driver supports the 2 SMBuses that are included in the MCP of the
38 nForce2/3/4 chipsets. 38 nForce2/3/4/5xx chipsets.
39*/ 39*/
40 40
41/* Note: we assume there can only be one nForce2, with two SMBus interfaces */ 41/* Note: we assume there can only be one nForce2, with two SMBus interfaces */
@@ -52,8 +52,8 @@
52#include <asm/io.h> 52#include <asm/io.h>
53 53
54MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
55MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@arcor.de>"); 55MODULE_AUTHOR ("Hans-Frieder Vogt <hfvogt@gmx.net>");
56MODULE_DESCRIPTION("nForce2 SMBus driver"); 56MODULE_DESCRIPTION("nForce2/3/4/5xx SMBus driver");
57 57
58 58
59struct nforce2_smbus { 59struct nforce2_smbus {
@@ -80,9 +80,6 @@ struct nforce2_smbus {
80#define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */ 80#define NVIDIA_SMB_ADDR (smbus->base + 0x02) /* address */
81#define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */ 81#define NVIDIA_SMB_CMD (smbus->base + 0x03) /* command */
82#define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */ 82#define NVIDIA_SMB_DATA (smbus->base + 0x04) /* 32 data registers */
83#define NVIDIA_SMB_BCNT (smbus->base + 0x24) /* number of data bytes */
84#define NVIDIA_SMB_ALRM_A (smbus->base + 0x25) /* alarm address */
85#define NVIDIA_SMB_ALRM_D (smbus->base + 0x26) /* 2 bytes alarm data */
86 83
87#define NVIDIA_SMB_STS_DONE 0x80 84#define NVIDIA_SMB_STS_DONE 0x80
88#define NVIDIA_SMB_STS_ALRM 0x40 85#define NVIDIA_SMB_STS_ALRM 0x40
@@ -95,40 +92,17 @@ struct nforce2_smbus {
95#define NVIDIA_SMB_PRTCL_BYTE 0x04 92#define NVIDIA_SMB_PRTCL_BYTE 0x04
96#define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06 93#define NVIDIA_SMB_PRTCL_BYTE_DATA 0x06
97#define NVIDIA_SMB_PRTCL_WORD_DATA 0x08 94#define NVIDIA_SMB_PRTCL_WORD_DATA 0x08
98#define NVIDIA_SMB_PRTCL_BLOCK_DATA 0x0a
99#define NVIDIA_SMB_PRTCL_PROC_CALL 0x0c
100#define NVIDIA_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
101#define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
102#define NVIDIA_SMB_PRTCL_PEC 0x80 95#define NVIDIA_SMB_PRTCL_PEC 0x80
103 96
104static struct pci_driver nforce2_driver; 97static struct pci_driver nforce2_driver;
105 98
106static s32 nforce2_access(struct i2c_adapter *adap, u16 addr, 99/* Return -1 on error */
107 unsigned short flags, char read_write,
108 u8 command, int size, union i2c_smbus_data *data);
109static u32 nforce2_func(struct i2c_adapter *adapter);
110
111
112static const struct i2c_algorithm smbus_algorithm = {
113 .smbus_xfer = nforce2_access,
114 .functionality = nforce2_func,
115};
116
117static struct i2c_adapter nforce2_adapter = {
118 .owner = THIS_MODULE,
119 .class = I2C_CLASS_HWMON,
120 .algo = &smbus_algorithm,
121};
122
123/* Return -1 on error. See smbus.h for more information */
124static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, 100static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
125 unsigned short flags, char read_write, 101 unsigned short flags, char read_write,
126 u8 command, int size, union i2c_smbus_data * data) 102 u8 command, int size, union i2c_smbus_data * data)
127{ 103{
128 struct nforce2_smbus *smbus = adap->algo_data; 104 struct nforce2_smbus *smbus = adap->algo_data;
129 unsigned char protocol, pec, temp; 105 unsigned char protocol, pec, temp;
130 unsigned char len = 0; /* to keep the compiler quiet */
131 int i;
132 106
133 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 107 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
134 NVIDIA_SMB_PRTCL_WRITE; 108 NVIDIA_SMB_PRTCL_WRITE;
@@ -163,35 +137,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
163 protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec; 137 protocol |= NVIDIA_SMB_PRTCL_WORD_DATA | pec;
164 break; 138 break;
165 139
166 case I2C_SMBUS_BLOCK_DATA:
167 outb_p(command, NVIDIA_SMB_CMD);
168 if (read_write == I2C_SMBUS_WRITE) {
169 len = min_t(u8, data->block[0], 32);
170 outb_p(len, NVIDIA_SMB_BCNT);
171 for (i = 0; i < len; i++)
172 outb_p(data->block[i + 1], NVIDIA_SMB_DATA+i);
173 }
174 protocol |= NVIDIA_SMB_PRTCL_BLOCK_DATA | pec;
175 break;
176
177 case I2C_SMBUS_I2C_BLOCK_DATA:
178 len = min_t(u8, data->block[0], 32);
179 outb_p(command, NVIDIA_SMB_CMD);
180 outb_p(len, NVIDIA_SMB_BCNT);
181 if (read_write == I2C_SMBUS_WRITE)
182 for (i = 0; i < len; i++)
183 outb_p(data->block[i + 1], NVIDIA_SMB_DATA+i);
184 protocol |= NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA;
185 break;
186
187 case I2C_SMBUS_PROC_CALL:
188 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
189 return -1;
190
191 case I2C_SMBUS_BLOCK_PROC_CALL:
192 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n");
193 return -1;
194
195 default: 140 default:
196 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 141 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
197 return -1; 142 return -1;
@@ -227,19 +172,8 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
227 break; 172 break;
228 173
229 case I2C_SMBUS_WORD_DATA: 174 case I2C_SMBUS_WORD_DATA:
230 /* case I2C_SMBUS_PROC_CALL: not supported */
231 data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8); 175 data->word = inb_p(NVIDIA_SMB_DATA) | (inb_p(NVIDIA_SMB_DATA+1) << 8);
232 break; 176 break;
233
234 case I2C_SMBUS_BLOCK_DATA:
235 /* case I2C_SMBUS_BLOCK_PROC_CALL: not supported */
236 len = inb_p(NVIDIA_SMB_BCNT);
237 len = min_t(u8, len, 32);
238 case I2C_SMBUS_I2C_BLOCK_DATA:
239 for (i = 0; i < len; i++)
240 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i);
241 data->block[0] = len;
242 break;
243 } 177 }
244 178
245 return 0; 179 return 0;
@@ -250,10 +184,14 @@ static u32 nforce2_func(struct i2c_adapter *adapter)
250{ 184{
251 /* other functionality might be possible, but is not tested */ 185 /* other functionality might be possible, but is not tested */
252 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 186 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
253 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA /* | 187 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA;
254 I2C_FUNC_SMBUS_BLOCK_DATA */;
255} 188}
256 189
190static struct i2c_algorithm smbus_algorithm = {
191 .smbus_xfer = nforce2_access,
192 .functionality = nforce2_func,
193};
194
257 195
258static struct pci_device_id nforce2_ids[] = { 196static struct pci_device_id nforce2_ids[] = {
259 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) }, 197 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2_SMBUS) },
@@ -267,7 +205,6 @@ static struct pci_device_id nforce2_ids[] = {
267 { 0 } 205 { 0 }
268}; 206};
269 207
270
271MODULE_DEVICE_TABLE (pci, nforce2_ids); 208MODULE_DEVICE_TABLE (pci, nforce2_ids);
272 209
273 210
@@ -291,7 +228,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
291 } 228 }
292 229
293 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; 230 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK;
294 smbus->size = 8; 231 smbus->size = 64;
295 } 232 }
296 smbus->dev = dev; 233 smbus->dev = dev;
297 234
@@ -300,7 +237,9 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
300 smbus->base, smbus->base+smbus->size-1, name); 237 smbus->base, smbus->base+smbus->size-1, name);
301 return -1; 238 return -1;
302 } 239 }
303 smbus->adapter = nforce2_adapter; 240 smbus->adapter.owner = THIS_MODULE;
241 smbus->adapter.class = I2C_CLASS_HWMON;
242 smbus->adapter.algo = &smbus_algorithm;
304 smbus->adapter.algo_data = smbus; 243 smbus->adapter.algo_data = smbus;
305 smbus->adapter.dev.parent = &dev->dev; 244 smbus->adapter.dev.parent = &dev->dev;
306 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 245 snprintf(smbus->adapter.name, I2C_NAME_SIZE,
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index dec04da0455c..bcd8367cede1 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -231,8 +231,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
231 * 13 2 1 231 * 13 2 1
232 * 19.2 2 1 232 * 19.2 2 1
233 */ 233 */
234 if (fclk_rate > 16000000) 234 if (fclk_rate > 12000000)
235 psc = (fclk_rate + 8000000) / 12000000; 235 psc = fclk_rate / 12000000;
236 } 236 }
237 237
238 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */ 238 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 5eb2bd294fd9..4bc42810b9aa 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -163,7 +163,7 @@ static void __exit i2c_parport_exit(void)
163 if (adapter_parm[type].init.val) 163 if (adapter_parm[type].init.val)
164 line_set(0, &adapter_parm[type].init); 164 line_set(0, &adapter_parm[type].init);
165 165
166 i2c_bit_del_bus(&parport_adapter); 166 i2c_del_adapter(&parport_adapter);
167 release_region(base, 3); 167 release_region(base, 3);
168} 168}
169 169
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 48a829431c7b..66696a40c7b5 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -218,7 +218,7 @@ static void i2c_parport_detach (struct parport *port)
218 if (adapter_parm[type].init.val) 218 if (adapter_parm[type].init.val)
219 line_set(port, 0, &adapter_parm[type].init); 219 line_set(port, 0, &adapter_parm[type].init);
220 220
221 i2c_bit_del_bus(&adapter->adapter); 221 i2c_del_adapter(&adapter->adapter);
222 parport_unregister_device(adapter->pdev); 222 parport_unregister_device(adapter->pdev);
223 if (prev) 223 if (prev)
224 prev->next = adapter->next; 224 prev->next = adapter->next;
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 407840b6a260..cc6536a19eca 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -156,7 +156,7 @@ static int __init pca_isa_init(void)
156 156
157static void pca_isa_exit(void) 157static void pca_isa_exit(void)
158{ 158{
159 i2c_pca_del_bus(&pca_isa_ops); 159 i2c_del_adapter(&pca_isa_ops);
160 160
161 if (irq > 0) { 161 if (irq > 0) {
162 disable_irq(irq); 162 disable_irq(irq);
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
new file mode 100644
index 000000000000..de0bca77e926
--- /dev/null
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -0,0 +1,708 @@
1/*
2 * Provides I2C support for Philips PNX010x/PNX4008 boards.
3 *
4 * Authors: Dennis Kovalev <dkovalev@ru.mvista.com>
5 * Vitaly Wool <vwool@ru.mvista.com>
6 *
7 * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
8 * the terms of the GNU General Public License version 2. This program
9 * is licensed "as is" without any warranty of any kind, whether express
10 * or implied.
11 */
12
13#include <linux/module.h>
14#include <linux/interrupt.h>
15#include <linux/ioport.h>
16#include <linux/delay.h>
17#include <linux/i2c.h>
18#include <linux/timer.h>
19#include <linux/completion.h>
20#include <linux/platform_device.h>
21#include <linux/i2c-pnx.h>
22#include <asm/hardware.h>
23#include <asm/irq.h>
24#include <asm/uaccess.h>
25
26#define I2C_PNX_TIMEOUT 10 /* msec */
27#define I2C_PNX_SPEED_KHZ 100
28#define I2C_PNX_REGION_SIZE 0x100
29#define PNX_DEFAULT_FREQ 13 /* MHz */
30
31static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data)
32{
33 while (timeout > 0 &&
34 (ioread32(I2C_REG_STS(data)) & mstatus_active)) {
35 mdelay(1);
36 timeout--;
37 }
38 return (timeout <= 0);
39}
40
41static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data)
42{
43 while (timeout > 0 &&
44 (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) {
45 mdelay(1);
46 timeout--;
47 }
48 return (timeout <= 0);
49}
50
51static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap)
52{
53 struct i2c_pnx_algo_data *data = adap->algo_data;
54 struct timer_list *timer = &data->mif.timer;
55 int expires = I2C_PNX_TIMEOUT / (1000 / HZ);
56
57 del_timer_sync(timer);
58
59 dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n",
60 jiffies, expires);
61
62 timer->expires = jiffies + expires;
63 timer->data = (unsigned long)adap;
64
65 add_timer(timer);
66}
67
68/**
69 * i2c_pnx_start - start a device
70 * @slave_addr: slave address
71 * @adap: pointer to adapter structure
72 *
73 * Generate a START signal in the desired mode.
74 */
75static int i2c_pnx_start(unsigned char slave_addr, struct i2c_adapter *adap)
76{
77 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
78
79 dev_dbg(&adap->dev, "%s(): addr 0x%x mode %d\n", __FUNCTION__,
80 slave_addr, alg_data->mif.mode);
81
82 /* Check for 7 bit slave addresses only */
83 if (slave_addr & ~0x7f) {
84 dev_err(&adap->dev, "%s: Invalid slave address %x. "
85 "Only 7-bit addresses are supported\n",
86 adap->name, slave_addr);
87 return -EINVAL;
88 }
89
90 /* First, make sure bus is idle */
91 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) {
92 /* Somebody else is monopolizing the bus */
93 dev_err(&adap->dev, "%s: Bus busy. Slave addr = %02x, "
94 "cntrl = %x, stat = %x\n",
95 adap->name, slave_addr,
96 ioread32(I2C_REG_CTL(alg_data)),
97 ioread32(I2C_REG_STS(alg_data)));
98 return -EBUSY;
99 } else if (ioread32(I2C_REG_STS(alg_data)) & mstatus_afi) {
100 /* Sorry, we lost the bus */
101 dev_err(&adap->dev, "%s: Arbitration failure. "
102 "Slave addr = %02x\n", adap->name, slave_addr);
103 return -EIO;
104 }
105
106 /*
107 * OK, I2C is enabled and we have the bus.
108 * Clear the current TDI and AFI status flags.
109 */
110 iowrite32(ioread32(I2C_REG_STS(alg_data)) | mstatus_tdi | mstatus_afi,
111 I2C_REG_STS(alg_data));
112
113 dev_dbg(&adap->dev, "%s(): sending %#x\n", __FUNCTION__,
114 (slave_addr << 1) | start_bit | alg_data->mif.mode);
115
116 /* Write the slave address, START bit and R/W bit */
117 iowrite32((slave_addr << 1) | start_bit | alg_data->mif.mode,
118 I2C_REG_TX(alg_data));
119
120 dev_dbg(&adap->dev, "%s(): exit\n", __FUNCTION__);
121
122 return 0;
123}
124
125/**
126 * i2c_pnx_stop - stop a device
127 * @adap: pointer to I2C adapter structure
128 *
129 * Generate a STOP signal to terminate the master transaction.
130 */
131static void i2c_pnx_stop(struct i2c_adapter *adap)
132{
133 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
134 /* Only 1 msec max timeout due to interrupt context */
135 long timeout = 1000;
136
137 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
138 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
139
140 /* Write a STOP bit to TX FIFO */
141 iowrite32(0xff | stop_bit, I2C_REG_TX(alg_data));
142
143 /* Wait until the STOP is seen. */
144 while (timeout > 0 &&
145 (ioread32(I2C_REG_STS(alg_data)) & mstatus_active)) {
146 /* may be called from interrupt context */
147 udelay(1);
148 timeout--;
149 }
150
151 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
152 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
153}
154
155/**
156 * i2c_pnx_master_xmit - transmit data to slave
157 * @adap: pointer to I2C adapter structure
158 *
159 * Sends one byte of data to the slave
160 */
161static int i2c_pnx_master_xmit(struct i2c_adapter *adap)
162{
163 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
164 u32 val;
165
166 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
167 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
168
169 if (alg_data->mif.len > 0) {
170 /* We still have something to talk about... */
171 val = *alg_data->mif.buf++;
172
173 if (alg_data->mif.len == 1) {
174 val |= stop_bit;
175 if (!alg_data->last)
176 val |= start_bit;
177 }
178
179 alg_data->mif.len--;
180 iowrite32(val, I2C_REG_TX(alg_data));
181
182 dev_dbg(&adap->dev, "%s(): xmit %#x [%d]\n", __FUNCTION__,
183 val, alg_data->mif.len + 1);
184
185 if (alg_data->mif.len == 0) {
186 if (alg_data->last) {
187 /* Wait until the STOP is seen. */
188 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data))
189 dev_err(&adap->dev, "The bus is still "
190 "active after timeout\n");
191 }
192 /* Disable master interrupts */
193 iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
194 ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie),
195 I2C_REG_CTL(alg_data));
196
197 del_timer_sync(&alg_data->mif.timer);
198
199 dev_dbg(&adap->dev, "%s(): Waking up xfer routine.\n",
200 __FUNCTION__);
201
202 complete(&alg_data->mif.complete);
203 }
204 } else if (alg_data->mif.len == 0) {
205 /* zero-sized transfer */
206 i2c_pnx_stop(adap);
207
208 /* Disable master interrupts. */
209 iowrite32(ioread32(I2C_REG_CTL(alg_data)) &
210 ~(mcntrl_afie | mcntrl_naie | mcntrl_drmie),
211 I2C_REG_CTL(alg_data));
212
213 /* Stop timer. */
214 del_timer_sync(&alg_data->mif.timer);
215 dev_dbg(&adap->dev, "%s(): Waking up xfer routine after "
216 "zero-xfer.\n", __FUNCTION__);
217
218 complete(&alg_data->mif.complete);
219 }
220
221 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
222 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
223
224 return 0;
225}
226
227/**
228 * i2c_pnx_master_rcv - receive data from slave
229 * @adap: pointer to I2C adapter structure
230 *
231 * Reads one byte data from the slave
232 */
233static int i2c_pnx_master_rcv(struct i2c_adapter *adap)
234{
235 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
236 unsigned int val = 0;
237 u32 ctl = 0;
238
239 dev_dbg(&adap->dev, "%s(): entering: stat = %04x.\n",
240 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
241
242 /* Check, whether there is already data,
243 * or we didn't 'ask' for it yet.
244 */
245 if (ioread32(I2C_REG_STS(alg_data)) & mstatus_rfe) {
246 dev_dbg(&adap->dev, "%s(): Write dummy data to fill "
247 "Rx-fifo...\n", __FUNCTION__);
248
249 if (alg_data->mif.len == 1) {
250 /* Last byte, do not acknowledge next rcv. */
251 val |= stop_bit;
252 if (!alg_data->last)
253 val |= start_bit;
254
255 /*
256 * Enable interrupt RFDAIE (data in Rx fifo),
257 * and disable DRMIE (need data for Tx)
258 */
259 ctl = ioread32(I2C_REG_CTL(alg_data));
260 ctl |= mcntrl_rffie | mcntrl_daie;
261 ctl &= ~mcntrl_drmie;
262 iowrite32(ctl, I2C_REG_CTL(alg_data));
263 }
264
265 /*
266 * Now we'll 'ask' for data:
267 * For each byte we want to receive, we must
268 * write a (dummy) byte to the Tx-FIFO.
269 */
270 iowrite32(val, I2C_REG_TX(alg_data));
271
272 return 0;
273 }
274
275 /* Handle data. */
276 if (alg_data->mif.len > 0) {
277 val = ioread32(I2C_REG_RX(alg_data));
278 *alg_data->mif.buf++ = (u8) (val & 0xff);
279 dev_dbg(&adap->dev, "%s(): rcv 0x%x [%d]\n", __FUNCTION__, val,
280 alg_data->mif.len);
281
282 alg_data->mif.len--;
283 if (alg_data->mif.len == 0) {
284 if (alg_data->last)
285 /* Wait until the STOP is seen. */
286 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data))
287 dev_err(&adap->dev, "The bus is still "
288 "active after timeout\n");
289
290 /* Disable master interrupts */
291 ctl = ioread32(I2C_REG_CTL(alg_data));
292 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
293 mcntrl_drmie | mcntrl_daie);
294 iowrite32(ctl, I2C_REG_CTL(alg_data));
295
296 /* Kill timer. */
297 del_timer_sync(&alg_data->mif.timer);
298 complete(&alg_data->mif.complete);
299 }
300 }
301
302 dev_dbg(&adap->dev, "%s(): exiting: stat = %04x.\n",
303 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
304
305 return 0;
306}
307
308static irqreturn_t
309i2c_pnx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
310{
311 u32 stat, ctl;
312 struct i2c_adapter *adap = dev_id;
313 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
314
315 dev_dbg(&adap->dev, "%s(): mstat = %x mctrl = %x, mode = %d\n",
316 __FUNCTION__,
317 ioread32(I2C_REG_STS(alg_data)),
318 ioread32(I2C_REG_CTL(alg_data)),
319 alg_data->mif.mode);
320 stat = ioread32(I2C_REG_STS(alg_data));
321
322 /* let's see what kind of event this is */
323 if (stat & mstatus_afi) {
324 /* We lost arbitration in the midst of a transfer */
325 alg_data->mif.ret = -EIO;
326
327 /* Disable master interrupts. */
328 ctl = ioread32(I2C_REG_CTL(alg_data));
329 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
330 mcntrl_drmie);
331 iowrite32(ctl, I2C_REG_CTL(alg_data));
332
333 /* Stop timer, to prevent timeout. */
334 del_timer_sync(&alg_data->mif.timer);
335 complete(&alg_data->mif.complete);
336 } else if (stat & mstatus_nai) {
337 /* Slave did not acknowledge, generate a STOP */
338 dev_dbg(&adap->dev, "%s(): "
339 "Slave did not acknowledge, generating a STOP.\n",
340 __FUNCTION__);
341 i2c_pnx_stop(adap);
342
343 /* Disable master interrupts. */
344 ctl = ioread32(I2C_REG_CTL(alg_data));
345 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie |
346 mcntrl_drmie);
347 iowrite32(ctl, I2C_REG_CTL(alg_data));
348
349 /* Our return value. */
350 alg_data->mif.ret = -EIO;
351
352 /* Stop timer, to prevent timeout. */
353 del_timer_sync(&alg_data->mif.timer);
354 complete(&alg_data->mif.complete);
355 } else {
356 /*
357 * Two options:
358 * - Master Tx needs data.
359 * - There is data in the Rx-fifo
360 * The latter is only the case if we have requested for data,
361 * via a dummy write. (See 'i2c_pnx_master_rcv'.)
362 * We therefore check, as a sanity check, whether that interrupt
363 * has been enabled.
364 */
365 if ((stat & mstatus_drmi) || !(stat & mstatus_rfe)) {
366 if (alg_data->mif.mode == I2C_SMBUS_WRITE) {
367 i2c_pnx_master_xmit(adap);
368 } else if (alg_data->mif.mode == I2C_SMBUS_READ) {
369 i2c_pnx_master_rcv(adap);
370 }
371 }
372 }
373
374 /* Clear TDI and AFI bits */
375 stat = ioread32(I2C_REG_STS(alg_data));
376 iowrite32(stat | mstatus_tdi | mstatus_afi, I2C_REG_STS(alg_data));
377
378 dev_dbg(&adap->dev, "%s(): exiting, stat = %x ctrl = %x.\n",
379 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)),
380 ioread32(I2C_REG_CTL(alg_data)));
381
382 return IRQ_HANDLED;
383}
384
385static void i2c_pnx_timeout(unsigned long data)
386{
387 struct i2c_adapter *adap = (struct i2c_adapter *)data;
388 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
389 u32 ctl;
390
391 dev_err(&adap->dev, "Master timed out. stat = %04x, cntrl = %04x. "
392 "Resetting master...\n",
393 ioread32(I2C_REG_STS(alg_data)),
394 ioread32(I2C_REG_CTL(alg_data)));
395
396 /* Reset master and disable interrupts */
397 ctl = ioread32(I2C_REG_CTL(alg_data));
398 ctl &= ~(mcntrl_afie | mcntrl_naie | mcntrl_rffie | mcntrl_drmie);
399 iowrite32(ctl, I2C_REG_CTL(alg_data));
400
401 ctl |= mcntrl_reset;
402 iowrite32(ctl, I2C_REG_CTL(alg_data));
403 wait_reset(I2C_PNX_TIMEOUT, alg_data);
404 alg_data->mif.ret = -EIO;
405 complete(&alg_data->mif.complete);
406}
407
408static inline void bus_reset_if_active(struct i2c_adapter *adap)
409{
410 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
411 u32 stat;
412
413 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_active) {
414 dev_err(&adap->dev,
415 "%s: Bus is still active after xfer. Reset it...\n",
416 adap->name);
417 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
418 I2C_REG_CTL(alg_data));
419 wait_reset(I2C_PNX_TIMEOUT, alg_data);
420 } else if (!(stat & mstatus_rfe) || !(stat & mstatus_tfe)) {
421 /* If there is data in the fifo's after transfer,
422 * flush fifo's by reset.
423 */
424 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
425 I2C_REG_CTL(alg_data));
426 wait_reset(I2C_PNX_TIMEOUT, alg_data);
427 } else if (stat & mstatus_nai) {
428 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
429 I2C_REG_CTL(alg_data));
430 wait_reset(I2C_PNX_TIMEOUT, alg_data);
431 }
432}
433
434/**
435 * i2c_pnx_xfer - generic transfer entry point
436 * @adap: pointer to I2C adapter structure
437 * @msgs: array of messages
438 * @num: number of messages
439 *
440 * Initiates the transfer
441 */
442static int
443i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
444{
445 struct i2c_msg *pmsg;
446 int rc = 0, completed = 0, i;
447 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
448 u32 stat = ioread32(I2C_REG_STS(alg_data));
449
450 dev_dbg(&adap->dev, "%s(): entering: %d messages, stat = %04x.\n",
451 __FUNCTION__, num, ioread32(I2C_REG_STS(alg_data)));
452
453 bus_reset_if_active(adap);
454
455 /* Process transactions in a loop. */
456 for (i = 0; rc >= 0 && i < num; i++) {
457 u8 addr;
458
459 pmsg = &msgs[i];
460 addr = pmsg->addr;
461
462 if (pmsg->flags & I2C_M_TEN) {
463 dev_err(&adap->dev,
464 "%s: 10 bits addr not supported!\n",
465 adap->name);
466 rc = -EINVAL;
467 break;
468 }
469
470 alg_data->mif.buf = pmsg->buf;
471 alg_data->mif.len = pmsg->len;
472 alg_data->mif.mode = (pmsg->flags & I2C_M_RD) ?
473 I2C_SMBUS_READ : I2C_SMBUS_WRITE;
474 alg_data->mif.ret = 0;
475 alg_data->last = (i == num - 1);
476
477 dev_dbg(&adap->dev, "%s(): mode %d, %d bytes\n", __FUNCTION__,
478 alg_data->mif.mode,
479 alg_data->mif.len);
480
481 i2c_pnx_arm_timer(adap);
482
483 /* initialize the completion var */
484 init_completion(&alg_data->mif.complete);
485
486 /* Enable master interrupt */
487 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
488 mcntrl_naie | mcntrl_drmie,
489 I2C_REG_CTL(alg_data));
490
491 /* Put start-code and slave-address on the bus. */
492 rc = i2c_pnx_start(addr, adap);
493 if (rc < 0)
494 break;
495
496 /* Wait for completion */
497 wait_for_completion(&alg_data->mif.complete);
498
499 if (!(rc = alg_data->mif.ret))
500 completed++;
501 dev_dbg(&adap->dev, "%s(): Complete, return code = %d.\n",
502 __FUNCTION__, rc);
503
504 /* Clear TDI and AFI bits in case they are set. */
505 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_tdi) {
506 dev_dbg(&adap->dev,
507 "%s: TDI still set... clearing now.\n",
508 adap->name);
509 iowrite32(stat, I2C_REG_STS(alg_data));
510 }
511 if ((stat = ioread32(I2C_REG_STS(alg_data))) & mstatus_afi) {
512 dev_dbg(&adap->dev,
513 "%s: AFI still set... clearing now.\n",
514 adap->name);
515 iowrite32(stat, I2C_REG_STS(alg_data));
516 }
517 }
518
519 bus_reset_if_active(adap);
520
521 /* Cleanup to be sure... */
522 alg_data->mif.buf = NULL;
523 alg_data->mif.len = 0;
524
525 dev_dbg(&adap->dev, "%s(): exiting, stat = %x\n",
526 __FUNCTION__, ioread32(I2C_REG_STS(alg_data)));
527
528 if (completed != num)
529 return ((rc < 0) ? rc : -EREMOTEIO);
530
531 return num;
532}
533
534static u32 i2c_pnx_func(struct i2c_adapter *adapter)
535{
536 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
537}
538
539static struct i2c_algorithm pnx_algorithm = {
540 .master_xfer = i2c_pnx_xfer,
541 .functionality = i2c_pnx_func,
542};
543
544static int i2c_pnx_controller_suspend(struct platform_device *pdev,
545 pm_message_t state)
546{
547 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
548 return i2c_pnx->suspend(pdev, state);
549}
550
551static int i2c_pnx_controller_resume(struct platform_device *pdev)
552{
553 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
554 return i2c_pnx->resume(pdev);
555}
556
557static int __devinit i2c_pnx_probe(struct platform_device *pdev)
558{
559 unsigned long tmp;
560 int ret = 0;
561 struct i2c_pnx_algo_data *alg_data;
562 int freq_mhz;
563 struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data;
564
565 if (!i2c_pnx || !i2c_pnx->adapter) {
566 dev_err(&pdev->dev, "%s: no platform data supplied\n",
567 __FUNCTION__);
568 ret = -EINVAL;
569 goto out;
570 }
571
572 platform_set_drvdata(pdev, i2c_pnx);
573
574 if (i2c_pnx->calculate_input_freq)
575 freq_mhz = i2c_pnx->calculate_input_freq(pdev);
576 else {
577 freq_mhz = PNX_DEFAULT_FREQ;
578 dev_info(&pdev->dev, "Setting bus frequency to default value: "
579 "%d MHz", freq_mhz);
580 }
581
582 i2c_pnx->adapter->algo = &pnx_algorithm;
583
584 alg_data = i2c_pnx->adapter->algo_data;
585 init_timer(&alg_data->mif.timer);
586 alg_data->mif.timer.function = i2c_pnx_timeout;
587 alg_data->mif.timer.data = (unsigned long)i2c_pnx->adapter;
588
589 /* Register I/O resource */
590 if (!request_region(alg_data->base, I2C_PNX_REGION_SIZE, pdev->name)) {
591 dev_err(&pdev->dev,
592 "I/O region 0x%08x for I2C already in use.\n",
593 alg_data->base);
594 ret = -ENODEV;
595 goto out_drvdata;
596 }
597
598 if (!(alg_data->ioaddr =
599 (u32)ioremap(alg_data->base, I2C_PNX_REGION_SIZE))) {
600 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
601 ret = -ENOMEM;
602 goto out_release;
603 }
604
605 i2c_pnx->set_clock_run(pdev);
606
607 /*
608 * Clock Divisor High This value is the number of system clocks
609 * the serial clock (SCL) will be high.
610 * For example, if the system clock period is 50 ns and the maximum
611 * desired serial period is 10000 ns (100 kHz), then CLKHI would be
612 * set to 0.5*(f_sys/f_i2c)-2=0.5*(20e6/100e3)-2=98. The actual value
613 * programmed into CLKHI will vary from this slightly due to
614 * variations in the output pad's rise and fall times as well as
615 * the deglitching filter length.
616 */
617
618 tmp = ((freq_mhz * 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2;
619 iowrite32(tmp, I2C_REG_CKH(alg_data));
620 iowrite32(tmp, I2C_REG_CKL(alg_data));
621
622 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data));
623 if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) {
624 ret = -ENODEV;
625 goto out_unmap;
626 }
627 init_completion(&alg_data->mif.complete);
628
629 ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
630 0, pdev->name, i2c_pnx->adapter);
631 if (ret)
632 goto out_clock;
633
634 /* Register this adapter with the I2C subsystem */
635 i2c_pnx->adapter->dev.parent = &pdev->dev;
636 ret = i2c_add_adapter(i2c_pnx->adapter);
637 if (ret < 0) {
638 dev_err(&pdev->dev, "I2C: Failed to add bus\n");
639 goto out_irq;
640 }
641
642 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
643 i2c_pnx->adapter->name, alg_data->base, alg_data->irq);
644
645 return 0;
646
647out_irq:
648 free_irq(alg_data->irq, alg_data);
649out_clock:
650 i2c_pnx->set_clock_stop(pdev);
651out_unmap:
652 iounmap((void *)alg_data->ioaddr);
653out_release:
654 release_region(alg_data->base, I2C_PNX_REGION_SIZE);
655out_drvdata:
656 platform_set_drvdata(pdev, NULL);
657out:
658 return ret;
659}
660
661static int __devexit i2c_pnx_remove(struct platform_device *pdev)
662{
663 struct i2c_pnx_data *i2c_pnx = platform_get_drvdata(pdev);
664 struct i2c_adapter *adap = i2c_pnx->adapter;
665 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
666
667 free_irq(alg_data->irq, alg_data);
668 i2c_del_adapter(adap);
669 i2c_pnx->set_clock_stop(pdev);
670 iounmap((void *)alg_data->ioaddr);
671 release_region(alg_data->base, I2C_PNX_REGION_SIZE);
672 platform_set_drvdata(pdev, NULL);
673
674 return 0;
675}
676
677static struct platform_driver i2c_pnx_driver = {
678 .driver = {
679 .name = "pnx-i2c",
680 .owner = THIS_MODULE,
681 },
682 .probe = i2c_pnx_probe,
683 .remove = __devexit_p(i2c_pnx_remove),
684 .suspend = i2c_pnx_controller_suspend,
685 .resume = i2c_pnx_controller_resume,
686};
687
688static int __init i2c_adap_pnx_init(void)
689{
690 return platform_driver_register(&i2c_pnx_driver);
691}
692
693static void __exit i2c_adap_pnx_exit(void)
694{
695 platform_driver_unregister(&i2c_pnx_driver);
696}
697
698MODULE_AUTHOR("Vitaly Wool, Dennis Kovalev <source@mvista.com>");
699MODULE_DESCRIPTION("I2C driver for Philips IP3204-based I2C busses");
700MODULE_LICENSE("GPL");
701
702#ifdef CONFIG_I2C_PNX_EARLY
703/* We need to make sure I2C is initialized before USB */
704subsys_initcall(i2c_adap_pnx_init);
705#else
706mudule_init(i2c_adap_pnx_init);
707#endif
708module_exit(i2c_adap_pnx_exit);
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 7745e21874a8..07c1f1e27df1 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -212,7 +212,7 @@ static void prosavage_remove(struct pci_dev *dev)
212 if (chip->i2c_bus[i].adap_ok == 0) 212 if (chip->i2c_bus[i].adap_ok == 0)
213 continue; 213 continue;
214 214
215 ret = i2c_bit_del_bus(&chip->i2c_bus[i].adap); 215 ret = i2c_del_adapter(&chip->i2c_bus[i].adap);
216 if (ret) { 216 if (ret) {
217 dev_err(&dev->dev, "%s not removed\n", 217 dev_err(&dev->dev, "%s not removed\n",
218 chip->i2c_bus[i].adap.name); 218 chip->i2c_bus[i].adap.name);
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 209f47ea1750..844b4ff90893 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -173,7 +173,7 @@ static int __devinit savage4_probe(struct pci_dev *dev, const struct pci_device_
173 173
174static void __devexit savage4_remove(struct pci_dev *dev) 174static void __devexit savage4_remove(struct pci_dev *dev)
175{ 175{
176 i2c_bit_del_bus(&savage4_i2c_adapter); 176 i2c_del_adapter(&savage4_i2c_adapter);
177 iounmap(ioaddr); 177 iounmap(ioaddr);
178} 178}
179 179
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
new file mode 100644
index 000000000000..081d9578ce10
--- /dev/null
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -0,0 +1,153 @@
1/*
2 * i2c-versatile.c
3 *
4 * Copyright (C) 2006 ARM Ltd.
5 * written by Russell King, Deep Blue Solutions Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/i2c.h>
14#include <linux/i2c-algo-bit.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17
18#include <asm/io.h>
19
20#define I2C_CONTROL 0x00
21#define I2C_CONTROLS 0x00
22#define I2C_CONTROLC 0x04
23#define SCL (1 << 0)
24#define SDA (1 << 1)
25
26struct i2c_versatile {
27 struct i2c_adapter adap;
28 struct i2c_algo_bit_data algo;
29 void __iomem *base;
30};
31
32static void i2c_versatile_setsda(void *data, int state)
33{
34 struct i2c_versatile *i2c = data;
35
36 writel(SDA, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC));
37}
38
39static void i2c_versatile_setscl(void *data, int state)
40{
41 struct i2c_versatile *i2c = data;
42
43 writel(SCL, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC));
44}
45
46static int i2c_versatile_getsda(void *data)
47{
48 struct i2c_versatile *i2c = data;
49 return !!(readl(i2c->base + I2C_CONTROL) & SDA);
50}
51
52static int i2c_versatile_getscl(void *data)
53{
54 struct i2c_versatile *i2c = data;
55 return !!(readl(i2c->base + I2C_CONTROL) & SCL);
56}
57
58static struct i2c_algo_bit_data i2c_versatile_algo = {
59 .setsda = i2c_versatile_setsda,
60 .setscl = i2c_versatile_setscl,
61 .getsda = i2c_versatile_getsda,
62 .getscl = i2c_versatile_getscl,
63 .udelay = 30,
64 .timeout = HZ,
65};
66
67static int i2c_versatile_probe(struct platform_device *dev)
68{
69 struct i2c_versatile *i2c;
70 struct resource *r;
71 int ret;
72
73 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
74 if (!r) {
75 ret = -EINVAL;
76 goto err_out;
77 }
78
79 if (!request_mem_region(r->start, r->end - r->start + 1, "versatile-i2c")) {
80 ret = -EBUSY;
81 goto err_out;
82 }
83
84 i2c = kzalloc(sizeof(struct i2c_versatile), GFP_KERNEL);
85 if (!i2c) {
86 ret = -ENOMEM;
87 goto err_release;
88 }
89
90 i2c->base = ioremap(r->start, r->end - r->start + 1);
91 if (!i2c->base) {
92 ret = -ENOMEM;
93 goto err_free;
94 }
95
96 writel(SCL | SDA, i2c->base + I2C_CONTROLS);
97
98 i2c->adap.owner = THIS_MODULE;
99 strlcpy(i2c->adap.name, "Versatile I2C adapter", sizeof(i2c->adap.name));
100 i2c->adap.algo_data = &i2c->algo;
101 i2c->adap.dev.parent = &dev->dev;
102 i2c->algo = i2c_versatile_algo;
103 i2c->algo.data = i2c;
104
105 ret = i2c_bit_add_bus(&i2c->adap);
106 if (ret >= 0) {
107 platform_set_drvdata(dev, i2c);
108 return 0;
109 }
110
111 iounmap(i2c->base);
112 err_free:
113 kfree(i2c);
114 err_release:
115 release_mem_region(r->start, r->end - r->start + 1);
116 err_out:
117 return ret;
118}
119
120static int i2c_versatile_remove(struct platform_device *dev)
121{
122 struct i2c_versatile *i2c = platform_get_drvdata(dev);
123
124 platform_set_drvdata(dev, NULL);
125
126 i2c_del_adapter(&i2c->adap);
127 return 0;
128}
129
130static struct platform_driver i2c_versatile_driver = {
131 .probe = i2c_versatile_probe,
132 .remove = i2c_versatile_remove,
133 .driver = {
134 .name = "versatile-i2c",
135 .owner = THIS_MODULE,
136 },
137};
138
139static int __init i2c_versatile_init(void)
140{
141 return platform_driver_register(&i2c_versatile_driver);
142}
143
144static void __exit i2c_versatile_exit(void)
145{
146 platform_driver_unregister(&i2c_versatile_driver);
147}
148
149module_init(i2c_versatile_init);
150module_exit(i2c_versatile_exit);
151
152MODULE_DESCRIPTION("ARM Versatile I2C bus driver");
153MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 910e200ad500..15d7e00e47e6 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -151,7 +151,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i
151 151
152static void __devexit vt586b_remove(struct pci_dev *dev) 152static void __devexit vt586b_remove(struct pci_dev *dev)
153{ 153{
154 i2c_bit_del_bus(&vt586b_adapter); 154 i2c_del_adapter(&vt586b_adapter);
155 release_region(I2C_DIR, IOSPACE); 155 release_region(I2C_DIR, IOSPACE);
156 pm_io_base = 0; 156 pm_io_base = 0;
157} 157}
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index 6c8d25183382..b0377b81744b 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -211,14 +211,14 @@ static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_
211 return retval; 211 return retval;
212 retval = i2c_bit_add_bus(&voodoo3_ddc_adapter); 212 retval = i2c_bit_add_bus(&voodoo3_ddc_adapter);
213 if (retval) 213 if (retval)
214 i2c_bit_del_bus(&voodoo3_i2c_adapter); 214 i2c_del_adapter(&voodoo3_i2c_adapter);
215 return retval; 215 return retval;
216} 216}
217 217
218static void __devexit voodoo3_remove(struct pci_dev *dev) 218static void __devexit voodoo3_remove(struct pci_dev *dev)
219{ 219{
220 i2c_bit_del_bus(&voodoo3_i2c_adapter); 220 i2c_del_adapter(&voodoo3_i2c_adapter);
221 i2c_bit_del_bus(&voodoo3_ddc_adapter); 221 i2c_del_adapter(&voodoo3_ddc_adapter);
222 iounmap(ioaddr); 222 iounmap(ioaddr);
223} 223}
224 224
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
index 8ddbae4fafe6..6cd96e43aa72 100644
--- a/drivers/i2c/busses/scx200_i2c.c
+++ b/drivers/i2c/busses/scx200_i2c.c
@@ -116,7 +116,7 @@ static int scx200_i2c_init(void)
116 116
117static void scx200_i2c_cleanup(void) 117static void scx200_i2c_cleanup(void)
118{ 118{
119 i2c_bit_del_bus(&scx200_i2c_ops); 119 i2c_del_adapter(&scx200_i2c_ops);
120} 120}
121 121
122module_init(scx200_i2c_init); 122module_init(scx200_i2c_init);
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 93d483b8b770..ec17d6b684a2 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -347,13 +347,19 @@ static void ds1337_init_client(struct i2c_client *client)
347 347
348 if ((status & 0x80) || (control & 0x80)) { 348 if ((status & 0x80) || (control & 0x80)) {
349 /* RTC not running */ 349 /* RTC not running */
350 u8 buf[16]; 350 u8 buf[1+16]; /* First byte is interpreted as address */
351 struct i2c_msg msg[1]; 351 struct i2c_msg msg[1];
352 352
353 dev_dbg(&client->dev, "%s: RTC not running!\n", __FUNCTION__); 353 dev_dbg(&client->dev, "%s: RTC not running!\n", __FUNCTION__);
354 354
355 /* Initialize all, including STATUS and CONTROL to zero */ 355 /* Initialize all, including STATUS and CONTROL to zero */
356 memset(buf, 0, sizeof(buf)); 356 memset(buf, 0, sizeof(buf));
357
358 /* Write valid values in the date/time registers */
359 buf[1+DS1337_REG_DAY] = 1;
360 buf[1+DS1337_REG_DATE] = 1;
361 buf[1+DS1337_REG_MONTH] = 1;
362
357 msg[0].addr = client->addr; 363 msg[0].addr = client->addr;
358 msg[0].flags = 0; 364 msg[0].flags = 0;
359 msg[0].len = sizeof(buf); 365 msg[0].len = sizeof(buf);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7ca81f42d14b..3e31f1d265c9 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -127,20 +127,17 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att
127 return sprintf(buf, "%s\n", client->name); 127 return sprintf(buf, "%s\n", client->name);
128} 128}
129 129
130/* 130/*
131 * We can't use the DEVICE_ATTR() macro here as we want the same filename for a 131 * We can't use the DEVICE_ATTR() macro here, as we used the same name for
132 * different type of a device. So beware if the DEVICE_ATTR() macro ever 132 * an i2c adapter attribute (above).
133 * changes, this definition will also have to change.
134 */ 133 */
135static struct device_attribute dev_attr_client_name = { 134static struct device_attribute dev_attr_client_name =
136 .attr = {.name = "name", .mode = S_IRUGO, .owner = THIS_MODULE }, 135 __ATTR(name, S_IRUGO, &show_client_name, NULL);
137 .show = &show_client_name,
138};
139 136
140 137
141/* --------------------------------------------------- 138/* ---------------------------------------------------
142 * registering functions 139 * registering functions
143 * --------------------------------------------------- 140 * ---------------------------------------------------
144 */ 141 */
145 142
146/* ----- 143/* -----
@@ -314,7 +311,7 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
314 res = driver_register(&driver->driver); 311 res = driver_register(&driver->driver);
315 if (res) 312 if (res)
316 return res; 313 return res;
317 314
318 mutex_lock(&core_lists); 315 mutex_lock(&core_lists);
319 316
320 list_add_tail(&driver->list,&drivers); 317 list_add_tail(&driver->list,&drivers);
@@ -338,13 +335,13 @@ int i2c_del_driver(struct i2c_driver *driver)
338 struct list_head *item1, *item2, *_n; 335 struct list_head *item1, *item2, *_n;
339 struct i2c_client *client; 336 struct i2c_client *client;
340 struct i2c_adapter *adap; 337 struct i2c_adapter *adap;
341 338
342 int res = 0; 339 int res = 0;
343 340
344 mutex_lock(&core_lists); 341 mutex_lock(&core_lists);
345 342
346 /* Have a look at each adapter, if clients of this driver are still 343 /* Have a look at each adapter, if clients of this driver are still
347 * attached. If so, detach them to be able to kill the driver 344 * attached. If so, detach them to be able to kill the driver
348 * afterwards. 345 * afterwards.
349 */ 346 */
350 list_for_each(item1,&adapters) { 347 list_for_each(item1,&adapters) {
@@ -419,14 +416,14 @@ int i2c_attach_client(struct i2c_client *client)
419 goto out_unlock; 416 goto out_unlock;
420 } 417 }
421 list_add_tail(&client->list,&adapter->clients); 418 list_add_tail(&client->list,&adapter->clients);
422 419
423 client->usage_count = 0; 420 client->usage_count = 0;
424 421
425 client->dev.parent = &client->adapter->dev; 422 client->dev.parent = &client->adapter->dev;
426 client->dev.driver = &client->driver->driver; 423 client->dev.driver = &client->driver->driver;
427 client->dev.bus = &i2c_bus_type; 424 client->dev.bus = &i2c_bus_type;
428 client->dev.release = &i2c_client_release; 425 client->dev.release = &i2c_client_release;
429 426
430 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 427 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
431 "%d-%04x", i2c_adapter_id(adapter), client->addr); 428 "%d-%04x", i2c_adapter_id(adapter), client->addr);
432 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n", 429 dev_dbg(&adapter->dev, "client [%s] registered with bus id %s\n",
@@ -467,7 +464,7 @@ int i2c_detach_client(struct i2c_client *client)
467{ 464{
468 struct i2c_adapter *adapter = client->adapter; 465 struct i2c_adapter *adapter = client->adapter;
469 int res = 0; 466 int res = 0;
470 467
471 if (client->usage_count > 0) { 468 if (client->usage_count > 0) {
472 dev_warn(&client->dev, "Client [%s] still busy, " 469 dev_warn(&client->dev, "Client [%s] still busy, "
473 "can't detach\n", client->name); 470 "can't detach\n", client->name);
@@ -535,10 +532,10 @@ int i2c_release_client(struct i2c_client *client)
535 __FUNCTION__); 532 __FUNCTION__);
536 return -EPERM; 533 return -EPERM;
537 } 534 }
538 535
539 client->usage_count--; 536 client->usage_count--;
540 i2c_dec_use_client(client); 537 i2c_dec_use_client(client);
541 538
542 return 0; 539 return 0;
543} 540}
544 541
@@ -603,7 +600,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
603 } 600 }
604#endif 601#endif
605 602
606 mutex_lock(&adap->bus_lock); 603 mutex_lock_nested(&adap->bus_lock, adap->level);
607 ret = adap->algo->master_xfer(adap,msgs,num); 604 ret = adap->algo->master_xfer(adap,msgs,num);
608 mutex_unlock(&adap->bus_lock); 605 mutex_unlock(&adap->bus_lock);
609 606
@@ -624,7 +621,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
624 msg.flags = client->flags & I2C_M_TEN; 621 msg.flags = client->flags & I2C_M_TEN;
625 msg.len = count; 622 msg.len = count;
626 msg.buf = (char *)buf; 623 msg.buf = (char *)buf;
627 624
628 ret = i2c_transfer(adap, &msg, 1); 625 ret = i2c_transfer(adap, &msg, 1);
629 626
630 /* If everything went ok (i.e. 1 msg transmitted), return #bytes 627 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
@@ -757,7 +754,7 @@ int i2c_probe(struct i2c_adapter *adapter,
757 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { 754 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
758 if (address_data->probe[0] == I2C_CLIENT_END 755 if (address_data->probe[0] == I2C_CLIENT_END
759 && address_data->normal_i2c[0] == I2C_CLIENT_END) 756 && address_data->normal_i2c[0] == I2C_CLIENT_END)
760 return 0; 757 return 0;
761 758
762 dev_warn(&adapter->dev, "SMBus Quick command not supported, " 759 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
763 "can't probe for chips\n"); 760 "can't probe for chips\n");
@@ -817,7 +814,7 @@ int i2c_probe(struct i2c_adapter *adapter,
817struct i2c_adapter* i2c_get_adapter(int id) 814struct i2c_adapter* i2c_get_adapter(int id)
818{ 815{
819 struct i2c_adapter *adapter; 816 struct i2c_adapter *adapter;
820 817
821 mutex_lock(&core_lists); 818 mutex_lock(&core_lists);
822 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id); 819 adapter = (struct i2c_adapter *)idr_find(&i2c_adapter_idr, id);
823 if (adapter && !try_module_get(adapter->owner)) 820 if (adapter && !try_module_get(adapter->owner))
@@ -834,14 +831,14 @@ void i2c_put_adapter(struct i2c_adapter *adap)
834 831
835/* The SMBus parts */ 832/* The SMBus parts */
836 833
837#define POLY (0x1070U << 3) 834#define POLY (0x1070U << 3)
838static u8 835static u8
839crc8(u16 data) 836crc8(u16 data)
840{ 837{
841 int i; 838 int i;
842 839
843 for(i = 0; i < 8; i++) { 840 for(i = 0; i < 8; i++) {
844 if (data & 0x8000) 841 if (data & 0x8000)
845 data = data ^ POLY; 842 data = data ^ POLY;
846 data = data << 1; 843 data = data << 1;
847 } 844 }
@@ -891,13 +888,13 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
891 rpec, cpec); 888 rpec, cpec);
892 return -1; 889 return -1;
893 } 890 }
894 return 0; 891 return 0;
895} 892}
896 893
897s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) 894s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value)
898{ 895{
899 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 896 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
900 value,0,I2C_SMBUS_QUICK,NULL); 897 value,0,I2C_SMBUS_QUICK,NULL);
901} 898}
902 899
903s32 i2c_smbus_read_byte(struct i2c_client *client) 900s32 i2c_smbus_read_byte(struct i2c_client *client)
@@ -996,11 +993,11 @@ s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, u8 command,
996 I2C_SMBUS_I2C_BLOCK_DATA, &data); 993 I2C_SMBUS_I2C_BLOCK_DATA, &data);
997} 994}
998 995
999/* Simulate a SMBus command using the i2c protocol 996/* Simulate a SMBus command using the i2c protocol
1000 No checking of parameters is done! */ 997 No checking of parameters is done! */
1001static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, 998static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1002 unsigned short flags, 999 unsigned short flags,
1003 char read_write, u8 command, int size, 1000 char read_write, u8 command, int size,
1004 union i2c_smbus_data * data) 1001 union i2c_smbus_data * data)
1005{ 1002{
1006 /* So we need to generate a series of msgs. In the case of writing, we 1003 /* So we need to generate a series of msgs. In the case of writing, we
@@ -1010,7 +1007,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1010 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3]; 1007 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
1011 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2]; 1008 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
1012 int num = read_write == I2C_SMBUS_READ?2:1; 1009 int num = read_write == I2C_SMBUS_READ?2:1;
1013 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 1010 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
1014 { addr, flags | I2C_M_RD, 0, msgbuf1 } 1011 { addr, flags | I2C_M_RD, 0, msgbuf1 }
1015 }; 1012 };
1016 int i; 1013 int i;
@@ -1103,14 +1100,14 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1103 if (i) { 1100 if (i) {
1104 /* Compute PEC if first message is a write */ 1101 /* Compute PEC if first message is a write */
1105 if (!(msg[0].flags & I2C_M_RD)) { 1102 if (!(msg[0].flags & I2C_M_RD)) {
1106 if (num == 1) /* Write only */ 1103 if (num == 1) /* Write only */
1107 i2c_smbus_add_pec(&msg[0]); 1104 i2c_smbus_add_pec(&msg[0]);
1108 else /* Write followed by read */ 1105 else /* Write followed by read */
1109 partial_pec = i2c_smbus_msg_pec(0, &msg[0]); 1106 partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
1110 } 1107 }
1111 /* Ask for PEC if last message is a read */ 1108 /* Ask for PEC if last message is a read */
1112 if (msg[num-1].flags & I2C_M_RD) 1109 if (msg[num-1].flags & I2C_M_RD)
1113 msg[num-1].len++; 1110 msg[num-1].len++;
1114 } 1111 }
1115 1112
1116 if (i2c_transfer(adapter, msg, num) < 0) 1113 if (i2c_transfer(adapter, msg, num) < 0)
@@ -1130,7 +1127,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1130 case I2C_SMBUS_BYTE_DATA: 1127 case I2C_SMBUS_BYTE_DATA:
1131 data->byte = msgbuf1[0]; 1128 data->byte = msgbuf1[0];
1132 break; 1129 break;
1133 case I2C_SMBUS_WORD_DATA: 1130 case I2C_SMBUS_WORD_DATA:
1134 case I2C_SMBUS_PROC_CALL: 1131 case I2C_SMBUS_PROC_CALL:
1135 data->word = msgbuf1[0] | (msgbuf1[1] << 8); 1132 data->word = msgbuf1[0] | (msgbuf1[1] << 8);
1136 break; 1133 break;
@@ -1146,7 +1143,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1146 1143
1147 1144
1148s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, 1145s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1149 char read_write, u8 command, int size, 1146 char read_write, u8 command, int size,
1150 union i2c_smbus_data * data) 1147 union i2c_smbus_data * data)
1151{ 1148{
1152 s32 res; 1149 s32 res;
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 94a4e9a3013c..ac5bd2a7ca99 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -1,5 +1,5 @@
1/* 1/*
2 i2c-dev.c - i2c-bus driver, char device interface 2 i2c-dev.c - i2c-bus driver, char device interface
3 3
4 Copyright (C) 1995-97 Simon G. Vogl 4 Copyright (C) 1995-97 Simon G. Vogl
5 Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl> 5 Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl>
@@ -90,6 +90,7 @@ static void return_i2c_dev(struct i2c_dev *i2c_dev)
90 spin_lock(&i2c_dev_list_lock); 90 spin_lock(&i2c_dev_list_lock);
91 list_del(&i2c_dev->list); 91 list_del(&i2c_dev->list);
92 spin_unlock(&i2c_dev_list_lock); 92 spin_unlock(&i2c_dev_list_lock);
93 kfree(i2c_dev);
93} 94}
94 95
95static ssize_t show_adapter_name(struct device *dev, 96static ssize_t show_adapter_name(struct device *dev,
@@ -119,7 +120,7 @@ static ssize_t i2cdev_read (struct file *file, char __user *buf, size_t count,
119 return -ENOMEM; 120 return -ENOMEM;
120 121
121 pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n", 122 pr_debug("i2c-dev: i2c-%d reading %zd bytes.\n",
122 iminor(file->f_dentry->d_inode), count); 123 iminor(file->f_path.dentry->d_inode), count);
123 124
124 ret = i2c_master_recv(client,tmp,count); 125 ret = i2c_master_recv(client,tmp,count);
125 if (ret >= 0) 126 if (ret >= 0)
@@ -147,7 +148,7 @@ static ssize_t i2cdev_write (struct file *file, const char __user *buf, size_t c
147 } 148 }
148 149
149 pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n", 150 pr_debug("i2c-dev: i2c-%d writing %zd bytes.\n",
150 iminor(file->f_dentry->d_inode), count); 151 iminor(file->f_path.dentry->d_inode), count);
151 152
152 ret = i2c_master_send(client,tmp,count); 153 ret = i2c_master_send(client,tmp,count);
153 kfree(tmp); 154 kfree(tmp);
@@ -172,7 +173,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
172 switch ( cmd ) { 173 switch ( cmd ) {
173 case I2C_SLAVE: 174 case I2C_SLAVE:
174 case I2C_SLAVE_FORCE: 175 case I2C_SLAVE_FORCE:
175 if ((arg > 0x3ff) || 176 if ((arg > 0x3ff) ||
176 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) 177 (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f))
177 return -EINVAL; 178 return -EINVAL;
178 if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) 179 if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg))
@@ -193,12 +194,11 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
193 return 0; 194 return 0;
194 case I2C_FUNCS: 195 case I2C_FUNCS:
195 funcs = i2c_get_functionality(client->adapter); 196 funcs = i2c_get_functionality(client->adapter);
196 return (copy_to_user((unsigned long __user *)arg, &funcs, 197 return put_user(funcs, (unsigned long __user *)arg);
197 sizeof(unsigned long)))?-EFAULT:0;
198 198
199 case I2C_RDWR: 199 case I2C_RDWR:
200 if (copy_from_user(&rdwr_arg, 200 if (copy_from_user(&rdwr_arg,
201 (struct i2c_rdwr_ioctl_data __user *)arg, 201 (struct i2c_rdwr_ioctl_data __user *)arg,
202 sizeof(rdwr_arg))) 202 sizeof(rdwr_arg)))
203 return -EFAULT; 203 return -EFAULT;
204 204
@@ -206,9 +206,9 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
206 * be sent at once */ 206 * be sent at once */
207 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS) 207 if (rdwr_arg.nmsgs > I2C_RDRW_IOCTL_MAX_MSGS)
208 return -EINVAL; 208 return -EINVAL;
209 209
210 rdwr_pa = (struct i2c_msg *) 210 rdwr_pa = (struct i2c_msg *)
211 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg), 211 kmalloc(rdwr_arg.nmsgs * sizeof(struct i2c_msg),
212 GFP_KERNEL); 212 GFP_KERNEL);
213 213
214 if (rdwr_pa == NULL) return -ENOMEM; 214 if (rdwr_pa == NULL) return -ENOMEM;
@@ -278,9 +278,9 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
278 (struct i2c_smbus_ioctl_data __user *) arg, 278 (struct i2c_smbus_ioctl_data __user *) arg,
279 sizeof(struct i2c_smbus_ioctl_data))) 279 sizeof(struct i2c_smbus_ioctl_data)))
280 return -EFAULT; 280 return -EFAULT;
281 if ((data_arg.size != I2C_SMBUS_BYTE) && 281 if ((data_arg.size != I2C_SMBUS_BYTE) &&
282 (data_arg.size != I2C_SMBUS_QUICK) && 282 (data_arg.size != I2C_SMBUS_QUICK) &&
283 (data_arg.size != I2C_SMBUS_BYTE_DATA) && 283 (data_arg.size != I2C_SMBUS_BYTE_DATA) &&
284 (data_arg.size != I2C_SMBUS_WORD_DATA) && 284 (data_arg.size != I2C_SMBUS_WORD_DATA) &&
285 (data_arg.size != I2C_SMBUS_PROC_CALL) && 285 (data_arg.size != I2C_SMBUS_PROC_CALL) &&
286 (data_arg.size != I2C_SMBUS_BLOCK_DATA) && 286 (data_arg.size != I2C_SMBUS_BLOCK_DATA) &&
@@ -291,11 +291,11 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
291 data_arg.size); 291 data_arg.size);
292 return -EINVAL; 292 return -EINVAL;
293 } 293 }
294 /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, 294 /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1,
295 so the check is valid if size==I2C_SMBUS_QUICK too. */ 295 so the check is valid if size==I2C_SMBUS_QUICK too. */
296 if ((data_arg.read_write != I2C_SMBUS_READ) && 296 if ((data_arg.read_write != I2C_SMBUS_READ) &&
297 (data_arg.read_write != I2C_SMBUS_WRITE)) { 297 (data_arg.read_write != I2C_SMBUS_WRITE)) {
298 dev_dbg(&client->adapter->dev, 298 dev_dbg(&client->adapter->dev,
299 "read_write out of range (%x) in ioctl I2C_SMBUS.\n", 299 "read_write out of range (%x) in ioctl I2C_SMBUS.\n",
300 data_arg.read_write); 300 data_arg.read_write);
301 return -EINVAL; 301 return -EINVAL;
@@ -304,7 +304,7 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
304 /* Note that command values are always valid! */ 304 /* Note that command values are always valid! */
305 305
306 if ((data_arg.size == I2C_SMBUS_QUICK) || 306 if ((data_arg.size == I2C_SMBUS_QUICK) ||
307 ((data_arg.size == I2C_SMBUS_BYTE) && 307 ((data_arg.size == I2C_SMBUS_BYTE) &&
308 (data_arg.read_write == I2C_SMBUS_WRITE))) 308 (data_arg.read_write == I2C_SMBUS_WRITE)))
309 /* These are special: we do not use data */ 309 /* These are special: we do not use data */
310 return i2c_smbus_xfer(client->adapter, client->addr, 310 return i2c_smbus_xfer(client->adapter, client->addr,
@@ -322,14 +322,14 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
322 if ((data_arg.size == I2C_SMBUS_BYTE_DATA) || 322 if ((data_arg.size == I2C_SMBUS_BYTE_DATA) ||
323 (data_arg.size == I2C_SMBUS_BYTE)) 323 (data_arg.size == I2C_SMBUS_BYTE))
324 datasize = sizeof(data_arg.data->byte); 324 datasize = sizeof(data_arg.data->byte);
325 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || 325 else if ((data_arg.size == I2C_SMBUS_WORD_DATA) ||
326 (data_arg.size == I2C_SMBUS_PROC_CALL)) 326 (data_arg.size == I2C_SMBUS_PROC_CALL))
327 datasize = sizeof(data_arg.data->word); 327 datasize = sizeof(data_arg.data->word);
328 else /* size == smbus block, i2c block, or block proc. call */ 328 else /* size == smbus block, i2c block, or block proc. call */
329 datasize = sizeof(data_arg.data->block); 329 datasize = sizeof(data_arg.data->block);
330 330
331 if ((data_arg.size == I2C_SMBUS_PROC_CALL) || 331 if ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
332 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 332 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
333 (data_arg.read_write == I2C_SMBUS_WRITE)) { 333 (data_arg.read_write == I2C_SMBUS_WRITE)) {
334 if (copy_from_user(&temp, data_arg.data, datasize)) 334 if (copy_from_user(&temp, data_arg.data, datasize))
335 return -EFAULT; 335 return -EFAULT;
@@ -337,8 +337,8 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
337 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, 337 res = i2c_smbus_xfer(client->adapter,client->addr,client->flags,
338 data_arg.read_write, 338 data_arg.read_write,
339 data_arg.command,data_arg.size,&temp); 339 data_arg.command,data_arg.size,&temp);
340 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || 340 if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) ||
341 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) || 341 (data_arg.size == I2C_SMBUS_BLOCK_PROC_CALL) ||
342 (data_arg.read_write == I2C_SMBUS_READ))) { 342 (data_arg.read_write == I2C_SMBUS_READ))) {
343 if (copy_to_user(data_arg.data, &temp, datasize)) 343 if (copy_to_user(data_arg.data, &temp, datasize))
344 return -EFAULT; 344 return -EFAULT;
@@ -417,8 +417,8 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
417 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev, 417 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
418 MKDEV(I2C_MAJOR, adap->nr), 418 MKDEV(I2C_MAJOR, adap->nr),
419 "i2c-%d", adap->nr); 419 "i2c-%d", adap->nr);
420 if (!i2c_dev->dev) { 420 if (IS_ERR(i2c_dev->dev)) {
421 res = -ENODEV; 421 res = PTR_ERR(i2c_dev->dev);
422 goto error; 422 goto error;
423 } 423 }
424 res = device_create_file(i2c_dev->dev, &dev_attr_name); 424 res = device_create_file(i2c_dev->dev, &dev_attr_name);
@@ -432,7 +432,6 @@ error_destroy:
432 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 432 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
433error: 433error:
434 return_i2c_dev(i2c_dev); 434 return_i2c_dev(i2c_dev);
435 kfree(i2c_dev);
436 return res; 435 return res;
437} 436}
438 437
@@ -447,7 +446,6 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
447 device_remove_file(i2c_dev->dev, &dev_attr_name); 446 device_remove_file(i2c_dev->dev, &dev_attr_name);
448 return_i2c_dev(i2c_dev); 447 return_i2c_dev(i2c_dev);
449 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr)); 448 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, adap->nr));
450 kfree(i2c_dev);
451 449
452 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name); 450 pr_debug("i2c-dev: adapter [%s] unregistered\n", adap->name);
453 return 0; 451 return 0;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 88214943d00a..5969cec58dc1 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -687,8 +687,15 @@ static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 sta
687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) 687static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
688{ 688{
689 struct request *rq = HWGROUP(drive)->rq; 689 struct request *rq = HWGROUP(drive)->rq;
690 ide_hwif_t *hwif = HWIF(drive);
690 int stat, err, sense_key; 691 int stat, err, sense_key;
691 692
693 /* We may have bogus DMA interrupts in PIO state here */
694 if (HWIF(drive)->dma_status && hwif->atapi_irq_bogon) {
695 stat = hwif->INB(hwif->dma_status);
696 /* Should we force the bit as well ? */
697 hwif->OUTB(stat, hwif->dma_status);
698 }
692 /* Check for errors. */ 699 /* Check for errors. */
693 stat = HWIF(drive)->INB(IDE_STATUS_REG); 700 stat = HWIF(drive)->INB(IDE_STATUS_REG);
694 if (stat_ret) 701 if (stat_ret)
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index dad9c47ebb69..5a5c565a32a8 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1000,10 +1000,6 @@ static int ide_init_queue(ide_drive_t *drive)
1000 /* needs drive->queue to be set */ 1000 /* needs drive->queue to be set */
1001 ide_toggle_bounce(drive, 1); 1001 ide_toggle_bounce(drive, 1);
1002 1002
1003 /* enable led activity for disk drives only */
1004 if (drive->media == ide_disk && hwif->led_act)
1005 blk_queue_activity_fn(q, hwif->led_act, drive);
1006
1007 return 0; 1003 return 0;
1008} 1004}
1009 1005
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index d419e4bb54f4..89109be5162c 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -586,11 +586,11 @@ static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const c
586{ 586{
587 unsigned long flags; 587 unsigned long flags;
588 u8 tmpbyte; 588 u8 tmpbyte;
589 struct pci_dev *north = pci_find_slot(0, PCI_DEVFN(0,0)); 589 struct pci_dev *north = pci_get_slot(dev->bus, PCI_DEVFN(0,0));
590 590
591 pci_read_config_byte(dev, PCI_REVISION_ID, &m5229_revision); 591 pci_read_config_byte(dev, PCI_REVISION_ID, &m5229_revision);
592 592
593 isa_dev = pci_find_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 593 isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
594 594
595#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) 595#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS)
596 if (!ali_proc) { 596 if (!ali_proc) {
@@ -613,8 +613,7 @@ static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const c
613 * clear bit 7 613 * clear bit 7
614 */ 614 */
615 pci_write_config_byte(dev, 0x4b, tmpbyte & 0x7F); 615 pci_write_config_byte(dev, 0x4b, tmpbyte & 0x7F);
616 local_irq_restore(flags); 616 goto out;
617 return 0;
618 } 617 }
619 618
620 /* 619 /*
@@ -637,10 +636,8 @@ static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const c
637 * box without a device at 0:0.0. The ALi bridge will be at 636 * box without a device at 0:0.0. The ALi bridge will be at
638 * 0:0.0 so if we didn't find one we know what is cooking. 637 * 0:0.0 so if we didn't find one we know what is cooking.
639 */ 638 */
640 if (north && north->vendor != PCI_VENDOR_ID_AL) { 639 if (north && north->vendor != PCI_VENDOR_ID_AL)
641 local_irq_restore(flags); 640 goto out;
642 return 0;
643 }
644 641
645 if (m5229_revision < 0xC5 && isa_dev) 642 if (m5229_revision < 0xC5 && isa_dev)
646 { 643 {
@@ -661,6 +658,9 @@ static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const c
661 pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x02); 658 pci_write_config_byte(isa_dev, 0x79, tmpbyte | 0x02);
662 } 659 }
663 } 660 }
661out:
662 pci_dev_put(north);
663 pci_dev_put(isa_dev);
664 local_irq_restore(flags); 664 local_irq_restore(flags);
665 return 0; 665 return 0;
666} 666}
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 6c097e80b4df..7cb48576e479 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -9,6 +9,7 @@
9 * Split from: 9 * Split from:
10 * linux/drivers/ide/pdc202xx.c Version 0.35 Mar. 30, 2002 10 * linux/drivers/ide/pdc202xx.c Version 0.35 Mar. 30, 2002
11 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 11 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
12 * Copyright (C) 2005-2006 MontaVista Software, Inc.
12 * Portions Copyright (C) 1999 Promise Technology, Inc. 13 * Portions Copyright (C) 1999 Promise Technology, Inc.
13 * Author: Frank Tiernan (frankt@promise.com) 14 * Author: Frank Tiernan (frankt@promise.com)
14 * Released under terms of General Public License 15 * Released under terms of General Public License
@@ -38,6 +39,14 @@
38 39
39#define PDC202_DEBUG_CABLE 0 40#define PDC202_DEBUG_CABLE 0
40 41
42#undef DEBUG
43
44#ifdef DEBUG
45#define DBG(fmt, args...) printk("%s: " fmt, __FUNCTION__, ## args)
46#else
47#define DBG(fmt, args...)
48#endif
49
41static const char *pdc_quirk_drives[] = { 50static const char *pdc_quirk_drives[] = {
42 "QUANTUM FIREBALLlct08 08", 51 "QUANTUM FIREBALLlct08 08",
43 "QUANTUM FIREBALLP KA6.4", 52 "QUANTUM FIREBALLP KA6.4",
@@ -50,37 +59,11 @@ static const char *pdc_quirk_drives[] = {
50 NULL 59 NULL
51}; 60};
52 61
53#define set_2regs(a, b) \ 62static u8 max_dma_rate(struct pci_dev *pdev)
54 do { \
55 hwif->OUTB((a + adj), indexreg); \
56 hwif->OUTB(b, datareg); \
57 } while(0)
58
59#define set_ultra(a, b, c) \
60 do { \
61 set_2regs(0x10,(a)); \
62 set_2regs(0x11,(b)); \
63 set_2regs(0x12,(c)); \
64 } while(0)
65
66#define set_ata2(a, b) \
67 do { \
68 set_2regs(0x0e,(a)); \
69 set_2regs(0x0f,(b)); \
70 } while(0)
71
72#define set_pio(a, b, c) \
73 do { \
74 set_2regs(0x0c,(a)); \
75 set_2regs(0x0d,(b)); \
76 set_2regs(0x13,(c)); \
77 } while(0)
78
79static u8 pdcnew_ratemask (ide_drive_t *drive)
80{ 63{
81 u8 mode; 64 u8 mode;
82 65
83 switch(HWIF(drive)->pci_dev->device) { 66 switch(pdev->device) {
84 case PCI_DEVICE_ID_PROMISE_20277: 67 case PCI_DEVICE_ID_PROMISE_20277:
85 case PCI_DEVICE_ID_PROMISE_20276: 68 case PCI_DEVICE_ID_PROMISE_20276:
86 case PCI_DEVICE_ID_PROMISE_20275: 69 case PCI_DEVICE_ID_PROMISE_20275:
@@ -95,12 +78,21 @@ static u8 pdcnew_ratemask (ide_drive_t *drive)
95 default: 78 default:
96 return 0; 79 return 0;
97 } 80 }
98 if (!eighty_ninty_three(drive)) 81
99 mode = min(mode, (u8)1);
100 return mode; 82 return mode;
101} 83}
102 84
103static int check_in_drive_lists (ide_drive_t *drive, const char **list) 85static u8 pdcnew_ratemask(ide_drive_t *drive)
86{
87 u8 mode = max_dma_rate(HWIF(drive)->pci_dev);
88
89 if (!eighty_ninty_three(drive))
90 mode = min_t(u8, mode, 1);
91
92 return mode;
93}
94
95static int check_in_drive_lists(ide_drive_t *drive, const char **list)
104{ 96{
105 struct hd_driveid *id = drive->id; 97 struct hd_driveid *id = drive->id;
106 98
@@ -120,43 +112,141 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list)
120 return 0; 112 return 0;
121} 113}
122 114
123static int pdcnew_new_tune_chipset (ide_drive_t *drive, u8 xferspeed) 115/**
116 * get_indexed_reg - Get indexed register
117 * @hwif: for the port address
118 * @index: index of the indexed register
119 */
120static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
121{
122 u8 value;
123
124 hwif->OUTB(index, hwif->dma_vendor1);
125 value = hwif->INB(hwif->dma_vendor3);
126
127 DBG("index[%02X] value[%02X]\n", index, value);
128 return value;
129}
130
131/**
132 * set_indexed_reg - Set indexed register
133 * @hwif: for the port address
134 * @index: index of the indexed register
135 */
136static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value)
137{
138 hwif->OUTB(index, hwif->dma_vendor1);
139 hwif->OUTB(value, hwif->dma_vendor3);
140 DBG("index[%02X] value[%02X]\n", index, value);
141}
142
143/*
144 * ATA Timing Tables based on 133 MHz PLL output clock.
145 *
146 * If the PLL outputs 100 MHz clock, the ASIC hardware will set
147 * the timing registers automatically when "set features" command is
148 * issued to the device. However, if the PLL output clock is 133 MHz,
149 * the following tables must be used.
150 */
151static struct pio_timing {
152 u8 reg0c, reg0d, reg13;
153} pio_timings [] = {
154 { 0xfb, 0x2b, 0xac }, /* PIO mode 0, IORDY off, Prefetch off */
155 { 0x46, 0x29, 0xa4 }, /* PIO mode 1, IORDY off, Prefetch off */
156 { 0x23, 0x26, 0x64 }, /* PIO mode 2, IORDY off, Prefetch off */
157 { 0x27, 0x0d, 0x35 }, /* PIO mode 3, IORDY on, Prefetch off */
158 { 0x23, 0x09, 0x25 }, /* PIO mode 4, IORDY on, Prefetch off */
159};
160
161static struct mwdma_timing {
162 u8 reg0e, reg0f;
163} mwdma_timings [] = {
164 { 0xdf, 0x5f }, /* MWDMA mode 0 */
165 { 0x6b, 0x27 }, /* MWDMA mode 1 */
166 { 0x69, 0x25 }, /* MWDMA mode 2 */
167};
168
169static struct udma_timing {
170 u8 reg10, reg11, reg12;
171} udma_timings [] = {
172 { 0x4a, 0x0f, 0xd5 }, /* UDMA mode 0 */
173 { 0x3a, 0x0a, 0xd0 }, /* UDMA mode 1 */
174 { 0x2a, 0x07, 0xcd }, /* UDMA mode 2 */
175 { 0x1a, 0x05, 0xcd }, /* UDMA mode 3 */
176 { 0x1a, 0x03, 0xcd }, /* UDMA mode 4 */
177 { 0x1a, 0x02, 0xcb }, /* UDMA mode 5 */
178 { 0x1a, 0x01, 0xcb }, /* UDMA mode 6 */
179};
180
181static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
124{ 182{
125 ide_hwif_t *hwif = HWIF(drive); 183 ide_hwif_t *hwif = HWIF(drive);
126 unsigned long indexreg = hwif->dma_vendor1; 184 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
127 unsigned long datareg = hwif->dma_vendor3; 185 int err;
128 u8 thold = 0x10;
129 u8 adj = (drive->dn%2) ? 0x08 : 0x00;
130 u8 speed = ide_rate_filter(pdcnew_ratemask(drive), xferspeed);
131
132 if (speed == XFER_UDMA_2) {
133 hwif->OUTB((thold + adj), indexreg);
134 hwif->OUTB((hwif->INB(datareg) & 0x7f), datareg);
135 }
136 186
137 switch (speed) { 187 speed = ide_rate_filter(pdcnew_ratemask(drive), speed);
138 case XFER_UDMA_7: 188
139 speed = XFER_UDMA_6; 189 /*
140 case XFER_UDMA_6: set_ultra(0x1a, 0x01, 0xcb); break; 190 * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will
141 case XFER_UDMA_5: set_ultra(0x1a, 0x02, 0xcb); break; 191 * automatically set the timing registers based on 100 MHz PLL output.
142 case XFER_UDMA_4: set_ultra(0x1a, 0x03, 0xcd); break; 192 */
143 case XFER_UDMA_3: set_ultra(0x1a, 0x05, 0xcd); break; 193 err = ide_config_drive_speed(drive, speed);
144 case XFER_UDMA_2: set_ultra(0x2a, 0x07, 0xcd); break; 194
145 case XFER_UDMA_1: set_ultra(0x3a, 0x0a, 0xd0); break; 195 /*
146 case XFER_UDMA_0: set_ultra(0x4a, 0x0f, 0xd5); break; 196 * As we set up the PLL to output 133 MHz for UltraDMA/133 capable
147 case XFER_MW_DMA_2: set_ata2(0x69, 0x25); break; 197 * chips, we must override the default register settings...
148 case XFER_MW_DMA_1: set_ata2(0x6b, 0x27); break; 198 */
149 case XFER_MW_DMA_0: set_ata2(0xdf, 0x5f); break; 199 if (max_dma_rate(hwif->pci_dev) == 4) {
150 case XFER_PIO_4: set_pio(0x23, 0x09, 0x25); break; 200 u8 mode = speed & 0x07;
151 case XFER_PIO_3: set_pio(0x27, 0x0d, 0x35); break; 201
152 case XFER_PIO_2: set_pio(0x23, 0x26, 0x64); break; 202 switch (speed) {
153 case XFER_PIO_1: set_pio(0x46, 0x29, 0xa4); break; 203 case XFER_UDMA_6:
154 case XFER_PIO_0: set_pio(0xfb, 0x2b, 0xac); break; 204 case XFER_UDMA_5:
155 default: 205 case XFER_UDMA_4:
156 ; 206 case XFER_UDMA_3:
157 } 207 case XFER_UDMA_2:
208 case XFER_UDMA_1:
209 case XFER_UDMA_0:
210 set_indexed_reg(hwif, 0x10 + adj,
211 udma_timings[mode].reg10);
212 set_indexed_reg(hwif, 0x11 + adj,
213 udma_timings[mode].reg11);
214 set_indexed_reg(hwif, 0x12 + adj,
215 udma_timings[mode].reg12);
216 break;
217
218 case XFER_MW_DMA_2:
219 case XFER_MW_DMA_1:
220 case XFER_MW_DMA_0:
221 set_indexed_reg(hwif, 0x0e + adj,
222 mwdma_timings[mode].reg0e);
223 set_indexed_reg(hwif, 0x0f + adj,
224 mwdma_timings[mode].reg0f);
225 break;
226 case XFER_PIO_4:
227 case XFER_PIO_3:
228 case XFER_PIO_2:
229 case XFER_PIO_1:
230 case XFER_PIO_0:
231 set_indexed_reg(hwif, 0x0c + adj,
232 pio_timings[mode].reg0c);
233 set_indexed_reg(hwif, 0x0d + adj,
234 pio_timings[mode].reg0d);
235 set_indexed_reg(hwif, 0x13 + adj,
236 pio_timings[mode].reg13);
237 break;
238 default:
239 printk(KERN_ERR "pdc202xx_new: "
240 "Unknown speed %d ignored\n", speed);
241 }
242 } else if (speed == XFER_UDMA_2) {
243 /* Set tHOLD bit to 0 if using UDMA mode 2 */
244 u8 tmp = get_indexed_reg(hwif, 0x10 + adj);
158 245
159 return (ide_config_drive_speed(drive, speed)); 246 set_indexed_reg(hwif, 0x10 + adj, tmp & 0x7f);
247 }
248
249 return err;
160} 250}
161 251
162/* 0 1 2 3 4 5 6 7 8 252/* 0 1 2 3 4 5 6 7 8
@@ -168,55 +258,55 @@ static int pdcnew_new_tune_chipset (ide_drive_t *drive, u8 xferspeed)
168 */ 258 */
169static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio) 259static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio)
170{ 260{
171 u8 speed; 261 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
172 262 (void)pdcnew_tune_chipset(drive, XFER_PIO_0 + pio);
173 if (pio == 5) pio = 4;
174 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, pio, NULL);
175
176 (void)pdcnew_new_tune_chipset(drive, speed);
177} 263}
178 264
179static u8 pdcnew_new_cable_detect (ide_hwif_t *hwif) 265static u8 pdcnew_cable_detect(ide_hwif_t *hwif)
180{ 266{
181 hwif->OUTB(0x0b, hwif->dma_vendor1); 267 return get_indexed_reg(hwif, 0x0b) & 0x04;
182 return ((u8)((hwif->INB(hwif->dma_vendor3) & 0x04)));
183} 268}
184static int config_chipset_for_dma (ide_drive_t *drive) 269
270static int config_chipset_for_dma(ide_drive_t *drive)
185{ 271{
186 struct hd_driveid *id = drive->id; 272 struct hd_driveid *id = drive->id;
187 ide_hwif_t *hwif = HWIF(drive); 273 ide_hwif_t *hwif = HWIF(drive);
188 u8 speed = -1; 274 u8 ultra_66 = (id->dma_ultra & 0x0078) ? 1 : 0;
189 u8 cable; 275 u8 cable = pdcnew_cable_detect(hwif);
190 276 u8 speed;
191 u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
192 (id->dma_ultra & 0x0008)) ? 1 : 0;
193
194 cable = pdcnew_new_cable_detect(hwif);
195 277
196 if (ultra_66 && cable) { 278 if (ultra_66 && cable) {
197 printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary"); 279 printk(KERN_WARNING "Warning: %s channel "
280 "requires an 80-pin cable for operation.\n",
281 hwif->channel ? "Secondary" : "Primary");
198 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name); 282 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
199 } 283 }
200 284
201 if (drive->media != ide_disk) 285 if (drive->media != ide_disk)
202 return 0; 286 return 0;
203 if (id->capability & 4) { /* IORDY_EN & PREFETCH_EN */ 287
204 hwif->OUTB((0x13 + ((drive->dn%2) ? 0x08 : 0x00)), hwif->dma_vendor1); 288 if (id->capability & 4) {
205 hwif->OUTB((hwif->INB(hwif->dma_vendor3)|0x03), hwif->dma_vendor3); 289 /*
290 * Set IORDY_EN & PREFETCH_EN (this seems to have
291 * NO real effect since this register is reloaded
292 * by hardware when the transfer mode is selected)
293 */
294 u8 tmp, adj = (drive->dn & 1) ? 0x08 : 0x00;
295
296 tmp = get_indexed_reg(hwif, 0x13 + adj);
297 set_indexed_reg(hwif, 0x13 + adj, tmp | 0x03);
206 } 298 }
207 299
208 speed = ide_dma_speed(drive, pdcnew_ratemask(drive)); 300 speed = ide_dma_speed(drive, pdcnew_ratemask(drive));
209 301
210 if (!(speed)) { 302 if (!speed)
211 hwif->tuneproc(drive, 5);
212 return 0; 303 return 0;
213 }
214 304
215 (void) hwif->speedproc(drive, speed); 305 (void) hwif->speedproc(drive, speed);
216 return ide_dma_enable(drive); 306 return ide_dma_enable(drive);
217} 307}
218 308
219static int pdcnew_config_drive_xfer_rate (ide_drive_t *drive) 309static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
220{ 310{
221 ide_hwif_t *hwif = HWIF(drive); 311 ide_hwif_t *hwif = HWIF(drive);
222 struct hd_driveid *id = drive->id; 312 struct hd_driveid *id = drive->id;
@@ -234,16 +324,16 @@ static int pdcnew_config_drive_xfer_rate (ide_drive_t *drive)
234 324
235 } else if ((id->capability & 8) || (id->field_valid & 2)) { 325 } else if ((id->capability & 8) || (id->field_valid & 2)) {
236fast_ata_pio: 326fast_ata_pio:
237 hwif->tuneproc(drive, 5); 327 hwif->tuneproc(drive, 255);
238 return hwif->ide_dma_off_quietly(drive); 328 return hwif->ide_dma_off_quietly(drive);
239 } 329 }
240 /* IORDY not supported */ 330 /* IORDY not supported */
241 return 0; 331 return 0;
242} 332}
243 333
244static int pdcnew_quirkproc (ide_drive_t *drive) 334static int pdcnew_quirkproc(ide_drive_t *drive)
245{ 335{
246 return ((int) check_in_drive_lists(drive, pdc_quirk_drives)); 336 return check_in_drive_lists(drive, pdc_quirk_drives);
247} 337}
248 338
249static int pdcnew_ide_dma_lostirq(ide_drive_t *drive) 339static int pdcnew_ide_dma_lostirq(ide_drive_t *drive)
@@ -260,21 +350,100 @@ static int pdcnew_ide_dma_timeout(ide_drive_t *drive)
260 return __ide_dma_timeout(drive); 350 return __ide_dma_timeout(drive);
261} 351}
262 352
263static void pdcnew_new_reset (ide_drive_t *drive) 353static void pdcnew_reset(ide_drive_t *drive)
264{ 354{
265 /* 355 /*
266 * Deleted this because it is redundant from the caller. 356 * Deleted this because it is redundant from the caller.
267 */ 357 */
268 printk(KERN_WARNING "PDC202XX: %s channel reset.\n", 358 printk(KERN_WARNING "pdc202xx_new: %s channel reset.\n",
269 HWIF(drive)->channel ? "Secondary" : "Primary"); 359 HWIF(drive)->channel ? "Secondary" : "Primary");
270} 360}
271 361
362/**
363 * read_counter - Read the byte count registers
364 * @dma_base: for the port address
365 */
366static long __devinit read_counter(u32 dma_base)
367{
368 u32 pri_dma_base = dma_base, sec_dma_base = dma_base + 0x08;
369 u8 cnt0, cnt1, cnt2, cnt3;
370 long count = 0, last;
371 int retry = 3;
372
373 do {
374 last = count;
375
376 /* Read the current count */
377 outb(0x20, pri_dma_base + 0x01);
378 cnt0 = inb(pri_dma_base + 0x03);
379 outb(0x21, pri_dma_base + 0x01);
380 cnt1 = inb(pri_dma_base + 0x03);
381 outb(0x20, sec_dma_base + 0x01);
382 cnt2 = inb(sec_dma_base + 0x03);
383 outb(0x21, sec_dma_base + 0x01);
384 cnt3 = inb(sec_dma_base + 0x03);
385
386 count = (cnt3 << 23) | (cnt2 << 15) | (cnt1 << 8) | cnt0;
387
388 /*
389 * The 30-bit decrementing counter is read in 4 pieces.
390 * Incorrect value may be read when the most significant bytes
391 * are changing...
392 */
393 } while (retry-- && (((last ^ count) & 0x3fff8000) || last < count));
394
395 DBG("cnt0[%02X] cnt1[%02X] cnt2[%02X] cnt3[%02X]\n",
396 cnt0, cnt1, cnt2, cnt3);
397
398 return count;
399}
400
401/**
402 * detect_pll_input_clock - Detect the PLL input clock in Hz.
403 * @dma_base: for the port address
404 * E.g. 16949000 on 33 MHz PCI bus, i.e. half of the PCI clock.
405 */
406static long __devinit detect_pll_input_clock(unsigned long dma_base)
407{
408 long start_count, end_count;
409 long pll_input;
410 u8 scr1;
411
412 start_count = read_counter(dma_base);
413
414 /* Start the test mode */
415 outb(0x01, dma_base + 0x01);
416 scr1 = inb(dma_base + 0x03);
417 DBG("scr1[%02X]\n", scr1);
418 outb(scr1 | 0x40, dma_base + 0x03);
419
420 /* Let the counter run for 10 ms. */
421 mdelay(10);
422
423 end_count = read_counter(dma_base);
424
425 /* Stop the test mode */
426 outb(0x01, dma_base + 0x01);
427 scr1 = inb(dma_base + 0x03);
428 DBG("scr1[%02X]\n", scr1);
429 outb(scr1 & ~0x40, dma_base + 0x03);
430
431 /*
432 * Calculate the input clock in Hz
433 * (the clock counter is 30 bit wide and counts down)
434 */
435 pll_input = ((start_count - end_count) & 0x3ffffff) * 100;
436
437 DBG("start[%ld] end[%ld]\n", start_count, end_count);
438
439 return pll_input;
440}
441
272#ifdef CONFIG_PPC_PMAC 442#ifdef CONFIG_PPC_PMAC
273static void __devinit apple_kiwi_init(struct pci_dev *pdev) 443static void __devinit apple_kiwi_init(struct pci_dev *pdev)
274{ 444{
275 struct device_node *np = pci_device_to_OF_node(pdev); 445 struct device_node *np = pci_device_to_OF_node(pdev);
276 unsigned int class_rev = 0; 446 unsigned int class_rev = 0;
277 void __iomem *mmio;
278 u8 conf; 447 u8 conf;
279 448
280 if (np == NULL || !device_is_compatible(np, "kiwi-root")) 449 if (np == NULL || !device_is_compatible(np, "kiwi-root"))
@@ -285,30 +454,20 @@ static void __devinit apple_kiwi_init(struct pci_dev *pdev)
285 454
286 if (class_rev >= 0x03) { 455 if (class_rev >= 0x03) {
287 /* Setup chip magic config stuff (from darwin) */ 456 /* Setup chip magic config stuff (from darwin) */
288 pci_read_config_byte(pdev, 0x40, &conf); 457 pci_read_config_byte (pdev, 0x40, &conf);
289 pci_write_config_byte(pdev, 0x40, conf | 0x01); 458 pci_write_config_byte(pdev, 0x40, (conf | 0x01));
290 }
291 mmio = ioremap(pci_resource_start(pdev, 5),
292 pci_resource_len(pdev, 5));
293
294 /* Setup some PLL stuffs */
295 switch (pdev->device) {
296 case PCI_DEVICE_ID_PROMISE_20270:
297 writew(0x0d2b, mmio + 0x1202);
298 mdelay(30);
299 break;
300 case PCI_DEVICE_ID_PROMISE_20271:
301 writew(0x0826, mmio + 0x1202);
302 mdelay(30);
303 break;
304 } 459 }
305
306 iounmap(mmio);
307} 460}
308#endif /* CONFIG_PPC_PMAC */ 461#endif /* CONFIG_PPC_PMAC */
309 462
310static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const char *name) 463static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const char *name)
311{ 464{
465 unsigned long dma_base = pci_resource_start(dev, 4);
466 unsigned long sec_dma_base = dma_base + 0x08;
467 long pll_input, pll_output, ratio;
468 int f, r;
469 u8 pll_ctl0, pll_ctl1;
470
312 if (dev->resource[PCI_ROM_RESOURCE].start) { 471 if (dev->resource[PCI_ROM_RESOURCE].start) {
313 pci_write_config_dword(dev, PCI_ROM_ADDRESS, 472 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
314 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE); 473 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
@@ -320,6 +479,106 @@ static unsigned int __devinit init_chipset_pdcnew(struct pci_dev *dev, const cha
320 apple_kiwi_init(dev); 479 apple_kiwi_init(dev);
321#endif 480#endif
322 481
482 /* Calculate the required PLL output frequency */
483 switch(max_dma_rate(dev)) {
484 case 4: /* it's 133 MHz for Ultra133 chips */
485 pll_output = 133333333;
486 break;
487 case 3: /* and 100 MHz for Ultra100 chips */
488 default:
489 pll_output = 100000000;
490 break;
491 }
492
493 /*
494 * Detect PLL input clock.
495 * On some systems, where PCI bus is running at non-standard clock rate
496 * (e.g. 25 or 40 MHz), we have to adjust the cycle time.
497 * PDC20268 and newer chips employ PLL circuit to help correct timing
498 * registers setting.
499 */
500 pll_input = detect_pll_input_clock(dma_base);
501 printk("%s: PLL input clock is %ld kHz\n", name, pll_input / 1000);
502
503 /* Sanity check */
504 if (unlikely(pll_input < 5000000L || pll_input > 70000000L)) {
505 printk(KERN_ERR "%s: Bad PLL input clock %ld Hz, giving up!\n",
506 name, pll_input);
507 goto out;
508 }
509
510#ifdef DEBUG
511 DBG("pll_output is %ld Hz\n", pll_output);
512
513 /* Show the current clock value of PLL control register
514 * (maybe already configured by the BIOS)
515 */
516 outb(0x02, sec_dma_base + 0x01);
517 pll_ctl0 = inb(sec_dma_base + 0x03);
518 outb(0x03, sec_dma_base + 0x01);
519 pll_ctl1 = inb(sec_dma_base + 0x03);
520
521 DBG("pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
522#endif
523
524 /*
525 * Calculate the ratio of F, R and NO
526 * POUT = (F + 2) / (( R + 2) * NO)
527 */
528 ratio = pll_output / (pll_input / 1000);
529 if (ratio < 8600L) { /* 8.6x */
530 /* Using NO = 0x01, R = 0x0d */
531 r = 0x0d;
532 } else if (ratio < 12900L) { /* 12.9x */
533 /* Using NO = 0x01, R = 0x08 */
534 r = 0x08;
535 } else if (ratio < 16100L) { /* 16.1x */
536 /* Using NO = 0x01, R = 0x06 */
537 r = 0x06;
538 } else if (ratio < 64000L) { /* 64x */
539 r = 0x00;
540 } else {
541 /* Invalid ratio */
542 printk(KERN_ERR "%s: Bad ratio %ld, giving up!\n", name, ratio);
543 goto out;
544 }
545
546 f = (ratio * (r + 2)) / 1000 - 2;
547
548 DBG("F[%d] R[%d] ratio*1000[%ld]\n", f, r, ratio);
549
550 if (unlikely(f < 0 || f > 127)) {
551 /* Invalid F */
552 printk(KERN_ERR "%s: F[%d] invalid!\n", name, f);
553 goto out;
554 }
555
556 pll_ctl0 = (u8) f;
557 pll_ctl1 = (u8) r;
558
559 DBG("Writing pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
560
561 outb(0x02, sec_dma_base + 0x01);
562 outb(pll_ctl0, sec_dma_base + 0x03);
563 outb(0x03, sec_dma_base + 0x01);
564 outb(pll_ctl1, sec_dma_base + 0x03);
565
566 /* Wait the PLL circuit to be stable */
567 mdelay(30);
568
569#ifdef DEBUG
570 /*
571 * Show the current clock value of PLL control register
572 */
573 outb(0x02, sec_dma_base + 0x01);
574 pll_ctl0 = inb(sec_dma_base + 0x03);
575 outb(0x03, sec_dma_base + 0x01);
576 pll_ctl1 = inb(sec_dma_base + 0x03);
577
578 DBG("pll_ctl[%02X][%02X]\n", pll_ctl0, pll_ctl1);
579#endif
580
581 out:
323 return dev->irq; 582 return dev->irq;
324} 583}
325 584
@@ -329,8 +588,8 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
329 588
330 hwif->tuneproc = &pdcnew_tune_drive; 589 hwif->tuneproc = &pdcnew_tune_drive;
331 hwif->quirkproc = &pdcnew_quirkproc; 590 hwif->quirkproc = &pdcnew_quirkproc;
332 hwif->speedproc = &pdcnew_new_tune_chipset; 591 hwif->speedproc = &pdcnew_tune_chipset;
333 hwif->resetproc = &pdcnew_new_reset; 592 hwif->resetproc = &pdcnew_reset;
334 593
335 hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 594 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
336 595
@@ -342,11 +601,14 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
342 hwif->ide_dma_check = &pdcnew_config_drive_xfer_rate; 601 hwif->ide_dma_check = &pdcnew_config_drive_xfer_rate;
343 hwif->ide_dma_lostirq = &pdcnew_ide_dma_lostirq; 602 hwif->ide_dma_lostirq = &pdcnew_ide_dma_lostirq;
344 hwif->ide_dma_timeout = &pdcnew_ide_dma_timeout; 603 hwif->ide_dma_timeout = &pdcnew_ide_dma_timeout;
345 if (!(hwif->udma_four)) 604
346 hwif->udma_four = (pdcnew_new_cable_detect(hwif)) ? 0 : 1; 605 if (!hwif->udma_four)
606 hwif->udma_four = pdcnew_cable_detect(hwif) ? 0 : 1;
607
347 if (!noautodma) 608 if (!noautodma)
348 hwif->autodma = 1; 609 hwif->autodma = 1;
349 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma; 610 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
611
350#if PDC202_DEBUG_CABLE 612#if PDC202_DEBUG_CABLE
351 printk(KERN_DEBUG "%s: %s-pin cable\n", 613 printk(KERN_DEBUG "%s: %s-pin cable\n",
352 hwif->name, hwif->udma_four ? "80" : "40"); 614 hwif->name, hwif->udma_four ? "80" : "40");
@@ -362,6 +624,7 @@ static int __devinit init_setup_pdc20270(struct pci_dev *dev,
362 ide_pci_device_t *d) 624 ide_pci_device_t *d)
363{ 625{
364 struct pci_dev *findev = NULL; 626 struct pci_dev *findev = NULL;
627 int ret;
365 628
366 if ((dev->bus->self && 629 if ((dev->bus->self &&
367 dev->bus->self->vendor == PCI_VENDOR_ID_DEC) && 630 dev->bus->self->vendor == PCI_VENDOR_ID_DEC) &&
@@ -369,14 +632,16 @@ static int __devinit init_setup_pdc20270(struct pci_dev *dev,
369 if (PCI_SLOT(dev->devfn) & 2) 632 if (PCI_SLOT(dev->devfn) & 2)
370 return -ENODEV; 633 return -ENODEV;
371 d->extra = 0; 634 d->extra = 0;
372 while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) { 635 while ((findev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {
373 if ((findev->vendor == dev->vendor) && 636 if ((findev->vendor == dev->vendor) &&
374 (findev->device == dev->device) && 637 (findev->device == dev->device) &&
375 (PCI_SLOT(findev->devfn) & 2)) { 638 (PCI_SLOT(findev->devfn) & 2)) {
376 if (findev->irq != dev->irq) { 639 if (findev->irq != dev->irq) {
377 findev->irq = dev->irq; 640 findev->irq = dev->irq;
378 } 641 }
379 return ide_setup_pci_devices(dev, findev, d); 642 ret = ide_setup_pci_devices(dev, findev, d);
643 pci_dev_put(findev);
644 return ret;
380 } 645 }
381 } 646 }
382 } 647 }
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index cdc3aab9ebcb..b1e9a8eba6b6 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -505,6 +505,10 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
505 /* This is a painful system best to let it self tune for now */ 505 /* This is a painful system best to let it self tune for now */
506 return; 506 return;
507 } 507 }
508 /* ESB2 appears to generate spurious DMA interrupts in PIO mode
509 when in native mode */
510 if (hwif->pci_dev->device == PCI_DEVICE_ID_INTEL_ESB2_18)
511 hwif->atapi_irq_bogon = 1;
508 512
509 hwif->autodma = 0; 513 hwif->autodma = 0;
510 hwif->tuneproc = &piix_tune_drive; 514 hwif->tuneproc = &piix_tune_drive;
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 92edf76bd7ad..6b313139b5e4 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -800,9 +800,10 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
800 800
801 if (trueid == 0x5517) { /* SiS 961/961B */ 801 if (trueid == 0x5517) { /* SiS 961/961B */
802 802
803 lpc_bridge = pci_find_slot(0x00, 0x10); /* Bus 0, Dev 2, Fn 0 */ 803 lpc_bridge = pci_get_slot(dev->bus, 0x10); /* Bus 0, Dev 2, Fn 0 */
804 pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev); 804 pci_read_config_byte(lpc_bridge, PCI_REVISION_ID, &sbrev);
805 pci_read_config_byte(dev, 0x49, &prefctl); 805 pci_read_config_byte(dev, 0x49, &prefctl);
806 pci_dev_put(lpc_bridge);
806 807
807 if (sbrev == 0x10 && (prefctl & 0x80)) { 808 if (sbrev == 0x10 && (prefctl & 0x80)) {
808 printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n"); 809 printk(KERN_INFO "SIS5513: SiS 961B MuTIOL IDE UDMA133 controller\n");
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 0b4b60498515..5afefe8692fe 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -299,14 +299,14 @@ static void sl82c105_selectproc(ide_drive_t *drive)
299 //DBG(("sl82c105_selectproc(drive:%s)\n", drive->name)); 299 //DBG(("sl82c105_selectproc(drive:%s)\n", drive->name));
300 300
301 mask = hwif->channel ? CTRL_P1F16 : CTRL_P0F16; 301 mask = hwif->channel ? CTRL_P1F16 : CTRL_P0F16;
302 old = val = *((u32 *)&hwif->hwif_data); 302 old = val = (u32)pci_get_drvdata(dev);
303 if (drive->using_dma) 303 if (drive->using_dma)
304 val &= ~mask; 304 val &= ~mask;
305 else 305 else
306 val |= mask; 306 val |= mask;
307 if (old != val) { 307 if (old != val) {
308 pci_write_config_dword(dev, 0x40, val); 308 pci_write_config_dword(dev, 0x40, val);
309 *((u32 *)&hwif->hwif_data) = val; 309 pci_set_drvdata(dev, (void *)val);
310 } 310 }
311} 311}
312 312
@@ -316,14 +316,13 @@ static void sl82c105_selectproc(ide_drive_t *drive)
316 */ 316 */
317static void sl82c105_resetproc(ide_drive_t *drive) 317static void sl82c105_resetproc(ide_drive_t *drive)
318{ 318{
319 ide_hwif_t *hwif = HWIF(drive); 319 struct pci_dev *dev = HWIF(drive)->pci_dev;
320 struct pci_dev *dev = hwif->pci_dev;
321 u32 val; 320 u32 val;
322 321
323 DBG(("sl82c105_resetproc(drive:%s)\n", drive->name)); 322 DBG(("sl82c105_resetproc(drive:%s)\n", drive->name));
324 323
325 pci_read_config_dword(dev, 0x40, &val); 324 pci_read_config_dword(dev, 0x40, &val);
326 *((u32 *)&hwif->hwif_data) = val; 325 pci_set_drvdata(dev, (void *)val);
327} 326}
328 327
329/* 328/*
@@ -394,6 +393,7 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
394 pci_read_config_dword(dev, 0x40, &val); 393 pci_read_config_dword(dev, 0x40, &val);
395 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16; 394 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16;
396 pci_write_config_dword(dev, 0x40, val); 395 pci_write_config_dword(dev, 0x40, val);
396 pci_set_drvdata(dev, (void *)val);
397 397
398 return dev->irq; 398 return dev->irq;
399} 399}
@@ -404,30 +404,25 @@ static unsigned int __devinit init_chipset_sl82c105(struct pci_dev *dev, const c
404 404
405static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif) 405static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
406{ 406{
407 struct pci_dev *dev = hwif->pci_dev;
408 unsigned int rev; 407 unsigned int rev;
409 u8 dma_state; 408 u8 dma_state;
410 u32 val; 409
411
412 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 410 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
413 411
414 hwif->tuneproc = tune_sl82c105; 412 hwif->tuneproc = tune_sl82c105;
415 hwif->selectproc = sl82c105_selectproc; 413 hwif->selectproc = sl82c105_selectproc;
416 hwif->resetproc = sl82c105_resetproc; 414 hwif->resetproc = sl82c105_resetproc;
417 415
418 /* Default to PIO 0 for fallback unless tuned otherwise, 416 /*
419 * we always autotune PIO, this is done before DMA is 417 * Default to PIO 0 for fallback unless tuned otherwise.
420 * checked, so there is no risk of accidentally disabling 418 * We always autotune PIO, this is done before DMA is checked,
421 * DMA 419 * so there's no risk of accidentally disabling DMA
422 */ 420 */
423 hwif->drives[0].pio_speed = XFER_PIO_0; 421 hwif->drives[0].pio_speed = XFER_PIO_0;
424 hwif->drives[0].autotune = 1; 422 hwif->drives[0].autotune = 1;
425 hwif->drives[1].pio_speed = XFER_PIO_1; 423 hwif->drives[1].pio_speed = XFER_PIO_0;
426 hwif->drives[1].autotune = 1; 424 hwif->drives[1].autotune = 1;
427 425
428 pci_read_config_dword(dev, 0x40, &val);
429 *((u32 *)&hwif->hwif_data) = val;
430
431 hwif->atapi_dma = 0; 426 hwif->atapi_dma = 0;
432 hwif->mwdma_mask = 0; 427 hwif->mwdma_mask = 0;
433 hwif->swdma_mask = 0; 428 hwif->swdma_mask = 0;
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 0719b6484824..695e23904d30 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -844,11 +844,11 @@ void __init ide_scan_pcibus (int scan_direction)
844 844
845 pre_init = 0; 845 pre_init = 0;
846 if (!scan_direction) { 846 if (!scan_direction) {
847 while ((dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 847 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
848 ide_scan_pcidev(dev); 848 ide_scan_pcidev(dev);
849 } 849 }
850 } else { 850 } else {
851 while ((dev = pci_find_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { 851 while ((dev = pci_get_device_reverse(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
852 ide_scan_pcidev(dev); 852 ide_scan_pcidev(dev);
853 } 853 }
854 } 854 }
diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h
index af4a78a8ef3b..536ba3f580fd 100644
--- a/drivers/ieee1394/ieee1394_core.h
+++ b/drivers/ieee1394/ieee1394_core.h
@@ -217,7 +217,7 @@ void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
217/* return the index (within a minor number block) of a file */ 217/* return the index (within a minor number block) of a file */
218static inline unsigned char ieee1394_file_to_instance(struct file *file) 218static inline unsigned char ieee1394_file_to_instance(struct file *file)
219{ 219{
220 return file->f_dentry->d_inode->i_cindex; 220 return file->f_path.dentry->d_inode->i_cindex;
221} 221}
222 222
223extern int hpsb_disable_irm; 223extern int hpsb_disable_irm;
diff --git a/drivers/ieee1394/pcilynx.c b/drivers/ieee1394/pcilynx.c
index 13a617917bf2..fbb7f14ec509 100644
--- a/drivers/ieee1394/pcilynx.c
+++ b/drivers/ieee1394/pcilynx.c
@@ -1485,7 +1485,7 @@ static int __devinit add_card(struct pci_dev *dev,
1485 1485
1486 } 1486 }
1487 1487
1488 i2c_bit_del_bus(i2c_ad); 1488 i2c_del_adapter(i2c_ad);
1489 kfree(i2c_ad); 1489 kfree(i2c_ad);
1490 } 1490 }
1491 } 1491 }
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index 4e16314e8e6d..a617ca7b6923 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -534,9 +534,9 @@ struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
534 * module reference. 534 * module reference.
535 */ 535 */
536 filp->f_op = fops_get(&uverbs_event_fops); 536 filp->f_op = fops_get(&uverbs_event_fops);
537 filp->f_vfsmnt = mntget(uverbs_event_mnt); 537 filp->f_path.mnt = mntget(uverbs_event_mnt);
538 filp->f_dentry = dget(uverbs_event_mnt->mnt_root); 538 filp->f_path.dentry = dget(uverbs_event_mnt->mnt_root);
539 filp->f_mapping = filp->f_dentry->d_inode->i_mapping; 539 filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
540 filp->f_flags = O_RDONLY; 540 filp->f_flags = O_RDONLY;
541 filp->f_mode = FMODE_READ; 541 filp->f_mode = FMODE_READ;
542 filp->private_data = ev_file; 542 filp->private_data = ev_file;
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index a9ddc6911f66..340f27e3ebff 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -1745,9 +1745,9 @@ static int ipath_assign_port(struct file *fp,
1745 goto done; 1745 goto done;
1746 } 1746 }
1747 1747
1748 i_minor = iminor(fp->f_dentry->d_inode) - IPATH_USER_MINOR_BASE; 1748 i_minor = iminor(fp->f_path.dentry->d_inode) - IPATH_USER_MINOR_BASE;
1749 ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n", 1749 ipath_cdbg(VERBOSE, "open on dev %lx (minor %d)\n",
1750 (long)fp->f_dentry->d_inode->i_rdev, i_minor); 1750 (long)fp->f_path.dentry->d_inode->i_rdev, i_minor);
1751 1751
1752 if (i_minor) 1752 if (i_minor)
1753 ret = find_free_port(i_minor - 1, fp, uinfo); 1753 ret = find_free_port(i_minor - 1, fp, uinfo);
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
index d9ff283f725e..79a60f020a21 100644
--- a/drivers/infiniband/hw/ipath/ipath_fs.c
+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
@@ -118,7 +118,7 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
118 u16 i; 118 u16 i;
119 struct ipath_devdata *dd; 119 struct ipath_devdata *dd;
120 120
121 dd = file->f_dentry->d_inode->i_private; 121 dd = file->f_path.dentry->d_inode->i_private;
122 122
123 for (i = 0; i < NUM_COUNTERS; i++) 123 for (i = 0; i < NUM_COUNTERS; i++)
124 counters[i] = ipath_snap_cntr(dd, i); 124 counters[i] = ipath_snap_cntr(dd, i);
@@ -138,7 +138,7 @@ static ssize_t atomic_node_info_read(struct file *file, char __user *buf,
138 struct ipath_devdata *dd; 138 struct ipath_devdata *dd;
139 u64 guid; 139 u64 guid;
140 140
141 dd = file->f_dentry->d_inode->i_private; 141 dd = file->f_path.dentry->d_inode->i_private;
142 142
143 guid = be64_to_cpu(dd->ipath_guid); 143 guid = be64_to_cpu(dd->ipath_guid);
144 144
@@ -177,7 +177,7 @@ static ssize_t atomic_port_info_read(struct file *file, char __user *buf,
177 u32 tmp, tmp2; 177 u32 tmp, tmp2;
178 struct ipath_devdata *dd; 178 struct ipath_devdata *dd;
179 179
180 dd = file->f_dentry->d_inode->i_private; 180 dd = file->f_path.dentry->d_inode->i_private;
181 181
182 /* so we only initialize non-zero fields. */ 182 /* so we only initialize non-zero fields. */
183 memset(portinfo, 0, sizeof portinfo); 183 memset(portinfo, 0, sizeof portinfo);
@@ -324,7 +324,7 @@ static ssize_t flash_read(struct file *file, char __user *buf,
324 goto bail; 324 goto bail;
325 } 325 }
326 326
327 dd = file->f_dentry->d_inode->i_private; 327 dd = file->f_path.dentry->d_inode->i_private;
328 if (ipath_eeprom_read(dd, pos, tmp, count)) { 328 if (ipath_eeprom_read(dd, pos, tmp, count)) {
329 ipath_dev_err(dd, "failed to read from flash\n"); 329 ipath_dev_err(dd, "failed to read from flash\n");
330 ret = -ENXIO; 330 ret = -ENXIO;
@@ -377,7 +377,7 @@ static ssize_t flash_write(struct file *file, const char __user *buf,
377 goto bail_tmp; 377 goto bail_tmp;
378 } 378 }
379 379
380 dd = file->f_dentry->d_inode->i_private; 380 dd = file->f_path.dentry->d_inode->i_private;
381 if (ipath_eeprom_write(dd, pos, tmp, count)) { 381 if (ipath_eeprom_write(dd, pos, tmp, count)) {
382 ret = -ENXIO; 382 ret = -ENXIO;
383 ipath_dev_err(dd, "failed to write to flash\n"); 383 ipath_dev_err(dd, "failed to write to flash\n");
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 21422a3336ad..7ec7c4b937f9 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -124,7 +124,7 @@ static int mthca_query_device(struct ib_device *ibdev,
124 props->max_map_per_fmr = 255; 124 props->max_map_per_fmr = 255;
125 else 125 else
126 props->max_map_per_fmr = 126 props->max_map_per_fmr =
127 (1 << (32 - long_log2(mdev->limits.num_mpts))) - 1; 127 (1 << (32 - ilog2(mdev->limits.num_mpts))) - 1;
128 128
129 err = 0; 129 err = 0;
130 out: 130 out:
@@ -816,7 +816,7 @@ static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *uda
816 lkey = ucmd.lkey; 816 lkey = ucmd.lkey;
817 } 817 }
818 818
819 ret = mthca_RESIZE_CQ(dev, cq->cqn, lkey, long_log2(entries), &status); 819 ret = mthca_RESIZE_CQ(dev, cq->cqn, lkey, ilog2(entries), &status);
820 if (status) 820 if (status)
821 ret = -EINVAL; 821 ret = -EINVAL;
822 822
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index 33e3ba7937f1..d844a2569b47 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -636,11 +636,11 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
636 636
637 if (mthca_is_memfree(dev)) { 637 if (mthca_is_memfree(dev)) {
638 if (qp->rq.max) 638 if (qp->rq.max)
639 qp_context->rq_size_stride = long_log2(qp->rq.max) << 3; 639 qp_context->rq_size_stride = ilog2(qp->rq.max) << 3;
640 qp_context->rq_size_stride |= qp->rq.wqe_shift - 4; 640 qp_context->rq_size_stride |= qp->rq.wqe_shift - 4;
641 641
642 if (qp->sq.max) 642 if (qp->sq.max)
643 qp_context->sq_size_stride = long_log2(qp->sq.max) << 3; 643 qp_context->sq_size_stride = ilog2(qp->sq.max) << 3;
644 qp_context->sq_size_stride |= qp->sq.wqe_shift - 4; 644 qp_context->sq_size_stride |= qp->sq.wqe_shift - 4;
645 } 645 }
646 646
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 34d2c4768962..10684da33d58 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -120,7 +120,7 @@ static void mthca_arbel_init_srq_context(struct mthca_dev *dev,
120 120
121 memset(context, 0, sizeof *context); 121 memset(context, 0, sizeof *context);
122 122
123 logsize = long_log2(srq->max); 123 logsize = ilog2(srq->max);
124 context->state_logsize_srqn = cpu_to_be32(logsize << 24 | srq->srqn); 124 context->state_logsize_srqn = cpu_to_be32(logsize << 24 | srq->srqn);
125 context->lkey = cpu_to_be32(srq->mr.ibmr.lkey); 125 context->lkey = cpu_to_be32(srq->mr.ibmr.lkey);
126 context->db_index = cpu_to_be32(srq->db_index); 126 context->db_index = cpu_to_be32(srq->db_index);
@@ -213,7 +213,7 @@ int mthca_alloc_srq(struct mthca_dev *dev, struct mthca_pd *pd,
213 if (!mthca_is_memfree(dev) && (ds > dev->limits.max_desc_sz)) 213 if (!mthca_is_memfree(dev) && (ds > dev->limits.max_desc_sz))
214 return -EINVAL; 214 return -EINVAL;
215 215
216 srq->wqe_shift = long_log2(ds); 216 srq->wqe_shift = ilog2(ds);
217 217
218 srq->srqn = mthca_alloc(&dev->srq_table.alloc); 218 srq->srqn = mthca_alloc(&dev->srq_table.alloc);
219 if (srq->srqn == -1) 219 if (srq->srqn == -1)
diff --git a/drivers/infiniband/ulp/iser/iser_memory.c b/drivers/infiniband/ulp/iser/iser_memory.c
index 5e122501fd80..3aedd59b8a84 100644
--- a/drivers/infiniband/ulp/iser/iser_memory.c
+++ b/drivers/infiniband/ulp/iser/iser_memory.c
@@ -114,7 +114,7 @@ int iser_start_rdma_unaligned_sg(struct iscsi_iser_cmd_task *iser_ctask,
114 114
115 if (cmd_data_len > ISER_KMALLOC_THRESHOLD) 115 if (cmd_data_len > ISER_KMALLOC_THRESHOLD)
116 mem = (void *)__get_free_pages(GFP_NOIO, 116 mem = (void *)__get_free_pages(GFP_NOIO,
117 long_log2(roundup_pow_of_two(cmd_data_len)) - PAGE_SHIFT); 117 ilog2(roundup_pow_of_two(cmd_data_len)) - PAGE_SHIFT);
118 else 118 else
119 mem = kmalloc(cmd_data_len, GFP_NOIO); 119 mem = kmalloc(cmd_data_len, GFP_NOIO);
120 120
@@ -211,7 +211,7 @@ void iser_finalize_rdma_unaligned_sg(struct iscsi_iser_cmd_task *iser_ctask,
211 211
212 if (cmd_data_len > ISER_KMALLOC_THRESHOLD) 212 if (cmd_data_len > ISER_KMALLOC_THRESHOLD)
213 free_pages((unsigned long)mem_copy->copy_buf, 213 free_pages((unsigned long)mem_copy->copy_buf,
214 long_log2(roundup_pow_of_two(cmd_data_len)) - PAGE_SHIFT); 214 ilog2(roundup_pow_of_two(cmd_data_len)) - PAGE_SHIFT);
215 else 215 else
216 kfree(mem_copy->copy_buf); 216 kfree(mem_copy->copy_buf);
217 217
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index a005b1df5f1a..da575deb3c7a 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -21,3 +21,4 @@ obj-$(CONFIG_INPUT_MOUSE) += mouse/
21obj-$(CONFIG_INPUT_JOYSTICK) += joystick/ 21obj-$(CONFIG_INPUT_JOYSTICK) += joystick/
22obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/ 22obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
23obj-$(CONFIG_INPUT_MISC) += misc/ 23obj-$(CONFIG_INPUT_MISC) += misc/
24
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c
index 35656cadc914..783b3412cead 100644
--- a/drivers/input/ff-core.c
+++ b/drivers/input/ff-core.c
@@ -203,7 +203,7 @@ static int erase_effect(struct input_dev *dev, int effect_id,
203} 203}
204 204
205/** 205/**
206 * input_ff_erase - erase an effect from device 206 * input_ff_erase - erase a force-feedback effect from device
207 * @dev: input device to erase effect from 207 * @dev: input device to erase effect from
208 * @effect_id: id of the ffect to be erased 208 * @effect_id: id of the ffect to be erased
209 * @file: purported owner of the request 209 * @file: purported owner of the request
@@ -347,7 +347,7 @@ EXPORT_SYMBOL_GPL(input_ff_create);
347 347
348/** 348/**
349 * input_ff_free() - frees force feedback portion of input device 349 * input_ff_free() - frees force feedback portion of input device
350 * @dev: input device supporintg force feedback 350 * @dev: input device supporting force feedback
351 * 351 *
352 * This function is only needed in error path as input core will 352 * This function is only needed in error path as input core will
353 * automatically free force feedback structures when device is 353 * automatically free force feedback structures when device is
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index cd8b7297e6df..eba18b6ac5e4 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -460,7 +460,7 @@ static void ml_ff_destroy(struct ff_device *ff)
460} 460}
461 461
462/** 462/**
463 * input_ff_create_memless() - create memoryless FF device 463 * input_ff_create_memless() - create memoryless force-feedback device
464 * @dev: input device supporting force-feedback 464 * @dev: input device supporting force-feedback
465 * @data: driver-specific data to be passed into @play_effect 465 * @data: driver-specific data to be passed into @play_effect
466 * @play_effect: driver-specific method for playing FF effect 466 * @play_effect: driver-specific method for playing FF effect
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index 79dfb4b25c97..a00fe470a829 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -731,12 +731,6 @@ static int gameport_driver_remove(struct device *dev)
731 return 0; 731 return 0;
732} 732}
733 733
734static struct bus_type gameport_bus = {
735 .name = "gameport",
736 .probe = gameport_driver_probe,
737 .remove = gameport_driver_remove,
738};
739
740static void gameport_add_driver(struct gameport_driver *drv) 734static void gameport_add_driver(struct gameport_driver *drv)
741{ 735{
742 int error; 736 int error;
@@ -782,6 +776,15 @@ static int gameport_bus_match(struct device *dev, struct device_driver *drv)
782 return !gameport_drv->ignore; 776 return !gameport_drv->ignore;
783} 777}
784 778
779static struct bus_type gameport_bus = {
780 .name = "gameport",
781 .dev_attrs = gameport_device_attrs,
782 .drv_attrs = gameport_driver_attrs,
783 .match = gameport_bus_match,
784 .probe = gameport_driver_probe,
785 .remove = gameport_driver_remove,
786};
787
785static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv) 788static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *drv)
786{ 789{
787 mutex_lock(&gameport->drv_mutex); 790 mutex_lock(&gameport->drv_mutex);
@@ -791,7 +794,6 @@ static void gameport_set_drv(struct gameport *gameport, struct gameport_driver *
791 794
792int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode) 795int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode)
793{ 796{
794
795 if (gameport->open) { 797 if (gameport->open) {
796 if (gameport->open(gameport, mode)) { 798 if (gameport->open(gameport, mode)) {
797 return -1; 799 return -1;
@@ -819,9 +821,6 @@ static int __init gameport_init(void)
819{ 821{
820 int error; 822 int error;
821 823
822 gameport_bus.dev_attrs = gameport_device_attrs;
823 gameport_bus.drv_attrs = gameport_driver_attrs;
824 gameport_bus.match = gameport_bus_match;
825 error = bus_register(&gameport_bus); 824 error = bus_register(&gameport_bus);
826 if (error) { 825 if (error) {
827 printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error); 826 printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error);
diff --git a/drivers/input/gameport/lightning.c b/drivers/input/gameport/lightning.c
index d65d81080257..6b4d4561d465 100644
--- a/drivers/input/gameport/lightning.c
+++ b/drivers/input/gameport/lightning.c
@@ -309,7 +309,7 @@ static int __init l4_init(void)
309 int i, cards = 0; 309 int i, cards = 0;
310 310
311 if (!request_region(L4_PORT, 1, "lightning")) 311 if (!request_region(L4_PORT, 1, "lightning"))
312 return -1; 312 return -EBUSY;
313 313
314 for (i = 0; i < 2; i++) 314 for (i = 0; i < 2; i++)
315 if (l4_add_card(i) == 0) 315 if (l4_add_card(i) == 0)
@@ -319,7 +319,7 @@ static int __init l4_init(void)
319 319
320 if (!cards) { 320 if (!cards) {
321 release_region(L4_PORT, 1); 321 release_region(L4_PORT, 1);
322 return -1; 322 return -ENODEV;
323 } 323 }
324 324
325 return 0; 325 return 0;
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 1c8c8a5bc4a9..7cf2b4f603a3 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -37,7 +37,7 @@ static struct input_handler *input_table[8];
37 37
38/** 38/**
39 * input_event() - report new input event 39 * input_event() - report new input event
40 * @handle: device that generated the event 40 * @dev: device that generated the event
41 * @type: type of the event 41 * @type: type of the event
42 * @code: event code 42 * @code: event code
43 * @value: value of the event 43 * @value: value of the event
@@ -900,6 +900,15 @@ struct class input_class = {
900}; 900};
901EXPORT_SYMBOL_GPL(input_class); 901EXPORT_SYMBOL_GPL(input_class);
902 902
903/**
904 * input_allocate_device - allocate memory for new input device
905 *
906 * Returns prepared struct input_dev or NULL.
907 *
908 * NOTE: Use input_free_device() to free devices that have not been
909 * registered; input_unregister_device() should be used for already
910 * registered devices.
911 */
903struct input_dev *input_allocate_device(void) 912struct input_dev *input_allocate_device(void)
904{ 913{
905 struct input_dev *dev; 914 struct input_dev *dev;
@@ -919,6 +928,20 @@ struct input_dev *input_allocate_device(void)
919} 928}
920EXPORT_SYMBOL(input_allocate_device); 929EXPORT_SYMBOL(input_allocate_device);
921 930
931/**
932 * input_free_device - free memory occupied by input_dev structure
933 * @dev: input device to free
934 *
935 * This function should only be used if input_register_device()
936 * was not called yet or if it failed. Once device was registered
937 * use input_unregister_device() and memory will be freed once last
938 * refrence to the device is dropped.
939 *
940 * Device should be allocated by input_allocate_device().
941 *
942 * NOTE: If there are references to the input device then memory
943 * will not be freed until last reference is dropped.
944 */
922void input_free_device(struct input_dev *dev) 945void input_free_device(struct input_dev *dev)
923{ 946{
924 if (dev) { 947 if (dev) {
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index 704bf70f1db7..6279ced8a35b 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -521,11 +521,19 @@ static int adi_connect(struct gameport *gameport, struct gameport_driver *drv)
521 for (i = 0; i < 2; i++) 521 for (i = 0; i < 2; i++)
522 if (port->adi[i].length > 0) { 522 if (port->adi[i].length > 0) {
523 adi_init_center(port->adi + i); 523 adi_init_center(port->adi + i);
524 input_register_device(port->adi[i].dev); 524 err = input_register_device(port->adi[i].dev);
525 if (err)
526 goto fail3;
525 } 527 }
526 528
527 return 0; 529 return 0;
528 530
531 fail3: while (--i >= 0) {
532 if (port->adi[i].length > 0) {
533 input_unregister_device(port->adi[i].dev);
534 port->adi[i].dev = NULL;
535 }
536 }
529 fail2: for (i = 0; i < 2; i++) 537 fail2: for (i = 0; i < 2; i++)
530 if (port->adi[i].dev) 538 if (port->adi[i].dev)
531 input_free_device(port->adi[i].dev); 539 input_free_device(port->adi[i].dev);
diff --git a/drivers/input/joystick/amijoy.c b/drivers/input/joystick/amijoy.c
index 650acf3a30b7..e608691b5a61 100644
--- a/drivers/input/joystick/amijoy.c
+++ b/drivers/input/joystick/amijoy.c
@@ -147,7 +147,11 @@ static int __init amijoy_init(void)
147 amijoy_dev[i]->absmax[ABS_X + j] = 1; 147 amijoy_dev[i]->absmax[ABS_X + j] = 1;
148 } 148 }
149 149
150 input_register_device(amijoy_dev[i]); 150 err = input_register_device(amijoy_dev[i]);
151 if (err) {
152 input_free_device(amijoy_dev[i]);
153 goto fail;
154 }
151 } 155 }
152 return 0; 156 return 0;
153 157
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index e9a02db36ecc..7ef68456d7d6 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -434,6 +434,7 @@ static int analog_init_device(struct analog_port *port, struct analog *analog, i
434{ 434{
435 struct input_dev *input_dev; 435 struct input_dev *input_dev;
436 int i, j, t, v, w, x, y, z; 436 int i, j, t, v, w, x, y, z;
437 int error;
437 438
438 analog_name(analog); 439 analog_name(analog);
439 snprintf(analog->phys, sizeof(analog->phys), 440 snprintf(analog->phys, sizeof(analog->phys),
@@ -505,7 +506,11 @@ static int analog_init_device(struct analog_port *port, struct analog *analog, i
505 506
506 analog_decode(analog, port->axes, port->initial, port->buttons); 507 analog_decode(analog, port->axes, port->initial, port->buttons);
507 508
508 input_register_device(analog->dev); 509 error = input_register_device(analog->dev);
510 if (error) {
511 input_free_device(analog->dev);
512 return error;
513 }
509 514
510 return 0; 515 return 0;
511} 516}
@@ -668,7 +673,8 @@ static int analog_connect(struct gameport *gameport, struct gameport_driver *drv
668 return 0; 673 return 0;
669 674
670 fail3: while (--i >= 0) 675 fail3: while (--i >= 0)
671 input_unregister_device(port->analog[i].dev); 676 if (port->analog[i].mask)
677 input_unregister_device(port->analog[i].dev);
672 fail2: gameport_close(gameport); 678 fail2: gameport_close(gameport);
673 fail1: gameport_set_drvdata(gameport, NULL); 679 fail1: gameport_set_drvdata(gameport, NULL);
674 kfree(port); 680 kfree(port);
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index d5e42eb88a20..034ec39c251d 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -223,12 +223,15 @@ static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
223 for (j = 0; cobra_btn[j]; j++) 223 for (j = 0; cobra_btn[j]; j++)
224 set_bit(cobra_btn[j], input_dev->keybit); 224 set_bit(cobra_btn[j], input_dev->keybit);
225 225
226 input_register_device(cobra->dev[i]); 226 err = input_register_device(cobra->dev[i]);
227 if (err)
228 goto fail4;
227 } 229 }
228 230
229 return 0; 231 return 0;
230 232
231 fail3: for (i = 0; i < 2; i++) 233 fail4: input_free_device(cobra->dev[i]);
234 fail3: while (--i >= 0)
232 if (cobra->dev[i]) 235 if (cobra->dev[i])
233 input_unregister_device(cobra->dev[i]); 236 input_unregister_device(cobra->dev[i]);
234 fail2: gameport_close(gameport); 237 fail2: gameport_close(gameport);
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index e4a699f6ec87..bacbab5d1b6f 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -341,7 +341,9 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
342 } 342 }
343 343
344 input_register_device(gf2k->dev); 344 err = input_register_device(gf2k->dev);
345 if (err)
346 goto fail2;
345 347
346 return 0; 348 return 0;
347 349
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 62438944a69a..8120a9c40773 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -423,7 +423,10 @@ static int get_and_decode_packet(struct grip_mp *grip, int flags)
423 423
424 if (!port->registered) { 424 if (!port->registered) {
425 dbg("New Grip pad in multiport slot %d.\n", slot); 425 dbg("New Grip pad in multiport slot %d.\n", slot);
426 register_slot(slot, grip); 426 if (register_slot(slot, grip)) {
427 port->mode = GRIP_MODE_RESET;
428 port->dirty = 0;
429 }
427 } 430 }
428 return flags; 431 return flags;
429 } 432 }
@@ -585,6 +588,7 @@ static int register_slot(int slot, struct grip_mp *grip)
585 struct grip_port *port = grip->port[slot]; 588 struct grip_port *port = grip->port[slot];
586 struct input_dev *input_dev; 589 struct input_dev *input_dev;
587 int j, t; 590 int j, t;
591 int err;
588 592
589 port->dev = input_dev = input_allocate_device(); 593 port->dev = input_dev = input_allocate_device();
590 if (!input_dev) 594 if (!input_dev)
@@ -610,7 +614,12 @@ static int register_slot(int slot, struct grip_mp *grip)
610 if (t > 0) 614 if (t > 0)
611 set_bit(t, input_dev->keybit); 615 set_bit(t, input_dev->keybit);
612 616
613 input_register_device(port->dev); 617 err = input_register_device(port->dev);
618 if (err) {
619 input_free_device(port->dev);
620 return err;
621 }
622
614 port->registered = 1; 623 port->registered = 1;
615 624
616 if (port->dirty) /* report initial state, if any */ 625 if (port->dirty) /* report initial state, if any */
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index 840ed9b512b2..dbc5d92858b8 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -250,7 +250,9 @@ static int guillemot_connect(struct gameport *gameport, struct gameport_driver *
250 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++) 250 for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
251 set_bit(t, input_dev->keybit); 251 set_bit(t, input_dev->keybit);
252 252
253 input_register_device(guillemot->dev); 253 err = input_register_device(guillemot->dev);
254 if (err)
255 goto fail2;
254 256
255 return 0; 257 return 0;
256 258
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index 24c684bc6337..3393a37fec39 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -325,8 +325,8 @@ int iforce_init_device(struct iforce *iforce)
325 325
326 if (i == 20) { /* 5 seconds */ 326 if (i == 20) { /* 5 seconds */
327 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n"); 327 printk(KERN_ERR "iforce-main.c: Timeout waiting for response from device.\n");
328 input_free_device(input_dev); 328 error = -ENODEV;
329 return -ENODEV; 329 goto fail;
330 } 330 }
331 331
332/* 332/*
@@ -439,10 +439,8 @@ int iforce_init_device(struct iforce *iforce)
439 set_bit(iforce->type->ff[i], input_dev->ffbit); 439 set_bit(iforce->type->ff[i], input_dev->ffbit);
440 440
441 error = input_ff_create(input_dev, ff_effects); 441 error = input_ff_create(input_dev, ff_effects);
442 if (error) { 442 if (error)
443 input_free_device(input_dev); 443 goto fail;
444 return error;
445 }
446 444
447 ff = input_dev->ff; 445 ff = input_dev->ff;
448 ff->upload = iforce_upload_effect; 446 ff->upload = iforce_upload_effect;
@@ -455,22 +453,35 @@ int iforce_init_device(struct iforce *iforce)
455 * Register input device. 453 * Register input device.
456 */ 454 */
457 455
458 input_register_device(iforce->dev); 456 error = input_register_device(iforce->dev);
457 if (error)
458 goto fail;
459 459
460 printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open); 460 printk(KERN_DEBUG "iforce->dev->open = %p\n", iforce->dev->open);
461 461
462 return 0; 462 return 0;
463
464 fail: input_free_device(input_dev);
465 return error;
463} 466}
464 467
465static int __init iforce_init(void) 468static int __init iforce_init(void)
466{ 469{
470 int err = 0;
471
467#ifdef CONFIG_JOYSTICK_IFORCE_USB 472#ifdef CONFIG_JOYSTICK_IFORCE_USB
468 usb_register(&iforce_usb_driver); 473 err = usb_register(&iforce_usb_driver);
474 if (err)
475 return err;
469#endif 476#endif
470#ifdef CONFIG_JOYSTICK_IFORCE_232 477#ifdef CONFIG_JOYSTICK_IFORCE_232
471 serio_register_driver(&iforce_serio_drv); 478 err = serio_register_driver(&iforce_serio_drv);
479#ifdef CONFIG_JOYSTICK_IFORCE_USB
480 if (err)
481 usb_deregister(&iforce_usb_driver);
472#endif 482#endif
473 return 0; 483#endif
484 return err;
474} 485}
475 486
476static void __exit iforce_exit(void) 487static void __exit iforce_exit(void)
diff --git a/drivers/input/joystick/iforce/iforce-serio.c b/drivers/input/joystick/iforce/iforce-serio.c
index ca08f45c2040..ec4be535f483 100644
--- a/drivers/input/joystick/iforce/iforce-serio.c
+++ b/drivers/input/joystick/iforce/iforce-serio.c
@@ -141,21 +141,19 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
141 serio_set_drvdata(serio, iforce); 141 serio_set_drvdata(serio, iforce);
142 142
143 err = serio_open(serio, drv); 143 err = serio_open(serio, drv);
144 if (err) { 144 if (err)
145 serio_set_drvdata(serio, NULL); 145 goto fail1;
146 kfree(iforce);
147 return err;
148 }
149 146
150 err = iforce_init_device(iforce); 147 err = iforce_init_device(iforce);
151 if (err) { 148 if (err)
152 serio_close(serio); 149 goto fail2;
153 serio_set_drvdata(serio, NULL);
154 kfree(iforce);
155 return -ENODEV;
156 }
157 150
158 return 0; 151 return 0;
152
153 fail2: serio_close(serio);
154 fail1: serio_set_drvdata(serio, NULL);
155 kfree(iforce);
156 return err;
159} 157}
160 158
161static void iforce_serio_disconnect(struct serio *serio) 159static void iforce_serio_disconnect(struct serio *serio)
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index bbfeb9c59b87..fec8b3d0967d 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -283,7 +283,9 @@ static int interact_connect(struct gameport *gameport, struct gameport_driver *d
283 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++) 283 for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
284 set_bit(t, input_dev->keybit); 284 set_bit(t, input_dev->keybit);
285 285
286 input_register_device(interact->dev); 286 err = input_register_device(interact->dev);
287 if (err)
288 goto fail2;
287 289
288 return 0; 290 return 0;
289 291
diff --git a/drivers/input/joystick/magellan.c b/drivers/input/joystick/magellan.c
index e3d19444ba2e..4112789f1196 100644
--- a/drivers/input/joystick/magellan.c
+++ b/drivers/input/joystick/magellan.c
@@ -157,7 +157,7 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
157 magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL); 157 magellan = kzalloc(sizeof(struct magellan), GFP_KERNEL);
158 input_dev = input_allocate_device(); 158 input_dev = input_allocate_device();
159 if (!magellan || !input_dev) 159 if (!magellan || !input_dev)
160 goto fail; 160 goto fail1;
161 161
162 magellan->dev = input_dev; 162 magellan->dev = input_dev;
163 snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys); 163 snprintf(magellan->phys, sizeof(magellan->phys), "%s/input0", serio->phys);
@@ -183,13 +183,17 @@ static int magellan_connect(struct serio *serio, struct serio_driver *drv)
183 183
184 err = serio_open(serio, drv); 184 err = serio_open(serio, drv);
185 if (err) 185 if (err)
186 goto fail; 186 goto fail2;
187
188 err = input_register_device(magellan->dev);
189 if (err)
190 goto fail3;
187 191
188 input_register_device(magellan->dev);
189 return 0; 192 return 0;
190 193
191 fail: serio_set_drvdata(serio, NULL); 194 fail3: serio_close(serio);
192 input_free_device(input_dev); 195 fail2: serio_set_drvdata(serio, NULL);
196 fail1: input_free_device(input_dev);
193 kfree(magellan); 197 kfree(magellan);
194 return err; 198 return err;
195} 199}
@@ -227,8 +231,7 @@ static struct serio_driver magellan_drv = {
227 231
228static int __init magellan_init(void) 232static int __init magellan_init(void)
229{ 233{
230 serio_register_driver(&magellan_drv); 234 return serio_register_driver(&magellan_drv);
231 return 0;
232} 235}
233 236
234static void __exit magellan_exit(void) 237static void __exit magellan_exit(void)
diff --git a/drivers/input/joystick/spaceball.c b/drivers/input/joystick/spaceball.c
index 2a9808cf826f..08bf113e62eb 100644
--- a/drivers/input/joystick/spaceball.c
+++ b/drivers/input/joystick/spaceball.c
@@ -215,7 +215,7 @@ static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
215 spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL); 215 spaceball = kmalloc(sizeof(struct spaceball), GFP_KERNEL);
216 input_dev = input_allocate_device(); 216 input_dev = input_allocate_device();
217 if (!spaceball || !input_dev) 217 if (!spaceball || !input_dev)
218 goto fail; 218 goto fail1;
219 219
220 spaceball->dev = input_dev; 220 spaceball->dev = input_dev;
221 snprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys); 221 snprintf(spaceball->phys, sizeof(spaceball->phys), "%s/input0", serio->phys);
@@ -252,13 +252,17 @@ static int spaceball_connect(struct serio *serio, struct serio_driver *drv)
252 252
253 err = serio_open(serio, drv); 253 err = serio_open(serio, drv);
254 if (err) 254 if (err)
255 goto fail; 255 goto fail2;
256
257 err = input_register_device(spaceball->dev);
258 if (err)
259 goto fail3;
256 260
257 input_register_device(spaceball->dev);
258 return 0; 261 return 0;
259 262
260 fail: serio_set_drvdata(serio, NULL); 263 fail3: serio_close(serio);
261 input_free_device(input_dev); 264 fail2: serio_set_drvdata(serio, NULL);
265 fail1: input_free_device(input_dev);
262 kfree(spaceball); 266 kfree(spaceball);
263 return err; 267 return err;
264} 268}
@@ -296,8 +300,7 @@ static struct serio_driver spaceball_drv = {
296 300
297static int __init spaceball_init(void) 301static int __init spaceball_init(void)
298{ 302{
299 serio_register_driver(&spaceball_drv); 303 return serio_register_driver(&spaceball_drv);
300 return 0;
301} 304}
302 305
303static void __exit spaceball_exit(void) 306static void __exit spaceball_exit(void)
diff --git a/drivers/input/joystick/spaceorb.c b/drivers/input/joystick/spaceorb.c
index c4db0247c5fb..c9c79211af71 100644
--- a/drivers/input/joystick/spaceorb.c
+++ b/drivers/input/joystick/spaceorb.c
@@ -172,7 +172,7 @@ static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
172 spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL); 172 spaceorb = kzalloc(sizeof(struct spaceorb), GFP_KERNEL);
173 input_dev = input_allocate_device(); 173 input_dev = input_allocate_device();
174 if (!spaceorb || !input_dev) 174 if (!spaceorb || !input_dev)
175 goto fail; 175 goto fail1;
176 176
177 spaceorb->dev = input_dev; 177 spaceorb->dev = input_dev;
178 snprintf(spaceorb->phys, sizeof(spaceorb->phys), "%s/input0", serio->phys); 178 snprintf(spaceorb->phys, sizeof(spaceorb->phys), "%s/input0", serio->phys);
@@ -198,13 +198,17 @@ static int spaceorb_connect(struct serio *serio, struct serio_driver *drv)
198 198
199 err = serio_open(serio, drv); 199 err = serio_open(serio, drv);
200 if (err) 200 if (err)
201 goto fail; 201 goto fail2;
202
203 err = input_register_device(spaceorb->dev);
204 if (err)
205 goto fail3;
202 206
203 input_register_device(spaceorb->dev);
204 return 0; 207 return 0;
205 208
206 fail: serio_set_drvdata(serio, NULL); 209 fail3: serio_close(serio);
207 input_free_device(input_dev); 210 fail2: serio_set_drvdata(serio, NULL);
211 fail1: input_free_device(input_dev);
208 kfree(spaceorb); 212 kfree(spaceorb);
209 return err; 213 return err;
210} 214}
@@ -242,8 +246,7 @@ static struct serio_driver spaceorb_drv = {
242 246
243static int __init spaceorb_init(void) 247static int __init spaceorb_init(void)
244{ 248{
245 serio_register_driver(&spaceorb_drv); 249 return serio_register_driver(&spaceorb_drv);
246 return 0;
247} 250}
248 251
249static void __exit spaceorb_exit(void) 252static void __exit spaceorb_exit(void)
diff --git a/drivers/input/joystick/stinger.c b/drivers/input/joystick/stinger.c
index 1ffb03223311..ecb0916215fa 100644
--- a/drivers/input/joystick/stinger.c
+++ b/drivers/input/joystick/stinger.c
@@ -143,7 +143,7 @@ static int stinger_connect(struct serio *serio, struct serio_driver *drv)
143 stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL); 143 stinger = kmalloc(sizeof(struct stinger), GFP_KERNEL);
144 input_dev = input_allocate_device(); 144 input_dev = input_allocate_device();
145 if (!stinger || !input_dev) 145 if (!stinger || !input_dev)
146 goto fail; 146 goto fail1;
147 147
148 stinger->dev = input_dev; 148 stinger->dev = input_dev;
149 snprintf(stinger->phys, sizeof(stinger->phys), "%s/serio0", serio->phys); 149 snprintf(stinger->phys, sizeof(stinger->phys), "%s/serio0", serio->phys);
@@ -168,13 +168,17 @@ static int stinger_connect(struct serio *serio, struct serio_driver *drv)
168 168
169 err = serio_open(serio, drv); 169 err = serio_open(serio, drv);
170 if (err) 170 if (err)
171 goto fail; 171 goto fail2;
172
173 err = input_register_device(stinger->dev);
174 if (err)
175 goto fail3;
172 176
173 input_register_device(stinger->dev);
174 return 0; 177 return 0;
175 178
176 fail: serio_set_drvdata(serio, NULL); 179 fail3: serio_close(serio);
177 input_free_device(input_dev); 180 fail2: serio_set_drvdata(serio, NULL);
181 fail1: input_free_device(input_dev);
178 kfree(stinger); 182 kfree(stinger);
179 return err; 183 return err;
180} 184}
@@ -212,8 +216,7 @@ static struct serio_driver stinger_drv = {
212 216
213static int __init stinger_init(void) 217static int __init stinger_init(void)
214{ 218{
215 serio_register_driver(&stinger_drv); 219 return serio_register_driver(&stinger_drv);
216 return 0;
217} 220}
218 221
219static void __exit stinger_exit(void) 222static void __exit stinger_exit(void)
diff --git a/drivers/input/joystick/twidjoy.c b/drivers/input/joystick/twidjoy.c
index 49085df2d631..9cf17d6ced82 100644
--- a/drivers/input/joystick/twidjoy.c
+++ b/drivers/input/joystick/twidjoy.c
@@ -194,7 +194,7 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
194 twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL); 194 twidjoy = kzalloc(sizeof(struct twidjoy), GFP_KERNEL);
195 input_dev = input_allocate_device(); 195 input_dev = input_allocate_device();
196 if (!twidjoy || !input_dev) 196 if (!twidjoy || !input_dev)
197 goto fail; 197 goto fail1;
198 198
199 twidjoy->dev = input_dev; 199 twidjoy->dev = input_dev;
200 snprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys); 200 snprintf(twidjoy->phys, sizeof(twidjoy->phys), "%s/input0", serio->phys);
@@ -221,13 +221,17 @@ static int twidjoy_connect(struct serio *serio, struct serio_driver *drv)
221 221
222 err = serio_open(serio, drv); 222 err = serio_open(serio, drv);
223 if (err) 223 if (err)
224 goto fail; 224 goto fail2;
225
226 err = input_register_device(twidjoy->dev);
227 if (err)
228 goto fail3;
225 229
226 input_register_device(twidjoy->dev);
227 return 0; 230 return 0;
228 231
229 fail: serio_set_drvdata(serio, NULL); 232 fail3: serio_close(serio);
230 input_free_device(input_dev); 233 fail2: serio_set_drvdata(serio, NULL);
234 fail1: input_free_device(input_dev);
231 kfree(twidjoy); 235 kfree(twidjoy);
232 return err; 236 return err;
233} 237}
@@ -265,8 +269,7 @@ static struct serio_driver twidjoy_drv = {
265 269
266static int __init twidjoy_init(void) 270static int __init twidjoy_init(void)
267{ 271{
268 serio_register_driver(&twidjoy_drv); 272 return serio_register_driver(&twidjoy_drv);
269 return 0;
270} 273}
271 274
272static void __exit twidjoy_exit(void) 275static void __exit twidjoy_exit(void)
diff --git a/drivers/input/joystick/warrior.c b/drivers/input/joystick/warrior.c
index 35edea1ab955..29d339acf430 100644
--- a/drivers/input/joystick/warrior.c
+++ b/drivers/input/joystick/warrior.c
@@ -149,7 +149,7 @@ static int warrior_connect(struct serio *serio, struct serio_driver *drv)
149 warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL); 149 warrior = kzalloc(sizeof(struct warrior), GFP_KERNEL);
150 input_dev = input_allocate_device(); 150 input_dev = input_allocate_device();
151 if (!warrior || !input_dev) 151 if (!warrior || !input_dev)
152 goto fail; 152 goto fail1;
153 153
154 warrior->dev = input_dev; 154 warrior->dev = input_dev;
155 snprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys); 155 snprintf(warrior->phys, sizeof(warrior->phys), "%s/input0", serio->phys);
@@ -176,13 +176,17 @@ static int warrior_connect(struct serio *serio, struct serio_driver *drv)
176 176
177 err = serio_open(serio, drv); 177 err = serio_open(serio, drv);
178 if (err) 178 if (err)
179 goto fail; 179 goto fail2;
180
181 err = input_register_device(warrior->dev);
182 if (err)
183 goto fail3;
180 184
181 input_register_device(warrior->dev);
182 return 0; 185 return 0;
183 186
184 fail: serio_set_drvdata(serio, NULL); 187 fail3: serio_close(serio);
185 input_free_device(input_dev); 188 fail2: serio_set_drvdata(serio, NULL);
189 fail1: input_free_device(input_dev);
186 kfree(warrior); 190 kfree(warrior);
187 return err; 191 return err;
188} 192}
@@ -220,8 +224,7 @@ static struct serio_driver warrior_drv = {
220 224
221static int __init warrior_init(void) 225static int __init warrior_init(void)
222{ 226{
223 serio_register_driver(&warrior_drv); 227 return serio_register_driver(&warrior_drv);
224 return 0;
225} 228}
226 229
227static void __exit warrior_exit(void) 230static void __exit warrior_exit(void)
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 81a333f73010..049f2f544e75 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -203,4 +203,15 @@ config KEYBOARD_OMAP
203 To compile this driver as a module, choose M here: the 203 To compile this driver as a module, choose M here: the
204 module will be called omap-keypad. 204 module will be called omap-keypad.
205 205
206config KEYBOARD_AAED2000
207 tristate "AAED-2000 keyboard"
208 depends on MACH_AAED2000
209 default y
210 help
211 Say Y here to enable the keyboard on the Agilent AAED-2000
212 development board.
213
214 To compile this driver as a module, choose M here: the
215 module will be called aaed2000_kbd.
216
206endif 217endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 4c79e7bc9d06..568797907347 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -17,4 +17,5 @@ obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
17obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 17obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
18obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 18obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
19obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 19obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
20obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
20 21
diff --git a/drivers/input/keyboard/aaed2000_kbd.c b/drivers/input/keyboard/aaed2000_kbd.c
new file mode 100644
index 000000000000..65fcb6af63a8
--- /dev/null
+++ b/drivers/input/keyboard/aaed2000_kbd.c
@@ -0,0 +1,203 @@
1/*
2 * Keyboard driver for the AAED-2000 dev board
3 *
4 * Copyright (c) 2006 Nicolas Bellido Y Ortega
5 *
6 * Based on corgikbd.c
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/delay.h>
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/input.h>
18#include <linux/interrupt.h>
19#include <linux/jiffies.h>
20#include <linux/module.h>
21#include <linux/slab.h>
22#include <linux/workqueue.h>
23
24#include <asm/arch/hardware.h>
25#include <asm/arch/aaed2000.h>
26
27#define KB_ROWS 12
28#define KB_COLS 8
29#define KB_ROWMASK(r) (1 << (r))
30#define SCANCODE(r,c) (((c) * KB_ROWS) + (r))
31#define NR_SCANCODES (KB_COLS * KB_ROWS)
32
33#define SCAN_INTERVAL (50) /* ms */
34#define KB_ACTIVATE_DELAY (20) /* us */
35
36static unsigned char aaedkbd_keycode[NR_SCANCODES] = {
37 KEY_9, KEY_0, KEY_MINUS, KEY_EQUAL, KEY_BACKSPACE, 0, KEY_SPACE, KEY_KP6, 0, KEY_KPDOT, 0, 0,
38 KEY_K, KEY_M, KEY_O, KEY_DOT, KEY_SLASH, 0, KEY_F, 0, 0, 0, KEY_LEFTSHIFT, 0,
39 KEY_I, KEY_P, KEY_LEFTBRACE, KEY_RIGHTBRACE, KEY_BACKSLASH, 0, 0, 0, 0, 0, KEY_RIGHTSHIFT, 0,
40 KEY_8, KEY_L, KEY_SEMICOLON, KEY_APOSTROPHE, KEY_ENTER, 0, 0, 0, 0, 0, 0, 0,
41 KEY_J, KEY_H, KEY_B, KEY_KP8, KEY_KP4, 0, KEY_C, KEY_D, KEY_S, KEY_A, 0, KEY_CAPSLOCK,
42 KEY_Y, KEY_U, KEY_N, KEY_T, 0, 0, KEY_R, KEY_E, KEY_W, KEY_Q, 0, KEY_TAB,
43 KEY_7, KEY_6, KEY_G, 0, KEY_5, 0, KEY_4, KEY_3, KEY_2, KEY_1, 0, KEY_GRAVE,
44 0, 0, KEY_COMMA, 0, KEY_KP2, 0, KEY_V, KEY_LEFTALT, KEY_X, KEY_Z, 0, KEY_LEFTCTRL
45};
46
47struct aaedkbd {
48 unsigned char keycode[ARRAY_SIZE(aaedkbd_keycode)];
49 struct input_dev *input;
50 struct work_struct workq;
51 int kbdscan_state[KB_COLS];
52 int kbdscan_count[KB_COLS];
53};
54
55#define KBDSCAN_STABLE_COUNT 2
56
57static void aaedkbd_report_col(struct aaedkbd *aaedkbd,
58 unsigned int col, unsigned int rowd)
59{
60 unsigned int scancode, pressed;
61 unsigned int row;
62
63 for (row = 0; row < KB_ROWS; row++) {
64 scancode = SCANCODE(row, col);
65 pressed = rowd & KB_ROWMASK(row);
66
67 input_report_key(aaedkbd->input, aaedkbd->keycode[scancode], pressed);
68 }
69}
70
71/* Scan the hardware keyboard and push any changes up through the input layer */
72static void aaedkbd_work(void *data)
73{
74 struct aaedkbd *aaedkbd = data;
75 unsigned int col, rowd;
76
77 col = 0;
78 do {
79 AAEC_GPIO_KSCAN = col + 8;
80 udelay(KB_ACTIVATE_DELAY);
81 rowd = AAED_EXT_GPIO & AAED_EGPIO_KBD_SCAN;
82
83 if (rowd != aaedkbd->kbdscan_state[col]) {
84 aaedkbd->kbdscan_count[col] = 0;
85 aaedkbd->kbdscan_state[col] = rowd;
86 } else if (++aaedkbd->kbdscan_count[col] >= KBDSCAN_STABLE_COUNT) {
87 aaedkbd_report_col(aaedkbd, col, rowd);
88 col++;
89 }
90 } while (col < KB_COLS);
91
92 AAEC_GPIO_KSCAN = 0x07;
93 input_sync(aaedkbd->input);
94
95 schedule_delayed_work(&aaedkbd->workq, msecs_to_jiffies(SCAN_INTERVAL));
96}
97
98static int aaedkbd_open(struct input_dev *indev)
99{
100 struct aaedkbd *aaedkbd = indev->private;
101
102 schedule_delayed_work(&aaedkbd->workq, msecs_to_jiffies(SCAN_INTERVAL));
103
104 return 0;
105}
106
107static void aaedkbd_close(struct input_dev *indev)
108{
109 struct aaedkbd *aaedkbd = indev->private;
110
111 cancel_delayed_work(&aaedkbd->workq);
112 flush_scheduled_work();
113}
114
115static int __devinit aaedkbd_probe(struct platform_device *pdev)
116{
117 struct aaedkbd *aaedkbd;
118 struct input_dev *input_dev;
119 int i;
120 int error;
121
122 aaedkbd = kzalloc(sizeof(struct aaedkbd), GFP_KERNEL);
123 input_dev = input_allocate_device();
124 if (!aaedkbd || !input_dev) {
125 error = -ENOMEM;
126 goto fail;
127 }
128
129 platform_set_drvdata(pdev, aaedkbd);
130
131 aaedkbd->input = input_dev;
132
133 /* Init keyboard rescan workqueue */
134 INIT_WORK(&aaedkbd->workq, aaedkbd_work, aaedkbd);
135
136 memcpy(aaedkbd->keycode, aaedkbd_keycode, sizeof(aaedkbd->keycode));
137
138 input_dev->name = "AAED-2000 Keyboard";
139 input_dev->phys = "aaedkbd/input0";
140 input_dev->id.bustype = BUS_HOST;
141 input_dev->id.vendor = 0x0001;
142 input_dev->id.product = 0x0001;
143 input_dev->id.version = 0x0100;
144 input_dev->cdev.dev = &pdev->dev;
145 input_dev->private = aaedkbd;
146
147 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
148 input_dev->keycode = aaedkbd->keycode;
149 input_dev->keycodesize = sizeof(unsigned char);
150 input_dev->keycodemax = ARRAY_SIZE(aaedkbd_keycode);
151
152 for (i = 0; i < ARRAY_SIZE(aaedkbd_keycode); i++)
153 set_bit(aaedkbd->keycode[i], input_dev->keybit);
154 clear_bit(0, input_dev->keybit);
155
156 input_dev->open = aaedkbd_open;
157 input_dev->close = aaedkbd_close;
158
159 error = input_register_device(aaedkbd->input);
160 if (error)
161 goto fail;
162
163 return 0;
164
165 fail: kfree(aaedkbd);
166 input_free_device(input_dev);
167 return error;
168}
169
170static int __devexit aaedkbd_remove(struct platform_device *pdev)
171{
172 struct aaedkbd *aaedkbd = platform_get_drvdata(pdev);
173
174 input_unregister_device(aaedkbd->input);
175 kfree(aaedkbd);
176
177 return 0;
178}
179
180static struct platform_driver aaedkbd_driver = {
181 .probe = aaedkbd_probe,
182 .remove = __devexit_p(aaedkbd_remove),
183 .driver = {
184 .name = "aaed2000-keyboard",
185 },
186};
187
188static int __init aaedkbd_init(void)
189{
190 return platform_driver_register(&aaedkbd_driver);
191}
192
193static void __exit aaedkbd_exit(void)
194{
195 platform_driver_unregister(&aaedkbd_driver);
196}
197
198module_init(aaedkbd_init);
199module_exit(aaedkbd_exit);
200
201MODULE_AUTHOR("Nicolas Bellido Y Ortega");
202MODULE_DESCRIPTION("AAED-2000 Keyboard Driver");
203MODULE_LICENSE("GPLv2");
diff --git a/drivers/input/keyboard/amikbd.c b/drivers/input/keyboard/amikbd.c
index 8abdbd0ee8f9..16583d71753b 100644
--- a/drivers/input/keyboard/amikbd.c
+++ b/drivers/input/keyboard/amikbd.c
@@ -190,7 +190,7 @@ static int __init amikbd_init(void)
190 int i, j; 190 int i, j;
191 191
192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD)) 192 if (!AMIGAHW_PRESENT(AMI_KEYBOARD))
193 return -EIO; 193 return -ENODEV;
194 194
195 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb")) 195 if (!request_mem_region(CIAA_PHYSADDR-1+0xb00, 0x100, "amikeyb"))
196 return -EBUSY; 196 return -EBUSY;
@@ -198,8 +198,8 @@ static int __init amikbd_init(void)
198 amikbd_dev = input_allocate_device(); 198 amikbd_dev = input_allocate_device();
199 if (!amikbd_dev) { 199 if (!amikbd_dev) {
200 printk(KERN_ERR "amikbd: not enough memory for input device\n"); 200 printk(KERN_ERR "amikbd: not enough memory for input device\n");
201 release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100); 201 err = -ENOMEM;
202 return -ENOMEM; 202 goto fail1;
203 } 203 }
204 204
205 amikbd_dev->name = "Amiga Keyboard"; 205 amikbd_dev->name = "Amiga Keyboard";
@@ -231,10 +231,22 @@ static int __init amikbd_init(void)
231 memcpy(key_maps[i], temp_map, sizeof(temp_map)); 231 memcpy(key_maps[i], temp_map, sizeof(temp_map));
232 } 232 }
233 ciaa.cra &= ~0x41; /* serial data in, turn off TA */ 233 ciaa.cra &= ~0x41; /* serial data in, turn off TA */
234 request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd", amikbd_interrupt); 234 if (request_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt, 0, "amikbd",
235 amikbd_interrupt)) {
236 err = -EBUSY;
237 goto fail2;
238 }
239
240 err = input_register_device(amikbd_dev);
241 if (err)
242 goto fail3;
235 243
236 input_register_device(amikbd_dev);
237 return 0; 244 return 0;
245
246 fail3: free_irq(IRQ_AMIGA_CIAA_SP, amikbd_interrupt);
247 fail2: input_free_device(amikbd_dev);
248 fail1: release_mem_region(CIAA_PHYSADDR - 1 + 0xb00, 0x100);
249 return err;
238} 250}
239 251
240static void __exit amikbd_exit(void) 252static void __exit amikbd_exit(void)
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 8451b29a3db5..c621a9177a56 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -939,7 +939,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
939 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL); 939 atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
940 dev = input_allocate_device(); 940 dev = input_allocate_device();
941 if (!atkbd || !dev) 941 if (!atkbd || !dev)
942 goto fail; 942 goto fail1;
943 943
944 atkbd->dev = dev; 944 atkbd->dev = dev;
945 ps2_init(&atkbd->ps2dev, serio); 945 ps2_init(&atkbd->ps2dev, serio);
@@ -967,14 +967,13 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
967 967
968 err = serio_open(serio, drv); 968 err = serio_open(serio, drv);
969 if (err) 969 if (err)
970 goto fail; 970 goto fail2;
971 971
972 if (atkbd->write) { 972 if (atkbd->write) {
973 973
974 if (atkbd_probe(atkbd)) { 974 if (atkbd_probe(atkbd)) {
975 serio_close(serio);
976 err = -ENODEV; 975 err = -ENODEV;
977 goto fail; 976 goto fail3;
978 } 977 }
979 978
980 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra); 979 atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
@@ -988,16 +987,22 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
988 atkbd_set_keycode_table(atkbd); 987 atkbd_set_keycode_table(atkbd);
989 atkbd_set_device_attrs(atkbd); 988 atkbd_set_device_attrs(atkbd);
990 989
991 sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group); 990 err = sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group);
991 if (err)
992 goto fail3;
992 993
993 atkbd_enable(atkbd); 994 atkbd_enable(atkbd);
994 995
995 input_register_device(atkbd->dev); 996 err = input_register_device(atkbd->dev);
997 if (err)
998 goto fail4;
996 999
997 return 0; 1000 return 0;
998 1001
999 fail: serio_set_drvdata(serio, NULL); 1002 fail4: sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
1000 input_free_device(dev); 1003 fail3: serio_close(serio);
1004 fail2: serio_set_drvdata(serio, NULL);
1005 fail1: input_free_device(dev);
1001 kfree(atkbd); 1006 kfree(atkbd);
1002 return err; 1007 return err;
1003} 1008}
@@ -1133,9 +1138,11 @@ static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
1133 1138
1134static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count) 1139static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
1135{ 1140{
1136 struct input_dev *new_dev; 1141 struct input_dev *old_dev, *new_dev;
1137 unsigned long value; 1142 unsigned long value;
1138 char *rest; 1143 char *rest;
1144 int err;
1145 unsigned char old_extra, old_set;
1139 1146
1140 if (!atkbd->write) 1147 if (!atkbd->write)
1141 return -EIO; 1148 return -EIO;
@@ -1147,17 +1154,36 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1147 if (atkbd->extra != value) { 1154 if (atkbd->extra != value) {
1148 /* 1155 /*
1149 * Since device's properties will change we need to 1156 * Since device's properties will change we need to
1150 * unregister old device. But allocate new one first 1157 * unregister old device. But allocate and register
1151 * to make sure we have it. 1158 * new one first to make sure we have it.
1152 */ 1159 */
1153 if (!(new_dev = input_allocate_device())) 1160 old_dev = atkbd->dev;
1161 old_extra = atkbd->extra;
1162 old_set = atkbd->set;
1163
1164 new_dev = input_allocate_device();
1165 if (!new_dev)
1154 return -ENOMEM; 1166 return -ENOMEM;
1155 input_unregister_device(atkbd->dev); 1167
1156 atkbd->dev = new_dev; 1168 atkbd->dev = new_dev;
1157 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value); 1169 atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
1158 atkbd_activate(atkbd); 1170 atkbd_activate(atkbd);
1171 atkbd_set_keycode_table(atkbd);
1159 atkbd_set_device_attrs(atkbd); 1172 atkbd_set_device_attrs(atkbd);
1160 input_register_device(atkbd->dev); 1173
1174 err = input_register_device(atkbd->dev);
1175 if (err) {
1176 input_free_device(new_dev);
1177
1178 atkbd->dev = old_dev;
1179 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1180 atkbd_set_keycode_table(atkbd);
1181 atkbd_set_device_attrs(atkbd);
1182
1183 return err;
1184 }
1185 input_unregister_device(old_dev);
1186
1161 } 1187 }
1162 return count; 1188 return count;
1163} 1189}
@@ -1169,23 +1195,41 @@ static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
1169 1195
1170static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count) 1196static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
1171{ 1197{
1172 struct input_dev *new_dev; 1198 struct input_dev *old_dev, *new_dev;
1173 unsigned long value; 1199 unsigned long value;
1174 char *rest; 1200 char *rest;
1201 int err;
1202 unsigned char old_scroll;
1175 1203
1176 value = simple_strtoul(buf, &rest, 10); 1204 value = simple_strtoul(buf, &rest, 10);
1177 if (*rest || value > 1) 1205 if (*rest || value > 1)
1178 return -EINVAL; 1206 return -EINVAL;
1179 1207
1180 if (atkbd->scroll != value) { 1208 if (atkbd->scroll != value) {
1181 if (!(new_dev = input_allocate_device())) 1209 old_dev = atkbd->dev;
1210 old_scroll = atkbd->scroll;
1211
1212 new_dev = input_allocate_device();
1213 if (!new_dev)
1182 return -ENOMEM; 1214 return -ENOMEM;
1183 input_unregister_device(atkbd->dev); 1215
1184 atkbd->dev = new_dev; 1216 atkbd->dev = new_dev;
1185 atkbd->scroll = value; 1217 atkbd->scroll = value;
1186 atkbd_set_keycode_table(atkbd); 1218 atkbd_set_keycode_table(atkbd);
1187 atkbd_set_device_attrs(atkbd); 1219 atkbd_set_device_attrs(atkbd);
1188 input_register_device(atkbd->dev); 1220
1221 err = input_register_device(atkbd->dev);
1222 if (err) {
1223 input_free_device(new_dev);
1224
1225 atkbd->scroll = old_scroll;
1226 atkbd->dev = old_dev;
1227 atkbd_set_keycode_table(atkbd);
1228 atkbd_set_device_attrs(atkbd);
1229
1230 return err;
1231 }
1232 input_unregister_device(old_dev);
1189 } 1233 }
1190 return count; 1234 return count;
1191} 1235}
@@ -1197,9 +1241,11 @@ static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
1197 1241
1198static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count) 1242static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1199{ 1243{
1200 struct input_dev *new_dev; 1244 struct input_dev *old_dev, *new_dev;
1201 unsigned long value; 1245 unsigned long value;
1202 char *rest; 1246 char *rest;
1247 int err;
1248 unsigned char old_set, old_extra;
1203 1249
1204 if (!atkbd->write) 1250 if (!atkbd->write)
1205 return -EIO; 1251 return -EIO;
@@ -1209,15 +1255,32 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1209 return -EINVAL; 1255 return -EINVAL;
1210 1256
1211 if (atkbd->set != value) { 1257 if (atkbd->set != value) {
1212 if (!(new_dev = input_allocate_device())) 1258 old_dev = atkbd->dev;
1259 old_extra = atkbd->extra;
1260 old_set = atkbd->set;
1261
1262 new_dev = input_allocate_device();
1263 if (!new_dev)
1213 return -ENOMEM; 1264 return -ENOMEM;
1214 input_unregister_device(atkbd->dev); 1265
1215 atkbd->dev = new_dev; 1266 atkbd->dev = new_dev;
1216 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra); 1267 atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
1217 atkbd_activate(atkbd); 1268 atkbd_activate(atkbd);
1218 atkbd_set_keycode_table(atkbd); 1269 atkbd_set_keycode_table(atkbd);
1219 atkbd_set_device_attrs(atkbd); 1270 atkbd_set_device_attrs(atkbd);
1220 input_register_device(atkbd->dev); 1271
1272 err = input_register_device(atkbd->dev);
1273 if (err) {
1274 input_free_device(new_dev);
1275
1276 atkbd->dev = old_dev;
1277 atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
1278 atkbd_set_keycode_table(atkbd);
1279 atkbd_set_device_attrs(atkbd);
1280
1281 return err;
1282 }
1283 input_unregister_device(old_dev);
1221 } 1284 }
1222 return count; 1285 return count;
1223} 1286}
@@ -1229,9 +1292,11 @@ static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
1229 1292
1230static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count) 1293static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
1231{ 1294{
1232 struct input_dev *new_dev; 1295 struct input_dev *old_dev, *new_dev;
1233 unsigned long value; 1296 unsigned long value;
1234 char *rest; 1297 char *rest;
1298 int err;
1299 unsigned char old_softrepeat, old_softraw;
1235 1300
1236 if (!atkbd->write) 1301 if (!atkbd->write)
1237 return -EIO; 1302 return -EIO;
@@ -1241,15 +1306,32 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1241 return -EINVAL; 1306 return -EINVAL;
1242 1307
1243 if (atkbd->softrepeat != value) { 1308 if (atkbd->softrepeat != value) {
1244 if (!(new_dev = input_allocate_device())) 1309 old_dev = atkbd->dev;
1310 old_softrepeat = atkbd->softrepeat;
1311 old_softraw = atkbd->softraw;
1312
1313 new_dev = input_allocate_device();
1314 if (!new_dev)
1245 return -ENOMEM; 1315 return -ENOMEM;
1246 input_unregister_device(atkbd->dev); 1316
1247 atkbd->dev = new_dev; 1317 atkbd->dev = new_dev;
1248 atkbd->softrepeat = value; 1318 atkbd->softrepeat = value;
1249 if (atkbd->softrepeat) 1319 if (atkbd->softrepeat)
1250 atkbd->softraw = 1; 1320 atkbd->softraw = 1;
1251 atkbd_set_device_attrs(atkbd); 1321 atkbd_set_device_attrs(atkbd);
1252 input_register_device(atkbd->dev); 1322
1323 err = input_register_device(atkbd->dev);
1324 if (err) {
1325 input_free_device(new_dev);
1326
1327 atkbd->dev = old_dev;
1328 atkbd->softrepeat = old_softrepeat;
1329 atkbd->softraw = old_softraw;
1330 atkbd_set_device_attrs(atkbd);
1331
1332 return err;
1333 }
1334 input_unregister_device(old_dev);
1253 } 1335 }
1254 return count; 1336 return count;
1255} 1337}
@@ -1262,22 +1344,39 @@ static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
1262 1344
1263static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count) 1345static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
1264{ 1346{
1265 struct input_dev *new_dev; 1347 struct input_dev *old_dev, *new_dev;
1266 unsigned long value; 1348 unsigned long value;
1267 char *rest; 1349 char *rest;
1350 int err;
1351 unsigned char old_softraw;
1268 1352
1269 value = simple_strtoul(buf, &rest, 10); 1353 value = simple_strtoul(buf, &rest, 10);
1270 if (*rest || value > 1) 1354 if (*rest || value > 1)
1271 return -EINVAL; 1355 return -EINVAL;
1272 1356
1273 if (atkbd->softraw != value) { 1357 if (atkbd->softraw != value) {
1274 if (!(new_dev = input_allocate_device())) 1358 old_dev = atkbd->dev;
1359 old_softraw = atkbd->softraw;
1360
1361 new_dev = input_allocate_device();
1362 if (!new_dev)
1275 return -ENOMEM; 1363 return -ENOMEM;
1276 input_unregister_device(atkbd->dev); 1364
1277 atkbd->dev = new_dev; 1365 atkbd->dev = new_dev;
1278 atkbd->softraw = value; 1366 atkbd->softraw = value;
1279 atkbd_set_device_attrs(atkbd); 1367 atkbd_set_device_attrs(atkbd);
1280 input_register_device(atkbd->dev); 1368
1369 err = input_register_device(atkbd->dev);
1370 if (err) {
1371 input_free_device(new_dev);
1372
1373 atkbd->dev = old_dev;
1374 atkbd->softraw = old_softraw;
1375 atkbd_set_device_attrs(atkbd);
1376
1377 return err;
1378 }
1379 input_unregister_device(old_dev);
1281 } 1380 }
1282 return count; 1381 return count;
1283} 1382}
@@ -1290,8 +1389,7 @@ static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf)
1290 1389
1291static int __init atkbd_init(void) 1390static int __init atkbd_init(void)
1292{ 1391{
1293 serio_register_driver(&atkbd_drv); 1392 return serio_register_driver(&atkbd_drv);
1294 return 0;
1295} 1393}
1296 1394
1297static void __exit atkbd_exit(void) 1395static void __exit atkbd_exit(void)
diff --git a/drivers/input/keyboard/corgikbd.c b/drivers/input/keyboard/corgikbd.c
index befdd6006b50..1016c94e65db 100644
--- a/drivers/input/keyboard/corgikbd.c
+++ b/drivers/input/keyboard/corgikbd.c
@@ -291,15 +291,12 @@ static int __init corgikbd_probe(struct platform_device *pdev)
291{ 291{
292 struct corgikbd *corgikbd; 292 struct corgikbd *corgikbd;
293 struct input_dev *input_dev; 293 struct input_dev *input_dev;
294 int i; 294 int i, err = -ENOMEM;
295 295
296 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL); 296 corgikbd = kzalloc(sizeof(struct corgikbd), GFP_KERNEL);
297 input_dev = input_allocate_device(); 297 input_dev = input_allocate_device();
298 if (!corgikbd || !input_dev) { 298 if (!corgikbd || !input_dev)
299 kfree(corgikbd); 299 goto fail;
300 input_free_device(input_dev);
301 return -ENOMEM;
302 }
303 300
304 platform_set_drvdata(pdev, corgikbd); 301 platform_set_drvdata(pdev, corgikbd);
305 302
@@ -341,7 +338,9 @@ static int __init corgikbd_probe(struct platform_device *pdev)
341 set_bit(SW_TABLET_MODE, input_dev->swbit); 338 set_bit(SW_TABLET_MODE, input_dev->swbit);
342 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit); 339 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
343 340
344 input_register_device(corgikbd->input); 341 err = input_register_device(corgikbd->input);
342 if (err)
343 goto fail;
345 344
346 mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); 345 mod_timer(&corgikbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
347 346
@@ -362,6 +361,10 @@ static int __init corgikbd_probe(struct platform_device *pdev)
362 pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN); 361 pxa_gpio_mode(CORGI_GPIO_AK_INT | GPIO_IN);
363 362
364 return 0; 363 return 0;
364
365 fail: input_free_device(input_dev);
366 kfree(corgikbd);
367 return err;
365} 368}
366 369
367static int corgikbd_remove(struct platform_device *pdev) 370static int corgikbd_remove(struct platform_device *pdev)
diff --git a/drivers/input/keyboard/hil_kbd.c b/drivers/input/keyboard/hil_kbd.c
index e774dd31e99b..7cc9728b04df 100644
--- a/drivers/input/keyboard/hil_kbd.c
+++ b/drivers/input/keyboard/hil_kbd.c
@@ -381,8 +381,7 @@ struct serio_driver hil_kbd_serio_drv = {
381 381
382static int __init hil_kbd_init(void) 382static int __init hil_kbd_init(void)
383{ 383{
384 serio_register_driver(&hil_kbd_serio_drv); 384 return serio_register_driver(&hil_kbd_serio_drv);
385 return 0;
386} 385}
387 386
388static void __exit hil_kbd_exit(void) 387static void __exit hil_kbd_exit(void)
diff --git a/drivers/input/keyboard/lkkbd.c b/drivers/input/keyboard/lkkbd.c
index b7f049b45b6b..3d4d0a0ede28 100644
--- a/drivers/input/keyboard/lkkbd.c
+++ b/drivers/input/keyboard/lkkbd.c
@@ -646,7 +646,7 @@ lkkbd_connect (struct serio *serio, struct serio_driver *drv)
646 input_dev = input_allocate_device (); 646 input_dev = input_allocate_device ();
647 if (!lk || !input_dev) { 647 if (!lk || !input_dev) {
648 err = -ENOMEM; 648 err = -ENOMEM;
649 goto fail; 649 goto fail1;
650 } 650 }
651 651
652 lk->serio = serio; 652 lk->serio = serio;
@@ -691,15 +691,19 @@ lkkbd_connect (struct serio *serio, struct serio_driver *drv)
691 691
692 err = serio_open (serio, drv); 692 err = serio_open (serio, drv);
693 if (err) 693 if (err)
694 goto fail; 694 goto fail2;
695
696 err = input_register_device (lk->dev);
697 if (err)
698 goto fail3;
695 699
696 input_register_device (lk->dev);
697 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET); 700 lk->serio->write (lk->serio, LK_CMD_POWERCYCLE_RESET);
698 701
699 return 0; 702 return 0;
700 703
701 fail: serio_set_drvdata (serio, NULL); 704 fail3: serio_close (serio);
702 input_free_device (input_dev); 705 fail2: serio_set_drvdata (serio, NULL);
706 fail1: input_free_device (input_dev);
703 kfree (lk); 707 kfree (lk);
704 return err; 708 return err;
705} 709}
@@ -749,8 +753,7 @@ static struct serio_driver lkkbd_drv = {
749static int __init 753static int __init
750lkkbd_init (void) 754lkkbd_init (void)
751{ 755{
752 serio_register_driver(&lkkbd_drv); 756 return serio_register_driver(&lkkbd_drv);
753 return 0;
754} 757}
755 758
756static void __exit 759static void __exit
diff --git a/drivers/input/keyboard/locomokbd.c b/drivers/input/keyboard/locomokbd.c
index 5788dbc317bb..2ade5186cc41 100644
--- a/drivers/input/keyboard/locomokbd.c
+++ b/drivers/input/keyboard/locomokbd.c
@@ -193,22 +193,22 @@ static int locomokbd_probe(struct locomo_dev *dev)
193{ 193{
194 struct locomokbd *locomokbd; 194 struct locomokbd *locomokbd;
195 struct input_dev *input_dev; 195 struct input_dev *input_dev;
196 int i, ret; 196 int i, err;
197 197
198 locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL); 198 locomokbd = kzalloc(sizeof(struct locomokbd), GFP_KERNEL);
199 input_dev = input_allocate_device(); 199 input_dev = input_allocate_device();
200 if (!locomokbd || !input_dev) { 200 if (!locomokbd || !input_dev) {
201 ret = -ENOMEM; 201 err = -ENOMEM;
202 goto free; 202 goto err_free_mem;
203 } 203 }
204 204
205 /* try and claim memory region */ 205 /* try and claim memory region */
206 if (!request_mem_region((unsigned long) dev->mapbase, 206 if (!request_mem_region((unsigned long) dev->mapbase,
207 dev->length, 207 dev->length,
208 LOCOMO_DRIVER_NAME(dev))) { 208 LOCOMO_DRIVER_NAME(dev))) {
209 ret = -EBUSY; 209 err = -EBUSY;
210 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n"); 210 printk(KERN_ERR "locomokbd: Can't acquire access to io memory for keyboard\n");
211 goto free; 211 goto err_free_mem;
212 } 212 }
213 213
214 locomokbd->ldev = dev; 214 locomokbd->ldev = dev;
@@ -244,24 +244,28 @@ static int locomokbd_probe(struct locomo_dev *dev)
244 clear_bit(0, input_dev->keybit); 244 clear_bit(0, input_dev->keybit);
245 245
246 /* attempt to get the interrupt */ 246 /* attempt to get the interrupt */
247 ret = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd); 247 err = request_irq(dev->irq[0], locomokbd_interrupt, 0, "locomokbd", locomokbd);
248 if (ret) { 248 if (err) {
249 printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n"); 249 printk(KERN_ERR "locomokbd: Can't get irq for keyboard\n");
250 goto out; 250 goto err_release_region;
251 } 251 }
252 252
253 input_register_device(locomokbd->input); 253 err = input_register_device(locomokbd->input);
254 if (err)
255 goto err_free_irq;
254 256
255 return 0; 257 return 0;
256 258
257out: 259 err_free_irq:
260 free_irq(dev->irq[0], locomokbd);
261 err_release_region:
258 release_mem_region((unsigned long) dev->mapbase, dev->length); 262 release_mem_region((unsigned long) dev->mapbase, dev->length);
259 locomo_set_drvdata(dev, NULL); 263 locomo_set_drvdata(dev, NULL);
260free: 264 err_free_mem:
261 input_free_device(input_dev); 265 input_free_device(input_dev);
262 kfree(locomokbd); 266 kfree(locomokbd);
263 267
264 return ret; 268 return err;
265} 269}
266 270
267static int locomokbd_remove(struct locomo_dev *dev) 271static int locomokbd_remove(struct locomo_dev *dev)
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
deleted file mode 100644
index cc6aaf9e85be..000000000000
--- a/drivers/input/keyboard/maple_keyb.c
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * $Id: maple_keyb.c,v 1.4 2004/03/22 01:18:15 lethal Exp $
3 * SEGA Dreamcast keyboard driver
4 * Based on drivers/usb/usbkbd.c
5 */
6
7#include <linux/kernel.h>
8#include <linux/slab.h>
9#include <linux/input.h>
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/timer.h>
13#include <linux/maple.h>
14
15MODULE_AUTHOR("YAEGASHI Takeshi <t@keshi.org>");
16MODULE_DESCRIPTION("SEGA Dreamcast keyboard driver");
17MODULE_LICENSE("GPL");
18
19static unsigned char dc_kbd_keycode[256] = {
20 0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
21 50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
22 4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
23 27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
24 65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
25 105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
26 72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
27 191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
28 115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
29 122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
30 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
35 150,158,159,128,136,177,178,176,142,152,173,140
36};
37
38
39struct dc_kbd {
40 struct input_dev *dev;
41 unsigned char new[8];
42 unsigned char old[8];
43};
44
45
46static void dc_scan_kbd(struct dc_kbd *kbd)
47{
48 int i;
49 struct input_dev *dev = kbd->dev;
50
51 for (i = 0; i < 8; i++)
52 input_report_key(dev, dc_kbd_keycode[i + 224], (kbd->new[0] >> i) & 1);
53
54 for (i = 2; i < 8; i++) {
55
56 if (kbd->old[i] > 3 && memscan(kbd->new + 2, kbd->old[i], 6) == NULL) {
57 if (dc_kbd_keycode[kbd->old[i]])
58 input_report_key(dev, dc_kbd_keycode[kbd->old[i]], 0);
59 else
60 printk("Unknown key (scancode %#x) released.",
61 kbd->old[i]);
62 }
63
64 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) != NULL) {
65 if(dc_kbd_keycode[kbd->new[i]])
66 input_report_key(dev, dc_kbd_keycode[kbd->new[i]], 1);
67 else
68 printk("Unknown key (scancode %#x) pressed.",
69 kbd->new[i]);
70 }
71 }
72
73 input_sync(dev);
74
75 memcpy(kbd->old, kbd->new, 8);
76}
77
78
79static void dc_kbd_callback(struct mapleq *mq)
80{
81 struct maple_device *mapledev = mq->dev;
82 struct dc_kbd *kbd = mapledev->private_data;
83 unsigned long *buf = mq->recvbuf;
84
85 if (buf[1] == mapledev->function) {
86 memcpy(kbd->new, buf + 2, 8);
87 dc_scan_kbd(kbd);
88 }
89}
90
91static int dc_kbd_connect(struct maple_device *dev)
92{
93 struct dc_kbd *kbd;
94 struct input_dev *input_dev;
95 unsigned long data = be32_to_cpu(dev->devinfo.function_data[0]);
96 int i;
97
98 dev->private_data = kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
99 input_dev = input_allocate_device();
100 if (!kbd || !input_dev) {
101 kfree(kbd);
102 input_free_device(input_dev);
103 return -ENOMEM;
104 }
105
106 kbd->dev = input_dev;
107
108 input_dev->name = dev->product_name;
109 input_dev->id.bustype = BUS_MAPLE;
110 input_dev->private = kbd;
111 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
112 for (i = 0; i < 255; i++)
113 set_bit(dc_kbd_keycode[i], input_dev->keybit);
114 clear_bit(0, input_dev->keybit);
115
116 input_register_device(kbd->dev);
117
118 maple_getcond_callback(dev, dc_kbd_callback, 1, MAPLE_FUNC_KEYBOARD);
119 return 0;
120}
121
122
123static void dc_kbd_disconnect(struct maple_device *dev)
124{
125 struct dc_kbd *kbd = dev->private_data;
126
127 input_unregister_device(kbd->dev);
128 kfree(kbd);
129}
130
131
132static struct maple_driver dc_kbd_driver = {
133 .function = MAPLE_FUNC_KEYBOARD,
134 .name = "Dreamcast keyboard",
135 .connect = dc_kbd_connect,
136 .disconnect = dc_kbd_disconnect,
137};
138
139
140static int __init dc_kbd_init(void)
141{
142 maple_register_driver(&dc_kbd_driver);
143 return 0;
144}
145
146
147static void __exit dc_kbd_exit(void)
148{
149 maple_unregister_driver(&dc_kbd_driver);
150}
151
152
153module_init(dc_kbd_init);
154module_exit(dc_kbd_exit);
155
156/*
157 * Local variables:
158 * c-basic-offset: 8
159 * End:
160 */
diff --git a/drivers/input/keyboard/newtonkbd.c b/drivers/input/keyboard/newtonkbd.c
index 9282e4e082bd..aa29b50765c9 100644
--- a/drivers/input/keyboard/newtonkbd.c
+++ b/drivers/input/keyboard/newtonkbd.c
@@ -91,7 +91,7 @@ static int nkbd_connect(struct serio *serio, struct serio_driver *drv)
91 nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL); 91 nkbd = kzalloc(sizeof(struct nkbd), GFP_KERNEL);
92 input_dev = input_allocate_device(); 92 input_dev = input_allocate_device();
93 if (!nkbd || !input_dev) 93 if (!nkbd || !input_dev)
94 goto fail; 94 goto fail1;
95 95
96 nkbd->serio = serio; 96 nkbd->serio = serio;
97 nkbd->dev = input_dev; 97 nkbd->dev = input_dev;
@@ -119,13 +119,17 @@ static int nkbd_connect(struct serio *serio, struct serio_driver *drv)
119 119
120 err = serio_open(serio, drv); 120 err = serio_open(serio, drv);
121 if (err) 121 if (err)
122 goto fail; 122 goto fail2;
123
124 err = input_register_device(nkbd->dev);
125 if (err)
126 goto fail3;
123 127
124 input_register_device(nkbd->dev);
125 return 0; 128 return 0;
126 129
127 fail: serio_set_drvdata(serio, NULL); 130 fail3: serio_close(serio);
128 input_free_device(input_dev); 131 fail2: serio_set_drvdata(serio, NULL);
132 fail1: input_free_device(input_dev);
129 kfree(nkbd); 133 kfree(nkbd);
130 return err; 134 return err;
131} 135}
@@ -165,8 +169,7 @@ static struct serio_driver nkbd_drv = {
165 169
166static int __init nkbd_init(void) 170static int __init nkbd_init(void)
167{ 171{
168 serio_register_driver(&nkbd_drv); 172 return serio_register_driver(&nkbd_drv);
169 return 0;
170} 173}
171 174
172static void __exit nkbd_exit(void) 175static void __exit nkbd_exit(void)
diff --git a/drivers/input/keyboard/spitzkbd.c b/drivers/input/keyboard/spitzkbd.c
index 28b2748e82d0..8a2166c77ff4 100644
--- a/drivers/input/keyboard/spitzkbd.c
+++ b/drivers/input/keyboard/spitzkbd.c
@@ -346,17 +346,12 @@ static int __init spitzkbd_probe(struct platform_device *dev)
346{ 346{
347 struct spitzkbd *spitzkbd; 347 struct spitzkbd *spitzkbd;
348 struct input_dev *input_dev; 348 struct input_dev *input_dev;
349 int i; 349 int i, err = -ENOMEM;
350 350
351 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL); 351 spitzkbd = kzalloc(sizeof(struct spitzkbd), GFP_KERNEL);
352 if (!spitzkbd)
353 return -ENOMEM;
354
355 input_dev = input_allocate_device(); 352 input_dev = input_allocate_device();
356 if (!input_dev) { 353 if (!spitzkbd || !input_dev)
357 kfree(spitzkbd); 354 goto fail;
358 return -ENOMEM;
359 }
360 355
361 platform_set_drvdata(dev, spitzkbd); 356 platform_set_drvdata(dev, spitzkbd);
362 strcpy(spitzkbd->phys, "spitzkbd/input0"); 357 strcpy(spitzkbd->phys, "spitzkbd/input0");
@@ -400,7 +395,9 @@ static int __init spitzkbd_probe(struct platform_device *dev)
400 set_bit(SW_TABLET_MODE, input_dev->swbit); 395 set_bit(SW_TABLET_MODE, input_dev->swbit);
401 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit); 396 set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
402 397
403 input_register_device(input_dev); 398 err = input_register_device(input_dev);
399 if (err)
400 goto fail;
404 401
405 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL)); 402 mod_timer(&spitzkbd->htimer, jiffies + msecs_to_jiffies(HINGE_SCAN_INTERVAL));
406 403
@@ -434,13 +431,15 @@ static int __init spitzkbd_probe(struct platform_device *dev)
434 request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr, 431 request_irq(SPITZ_IRQ_GPIO_SWB, spitzkbd_hinge_isr,
435 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 432 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
436 "Spitzkbd SWB", spitzkbd); 433 "Spitzkbd SWB", spitzkbd);
437 request_irq(SPITZ_IRQ_GPIO_AK_INT, spitzkbd_hinge_isr, 434 request_irq(SPITZ_IRQ_GPIO_AK_INT, spitzkbd_hinge_isr,
438 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 435 IRQF_DISABLED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
439 "Spitzkbd HP", spitzkbd); 436 "Spitzkbd HP", spitzkbd);
440 437
441 printk(KERN_INFO "input: Spitz Keyboard Registered\n");
442
443 return 0; 438 return 0;
439
440 fail: input_free_device(input_dev);
441 kfree(spitzkbd);
442 return err;
444} 443}
445 444
446static int spitzkbd_remove(struct platform_device *dev) 445static int spitzkbd_remove(struct platform_device *dev)
@@ -474,6 +473,7 @@ static struct platform_driver spitzkbd_driver = {
474 .resume = spitzkbd_resume, 473 .resume = spitzkbd_resume,
475 .driver = { 474 .driver = {
476 .name = "spitz-keyboard", 475 .name = "spitz-keyboard",
476 .owner = THIS_MODULE,
477 }, 477 },
478}; 478};
479 479
diff --git a/drivers/input/keyboard/stowaway.c b/drivers/input/keyboard/stowaway.c
index e60937d17b1c..f7b5c5b81451 100644
--- a/drivers/input/keyboard/stowaway.c
+++ b/drivers/input/keyboard/stowaway.c
@@ -173,8 +173,7 @@ static struct serio_driver skbd_drv = {
173 173
174static int __init skbd_init(void) 174static int __init skbd_init(void)
175{ 175{
176 serio_register_driver(&skbd_drv); 176 return serio_register_driver(&skbd_drv);
177 return 0;
178} 177}
179 178
180static void __exit skbd_exit(void) 179static void __exit skbd_exit(void)
diff --git a/drivers/input/keyboard/sunkbd.c b/drivers/input/keyboard/sunkbd.c
index 6cd887c5eb0a..3826db9403e6 100644
--- a/drivers/input/keyboard/sunkbd.c
+++ b/drivers/input/keyboard/sunkbd.c
@@ -243,7 +243,7 @@ static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
243 sunkbd = kzalloc(sizeof(struct sunkbd), GFP_KERNEL); 243 sunkbd = kzalloc(sizeof(struct sunkbd), GFP_KERNEL);
244 input_dev = input_allocate_device(); 244 input_dev = input_allocate_device();
245 if (!sunkbd || !input_dev) 245 if (!sunkbd || !input_dev)
246 goto fail; 246 goto fail1;
247 247
248 sunkbd->serio = serio; 248 sunkbd->serio = serio;
249 sunkbd->dev = input_dev; 249 sunkbd->dev = input_dev;
@@ -255,11 +255,11 @@ static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
255 255
256 err = serio_open(serio, drv); 256 err = serio_open(serio, drv);
257 if (err) 257 if (err)
258 goto fail; 258 goto fail2;
259 259
260 if (sunkbd_initialize(sunkbd) < 0) { 260 if (sunkbd_initialize(sunkbd) < 0) {
261 serio_close(serio); 261 err = -ENODEV;
262 goto fail; 262 goto fail3;
263 } 263 }
264 264
265 snprintf(sunkbd->name, sizeof(sunkbd->name), "Sun Type %d keyboard", sunkbd->type); 265 snprintf(sunkbd->name, sizeof(sunkbd->name), "Sun Type %d keyboard", sunkbd->type);
@@ -287,11 +287,17 @@ static int sunkbd_connect(struct serio *serio, struct serio_driver *drv)
287 clear_bit(0, input_dev->keybit); 287 clear_bit(0, input_dev->keybit);
288 288
289 sunkbd_enable(sunkbd, 1); 289 sunkbd_enable(sunkbd, 1);
290 input_register_device(sunkbd->dev); 290
291 err = input_register_device(sunkbd->dev);
292 if (err)
293 goto fail4;
294
291 return 0; 295 return 0;
292 296
293 fail: serio_set_drvdata(serio, NULL); 297 fail4: sunkbd_enable(sunkbd, 0);
294 input_free_device(input_dev); 298 fail3: serio_close(serio);
299 fail2: serio_set_drvdata(serio, NULL);
300 fail1: input_free_device(input_dev);
295 kfree(sunkbd); 301 kfree(sunkbd);
296 return err; 302 return err;
297} 303}
@@ -346,8 +352,7 @@ static struct serio_driver sunkbd_drv = {
346 352
347static int __init sunkbd_init(void) 353static int __init sunkbd_init(void)
348{ 354{
349 serio_register_driver(&sunkbd_drv); 355 return serio_register_driver(&sunkbd_drv);
350 return 0;
351} 356}
352 357
353static void __exit sunkbd_exit(void) 358static void __exit sunkbd_exit(void)
diff --git a/drivers/input/keyboard/xtkbd.c b/drivers/input/keyboard/xtkbd.c
index 8c11dc935454..a82093432138 100644
--- a/drivers/input/keyboard/xtkbd.c
+++ b/drivers/input/keyboard/xtkbd.c
@@ -95,7 +95,7 @@ static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
95 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL); 95 xtkbd = kmalloc(sizeof(struct xtkbd), GFP_KERNEL);
96 input_dev = input_allocate_device(); 96 input_dev = input_allocate_device();
97 if (!xtkbd || !input_dev) 97 if (!xtkbd || !input_dev)
98 goto fail; 98 goto fail1;
99 99
100 xtkbd->serio = serio; 100 xtkbd->serio = serio;
101 xtkbd->dev = input_dev; 101 xtkbd->dev = input_dev;
@@ -124,13 +124,17 @@ static int xtkbd_connect(struct serio *serio, struct serio_driver *drv)
124 124
125 err = serio_open(serio, drv); 125 err = serio_open(serio, drv);
126 if (err) 126 if (err)
127 goto fail; 127 goto fail2;
128
129 err = input_register_device(xtkbd->dev);
130 if (err)
131 goto fail3;
128 132
129 input_register_device(xtkbd->dev);
130 return 0; 133 return 0;
131 134
132 fail: serio_set_drvdata(serio, NULL); 135 fail3: serio_close(serio);
133 input_free_device(input_dev); 136 fail2: serio_set_drvdata(serio, NULL);
137 fail1: input_free_device(input_dev);
134 kfree(xtkbd); 138 kfree(xtkbd);
135 return err; 139 return err;
136} 140}
@@ -170,8 +174,7 @@ static struct serio_driver xtkbd_drv = {
170 174
171static int __init xtkbd_init(void) 175static int __init xtkbd_init(void)
172{ 176{
173 serio_register_driver(&xtkbd_drv); 177 return serio_register_driver(&xtkbd_drv);
174 return 0;
175} 178}
176 179
177static void __exit xtkbd_exit(void) 180static void __exit xtkbd_exit(void)
diff --git a/drivers/input/mouse/amimouse.c b/drivers/input/mouse/amimouse.c
index 599a7b2dc519..239a0e16d91a 100644
--- a/drivers/input/mouse/amimouse.c
+++ b/drivers/input/mouse/amimouse.c
@@ -95,10 +95,13 @@ static void amimouse_close(struct input_dev *dev)
95 95
96static int __init amimouse_init(void) 96static int __init amimouse_init(void)
97{ 97{
98 int err;
99
98 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE)) 100 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_MOUSE))
99 return -ENODEV; 101 return -ENODEV;
100 102
101 if (!(amimouse_dev = input_allocate_device())) 103 amimouse_dev = input_allocate_device();
104 if (!amimouse_dev)
102 return -ENOMEM; 105 return -ENOMEM;
103 106
104 amimouse_dev->name = "Amiga mouse"; 107 amimouse_dev->name = "Amiga mouse";
@@ -114,7 +117,11 @@ static int __init amimouse_init(void)
114 amimouse_dev->open = amimouse_open; 117 amimouse_dev->open = amimouse_open;
115 amimouse_dev->close = amimouse_close; 118 amimouse_dev->close = amimouse_close;
116 119
117 input_register_device(amimouse_dev); 120 err = input_register_device(amimouse_dev);
121 if (err) {
122 input_free_device(amimouse_dev);
123 return err;
124 }
118 125
119 return 0; 126 return 0;
120} 127}
diff --git a/drivers/input/mouse/hil_ptr.c b/drivers/input/mouse/hil_ptr.c
index 4f2b503c1ac7..bfb174fe3230 100644
--- a/drivers/input/mouse/hil_ptr.c
+++ b/drivers/input/mouse/hil_ptr.c
@@ -417,8 +417,7 @@ static struct serio_driver hil_ptr_serio_driver = {
417 417
418static int __init hil_ptr_init(void) 418static int __init hil_ptr_init(void)
419{ 419{
420 serio_register_driver(&hil_ptr_serio_driver); 420 return serio_register_driver(&hil_ptr_serio_driver);
421 return 0;
422} 421}
423 422
424static void __exit hil_ptr_exit(void) 423static void __exit hil_ptr_exit(void)
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index e1252fa9a107..13dd96785e39 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -135,6 +135,7 @@ static void inport_close(struct input_dev *dev)
135static int __init inport_init(void) 135static int __init inport_init(void)
136{ 136{
137 unsigned char a, b, c; 137 unsigned char a, b, c;
138 int err;
138 139
139 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) { 140 if (!request_region(INPORT_BASE, INPORT_EXTENT, "inport")) {
140 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE); 141 printk(KERN_ERR "inport.c: Can't allocate ports at %#x\n", INPORT_BASE);
@@ -145,15 +146,16 @@ static int __init inport_init(void)
145 b = inb(INPORT_SIGNATURE_PORT); 146 b = inb(INPORT_SIGNATURE_PORT);
146 c = inb(INPORT_SIGNATURE_PORT); 147 c = inb(INPORT_SIGNATURE_PORT);
147 if (a == b || a != c) { 148 if (a == b || a != c) {
148 release_region(INPORT_BASE, INPORT_EXTENT);
149 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE); 149 printk(KERN_ERR "inport.c: Didn't find InPort mouse at %#x\n", INPORT_BASE);
150 return -ENODEV; 150 err = -ENODEV;
151 goto err_release_region;
151 } 152 }
152 153
153 if (!(inport_dev = input_allocate_device())) { 154 inport_dev = input_allocate_device();
155 if (!inport_dev) {
154 printk(KERN_ERR "inport.c: Not enough memory for input device\n"); 156 printk(KERN_ERR "inport.c: Not enough memory for input device\n");
155 release_region(INPORT_BASE, INPORT_EXTENT); 157 err = -ENOMEM;
156 return -ENOMEM; 158 goto err_release_region;
157 } 159 }
158 160
159 inport_dev->name = INPORT_NAME; 161 inport_dev->name = INPORT_NAME;
@@ -174,9 +176,18 @@ static int __init inport_init(void)
174 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT); 176 outb(INPORT_REG_MODE, INPORT_CONTROL_PORT);
175 outb(INPORT_MODE_BASE, INPORT_DATA_PORT); 177 outb(INPORT_MODE_BASE, INPORT_DATA_PORT);
176 178
177 input_register_device(inport_dev); 179 err = input_register_device(inport_dev);
180 if (err)
181 goto err_free_dev;
178 182
179 return 0; 183 return 0;
184
185 err_free_dev:
186 input_free_device(inport_dev);
187 err_release_region:
188 release_region(INPORT_BASE, INPORT_EXTENT);
189
190 return err;
180} 191}
181 192
182static void __exit inport_exit(void) 193static void __exit inport_exit(void)
diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c
index c57e8853b949..29542f0631cb 100644
--- a/drivers/input/mouse/lifebook.c
+++ b/drivers/input/mouse/lifebook.c
@@ -21,47 +21,51 @@
21#include "lifebook.h" 21#include "lifebook.h"
22 22
23static struct dmi_system_id lifebook_dmi_table[] = { 23static struct dmi_system_id lifebook_dmi_table[] = {
24 { 24 {
25 .ident = "LifeBook B", 25 .ident = "FLORA-ie 55mi",
26 .matches = { 26 .matches = {
27 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"), 27 DMI_MATCH(DMI_PRODUCT_NAME, "FLORA-ie 55mi"),
28 }, 28 },
29 }, 29 },
30 { 30 {
31 .ident = "Lifebook B", 31 .ident = "LifeBook B",
32 .matches = { 32 .matches = {
33 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"), 33 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B Series"),
34 }, 34 },
35 }, 35 },
36 { 36 {
37 .ident = "Lifebook B213x/B2150", 37 .ident = "Lifebook B",
38 .matches = { 38 .matches = {
39 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"), 39 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK B Series"),
40 }, 40 },
41 }, 41 },
42 { 42 {
43 .ident = "Zephyr", 43 .ident = "Lifebook B213x/B2150",
44 .matches = { 44 .matches = {
45 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"), 45 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B2131/B2133/B2150"),
46 }, 46 },
47 }, 47 },
48 { 48 {
49 .ident = "CF-18", 49 .ident = "Zephyr",
50 .matches = { 50 .matches = {
51 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"), 51 DMI_MATCH(DMI_PRODUCT_NAME, "ZEPHYR"),
52 }, 52 },
53 }, 53 },
54 { 54 {
55 .ident = "Lifebook B142", 55 .ident = "CF-18",
56 .matches = { 56 .matches = {
57 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"), 57 DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
58 }, 58 },
59 59 },
60 }, 60 {
61 { } 61 .ident = "Lifebook B142",
62 .matches = {
63 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
64 },
65 },
66 { }
62}; 67};
63 68
64
65static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse) 69static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
66{ 70{
67 unsigned char *packet = psmouse->packet; 71 unsigned char *packet = psmouse->packet;
diff --git a/drivers/input/mouse/logibm.c b/drivers/input/mouse/logibm.c
index 8e9c2f3d69a8..db205995bffd 100644
--- a/drivers/input/mouse/logibm.c
+++ b/drivers/input/mouse/logibm.c
@@ -124,6 +124,8 @@ static void logibm_close(struct input_dev *dev)
124 124
125static int __init logibm_init(void) 125static int __init logibm_init(void)
126{ 126{
127 int err;
128
127 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) { 129 if (!request_region(LOGIBM_BASE, LOGIBM_EXTENT, "logibm")) {
128 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE); 130 printk(KERN_ERR "logibm.c: Can't allocate ports at %#x\n", LOGIBM_BASE);
129 return -EBUSY; 131 return -EBUSY;
@@ -134,18 +136,19 @@ static int __init logibm_init(void)
134 udelay(100); 136 udelay(100);
135 137
136 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) { 138 if (inb(LOGIBM_SIGNATURE_PORT) != LOGIBM_SIGNATURE_BYTE) {
137 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
138 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE); 139 printk(KERN_ERR "logibm.c: Didn't find Logitech busmouse at %#x\n", LOGIBM_BASE);
139 return -ENODEV; 140 err = -ENODEV;
141 goto err_release_region;
140 } 142 }
141 143
142 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT); 144 outb(LOGIBM_DEFAULT_MODE, LOGIBM_CONFIG_PORT);
143 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT); 145 outb(LOGIBM_DISABLE_IRQ, LOGIBM_CONTROL_PORT);
144 146
145 if (!(logibm_dev = input_allocate_device())) { 147 logibm_dev = input_allocate_device();
148 if (!logibm_dev) {
146 printk(KERN_ERR "logibm.c: Not enough memory for input device\n"); 149 printk(KERN_ERR "logibm.c: Not enough memory for input device\n");
147 release_region(LOGIBM_BASE, LOGIBM_EXTENT); 150 err = -ENOMEM;
148 return -ENOMEM; 151 goto err_release_region;
149 } 152 }
150 153
151 logibm_dev->name = "Logitech bus mouse"; 154 logibm_dev->name = "Logitech bus mouse";
@@ -162,9 +165,18 @@ static int __init logibm_init(void)
162 logibm_dev->open = logibm_open; 165 logibm_dev->open = logibm_open;
163 logibm_dev->close = logibm_close; 166 logibm_dev->close = logibm_close;
164 167
165 input_register_device(logibm_dev); 168 err = input_register_device(logibm_dev);
169 if (err)
170 goto err_free_dev;
166 171
167 return 0; 172 return 0;
173
174 err_free_dev:
175 input_free_device(logibm_dev);
176 err_release_region:
177 release_region(LOGIBM_BASE, LOGIBM_EXTENT);
178
179 return err;
168} 180}
169 181
170static void __exit logibm_exit(void) 182static void __exit logibm_exit(void)
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 8a4f862709e7..d3ddea26b8ca 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -328,6 +328,7 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
328 unsigned char model, buttons; 328 unsigned char model, buttons;
329 const struct ps2pp_info *model_info; 329 const struct ps2pp_info *model_info;
330 int use_ps2pp = 0; 330 int use_ps2pp = 0;
331 int error;
331 332
332 param[0] = 0; 333 param[0] = 0;
333 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES); 334 ps2_command(ps2dev, param, PSMOUSE_CMD_SETRES);
@@ -393,8 +394,14 @@ int ps2pp_init(struct psmouse *psmouse, int set_properties)
393 psmouse->set_resolution = ps2pp_set_resolution; 394 psmouse->set_resolution = ps2pp_set_resolution;
394 psmouse->disconnect = ps2pp_disconnect; 395 psmouse->disconnect = ps2pp_disconnect;
395 396
396 device_create_file(&psmouse->ps2dev.serio->dev, 397 error = device_create_file(&psmouse->ps2dev.serio->dev,
397 &psmouse_attr_smartscroll.dattr); 398 &psmouse_attr_smartscroll.dattr);
399 if (error) {
400 printk(KERN_ERR
401 "logips2pp.c: failed to create smartscroll "
402 "sysfs attribute, error: %d\n", error);
403 return -1;
404 }
398 } 405 }
399 } 406 }
400 407
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index 8c075aa7223b..f155c1fea04e 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -108,6 +108,7 @@ static int pc110pad_open(struct input_dev *dev)
108static int __init pc110pad_init(void) 108static int __init pc110pad_init(void)
109{ 109{
110 struct pci_dev *dev; 110 struct pci_dev *dev;
111 int err;
111 112
112 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); 113 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
113 if (dev) { 114 if (dev) {
@@ -124,16 +125,16 @@ static int __init pc110pad_init(void)
124 outb(PC110PAD_OFF, pc110pad_io + 2); 125 outb(PC110PAD_OFF, pc110pad_io + 2);
125 126
126 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) { 127 if (request_irq(pc110pad_irq, pc110pad_interrupt, 0, "pc110pad", NULL)) {
127 release_region(pc110pad_io, 4);
128 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq); 128 printk(KERN_ERR "pc110pad: Unable to get irq %d.\n", pc110pad_irq);
129 return -EBUSY; 129 err = -EBUSY;
130 goto err_release_region;
130 } 131 }
131 132
132 if (!(pc110pad_dev = input_allocate_device())) { 133 pc110pad_dev = input_allocate_device();
133 free_irq(pc110pad_irq, NULL); 134 if (!pc110pad_dev) {
134 release_region(pc110pad_io, 4);
135 printk(KERN_ERR "pc110pad: Not enough memory.\n"); 135 printk(KERN_ERR "pc110pad: Not enough memory.\n");
136 return -ENOMEM; 136 err = -ENOMEM;
137 goto err_free_irq;
137 } 138 }
138 139
139 pc110pad_dev->name = "IBM PC110 TouchPad"; 140 pc110pad_dev->name = "IBM PC110 TouchPad";
@@ -153,9 +154,20 @@ static int __init pc110pad_init(void)
153 pc110pad_dev->open = pc110pad_open; 154 pc110pad_dev->open = pc110pad_open;
154 pc110pad_dev->close = pc110pad_close; 155 pc110pad_dev->close = pc110pad_close;
155 156
156 input_register_device(pc110pad_dev); 157 err = input_register_device(pc110pad_dev);
158 if (err)
159 goto err_free_dev;
157 160
158 return 0; 161 return 0;
162
163 err_free_dev:
164 input_free_device(pc110pad_dev);
165 err_free_irq:
166 free_irq(pc110pad_irq, NULL);
167 err_release_region:
168 release_region(pc110pad_io, 4);
169
170 return err;
159} 171}
160 172
161static void __exit pc110pad_exit(void) 173static void __exit pc110pad_exit(void)
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 52bb2226ce2f..a0e4a033e2db 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -1103,7 +1103,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1103{ 1103{
1104 struct psmouse *psmouse, *parent = NULL; 1104 struct psmouse *psmouse, *parent = NULL;
1105 struct input_dev *input_dev; 1105 struct input_dev *input_dev;
1106 int retval = -ENOMEM; 1106 int retval = 0, error = -ENOMEM;
1107 1107
1108 mutex_lock(&psmouse_mutex); 1108 mutex_lock(&psmouse_mutex);
1109 1109
@@ -1119,7 +1119,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1119 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL); 1119 psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL);
1120 input_dev = input_allocate_device(); 1120 input_dev = input_allocate_device();
1121 if (!psmouse || !input_dev) 1121 if (!psmouse || !input_dev)
1122 goto out; 1122 goto err_free;
1123 1123
1124 ps2_init(&psmouse->ps2dev, serio); 1124 ps2_init(&psmouse->ps2dev, serio);
1125 INIT_WORK(&psmouse->resync_work, psmouse_resync); 1125 INIT_WORK(&psmouse->resync_work, psmouse_resync);
@@ -1130,14 +1130,13 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1130 1130
1131 serio_set_drvdata(serio, psmouse); 1131 serio_set_drvdata(serio, psmouse);
1132 1132
1133 retval = serio_open(serio, drv); 1133 error = serio_open(serio, drv);
1134 if (retval) 1134 if (error)
1135 goto out; 1135 goto err_clear_drvdata;
1136 1136
1137 if (psmouse_probe(psmouse) < 0) { 1137 if (psmouse_probe(psmouse) < 0) {
1138 serio_close(serio); 1138 error = -ENODEV;
1139 retval = -ENODEV; 1139 goto err_close_serio;
1140 goto out;
1141 } 1140 }
1142 1141
1143 psmouse->rate = psmouse_rate; 1142 psmouse->rate = psmouse_rate;
@@ -1151,30 +1150,44 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1151 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1150 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1152 psmouse_initialize(psmouse); 1151 psmouse_initialize(psmouse);
1153 1152
1154 input_register_device(psmouse->dev); 1153 error = input_register_device(psmouse->dev);
1154 if (error)
1155 goto err_protocol_disconnect;
1155 1156
1156 if (parent && parent->pt_activate) 1157 if (parent && parent->pt_activate)
1157 parent->pt_activate(parent); 1158 parent->pt_activate(parent);
1158 1159
1159 sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group); 1160 error = sysfs_create_group(&serio->dev.kobj, &psmouse_attribute_group);
1161 if (error)
1162 goto err_pt_deactivate;
1160 1163
1161 psmouse_activate(psmouse); 1164 psmouse_activate(psmouse);
1162 1165
1163 retval = 0; 1166 out:
1164
1165out:
1166 if (retval) {
1167 serio_set_drvdata(serio, NULL);
1168 input_free_device(input_dev);
1169 kfree(psmouse);
1170 }
1171
1172 /* If this is a pass-through port the parent needs to be re-activated */ 1167 /* If this is a pass-through port the parent needs to be re-activated */
1173 if (parent) 1168 if (parent)
1174 psmouse_activate(parent); 1169 psmouse_activate(parent);
1175 1170
1176 mutex_unlock(&psmouse_mutex); 1171 mutex_unlock(&psmouse_mutex);
1177 return retval; 1172 return retval;
1173
1174 err_pt_deactivate:
1175 if (parent && parent->pt_deactivate)
1176 parent->pt_deactivate(parent);
1177 err_protocol_disconnect:
1178 if (psmouse->disconnect)
1179 psmouse->disconnect(psmouse);
1180 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1181 err_close_serio:
1182 serio_close(serio);
1183 err_clear_drvdata:
1184 serio_set_drvdata(serio, NULL);
1185 err_free:
1186 input_free_device(input_dev);
1187 kfree(psmouse);
1188
1189 retval = error;
1190 goto out;
1178} 1191}
1179 1192
1180 1193
@@ -1337,14 +1350,14 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
1337 1350
1338static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf) 1351static ssize_t psmouse_show_int_attr(struct psmouse *psmouse, void *offset, char *buf)
1339{ 1352{
1340 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset); 1353 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1341 1354
1342 return sprintf(buf, "%lu\n", *field); 1355 return sprintf(buf, "%u\n", *field);
1343} 1356}
1344 1357
1345static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count) 1358static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const char *buf, size_t count)
1346{ 1359{
1347 unsigned long *field = (unsigned long *)((char *)psmouse + (size_t)offset); 1360 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1348 unsigned long value; 1361 unsigned long value;
1349 char *rest; 1362 char *rest;
1350 1363
@@ -1352,6 +1365,9 @@ static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const
1352 if (*rest) 1365 if (*rest)
1353 return -EINVAL; 1366 return -EINVAL;
1354 1367
1368 if ((unsigned int)value != value)
1369 return -EINVAL;
1370
1355 *field = value; 1371 *field = value;
1356 1372
1357 return count; 1373 return count;
@@ -1366,17 +1382,20 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1366{ 1382{
1367 struct serio *serio = psmouse->ps2dev.serio; 1383 struct serio *serio = psmouse->ps2dev.serio;
1368 struct psmouse *parent = NULL; 1384 struct psmouse *parent = NULL;
1369 struct input_dev *new_dev; 1385 struct input_dev *old_dev, *new_dev;
1370 const struct psmouse_protocol *proto; 1386 const struct psmouse_protocol *proto, *old_proto;
1387 int error;
1371 int retry = 0; 1388 int retry = 0;
1372 1389
1373 if (!(proto = psmouse_protocol_by_name(buf, count))) 1390 proto = psmouse_protocol_by_name(buf, count);
1391 if (!proto)
1374 return -EINVAL; 1392 return -EINVAL;
1375 1393
1376 if (psmouse->type == proto->type) 1394 if (psmouse->type == proto->type)
1377 return count; 1395 return count;
1378 1396
1379 if (!(new_dev = input_allocate_device())) 1397 new_dev = input_allocate_device();
1398 if (!new_dev)
1380 return -ENOMEM; 1399 return -ENOMEM;
1381 1400
1382 while (serio->child) { 1401 while (serio->child) {
@@ -1409,11 +1428,13 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1409 parent->pt_deactivate(parent); 1428 parent->pt_deactivate(parent);
1410 } 1429 }
1411 1430
1431 old_dev = psmouse->dev;
1432 old_proto = psmouse_protocol_by_type(psmouse->type);
1433
1412 if (psmouse->disconnect) 1434 if (psmouse->disconnect)
1413 psmouse->disconnect(psmouse); 1435 psmouse->disconnect(psmouse);
1414 1436
1415 psmouse_set_state(psmouse, PSMOUSE_IGNORE); 1437 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1416 input_unregister_device(psmouse->dev);
1417 1438
1418 psmouse->dev = new_dev; 1439 psmouse->dev = new_dev;
1419 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING); 1440 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
@@ -1427,7 +1448,23 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1427 psmouse_initialize(psmouse); 1448 psmouse_initialize(psmouse);
1428 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE); 1449 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1429 1450
1430 input_register_device(psmouse->dev); 1451 error = input_register_device(psmouse->dev);
1452 if (error) {
1453 if (psmouse->disconnect)
1454 psmouse->disconnect(psmouse);
1455
1456 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
1457 input_free_device(new_dev);
1458 psmouse->dev = old_dev;
1459 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
1460 psmouse_switch_protocol(psmouse, old_proto);
1461 psmouse_initialize(psmouse);
1462 psmouse_set_state(psmouse, PSMOUSE_CMD_MODE);
1463
1464 return error;
1465 }
1466
1467 input_unregister_device(old_dev);
1431 1468
1432 if (parent && parent->pt_activate) 1469 if (parent && parent->pt_activate)
1433 parent->pt_activate(parent); 1470 parent->pt_activate(parent);
@@ -1488,15 +1525,19 @@ static int psmouse_get_maxproto(char *buffer, struct kernel_param *kp)
1488 1525
1489static int __init psmouse_init(void) 1526static int __init psmouse_init(void)
1490{ 1527{
1528 int err;
1529
1491 kpsmoused_wq = create_singlethread_workqueue("kpsmoused"); 1530 kpsmoused_wq = create_singlethread_workqueue("kpsmoused");
1492 if (!kpsmoused_wq) { 1531 if (!kpsmoused_wq) {
1493 printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n"); 1532 printk(KERN_ERR "psmouse: failed to create kpsmoused workqueue\n");
1494 return -ENOMEM; 1533 return -ENOMEM;
1495 } 1534 }
1496 1535
1497 serio_register_driver(&psmouse_drv); 1536 err = serio_register_driver(&psmouse_drv);
1537 if (err)
1538 destroy_workqueue(kpsmoused_wq);
1498 1539
1499 return 0; 1540 return err;
1500} 1541}
1501 1542
1502static void __exit psmouse_exit(void) 1543static void __exit psmouse_exit(void)
diff --git a/drivers/input/mouse/rpcmouse.c b/drivers/input/mouse/rpcmouse.c
index ea0468569610..fbdcfd8eb4e9 100644
--- a/drivers/input/mouse/rpcmouse.c
+++ b/drivers/input/mouse/rpcmouse.c
@@ -66,7 +66,10 @@ static irqreturn_t rpcmouse_irq(int irq, void *dev_id)
66 66
67static int __init rpcmouse_init(void) 67static int __init rpcmouse_init(void)
68{ 68{
69 if (!(rpcmouse_dev = input_allocate_device())) 69 int err;
70
71 rpcmouse_dev = input_allocate_device();
72 if (!rpcmouse_dev)
70 return -ENOMEM; 73 return -ENOMEM;
71 74
72 rpcmouse_dev->name = "Acorn RiscPC Mouse"; 75 rpcmouse_dev->name = "Acorn RiscPC Mouse";
@@ -85,13 +88,22 @@ static int __init rpcmouse_init(void)
85 88
86 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) { 89 if (request_irq(IRQ_VSYNCPULSE, rpcmouse_irq, IRQF_SHARED, "rpcmouse", rpcmouse_dev)) {
87 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n"); 90 printk(KERN_ERR "rpcmouse: unable to allocate VSYNC interrupt\n");
88 input_free_device(rpcmouse_dev); 91 err = -EBUSY;
89 return -EBUSY; 92 goto err_free_dev;
90 } 93 }
91 94
92 input_register_device(rpcmouse_dev); 95 err = input_register_device(rpcmouse_dev);
96 if (err)
97 goto err_free_irq;
93 98
94 return 0; 99 return 0;
100
101 err_free_irq:
102 free_irq(IRQ_VSYNCPULSE, rpcmouse_dev);
103 err_free_dev:
104 input_free_device(rpcmouse_dev);
105
106 return err;
95} 107}
96 108
97static void __exit rpcmouse_exit(void) 109static void __exit rpcmouse_exit(void)
diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c
index 2a272c5daf08..a85d74710b44 100644
--- a/drivers/input/mouse/sermouse.c
+++ b/drivers/input/mouse/sermouse.c
@@ -246,7 +246,7 @@ static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
246 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL); 246 sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL);
247 input_dev = input_allocate_device(); 247 input_dev = input_allocate_device();
248 if (!sermouse || !input_dev) 248 if (!sermouse || !input_dev)
249 goto fail; 249 goto fail1;
250 250
251 sermouse->dev = input_dev; 251 sermouse->dev = input_dev;
252 snprintf(sermouse->phys, sizeof(sermouse->phys), "%s/input0", serio->phys); 252 snprintf(sermouse->phys, sizeof(sermouse->phys), "%s/input0", serio->phys);
@@ -275,14 +275,17 @@ static int sermouse_connect(struct serio *serio, struct serio_driver *drv)
275 275
276 err = serio_open(serio, drv); 276 err = serio_open(serio, drv);
277 if (err) 277 if (err)
278 goto fail; 278 goto fail2;
279 279
280 input_register_device(sermouse->dev); 280 err = input_register_device(sermouse->dev);
281 if (err)
282 goto fail3;
281 283
282 return 0; 284 return 0;
283 285
284 fail: serio_set_drvdata(serio, NULL); 286 fail3: serio_close(serio);
285 input_free_device(input_dev); 287 fail2: serio_set_drvdata(serio, NULL);
288 fail1: input_free_device(input_dev);
286 kfree(sermouse); 289 kfree(sermouse);
287 return err; 290 return err;
288} 291}
@@ -348,8 +351,7 @@ static struct serio_driver sermouse_drv = {
348 351
349static int __init sermouse_init(void) 352static int __init sermouse_init(void)
350{ 353{
351 serio_register_driver(&sermouse_drv); 354 return serio_register_driver(&sermouse_drv);
352 return 0;
353} 355}
354 356
355static void __exit sermouse_exit(void) 357static void __exit sermouse_exit(void)
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index ae5871a0e060..9ab5b5ea809d 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -293,6 +293,7 @@ int trackpoint_detect(struct psmouse *psmouse, int set_properties)
293 struct ps2dev *ps2dev = &psmouse->ps2dev; 293 struct ps2dev *ps2dev = &psmouse->ps2dev;
294 unsigned char firmware_id; 294 unsigned char firmware_id;
295 unsigned char button_info; 295 unsigned char button_info;
296 int error;
296 297
297 if (trackpoint_start_protocol(psmouse, &firmware_id)) 298 if (trackpoint_start_protocol(psmouse, &firmware_id))
298 return -1; 299 return -1;
@@ -305,7 +306,7 @@ int trackpoint_detect(struct psmouse *psmouse, int set_properties)
305 button_info = 0; 306 button_info = 0;
306 } 307 }
307 308
308 psmouse->private = priv = kcalloc(1, sizeof(struct trackpoint_data), GFP_KERNEL); 309 psmouse->private = priv = kzalloc(sizeof(struct trackpoint_data), GFP_KERNEL);
309 if (!priv) 310 if (!priv)
310 return -1; 311 return -1;
311 312
@@ -318,7 +319,14 @@ int trackpoint_detect(struct psmouse *psmouse, int set_properties)
318 trackpoint_defaults(priv); 319 trackpoint_defaults(priv);
319 trackpoint_sync(psmouse); 320 trackpoint_sync(psmouse);
320 321
321 sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group); 322 error = sysfs_create_group(&ps2dev->serio->dev.kobj, &trackpoint_attr_group);
323 if (error) {
324 printk(KERN_ERR
325 "trackpoint.c: failed to create sysfs attributes, error: %d\n",
326 error);
327 kfree(priv);
328 return -1;
329 }
322 330
323 printk(KERN_INFO "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n", 331 printk(KERN_INFO "IBM TrackPoint firmware: 0x%02x, buttons: %d/%d\n",
324 firmware_id, (button_info & 0xf0) >> 4, button_info & 0x0f); 332 firmware_id, (button_info & 0xf0) >> 4, button_info & 0x0f);
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index ffdb50eee93d..c3d64fcc858d 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -497,7 +497,7 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
497 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL); 497 mouse = kzalloc (sizeof (struct vsxxxaa), GFP_KERNEL);
498 input_dev = input_allocate_device (); 498 input_dev = input_allocate_device ();
499 if (!mouse || !input_dev) 499 if (!mouse || !input_dev)
500 goto fail; 500 goto fail1;
501 501
502 mouse->dev = input_dev; 502 mouse->dev = input_dev;
503 mouse->serio = serio; 503 mouse->serio = serio;
@@ -527,7 +527,7 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
527 527
528 err = serio_open (serio, drv); 528 err = serio_open (serio, drv);
529 if (err) 529 if (err)
530 goto fail; 530 goto fail2;
531 531
532 /* 532 /*
533 * Request selftest. Standard packet format and differential 533 * Request selftest. Standard packet format and differential
@@ -535,12 +535,15 @@ vsxxxaa_connect (struct serio *serio, struct serio_driver *drv)
535 */ 535 */
536 serio->write (serio, 'T'); /* Test */ 536 serio->write (serio, 'T'); /* Test */
537 537
538 input_register_device (input_dev); 538 err = input_register_device (input_dev);
539 if (err)
540 goto fail3;
539 541
540 return 0; 542 return 0;
541 543
542 fail: serio_set_drvdata (serio, NULL); 544 fail3: serio_close (serio);
543 input_free_device (input_dev); 545 fail2: serio_set_drvdata (serio, NULL);
546 fail1: input_free_device (input_dev);
544 kfree (mouse); 547 kfree (mouse);
545 return err; 548 return err;
546} 549}
@@ -571,8 +574,7 @@ static struct serio_driver vsxxxaa_drv = {
571static int __init 574static int __init
572vsxxxaa_init (void) 575vsxxxaa_init (void)
573{ 576{
574 serio_register_driver(&vsxxxaa_drv); 577 return serio_register_driver(&vsxxxaa_drv);
575 return 0;
576} 578}
577 579
578static void __exit 580static void __exit
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index a22a74a2a3dc..664bcc8116fc 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -196,12 +196,12 @@ static void mousedev_key_event(struct mousedev *mousedev, unsigned int code, int
196 switch (code) { 196 switch (code) {
197 case BTN_TOUCH: 197 case BTN_TOUCH:
198 case BTN_0: 198 case BTN_0:
199 case BTN_FORWARD:
200 case BTN_LEFT: index = 0; break; 199 case BTN_LEFT: index = 0; break;
201 case BTN_STYLUS: 200 case BTN_STYLUS:
202 case BTN_1: 201 case BTN_1:
203 case BTN_RIGHT: index = 1; break; 202 case BTN_RIGHT: index = 1; break;
204 case BTN_2: 203 case BTN_2:
204 case BTN_FORWARD:
205 case BTN_STYLUS2: 205 case BTN_STYLUS2:
206 case BTN_MIDDLE: index = 2; break; 206 case BTN_MIDDLE: index = 2; break;
207 case BTN_3: 207 case BTN_3:
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 8738edda6610..d36bd5475b6d 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -111,6 +111,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
111 }, 111 },
112 }, 112 },
113 { 113 {
114 .ident = "Fujitsu Lifebook P7010",
115 .matches = {
116 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
117 DMI_MATCH(DMI_PRODUCT_NAME, "0000000000"),
118 },
119 },
120 {
114 .ident = "Fujitsu Lifebook P5020D", 121 .ident = "Fujitsu Lifebook P5020D",
115 .matches = { 122 .matches = {
116 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"), 123 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index 7e3141f37e32..debe9445488c 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -255,25 +255,10 @@ static int i8042_kbd_write(struct serio *port, unsigned char c)
255static int i8042_aux_write(struct serio *serio, unsigned char c) 255static int i8042_aux_write(struct serio *serio, unsigned char c)
256{ 256{
257 struct i8042_port *port = serio->port_data; 257 struct i8042_port *port = serio->port_data;
258 int retval;
259
260/*
261 * Send the byte out.
262 */
263
264 if (port->mux == -1)
265 retval = i8042_command(&c, I8042_CMD_AUX_SEND);
266 else
267 retval = i8042_command(&c, I8042_CMD_MUX_SEND + port->mux);
268
269/*
270 * Make sure the interrupt happens and the character is received even
271 * in the case the IRQ isn't wired, so that we can receive further
272 * characters later.
273 */
274 258
275 i8042_interrupt(0, NULL); 259 return i8042_command(&c, port->mux == -1 ?
276 return retval; 260 I8042_CMD_AUX_SEND :
261 I8042_CMD_MUX_SEND + port->mux);
277} 262}
278 263
279/* 264/*
@@ -337,23 +322,27 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id)
337 dfl = 0; 322 dfl = 0;
338 if (str & I8042_STR_MUXERR) { 323 if (str & I8042_STR_MUXERR) {
339 dbg("MUX error, status is %02x, data is %02x", str, data); 324 dbg("MUX error, status is %02x, data is %02x", str, data);
340 switch (data) {
341 default:
342/* 325/*
343 * When MUXERR condition is signalled the data register can only contain 326 * When MUXERR condition is signalled the data register can only contain
344 * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately 327 * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately
345 * it is not always the case. Some KBC just get confused which port the 328 * it is not always the case. Some KBCs also report 0xfc when there is
346 * data came from and signal error leaving the data intact. They _do not_ 329 * nothing connected to the port while others sometimes get confused which
347 * revert to legacy mode (actually I've never seen KBC reverting to legacy 330 * port the data came from and signal error leaving the data intact. They
348 * mode yet, when we see one we'll add proper handling). 331 * _do not_ revert to legacy mode (actually I've never seen KBC reverting
349 * Anyway, we will assume that the data came from the same serio last byte 332 * to legacy mode yet, when we see one we'll add proper handling).
333 * Anyway, we process 0xfc, 0xfd, 0xfe and 0xff as timeouts, and for the
334 * rest assume that the data came from the same serio last byte
350 * was transmitted (if transmission happened not too long ago). 335 * was transmitted (if transmission happened not too long ago).
351 */ 336 */
337
338 switch (data) {
339 default:
352 if (time_before(jiffies, last_transmit + HZ/10)) { 340 if (time_before(jiffies, last_transmit + HZ/10)) {
353 str = last_str; 341 str = last_str;
354 break; 342 break;
355 } 343 }
356 /* fall through - report timeout */ 344 /* fall through - report timeout */
345 case 0xfc:
357 case 0xfd: 346 case 0xfd:
358 case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break; 347 case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break;
359 case 0xff: dfl = SERIO_PARITY; data = 0xfe; break; 348 case 0xff: dfl = SERIO_PARITY; data = 0xfe; break;
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index 5f1d4032fd57..f0ce822c1028 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -45,8 +45,7 @@ EXPORT_SYMBOL(serio_interrupt);
45EXPORT_SYMBOL(__serio_register_port); 45EXPORT_SYMBOL(__serio_register_port);
46EXPORT_SYMBOL(serio_unregister_port); 46EXPORT_SYMBOL(serio_unregister_port);
47EXPORT_SYMBOL(serio_unregister_child_port); 47EXPORT_SYMBOL(serio_unregister_child_port);
48EXPORT_SYMBOL(__serio_unregister_port_delayed); 48EXPORT_SYMBOL(serio_register_driver);
49EXPORT_SYMBOL(__serio_register_driver);
50EXPORT_SYMBOL(serio_unregister_driver); 49EXPORT_SYMBOL(serio_unregister_driver);
51EXPORT_SYMBOL(serio_open); 50EXPORT_SYMBOL(serio_open);
52EXPORT_SYMBOL(serio_close); 51EXPORT_SYMBOL(serio_close);
@@ -63,11 +62,10 @@ static LIST_HEAD(serio_list);
63 62
64static struct bus_type serio_bus; 63static struct bus_type serio_bus;
65 64
66static void serio_add_driver(struct serio_driver *drv);
67static void serio_add_port(struct serio *serio); 65static void serio_add_port(struct serio *serio);
68static void serio_destroy_port(struct serio *serio);
69static void serio_reconnect_port(struct serio *serio); 66static void serio_reconnect_port(struct serio *serio);
70static void serio_disconnect_port(struct serio *serio); 67static void serio_disconnect_port(struct serio *serio);
68static void serio_attach_driver(struct serio_driver *drv);
71 69
72static int serio_connect_driver(struct serio *serio, struct serio_driver *drv) 70static int serio_connect_driver(struct serio *serio, struct serio_driver *drv)
73{ 71{
@@ -171,11 +169,10 @@ static void serio_find_driver(struct serio *serio)
171 */ 169 */
172 170
173enum serio_event_type { 171enum serio_event_type {
174 SERIO_RESCAN, 172 SERIO_RESCAN_PORT,
175 SERIO_RECONNECT, 173 SERIO_RECONNECT_PORT,
176 SERIO_REGISTER_PORT, 174 SERIO_REGISTER_PORT,
177 SERIO_UNREGISTER_PORT, 175 SERIO_ATTACH_DRIVER,
178 SERIO_REGISTER_DRIVER,
179}; 176};
180 177
181struct serio_event { 178struct serio_event {
@@ -190,11 +187,12 @@ static LIST_HEAD(serio_event_list);
190static DECLARE_WAIT_QUEUE_HEAD(serio_wait); 187static DECLARE_WAIT_QUEUE_HEAD(serio_wait);
191static struct task_struct *serio_task; 188static struct task_struct *serio_task;
192 189
193static void serio_queue_event(void *object, struct module *owner, 190static int serio_queue_event(void *object, struct module *owner,
194 enum serio_event_type event_type) 191 enum serio_event_type event_type)
195{ 192{
196 unsigned long flags; 193 unsigned long flags;
197 struct serio_event *event; 194 struct serio_event *event;
195 int retval = 0;
198 196
199 spin_lock_irqsave(&serio_event_lock, flags); 197 spin_lock_irqsave(&serio_event_lock, flags);
200 198
@@ -213,24 +211,34 @@ static void serio_queue_event(void *object, struct module *owner,
213 } 211 }
214 } 212 }
215 213
216 if ((event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC))) { 214 event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC);
217 if (!try_module_get(owner)) { 215 if (!event) {
218 printk(KERN_WARNING "serio: Can't get module reference, dropping event %d\n", event_type); 216 printk(KERN_ERR
219 kfree(event); 217 "serio: Not enough memory to queue event %d\n",
220 goto out; 218 event_type);
221 } 219 retval = -ENOMEM;
222 220 goto out;
223 event->type = event_type; 221 }
224 event->object = object;
225 event->owner = owner;
226 222
227 list_add_tail(&event->node, &serio_event_list); 223 if (!try_module_get(owner)) {
228 wake_up(&serio_wait); 224 printk(KERN_WARNING
229 } else { 225 "serio: Can't get module reference, dropping event %d\n",
230 printk(KERN_ERR "serio: Not enough memory to queue event %d\n", event_type); 226 event_type);
227 kfree(event);
228 retval = -EINVAL;
229 goto out;
231 } 230 }
231
232 event->type = event_type;
233 event->object = object;
234 event->owner = owner;
235
236 list_add_tail(&event->node, &serio_event_list);
237 wake_up(&serio_wait);
238
232out: 239out:
233 spin_unlock_irqrestore(&serio_event_lock, flags); 240 spin_unlock_irqrestore(&serio_event_lock, flags);
241 return retval;
234} 242}
235 243
236static void serio_free_event(struct serio_event *event) 244static void serio_free_event(struct serio_event *event)
@@ -308,22 +316,17 @@ static void serio_handle_event(void)
308 serio_add_port(event->object); 316 serio_add_port(event->object);
309 break; 317 break;
310 318
311 case SERIO_UNREGISTER_PORT: 319 case SERIO_RECONNECT_PORT:
312 serio_disconnect_port(event->object);
313 serio_destroy_port(event->object);
314 break;
315
316 case SERIO_RECONNECT:
317 serio_reconnect_port(event->object); 320 serio_reconnect_port(event->object);
318 break; 321 break;
319 322
320 case SERIO_RESCAN: 323 case SERIO_RESCAN_PORT:
321 serio_disconnect_port(event->object); 324 serio_disconnect_port(event->object);
322 serio_find_driver(event->object); 325 serio_find_driver(event->object);
323 break; 326 break;
324 327
325 case SERIO_REGISTER_DRIVER: 328 case SERIO_ATTACH_DRIVER:
326 serio_add_driver(event->object); 329 serio_attach_driver(event->object);
327 break; 330 break;
328 331
329 default: 332 default:
@@ -675,12 +678,12 @@ static void serio_disconnect_port(struct serio *serio)
675 678
676void serio_rescan(struct serio *serio) 679void serio_rescan(struct serio *serio)
677{ 680{
678 serio_queue_event(serio, NULL, SERIO_RESCAN); 681 serio_queue_event(serio, NULL, SERIO_RESCAN_PORT);
679} 682}
680 683
681void serio_reconnect(struct serio *serio) 684void serio_reconnect(struct serio *serio)
682{ 685{
683 serio_queue_event(serio, NULL, SERIO_RECONNECT); 686 serio_queue_event(serio, NULL, SERIO_RECONNECT_PORT);
684} 687}
685 688
686/* 689/*
@@ -717,16 +720,6 @@ void serio_unregister_child_port(struct serio *serio)
717 mutex_unlock(&serio_mutex); 720 mutex_unlock(&serio_mutex);
718} 721}
719 722
720/*
721 * Submits register request to kseriod for subsequent execution.
722 * Can be used when it is not obvious whether the serio_mutex is
723 * taken or not and when delayed execution is feasible.
724 */
725void __serio_unregister_port_delayed(struct serio *serio, struct module *owner)
726{
727 serio_queue_event(serio, owner, SERIO_UNREGISTER_PORT);
728}
729
730 723
731/* 724/*
732 * Serio driver operations 725 * Serio driver operations
@@ -785,28 +778,52 @@ static int serio_driver_remove(struct device *dev)
785 return 0; 778 return 0;
786} 779}
787 780
788static struct bus_type serio_bus = { 781static void serio_attach_driver(struct serio_driver *drv)
789 .name = "serio",
790 .probe = serio_driver_probe,
791 .remove = serio_driver_remove,
792};
793
794static void serio_add_driver(struct serio_driver *drv)
795{ 782{
796 int error; 783 int error;
797 784
798 error = driver_register(&drv->driver); 785 error = driver_attach(&drv->driver);
799 if (error) 786 if (error)
800 printk(KERN_ERR 787 printk(KERN_WARNING
801 "serio: driver_register() failed for %s, error: %d\n", 788 "serio: driver_attach() failed for %s with error %d\n",
802 drv->driver.name, error); 789 drv->driver.name, error);
803} 790}
804 791
805void __serio_register_driver(struct serio_driver *drv, struct module *owner) 792int serio_register_driver(struct serio_driver *drv)
806{ 793{
794 int manual_bind = drv->manual_bind;
795 int error;
796
807 drv->driver.bus = &serio_bus; 797 drv->driver.bus = &serio_bus;
808 798
809 serio_queue_event(drv, owner, SERIO_REGISTER_DRIVER); 799 /*
800 * Temporarily disable automatic binding because probing
801 * takes long time and we are better off doing it in kseriod
802 */
803 drv->manual_bind = 1;
804
805 error = driver_register(&drv->driver);
806 if (error) {
807 printk(KERN_ERR
808 "serio: driver_register() failed for %s, error: %d\n",
809 drv->driver.name, error);
810 return error;
811 }
812
813 /*
814 * Restore original bind mode and let kseriod bind the
815 * driver to free ports
816 */
817 if (!manual_bind) {
818 drv->manual_bind = 0;
819 error = serio_queue_event(drv, NULL, SERIO_ATTACH_DRIVER);
820 if (error) {
821 driver_unregister(&drv->driver);
822 return error;
823 }
824 }
825
826 return 0;
810} 827}
811 828
812void serio_unregister_driver(struct serio_driver *drv) 829void serio_unregister_driver(struct serio_driver *drv)
@@ -947,15 +964,21 @@ irqreturn_t serio_interrupt(struct serio *serio,
947 return ret; 964 return ret;
948} 965}
949 966
967static struct bus_type serio_bus = {
968 .name = "serio",
969 .dev_attrs = serio_device_attrs,
970 .drv_attrs = serio_driver_attrs,
971 .match = serio_bus_match,
972 .uevent = serio_uevent,
973 .probe = serio_driver_probe,
974 .remove = serio_driver_remove,
975 .resume = serio_resume,
976};
977
950static int __init serio_init(void) 978static int __init serio_init(void)
951{ 979{
952 int error; 980 int error;
953 981
954 serio_bus.dev_attrs = serio_device_attrs;
955 serio_bus.drv_attrs = serio_driver_attrs;
956 serio_bus.match = serio_bus_match;
957 serio_bus.uevent = serio_uevent;
958 serio_bus.resume = serio_resume;
959 error = bus_register(&serio_bus); 982 error = bus_register(&serio_bus);
960 if (error) { 983 if (error) {
961 printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error); 984 printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error);
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index 7c8d0399ae82..088ebc348ba3 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -389,8 +389,7 @@ static struct serio_driver serio_raw_drv = {
389 389
390static int __init serio_raw_init(void) 390static int __init serio_raw_init(void)
391{ 391{
392 serio_register_driver(&serio_raw_drv); 392 return serio_register_driver(&serio_raw_drv);
393 return 0;
394} 393}
395 394
396static void __exit serio_raw_exit(void) 395static void __exit serio_raw_exit(void)
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9418bbe47072..6b46c9bf1d20 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -144,4 +144,19 @@ config TOUCHSCREEN_TOUCHWIN
144 To compile this driver as a module, choose M here: the 144 To compile this driver as a module, choose M here: the
145 module will be called touchwin. 145 module will be called touchwin.
146 146
147config TOUCHSCREEN_UCB1400
148 tristate "Philips UCB1400 touchscreen"
149 select AC97_BUS
150 help
151 This enables support for the Philips UCB1400 touchscreen interface.
152 The UCB1400 is an AC97 audio codec. The touchscreen interface
153 will be initialized only after the ALSA subsystem has been
154 brought up and the UCB1400 detected. You therefore have to
155 configure ALSA support as well (either built-in or modular,
156 independently of whether this driver is itself built-in or
157 modular) for this driver to work.
158
159 To compile this driver as a module, choose M here: the
160 module will be called ucb1400_ts.
161
147endif 162endif
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 1abb8f10d608..30e6e2217a15 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o
15obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o 15obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o
16obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o 16obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o
17obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o 17obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o
18obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 0517c7387d67..c6164b6f476a 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -76,6 +76,7 @@ struct ads7846 {
76 char phys[32]; 76 char phys[32];
77 77
78 struct spi_device *spi; 78 struct spi_device *spi;
79 struct attribute_group *attr_group;
79 u16 model; 80 u16 model;
80 u16 vref_delay_usecs; 81 u16 vref_delay_usecs;
81 u16 x_plate_ohms; 82 u16 x_plate_ohms;
@@ -317,6 +318,48 @@ static ssize_t ads7846_disable_store(struct device *dev,
317 318
318static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); 319static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
319 320
321static struct attribute *ads7846_attributes[] = {
322 &dev_attr_temp0.attr,
323 &dev_attr_temp1.attr,
324 &dev_attr_vbatt.attr,
325 &dev_attr_vaux.attr,
326 &dev_attr_pen_down.attr,
327 &dev_attr_disable.attr,
328 NULL,
329};
330
331static struct attribute_group ads7846_attr_group = {
332 .attrs = ads7846_attributes,
333};
334
335/*
336 * ads7843/7845 don't have temperature sensors, and
337 * use the other sensors a bit differently too
338 */
339
340static struct attribute *ads7843_attributes[] = {
341 &dev_attr_vbatt.attr,
342 &dev_attr_vaux.attr,
343 &dev_attr_pen_down.attr,
344 &dev_attr_disable.attr,
345 NULL,
346};
347
348static struct attribute_group ads7843_attr_group = {
349 .attrs = ads7843_attributes,
350};
351
352static struct attribute *ads7845_attributes[] = {
353 &dev_attr_vaux.attr,
354 &dev_attr_pen_down.attr,
355 &dev_attr_disable.attr,
356 NULL,
357};
358
359static struct attribute_group ads7845_attr_group = {
360 .attrs = ads7845_attributes,
361};
362
320/*--------------------------------------------------------------------------*/ 363/*--------------------------------------------------------------------------*/
321 364
322/* 365/*
@@ -788,38 +831,30 @@ static int __devinit ads7846_probe(struct spi_device *spi)
788 (void) ads7846_read12_ser(&spi->dev, 831 (void) ads7846_read12_ser(&spi->dev,
789 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); 832 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
790 833
791 /* ads7843/7845 don't have temperature sensors, and 834 switch (ts->model) {
792 * use the other sensors a bit differently too 835 case 7846:
793 */ 836 ts->attr_group = &ads7846_attr_group;
794 if (ts->model == 7846) { 837 break;
795 device_create_file(&spi->dev, &dev_attr_temp0); 838 case 7845:
796 device_create_file(&spi->dev, &dev_attr_temp1); 839 ts->attr_group = &ads7845_attr_group;
840 break;
841 default:
842 ts->attr_group = &ads7843_attr_group;
843 break;
797 } 844 }
798 if (ts->model != 7845) 845 err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
799 device_create_file(&spi->dev, &dev_attr_vbatt); 846 if (err)
800 device_create_file(&spi->dev, &dev_attr_vaux); 847 goto err_free_irq;
801
802 device_create_file(&spi->dev, &dev_attr_pen_down);
803
804 device_create_file(&spi->dev, &dev_attr_disable);
805 848
806 err = input_register_device(input_dev); 849 err = input_register_device(input_dev);
807 if (err) 850 if (err)
808 goto err_remove_attr; 851 goto err_remove_attr_group;
809 852
810 return 0; 853 return 0;
811 854
812 err_remove_attr: 855 err_remove_attr_group:
813 device_remove_file(&spi->dev, &dev_attr_disable); 856 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
814 device_remove_file(&spi->dev, &dev_attr_pen_down); 857 err_free_irq:
815 if (ts->model == 7846) {
816 device_remove_file(&spi->dev, &dev_attr_temp1);
817 device_remove_file(&spi->dev, &dev_attr_temp0);
818 }
819 if (ts->model != 7845)
820 device_remove_file(&spi->dev, &dev_attr_vbatt);
821 device_remove_file(&spi->dev, &dev_attr_vaux);
822
823 free_irq(spi->irq, ts); 858 free_irq(spi->irq, ts);
824 err_free_mem: 859 err_free_mem:
825 input_free_device(input_dev); 860 input_free_device(input_dev);
@@ -835,15 +870,7 @@ static int __devexit ads7846_remove(struct spi_device *spi)
835 870
836 ads7846_suspend(spi, PMSG_SUSPEND); 871 ads7846_suspend(spi, PMSG_SUSPEND);
837 872
838 device_remove_file(&spi->dev, &dev_attr_disable); 873 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
839 device_remove_file(&spi->dev, &dev_attr_pen_down);
840 if (ts->model == 7846) {
841 device_remove_file(&spi->dev, &dev_attr_temp1);
842 device_remove_file(&spi->dev, &dev_attr_temp0);
843 }
844 if (ts->model != 7845)
845 device_remove_file(&spi->dev, &dev_attr_vbatt);
846 device_remove_file(&spi->dev, &dev_attr_vaux);
847 874
848 free_irq(ts->spi->irq, ts); 875 free_irq(ts->spi->irq, ts);
849 /* suspend left the IRQ disabled */ 876 /* suspend left the IRQ disabled */
diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c
index 66121f6a89ad..e2945582828e 100644
--- a/drivers/input/touchscreen/corgi_ts.c
+++ b/drivers/input/touchscreen/corgi_ts.c
@@ -175,17 +175,19 @@ static int read_xydata(struct corgi_ts *corgi_ts)
175 175
176static void new_data(struct corgi_ts *corgi_ts) 176static void new_data(struct corgi_ts *corgi_ts)
177{ 177{
178 struct input_dev *dev = corgi_ts->input;
179
178 if (corgi_ts->power_mode != PWR_MODE_ACTIVE) 180 if (corgi_ts->power_mode != PWR_MODE_ACTIVE)
179 return; 181 return;
180 182
181 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0) 183 if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0)
182 return; 184 return;
183 185
184 input_report_abs(corgi_ts->input, ABS_X, corgi_ts->tc.x); 186 input_report_abs(dev, ABS_X, corgi_ts->tc.x);
185 input_report_abs(corgi_ts->input, ABS_Y, corgi_ts->tc.y); 187 input_report_abs(dev, ABS_Y, corgi_ts->tc.y);
186 input_report_abs(corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure); 188 input_report_abs(dev, ABS_PRESSURE, corgi_ts->tc.pressure);
187 input_report_key(corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0)); 189 input_report_key(dev, BTN_TOUCH, corgi_ts->pendown);
188 input_sync(corgi_ts->input); 190 input_sync(dev);
189} 191}
190 192
191static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer) 193static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer)
@@ -219,12 +221,14 @@ static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer)
219static void corgi_ts_timer(unsigned long data) 221static void corgi_ts_timer(unsigned long data)
220{ 222{
221 struct corgi_ts *corgits_data = (struct corgi_ts *) data; 223 struct corgi_ts *corgits_data = (struct corgi_ts *) data;
224
222 ts_interrupt_main(corgits_data, 1); 225 ts_interrupt_main(corgits_data, 1);
223} 226}
224 227
225static irqreturn_t ts_interrupt(int irq, void *dev_id) 228static irqreturn_t ts_interrupt(int irq, void *dev_id)
226{ 229{
227 struct corgi_ts *corgits_data = dev_id; 230 struct corgi_ts *corgits_data = dev_id;
231
228 ts_interrupt_main(corgits_data, 0); 232 ts_interrupt_main(corgits_data, 0);
229 return IRQ_HANDLED; 233 return IRQ_HANDLED;
230} 234}
@@ -272,7 +276,7 @@ static int __init corgits_probe(struct platform_device *pdev)
272 corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL); 276 corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL);
273 input_dev = input_allocate_device(); 277 input_dev = input_allocate_device();
274 if (!corgi_ts || !input_dev) 278 if (!corgi_ts || !input_dev)
275 goto fail; 279 goto fail1;
276 280
277 platform_set_drvdata(pdev, corgi_ts); 281 platform_set_drvdata(pdev, corgi_ts);
278 282
@@ -281,7 +285,7 @@ static int __init corgits_probe(struct platform_device *pdev)
281 285
282 if (corgi_ts->irq_gpio < 0) { 286 if (corgi_ts->irq_gpio < 0) {
283 err = -ENODEV; 287 err = -ENODEV;
284 goto fail; 288 goto fail1;
285 } 289 }
286 290
287 corgi_ts->input = input_dev; 291 corgi_ts->input = input_dev;
@@ -319,10 +323,12 @@ static int __init corgits_probe(struct platform_device *pdev)
319 323
320 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, IRQF_DISABLED, "ts", corgi_ts)) { 324 if (request_irq(corgi_ts->irq_gpio, ts_interrupt, IRQF_DISABLED, "ts", corgi_ts)) {
321 err = -EBUSY; 325 err = -EBUSY;
322 goto fail; 326 goto fail1;
323 } 327 }
324 328
325 input_register_device(corgi_ts->input); 329 err = input_register_device(corgi_ts->input);
330 if (err)
331 goto fail2;
326 332
327 corgi_ts->power_mode = PWR_MODE_ACTIVE; 333 corgi_ts->power_mode = PWR_MODE_ACTIVE;
328 334
@@ -331,17 +337,17 @@ static int __init corgits_probe(struct platform_device *pdev)
331 337
332 return 0; 338 return 0;
333 339
334 fail: input_free_device(input_dev); 340 fail2: free_irq(corgi_ts->irq_gpio, corgi_ts);
341 fail1: input_free_device(input_dev);
335 kfree(corgi_ts); 342 kfree(corgi_ts);
336 return err; 343 return err;
337
338} 344}
339 345
340static int corgits_remove(struct platform_device *pdev) 346static int corgits_remove(struct platform_device *pdev)
341{ 347{
342 struct corgi_ts *corgi_ts = platform_get_drvdata(pdev); 348 struct corgi_ts *corgi_ts = platform_get_drvdata(pdev);
343 349
344 free_irq(corgi_ts->irq_gpio, NULL); 350 free_irq(corgi_ts->irq_gpio, corgi_ts);
345 del_timer_sync(&corgi_ts->timer); 351 del_timer_sync(&corgi_ts->timer);
346 corgi_ts->machinfo->put_hsync(); 352 corgi_ts->machinfo->put_hsync();
347 input_unregister_device(corgi_ts->input); 353 input_unregister_device(corgi_ts->input);
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 913e1b73bb0e..9d61cd133d01 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -397,8 +397,7 @@ static struct serio_driver elo_drv = {
397 397
398static int __init elo_init(void) 398static int __init elo_init(void)
399{ 399{
400 serio_register_driver(&elo_drv); 400 return serio_register_driver(&elo_drv);
401 return 0;
402} 401}
403 402
404static void __exit elo_exit(void) 403static void __exit elo_exit(void)
diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c
index 817c2198933d..9157eb148e84 100644
--- a/drivers/input/touchscreen/gunze.c
+++ b/drivers/input/touchscreen/gunze.c
@@ -123,7 +123,7 @@ static int gunze_connect(struct serio *serio, struct serio_driver *drv)
123 input_dev = input_allocate_device(); 123 input_dev = input_allocate_device();
124 if (!gunze || !input_dev) { 124 if (!gunze || !input_dev) {
125 err = -ENOMEM; 125 err = -ENOMEM;
126 goto fail; 126 goto fail1;
127 } 127 }
128 128
129 gunze->serio = serio; 129 gunze->serio = serio;
@@ -146,13 +146,17 @@ static int gunze_connect(struct serio *serio, struct serio_driver *drv)
146 146
147 err = serio_open(serio, drv); 147 err = serio_open(serio, drv);
148 if (err) 148 if (err)
149 goto fail; 149 goto fail2;
150
151 err = input_register_device(gunze->dev);
152 if (err)
153 goto fail3;
150 154
151 input_register_device(gunze->dev);
152 return 0; 155 return 0;
153 156
154 fail: serio_set_drvdata(serio, NULL); 157 fail3: serio_close(serio);
155 input_free_device(input_dev); 158 fail2: serio_set_drvdata(serio, NULL);
159 fail1: input_free_device(input_dev);
156 kfree(gunze); 160 kfree(gunze);
157 return err; 161 return err;
158} 162}
@@ -190,8 +194,7 @@ static struct serio_driver gunze_drv = {
190 194
191static int __init gunze_init(void) 195static int __init gunze_init(void)
192{ 196{
193 serio_register_driver(&gunze_drv); 197 return serio_register_driver(&gunze_drv);
194 return 0;
195} 198}
196 199
197static void __exit gunze_exit(void) 200static void __exit gunze_exit(void)
diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c
index d9e61ee05ea9..c4116d4f64e7 100644
--- a/drivers/input/touchscreen/h3600_ts_input.c
+++ b/drivers/input/touchscreen/h3600_ts_input.c
@@ -478,8 +478,7 @@ static struct serio_driver h3600ts_drv = {
478 478
479static int __init h3600ts_init(void) 479static int __init h3600ts_init(void)
480{ 480{
481 serio_register_driver(&h3600ts_drv); 481 return serio_register_driver(&h3600ts_drv);
482 return 0;
483} 482}
484 483
485static void __exit h3600ts_exit(void) 484static void __exit h3600ts_exit(void)
diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c
index 58fca316786c..249087472740 100644
--- a/drivers/input/touchscreen/hp680_ts_input.c
+++ b/drivers/input/touchscreen/hp680_ts_input.c
@@ -76,38 +76,47 @@ static irqreturn_t hp680_ts_interrupt(int irq, void *dev)
76 76
77static int __init hp680_ts_init(void) 77static int __init hp680_ts_init(void)
78{ 78{
79 int err;
80
79 hp680_ts_dev = input_allocate_device(); 81 hp680_ts_dev = input_allocate_device();
80 if (!hp680_ts_dev) 82 if (!hp680_ts_dev)
81 return -ENOMEM; 83 return -ENOMEM;
82 84
83 hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); 85 hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY);
84 hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
85 hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); 86 hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH);
86 87
87 hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN; 88 input_set_abs_params(hp680_ts_dev, ABS_X,
88 hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN; 89 HP680_TS_ABS_X_MIN, HP680_TS_ABS_X_MAX, 0, 0);
89 hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX; 90 input_set_abs_params(hp680_ts_dev, ABS_Y,
90 hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX; 91 HP680_TS_ABS_Y_MIN, HP680_TS_ABS_Y_MAX, 0, 0);
91 92
92 hp680_ts_dev->name = "HP Jornada touchscreen"; 93 hp680_ts_dev->name = "HP Jornada touchscreen";
93 hp680_ts_dev->phys = "hp680_ts/input0"; 94 hp680_ts_dev->phys = "hp680_ts/input0";
94 95
95 input_register_device(hp680_ts_dev);
96
97 if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt, 96 if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt,
98 IRQF_DISABLED, MODNAME, 0) < 0) { 97 IRQF_DISABLED, MODNAME, 0) < 0) {
99 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n", 98 printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n",
100 HP680_TS_IRQ); 99 HP680_TS_IRQ);
101 input_unregister_device(hp680_ts_dev); 100 err = -EBUSY;
102 return -EBUSY; 101 goto fail1;
103 } 102 }
104 103
104 err = input_register_device(hp680_ts_dev);
105 if (err)
106 goto fail2;
107
105 return 0; 108 return 0;
109
110 fail2: free_irq(HP680_TS_IRQ, NULL);
111 cancel_delayed_work(&work);
112 flush_scheduled_work();
113 fail1: input_free_device(hp680_ts_dev);
114 return err;
106} 115}
107 116
108static void __exit hp680_ts_exit(void) 117static void __exit hp680_ts_exit(void)
109{ 118{
110 free_irq(HP680_TS_IRQ, 0); 119 free_irq(HP680_TS_IRQ, NULL);
111 cancel_delayed_work(&work); 120 cancel_delayed_work(&work);
112 flush_scheduled_work(); 121 flush_scheduled_work();
113 input_unregister_device(hp680_ts_dev); 122 input_unregister_device(hp680_ts_dev);
diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c
index 4cbcaa6a71e5..44140feeffc5 100644
--- a/drivers/input/touchscreen/mk712.c
+++ b/drivers/input/touchscreen/mk712.c
@@ -96,15 +96,13 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id)
96 goto end; 96 goto end;
97 } 97 }
98 98
99 if (~status & MK712_STATUS_TOUCH) 99 if (~status & MK712_STATUS_TOUCH) {
100 {
101 debounce = 1; 100 debounce = 1;
102 input_report_key(mk712_dev, BTN_TOUCH, 0); 101 input_report_key(mk712_dev, BTN_TOUCH, 0);
103 goto end; 102 goto end;
104 } 103 }
105 104
106 if (debounce) 105 if (debounce) {
107 {
108 debounce = 0; 106 debounce = 0;
109 goto end; 107 goto end;
110 } 108 }
@@ -113,8 +111,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id)
113 input_report_abs(mk712_dev, ABS_X, last_x); 111 input_report_abs(mk712_dev, ABS_X, last_x);
114 input_report_abs(mk712_dev, ABS_Y, last_y); 112 input_report_abs(mk712_dev, ABS_Y, last_y);
115 113
116end: 114 end:
117
118 last_x = inw(mk712_io + MK712_X) & 0x0fff; 115 last_x = inw(mk712_io + MK712_X) & 0x0fff;
119 last_y = inw(mk712_io + MK712_Y) & 0x0fff; 116 last_y = inw(mk712_io + MK712_Y) & 0x0fff;
120 input_sync(mk712_dev); 117 input_sync(mk712_dev);
@@ -169,13 +166,14 @@ static int __init mk712_init(void)
169 (inw(mk712_io + MK712_STATUS) & 0xf333)) { 166 (inw(mk712_io + MK712_STATUS) & 0xf333)) {
170 printk(KERN_WARNING "mk712: device not present\n"); 167 printk(KERN_WARNING "mk712: device not present\n");
171 err = -ENODEV; 168 err = -ENODEV;
172 goto fail; 169 goto fail1;
173 } 170 }
174 171
175 if (!(mk712_dev = input_allocate_device())) { 172 mk712_dev = input_allocate_device();
173 if (!mk712_dev) {
176 printk(KERN_ERR "mk712: not enough memory\n"); 174 printk(KERN_ERR "mk712: not enough memory\n");
177 err = -ENOMEM; 175 err = -ENOMEM;
178 goto fail; 176 goto fail1;
179 } 177 }
180 178
181 mk712_dev->name = "ICS MicroClock MK712 TouchScreen"; 179 mk712_dev->name = "ICS MicroClock MK712 TouchScreen";
@@ -196,13 +194,17 @@ static int __init mk712_init(void)
196 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) { 194 if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) {
197 printk(KERN_WARNING "mk712: unable to get IRQ\n"); 195 printk(KERN_WARNING "mk712: unable to get IRQ\n");
198 err = -EBUSY; 196 err = -EBUSY;
199 goto fail; 197 goto fail1;
200 } 198 }
201 199
202 input_register_device(mk712_dev); 200 err = input_register_device(mk712_dev);
201 if (err)
202 goto fail2;
203
203 return 0; 204 return 0;
204 205
205 fail: input_free_device(mk712_dev); 206 fail2: free_irq(mk712_irq, mk712_dev);
207 fail1: input_free_device(mk712_dev);
206 release_region(mk712_io, 8); 208 release_region(mk712_io, 8);
207 return err; 209 return err;
208} 210}
diff --git a/drivers/input/touchscreen/mtouch.c b/drivers/input/touchscreen/mtouch.c
index 3b4c61664b63..c3c2d735d0ec 100644
--- a/drivers/input/touchscreen/mtouch.c
+++ b/drivers/input/touchscreen/mtouch.c
@@ -137,7 +137,7 @@ static int mtouch_connect(struct serio *serio, struct serio_driver *drv)
137 input_dev = input_allocate_device(); 137 input_dev = input_allocate_device();
138 if (!mtouch || !input_dev) { 138 if (!mtouch || !input_dev) {
139 err = -ENOMEM; 139 err = -ENOMEM;
140 goto fail; 140 goto fail1;
141 } 141 }
142 142
143 mtouch->serio = serio; 143 mtouch->serio = serio;
@@ -160,14 +160,17 @@ static int mtouch_connect(struct serio *serio, struct serio_driver *drv)
160 160
161 err = serio_open(serio, drv); 161 err = serio_open(serio, drv);
162 if (err) 162 if (err)
163 goto fail; 163 goto fail2;
164 164
165 input_register_device(mtouch->dev); 165 err = input_register_device(mtouch->dev);
166 if (err)
167 goto fail3;
166 168
167 return 0; 169 return 0;
168 170
169 fail: serio_set_drvdata(serio, NULL); 171 fail3: serio_close(serio);
170 input_free_device(input_dev); 172 fail2: serio_set_drvdata(serio, NULL);
173 fail1: input_free_device(input_dev);
171 kfree(mtouch); 174 kfree(mtouch);
172 return err; 175 return err;
173} 176}
@@ -205,8 +208,7 @@ static struct serio_driver mtouch_drv = {
205 208
206static int __init mtouch_init(void) 209static int __init mtouch_init(void)
207{ 210{
208 serio_register_driver(&mtouch_drv); 211 return serio_register_driver(&mtouch_drv);
209 return 0;
210} 212}
211 213
212static void __exit mtouch_exit(void) 214static void __exit mtouch_exit(void)
diff --git a/drivers/input/touchscreen/penmount.c b/drivers/input/touchscreen/penmount.c
index 6c7d0c2c76cc..bd2767991ae9 100644
--- a/drivers/input/touchscreen/penmount.c
+++ b/drivers/input/touchscreen/penmount.c
@@ -171,8 +171,7 @@ static struct serio_driver pm_drv = {
171 171
172static int __init pm_init(void) 172static int __init pm_init(void)
173{ 173{
174 serio_register_driver(&pm_drv); 174 return serio_register_driver(&pm_drv);
175 return 0;
176} 175}
177 176
178static void __exit pm_exit(void) 177static void __exit pm_exit(void)
diff --git a/drivers/input/touchscreen/touchright.c b/drivers/input/touchscreen/touchright.c
index c74f74e57af0..35ba46c6ad2d 100644
--- a/drivers/input/touchscreen/touchright.c
+++ b/drivers/input/touchscreen/touchright.c
@@ -182,8 +182,7 @@ static struct serio_driver tr_drv = {
182 182
183static int __init tr_init(void) 183static int __init tr_init(void)
184{ 184{
185 serio_register_driver(&tr_drv); 185 return serio_register_driver(&tr_drv);
186 return 0;
187} 186}
188 187
189static void __exit tr_exit(void) 188static void __exit tr_exit(void)
diff --git a/drivers/input/touchscreen/touchwin.c b/drivers/input/touchscreen/touchwin.c
index 9911820fa2fe..4dc073dacabb 100644
--- a/drivers/input/touchscreen/touchwin.c
+++ b/drivers/input/touchscreen/touchwin.c
@@ -189,8 +189,7 @@ static struct serio_driver tw_drv = {
189 189
190static int __init tw_init(void) 190static int __init tw_init(void)
191{ 191{
192 serio_register_driver(&tw_drv); 192 return serio_register_driver(&tw_drv);
193 return 0;
194} 193}
195 194
196static void __exit tw_exit(void) 195static void __exit tw_exit(void)
diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c
new file mode 100644
index 000000000000..4358a0a78eaa
--- /dev/null
+++ b/drivers/input/touchscreen/ucb1400_ts.c
@@ -0,0 +1,579 @@
1/*
2 * Philips UCB1400 touchscreen driver
3 *
4 * Author: Nicolas Pitre
5 * Created: September 25, 2006
6 * Copyright: MontaVista Software, Inc.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This code is heavily based on ucb1x00-*.c copyrighted by Russell King
13 * covering the UCB1100, UCB1200 and UCB1300.. Support for the UCB1400 has
14 * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request.
15 */
16
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/init.h>
20#include <linux/completion.h>
21#include <linux/delay.h>
22#include <linux/input.h>
23#include <linux/device.h>
24#include <linux/interrupt.h>
25#include <linux/suspend.h>
26#include <linux/slab.h>
27#include <linux/kthread.h>
28#include <linux/freezer.h>
29
30#include <sound/driver.h>
31#include <sound/core.h>
32#include <sound/ac97_codec.h>
33
34
35/*
36 * Interesting UCB1400 AC-link registers
37 */
38
39#define UCB_IE_RIS 0x5e
40#define UCB_IE_FAL 0x60
41#define UCB_IE_STATUS 0x62
42#define UCB_IE_CLEAR 0x62
43#define UCB_IE_ADC (1 << 11)
44#define UCB_IE_TSPX (1 << 12)
45
46#define UCB_TS_CR 0x64
47#define UCB_TS_CR_TSMX_POW (1 << 0)
48#define UCB_TS_CR_TSPX_POW (1 << 1)
49#define UCB_TS_CR_TSMY_POW (1 << 2)
50#define UCB_TS_CR_TSPY_POW (1 << 3)
51#define UCB_TS_CR_TSMX_GND (1 << 4)
52#define UCB_TS_CR_TSPX_GND (1 << 5)
53#define UCB_TS_CR_TSMY_GND (1 << 6)
54#define UCB_TS_CR_TSPY_GND (1 << 7)
55#define UCB_TS_CR_MODE_INT (0 << 8)
56#define UCB_TS_CR_MODE_PRES (1 << 8)
57#define UCB_TS_CR_MODE_POS (2 << 8)
58#define UCB_TS_CR_BIAS_ENA (1 << 11)
59#define UCB_TS_CR_TSPX_LOW (1 << 12)
60#define UCB_TS_CR_TSMX_LOW (1 << 13)
61
62#define UCB_ADC_CR 0x66
63#define UCB_ADC_SYNC_ENA (1 << 0)
64#define UCB_ADC_VREFBYP_CON (1 << 1)
65#define UCB_ADC_INP_TSPX (0 << 2)
66#define UCB_ADC_INP_TSMX (1 << 2)
67#define UCB_ADC_INP_TSPY (2 << 2)
68#define UCB_ADC_INP_TSMY (3 << 2)
69#define UCB_ADC_INP_AD0 (4 << 2)
70#define UCB_ADC_INP_AD1 (5 << 2)
71#define UCB_ADC_INP_AD2 (6 << 2)
72#define UCB_ADC_INP_AD3 (7 << 2)
73#define UCB_ADC_EXT_REF (1 << 5)
74#define UCB_ADC_START (1 << 7)
75#define UCB_ADC_ENA (1 << 15)
76
77#define UCB_ADC_DATA 0x68
78#define UCB_ADC_DAT_VALID (1 << 15)
79#define UCB_ADC_DAT_VALUE(x) ((x) & 0x3ff)
80
81#define UCB_ID 0x7e
82#define UCB_ID_1400 0x4304
83
84
85struct ucb1400 {
86 ac97_t *ac97;
87 struct input_dev *ts_idev;
88
89 int irq;
90
91 wait_queue_head_t ts_wait;
92 struct task_struct *ts_task;
93
94 unsigned int irq_pending; /* not bit field shared */
95 unsigned int ts_restart:1;
96 unsigned int adcsync:1;
97};
98
99static int adcsync;
100
101static inline u16 ucb1400_reg_read(struct ucb1400 *ucb, u16 reg)
102{
103 return ucb->ac97->bus->ops->read(ucb->ac97, reg);
104}
105
106static inline void ucb1400_reg_write(struct ucb1400 *ucb, u16 reg, u16 val)
107{
108 ucb->ac97->bus->ops->write(ucb->ac97, reg, val);
109}
110
111static inline void ucb1400_adc_enable(struct ucb1400 *ucb)
112{
113 ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA);
114}
115
116static unsigned int ucb1400_adc_read(struct ucb1400 *ucb, u16 adc_channel)
117{
118 unsigned int val;
119
120 if (ucb->adcsync)
121 adc_channel |= UCB_ADC_SYNC_ENA;
122
123 ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel);
124 ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel | UCB_ADC_START);
125
126 for (;;) {
127 val = ucb1400_reg_read(ucb, UCB_ADC_DATA);
128 if (val & UCB_ADC_DAT_VALID)
129 break;
130 /* yield to other processes */
131 set_current_state(TASK_INTERRUPTIBLE);
132 schedule_timeout(1);
133 }
134
135 return UCB_ADC_DAT_VALUE(val);
136}
137
138static inline void ucb1400_adc_disable(struct ucb1400 *ucb)
139{
140 ucb1400_reg_write(ucb, UCB_ADC_CR, 0);
141}
142
143/* Switch to interrupt mode. */
144static inline void ucb1400_ts_mode_int(struct ucb1400 *ucb)
145{
146 ucb1400_reg_write(ucb, UCB_TS_CR,
147 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
148 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
149 UCB_TS_CR_MODE_INT);
150}
151
152/*
153 * Switch to pressure mode, and read pressure. We don't need to wait
154 * here, since both plates are being driven.
155 */
156static inline unsigned int ucb1400_ts_read_pressure(struct ucb1400 *ucb)
157{
158 ucb1400_reg_write(ucb, UCB_TS_CR,
159 UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW |
160 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND |
161 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
162 return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY);
163}
164
165/*
166 * Switch to X position mode and measure Y plate. We switch the plate
167 * configuration in pressure mode, then switch to position mode. This
168 * gives a faster response time. Even so, we need to wait about 55us
169 * for things to stabilise.
170 */
171static inline unsigned int ucb1400_ts_read_xpos(struct ucb1400 *ucb)
172{
173 ucb1400_reg_write(ucb, UCB_TS_CR,
174 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
175 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
176 ucb1400_reg_write(ucb, UCB_TS_CR,
177 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
178 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
179 ucb1400_reg_write(ucb, UCB_TS_CR,
180 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
181 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
182
183 udelay(55);
184
185 return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY);
186}
187
188/*
189 * Switch to Y position mode and measure X plate. We switch the plate
190 * configuration in pressure mode, then switch to position mode. This
191 * gives a faster response time. Even so, we need to wait about 55us
192 * for things to stabilise.
193 */
194static inline unsigned int ucb1400_ts_read_ypos(struct ucb1400 *ucb)
195{
196 ucb1400_reg_write(ucb, UCB_TS_CR,
197 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
198 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
199 ucb1400_reg_write(ucb, UCB_TS_CR,
200 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
201 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
202 ucb1400_reg_write(ucb, UCB_TS_CR,
203 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
204 UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA);
205
206 udelay(55);
207
208 return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPX);
209}
210
211/*
212 * Switch to X plate resistance mode. Set MX to ground, PX to
213 * supply. Measure current.
214 */
215static inline unsigned int ucb1400_ts_read_xres(struct ucb1400 *ucb)
216{
217 ucb1400_reg_write(ucb, UCB_TS_CR,
218 UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW |
219 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
220 return ucb1400_adc_read(ucb, 0);
221}
222
223/*
224 * Switch to Y plate resistance mode. Set MY to ground, PY to
225 * supply. Measure current.
226 */
227static inline unsigned int ucb1400_ts_read_yres(struct ucb1400 *ucb)
228{
229 ucb1400_reg_write(ucb, UCB_TS_CR,
230 UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW |
231 UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA);
232 return ucb1400_adc_read(ucb, 0);
233}
234
235static inline int ucb1400_ts_pen_down(struct ucb1400 *ucb)
236{
237 unsigned short val = ucb1400_reg_read(ucb, UCB_TS_CR);
238 return (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW));
239}
240
241static inline void ucb1400_ts_irq_enable(struct ucb1400 *ucb)
242{
243 ucb1400_reg_write(ucb, UCB_IE_CLEAR, UCB_IE_TSPX);
244 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0);
245 ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_TSPX);
246}
247
248static inline void ucb1400_ts_irq_disable(struct ucb1400 *ucb)
249{
250 ucb1400_reg_write(ucb, UCB_IE_FAL, 0);
251}
252
253static void ucb1400_ts_evt_add(struct input_dev *idev, u16 pressure, u16 x, u16 y)
254{
255 input_report_abs(idev, ABS_X, x);
256 input_report_abs(idev, ABS_Y, y);
257 input_report_abs(idev, ABS_PRESSURE, pressure);
258 input_sync(idev);
259}
260
261static void ucb1400_ts_event_release(struct input_dev *idev)
262{
263 input_report_abs(idev, ABS_PRESSURE, 0);
264 input_sync(idev);
265}
266
267static void ucb1400_handle_pending_irq(struct ucb1400 *ucb)
268{
269 unsigned int isr;
270
271 isr = ucb1400_reg_read(ucb, UCB_IE_STATUS);
272 ucb1400_reg_write(ucb, UCB_IE_CLEAR, isr);
273 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0);
274
275 if (isr & UCB_IE_TSPX)
276 ucb1400_ts_irq_disable(ucb);
277 else
278 printk(KERN_ERR "ucb1400: unexpected IE_STATUS = %#x\n", isr);
279
280 enable_irq(ucb->irq);
281}
282
283static int ucb1400_ts_thread(void *_ucb)
284{
285 struct ucb1400 *ucb = _ucb;
286 struct task_struct *tsk = current;
287 int valid = 0;
288
289 tsk->policy = SCHED_FIFO;
290 tsk->rt_priority = 1;
291
292 while (!kthread_should_stop()) {
293 unsigned int x, y, p;
294 long timeout;
295
296 ucb->ts_restart = 0;
297
298 if (ucb->irq_pending) {
299 ucb->irq_pending = 0;
300 ucb1400_handle_pending_irq(ucb);
301 }
302
303 ucb1400_adc_enable(ucb);
304 x = ucb1400_ts_read_xpos(ucb);
305 y = ucb1400_ts_read_ypos(ucb);
306 p = ucb1400_ts_read_pressure(ucb);
307 ucb1400_adc_disable(ucb);
308
309 /* Switch back to interrupt mode. */
310 ucb1400_ts_mode_int(ucb);
311
312 msleep(10);
313
314 if (ucb1400_ts_pen_down(ucb)) {
315 ucb1400_ts_irq_enable(ucb);
316
317 /*
318 * If we spat out a valid sample set last time,
319 * spit out a "pen off" sample here.
320 */
321 if (valid) {
322 ucb1400_ts_event_release(ucb->ts_idev);
323 valid = 0;
324 }
325
326 timeout = MAX_SCHEDULE_TIMEOUT;
327 } else {
328 valid = 1;
329 ucb1400_ts_evt_add(ucb->ts_idev, p, x, y);
330 timeout = msecs_to_jiffies(10);
331 }
332
333 wait_event_interruptible_timeout(ucb->ts_wait,
334 ucb->irq_pending || ucb->ts_restart || kthread_should_stop(),
335 timeout);
336 try_to_freeze();
337 }
338
339 /* Send the "pen off" if we are stopping with the pen still active */
340 if (valid)
341 ucb1400_ts_event_release(ucb->ts_idev);
342
343 ucb->ts_task = NULL;
344 return 0;
345}
346
347/*
348 * A restriction with interrupts exists when using the ucb1400, as
349 * the codec read/write routines may sleep while waiting for codec
350 * access completion and uses semaphores for access control to the
351 * AC97 bus. A complete codec read cycle could take anywhere from
352 * 60 to 100uSec so we *definitely* don't want to spin inside the
353 * interrupt handler waiting for codec access. So, we handle the
354 * interrupt by scheduling a RT kernel thread to run in process
355 * context instead of interrupt context.
356 */
357static irqreturn_t ucb1400_hard_irq(int irqnr, void *devid)
358{
359 struct ucb1400 *ucb = devid;
360
361 if (irqnr == ucb->irq) {
362 disable_irq(ucb->irq);
363 ucb->irq_pending = 1;
364 wake_up(&ucb->ts_wait);
365 return IRQ_HANDLED;
366 }
367 return IRQ_NONE;
368}
369
370static int ucb1400_ts_open(struct input_dev *idev)
371{
372 struct ucb1400 *ucb = idev->private;
373 int ret = 0;
374
375 BUG_ON(ucb->ts_task);
376
377 ucb->ts_task = kthread_run(ucb1400_ts_thread, ucb, "UCB1400_ts");
378 if (IS_ERR(ucb->ts_task)) {
379 ret = PTR_ERR(ucb->ts_task);
380 ucb->ts_task = NULL;
381 }
382
383 return ret;
384}
385
386static void ucb1400_ts_close(struct input_dev *idev)
387{
388 struct ucb1400 *ucb = idev->private;
389
390 if (ucb->ts_task)
391 kthread_stop(ucb->ts_task);
392
393 ucb1400_ts_irq_disable(ucb);
394 ucb1400_reg_write(ucb, UCB_TS_CR, 0);
395}
396
397#ifdef CONFIG_PM
398static int ucb1400_ts_resume(struct device *dev)
399{
400 struct ucb1400 *ucb = dev_get_drvdata(dev);
401
402 if (ucb->ts_task) {
403 /*
404 * Restart the TS thread to ensure the
405 * TS interrupt mode is set up again
406 * after sleep.
407 */
408 ucb->ts_restart = 1;
409 wake_up(&ucb->ts_wait);
410 }
411 return 0;
412}
413#else
414#define ucb1400_ts_resume NULL
415#endif
416
417#ifndef NO_IRQ
418#define NO_IRQ 0
419#endif
420
421/*
422 * Try to probe our interrupt, rather than relying on lots of
423 * hard-coded machine dependencies.
424 */
425static int ucb1400_detect_irq(struct ucb1400 *ucb)
426{
427 unsigned long mask, timeout;
428
429 mask = probe_irq_on();
430 if (!mask) {
431 probe_irq_off(mask);
432 return -EBUSY;
433 }
434
435 /* Enable the ADC interrupt. */
436 ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC);
437 ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_ADC);
438 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff);
439 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0);
440
441 /* Cause an ADC interrupt. */
442 ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA);
443 ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START);
444
445 /* Wait for the conversion to complete. */
446 timeout = jiffies + HZ/2;
447 while (!(ucb1400_reg_read(ucb, UCB_ADC_DATA) & UCB_ADC_DAT_VALID)) {
448 cpu_relax();
449 if (time_after(jiffies, timeout)) {
450 printk(KERN_ERR "ucb1400: timed out in IRQ probe\n");
451 probe_irq_off(mask);
452 return -ENODEV;
453 }
454 }
455 ucb1400_reg_write(ucb, UCB_ADC_CR, 0);
456
457 /* Disable and clear interrupt. */
458 ucb1400_reg_write(ucb, UCB_IE_RIS, 0);
459 ucb1400_reg_write(ucb, UCB_IE_FAL, 0);
460 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff);
461 ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0);
462
463 /* Read triggered interrupt. */
464 ucb->irq = probe_irq_off(mask);
465 if (ucb->irq < 0 || ucb->irq == NO_IRQ)
466 return -ENODEV;
467
468 return 0;
469}
470
471static int ucb1400_ts_probe(struct device *dev)
472{
473 struct ucb1400 *ucb;
474 struct input_dev *idev;
475 int error, id, x_res, y_res;
476
477 ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL);
478 idev = input_allocate_device();
479 if (!ucb || !idev) {
480 error = -ENOMEM;
481 goto err_free_devs;
482 }
483
484 ucb->ts_idev = idev;
485 ucb->adcsync = adcsync;
486 ucb->ac97 = to_ac97_t(dev);
487 init_waitqueue_head(&ucb->ts_wait);
488
489 id = ucb1400_reg_read(ucb, UCB_ID);
490 if (id != UCB_ID_1400) {
491 error = -ENODEV;
492 goto err_free_devs;
493 }
494
495 error = ucb1400_detect_irq(ucb);
496 if (error) {
497 printk(KERN_ERR "UCB1400: IRQ probe failed\n");
498 goto err_free_devs;
499 }
500
501 error = request_irq(ucb->irq, ucb1400_hard_irq, IRQF_TRIGGER_RISING,
502 "UCB1400", ucb);
503 if (error) {
504 printk(KERN_ERR "ucb1400: unable to grab irq%d: %d\n",
505 ucb->irq, error);
506 goto err_free_devs;
507 }
508 printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq);
509
510 idev->private = ucb;
511 idev->cdev.dev = dev;
512 idev->name = "UCB1400 touchscreen interface";
513 idev->id.vendor = ucb1400_reg_read(ucb, AC97_VENDOR_ID1);
514 idev->id.product = id;
515 idev->open = ucb1400_ts_open;
516 idev->close = ucb1400_ts_close;
517 idev->evbit[0] = BIT(EV_ABS);
518
519 ucb1400_adc_enable(ucb);
520 x_res = ucb1400_ts_read_xres(ucb);
521 y_res = ucb1400_ts_read_yres(ucb);
522 ucb1400_adc_disable(ucb);
523 printk(KERN_DEBUG "UCB1400: x/y = %d/%d\n", x_res, y_res);
524
525 input_set_abs_params(idev, ABS_X, 0, x_res, 0, 0);
526 input_set_abs_params(idev, ABS_Y, 0, y_res, 0, 0);
527 input_set_abs_params(idev, ABS_PRESSURE, 0, 0, 0, 0);
528
529 error = input_register_device(idev);
530 if (error)
531 goto err_free_irq;
532
533 dev_set_drvdata(dev, ucb);
534 return 0;
535
536 err_free_irq:
537 free_irq(ucb->irq, ucb);
538 err_free_devs:
539 input_free_device(idev);
540 kfree(ucb);
541 return error;
542}
543
544static int ucb1400_ts_remove(struct device *dev)
545{
546 struct ucb1400 *ucb = dev_get_drvdata(dev);
547
548 free_irq(ucb->irq, ucb);
549 input_unregister_device(ucb->ts_idev);
550 dev_set_drvdata(dev, NULL);
551 kfree(ucb);
552 return 0;
553}
554
555static struct device_driver ucb1400_ts_driver = {
556 .owner = THIS_MODULE,
557 .bus = &ac97_bus_type,
558 .probe = ucb1400_ts_probe,
559 .remove = ucb1400_ts_remove,
560 .resume = ucb1400_ts_resume,
561};
562
563static int __init ucb1400_ts_init(void)
564{
565 return driver_register(&ucb1400_ts_driver);
566}
567
568static void __exit ucb1400_ts_exit(void)
569{
570 driver_unregister(&ucb1400_ts_driver);
571}
572
573module_param(adcsync, int, 0444);
574
575module_init(ucb1400_ts_init);
576module_exit(ucb1400_ts_exit);
577
578MODULE_DESCRIPTION("Philips UCB1400 touchscreen driver");
579MODULE_LICENSE("GPL");
diff --git a/drivers/isdn/act2000/module.c b/drivers/isdn/act2000/module.c
index 90593e2ef872..e3e5c1399076 100644
--- a/drivers/isdn/act2000/module.c
+++ b/drivers/isdn/act2000/module.c
@@ -573,12 +573,11 @@ act2000_alloccard(int bus, int port, int irq, char *id)
573{ 573{
574 int i; 574 int i;
575 act2000_card *card; 575 act2000_card *card;
576 if (!(card = (act2000_card *) kmalloc(sizeof(act2000_card), GFP_KERNEL))) { 576 if (!(card = kzalloc(sizeof(act2000_card), GFP_KERNEL))) {
577 printk(KERN_WARNING 577 printk(KERN_WARNING
578 "act2000: (%s) Could not allocate card-struct.\n", id); 578 "act2000: (%s) Could not allocate card-struct.\n", id);
579 return; 579 return;
580 } 580 }
581 memset((char *) card, 0, sizeof(act2000_card));
582 spin_lock_init(&card->lock); 581 spin_lock_init(&card->lock);
583 spin_lock_init(&card->mnlock); 582 spin_lock_init(&card->mnlock);
584 skb_queue_head_init(&card->sndq); 583 skb_queue_head_init(&card->sndq);
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 11844bbfe933..d22c0224fde6 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -215,13 +215,12 @@ static struct capiminor *capiminor_alloc(struct capi20_appl *ap, u32 ncci)
215 unsigned int minor = 0; 215 unsigned int minor = 0;
216 unsigned long flags; 216 unsigned long flags;
217 217
218 mp = kmalloc(sizeof(*mp), GFP_ATOMIC); 218 mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
219 if (!mp) { 219 if (!mp) {
220 printk(KERN_ERR "capi: can't alloc capiminor\n"); 220 printk(KERN_ERR "capi: can't alloc capiminor\n");
221 return NULL; 221 return NULL;
222 } 222 }
223 223
224 memset(mp, 0, sizeof(struct capiminor));
225 mp->ap = ap; 224 mp->ap = ap;
226 mp->ncci = ncci; 225 mp->ncci = ncci;
227 mp->msgid = 0; 226 mp->msgid = 0;
@@ -304,10 +303,9 @@ static struct capincci *capincci_alloc(struct capidev *cdev, u32 ncci)
304 struct capiminor *mp = NULL; 303 struct capiminor *mp = NULL;
305#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ 304#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
306 305
307 np = kmalloc(sizeof(*np), GFP_ATOMIC); 306 np = kzalloc(sizeof(*np), GFP_ATOMIC);
308 if (!np) 307 if (!np)
309 return NULL; 308 return NULL;
310 memset(np, 0, sizeof(struct capincci));
311 np->ncci = ncci; 309 np->ncci = ncci;
312 np->cdev = cdev; 310 np->cdev = cdev;
313#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 311#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -384,10 +382,9 @@ static struct capidev *capidev_alloc(void)
384 struct capidev *cdev; 382 struct capidev *cdev;
385 unsigned long flags; 383 unsigned long flags;
386 384
387 cdev = kmalloc(sizeof(*cdev), GFP_KERNEL); 385 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
388 if (!cdev) 386 if (!cdev)
389 return NULL; 387 return NULL;
390 memset(cdev, 0, sizeof(struct capidev));
391 388
392 init_MUTEX(&cdev->ncci_list_sem); 389 init_MUTEX(&cdev->ncci_list_sem);
393 skb_queue_head_init(&cdev->recvqueue); 390 skb_queue_head_init(&cdev->recvqueue);
@@ -1010,7 +1007,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1010{ 1007{
1011 struct capiminor *mp; 1008 struct capiminor *mp;
1012 1009
1013 if ((mp = capiminor_find(iminor(file->f_dentry->d_inode))) == 0) 1010 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == 0)
1014 return -ENXIO; 1011 return -ENXIO;
1015 if (mp->nccip == 0) 1012 if (mp->nccip == 0)
1016 return -ENXIO; 1013 return -ENXIO;
@@ -1203,7 +1200,7 @@ static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1203 return error; 1200 return error;
1204} 1201}
1205 1202
1206static void capinc_tty_set_termios(struct tty_struct *tty, struct termios * old) 1203static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
1207{ 1204{
1208#ifdef _DEBUG_TTYFUNCS 1205#ifdef _DEBUG_TTYFUNCS
1209 printk(KERN_DEBUG "capinc_tty_set_termios\n"); 1206 printk(KERN_DEBUG "capinc_tty_set_termios\n");
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index b6f9476c0501..097bfa7bc323 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -334,12 +334,11 @@ static capidrv_plci *new_plci(capidrv_contr * card, int chan)
334{ 334{
335 capidrv_plci *plcip; 335 capidrv_plci *plcip;
336 336
337 plcip = (capidrv_plci *) kmalloc(sizeof(capidrv_plci), GFP_ATOMIC); 337 plcip = kzalloc(sizeof(capidrv_plci), GFP_ATOMIC);
338 338
339 if (plcip == 0) 339 if (plcip == 0)
340 return NULL; 340 return NULL;
341 341
342 memset(plcip, 0, sizeof(capidrv_plci));
343 plcip->state = ST_PLCI_NONE; 342 plcip->state = ST_PLCI_NONE;
344 plcip->plci = 0; 343 plcip->plci = 0;
345 plcip->msgid = 0; 344 plcip->msgid = 0;
@@ -404,12 +403,11 @@ static inline capidrv_ncci *new_ncci(capidrv_contr * card,
404{ 403{
405 capidrv_ncci *nccip; 404 capidrv_ncci *nccip;
406 405
407 nccip = (capidrv_ncci *) kmalloc(sizeof(capidrv_ncci), GFP_ATOMIC); 406 nccip = kzalloc(sizeof(capidrv_ncci), GFP_ATOMIC);
408 407
409 if (nccip == 0) 408 if (nccip == 0)
410 return NULL; 409 return NULL;
411 410
412 memset(nccip, 0, sizeof(capidrv_ncci));
413 nccip->ncci = ncci; 411 nccip->ncci = ncci;
414 nccip->state = ST_NCCI_NONE; 412 nccip->state = ST_NCCI_NONE;
415 nccip->plcip = plcip; 413 nccip->plcip = plcip;
@@ -2005,12 +2003,11 @@ static int capidrv_addcontr(u16 contr, struct capi_profile *profp)
2005 printk(KERN_WARNING "capidrv: (%s) Could not reserve module\n", id); 2003 printk(KERN_WARNING "capidrv: (%s) Could not reserve module\n", id);
2006 return -1; 2004 return -1;
2007 } 2005 }
2008 if (!(card = (capidrv_contr *) kmalloc(sizeof(capidrv_contr), GFP_ATOMIC))) { 2006 if (!(card = kzalloc(sizeof(capidrv_contr), GFP_ATOMIC))) {
2009 printk(KERN_WARNING 2007 printk(KERN_WARNING
2010 "capidrv: (%s) Could not allocate contr-struct.\n", id); 2008 "capidrv: (%s) Could not allocate contr-struct.\n", id);
2011 return -1; 2009 return -1;
2012 } 2010 }
2013 memset(card, 0, sizeof(capidrv_contr));
2014 card->owner = THIS_MODULE; 2011 card->owner = THIS_MODULE;
2015 init_timer(&card->listentimer); 2012 init_timer(&card->listentimer);
2016 strcpy(card->name, id); 2013 strcpy(card->name, id);
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index 5b203fe21dcd..708d47a6484b 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -5,6 +5,7 @@ config ISDN_DRV_GIGASET
5 tristate "Siemens Gigaset support (isdn)" 5 tristate "Siemens Gigaset support (isdn)"
6 depends on ISDN_I4L 6 depends on ISDN_I4L
7 select CRC_CCITT 7 select CRC_CCITT
8 select BITREVERSE
8 help 9 help
9 Say m here if you have a Gigaset or Sinus isdn device. 10 Say m here if you have a Gigaset or Sinus isdn device.
10 11
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index ce3cd77094b3..88e958f176d2 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -15,6 +15,7 @@
15 15
16#include "gigaset.h" 16#include "gigaset.h"
17#include <linux/crc-ccitt.h> 17#include <linux/crc-ccitt.h>
18#include <linux/bitrev.h>
18 19
19//#define GIG_M10x_STUFF_VOICE_DATA 20//#define GIG_M10x_STUFF_VOICE_DATA
20 21
@@ -302,7 +303,7 @@ static inline int iraw_loop(unsigned char c, unsigned char *src, int numbytes,
302 inputstate |= INS_skip_frame; 303 inputstate |= INS_skip_frame;
303 break; 304 break;
304 } 305 }
305 *__skb_put(skb, 1) = gigaset_invtab[c]; 306 *__skb_put(skb, 1) = bitrev8(c);
306 } 307 }
307 308
308 if (unlikely(!numbytes)) 309 if (unlikely(!numbytes))
@@ -543,7 +544,7 @@ static struct sk_buff *iraw_encode(struct sk_buff *skb, int head, int tail)
543 cp = skb->data; 544 cp = skb->data;
544 len = skb->len; 545 len = skb->len;
545 while (len--) { 546 while (len--) {
546 c = gigaset_invtab[*cp++]; 547 c = bitrev8(*cp++);
547 if (c == DLE_FLAG) 548 if (c == DLE_FLAG)
548 *(skb_put(iraw_skb, 1)) = c; 549 *(skb_put(iraw_skb, 1)) = c;
549 *(skb_put(iraw_skb, 1)) = c; 550 *(skb_put(iraw_skb, 1)) = c;
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index defd5743dba6..95eff3b2917a 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -33,43 +33,6 @@ MODULE_PARM_DESC(debug, "debug level");
33#define VALID_ID 0x02 33#define VALID_ID 0x02
34#define ASSIGNED 0x04 34#define ASSIGNED 0x04
35 35
36/* bitwise byte inversion table */
37__u8 gigaset_invtab[256] = {
38 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
39 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
40 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
41 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
42 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
43 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
44 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
45 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
46 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
47 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
48 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
49 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
50 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
51 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
52 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
53 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
54 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
55 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
56 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
57 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
58 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
59 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
60 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
61 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
62 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
63 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
64 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
65 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
66 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
67 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
68 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
69 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
70};
71EXPORT_SYMBOL_GPL(gigaset_invtab);
72
73void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg, 36void gigaset_dbg_buffer(enum debuglevel level, const unsigned char *msg,
74 size_t len, const unsigned char *buf) 37 size_t len, const unsigned char *buf)
75{ 38{
diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
index 06298cc52bf5..a0317abaeb11 100644
--- a/drivers/isdn/gigaset/gigaset.h
+++ b/drivers/isdn/gigaset/gigaset.h
@@ -876,10 +876,6 @@ static inline void gigaset_rcv_error(struct sk_buff *procskb,
876 } 876 }
877} 877}
878 878
879
880/* bitwise byte inversion table */
881extern __u8 gigaset_invtab[]; /* in common.c */
882
883/* append received bytes to inbuf */ 879/* append received bytes to inbuf */
884int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src, 880int gigaset_fill_inbuf(struct inbuf_t *inbuf, const unsigned char *src,
885 unsigned numbytes); 881 unsigned numbytes);
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 7edea015867e..458b6462f937 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -127,7 +127,7 @@ static int if_write_room(struct tty_struct *tty);
127static int if_chars_in_buffer(struct tty_struct *tty); 127static int if_chars_in_buffer(struct tty_struct *tty);
128static void if_throttle(struct tty_struct *tty); 128static void if_throttle(struct tty_struct *tty);
129static void if_unthrottle(struct tty_struct *tty); 129static void if_unthrottle(struct tty_struct *tty);
130static void if_set_termios(struct tty_struct *tty, struct termios *old); 130static void if_set_termios(struct tty_struct *tty, struct ktermios *old);
131static int if_tiocmget(struct tty_struct *tty, struct file *file); 131static int if_tiocmget(struct tty_struct *tty, struct file *file);
132static int if_tiocmset(struct tty_struct *tty, struct file *file, 132static int if_tiocmset(struct tty_struct *tty, struct file *file,
133 unsigned int set, unsigned int clear); 133 unsigned int set, unsigned int clear);
@@ -490,7 +490,7 @@ static void if_unthrottle(struct tty_struct *tty)
490 mutex_unlock(&cs->mutex); 490 mutex_unlock(&cs->mutex);
491} 491}
492 492
493static void if_set_termios(struct tty_struct *tty, struct termios *old) 493static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
494{ 494{
495 struct cardstate *cs; 495 struct cardstate *cs;
496 unsigned int iflag; 496 unsigned int iflag;
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index 8667daaa1a82..df988eb0e36f 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -14,6 +14,7 @@
14 14
15#include "gigaset.h" 15#include "gigaset.h"
16#include <linux/crc-ccitt.h> 16#include <linux/crc-ccitt.h>
17#include <linux/bitrev.h>
17 18
18/* access methods for isowbuf_t */ 19/* access methods for isowbuf_t */
19/* ============================ */ 20/* ============================ */
@@ -487,7 +488,7 @@ static inline int trans_buildframe(struct isowbuf_t *iwb,
487 gig_dbg(DEBUG_STREAM, "put %d bytes", count); 488 gig_dbg(DEBUG_STREAM, "put %d bytes", count);
488 write = atomic_read(&iwb->write); 489 write = atomic_read(&iwb->write);
489 do { 490 do {
490 c = gigaset_invtab[*in++]; 491 c = bitrev8(*in++);
491 iwb->data[write++] = c; 492 iwb->data[write++] = c;
492 write %= BAS_OUTBUFSIZE; 493 write %= BAS_OUTBUFSIZE;
493 } while (--count > 0); 494 } while (--count > 0);
@@ -876,7 +877,7 @@ static inline void trans_receive(unsigned char *src, unsigned count,
876 while (count > 0) { 877 while (count > 0) {
877 dst = skb_put(skb, count < dobytes ? count : dobytes); 878 dst = skb_put(skb, count < dobytes ? count : dobytes);
878 while (count > 0 && dobytes > 0) { 879 while (count > 0 && dobytes > 0) {
879 *dst++ = gigaset_invtab[*src++]; 880 *dst++ = bitrev8(*src++);
880 count--; 881 count--;
881 dobytes--; 882 dobytes--;
882 } 883 }
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index fd5d7364a487..eba10466ccc6 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -121,10 +121,9 @@ static int avmcs_probe(struct pcmcia_device *p_dev)
121 p_dev->conf.Present = PRESENT_OPTION; 121 p_dev->conf.Present = PRESENT_OPTION;
122 122
123 /* Allocate space for private device-specific data */ 123 /* Allocate space for private device-specific data */
124 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 124 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
125 if (!local) 125 if (!local)
126 goto err; 126 goto err;
127 memset(local, 0, sizeof(local_info_t));
128 p_dev->priv = local; 127 p_dev->priv = local;
129 128
130 return avmcs_config(p_dev); 129 return avmcs_config(p_dev);
diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
index da2729247713..7a69a18d07e2 100644
--- a/drivers/isdn/hardware/avm/b1.c
+++ b/drivers/isdn/hardware/avm/b1.c
@@ -65,18 +65,15 @@ avmcard *b1_alloc_card(int nr_controllers)
65 avmctrl_info *cinfo; 65 avmctrl_info *cinfo;
66 int i; 66 int i;
67 67
68 card = kmalloc(sizeof(*card), GFP_KERNEL); 68 card = kzalloc(sizeof(*card), GFP_KERNEL);
69 if (!card) 69 if (!card)
70 return NULL; 70 return NULL;
71 71
72 memset(card, 0, sizeof(*card)); 72 cinfo = kzalloc(sizeof(*cinfo) * nr_controllers, GFP_KERNEL);
73
74 cinfo = kmalloc(sizeof(*cinfo) * nr_controllers, GFP_KERNEL);
75 if (!cinfo) { 73 if (!cinfo) {
76 kfree(card); 74 kfree(card);
77 return NULL; 75 return NULL;
78 } 76 }
79 memset(cinfo, 0, sizeof(*cinfo) * nr_controllers);
80 77
81 card->ctrlinfo = cinfo; 78 card->ctrlinfo = cinfo;
82 for (i = 0; i < nr_controllers; i++) { 79 for (i = 0; i < nr_controllers; i++) {
@@ -718,12 +715,11 @@ avmcard_dma_alloc(char *name, struct pci_dev *pdev, long rsize, long ssize)
718 avmcard_dmainfo *p; 715 avmcard_dmainfo *p;
719 void *buf; 716 void *buf;
720 717
721 p = kmalloc(sizeof(avmcard_dmainfo), GFP_KERNEL); 718 p = kzalloc(sizeof(avmcard_dmainfo), GFP_KERNEL);
722 if (!p) { 719 if (!p) {
723 printk(KERN_WARNING "%s: no memory.\n", name); 720 printk(KERN_WARNING "%s: no memory.\n", name);
724 goto err; 721 goto err;
725 } 722 }
726 memset(p, 0, sizeof(avmcard_dmainfo));
727 723
728 p->recvbuf.size = rsize; 724 p->recvbuf.size = rsize;
729 buf = pci_alloc_consistent(pdev, rsize, &p->recvbuf.dmaaddr); 725 buf = pci_alloc_consistent(pdev, rsize, &p->recvbuf.dmaaddr);
diff --git a/drivers/isdn/hardware/avm/t1isa.c b/drivers/isdn/hardware/avm/t1isa.c
index e47c60b0a8ec..c925020fe9b7 100644
--- a/drivers/isdn/hardware/avm/t1isa.c
+++ b/drivers/isdn/hardware/avm/t1isa.c
@@ -584,6 +584,7 @@ static void __exit t1isa_exit(void)
584{ 584{
585 int i; 585 int i;
586 586
587 unregister_capi_driver(&capi_driver_t1isa);
587 for (i = 0; i < MAX_CARDS; i++) { 588 for (i = 0; i < MAX_CARDS; i++) {
588 if (!io[i]) 589 if (!io[i])
589 break; 590 break;
diff --git a/drivers/isdn/hardware/eicon/debug.c b/drivers/isdn/hardware/eicon/debug.c
index 6851c6270ce8..d835e74ecf18 100644
--- a/drivers/isdn/hardware/eicon/debug.c
+++ b/drivers/isdn/hardware/eicon/debug.c
@@ -756,14 +756,14 @@ int diva_get_driver_info (dword id, byte* data, int data_length) {
756 756
757 data_length -= 9; 757 data_length -= 9;
758 758
759 if ((to_copy = MIN(strlen(clients[id].drvName), data_length-1))) { 759 if ((to_copy = min(strlen(clients[id].drvName), (size_t)(data_length-1)))) {
760 memcpy (p, clients[id].drvName, to_copy); 760 memcpy (p, clients[id].drvName, to_copy);
761 p += to_copy; 761 p += to_copy;
762 data_length -= to_copy; 762 data_length -= to_copy;
763 if ((data_length >= 4) && clients[id].hDbg->drvTag[0]) { 763 if ((data_length >= 4) && clients[id].hDbg->drvTag[0]) {
764 *p++ = '('; 764 *p++ = '(';
765 data_length -= 1; 765 data_length -= 1;
766 if ((to_copy = MIN(strlen(clients[id].hDbg->drvTag), data_length-2))) { 766 if ((to_copy = min(strlen(clients[id].hDbg->drvTag), (size_t)(data_length-2)))) {
767 memcpy (p, clients[id].hDbg->drvTag, to_copy); 767 memcpy (p, clients[id].hDbg->drvTag, to_copy);
768 p += to_copy; 768 p += to_copy;
769 data_length -= to_copy; 769 data_length -= to_copy;
diff --git a/drivers/isdn/hardware/eicon/di.c b/drivers/isdn/hardware/eicon/di.c
index 0617d7cabf06..e1df8d98c311 100644
--- a/drivers/isdn/hardware/eicon/di.c
+++ b/drivers/isdn/hardware/eicon/di.c
@@ -133,7 +133,7 @@ void pr_out(ADAPTER * a)
133 i = this->XCurrent; 133 i = this->XCurrent;
134 X = PTR_X(a,this); 134 X = PTR_X(a,this);
135 while(i<this->XNum && length<270) { 135 while(i<this->XNum && length<270) {
136 clength = MIN((word)(270-length),X[i].PLength-this->XOffset); 136 clength = min((word)(270-length),(word)(X[i].PLength-this->XOffset));
137 a->ram_out_buffer(a, 137 a->ram_out_buffer(a,
138 &ReqOut->XBuffer.P[length], 138 &ReqOut->XBuffer.P[length],
139 PTR_P(a,this,&X[i].P[this->XOffset]), 139 PTR_P(a,this,&X[i].P[this->XOffset]),
@@ -622,7 +622,7 @@ byte isdn_ind(ADAPTER * a,
622 sizeof(a->stream_buffer), 622 sizeof(a->stream_buffer),
623 &final, NULL, NULL); 623 &final, NULL, NULL);
624 } 624 }
625 IoAdapter->RBuffer.length = MIN(MLength, 270); 625 IoAdapter->RBuffer.length = min(MLength, (word)270);
626 if (IoAdapter->RBuffer.length != MLength) { 626 if (IoAdapter->RBuffer.length != MLength) {
627 this->complete = 0; 627 this->complete = 0;
628 } else { 628 } else {
@@ -676,9 +676,9 @@ byte isdn_ind(ADAPTER * a,
676 this->RCurrent++; 676 this->RCurrent++;
677 } 677 }
678 if (cma) { 678 if (cma) {
679 clength = MIN(MLength, R[this->RCurrent].PLength-this->ROffset); 679 clength = min(MLength, (word)(R[this->RCurrent].PLength-this->ROffset));
680 } else { 680 } else {
681 clength = MIN(a->ram_inw(a, &RBuffer->length)-offset, 681 clength = min(a->ram_inw(a, &RBuffer->length)-offset,
682 R[this->RCurrent].PLength-this->ROffset); 682 R[this->RCurrent].PLength-this->ROffset);
683 } 683 }
684 if(R[this->RCurrent].P) { 684 if(R[this->RCurrent].P) {
diff --git a/drivers/isdn/hardware/eicon/divasmain.c b/drivers/isdn/hardware/eicon/divasmain.c
index dae2e83dd5e8..91fc92c01afe 100644
--- a/drivers/isdn/hardware/eicon/divasmain.c
+++ b/drivers/isdn/hardware/eicon/divasmain.c
@@ -185,7 +185,7 @@ void diva_log_info(unsigned char *format, ...)
185 unsigned char line[160]; 185 unsigned char line[160];
186 186
187 va_start(args, format); 187 va_start(args, format);
188 vsprintf(line, format, args); 188 vsnprintf(line, sizeof(line), format, args);
189 va_end(args); 189 va_end(args);
190 190
191 printk(KERN_INFO "%s: %s\n", DRIVERLNAME, line); 191 printk(KERN_INFO "%s: %s\n", DRIVERLNAME, line);
diff --git a/drivers/isdn/hardware/eicon/io.c b/drivers/isdn/hardware/eicon/io.c
index 4a27e230b0a5..6fd9b007417d 100644
--- a/drivers/isdn/hardware/eicon/io.c
+++ b/drivers/isdn/hardware/eicon/io.c
@@ -262,7 +262,7 @@ void request(PISDN_ADAPTER IoAdapter, ENTITY * e)
262 case IDI_SYNC_REQ_XDI_GET_CAPI_PARAMS: { 262 case IDI_SYNC_REQ_XDI_GET_CAPI_PARAMS: {
263 diva_xdi_get_capi_parameters_t prms, *pI = &syncReq->xdi_capi_prms.info; 263 diva_xdi_get_capi_parameters_t prms, *pI = &syncReq->xdi_capi_prms.info;
264 memset (&prms, 0x00, sizeof(prms)); 264 memset (&prms, 0x00, sizeof(prms));
265 prms.structure_length = MIN(sizeof(prms), pI->structure_length); 265 prms.structure_length = min_t(size_t, sizeof(prms), pI->structure_length);
266 memset (pI, 0x00, pI->structure_length); 266 memset (pI, 0x00, pI->structure_length);
267 prms.flag_dynamic_l1_down = (IoAdapter->capi_cfg.cfg_1 & \ 267 prms.flag_dynamic_l1_down = (IoAdapter->capi_cfg.cfg_1 & \
268 DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? 1 : 0; 268 DIVA_XDI_CAPI_CFG_1_DYNAMIC_L1_ON) ? 1 : 0;
diff --git a/drivers/isdn/hardware/eicon/istream.c b/drivers/isdn/hardware/eicon/istream.c
index 23139668d9b1..18f8798442fa 100644
--- a/drivers/isdn/hardware/eicon/istream.c
+++ b/drivers/isdn/hardware/eicon/istream.c
@@ -92,7 +92,7 @@ int diva_istream_write (void* context,
92 return (-1); /* was not able to write */ 92 return (-1); /* was not able to write */
93 break; /* only part of message was written */ 93 break; /* only part of message was written */
94 } 94 }
95 to_write = MIN(length, DIVA_DFIFO_DATA_SZ); 95 to_write = min(length, DIVA_DFIFO_DATA_SZ);
96 if (to_write) { 96 if (to_write) {
97 a->ram_out_buffer (a, 97 a->ram_out_buffer (a,
98#ifdef PLATFORM_GT_32BIT 98#ifdef PLATFORM_GT_32BIT
@@ -176,7 +176,7 @@ int diva_istream_read (void* context,
176 return (-1); /* was not able to read */ 176 return (-1); /* was not able to read */
177 break; 177 break;
178 } 178 }
179 to_read = MIN(max_length, tmp[1]); 179 to_read = min(max_length, (int)tmp[1]);
180 if (to_read) { 180 if (to_read) {
181 a->ram_in_buffer(a, 181 a->ram_in_buffer(a,
182#ifdef PLATFORM_GT_32BIT 182#ifdef PLATFORM_GT_32BIT
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index a66836cf756c..2444811e0b38 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -83,14 +83,6 @@
83#define NULL ((void *) 0) 83#define NULL ((void *) 0)
84#endif 84#endif
85 85
86#ifndef MIN
87#define MIN(a,b) ((a)>(b) ? (b) : (a))
88#endif
89
90#ifndef MAX
91#define MAX(a,b) ((a)>(b) ? (a) : (b))
92#endif
93
94#ifndef far 86#ifndef far
95#define far 87#define far
96#endif 88#endif
diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig
index cfd2718a490d..34ab5f7dcabc 100644
--- a/drivers/isdn/hisax/Kconfig
+++ b/drivers/isdn/hisax/Kconfig
@@ -110,7 +110,7 @@ config HISAX_16_3
110 110
111config HISAX_TELESPCI 111config HISAX_TELESPCI
112 bool "Teles PCI" 112 bool "Teles PCI"
113 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || FRV)) 113 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
114 help 114 help
115 This enables HiSax support for the Teles PCI. 115 This enables HiSax support for the Teles PCI.
116 See <file:Documentation/isdn/README.HiSax> on how to configure it. 116 See <file:Documentation/isdn/README.HiSax> on how to configure it.
@@ -238,7 +238,7 @@ config HISAX_MIC
238 238
239config HISAX_NETJET 239config HISAX_NETJET
240 bool "NETjet card" 240 bool "NETjet card"
241 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || FRV)) 241 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
242 help 242 help
243 This enables HiSax support for the NetJet from Traverse 243 This enables HiSax support for the NetJet from Traverse
244 Technologies. 244 Technologies.
@@ -249,7 +249,7 @@ config HISAX_NETJET
249 249
250config HISAX_NETJET_U 250config HISAX_NETJET_U
251 bool "NETspider U card" 251 bool "NETspider U card"
252 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || FRV)) 252 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
253 help 253 help
254 This enables HiSax support for the Netspider U interface ISDN card 254 This enables HiSax support for the Netspider U interface ISDN card
255 from Traverse Technologies. 255 from Traverse Technologies.
@@ -317,7 +317,7 @@ config HISAX_GAZEL
317 317
318config HISAX_HFC_PCI 318config HISAX_HFC_PCI
319 bool "HFC PCI-Bus cards" 319 bool "HFC PCI-Bus cards"
320 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || FRV)) 320 depends on PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
321 help 321 help
322 This enables HiSax support for the HFC-S PCI 2BDS0 based cards. 322 This enables HiSax support for the HFC-S PCI 2BDS0 based cards.
323 323
@@ -344,18 +344,11 @@ config HISAX_HFC_SX
344 344
345config HISAX_ENTERNOW_PCI 345config HISAX_ENTERNOW_PCI
346 bool "Formula-n enter:now PCI card" 346 bool "Formula-n enter:now PCI card"
347 depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || FRV)) 347 depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
348 help 348 help
349 This enables HiSax support for the Formula-n enter:now PCI 349 This enables HiSax support for the Formula-n enter:now PCI
350 ISDN card. 350 ISDN card.
351 351
352config HISAX_AMD7930
353 bool "Am7930 (EXPERIMENTAL)"
354 depends on EXPERIMENTAL && SPARC && BROKEN
355 help
356 This enables HiSax support for the AMD7930 chips on some SPARCs.
357 This code is not finished yet.
358
359endif 352endif
360 353
361if ISDN_DRV_HISAX 354if ISDN_DRV_HISAX
@@ -402,6 +395,7 @@ config HISAX_ST5481
402 tristate "ST5481 USB ISDN modem (EXPERIMENTAL)" 395 tristate "ST5481 USB ISDN modem (EXPERIMENTAL)"
403 depends on USB && EXPERIMENTAL 396 depends on USB && EXPERIMENTAL
404 select CRC_CCITT 397 select CRC_CCITT
398 select BITREVERSE
405 help 399 help
406 This enables the driver for ST5481 based USB ISDN adapters, 400 This enables the driver for ST5481 based USB ISDN adapters,
407 e.g. the BeWan Gazel 128 USB 401 e.g. the BeWan Gazel 128 USB
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index 876fec6c6be8..9e70c206779e 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -123,11 +123,10 @@ static int avma1cs_probe(struct pcmcia_device *p_dev)
123 DEBUG(0, "avma1cs_attach()\n"); 123 DEBUG(0, "avma1cs_attach()\n");
124 124
125 /* Allocate space for private device-specific data */ 125 /* Allocate space for private device-specific data */
126 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 126 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
127 if (!local) 127 if (!local)
128 return -ENOMEM; 128 return -ENOMEM;
129 129
130 memset(local, 0, sizeof(local_info_t));
131 p_dev->priv = local; 130 p_dev->priv = local;
132 131
133 /* The io structure describes IO port mapping */ 132 /* The io structure describes IO port mapping */
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index cede72cdbb31..17ec0b70ba1d 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -227,14 +227,6 @@ const char *CardType[] = {
227#define DEFAULT_CFG {5,0x2E0,0,0} 227#define DEFAULT_CFG {5,0x2E0,0,0}
228#endif 228#endif
229 229
230
231#ifdef CONFIG_HISAX_AMD7930
232#undef DEFAULT_CARD
233#undef DEFAULT_CFG
234#define DEFAULT_CARD ISDN_CTYPE_AMD7930
235#define DEFAULT_CFG {12,0x3e0,0,0}
236#endif
237
238#ifdef CONFIG_HISAX_NICCY 230#ifdef CONFIG_HISAX_NICCY
239#undef DEFAULT_CARD 231#undef DEFAULT_CARD
240#undef DEFAULT_CFG 232#undef DEFAULT_CFG
@@ -545,10 +537,6 @@ extern int setup_hfcpci(struct IsdnCard *card);
545extern int setup_hfcsx(struct IsdnCard *card); 537extern int setup_hfcsx(struct IsdnCard *card);
546#endif 538#endif
547 539
548#if CARD_AMD7930
549extern int setup_amd7930(struct IsdnCard *card);
550#endif
551
552#if CARD_NICCY 540#if CARD_NICCY
553extern int setup_niccy(struct IsdnCard *card); 541extern int setup_niccy(struct IsdnCard *card);
554#endif 542#endif
@@ -869,14 +857,13 @@ static int checkcard(int cardnr, char *id, int *busy_flag, struct module *lockow
869 struct IsdnCard *card = cards + cardnr; 857 struct IsdnCard *card = cards + cardnr;
870 struct IsdnCardState *cs; 858 struct IsdnCardState *cs;
871 859
872 cs = kmalloc(sizeof(struct IsdnCardState), GFP_ATOMIC); 860 cs = kzalloc(sizeof(struct IsdnCardState), GFP_ATOMIC);
873 if (!cs) { 861 if (!cs) {
874 printk(KERN_WARNING 862 printk(KERN_WARNING
875 "HiSax: No memory for IsdnCardState(card %d)\n", 863 "HiSax: No memory for IsdnCardState(card %d)\n",
876 cardnr + 1); 864 cardnr + 1);
877 goto out; 865 goto out;
878 } 866 }
879 memset(cs, 0, sizeof(struct IsdnCardState));
880 card->cs = cs; 867 card->cs = cs;
881 spin_lock_init(&cs->statlock); 868 spin_lock_init(&cs->statlock);
882 spin_lock_init(&cs->lock); 869 spin_lock_init(&cs->lock);
@@ -1064,11 +1051,6 @@ static int checkcard(int cardnr, char *id, int *busy_flag, struct module *lockow
1064 ret = setup_niccy(card); 1051 ret = setup_niccy(card);
1065 break; 1052 break;
1066#endif 1053#endif
1067#if CARD_AMD7930
1068 case ISDN_CTYPE_AMD7930:
1069 ret = setup_amd7930(card);
1070 break;
1071#endif
1072#if CARD_ISURF 1054#if CARD_ISURF
1073 case ISDN_CTYPE_ISURF: 1055 case ISDN_CTYPE_ISURF:
1074 ret = setup_isurf(card); 1056 ret = setup_isurf(card);
@@ -1437,7 +1419,6 @@ static int __init HiSax_init(void)
1437 break; 1419 break;
1438 case ISDN_CTYPE_ELSA_PCI: 1420 case ISDN_CTYPE_ELSA_PCI:
1439 case ISDN_CTYPE_NETJET_S: 1421 case ISDN_CTYPE_NETJET_S:
1440 case ISDN_CTYPE_AMD7930:
1441 case ISDN_CTYPE_TELESPCI: 1422 case ISDN_CTYPE_TELESPCI:
1442 case ISDN_CTYPE_W6692: 1423 case ISDN_CTYPE_W6692:
1443 case ISDN_CTYPE_NETJET_U: 1424 case ISDN_CTYPE_NETJET_U:
diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
index 3dacfff93f5f..6eebeb441bfd 100644
--- a/drivers/isdn/hisax/diva.c
+++ b/drivers/isdn/hisax/diva.c
@@ -1121,7 +1121,11 @@ setup_diva(struct IsdnCard *card)
1121 bytecnt = 32; 1121 bytecnt = 32;
1122 } 1122 }
1123 } 1123 }
1124
1125#ifdef __ISAPNP__
1124ready: 1126ready:
1127#endif
1128
1125 printk(KERN_INFO 1129 printk(KERN_INFO
1126 "Diva: %s card configured at %#lx IRQ %d\n", 1130 "Diva: %s card configured at %#lx IRQ %d\n",
1127 (cs->subtyp == DIVA_PCI) ? "PCI" : 1131 (cs->subtyp == DIVA_PCI) ? "PCI" :
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index 4e180d210faa..79ab9dda7d08 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -146,9 +146,8 @@ static int elsa_cs_probe(struct pcmcia_device *link)
146 DEBUG(0, "elsa_cs_attach()\n"); 146 DEBUG(0, "elsa_cs_attach()\n");
147 147
148 /* Allocate space for private device-specific data */ 148 /* Allocate space for private device-specific data */
149 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 149 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
150 if (!local) return -ENOMEM; 150 if (!local) return -ENOMEM;
151 memset(local, 0, sizeof(local_info_t));
152 151
153 local->p_dev = link; 152 local->p_dev = link;
154 link->priv = local; 153 link->priv = local;
diff --git a/drivers/isdn/hisax/fsm.c b/drivers/isdn/hisax/fsm.c
index 0d44a3f480ac..34fade96a581 100644
--- a/drivers/isdn/hisax/fsm.c
+++ b/drivers/isdn/hisax/fsm.c
@@ -26,12 +26,10 @@ FsmNew(struct Fsm *fsm, struct FsmNode *fnlist, int fncount)
26 int i; 26 int i;
27 27
28 fsm->jumpmatrix = (FSMFNPTR *) 28 fsm->jumpmatrix = (FSMFNPTR *)
29 kmalloc(sizeof (FSMFNPTR) * fsm->state_count * fsm->event_count, GFP_KERNEL); 29 kzalloc(sizeof (FSMFNPTR) * fsm->state_count * fsm->event_count, GFP_KERNEL);
30 if (!fsm->jumpmatrix) 30 if (!fsm->jumpmatrix)
31 return -ENOMEM; 31 return -ENOMEM;
32 32
33 memset(fsm->jumpmatrix, 0, sizeof (FSMFNPTR) * fsm->state_count * fsm->event_count);
34
35 for (i = 0; i < fncount; i++) 33 for (i = 0; i < fncount; i++)
36 if ((fnlist[i].state>=fsm->state_count) || (fnlist[i].event>=fsm->event_count)) { 34 if ((fnlist[i].state>=fsm->state_count) || (fnlist[i].event>=fsm->event_count)) {
37 printk(KERN_ERR "FsmNew Error line %d st(%ld/%ld) ev(%ld/%ld)\n", 35 printk(KERN_ERR "FsmNew Error line %d st(%ld/%ld) ev(%ld/%ld)\n",
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index de9b1a4d6bac..a2fa4ecb8c88 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -1591,11 +1591,10 @@ hfc4s8s_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1591 hfc4s8s_param *driver_data = (hfc4s8s_param *) ent->driver_data; 1591 hfc4s8s_param *driver_data = (hfc4s8s_param *) ent->driver_data;
1592 hfc4s8s_hw *hw; 1592 hfc4s8s_hw *hw;
1593 1593
1594 if (!(hw = kmalloc(sizeof(hfc4s8s_hw), GFP_ATOMIC))) { 1594 if (!(hw = kzalloc(sizeof(hfc4s8s_hw), GFP_ATOMIC))) {
1595 printk(KERN_ERR "No kmem for HFC-4S/8S card\n"); 1595 printk(KERN_ERR "No kmem for HFC-4S/8S card\n");
1596 return (err); 1596 return (err);
1597 } 1597 }
1598 memset(hw, 0, sizeof(hfc4s8s_hw));
1599 1598
1600 hw->pdev = pdev; 1599 hw->pdev = pdev;
1601 err = pci_enable_device(pdev); 1600 err = pci_enable_device(pdev);
diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
index 5db0a85b827f..8a48a3ce0a55 100644
--- a/drivers/isdn/hisax/hfc_pci.c
+++ b/drivers/isdn/hisax/hfc_pci.c
@@ -1211,7 +1211,7 @@ HFCPCI_l1hw(struct PStack *st, int pr, void *arg)
1211 break; 1211 break;
1212 case (HW_TESTLOOP | REQUEST): 1212 case (HW_TESTLOOP | REQUEST):
1213 spin_lock_irqsave(&cs->lock, flags); 1213 spin_lock_irqsave(&cs->lock, flags);
1214 switch ((int) arg) { 1214 switch ((long) arg) {
1215 case (1): 1215 case (1):
1216 Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* tx slot */ 1216 Write_hfc(cs, HFCPCI_B1_SSL, 0x80); /* tx slot */
1217 Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* rx slot */ 1217 Write_hfc(cs, HFCPCI_B1_RSL, 0x80); /* rx slot */
@@ -1229,7 +1229,7 @@ HFCPCI_l1hw(struct PStack *st, int pr, void *arg)
1229 default: 1229 default:
1230 spin_unlock_irqrestore(&cs->lock, flags); 1230 spin_unlock_irqrestore(&cs->lock, flags);
1231 if (cs->debug & L1_DEB_WARN) 1231 if (cs->debug & L1_DEB_WARN)
1232 debugl1(cs, "hfcpci_l1hw loop invalid %4x", (int) arg); 1232 debugl1(cs, "hfcpci_l1hw loop invalid %4lx", (long) arg);
1233 return; 1233 return;
1234 } 1234 }
1235 cs->hw.hfcpci.trm |= 0x80; /* enable IOM-loop */ 1235 cs->hw.hfcpci.trm |= 0x80; /* enable IOM-loop */
@@ -1711,9 +1711,9 @@ setup_hfcpci(struct IsdnCard *card)
1711 pci_write_config_dword(cs->hw.hfcpci.dev, 0x80, (u_int) virt_to_bus(cs->hw.hfcpci.fifos)); 1711 pci_write_config_dword(cs->hw.hfcpci.dev, 0x80, (u_int) virt_to_bus(cs->hw.hfcpci.fifos));
1712 cs->hw.hfcpci.pci_io = ioremap((ulong) cs->hw.hfcpci.pci_io, 256); 1712 cs->hw.hfcpci.pci_io = ioremap((ulong) cs->hw.hfcpci.pci_io, 256);
1713 printk(KERN_INFO 1713 printk(KERN_INFO
1714 "HFC-PCI: defined at mem %#x fifo %#x(%#x) IRQ %d HZ %d\n", 1714 "HFC-PCI: defined at mem %p fifo %p(%#x) IRQ %d HZ %d\n",
1715 (u_int) cs->hw.hfcpci.pci_io, 1715 cs->hw.hfcpci.pci_io,
1716 (u_int) cs->hw.hfcpci.fifos, 1716 cs->hw.hfcpci.fifos,
1717 (u_int) virt_to_bus(cs->hw.hfcpci.fifos), 1717 (u_int) virt_to_bus(cs->hw.hfcpci.fifos),
1718 cs->irq, HZ); 1718 cs->irq, HZ);
1719 spin_lock_irqsave(&cs->lock, flags); 1719 spin_lock_irqsave(&cs->lock, flags);
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index 7105b043add8..5a6989f23fcf 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -1481,9 +1481,8 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1481 iface = iface_used; 1481 iface = iface_used;
1482 if (! 1482 if (!
1483 (context = 1483 (context =
1484 kmalloc(sizeof(hfcusb_data), GFP_KERNEL))) 1484 kzalloc(sizeof(hfcusb_data), GFP_KERNEL)))
1485 return (-ENOMEM); /* got no mem */ 1485 return (-ENOMEM); /* got no mem */
1486 memset(context, 0, sizeof(hfcusb_data));
1487 1486
1488 ep = iface->endpoint; 1487 ep = iface->endpoint;
1489 vcf = validconf[small_match]; 1488 vcf = validconf[small_match];
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 159c5896061e..3f1137e34678 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -1139,12 +1139,6 @@ struct IsdnCardState {
1139#define CARD_HFC_SX 0 1139#define CARD_HFC_SX 0
1140#endif 1140#endif
1141 1141
1142#ifdef CONFIG_HISAX_AMD7930
1143#define CARD_AMD7930 1
1144#else
1145#define CARD_AMD7930 0
1146#endif
1147
1148#ifdef CONFIG_HISAX_NICCY 1142#ifdef CONFIG_HISAX_NICCY
1149#define CARD_NICCY 1 1143#define CARD_NICCY 1
1150#ifndef ISDN_CHIP_ISAC 1144#ifndef ISDN_CHIP_ISAC
diff --git a/drivers/isdn/hisax/hisax_fcpcipnp.c b/drivers/isdn/hisax/hisax_fcpcipnp.c
index f6db55a752c4..9e088fce8c3a 100644
--- a/drivers/isdn/hisax/hisax_fcpcipnp.c
+++ b/drivers/isdn/hisax/hisax_fcpcipnp.c
@@ -841,12 +841,10 @@ new_adapter(void)
841 struct hisax_b_if *b_if[2]; 841 struct hisax_b_if *b_if[2];
842 int i; 842 int i;
843 843
844 adapter = kmalloc(sizeof(struct fritz_adapter), GFP_KERNEL); 844 adapter = kzalloc(sizeof(struct fritz_adapter), GFP_KERNEL);
845 if (!adapter) 845 if (!adapter)
846 return NULL; 846 return NULL;
847 847
848 memset(adapter, 0, sizeof(struct fritz_adapter));
849
850 adapter->isac.hisax_d_if.owner = THIS_MODULE; 848 adapter->isac.hisax_d_if.owner = THIS_MODULE;
851 adapter->isac.hisax_d_if.ifc.priv = &adapter->isac; 849 adapter->isac.hisax_d_if.ifc.priv = &adapter->isac;
852 adapter->isac.hisax_d_if.ifc.l2l1 = isac_d_l2l1; 850 adapter->isac.hisax_d_if.ifc.l2l1 = isac_d_l2l1;
diff --git a/drivers/isdn/hisax/hisax_isac.c b/drivers/isdn/hisax/hisax_isac.c
index 81eac344bb03..d0fefcf999cb 100644
--- a/drivers/isdn/hisax/hisax_isac.c
+++ b/drivers/isdn/hisax/hisax_isac.c
@@ -433,7 +433,7 @@ static void l1m_debug(struct FsmInst *fi, char *fmt, ...)
433 char buf[256]; 433 char buf[256];
434 434
435 va_start(args, fmt); 435 va_start(args, fmt);
436 vsprintf(buf, fmt, args); 436 vsnprintf(buf, sizeof(buf), fmt, args);
437 DBG(DBG_L1M, "%s", buf); 437 DBG(DBG_L1M, "%s", buf);
438 va_end(args); 438 va_end(args);
439} 439}
diff --git a/drivers/isdn/hisax/isdnhdlc.c b/drivers/isdn/hisax/isdnhdlc.c
index cbdf54c5af84..268dced6c34a 100644
--- a/drivers/isdn/hisax/isdnhdlc.c
+++ b/drivers/isdn/hisax/isdnhdlc.c
@@ -35,30 +35,6 @@ MODULE_LICENSE("GPL");
35 35
36/*-------------------------------------------------------------------*/ 36/*-------------------------------------------------------------------*/
37 37
38/* bit swap table.
39 * Very handy for devices with different bit order,
40 * and neccessary for each transparent B-channel access for all
41 * devices which works with this HDLC decoder without bit reversal.
42 */
43const unsigned char isdnhdlc_bit_rev_tab[256] = {
44 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
45 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
46 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
47 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
48 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
49 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
50 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
51 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
52 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
53 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
54 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
55 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
56 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
57 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
58 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
59 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF
60};
61
62enum { 38enum {
63 HDLC_FAST_IDLE,HDLC_GET_FLAG_B0,HDLC_GETFLAG_B1A6,HDLC_GETFLAG_B7, 39 HDLC_FAST_IDLE,HDLC_GET_FLAG_B0,HDLC_GETFLAG_B1A6,HDLC_GETFLAG_B7,
64 HDLC_GET_DATA,HDLC_FAST_FLAG 40 HDLC_GET_DATA,HDLC_FAST_FLAG
@@ -621,7 +597,6 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
621 return len; 597 return len;
622} 598}
623 599
624EXPORT_SYMBOL(isdnhdlc_bit_rev_tab);
625EXPORT_SYMBOL(isdnhdlc_rcv_init); 600EXPORT_SYMBOL(isdnhdlc_rcv_init);
626EXPORT_SYMBOL(isdnhdlc_decode); 601EXPORT_SYMBOL(isdnhdlc_decode);
627EXPORT_SYMBOL(isdnhdlc_out_init); 602EXPORT_SYMBOL(isdnhdlc_out_init);
diff --git a/drivers/isdn/hisax/isdnhdlc.h b/drivers/isdn/hisax/isdnhdlc.h
index 5655b5f9c48e..45167d2f8fb0 100644
--- a/drivers/isdn/hisax/isdnhdlc.h
+++ b/drivers/isdn/hisax/isdnhdlc.h
@@ -57,8 +57,6 @@ struct isdnhdlc_vars {
57#define HDLC_CRC_ERROR 2 57#define HDLC_CRC_ERROR 2
58#define HDLC_LENGTH_ERROR 3 58#define HDLC_LENGTH_ERROR 3
59 59
60extern const unsigned char isdnhdlc_bit_rev_tab[256];
61
62extern void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56); 60extern void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56);
63 61
64extern int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, int slen,int *count, 62extern int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, int slen,int *count,
diff --git a/drivers/isdn/hisax/sedlbauer.c b/drivers/isdn/hisax/sedlbauer.c
index 9522141f4351..030d1625c5c6 100644
--- a/drivers/isdn/hisax/sedlbauer.c
+++ b/drivers/isdn/hisax/sedlbauer.c
@@ -677,7 +677,11 @@ setup_sedlbauer(struct IsdnCard *card)
677 return (0); 677 return (0);
678#endif /* CONFIG_PCI */ 678#endif /* CONFIG_PCI */
679 } 679 }
680
681#ifdef __ISAPNP__
680ready: 682ready:
683#endif
684
681 /* In case of the sedlbauer pcmcia card, this region is in use, 685 /* In case of the sedlbauer pcmcia card, this region is in use,
682 * reserved for us by the card manager. So we do not check it 686 * reserved for us by the card manager. So we do not check it
683 * here, it would fail. 687 * here, it would fail.
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 46ed65334c51..45debde05fbd 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -155,9 +155,8 @@ static int sedlbauer_probe(struct pcmcia_device *link)
155 DEBUG(0, "sedlbauer_attach()\n"); 155 DEBUG(0, "sedlbauer_attach()\n");
156 156
157 /* Allocate space for private device-specific data */ 157 /* Allocate space for private device-specific data */
158 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 158 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
159 if (!local) return -ENOMEM; 159 if (!local) return -ENOMEM;
160 memset(local, 0, sizeof(local_info_t));
161 local->cardnr = -1; 160 local->cardnr = -1;
162 161
163 local->p_dev = link; 162 local->p_dev = link;
diff --git a/drivers/isdn/hisax/st5481_b.c b/drivers/isdn/hisax/st5481_b.c
index 75d0f248e4ee..fa64115cd7c7 100644
--- a/drivers/isdn/hisax/st5481_b.c
+++ b/drivers/isdn/hisax/st5481_b.c
@@ -14,6 +14,7 @@
14#include <linux/usb.h> 14#include <linux/usb.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/netdevice.h> 16#include <linux/netdevice.h>
17#include <linux/bitrev.h>
17#include "st5481.h" 18#include "st5481.h"
18 19
19static inline void B_L1L2(struct st5481_bcs *bcs, int pr, void *arg) 20static inline void B_L1L2(struct st5481_bcs *bcs, int pr, void *arg)
@@ -72,7 +73,7 @@ static void usb_b_out(struct st5481_bcs *bcs,int buf_nr)
72 register unsigned char *dest = urb->transfer_buffer+len; 73 register unsigned char *dest = urb->transfer_buffer+len;
73 register unsigned int count; 74 register unsigned int count;
74 for (count = 0; count < bytes_sent; count++) 75 for (count = 0; count < bytes_sent; count++)
75 *dest++ = isdnhdlc_bit_rev_tab[*src++]; 76 *dest++ = bitrev8(*src++);
76 } 77 }
77 len += bytes_sent; 78 len += bytes_sent;
78 } else { 79 } else {
diff --git a/drivers/isdn/hisax/st5481_d.c b/drivers/isdn/hisax/st5481_d.c
index 1d8c2618366c..b8c4855cc889 100644
--- a/drivers/isdn/hisax/st5481_d.c
+++ b/drivers/isdn/hisax/st5481_d.c
@@ -173,7 +173,7 @@ static void l1m_debug(struct FsmInst *fi, char *fmt, ...)
173 char buf[256]; 173 char buf[256];
174 174
175 va_start(args, fmt); 175 va_start(args, fmt);
176 vsprintf(buf, fmt, args); 176 vsnprintf(buf, sizeof(buf), fmt, args);
177 DBG(8, "%s", buf); 177 DBG(8, "%s", buf);
178 va_end(args); 178 va_end(args);
179} 179}
@@ -275,7 +275,7 @@ static void dout_debug(struct FsmInst *fi, char *fmt, ...)
275 char buf[256]; 275 char buf[256];
276 276
277 va_start(args, fmt); 277 va_start(args, fmt);
278 vsprintf(buf, fmt, args); 278 vsnprintf(buf, sizeof(buf), fmt, args);
279 DBG(0x2, "%s", buf); 279 DBG(0x2, "%s", buf);
280 va_end(args); 280 va_end(args);
281} 281}
diff --git a/drivers/isdn/hisax/st5481_init.c b/drivers/isdn/hisax/st5481_init.c
index 2716aa5c60f7..bb3a28a53ff4 100644
--- a/drivers/isdn/hisax/st5481_init.c
+++ b/drivers/isdn/hisax/st5481_init.c
@@ -69,12 +69,10 @@ static int probe_st5481(struct usb_interface *intf,
69 le16_to_cpu(dev->descriptor.idProduct), 69 le16_to_cpu(dev->descriptor.idProduct),
70 number_of_leds); 70 number_of_leds);
71 71
72 adapter = kmalloc(sizeof(struct st5481_adapter), GFP_KERNEL); 72 adapter = kzalloc(sizeof(struct st5481_adapter), GFP_KERNEL);
73 if (!adapter) 73 if (!adapter)
74 return -ENOMEM; 74 return -ENOMEM;
75 75
76 memset(adapter, 0, sizeof(struct st5481_adapter));
77
78 adapter->number_of_leds = number_of_leds; 76 adapter->number_of_leds = number_of_leds;
79 adapter->usb_dev = dev; 77 adapter->usb_dev = dev;
80 78
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index 6b754f183796..3e3e18239ec7 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -137,9 +137,8 @@ static int teles_probe(struct pcmcia_device *link)
137 DEBUG(0, "teles_attach()\n"); 137 DEBUG(0, "teles_attach()\n");
138 138
139 /* Allocate space for private device-specific data */ 139 /* Allocate space for private device-specific data */
140 local = kmalloc(sizeof(local_info_t), GFP_KERNEL); 140 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
141 if (!local) return -ENOMEM; 141 if (!local) return -ENOMEM;
142 memset(local, 0, sizeof(local_info_t));
143 local->cardnr = -1; 142 local->cardnr = -1;
144 143
145 local->p_dev = link; 144 local->p_dev = link;
diff --git a/drivers/isdn/hysdn/hycapi.c b/drivers/isdn/hysdn/hycapi.c
index 6bac43cc91bd..b2ae4ec1e49e 100644
--- a/drivers/isdn/hysdn/hycapi.c
+++ b/drivers/isdn/hysdn/hycapi.c
@@ -745,12 +745,11 @@ hycapi_capi_create(hysdn_card *card)
745 return 1; 745 return 1;
746 } 746 }
747 if (!card->hyctrlinfo) { 747 if (!card->hyctrlinfo) {
748 cinfo = (hycapictrl_info *) kmalloc(sizeof(hycapictrl_info), GFP_ATOMIC); 748 cinfo = kzalloc(sizeof(hycapictrl_info), GFP_ATOMIC);
749 if (!cinfo) { 749 if (!cinfo) {
750 printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n"); 750 printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n");
751 return -ENOMEM; 751 return -ENOMEM;
752 } 752 }
753 memset(cinfo, 0, sizeof(hycapictrl_info));
754 card->hyctrlinfo = cinfo; 753 card->hyctrlinfo = cinfo;
755 cinfo->card = card; 754 cinfo->card = card;
756 spin_lock_init(&cinfo->lock); 755 spin_lock_init(&cinfo->lock);
diff --git a/drivers/isdn/hysdn/hysdn_boot.c b/drivers/isdn/hysdn/hysdn_boot.c
index 6d0eb0f42fca..be787e16bb79 100644
--- a/drivers/isdn/hysdn/hysdn_boot.c
+++ b/drivers/isdn/hysdn/hysdn_boot.c
@@ -278,14 +278,13 @@ pof_write_open(hysdn_card * card, unsigned char **bufp)
278 return (-ERR_ALREADY_BOOT); /* boot already active */ 278 return (-ERR_ALREADY_BOOT); /* boot already active */
279 } 279 }
280 /* error no mem available */ 280 /* error no mem available */
281 if (!(boot = kmalloc(sizeof(struct boot_data), GFP_KERNEL))) { 281 if (!(boot = kzalloc(sizeof(struct boot_data), GFP_KERNEL))) {
282 if (card->debug_flags & LOG_MEM_ERR) 282 if (card->debug_flags & LOG_MEM_ERR)
283 hysdn_addlog(card, "POF open: unable to allocate mem"); 283 hysdn_addlog(card, "POF open: unable to allocate mem");
284 return (-EFAULT); 284 return (-EFAULT);
285 } 285 }
286 card->boot = boot; 286 card->boot = boot;
287 card->state = CARD_STATE_BOOTING; 287 card->state = CARD_STATE_BOOTING;
288 memset(boot, 0, sizeof(struct boot_data));
289 288
290 card->stopcard(card); /* first stop the card */ 289 card->stopcard(card); /* first stop the card */
291 if (card->testram(card)) { 290 if (card->testram(card)) {
diff --git a/drivers/isdn/hysdn/hysdn_init.c b/drivers/isdn/hysdn/hysdn_init.c
index b702ed27252b..9e01748a176e 100644
--- a/drivers/isdn/hysdn/hysdn_init.c
+++ b/drivers/isdn/hysdn/hysdn_init.c
@@ -81,11 +81,10 @@ search_cards(void)
81 if (pci_enable_device(akt_pcidev)) 81 if (pci_enable_device(akt_pcidev))
82 continue; 82 continue;
83 83
84 if (!(card = kmalloc(sizeof(hysdn_card), GFP_KERNEL))) { 84 if (!(card = kzalloc(sizeof(hysdn_card), GFP_KERNEL))) {
85 printk(KERN_ERR "HYSDN: unable to alloc device mem \n"); 85 printk(KERN_ERR "HYSDN: unable to alloc device mem \n");
86 return; 86 return;
87 } 87 }
88 memset(card, 0, sizeof(hysdn_card));
89 card->myid = cardmax; /* set own id */ 88 card->myid = cardmax; /* set own id */
90 card->bus = akt_pcidev->bus->number; 89 card->bus = akt_pcidev->bus->number;
91 card->devfn = akt_pcidev->devfn; /* slot + function */ 90 card->devfn = akt_pcidev->devfn; /* slot + function */
diff --git a/drivers/isdn/hysdn/hysdn_net.c b/drivers/isdn/hysdn/hysdn_net.c
index d205249a1242..557d96c78a62 100644
--- a/drivers/isdn/hysdn/hysdn_net.c
+++ b/drivers/isdn/hysdn/hysdn_net.c
@@ -278,11 +278,10 @@ hysdn_net_create(hysdn_card * card)
278 return (-ENOMEM); 278 return (-ENOMEM);
279 } 279 }
280 hysdn_net_release(card); /* release an existing net device */ 280 hysdn_net_release(card); /* release an existing net device */
281 if ((dev = kmalloc(sizeof(struct net_local), GFP_KERNEL)) == NULL) { 281 if ((dev = kzalloc(sizeof(struct net_local), GFP_KERNEL)) == NULL) {
282 printk(KERN_WARNING "HYSDN: unable to allocate mem\n"); 282 printk(KERN_WARNING "HYSDN: unable to allocate mem\n");
283 return (-ENOMEM); 283 return (-ENOMEM);
284 } 284 }
285 memset(dev, 0, sizeof(struct net_local)); /* clean the structure */
286 285
287 spin_lock_init(&((struct net_local *) dev)->lock); 286 spin_lock_init(&((struct net_local *) dev)->lock);
288 287
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index fcd49920b220..f241f5e551cb 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -204,7 +204,7 @@ hysdn_log_read(struct file *file, char __user *buf, size_t count, loff_t * off)
204{ 204{
205 struct log_data *inf; 205 struct log_data *inf;
206 int len; 206 int len;
207 struct proc_dir_entry *pde = PDE(file->f_dentry->d_inode); 207 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
208 struct procdata *pd = NULL; 208 struct procdata *pd = NULL;
209 hysdn_card *card; 209 hysdn_card *card;
210 210
@@ -354,7 +354,7 @@ static unsigned int
354hysdn_log_poll(struct file *file, poll_table * wait) 354hysdn_log_poll(struct file *file, poll_table * wait)
355{ 355{
356 unsigned int mask = 0; 356 unsigned int mask = 0;
357 struct proc_dir_entry *pde = PDE(file->f_dentry->d_inode); 357 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
358 hysdn_card *card; 358 hysdn_card *card;
359 struct procdata *pd = NULL; 359 struct procdata *pd = NULL;
360 360
@@ -405,8 +405,7 @@ hysdn_proclog_init(hysdn_card * card)
405 405
406 /* create a cardlog proc entry */ 406 /* create a cardlog proc entry */
407 407
408 if ((pd = (struct procdata *) kmalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) { 408 if ((pd = kzalloc(sizeof(struct procdata), GFP_KERNEL)) != NULL) {
409 memset(pd, 0, sizeof(struct procdata));
410 sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid); 409 sprintf(pd->log_name, "%s%d", PROC_LOG_BASENAME, card->myid);
411 if ((pd->log = create_proc_entry(pd->log_name, S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry)) != NULL) { 410 if ((pd->log = create_proc_entry(pd->log_name, S_IFREG | S_IRUGO | S_IWUSR, hysdn_proc_entry)) != NULL) {
412 pd->log->proc_fops = &log_fops; 411 pd->log->proc_fops = &log_fops;
diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c
index 0afe442db3b0..a20f33b4a220 100644
--- a/drivers/isdn/i4l/isdn_bsdcomp.c
+++ b/drivers/isdn/i4l/isdn_bsdcomp.c
@@ -331,12 +331,10 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
331 * Allocate the main control structure for this instance. 331 * Allocate the main control structure for this instance.
332 */ 332 */
333 maxmaxcode = MAXCODE(bits); 333 maxmaxcode = MAXCODE(bits);
334 db = (struct bsd_db *) kmalloc (sizeof (struct bsd_db),GFP_KERNEL); 334 db = kzalloc (sizeof (struct bsd_db),GFP_KERNEL);
335 if (!db) 335 if (!db)
336 return NULL; 336 return NULL;
337 337
338 memset (db, 0, sizeof(struct bsd_db));
339
340 db->xmit = data->flags & IPPP_COMP_FLAG_XMIT; 338 db->xmit = data->flags & IPPP_COMP_FLAG_XMIT;
341 decomp = db->xmit ? 0 : 1; 339 decomp = db->xmit ? 0 : 1;
342 340
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index 69aee2602aa6..6a2ef0a87ed9 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -1059,7 +1059,7 @@ isdn_info_update(void)
1059static ssize_t 1059static ssize_t
1060isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off) 1060isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1061{ 1061{
1062 uint minor = iminor(file->f_dentry->d_inode); 1062 uint minor = iminor(file->f_path.dentry->d_inode);
1063 int len = 0; 1063 int len = 0;
1064 int drvidx; 1064 int drvidx;
1065 int chidx; 1065 int chidx;
@@ -1166,7 +1166,7 @@ isdn_read(struct file *file, char __user *buf, size_t count, loff_t * off)
1166static ssize_t 1166static ssize_t
1167isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off) 1167isdn_write(struct file *file, const char __user *buf, size_t count, loff_t * off)
1168{ 1168{
1169 uint minor = iminor(file->f_dentry->d_inode); 1169 uint minor = iminor(file->f_path.dentry->d_inode);
1170 int drvidx; 1170 int drvidx;
1171 int chidx; 1171 int chidx;
1172 int retval; 1172 int retval;
@@ -1228,7 +1228,7 @@ static unsigned int
1228isdn_poll(struct file *file, poll_table * wait) 1228isdn_poll(struct file *file, poll_table * wait)
1229{ 1229{
1230 unsigned int mask = 0; 1230 unsigned int mask = 0;
1231 unsigned int minor = iminor(file->f_dentry->d_inode); 1231 unsigned int minor = iminor(file->f_path.dentry->d_inode);
1232 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL); 1232 int drvidx = isdn_minor2drv(minor - ISDN_MINOR_CTRL);
1233 1233
1234 lock_kernel(); 1234 lock_kernel();
@@ -2072,21 +2072,19 @@ isdn_add_channels(isdn_driver_t *d, int drvidx, int n, int adding)
2072 2072
2073 if ((adding) && (d->rcverr)) 2073 if ((adding) && (d->rcverr))
2074 kfree(d->rcverr); 2074 kfree(d->rcverr);
2075 if (!(d->rcverr = kmalloc(sizeof(int) * m, GFP_ATOMIC))) { 2075 if (!(d->rcverr = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
2076 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n"); 2076 printk(KERN_WARNING "register_isdn: Could not alloc rcverr\n");
2077 return -1; 2077 return -1;
2078 } 2078 }
2079 memset((char *) d->rcverr, 0, sizeof(int) * m);
2080 2079
2081 if ((adding) && (d->rcvcount)) 2080 if ((adding) && (d->rcvcount))
2082 kfree(d->rcvcount); 2081 kfree(d->rcvcount);
2083 if (!(d->rcvcount = kmalloc(sizeof(int) * m, GFP_ATOMIC))) { 2082 if (!(d->rcvcount = kzalloc(sizeof(int) * m, GFP_ATOMIC))) {
2084 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n"); 2083 printk(KERN_WARNING "register_isdn: Could not alloc rcvcount\n");
2085 if (!adding) 2084 if (!adding)
2086 kfree(d->rcverr); 2085 kfree(d->rcverr);
2087 return -1; 2086 return -1;
2088 } 2087 }
2089 memset((char *) d->rcvcount, 0, sizeof(int) * m);
2090 2088
2091 if ((adding) && (d->rpqueue)) { 2089 if ((adding) && (d->rpqueue)) {
2092 for (j = 0; j < d->channels; j++) 2090 for (j = 0; j < d->channels; j++)
@@ -2226,11 +2224,10 @@ register_isdn(isdn_if * i)
2226 printk(KERN_WARNING "register_isdn: No write routine given.\n"); 2224 printk(KERN_WARNING "register_isdn: No write routine given.\n");
2227 return 0; 2225 return 0;
2228 } 2226 }
2229 if (!(d = kmalloc(sizeof(isdn_driver_t), GFP_KERNEL))) { 2227 if (!(d = kzalloc(sizeof(isdn_driver_t), GFP_KERNEL))) {
2230 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n"); 2228 printk(KERN_WARNING "register_isdn: Could not alloc driver-struct\n");
2231 return 0; 2229 return 0;
2232 } 2230 }
2233 memset((char *) d, 0, sizeof(isdn_driver_t));
2234 2231
2235 d->maxbufsize = i->maxbufsize; 2232 d->maxbufsize = i->maxbufsize;
2236 d->pktcount = 0; 2233 d->pktcount = 0;
diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
index 2e4daebfb7e0..c36c817578cb 100644
--- a/drivers/isdn/i4l/isdn_net.c
+++ b/drivers/isdn/i4l/isdn_net.c
@@ -2542,17 +2542,15 @@ isdn_net_new(char *name, struct net_device *master)
2542 printk(KERN_WARNING "isdn_net: interface %s already exists\n", name); 2542 printk(KERN_WARNING "isdn_net: interface %s already exists\n", name);
2543 return NULL; 2543 return NULL;
2544 } 2544 }
2545 if (!(netdev = (isdn_net_dev *) kmalloc(sizeof(isdn_net_dev), GFP_KERNEL))) { 2545 if (!(netdev = kzalloc(sizeof(isdn_net_dev), GFP_KERNEL))) {
2546 printk(KERN_WARNING "isdn_net: Could not allocate net-device\n"); 2546 printk(KERN_WARNING "isdn_net: Could not allocate net-device\n");
2547 return NULL; 2547 return NULL;
2548 } 2548 }
2549 memset(netdev, 0, sizeof(isdn_net_dev)); 2549 if (!(netdev->local = kzalloc(sizeof(isdn_net_local), GFP_KERNEL))) {
2550 if (!(netdev->local = (isdn_net_local *) kmalloc(sizeof(isdn_net_local), GFP_KERNEL))) {
2551 printk(KERN_WARNING "isdn_net: Could not allocate device locals\n"); 2550 printk(KERN_WARNING "isdn_net: Could not allocate device locals\n");
2552 kfree(netdev); 2551 kfree(netdev);
2553 return NULL; 2552 return NULL;
2554 } 2553 }
2555 memset(netdev->local, 0, sizeof(isdn_net_local));
2556 if (name == NULL) 2554 if (name == NULL)
2557 strcpy(netdev->local->name, " "); 2555 strcpy(netdev->local->name, " ");
2558 else 2556 else
diff --git a/drivers/isdn/i4l/isdn_ppp.c b/drivers/isdn/i4l/isdn_ppp.c
index 119412d6bd15..43811795b46b 100644
--- a/drivers/isdn/i4l/isdn_ppp.c
+++ b/drivers/isdn/i4l/isdn_ppp.c
@@ -667,7 +667,7 @@ isdn_ppp_poll(struct file *file, poll_table * wait)
667 667
668 if (is->debug & 0x2) 668 if (is->debug & 0x2)
669 printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n", 669 printk(KERN_DEBUG "isdn_ppp_poll: minor: %d\n",
670 iminor(file->f_dentry->d_inode)); 670 iminor(file->f_path.dentry->d_inode));
671 671
672 /* just registers wait_queue hook. This doesn't really wait. */ 672 /* just registers wait_queue hook. This doesn't really wait. */
673 poll_wait(file, &is->wq, wait); 673 poll_wait(file, &is->wq, wait);
@@ -876,14 +876,12 @@ isdn_ppp_init(void)
876#endif /* CONFIG_ISDN_MPP */ 876#endif /* CONFIG_ISDN_MPP */
877 877
878 for (i = 0; i < ISDN_MAX_CHANNELS; i++) { 878 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
879 if (!(ippp_table[i] = (struct ippp_struct *) 879 if (!(ippp_table[i] = kzalloc(sizeof(struct ippp_struct), GFP_KERNEL))) {
880 kmalloc(sizeof(struct ippp_struct), GFP_KERNEL))) {
881 printk(KERN_WARNING "isdn_ppp_init: Could not alloc ippp_table\n"); 880 printk(KERN_WARNING "isdn_ppp_init: Could not alloc ippp_table\n");
882 for (j = 0; j < i; j++) 881 for (j = 0; j < i; j++)
883 kfree(ippp_table[j]); 882 kfree(ippp_table[j]);
884 return -1; 883 return -1;
885 } 884 }
886 memset((char *) ippp_table[i], 0, sizeof(struct ippp_struct));
887 spin_lock_init(&ippp_table[i]->buflock); 885 spin_lock_init(&ippp_table[i]->buflock);
888 ippp_table[i]->state = 0; 886 ippp_table[i]->state = 0;
889 ippp_table[i]->first = ippp_table[i]->rq + NUM_RCV_BUFFS - 1; 887 ippp_table[i]->first = ippp_table[i]->rq + NUM_RCV_BUFFS - 1;
@@ -1529,10 +1527,8 @@ static int isdn_ppp_mp_bundle_array_init(void)
1529{ 1527{
1530 int i; 1528 int i;
1531 int sz = ISDN_MAX_CHANNELS*sizeof(ippp_bundle); 1529 int sz = ISDN_MAX_CHANNELS*sizeof(ippp_bundle);
1532 if( (isdn_ppp_bundle_arr = (ippp_bundle*)kmalloc(sz, 1530 if( (isdn_ppp_bundle_arr = kzalloc(sz, GFP_KERNEL)) == NULL )
1533 GFP_KERNEL)) == NULL )
1534 return -ENOMEM; 1531 return -ENOMEM;
1535 memset(isdn_ppp_bundle_arr, 0, sz);
1536 for( i = 0; i < ISDN_MAX_CHANNELS; i++ ) 1532 for( i = 0; i < ISDN_MAX_CHANNELS; i++ )
1537 spin_lock_init(&isdn_ppp_bundle_arr[i].lock); 1533 spin_lock_init(&isdn_ppp_bundle_arr[i].lock);
1538 return 0; 1534 return 0;
@@ -2246,13 +2242,12 @@ static void isdn_ppp_ccp_xmit_reset(struct ippp_struct *is, int proto,
2246static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is) 2242static struct ippp_ccp_reset *isdn_ppp_ccp_reset_alloc(struct ippp_struct *is)
2247{ 2243{
2248 struct ippp_ccp_reset *r; 2244 struct ippp_ccp_reset *r;
2249 r = kmalloc(sizeof(struct ippp_ccp_reset), GFP_KERNEL); 2245 r = kzalloc(sizeof(struct ippp_ccp_reset), GFP_KERNEL);
2250 if(!r) { 2246 if(!r) {
2251 printk(KERN_ERR "ippp_ccp: failed to allocate reset data" 2247 printk(KERN_ERR "ippp_ccp: failed to allocate reset data"
2252 " structure - no mem\n"); 2248 " structure - no mem\n");
2253 return NULL; 2249 return NULL;
2254 } 2250 }
2255 memset(r, 0, sizeof(struct ippp_ccp_reset));
2256 printk(KERN_DEBUG "ippp_ccp: allocated reset data structure %p\n", r); 2251 printk(KERN_DEBUG "ippp_ccp: allocated reset data structure %p\n", r);
2257 is->reset = r; 2252 is->reset = r;
2258 return r; 2253 return r;
@@ -2338,10 +2333,9 @@ static struct ippp_ccp_reset_state *isdn_ppp_ccp_reset_alloc_state(struct ippp_s
2338 id); 2333 id);
2339 return NULL; 2334 return NULL;
2340 } else { 2335 } else {
2341 rs = kmalloc(sizeof(struct ippp_ccp_reset_state), GFP_KERNEL); 2336 rs = kzalloc(sizeof(struct ippp_ccp_reset_state), GFP_KERNEL);
2342 if(!rs) 2337 if(!rs)
2343 return NULL; 2338 return NULL;
2344 memset(rs, 0, sizeof(struct ippp_ccp_reset_state));
2345 rs->state = CCPResetIdle; 2339 rs->state = CCPResetIdle;
2346 rs->is = is; 2340 rs->is = is;
2347 rs->id = id; 2341 rs->id = id;
@@ -2536,6 +2530,11 @@ static struct sk_buff *isdn_ppp_decompress(struct sk_buff *skb,struct ippp_struc
2536 rsparm.maxdlen = IPPP_RESET_MAXDATABYTES; 2530 rsparm.maxdlen = IPPP_RESET_MAXDATABYTES;
2537 2531
2538 skb_out = dev_alloc_skb(is->mru + PPP_HDRLEN); 2532 skb_out = dev_alloc_skb(is->mru + PPP_HDRLEN);
2533 if (!skb_out) {
2534 kfree_skb(skb);
2535 printk(KERN_ERR "ippp: decomp memory allocation failure\n");
2536 return NULL;
2537 }
2539 len = ipc->decompress(stat, skb, skb_out, &rsparm); 2538 len = ipc->decompress(stat, skb, skb_out, &rsparm);
2540 kfree_skb(skb); 2539 kfree_skb(skb);
2541 if (len <= 0) { 2540 if (len <= 0) {
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 2b91bb07fc7f..fc80afe555b9 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1464,7 +1464,7 @@ isdn_tty_ioctl(struct tty_struct *tty, struct file *file,
1464} 1464}
1465 1465
1466static void 1466static void
1467isdn_tty_set_termios(struct tty_struct *tty, struct termios *old_termios) 1467isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1468{ 1468{
1469 modem_info *info = (modem_info *) tty->driver_data; 1469 modem_info *info = (modem_info *) tty->driver_data;
1470 1470
diff --git a/drivers/isdn/i4l/isdn_v110.c b/drivers/isdn/i4l/isdn_v110.c
index 38619e8cd823..5484d3c38a57 100644
--- a/drivers/isdn/i4l/isdn_v110.c
+++ b/drivers/isdn/i4l/isdn_v110.c
@@ -92,9 +92,8 @@ isdn_v110_open(unsigned char key, int hdrlen, int maxsize)
92 int i; 92 int i;
93 isdn_v110_stream *v; 93 isdn_v110_stream *v;
94 94
95 if ((v = kmalloc(sizeof(isdn_v110_stream), GFP_ATOMIC)) == NULL) 95 if ((v = kzalloc(sizeof(isdn_v110_stream), GFP_ATOMIC)) == NULL)
96 return NULL; 96 return NULL;
97 memset(v, 0, sizeof(isdn_v110_stream));
98 v->key = key; 97 v->key = key;
99 v->nbits = 0; 98 v->nbits = 0;
100 for (i = 0; key & (1 << i); i++) 99 for (i = 0; key & (1 << i); i++)
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index 730bbd07ebc7..1e699bcaba0f 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -1519,12 +1519,11 @@ icn_initcard(int port, char *id)
1519 icn_card *card; 1519 icn_card *card;
1520 int i; 1520 int i;
1521 1521
1522 if (!(card = (icn_card *) kmalloc(sizeof(icn_card), GFP_KERNEL))) { 1522 if (!(card = kzalloc(sizeof(icn_card), GFP_KERNEL))) {
1523 printk(KERN_WARNING 1523 printk(KERN_WARNING
1524 "icn: (%s) Could not allocate card-struct.\n", id); 1524 "icn: (%s) Could not allocate card-struct.\n", id);
1525 return (icn_card *) 0; 1525 return (icn_card *) 0;
1526 } 1526 }
1527 memset((char *) card, 0, sizeof(icn_card));
1528 spin_lock_init(&card->lock); 1527 spin_lock_init(&card->lock);
1529 card->port = port; 1528 card->port = port;
1530 card->interface.owner = THIS_MODULE; 1529 card->interface.owner = THIS_MODULE;
diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index c3ae2edaf6fa..e3add27dd0e1 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -1430,12 +1430,11 @@ isdnloop_initcard(char *id)
1430 isdnloop_card *card; 1430 isdnloop_card *card;
1431 int i; 1431 int i;
1432 1432
1433 if (!(card = (isdnloop_card *) kmalloc(sizeof(isdnloop_card), GFP_KERNEL))) { 1433 if (!(card = kzalloc(sizeof(isdnloop_card), GFP_KERNEL))) {
1434 printk(KERN_WARNING 1434 printk(KERN_WARNING
1435 "isdnloop: (%s) Could not allocate card-struct.\n", id); 1435 "isdnloop: (%s) Could not allocate card-struct.\n", id);
1436 return (isdnloop_card *) 0; 1436 return (isdnloop_card *) 0;
1437 } 1437 }
1438 memset((char *) card, 0, sizeof(isdnloop_card));
1439 card->interface.owner = THIS_MODULE; 1438 card->interface.owner = THIS_MODULE;
1440 card->interface.channels = ISDNLOOP_BCH; 1439 card->interface.channels = ISDNLOOP_BCH;
1441 card->interface.hl_hdrlen = 1; /* scratch area for storing ack flag*/ 1440 card->interface.hl_hdrlen = 1; /* scratch area for storing ack flag*/
diff --git a/drivers/isdn/pcbit/drv.c b/drivers/isdn/pcbit/drv.c
index 1966f3410a13..11c1b0b6e390 100644
--- a/drivers/isdn/pcbit/drv.c
+++ b/drivers/isdn/pcbit/drv.c
@@ -73,14 +73,13 @@ int pcbit_init_dev(int board, int mem_base, int irq)
73 struct pcbit_dev *dev; 73 struct pcbit_dev *dev;
74 isdn_if *dev_if; 74 isdn_if *dev_if;
75 75
76 if ((dev=kmalloc(sizeof(struct pcbit_dev), GFP_KERNEL)) == NULL) 76 if ((dev=kzalloc(sizeof(struct pcbit_dev), GFP_KERNEL)) == NULL)
77 { 77 {
78 printk("pcbit_init: couldn't malloc pcbit_dev struct\n"); 78 printk("pcbit_init: couldn't malloc pcbit_dev struct\n");
79 return -ENOMEM; 79 return -ENOMEM;
80 } 80 }
81 81
82 dev_pcbit[board] = dev; 82 dev_pcbit[board] = dev;
83 memset(dev, 0, sizeof(struct pcbit_dev));
84 init_waitqueue_head(&dev->set_running_wq); 83 init_waitqueue_head(&dev->set_running_wq);
85 spin_lock_init(&dev->lock); 84 spin_lock_init(&dev->lock);
86 85
@@ -104,7 +103,7 @@ int pcbit_init_dev(int board, int mem_base, int irq)
104 return -EACCES; 103 return -EACCES;
105 } 104 }
106 105
107 dev->b1 = kmalloc(sizeof(struct pcbit_chan), GFP_KERNEL); 106 dev->b1 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL);
108 if (!dev->b1) { 107 if (!dev->b1) {
109 printk("pcbit_init: couldn't malloc pcbit_chan struct\n"); 108 printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
110 iounmap(dev->sh_mem); 109 iounmap(dev->sh_mem);
@@ -113,7 +112,7 @@ int pcbit_init_dev(int board, int mem_base, int irq)
113 return -ENOMEM; 112 return -ENOMEM;
114 } 113 }
115 114
116 dev->b2 = kmalloc(sizeof(struct pcbit_chan), GFP_KERNEL); 115 dev->b2 = kzalloc(sizeof(struct pcbit_chan), GFP_KERNEL);
117 if (!dev->b2) { 116 if (!dev->b2) {
118 printk("pcbit_init: couldn't malloc pcbit_chan struct\n"); 117 printk("pcbit_init: couldn't malloc pcbit_chan struct\n");
119 kfree(dev->b1); 118 kfree(dev->b1);
@@ -123,8 +122,6 @@ int pcbit_init_dev(int board, int mem_base, int irq)
123 return -ENOMEM; 122 return -ENOMEM;
124 } 123 }
125 124
126 memset(dev->b1, 0, sizeof(struct pcbit_chan));
127 memset(dev->b2, 0, sizeof(struct pcbit_chan));
128 dev->b2->id = 1; 125 dev->b2->id = 1;
129 126
130 INIT_WORK(&dev->qdelivery, pcbit_deliver); 127 INIT_WORK(&dev->qdelivery, pcbit_deliver);
diff --git a/drivers/isdn/pcbit/layer2.c b/drivers/isdn/pcbit/layer2.c
index 0c9f6df873fc..6ff85574e941 100644
--- a/drivers/isdn/pcbit/layer2.c
+++ b/drivers/isdn/pcbit/layer2.c
@@ -369,13 +369,12 @@ pcbit_receive(struct pcbit_dev *dev)
369 kfree(dev->read_frame); 369 kfree(dev->read_frame);
370 dev->read_frame = NULL; 370 dev->read_frame = NULL;
371 } 371 }
372 frame = kmalloc(sizeof(struct frame_buf), GFP_ATOMIC); 372 frame = kzalloc(sizeof(struct frame_buf), GFP_ATOMIC);
373 373
374 if (frame == NULL) { 374 if (frame == NULL) {
375 printk(KERN_WARNING "kmalloc failed\n"); 375 printk(KERN_WARNING "kmalloc failed\n");
376 return; 376 return;
377 } 377 }
378 memset(frame, 0, sizeof(struct frame_buf));
379 378
380 cpu = pcbit_readb(dev); 379 cpu = pcbit_readb(dev);
381 proc = pcbit_readb(dev); 380 proc = pcbit_readb(dev);
diff --git a/drivers/isdn/sc/init.c b/drivers/isdn/sc/init.c
index 06c9872e8c6a..150759a5cddf 100644
--- a/drivers/isdn/sc/init.c
+++ b/drivers/isdn/sc/init.c
@@ -271,14 +271,13 @@ static int __init sc_init(void)
271 * Horray! We found a board, Make sure we can register 271 * Horray! We found a board, Make sure we can register
272 * it with ISDN4Linux 272 * it with ISDN4Linux
273 */ 273 */
274 interface = kmalloc(sizeof(isdn_if), GFP_KERNEL); 274 interface = kzalloc(sizeof(isdn_if), GFP_KERNEL);
275 if (interface == NULL) { 275 if (interface == NULL) {
276 /* 276 /*
277 * Oops, can't malloc isdn_if 277 * Oops, can't malloc isdn_if
278 */ 278 */
279 continue; 279 continue;
280 } 280 }
281 memset(interface, 0, sizeof(isdn_if));
282 281
283 interface->owner = THIS_MODULE; 282 interface->owner = THIS_MODULE;
284 interface->hl_hdrlen = 0; 283 interface->hl_hdrlen = 0;
@@ -294,7 +293,7 @@ static int __init sc_init(void)
294 /* 293 /*
295 * Allocate the board structure 294 * Allocate the board structure
296 */ 295 */
297 sc_adapter[cinst] = kmalloc(sizeof(board), GFP_KERNEL); 296 sc_adapter[cinst] = kzalloc(sizeof(board), GFP_KERNEL);
298 if (sc_adapter[cinst] == NULL) { 297 if (sc_adapter[cinst] == NULL) {
299 /* 298 /*
300 * Oops, can't alloc memory for the board 299 * Oops, can't alloc memory for the board
@@ -302,7 +301,6 @@ static int __init sc_init(void)
302 kfree(interface); 301 kfree(interface);
303 continue; 302 continue;
304 } 303 }
305 memset(sc_adapter[cinst], 0, sizeof(board));
306 spin_lock_init(&sc_adapter[cinst]->lock); 304 spin_lock_init(&sc_adapter[cinst]->lock);
307 305
308 if(!register_isdn(interface)) { 306 if(!register_isdn(interface)) {
@@ -326,7 +324,7 @@ static int __init sc_init(void)
326 /* 324 /*
327 * Allocate channels status structures 325 * Allocate channels status structures
328 */ 326 */
329 sc_adapter[cinst]->channel = kmalloc(sizeof(bchan) * channels, GFP_KERNEL); 327 sc_adapter[cinst]->channel = kzalloc(sizeof(bchan) * channels, GFP_KERNEL);
330 if (sc_adapter[cinst]->channel == NULL) { 328 if (sc_adapter[cinst]->channel == NULL) {
331 /* 329 /*
332 * Oops, can't alloc memory for the channels 330 * Oops, can't alloc memory for the channels
@@ -336,7 +334,6 @@ static int __init sc_init(void)
336 kfree(sc_adapter[cinst]); 334 kfree(sc_adapter[cinst]);
337 continue; 335 continue;
338 } 336 }
339 memset(sc_adapter[cinst]->channel, 0, sizeof(bchan) * channels);
340 337
341 /* 338 /*
342 * Lock down the hardware resources 339 * Lock down the hardware resources
diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig
new file mode 100644
index 000000000000..36412e90f09b
--- /dev/null
+++ b/drivers/kvm/Kconfig
@@ -0,0 +1,33 @@
1#
2# KVM configuration
3#
4config KVM
5 tristate "Kernel-based Virtual Machine (KVM) support"
6 depends on X86 && EXPERIMENTAL
7 ---help---
8 Support hosting fully virtualized guest machines using hardware
9 virtualization extensions. You will need a fairly recent
10 processor equipped with virtualization extensions. You will also
11 need to select one or more of the processor modules below.
12
13 This module provides access to the hardware capabilities through
14 a character device node named /dev/kvm.
15
16 To compile this as a module, choose M here: the module
17 will be called kvm.
18
19 If unsure, say N.
20
21config KVM_INTEL
22 tristate "KVM for Intel processors support"
23 depends on KVM
24 ---help---
25 Provides support for KVM on Intel processors equipped with the VT
26 extensions.
27
28config KVM_AMD
29 tristate "KVM for AMD processors support"
30 depends on KVM
31 ---help---
32 Provides support for KVM on AMD processors equipped with the AMD-V
33 (SVM) extensions.
diff --git a/drivers/kvm/Makefile b/drivers/kvm/Makefile
new file mode 100644
index 000000000000..c0a789fa9d65
--- /dev/null
+++ b/drivers/kvm/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for Kernel-based Virtual Machine module
3#
4
5kvm-objs := kvm_main.o mmu.o x86_emulate.o
6obj-$(CONFIG_KVM) += kvm.o
7kvm-intel-objs = vmx.o
8obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
9kvm-amd-objs = svm.o
10obj-$(CONFIG_KVM_AMD) += kvm-amd.o
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
new file mode 100644
index 000000000000..5785d0870ab6
--- /dev/null
+++ b/drivers/kvm/kvm.h
@@ -0,0 +1,551 @@
1#ifndef __KVM_H
2#define __KVM_H
3
4/*
5 * This work is licensed under the terms of the GNU GPL, version 2. See
6 * the COPYING file in the top-level directory.
7 */
8
9#include <linux/types.h>
10#include <linux/list.h>
11#include <linux/mutex.h>
12#include <linux/spinlock.h>
13#include <linux/mm.h>
14
15#include "vmx.h"
16#include <linux/kvm.h>
17
18#define CR0_PE_MASK (1ULL << 0)
19#define CR0_TS_MASK (1ULL << 3)
20#define CR0_NE_MASK (1ULL << 5)
21#define CR0_WP_MASK (1ULL << 16)
22#define CR0_NW_MASK (1ULL << 29)
23#define CR0_CD_MASK (1ULL << 30)
24#define CR0_PG_MASK (1ULL << 31)
25
26#define CR3_WPT_MASK (1ULL << 3)
27#define CR3_PCD_MASK (1ULL << 4)
28
29#define CR3_RESEVED_BITS 0x07ULL
30#define CR3_L_MODE_RESEVED_BITS (~((1ULL << 40) - 1) | 0x0fe7ULL)
31#define CR3_FLAGS_MASK ((1ULL << 5) - 1)
32
33#define CR4_VME_MASK (1ULL << 0)
34#define CR4_PSE_MASK (1ULL << 4)
35#define CR4_PAE_MASK (1ULL << 5)
36#define CR4_PGE_MASK (1ULL << 7)
37#define CR4_VMXE_MASK (1ULL << 13)
38
39#define KVM_GUEST_CR0_MASK \
40 (CR0_PG_MASK | CR0_PE_MASK | CR0_WP_MASK | CR0_NE_MASK \
41 | CR0_NW_MASK | CR0_CD_MASK)
42#define KVM_VM_CR0_ALWAYS_ON \
43 (CR0_PG_MASK | CR0_PE_MASK | CR0_WP_MASK | CR0_NE_MASK)
44#define KVM_GUEST_CR4_MASK \
45 (CR4_PSE_MASK | CR4_PAE_MASK | CR4_PGE_MASK | CR4_VMXE_MASK | CR4_VME_MASK)
46#define KVM_PMODE_VM_CR4_ALWAYS_ON (CR4_VMXE_MASK | CR4_PAE_MASK)
47#define KVM_RMODE_VM_CR4_ALWAYS_ON (CR4_VMXE_MASK | CR4_PAE_MASK | CR4_VME_MASK)
48
49#define INVALID_PAGE (~(hpa_t)0)
50#define UNMAPPED_GVA (~(gpa_t)0)
51
52#define KVM_MAX_VCPUS 1
53#define KVM_MEMORY_SLOTS 4
54#define KVM_NUM_MMU_PAGES 256
55
56#define FX_IMAGE_SIZE 512
57#define FX_IMAGE_ALIGN 16
58#define FX_BUF_SIZE (2 * FX_IMAGE_SIZE + FX_IMAGE_ALIGN)
59
60#define DE_VECTOR 0
61#define DF_VECTOR 8
62#define TS_VECTOR 10
63#define NP_VECTOR 11
64#define SS_VECTOR 12
65#define GP_VECTOR 13
66#define PF_VECTOR 14
67
68#define SELECTOR_TI_MASK (1 << 2)
69#define SELECTOR_RPL_MASK 0x03
70
71#define IOPL_SHIFT 12
72
73/*
74 * Address types:
75 *
76 * gva - guest virtual address
77 * gpa - guest physical address
78 * gfn - guest frame number
79 * hva - host virtual address
80 * hpa - host physical address
81 * hfn - host frame number
82 */
83
84typedef unsigned long gva_t;
85typedef u64 gpa_t;
86typedef unsigned long gfn_t;
87
88typedef unsigned long hva_t;
89typedef u64 hpa_t;
90typedef unsigned long hfn_t;
91
92struct kvm_mmu_page {
93 struct list_head link;
94 hpa_t page_hpa;
95 unsigned long slot_bitmap; /* One bit set per slot which has memory
96 * in this shadow page.
97 */
98 int global; /* Set if all ptes in this page are global */
99 u64 *parent_pte;
100};
101
102struct vmcs {
103 u32 revision_id;
104 u32 abort;
105 char data[0];
106};
107
108#define vmx_msr_entry kvm_msr_entry
109
110struct kvm_vcpu;
111
112/*
113 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
114 * 32-bit). The kvm_mmu structure abstracts the details of the current mmu
115 * mode.
116 */
117struct kvm_mmu {
118 void (*new_cr3)(struct kvm_vcpu *vcpu);
119 int (*page_fault)(struct kvm_vcpu *vcpu, gva_t gva, u32 err);
120 void (*inval_page)(struct kvm_vcpu *vcpu, gva_t gva);
121 void (*free)(struct kvm_vcpu *vcpu);
122 gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t gva);
123 hpa_t root_hpa;
124 int root_level;
125 int shadow_root_level;
126};
127
128struct kvm_guest_debug {
129 int enabled;
130 unsigned long bp[4];
131 int singlestep;
132};
133
134enum {
135 VCPU_REGS_RAX = 0,
136 VCPU_REGS_RCX = 1,
137 VCPU_REGS_RDX = 2,
138 VCPU_REGS_RBX = 3,
139 VCPU_REGS_RSP = 4,
140 VCPU_REGS_RBP = 5,
141 VCPU_REGS_RSI = 6,
142 VCPU_REGS_RDI = 7,
143#ifdef __x86_64__
144 VCPU_REGS_R8 = 8,
145 VCPU_REGS_R9 = 9,
146 VCPU_REGS_R10 = 10,
147 VCPU_REGS_R11 = 11,
148 VCPU_REGS_R12 = 12,
149 VCPU_REGS_R13 = 13,
150 VCPU_REGS_R14 = 14,
151 VCPU_REGS_R15 = 15,
152#endif
153 NR_VCPU_REGS
154};
155
156enum {
157 VCPU_SREG_CS,
158 VCPU_SREG_DS,
159 VCPU_SREG_ES,
160 VCPU_SREG_FS,
161 VCPU_SREG_GS,
162 VCPU_SREG_SS,
163 VCPU_SREG_TR,
164 VCPU_SREG_LDTR,
165};
166
167struct kvm_vcpu {
168 struct kvm *kvm;
169 union {
170 struct vmcs *vmcs;
171 struct vcpu_svm *svm;
172 };
173 struct mutex mutex;
174 int cpu;
175 int launched;
176 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
177#define NR_IRQ_WORDS KVM_IRQ_BITMAP_SIZE(unsigned long)
178 unsigned long irq_pending[NR_IRQ_WORDS];
179 unsigned long regs[NR_VCPU_REGS]; /* for rsp: vcpu_load_rsp_rip() */
180 unsigned long rip; /* needs vcpu_load_rsp_rip() */
181
182 unsigned long cr0;
183 unsigned long cr2;
184 unsigned long cr3;
185 unsigned long cr4;
186 unsigned long cr8;
187 u64 shadow_efer;
188 u64 apic_base;
189 int nmsrs;
190 struct vmx_msr_entry *guest_msrs;
191 struct vmx_msr_entry *host_msrs;
192
193 struct list_head free_pages;
194 struct kvm_mmu_page page_header_buf[KVM_NUM_MMU_PAGES];
195 struct kvm_mmu mmu;
196
197 struct kvm_guest_debug guest_debug;
198
199 char fx_buf[FX_BUF_SIZE];
200 char *host_fx_image;
201 char *guest_fx_image;
202
203 int mmio_needed;
204 int mmio_read_completed;
205 int mmio_is_write;
206 int mmio_size;
207 unsigned char mmio_data[8];
208 gpa_t mmio_phys_addr;
209
210 struct {
211 int active;
212 u8 save_iopl;
213 struct kvm_save_segment {
214 u16 selector;
215 unsigned long base;
216 u32 limit;
217 u32 ar;
218 } tr, es, ds, fs, gs;
219 } rmode;
220};
221
222struct kvm_memory_slot {
223 gfn_t base_gfn;
224 unsigned long npages;
225 unsigned long flags;
226 struct page **phys_mem;
227 unsigned long *dirty_bitmap;
228};
229
230struct kvm {
231 spinlock_t lock; /* protects everything except vcpus */
232 int nmemslots;
233 struct kvm_memory_slot memslots[KVM_MEMORY_SLOTS];
234 struct list_head active_mmu_pages;
235 struct kvm_vcpu vcpus[KVM_MAX_VCPUS];
236 int memory_config_version;
237 int busy;
238};
239
240struct kvm_stat {
241 u32 pf_fixed;
242 u32 pf_guest;
243 u32 tlb_flush;
244 u32 invlpg;
245
246 u32 exits;
247 u32 io_exits;
248 u32 mmio_exits;
249 u32 signal_exits;
250 u32 irq_exits;
251};
252
253struct descriptor_table {
254 u16 limit;
255 unsigned long base;
256} __attribute__((packed));
257
258struct kvm_arch_ops {
259 int (*cpu_has_kvm_support)(void); /* __init */
260 int (*disabled_by_bios)(void); /* __init */
261 void (*hardware_enable)(void *dummy); /* __init */
262 void (*hardware_disable)(void *dummy);
263 int (*hardware_setup)(void); /* __init */
264 void (*hardware_unsetup)(void); /* __exit */
265
266 int (*vcpu_create)(struct kvm_vcpu *vcpu);
267 void (*vcpu_free)(struct kvm_vcpu *vcpu);
268
269 struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu);
270 void (*vcpu_put)(struct kvm_vcpu *vcpu);
271
272 int (*set_guest_debug)(struct kvm_vcpu *vcpu,
273 struct kvm_debug_guest *dbg);
274 int (*get_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata);
275 int (*set_msr)(struct kvm_vcpu *vcpu, u32 msr_index, u64 data);
276 u64 (*get_segment_base)(struct kvm_vcpu *vcpu, int seg);
277 void (*get_segment)(struct kvm_vcpu *vcpu,
278 struct kvm_segment *var, int seg);
279 void (*set_segment)(struct kvm_vcpu *vcpu,
280 struct kvm_segment *var, int seg);
281 int (*is_long_mode)(struct kvm_vcpu *vcpu);
282 void (*get_cs_db_l_bits)(struct kvm_vcpu *vcpu, int *db, int *l);
283 void (*set_cr0)(struct kvm_vcpu *vcpu, unsigned long cr0);
284 void (*set_cr0_no_modeswitch)(struct kvm_vcpu *vcpu,
285 unsigned long cr0);
286 void (*set_cr3)(struct kvm_vcpu *vcpu, unsigned long cr3);
287 void (*set_cr4)(struct kvm_vcpu *vcpu, unsigned long cr4);
288 void (*set_efer)(struct kvm_vcpu *vcpu, u64 efer);
289 void (*get_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
290 void (*set_idt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
291 void (*get_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
292 void (*set_gdt)(struct kvm_vcpu *vcpu, struct descriptor_table *dt);
293 unsigned long (*get_dr)(struct kvm_vcpu *vcpu, int dr);
294 void (*set_dr)(struct kvm_vcpu *vcpu, int dr, unsigned long value,
295 int *exception);
296 void (*cache_regs)(struct kvm_vcpu *vcpu);
297 void (*decache_regs)(struct kvm_vcpu *vcpu);
298 unsigned long (*get_rflags)(struct kvm_vcpu *vcpu);
299 void (*set_rflags)(struct kvm_vcpu *vcpu, unsigned long rflags);
300
301 void (*invlpg)(struct kvm_vcpu *vcpu, gva_t addr);
302 void (*tlb_flush)(struct kvm_vcpu *vcpu);
303 void (*inject_page_fault)(struct kvm_vcpu *vcpu,
304 unsigned long addr, u32 err_code);
305
306 void (*inject_gp)(struct kvm_vcpu *vcpu, unsigned err_code);
307
308 int (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);
309 int (*vcpu_setup)(struct kvm_vcpu *vcpu);
310 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
311};
312
313extern struct kvm_stat kvm_stat;
314extern struct kvm_arch_ops *kvm_arch_ops;
315
316#define kvm_printf(kvm, fmt ...) printk(KERN_DEBUG fmt)
317#define vcpu_printf(vcpu, fmt...) kvm_printf(vcpu->kvm, fmt)
318
319int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module);
320void kvm_exit_arch(void);
321
322void kvm_mmu_destroy(struct kvm_vcpu *vcpu);
323int kvm_mmu_init(struct kvm_vcpu *vcpu);
324
325int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
326void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
327
328hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa);
329#define HPA_MSB ((sizeof(hpa_t) * 8) - 1)
330#define HPA_ERR_MASK ((hpa_t)1 << HPA_MSB)
331static inline int is_error_hpa(hpa_t hpa) { return hpa >> HPA_MSB; }
332hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva);
333
334void kvm_emulator_want_group7_invlpg(void);
335
336extern hpa_t bad_page_address;
337
338static inline struct page *gfn_to_page(struct kvm_memory_slot *slot, gfn_t gfn)
339{
340 return slot->phys_mem[gfn - slot->base_gfn];
341}
342
343struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn);
344void mark_page_dirty(struct kvm *kvm, gfn_t gfn);
345
346enum emulation_result {
347 EMULATE_DONE, /* no further processing */
348 EMULATE_DO_MMIO, /* kvm_run filled with mmio request */
349 EMULATE_FAIL, /* can't emulate this instruction */
350};
351
352int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run,
353 unsigned long cr2, u16 error_code);
354void realmode_lgdt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
355void realmode_lidt(struct kvm_vcpu *vcpu, u16 size, unsigned long address);
356void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
357 unsigned long *rflags);
358
359unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr);
360void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long value,
361 unsigned long *rflags);
362
363struct x86_emulate_ctxt;
364
365int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address);
366int emulate_clts(struct kvm_vcpu *vcpu);
367int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr,
368 unsigned long *dest);
369int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr,
370 unsigned long value);
371
372void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0);
373void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr0);
374void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr0);
375void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr0);
376void lmsw(struct kvm_vcpu *vcpu, unsigned long msw);
377
378#ifdef __x86_64__
379void set_efer(struct kvm_vcpu *vcpu, u64 efer);
380#endif
381
382void fx_init(struct kvm_vcpu *vcpu);
383
384void load_msrs(struct vmx_msr_entry *e, int n);
385void save_msrs(struct vmx_msr_entry *e, int n);
386void kvm_resched(struct kvm_vcpu *vcpu);
387
388int kvm_read_guest(struct kvm_vcpu *vcpu,
389 gva_t addr,
390 unsigned long size,
391 void *dest);
392
393int kvm_write_guest(struct kvm_vcpu *vcpu,
394 gva_t addr,
395 unsigned long size,
396 void *data);
397
398unsigned long segment_base(u16 selector);
399
400static inline struct page *_gfn_to_page(struct kvm *kvm, gfn_t gfn)
401{
402 struct kvm_memory_slot *slot = gfn_to_memslot(kvm, gfn);
403 return (slot) ? slot->phys_mem[gfn - slot->base_gfn] : NULL;
404}
405
406static inline int is_pae(struct kvm_vcpu *vcpu)
407{
408 return vcpu->cr4 & CR4_PAE_MASK;
409}
410
411static inline int is_pse(struct kvm_vcpu *vcpu)
412{
413 return vcpu->cr4 & CR4_PSE_MASK;
414}
415
416static inline int is_paging(struct kvm_vcpu *vcpu)
417{
418 return vcpu->cr0 & CR0_PG_MASK;
419}
420
421static inline int memslot_id(struct kvm *kvm, struct kvm_memory_slot *slot)
422{
423 return slot - kvm->memslots;
424}
425
426static inline struct kvm_mmu_page *page_header(hpa_t shadow_page)
427{
428 struct page *page = pfn_to_page(shadow_page >> PAGE_SHIFT);
429
430 return (struct kvm_mmu_page *)page->private;
431}
432
433static inline u16 read_fs(void)
434{
435 u16 seg;
436 asm ("mov %%fs, %0" : "=g"(seg));
437 return seg;
438}
439
440static inline u16 read_gs(void)
441{
442 u16 seg;
443 asm ("mov %%gs, %0" : "=g"(seg));
444 return seg;
445}
446
447static inline u16 read_ldt(void)
448{
449 u16 ldt;
450 asm ("sldt %0" : "=g"(ldt));
451 return ldt;
452}
453
454static inline void load_fs(u16 sel)
455{
456 asm ("mov %0, %%fs" : : "rm"(sel));
457}
458
459static inline void load_gs(u16 sel)
460{
461 asm ("mov %0, %%gs" : : "rm"(sel));
462}
463
464#ifndef load_ldt
465static inline void load_ldt(u16 sel)
466{
467 asm ("lldt %0" : : "g"(sel));
468}
469#endif
470
471static inline void get_idt(struct descriptor_table *table)
472{
473 asm ("sidt %0" : "=m"(*table));
474}
475
476static inline void get_gdt(struct descriptor_table *table)
477{
478 asm ("sgdt %0" : "=m"(*table));
479}
480
481static inline unsigned long read_tr_base(void)
482{
483 u16 tr;
484 asm ("str %0" : "=g"(tr));
485 return segment_base(tr);
486}
487
488#ifdef __x86_64__
489static inline unsigned long read_msr(unsigned long msr)
490{
491 u64 value;
492
493 rdmsrl(msr, value);
494 return value;
495}
496#endif
497
498static inline void fx_save(void *image)
499{
500 asm ("fxsave (%0)":: "r" (image));
501}
502
503static inline void fx_restore(void *image)
504{
505 asm ("fxrstor (%0)":: "r" (image));
506}
507
508static inline void fpu_init(void)
509{
510 asm ("finit");
511}
512
513static inline u32 get_rdx_init_val(void)
514{
515 return 0x600; /* P6 family */
516}
517
518#define ASM_VMX_VMCLEAR_RAX ".byte 0x66, 0x0f, 0xc7, 0x30"
519#define ASM_VMX_VMLAUNCH ".byte 0x0f, 0x01, 0xc2"
520#define ASM_VMX_VMRESUME ".byte 0x0f, 0x01, 0xc3"
521#define ASM_VMX_VMPTRLD_RAX ".byte 0x0f, 0xc7, 0x30"
522#define ASM_VMX_VMREAD_RDX_RAX ".byte 0x0f, 0x78, 0xd0"
523#define ASM_VMX_VMWRITE_RAX_RDX ".byte 0x0f, 0x79, 0xd0"
524#define ASM_VMX_VMWRITE_RSP_RDX ".byte 0x0f, 0x79, 0xd4"
525#define ASM_VMX_VMXOFF ".byte 0x0f, 0x01, 0xc4"
526#define ASM_VMX_VMXON_RAX ".byte 0xf3, 0x0f, 0xc7, 0x30"
527
528#define MSR_IA32_TIME_STAMP_COUNTER 0x010
529
530#define TSS_IOPB_BASE_OFFSET 0x66
531#define TSS_BASE_SIZE 0x68
532#define TSS_IOPB_SIZE (65536 / 8)
533#define TSS_REDIRECTION_SIZE (256 / 8)
534#define RMODE_TSS_SIZE (TSS_BASE_SIZE + TSS_REDIRECTION_SIZE + TSS_IOPB_SIZE + 1)
535
536#ifdef __x86_64__
537
538/*
539 * When emulating 32-bit mode, cr3 is only 32 bits even on x86_64. Therefore
540 * we need to allocate shadow page tables in the first 4GB of memory, which
541 * happens to fit the DMA32 zone.
542 */
543#define GFP_KVM_MMU (GFP_KERNEL | __GFP_DMA32)
544
545#else
546
547#define GFP_KVM_MMU GFP_KERNEL
548
549#endif
550
551#endif
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
new file mode 100644
index 000000000000..b6b8a41b5ec8
--- /dev/null
+++ b/drivers/kvm/kvm_main.c
@@ -0,0 +1,1935 @@
1/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This module enables machines with Intel VT-x extensions to run virtual
5 * machines without emulation or binary translation.
6 *
7 * Copyright (C) 2006 Qumranet, Inc.
8 *
9 * Authors:
10 * Avi Kivity <avi@qumranet.com>
11 * Yaniv Kamay <yaniv@qumranet.com>
12 *
13 * This work is licensed under the terms of the GNU GPL, version 2. See
14 * the COPYING file in the top-level directory.
15 *
16 */
17
18#include "kvm.h"
19
20#include <linux/kvm.h>
21#include <linux/module.h>
22#include <linux/errno.h>
23#include <asm/processor.h>
24#include <linux/percpu.h>
25#include <linux/gfp.h>
26#include <asm/msr.h>
27#include <linux/mm.h>
28#include <linux/miscdevice.h>
29#include <linux/vmalloc.h>
30#include <asm/uaccess.h>
31#include <linux/reboot.h>
32#include <asm/io.h>
33#include <linux/debugfs.h>
34#include <linux/highmem.h>
35#include <linux/file.h>
36#include <asm/desc.h>
37
38#include "x86_emulate.h"
39#include "segment_descriptor.h"
40
41MODULE_AUTHOR("Qumranet");
42MODULE_LICENSE("GPL");
43
44struct kvm_arch_ops *kvm_arch_ops;
45struct kvm_stat kvm_stat;
46EXPORT_SYMBOL_GPL(kvm_stat);
47
48static struct kvm_stats_debugfs_item {
49 const char *name;
50 u32 *data;
51 struct dentry *dentry;
52} debugfs_entries[] = {
53 { "pf_fixed", &kvm_stat.pf_fixed },
54 { "pf_guest", &kvm_stat.pf_guest },
55 { "tlb_flush", &kvm_stat.tlb_flush },
56 { "invlpg", &kvm_stat.invlpg },
57 { "exits", &kvm_stat.exits },
58 { "io_exits", &kvm_stat.io_exits },
59 { "mmio_exits", &kvm_stat.mmio_exits },
60 { "signal_exits", &kvm_stat.signal_exits },
61 { "irq_exits", &kvm_stat.irq_exits },
62 { 0, 0 }
63};
64
65static struct dentry *debugfs_dir;
66
67#define MAX_IO_MSRS 256
68
69#define CR0_RESEVED_BITS 0xffffffff1ffaffc0ULL
70#define LMSW_GUEST_MASK 0x0eULL
71#define CR4_RESEVED_BITS (~((1ULL << 11) - 1))
72#define CR8_RESEVED_BITS (~0x0fULL)
73#define EFER_RESERVED_BITS 0xfffffffffffff2fe
74
75struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr)
76{
77 int i;
78
79 for (i = 0; i < vcpu->nmsrs; ++i)
80 if (vcpu->guest_msrs[i].index == msr)
81 return &vcpu->guest_msrs[i];
82 return 0;
83}
84EXPORT_SYMBOL_GPL(find_msr_entry);
85
86#ifdef __x86_64__
87// LDT or TSS descriptor in the GDT. 16 bytes.
88struct segment_descriptor_64 {
89 struct segment_descriptor s;
90 u32 base_higher;
91 u32 pad_zero;
92};
93
94#endif
95
96unsigned long segment_base(u16 selector)
97{
98 struct descriptor_table gdt;
99 struct segment_descriptor *d;
100 unsigned long table_base;
101 typedef unsigned long ul;
102 unsigned long v;
103
104 if (selector == 0)
105 return 0;
106
107 asm ("sgdt %0" : "=m"(gdt));
108 table_base = gdt.base;
109
110 if (selector & 4) { /* from ldt */
111 u16 ldt_selector;
112
113 asm ("sldt %0" : "=g"(ldt_selector));
114 table_base = segment_base(ldt_selector);
115 }
116 d = (struct segment_descriptor *)(table_base + (selector & ~7));
117 v = d->base_low | ((ul)d->base_mid << 16) | ((ul)d->base_high << 24);
118#ifdef __x86_64__
119 if (d->system == 0
120 && (d->type == 2 || d->type == 9 || d->type == 11))
121 v |= ((ul)((struct segment_descriptor_64 *)d)->base_higher) << 32;
122#endif
123 return v;
124}
125EXPORT_SYMBOL_GPL(segment_base);
126
127int kvm_read_guest(struct kvm_vcpu *vcpu,
128 gva_t addr,
129 unsigned long size,
130 void *dest)
131{
132 unsigned char *host_buf = dest;
133 unsigned long req_size = size;
134
135 while (size) {
136 hpa_t paddr;
137 unsigned now;
138 unsigned offset;
139 hva_t guest_buf;
140
141 paddr = gva_to_hpa(vcpu, addr);
142
143 if (is_error_hpa(paddr))
144 break;
145
146 guest_buf = (hva_t)kmap_atomic(
147 pfn_to_page(paddr >> PAGE_SHIFT),
148 KM_USER0);
149 offset = addr & ~PAGE_MASK;
150 guest_buf |= offset;
151 now = min(size, PAGE_SIZE - offset);
152 memcpy(host_buf, (void*)guest_buf, now);
153 host_buf += now;
154 addr += now;
155 size -= now;
156 kunmap_atomic((void *)(guest_buf & PAGE_MASK), KM_USER0);
157 }
158 return req_size - size;
159}
160EXPORT_SYMBOL_GPL(kvm_read_guest);
161
162int kvm_write_guest(struct kvm_vcpu *vcpu,
163 gva_t addr,
164 unsigned long size,
165 void *data)
166{
167 unsigned char *host_buf = data;
168 unsigned long req_size = size;
169
170 while (size) {
171 hpa_t paddr;
172 unsigned now;
173 unsigned offset;
174 hva_t guest_buf;
175
176 paddr = gva_to_hpa(vcpu, addr);
177
178 if (is_error_hpa(paddr))
179 break;
180
181 guest_buf = (hva_t)kmap_atomic(
182 pfn_to_page(paddr >> PAGE_SHIFT), KM_USER0);
183 offset = addr & ~PAGE_MASK;
184 guest_buf |= offset;
185 now = min(size, PAGE_SIZE - offset);
186 memcpy((void*)guest_buf, host_buf, now);
187 host_buf += now;
188 addr += now;
189 size -= now;
190 kunmap_atomic((void *)(guest_buf & PAGE_MASK), KM_USER0);
191 }
192 return req_size - size;
193}
194EXPORT_SYMBOL_GPL(kvm_write_guest);
195
196static int vcpu_slot(struct kvm_vcpu *vcpu)
197{
198 return vcpu - vcpu->kvm->vcpus;
199}
200
201/*
202 * Switches to specified vcpu, until a matching vcpu_put()
203 */
204static struct kvm_vcpu *vcpu_load(struct kvm *kvm, int vcpu_slot)
205{
206 struct kvm_vcpu *vcpu = &kvm->vcpus[vcpu_slot];
207
208 mutex_lock(&vcpu->mutex);
209 if (unlikely(!vcpu->vmcs)) {
210 mutex_unlock(&vcpu->mutex);
211 return 0;
212 }
213 return kvm_arch_ops->vcpu_load(vcpu);
214}
215
216static void vcpu_put(struct kvm_vcpu *vcpu)
217{
218 kvm_arch_ops->vcpu_put(vcpu);
219 put_cpu();
220 mutex_unlock(&vcpu->mutex);
221}
222
223static int kvm_dev_open(struct inode *inode, struct file *filp)
224{
225 struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
226 int i;
227
228 if (!kvm)
229 return -ENOMEM;
230
231 spin_lock_init(&kvm->lock);
232 INIT_LIST_HEAD(&kvm->active_mmu_pages);
233 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
234 struct kvm_vcpu *vcpu = &kvm->vcpus[i];
235
236 mutex_init(&vcpu->mutex);
237 vcpu->mmu.root_hpa = INVALID_PAGE;
238 INIT_LIST_HEAD(&vcpu->free_pages);
239 }
240 filp->private_data = kvm;
241 return 0;
242}
243
244/*
245 * Free any memory in @free but not in @dont.
246 */
247static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
248 struct kvm_memory_slot *dont)
249{
250 int i;
251
252 if (!dont || free->phys_mem != dont->phys_mem)
253 if (free->phys_mem) {
254 for (i = 0; i < free->npages; ++i)
255 __free_page(free->phys_mem[i]);
256 vfree(free->phys_mem);
257 }
258
259 if (!dont || free->dirty_bitmap != dont->dirty_bitmap)
260 vfree(free->dirty_bitmap);
261
262 free->phys_mem = 0;
263 free->npages = 0;
264 free->dirty_bitmap = 0;
265}
266
267static void kvm_free_physmem(struct kvm *kvm)
268{
269 int i;
270
271 for (i = 0; i < kvm->nmemslots; ++i)
272 kvm_free_physmem_slot(&kvm->memslots[i], 0);
273}
274
275static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
276{
277 kvm_arch_ops->vcpu_free(vcpu);
278 kvm_mmu_destroy(vcpu);
279}
280
281static void kvm_free_vcpus(struct kvm *kvm)
282{
283 unsigned int i;
284
285 for (i = 0; i < KVM_MAX_VCPUS; ++i)
286 kvm_free_vcpu(&kvm->vcpus[i]);
287}
288
289static int kvm_dev_release(struct inode *inode, struct file *filp)
290{
291 struct kvm *kvm = filp->private_data;
292
293 kvm_free_vcpus(kvm);
294 kvm_free_physmem(kvm);
295 kfree(kvm);
296 return 0;
297}
298
299static void inject_gp(struct kvm_vcpu *vcpu)
300{
301 kvm_arch_ops->inject_gp(vcpu, 0);
302}
303
304static int pdptrs_have_reserved_bits_set(struct kvm_vcpu *vcpu,
305 unsigned long cr3)
306{
307 gfn_t pdpt_gfn = cr3 >> PAGE_SHIFT;
308 unsigned offset = (cr3 & (PAGE_SIZE-1)) >> 5;
309 int i;
310 u64 pdpte;
311 u64 *pdpt;
312 struct kvm_memory_slot *memslot;
313
314 spin_lock(&vcpu->kvm->lock);
315 memslot = gfn_to_memslot(vcpu->kvm, pdpt_gfn);
316 /* FIXME: !memslot - emulate? 0xff? */
317 pdpt = kmap_atomic(gfn_to_page(memslot, pdpt_gfn), KM_USER0);
318
319 for (i = 0; i < 4; ++i) {
320 pdpte = pdpt[offset + i];
321 if ((pdpte & 1) && (pdpte & 0xfffffff0000001e6ull))
322 break;
323 }
324
325 kunmap_atomic(pdpt, KM_USER0);
326 spin_unlock(&vcpu->kvm->lock);
327
328 return i != 4;
329}
330
331void set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
332{
333 if (cr0 & CR0_RESEVED_BITS) {
334 printk(KERN_DEBUG "set_cr0: 0x%lx #GP, reserved bits 0x%lx\n",
335 cr0, vcpu->cr0);
336 inject_gp(vcpu);
337 return;
338 }
339
340 if ((cr0 & CR0_NW_MASK) && !(cr0 & CR0_CD_MASK)) {
341 printk(KERN_DEBUG "set_cr0: #GP, CD == 0 && NW == 1\n");
342 inject_gp(vcpu);
343 return;
344 }
345
346 if ((cr0 & CR0_PG_MASK) && !(cr0 & CR0_PE_MASK)) {
347 printk(KERN_DEBUG "set_cr0: #GP, set PG flag "
348 "and a clear PE flag\n");
349 inject_gp(vcpu);
350 return;
351 }
352
353 if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK)) {
354#ifdef __x86_64__
355 if ((vcpu->shadow_efer & EFER_LME)) {
356 int cs_db, cs_l;
357
358 if (!is_pae(vcpu)) {
359 printk(KERN_DEBUG "set_cr0: #GP, start paging "
360 "in long mode while PAE is disabled\n");
361 inject_gp(vcpu);
362 return;
363 }
364 kvm_arch_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
365 if (cs_l) {
366 printk(KERN_DEBUG "set_cr0: #GP, start paging "
367 "in long mode while CS.L == 1\n");
368 inject_gp(vcpu);
369 return;
370
371 }
372 } else
373#endif
374 if (is_pae(vcpu) &&
375 pdptrs_have_reserved_bits_set(vcpu, vcpu->cr3)) {
376 printk(KERN_DEBUG "set_cr0: #GP, pdptrs "
377 "reserved bits\n");
378 inject_gp(vcpu);
379 return;
380 }
381
382 }
383
384 kvm_arch_ops->set_cr0(vcpu, cr0);
385 vcpu->cr0 = cr0;
386
387 spin_lock(&vcpu->kvm->lock);
388 kvm_mmu_reset_context(vcpu);
389 spin_unlock(&vcpu->kvm->lock);
390 return;
391}
392EXPORT_SYMBOL_GPL(set_cr0);
393
394void lmsw(struct kvm_vcpu *vcpu, unsigned long msw)
395{
396 set_cr0(vcpu, (vcpu->cr0 & ~0x0ful) | (msw & 0x0f));
397}
398EXPORT_SYMBOL_GPL(lmsw);
399
400void set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
401{
402 if (cr4 & CR4_RESEVED_BITS) {
403 printk(KERN_DEBUG "set_cr4: #GP, reserved bits\n");
404 inject_gp(vcpu);
405 return;
406 }
407
408 if (kvm_arch_ops->is_long_mode(vcpu)) {
409 if (!(cr4 & CR4_PAE_MASK)) {
410 printk(KERN_DEBUG "set_cr4: #GP, clearing PAE while "
411 "in long mode\n");
412 inject_gp(vcpu);
413 return;
414 }
415 } else if (is_paging(vcpu) && !is_pae(vcpu) && (cr4 & CR4_PAE_MASK)
416 && pdptrs_have_reserved_bits_set(vcpu, vcpu->cr3)) {
417 printk(KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n");
418 inject_gp(vcpu);
419 }
420
421 if (cr4 & CR4_VMXE_MASK) {
422 printk(KERN_DEBUG "set_cr4: #GP, setting VMXE\n");
423 inject_gp(vcpu);
424 return;
425 }
426 kvm_arch_ops->set_cr4(vcpu, cr4);
427 spin_lock(&vcpu->kvm->lock);
428 kvm_mmu_reset_context(vcpu);
429 spin_unlock(&vcpu->kvm->lock);
430}
431EXPORT_SYMBOL_GPL(set_cr4);
432
433void set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
434{
435 if (kvm_arch_ops->is_long_mode(vcpu)) {
436 if ( cr3 & CR3_L_MODE_RESEVED_BITS) {
437 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
438 inject_gp(vcpu);
439 return;
440 }
441 } else {
442 if (cr3 & CR3_RESEVED_BITS) {
443 printk(KERN_DEBUG "set_cr3: #GP, reserved bits\n");
444 inject_gp(vcpu);
445 return;
446 }
447 if (is_paging(vcpu) && is_pae(vcpu) &&
448 pdptrs_have_reserved_bits_set(vcpu, cr3)) {
449 printk(KERN_DEBUG "set_cr3: #GP, pdptrs "
450 "reserved bits\n");
451 inject_gp(vcpu);
452 return;
453 }
454 }
455
456 vcpu->cr3 = cr3;
457 spin_lock(&vcpu->kvm->lock);
458 vcpu->mmu.new_cr3(vcpu);
459 spin_unlock(&vcpu->kvm->lock);
460}
461EXPORT_SYMBOL_GPL(set_cr3);
462
463void set_cr8(struct kvm_vcpu *vcpu, unsigned long cr8)
464{
465 if ( cr8 & CR8_RESEVED_BITS) {
466 printk(KERN_DEBUG "set_cr8: #GP, reserved bits 0x%lx\n", cr8);
467 inject_gp(vcpu);
468 return;
469 }
470 vcpu->cr8 = cr8;
471}
472EXPORT_SYMBOL_GPL(set_cr8);
473
474void fx_init(struct kvm_vcpu *vcpu)
475{
476 struct __attribute__ ((__packed__)) fx_image_s {
477 u16 control; //fcw
478 u16 status; //fsw
479 u16 tag; // ftw
480 u16 opcode; //fop
481 u64 ip; // fpu ip
482 u64 operand;// fpu dp
483 u32 mxcsr;
484 u32 mxcsr_mask;
485
486 } *fx_image;
487
488 fx_save(vcpu->host_fx_image);
489 fpu_init();
490 fx_save(vcpu->guest_fx_image);
491 fx_restore(vcpu->host_fx_image);
492
493 fx_image = (struct fx_image_s *)vcpu->guest_fx_image;
494 fx_image->mxcsr = 0x1f80;
495 memset(vcpu->guest_fx_image + sizeof(struct fx_image_s),
496 0, FX_IMAGE_SIZE - sizeof(struct fx_image_s));
497}
498EXPORT_SYMBOL_GPL(fx_init);
499
500/*
501 * Creates some virtual cpus. Good luck creating more than one.
502 */
503static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
504{
505 int r;
506 struct kvm_vcpu *vcpu;
507
508 r = -EINVAL;
509 if (n < 0 || n >= KVM_MAX_VCPUS)
510 goto out;
511
512 vcpu = &kvm->vcpus[n];
513
514 mutex_lock(&vcpu->mutex);
515
516 if (vcpu->vmcs) {
517 mutex_unlock(&vcpu->mutex);
518 return -EEXIST;
519 }
520
521 vcpu->host_fx_image = (char*)ALIGN((hva_t)vcpu->fx_buf,
522 FX_IMAGE_ALIGN);
523 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE;
524
525 vcpu->cpu = -1; /* First load will set up TR */
526 vcpu->kvm = kvm;
527 r = kvm_arch_ops->vcpu_create(vcpu);
528 if (r < 0)
529 goto out_free_vcpus;
530
531 kvm_arch_ops->vcpu_load(vcpu);
532
533 r = kvm_arch_ops->vcpu_setup(vcpu);
534 if (r >= 0)
535 r = kvm_mmu_init(vcpu);
536
537 vcpu_put(vcpu);
538
539 if (r < 0)
540 goto out_free_vcpus;
541
542 return 0;
543
544out_free_vcpus:
545 kvm_free_vcpu(vcpu);
546 mutex_unlock(&vcpu->mutex);
547out:
548 return r;
549}
550
551/*
552 * Allocate some memory and give it an address in the guest physical address
553 * space.
554 *
555 * Discontiguous memory is allowed, mostly for framebuffers.
556 */
557static int kvm_dev_ioctl_set_memory_region(struct kvm *kvm,
558 struct kvm_memory_region *mem)
559{
560 int r;
561 gfn_t base_gfn;
562 unsigned long npages;
563 unsigned long i;
564 struct kvm_memory_slot *memslot;
565 struct kvm_memory_slot old, new;
566 int memory_config_version;
567
568 r = -EINVAL;
569 /* General sanity checks */
570 if (mem->memory_size & (PAGE_SIZE - 1))
571 goto out;
572 if (mem->guest_phys_addr & (PAGE_SIZE - 1))
573 goto out;
574 if (mem->slot >= KVM_MEMORY_SLOTS)
575 goto out;
576 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
577 goto out;
578
579 memslot = &kvm->memslots[mem->slot];
580 base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
581 npages = mem->memory_size >> PAGE_SHIFT;
582
583 if (!npages)
584 mem->flags &= ~KVM_MEM_LOG_DIRTY_PAGES;
585
586raced:
587 spin_lock(&kvm->lock);
588
589 memory_config_version = kvm->memory_config_version;
590 new = old = *memslot;
591
592 new.base_gfn = base_gfn;
593 new.npages = npages;
594 new.flags = mem->flags;
595
596 /* Disallow changing a memory slot's size. */
597 r = -EINVAL;
598 if (npages && old.npages && npages != old.npages)
599 goto out_unlock;
600
601 /* Check for overlaps */
602 r = -EEXIST;
603 for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
604 struct kvm_memory_slot *s = &kvm->memslots[i];
605
606 if (s == memslot)
607 continue;
608 if (!((base_gfn + npages <= s->base_gfn) ||
609 (base_gfn >= s->base_gfn + s->npages)))
610 goto out_unlock;
611 }
612 /*
613 * Do memory allocations outside lock. memory_config_version will
614 * detect any races.
615 */
616 spin_unlock(&kvm->lock);
617
618 /* Deallocate if slot is being removed */
619 if (!npages)
620 new.phys_mem = 0;
621
622 /* Free page dirty bitmap if unneeded */
623 if (!(new.flags & KVM_MEM_LOG_DIRTY_PAGES))
624 new.dirty_bitmap = 0;
625
626 r = -ENOMEM;
627
628 /* Allocate if a slot is being created */
629 if (npages && !new.phys_mem) {
630 new.phys_mem = vmalloc(npages * sizeof(struct page *));
631
632 if (!new.phys_mem)
633 goto out_free;
634
635 memset(new.phys_mem, 0, npages * sizeof(struct page *));
636 for (i = 0; i < npages; ++i) {
637 new.phys_mem[i] = alloc_page(GFP_HIGHUSER
638 | __GFP_ZERO);
639 if (!new.phys_mem[i])
640 goto out_free;
641 }
642 }
643
644 /* Allocate page dirty bitmap if needed */
645 if ((new.flags & KVM_MEM_LOG_DIRTY_PAGES) && !new.dirty_bitmap) {
646 unsigned dirty_bytes = ALIGN(npages, BITS_PER_LONG) / 8;
647
648 new.dirty_bitmap = vmalloc(dirty_bytes);
649 if (!new.dirty_bitmap)
650 goto out_free;
651 memset(new.dirty_bitmap, 0, dirty_bytes);
652 }
653
654 spin_lock(&kvm->lock);
655
656 if (memory_config_version != kvm->memory_config_version) {
657 spin_unlock(&kvm->lock);
658 kvm_free_physmem_slot(&new, &old);
659 goto raced;
660 }
661
662 r = -EAGAIN;
663 if (kvm->busy)
664 goto out_unlock;
665
666 if (mem->slot >= kvm->nmemslots)
667 kvm->nmemslots = mem->slot + 1;
668
669 *memslot = new;
670 ++kvm->memory_config_version;
671
672 spin_unlock(&kvm->lock);
673
674 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
675 struct kvm_vcpu *vcpu;
676
677 vcpu = vcpu_load(kvm, i);
678 if (!vcpu)
679 continue;
680 kvm_mmu_reset_context(vcpu);
681 vcpu_put(vcpu);
682 }
683
684 kvm_free_physmem_slot(&old, &new);
685 return 0;
686
687out_unlock:
688 spin_unlock(&kvm->lock);
689out_free:
690 kvm_free_physmem_slot(&new, &old);
691out:
692 return r;
693}
694
695/*
696 * Get (and clear) the dirty memory log for a memory slot.
697 */
698static int kvm_dev_ioctl_get_dirty_log(struct kvm *kvm,
699 struct kvm_dirty_log *log)
700{
701 struct kvm_memory_slot *memslot;
702 int r, i;
703 int n;
704 unsigned long any = 0;
705
706 spin_lock(&kvm->lock);
707
708 /*
709 * Prevent changes to guest memory configuration even while the lock
710 * is not taken.
711 */
712 ++kvm->busy;
713 spin_unlock(&kvm->lock);
714 r = -EINVAL;
715 if (log->slot >= KVM_MEMORY_SLOTS)
716 goto out;
717
718 memslot = &kvm->memslots[log->slot];
719 r = -ENOENT;
720 if (!memslot->dirty_bitmap)
721 goto out;
722
723 n = ALIGN(memslot->npages, 8) / 8;
724
725 for (i = 0; !any && i < n; ++i)
726 any = memslot->dirty_bitmap[i];
727
728 r = -EFAULT;
729 if (copy_to_user(log->dirty_bitmap, memslot->dirty_bitmap, n))
730 goto out;
731
732
733 if (any) {
734 spin_lock(&kvm->lock);
735 kvm_mmu_slot_remove_write_access(kvm, log->slot);
736 spin_unlock(&kvm->lock);
737 memset(memslot->dirty_bitmap, 0, n);
738 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
739 struct kvm_vcpu *vcpu = vcpu_load(kvm, i);
740
741 if (!vcpu)
742 continue;
743 kvm_arch_ops->tlb_flush(vcpu);
744 vcpu_put(vcpu);
745 }
746 }
747
748 r = 0;
749
750out:
751 spin_lock(&kvm->lock);
752 --kvm->busy;
753 spin_unlock(&kvm->lock);
754 return r;
755}
756
757struct kvm_memory_slot *gfn_to_memslot(struct kvm *kvm, gfn_t gfn)
758{
759 int i;
760
761 for (i = 0; i < kvm->nmemslots; ++i) {
762 struct kvm_memory_slot *memslot = &kvm->memslots[i];
763
764 if (gfn >= memslot->base_gfn
765 && gfn < memslot->base_gfn + memslot->npages)
766 return memslot;
767 }
768 return 0;
769}
770EXPORT_SYMBOL_GPL(gfn_to_memslot);
771
772void mark_page_dirty(struct kvm *kvm, gfn_t gfn)
773{
774 int i;
775 struct kvm_memory_slot *memslot = 0;
776 unsigned long rel_gfn;
777
778 for (i = 0; i < kvm->nmemslots; ++i) {
779 memslot = &kvm->memslots[i];
780
781 if (gfn >= memslot->base_gfn
782 && gfn < memslot->base_gfn + memslot->npages) {
783
784 if (!memslot || !memslot->dirty_bitmap)
785 return;
786
787 rel_gfn = gfn - memslot->base_gfn;
788
789 /* avoid RMW */
790 if (!test_bit(rel_gfn, memslot->dirty_bitmap))
791 set_bit(rel_gfn, memslot->dirty_bitmap);
792 return;
793 }
794 }
795}
796
797static int emulator_read_std(unsigned long addr,
798 unsigned long *val,
799 unsigned int bytes,
800 struct x86_emulate_ctxt *ctxt)
801{
802 struct kvm_vcpu *vcpu = ctxt->vcpu;
803 void *data = val;
804
805 while (bytes) {
806 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr);
807 unsigned offset = addr & (PAGE_SIZE-1);
808 unsigned tocopy = min(bytes, (unsigned)PAGE_SIZE - offset);
809 unsigned long pfn;
810 struct kvm_memory_slot *memslot;
811 void *page;
812
813 if (gpa == UNMAPPED_GVA)
814 return X86EMUL_PROPAGATE_FAULT;
815 pfn = gpa >> PAGE_SHIFT;
816 memslot = gfn_to_memslot(vcpu->kvm, pfn);
817 if (!memslot)
818 return X86EMUL_UNHANDLEABLE;
819 page = kmap_atomic(gfn_to_page(memslot, pfn), KM_USER0);
820
821 memcpy(data, page + offset, tocopy);
822
823 kunmap_atomic(page, KM_USER0);
824
825 bytes -= tocopy;
826 data += tocopy;
827 addr += tocopy;
828 }
829
830 return X86EMUL_CONTINUE;
831}
832
833static int emulator_write_std(unsigned long addr,
834 unsigned long val,
835 unsigned int bytes,
836 struct x86_emulate_ctxt *ctxt)
837{
838 printk(KERN_ERR "emulator_write_std: addr %lx n %d\n",
839 addr, bytes);
840 return X86EMUL_UNHANDLEABLE;
841}
842
843static int emulator_read_emulated(unsigned long addr,
844 unsigned long *val,
845 unsigned int bytes,
846 struct x86_emulate_ctxt *ctxt)
847{
848 struct kvm_vcpu *vcpu = ctxt->vcpu;
849
850 if (vcpu->mmio_read_completed) {
851 memcpy(val, vcpu->mmio_data, bytes);
852 vcpu->mmio_read_completed = 0;
853 return X86EMUL_CONTINUE;
854 } else if (emulator_read_std(addr, val, bytes, ctxt)
855 == X86EMUL_CONTINUE)
856 return X86EMUL_CONTINUE;
857 else {
858 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr);
859 if (gpa == UNMAPPED_GVA)
860 return vcpu_printf(vcpu, "not present\n"), X86EMUL_PROPAGATE_FAULT;
861 vcpu->mmio_needed = 1;
862 vcpu->mmio_phys_addr = gpa;
863 vcpu->mmio_size = bytes;
864 vcpu->mmio_is_write = 0;
865
866 return X86EMUL_UNHANDLEABLE;
867 }
868}
869
870static int emulator_write_emulated(unsigned long addr,
871 unsigned long val,
872 unsigned int bytes,
873 struct x86_emulate_ctxt *ctxt)
874{
875 struct kvm_vcpu *vcpu = ctxt->vcpu;
876 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, addr);
877
878 if (gpa == UNMAPPED_GVA)
879 return X86EMUL_PROPAGATE_FAULT;
880
881 vcpu->mmio_needed = 1;
882 vcpu->mmio_phys_addr = gpa;
883 vcpu->mmio_size = bytes;
884 vcpu->mmio_is_write = 1;
885 memcpy(vcpu->mmio_data, &val, bytes);
886
887 return X86EMUL_CONTINUE;
888}
889
890static int emulator_cmpxchg_emulated(unsigned long addr,
891 unsigned long old,
892 unsigned long new,
893 unsigned int bytes,
894 struct x86_emulate_ctxt *ctxt)
895{
896 static int reported;
897
898 if (!reported) {
899 reported = 1;
900 printk(KERN_WARNING "kvm: emulating exchange as write\n");
901 }
902 return emulator_write_emulated(addr, new, bytes, ctxt);
903}
904
905static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg)
906{
907 return kvm_arch_ops->get_segment_base(vcpu, seg);
908}
909
910int emulate_invlpg(struct kvm_vcpu *vcpu, gva_t address)
911{
912 spin_lock(&vcpu->kvm->lock);
913 vcpu->mmu.inval_page(vcpu, address);
914 spin_unlock(&vcpu->kvm->lock);
915 kvm_arch_ops->invlpg(vcpu, address);
916 return X86EMUL_CONTINUE;
917}
918
919int emulate_clts(struct kvm_vcpu *vcpu)
920{
921 unsigned long cr0 = vcpu->cr0;
922
923 cr0 &= ~CR0_TS_MASK;
924 kvm_arch_ops->set_cr0(vcpu, cr0);
925 return X86EMUL_CONTINUE;
926}
927
928int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr, unsigned long *dest)
929{
930 struct kvm_vcpu *vcpu = ctxt->vcpu;
931
932 switch (dr) {
933 case 0 ... 3:
934 *dest = kvm_arch_ops->get_dr(vcpu, dr);
935 return X86EMUL_CONTINUE;
936 default:
937 printk(KERN_DEBUG "%s: unexpected dr %u\n",
938 __FUNCTION__, dr);
939 return X86EMUL_UNHANDLEABLE;
940 }
941}
942
943int emulator_set_dr(struct x86_emulate_ctxt *ctxt, int dr, unsigned long value)
944{
945 unsigned long mask = (ctxt->mode == X86EMUL_MODE_PROT64) ? ~0ULL : ~0U;
946 int exception;
947
948 kvm_arch_ops->set_dr(ctxt->vcpu, dr, value & mask, &exception);
949 if (exception) {
950 /* FIXME: better handling */
951 return X86EMUL_UNHANDLEABLE;
952 }
953 return X86EMUL_CONTINUE;
954}
955
956static void report_emulation_failure(struct x86_emulate_ctxt *ctxt)
957{
958 static int reported;
959 u8 opcodes[4];
960 unsigned long rip = ctxt->vcpu->rip;
961 unsigned long rip_linear;
962
963 rip_linear = rip + get_segment_base(ctxt->vcpu, VCPU_SREG_CS);
964
965 if (reported)
966 return;
967
968 emulator_read_std(rip_linear, (void *)opcodes, 4, ctxt);
969
970 printk(KERN_ERR "emulation failed but !mmio_needed?"
971 " rip %lx %02x %02x %02x %02x\n",
972 rip, opcodes[0], opcodes[1], opcodes[2], opcodes[3]);
973 reported = 1;
974}
975
976struct x86_emulate_ops emulate_ops = {
977 .read_std = emulator_read_std,
978 .write_std = emulator_write_std,
979 .read_emulated = emulator_read_emulated,
980 .write_emulated = emulator_write_emulated,
981 .cmpxchg_emulated = emulator_cmpxchg_emulated,
982};
983
984int emulate_instruction(struct kvm_vcpu *vcpu,
985 struct kvm_run *run,
986 unsigned long cr2,
987 u16 error_code)
988{
989 struct x86_emulate_ctxt emulate_ctxt;
990 int r;
991 int cs_db, cs_l;
992
993 kvm_arch_ops->cache_regs(vcpu);
994
995 kvm_arch_ops->get_cs_db_l_bits(vcpu, &cs_db, &cs_l);
996
997 emulate_ctxt.vcpu = vcpu;
998 emulate_ctxt.eflags = kvm_arch_ops->get_rflags(vcpu);
999 emulate_ctxt.cr2 = cr2;
1000 emulate_ctxt.mode = (emulate_ctxt.eflags & X86_EFLAGS_VM)
1001 ? X86EMUL_MODE_REAL : cs_l
1002 ? X86EMUL_MODE_PROT64 : cs_db
1003 ? X86EMUL_MODE_PROT32 : X86EMUL_MODE_PROT16;
1004
1005 if (emulate_ctxt.mode == X86EMUL_MODE_PROT64) {
1006 emulate_ctxt.cs_base = 0;
1007 emulate_ctxt.ds_base = 0;
1008 emulate_ctxt.es_base = 0;
1009 emulate_ctxt.ss_base = 0;
1010 } else {
1011 emulate_ctxt.cs_base = get_segment_base(vcpu, VCPU_SREG_CS);
1012 emulate_ctxt.ds_base = get_segment_base(vcpu, VCPU_SREG_DS);
1013 emulate_ctxt.es_base = get_segment_base(vcpu, VCPU_SREG_ES);
1014 emulate_ctxt.ss_base = get_segment_base(vcpu, VCPU_SREG_SS);
1015 }
1016
1017 emulate_ctxt.gs_base = get_segment_base(vcpu, VCPU_SREG_GS);
1018 emulate_ctxt.fs_base = get_segment_base(vcpu, VCPU_SREG_FS);
1019
1020 vcpu->mmio_is_write = 0;
1021 r = x86_emulate_memop(&emulate_ctxt, &emulate_ops);
1022
1023 if ((r || vcpu->mmio_is_write) && run) {
1024 run->mmio.phys_addr = vcpu->mmio_phys_addr;
1025 memcpy(run->mmio.data, vcpu->mmio_data, 8);
1026 run->mmio.len = vcpu->mmio_size;
1027 run->mmio.is_write = vcpu->mmio_is_write;
1028 }
1029
1030 if (r) {
1031 if (!vcpu->mmio_needed) {
1032 report_emulation_failure(&emulate_ctxt);
1033 return EMULATE_FAIL;
1034 }
1035 return EMULATE_DO_MMIO;
1036 }
1037
1038 kvm_arch_ops->decache_regs(vcpu);
1039 kvm_arch_ops->set_rflags(vcpu, emulate_ctxt.eflags);
1040
1041 if (vcpu->mmio_is_write)
1042 return EMULATE_DO_MMIO;
1043
1044 return EMULATE_DONE;
1045}
1046EXPORT_SYMBOL_GPL(emulate_instruction);
1047
1048static u64 mk_cr_64(u64 curr_cr, u32 new_val)
1049{
1050 return (curr_cr & ~((1ULL << 32) - 1)) | new_val;
1051}
1052
1053void realmode_lgdt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
1054{
1055 struct descriptor_table dt = { limit, base };
1056
1057 kvm_arch_ops->set_gdt(vcpu, &dt);
1058}
1059
1060void realmode_lidt(struct kvm_vcpu *vcpu, u16 limit, unsigned long base)
1061{
1062 struct descriptor_table dt = { limit, base };
1063
1064 kvm_arch_ops->set_idt(vcpu, &dt);
1065}
1066
1067void realmode_lmsw(struct kvm_vcpu *vcpu, unsigned long msw,
1068 unsigned long *rflags)
1069{
1070 lmsw(vcpu, msw);
1071 *rflags = kvm_arch_ops->get_rflags(vcpu);
1072}
1073
1074unsigned long realmode_get_cr(struct kvm_vcpu *vcpu, int cr)
1075{
1076 switch (cr) {
1077 case 0:
1078 return vcpu->cr0;
1079 case 2:
1080 return vcpu->cr2;
1081 case 3:
1082 return vcpu->cr3;
1083 case 4:
1084 return vcpu->cr4;
1085 default:
1086 vcpu_printf(vcpu, "%s: unexpected cr %u\n", __FUNCTION__, cr);
1087 return 0;
1088 }
1089}
1090
1091void realmode_set_cr(struct kvm_vcpu *vcpu, int cr, unsigned long val,
1092 unsigned long *rflags)
1093{
1094 switch (cr) {
1095 case 0:
1096 set_cr0(vcpu, mk_cr_64(vcpu->cr0, val));
1097 *rflags = kvm_arch_ops->get_rflags(vcpu);
1098 break;
1099 case 2:
1100 vcpu->cr2 = val;
1101 break;
1102 case 3:
1103 set_cr3(vcpu, val);
1104 break;
1105 case 4:
1106 set_cr4(vcpu, mk_cr_64(vcpu->cr4, val));
1107 break;
1108 default:
1109 vcpu_printf(vcpu, "%s: unexpected cr %u\n", __FUNCTION__, cr);
1110 }
1111}
1112
1113/*
1114 * Reads an msr value (of 'msr_index') into 'pdata'.
1115 * Returns 0 on success, non-0 otherwise.
1116 * Assumes vcpu_load() was already called.
1117 */
1118static int get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
1119{
1120 return kvm_arch_ops->get_msr(vcpu, msr_index, pdata);
1121}
1122
1123#ifdef __x86_64__
1124
1125void set_efer(struct kvm_vcpu *vcpu, u64 efer)
1126{
1127 struct vmx_msr_entry *msr;
1128
1129 if (efer & EFER_RESERVED_BITS) {
1130 printk(KERN_DEBUG "set_efer: 0x%llx #GP, reserved bits\n",
1131 efer);
1132 inject_gp(vcpu);
1133 return;
1134 }
1135
1136 if (is_paging(vcpu)
1137 && (vcpu->shadow_efer & EFER_LME) != (efer & EFER_LME)) {
1138 printk(KERN_DEBUG "set_efer: #GP, change LME while paging\n");
1139 inject_gp(vcpu);
1140 return;
1141 }
1142
1143 efer &= ~EFER_LMA;
1144 efer |= vcpu->shadow_efer & EFER_LMA;
1145
1146 vcpu->shadow_efer = efer;
1147
1148 msr = find_msr_entry(vcpu, MSR_EFER);
1149
1150 if (!(efer & EFER_LMA))
1151 efer &= ~EFER_LME;
1152 msr->data = efer;
1153}
1154EXPORT_SYMBOL_GPL(set_efer);
1155
1156#endif
1157
1158/*
1159 * Writes msr value into into the appropriate "register".
1160 * Returns 0 on success, non-0 otherwise.
1161 * Assumes vcpu_load() was already called.
1162 */
1163static int set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
1164{
1165 return kvm_arch_ops->set_msr(vcpu, msr_index, data);
1166}
1167
1168void kvm_resched(struct kvm_vcpu *vcpu)
1169{
1170 vcpu_put(vcpu);
1171 cond_resched();
1172 /* Cannot fail - no vcpu unplug yet. */
1173 vcpu_load(vcpu->kvm, vcpu_slot(vcpu));
1174}
1175EXPORT_SYMBOL_GPL(kvm_resched);
1176
1177void load_msrs(struct vmx_msr_entry *e, int n)
1178{
1179 int i;
1180
1181 for (i = 0; i < n; ++i)
1182 wrmsrl(e[i].index, e[i].data);
1183}
1184EXPORT_SYMBOL_GPL(load_msrs);
1185
1186void save_msrs(struct vmx_msr_entry *e, int n)
1187{
1188 int i;
1189
1190 for (i = 0; i < n; ++i)
1191 rdmsrl(e[i].index, e[i].data);
1192}
1193EXPORT_SYMBOL_GPL(save_msrs);
1194
1195static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run)
1196{
1197 struct kvm_vcpu *vcpu;
1198 int r;
1199
1200 if (kvm_run->vcpu < 0 || kvm_run->vcpu >= KVM_MAX_VCPUS)
1201 return -EINVAL;
1202
1203 vcpu = vcpu_load(kvm, kvm_run->vcpu);
1204 if (!vcpu)
1205 return -ENOENT;
1206
1207 if (kvm_run->emulated) {
1208 kvm_arch_ops->skip_emulated_instruction(vcpu);
1209 kvm_run->emulated = 0;
1210 }
1211
1212 if (kvm_run->mmio_completed) {
1213 memcpy(vcpu->mmio_data, kvm_run->mmio.data, 8);
1214 vcpu->mmio_read_completed = 1;
1215 }
1216
1217 vcpu->mmio_needed = 0;
1218
1219 r = kvm_arch_ops->run(vcpu, kvm_run);
1220
1221 vcpu_put(vcpu);
1222 return r;
1223}
1224
1225static int kvm_dev_ioctl_get_regs(struct kvm *kvm, struct kvm_regs *regs)
1226{
1227 struct kvm_vcpu *vcpu;
1228
1229 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS)
1230 return -EINVAL;
1231
1232 vcpu = vcpu_load(kvm, regs->vcpu);
1233 if (!vcpu)
1234 return -ENOENT;
1235
1236 kvm_arch_ops->cache_regs(vcpu);
1237
1238 regs->rax = vcpu->regs[VCPU_REGS_RAX];
1239 regs->rbx = vcpu->regs[VCPU_REGS_RBX];
1240 regs->rcx = vcpu->regs[VCPU_REGS_RCX];
1241 regs->rdx = vcpu->regs[VCPU_REGS_RDX];
1242 regs->rsi = vcpu->regs[VCPU_REGS_RSI];
1243 regs->rdi = vcpu->regs[VCPU_REGS_RDI];
1244 regs->rsp = vcpu->regs[VCPU_REGS_RSP];
1245 regs->rbp = vcpu->regs[VCPU_REGS_RBP];
1246#ifdef __x86_64__
1247 regs->r8 = vcpu->regs[VCPU_REGS_R8];
1248 regs->r9 = vcpu->regs[VCPU_REGS_R9];
1249 regs->r10 = vcpu->regs[VCPU_REGS_R10];
1250 regs->r11 = vcpu->regs[VCPU_REGS_R11];
1251 regs->r12 = vcpu->regs[VCPU_REGS_R12];
1252 regs->r13 = vcpu->regs[VCPU_REGS_R13];
1253 regs->r14 = vcpu->regs[VCPU_REGS_R14];
1254 regs->r15 = vcpu->regs[VCPU_REGS_R15];
1255#endif
1256
1257 regs->rip = vcpu->rip;
1258 regs->rflags = kvm_arch_ops->get_rflags(vcpu);
1259
1260 /*
1261 * Don't leak debug flags in case they were set for guest debugging
1262 */
1263 if (vcpu->guest_debug.enabled && vcpu->guest_debug.singlestep)
1264 regs->rflags &= ~(X86_EFLAGS_TF | X86_EFLAGS_RF);
1265
1266 vcpu_put(vcpu);
1267
1268 return 0;
1269}
1270
1271static int kvm_dev_ioctl_set_regs(struct kvm *kvm, struct kvm_regs *regs)
1272{
1273 struct kvm_vcpu *vcpu;
1274
1275 if (regs->vcpu < 0 || regs->vcpu >= KVM_MAX_VCPUS)
1276 return -EINVAL;
1277
1278 vcpu = vcpu_load(kvm, regs->vcpu);
1279 if (!vcpu)
1280 return -ENOENT;
1281
1282 vcpu->regs[VCPU_REGS_RAX] = regs->rax;
1283 vcpu->regs[VCPU_REGS_RBX] = regs->rbx;
1284 vcpu->regs[VCPU_REGS_RCX] = regs->rcx;
1285 vcpu->regs[VCPU_REGS_RDX] = regs->rdx;
1286 vcpu->regs[VCPU_REGS_RSI] = regs->rsi;
1287 vcpu->regs[VCPU_REGS_RDI] = regs->rdi;
1288 vcpu->regs[VCPU_REGS_RSP] = regs->rsp;
1289 vcpu->regs[VCPU_REGS_RBP] = regs->rbp;
1290#ifdef __x86_64__
1291 vcpu->regs[VCPU_REGS_R8] = regs->r8;
1292 vcpu->regs[VCPU_REGS_R9] = regs->r9;
1293 vcpu->regs[VCPU_REGS_R10] = regs->r10;
1294 vcpu->regs[VCPU_REGS_R11] = regs->r11;
1295 vcpu->regs[VCPU_REGS_R12] = regs->r12;
1296 vcpu->regs[VCPU_REGS_R13] = regs->r13;
1297 vcpu->regs[VCPU_REGS_R14] = regs->r14;
1298 vcpu->regs[VCPU_REGS_R15] = regs->r15;
1299#endif
1300
1301 vcpu->rip = regs->rip;
1302 kvm_arch_ops->set_rflags(vcpu, regs->rflags);
1303
1304 kvm_arch_ops->decache_regs(vcpu);
1305
1306 vcpu_put(vcpu);
1307
1308 return 0;
1309}
1310
1311static void get_segment(struct kvm_vcpu *vcpu,
1312 struct kvm_segment *var, int seg)
1313{
1314 return kvm_arch_ops->get_segment(vcpu, var, seg);
1315}
1316
1317static int kvm_dev_ioctl_get_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1318{
1319 struct kvm_vcpu *vcpu;
1320 struct descriptor_table dt;
1321
1322 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS)
1323 return -EINVAL;
1324 vcpu = vcpu_load(kvm, sregs->vcpu);
1325 if (!vcpu)
1326 return -ENOENT;
1327
1328 get_segment(vcpu, &sregs->cs, VCPU_SREG_CS);
1329 get_segment(vcpu, &sregs->ds, VCPU_SREG_DS);
1330 get_segment(vcpu, &sregs->es, VCPU_SREG_ES);
1331 get_segment(vcpu, &sregs->fs, VCPU_SREG_FS);
1332 get_segment(vcpu, &sregs->gs, VCPU_SREG_GS);
1333 get_segment(vcpu, &sregs->ss, VCPU_SREG_SS);
1334
1335 get_segment(vcpu, &sregs->tr, VCPU_SREG_TR);
1336 get_segment(vcpu, &sregs->ldt, VCPU_SREG_LDTR);
1337
1338 kvm_arch_ops->get_idt(vcpu, &dt);
1339 sregs->idt.limit = dt.limit;
1340 sregs->idt.base = dt.base;
1341 kvm_arch_ops->get_gdt(vcpu, &dt);
1342 sregs->gdt.limit = dt.limit;
1343 sregs->gdt.base = dt.base;
1344
1345 sregs->cr0 = vcpu->cr0;
1346 sregs->cr2 = vcpu->cr2;
1347 sregs->cr3 = vcpu->cr3;
1348 sregs->cr4 = vcpu->cr4;
1349 sregs->cr8 = vcpu->cr8;
1350 sregs->efer = vcpu->shadow_efer;
1351 sregs->apic_base = vcpu->apic_base;
1352
1353 memcpy(sregs->interrupt_bitmap, vcpu->irq_pending,
1354 sizeof sregs->interrupt_bitmap);
1355
1356 vcpu_put(vcpu);
1357
1358 return 0;
1359}
1360
1361static void set_segment(struct kvm_vcpu *vcpu,
1362 struct kvm_segment *var, int seg)
1363{
1364 return kvm_arch_ops->set_segment(vcpu, var, seg);
1365}
1366
1367static int kvm_dev_ioctl_set_sregs(struct kvm *kvm, struct kvm_sregs *sregs)
1368{
1369 struct kvm_vcpu *vcpu;
1370 int mmu_reset_needed = 0;
1371 int i;
1372 struct descriptor_table dt;
1373
1374 if (sregs->vcpu < 0 || sregs->vcpu >= KVM_MAX_VCPUS)
1375 return -EINVAL;
1376 vcpu = vcpu_load(kvm, sregs->vcpu);
1377 if (!vcpu)
1378 return -ENOENT;
1379
1380 set_segment(vcpu, &sregs->cs, VCPU_SREG_CS);
1381 set_segment(vcpu, &sregs->ds, VCPU_SREG_DS);
1382 set_segment(vcpu, &sregs->es, VCPU_SREG_ES);
1383 set_segment(vcpu, &sregs->fs, VCPU_SREG_FS);
1384 set_segment(vcpu, &sregs->gs, VCPU_SREG_GS);
1385 set_segment(vcpu, &sregs->ss, VCPU_SREG_SS);
1386
1387 set_segment(vcpu, &sregs->tr, VCPU_SREG_TR);
1388 set_segment(vcpu, &sregs->ldt, VCPU_SREG_LDTR);
1389
1390 dt.limit = sregs->idt.limit;
1391 dt.base = sregs->idt.base;
1392 kvm_arch_ops->set_idt(vcpu, &dt);
1393 dt.limit = sregs->gdt.limit;
1394 dt.base = sregs->gdt.base;
1395 kvm_arch_ops->set_gdt(vcpu, &dt);
1396
1397 vcpu->cr2 = sregs->cr2;
1398 mmu_reset_needed |= vcpu->cr3 != sregs->cr3;
1399 vcpu->cr3 = sregs->cr3;
1400
1401 vcpu->cr8 = sregs->cr8;
1402
1403 mmu_reset_needed |= vcpu->shadow_efer != sregs->efer;
1404#ifdef __x86_64__
1405 kvm_arch_ops->set_efer(vcpu, sregs->efer);
1406#endif
1407 vcpu->apic_base = sregs->apic_base;
1408
1409 mmu_reset_needed |= vcpu->cr0 != sregs->cr0;
1410 kvm_arch_ops->set_cr0_no_modeswitch(vcpu, sregs->cr0);
1411
1412 mmu_reset_needed |= vcpu->cr4 != sregs->cr4;
1413 kvm_arch_ops->set_cr4(vcpu, sregs->cr4);
1414
1415 if (mmu_reset_needed)
1416 kvm_mmu_reset_context(vcpu);
1417
1418 memcpy(vcpu->irq_pending, sregs->interrupt_bitmap,
1419 sizeof vcpu->irq_pending);
1420 vcpu->irq_summary = 0;
1421 for (i = 0; i < NR_IRQ_WORDS; ++i)
1422 if (vcpu->irq_pending[i])
1423 __set_bit(i, &vcpu->irq_summary);
1424
1425 vcpu_put(vcpu);
1426
1427 return 0;
1428}
1429
1430/*
1431 * List of msr numbers which we expose to userspace through KVM_GET_MSRS
1432 * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
1433 */
1434static u32 msrs_to_save[] = {
1435 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
1436 MSR_K6_STAR,
1437#ifdef __x86_64__
1438 MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
1439#endif
1440 MSR_IA32_TIME_STAMP_COUNTER,
1441};
1442
1443
1444/*
1445 * Adapt set_msr() to msr_io()'s calling convention
1446 */
1447static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
1448{
1449 return set_msr(vcpu, index, *data);
1450}
1451
1452/*
1453 * Read or write a bunch of msrs. All parameters are kernel addresses.
1454 *
1455 * @return number of msrs set successfully.
1456 */
1457static int __msr_io(struct kvm *kvm, struct kvm_msrs *msrs,
1458 struct kvm_msr_entry *entries,
1459 int (*do_msr)(struct kvm_vcpu *vcpu,
1460 unsigned index, u64 *data))
1461{
1462 struct kvm_vcpu *vcpu;
1463 int i;
1464
1465 if (msrs->vcpu < 0 || msrs->vcpu >= KVM_MAX_VCPUS)
1466 return -EINVAL;
1467
1468 vcpu = vcpu_load(kvm, msrs->vcpu);
1469 if (!vcpu)
1470 return -ENOENT;
1471
1472 for (i = 0; i < msrs->nmsrs; ++i)
1473 if (do_msr(vcpu, entries[i].index, &entries[i].data))
1474 break;
1475
1476 vcpu_put(vcpu);
1477
1478 return i;
1479}
1480
1481/*
1482 * Read or write a bunch of msrs. Parameters are user addresses.
1483 *
1484 * @return number of msrs set successfully.
1485 */
1486static int msr_io(struct kvm *kvm, struct kvm_msrs __user *user_msrs,
1487 int (*do_msr)(struct kvm_vcpu *vcpu,
1488 unsigned index, u64 *data),
1489 int writeback)
1490{
1491 struct kvm_msrs msrs;
1492 struct kvm_msr_entry *entries;
1493 int r, n;
1494 unsigned size;
1495
1496 r = -EFAULT;
1497 if (copy_from_user(&msrs, user_msrs, sizeof msrs))
1498 goto out;
1499
1500 r = -E2BIG;
1501 if (msrs.nmsrs >= MAX_IO_MSRS)
1502 goto out;
1503
1504 r = -ENOMEM;
1505 size = sizeof(struct kvm_msr_entry) * msrs.nmsrs;
1506 entries = vmalloc(size);
1507 if (!entries)
1508 goto out;
1509
1510 r = -EFAULT;
1511 if (copy_from_user(entries, user_msrs->entries, size))
1512 goto out_free;
1513
1514 r = n = __msr_io(kvm, &msrs, entries, do_msr);
1515 if (r < 0)
1516 goto out_free;
1517
1518 r = -EFAULT;
1519 if (writeback && copy_to_user(user_msrs->entries, entries, size))
1520 goto out_free;
1521
1522 r = n;
1523
1524out_free:
1525 vfree(entries);
1526out:
1527 return r;
1528}
1529
1530/*
1531 * Translate a guest virtual address to a guest physical address.
1532 */
1533static int kvm_dev_ioctl_translate(struct kvm *kvm, struct kvm_translation *tr)
1534{
1535 unsigned long vaddr = tr->linear_address;
1536 struct kvm_vcpu *vcpu;
1537 gpa_t gpa;
1538
1539 vcpu = vcpu_load(kvm, tr->vcpu);
1540 if (!vcpu)
1541 return -ENOENT;
1542 spin_lock(&kvm->lock);
1543 gpa = vcpu->mmu.gva_to_gpa(vcpu, vaddr);
1544 tr->physical_address = gpa;
1545 tr->valid = gpa != UNMAPPED_GVA;
1546 tr->writeable = 1;
1547 tr->usermode = 0;
1548 spin_unlock(&kvm->lock);
1549 vcpu_put(vcpu);
1550
1551 return 0;
1552}
1553
1554static int kvm_dev_ioctl_interrupt(struct kvm *kvm, struct kvm_interrupt *irq)
1555{
1556 struct kvm_vcpu *vcpu;
1557
1558 if (irq->vcpu < 0 || irq->vcpu >= KVM_MAX_VCPUS)
1559 return -EINVAL;
1560 if (irq->irq < 0 || irq->irq >= 256)
1561 return -EINVAL;
1562 vcpu = vcpu_load(kvm, irq->vcpu);
1563 if (!vcpu)
1564 return -ENOENT;
1565
1566 set_bit(irq->irq, vcpu->irq_pending);
1567 set_bit(irq->irq / BITS_PER_LONG, &vcpu->irq_summary);
1568
1569 vcpu_put(vcpu);
1570
1571 return 0;
1572}
1573
1574static int kvm_dev_ioctl_debug_guest(struct kvm *kvm,
1575 struct kvm_debug_guest *dbg)
1576{
1577 struct kvm_vcpu *vcpu;
1578 int r;
1579
1580 if (dbg->vcpu < 0 || dbg->vcpu >= KVM_MAX_VCPUS)
1581 return -EINVAL;
1582 vcpu = vcpu_load(kvm, dbg->vcpu);
1583 if (!vcpu)
1584 return -ENOENT;
1585
1586 r = kvm_arch_ops->set_guest_debug(vcpu, dbg);
1587
1588 vcpu_put(vcpu);
1589
1590 return r;
1591}
1592
1593static long kvm_dev_ioctl(struct file *filp,
1594 unsigned int ioctl, unsigned long arg)
1595{
1596 struct kvm *kvm = filp->private_data;
1597 int r = -EINVAL;
1598
1599 switch (ioctl) {
1600 case KVM_CREATE_VCPU: {
1601 r = kvm_dev_ioctl_create_vcpu(kvm, arg);
1602 if (r)
1603 goto out;
1604 break;
1605 }
1606 case KVM_RUN: {
1607 struct kvm_run kvm_run;
1608
1609 r = -EFAULT;
1610 if (copy_from_user(&kvm_run, (void *)arg, sizeof kvm_run))
1611 goto out;
1612 r = kvm_dev_ioctl_run(kvm, &kvm_run);
1613 if (r < 0)
1614 goto out;
1615 r = -EFAULT;
1616 if (copy_to_user((void *)arg, &kvm_run, sizeof kvm_run))
1617 goto out;
1618 r = 0;
1619 break;
1620 }
1621 case KVM_GET_REGS: {
1622 struct kvm_regs kvm_regs;
1623
1624 r = -EFAULT;
1625 if (copy_from_user(&kvm_regs, (void *)arg, sizeof kvm_regs))
1626 goto out;
1627 r = kvm_dev_ioctl_get_regs(kvm, &kvm_regs);
1628 if (r)
1629 goto out;
1630 r = -EFAULT;
1631 if (copy_to_user((void *)arg, &kvm_regs, sizeof kvm_regs))
1632 goto out;
1633 r = 0;
1634 break;
1635 }
1636 case KVM_SET_REGS: {
1637 struct kvm_regs kvm_regs;
1638
1639 r = -EFAULT;
1640 if (copy_from_user(&kvm_regs, (void *)arg, sizeof kvm_regs))
1641 goto out;
1642 r = kvm_dev_ioctl_set_regs(kvm, &kvm_regs);
1643 if (r)
1644 goto out;
1645 r = 0;
1646 break;
1647 }
1648 case KVM_GET_SREGS: {
1649 struct kvm_sregs kvm_sregs;
1650
1651 r = -EFAULT;
1652 if (copy_from_user(&kvm_sregs, (void *)arg, sizeof kvm_sregs))
1653 goto out;
1654 r = kvm_dev_ioctl_get_sregs(kvm, &kvm_sregs);
1655 if (r)
1656 goto out;
1657 r = -EFAULT;
1658 if (copy_to_user((void *)arg, &kvm_sregs, sizeof kvm_sregs))
1659 goto out;
1660 r = 0;
1661 break;
1662 }
1663 case KVM_SET_SREGS: {
1664 struct kvm_sregs kvm_sregs;
1665
1666 r = -EFAULT;
1667 if (copy_from_user(&kvm_sregs, (void *)arg, sizeof kvm_sregs))
1668 goto out;
1669 r = kvm_dev_ioctl_set_sregs(kvm, &kvm_sregs);
1670 if (r)
1671 goto out;
1672 r = 0;
1673 break;
1674 }
1675 case KVM_TRANSLATE: {
1676 struct kvm_translation tr;
1677
1678 r = -EFAULT;
1679 if (copy_from_user(&tr, (void *)arg, sizeof tr))
1680 goto out;
1681 r = kvm_dev_ioctl_translate(kvm, &tr);
1682 if (r)
1683 goto out;
1684 r = -EFAULT;
1685 if (copy_to_user((void *)arg, &tr, sizeof tr))
1686 goto out;
1687 r = 0;
1688 break;
1689 }
1690 case KVM_INTERRUPT: {
1691 struct kvm_interrupt irq;
1692
1693 r = -EFAULT;
1694 if (copy_from_user(&irq, (void *)arg, sizeof irq))
1695 goto out;
1696 r = kvm_dev_ioctl_interrupt(kvm, &irq);
1697 if (r)
1698 goto out;
1699 r = 0;
1700 break;
1701 }
1702 case KVM_DEBUG_GUEST: {
1703 struct kvm_debug_guest dbg;
1704
1705 r = -EFAULT;
1706 if (copy_from_user(&dbg, (void *)arg, sizeof dbg))
1707 goto out;
1708 r = kvm_dev_ioctl_debug_guest(kvm, &dbg);
1709 if (r)
1710 goto out;
1711 r = 0;
1712 break;
1713 }
1714 case KVM_SET_MEMORY_REGION: {
1715 struct kvm_memory_region kvm_mem;
1716
1717 r = -EFAULT;
1718 if (copy_from_user(&kvm_mem, (void *)arg, sizeof kvm_mem))
1719 goto out;
1720 r = kvm_dev_ioctl_set_memory_region(kvm, &kvm_mem);
1721 if (r)
1722 goto out;
1723 break;
1724 }
1725 case KVM_GET_DIRTY_LOG: {
1726 struct kvm_dirty_log log;
1727
1728 r = -EFAULT;
1729 if (copy_from_user(&log, (void *)arg, sizeof log))
1730 goto out;
1731 r = kvm_dev_ioctl_get_dirty_log(kvm, &log);
1732 if (r)
1733 goto out;
1734 break;
1735 }
1736 case KVM_GET_MSRS:
1737 r = msr_io(kvm, (void __user *)arg, get_msr, 1);
1738 break;
1739 case KVM_SET_MSRS:
1740 r = msr_io(kvm, (void __user *)arg, do_set_msr, 0);
1741 break;
1742 case KVM_GET_MSR_INDEX_LIST: {
1743 struct kvm_msr_list __user *user_msr_list = (void __user *)arg;
1744 struct kvm_msr_list msr_list;
1745 unsigned n;
1746
1747 r = -EFAULT;
1748 if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
1749 goto out;
1750 n = msr_list.nmsrs;
1751 msr_list.nmsrs = ARRAY_SIZE(msrs_to_save);
1752 if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
1753 goto out;
1754 r = -E2BIG;
1755 if (n < ARRAY_SIZE(msrs_to_save))
1756 goto out;
1757 r = -EFAULT;
1758 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
1759 sizeof msrs_to_save))
1760 goto out;
1761 r = 0;
1762 }
1763 default:
1764 ;
1765 }
1766out:
1767 return r;
1768}
1769
1770static struct page *kvm_dev_nopage(struct vm_area_struct *vma,
1771 unsigned long address,
1772 int *type)
1773{
1774 struct kvm *kvm = vma->vm_file->private_data;
1775 unsigned long pgoff;
1776 struct kvm_memory_slot *slot;
1777 struct page *page;
1778
1779 *type = VM_FAULT_MINOR;
1780 pgoff = ((address - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
1781 slot = gfn_to_memslot(kvm, pgoff);
1782 if (!slot)
1783 return NOPAGE_SIGBUS;
1784 page = gfn_to_page(slot, pgoff);
1785 if (!page)
1786 return NOPAGE_SIGBUS;
1787 get_page(page);
1788 return page;
1789}
1790
1791static struct vm_operations_struct kvm_dev_vm_ops = {
1792 .nopage = kvm_dev_nopage,
1793};
1794
1795static int kvm_dev_mmap(struct file *file, struct vm_area_struct *vma)
1796{
1797 vma->vm_ops = &kvm_dev_vm_ops;
1798 return 0;
1799}
1800
1801static struct file_operations kvm_chardev_ops = {
1802 .open = kvm_dev_open,
1803 .release = kvm_dev_release,
1804 .unlocked_ioctl = kvm_dev_ioctl,
1805 .compat_ioctl = kvm_dev_ioctl,
1806 .mmap = kvm_dev_mmap,
1807};
1808
1809static struct miscdevice kvm_dev = {
1810 MISC_DYNAMIC_MINOR,
1811 "kvm",
1812 &kvm_chardev_ops,
1813};
1814
1815static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
1816 void *v)
1817{
1818 if (val == SYS_RESTART) {
1819 /*
1820 * Some (well, at least mine) BIOSes hang on reboot if
1821 * in vmx root mode.
1822 */
1823 printk(KERN_INFO "kvm: exiting hardware virtualization\n");
1824 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
1825 }
1826 return NOTIFY_OK;
1827}
1828
1829static struct notifier_block kvm_reboot_notifier = {
1830 .notifier_call = kvm_reboot,
1831 .priority = 0,
1832};
1833
1834static __init void kvm_init_debug(void)
1835{
1836 struct kvm_stats_debugfs_item *p;
1837
1838 debugfs_dir = debugfs_create_dir("kvm", 0);
1839 for (p = debugfs_entries; p->name; ++p)
1840 p->dentry = debugfs_create_u32(p->name, 0444, debugfs_dir,
1841 p->data);
1842}
1843
1844static void kvm_exit_debug(void)
1845{
1846 struct kvm_stats_debugfs_item *p;
1847
1848 for (p = debugfs_entries; p->name; ++p)
1849 debugfs_remove(p->dentry);
1850 debugfs_remove(debugfs_dir);
1851}
1852
1853hpa_t bad_page_address;
1854
1855int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
1856{
1857 int r;
1858
1859 kvm_arch_ops = ops;
1860
1861 if (!kvm_arch_ops->cpu_has_kvm_support()) {
1862 printk(KERN_ERR "kvm: no hardware support\n");
1863 return -EOPNOTSUPP;
1864 }
1865 if (kvm_arch_ops->disabled_by_bios()) {
1866 printk(KERN_ERR "kvm: disabled by bios\n");
1867 return -EOPNOTSUPP;
1868 }
1869
1870 r = kvm_arch_ops->hardware_setup();
1871 if (r < 0)
1872 return r;
1873
1874 on_each_cpu(kvm_arch_ops->hardware_enable, 0, 0, 1);
1875 register_reboot_notifier(&kvm_reboot_notifier);
1876
1877 kvm_chardev_ops.owner = module;
1878
1879 r = misc_register(&kvm_dev);
1880 if (r) {
1881 printk (KERN_ERR "kvm: misc device register failed\n");
1882 goto out_free;
1883 }
1884
1885 return r;
1886
1887out_free:
1888 unregister_reboot_notifier(&kvm_reboot_notifier);
1889 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
1890 kvm_arch_ops->hardware_unsetup();
1891 return r;
1892}
1893
1894void kvm_exit_arch(void)
1895{
1896 misc_deregister(&kvm_dev);
1897
1898 unregister_reboot_notifier(&kvm_reboot_notifier);
1899 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
1900 kvm_arch_ops->hardware_unsetup();
1901}
1902
1903static __init int kvm_init(void)
1904{
1905 static struct page *bad_page;
1906 int r = 0;
1907
1908 kvm_init_debug();
1909
1910 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) {
1911 r = -ENOMEM;
1912 goto out;
1913 }
1914
1915 bad_page_address = page_to_pfn(bad_page) << PAGE_SHIFT;
1916 memset(__va(bad_page_address), 0, PAGE_SIZE);
1917
1918 return r;
1919
1920out:
1921 kvm_exit_debug();
1922 return r;
1923}
1924
1925static __exit void kvm_exit(void)
1926{
1927 kvm_exit_debug();
1928 __free_page(pfn_to_page(bad_page_address >> PAGE_SHIFT));
1929}
1930
1931module_init(kvm_init)
1932module_exit(kvm_exit)
1933
1934EXPORT_SYMBOL_GPL(kvm_init_arch);
1935EXPORT_SYMBOL_GPL(kvm_exit_arch);
diff --git a/drivers/kvm/kvm_svm.h b/drivers/kvm/kvm_svm.h
new file mode 100644
index 000000000000..7d7f2aa10960
--- /dev/null
+++ b/drivers/kvm/kvm_svm.h
@@ -0,0 +1,44 @@
1#ifndef __KVM_SVM_H
2#define __KVM_SVM_H
3
4#include <linux/types.h>
5#include <linux/list.h>
6#include <asm/msr.h>
7
8#include "svm.h"
9#include "kvm.h"
10
11static const u32 host_save_msrs[] = {
12#ifdef __x86_64__
13 MSR_STAR, MSR_LSTAR, MSR_CSTAR, MSR_SYSCALL_MASK, MSR_KERNEL_GS_BASE,
14 MSR_FS_BASE, MSR_GS_BASE,
15#endif
16 MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
17 MSR_IA32_DEBUGCTLMSR, /*MSR_IA32_LASTBRANCHFROMIP,
18 MSR_IA32_LASTBRANCHTOIP, MSR_IA32_LASTINTFROMIP,MSR_IA32_LASTINTTOIP,*/
19};
20
21#define NR_HOST_SAVE_MSRS (sizeof(host_save_msrs) / sizeof(*host_save_msrs))
22#define NUM_DB_REGS 4
23
24struct vcpu_svm {
25 struct vmcb *vmcb;
26 unsigned long vmcb_pa;
27 struct svm_cpu_data *svm_data;
28 uint64_t asid_generation;
29
30 unsigned long cr0;
31 unsigned long cr4;
32 unsigned long db_regs[NUM_DB_REGS];
33
34 u64 next_rip;
35
36 u64 host_msrs[NR_HOST_SAVE_MSRS];
37 unsigned long host_cr2;
38 unsigned long host_db_regs[NUM_DB_REGS];
39 unsigned long host_dr6;
40 unsigned long host_dr7;
41};
42
43#endif
44
diff --git a/drivers/kvm/kvm_vmx.h b/drivers/kvm/kvm_vmx.h
new file mode 100644
index 000000000000..87e12d2bfa16
--- /dev/null
+++ b/drivers/kvm/kvm_vmx.h
@@ -0,0 +1,14 @@
1#ifndef __KVM_VMX_H
2#define __KVM_VMX_H
3
4#ifdef __x86_64__
5/*
6 * avoid save/load MSR_SYSCALL_MASK and MSR_LSTAR by std vt
7 * mechanism (cpu bug AA24)
8 */
9#define NR_BAD_MSRS 2
10#else
11#define NR_BAD_MSRS 0
12#endif
13
14#endif
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
new file mode 100644
index 000000000000..4e29d9b7211c
--- /dev/null
+++ b/drivers/kvm/mmu.c
@@ -0,0 +1,699 @@
1/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This module enables machines with Intel VT-x extensions to run virtual
5 * machines without emulation or binary translation.
6 *
7 * MMU support
8 *
9 * Copyright (C) 2006 Qumranet, Inc.
10 *
11 * Authors:
12 * Yaniv Kamay <yaniv@qumranet.com>
13 * Avi Kivity <avi@qumranet.com>
14 *
15 * This work is licensed under the terms of the GNU GPL, version 2. See
16 * the COPYING file in the top-level directory.
17 *
18 */
19#include <linux/types.h>
20#include <linux/string.h>
21#include <asm/page.h>
22#include <linux/mm.h>
23#include <linux/highmem.h>
24#include <linux/module.h>
25
26#include "vmx.h"
27#include "kvm.h"
28
29#define pgprintk(x...) do { } while (0)
30
31#define ASSERT(x) \
32 if (!(x)) { \
33 printk(KERN_WARNING "assertion failed %s:%d: %s\n", \
34 __FILE__, __LINE__, #x); \
35 }
36
37#define PT64_ENT_PER_PAGE 512
38#define PT32_ENT_PER_PAGE 1024
39
40#define PT_WRITABLE_SHIFT 1
41
42#define PT_PRESENT_MASK (1ULL << 0)
43#define PT_WRITABLE_MASK (1ULL << PT_WRITABLE_SHIFT)
44#define PT_USER_MASK (1ULL << 2)
45#define PT_PWT_MASK (1ULL << 3)
46#define PT_PCD_MASK (1ULL << 4)
47#define PT_ACCESSED_MASK (1ULL << 5)
48#define PT_DIRTY_MASK (1ULL << 6)
49#define PT_PAGE_SIZE_MASK (1ULL << 7)
50#define PT_PAT_MASK (1ULL << 7)
51#define PT_GLOBAL_MASK (1ULL << 8)
52#define PT64_NX_MASK (1ULL << 63)
53
54#define PT_PAT_SHIFT 7
55#define PT_DIR_PAT_SHIFT 12
56#define PT_DIR_PAT_MASK (1ULL << PT_DIR_PAT_SHIFT)
57
58#define PT32_DIR_PSE36_SIZE 4
59#define PT32_DIR_PSE36_SHIFT 13
60#define PT32_DIR_PSE36_MASK (((1ULL << PT32_DIR_PSE36_SIZE) - 1) << PT32_DIR_PSE36_SHIFT)
61
62
63#define PT32_PTE_COPY_MASK \
64 (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK | \
65 PT_ACCESSED_MASK | PT_DIRTY_MASK | PT_PAT_MASK | \
66 PT_GLOBAL_MASK )
67
68#define PT32_NON_PTE_COPY_MASK \
69 (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK | \
70 PT_ACCESSED_MASK | PT_DIRTY_MASK)
71
72
73#define PT64_PTE_COPY_MASK \
74 (PT64_NX_MASK | PT32_PTE_COPY_MASK)
75
76#define PT64_NON_PTE_COPY_MASK \
77 (PT64_NX_MASK | PT32_NON_PTE_COPY_MASK)
78
79
80
81#define PT_FIRST_AVAIL_BITS_SHIFT 9
82#define PT64_SECOND_AVAIL_BITS_SHIFT 52
83
84#define PT_SHADOW_PS_MARK (1ULL << PT_FIRST_AVAIL_BITS_SHIFT)
85#define PT_SHADOW_IO_MARK (1ULL << PT_FIRST_AVAIL_BITS_SHIFT)
86
87#define PT_SHADOW_WRITABLE_SHIFT (PT_FIRST_AVAIL_BITS_SHIFT + 1)
88#define PT_SHADOW_WRITABLE_MASK (1ULL << PT_SHADOW_WRITABLE_SHIFT)
89
90#define PT_SHADOW_USER_SHIFT (PT_SHADOW_WRITABLE_SHIFT + 1)
91#define PT_SHADOW_USER_MASK (1ULL << (PT_SHADOW_USER_SHIFT))
92
93#define PT_SHADOW_BITS_OFFSET (PT_SHADOW_WRITABLE_SHIFT - PT_WRITABLE_SHIFT)
94
95#define VALID_PAGE(x) ((x) != INVALID_PAGE)
96
97#define PT64_LEVEL_BITS 9
98
99#define PT64_LEVEL_SHIFT(level) \
100 ( PAGE_SHIFT + (level - 1) * PT64_LEVEL_BITS )
101
102#define PT64_LEVEL_MASK(level) \
103 (((1ULL << PT64_LEVEL_BITS) - 1) << PT64_LEVEL_SHIFT(level))
104
105#define PT64_INDEX(address, level)\
106 (((address) >> PT64_LEVEL_SHIFT(level)) & ((1 << PT64_LEVEL_BITS) - 1))
107
108
109#define PT32_LEVEL_BITS 10
110
111#define PT32_LEVEL_SHIFT(level) \
112 ( PAGE_SHIFT + (level - 1) * PT32_LEVEL_BITS )
113
114#define PT32_LEVEL_MASK(level) \
115 (((1ULL << PT32_LEVEL_BITS) - 1) << PT32_LEVEL_SHIFT(level))
116
117#define PT32_INDEX(address, level)\
118 (((address) >> PT32_LEVEL_SHIFT(level)) & ((1 << PT32_LEVEL_BITS) - 1))
119
120
121#define PT64_BASE_ADDR_MASK (((1ULL << 52) - 1) & PAGE_MASK)
122#define PT64_DIR_BASE_ADDR_MASK \
123 (PT64_BASE_ADDR_MASK & ~((1ULL << (PAGE_SHIFT + PT64_LEVEL_BITS)) - 1))
124
125#define PT32_BASE_ADDR_MASK PAGE_MASK
126#define PT32_DIR_BASE_ADDR_MASK \
127 (PAGE_MASK & ~((1ULL << (PAGE_SHIFT + PT32_LEVEL_BITS)) - 1))
128
129
130#define PFERR_PRESENT_MASK (1U << 0)
131#define PFERR_WRITE_MASK (1U << 1)
132#define PFERR_USER_MASK (1U << 2)
133
134#define PT64_ROOT_LEVEL 4
135#define PT32_ROOT_LEVEL 2
136#define PT32E_ROOT_LEVEL 3
137
138#define PT_DIRECTORY_LEVEL 2
139#define PT_PAGE_TABLE_LEVEL 1
140
141static int is_write_protection(struct kvm_vcpu *vcpu)
142{
143 return vcpu->cr0 & CR0_WP_MASK;
144}
145
146static int is_cpuid_PSE36(void)
147{
148 return 1;
149}
150
151static int is_present_pte(unsigned long pte)
152{
153 return pte & PT_PRESENT_MASK;
154}
155
156static int is_writeble_pte(unsigned long pte)
157{
158 return pte & PT_WRITABLE_MASK;
159}
160
161static int is_io_pte(unsigned long pte)
162{
163 return pte & PT_SHADOW_IO_MARK;
164}
165
166static void kvm_mmu_free_page(struct kvm_vcpu *vcpu, hpa_t page_hpa)
167{
168 struct kvm_mmu_page *page_head = page_header(page_hpa);
169
170 list_del(&page_head->link);
171 page_head->page_hpa = page_hpa;
172 list_add(&page_head->link, &vcpu->free_pages);
173}
174
175static int is_empty_shadow_page(hpa_t page_hpa)
176{
177 u32 *pos;
178 u32 *end;
179 for (pos = __va(page_hpa), end = pos + PAGE_SIZE / sizeof(u32);
180 pos != end; pos++)
181 if (*pos != 0)
182 return 0;
183 return 1;
184}
185
186static hpa_t kvm_mmu_alloc_page(struct kvm_vcpu *vcpu, u64 *parent_pte)
187{
188 struct kvm_mmu_page *page;
189
190 if (list_empty(&vcpu->free_pages))
191 return INVALID_PAGE;
192
193 page = list_entry(vcpu->free_pages.next, struct kvm_mmu_page, link);
194 list_del(&page->link);
195 list_add(&page->link, &vcpu->kvm->active_mmu_pages);
196 ASSERT(is_empty_shadow_page(page->page_hpa));
197 page->slot_bitmap = 0;
198 page->global = 1;
199 page->parent_pte = parent_pte;
200 return page->page_hpa;
201}
202
203static void page_header_update_slot(struct kvm *kvm, void *pte, gpa_t gpa)
204{
205 int slot = memslot_id(kvm, gfn_to_memslot(kvm, gpa >> PAGE_SHIFT));
206 struct kvm_mmu_page *page_head = page_header(__pa(pte));
207
208 __set_bit(slot, &page_head->slot_bitmap);
209}
210
211hpa_t safe_gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
212{
213 hpa_t hpa = gpa_to_hpa(vcpu, gpa);
214
215 return is_error_hpa(hpa) ? bad_page_address | (gpa & ~PAGE_MASK): hpa;
216}
217
218hpa_t gpa_to_hpa(struct kvm_vcpu *vcpu, gpa_t gpa)
219{
220 struct kvm_memory_slot *slot;
221 struct page *page;
222
223 ASSERT((gpa & HPA_ERR_MASK) == 0);
224 slot = gfn_to_memslot(vcpu->kvm, gpa >> PAGE_SHIFT);
225 if (!slot)
226 return gpa | HPA_ERR_MASK;
227 page = gfn_to_page(slot, gpa >> PAGE_SHIFT);
228 return ((hpa_t)page_to_pfn(page) << PAGE_SHIFT)
229 | (gpa & (PAGE_SIZE-1));
230}
231
232hpa_t gva_to_hpa(struct kvm_vcpu *vcpu, gva_t gva)
233{
234 gpa_t gpa = vcpu->mmu.gva_to_gpa(vcpu, gva);
235
236 if (gpa == UNMAPPED_GVA)
237 return UNMAPPED_GVA;
238 return gpa_to_hpa(vcpu, gpa);
239}
240
241
242static void release_pt_page_64(struct kvm_vcpu *vcpu, hpa_t page_hpa,
243 int level)
244{
245 ASSERT(vcpu);
246 ASSERT(VALID_PAGE(page_hpa));
247 ASSERT(level <= PT64_ROOT_LEVEL && level > 0);
248
249 if (level == 1)
250 memset(__va(page_hpa), 0, PAGE_SIZE);
251 else {
252 u64 *pos;
253 u64 *end;
254
255 for (pos = __va(page_hpa), end = pos + PT64_ENT_PER_PAGE;
256 pos != end; pos++) {
257 u64 current_ent = *pos;
258
259 *pos = 0;
260 if (is_present_pte(current_ent))
261 release_pt_page_64(vcpu,
262 current_ent &
263 PT64_BASE_ADDR_MASK,
264 level - 1);
265 }
266 }
267 kvm_mmu_free_page(vcpu, page_hpa);
268}
269
270static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
271{
272}
273
274static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, hpa_t p)
275{
276 int level = PT32E_ROOT_LEVEL;
277 hpa_t table_addr = vcpu->mmu.root_hpa;
278
279 for (; ; level--) {
280 u32 index = PT64_INDEX(v, level);
281 u64 *table;
282
283 ASSERT(VALID_PAGE(table_addr));
284 table = __va(table_addr);
285
286 if (level == 1) {
287 mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
288 page_header_update_slot(vcpu->kvm, table, v);
289 table[index] = p | PT_PRESENT_MASK | PT_WRITABLE_MASK |
290 PT_USER_MASK;
291 return 0;
292 }
293
294 if (table[index] == 0) {
295 hpa_t new_table = kvm_mmu_alloc_page(vcpu,
296 &table[index]);
297
298 if (!VALID_PAGE(new_table)) {
299 pgprintk("nonpaging_map: ENOMEM\n");
300 return -ENOMEM;
301 }
302
303 if (level == PT32E_ROOT_LEVEL)
304 table[index] = new_table | PT_PRESENT_MASK;
305 else
306 table[index] = new_table | PT_PRESENT_MASK |
307 PT_WRITABLE_MASK | PT_USER_MASK;
308 }
309 table_addr = table[index] & PT64_BASE_ADDR_MASK;
310 }
311}
312
313static void nonpaging_flush(struct kvm_vcpu *vcpu)
314{
315 hpa_t root = vcpu->mmu.root_hpa;
316
317 ++kvm_stat.tlb_flush;
318 pgprintk("nonpaging_flush\n");
319 ASSERT(VALID_PAGE(root));
320 release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level);
321 root = kvm_mmu_alloc_page(vcpu, NULL);
322 ASSERT(VALID_PAGE(root));
323 vcpu->mmu.root_hpa = root;
324 if (is_paging(vcpu))
325 root |= (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK));
326 kvm_arch_ops->set_cr3(vcpu, root);
327 kvm_arch_ops->tlb_flush(vcpu);
328}
329
330static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
331{
332 return vaddr;
333}
334
335static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
336 u32 error_code)
337{
338 int ret;
339 gpa_t addr = gva;
340
341 ASSERT(vcpu);
342 ASSERT(VALID_PAGE(vcpu->mmu.root_hpa));
343
344 for (;;) {
345 hpa_t paddr;
346
347 paddr = gpa_to_hpa(vcpu , addr & PT64_BASE_ADDR_MASK);
348
349 if (is_error_hpa(paddr))
350 return 1;
351
352 ret = nonpaging_map(vcpu, addr & PAGE_MASK, paddr);
353 if (ret) {
354 nonpaging_flush(vcpu);
355 continue;
356 }
357 break;
358 }
359 return ret;
360}
361
362static void nonpaging_inval_page(struct kvm_vcpu *vcpu, gva_t addr)
363{
364}
365
366static void nonpaging_free(struct kvm_vcpu *vcpu)
367{
368 hpa_t root;
369
370 ASSERT(vcpu);
371 root = vcpu->mmu.root_hpa;
372 if (VALID_PAGE(root))
373 release_pt_page_64(vcpu, root, vcpu->mmu.shadow_root_level);
374 vcpu->mmu.root_hpa = INVALID_PAGE;
375}
376
377static int nonpaging_init_context(struct kvm_vcpu *vcpu)
378{
379 struct kvm_mmu *context = &vcpu->mmu;
380
381 context->new_cr3 = nonpaging_new_cr3;
382 context->page_fault = nonpaging_page_fault;
383 context->inval_page = nonpaging_inval_page;
384 context->gva_to_gpa = nonpaging_gva_to_gpa;
385 context->free = nonpaging_free;
386 context->root_level = PT32E_ROOT_LEVEL;
387 context->shadow_root_level = PT32E_ROOT_LEVEL;
388 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
389 ASSERT(VALID_PAGE(context->root_hpa));
390 kvm_arch_ops->set_cr3(vcpu, context->root_hpa);
391 return 0;
392}
393
394
395static void kvm_mmu_flush_tlb(struct kvm_vcpu *vcpu)
396{
397 struct kvm_mmu_page *page, *npage;
398
399 list_for_each_entry_safe(page, npage, &vcpu->kvm->active_mmu_pages,
400 link) {
401 if (page->global)
402 continue;
403
404 if (!page->parent_pte)
405 continue;
406
407 *page->parent_pte = 0;
408 release_pt_page_64(vcpu, page->page_hpa, 1);
409 }
410 ++kvm_stat.tlb_flush;
411 kvm_arch_ops->tlb_flush(vcpu);
412}
413
414static void paging_new_cr3(struct kvm_vcpu *vcpu)
415{
416 kvm_mmu_flush_tlb(vcpu);
417}
418
419static void mark_pagetable_nonglobal(void *shadow_pte)
420{
421 page_header(__pa(shadow_pte))->global = 0;
422}
423
424static inline void set_pte_common(struct kvm_vcpu *vcpu,
425 u64 *shadow_pte,
426 gpa_t gaddr,
427 int dirty,
428 u64 access_bits)
429{
430 hpa_t paddr;
431
432 *shadow_pte |= access_bits << PT_SHADOW_BITS_OFFSET;
433 if (!dirty)
434 access_bits &= ~PT_WRITABLE_MASK;
435
436 if (access_bits & PT_WRITABLE_MASK)
437 mark_page_dirty(vcpu->kvm, gaddr >> PAGE_SHIFT);
438
439 *shadow_pte |= access_bits;
440
441 paddr = gpa_to_hpa(vcpu, gaddr & PT64_BASE_ADDR_MASK);
442
443 if (!(*shadow_pte & PT_GLOBAL_MASK))
444 mark_pagetable_nonglobal(shadow_pte);
445
446 if (is_error_hpa(paddr)) {
447 *shadow_pte |= gaddr;
448 *shadow_pte |= PT_SHADOW_IO_MARK;
449 *shadow_pte &= ~PT_PRESENT_MASK;
450 } else {
451 *shadow_pte |= paddr;
452 page_header_update_slot(vcpu->kvm, shadow_pte, gaddr);
453 }
454}
455
456static void inject_page_fault(struct kvm_vcpu *vcpu,
457 u64 addr,
458 u32 err_code)
459{
460 kvm_arch_ops->inject_page_fault(vcpu, addr, err_code);
461}
462
463static inline int fix_read_pf(u64 *shadow_ent)
464{
465 if ((*shadow_ent & PT_SHADOW_USER_MASK) &&
466 !(*shadow_ent & PT_USER_MASK)) {
467 /*
468 * If supervisor write protect is disabled, we shadow kernel
469 * pages as user pages so we can trap the write access.
470 */
471 *shadow_ent |= PT_USER_MASK;
472 *shadow_ent &= ~PT_WRITABLE_MASK;
473
474 return 1;
475
476 }
477 return 0;
478}
479
480static int may_access(u64 pte, int write, int user)
481{
482
483 if (user && !(pte & PT_USER_MASK))
484 return 0;
485 if (write && !(pte & PT_WRITABLE_MASK))
486 return 0;
487 return 1;
488}
489
490/*
491 * Remove a shadow pte.
492 */
493static void paging_inval_page(struct kvm_vcpu *vcpu, gva_t addr)
494{
495 hpa_t page_addr = vcpu->mmu.root_hpa;
496 int level = vcpu->mmu.shadow_root_level;
497
498 ++kvm_stat.invlpg;
499
500 for (; ; level--) {
501 u32 index = PT64_INDEX(addr, level);
502 u64 *table = __va(page_addr);
503
504 if (level == PT_PAGE_TABLE_LEVEL ) {
505 table[index] = 0;
506 return;
507 }
508
509 if (!is_present_pte(table[index]))
510 return;
511
512 page_addr = table[index] & PT64_BASE_ADDR_MASK;
513
514 if (level == PT_DIRECTORY_LEVEL &&
515 (table[index] & PT_SHADOW_PS_MARK)) {
516 table[index] = 0;
517 release_pt_page_64(vcpu, page_addr, PT_PAGE_TABLE_LEVEL);
518
519 kvm_arch_ops->tlb_flush(vcpu);
520 return;
521 }
522 }
523}
524
525static void paging_free(struct kvm_vcpu *vcpu)
526{
527 nonpaging_free(vcpu);
528}
529
530#define PTTYPE 64
531#include "paging_tmpl.h"
532#undef PTTYPE
533
534#define PTTYPE 32
535#include "paging_tmpl.h"
536#undef PTTYPE
537
538static int paging64_init_context(struct kvm_vcpu *vcpu)
539{
540 struct kvm_mmu *context = &vcpu->mmu;
541
542 ASSERT(is_pae(vcpu));
543 context->new_cr3 = paging_new_cr3;
544 context->page_fault = paging64_page_fault;
545 context->inval_page = paging_inval_page;
546 context->gva_to_gpa = paging64_gva_to_gpa;
547 context->free = paging_free;
548 context->root_level = PT64_ROOT_LEVEL;
549 context->shadow_root_level = PT64_ROOT_LEVEL;
550 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
551 ASSERT(VALID_PAGE(context->root_hpa));
552 kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
553 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
554 return 0;
555}
556
557static int paging32_init_context(struct kvm_vcpu *vcpu)
558{
559 struct kvm_mmu *context = &vcpu->mmu;
560
561 context->new_cr3 = paging_new_cr3;
562 context->page_fault = paging32_page_fault;
563 context->inval_page = paging_inval_page;
564 context->gva_to_gpa = paging32_gva_to_gpa;
565 context->free = paging_free;
566 context->root_level = PT32_ROOT_LEVEL;
567 context->shadow_root_level = PT32E_ROOT_LEVEL;
568 context->root_hpa = kvm_mmu_alloc_page(vcpu, NULL);
569 ASSERT(VALID_PAGE(context->root_hpa));
570 kvm_arch_ops->set_cr3(vcpu, context->root_hpa |
571 (vcpu->cr3 & (CR3_PCD_MASK | CR3_WPT_MASK)));
572 return 0;
573}
574
575static int paging32E_init_context(struct kvm_vcpu *vcpu)
576{
577 int ret;
578
579 if ((ret = paging64_init_context(vcpu)))
580 return ret;
581
582 vcpu->mmu.root_level = PT32E_ROOT_LEVEL;
583 vcpu->mmu.shadow_root_level = PT32E_ROOT_LEVEL;
584 return 0;
585}
586
587static int init_kvm_mmu(struct kvm_vcpu *vcpu)
588{
589 ASSERT(vcpu);
590 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
591
592 if (!is_paging(vcpu))
593 return nonpaging_init_context(vcpu);
594 else if (kvm_arch_ops->is_long_mode(vcpu))
595 return paging64_init_context(vcpu);
596 else if (is_pae(vcpu))
597 return paging32E_init_context(vcpu);
598 else
599 return paging32_init_context(vcpu);
600}
601
602static void destroy_kvm_mmu(struct kvm_vcpu *vcpu)
603{
604 ASSERT(vcpu);
605 if (VALID_PAGE(vcpu->mmu.root_hpa)) {
606 vcpu->mmu.free(vcpu);
607 vcpu->mmu.root_hpa = INVALID_PAGE;
608 }
609}
610
611int kvm_mmu_reset_context(struct kvm_vcpu *vcpu)
612{
613 destroy_kvm_mmu(vcpu);
614 return init_kvm_mmu(vcpu);
615}
616
617static void free_mmu_pages(struct kvm_vcpu *vcpu)
618{
619 while (!list_empty(&vcpu->free_pages)) {
620 struct kvm_mmu_page *page;
621
622 page = list_entry(vcpu->free_pages.next,
623 struct kvm_mmu_page, link);
624 list_del(&page->link);
625 __free_page(pfn_to_page(page->page_hpa >> PAGE_SHIFT));
626 page->page_hpa = INVALID_PAGE;
627 }
628}
629
630static int alloc_mmu_pages(struct kvm_vcpu *vcpu)
631{
632 int i;
633
634 ASSERT(vcpu);
635
636 for (i = 0; i < KVM_NUM_MMU_PAGES; i++) {
637 struct page *page;
638 struct kvm_mmu_page *page_header = &vcpu->page_header_buf[i];
639
640 INIT_LIST_HEAD(&page_header->link);
641 if ((page = alloc_page(GFP_KVM_MMU)) == NULL)
642 goto error_1;
643 page->private = (unsigned long)page_header;
644 page_header->page_hpa = (hpa_t)page_to_pfn(page) << PAGE_SHIFT;
645 memset(__va(page_header->page_hpa), 0, PAGE_SIZE);
646 list_add(&page_header->link, &vcpu->free_pages);
647 }
648 return 0;
649
650error_1:
651 free_mmu_pages(vcpu);
652 return -ENOMEM;
653}
654
655int kvm_mmu_init(struct kvm_vcpu *vcpu)
656{
657 int r;
658
659 ASSERT(vcpu);
660 ASSERT(!VALID_PAGE(vcpu->mmu.root_hpa));
661 ASSERT(list_empty(&vcpu->free_pages));
662
663 if ((r = alloc_mmu_pages(vcpu)))
664 return r;
665
666 if ((r = init_kvm_mmu(vcpu))) {
667 free_mmu_pages(vcpu);
668 return r;
669 }
670 return 0;
671}
672
673void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
674{
675 ASSERT(vcpu);
676
677 destroy_kvm_mmu(vcpu);
678 free_mmu_pages(vcpu);
679}
680
681void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
682{
683 struct kvm_mmu_page *page;
684
685 list_for_each_entry(page, &kvm->active_mmu_pages, link) {
686 int i;
687 u64 *pt;
688
689 if (!test_bit(slot, &page->slot_bitmap))
690 continue;
691
692 pt = __va(page->page_hpa);
693 for (i = 0; i < PT64_ENT_PER_PAGE; ++i)
694 /* avoid RMW */
695 if (pt[i] & PT_WRITABLE_MASK)
696 pt[i] &= ~PT_WRITABLE_MASK;
697
698 }
699}
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
new file mode 100644
index 000000000000..765c2e1a048e
--- /dev/null
+++ b/drivers/kvm/paging_tmpl.h
@@ -0,0 +1,397 @@
1/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This module enables machines with Intel VT-x extensions to run virtual
5 * machines without emulation or binary translation.
6 *
7 * MMU support
8 *
9 * Copyright (C) 2006 Qumranet, Inc.
10 *
11 * Authors:
12 * Yaniv Kamay <yaniv@qumranet.com>
13 * Avi Kivity <avi@qumranet.com>
14 *
15 * This work is licensed under the terms of the GNU GPL, version 2. See
16 * the COPYING file in the top-level directory.
17 *
18 */
19
20/*
21 * We need the mmu code to access both 32-bit and 64-bit guest ptes,
22 * so the code in this file is compiled twice, once per pte size.
23 */
24
25#if PTTYPE == 64
26 #define pt_element_t u64
27 #define guest_walker guest_walker64
28 #define FNAME(name) paging##64_##name
29 #define PT_BASE_ADDR_MASK PT64_BASE_ADDR_MASK
30 #define PT_DIR_BASE_ADDR_MASK PT64_DIR_BASE_ADDR_MASK
31 #define PT_INDEX(addr, level) PT64_INDEX(addr, level)
32 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level)
33 #define PT_LEVEL_MASK(level) PT64_LEVEL_MASK(level)
34 #define PT_PTE_COPY_MASK PT64_PTE_COPY_MASK
35 #define PT_NON_PTE_COPY_MASK PT64_NON_PTE_COPY_MASK
36#elif PTTYPE == 32
37 #define pt_element_t u32
38 #define guest_walker guest_walker32
39 #define FNAME(name) paging##32_##name
40 #define PT_BASE_ADDR_MASK PT32_BASE_ADDR_MASK
41 #define PT_DIR_BASE_ADDR_MASK PT32_DIR_BASE_ADDR_MASK
42 #define PT_INDEX(addr, level) PT32_INDEX(addr, level)
43 #define SHADOW_PT_INDEX(addr, level) PT64_INDEX(addr, level)
44 #define PT_LEVEL_MASK(level) PT32_LEVEL_MASK(level)
45 #define PT_PTE_COPY_MASK PT32_PTE_COPY_MASK
46 #define PT_NON_PTE_COPY_MASK PT32_NON_PTE_COPY_MASK
47#else
48 #error Invalid PTTYPE value
49#endif
50
51/*
52 * The guest_walker structure emulates the behavior of the hardware page
53 * table walker.
54 */
55struct guest_walker {
56 int level;
57 pt_element_t *table;
58 pt_element_t inherited_ar;
59};
60
61static void FNAME(init_walker)(struct guest_walker *walker,
62 struct kvm_vcpu *vcpu)
63{
64 hpa_t hpa;
65 struct kvm_memory_slot *slot;
66
67 walker->level = vcpu->mmu.root_level;
68 slot = gfn_to_memslot(vcpu->kvm,
69 (vcpu->cr3 & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT);
70 hpa = safe_gpa_to_hpa(vcpu, vcpu->cr3 & PT64_BASE_ADDR_MASK);
71 walker->table = kmap_atomic(pfn_to_page(hpa >> PAGE_SHIFT), KM_USER0);
72
73 ASSERT((!kvm_arch_ops->is_long_mode(vcpu) && is_pae(vcpu)) ||
74 (vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) == 0);
75
76 walker->table = (pt_element_t *)( (unsigned long)walker->table |
77 (unsigned long)(vcpu->cr3 & ~(PAGE_MASK | CR3_FLAGS_MASK)) );
78 walker->inherited_ar = PT_USER_MASK | PT_WRITABLE_MASK;
79}
80
81static void FNAME(release_walker)(struct guest_walker *walker)
82{
83 kunmap_atomic(walker->table, KM_USER0);
84}
85
86static void FNAME(set_pte)(struct kvm_vcpu *vcpu, u64 guest_pte,
87 u64 *shadow_pte, u64 access_bits)
88{
89 ASSERT(*shadow_pte == 0);
90 access_bits &= guest_pte;
91 *shadow_pte = (guest_pte & PT_PTE_COPY_MASK);
92 set_pte_common(vcpu, shadow_pte, guest_pte & PT_BASE_ADDR_MASK,
93 guest_pte & PT_DIRTY_MASK, access_bits);
94}
95
96static void FNAME(set_pde)(struct kvm_vcpu *vcpu, u64 guest_pde,
97 u64 *shadow_pte, u64 access_bits,
98 int index)
99{
100 gpa_t gaddr;
101
102 ASSERT(*shadow_pte == 0);
103 access_bits &= guest_pde;
104 gaddr = (guest_pde & PT_DIR_BASE_ADDR_MASK) + PAGE_SIZE * index;
105 if (PTTYPE == 32 && is_cpuid_PSE36())
106 gaddr |= (guest_pde & PT32_DIR_PSE36_MASK) <<
107 (32 - PT32_DIR_PSE36_SHIFT);
108 *shadow_pte = (guest_pde & (PT_NON_PTE_COPY_MASK | PT_GLOBAL_MASK)) |
109 ((guest_pde & PT_DIR_PAT_MASK) >>
110 (PT_DIR_PAT_SHIFT - PT_PAT_SHIFT));
111 set_pte_common(vcpu, shadow_pte, gaddr,
112 guest_pde & PT_DIRTY_MASK, access_bits);
113}
114
115/*
116 * Fetch a guest pte from a specific level in the paging hierarchy.
117 */
118static pt_element_t *FNAME(fetch_guest)(struct kvm_vcpu *vcpu,
119 struct guest_walker *walker,
120 int level,
121 gva_t addr)
122{
123
124 ASSERT(level > 0 && level <= walker->level);
125
126 for (;;) {
127 int index = PT_INDEX(addr, walker->level);
128 hpa_t paddr;
129
130 ASSERT(((unsigned long)walker->table & PAGE_MASK) ==
131 ((unsigned long)&walker->table[index] & PAGE_MASK));
132 if (level == walker->level ||
133 !is_present_pte(walker->table[index]) ||
134 (walker->level == PT_DIRECTORY_LEVEL &&
135 (walker->table[index] & PT_PAGE_SIZE_MASK) &&
136 (PTTYPE == 64 || is_pse(vcpu))))
137 return &walker->table[index];
138 if (walker->level != 3 || kvm_arch_ops->is_long_mode(vcpu))
139 walker->inherited_ar &= walker->table[index];
140 paddr = safe_gpa_to_hpa(vcpu, walker->table[index] & PT_BASE_ADDR_MASK);
141 kunmap_atomic(walker->table, KM_USER0);
142 walker->table = kmap_atomic(pfn_to_page(paddr >> PAGE_SHIFT),
143 KM_USER0);
144 --walker->level;
145 }
146}
147
148/*
149 * Fetch a shadow pte for a specific level in the paging hierarchy.
150 */
151static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
152 struct guest_walker *walker)
153{
154 hpa_t shadow_addr;
155 int level;
156 u64 *prev_shadow_ent = NULL;
157
158 shadow_addr = vcpu->mmu.root_hpa;
159 level = vcpu->mmu.shadow_root_level;
160
161 for (; ; level--) {
162 u32 index = SHADOW_PT_INDEX(addr, level);
163 u64 *shadow_ent = ((u64 *)__va(shadow_addr)) + index;
164 pt_element_t *guest_ent;
165
166 if (is_present_pte(*shadow_ent) || is_io_pte(*shadow_ent)) {
167 if (level == PT_PAGE_TABLE_LEVEL)
168 return shadow_ent;
169 shadow_addr = *shadow_ent & PT64_BASE_ADDR_MASK;
170 prev_shadow_ent = shadow_ent;
171 continue;
172 }
173
174 if (PTTYPE == 32 && level > PT32_ROOT_LEVEL) {
175 ASSERT(level == PT32E_ROOT_LEVEL);
176 guest_ent = FNAME(fetch_guest)(vcpu, walker,
177 PT32_ROOT_LEVEL, addr);
178 } else
179 guest_ent = FNAME(fetch_guest)(vcpu, walker,
180 level, addr);
181
182 if (!is_present_pte(*guest_ent))
183 return NULL;
184
185 /* Don't set accessed bit on PAE PDPTRs */
186 if (vcpu->mmu.root_level != 3 || walker->level != 3)
187 *guest_ent |= PT_ACCESSED_MASK;
188
189 if (level == PT_PAGE_TABLE_LEVEL) {
190
191 if (walker->level == PT_DIRECTORY_LEVEL) {
192 if (prev_shadow_ent)
193 *prev_shadow_ent |= PT_SHADOW_PS_MARK;
194 FNAME(set_pde)(vcpu, *guest_ent, shadow_ent,
195 walker->inherited_ar,
196 PT_INDEX(addr, PT_PAGE_TABLE_LEVEL));
197 } else {
198 ASSERT(walker->level == PT_PAGE_TABLE_LEVEL);
199 FNAME(set_pte)(vcpu, *guest_ent, shadow_ent, walker->inherited_ar);
200 }
201 return shadow_ent;
202 }
203
204 shadow_addr = kvm_mmu_alloc_page(vcpu, shadow_ent);
205 if (!VALID_PAGE(shadow_addr))
206 return ERR_PTR(-ENOMEM);
207 if (!kvm_arch_ops->is_long_mode(vcpu) && level == 3)
208 *shadow_ent = shadow_addr |
209 (*guest_ent & (PT_PRESENT_MASK | PT_PWT_MASK | PT_PCD_MASK));
210 else {
211 *shadow_ent = shadow_addr |
212 (*guest_ent & PT_NON_PTE_COPY_MASK);
213 *shadow_ent |= (PT_WRITABLE_MASK | PT_USER_MASK);
214 }
215 prev_shadow_ent = shadow_ent;
216 }
217}
218
219/*
220 * The guest faulted for write. We need to
221 *
222 * - check write permissions
223 * - update the guest pte dirty bit
224 * - update our own dirty page tracking structures
225 */
226static int FNAME(fix_write_pf)(struct kvm_vcpu *vcpu,
227 u64 *shadow_ent,
228 struct guest_walker *walker,
229 gva_t addr,
230 int user)
231{
232 pt_element_t *guest_ent;
233 int writable_shadow;
234 gfn_t gfn;
235
236 if (is_writeble_pte(*shadow_ent))
237 return 0;
238
239 writable_shadow = *shadow_ent & PT_SHADOW_WRITABLE_MASK;
240 if (user) {
241 /*
242 * User mode access. Fail if it's a kernel page or a read-only
243 * page.
244 */
245 if (!(*shadow_ent & PT_SHADOW_USER_MASK) || !writable_shadow)
246 return 0;
247 ASSERT(*shadow_ent & PT_USER_MASK);
248 } else
249 /*
250 * Kernel mode access. Fail if it's a read-only page and
251 * supervisor write protection is enabled.
252 */
253 if (!writable_shadow) {
254 if (is_write_protection(vcpu))
255 return 0;
256 *shadow_ent &= ~PT_USER_MASK;
257 }
258
259 guest_ent = FNAME(fetch_guest)(vcpu, walker, PT_PAGE_TABLE_LEVEL, addr);
260
261 if (!is_present_pte(*guest_ent)) {
262 *shadow_ent = 0;
263 return 0;
264 }
265
266 gfn = (*guest_ent & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
267 mark_page_dirty(vcpu->kvm, gfn);
268 *shadow_ent |= PT_WRITABLE_MASK;
269 *guest_ent |= PT_DIRTY_MASK;
270
271 return 1;
272}
273
274/*
275 * Page fault handler. There are several causes for a page fault:
276 * - there is no shadow pte for the guest pte
277 * - write access through a shadow pte marked read only so that we can set
278 * the dirty bit
279 * - write access to a shadow pte marked read only so we can update the page
280 * dirty bitmap, when userspace requests it
281 * - mmio access; in this case we will never install a present shadow pte
282 * - normal guest page fault due to the guest pte marked not present, not
283 * writable, or not executable
284 *
285 * Returns: 1 if we need to emulate the instruction, 0 otherwise
286 */
287static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
288 u32 error_code)
289{
290 int write_fault = error_code & PFERR_WRITE_MASK;
291 int pte_present = error_code & PFERR_PRESENT_MASK;
292 int user_fault = error_code & PFERR_USER_MASK;
293 struct guest_walker walker;
294 u64 *shadow_pte;
295 int fixed;
296
297 /*
298 * Look up the shadow pte for the faulting address.
299 */
300 for (;;) {
301 FNAME(init_walker)(&walker, vcpu);
302 shadow_pte = FNAME(fetch)(vcpu, addr, &walker);
303 if (IS_ERR(shadow_pte)) { /* must be -ENOMEM */
304 nonpaging_flush(vcpu);
305 FNAME(release_walker)(&walker);
306 continue;
307 }
308 break;
309 }
310
311 /*
312 * The page is not mapped by the guest. Let the guest handle it.
313 */
314 if (!shadow_pte) {
315 inject_page_fault(vcpu, addr, error_code);
316 FNAME(release_walker)(&walker);
317 return 0;
318 }
319
320 /*
321 * Update the shadow pte.
322 */
323 if (write_fault)
324 fixed = FNAME(fix_write_pf)(vcpu, shadow_pte, &walker, addr,
325 user_fault);
326 else
327 fixed = fix_read_pf(shadow_pte);
328
329 FNAME(release_walker)(&walker);
330
331 /*
332 * mmio: emulate if accessible, otherwise its a guest fault.
333 */
334 if (is_io_pte(*shadow_pte)) {
335 if (may_access(*shadow_pte, write_fault, user_fault))
336 return 1;
337 pgprintk("%s: io work, no access\n", __FUNCTION__);
338 inject_page_fault(vcpu, addr,
339 error_code | PFERR_PRESENT_MASK);
340 return 0;
341 }
342
343 /*
344 * pte not present, guest page fault.
345 */
346 if (pte_present && !fixed) {
347 inject_page_fault(vcpu, addr, error_code);
348 return 0;
349 }
350
351 ++kvm_stat.pf_fixed;
352
353 return 0;
354}
355
356static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
357{
358 struct guest_walker walker;
359 pt_element_t guest_pte;
360 gpa_t gpa;
361
362 FNAME(init_walker)(&walker, vcpu);
363 guest_pte = *FNAME(fetch_guest)(vcpu, &walker, PT_PAGE_TABLE_LEVEL,
364 vaddr);
365 FNAME(release_walker)(&walker);
366
367 if (!is_present_pte(guest_pte))
368 return UNMAPPED_GVA;
369
370 if (walker.level == PT_DIRECTORY_LEVEL) {
371 ASSERT((guest_pte & PT_PAGE_SIZE_MASK));
372 ASSERT(PTTYPE == 64 || is_pse(vcpu));
373
374 gpa = (guest_pte & PT_DIR_BASE_ADDR_MASK) | (vaddr &
375 (PT_LEVEL_MASK(PT_PAGE_TABLE_LEVEL) | ~PAGE_MASK));
376
377 if (PTTYPE == 32 && is_cpuid_PSE36())
378 gpa |= (guest_pte & PT32_DIR_PSE36_MASK) <<
379 (32 - PT32_DIR_PSE36_SHIFT);
380 } else {
381 gpa = (guest_pte & PT_BASE_ADDR_MASK);
382 gpa |= (vaddr & ~PAGE_MASK);
383 }
384
385 return gpa;
386}
387
388#undef pt_element_t
389#undef guest_walker
390#undef FNAME
391#undef PT_BASE_ADDR_MASK
392#undef PT_INDEX
393#undef SHADOW_PT_INDEX
394#undef PT_LEVEL_MASK
395#undef PT_PTE_COPY_MASK
396#undef PT_NON_PTE_COPY_MASK
397#undef PT_DIR_BASE_ADDR_MASK
diff --git a/drivers/kvm/segment_descriptor.h b/drivers/kvm/segment_descriptor.h
new file mode 100644
index 000000000000..71fdf458619a
--- /dev/null
+++ b/drivers/kvm/segment_descriptor.h
@@ -0,0 +1,17 @@
1struct segment_descriptor {
2 u16 limit_low;
3 u16 base_low;
4 u8 base_mid;
5 u8 type : 4;
6 u8 system : 1;
7 u8 dpl : 2;
8 u8 present : 1;
9 u8 limit_high : 4;
10 u8 avl : 1;
11 u8 long_mode : 1;
12 u8 default_op : 1;
13 u8 granularity : 1;
14 u8 base_high;
15} __attribute__((packed));
16
17
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
new file mode 100644
index 000000000000..a33a89c68138
--- /dev/null
+++ b/drivers/kvm/svm.c
@@ -0,0 +1,1677 @@
1/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * AMD SVM support
5 *
6 * Copyright (C) 2006 Qumranet, Inc.
7 *
8 * Authors:
9 * Yaniv Kamay <yaniv@qumranet.com>
10 * Avi Kivity <avi@qumranet.com>
11 *
12 * This work is licensed under the terms of the GNU GPL, version 2. See
13 * the COPYING file in the top-level directory.
14 *
15 */
16
17#include <linux/module.h>
18#include <linux/vmalloc.h>
19#include <linux/highmem.h>
20#include <asm/desc.h>
21
22#include "kvm_svm.h"
23#include "x86_emulate.h"
24
25MODULE_AUTHOR("Qumranet");
26MODULE_LICENSE("GPL");
27
28#define IOPM_ALLOC_ORDER 2
29#define MSRPM_ALLOC_ORDER 1
30
31#define DB_VECTOR 1
32#define UD_VECTOR 6
33#define GP_VECTOR 13
34
35#define DR7_GD_MASK (1 << 13)
36#define DR6_BD_MASK (1 << 13)
37#define CR4_DE_MASK (1UL << 3)
38
39#define SEG_TYPE_LDT 2
40#define SEG_TYPE_BUSY_TSS16 3
41
42#define KVM_EFER_LMA (1 << 10)
43#define KVM_EFER_LME (1 << 8)
44
45unsigned long iopm_base;
46unsigned long msrpm_base;
47
48struct kvm_ldttss_desc {
49 u16 limit0;
50 u16 base0;
51 unsigned base1 : 8, type : 5, dpl : 2, p : 1;
52 unsigned limit1 : 4, zero0 : 3, g : 1, base2 : 8;
53 u32 base3;
54 u32 zero1;
55} __attribute__((packed));
56
57struct svm_cpu_data {
58 int cpu;
59
60 uint64_t asid_generation;
61 uint32_t max_asid;
62 uint32_t next_asid;
63 struct kvm_ldttss_desc *tss_desc;
64
65 struct page *save_area;
66};
67
68static DEFINE_PER_CPU(struct svm_cpu_data *, svm_data);
69
70struct svm_init_data {
71 int cpu;
72 int r;
73};
74
75static u32 msrpm_ranges[] = {0, 0xc0000000, 0xc0010000};
76
77#define NUM_MSR_MAPS (sizeof(msrpm_ranges) / sizeof(*msrpm_ranges))
78#define MSRS_RANGE_SIZE 2048
79#define MSRS_IN_RANGE (MSRS_RANGE_SIZE * 8 / 2)
80
81#define MAX_INST_SIZE 15
82
83static unsigned get_addr_size(struct kvm_vcpu *vcpu)
84{
85 struct vmcb_save_area *sa = &vcpu->svm->vmcb->save;
86 u16 cs_attrib;
87
88 if (!(sa->cr0 & CR0_PE_MASK) || (sa->rflags & X86_EFLAGS_VM))
89 return 2;
90
91 cs_attrib = sa->cs.attrib;
92
93 return (cs_attrib & SVM_SELECTOR_L_MASK) ? 8 :
94 (cs_attrib & SVM_SELECTOR_DB_MASK) ? 4 : 2;
95}
96
97static inline u8 pop_irq(struct kvm_vcpu *vcpu)
98{
99 int word_index = __ffs(vcpu->irq_summary);
100 int bit_index = __ffs(vcpu->irq_pending[word_index]);
101 int irq = word_index * BITS_PER_LONG + bit_index;
102
103 clear_bit(bit_index, &vcpu->irq_pending[word_index]);
104 if (!vcpu->irq_pending[word_index])
105 clear_bit(word_index, &vcpu->irq_summary);
106 return irq;
107}
108
109static inline void push_irq(struct kvm_vcpu *vcpu, u8 irq)
110{
111 set_bit(irq, vcpu->irq_pending);
112 set_bit(irq / BITS_PER_LONG, &vcpu->irq_summary);
113}
114
115static inline void clgi(void)
116{
117 asm volatile (SVM_CLGI);
118}
119
120static inline void stgi(void)
121{
122 asm volatile (SVM_STGI);
123}
124
125static inline void invlpga(unsigned long addr, u32 asid)
126{
127 asm volatile (SVM_INVLPGA :: "a"(addr), "c"(asid));
128}
129
130static inline unsigned long kvm_read_cr2(void)
131{
132 unsigned long cr2;
133
134 asm volatile ("mov %%cr2, %0" : "=r" (cr2));
135 return cr2;
136}
137
138static inline void kvm_write_cr2(unsigned long val)
139{
140 asm volatile ("mov %0, %%cr2" :: "r" (val));
141}
142
143static inline unsigned long read_dr6(void)
144{
145 unsigned long dr6;
146
147 asm volatile ("mov %%dr6, %0" : "=r" (dr6));
148 return dr6;
149}
150
151static inline void write_dr6(unsigned long val)
152{
153 asm volatile ("mov %0, %%dr6" :: "r" (val));
154}
155
156static inline unsigned long read_dr7(void)
157{
158 unsigned long dr7;
159
160 asm volatile ("mov %%dr7, %0" : "=r" (dr7));
161 return dr7;
162}
163
164static inline void write_dr7(unsigned long val)
165{
166 asm volatile ("mov %0, %%dr7" :: "r" (val));
167}
168
169static inline int svm_is_long_mode(struct kvm_vcpu *vcpu)
170{
171 return vcpu->svm->vmcb->save.efer & KVM_EFER_LMA;
172}
173
174static inline void force_new_asid(struct kvm_vcpu *vcpu)
175{
176 vcpu->svm->asid_generation--;
177}
178
179static inline void flush_guest_tlb(struct kvm_vcpu *vcpu)
180{
181 force_new_asid(vcpu);
182}
183
184static void svm_set_efer(struct kvm_vcpu *vcpu, u64 efer)
185{
186 if (!(efer & KVM_EFER_LMA))
187 efer &= ~KVM_EFER_LME;
188
189 vcpu->svm->vmcb->save.efer = efer | MSR_EFER_SVME_MASK;
190 vcpu->shadow_efer = efer;
191}
192
193static void svm_inject_gp(struct kvm_vcpu *vcpu, unsigned error_code)
194{
195 vcpu->svm->vmcb->control.event_inj = SVM_EVTINJ_VALID |
196 SVM_EVTINJ_VALID_ERR |
197 SVM_EVTINJ_TYPE_EXEPT |
198 GP_VECTOR;
199 vcpu->svm->vmcb->control.event_inj_err = error_code;
200}
201
202static void inject_ud(struct kvm_vcpu *vcpu)
203{
204 vcpu->svm->vmcb->control.event_inj = SVM_EVTINJ_VALID |
205 SVM_EVTINJ_TYPE_EXEPT |
206 UD_VECTOR;
207}
208
209static void inject_db(struct kvm_vcpu *vcpu)
210{
211 vcpu->svm->vmcb->control.event_inj = SVM_EVTINJ_VALID |
212 SVM_EVTINJ_TYPE_EXEPT |
213 DB_VECTOR;
214}
215
216static int is_page_fault(uint32_t info)
217{
218 info &= SVM_EVTINJ_VEC_MASK | SVM_EVTINJ_TYPE_MASK | SVM_EVTINJ_VALID;
219 return info == (PF_VECTOR | SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_EXEPT);
220}
221
222static int is_external_interrupt(u32 info)
223{
224 info &= SVM_EVTINJ_TYPE_MASK | SVM_EVTINJ_VALID;
225 return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR);
226}
227
228static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
229{
230 if (!vcpu->svm->next_rip) {
231 printk(KERN_DEBUG "%s: NOP\n", __FUNCTION__);
232 return;
233 }
234 if (vcpu->svm->next_rip - vcpu->svm->vmcb->save.rip > 15) {
235 printk(KERN_ERR "%s: ip 0x%llx next 0x%llx\n",
236 __FUNCTION__,
237 vcpu->svm->vmcb->save.rip,
238 vcpu->svm->next_rip);
239 }
240
241 vcpu->rip = vcpu->svm->vmcb->save.rip = vcpu->svm->next_rip;
242 vcpu->svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK;
243}
244
245static int has_svm(void)
246{
247 uint32_t eax, ebx, ecx, edx;
248
249 if (current_cpu_data.x86_vendor != X86_VENDOR_AMD) {
250 printk(KERN_INFO "has_svm: not amd\n");
251 return 0;
252 }
253
254 cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
255 if (eax < SVM_CPUID_FUNC) {
256 printk(KERN_INFO "has_svm: can't execute cpuid_8000000a\n");
257 return 0;
258 }
259
260 cpuid(0x80000001, &eax, &ebx, &ecx, &edx);
261 if (!(ecx & (1 << SVM_CPUID_FEATURE_SHIFT))) {
262 printk(KERN_DEBUG "has_svm: svm not available\n");
263 return 0;
264 }
265 return 1;
266}
267
268static void svm_hardware_disable(void *garbage)
269{
270 struct svm_cpu_data *svm_data
271 = per_cpu(svm_data, raw_smp_processor_id());
272
273 if (svm_data) {
274 uint64_t efer;
275
276 wrmsrl(MSR_VM_HSAVE_PA, 0);
277 rdmsrl(MSR_EFER, efer);
278 wrmsrl(MSR_EFER, efer & ~MSR_EFER_SVME_MASK);
279 per_cpu(svm_data, raw_smp_processor_id()) = 0;
280 __free_page(svm_data->save_area);
281 kfree(svm_data);
282 }
283}
284
285static void svm_hardware_enable(void *garbage)
286{
287
288 struct svm_cpu_data *svm_data;
289 uint64_t efer;
290#ifdef __x86_64__
291 struct desc_ptr gdt_descr;
292#else
293 struct Xgt_desc_struct gdt_descr;
294#endif
295 struct desc_struct *gdt;
296 int me = raw_smp_processor_id();
297
298 if (!has_svm()) {
299 printk(KERN_ERR "svm_cpu_init: err EOPNOTSUPP on %d\n", me);
300 return;
301 }
302 svm_data = per_cpu(svm_data, me);
303
304 if (!svm_data) {
305 printk(KERN_ERR "svm_cpu_init: svm_data is NULL on %d\n",
306 me);
307 return;
308 }
309
310 svm_data->asid_generation = 1;
311 svm_data->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1;
312 svm_data->next_asid = svm_data->max_asid + 1;
313
314 asm volatile ( "sgdt %0" : "=m"(gdt_descr) );
315 gdt = (struct desc_struct *)gdt_descr.address;
316 svm_data->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS);
317
318 rdmsrl(MSR_EFER, efer);
319 wrmsrl(MSR_EFER, efer | MSR_EFER_SVME_MASK);
320
321 wrmsrl(MSR_VM_HSAVE_PA,
322 page_to_pfn(svm_data->save_area) << PAGE_SHIFT);
323}
324
325static int svm_cpu_init(int cpu)
326{
327 struct svm_cpu_data *svm_data;
328 int r;
329
330 svm_data = kzalloc(sizeof(struct svm_cpu_data), GFP_KERNEL);
331 if (!svm_data)
332 return -ENOMEM;
333 svm_data->cpu = cpu;
334 svm_data->save_area = alloc_page(GFP_KERNEL);
335 r = -ENOMEM;
336 if (!svm_data->save_area)
337 goto err_1;
338
339 per_cpu(svm_data, cpu) = svm_data;
340
341 return 0;
342
343err_1:
344 kfree(svm_data);
345 return r;
346
347}
348
349static int set_msr_interception(u32 *msrpm, unsigned msr,
350 int read, int write)
351{
352 int i;
353
354 for (i = 0; i < NUM_MSR_MAPS; i++) {
355 if (msr >= msrpm_ranges[i] &&
356 msr < msrpm_ranges[i] + MSRS_IN_RANGE) {
357 u32 msr_offset = (i * MSRS_IN_RANGE + msr -
358 msrpm_ranges[i]) * 2;
359
360 u32 *base = msrpm + (msr_offset / 32);
361 u32 msr_shift = msr_offset % 32;
362 u32 mask = ((write) ? 0 : 2) | ((read) ? 0 : 1);
363 *base = (*base & ~(0x3 << msr_shift)) |
364 (mask << msr_shift);
365 return 1;
366 }
367 }
368 printk(KERN_DEBUG "%s: not found 0x%x\n", __FUNCTION__, msr);
369 return 0;
370}
371
372static __init int svm_hardware_setup(void)
373{
374 int cpu;
375 struct page *iopm_pages;
376 struct page *msrpm_pages;
377 void *msrpm_va;
378 int r;
379
380
381 iopm_pages = alloc_pages(GFP_KERNEL, IOPM_ALLOC_ORDER);
382
383 if (!iopm_pages)
384 return -ENOMEM;
385 memset(page_address(iopm_pages), 0xff,
386 PAGE_SIZE * (1 << IOPM_ALLOC_ORDER));
387 iopm_base = page_to_pfn(iopm_pages) << PAGE_SHIFT;
388
389
390 msrpm_pages = alloc_pages(GFP_KERNEL, MSRPM_ALLOC_ORDER);
391
392 r = -ENOMEM;
393 if (!msrpm_pages)
394 goto err_1;
395
396 msrpm_va = page_address(msrpm_pages);
397 memset(msrpm_va, 0xff, PAGE_SIZE * (1 << MSRPM_ALLOC_ORDER));
398 msrpm_base = page_to_pfn(msrpm_pages) << PAGE_SHIFT;
399
400#ifdef __x86_64__
401 set_msr_interception(msrpm_va, MSR_GS_BASE, 1, 1);
402 set_msr_interception(msrpm_va, MSR_FS_BASE, 1, 1);
403 set_msr_interception(msrpm_va, MSR_KERNEL_GS_BASE, 1, 1);
404 set_msr_interception(msrpm_va, MSR_STAR, 1, 1);
405 set_msr_interception(msrpm_va, MSR_LSTAR, 1, 1);
406 set_msr_interception(msrpm_va, MSR_CSTAR, 1, 1);
407 set_msr_interception(msrpm_va, MSR_SYSCALL_MASK, 1, 1);
408#endif
409 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_CS, 1, 1);
410 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_ESP, 1, 1);
411 set_msr_interception(msrpm_va, MSR_IA32_SYSENTER_EIP, 1, 1);
412
413 for_each_online_cpu(cpu) {
414 r = svm_cpu_init(cpu);
415 if (r)
416 goto err_2;
417 }
418 return 0;
419
420err_2:
421 __free_pages(msrpm_pages, MSRPM_ALLOC_ORDER);
422 msrpm_base = 0;
423err_1:
424 __free_pages(iopm_pages, IOPM_ALLOC_ORDER);
425 iopm_base = 0;
426 return r;
427}
428
429static __exit void svm_hardware_unsetup(void)
430{
431 __free_pages(pfn_to_page(msrpm_base >> PAGE_SHIFT), MSRPM_ALLOC_ORDER);
432 __free_pages(pfn_to_page(iopm_base >> PAGE_SHIFT), IOPM_ALLOC_ORDER);
433 iopm_base = msrpm_base = 0;
434}
435
436static void init_seg(struct vmcb_seg *seg)
437{
438 seg->selector = 0;
439 seg->attrib = SVM_SELECTOR_P_MASK | SVM_SELECTOR_S_MASK |
440 SVM_SELECTOR_WRITE_MASK; /* Read/Write Data Segment */
441 seg->limit = 0xffff;
442 seg->base = 0;
443}
444
445static void init_sys_seg(struct vmcb_seg *seg, uint32_t type)
446{
447 seg->selector = 0;
448 seg->attrib = SVM_SELECTOR_P_MASK | type;
449 seg->limit = 0xffff;
450 seg->base = 0;
451}
452
453static int svm_vcpu_setup(struct kvm_vcpu *vcpu)
454{
455 return 0;
456}
457
458static void init_vmcb(struct vmcb *vmcb)
459{
460 struct vmcb_control_area *control = &vmcb->control;
461 struct vmcb_save_area *save = &vmcb->save;
462 u64 tsc;
463
464 control->intercept_cr_read = INTERCEPT_CR0_MASK |
465 INTERCEPT_CR3_MASK |
466 INTERCEPT_CR4_MASK;
467
468 control->intercept_cr_write = INTERCEPT_CR0_MASK |
469 INTERCEPT_CR3_MASK |
470 INTERCEPT_CR4_MASK;
471
472 control->intercept_dr_read = INTERCEPT_DR0_MASK |
473 INTERCEPT_DR1_MASK |
474 INTERCEPT_DR2_MASK |
475 INTERCEPT_DR3_MASK;
476
477 control->intercept_dr_write = INTERCEPT_DR0_MASK |
478 INTERCEPT_DR1_MASK |
479 INTERCEPT_DR2_MASK |
480 INTERCEPT_DR3_MASK |
481 INTERCEPT_DR5_MASK |
482 INTERCEPT_DR7_MASK;
483
484 control->intercept_exceptions = 1 << PF_VECTOR;
485
486
487 control->intercept = (1ULL << INTERCEPT_INTR) |
488 (1ULL << INTERCEPT_NMI) |
489 /*
490 * selective cr0 intercept bug?
491 * 0: 0f 22 d8 mov %eax,%cr3
492 * 3: 0f 20 c0 mov %cr0,%eax
493 * 6: 0d 00 00 00 80 or $0x80000000,%eax
494 * b: 0f 22 c0 mov %eax,%cr0
495 * set cr3 ->interception
496 * get cr0 ->interception
497 * set cr0 -> no interception
498 */
499 /* (1ULL << INTERCEPT_SELECTIVE_CR0) | */
500 (1ULL << INTERCEPT_CPUID) |
501 (1ULL << INTERCEPT_HLT) |
502 (1ULL << INTERCEPT_INVLPG) |
503 (1ULL << INTERCEPT_INVLPGA) |
504 (1ULL << INTERCEPT_IOIO_PROT) |
505 (1ULL << INTERCEPT_MSR_PROT) |
506 (1ULL << INTERCEPT_TASK_SWITCH) |
507 (1ULL << INTERCEPT_VMRUN) |
508 (1ULL << INTERCEPT_VMMCALL) |
509 (1ULL << INTERCEPT_VMLOAD) |
510 (1ULL << INTERCEPT_VMSAVE) |
511 (1ULL << INTERCEPT_STGI) |
512 (1ULL << INTERCEPT_CLGI) |
513 (1ULL << INTERCEPT_SKINIT);
514
515 control->iopm_base_pa = iopm_base;
516 control->msrpm_base_pa = msrpm_base;
517 rdtscll(tsc);
518 control->tsc_offset = -tsc;
519 control->int_ctl = V_INTR_MASKING_MASK;
520
521 init_seg(&save->es);
522 init_seg(&save->ss);
523 init_seg(&save->ds);
524 init_seg(&save->fs);
525 init_seg(&save->gs);
526
527 save->cs.selector = 0xf000;
528 /* Executable/Readable Code Segment */
529 save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK |
530 SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK;
531 save->cs.limit = 0xffff;
532 save->cs.base = 0xffff0000;
533
534 save->gdtr.limit = 0xffff;
535 save->idtr.limit = 0xffff;
536
537 init_sys_seg(&save->ldtr, SEG_TYPE_LDT);
538 init_sys_seg(&save->tr, SEG_TYPE_BUSY_TSS16);
539
540 save->efer = MSR_EFER_SVME_MASK;
541
542 save->dr6 = 0xffff0ff0;
543 save->dr7 = 0x400;
544 save->rflags = 2;
545 save->rip = 0x0000fff0;
546
547 /*
548 * cr0 val on cpu init should be 0x60000010, we enable cpu
549 * cache by default. the orderly way is to enable cache in bios.
550 */
551 save->cr0 = 0x00000010 | CR0_PG_MASK;
552 save->cr4 = CR4_PAE_MASK;
553 /* rdx = ?? */
554}
555
556static int svm_create_vcpu(struct kvm_vcpu *vcpu)
557{
558 struct page *page;
559 int r;
560
561 r = -ENOMEM;
562 vcpu->svm = kzalloc(sizeof *vcpu->svm, GFP_KERNEL);
563 if (!vcpu->svm)
564 goto out1;
565 page = alloc_page(GFP_KERNEL);
566 if (!page)
567 goto out2;
568
569 vcpu->svm->vmcb = page_address(page);
570 memset(vcpu->svm->vmcb, 0, PAGE_SIZE);
571 vcpu->svm->vmcb_pa = page_to_pfn(page) << PAGE_SHIFT;
572 vcpu->svm->cr0 = 0x00000010;
573 vcpu->svm->asid_generation = 0;
574 memset(vcpu->svm->db_regs, 0, sizeof(vcpu->svm->db_regs));
575 init_vmcb(vcpu->svm->vmcb);
576
577 return 0;
578
579out2:
580 kfree(vcpu->svm);
581out1:
582 return r;
583}
584
585static void svm_free_vcpu(struct kvm_vcpu *vcpu)
586{
587 if (!vcpu->svm)
588 return;
589 if (vcpu->svm->vmcb)
590 __free_page(pfn_to_page(vcpu->svm->vmcb_pa >> PAGE_SHIFT));
591 kfree(vcpu->svm);
592}
593
594static struct kvm_vcpu *svm_vcpu_load(struct kvm_vcpu *vcpu)
595{
596 get_cpu();
597 return vcpu;
598}
599
600static void svm_vcpu_put(struct kvm_vcpu *vcpu)
601{
602 put_cpu();
603}
604
605static void svm_cache_regs(struct kvm_vcpu *vcpu)
606{
607 vcpu->regs[VCPU_REGS_RAX] = vcpu->svm->vmcb->save.rax;
608 vcpu->regs[VCPU_REGS_RSP] = vcpu->svm->vmcb->save.rsp;
609 vcpu->rip = vcpu->svm->vmcb->save.rip;
610}
611
612static void svm_decache_regs(struct kvm_vcpu *vcpu)
613{
614 vcpu->svm->vmcb->save.rax = vcpu->regs[VCPU_REGS_RAX];
615 vcpu->svm->vmcb->save.rsp = vcpu->regs[VCPU_REGS_RSP];
616 vcpu->svm->vmcb->save.rip = vcpu->rip;
617}
618
619static unsigned long svm_get_rflags(struct kvm_vcpu *vcpu)
620{
621 return vcpu->svm->vmcb->save.rflags;
622}
623
624static void svm_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
625{
626 vcpu->svm->vmcb->save.rflags = rflags;
627}
628
629static struct vmcb_seg *svm_seg(struct kvm_vcpu *vcpu, int seg)
630{
631 struct vmcb_save_area *save = &vcpu->svm->vmcb->save;
632
633 switch (seg) {
634 case VCPU_SREG_CS: return &save->cs;
635 case VCPU_SREG_DS: return &save->ds;
636 case VCPU_SREG_ES: return &save->es;
637 case VCPU_SREG_FS: return &save->fs;
638 case VCPU_SREG_GS: return &save->gs;
639 case VCPU_SREG_SS: return &save->ss;
640 case VCPU_SREG_TR: return &save->tr;
641 case VCPU_SREG_LDTR: return &save->ldtr;
642 }
643 BUG();
644 return 0;
645}
646
647static u64 svm_get_segment_base(struct kvm_vcpu *vcpu, int seg)
648{
649 struct vmcb_seg *s = svm_seg(vcpu, seg);
650
651 return s->base;
652}
653
654static void svm_get_segment(struct kvm_vcpu *vcpu,
655 struct kvm_segment *var, int seg)
656{
657 struct vmcb_seg *s = svm_seg(vcpu, seg);
658
659 var->base = s->base;
660 var->limit = s->limit;
661 var->selector = s->selector;
662 var->type = s->attrib & SVM_SELECTOR_TYPE_MASK;
663 var->s = (s->attrib >> SVM_SELECTOR_S_SHIFT) & 1;
664 var->dpl = (s->attrib >> SVM_SELECTOR_DPL_SHIFT) & 3;
665 var->present = (s->attrib >> SVM_SELECTOR_P_SHIFT) & 1;
666 var->avl = (s->attrib >> SVM_SELECTOR_AVL_SHIFT) & 1;
667 var->l = (s->attrib >> SVM_SELECTOR_L_SHIFT) & 1;
668 var->db = (s->attrib >> SVM_SELECTOR_DB_SHIFT) & 1;
669 var->g = (s->attrib >> SVM_SELECTOR_G_SHIFT) & 1;
670 var->unusable = !var->present;
671}
672
673static void svm_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
674{
675 struct vmcb_seg *s = svm_seg(vcpu, VCPU_SREG_CS);
676
677 *db = (s->attrib >> SVM_SELECTOR_DB_SHIFT) & 1;
678 *l = (s->attrib >> SVM_SELECTOR_L_SHIFT) & 1;
679}
680
681static void svm_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
682{
683 dt->limit = vcpu->svm->vmcb->save.ldtr.limit;
684 dt->base = vcpu->svm->vmcb->save.ldtr.base;
685}
686
687static void svm_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
688{
689 vcpu->svm->vmcb->save.ldtr.limit = dt->limit;
690 vcpu->svm->vmcb->save.ldtr.base = dt->base ;
691}
692
693static void svm_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
694{
695 dt->limit = vcpu->svm->vmcb->save.gdtr.limit;
696 dt->base = vcpu->svm->vmcb->save.gdtr.base;
697}
698
699static void svm_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
700{
701 vcpu->svm->vmcb->save.gdtr.limit = dt->limit;
702 vcpu->svm->vmcb->save.gdtr.base = dt->base ;
703}
704
705static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
706{
707#ifdef __x86_64__
708 if (vcpu->shadow_efer & KVM_EFER_LME) {
709 if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK)) {
710 vcpu->shadow_efer |= KVM_EFER_LMA;
711 vcpu->svm->vmcb->save.efer |= KVM_EFER_LMA | KVM_EFER_LME;
712 }
713
714 if (is_paging(vcpu) && !(cr0 & CR0_PG_MASK) ) {
715 vcpu->shadow_efer &= ~KVM_EFER_LMA;
716 vcpu->svm->vmcb->save.efer &= ~(KVM_EFER_LMA | KVM_EFER_LME);
717 }
718 }
719#endif
720 vcpu->svm->cr0 = cr0;
721 vcpu->svm->vmcb->save.cr0 = cr0 | CR0_PG_MASK;
722 vcpu->cr0 = cr0;
723}
724
725static void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
726{
727 vcpu->cr4 = cr4;
728 vcpu->svm->vmcb->save.cr4 = cr4 | CR4_PAE_MASK;
729}
730
731static void svm_set_segment(struct kvm_vcpu *vcpu,
732 struct kvm_segment *var, int seg)
733{
734 struct vmcb_seg *s = svm_seg(vcpu, seg);
735
736 s->base = var->base;
737 s->limit = var->limit;
738 s->selector = var->selector;
739 if (var->unusable)
740 s->attrib = 0;
741 else {
742 s->attrib = (var->type & SVM_SELECTOR_TYPE_MASK);
743 s->attrib |= (var->s & 1) << SVM_SELECTOR_S_SHIFT;
744 s->attrib |= (var->dpl & 3) << SVM_SELECTOR_DPL_SHIFT;
745 s->attrib |= (var->present & 1) << SVM_SELECTOR_P_SHIFT;
746 s->attrib |= (var->avl & 1) << SVM_SELECTOR_AVL_SHIFT;
747 s->attrib |= (var->l & 1) << SVM_SELECTOR_L_SHIFT;
748 s->attrib |= (var->db & 1) << SVM_SELECTOR_DB_SHIFT;
749 s->attrib |= (var->g & 1) << SVM_SELECTOR_G_SHIFT;
750 }
751 if (seg == VCPU_SREG_CS)
752 vcpu->svm->vmcb->save.cpl
753 = (vcpu->svm->vmcb->save.cs.attrib
754 >> SVM_SELECTOR_DPL_SHIFT) & 3;
755
756}
757
758/* FIXME:
759
760 vcpu->svm->vmcb->control.int_ctl &= ~V_TPR_MASK;
761 vcpu->svm->vmcb->control.int_ctl |= (sregs->cr8 & V_TPR_MASK);
762
763*/
764
765static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg)
766{
767 return -EOPNOTSUPP;
768}
769
770static void load_host_msrs(struct kvm_vcpu *vcpu)
771{
772 int i;
773
774 for ( i = 0; i < NR_HOST_SAVE_MSRS; i++)
775 wrmsrl(host_save_msrs[i], vcpu->svm->host_msrs[i]);
776}
777
778static void save_host_msrs(struct kvm_vcpu *vcpu)
779{
780 int i;
781
782 for ( i = 0; i < NR_HOST_SAVE_MSRS; i++)
783 rdmsrl(host_save_msrs[i], vcpu->svm->host_msrs[i]);
784}
785
786static void new_asid(struct kvm_vcpu *vcpu, struct svm_cpu_data *svm_data)
787{
788 if (svm_data->next_asid > svm_data->max_asid) {
789 ++svm_data->asid_generation;
790 svm_data->next_asid = 1;
791 vcpu->svm->vmcb->control.tlb_ctl = TLB_CONTROL_FLUSH_ALL_ASID;
792 }
793
794 vcpu->cpu = svm_data->cpu;
795 vcpu->svm->asid_generation = svm_data->asid_generation;
796 vcpu->svm->vmcb->control.asid = svm_data->next_asid++;
797}
798
799static void svm_invlpg(struct kvm_vcpu *vcpu, gva_t address)
800{
801 invlpga(address, vcpu->svm->vmcb->control.asid); // is needed?
802}
803
804static unsigned long svm_get_dr(struct kvm_vcpu *vcpu, int dr)
805{
806 return vcpu->svm->db_regs[dr];
807}
808
809static void svm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long value,
810 int *exception)
811{
812 *exception = 0;
813
814 if (vcpu->svm->vmcb->save.dr7 & DR7_GD_MASK) {
815 vcpu->svm->vmcb->save.dr7 &= ~DR7_GD_MASK;
816 vcpu->svm->vmcb->save.dr6 |= DR6_BD_MASK;
817 *exception = DB_VECTOR;
818 return;
819 }
820
821 switch (dr) {
822 case 0 ... 3:
823 vcpu->svm->db_regs[dr] = value;
824 return;
825 case 4 ... 5:
826 if (vcpu->cr4 & CR4_DE_MASK) {
827 *exception = UD_VECTOR;
828 return;
829 }
830 case 7: {
831 if (value & ~((1ULL << 32) - 1)) {
832 *exception = GP_VECTOR;
833 return;
834 }
835 vcpu->svm->vmcb->save.dr7 = value;
836 return;
837 }
838 default:
839 printk(KERN_DEBUG "%s: unexpected dr %u\n",
840 __FUNCTION__, dr);
841 *exception = UD_VECTOR;
842 return;
843 }
844}
845
846static int pf_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
847{
848 u32 exit_int_info = vcpu->svm->vmcb->control.exit_int_info;
849 u64 fault_address;
850 u32 error_code;
851 enum emulation_result er;
852
853 if (is_external_interrupt(exit_int_info))
854 push_irq(vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK);
855
856 spin_lock(&vcpu->kvm->lock);
857
858 fault_address = vcpu->svm->vmcb->control.exit_info_2;
859 error_code = vcpu->svm->vmcb->control.exit_info_1;
860 if (!vcpu->mmu.page_fault(vcpu, fault_address, error_code)) {
861 spin_unlock(&vcpu->kvm->lock);
862 return 1;
863 }
864 er = emulate_instruction(vcpu, kvm_run, fault_address, error_code);
865 spin_unlock(&vcpu->kvm->lock);
866
867 switch (er) {
868 case EMULATE_DONE:
869 return 1;
870 case EMULATE_DO_MMIO:
871 ++kvm_stat.mmio_exits;
872 kvm_run->exit_reason = KVM_EXIT_MMIO;
873 return 0;
874 case EMULATE_FAIL:
875 vcpu_printf(vcpu, "%s: emulate fail\n", __FUNCTION__);
876 break;
877 default:
878 BUG();
879 }
880
881 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
882 return 0;
883}
884
885static int io_get_override(struct kvm_vcpu *vcpu,
886 struct vmcb_seg **seg,
887 int *addr_override)
888{
889 u8 inst[MAX_INST_SIZE];
890 unsigned ins_length;
891 gva_t rip;
892 int i;
893
894 rip = vcpu->svm->vmcb->save.rip;
895 ins_length = vcpu->svm->next_rip - rip;
896 rip += vcpu->svm->vmcb->save.cs.base;
897
898 if (ins_length > MAX_INST_SIZE)
899 printk(KERN_DEBUG
900 "%s: inst length err, cs base 0x%llx rip 0x%llx "
901 "next rip 0x%llx ins_length %u\n",
902 __FUNCTION__,
903 vcpu->svm->vmcb->save.cs.base,
904 vcpu->svm->vmcb->save.rip,
905 vcpu->svm->vmcb->control.exit_info_2,
906 ins_length);
907
908 if (kvm_read_guest(vcpu, rip, ins_length, inst) != ins_length)
909 /* #PF */
910 return 0;
911
912 *addr_override = 0;
913 *seg = 0;
914 for (i = 0; i < ins_length; i++)
915 switch (inst[i]) {
916 case 0xf0:
917 case 0xf2:
918 case 0xf3:
919 case 0x66:
920 continue;
921 case 0x67:
922 *addr_override = 1;
923 continue;
924 case 0x2e:
925 *seg = &vcpu->svm->vmcb->save.cs;
926 continue;
927 case 0x36:
928 *seg = &vcpu->svm->vmcb->save.ss;
929 continue;
930 case 0x3e:
931 *seg = &vcpu->svm->vmcb->save.ds;
932 continue;
933 case 0x26:
934 *seg = &vcpu->svm->vmcb->save.es;
935 continue;
936 case 0x64:
937 *seg = &vcpu->svm->vmcb->save.fs;
938 continue;
939 case 0x65:
940 *seg = &vcpu->svm->vmcb->save.gs;
941 continue;
942 default:
943 return 1;
944 }
945 printk(KERN_DEBUG "%s: unexpected\n", __FUNCTION__);
946 return 0;
947}
948
949static unsigned long io_adress(struct kvm_vcpu *vcpu, int ins, u64 *address)
950{
951 unsigned long addr_mask;
952 unsigned long *reg;
953 struct vmcb_seg *seg;
954 int addr_override;
955 struct vmcb_save_area *save_area = &vcpu->svm->vmcb->save;
956 u16 cs_attrib = save_area->cs.attrib;
957 unsigned addr_size = get_addr_size(vcpu);
958
959 if (!io_get_override(vcpu, &seg, &addr_override))
960 return 0;
961
962 if (addr_override)
963 addr_size = (addr_size == 2) ? 4: (addr_size >> 1);
964
965 if (ins) {
966 reg = &vcpu->regs[VCPU_REGS_RDI];
967 seg = &vcpu->svm->vmcb->save.es;
968 } else {
969 reg = &vcpu->regs[VCPU_REGS_RSI];
970 seg = (seg) ? seg : &vcpu->svm->vmcb->save.ds;
971 }
972
973 addr_mask = ~0ULL >> (64 - (addr_size * 8));
974
975 if ((cs_attrib & SVM_SELECTOR_L_MASK) &&
976 !(vcpu->svm->vmcb->save.rflags & X86_EFLAGS_VM)) {
977 *address = (*reg & addr_mask);
978 return addr_mask;
979 }
980
981 if (!(seg->attrib & SVM_SELECTOR_P_SHIFT)) {
982 svm_inject_gp(vcpu, 0);
983 return 0;
984 }
985
986 *address = (*reg & addr_mask) + seg->base;
987 return addr_mask;
988}
989
990static int io_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
991{
992 u32 io_info = vcpu->svm->vmcb->control.exit_info_1; //address size bug?
993 int _in = io_info & SVM_IOIO_TYPE_MASK;
994
995 ++kvm_stat.io_exits;
996
997 vcpu->svm->next_rip = vcpu->svm->vmcb->control.exit_info_2;
998
999 kvm_run->exit_reason = KVM_EXIT_IO;
1000 kvm_run->io.port = io_info >> 16;
1001 kvm_run->io.direction = (_in) ? KVM_EXIT_IO_IN : KVM_EXIT_IO_OUT;
1002 kvm_run->io.size = ((io_info & SVM_IOIO_SIZE_MASK) >> SVM_IOIO_SIZE_SHIFT);
1003 kvm_run->io.string = (io_info & SVM_IOIO_STR_MASK) != 0;
1004 kvm_run->io.rep = (io_info & SVM_IOIO_REP_MASK) != 0;
1005
1006 if (kvm_run->io.string) {
1007 unsigned addr_mask;
1008
1009 addr_mask = io_adress(vcpu, _in, &kvm_run->io.address);
1010 if (!addr_mask) {
1011 printk(KERN_DEBUG "%s: get io address failed\n", __FUNCTION__);
1012 return 1;
1013 }
1014
1015 if (kvm_run->io.rep) {
1016 kvm_run->io.count = vcpu->regs[VCPU_REGS_RCX] & addr_mask;
1017 kvm_run->io.string_down = (vcpu->svm->vmcb->save.rflags
1018 & X86_EFLAGS_DF) != 0;
1019 }
1020 } else {
1021 kvm_run->io.value = vcpu->svm->vmcb->save.rax;
1022 }
1023 return 0;
1024}
1025
1026
1027static int nop_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1028{
1029 return 1;
1030}
1031
1032static int halt_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1033{
1034 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 1;
1035 skip_emulated_instruction(vcpu);
1036 if (vcpu->irq_summary && (vcpu->svm->vmcb->save.rflags & X86_EFLAGS_IF))
1037 return 1;
1038
1039 kvm_run->exit_reason = KVM_EXIT_HLT;
1040 return 0;
1041}
1042
1043static int invalid_op_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1044{
1045 inject_ud(vcpu);
1046 return 1;
1047}
1048
1049static int task_switch_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1050{
1051 printk(KERN_DEBUG "%s: task swiche is unsupported\n", __FUNCTION__);
1052 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
1053 return 0;
1054}
1055
1056static int cpuid_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1057{
1058 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 2;
1059 kvm_run->exit_reason = KVM_EXIT_CPUID;
1060 return 0;
1061}
1062
1063static int emulate_on_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1064{
1065 if (emulate_instruction(vcpu, 0, 0, 0) != EMULATE_DONE)
1066 printk(KERN_ERR "%s: failed\n", __FUNCTION__);
1067 return 1;
1068}
1069
1070static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
1071{
1072 switch (ecx) {
1073 case MSR_IA32_MC0_CTL:
1074 case MSR_IA32_MCG_STATUS:
1075 case MSR_IA32_MCG_CAP:
1076 case MSR_IA32_MC0_MISC:
1077 case MSR_IA32_MC0_MISC+4:
1078 case MSR_IA32_MC0_MISC+8:
1079 case MSR_IA32_MC0_MISC+12:
1080 case MSR_IA32_MC0_MISC+16:
1081 case MSR_IA32_UCODE_REV:
1082 /* MTRR registers */
1083 case 0xfe:
1084 case 0x200 ... 0x2ff:
1085 *data = 0;
1086 break;
1087 case MSR_IA32_TIME_STAMP_COUNTER: {
1088 u64 tsc;
1089
1090 rdtscll(tsc);
1091 *data = vcpu->svm->vmcb->control.tsc_offset + tsc;
1092 break;
1093 }
1094 case MSR_EFER:
1095 *data = vcpu->shadow_efer;
1096 break;
1097 case MSR_IA32_APICBASE:
1098 *data = vcpu->apic_base;
1099 break;
1100#ifdef __x86_64__
1101 case MSR_STAR:
1102 *data = vcpu->svm->vmcb->save.star;
1103 break;
1104 case MSR_LSTAR:
1105 *data = vcpu->svm->vmcb->save.lstar;
1106 break;
1107 case MSR_CSTAR:
1108 *data = vcpu->svm->vmcb->save.cstar;
1109 break;
1110 case MSR_KERNEL_GS_BASE:
1111 *data = vcpu->svm->vmcb->save.kernel_gs_base;
1112 break;
1113 case MSR_SYSCALL_MASK:
1114 *data = vcpu->svm->vmcb->save.sfmask;
1115 break;
1116#endif
1117 case MSR_IA32_SYSENTER_CS:
1118 *data = vcpu->svm->vmcb->save.sysenter_cs;
1119 break;
1120 case MSR_IA32_SYSENTER_EIP:
1121 *data = vcpu->svm->vmcb->save.sysenter_eip;
1122 break;
1123 case MSR_IA32_SYSENTER_ESP:
1124 *data = vcpu->svm->vmcb->save.sysenter_esp;
1125 break;
1126 default:
1127 printk(KERN_ERR "kvm: unhandled rdmsr: 0x%x\n", ecx);
1128 return 1;
1129 }
1130 return 0;
1131}
1132
1133static int rdmsr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1134{
1135 u32 ecx = vcpu->regs[VCPU_REGS_RCX];
1136 u64 data;
1137
1138 if (svm_get_msr(vcpu, ecx, &data))
1139 svm_inject_gp(vcpu, 0);
1140 else {
1141 vcpu->svm->vmcb->save.rax = data & 0xffffffff;
1142 vcpu->regs[VCPU_REGS_RDX] = data >> 32;
1143 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 2;
1144 skip_emulated_instruction(vcpu);
1145 }
1146 return 1;
1147}
1148
1149static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
1150{
1151 switch (ecx) {
1152#ifdef __x86_64__
1153 case MSR_EFER:
1154 set_efer(vcpu, data);
1155 break;
1156#endif
1157 case MSR_IA32_MC0_STATUS:
1158 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
1159 , __FUNCTION__, data);
1160 break;
1161 case MSR_IA32_TIME_STAMP_COUNTER: {
1162 u64 tsc;
1163
1164 rdtscll(tsc);
1165 vcpu->svm->vmcb->control.tsc_offset = data - tsc;
1166 break;
1167 }
1168 case MSR_IA32_UCODE_REV:
1169 case MSR_IA32_UCODE_WRITE:
1170 case 0x200 ... 0x2ff: /* MTRRs */
1171 break;
1172 case MSR_IA32_APICBASE:
1173 vcpu->apic_base = data;
1174 break;
1175#ifdef __x86_64___
1176 case MSR_STAR:
1177 vcpu->svm->vmcb->save.star = data;
1178 break;
1179 case MSR_LSTAR:
1180 vcpu->svm->vmcb->save.lstar = data;
1181 break;
1182 case MSR_CSTAR:
1183 vcpu->svm->vmcb->save.cstar = data;
1184 break;
1185 case MSR_KERNEL_GS_BASE:
1186 vcpu->svm->vmcb->save.kernel_gs_base = data;
1187 break;
1188 case MSR_SYSCALL_MASK:
1189 vcpu->svm->vmcb->save.sfmask = data;
1190 break;
1191#endif
1192 case MSR_IA32_SYSENTER_CS:
1193 vcpu->svm->vmcb->save.sysenter_cs = data;
1194 break;
1195 case MSR_IA32_SYSENTER_EIP:
1196 vcpu->svm->vmcb->save.sysenter_eip = data;
1197 break;
1198 case MSR_IA32_SYSENTER_ESP:
1199 vcpu->svm->vmcb->save.sysenter_esp = data;
1200 break;
1201 default:
1202 printk(KERN_ERR "kvm: unhandled wrmsr: %x\n", ecx);
1203 return 1;
1204 }
1205 return 0;
1206}
1207
1208static int wrmsr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1209{
1210 u32 ecx = vcpu->regs[VCPU_REGS_RCX];
1211 u64 data = (vcpu->svm->vmcb->save.rax & -1u)
1212 | ((u64)(vcpu->regs[VCPU_REGS_RDX] & -1u) << 32);
1213 vcpu->svm->next_rip = vcpu->svm->vmcb->save.rip + 2;
1214 if (svm_set_msr(vcpu, ecx, data))
1215 svm_inject_gp(vcpu, 0);
1216 else
1217 skip_emulated_instruction(vcpu);
1218 return 1;
1219}
1220
1221static int msr_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1222{
1223 if (vcpu->svm->vmcb->control.exit_info_1)
1224 return wrmsr_interception(vcpu, kvm_run);
1225 else
1226 return rdmsr_interception(vcpu, kvm_run);
1227}
1228
1229static int (*svm_exit_handlers[])(struct kvm_vcpu *vcpu,
1230 struct kvm_run *kvm_run) = {
1231 [SVM_EXIT_READ_CR0] = emulate_on_interception,
1232 [SVM_EXIT_READ_CR3] = emulate_on_interception,
1233 [SVM_EXIT_READ_CR4] = emulate_on_interception,
1234 /* for now: */
1235 [SVM_EXIT_WRITE_CR0] = emulate_on_interception,
1236 [SVM_EXIT_WRITE_CR3] = emulate_on_interception,
1237 [SVM_EXIT_WRITE_CR4] = emulate_on_interception,
1238 [SVM_EXIT_READ_DR0] = emulate_on_interception,
1239 [SVM_EXIT_READ_DR1] = emulate_on_interception,
1240 [SVM_EXIT_READ_DR2] = emulate_on_interception,
1241 [SVM_EXIT_READ_DR3] = emulate_on_interception,
1242 [SVM_EXIT_WRITE_DR0] = emulate_on_interception,
1243 [SVM_EXIT_WRITE_DR1] = emulate_on_interception,
1244 [SVM_EXIT_WRITE_DR2] = emulate_on_interception,
1245 [SVM_EXIT_WRITE_DR3] = emulate_on_interception,
1246 [SVM_EXIT_WRITE_DR5] = emulate_on_interception,
1247 [SVM_EXIT_WRITE_DR7] = emulate_on_interception,
1248 [SVM_EXIT_EXCP_BASE + PF_VECTOR] = pf_interception,
1249 [SVM_EXIT_INTR] = nop_on_interception,
1250 [SVM_EXIT_NMI] = nop_on_interception,
1251 [SVM_EXIT_SMI] = nop_on_interception,
1252 [SVM_EXIT_INIT] = nop_on_interception,
1253 /* [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, */
1254 [SVM_EXIT_CPUID] = cpuid_interception,
1255 [SVM_EXIT_HLT] = halt_interception,
1256 [SVM_EXIT_INVLPG] = emulate_on_interception,
1257 [SVM_EXIT_INVLPGA] = invalid_op_interception,
1258 [SVM_EXIT_IOIO] = io_interception,
1259 [SVM_EXIT_MSR] = msr_interception,
1260 [SVM_EXIT_TASK_SWITCH] = task_switch_interception,
1261 [SVM_EXIT_VMRUN] = invalid_op_interception,
1262 [SVM_EXIT_VMMCALL] = invalid_op_interception,
1263 [SVM_EXIT_VMLOAD] = invalid_op_interception,
1264 [SVM_EXIT_VMSAVE] = invalid_op_interception,
1265 [SVM_EXIT_STGI] = invalid_op_interception,
1266 [SVM_EXIT_CLGI] = invalid_op_interception,
1267 [SVM_EXIT_SKINIT] = invalid_op_interception,
1268};
1269
1270
1271static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1272{
1273 u32 exit_code = vcpu->svm->vmcb->control.exit_code;
1274
1275 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
1276
1277 if (is_external_interrupt(vcpu->svm->vmcb->control.exit_int_info) &&
1278 exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
1279 printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
1280 "exit_code 0x%x\n",
1281 __FUNCTION__, vcpu->svm->vmcb->control.exit_int_info,
1282 exit_code);
1283
1284 if (exit_code >= sizeof(svm_exit_handlers) / sizeof(*svm_exit_handlers)
1285 || svm_exit_handlers[exit_code] == 0) {
1286 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
1287 printk(KERN_ERR "%s: 0x%x @ 0x%llx cr0 0x%lx rflags 0x%llx\n",
1288 __FUNCTION__,
1289 exit_code,
1290 vcpu->svm->vmcb->save.rip,
1291 vcpu->cr0,
1292 vcpu->svm->vmcb->save.rflags);
1293 return 0;
1294 }
1295
1296 return svm_exit_handlers[exit_code](vcpu, kvm_run);
1297}
1298
1299static void reload_tss(struct kvm_vcpu *vcpu)
1300{
1301 int cpu = raw_smp_processor_id();
1302
1303 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
1304 svm_data->tss_desc->type = 9; //available 32/64-bit TSS
1305 load_TR_desc();
1306}
1307
1308static void pre_svm_run(struct kvm_vcpu *vcpu)
1309{
1310 int cpu = raw_smp_processor_id();
1311
1312 struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
1313
1314 vcpu->svm->vmcb->control.tlb_ctl = TLB_CONTROL_DO_NOTHING;
1315 if (vcpu->cpu != cpu ||
1316 vcpu->svm->asid_generation != svm_data->asid_generation)
1317 new_asid(vcpu, svm_data);
1318}
1319
1320
1321static inline void kvm_try_inject_irq(struct kvm_vcpu *vcpu)
1322{
1323 struct vmcb_control_area *control;
1324
1325 if (!vcpu->irq_summary)
1326 return;
1327
1328 control = &vcpu->svm->vmcb->control;
1329
1330 control->int_vector = pop_irq(vcpu);
1331 control->int_ctl &= ~V_INTR_PRIO_MASK;
1332 control->int_ctl |= V_IRQ_MASK |
1333 ((/*control->int_vector >> 4*/ 0xf) << V_INTR_PRIO_SHIFT);
1334}
1335
1336static void kvm_reput_irq(struct kvm_vcpu *vcpu)
1337{
1338 struct vmcb_control_area *control = &vcpu->svm->vmcb->control;
1339
1340 if (control->int_ctl & V_IRQ_MASK) {
1341 control->int_ctl &= ~V_IRQ_MASK;
1342 push_irq(vcpu, control->int_vector);
1343 }
1344}
1345
1346static void save_db_regs(unsigned long *db_regs)
1347{
1348#ifdef __x86_64__
1349 asm ("mov %%dr0, %%rax \n\t"
1350 "mov %%rax, %[dr0] \n\t"
1351 "mov %%dr1, %%rax \n\t"
1352 "mov %%rax, %[dr1] \n\t"
1353 "mov %%dr2, %%rax \n\t"
1354 "mov %%rax, %[dr2] \n\t"
1355 "mov %%dr3, %%rax \n\t"
1356 "mov %%rax, %[dr3] \n\t"
1357 : [dr0] "=m"(db_regs[0]),
1358 [dr1] "=m"(db_regs[1]),
1359 [dr2] "=m"(db_regs[2]),
1360 [dr3] "=m"(db_regs[3])
1361 : : "rax");
1362#else
1363 asm ("mov %%dr0, %%eax \n\t"
1364 "mov %%eax, %[dr0] \n\t"
1365 "mov %%dr1, %%eax \n\t"
1366 "mov %%eax, %[dr1] \n\t"
1367 "mov %%dr2, %%eax \n\t"
1368 "mov %%eax, %[dr2] \n\t"
1369 "mov %%dr3, %%eax \n\t"
1370 "mov %%eax, %[dr3] \n\t"
1371 : [dr0] "=m"(db_regs[0]),
1372 [dr1] "=m"(db_regs[1]),
1373 [dr2] "=m"(db_regs[2]),
1374 [dr3] "=m"(db_regs[3])
1375 : : "eax");
1376#endif
1377}
1378
1379static void load_db_regs(unsigned long *db_regs)
1380{
1381 asm volatile ("mov %[dr0], %%dr0 \n\t"
1382 "mov %[dr1], %%dr1 \n\t"
1383 "mov %[dr2], %%dr2 \n\t"
1384 "mov %[dr3], %%dr3 \n\t"
1385 :
1386 : [dr0] "r"(db_regs[0]),
1387 [dr1] "r"(db_regs[1]),
1388 [dr2] "r"(db_regs[2]),
1389 [dr3] "r"(db_regs[3])
1390#ifdef __x86_64__
1391 : "rax");
1392#else
1393 : "eax");
1394#endif
1395}
1396
1397static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1398{
1399 u16 fs_selector;
1400 u16 gs_selector;
1401 u16 ldt_selector;
1402
1403again:
1404 kvm_try_inject_irq(vcpu);
1405
1406 clgi();
1407
1408 pre_svm_run(vcpu);
1409
1410 save_host_msrs(vcpu);
1411 fs_selector = read_fs();
1412 gs_selector = read_gs();
1413 ldt_selector = read_ldt();
1414 vcpu->svm->host_cr2 = kvm_read_cr2();
1415 vcpu->svm->host_dr6 = read_dr6();
1416 vcpu->svm->host_dr7 = read_dr7();
1417 vcpu->svm->vmcb->save.cr2 = vcpu->cr2;
1418
1419 if (vcpu->svm->vmcb->save.dr7 & 0xff) {
1420 write_dr7(0);
1421 save_db_regs(vcpu->svm->host_db_regs);
1422 load_db_regs(vcpu->svm->db_regs);
1423 }
1424 asm volatile (
1425#ifdef __x86_64__
1426 "push %%rbx; push %%rcx; push %%rdx;"
1427 "push %%rsi; push %%rdi; push %%rbp;"
1428 "push %%r8; push %%r9; push %%r10; push %%r11;"
1429 "push %%r12; push %%r13; push %%r14; push %%r15;"
1430#else
1431 "push %%ebx; push %%ecx; push %%edx;"
1432 "push %%esi; push %%edi; push %%ebp;"
1433#endif
1434
1435#ifdef __x86_64__
1436 "mov %c[rbx](%[vcpu]), %%rbx \n\t"
1437 "mov %c[rcx](%[vcpu]), %%rcx \n\t"
1438 "mov %c[rdx](%[vcpu]), %%rdx \n\t"
1439 "mov %c[rsi](%[vcpu]), %%rsi \n\t"
1440 "mov %c[rdi](%[vcpu]), %%rdi \n\t"
1441 "mov %c[rbp](%[vcpu]), %%rbp \n\t"
1442 "mov %c[r8](%[vcpu]), %%r8 \n\t"
1443 "mov %c[r9](%[vcpu]), %%r9 \n\t"
1444 "mov %c[r10](%[vcpu]), %%r10 \n\t"
1445 "mov %c[r11](%[vcpu]), %%r11 \n\t"
1446 "mov %c[r12](%[vcpu]), %%r12 \n\t"
1447 "mov %c[r13](%[vcpu]), %%r13 \n\t"
1448 "mov %c[r14](%[vcpu]), %%r14 \n\t"
1449 "mov %c[r15](%[vcpu]), %%r15 \n\t"
1450#else
1451 "mov %c[rbx](%[vcpu]), %%ebx \n\t"
1452 "mov %c[rcx](%[vcpu]), %%ecx \n\t"
1453 "mov %c[rdx](%[vcpu]), %%edx \n\t"
1454 "mov %c[rsi](%[vcpu]), %%esi \n\t"
1455 "mov %c[rdi](%[vcpu]), %%edi \n\t"
1456 "mov %c[rbp](%[vcpu]), %%ebp \n\t"
1457#endif
1458
1459#ifdef __x86_64__
1460 /* Enter guest mode */
1461 "push %%rax \n\t"
1462 "mov %c[svm](%[vcpu]), %%rax \n\t"
1463 "mov %c[vmcb](%%rax), %%rax \n\t"
1464 SVM_VMLOAD "\n\t"
1465 SVM_VMRUN "\n\t"
1466 SVM_VMSAVE "\n\t"
1467 "pop %%rax \n\t"
1468#else
1469 /* Enter guest mode */
1470 "push %%eax \n\t"
1471 "mov %c[svm](%[vcpu]), %%eax \n\t"
1472 "mov %c[vmcb](%%eax), %%eax \n\t"
1473 SVM_VMLOAD "\n\t"
1474 SVM_VMRUN "\n\t"
1475 SVM_VMSAVE "\n\t"
1476 "pop %%eax \n\t"
1477#endif
1478
1479 /* Save guest registers, load host registers */
1480#ifdef __x86_64__
1481 "mov %%rbx, %c[rbx](%[vcpu]) \n\t"
1482 "mov %%rcx, %c[rcx](%[vcpu]) \n\t"
1483 "mov %%rdx, %c[rdx](%[vcpu]) \n\t"
1484 "mov %%rsi, %c[rsi](%[vcpu]) \n\t"
1485 "mov %%rdi, %c[rdi](%[vcpu]) \n\t"
1486 "mov %%rbp, %c[rbp](%[vcpu]) \n\t"
1487 "mov %%r8, %c[r8](%[vcpu]) \n\t"
1488 "mov %%r9, %c[r9](%[vcpu]) \n\t"
1489 "mov %%r10, %c[r10](%[vcpu]) \n\t"
1490 "mov %%r11, %c[r11](%[vcpu]) \n\t"
1491 "mov %%r12, %c[r12](%[vcpu]) \n\t"
1492 "mov %%r13, %c[r13](%[vcpu]) \n\t"
1493 "mov %%r14, %c[r14](%[vcpu]) \n\t"
1494 "mov %%r15, %c[r15](%[vcpu]) \n\t"
1495
1496 "pop %%r15; pop %%r14; pop %%r13; pop %%r12;"
1497 "pop %%r11; pop %%r10; pop %%r9; pop %%r8;"
1498 "pop %%rbp; pop %%rdi; pop %%rsi;"
1499 "pop %%rdx; pop %%rcx; pop %%rbx; \n\t"
1500#else
1501 "mov %%ebx, %c[rbx](%[vcpu]) \n\t"
1502 "mov %%ecx, %c[rcx](%[vcpu]) \n\t"
1503 "mov %%edx, %c[rdx](%[vcpu]) \n\t"
1504 "mov %%esi, %c[rsi](%[vcpu]) \n\t"
1505 "mov %%edi, %c[rdi](%[vcpu]) \n\t"
1506 "mov %%ebp, %c[rbp](%[vcpu]) \n\t"
1507
1508 "pop %%ebp; pop %%edi; pop %%esi;"
1509 "pop %%edx; pop %%ecx; pop %%ebx; \n\t"
1510#endif
1511 :
1512 : [vcpu]"a"(vcpu),
1513 [svm]"i"(offsetof(struct kvm_vcpu, svm)),
1514 [vmcb]"i"(offsetof(struct vcpu_svm, vmcb_pa)),
1515 [rbx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBX])),
1516 [rcx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RCX])),
1517 [rdx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDX])),
1518 [rsi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RSI])),
1519 [rdi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDI])),
1520 [rbp]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBP]))
1521#ifdef __x86_64__
1522 ,[r8 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R8 ])),
1523 [r9 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R9 ])),
1524 [r10]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R10])),
1525 [r11]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R11])),
1526 [r12]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R12])),
1527 [r13]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R13])),
1528 [r14]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R14])),
1529 [r15]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R15]))
1530#endif
1531 : "cc", "memory" );
1532
1533 if ((vcpu->svm->vmcb->save.dr7 & 0xff))
1534 load_db_regs(vcpu->svm->host_db_regs);
1535
1536 vcpu->cr2 = vcpu->svm->vmcb->save.cr2;
1537
1538 write_dr6(vcpu->svm->host_dr6);
1539 write_dr7(vcpu->svm->host_dr7);
1540 kvm_write_cr2(vcpu->svm->host_cr2);
1541
1542 load_fs(fs_selector);
1543 load_gs(gs_selector);
1544 load_ldt(ldt_selector);
1545 load_host_msrs(vcpu);
1546
1547 reload_tss(vcpu);
1548
1549 stgi();
1550
1551 kvm_reput_irq(vcpu);
1552
1553 vcpu->svm->next_rip = 0;
1554
1555 if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
1556 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
1557 kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code;
1558 return 0;
1559 }
1560
1561 if (handle_exit(vcpu, kvm_run)) {
1562 if (signal_pending(current)) {
1563 ++kvm_stat.signal_exits;
1564 return -EINTR;
1565 }
1566 kvm_resched(vcpu);
1567 goto again;
1568 }
1569 return 0;
1570}
1571
1572static void svm_flush_tlb(struct kvm_vcpu *vcpu)
1573{
1574 force_new_asid(vcpu);
1575}
1576
1577static void svm_set_cr3(struct kvm_vcpu *vcpu, unsigned long root)
1578{
1579 vcpu->svm->vmcb->save.cr3 = root;
1580 force_new_asid(vcpu);
1581}
1582
1583static void svm_inject_page_fault(struct kvm_vcpu *vcpu,
1584 unsigned long addr,
1585 uint32_t err_code)
1586{
1587 uint32_t exit_int_info = vcpu->svm->vmcb->control.exit_int_info;
1588
1589 ++kvm_stat.pf_guest;
1590
1591 if (is_page_fault(exit_int_info)) {
1592
1593 vcpu->svm->vmcb->control.event_inj_err = 0;
1594 vcpu->svm->vmcb->control.event_inj = SVM_EVTINJ_VALID |
1595 SVM_EVTINJ_VALID_ERR |
1596 SVM_EVTINJ_TYPE_EXEPT |
1597 DF_VECTOR;
1598 return;
1599 }
1600 vcpu->cr2 = addr;
1601 vcpu->svm->vmcb->save.cr2 = addr;
1602 vcpu->svm->vmcb->control.event_inj = SVM_EVTINJ_VALID |
1603 SVM_EVTINJ_VALID_ERR |
1604 SVM_EVTINJ_TYPE_EXEPT |
1605 PF_VECTOR;
1606 vcpu->svm->vmcb->control.event_inj_err = err_code;
1607}
1608
1609
1610static int is_disabled(void)
1611{
1612 return 0;
1613}
1614
1615static struct kvm_arch_ops svm_arch_ops = {
1616 .cpu_has_kvm_support = has_svm,
1617 .disabled_by_bios = is_disabled,
1618 .hardware_setup = svm_hardware_setup,
1619 .hardware_unsetup = svm_hardware_unsetup,
1620 .hardware_enable = svm_hardware_enable,
1621 .hardware_disable = svm_hardware_disable,
1622
1623 .vcpu_create = svm_create_vcpu,
1624 .vcpu_free = svm_free_vcpu,
1625
1626 .vcpu_load = svm_vcpu_load,
1627 .vcpu_put = svm_vcpu_put,
1628
1629 .set_guest_debug = svm_guest_debug,
1630 .get_msr = svm_get_msr,
1631 .set_msr = svm_set_msr,
1632 .get_segment_base = svm_get_segment_base,
1633 .get_segment = svm_get_segment,
1634 .set_segment = svm_set_segment,
1635 .is_long_mode = svm_is_long_mode,
1636 .get_cs_db_l_bits = svm_get_cs_db_l_bits,
1637 .set_cr0 = svm_set_cr0,
1638 .set_cr0_no_modeswitch = svm_set_cr0,
1639 .set_cr3 = svm_set_cr3,
1640 .set_cr4 = svm_set_cr4,
1641 .set_efer = svm_set_efer,
1642 .get_idt = svm_get_idt,
1643 .set_idt = svm_set_idt,
1644 .get_gdt = svm_get_gdt,
1645 .set_gdt = svm_set_gdt,
1646 .get_dr = svm_get_dr,
1647 .set_dr = svm_set_dr,
1648 .cache_regs = svm_cache_regs,
1649 .decache_regs = svm_decache_regs,
1650 .get_rflags = svm_get_rflags,
1651 .set_rflags = svm_set_rflags,
1652
1653 .invlpg = svm_invlpg,
1654 .tlb_flush = svm_flush_tlb,
1655 .inject_page_fault = svm_inject_page_fault,
1656
1657 .inject_gp = svm_inject_gp,
1658
1659 .run = svm_vcpu_run,
1660 .skip_emulated_instruction = skip_emulated_instruction,
1661 .vcpu_setup = svm_vcpu_setup,
1662};
1663
1664static int __init svm_init(void)
1665{
1666 kvm_emulator_want_group7_invlpg();
1667 kvm_init_arch(&svm_arch_ops, THIS_MODULE);
1668 return 0;
1669}
1670
1671static void __exit svm_exit(void)
1672{
1673 kvm_exit_arch();
1674}
1675
1676module_init(svm_init)
1677module_exit(svm_exit)
diff --git a/drivers/kvm/svm.h b/drivers/kvm/svm.h
new file mode 100644
index 000000000000..df731c3fb588
--- /dev/null
+++ b/drivers/kvm/svm.h
@@ -0,0 +1,315 @@
1#ifndef __SVM_H
2#define __SVM_H
3
4enum {
5 INTERCEPT_INTR,
6 INTERCEPT_NMI,
7 INTERCEPT_SMI,
8 INTERCEPT_INIT,
9 INTERCEPT_VINTR,
10 INTERCEPT_SELECTIVE_CR0,
11 INTERCEPT_STORE_IDTR,
12 INTERCEPT_STORE_GDTR,
13 INTERCEPT_STORE_LDTR,
14 INTERCEPT_STORE_TR,
15 INTERCEPT_LOAD_IDTR,
16 INTERCEPT_LOAD_GDTR,
17 INTERCEPT_LOAD_LDTR,
18 INTERCEPT_LOAD_TR,
19 INTERCEPT_RDTSC,
20 INTERCEPT_RDPMC,
21 INTERCEPT_PUSHF,
22 INTERCEPT_POPF,
23 INTERCEPT_CPUID,
24 INTERCEPT_RSM,
25 INTERCEPT_IRET,
26 INTERCEPT_INTn,
27 INTERCEPT_INVD,
28 INTERCEPT_PAUSE,
29 INTERCEPT_HLT,
30 INTERCEPT_INVLPG,
31 INTERCEPT_INVLPGA,
32 INTERCEPT_IOIO_PROT,
33 INTERCEPT_MSR_PROT,
34 INTERCEPT_TASK_SWITCH,
35 INTERCEPT_FERR_FREEZE,
36 INTERCEPT_SHUTDOWN,
37 INTERCEPT_VMRUN,
38 INTERCEPT_VMMCALL,
39 INTERCEPT_VMLOAD,
40 INTERCEPT_VMSAVE,
41 INTERCEPT_STGI,
42 INTERCEPT_CLGI,
43 INTERCEPT_SKINIT,
44 INTERCEPT_RDTSCP,
45 INTERCEPT_ICEBP,
46 INTERCEPT_WBINVD,
47};
48
49
50struct __attribute__ ((__packed__)) vmcb_control_area {
51 u16 intercept_cr_read;
52 u16 intercept_cr_write;
53 u16 intercept_dr_read;
54 u16 intercept_dr_write;
55 u32 intercept_exceptions;
56 u64 intercept;
57 u8 reserved_1[44];
58 u64 iopm_base_pa;
59 u64 msrpm_base_pa;
60 u64 tsc_offset;
61 u32 asid;
62 u8 tlb_ctl;
63 u8 reserved_2[3];
64 u32 int_ctl;
65 u32 int_vector;
66 u32 int_state;
67 u8 reserved_3[4];
68 u32 exit_code;
69 u32 exit_code_hi;
70 u64 exit_info_1;
71 u64 exit_info_2;
72 u32 exit_int_info;
73 u32 exit_int_info_err;
74 u64 nested_ctl;
75 u8 reserved_4[16];
76 u32 event_inj;
77 u32 event_inj_err;
78 u64 nested_cr3;
79 u64 lbr_ctl;
80 u8 reserved_5[832];
81};
82
83
84#define TLB_CONTROL_DO_NOTHING 0
85#define TLB_CONTROL_FLUSH_ALL_ASID 1
86
87#define V_TPR_MASK 0x0f
88
89#define V_IRQ_SHIFT 8
90#define V_IRQ_MASK (1 << V_IRQ_SHIFT)
91
92#define V_INTR_PRIO_SHIFT 16
93#define V_INTR_PRIO_MASK (0x0f << V_INTR_PRIO_SHIFT)
94
95#define V_IGN_TPR_SHIFT 20
96#define V_IGN_TPR_MASK (1 << V_IGN_TPR_SHIFT)
97
98#define V_INTR_MASKING_SHIFT 24
99#define V_INTR_MASKING_MASK (1 << V_INTR_MASKING_SHIFT)
100
101#define SVM_INTERRUPT_SHADOW_MASK 1
102
103#define SVM_IOIO_STR_SHIFT 2
104#define SVM_IOIO_REP_SHIFT 3
105#define SVM_IOIO_SIZE_SHIFT 4
106#define SVM_IOIO_ASIZE_SHIFT 7
107
108#define SVM_IOIO_TYPE_MASK 1
109#define SVM_IOIO_STR_MASK (1 << SVM_IOIO_STR_SHIFT)
110#define SVM_IOIO_REP_MASK (1 << SVM_IOIO_REP_SHIFT)
111#define SVM_IOIO_SIZE_MASK (7 << SVM_IOIO_SIZE_SHIFT)
112#define SVM_IOIO_ASIZE_MASK (7 << SVM_IOIO_ASIZE_SHIFT)
113
114struct __attribute__ ((__packed__)) vmcb_seg {
115 u16 selector;
116 u16 attrib;
117 u32 limit;
118 u64 base;
119};
120
121struct __attribute__ ((__packed__)) vmcb_save_area {
122 struct vmcb_seg es;
123 struct vmcb_seg cs;
124 struct vmcb_seg ss;
125 struct vmcb_seg ds;
126 struct vmcb_seg fs;
127 struct vmcb_seg gs;
128 struct vmcb_seg gdtr;
129 struct vmcb_seg ldtr;
130 struct vmcb_seg idtr;
131 struct vmcb_seg tr;
132 u8 reserved_1[43];
133 u8 cpl;
134 u8 reserved_2[4];
135 u64 efer;
136 u8 reserved_3[112];
137 u64 cr4;
138 u64 cr3;
139 u64 cr0;
140 u64 dr7;
141 u64 dr6;
142 u64 rflags;
143 u64 rip;
144 u8 reserved_4[88];
145 u64 rsp;
146 u8 reserved_5[24];
147 u64 rax;
148 u64 star;
149 u64 lstar;
150 u64 cstar;
151 u64 sfmask;
152 u64 kernel_gs_base;
153 u64 sysenter_cs;
154 u64 sysenter_esp;
155 u64 sysenter_eip;
156 u64 cr2;
157 u8 reserved_6[32];
158 u64 g_pat;
159 u64 dbgctl;
160 u64 br_from;
161 u64 br_to;
162 u64 last_excp_from;
163 u64 last_excp_to;
164};
165
166struct __attribute__ ((__packed__)) vmcb {
167 struct vmcb_control_area control;
168 struct vmcb_save_area save;
169};
170
171#define SVM_CPUID_FEATURE_SHIFT 2
172#define SVM_CPUID_FUNC 0x8000000a
173
174#define MSR_EFER_SVME_MASK (1ULL << 12)
175#define MSR_VM_HSAVE_PA 0xc0010117ULL
176
177#define SVM_SELECTOR_S_SHIFT 4
178#define SVM_SELECTOR_DPL_SHIFT 5
179#define SVM_SELECTOR_P_SHIFT 7
180#define SVM_SELECTOR_AVL_SHIFT 8
181#define SVM_SELECTOR_L_SHIFT 9
182#define SVM_SELECTOR_DB_SHIFT 10
183#define SVM_SELECTOR_G_SHIFT 11
184
185#define SVM_SELECTOR_TYPE_MASK (0xf)
186#define SVM_SELECTOR_S_MASK (1 << SVM_SELECTOR_S_SHIFT)
187#define SVM_SELECTOR_DPL_MASK (3 << SVM_SELECTOR_DPL_SHIFT)
188#define SVM_SELECTOR_P_MASK (1 << SVM_SELECTOR_P_SHIFT)
189#define SVM_SELECTOR_AVL_MASK (1 << SVM_SELECTOR_AVL_SHIFT)
190#define SVM_SELECTOR_L_MASK (1 << SVM_SELECTOR_L_SHIFT)
191#define SVM_SELECTOR_DB_MASK (1 << SVM_SELECTOR_DB_SHIFT)
192#define SVM_SELECTOR_G_MASK (1 << SVM_SELECTOR_G_SHIFT)
193
194#define SVM_SELECTOR_WRITE_MASK (1 << 1)
195#define SVM_SELECTOR_READ_MASK SVM_SELECTOR_WRITE_MASK
196#define SVM_SELECTOR_CODE_MASK (1 << 3)
197
198#define INTERCEPT_CR0_MASK 1
199#define INTERCEPT_CR3_MASK (1 << 3)
200#define INTERCEPT_CR4_MASK (1 << 4)
201
202#define INTERCEPT_DR0_MASK 1
203#define INTERCEPT_DR1_MASK (1 << 1)
204#define INTERCEPT_DR2_MASK (1 << 2)
205#define INTERCEPT_DR3_MASK (1 << 3)
206#define INTERCEPT_DR4_MASK (1 << 4)
207#define INTERCEPT_DR5_MASK (1 << 5)
208#define INTERCEPT_DR6_MASK (1 << 6)
209#define INTERCEPT_DR7_MASK (1 << 7)
210
211#define SVM_EVTINJ_VEC_MASK 0xff
212
213#define SVM_EVTINJ_TYPE_SHIFT 8
214#define SVM_EVTINJ_TYPE_MASK (7 << SVM_EVTINJ_TYPE_SHIFT)
215
216#define SVM_EVTINJ_TYPE_INTR (0 << SVM_EVTINJ_TYPE_SHIFT)
217#define SVM_EVTINJ_TYPE_NMI (2 << SVM_EVTINJ_TYPE_SHIFT)
218#define SVM_EVTINJ_TYPE_EXEPT (3 << SVM_EVTINJ_TYPE_SHIFT)
219#define SVM_EVTINJ_TYPE_SOFT (4 << SVM_EVTINJ_TYPE_SHIFT)
220
221#define SVM_EVTINJ_VALID (1 << 31)
222#define SVM_EVTINJ_VALID_ERR (1 << 11)
223
224#define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK
225
226#define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR
227#define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI
228#define SVM_EXITINTINFO_TYPE_EXEPT SVM_EVTINJ_TYPE_EXEPT
229#define SVM_EXITINTINFO_TYPE_SOFT SVM_EVTINJ_TYPE_SOFT
230
231#define SVM_EXITINTINFO_VALID SVM_EVTINJ_VALID
232#define SVM_EXITINTINFO_VALID_ERR SVM_EVTINJ_VALID_ERR
233
234#define SVM_EXIT_READ_CR0 0x000
235#define SVM_EXIT_READ_CR3 0x003
236#define SVM_EXIT_READ_CR4 0x004
237#define SVM_EXIT_READ_CR8 0x008
238#define SVM_EXIT_WRITE_CR0 0x010
239#define SVM_EXIT_WRITE_CR3 0x013
240#define SVM_EXIT_WRITE_CR4 0x014
241#define SVM_EXIT_WRITE_CR8 0x018
242#define SVM_EXIT_READ_DR0 0x020
243#define SVM_EXIT_READ_DR1 0x021
244#define SVM_EXIT_READ_DR2 0x022
245#define SVM_EXIT_READ_DR3 0x023
246#define SVM_EXIT_READ_DR4 0x024
247#define SVM_EXIT_READ_DR5 0x025
248#define SVM_EXIT_READ_DR6 0x026
249#define SVM_EXIT_READ_DR7 0x027
250#define SVM_EXIT_WRITE_DR0 0x030
251#define SVM_EXIT_WRITE_DR1 0x031
252#define SVM_EXIT_WRITE_DR2 0x032
253#define SVM_EXIT_WRITE_DR3 0x033
254#define SVM_EXIT_WRITE_DR4 0x034
255#define SVM_EXIT_WRITE_DR5 0x035
256#define SVM_EXIT_WRITE_DR6 0x036
257#define SVM_EXIT_WRITE_DR7 0x037
258#define SVM_EXIT_EXCP_BASE 0x040
259#define SVM_EXIT_INTR 0x060
260#define SVM_EXIT_NMI 0x061
261#define SVM_EXIT_SMI 0x062
262#define SVM_EXIT_INIT 0x063
263#define SVM_EXIT_VINTR 0x064
264#define SVM_EXIT_CR0_SEL_WRITE 0x065
265#define SVM_EXIT_IDTR_READ 0x066
266#define SVM_EXIT_GDTR_READ 0x067
267#define SVM_EXIT_LDTR_READ 0x068
268#define SVM_EXIT_TR_READ 0x069
269#define SVM_EXIT_IDTR_WRITE 0x06a
270#define SVM_EXIT_GDTR_WRITE 0x06b
271#define SVM_EXIT_LDTR_WRITE 0x06c
272#define SVM_EXIT_TR_WRITE 0x06d
273#define SVM_EXIT_RDTSC 0x06e
274#define SVM_EXIT_RDPMC 0x06f
275#define SVM_EXIT_PUSHF 0x070
276#define SVM_EXIT_POPF 0x071
277#define SVM_EXIT_CPUID 0x072
278#define SVM_EXIT_RSM 0x073
279#define SVM_EXIT_IRET 0x074
280#define SVM_EXIT_SWINT 0x075
281#define SVM_EXIT_INVD 0x076
282#define SVM_EXIT_PAUSE 0x077
283#define SVM_EXIT_HLT 0x078
284#define SVM_EXIT_INVLPG 0x079
285#define SVM_EXIT_INVLPGA 0x07a
286#define SVM_EXIT_IOIO 0x07b
287#define SVM_EXIT_MSR 0x07c
288#define SVM_EXIT_TASK_SWITCH 0x07d
289#define SVM_EXIT_FERR_FREEZE 0x07e
290#define SVM_EXIT_SHUTDOWN 0x07f
291#define SVM_EXIT_VMRUN 0x080
292#define SVM_EXIT_VMMCALL 0x081
293#define SVM_EXIT_VMLOAD 0x082
294#define SVM_EXIT_VMSAVE 0x083
295#define SVM_EXIT_STGI 0x084
296#define SVM_EXIT_CLGI 0x085
297#define SVM_EXIT_SKINIT 0x086
298#define SVM_EXIT_RDTSCP 0x087
299#define SVM_EXIT_ICEBP 0x088
300#define SVM_EXIT_WBINVD 0x089
301#define SVM_EXIT_NPF 0x400
302
303#define SVM_EXIT_ERR -1
304
305#define SVM_CR0_SELECTIVE_MASK (1 << 3 | 1) // TS and MP
306
307#define SVM_VMLOAD ".byte 0x0f, 0x01, 0xda"
308#define SVM_VMRUN ".byte 0x0f, 0x01, 0xd8"
309#define SVM_VMSAVE ".byte 0x0f, 0x01, 0xdb"
310#define SVM_CLGI ".byte 0x0f, 0x01, 0xdd"
311#define SVM_STGI ".byte 0x0f, 0x01, 0xdc"
312#define SVM_INVLPGA ".byte 0x0f, 0x01, 0xdf"
313
314#endif
315
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
new file mode 100644
index 000000000000..bda7a7ae2167
--- /dev/null
+++ b/drivers/kvm/vmx.c
@@ -0,0 +1,2002 @@
1/*
2 * Kernel-based Virtual Machine driver for Linux
3 *
4 * This module enables machines with Intel VT-x extensions to run virtual
5 * machines without emulation or binary translation.
6 *
7 * Copyright (C) 2006 Qumranet, Inc.
8 *
9 * Authors:
10 * Avi Kivity <avi@qumranet.com>
11 * Yaniv Kamay <yaniv@qumranet.com>
12 *
13 * This work is licensed under the terms of the GNU GPL, version 2. See
14 * the COPYING file in the top-level directory.
15 *
16 */
17
18#include "kvm.h"
19#include "vmx.h"
20#include "kvm_vmx.h"
21#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/highmem.h>
24#include <asm/io.h>
25
26#include "segment_descriptor.h"
27
28#define MSR_IA32_FEATURE_CONTROL 0x03a
29
30MODULE_AUTHOR("Qumranet");
31MODULE_LICENSE("GPL");
32
33static DEFINE_PER_CPU(struct vmcs *, vmxarea);
34static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
35
36#ifdef __x86_64__
37#define HOST_IS_64 1
38#else
39#define HOST_IS_64 0
40#endif
41
42static struct vmcs_descriptor {
43 int size;
44 int order;
45 u32 revision_id;
46} vmcs_descriptor;
47
48#define VMX_SEGMENT_FIELD(seg) \
49 [VCPU_SREG_##seg] = { \
50 .selector = GUEST_##seg##_SELECTOR, \
51 .base = GUEST_##seg##_BASE, \
52 .limit = GUEST_##seg##_LIMIT, \
53 .ar_bytes = GUEST_##seg##_AR_BYTES, \
54 }
55
56static struct kvm_vmx_segment_field {
57 unsigned selector;
58 unsigned base;
59 unsigned limit;
60 unsigned ar_bytes;
61} kvm_vmx_segment_fields[] = {
62 VMX_SEGMENT_FIELD(CS),
63 VMX_SEGMENT_FIELD(DS),
64 VMX_SEGMENT_FIELD(ES),
65 VMX_SEGMENT_FIELD(FS),
66 VMX_SEGMENT_FIELD(GS),
67 VMX_SEGMENT_FIELD(SS),
68 VMX_SEGMENT_FIELD(TR),
69 VMX_SEGMENT_FIELD(LDTR),
70};
71
72static const u32 vmx_msr_index[] = {
73#ifdef __x86_64__
74 MSR_SYSCALL_MASK, MSR_LSTAR, MSR_CSTAR, MSR_KERNEL_GS_BASE,
75#endif
76 MSR_EFER, MSR_K6_STAR,
77};
78#define NR_VMX_MSR (sizeof(vmx_msr_index) / sizeof(*vmx_msr_index))
79
80struct vmx_msr_entry *find_msr_entry(struct kvm_vcpu *vcpu, u32 msr);
81
82static inline int is_page_fault(u32 intr_info)
83{
84 return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
85 INTR_INFO_VALID_MASK)) ==
86 (INTR_TYPE_EXCEPTION | PF_VECTOR | INTR_INFO_VALID_MASK);
87}
88
89static inline int is_external_interrupt(u32 intr_info)
90{
91 return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VALID_MASK))
92 == (INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
93}
94
95static void vmcs_clear(struct vmcs *vmcs)
96{
97 u64 phys_addr = __pa(vmcs);
98 u8 error;
99
100 asm volatile (ASM_VMX_VMCLEAR_RAX "; setna %0"
101 : "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
102 : "cc", "memory");
103 if (error)
104 printk(KERN_ERR "kvm: vmclear fail: %p/%llx\n",
105 vmcs, phys_addr);
106}
107
108static void __vcpu_clear(void *arg)
109{
110 struct kvm_vcpu *vcpu = arg;
111 int cpu = smp_processor_id();
112
113 if (vcpu->cpu == cpu)
114 vmcs_clear(vcpu->vmcs);
115 if (per_cpu(current_vmcs, cpu) == vcpu->vmcs)
116 per_cpu(current_vmcs, cpu) = NULL;
117}
118
119static unsigned long vmcs_readl(unsigned long field)
120{
121 unsigned long value;
122
123 asm volatile (ASM_VMX_VMREAD_RDX_RAX
124 : "=a"(value) : "d"(field) : "cc");
125 return value;
126}
127
128static u16 vmcs_read16(unsigned long field)
129{
130 return vmcs_readl(field);
131}
132
133static u32 vmcs_read32(unsigned long field)
134{
135 return vmcs_readl(field);
136}
137
138static u64 vmcs_read64(unsigned long field)
139{
140#ifdef __x86_64__
141 return vmcs_readl(field);
142#else
143 return vmcs_readl(field) | ((u64)vmcs_readl(field+1) << 32);
144#endif
145}
146
147static void vmcs_writel(unsigned long field, unsigned long value)
148{
149 u8 error;
150
151 asm volatile (ASM_VMX_VMWRITE_RAX_RDX "; setna %0"
152 : "=q"(error) : "a"(value), "d"(field) : "cc" );
153 if (error)
154 printk(KERN_ERR "vmwrite error: reg %lx value %lx (err %d)\n",
155 field, value, vmcs_read32(VM_INSTRUCTION_ERROR));
156}
157
158static void vmcs_write16(unsigned long field, u16 value)
159{
160 vmcs_writel(field, value);
161}
162
163static void vmcs_write32(unsigned long field, u32 value)
164{
165 vmcs_writel(field, value);
166}
167
168static void vmcs_write64(unsigned long field, u64 value)
169{
170#ifdef __x86_64__
171 vmcs_writel(field, value);
172#else
173 vmcs_writel(field, value);
174 asm volatile ("");
175 vmcs_writel(field+1, value >> 32);
176#endif
177}
178
179/*
180 * Switches to specified vcpu, until a matching vcpu_put(), but assumes
181 * vcpu mutex is already taken.
182 */
183static struct kvm_vcpu *vmx_vcpu_load(struct kvm_vcpu *vcpu)
184{
185 u64 phys_addr = __pa(vcpu->vmcs);
186 int cpu;
187
188 cpu = get_cpu();
189
190 if (vcpu->cpu != cpu) {
191 smp_call_function(__vcpu_clear, vcpu, 0, 1);
192 vcpu->launched = 0;
193 }
194
195 if (per_cpu(current_vmcs, cpu) != vcpu->vmcs) {
196 u8 error;
197
198 per_cpu(current_vmcs, cpu) = vcpu->vmcs;
199 asm volatile (ASM_VMX_VMPTRLD_RAX "; setna %0"
200 : "=g"(error) : "a"(&phys_addr), "m"(phys_addr)
201 : "cc");
202 if (error)
203 printk(KERN_ERR "kvm: vmptrld %p/%llx fail\n",
204 vcpu->vmcs, phys_addr);
205 }
206
207 if (vcpu->cpu != cpu) {
208 struct descriptor_table dt;
209 unsigned long sysenter_esp;
210
211 vcpu->cpu = cpu;
212 /*
213 * Linux uses per-cpu TSS and GDT, so set these when switching
214 * processors.
215 */
216 vmcs_writel(HOST_TR_BASE, read_tr_base()); /* 22.2.4 */
217 get_gdt(&dt);
218 vmcs_writel(HOST_GDTR_BASE, dt.base); /* 22.2.4 */
219
220 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
221 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
222 }
223 return vcpu;
224}
225
226static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
227{
228 put_cpu();
229}
230
231static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu)
232{
233 return vmcs_readl(GUEST_RFLAGS);
234}
235
236static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
237{
238 vmcs_writel(GUEST_RFLAGS, rflags);
239}
240
241static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
242{
243 unsigned long rip;
244 u32 interruptibility;
245
246 rip = vmcs_readl(GUEST_RIP);
247 rip += vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
248 vmcs_writel(GUEST_RIP, rip);
249
250 /*
251 * We emulated an instruction, so temporary interrupt blocking
252 * should be removed, if set.
253 */
254 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
255 if (interruptibility & 3)
256 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO,
257 interruptibility & ~3);
258}
259
260static void vmx_inject_gp(struct kvm_vcpu *vcpu, unsigned error_code)
261{
262 printk(KERN_DEBUG "inject_general_protection: rip 0x%lx\n",
263 vmcs_readl(GUEST_RIP));
264 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, error_code);
265 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
266 GP_VECTOR |
267 INTR_TYPE_EXCEPTION |
268 INTR_INFO_DELIEVER_CODE_MASK |
269 INTR_INFO_VALID_MASK);
270}
271
272/*
273 * reads and returns guest's timestamp counter "register"
274 * guest_tsc = host_tsc + tsc_offset -- 21.3
275 */
276static u64 guest_read_tsc(void)
277{
278 u64 host_tsc, tsc_offset;
279
280 rdtscll(host_tsc);
281 tsc_offset = vmcs_read64(TSC_OFFSET);
282 return host_tsc + tsc_offset;
283}
284
285/*
286 * writes 'guest_tsc' into guest's timestamp counter "register"
287 * guest_tsc = host_tsc + tsc_offset ==> tsc_offset = guest_tsc - host_tsc
288 */
289static void guest_write_tsc(u64 guest_tsc)
290{
291 u64 host_tsc;
292
293 rdtscll(host_tsc);
294 vmcs_write64(TSC_OFFSET, guest_tsc - host_tsc);
295}
296
297static void reload_tss(void)
298{
299#ifndef __x86_64__
300
301 /*
302 * VT restores TR but not its size. Useless.
303 */
304 struct descriptor_table gdt;
305 struct segment_descriptor *descs;
306
307 get_gdt(&gdt);
308 descs = (void *)gdt.base;
309 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
310 load_TR_desc();
311#endif
312}
313
314/*
315 * Reads an msr value (of 'msr_index') into 'pdata'.
316 * Returns 0 on success, non-0 otherwise.
317 * Assumes vcpu_load() was already called.
318 */
319static int vmx_get_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 *pdata)
320{
321 u64 data;
322 struct vmx_msr_entry *msr;
323
324 if (!pdata) {
325 printk(KERN_ERR "BUG: get_msr called with NULL pdata\n");
326 return -EINVAL;
327 }
328
329 switch (msr_index) {
330#ifdef __x86_64__
331 case MSR_FS_BASE:
332 data = vmcs_readl(GUEST_FS_BASE);
333 break;
334 case MSR_GS_BASE:
335 data = vmcs_readl(GUEST_GS_BASE);
336 break;
337 case MSR_EFER:
338 data = vcpu->shadow_efer;
339 break;
340#endif
341 case MSR_IA32_TIME_STAMP_COUNTER:
342 data = guest_read_tsc();
343 break;
344 case MSR_IA32_SYSENTER_CS:
345 data = vmcs_read32(GUEST_SYSENTER_CS);
346 break;
347 case MSR_IA32_SYSENTER_EIP:
348 data = vmcs_read32(GUEST_SYSENTER_EIP);
349 break;
350 case MSR_IA32_SYSENTER_ESP:
351 data = vmcs_read32(GUEST_SYSENTER_ESP);
352 break;
353 case MSR_IA32_MC0_CTL:
354 case MSR_IA32_MCG_STATUS:
355 case MSR_IA32_MCG_CAP:
356 case MSR_IA32_MC0_MISC:
357 case MSR_IA32_MC0_MISC+4:
358 case MSR_IA32_MC0_MISC+8:
359 case MSR_IA32_MC0_MISC+12:
360 case MSR_IA32_MC0_MISC+16:
361 case MSR_IA32_UCODE_REV:
362 /* MTRR registers */
363 case 0xfe:
364 case 0x200 ... 0x2ff:
365 data = 0;
366 break;
367 case MSR_IA32_APICBASE:
368 data = vcpu->apic_base;
369 break;
370 default:
371 msr = find_msr_entry(vcpu, msr_index);
372 if (!msr) {
373 printk(KERN_ERR "kvm: unhandled rdmsr: %x\n", msr_index);
374 return 1;
375 }
376 data = msr->data;
377 break;
378 }
379
380 *pdata = data;
381 return 0;
382}
383
384/*
385 * Writes msr value into into the appropriate "register".
386 * Returns 0 on success, non-0 otherwise.
387 * Assumes vcpu_load() was already called.
388 */
389static int vmx_set_msr(struct kvm_vcpu *vcpu, u32 msr_index, u64 data)
390{
391 struct vmx_msr_entry *msr;
392 switch (msr_index) {
393#ifdef __x86_64__
394 case MSR_FS_BASE:
395 vmcs_writel(GUEST_FS_BASE, data);
396 break;
397 case MSR_GS_BASE:
398 vmcs_writel(GUEST_GS_BASE, data);
399 break;
400#endif
401 case MSR_IA32_SYSENTER_CS:
402 vmcs_write32(GUEST_SYSENTER_CS, data);
403 break;
404 case MSR_IA32_SYSENTER_EIP:
405 vmcs_write32(GUEST_SYSENTER_EIP, data);
406 break;
407 case MSR_IA32_SYSENTER_ESP:
408 vmcs_write32(GUEST_SYSENTER_ESP, data);
409 break;
410#ifdef __x86_64
411 case MSR_EFER:
412 set_efer(vcpu, data);
413 break;
414 case MSR_IA32_MC0_STATUS:
415 printk(KERN_WARNING "%s: MSR_IA32_MC0_STATUS 0x%llx, nop\n"
416 , __FUNCTION__, data);
417 break;
418#endif
419 case MSR_IA32_TIME_STAMP_COUNTER: {
420 guest_write_tsc(data);
421 break;
422 }
423 case MSR_IA32_UCODE_REV:
424 case MSR_IA32_UCODE_WRITE:
425 case 0x200 ... 0x2ff: /* MTRRs */
426 break;
427 case MSR_IA32_APICBASE:
428 vcpu->apic_base = data;
429 break;
430 default:
431 msr = find_msr_entry(vcpu, msr_index);
432 if (!msr) {
433 printk(KERN_ERR "kvm: unhandled wrmsr: 0x%x\n", msr_index);
434 return 1;
435 }
436 msr->data = data;
437 break;
438 }
439
440 return 0;
441}
442
443/*
444 * Sync the rsp and rip registers into the vcpu structure. This allows
445 * registers to be accessed by indexing vcpu->regs.
446 */
447static void vcpu_load_rsp_rip(struct kvm_vcpu *vcpu)
448{
449 vcpu->regs[VCPU_REGS_RSP] = vmcs_readl(GUEST_RSP);
450 vcpu->rip = vmcs_readl(GUEST_RIP);
451}
452
453/*
454 * Syncs rsp and rip back into the vmcs. Should be called after possible
455 * modification.
456 */
457static void vcpu_put_rsp_rip(struct kvm_vcpu *vcpu)
458{
459 vmcs_writel(GUEST_RSP, vcpu->regs[VCPU_REGS_RSP]);
460 vmcs_writel(GUEST_RIP, vcpu->rip);
461}
462
463static int set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_debug_guest *dbg)
464{
465 unsigned long dr7 = 0x400;
466 u32 exception_bitmap;
467 int old_singlestep;
468
469 exception_bitmap = vmcs_read32(EXCEPTION_BITMAP);
470 old_singlestep = vcpu->guest_debug.singlestep;
471
472 vcpu->guest_debug.enabled = dbg->enabled;
473 if (vcpu->guest_debug.enabled) {
474 int i;
475
476 dr7 |= 0x200; /* exact */
477 for (i = 0; i < 4; ++i) {
478 if (!dbg->breakpoints[i].enabled)
479 continue;
480 vcpu->guest_debug.bp[i] = dbg->breakpoints[i].address;
481 dr7 |= 2 << (i*2); /* global enable */
482 dr7 |= 0 << (i*4+16); /* execution breakpoint */
483 }
484
485 exception_bitmap |= (1u << 1); /* Trap debug exceptions */
486
487 vcpu->guest_debug.singlestep = dbg->singlestep;
488 } else {
489 exception_bitmap &= ~(1u << 1); /* Ignore debug exceptions */
490 vcpu->guest_debug.singlestep = 0;
491 }
492
493 if (old_singlestep && !vcpu->guest_debug.singlestep) {
494 unsigned long flags;
495
496 flags = vmcs_readl(GUEST_RFLAGS);
497 flags &= ~(X86_EFLAGS_TF | X86_EFLAGS_RF);
498 vmcs_writel(GUEST_RFLAGS, flags);
499 }
500
501 vmcs_write32(EXCEPTION_BITMAP, exception_bitmap);
502 vmcs_writel(GUEST_DR7, dr7);
503
504 return 0;
505}
506
507static __init int cpu_has_kvm_support(void)
508{
509 unsigned long ecx = cpuid_ecx(1);
510 return test_bit(5, &ecx); /* CPUID.1:ECX.VMX[bit 5] -> VT */
511}
512
513static __init int vmx_disabled_by_bios(void)
514{
515 u64 msr;
516
517 rdmsrl(MSR_IA32_FEATURE_CONTROL, msr);
518 return (msr & 5) == 1; /* locked but not enabled */
519}
520
521static __init void hardware_enable(void *garbage)
522{
523 int cpu = raw_smp_processor_id();
524 u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
525 u64 old;
526
527 rdmsrl(MSR_IA32_FEATURE_CONTROL, old);
528 if ((old & 5) == 0)
529 /* enable and lock */
530 wrmsrl(MSR_IA32_FEATURE_CONTROL, old | 5);
531 write_cr4(read_cr4() | CR4_VMXE); /* FIXME: not cpu hotplug safe */
532 asm volatile (ASM_VMX_VMXON_RAX : : "a"(&phys_addr), "m"(phys_addr)
533 : "memory", "cc");
534}
535
536static void hardware_disable(void *garbage)
537{
538 asm volatile (ASM_VMX_VMXOFF : : : "cc");
539}
540
541static __init void setup_vmcs_descriptor(void)
542{
543 u32 vmx_msr_low, vmx_msr_high;
544
545 rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high);
546 vmcs_descriptor.size = vmx_msr_high & 0x1fff;
547 vmcs_descriptor.order = get_order(vmcs_descriptor.size);
548 vmcs_descriptor.revision_id = vmx_msr_low;
549};
550
551static struct vmcs *alloc_vmcs_cpu(int cpu)
552{
553 int node = cpu_to_node(cpu);
554 struct page *pages;
555 struct vmcs *vmcs;
556
557 pages = alloc_pages_node(node, GFP_KERNEL, vmcs_descriptor.order);
558 if (!pages)
559 return NULL;
560 vmcs = page_address(pages);
561 memset(vmcs, 0, vmcs_descriptor.size);
562 vmcs->revision_id = vmcs_descriptor.revision_id; /* vmcs revision id */
563 return vmcs;
564}
565
566static struct vmcs *alloc_vmcs(void)
567{
568 return alloc_vmcs_cpu(smp_processor_id());
569}
570
571static void free_vmcs(struct vmcs *vmcs)
572{
573 free_pages((unsigned long)vmcs, vmcs_descriptor.order);
574}
575
576static __exit void free_kvm_area(void)
577{
578 int cpu;
579
580 for_each_online_cpu(cpu)
581 free_vmcs(per_cpu(vmxarea, cpu));
582}
583
584extern struct vmcs *alloc_vmcs_cpu(int cpu);
585
586static __init int alloc_kvm_area(void)
587{
588 int cpu;
589
590 for_each_online_cpu(cpu) {
591 struct vmcs *vmcs;
592
593 vmcs = alloc_vmcs_cpu(cpu);
594 if (!vmcs) {
595 free_kvm_area();
596 return -ENOMEM;
597 }
598
599 per_cpu(vmxarea, cpu) = vmcs;
600 }
601 return 0;
602}
603
604static __init int hardware_setup(void)
605{
606 setup_vmcs_descriptor();
607 return alloc_kvm_area();
608}
609
610static __exit void hardware_unsetup(void)
611{
612 free_kvm_area();
613}
614
615static void update_exception_bitmap(struct kvm_vcpu *vcpu)
616{
617 if (vcpu->rmode.active)
618 vmcs_write32(EXCEPTION_BITMAP, ~0);
619 else
620 vmcs_write32(EXCEPTION_BITMAP, 1 << PF_VECTOR);
621}
622
623static void fix_pmode_dataseg(int seg, struct kvm_save_segment *save)
624{
625 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
626
627 if (vmcs_readl(sf->base) == save->base) {
628 vmcs_write16(sf->selector, save->selector);
629 vmcs_writel(sf->base, save->base);
630 vmcs_write32(sf->limit, save->limit);
631 vmcs_write32(sf->ar_bytes, save->ar);
632 } else {
633 u32 dpl = (vmcs_read16(sf->selector) & SELECTOR_RPL_MASK)
634 << AR_DPL_SHIFT;
635 vmcs_write32(sf->ar_bytes, 0x93 | dpl);
636 }
637}
638
639static void enter_pmode(struct kvm_vcpu *vcpu)
640{
641 unsigned long flags;
642
643 vcpu->rmode.active = 0;
644
645 vmcs_writel(GUEST_TR_BASE, vcpu->rmode.tr.base);
646 vmcs_write32(GUEST_TR_LIMIT, vcpu->rmode.tr.limit);
647 vmcs_write32(GUEST_TR_AR_BYTES, vcpu->rmode.tr.ar);
648
649 flags = vmcs_readl(GUEST_RFLAGS);
650 flags &= ~(IOPL_MASK | X86_EFLAGS_VM);
651 flags |= (vcpu->rmode.save_iopl << IOPL_SHIFT);
652 vmcs_writel(GUEST_RFLAGS, flags);
653
654 vmcs_writel(GUEST_CR4, (vmcs_readl(GUEST_CR4) & ~CR4_VME_MASK) |
655 (vmcs_readl(CR4_READ_SHADOW) & CR4_VME_MASK));
656
657 update_exception_bitmap(vcpu);
658
659 fix_pmode_dataseg(VCPU_SREG_ES, &vcpu->rmode.es);
660 fix_pmode_dataseg(VCPU_SREG_DS, &vcpu->rmode.ds);
661 fix_pmode_dataseg(VCPU_SREG_GS, &vcpu->rmode.gs);
662 fix_pmode_dataseg(VCPU_SREG_FS, &vcpu->rmode.fs);
663
664 vmcs_write16(GUEST_SS_SELECTOR, 0);
665 vmcs_write32(GUEST_SS_AR_BYTES, 0x93);
666
667 vmcs_write16(GUEST_CS_SELECTOR,
668 vmcs_read16(GUEST_CS_SELECTOR) & ~SELECTOR_RPL_MASK);
669 vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
670}
671
672static int rmode_tss_base(struct kvm* kvm)
673{
674 gfn_t base_gfn = kvm->memslots[0].base_gfn + kvm->memslots[0].npages - 3;
675 return base_gfn << PAGE_SHIFT;
676}
677
678static void fix_rmode_seg(int seg, struct kvm_save_segment *save)
679{
680 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
681
682 save->selector = vmcs_read16(sf->selector);
683 save->base = vmcs_readl(sf->base);
684 save->limit = vmcs_read32(sf->limit);
685 save->ar = vmcs_read32(sf->ar_bytes);
686 vmcs_write16(sf->selector, vmcs_readl(sf->base) >> 4);
687 vmcs_write32(sf->limit, 0xffff);
688 vmcs_write32(sf->ar_bytes, 0xf3);
689}
690
691static void enter_rmode(struct kvm_vcpu *vcpu)
692{
693 unsigned long flags;
694
695 vcpu->rmode.active = 1;
696
697 vcpu->rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
698 vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
699
700 vcpu->rmode.tr.limit = vmcs_read32(GUEST_TR_LIMIT);
701 vmcs_write32(GUEST_TR_LIMIT, RMODE_TSS_SIZE - 1);
702
703 vcpu->rmode.tr.ar = vmcs_read32(GUEST_TR_AR_BYTES);
704 vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
705
706 flags = vmcs_readl(GUEST_RFLAGS);
707 vcpu->rmode.save_iopl = (flags & IOPL_MASK) >> IOPL_SHIFT;
708
709 flags |= IOPL_MASK | X86_EFLAGS_VM;
710
711 vmcs_writel(GUEST_RFLAGS, flags);
712 vmcs_writel(GUEST_CR4, vmcs_readl(GUEST_CR4) | CR4_VME_MASK);
713 update_exception_bitmap(vcpu);
714
715 vmcs_write16(GUEST_SS_SELECTOR, vmcs_readl(GUEST_SS_BASE) >> 4);
716 vmcs_write32(GUEST_SS_LIMIT, 0xffff);
717 vmcs_write32(GUEST_SS_AR_BYTES, 0xf3);
718
719 vmcs_write32(GUEST_CS_AR_BYTES, 0xf3);
720 vmcs_write16(GUEST_CS_SELECTOR, vmcs_readl(GUEST_CS_BASE) >> 4);
721
722 fix_rmode_seg(VCPU_SREG_ES, &vcpu->rmode.es);
723 fix_rmode_seg(VCPU_SREG_DS, &vcpu->rmode.ds);
724 fix_rmode_seg(VCPU_SREG_GS, &vcpu->rmode.gs);
725 fix_rmode_seg(VCPU_SREG_FS, &vcpu->rmode.fs);
726}
727
728#ifdef __x86_64__
729
730static void enter_lmode(struct kvm_vcpu *vcpu)
731{
732 u32 guest_tr_ar;
733
734 guest_tr_ar = vmcs_read32(GUEST_TR_AR_BYTES);
735 if ((guest_tr_ar & AR_TYPE_MASK) != AR_TYPE_BUSY_64_TSS) {
736 printk(KERN_DEBUG "%s: tss fixup for long mode. \n",
737 __FUNCTION__);
738 vmcs_write32(GUEST_TR_AR_BYTES,
739 (guest_tr_ar & ~AR_TYPE_MASK)
740 | AR_TYPE_BUSY_64_TSS);
741 }
742
743 vcpu->shadow_efer |= EFER_LMA;
744
745 find_msr_entry(vcpu, MSR_EFER)->data |= EFER_LMA | EFER_LME;
746 vmcs_write32(VM_ENTRY_CONTROLS,
747 vmcs_read32(VM_ENTRY_CONTROLS)
748 | VM_ENTRY_CONTROLS_IA32E_MASK);
749}
750
751static void exit_lmode(struct kvm_vcpu *vcpu)
752{
753 vcpu->shadow_efer &= ~EFER_LMA;
754
755 vmcs_write32(VM_ENTRY_CONTROLS,
756 vmcs_read32(VM_ENTRY_CONTROLS)
757 & ~VM_ENTRY_CONTROLS_IA32E_MASK);
758}
759
760#endif
761
762static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
763{
764 if (vcpu->rmode.active && (cr0 & CR0_PE_MASK))
765 enter_pmode(vcpu);
766
767 if (!vcpu->rmode.active && !(cr0 & CR0_PE_MASK))
768 enter_rmode(vcpu);
769
770#ifdef __x86_64__
771 if (vcpu->shadow_efer & EFER_LME) {
772 if (!is_paging(vcpu) && (cr0 & CR0_PG_MASK))
773 enter_lmode(vcpu);
774 if (is_paging(vcpu) && !(cr0 & CR0_PG_MASK))
775 exit_lmode(vcpu);
776 }
777#endif
778
779 vmcs_writel(CR0_READ_SHADOW, cr0);
780 vmcs_writel(GUEST_CR0,
781 (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON);
782 vcpu->cr0 = cr0;
783}
784
785/*
786 * Used when restoring the VM to avoid corrupting segment registers
787 */
788static void vmx_set_cr0_no_modeswitch(struct kvm_vcpu *vcpu, unsigned long cr0)
789{
790 vcpu->rmode.active = ((cr0 & CR0_PE_MASK) == 0);
791 update_exception_bitmap(vcpu);
792 vmcs_writel(CR0_READ_SHADOW, cr0);
793 vmcs_writel(GUEST_CR0,
794 (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON);
795 vcpu->cr0 = cr0;
796}
797
798static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
799{
800 vmcs_writel(GUEST_CR3, cr3);
801}
802
803static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
804{
805 vmcs_writel(CR4_READ_SHADOW, cr4);
806 vmcs_writel(GUEST_CR4, cr4 | (vcpu->rmode.active ?
807 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON));
808 vcpu->cr4 = cr4;
809}
810
811#ifdef __x86_64__
812
813static void vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer)
814{
815 struct vmx_msr_entry *msr = find_msr_entry(vcpu, MSR_EFER);
816
817 vcpu->shadow_efer = efer;
818 if (efer & EFER_LMA) {
819 vmcs_write32(VM_ENTRY_CONTROLS,
820 vmcs_read32(VM_ENTRY_CONTROLS) |
821 VM_ENTRY_CONTROLS_IA32E_MASK);
822 msr->data = efer;
823
824 } else {
825 vmcs_write32(VM_ENTRY_CONTROLS,
826 vmcs_read32(VM_ENTRY_CONTROLS) &
827 ~VM_ENTRY_CONTROLS_IA32E_MASK);
828
829 msr->data = efer & ~EFER_LME;
830 }
831}
832
833#endif
834
835static u64 vmx_get_segment_base(struct kvm_vcpu *vcpu, int seg)
836{
837 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
838
839 return vmcs_readl(sf->base);
840}
841
842static void vmx_get_segment(struct kvm_vcpu *vcpu,
843 struct kvm_segment *var, int seg)
844{
845 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
846 u32 ar;
847
848 var->base = vmcs_readl(sf->base);
849 var->limit = vmcs_read32(sf->limit);
850 var->selector = vmcs_read16(sf->selector);
851 ar = vmcs_read32(sf->ar_bytes);
852 if (ar & AR_UNUSABLE_MASK)
853 ar = 0;
854 var->type = ar & 15;
855 var->s = (ar >> 4) & 1;
856 var->dpl = (ar >> 5) & 3;
857 var->present = (ar >> 7) & 1;
858 var->avl = (ar >> 12) & 1;
859 var->l = (ar >> 13) & 1;
860 var->db = (ar >> 14) & 1;
861 var->g = (ar >> 15) & 1;
862 var->unusable = (ar >> 16) & 1;
863}
864
865static void vmx_set_segment(struct kvm_vcpu *vcpu,
866 struct kvm_segment *var, int seg)
867{
868 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
869 u32 ar;
870
871 vmcs_writel(sf->base, var->base);
872 vmcs_write32(sf->limit, var->limit);
873 vmcs_write16(sf->selector, var->selector);
874 if (var->unusable)
875 ar = 1 << 16;
876 else {
877 ar = var->type & 15;
878 ar |= (var->s & 1) << 4;
879 ar |= (var->dpl & 3) << 5;
880 ar |= (var->present & 1) << 7;
881 ar |= (var->avl & 1) << 12;
882 ar |= (var->l & 1) << 13;
883 ar |= (var->db & 1) << 14;
884 ar |= (var->g & 1) << 15;
885 }
886 vmcs_write32(sf->ar_bytes, ar);
887}
888
889static int vmx_is_long_mode(struct kvm_vcpu *vcpu)
890{
891 return vmcs_read32(VM_ENTRY_CONTROLS) & VM_ENTRY_CONTROLS_IA32E_MASK;
892}
893
894static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
895{
896 u32 ar = vmcs_read32(GUEST_CS_AR_BYTES);
897
898 *db = (ar >> 14) & 1;
899 *l = (ar >> 13) & 1;
900}
901
902static void vmx_get_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
903{
904 dt->limit = vmcs_read32(GUEST_IDTR_LIMIT);
905 dt->base = vmcs_readl(GUEST_IDTR_BASE);
906}
907
908static void vmx_set_idt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
909{
910 vmcs_write32(GUEST_IDTR_LIMIT, dt->limit);
911 vmcs_writel(GUEST_IDTR_BASE, dt->base);
912}
913
914static void vmx_get_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
915{
916 dt->limit = vmcs_read32(GUEST_GDTR_LIMIT);
917 dt->base = vmcs_readl(GUEST_GDTR_BASE);
918}
919
920static void vmx_set_gdt(struct kvm_vcpu *vcpu, struct descriptor_table *dt)
921{
922 vmcs_write32(GUEST_GDTR_LIMIT, dt->limit);
923 vmcs_writel(GUEST_GDTR_BASE, dt->base);
924}
925
926static int init_rmode_tss(struct kvm* kvm)
927{
928 struct page *p1, *p2, *p3;
929 gfn_t fn = rmode_tss_base(kvm) >> PAGE_SHIFT;
930 char *page;
931
932 p1 = _gfn_to_page(kvm, fn++);
933 p2 = _gfn_to_page(kvm, fn++);
934 p3 = _gfn_to_page(kvm, fn);
935
936 if (!p1 || !p2 || !p3) {
937 kvm_printf(kvm,"%s: gfn_to_page failed\n", __FUNCTION__);
938 return 0;
939 }
940
941 page = kmap_atomic(p1, KM_USER0);
942 memset(page, 0, PAGE_SIZE);
943 *(u16*)(page + 0x66) = TSS_BASE_SIZE + TSS_REDIRECTION_SIZE;
944 kunmap_atomic(page, KM_USER0);
945
946 page = kmap_atomic(p2, KM_USER0);
947 memset(page, 0, PAGE_SIZE);
948 kunmap_atomic(page, KM_USER0);
949
950 page = kmap_atomic(p3, KM_USER0);
951 memset(page, 0, PAGE_SIZE);
952 *(page + RMODE_TSS_SIZE - 2 * PAGE_SIZE - 1) = ~0;
953 kunmap_atomic(page, KM_USER0);
954
955 return 1;
956}
957
958static void vmcs_write32_fixedbits(u32 msr, u32 vmcs_field, u32 val)
959{
960 u32 msr_high, msr_low;
961
962 rdmsr(msr, msr_low, msr_high);
963
964 val &= msr_high;
965 val |= msr_low;
966 vmcs_write32(vmcs_field, val);
967}
968
969static void seg_setup(int seg)
970{
971 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
972
973 vmcs_write16(sf->selector, 0);
974 vmcs_writel(sf->base, 0);
975 vmcs_write32(sf->limit, 0xffff);
976 vmcs_write32(sf->ar_bytes, 0x93);
977}
978
979/*
980 * Sets up the vmcs for emulated real mode.
981 */
982static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
983{
984 u32 host_sysenter_cs;
985 u32 junk;
986 unsigned long a;
987 struct descriptor_table dt;
988 int i;
989 int ret = 0;
990 int nr_good_msrs;
991 extern asmlinkage void kvm_vmx_return(void);
992
993 if (!init_rmode_tss(vcpu->kvm)) {
994 ret = -ENOMEM;
995 goto out;
996 }
997
998 memset(vcpu->regs, 0, sizeof(vcpu->regs));
999 vcpu->regs[VCPU_REGS_RDX] = get_rdx_init_val();
1000 vcpu->cr8 = 0;
1001 vcpu->apic_base = 0xfee00000 |
1002 /*for vcpu 0*/ MSR_IA32_APICBASE_BSP |
1003 MSR_IA32_APICBASE_ENABLE;
1004
1005 fx_init(vcpu);
1006
1007 /*
1008 * GUEST_CS_BASE should really be 0xffff0000, but VT vm86 mode
1009 * insists on having GUEST_CS_BASE == GUEST_CS_SELECTOR << 4. Sigh.
1010 */
1011 vmcs_write16(GUEST_CS_SELECTOR, 0xf000);
1012 vmcs_writel(GUEST_CS_BASE, 0x000f0000);
1013 vmcs_write32(GUEST_CS_LIMIT, 0xffff);
1014 vmcs_write32(GUEST_CS_AR_BYTES, 0x9b);
1015
1016 seg_setup(VCPU_SREG_DS);
1017 seg_setup(VCPU_SREG_ES);
1018 seg_setup(VCPU_SREG_FS);
1019 seg_setup(VCPU_SREG_GS);
1020 seg_setup(VCPU_SREG_SS);
1021
1022 vmcs_write16(GUEST_TR_SELECTOR, 0);
1023 vmcs_writel(GUEST_TR_BASE, 0);
1024 vmcs_write32(GUEST_TR_LIMIT, 0xffff);
1025 vmcs_write32(GUEST_TR_AR_BYTES, 0x008b);
1026
1027 vmcs_write16(GUEST_LDTR_SELECTOR, 0);
1028 vmcs_writel(GUEST_LDTR_BASE, 0);
1029 vmcs_write32(GUEST_LDTR_LIMIT, 0xffff);
1030 vmcs_write32(GUEST_LDTR_AR_BYTES, 0x00082);
1031
1032 vmcs_write32(GUEST_SYSENTER_CS, 0);
1033 vmcs_writel(GUEST_SYSENTER_ESP, 0);
1034 vmcs_writel(GUEST_SYSENTER_EIP, 0);
1035
1036 vmcs_writel(GUEST_RFLAGS, 0x02);
1037 vmcs_writel(GUEST_RIP, 0xfff0);
1038 vmcs_writel(GUEST_RSP, 0);
1039
1040 vmcs_writel(GUEST_CR3, 0);
1041
1042 //todo: dr0 = dr1 = dr2 = dr3 = 0; dr6 = 0xffff0ff0
1043 vmcs_writel(GUEST_DR7, 0x400);
1044
1045 vmcs_writel(GUEST_GDTR_BASE, 0);
1046 vmcs_write32(GUEST_GDTR_LIMIT, 0xffff);
1047
1048 vmcs_writel(GUEST_IDTR_BASE, 0);
1049 vmcs_write32(GUEST_IDTR_LIMIT, 0xffff);
1050
1051 vmcs_write32(GUEST_ACTIVITY_STATE, 0);
1052 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, 0);
1053 vmcs_write32(GUEST_PENDING_DBG_EXCEPTIONS, 0);
1054
1055 /* I/O */
1056 vmcs_write64(IO_BITMAP_A, 0);
1057 vmcs_write64(IO_BITMAP_B, 0);
1058
1059 guest_write_tsc(0);
1060
1061 vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */
1062
1063 /* Special registers */
1064 vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
1065
1066 /* Control */
1067 vmcs_write32_fixedbits(MSR_IA32_VMX_PINBASED_CTLS_MSR,
1068 PIN_BASED_VM_EXEC_CONTROL,
1069 PIN_BASED_EXT_INTR_MASK /* 20.6.1 */
1070 | PIN_BASED_NMI_EXITING /* 20.6.1 */
1071 );
1072 vmcs_write32_fixedbits(MSR_IA32_VMX_PROCBASED_CTLS_MSR,
1073 CPU_BASED_VM_EXEC_CONTROL,
1074 CPU_BASED_HLT_EXITING /* 20.6.2 */
1075 | CPU_BASED_CR8_LOAD_EXITING /* 20.6.2 */
1076 | CPU_BASED_CR8_STORE_EXITING /* 20.6.2 */
1077 | CPU_BASED_UNCOND_IO_EXITING /* 20.6.2 */
1078 | CPU_BASED_INVDPG_EXITING
1079 | CPU_BASED_MOV_DR_EXITING
1080 | CPU_BASED_USE_TSC_OFFSETING /* 21.3 */
1081 );
1082
1083 vmcs_write32(EXCEPTION_BITMAP, 1 << PF_VECTOR);
1084 vmcs_write32(PAGE_FAULT_ERROR_CODE_MASK, 0);
1085 vmcs_write32(PAGE_FAULT_ERROR_CODE_MATCH, 0);
1086 vmcs_write32(CR3_TARGET_COUNT, 0); /* 22.2.1 */
1087
1088 vmcs_writel(HOST_CR0, read_cr0()); /* 22.2.3 */
1089 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
1090 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
1091
1092 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
1093 vmcs_write16(HOST_DS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
1094 vmcs_write16(HOST_ES_SELECTOR, __KERNEL_DS); /* 22.2.4 */
1095 vmcs_write16(HOST_FS_SELECTOR, read_fs()); /* 22.2.4 */
1096 vmcs_write16(HOST_GS_SELECTOR, read_gs()); /* 22.2.4 */
1097 vmcs_write16(HOST_SS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
1098#ifdef __x86_64__
1099 rdmsrl(MSR_FS_BASE, a);
1100 vmcs_writel(HOST_FS_BASE, a); /* 22.2.4 */
1101 rdmsrl(MSR_GS_BASE, a);
1102 vmcs_writel(HOST_GS_BASE, a); /* 22.2.4 */
1103#else
1104 vmcs_writel(HOST_FS_BASE, 0); /* 22.2.4 */
1105 vmcs_writel(HOST_GS_BASE, 0); /* 22.2.4 */
1106#endif
1107
1108 vmcs_write16(HOST_TR_SELECTOR, GDT_ENTRY_TSS*8); /* 22.2.4 */
1109
1110 get_idt(&dt);
1111 vmcs_writel(HOST_IDTR_BASE, dt.base); /* 22.2.4 */
1112
1113
1114 vmcs_writel(HOST_RIP, (unsigned long)kvm_vmx_return); /* 22.2.5 */
1115
1116 rdmsr(MSR_IA32_SYSENTER_CS, host_sysenter_cs, junk);
1117 vmcs_write32(HOST_IA32_SYSENTER_CS, host_sysenter_cs);
1118 rdmsrl(MSR_IA32_SYSENTER_ESP, a);
1119 vmcs_writel(HOST_IA32_SYSENTER_ESP, a); /* 22.2.3 */
1120 rdmsrl(MSR_IA32_SYSENTER_EIP, a);
1121 vmcs_writel(HOST_IA32_SYSENTER_EIP, a); /* 22.2.3 */
1122
1123 ret = -ENOMEM;
1124 vcpu->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1125 if (!vcpu->guest_msrs)
1126 goto out;
1127 vcpu->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
1128 if (!vcpu->host_msrs)
1129 goto out_free_guest_msrs;
1130
1131 for (i = 0; i < NR_VMX_MSR; ++i) {
1132 u32 index = vmx_msr_index[i];
1133 u32 data_low, data_high;
1134 u64 data;
1135 int j = vcpu->nmsrs;
1136
1137 if (rdmsr_safe(index, &data_low, &data_high) < 0)
1138 continue;
1139 data = data_low | ((u64)data_high << 32);
1140 vcpu->host_msrs[j].index = index;
1141 vcpu->host_msrs[j].reserved = 0;
1142 vcpu->host_msrs[j].data = data;
1143 vcpu->guest_msrs[j] = vcpu->host_msrs[j];
1144 ++vcpu->nmsrs;
1145 }
1146 printk(KERN_DEBUG "kvm: msrs: %d\n", vcpu->nmsrs);
1147
1148 nr_good_msrs = vcpu->nmsrs - NR_BAD_MSRS;
1149 vmcs_writel(VM_ENTRY_MSR_LOAD_ADDR,
1150 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS));
1151 vmcs_writel(VM_EXIT_MSR_STORE_ADDR,
1152 virt_to_phys(vcpu->guest_msrs + NR_BAD_MSRS));
1153 vmcs_writel(VM_EXIT_MSR_LOAD_ADDR,
1154 virt_to_phys(vcpu->host_msrs + NR_BAD_MSRS));
1155 vmcs_write32_fixedbits(MSR_IA32_VMX_EXIT_CTLS_MSR, VM_EXIT_CONTROLS,
1156 (HOST_IS_64 << 9)); /* 22.2,1, 20.7.1 */
1157 vmcs_write32(VM_EXIT_MSR_STORE_COUNT, nr_good_msrs); /* 22.2.2 */
1158 vmcs_write32(VM_EXIT_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */
1159 vmcs_write32(VM_ENTRY_MSR_LOAD_COUNT, nr_good_msrs); /* 22.2.2 */
1160
1161
1162 /* 22.2.1, 20.8.1 */
1163 vmcs_write32_fixedbits(MSR_IA32_VMX_ENTRY_CTLS_MSR,
1164 VM_ENTRY_CONTROLS, 0);
1165 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0); /* 22.2.1 */
1166
1167 vmcs_writel(VIRTUAL_APIC_PAGE_ADDR, 0);
1168 vmcs_writel(TPR_THRESHOLD, 0);
1169
1170 vmcs_writel(CR0_GUEST_HOST_MASK, KVM_GUEST_CR0_MASK);
1171 vmcs_writel(CR4_GUEST_HOST_MASK, KVM_GUEST_CR4_MASK);
1172
1173 vcpu->cr0 = 0x60000010;
1174 vmx_set_cr0(vcpu, vcpu->cr0); // enter rmode
1175 vmx_set_cr4(vcpu, 0);
1176#ifdef __x86_64__
1177 vmx_set_efer(vcpu, 0);
1178#endif
1179
1180 return 0;
1181
1182out_free_guest_msrs:
1183 kfree(vcpu->guest_msrs);
1184out:
1185 return ret;
1186}
1187
1188static void inject_rmode_irq(struct kvm_vcpu *vcpu, int irq)
1189{
1190 u16 ent[2];
1191 u16 cs;
1192 u16 ip;
1193 unsigned long flags;
1194 unsigned long ss_base = vmcs_readl(GUEST_SS_BASE);
1195 u16 sp = vmcs_readl(GUEST_RSP);
1196 u32 ss_limit = vmcs_read32(GUEST_SS_LIMIT);
1197
1198 if (sp > ss_limit || sp - 6 > sp) {
1199 vcpu_printf(vcpu, "%s: #SS, rsp 0x%lx ss 0x%lx limit 0x%x\n",
1200 __FUNCTION__,
1201 vmcs_readl(GUEST_RSP),
1202 vmcs_readl(GUEST_SS_BASE),
1203 vmcs_read32(GUEST_SS_LIMIT));
1204 return;
1205 }
1206
1207 if (kvm_read_guest(vcpu, irq * sizeof(ent), sizeof(ent), &ent) !=
1208 sizeof(ent)) {
1209 vcpu_printf(vcpu, "%s: read guest err\n", __FUNCTION__);
1210 return;
1211 }
1212
1213 flags = vmcs_readl(GUEST_RFLAGS);
1214 cs = vmcs_readl(GUEST_CS_BASE) >> 4;
1215 ip = vmcs_readl(GUEST_RIP);
1216
1217
1218 if (kvm_write_guest(vcpu, ss_base + sp - 2, 2, &flags) != 2 ||
1219 kvm_write_guest(vcpu, ss_base + sp - 4, 2, &cs) != 2 ||
1220 kvm_write_guest(vcpu, ss_base + sp - 6, 2, &ip) != 2) {
1221 vcpu_printf(vcpu, "%s: write guest err\n", __FUNCTION__);
1222 return;
1223 }
1224
1225 vmcs_writel(GUEST_RFLAGS, flags &
1226 ~( X86_EFLAGS_IF | X86_EFLAGS_AC | X86_EFLAGS_TF));
1227 vmcs_write16(GUEST_CS_SELECTOR, ent[1]) ;
1228 vmcs_writel(GUEST_CS_BASE, ent[1] << 4);
1229 vmcs_writel(GUEST_RIP, ent[0]);
1230 vmcs_writel(GUEST_RSP, (vmcs_readl(GUEST_RSP) & ~0xffff) | (sp - 6));
1231}
1232
1233static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
1234{
1235 int word_index = __ffs(vcpu->irq_summary);
1236 int bit_index = __ffs(vcpu->irq_pending[word_index]);
1237 int irq = word_index * BITS_PER_LONG + bit_index;
1238
1239 clear_bit(bit_index, &vcpu->irq_pending[word_index]);
1240 if (!vcpu->irq_pending[word_index])
1241 clear_bit(word_index, &vcpu->irq_summary);
1242
1243 if (vcpu->rmode.active) {
1244 inject_rmode_irq(vcpu, irq);
1245 return;
1246 }
1247 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
1248 irq | INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
1249}
1250
1251static void kvm_try_inject_irq(struct kvm_vcpu *vcpu)
1252{
1253 if ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF)
1254 && (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0)
1255 /*
1256 * Interrupts enabled, and not blocked by sti or mov ss. Good.
1257 */
1258 kvm_do_inject_irq(vcpu);
1259 else
1260 /*
1261 * Interrupts blocked. Wait for unblock.
1262 */
1263 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
1264 vmcs_read32(CPU_BASED_VM_EXEC_CONTROL)
1265 | CPU_BASED_VIRTUAL_INTR_PENDING);
1266}
1267
1268static void kvm_guest_debug_pre(struct kvm_vcpu *vcpu)
1269{
1270 struct kvm_guest_debug *dbg = &vcpu->guest_debug;
1271
1272 set_debugreg(dbg->bp[0], 0);
1273 set_debugreg(dbg->bp[1], 1);
1274 set_debugreg(dbg->bp[2], 2);
1275 set_debugreg(dbg->bp[3], 3);
1276
1277 if (dbg->singlestep) {
1278 unsigned long flags;
1279
1280 flags = vmcs_readl(GUEST_RFLAGS);
1281 flags |= X86_EFLAGS_TF | X86_EFLAGS_RF;
1282 vmcs_writel(GUEST_RFLAGS, flags);
1283 }
1284}
1285
1286static int handle_rmode_exception(struct kvm_vcpu *vcpu,
1287 int vec, u32 err_code)
1288{
1289 if (!vcpu->rmode.active)
1290 return 0;
1291
1292 if (vec == GP_VECTOR && err_code == 0)
1293 if (emulate_instruction(vcpu, NULL, 0, 0) == EMULATE_DONE)
1294 return 1;
1295 return 0;
1296}
1297
1298static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1299{
1300 u32 intr_info, error_code;
1301 unsigned long cr2, rip;
1302 u32 vect_info;
1303 enum emulation_result er;
1304
1305 vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
1306 intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
1307
1308 if ((vect_info & VECTORING_INFO_VALID_MASK) &&
1309 !is_page_fault(intr_info)) {
1310 printk(KERN_ERR "%s: unexpected, vectoring info 0x%x "
1311 "intr info 0x%x\n", __FUNCTION__, vect_info, intr_info);
1312 }
1313
1314 if (is_external_interrupt(vect_info)) {
1315 int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
1316 set_bit(irq, vcpu->irq_pending);
1317 set_bit(irq / BITS_PER_LONG, &vcpu->irq_summary);
1318 }
1319
1320 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == 0x200) { /* nmi */
1321 asm ("int $2");
1322 return 1;
1323 }
1324 error_code = 0;
1325 rip = vmcs_readl(GUEST_RIP);
1326 if (intr_info & INTR_INFO_DELIEVER_CODE_MASK)
1327 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
1328 if (is_page_fault(intr_info)) {
1329 cr2 = vmcs_readl(EXIT_QUALIFICATION);
1330
1331 spin_lock(&vcpu->kvm->lock);
1332 if (!vcpu->mmu.page_fault(vcpu, cr2, error_code)) {
1333 spin_unlock(&vcpu->kvm->lock);
1334 return 1;
1335 }
1336
1337 er = emulate_instruction(vcpu, kvm_run, cr2, error_code);
1338 spin_unlock(&vcpu->kvm->lock);
1339
1340 switch (er) {
1341 case EMULATE_DONE:
1342 return 1;
1343 case EMULATE_DO_MMIO:
1344 ++kvm_stat.mmio_exits;
1345 kvm_run->exit_reason = KVM_EXIT_MMIO;
1346 return 0;
1347 case EMULATE_FAIL:
1348 vcpu_printf(vcpu, "%s: emulate fail\n", __FUNCTION__);
1349 break;
1350 default:
1351 BUG();
1352 }
1353 }
1354
1355 if (vcpu->rmode.active &&
1356 handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK,
1357 error_code))
1358 return 1;
1359
1360 if ((intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK)) == (INTR_TYPE_EXCEPTION | 1)) {
1361 kvm_run->exit_reason = KVM_EXIT_DEBUG;
1362 return 0;
1363 }
1364 kvm_run->exit_reason = KVM_EXIT_EXCEPTION;
1365 kvm_run->ex.exception = intr_info & INTR_INFO_VECTOR_MASK;
1366 kvm_run->ex.error_code = error_code;
1367 return 0;
1368}
1369
1370static int handle_external_interrupt(struct kvm_vcpu *vcpu,
1371 struct kvm_run *kvm_run)
1372{
1373 ++kvm_stat.irq_exits;
1374 return 1;
1375}
1376
1377
1378static int get_io_count(struct kvm_vcpu *vcpu, u64 *count)
1379{
1380 u64 inst;
1381 gva_t rip;
1382 int countr_size;
1383 int i, n;
1384
1385 if ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_VM)) {
1386 countr_size = 2;
1387 } else {
1388 u32 cs_ar = vmcs_read32(GUEST_CS_AR_BYTES);
1389
1390 countr_size = (cs_ar & AR_L_MASK) ? 8:
1391 (cs_ar & AR_DB_MASK) ? 4: 2;
1392 }
1393
1394 rip = vmcs_readl(GUEST_RIP);
1395 if (countr_size != 8)
1396 rip += vmcs_readl(GUEST_CS_BASE);
1397
1398 n = kvm_read_guest(vcpu, rip, sizeof(inst), &inst);
1399
1400 for (i = 0; i < n; i++) {
1401 switch (((u8*)&inst)[i]) {
1402 case 0xf0:
1403 case 0xf2:
1404 case 0xf3:
1405 case 0x2e:
1406 case 0x36:
1407 case 0x3e:
1408 case 0x26:
1409 case 0x64:
1410 case 0x65:
1411 case 0x66:
1412 break;
1413 case 0x67:
1414 countr_size = (countr_size == 2) ? 4: (countr_size >> 1);
1415 default:
1416 goto done;
1417 }
1418 }
1419 return 0;
1420done:
1421 countr_size *= 8;
1422 *count = vcpu->regs[VCPU_REGS_RCX] & (~0ULL >> (64 - countr_size));
1423 return 1;
1424}
1425
1426static int handle_io(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1427{
1428 u64 exit_qualification;
1429
1430 ++kvm_stat.io_exits;
1431 exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
1432 kvm_run->exit_reason = KVM_EXIT_IO;
1433 if (exit_qualification & 8)
1434 kvm_run->io.direction = KVM_EXIT_IO_IN;
1435 else
1436 kvm_run->io.direction = KVM_EXIT_IO_OUT;
1437 kvm_run->io.size = (exit_qualification & 7) + 1;
1438 kvm_run->io.string = (exit_qualification & 16) != 0;
1439 kvm_run->io.string_down
1440 = (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_DF) != 0;
1441 kvm_run->io.rep = (exit_qualification & 32) != 0;
1442 kvm_run->io.port = exit_qualification >> 16;
1443 if (kvm_run->io.string) {
1444 if (!get_io_count(vcpu, &kvm_run->io.count))
1445 return 1;
1446 kvm_run->io.address = vmcs_readl(GUEST_LINEAR_ADDRESS);
1447 } else
1448 kvm_run->io.value = vcpu->regs[VCPU_REGS_RAX]; /* rax */
1449 return 0;
1450}
1451
1452static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1453{
1454 u64 address = vmcs_read64(EXIT_QUALIFICATION);
1455 int instruction_length = vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
1456 spin_lock(&vcpu->kvm->lock);
1457 vcpu->mmu.inval_page(vcpu, address);
1458 spin_unlock(&vcpu->kvm->lock);
1459 vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP) + instruction_length);
1460 return 1;
1461}
1462
1463static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1464{
1465 u64 exit_qualification;
1466 int cr;
1467 int reg;
1468
1469 exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
1470 cr = exit_qualification & 15;
1471 reg = (exit_qualification >> 8) & 15;
1472 switch ((exit_qualification >> 4) & 3) {
1473 case 0: /* mov to cr */
1474 switch (cr) {
1475 case 0:
1476 vcpu_load_rsp_rip(vcpu);
1477 set_cr0(vcpu, vcpu->regs[reg]);
1478 skip_emulated_instruction(vcpu);
1479 return 1;
1480 case 3:
1481 vcpu_load_rsp_rip(vcpu);
1482 set_cr3(vcpu, vcpu->regs[reg]);
1483 skip_emulated_instruction(vcpu);
1484 return 1;
1485 case 4:
1486 vcpu_load_rsp_rip(vcpu);
1487 set_cr4(vcpu, vcpu->regs[reg]);
1488 skip_emulated_instruction(vcpu);
1489 return 1;
1490 case 8:
1491 vcpu_load_rsp_rip(vcpu);
1492 set_cr8(vcpu, vcpu->regs[reg]);
1493 skip_emulated_instruction(vcpu);
1494 return 1;
1495 };
1496 break;
1497 case 1: /*mov from cr*/
1498 switch (cr) {
1499 case 3:
1500 vcpu_load_rsp_rip(vcpu);
1501 vcpu->regs[reg] = vcpu->cr3;
1502 vcpu_put_rsp_rip(vcpu);
1503 skip_emulated_instruction(vcpu);
1504 return 1;
1505 case 8:
1506 printk(KERN_DEBUG "handle_cr: read CR8 "
1507 "cpu erratum AA15\n");
1508 vcpu_load_rsp_rip(vcpu);
1509 vcpu->regs[reg] = vcpu->cr8;
1510 vcpu_put_rsp_rip(vcpu);
1511 skip_emulated_instruction(vcpu);
1512 return 1;
1513 }
1514 break;
1515 case 3: /* lmsw */
1516 lmsw(vcpu, (exit_qualification >> LMSW_SOURCE_DATA_SHIFT) & 0x0f);
1517
1518 skip_emulated_instruction(vcpu);
1519 return 1;
1520 default:
1521 break;
1522 }
1523 kvm_run->exit_reason = 0;
1524 printk(KERN_ERR "kvm: unhandled control register: op %d cr %d\n",
1525 (int)(exit_qualification >> 4) & 3, cr);
1526 return 0;
1527}
1528
1529static int handle_dr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1530{
1531 u64 exit_qualification;
1532 unsigned long val;
1533 int dr, reg;
1534
1535 /*
1536 * FIXME: this code assumes the host is debugging the guest.
1537 * need to deal with guest debugging itself too.
1538 */
1539 exit_qualification = vmcs_read64(EXIT_QUALIFICATION);
1540 dr = exit_qualification & 7;
1541 reg = (exit_qualification >> 8) & 15;
1542 vcpu_load_rsp_rip(vcpu);
1543 if (exit_qualification & 16) {
1544 /* mov from dr */
1545 switch (dr) {
1546 case 6:
1547 val = 0xffff0ff0;
1548 break;
1549 case 7:
1550 val = 0x400;
1551 break;
1552 default:
1553 val = 0;
1554 }
1555 vcpu->regs[reg] = val;
1556 } else {
1557 /* mov to dr */
1558 }
1559 vcpu_put_rsp_rip(vcpu);
1560 skip_emulated_instruction(vcpu);
1561 return 1;
1562}
1563
1564static int handle_cpuid(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1565{
1566 kvm_run->exit_reason = KVM_EXIT_CPUID;
1567 return 0;
1568}
1569
1570static int handle_rdmsr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1571{
1572 u32 ecx = vcpu->regs[VCPU_REGS_RCX];
1573 u64 data;
1574
1575 if (vmx_get_msr(vcpu, ecx, &data)) {
1576 vmx_inject_gp(vcpu, 0);
1577 return 1;
1578 }
1579
1580 /* FIXME: handling of bits 32:63 of rax, rdx */
1581 vcpu->regs[VCPU_REGS_RAX] = data & -1u;
1582 vcpu->regs[VCPU_REGS_RDX] = (data >> 32) & -1u;
1583 skip_emulated_instruction(vcpu);
1584 return 1;
1585}
1586
1587static int handle_wrmsr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1588{
1589 u32 ecx = vcpu->regs[VCPU_REGS_RCX];
1590 u64 data = (vcpu->regs[VCPU_REGS_RAX] & -1u)
1591 | ((u64)(vcpu->regs[VCPU_REGS_RDX] & -1u) << 32);
1592
1593 if (vmx_set_msr(vcpu, ecx, data) != 0) {
1594 vmx_inject_gp(vcpu, 0);
1595 return 1;
1596 }
1597
1598 skip_emulated_instruction(vcpu);
1599 return 1;
1600}
1601
1602static int handle_interrupt_window(struct kvm_vcpu *vcpu,
1603 struct kvm_run *kvm_run)
1604{
1605 /* Turn off interrupt window reporting. */
1606 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL,
1607 vmcs_read32(CPU_BASED_VM_EXEC_CONTROL)
1608 & ~CPU_BASED_VIRTUAL_INTR_PENDING);
1609 return 1;
1610}
1611
1612static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1613{
1614 skip_emulated_instruction(vcpu);
1615 if (vcpu->irq_summary && (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF))
1616 return 1;
1617
1618 kvm_run->exit_reason = KVM_EXIT_HLT;
1619 return 0;
1620}
1621
1622/*
1623 * The exit handlers return 1 if the exit was handled fully and guest execution
1624 * may resume. Otherwise they set the kvm_run parameter to indicate what needs
1625 * to be done to userspace and return 0.
1626 */
1627static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
1628 struct kvm_run *kvm_run) = {
1629 [EXIT_REASON_EXCEPTION_NMI] = handle_exception,
1630 [EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt,
1631 [EXIT_REASON_IO_INSTRUCTION] = handle_io,
1632 [EXIT_REASON_INVLPG] = handle_invlpg,
1633 [EXIT_REASON_CR_ACCESS] = handle_cr,
1634 [EXIT_REASON_DR_ACCESS] = handle_dr,
1635 [EXIT_REASON_CPUID] = handle_cpuid,
1636 [EXIT_REASON_MSR_READ] = handle_rdmsr,
1637 [EXIT_REASON_MSR_WRITE] = handle_wrmsr,
1638 [EXIT_REASON_PENDING_INTERRUPT] = handle_interrupt_window,
1639 [EXIT_REASON_HLT] = handle_halt,
1640};
1641
1642static const int kvm_vmx_max_exit_handlers =
1643 sizeof(kvm_vmx_exit_handlers) / sizeof(*kvm_vmx_exit_handlers);
1644
1645/*
1646 * The guest has exited. See if we can fix it or if we need userspace
1647 * assistance.
1648 */
1649static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
1650{
1651 u32 vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
1652 u32 exit_reason = vmcs_read32(VM_EXIT_REASON);
1653
1654 if ( (vectoring_info & VECTORING_INFO_VALID_MASK) &&
1655 exit_reason != EXIT_REASON_EXCEPTION_NMI )
1656 printk(KERN_WARNING "%s: unexpected, valid vectoring info and "
1657 "exit reason is 0x%x\n", __FUNCTION__, exit_reason);
1658 kvm_run->instruction_length = vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
1659 if (exit_reason < kvm_vmx_max_exit_handlers
1660 && kvm_vmx_exit_handlers[exit_reason])
1661 return kvm_vmx_exit_handlers[exit_reason](vcpu, kvm_run);
1662 else {
1663 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
1664 kvm_run->hw.hardware_exit_reason = exit_reason;
1665 }
1666 return 0;
1667}
1668
1669static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1670{
1671 u8 fail;
1672 u16 fs_sel, gs_sel, ldt_sel;
1673 int fs_gs_ldt_reload_needed;
1674
1675again:
1676 /*
1677 * Set host fs and gs selectors. Unfortunately, 22.2.3 does not
1678 * allow segment selectors with cpl > 0 or ti == 1.
1679 */
1680 fs_sel = read_fs();
1681 gs_sel = read_gs();
1682 ldt_sel = read_ldt();
1683 fs_gs_ldt_reload_needed = (fs_sel & 7) | (gs_sel & 7) | ldt_sel;
1684 if (!fs_gs_ldt_reload_needed) {
1685 vmcs_write16(HOST_FS_SELECTOR, fs_sel);
1686 vmcs_write16(HOST_GS_SELECTOR, gs_sel);
1687 } else {
1688 vmcs_write16(HOST_FS_SELECTOR, 0);
1689 vmcs_write16(HOST_GS_SELECTOR, 0);
1690 }
1691
1692#ifdef __x86_64__
1693 vmcs_writel(HOST_FS_BASE, read_msr(MSR_FS_BASE));
1694 vmcs_writel(HOST_GS_BASE, read_msr(MSR_GS_BASE));
1695#else
1696 vmcs_writel(HOST_FS_BASE, segment_base(fs_sel));
1697 vmcs_writel(HOST_GS_BASE, segment_base(gs_sel));
1698#endif
1699
1700 if (vcpu->irq_summary &&
1701 !(vmcs_read32(VM_ENTRY_INTR_INFO_FIELD) & INTR_INFO_VALID_MASK))
1702 kvm_try_inject_irq(vcpu);
1703
1704 if (vcpu->guest_debug.enabled)
1705 kvm_guest_debug_pre(vcpu);
1706
1707 fx_save(vcpu->host_fx_image);
1708 fx_restore(vcpu->guest_fx_image);
1709
1710 save_msrs(vcpu->host_msrs, vcpu->nmsrs);
1711 load_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
1712
1713 asm (
1714 /* Store host registers */
1715 "pushf \n\t"
1716#ifdef __x86_64__
1717 "push %%rax; push %%rbx; push %%rdx;"
1718 "push %%rsi; push %%rdi; push %%rbp;"
1719 "push %%r8; push %%r9; push %%r10; push %%r11;"
1720 "push %%r12; push %%r13; push %%r14; push %%r15;"
1721 "push %%rcx \n\t"
1722 ASM_VMX_VMWRITE_RSP_RDX "\n\t"
1723#else
1724 "pusha; push %%ecx \n\t"
1725 ASM_VMX_VMWRITE_RSP_RDX "\n\t"
1726#endif
1727 /* Check if vmlaunch of vmresume is needed */
1728 "cmp $0, %1 \n\t"
1729 /* Load guest registers. Don't clobber flags. */
1730#ifdef __x86_64__
1731 "mov %c[cr2](%3), %%rax \n\t"
1732 "mov %%rax, %%cr2 \n\t"
1733 "mov %c[rax](%3), %%rax \n\t"
1734 "mov %c[rbx](%3), %%rbx \n\t"
1735 "mov %c[rdx](%3), %%rdx \n\t"
1736 "mov %c[rsi](%3), %%rsi \n\t"
1737 "mov %c[rdi](%3), %%rdi \n\t"
1738 "mov %c[rbp](%3), %%rbp \n\t"
1739 "mov %c[r8](%3), %%r8 \n\t"
1740 "mov %c[r9](%3), %%r9 \n\t"
1741 "mov %c[r10](%3), %%r10 \n\t"
1742 "mov %c[r11](%3), %%r11 \n\t"
1743 "mov %c[r12](%3), %%r12 \n\t"
1744 "mov %c[r13](%3), %%r13 \n\t"
1745 "mov %c[r14](%3), %%r14 \n\t"
1746 "mov %c[r15](%3), %%r15 \n\t"
1747 "mov %c[rcx](%3), %%rcx \n\t" /* kills %3 (rcx) */
1748#else
1749 "mov %c[cr2](%3), %%eax \n\t"
1750 "mov %%eax, %%cr2 \n\t"
1751 "mov %c[rax](%3), %%eax \n\t"
1752 "mov %c[rbx](%3), %%ebx \n\t"
1753 "mov %c[rdx](%3), %%edx \n\t"
1754 "mov %c[rsi](%3), %%esi \n\t"
1755 "mov %c[rdi](%3), %%edi \n\t"
1756 "mov %c[rbp](%3), %%ebp \n\t"
1757 "mov %c[rcx](%3), %%ecx \n\t" /* kills %3 (ecx) */
1758#endif
1759 /* Enter guest mode */
1760 "jne launched \n\t"
1761 ASM_VMX_VMLAUNCH "\n\t"
1762 "jmp kvm_vmx_return \n\t"
1763 "launched: " ASM_VMX_VMRESUME "\n\t"
1764 ".globl kvm_vmx_return \n\t"
1765 "kvm_vmx_return: "
1766 /* Save guest registers, load host registers, keep flags */
1767#ifdef __x86_64__
1768 "xchg %3, 0(%%rsp) \n\t"
1769 "mov %%rax, %c[rax](%3) \n\t"
1770 "mov %%rbx, %c[rbx](%3) \n\t"
1771 "pushq 0(%%rsp); popq %c[rcx](%3) \n\t"
1772 "mov %%rdx, %c[rdx](%3) \n\t"
1773 "mov %%rsi, %c[rsi](%3) \n\t"
1774 "mov %%rdi, %c[rdi](%3) \n\t"
1775 "mov %%rbp, %c[rbp](%3) \n\t"
1776 "mov %%r8, %c[r8](%3) \n\t"
1777 "mov %%r9, %c[r9](%3) \n\t"
1778 "mov %%r10, %c[r10](%3) \n\t"
1779 "mov %%r11, %c[r11](%3) \n\t"
1780 "mov %%r12, %c[r12](%3) \n\t"
1781 "mov %%r13, %c[r13](%3) \n\t"
1782 "mov %%r14, %c[r14](%3) \n\t"
1783 "mov %%r15, %c[r15](%3) \n\t"
1784 "mov %%cr2, %%rax \n\t"
1785 "mov %%rax, %c[cr2](%3) \n\t"
1786 "mov 0(%%rsp), %3 \n\t"
1787
1788 "pop %%rcx; pop %%r15; pop %%r14; pop %%r13; pop %%r12;"
1789 "pop %%r11; pop %%r10; pop %%r9; pop %%r8;"
1790 "pop %%rbp; pop %%rdi; pop %%rsi;"
1791 "pop %%rdx; pop %%rbx; pop %%rax \n\t"
1792#else
1793 "xchg %3, 0(%%esp) \n\t"
1794 "mov %%eax, %c[rax](%3) \n\t"
1795 "mov %%ebx, %c[rbx](%3) \n\t"
1796 "pushl 0(%%esp); popl %c[rcx](%3) \n\t"
1797 "mov %%edx, %c[rdx](%3) \n\t"
1798 "mov %%esi, %c[rsi](%3) \n\t"
1799 "mov %%edi, %c[rdi](%3) \n\t"
1800 "mov %%ebp, %c[rbp](%3) \n\t"
1801 "mov %%cr2, %%eax \n\t"
1802 "mov %%eax, %c[cr2](%3) \n\t"
1803 "mov 0(%%esp), %3 \n\t"
1804
1805 "pop %%ecx; popa \n\t"
1806#endif
1807 "setbe %0 \n\t"
1808 "popf \n\t"
1809 : "=g" (fail)
1810 : "r"(vcpu->launched), "d"((unsigned long)HOST_RSP),
1811 "c"(vcpu),
1812 [rax]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RAX])),
1813 [rbx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBX])),
1814 [rcx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RCX])),
1815 [rdx]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDX])),
1816 [rsi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RSI])),
1817 [rdi]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RDI])),
1818 [rbp]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_RBP])),
1819#ifdef __x86_64__
1820 [r8 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R8 ])),
1821 [r9 ]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R9 ])),
1822 [r10]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R10])),
1823 [r11]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R11])),
1824 [r12]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R12])),
1825 [r13]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R13])),
1826 [r14]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R14])),
1827 [r15]"i"(offsetof(struct kvm_vcpu, regs[VCPU_REGS_R15])),
1828#endif
1829 [cr2]"i"(offsetof(struct kvm_vcpu, cr2))
1830 : "cc", "memory" );
1831
1832 ++kvm_stat.exits;
1833
1834 save_msrs(vcpu->guest_msrs, NR_BAD_MSRS);
1835 load_msrs(vcpu->host_msrs, NR_BAD_MSRS);
1836
1837 fx_save(vcpu->guest_fx_image);
1838 fx_restore(vcpu->host_fx_image);
1839
1840#ifndef __x86_64__
1841 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
1842#endif
1843
1844 kvm_run->exit_type = 0;
1845 if (fail) {
1846 kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
1847 kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR);
1848 } else {
1849 if (fs_gs_ldt_reload_needed) {
1850 load_ldt(ldt_sel);
1851 load_fs(fs_sel);
1852 /*
1853 * If we have to reload gs, we must take care to
1854 * preserve our gs base.
1855 */
1856 local_irq_disable();
1857 load_gs(gs_sel);
1858#ifdef __x86_64__
1859 wrmsrl(MSR_GS_BASE, vmcs_readl(HOST_GS_BASE));
1860#endif
1861 local_irq_enable();
1862
1863 reload_tss();
1864 }
1865 vcpu->launched = 1;
1866 kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
1867 if (kvm_handle_exit(kvm_run, vcpu)) {
1868 /* Give scheduler a change to reschedule. */
1869 if (signal_pending(current)) {
1870 ++kvm_stat.signal_exits;
1871 return -EINTR;
1872 }
1873 kvm_resched(vcpu);
1874 goto again;
1875 }
1876 }
1877 return 0;
1878}
1879
1880static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
1881{
1882 vmcs_writel(GUEST_CR3, vmcs_readl(GUEST_CR3));
1883}
1884
1885static void vmx_inject_page_fault(struct kvm_vcpu *vcpu,
1886 unsigned long addr,
1887 u32 err_code)
1888{
1889 u32 vect_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
1890
1891 ++kvm_stat.pf_guest;
1892
1893 if (is_page_fault(vect_info)) {
1894 printk(KERN_DEBUG "inject_page_fault: "
1895 "double fault 0x%lx @ 0x%lx\n",
1896 addr, vmcs_readl(GUEST_RIP));
1897 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, 0);
1898 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
1899 DF_VECTOR |
1900 INTR_TYPE_EXCEPTION |
1901 INTR_INFO_DELIEVER_CODE_MASK |
1902 INTR_INFO_VALID_MASK);
1903 return;
1904 }
1905 vcpu->cr2 = addr;
1906 vmcs_write32(VM_ENTRY_EXCEPTION_ERROR_CODE, err_code);
1907 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD,
1908 PF_VECTOR |
1909 INTR_TYPE_EXCEPTION |
1910 INTR_INFO_DELIEVER_CODE_MASK |
1911 INTR_INFO_VALID_MASK);
1912
1913}
1914
1915static void vmx_free_vmcs(struct kvm_vcpu *vcpu)
1916{
1917 if (vcpu->vmcs) {
1918 on_each_cpu(__vcpu_clear, vcpu, 0, 1);
1919 free_vmcs(vcpu->vmcs);
1920 vcpu->vmcs = NULL;
1921 }
1922}
1923
1924static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
1925{
1926 vmx_free_vmcs(vcpu);
1927}
1928
1929static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
1930{
1931 struct vmcs *vmcs;
1932
1933 vmcs = alloc_vmcs();
1934 if (!vmcs)
1935 return -ENOMEM;
1936 vmcs_clear(vmcs);
1937 vcpu->vmcs = vmcs;
1938 vcpu->launched = 0;
1939 return 0;
1940}
1941
1942static struct kvm_arch_ops vmx_arch_ops = {
1943 .cpu_has_kvm_support = cpu_has_kvm_support,
1944 .disabled_by_bios = vmx_disabled_by_bios,
1945 .hardware_setup = hardware_setup,
1946 .hardware_unsetup = hardware_unsetup,
1947 .hardware_enable = hardware_enable,
1948 .hardware_disable = hardware_disable,
1949
1950 .vcpu_create = vmx_create_vcpu,
1951 .vcpu_free = vmx_free_vcpu,
1952
1953 .vcpu_load = vmx_vcpu_load,
1954 .vcpu_put = vmx_vcpu_put,
1955
1956 .set_guest_debug = set_guest_debug,
1957 .get_msr = vmx_get_msr,
1958 .set_msr = vmx_set_msr,
1959 .get_segment_base = vmx_get_segment_base,
1960 .get_segment = vmx_get_segment,
1961 .set_segment = vmx_set_segment,
1962 .is_long_mode = vmx_is_long_mode,
1963 .get_cs_db_l_bits = vmx_get_cs_db_l_bits,
1964 .set_cr0 = vmx_set_cr0,
1965 .set_cr0_no_modeswitch = vmx_set_cr0_no_modeswitch,
1966 .set_cr3 = vmx_set_cr3,
1967 .set_cr4 = vmx_set_cr4,
1968#ifdef __x86_64__
1969 .set_efer = vmx_set_efer,
1970#endif
1971 .get_idt = vmx_get_idt,
1972 .set_idt = vmx_set_idt,
1973 .get_gdt = vmx_get_gdt,
1974 .set_gdt = vmx_set_gdt,
1975 .cache_regs = vcpu_load_rsp_rip,
1976 .decache_regs = vcpu_put_rsp_rip,
1977 .get_rflags = vmx_get_rflags,
1978 .set_rflags = vmx_set_rflags,
1979
1980 .tlb_flush = vmx_flush_tlb,
1981 .inject_page_fault = vmx_inject_page_fault,
1982
1983 .inject_gp = vmx_inject_gp,
1984
1985 .run = vmx_vcpu_run,
1986 .skip_emulated_instruction = skip_emulated_instruction,
1987 .vcpu_setup = vmx_vcpu_setup,
1988};
1989
1990static int __init vmx_init(void)
1991{
1992 kvm_init_arch(&vmx_arch_ops, THIS_MODULE);
1993 return 0;
1994}
1995
1996static void __exit vmx_exit(void)
1997{
1998 kvm_exit_arch();
1999}
2000
2001module_init(vmx_init)
2002module_exit(vmx_exit)
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
new file mode 100644
index 000000000000..797278341581
--- /dev/null
+++ b/drivers/kvm/vmx.h
@@ -0,0 +1,296 @@
1#ifndef VMX_H
2#define VMX_H
3
4/*
5 * vmx.h: VMX Architecture related definitions
6 * Copyright (c) 2004, Intel Corporation.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope 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 Temple
19 * Place - Suite 330, Boston, MA 02111-1307 USA.
20 *
21 * A few random additions are:
22 * Copyright (C) 2006 Qumranet
23 * Avi Kivity <avi@qumranet.com>
24 * Yaniv Kamay <yaniv@qumranet.com>
25 *
26 */
27
28#define CPU_BASED_VIRTUAL_INTR_PENDING 0x00000004
29#define CPU_BASED_USE_TSC_OFFSETING 0x00000008
30#define CPU_BASED_HLT_EXITING 0x00000080
31#define CPU_BASED_INVDPG_EXITING 0x00000200
32#define CPU_BASED_MWAIT_EXITING 0x00000400
33#define CPU_BASED_RDPMC_EXITING 0x00000800
34#define CPU_BASED_RDTSC_EXITING 0x00001000
35#define CPU_BASED_CR8_LOAD_EXITING 0x00080000
36#define CPU_BASED_CR8_STORE_EXITING 0x00100000
37#define CPU_BASED_TPR_SHADOW 0x00200000
38#define CPU_BASED_MOV_DR_EXITING 0x00800000
39#define CPU_BASED_UNCOND_IO_EXITING 0x01000000
40#define CPU_BASED_ACTIVATE_IO_BITMAP 0x02000000
41#define CPU_BASED_MSR_BITMAPS 0x10000000
42#define CPU_BASED_MONITOR_EXITING 0x20000000
43#define CPU_BASED_PAUSE_EXITING 0x40000000
44
45#define PIN_BASED_EXT_INTR_MASK 0x1
46#define PIN_BASED_NMI_EXITING 0x8
47
48#define VM_EXIT_ACK_INTR_ON_EXIT 0x00008000
49#define VM_EXIT_HOST_ADD_SPACE_SIZE 0x00000200
50
51
52/* VMCS Encodings */
53enum vmcs_field {
54 GUEST_ES_SELECTOR = 0x00000800,
55 GUEST_CS_SELECTOR = 0x00000802,
56 GUEST_SS_SELECTOR = 0x00000804,
57 GUEST_DS_SELECTOR = 0x00000806,
58 GUEST_FS_SELECTOR = 0x00000808,
59 GUEST_GS_SELECTOR = 0x0000080a,
60 GUEST_LDTR_SELECTOR = 0x0000080c,
61 GUEST_TR_SELECTOR = 0x0000080e,
62 HOST_ES_SELECTOR = 0x00000c00,
63 HOST_CS_SELECTOR = 0x00000c02,
64 HOST_SS_SELECTOR = 0x00000c04,
65 HOST_DS_SELECTOR = 0x00000c06,
66 HOST_FS_SELECTOR = 0x00000c08,
67 HOST_GS_SELECTOR = 0x00000c0a,
68 HOST_TR_SELECTOR = 0x00000c0c,
69 IO_BITMAP_A = 0x00002000,
70 IO_BITMAP_A_HIGH = 0x00002001,
71 IO_BITMAP_B = 0x00002002,
72 IO_BITMAP_B_HIGH = 0x00002003,
73 MSR_BITMAP = 0x00002004,
74 MSR_BITMAP_HIGH = 0x00002005,
75 VM_EXIT_MSR_STORE_ADDR = 0x00002006,
76 VM_EXIT_MSR_STORE_ADDR_HIGH = 0x00002007,
77 VM_EXIT_MSR_LOAD_ADDR = 0x00002008,
78 VM_EXIT_MSR_LOAD_ADDR_HIGH = 0x00002009,
79 VM_ENTRY_MSR_LOAD_ADDR = 0x0000200a,
80 VM_ENTRY_MSR_LOAD_ADDR_HIGH = 0x0000200b,
81 TSC_OFFSET = 0x00002010,
82 TSC_OFFSET_HIGH = 0x00002011,
83 VIRTUAL_APIC_PAGE_ADDR = 0x00002012,
84 VIRTUAL_APIC_PAGE_ADDR_HIGH = 0x00002013,
85 VMCS_LINK_POINTER = 0x00002800,
86 VMCS_LINK_POINTER_HIGH = 0x00002801,
87 GUEST_IA32_DEBUGCTL = 0x00002802,
88 GUEST_IA32_DEBUGCTL_HIGH = 0x00002803,
89 PIN_BASED_VM_EXEC_CONTROL = 0x00004000,
90 CPU_BASED_VM_EXEC_CONTROL = 0x00004002,
91 EXCEPTION_BITMAP = 0x00004004,
92 PAGE_FAULT_ERROR_CODE_MASK = 0x00004006,
93 PAGE_FAULT_ERROR_CODE_MATCH = 0x00004008,
94 CR3_TARGET_COUNT = 0x0000400a,
95 VM_EXIT_CONTROLS = 0x0000400c,
96 VM_EXIT_MSR_STORE_COUNT = 0x0000400e,
97 VM_EXIT_MSR_LOAD_COUNT = 0x00004010,
98 VM_ENTRY_CONTROLS = 0x00004012,
99 VM_ENTRY_MSR_LOAD_COUNT = 0x00004014,
100 VM_ENTRY_INTR_INFO_FIELD = 0x00004016,
101 VM_ENTRY_EXCEPTION_ERROR_CODE = 0x00004018,
102 VM_ENTRY_INSTRUCTION_LEN = 0x0000401a,
103 TPR_THRESHOLD = 0x0000401c,
104 SECONDARY_VM_EXEC_CONTROL = 0x0000401e,
105 VM_INSTRUCTION_ERROR = 0x00004400,
106 VM_EXIT_REASON = 0x00004402,
107 VM_EXIT_INTR_INFO = 0x00004404,
108 VM_EXIT_INTR_ERROR_CODE = 0x00004406,
109 IDT_VECTORING_INFO_FIELD = 0x00004408,
110 IDT_VECTORING_ERROR_CODE = 0x0000440a,
111 VM_EXIT_INSTRUCTION_LEN = 0x0000440c,
112 VMX_INSTRUCTION_INFO = 0x0000440e,
113 GUEST_ES_LIMIT = 0x00004800,
114 GUEST_CS_LIMIT = 0x00004802,
115 GUEST_SS_LIMIT = 0x00004804,
116 GUEST_DS_LIMIT = 0x00004806,
117 GUEST_FS_LIMIT = 0x00004808,
118 GUEST_GS_LIMIT = 0x0000480a,
119 GUEST_LDTR_LIMIT = 0x0000480c,
120 GUEST_TR_LIMIT = 0x0000480e,
121 GUEST_GDTR_LIMIT = 0x00004810,
122 GUEST_IDTR_LIMIT = 0x00004812,
123 GUEST_ES_AR_BYTES = 0x00004814,
124 GUEST_CS_AR_BYTES = 0x00004816,
125 GUEST_SS_AR_BYTES = 0x00004818,
126 GUEST_DS_AR_BYTES = 0x0000481a,
127 GUEST_FS_AR_BYTES = 0x0000481c,
128 GUEST_GS_AR_BYTES = 0x0000481e,
129 GUEST_LDTR_AR_BYTES = 0x00004820,
130 GUEST_TR_AR_BYTES = 0x00004822,
131 GUEST_INTERRUPTIBILITY_INFO = 0x00004824,
132 GUEST_ACTIVITY_STATE = 0X00004826,
133 GUEST_SYSENTER_CS = 0x0000482A,
134 HOST_IA32_SYSENTER_CS = 0x00004c00,
135 CR0_GUEST_HOST_MASK = 0x00006000,
136 CR4_GUEST_HOST_MASK = 0x00006002,
137 CR0_READ_SHADOW = 0x00006004,
138 CR4_READ_SHADOW = 0x00006006,
139 CR3_TARGET_VALUE0 = 0x00006008,
140 CR3_TARGET_VALUE1 = 0x0000600a,
141 CR3_TARGET_VALUE2 = 0x0000600c,
142 CR3_TARGET_VALUE3 = 0x0000600e,
143 EXIT_QUALIFICATION = 0x00006400,
144 GUEST_LINEAR_ADDRESS = 0x0000640a,
145 GUEST_CR0 = 0x00006800,
146 GUEST_CR3 = 0x00006802,
147 GUEST_CR4 = 0x00006804,
148 GUEST_ES_BASE = 0x00006806,
149 GUEST_CS_BASE = 0x00006808,
150 GUEST_SS_BASE = 0x0000680a,
151 GUEST_DS_BASE = 0x0000680c,
152 GUEST_FS_BASE = 0x0000680e,
153 GUEST_GS_BASE = 0x00006810,
154 GUEST_LDTR_BASE = 0x00006812,
155 GUEST_TR_BASE = 0x00006814,
156 GUEST_GDTR_BASE = 0x00006816,
157 GUEST_IDTR_BASE = 0x00006818,
158 GUEST_DR7 = 0x0000681a,
159 GUEST_RSP = 0x0000681c,
160 GUEST_RIP = 0x0000681e,
161 GUEST_RFLAGS = 0x00006820,
162 GUEST_PENDING_DBG_EXCEPTIONS = 0x00006822,
163 GUEST_SYSENTER_ESP = 0x00006824,
164 GUEST_SYSENTER_EIP = 0x00006826,
165 HOST_CR0 = 0x00006c00,
166 HOST_CR3 = 0x00006c02,
167 HOST_CR4 = 0x00006c04,
168 HOST_FS_BASE = 0x00006c06,
169 HOST_GS_BASE = 0x00006c08,
170 HOST_TR_BASE = 0x00006c0a,
171 HOST_GDTR_BASE = 0x00006c0c,
172 HOST_IDTR_BASE = 0x00006c0e,
173 HOST_IA32_SYSENTER_ESP = 0x00006c10,
174 HOST_IA32_SYSENTER_EIP = 0x00006c12,
175 HOST_RSP = 0x00006c14,
176 HOST_RIP = 0x00006c16,
177};
178
179#define VMX_EXIT_REASONS_FAILED_VMENTRY 0x80000000
180
181#define EXIT_REASON_EXCEPTION_NMI 0
182#define EXIT_REASON_EXTERNAL_INTERRUPT 1
183
184#define EXIT_REASON_PENDING_INTERRUPT 7
185
186#define EXIT_REASON_TASK_SWITCH 9
187#define EXIT_REASON_CPUID 10
188#define EXIT_REASON_HLT 12
189#define EXIT_REASON_INVLPG 14
190#define EXIT_REASON_RDPMC 15
191#define EXIT_REASON_RDTSC 16
192#define EXIT_REASON_VMCALL 18
193#define EXIT_REASON_VMCLEAR 19
194#define EXIT_REASON_VMLAUNCH 20
195#define EXIT_REASON_VMPTRLD 21
196#define EXIT_REASON_VMPTRST 22
197#define EXIT_REASON_VMREAD 23
198#define EXIT_REASON_VMRESUME 24
199#define EXIT_REASON_VMWRITE 25
200#define EXIT_REASON_VMOFF 26
201#define EXIT_REASON_VMON 27
202#define EXIT_REASON_CR_ACCESS 28
203#define EXIT_REASON_DR_ACCESS 29
204#define EXIT_REASON_IO_INSTRUCTION 30
205#define EXIT_REASON_MSR_READ 31
206#define EXIT_REASON_MSR_WRITE 32
207#define EXIT_REASON_MWAIT_INSTRUCTION 36
208
209/*
210 * Interruption-information format
211 */
212#define INTR_INFO_VECTOR_MASK 0xff /* 7:0 */
213#define INTR_INFO_INTR_TYPE_MASK 0x700 /* 10:8 */
214#define INTR_INFO_DELIEVER_CODE_MASK 0x800 /* 11 */
215#define INTR_INFO_VALID_MASK 0x80000000 /* 31 */
216
217#define VECTORING_INFO_VECTOR_MASK INTR_INFO_VECTOR_MASK
218#define VECTORING_INFO_TYPE_MASK INTR_INFO_INTR_TYPE_MASK
219#define VECTORING_INFO_DELIEVER_CODE_MASK INTR_INFO_DELIEVER_CODE_MASK
220#define VECTORING_INFO_VALID_MASK INTR_INFO_VALID_MASK
221
222#define INTR_TYPE_EXT_INTR (0 << 8) /* external interrupt */
223#define INTR_TYPE_EXCEPTION (3 << 8) /* processor exception */
224
225/*
226 * Exit Qualifications for MOV for Control Register Access
227 */
228#define CONTROL_REG_ACCESS_NUM 0x7 /* 2:0, number of control register */
229#define CONTROL_REG_ACCESS_TYPE 0x30 /* 5:4, access type */
230#define CONTROL_REG_ACCESS_REG 0xf00 /* 10:8, general purpose register */
231#define LMSW_SOURCE_DATA_SHIFT 16
232#define LMSW_SOURCE_DATA (0xFFFF << LMSW_SOURCE_DATA_SHIFT) /* 16:31 lmsw source */
233#define REG_EAX (0 << 8)
234#define REG_ECX (1 << 8)
235#define REG_EDX (2 << 8)
236#define REG_EBX (3 << 8)
237#define REG_ESP (4 << 8)
238#define REG_EBP (5 << 8)
239#define REG_ESI (6 << 8)
240#define REG_EDI (7 << 8)
241#define REG_R8 (8 << 8)
242#define REG_R9 (9 << 8)
243#define REG_R10 (10 << 8)
244#define REG_R11 (11 << 8)
245#define REG_R12 (12 << 8)
246#define REG_R13 (13 << 8)
247#define REG_R14 (14 << 8)
248#define REG_R15 (15 << 8)
249
250/*
251 * Exit Qualifications for MOV for Debug Register Access
252 */
253#define DEBUG_REG_ACCESS_NUM 0x7 /* 2:0, number of debug register */
254#define DEBUG_REG_ACCESS_TYPE 0x10 /* 4, direction of access */
255#define TYPE_MOV_TO_DR (0 << 4)
256#define TYPE_MOV_FROM_DR (1 << 4)
257#define DEBUG_REG_ACCESS_REG 0xf00 /* 11:8, general purpose register */
258
259
260/* segment AR */
261#define SEGMENT_AR_L_MASK (1 << 13)
262
263/* entry controls */
264#define VM_ENTRY_CONTROLS_IA32E_MASK (1 << 9)
265
266#define AR_TYPE_ACCESSES_MASK 1
267#define AR_TYPE_READABLE_MASK (1 << 1)
268#define AR_TYPE_WRITEABLE_MASK (1 << 2)
269#define AR_TYPE_CODE_MASK (1 << 3)
270#define AR_TYPE_MASK 0x0f
271#define AR_TYPE_BUSY_64_TSS 11
272#define AR_TYPE_BUSY_32_TSS 11
273#define AR_TYPE_BUSY_16_TSS 3
274#define AR_TYPE_LDT 2
275
276#define AR_UNUSABLE_MASK (1 << 16)
277#define AR_S_MASK (1 << 4)
278#define AR_P_MASK (1 << 7)
279#define AR_L_MASK (1 << 13)
280#define AR_DB_MASK (1 << 14)
281#define AR_G_MASK (1 << 15)
282#define AR_DPL_SHIFT 5
283#define AR_DPL(ar) (((ar) >> AR_DPL_SHIFT) & 3)
284
285#define AR_RESERVD_MASK 0xfffe0f00
286
287#define CR4_VMXE 0x2000
288
289#define MSR_IA32_VMX_BASIC_MSR 0x480
290#define MSR_IA32_FEATURE_CONTROL 0x03a
291#define MSR_IA32_VMX_PINBASED_CTLS_MSR 0x481
292#define MSR_IA32_VMX_PROCBASED_CTLS_MSR 0x482
293#define MSR_IA32_VMX_EXIT_CTLS_MSR 0x483
294#define MSR_IA32_VMX_ENTRY_CTLS_MSR 0x484
295
296#endif
diff --git a/drivers/kvm/x86_emulate.c b/drivers/kvm/x86_emulate.c
new file mode 100644
index 000000000000..7e838bf0592d
--- /dev/null
+++ b/drivers/kvm/x86_emulate.c
@@ -0,0 +1,1409 @@
1/******************************************************************************
2 * x86_emulate.c
3 *
4 * Generic x86 (32-bit and 64-bit) instruction decoder and emulator.
5 *
6 * Copyright (c) 2005 Keir Fraser
7 *
8 * Linux coding style, mod r/m decoder, segment base fixes, real-mode
9 * privieged instructions:
10 *
11 * Copyright (C) 2006 Qumranet
12 *
13 * Avi Kivity <avi@qumranet.com>
14 * Yaniv Kamay <yaniv@qumranet.com>
15 *
16 * This work is licensed under the terms of the GNU GPL, version 2. See
17 * the COPYING file in the top-level directory.
18 *
19 * From: xen-unstable 10676:af9809f51f81a3c43f276f00c81a52ef558afda4
20 */
21
22#ifndef __KERNEL__
23#include <stdio.h>
24#include <stdint.h>
25#include <public/xen.h>
26#define DPRINTF(_f, _a ...) printf( _f , ## _a )
27#else
28#include "kvm.h"
29#define DPRINTF(x...) do {} while (0)
30#endif
31#include "x86_emulate.h"
32#include <linux/module.h>
33
34/*
35 * Opcode effective-address decode tables.
36 * Note that we only emulate instructions that have at least one memory
37 * operand (excluding implicit stack references). We assume that stack
38 * references and instruction fetches will never occur in special memory
39 * areas that require emulation. So, for example, 'mov <imm>,<reg>' need
40 * not be handled.
41 */
42
43/* Operand sizes: 8-bit operands or specified/overridden size. */
44#define ByteOp (1<<0) /* 8-bit operands. */
45/* Destination operand type. */
46#define ImplicitOps (1<<1) /* Implicit in opcode. No generic decode. */
47#define DstReg (2<<1) /* Register operand. */
48#define DstMem (3<<1) /* Memory operand. */
49#define DstMask (3<<1)
50/* Source operand type. */
51#define SrcNone (0<<3) /* No source operand. */
52#define SrcImplicit (0<<3) /* Source operand is implicit in the opcode. */
53#define SrcReg (1<<3) /* Register operand. */
54#define SrcMem (2<<3) /* Memory operand. */
55#define SrcMem16 (3<<3) /* Memory operand (16-bit). */
56#define SrcMem32 (4<<3) /* Memory operand (32-bit). */
57#define SrcImm (5<<3) /* Immediate operand. */
58#define SrcImmByte (6<<3) /* 8-bit sign-extended immediate operand. */
59#define SrcMask (7<<3)
60/* Generic ModRM decode. */
61#define ModRM (1<<6)
62/* Destination is only written; never read. */
63#define Mov (1<<7)
64
65static u8 opcode_table[256] = {
66 /* 0x00 - 0x07 */
67 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
68 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
69 0, 0, 0, 0,
70 /* 0x08 - 0x0F */
71 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
72 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
73 0, 0, 0, 0,
74 /* 0x10 - 0x17 */
75 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
76 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
77 0, 0, 0, 0,
78 /* 0x18 - 0x1F */
79 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
80 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
81 0, 0, 0, 0,
82 /* 0x20 - 0x27 */
83 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
84 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
85 0, 0, 0, 0,
86 /* 0x28 - 0x2F */
87 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
88 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
89 0, 0, 0, 0,
90 /* 0x30 - 0x37 */
91 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
92 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
93 0, 0, 0, 0,
94 /* 0x38 - 0x3F */
95 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
96 ByteOp | DstReg | SrcMem | ModRM, DstReg | SrcMem | ModRM,
97 0, 0, 0, 0,
98 /* 0x40 - 0x4F */
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
100 /* 0x50 - 0x5F */
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
102 /* 0x60 - 0x6F */
103 0, 0, 0, DstReg | SrcMem32 | ModRM | Mov /* movsxd (x86/64) */ ,
104 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
105 /* 0x70 - 0x7F */
106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107 /* 0x80 - 0x87 */
108 ByteOp | DstMem | SrcImm | ModRM, DstMem | SrcImm | ModRM,
109 ByteOp | DstMem | SrcImm | ModRM, DstMem | SrcImmByte | ModRM,
110 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
111 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM,
112 /* 0x88 - 0x8F */
113 ByteOp | DstMem | SrcReg | ModRM | Mov, DstMem | SrcReg | ModRM | Mov,
114 ByteOp | DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
115 0, 0, 0, DstMem | SrcNone | ModRM | Mov,
116 /* 0x90 - 0x9F */
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 /* 0xA0 - 0xA7 */
119 ByteOp | DstReg | SrcMem | Mov, DstReg | SrcMem | Mov,
120 ByteOp | DstMem | SrcReg | Mov, DstMem | SrcReg | Mov,
121 ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
122 ByteOp | ImplicitOps, ImplicitOps,
123 /* 0xA8 - 0xAF */
124 0, 0, ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
125 ByteOp | ImplicitOps | Mov, ImplicitOps | Mov,
126 ByteOp | ImplicitOps, ImplicitOps,
127 /* 0xB0 - 0xBF */
128 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
129 /* 0xC0 - 0xC7 */
130 ByteOp | DstMem | SrcImm | ModRM, DstMem | SrcImmByte | ModRM, 0, 0,
131 0, 0, ByteOp | DstMem | SrcImm | ModRM | Mov,
132 DstMem | SrcImm | ModRM | Mov,
133 /* 0xC8 - 0xCF */
134 0, 0, 0, 0, 0, 0, 0, 0,
135 /* 0xD0 - 0xD7 */
136 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM,
137 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM,
138 0, 0, 0, 0,
139 /* 0xD8 - 0xDF */
140 0, 0, 0, 0, 0, 0, 0, 0,
141 /* 0xE0 - 0xEF */
142 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
143 /* 0xF0 - 0xF7 */
144 0, 0, 0, 0,
145 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM,
146 /* 0xF8 - 0xFF */
147 0, 0, 0, 0,
148 0, 0, ByteOp | DstMem | SrcNone | ModRM, DstMem | SrcNone | ModRM
149};
150
151static u8 twobyte_table[256] = {
152 /* 0x00 - 0x0F */
153 0, SrcMem | ModRM | DstReg, 0, 0, 0, 0, ImplicitOps, 0,
154 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0,
155 /* 0x10 - 0x1F */
156 0, 0, 0, 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0, 0, 0, 0, 0, 0,
157 /* 0x20 - 0x2F */
158 ModRM | ImplicitOps, ModRM, ModRM | ImplicitOps, ModRM, 0, 0, 0, 0,
159 0, 0, 0, 0, 0, 0, 0, 0,
160 /* 0x30 - 0x3F */
161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
162 /* 0x40 - 0x47 */
163 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
164 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
165 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
166 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
167 /* 0x48 - 0x4F */
168 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
169 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
170 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
171 DstReg | SrcMem | ModRM | Mov, DstReg | SrcMem | ModRM | Mov,
172 /* 0x50 - 0x5F */
173 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
174 /* 0x60 - 0x6F */
175 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
176 /* 0x70 - 0x7F */
177 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
178 /* 0x80 - 0x8F */
179 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
180 /* 0x90 - 0x9F */
181 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
182 /* 0xA0 - 0xA7 */
183 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0,
184 /* 0xA8 - 0xAF */
185 0, 0, 0, DstMem | SrcReg | ModRM, 0, 0, 0, 0,
186 /* 0xB0 - 0xB7 */
187 ByteOp | DstMem | SrcReg | ModRM, DstMem | SrcReg | ModRM, 0,
188 DstMem | SrcReg | ModRM,
189 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
190 DstReg | SrcMem16 | ModRM | Mov,
191 /* 0xB8 - 0xBF */
192 0, 0, DstMem | SrcImmByte | ModRM, DstMem | SrcReg | ModRM,
193 0, 0, ByteOp | DstReg | SrcMem | ModRM | Mov,
194 DstReg | SrcMem16 | ModRM | Mov,
195 /* 0xC0 - 0xCF */
196 0, 0, 0, 0, 0, 0, 0, ImplicitOps | ModRM, 0, 0, 0, 0, 0, 0, 0, 0,
197 /* 0xD0 - 0xDF */
198 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199 /* 0xE0 - 0xEF */
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 /* 0xF0 - 0xFF */
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
203};
204
205/*
206 * Tell the emulator that of the Group 7 instructions (sgdt, lidt, etc.) we
207 * are interested only in invlpg and not in any of the rest.
208 *
209 * invlpg is a special instruction in that the data it references may not
210 * be mapped.
211 */
212void kvm_emulator_want_group7_invlpg(void)
213{
214 twobyte_table[1] &= ~SrcMem;
215}
216EXPORT_SYMBOL_GPL(kvm_emulator_want_group7_invlpg);
217
218/* Type, address-of, and value of an instruction's operand. */
219struct operand {
220 enum { OP_REG, OP_MEM, OP_IMM } type;
221 unsigned int bytes;
222 unsigned long val, orig_val, *ptr;
223};
224
225/* EFLAGS bit definitions. */
226#define EFLG_OF (1<<11)
227#define EFLG_DF (1<<10)
228#define EFLG_SF (1<<7)
229#define EFLG_ZF (1<<6)
230#define EFLG_AF (1<<4)
231#define EFLG_PF (1<<2)
232#define EFLG_CF (1<<0)
233
234/*
235 * Instruction emulation:
236 * Most instructions are emulated directly via a fragment of inline assembly
237 * code. This allows us to save/restore EFLAGS and thus very easily pick up
238 * any modified flags.
239 */
240
241#if defined(__x86_64__)
242#define _LO32 "k" /* force 32-bit operand */
243#define _STK "%%rsp" /* stack pointer */
244#elif defined(__i386__)
245#define _LO32 "" /* force 32-bit operand */
246#define _STK "%%esp" /* stack pointer */
247#endif
248
249/*
250 * These EFLAGS bits are restored from saved value during emulation, and
251 * any changes are written back to the saved value after emulation.
252 */
253#define EFLAGS_MASK (EFLG_OF|EFLG_SF|EFLG_ZF|EFLG_AF|EFLG_PF|EFLG_CF)
254
255/* Before executing instruction: restore necessary bits in EFLAGS. */
256#define _PRE_EFLAGS(_sav, _msk, _tmp) \
257 /* EFLAGS = (_sav & _msk) | (EFLAGS & ~_msk); */ \
258 "push %"_sav"; " \
259 "movl %"_msk",%"_LO32 _tmp"; " \
260 "andl %"_LO32 _tmp",("_STK"); " \
261 "pushf; " \
262 "notl %"_LO32 _tmp"; " \
263 "andl %"_LO32 _tmp",("_STK"); " \
264 "pop %"_tmp"; " \
265 "orl %"_LO32 _tmp",("_STK"); " \
266 "popf; " \
267 /* _sav &= ~msk; */ \
268 "movl %"_msk",%"_LO32 _tmp"; " \
269 "notl %"_LO32 _tmp"; " \
270 "andl %"_LO32 _tmp",%"_sav"; "
271
272/* After executing instruction: write-back necessary bits in EFLAGS. */
273#define _POST_EFLAGS(_sav, _msk, _tmp) \
274 /* _sav |= EFLAGS & _msk; */ \
275 "pushf; " \
276 "pop %"_tmp"; " \
277 "andl %"_msk",%"_LO32 _tmp"; " \
278 "orl %"_LO32 _tmp",%"_sav"; "
279
280/* Raw emulation: instruction has two explicit operands. */
281#define __emulate_2op_nobyte(_op,_src,_dst,_eflags,_wx,_wy,_lx,_ly,_qx,_qy) \
282 do { \
283 unsigned long _tmp; \
284 \
285 switch ((_dst).bytes) { \
286 case 2: \
287 __asm__ __volatile__ ( \
288 _PRE_EFLAGS("0","4","2") \
289 _op"w %"_wx"3,%1; " \
290 _POST_EFLAGS("0","4","2") \
291 : "=m" (_eflags), "=m" ((_dst).val), \
292 "=&r" (_tmp) \
293 : _wy ((_src).val), "i" (EFLAGS_MASK) ); \
294 break; \
295 case 4: \
296 __asm__ __volatile__ ( \
297 _PRE_EFLAGS("0","4","2") \
298 _op"l %"_lx"3,%1; " \
299 _POST_EFLAGS("0","4","2") \
300 : "=m" (_eflags), "=m" ((_dst).val), \
301 "=&r" (_tmp) \
302 : _ly ((_src).val), "i" (EFLAGS_MASK) ); \
303 break; \
304 case 8: \
305 __emulate_2op_8byte(_op, _src, _dst, \
306 _eflags, _qx, _qy); \
307 break; \
308 } \
309 } while (0)
310
311#define __emulate_2op(_op,_src,_dst,_eflags,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
312 do { \
313 unsigned long _tmp; \
314 switch ( (_dst).bytes ) \
315 { \
316 case 1: \
317 __asm__ __volatile__ ( \
318 _PRE_EFLAGS("0","4","2") \
319 _op"b %"_bx"3,%1; " \
320 _POST_EFLAGS("0","4","2") \
321 : "=m" (_eflags), "=m" ((_dst).val), \
322 "=&r" (_tmp) \
323 : _by ((_src).val), "i" (EFLAGS_MASK) ); \
324 break; \
325 default: \
326 __emulate_2op_nobyte(_op, _src, _dst, _eflags, \
327 _wx, _wy, _lx, _ly, _qx, _qy); \
328 break; \
329 } \
330 } while (0)
331
332/* Source operand is byte-sized and may be restricted to just %cl. */
333#define emulate_2op_SrcB(_op, _src, _dst, _eflags) \
334 __emulate_2op(_op, _src, _dst, _eflags, \
335 "b", "c", "b", "c", "b", "c", "b", "c")
336
337/* Source operand is byte, word, long or quad sized. */
338#define emulate_2op_SrcV(_op, _src, _dst, _eflags) \
339 __emulate_2op(_op, _src, _dst, _eflags, \
340 "b", "q", "w", "r", _LO32, "r", "", "r")
341
342/* Source operand is word, long or quad sized. */
343#define emulate_2op_SrcV_nobyte(_op, _src, _dst, _eflags) \
344 __emulate_2op_nobyte(_op, _src, _dst, _eflags, \
345 "w", "r", _LO32, "r", "", "r")
346
347/* Instruction has only one explicit operand (no source operand). */
348#define emulate_1op(_op, _dst, _eflags) \
349 do { \
350 unsigned long _tmp; \
351 \
352 switch ( (_dst).bytes ) \
353 { \
354 case 1: \
355 __asm__ __volatile__ ( \
356 _PRE_EFLAGS("0","3","2") \
357 _op"b %1; " \
358 _POST_EFLAGS("0","3","2") \
359 : "=m" (_eflags), "=m" ((_dst).val), \
360 "=&r" (_tmp) \
361 : "i" (EFLAGS_MASK) ); \
362 break; \
363 case 2: \
364 __asm__ __volatile__ ( \
365 _PRE_EFLAGS("0","3","2") \
366 _op"w %1; " \
367 _POST_EFLAGS("0","3","2") \
368 : "=m" (_eflags), "=m" ((_dst).val), \
369 "=&r" (_tmp) \
370 : "i" (EFLAGS_MASK) ); \
371 break; \
372 case 4: \
373 __asm__ __volatile__ ( \
374 _PRE_EFLAGS("0","3","2") \
375 _op"l %1; " \
376 _POST_EFLAGS("0","3","2") \
377 : "=m" (_eflags), "=m" ((_dst).val), \
378 "=&r" (_tmp) \
379 : "i" (EFLAGS_MASK) ); \
380 break; \
381 case 8: \
382 __emulate_1op_8byte(_op, _dst, _eflags); \
383 break; \
384 } \
385 } while (0)
386
387/* Emulate an instruction with quadword operands (x86/64 only). */
388#if defined(__x86_64__)
389#define __emulate_2op_8byte(_op, _src, _dst, _eflags, _qx, _qy) \
390 do { \
391 __asm__ __volatile__ ( \
392 _PRE_EFLAGS("0","4","2") \
393 _op"q %"_qx"3,%1; " \
394 _POST_EFLAGS("0","4","2") \
395 : "=m" (_eflags), "=m" ((_dst).val), "=&r" (_tmp) \
396 : _qy ((_src).val), "i" (EFLAGS_MASK) ); \
397 } while (0)
398
399#define __emulate_1op_8byte(_op, _dst, _eflags) \
400 do { \
401 __asm__ __volatile__ ( \
402 _PRE_EFLAGS("0","3","2") \
403 _op"q %1; " \
404 _POST_EFLAGS("0","3","2") \
405 : "=m" (_eflags), "=m" ((_dst).val), "=&r" (_tmp) \
406 : "i" (EFLAGS_MASK) ); \
407 } while (0)
408
409#elif defined(__i386__)
410#define __emulate_2op_8byte(_op, _src, _dst, _eflags, _qx, _qy)
411#define __emulate_1op_8byte(_op, _dst, _eflags)
412#endif /* __i386__ */
413
414/* Fetch next part of the instruction being emulated. */
415#define insn_fetch(_type, _size, _eip) \
416({ unsigned long _x; \
417 rc = ops->read_std((unsigned long)(_eip) + ctxt->cs_base, &_x, \
418 (_size), ctxt); \
419 if ( rc != 0 ) \
420 goto done; \
421 (_eip) += (_size); \
422 (_type)_x; \
423})
424
425/* Access/update address held in a register, based on addressing mode. */
426#define register_address(base, reg) \
427 ((base) + ((ad_bytes == sizeof(unsigned long)) ? (reg) : \
428 ((reg) & ((1UL << (ad_bytes << 3)) - 1))))
429
430#define register_address_increment(reg, inc) \
431 do { \
432 /* signed type ensures sign extension to long */ \
433 int _inc = (inc); \
434 if ( ad_bytes == sizeof(unsigned long) ) \
435 (reg) += _inc; \
436 else \
437 (reg) = ((reg) & ~((1UL << (ad_bytes << 3)) - 1)) | \
438 (((reg) + _inc) & ((1UL << (ad_bytes << 3)) - 1)); \
439 } while (0)
440
441void *decode_register(u8 modrm_reg, unsigned long *regs,
442 int highbyte_regs)
443{
444 void *p;
445
446 p = &regs[modrm_reg];
447 if (highbyte_regs && modrm_reg >= 4 && modrm_reg < 8)
448 p = (unsigned char *)&regs[modrm_reg & 3] + 1;
449 return p;
450}
451
452static int read_descriptor(struct x86_emulate_ctxt *ctxt,
453 struct x86_emulate_ops *ops,
454 void *ptr,
455 u16 *size, unsigned long *address, int op_bytes)
456{
457 int rc;
458
459 if (op_bytes == 2)
460 op_bytes = 3;
461 *address = 0;
462 rc = ops->read_std((unsigned long)ptr, (unsigned long *)size, 2, ctxt);
463 if (rc)
464 return rc;
465 rc = ops->read_std((unsigned long)ptr + 2, address, op_bytes, ctxt);
466 return rc;
467}
468
469int
470x86_emulate_memop(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
471{
472 u8 b, d, sib, twobyte = 0, rex_prefix = 0;
473 u8 modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
474 unsigned long *override_base = NULL;
475 unsigned int op_bytes, ad_bytes, lock_prefix = 0, rep_prefix = 0, i;
476 int rc = 0;
477 struct operand src, dst;
478 unsigned long cr2 = ctxt->cr2;
479 int mode = ctxt->mode;
480 unsigned long modrm_ea;
481 int use_modrm_ea, index_reg = 0, base_reg = 0, scale, rip_relative = 0;
482
483 /* Shadow copy of register state. Committed on successful emulation. */
484 unsigned long _regs[NR_VCPU_REGS];
485 unsigned long _eip = ctxt->vcpu->rip, _eflags = ctxt->eflags;
486 unsigned long modrm_val = 0;
487
488 memcpy(_regs, ctxt->vcpu->regs, sizeof _regs);
489
490 switch (mode) {
491 case X86EMUL_MODE_REAL:
492 case X86EMUL_MODE_PROT16:
493 op_bytes = ad_bytes = 2;
494 break;
495 case X86EMUL_MODE_PROT32:
496 op_bytes = ad_bytes = 4;
497 break;
498#ifdef __x86_64__
499 case X86EMUL_MODE_PROT64:
500 op_bytes = 4;
501 ad_bytes = 8;
502 break;
503#endif
504 default:
505 return -1;
506 }
507
508 /* Legacy prefixes. */
509 for (i = 0; i < 8; i++) {
510 switch (b = insn_fetch(u8, 1, _eip)) {
511 case 0x66: /* operand-size override */
512 op_bytes ^= 6; /* switch between 2/4 bytes */
513 break;
514 case 0x67: /* address-size override */
515 if (mode == X86EMUL_MODE_PROT64)
516 ad_bytes ^= 12; /* switch between 4/8 bytes */
517 else
518 ad_bytes ^= 6; /* switch between 2/4 bytes */
519 break;
520 case 0x2e: /* CS override */
521 override_base = &ctxt->cs_base;
522 break;
523 case 0x3e: /* DS override */
524 override_base = &ctxt->ds_base;
525 break;
526 case 0x26: /* ES override */
527 override_base = &ctxt->es_base;
528 break;
529 case 0x64: /* FS override */
530 override_base = &ctxt->fs_base;
531 break;
532 case 0x65: /* GS override */
533 override_base = &ctxt->gs_base;
534 break;
535 case 0x36: /* SS override */
536 override_base = &ctxt->ss_base;
537 break;
538 case 0xf0: /* LOCK */
539 lock_prefix = 1;
540 break;
541 case 0xf3: /* REP/REPE/REPZ */
542 rep_prefix = 1;
543 break;
544 case 0xf2: /* REPNE/REPNZ */
545 break;
546 default:
547 goto done_prefixes;
548 }
549 }
550
551done_prefixes:
552
553 /* REX prefix. */
554 if ((mode == X86EMUL_MODE_PROT64) && ((b & 0xf0) == 0x40)) {
555 rex_prefix = b;
556 if (b & 8)
557 op_bytes = 8; /* REX.W */
558 modrm_reg = (b & 4) << 1; /* REX.R */
559 index_reg = (b & 2) << 2; /* REX.X */
560 modrm_rm = base_reg = (b & 1) << 3; /* REG.B */
561 b = insn_fetch(u8, 1, _eip);
562 }
563
564 /* Opcode byte(s). */
565 d = opcode_table[b];
566 if (d == 0) {
567 /* Two-byte opcode? */
568 if (b == 0x0f) {
569 twobyte = 1;
570 b = insn_fetch(u8, 1, _eip);
571 d = twobyte_table[b];
572 }
573
574 /* Unrecognised? */
575 if (d == 0)
576 goto cannot_emulate;
577 }
578
579 /* ModRM and SIB bytes. */
580 if (d & ModRM) {
581 modrm = insn_fetch(u8, 1, _eip);
582 modrm_mod |= (modrm & 0xc0) >> 6;
583 modrm_reg |= (modrm & 0x38) >> 3;
584 modrm_rm |= (modrm & 0x07);
585 modrm_ea = 0;
586 use_modrm_ea = 1;
587
588 if (modrm_mod == 3) {
589 modrm_val = *(unsigned long *)
590 decode_register(modrm_rm, _regs, d & ByteOp);
591 goto modrm_done;
592 }
593
594 if (ad_bytes == 2) {
595 unsigned bx = _regs[VCPU_REGS_RBX];
596 unsigned bp = _regs[VCPU_REGS_RBP];
597 unsigned si = _regs[VCPU_REGS_RSI];
598 unsigned di = _regs[VCPU_REGS_RDI];
599
600 /* 16-bit ModR/M decode. */
601 switch (modrm_mod) {
602 case 0:
603 if (modrm_rm == 6)
604 modrm_ea += insn_fetch(u16, 2, _eip);
605 break;
606 case 1:
607 modrm_ea += insn_fetch(s8, 1, _eip);
608 break;
609 case 2:
610 modrm_ea += insn_fetch(u16, 2, _eip);
611 break;
612 }
613 switch (modrm_rm) {
614 case 0:
615 modrm_ea += bx + si;
616 break;
617 case 1:
618 modrm_ea += bx + di;
619 break;
620 case 2:
621 modrm_ea += bp + si;
622 break;
623 case 3:
624 modrm_ea += bp + di;
625 break;
626 case 4:
627 modrm_ea += si;
628 break;
629 case 5:
630 modrm_ea += di;
631 break;
632 case 6:
633 if (modrm_mod != 0)
634 modrm_ea += bp;
635 break;
636 case 7:
637 modrm_ea += bx;
638 break;
639 }
640 if (modrm_rm == 2 || modrm_rm == 3 ||
641 (modrm_rm == 6 && modrm_mod != 0))
642 if (!override_base)
643 override_base = &ctxt->ss_base;
644 modrm_ea = (u16)modrm_ea;
645 } else {
646 /* 32/64-bit ModR/M decode. */
647 switch (modrm_rm) {
648 case 4:
649 case 12:
650 sib = insn_fetch(u8, 1, _eip);
651 index_reg |= (sib >> 3) & 7;
652 base_reg |= sib & 7;
653 scale = sib >> 6;
654
655 switch (base_reg) {
656 case 5:
657 if (modrm_mod != 0)
658 modrm_ea += _regs[base_reg];
659 else
660 modrm_ea += insn_fetch(s32, 4, _eip);
661 break;
662 default:
663 modrm_ea += _regs[base_reg];
664 }
665 switch (index_reg) {
666 case 4:
667 break;
668 default:
669 modrm_ea += _regs[index_reg] << scale;
670
671 }
672 break;
673 case 5:
674 if (modrm_mod != 0)
675 modrm_ea += _regs[modrm_rm];
676 else if (mode == X86EMUL_MODE_PROT64)
677 rip_relative = 1;
678 break;
679 default:
680 modrm_ea += _regs[modrm_rm];
681 break;
682 }
683 switch (modrm_mod) {
684 case 0:
685 if (modrm_rm == 5)
686 modrm_ea += insn_fetch(s32, 4, _eip);
687 break;
688 case 1:
689 modrm_ea += insn_fetch(s8, 1, _eip);
690 break;
691 case 2:
692 modrm_ea += insn_fetch(s32, 4, _eip);
693 break;
694 }
695 }
696 if (!override_base)
697 override_base = &ctxt->ds_base;
698 if (mode == X86EMUL_MODE_PROT64 &&
699 override_base != &ctxt->fs_base &&
700 override_base != &ctxt->gs_base)
701 override_base = NULL;
702
703 if (override_base)
704 modrm_ea += *override_base;
705
706 if (rip_relative) {
707 modrm_ea += _eip;
708 switch (d & SrcMask) {
709 case SrcImmByte:
710 modrm_ea += 1;
711 break;
712 case SrcImm:
713 if (d & ByteOp)
714 modrm_ea += 1;
715 else
716 if (op_bytes == 8)
717 modrm_ea += 4;
718 else
719 modrm_ea += op_bytes;
720 }
721 }
722 if (ad_bytes != 8)
723 modrm_ea = (u32)modrm_ea;
724 cr2 = modrm_ea;
725 modrm_done:
726 ;
727 }
728
729 /* Decode and fetch the destination operand: register or memory. */
730 switch (d & DstMask) {
731 case ImplicitOps:
732 /* Special instructions do their own operand decoding. */
733 goto special_insn;
734 case DstReg:
735 dst.type = OP_REG;
736 if ((d & ByteOp)
737 && !(twobyte_table && (b == 0xb6 || b == 0xb7))) {
738 dst.ptr = decode_register(modrm_reg, _regs,
739 (rex_prefix == 0));
740 dst.val = *(u8 *) dst.ptr;
741 dst.bytes = 1;
742 } else {
743 dst.ptr = decode_register(modrm_reg, _regs, 0);
744 switch ((dst.bytes = op_bytes)) {
745 case 2:
746 dst.val = *(u16 *)dst.ptr;
747 break;
748 case 4:
749 dst.val = *(u32 *)dst.ptr;
750 break;
751 case 8:
752 dst.val = *(u64 *)dst.ptr;
753 break;
754 }
755 }
756 break;
757 case DstMem:
758 dst.type = OP_MEM;
759 dst.ptr = (unsigned long *)cr2;
760 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
761 if (!(d & Mov) && /* optimisation - avoid slow emulated read */
762 ((rc = ops->read_emulated((unsigned long)dst.ptr,
763 &dst.val, dst.bytes, ctxt)) != 0))
764 goto done;
765 break;
766 }
767 dst.orig_val = dst.val;
768
769 /*
770 * Decode and fetch the source operand: register, memory
771 * or immediate.
772 */
773 switch (d & SrcMask) {
774 case SrcNone:
775 break;
776 case SrcReg:
777 src.type = OP_REG;
778 if (d & ByteOp) {
779 src.ptr = decode_register(modrm_reg, _regs,
780 (rex_prefix == 0));
781 src.val = src.orig_val = *(u8 *) src.ptr;
782 src.bytes = 1;
783 } else {
784 src.ptr = decode_register(modrm_reg, _regs, 0);
785 switch ((src.bytes = op_bytes)) {
786 case 2:
787 src.val = src.orig_val = *(u16 *) src.ptr;
788 break;
789 case 4:
790 src.val = src.orig_val = *(u32 *) src.ptr;
791 break;
792 case 8:
793 src.val = src.orig_val = *(u64 *) src.ptr;
794 break;
795 }
796 }
797 break;
798 case SrcMem16:
799 src.bytes = 2;
800 goto srcmem_common;
801 case SrcMem32:
802 src.bytes = 4;
803 goto srcmem_common;
804 case SrcMem:
805 src.bytes = (d & ByteOp) ? 1 : op_bytes;
806 srcmem_common:
807 src.type = OP_MEM;
808 src.ptr = (unsigned long *)cr2;
809 if ((rc = ops->read_emulated((unsigned long)src.ptr,
810 &src.val, src.bytes, ctxt)) != 0)
811 goto done;
812 src.orig_val = src.val;
813 break;
814 case SrcImm:
815 src.type = OP_IMM;
816 src.ptr = (unsigned long *)_eip;
817 src.bytes = (d & ByteOp) ? 1 : op_bytes;
818 if (src.bytes == 8)
819 src.bytes = 4;
820 /* NB. Immediates are sign-extended as necessary. */
821 switch (src.bytes) {
822 case 1:
823 src.val = insn_fetch(s8, 1, _eip);
824 break;
825 case 2:
826 src.val = insn_fetch(s16, 2, _eip);
827 break;
828 case 4:
829 src.val = insn_fetch(s32, 4, _eip);
830 break;
831 }
832 break;
833 case SrcImmByte:
834 src.type = OP_IMM;
835 src.ptr = (unsigned long *)_eip;
836 src.bytes = 1;
837 src.val = insn_fetch(s8, 1, _eip);
838 break;
839 }
840
841 if (twobyte)
842 goto twobyte_insn;
843
844 switch (b) {
845 case 0x00 ... 0x05:
846 add: /* add */
847 emulate_2op_SrcV("add", src, dst, _eflags);
848 break;
849 case 0x08 ... 0x0d:
850 or: /* or */
851 emulate_2op_SrcV("or", src, dst, _eflags);
852 break;
853 case 0x10 ... 0x15:
854 adc: /* adc */
855 emulate_2op_SrcV("adc", src, dst, _eflags);
856 break;
857 case 0x18 ... 0x1d:
858 sbb: /* sbb */
859 emulate_2op_SrcV("sbb", src, dst, _eflags);
860 break;
861 case 0x20 ... 0x25:
862 and: /* and */
863 emulate_2op_SrcV("and", src, dst, _eflags);
864 break;
865 case 0x28 ... 0x2d:
866 sub: /* sub */
867 emulate_2op_SrcV("sub", src, dst, _eflags);
868 break;
869 case 0x30 ... 0x35:
870 xor: /* xor */
871 emulate_2op_SrcV("xor", src, dst, _eflags);
872 break;
873 case 0x38 ... 0x3d:
874 cmp: /* cmp */
875 emulate_2op_SrcV("cmp", src, dst, _eflags);
876 break;
877 case 0x63: /* movsxd */
878 if (mode != X86EMUL_MODE_PROT64)
879 goto cannot_emulate;
880 dst.val = (s32) src.val;
881 break;
882 case 0x80 ... 0x83: /* Grp1 */
883 switch (modrm_reg) {
884 case 0:
885 goto add;
886 case 1:
887 goto or;
888 case 2:
889 goto adc;
890 case 3:
891 goto sbb;
892 case 4:
893 goto and;
894 case 5:
895 goto sub;
896 case 6:
897 goto xor;
898 case 7:
899 goto cmp;
900 }
901 break;
902 case 0x84 ... 0x85:
903 test: /* test */
904 emulate_2op_SrcV("test", src, dst, _eflags);
905 break;
906 case 0x86 ... 0x87: /* xchg */
907 /* Write back the register source. */
908 switch (dst.bytes) {
909 case 1:
910 *(u8 *) src.ptr = (u8) dst.val;
911 break;
912 case 2:
913 *(u16 *) src.ptr = (u16) dst.val;
914 break;
915 case 4:
916 *src.ptr = (u32) dst.val;
917 break; /* 64b reg: zero-extend */
918 case 8:
919 *src.ptr = dst.val;
920 break;
921 }
922 /*
923 * Write back the memory destination with implicit LOCK
924 * prefix.
925 */
926 dst.val = src.val;
927 lock_prefix = 1;
928 break;
929 case 0xa0 ... 0xa1: /* mov */
930 dst.ptr = (unsigned long *)&_regs[VCPU_REGS_RAX];
931 dst.val = src.val;
932 _eip += ad_bytes; /* skip src displacement */
933 break;
934 case 0xa2 ... 0xa3: /* mov */
935 dst.val = (unsigned long)_regs[VCPU_REGS_RAX];
936 _eip += ad_bytes; /* skip dst displacement */
937 break;
938 case 0x88 ... 0x8b: /* mov */
939 case 0xc6 ... 0xc7: /* mov (sole member of Grp11) */
940 dst.val = src.val;
941 break;
942 case 0x8f: /* pop (sole member of Grp1a) */
943 /* 64-bit mode: POP always pops a 64-bit operand. */
944 if (mode == X86EMUL_MODE_PROT64)
945 dst.bytes = 8;
946 if ((rc = ops->read_std(register_address(ctxt->ss_base,
947 _regs[VCPU_REGS_RSP]),
948 &dst.val, dst.bytes, ctxt)) != 0)
949 goto done;
950 register_address_increment(_regs[VCPU_REGS_RSP], dst.bytes);
951 break;
952 case 0xc0 ... 0xc1:
953 grp2: /* Grp2 */
954 switch (modrm_reg) {
955 case 0: /* rol */
956 emulate_2op_SrcB("rol", src, dst, _eflags);
957 break;
958 case 1: /* ror */
959 emulate_2op_SrcB("ror", src, dst, _eflags);
960 break;
961 case 2: /* rcl */
962 emulate_2op_SrcB("rcl", src, dst, _eflags);
963 break;
964 case 3: /* rcr */
965 emulate_2op_SrcB("rcr", src, dst, _eflags);
966 break;
967 case 4: /* sal/shl */
968 case 6: /* sal/shl */
969 emulate_2op_SrcB("sal", src, dst, _eflags);
970 break;
971 case 5: /* shr */
972 emulate_2op_SrcB("shr", src, dst, _eflags);
973 break;
974 case 7: /* sar */
975 emulate_2op_SrcB("sar", src, dst, _eflags);
976 break;
977 }
978 break;
979 case 0xd0 ... 0xd1: /* Grp2 */
980 src.val = 1;
981 goto grp2;
982 case 0xd2 ... 0xd3: /* Grp2 */
983 src.val = _regs[VCPU_REGS_RCX];
984 goto grp2;
985 case 0xf6 ... 0xf7: /* Grp3 */
986 switch (modrm_reg) {
987 case 0 ... 1: /* test */
988 /*
989 * Special case in Grp3: test has an immediate
990 * source operand.
991 */
992 src.type = OP_IMM;
993 src.ptr = (unsigned long *)_eip;
994 src.bytes = (d & ByteOp) ? 1 : op_bytes;
995 if (src.bytes == 8)
996 src.bytes = 4;
997 switch (src.bytes) {
998 case 1:
999 src.val = insn_fetch(s8, 1, _eip);
1000 break;
1001 case 2:
1002 src.val = insn_fetch(s16, 2, _eip);
1003 break;
1004 case 4:
1005 src.val = insn_fetch(s32, 4, _eip);
1006 break;
1007 }
1008 goto test;
1009 case 2: /* not */
1010 dst.val = ~dst.val;
1011 break;
1012 case 3: /* neg */
1013 emulate_1op("neg", dst, _eflags);
1014 break;
1015 default:
1016 goto cannot_emulate;
1017 }
1018 break;
1019 case 0xfe ... 0xff: /* Grp4/Grp5 */
1020 switch (modrm_reg) {
1021 case 0: /* inc */
1022 emulate_1op("inc", dst, _eflags);
1023 break;
1024 case 1: /* dec */
1025 emulate_1op("dec", dst, _eflags);
1026 break;
1027 case 6: /* push */
1028 /* 64-bit mode: PUSH always pushes a 64-bit operand. */
1029 if (mode == X86EMUL_MODE_PROT64) {
1030 dst.bytes = 8;
1031 if ((rc = ops->read_std((unsigned long)dst.ptr,
1032 &dst.val, 8,
1033 ctxt)) != 0)
1034 goto done;
1035 }
1036 register_address_increment(_regs[VCPU_REGS_RSP],
1037 -dst.bytes);
1038 if ((rc = ops->write_std(
1039 register_address(ctxt->ss_base,
1040 _regs[VCPU_REGS_RSP]),
1041 dst.val, dst.bytes, ctxt)) != 0)
1042 goto done;
1043 dst.val = dst.orig_val; /* skanky: disable writeback */
1044 break;
1045 default:
1046 goto cannot_emulate;
1047 }
1048 break;
1049 }
1050
1051writeback:
1052 if ((d & Mov) || (dst.orig_val != dst.val)) {
1053 switch (dst.type) {
1054 case OP_REG:
1055 /* The 4-byte case *is* correct: in 64-bit mode we zero-extend. */
1056 switch (dst.bytes) {
1057 case 1:
1058 *(u8 *)dst.ptr = (u8)dst.val;
1059 break;
1060 case 2:
1061 *(u16 *)dst.ptr = (u16)dst.val;
1062 break;
1063 case 4:
1064 *dst.ptr = (u32)dst.val;
1065 break; /* 64b: zero-ext */
1066 case 8:
1067 *dst.ptr = dst.val;
1068 break;
1069 }
1070 break;
1071 case OP_MEM:
1072 if (lock_prefix)
1073 rc = ops->cmpxchg_emulated((unsigned long)dst.
1074 ptr, dst.orig_val,
1075 dst.val, dst.bytes,
1076 ctxt);
1077 else
1078 rc = ops->write_emulated((unsigned long)dst.ptr,
1079 dst.val, dst.bytes,
1080 ctxt);
1081 if (rc != 0)
1082 goto done;
1083 default:
1084 break;
1085 }
1086 }
1087
1088 /* Commit shadow register state. */
1089 memcpy(ctxt->vcpu->regs, _regs, sizeof _regs);
1090 ctxt->eflags = _eflags;
1091 ctxt->vcpu->rip = _eip;
1092
1093done:
1094 return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
1095
1096special_insn:
1097 if (twobyte)
1098 goto twobyte_special_insn;
1099 if (rep_prefix) {
1100 if (_regs[VCPU_REGS_RCX] == 0) {
1101 ctxt->vcpu->rip = _eip;
1102 goto done;
1103 }
1104 _regs[VCPU_REGS_RCX]--;
1105 _eip = ctxt->vcpu->rip;
1106 }
1107 switch (b) {
1108 case 0xa4 ... 0xa5: /* movs */
1109 dst.type = OP_MEM;
1110 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
1111 dst.ptr = (unsigned long *)register_address(ctxt->es_base,
1112 _regs[VCPU_REGS_RDI]);
1113 if ((rc = ops->read_emulated(register_address(
1114 override_base ? *override_base : ctxt->ds_base,
1115 _regs[VCPU_REGS_RSI]), &dst.val, dst.bytes, ctxt)) != 0)
1116 goto done;
1117 register_address_increment(_regs[VCPU_REGS_RSI],
1118 (_eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
1119 register_address_increment(_regs[VCPU_REGS_RDI],
1120 (_eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
1121 break;
1122 case 0xa6 ... 0xa7: /* cmps */
1123 DPRINTF("Urk! I don't handle CMPS.\n");
1124 goto cannot_emulate;
1125 case 0xaa ... 0xab: /* stos */
1126 dst.type = OP_MEM;
1127 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
1128 dst.ptr = (unsigned long *)cr2;
1129 dst.val = _regs[VCPU_REGS_RAX];
1130 register_address_increment(_regs[VCPU_REGS_RDI],
1131 (_eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
1132 break;
1133 case 0xac ... 0xad: /* lods */
1134 dst.type = OP_REG;
1135 dst.bytes = (d & ByteOp) ? 1 : op_bytes;
1136 dst.ptr = (unsigned long *)&_regs[VCPU_REGS_RAX];
1137 if ((rc = ops->read_emulated(cr2, &dst.val, dst.bytes, ctxt)) != 0)
1138 goto done;
1139 register_address_increment(_regs[VCPU_REGS_RSI],
1140 (_eflags & EFLG_DF) ? -dst.bytes : dst.bytes);
1141 break;
1142 case 0xae ... 0xaf: /* scas */
1143 DPRINTF("Urk! I don't handle SCAS.\n");
1144 goto cannot_emulate;
1145 }
1146 goto writeback;
1147
1148twobyte_insn:
1149 switch (b) {
1150 case 0x01: /* lgdt, lidt, lmsw */
1151 switch (modrm_reg) {
1152 u16 size;
1153 unsigned long address;
1154
1155 case 2: /* lgdt */
1156 rc = read_descriptor(ctxt, ops, src.ptr,
1157 &size, &address, op_bytes);
1158 if (rc)
1159 goto done;
1160 realmode_lgdt(ctxt->vcpu, size, address);
1161 break;
1162 case 3: /* lidt */
1163 rc = read_descriptor(ctxt, ops, src.ptr,
1164 &size, &address, op_bytes);
1165 if (rc)
1166 goto done;
1167 realmode_lidt(ctxt->vcpu, size, address);
1168 break;
1169 case 4: /* smsw */
1170 if (modrm_mod != 3)
1171 goto cannot_emulate;
1172 *(u16 *)&_regs[modrm_rm]
1173 = realmode_get_cr(ctxt->vcpu, 0);
1174 break;
1175 case 6: /* lmsw */
1176 if (modrm_mod != 3)
1177 goto cannot_emulate;
1178 realmode_lmsw(ctxt->vcpu, (u16)modrm_val, &_eflags);
1179 break;
1180 case 7: /* invlpg*/
1181 emulate_invlpg(ctxt->vcpu, cr2);
1182 break;
1183 default:
1184 goto cannot_emulate;
1185 }
1186 break;
1187 case 0x21: /* mov from dr to reg */
1188 if (modrm_mod != 3)
1189 goto cannot_emulate;
1190 rc = emulator_get_dr(ctxt, modrm_reg, &_regs[modrm_rm]);
1191 break;
1192 case 0x23: /* mov from reg to dr */
1193 if (modrm_mod != 3)
1194 goto cannot_emulate;
1195 rc = emulator_set_dr(ctxt, modrm_reg, _regs[modrm_rm]);
1196 break;
1197 case 0x40 ... 0x4f: /* cmov */
1198 dst.val = dst.orig_val = src.val;
1199 d &= ~Mov; /* default to no move */
1200 /*
1201 * First, assume we're decoding an even cmov opcode
1202 * (lsb == 0).
1203 */
1204 switch ((b & 15) >> 1) {
1205 case 0: /* cmovo */
1206 d |= (_eflags & EFLG_OF) ? Mov : 0;
1207 break;
1208 case 1: /* cmovb/cmovc/cmovnae */
1209 d |= (_eflags & EFLG_CF) ? Mov : 0;
1210 break;
1211 case 2: /* cmovz/cmove */
1212 d |= (_eflags & EFLG_ZF) ? Mov : 0;
1213 break;
1214 case 3: /* cmovbe/cmovna */
1215 d |= (_eflags & (EFLG_CF | EFLG_ZF)) ? Mov : 0;
1216 break;
1217 case 4: /* cmovs */
1218 d |= (_eflags & EFLG_SF) ? Mov : 0;
1219 break;
1220 case 5: /* cmovp/cmovpe */
1221 d |= (_eflags & EFLG_PF) ? Mov : 0;
1222 break;
1223 case 7: /* cmovle/cmovng */
1224 d |= (_eflags & EFLG_ZF) ? Mov : 0;
1225 /* fall through */
1226 case 6: /* cmovl/cmovnge */
1227 d |= (!(_eflags & EFLG_SF) !=
1228 !(_eflags & EFLG_OF)) ? Mov : 0;
1229 break;
1230 }
1231 /* Odd cmov opcodes (lsb == 1) have inverted sense. */
1232 d ^= (b & 1) ? Mov : 0;
1233 break;
1234 case 0xb0 ... 0xb1: /* cmpxchg */
1235 /*
1236 * Save real source value, then compare EAX against
1237 * destination.
1238 */
1239 src.orig_val = src.val;
1240 src.val = _regs[VCPU_REGS_RAX];
1241 emulate_2op_SrcV("cmp", src, dst, _eflags);
1242 /* Always write back. The question is: where to? */
1243 d |= Mov;
1244 if (_eflags & EFLG_ZF) {
1245 /* Success: write back to memory. */
1246 dst.val = src.orig_val;
1247 } else {
1248 /* Failure: write the value we saw to EAX. */
1249 dst.type = OP_REG;
1250 dst.ptr = (unsigned long *)&_regs[VCPU_REGS_RAX];
1251 }
1252 break;
1253 case 0xa3:
1254 bt: /* bt */
1255 src.val &= (dst.bytes << 3) - 1; /* only subword offset */
1256 emulate_2op_SrcV_nobyte("bt", src, dst, _eflags);
1257 break;
1258 case 0xb3:
1259 btr: /* btr */
1260 src.val &= (dst.bytes << 3) - 1; /* only subword offset */
1261 emulate_2op_SrcV_nobyte("btr", src, dst, _eflags);
1262 break;
1263 case 0xab:
1264 bts: /* bts */
1265 src.val &= (dst.bytes << 3) - 1; /* only subword offset */
1266 emulate_2op_SrcV_nobyte("bts", src, dst, _eflags);
1267 break;
1268 case 0xb6 ... 0xb7: /* movzx */
1269 dst.bytes = op_bytes;
1270 dst.val = (d & ByteOp) ? (u8) src.val : (u16) src.val;
1271 break;
1272 case 0xbb:
1273 btc: /* btc */
1274 src.val &= (dst.bytes << 3) - 1; /* only subword offset */
1275 emulate_2op_SrcV_nobyte("btc", src, dst, _eflags);
1276 break;
1277 case 0xba: /* Grp8 */
1278 switch (modrm_reg & 3) {
1279 case 0:
1280 goto bt;
1281 case 1:
1282 goto bts;
1283 case 2:
1284 goto btr;
1285 case 3:
1286 goto btc;
1287 }
1288 break;
1289 case 0xbe ... 0xbf: /* movsx */
1290 dst.bytes = op_bytes;
1291 dst.val = (d & ByteOp) ? (s8) src.val : (s16) src.val;
1292 break;
1293 }
1294 goto writeback;
1295
1296twobyte_special_insn:
1297 /* Disable writeback. */
1298 dst.orig_val = dst.val;
1299 switch (b) {
1300 case 0x0d: /* GrpP (prefetch) */
1301 case 0x18: /* Grp16 (prefetch/nop) */
1302 break;
1303 case 0x06:
1304 emulate_clts(ctxt->vcpu);
1305 break;
1306 case 0x20: /* mov cr, reg */
1307 if (modrm_mod != 3)
1308 goto cannot_emulate;
1309 _regs[modrm_rm] = realmode_get_cr(ctxt->vcpu, modrm_reg);
1310 break;
1311 case 0x22: /* mov reg, cr */
1312 if (modrm_mod != 3)
1313 goto cannot_emulate;
1314 realmode_set_cr(ctxt->vcpu, modrm_reg, modrm_val, &_eflags);
1315 break;
1316 case 0xc7: /* Grp9 (cmpxchg8b) */
1317#if defined(__i386__)
1318 {
1319 unsigned long old_lo, old_hi;
1320 if (((rc = ops->read_emulated(cr2 + 0, &old_lo, 4,
1321 ctxt)) != 0)
1322 || ((rc = ops->read_emulated(cr2 + 4, &old_hi, 4,
1323 ctxt)) != 0))
1324 goto done;
1325 if ((old_lo != _regs[VCPU_REGS_RAX])
1326 || (old_hi != _regs[VCPU_REGS_RDI])) {
1327 _regs[VCPU_REGS_RAX] = old_lo;
1328 _regs[VCPU_REGS_RDX] = old_hi;
1329 _eflags &= ~EFLG_ZF;
1330 } else if (ops->cmpxchg8b_emulated == NULL) {
1331 rc = X86EMUL_UNHANDLEABLE;
1332 goto done;
1333 } else {
1334 if ((rc = ops->cmpxchg8b_emulated(cr2, old_lo,
1335 old_hi,
1336 _regs[VCPU_REGS_RBX],
1337 _regs[VCPU_REGS_RCX],
1338 ctxt)) != 0)
1339 goto done;
1340 _eflags |= EFLG_ZF;
1341 }
1342 break;
1343 }
1344#elif defined(__x86_64__)
1345 {
1346 unsigned long old, new;
1347 if ((rc = ops->read_emulated(cr2, &old, 8, ctxt)) != 0)
1348 goto done;
1349 if (((u32) (old >> 0) != (u32) _regs[VCPU_REGS_RAX]) ||
1350 ((u32) (old >> 32) != (u32) _regs[VCPU_REGS_RDX])) {
1351 _regs[VCPU_REGS_RAX] = (u32) (old >> 0);
1352 _regs[VCPU_REGS_RDX] = (u32) (old >> 32);
1353 _eflags &= ~EFLG_ZF;
1354 } else {
1355 new = (_regs[VCPU_REGS_RCX] << 32) | (u32) _regs[VCPU_REGS_RBX];
1356 if ((rc = ops->cmpxchg_emulated(cr2, old,
1357 new, 8, ctxt)) != 0)
1358 goto done;
1359 _eflags |= EFLG_ZF;
1360 }
1361 break;
1362 }
1363#endif
1364 }
1365 goto writeback;
1366
1367cannot_emulate:
1368 DPRINTF("Cannot emulate %02x\n", b);
1369 return -1;
1370}
1371
1372#ifdef __XEN__
1373
1374#include <asm/mm.h>
1375#include <asm/uaccess.h>
1376
1377int
1378x86_emulate_read_std(unsigned long addr,
1379 unsigned long *val,
1380 unsigned int bytes, struct x86_emulate_ctxt *ctxt)
1381{
1382 unsigned int rc;
1383
1384 *val = 0;
1385
1386 if ((rc = copy_from_user((void *)val, (void *)addr, bytes)) != 0) {
1387 propagate_page_fault(addr + bytes - rc, 0); /* read fault */
1388 return X86EMUL_PROPAGATE_FAULT;
1389 }
1390
1391 return X86EMUL_CONTINUE;
1392}
1393
1394int
1395x86_emulate_write_std(unsigned long addr,
1396 unsigned long val,
1397 unsigned int bytes, struct x86_emulate_ctxt *ctxt)
1398{
1399 unsigned int rc;
1400
1401 if ((rc = copy_to_user((void *)addr, (void *)&val, bytes)) != 0) {
1402 propagate_page_fault(addr + bytes - rc, PGERR_write_access);
1403 return X86EMUL_PROPAGATE_FAULT;
1404 }
1405
1406 return X86EMUL_CONTINUE;
1407}
1408
1409#endif
diff --git a/drivers/kvm/x86_emulate.h b/drivers/kvm/x86_emulate.h
new file mode 100644
index 000000000000..658b58de30fc
--- /dev/null
+++ b/drivers/kvm/x86_emulate.h
@@ -0,0 +1,185 @@
1/******************************************************************************
2 * x86_emulate.h
3 *
4 * Generic x86 (32-bit and 64-bit) instruction decoder and emulator.
5 *
6 * Copyright (c) 2005 Keir Fraser
7 *
8 * From: xen-unstable 10676:af9809f51f81a3c43f276f00c81a52ef558afda4
9 */
10
11#ifndef __X86_EMULATE_H__
12#define __X86_EMULATE_H__
13
14struct x86_emulate_ctxt;
15
16/*
17 * x86_emulate_ops:
18 *
19 * These operations represent the instruction emulator's interface to memory.
20 * There are two categories of operation: those that act on ordinary memory
21 * regions (*_std), and those that act on memory regions known to require
22 * special treatment or emulation (*_emulated).
23 *
24 * The emulator assumes that an instruction accesses only one 'emulated memory'
25 * location, that this location is the given linear faulting address (cr2), and
26 * that this is one of the instruction's data operands. Instruction fetches and
27 * stack operations are assumed never to access emulated memory. The emulator
28 * automatically deduces which operand of a string-move operation is accessing
29 * emulated memory, and assumes that the other operand accesses normal memory.
30 *
31 * NOTES:
32 * 1. The emulator isn't very smart about emulated vs. standard memory.
33 * 'Emulated memory' access addresses should be checked for sanity.
34 * 'Normal memory' accesses may fault, and the caller must arrange to
35 * detect and handle reentrancy into the emulator via recursive faults.
36 * Accesses may be unaligned and may cross page boundaries.
37 * 2. If the access fails (cannot emulate, or a standard access faults) then
38 * it is up to the memop to propagate the fault to the guest VM via
39 * some out-of-band mechanism, unknown to the emulator. The memop signals
40 * failure by returning X86EMUL_PROPAGATE_FAULT to the emulator, which will
41 * then immediately bail.
42 * 3. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only
43 * cmpxchg8b_emulated need support 8-byte accesses.
44 * 4. The emulator cannot handle 64-bit mode emulation on an x86/32 system.
45 */
46/* Access completed successfully: continue emulation as normal. */
47#define X86EMUL_CONTINUE 0
48/* Access is unhandleable: bail from emulation and return error to caller. */
49#define X86EMUL_UNHANDLEABLE 1
50/* Terminate emulation but return success to the caller. */
51#define X86EMUL_PROPAGATE_FAULT 2 /* propagate a generated fault to guest */
52#define X86EMUL_RETRY_INSTR 2 /* retry the instruction for some reason */
53#define X86EMUL_CMPXCHG_FAILED 2 /* cmpxchg did not see expected value */
54struct x86_emulate_ops {
55 /*
56 * read_std: Read bytes of standard (non-emulated/special) memory.
57 * Used for instruction fetch, stack operations, and others.
58 * @addr: [IN ] Linear address from which to read.
59 * @val: [OUT] Value read from memory, zero-extended to 'u_long'.
60 * @bytes: [IN ] Number of bytes to read from memory.
61 */
62 int (*read_std)(unsigned long addr,
63 unsigned long *val,
64 unsigned int bytes, struct x86_emulate_ctxt * ctxt);
65
66 /*
67 * write_std: Write bytes of standard (non-emulated/special) memory.
68 * Used for stack operations, and others.
69 * @addr: [IN ] Linear address to which to write.
70 * @val: [IN ] Value to write to memory (low-order bytes used as
71 * required).
72 * @bytes: [IN ] Number of bytes to write to memory.
73 */
74 int (*write_std)(unsigned long addr,
75 unsigned long val,
76 unsigned int bytes, struct x86_emulate_ctxt * ctxt);
77
78 /*
79 * read_emulated: Read bytes from emulated/special memory area.
80 * @addr: [IN ] Linear address from which to read.
81 * @val: [OUT] Value read from memory, zero-extended to 'u_long'.
82 * @bytes: [IN ] Number of bytes to read from memory.
83 */
84 int (*read_emulated) (unsigned long addr,
85 unsigned long *val,
86 unsigned int bytes,
87 struct x86_emulate_ctxt * ctxt);
88
89 /*
90 * write_emulated: Read bytes from emulated/special memory area.
91 * @addr: [IN ] Linear address to which to write.
92 * @val: [IN ] Value to write to memory (low-order bytes used as
93 * required).
94 * @bytes: [IN ] Number of bytes to write to memory.
95 */
96 int (*write_emulated) (unsigned long addr,
97 unsigned long val,
98 unsigned int bytes,
99 struct x86_emulate_ctxt * ctxt);
100
101 /*
102 * cmpxchg_emulated: Emulate an atomic (LOCKed) CMPXCHG operation on an
103 * emulated/special memory area.
104 * @addr: [IN ] Linear address to access.
105 * @old: [IN ] Value expected to be current at @addr.
106 * @new: [IN ] Value to write to @addr.
107 * @bytes: [IN ] Number of bytes to access using CMPXCHG.
108 */
109 int (*cmpxchg_emulated) (unsigned long addr,
110 unsigned long old,
111 unsigned long new,
112 unsigned int bytes,
113 struct x86_emulate_ctxt * ctxt);
114
115 /*
116 * cmpxchg8b_emulated: Emulate an atomic (LOCKed) CMPXCHG8B operation on an
117 * emulated/special memory area.
118 * @addr: [IN ] Linear address to access.
119 * @old: [IN ] Value expected to be current at @addr.
120 * @new: [IN ] Value to write to @addr.
121 * NOTES:
122 * 1. This function is only ever called when emulating a real CMPXCHG8B.
123 * 2. This function is *never* called on x86/64 systems.
124 * 2. Not defining this function (i.e., specifying NULL) is equivalent
125 * to defining a function that always returns X86EMUL_UNHANDLEABLE.
126 */
127 int (*cmpxchg8b_emulated) (unsigned long addr,
128 unsigned long old_lo,
129 unsigned long old_hi,
130 unsigned long new_lo,
131 unsigned long new_hi,
132 struct x86_emulate_ctxt * ctxt);
133};
134
135struct cpu_user_regs;
136
137struct x86_emulate_ctxt {
138 /* Register state before/after emulation. */
139 struct kvm_vcpu *vcpu;
140
141 /* Linear faulting address (if emulating a page-faulting instruction). */
142 unsigned long eflags;
143 unsigned long cr2;
144
145 /* Emulated execution mode, represented by an X86EMUL_MODE value. */
146 int mode;
147
148 unsigned long cs_base;
149 unsigned long ds_base;
150 unsigned long es_base;
151 unsigned long ss_base;
152 unsigned long gs_base;
153 unsigned long fs_base;
154};
155
156/* Execution mode, passed to the emulator. */
157#define X86EMUL_MODE_REAL 0 /* Real mode. */
158#define X86EMUL_MODE_PROT16 2 /* 16-bit protected mode. */
159#define X86EMUL_MODE_PROT32 4 /* 32-bit protected mode. */
160#define X86EMUL_MODE_PROT64 8 /* 64-bit (long) mode. */
161
162/* Host execution mode. */
163#if defined(__i386__)
164#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT32
165#elif defined(__x86_64__)
166#define X86EMUL_MODE_HOST X86EMUL_MODE_PROT64
167#endif
168
169/*
170 * x86_emulate_memop: Emulate an instruction that faulted attempting to
171 * read/write a 'special' memory area.
172 * Returns -1 on failure, 0 on success.
173 */
174int x86_emulate_memop(struct x86_emulate_ctxt *ctxt,
175 struct x86_emulate_ops *ops);
176
177/*
178 * Given the 'reg' portion of a ModRM byte, and a register block, return a
179 * pointer into the block that addresses the relevant register.
180 * @highbyte_regs specifies whether to decode AH,CH,DH,BH.
181 */
182void *decode_register(u8 modrm_reg, unsigned long *regs,
183 int highbyte_regs);
184
185#endif /* __X86_EMULATE_H__ */
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 92ccee85e2a2..a9e747c39791 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -162,7 +162,6 @@ config INPUT_ADBHID
162 162
163config MAC_EMUMOUSEBTN 163config MAC_EMUMOUSEBTN
164 bool "Support for mouse button 2+3 emulation" 164 bool "Support for mouse button 2+3 emulation"
165 depends on INPUT_ADBHID
166 help 165 help
167 This provides generic support for emulating the 2nd and 3rd mouse 166 This provides generic support for emulating the 2nd and 3rd mouse
168 button with keypresses. If you say Y here, the emulation is still 167 button with keypresses. If you say Y here, the emulation is still
diff --git a/drivers/macintosh/adbhid.c b/drivers/macintosh/adbhid.c
index 5066e7a8ea9c..1c7d6f221b55 100644
--- a/drivers/macintosh/adbhid.c
+++ b/drivers/macintosh/adbhid.c
@@ -689,7 +689,6 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
689 if (!hid || !input_dev) { 689 if (!hid || !input_dev) {
690 err = -ENOMEM; 690 err = -ENOMEM;
691 goto fail; 691 goto fail;
692
693 } 692 }
694 693
695 sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id); 694 sprintf(hid->phys, "adb%d:%d.%02x/input", id, default_id, original_handler_id);
@@ -807,7 +806,9 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
807 806
808 input_dev->keycode = hid->keycode; 807 input_dev->keycode = hid->keycode;
809 808
810 input_register_device(input_dev); 809 err = input_register_device(input_dev);
810 if (err)
811 goto fail;
811 812
812 if (default_id == ADB_KEYBOARD) { 813 if (default_id == ADB_KEYBOARD) {
813 /* HACK WARNING!! This should go away as soon there is an utility 814 /* HACK WARNING!! This should go away as soon there is an utility
@@ -820,7 +821,10 @@ adbhid_input_register(int id, int default_id, int original_handler_id,
820 return 0; 821 return 0;
821 822
822 fail: input_free_device(input_dev); 823 fail: input_free_device(input_dev);
823 kfree(hid); 824 if (hid) {
825 kfree(hid->keycode);
826 kfree(hid);
827 }
824 adbhid[id] = NULL; 828 adbhid[id] = NULL;
825 return err; 829 return err;
826} 830}
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 6b129eef7987..ee6b4ca69130 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -106,6 +106,8 @@ EXPORT_SYMBOL(mac_hid_mouse_emulate_buttons);
106 106
107static int emumousebtn_input_register(void) 107static int emumousebtn_input_register(void)
108{ 108{
109 int ret;
110
109 emumousebtn = input_allocate_device(); 111 emumousebtn = input_allocate_device();
110 if (!emumousebtn) 112 if (!emumousebtn)
111 return -ENOMEM; 113 return -ENOMEM;
@@ -120,9 +122,11 @@ static int emumousebtn_input_register(void)
120 emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT); 122 emumousebtn->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_MIDDLE) | BIT(BTN_RIGHT);
121 emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y); 123 emumousebtn->relbit[0] = BIT(REL_X) | BIT(REL_Y);
122 124
123 input_register_device(emumousebtn); 125 ret = input_register_device(emumousebtn);
126 if (ret)
127 input_free_device(emumousebtn);
124 128
125 return 0; 129 return ret;
126} 130}
127 131
128int __init mac_hid_init(void) 132int __init mac_hid_init(void)
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index c92c1521546d..4540ade6b6b5 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -215,6 +215,7 @@ config DM_CRYPT
215 tristate "Crypt target support" 215 tristate "Crypt target support"
216 depends on BLK_DEV_DM && EXPERIMENTAL 216 depends on BLK_DEV_DM && EXPERIMENTAL
217 select CRYPTO 217 select CRYPTO
218 select CRYPTO_CBC
218 ---help--- 219 ---help---
219 This device-mapper target allows you to create a device that 220 This device-mapper target allows you to create a device that
220 transparently encrypts the data on it. You'll need to activate 221 transparently encrypts the data on it. You'll need to activate
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index d6f614738bbd..5432d07c074d 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -212,8 +212,8 @@ char *file_path(struct file *file, char *buf, int count)
212 if (!buf) 212 if (!buf)
213 return NULL; 213 return NULL;
214 214
215 d = file->f_dentry; 215 d = file->f_path.dentry;
216 v = file->f_vfsmnt; 216 v = file->f_path.mnt;
217 217
218 buf = d_path(d, v, buf, count); 218 buf = d_path(d, v, buf, count);
219 219
@@ -349,7 +349,7 @@ static struct page *read_page(struct file *file, unsigned long index,
349 unsigned long count) 349 unsigned long count)
350{ 350{
351 struct page *page = NULL; 351 struct page *page = NULL;
352 struct inode *inode = file->f_dentry->d_inode; 352 struct inode *inode = file->f_path.dentry->d_inode;
353 struct buffer_head *bh; 353 struct buffer_head *bh;
354 sector_t block; 354 sector_t block;
355 355
@@ -662,7 +662,7 @@ static void bitmap_file_put(struct bitmap *bitmap)
662 bitmap_file_unmap(bitmap); 662 bitmap_file_unmap(bitmap);
663 663
664 if (file) { 664 if (file) {
665 struct inode *inode = file->f_dentry->d_inode; 665 struct inode *inode = file->f_path.dentry->d_inode;
666 invalidate_inode_pages(inode->i_mapping); 666 invalidate_inode_pages(inode->i_mapping);
667 fput(file); 667 fput(file);
668 } 668 }
diff --git a/drivers/md/dm-bio-list.h b/drivers/md/dm-bio-list.h
index bbf4615f0e30..da4349649f7f 100644
--- a/drivers/md/dm-bio-list.h
+++ b/drivers/md/dm-bio-list.h
@@ -44,6 +44,20 @@ static inline void bio_list_merge(struct bio_list *bl, struct bio_list *bl2)
44 bl->tail = bl2->tail; 44 bl->tail = bl2->tail;
45} 45}
46 46
47static inline void bio_list_merge_head(struct bio_list *bl,
48 struct bio_list *bl2)
49{
50 if (!bl2->head)
51 return;
52
53 if (bl->head)
54 bl2->tail->bi_next = bl->head;
55 else
56 bl->tail = bl2->tail;
57
58 bl->head = bl2->head;
59}
60
47static inline struct bio *bio_list_pop(struct bio_list *bl) 61static inline struct bio *bio_list_pop(struct bio_list *bl)
48{ 62{
49 struct bio *bio = bl->head; 63 struct bio *bio = bl->head;
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index a1086ee8cccd..4c2471ee054a 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -220,7 +220,7 @@ static int crypt_iv_benbi_ctr(struct crypt_config *cc, struct dm_target *ti,
220 const char *opts) 220 const char *opts)
221{ 221{
222 unsigned int bs = crypto_blkcipher_blocksize(cc->tfm); 222 unsigned int bs = crypto_blkcipher_blocksize(cc->tfm);
223 int log = long_log2(bs); 223 int log = ilog2(bs);
224 224
225 /* we need to calculate how far we must shift the sector count 225 /* we need to calculate how far we must shift the sector count
226 * to get the cipher block count, we use this shift in _gen */ 226 * to get the cipher block count, we use this shift in _gen */
@@ -962,7 +962,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
962 atomic_set(&io->pending, 0); 962 atomic_set(&io->pending, 0);
963 kcryptd_queue_io(io); 963 kcryptd_queue_io(io);
964 964
965 return 0; 965 return DM_MAPIO_SUBMITTED;
966} 966}
967 967
968static int crypt_status(struct dm_target *ti, status_type_t type, 968static int crypt_status(struct dm_target *ti, status_type_t type,
diff --git a/drivers/md/dm-emc.c b/drivers/md/dm-emc.c
index 2b2d45d7baaa..265c467854da 100644
--- a/drivers/md/dm-emc.c
+++ b/drivers/md/dm-emc.c
@@ -40,7 +40,7 @@ static inline void free_bio(struct bio *bio)
40 40
41static int emc_endio(struct bio *bio, unsigned int bytes_done, int error) 41static int emc_endio(struct bio *bio, unsigned int bytes_done, int error)
42{ 42{
43 struct path *path = bio->bi_private; 43 struct dm_path *path = bio->bi_private;
44 44
45 if (bio->bi_size) 45 if (bio->bi_size)
46 return 1; 46 return 1;
@@ -61,7 +61,7 @@ static int emc_endio(struct bio *bio, unsigned int bytes_done, int error)
61 return 0; 61 return 0;
62} 62}
63 63
64static struct bio *get_failover_bio(struct path *path, unsigned data_size) 64static struct bio *get_failover_bio(struct dm_path *path, unsigned data_size)
65{ 65{
66 struct bio *bio; 66 struct bio *bio;
67 struct page *page; 67 struct page *page;
@@ -96,7 +96,7 @@ static struct bio *get_failover_bio(struct path *path, unsigned data_size)
96} 96}
97 97
98static struct request *get_failover_req(struct emc_handler *h, 98static struct request *get_failover_req(struct emc_handler *h,
99 struct bio *bio, struct path *path) 99 struct bio *bio, struct dm_path *path)
100{ 100{
101 struct request *rq; 101 struct request *rq;
102 struct block_device *bdev = bio->bi_bdev; 102 struct block_device *bdev = bio->bi_bdev;
@@ -133,7 +133,7 @@ static struct request *get_failover_req(struct emc_handler *h,
133} 133}
134 134
135static struct request *emc_trespass_get(struct emc_handler *h, 135static struct request *emc_trespass_get(struct emc_handler *h,
136 struct path *path) 136 struct dm_path *path)
137{ 137{
138 struct bio *bio; 138 struct bio *bio;
139 struct request *rq; 139 struct request *rq;
@@ -191,7 +191,7 @@ static struct request *emc_trespass_get(struct emc_handler *h,
191} 191}
192 192
193static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed, 193static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed,
194 struct path *path) 194 struct dm_path *path)
195{ 195{
196 struct request *rq; 196 struct request *rq;
197 struct request_queue *q = bdev_get_queue(path->dev->bdev); 197 struct request_queue *q = bdev_get_queue(path->dev->bdev);
diff --git a/drivers/md/dm-hw-handler.h b/drivers/md/dm-hw-handler.h
index 15f5629e231a..32eff28e4adc 100644
--- a/drivers/md/dm-hw-handler.h
+++ b/drivers/md/dm-hw-handler.h
@@ -32,7 +32,7 @@ struct hw_handler_type {
32 void (*destroy) (struct hw_handler *hwh); 32 void (*destroy) (struct hw_handler *hwh);
33 33
34 void (*pg_init) (struct hw_handler *hwh, unsigned bypassed, 34 void (*pg_init) (struct hw_handler *hwh, unsigned bypassed,
35 struct path *path); 35 struct dm_path *path);
36 unsigned (*error) (struct hw_handler *hwh, struct bio *bio); 36 unsigned (*error) (struct hw_handler *hwh, struct bio *bio);
37 int (*status) (struct hw_handler *hwh, status_type_t type, 37 int (*status) (struct hw_handler *hwh, status_type_t type,
38 char *result, unsigned int maxlen); 38 char *result, unsigned int maxlen);
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index da663d2ff552..4eb73d395213 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -92,12 +92,12 @@ void dm_io_put(unsigned int num_pages)
92 *---------------------------------------------------------------*/ 92 *---------------------------------------------------------------*/
93static inline void bio_set_region(struct bio *bio, unsigned region) 93static inline void bio_set_region(struct bio *bio, unsigned region)
94{ 94{
95 bio->bi_io_vec[bio->bi_max_vecs - 1].bv_len = region; 95 bio->bi_io_vec[bio->bi_max_vecs].bv_len = region;
96} 96}
97 97
98static inline unsigned bio_get_region(struct bio *bio) 98static inline unsigned bio_get_region(struct bio *bio)
99{ 99{
100 return bio->bi_io_vec[bio->bi_max_vecs - 1].bv_len; 100 return bio->bi_io_vec[bio->bi_max_vecs].bv_len;
101} 101}
102 102
103/*----------------------------------------------------------------- 103/*-----------------------------------------------------------------
@@ -136,6 +136,7 @@ static int endio(struct bio *bio, unsigned int done, int error)
136 zero_fill_bio(bio); 136 zero_fill_bio(bio);
137 137
138 dec_count(io, bio_get_region(bio), error); 138 dec_count(io, bio_get_region(bio), error);
139 bio->bi_max_vecs++;
139 bio_put(bio); 140 bio_put(bio);
140 141
141 return 0; 142 return 0;
@@ -250,16 +251,18 @@ static void do_region(int rw, unsigned int region, struct io_region *where,
250 251
251 while (remaining) { 252 while (remaining) {
252 /* 253 /*
253 * Allocate a suitably sized bio, we add an extra 254 * Allocate a suitably sized-bio: we add an extra
254 * bvec for bio_get/set_region(). 255 * bvec for bio_get/set_region() and decrement bi_max_vecs
256 * to hide it from bio_add_page().
255 */ 257 */
256 num_bvecs = (remaining / (PAGE_SIZE >> 9)) + 2; 258 num_bvecs = (remaining / (PAGE_SIZE >> SECTOR_SHIFT)) + 2;
257 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, _bios); 259 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, _bios);
258 bio->bi_sector = where->sector + (where->count - remaining); 260 bio->bi_sector = where->sector + (where->count - remaining);
259 bio->bi_bdev = where->bdev; 261 bio->bi_bdev = where->bdev;
260 bio->bi_end_io = endio; 262 bio->bi_end_io = endio;
261 bio->bi_private = io; 263 bio->bi_private = io;
262 bio->bi_destructor = dm_bio_destructor; 264 bio->bi_destructor = dm_bio_destructor;
265 bio->bi_max_vecs--;
263 bio_set_region(bio, region); 266 bio_set_region(bio, region);
264 267
265 /* 268 /*
@@ -302,7 +305,7 @@ static void dispatch_io(int rw, unsigned int num_regions,
302 } 305 }
303 306
304 /* 307 /*
305 * Drop the extra refence that we were holding to avoid 308 * Drop the extra reference that we were holding to avoid
306 * the io being completed too early. 309 * the io being completed too early.
307 */ 310 */
308 dec_count(io, 0, 0); 311 dec_count(io, 0, 0);
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 4510ad8f971c..cd6a184536a1 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -765,7 +765,7 @@ out:
765static int do_suspend(struct dm_ioctl *param) 765static int do_suspend(struct dm_ioctl *param)
766{ 766{
767 int r = 0; 767 int r = 0;
768 int do_lockfs = 1; 768 unsigned suspend_flags = DM_SUSPEND_LOCKFS_FLAG;
769 struct mapped_device *md; 769 struct mapped_device *md;
770 770
771 md = find_device(param); 771 md = find_device(param);
@@ -773,10 +773,12 @@ static int do_suspend(struct dm_ioctl *param)
773 return -ENXIO; 773 return -ENXIO;
774 774
775 if (param->flags & DM_SKIP_LOCKFS_FLAG) 775 if (param->flags & DM_SKIP_LOCKFS_FLAG)
776 do_lockfs = 0; 776 suspend_flags &= ~DM_SUSPEND_LOCKFS_FLAG;
777 if (param->flags & DM_NOFLUSH_FLAG)
778 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG;
777 779
778 if (!dm_suspended(md)) 780 if (!dm_suspended(md))
779 r = dm_suspend(md, do_lockfs); 781 r = dm_suspend(md, suspend_flags);
780 782
781 if (!r) 783 if (!r)
782 r = __dev_status(md, param); 784 r = __dev_status(md, param);
@@ -788,7 +790,7 @@ static int do_suspend(struct dm_ioctl *param)
788static int do_resume(struct dm_ioctl *param) 790static int do_resume(struct dm_ioctl *param)
789{ 791{
790 int r = 0; 792 int r = 0;
791 int do_lockfs = 1; 793 unsigned suspend_flags = DM_SUSPEND_LOCKFS_FLAG;
792 struct hash_cell *hc; 794 struct hash_cell *hc;
793 struct mapped_device *md; 795 struct mapped_device *md;
794 struct dm_table *new_map; 796 struct dm_table *new_map;
@@ -814,9 +816,11 @@ static int do_resume(struct dm_ioctl *param)
814 if (new_map) { 816 if (new_map) {
815 /* Suspend if it isn't already suspended */ 817 /* Suspend if it isn't already suspended */
816 if (param->flags & DM_SKIP_LOCKFS_FLAG) 818 if (param->flags & DM_SKIP_LOCKFS_FLAG)
817 do_lockfs = 0; 819 suspend_flags &= ~DM_SUSPEND_LOCKFS_FLAG;
820 if (param->flags & DM_NOFLUSH_FLAG)
821 suspend_flags |= DM_SUSPEND_NOFLUSH_FLAG;
818 if (!dm_suspended(md)) 822 if (!dm_suspended(md))
819 dm_suspend(md, do_lockfs); 823 dm_suspend(md, suspend_flags);
820 824
821 r = dm_swap_table(md, new_map); 825 r = dm_swap_table(md, new_map);
822 if (r) { 826 if (r) {
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 00234909b3db..17753d80ad22 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -77,7 +77,7 @@ static int linear_map(struct dm_target *ti, struct bio *bio,
77 bio->bi_bdev = lc->dev->bdev; 77 bio->bi_bdev = lc->dev->bdev;
78 bio->bi_sector = lc->start + (bio->bi_sector - ti->begin); 78 bio->bi_sector = lc->start + (bio->bi_sector - ti->begin);
79 79
80 return 1; 80 return DM_MAPIO_REMAPPED;
81} 81}
82 82
83static int linear_status(struct dm_target *ti, status_type_t type, 83static int linear_status(struct dm_target *ti, status_type_t type,
@@ -108,7 +108,7 @@ static int linear_ioctl(struct dm_target *ti, struct inode *inode,
108 struct dentry fake_dentry = {}; 108 struct dentry fake_dentry = {};
109 109
110 fake_file.f_mode = lc->dev->mode; 110 fake_file.f_mode = lc->dev->mode;
111 fake_file.f_dentry = &fake_dentry; 111 fake_file.f_path.dentry = &fake_dentry;
112 fake_dentry.d_inode = bdev->bd_inode; 112 fake_dentry.d_inode = bdev->bd_inode;
113 113
114 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg); 114 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 64b764bd02cc..6a9261351848 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -466,6 +466,7 @@ static int disk_resume(struct dirty_log *log)
466 /* copy clean across to sync */ 466 /* copy clean across to sync */
467 memcpy(lc->sync_bits, lc->clean_bits, size); 467 memcpy(lc->sync_bits, lc->clean_bits, size);
468 lc->sync_count = count_bits32(lc->clean_bits, lc->bitset_uint32_count); 468 lc->sync_count = count_bits32(lc->clean_bits, lc->bitset_uint32_count);
469 lc->sync_search = 0;
469 470
470 /* set the correct number of regions in the header */ 471 /* set the correct number of regions in the header */
471 lc->header.nr_regions = lc->region_count; 472 lc->header.nr_regions = lc->region_count;
@@ -480,6 +481,13 @@ static uint32_t core_get_region_size(struct dirty_log *log)
480 return lc->region_size; 481 return lc->region_size;
481} 482}
482 483
484static int core_resume(struct dirty_log *log)
485{
486 struct log_c *lc = (struct log_c *) log->context;
487 lc->sync_search = 0;
488 return 0;
489}
490
483static int core_is_clean(struct dirty_log *log, region_t region) 491static int core_is_clean(struct dirty_log *log, region_t region)
484{ 492{
485 struct log_c *lc = (struct log_c *) log->context; 493 struct log_c *lc = (struct log_c *) log->context;
@@ -549,16 +557,19 @@ static int core_get_resync_work(struct dirty_log *log, region_t *region)
549 return 1; 557 return 1;
550} 558}
551 559
552static void core_complete_resync_work(struct dirty_log *log, region_t region, 560static void core_set_region_sync(struct dirty_log *log, region_t region,
553 int success) 561 int in_sync)
554{ 562{
555 struct log_c *lc = (struct log_c *) log->context; 563 struct log_c *lc = (struct log_c *) log->context;
556 564
557 log_clear_bit(lc, lc->recovering_bits, region); 565 log_clear_bit(lc, lc->recovering_bits, region);
558 if (success) { 566 if (in_sync) {
559 log_set_bit(lc, lc->sync_bits, region); 567 log_set_bit(lc, lc->sync_bits, region);
560 lc->sync_count++; 568 lc->sync_count++;
561 } 569 } else if (log_test_bit(lc->sync_bits, region)) {
570 lc->sync_count--;
571 log_clear_bit(lc, lc->sync_bits, region);
572 }
562} 573}
563 574
564static region_t core_get_sync_count(struct dirty_log *log) 575static region_t core_get_sync_count(struct dirty_log *log)
@@ -618,6 +629,7 @@ static struct dirty_log_type _core_type = {
618 .module = THIS_MODULE, 629 .module = THIS_MODULE,
619 .ctr = core_ctr, 630 .ctr = core_ctr,
620 .dtr = core_dtr, 631 .dtr = core_dtr,
632 .resume = core_resume,
621 .get_region_size = core_get_region_size, 633 .get_region_size = core_get_region_size,
622 .is_clean = core_is_clean, 634 .is_clean = core_is_clean,
623 .in_sync = core_in_sync, 635 .in_sync = core_in_sync,
@@ -625,7 +637,7 @@ static struct dirty_log_type _core_type = {
625 .mark_region = core_mark_region, 637 .mark_region = core_mark_region,
626 .clear_region = core_clear_region, 638 .clear_region = core_clear_region,
627 .get_resync_work = core_get_resync_work, 639 .get_resync_work = core_get_resync_work,
628 .complete_resync_work = core_complete_resync_work, 640 .set_region_sync = core_set_region_sync,
629 .get_sync_count = core_get_sync_count, 641 .get_sync_count = core_get_sync_count,
630 .status = core_status, 642 .status = core_status,
631}; 643};
@@ -644,7 +656,7 @@ static struct dirty_log_type _disk_type = {
644 .mark_region = core_mark_region, 656 .mark_region = core_mark_region,
645 .clear_region = core_clear_region, 657 .clear_region = core_clear_region,
646 .get_resync_work = core_get_resync_work, 658 .get_resync_work = core_get_resync_work,
647 .complete_resync_work = core_complete_resync_work, 659 .set_region_sync = core_set_region_sync,
648 .get_sync_count = core_get_sync_count, 660 .get_sync_count = core_get_sync_count,
649 .status = disk_status, 661 .status = disk_status,
650}; 662};
diff --git a/drivers/md/dm-log.h b/drivers/md/dm-log.h
index 5ae5309ebf28..86a301c8daf1 100644
--- a/drivers/md/dm-log.h
+++ b/drivers/md/dm-log.h
@@ -90,12 +90,12 @@ struct dirty_log_type {
90 int (*get_resync_work)(struct dirty_log *log, region_t *region); 90 int (*get_resync_work)(struct dirty_log *log, region_t *region);
91 91
92 /* 92 /*
93 * This notifies the log that the resync of an area has 93 * This notifies the log that the resync status of a region
94 * been completed. The log should then mark this region 94 * has changed. It also clears the region from the recovering
95 * as CLEAN. 95 * list (if present).
96 */ 96 */
97 void (*complete_resync_work)(struct dirty_log *log, 97 void (*set_region_sync)(struct dirty_log *log,
98 region_t region, int success); 98 region_t region, int in_sync);
99 99
100 /* 100 /*
101 * Returns the number of regions that are in sync. 101 * Returns the number of regions that are in sync.
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index cf8bf052138e..3aa013506967 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -31,7 +31,7 @@ struct pgpath {
31 struct priority_group *pg; /* Owning PG */ 31 struct priority_group *pg; /* Owning PG */
32 unsigned fail_count; /* Cumulative failure count */ 32 unsigned fail_count; /* Cumulative failure count */
33 33
34 struct path path; 34 struct dm_path path;
35}; 35};
36 36
37#define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path) 37#define path_to_pgpath(__pgp) container_of((__pgp), struct pgpath, path)
@@ -229,7 +229,7 @@ static void __switch_pg(struct multipath *m, struct pgpath *pgpath)
229 229
230static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg) 230static int __choose_path_in_pg(struct multipath *m, struct priority_group *pg)
231{ 231{
232 struct path *path; 232 struct dm_path *path;
233 233
234 path = pg->ps.type->select_path(&pg->ps, &m->repeat_count); 234 path = pg->ps.type->select_path(&pg->ps, &m->repeat_count);
235 if (!path) 235 if (!path)
@@ -282,10 +282,27 @@ failed:
282 m->current_pg = NULL; 282 m->current_pg = NULL;
283} 283}
284 284
285/*
286 * Check whether bios must be queued in the device-mapper core rather
287 * than here in the target.
288 *
289 * m->lock must be held on entry.
290 *
291 * If m->queue_if_no_path and m->saved_queue_if_no_path hold the
292 * same value then we are not between multipath_presuspend()
293 * and multipath_resume() calls and we have no need to check
294 * for the DMF_NOFLUSH_SUSPENDING flag.
295 */
296static int __must_push_back(struct multipath *m)
297{
298 return (m->queue_if_no_path != m->saved_queue_if_no_path &&
299 dm_noflush_suspending(m->ti));
300}
301
285static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio, 302static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
286 unsigned was_queued) 303 unsigned was_queued)
287{ 304{
288 int r = 1; 305 int r = DM_MAPIO_REMAPPED;
289 unsigned long flags; 306 unsigned long flags;
290 struct pgpath *pgpath; 307 struct pgpath *pgpath;
291 308
@@ -310,11 +327,13 @@ static int map_io(struct multipath *m, struct bio *bio, struct mpath_io *mpio,
310 !m->queue_io) 327 !m->queue_io)
311 queue_work(kmultipathd, &m->process_queued_ios); 328 queue_work(kmultipathd, &m->process_queued_ios);
312 pgpath = NULL; 329 pgpath = NULL;
313 r = 0; 330 r = DM_MAPIO_SUBMITTED;
314 } else if (!pgpath) 331 } else if (pgpath)
315 r = -EIO; /* Failed */
316 else
317 bio->bi_bdev = pgpath->path.dev->bdev; 332 bio->bi_bdev = pgpath->path.dev->bdev;
333 else if (__must_push_back(m))
334 r = DM_MAPIO_REQUEUE;
335 else
336 r = -EIO; /* Failed */
318 337
319 mpio->pgpath = pgpath; 338 mpio->pgpath = pgpath;
320 339
@@ -372,8 +391,10 @@ static void dispatch_queued_ios(struct multipath *m)
372 r = map_io(m, bio, mpio, 1); 391 r = map_io(m, bio, mpio, 1);
373 if (r < 0) 392 if (r < 0)
374 bio_endio(bio, bio->bi_size, r); 393 bio_endio(bio, bio->bi_size, r);
375 else if (r == 1) 394 else if (r == DM_MAPIO_REMAPPED)
376 generic_make_request(bio); 395 generic_make_request(bio);
396 else if (r == DM_MAPIO_REQUEUE)
397 bio_endio(bio, bio->bi_size, -EIO);
377 398
378 bio = next; 399 bio = next;
379 } 400 }
@@ -783,7 +804,7 @@ static int multipath_map(struct dm_target *ti, struct bio *bio,
783 map_context->ptr = mpio; 804 map_context->ptr = mpio;
784 bio->bi_rw |= (1 << BIO_RW_FAILFAST); 805 bio->bi_rw |= (1 << BIO_RW_FAILFAST);
785 r = map_io(m, bio, mpio, 0); 806 r = map_io(m, bio, mpio, 0);
786 if (r < 0) 807 if (r < 0 || r == DM_MAPIO_REQUEUE)
787 mempool_free(mpio, m->mpio_pool); 808 mempool_free(mpio, m->mpio_pool);
788 809
789 return r; 810 return r;
@@ -957,7 +978,7 @@ static int bypass_pg_num(struct multipath *m, const char *pgstr, int bypassed)
957/* 978/*
958 * pg_init must call this when it has completed its initialisation 979 * pg_init must call this when it has completed its initialisation
959 */ 980 */
960void dm_pg_init_complete(struct path *path, unsigned err_flags) 981void dm_pg_init_complete(struct dm_path *path, unsigned err_flags)
961{ 982{
962 struct pgpath *pgpath = path_to_pgpath(path); 983 struct pgpath *pgpath = path_to_pgpath(path);
963 struct priority_group *pg = pgpath->pg; 984 struct priority_group *pg = pgpath->pg;
@@ -1007,7 +1028,10 @@ static int do_end_io(struct multipath *m, struct bio *bio,
1007 1028
1008 spin_lock_irqsave(&m->lock, flags); 1029 spin_lock_irqsave(&m->lock, flags);
1009 if (!m->nr_valid_paths) { 1030 if (!m->nr_valid_paths) {
1010 if (!m->queue_if_no_path) { 1031 if (__must_push_back(m)) {
1032 spin_unlock_irqrestore(&m->lock, flags);
1033 return DM_ENDIO_REQUEUE;
1034 } else if (!m->queue_if_no_path) {
1011 spin_unlock_irqrestore(&m->lock, flags); 1035 spin_unlock_irqrestore(&m->lock, flags);
1012 return -EIO; 1036 return -EIO;
1013 } else { 1037 } else {
@@ -1042,7 +1066,7 @@ static int do_end_io(struct multipath *m, struct bio *bio,
1042 queue_work(kmultipathd, &m->process_queued_ios); 1066 queue_work(kmultipathd, &m->process_queued_ios);
1043 spin_unlock_irqrestore(&m->lock, flags); 1067 spin_unlock_irqrestore(&m->lock, flags);
1044 1068
1045 return 1; /* io not complete */ 1069 return DM_ENDIO_INCOMPLETE; /* io not complete */
1046} 1070}
1047 1071
1048static int multipath_end_io(struct dm_target *ti, struct bio *bio, 1072static int multipath_end_io(struct dm_target *ti, struct bio *bio,
@@ -1060,7 +1084,7 @@ static int multipath_end_io(struct dm_target *ti, struct bio *bio,
1060 if (ps->type->end_io) 1084 if (ps->type->end_io)
1061 ps->type->end_io(ps, &pgpath->path); 1085 ps->type->end_io(ps, &pgpath->path);
1062 } 1086 }
1063 if (r <= 0) 1087 if (r != DM_ENDIO_INCOMPLETE)
1064 mempool_free(mpio, m->mpio_pool); 1088 mempool_free(mpio, m->mpio_pool);
1065 1089
1066 return r; 1090 return r;
@@ -1272,7 +1296,7 @@ static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
1272 struct dentry fake_dentry = {}; 1296 struct dentry fake_dentry = {};
1273 int r = 0; 1297 int r = 0;
1274 1298
1275 fake_file.f_dentry = &fake_dentry; 1299 fake_file.f_path.dentry = &fake_dentry;
1276 1300
1277 spin_lock_irqsave(&m->lock, flags); 1301 spin_lock_irqsave(&m->lock, flags);
1278 1302
diff --git a/drivers/md/dm-mpath.h b/drivers/md/dm-mpath.h
index 8a4bf2b6d52e..b9cdcbb3ed59 100644
--- a/drivers/md/dm-mpath.h
+++ b/drivers/md/dm-mpath.h
@@ -11,7 +11,7 @@
11 11
12struct dm_dev; 12struct dm_dev;
13 13
14struct path { 14struct dm_path {
15 struct dm_dev *dev; /* Read-only */ 15 struct dm_dev *dev; /* Read-only */
16 unsigned is_active; /* Read-only */ 16 unsigned is_active; /* Read-only */
17 17
@@ -20,6 +20,6 @@ struct path {
20}; 20};
21 21
22/* Callback for hwh_pg_init_fn to use when complete */ 22/* Callback for hwh_pg_init_fn to use when complete */
23void dm_pg_init_complete(struct path *path, unsigned err_flags); 23void dm_pg_init_complete(struct dm_path *path, unsigned err_flags);
24 24
25#endif 25#endif
diff --git a/drivers/md/dm-path-selector.h b/drivers/md/dm-path-selector.h
index 732d06a84f85..27357b85d73d 100644
--- a/drivers/md/dm-path-selector.h
+++ b/drivers/md/dm-path-selector.h
@@ -44,7 +44,7 @@ struct path_selector_type {
44 * Add an opaque path object, along with some selector specific 44 * Add an opaque path object, along with some selector specific
45 * path args (eg, path priority). 45 * path args (eg, path priority).
46 */ 46 */
47 int (*add_path) (struct path_selector *ps, struct path *path, 47 int (*add_path) (struct path_selector *ps, struct dm_path *path,
48 int argc, char **argv, char **error); 48 int argc, char **argv, char **error);
49 49
50 /* 50 /*
@@ -55,27 +55,27 @@ struct path_selector_type {
55 * calling the function again. 0 means don't call it again unless 55 * calling the function again. 0 means don't call it again unless
56 * the path fails. 56 * the path fails.
57 */ 57 */
58 struct path *(*select_path) (struct path_selector *ps, 58 struct dm_path *(*select_path) (struct path_selector *ps,
59 unsigned *repeat_count); 59 unsigned *repeat_count);
60 60
61 /* 61 /*
62 * Notify the selector that a path has failed. 62 * Notify the selector that a path has failed.
63 */ 63 */
64 void (*fail_path) (struct path_selector *ps, struct path *p); 64 void (*fail_path) (struct path_selector *ps, struct dm_path *p);
65 65
66 /* 66 /*
67 * Ask selector to reinstate a path. 67 * Ask selector to reinstate a path.
68 */ 68 */
69 int (*reinstate_path) (struct path_selector *ps, struct path *p); 69 int (*reinstate_path) (struct path_selector *ps, struct dm_path *p);
70 70
71 /* 71 /*
72 * Table content based on parameters added in ps_add_path_fn 72 * Table content based on parameters added in ps_add_path_fn
73 * or path selector status 73 * or path selector status
74 */ 74 */
75 int (*status) (struct path_selector *ps, struct path *path, 75 int (*status) (struct path_selector *ps, struct dm_path *path,
76 status_type_t type, char *result, unsigned int maxlen); 76 status_type_t type, char *result, unsigned int maxlen);
77 77
78 int (*end_io) (struct path_selector *ps, struct path *path); 78 int (*end_io) (struct path_selector *ps, struct dm_path *path);
79}; 79};
80 80
81/* Register a path selector */ 81/* Register a path selector */
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index fc8cbb168e3e..23a642619bed 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -344,6 +344,17 @@ static void dispatch_bios(struct mirror_set *ms, struct bio_list *bio_list)
344 } 344 }
345} 345}
346 346
347static void complete_resync_work(struct region *reg, int success)
348{
349 struct region_hash *rh = reg->rh;
350
351 rh->log->type->set_region_sync(rh->log, reg->key, success);
352 dispatch_bios(rh->ms, &reg->delayed_bios);
353 if (atomic_dec_and_test(&rh->recovery_in_flight))
354 wake_up_all(&_kmirrord_recovery_stopped);
355 up(&rh->recovery_count);
356}
357
347static void rh_update_states(struct region_hash *rh) 358static void rh_update_states(struct region_hash *rh)
348{ 359{
349 struct region *reg, *next; 360 struct region *reg, *next;
@@ -383,11 +394,7 @@ static void rh_update_states(struct region_hash *rh)
383 */ 394 */
384 list_for_each_entry_safe (reg, next, &recovered, list) { 395 list_for_each_entry_safe (reg, next, &recovered, list) {
385 rh->log->type->clear_region(rh->log, reg->key); 396 rh->log->type->clear_region(rh->log, reg->key);
386 rh->log->type->complete_resync_work(rh->log, reg->key, 1); 397 complete_resync_work(reg, 1);
387 dispatch_bios(rh->ms, &reg->delayed_bios);
388 if (atomic_dec_and_test(&rh->recovery_in_flight))
389 wake_up_all(&_kmirrord_recovery_stopped);
390 up(&rh->recovery_count);
391 mempool_free(reg, rh->region_pool); 398 mempool_free(reg, rh->region_pool);
392 } 399 }
393 400
@@ -1137,7 +1144,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
1137 1144
1138 if (rw == WRITE) { 1145 if (rw == WRITE) {
1139 queue_bio(ms, bio, rw); 1146 queue_bio(ms, bio, rw);
1140 return 0; 1147 return DM_MAPIO_SUBMITTED;
1141 } 1148 }
1142 1149
1143 r = ms->rh.log->type->in_sync(ms->rh.log, 1150 r = ms->rh.log->type->in_sync(ms->rh.log,
@@ -1146,7 +1153,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
1146 return r; 1153 return r;
1147 1154
1148 if (r == -EWOULDBLOCK) /* FIXME: ugly */ 1155 if (r == -EWOULDBLOCK) /* FIXME: ugly */
1149 r = 0; 1156 r = DM_MAPIO_SUBMITTED;
1150 1157
1151 /* 1158 /*
1152 * We don't want to fast track a recovery just for a read 1159 * We don't want to fast track a recovery just for a read
@@ -1159,7 +1166,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
1159 if (!r) { 1166 if (!r) {
1160 /* Pass this io over to the daemon */ 1167 /* Pass this io over to the daemon */
1161 queue_bio(ms, bio, rw); 1168 queue_bio(ms, bio, rw);
1162 return 0; 1169 return DM_MAPIO_SUBMITTED;
1163 } 1170 }
1164 1171
1165 m = choose_mirror(ms, bio->bi_sector); 1172 m = choose_mirror(ms, bio->bi_sector);
@@ -1167,7 +1174,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
1167 return -EIO; 1174 return -EIO;
1168 1175
1169 map_bio(ms, m, bio); 1176 map_bio(ms, m, bio);
1170 return 1; 1177 return DM_MAPIO_REMAPPED;
1171} 1178}
1172 1179
1173static int mirror_end_io(struct dm_target *ti, struct bio *bio, 1180static int mirror_end_io(struct dm_target *ti, struct bio *bio,
diff --git a/drivers/md/dm-round-robin.c b/drivers/md/dm-round-robin.c
index 6f9fcd4db9b5..a348a97b65af 100644
--- a/drivers/md/dm-round-robin.c
+++ b/drivers/md/dm-round-robin.c
@@ -21,7 +21,7 @@
21 *---------------------------------------------------------------*/ 21 *---------------------------------------------------------------*/
22struct path_info { 22struct path_info {
23 struct list_head list; 23 struct list_head list;
24 struct path *path; 24 struct dm_path *path;
25 unsigned repeat_count; 25 unsigned repeat_count;
26}; 26};
27 27
@@ -80,7 +80,7 @@ static void rr_destroy(struct path_selector *ps)
80 ps->context = NULL; 80 ps->context = NULL;
81} 81}
82 82
83static int rr_status(struct path_selector *ps, struct path *path, 83static int rr_status(struct path_selector *ps, struct dm_path *path,
84 status_type_t type, char *result, unsigned int maxlen) 84 status_type_t type, char *result, unsigned int maxlen)
85{ 85{
86 struct path_info *pi; 86 struct path_info *pi;
@@ -106,7 +106,7 @@ static int rr_status(struct path_selector *ps, struct path *path,
106 * Called during initialisation to register each path with an 106 * Called during initialisation to register each path with an
107 * optional repeat_count. 107 * optional repeat_count.
108 */ 108 */
109static int rr_add_path(struct path_selector *ps, struct path *path, 109static int rr_add_path(struct path_selector *ps, struct dm_path *path,
110 int argc, char **argv, char **error) 110 int argc, char **argv, char **error)
111{ 111{
112 struct selector *s = (struct selector *) ps->context; 112 struct selector *s = (struct selector *) ps->context;
@@ -141,7 +141,7 @@ static int rr_add_path(struct path_selector *ps, struct path *path,
141 return 0; 141 return 0;
142} 142}
143 143
144static void rr_fail_path(struct path_selector *ps, struct path *p) 144static void rr_fail_path(struct path_selector *ps, struct dm_path *p)
145{ 145{
146 struct selector *s = (struct selector *) ps->context; 146 struct selector *s = (struct selector *) ps->context;
147 struct path_info *pi = p->pscontext; 147 struct path_info *pi = p->pscontext;
@@ -149,7 +149,7 @@ static void rr_fail_path(struct path_selector *ps, struct path *p)
149 list_move(&pi->list, &s->invalid_paths); 149 list_move(&pi->list, &s->invalid_paths);
150} 150}
151 151
152static int rr_reinstate_path(struct path_selector *ps, struct path *p) 152static int rr_reinstate_path(struct path_selector *ps, struct dm_path *p)
153{ 153{
154 struct selector *s = (struct selector *) ps->context; 154 struct selector *s = (struct selector *) ps->context;
155 struct path_info *pi = p->pscontext; 155 struct path_info *pi = p->pscontext;
@@ -159,7 +159,7 @@ static int rr_reinstate_path(struct path_selector *ps, struct path *p)
159 return 0; 159 return 0;
160} 160}
161 161
162static struct path *rr_select_path(struct path_selector *ps, 162static struct dm_path *rr_select_path(struct path_selector *ps,
163 unsigned *repeat_count) 163 unsigned *repeat_count)
164{ 164{
165 struct selector *s = (struct selector *) ps->context; 165 struct selector *s = (struct selector *) ps->context;
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index b0ce2ce82278..0821a2b68a73 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -39,7 +39,7 @@
39 */ 39 */
40#define SNAPSHOT_PAGES 256 40#define SNAPSHOT_PAGES 256
41 41
42struct workqueue_struct *ksnapd; 42static struct workqueue_struct *ksnapd;
43static void flush_queued_bios(struct work_struct *work); 43static void flush_queued_bios(struct work_struct *work);
44 44
45struct pending_exception { 45struct pending_exception {
@@ -564,6 +564,17 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
564 return r; 564 return r;
565} 565}
566 566
567static void __free_exceptions(struct dm_snapshot *s)
568{
569 kcopyd_client_destroy(s->kcopyd_client);
570 s->kcopyd_client = NULL;
571
572 exit_exception_table(&s->pending, pending_cache);
573 exit_exception_table(&s->complete, exception_cache);
574
575 s->store.destroy(&s->store);
576}
577
567static void snapshot_dtr(struct dm_target *ti) 578static void snapshot_dtr(struct dm_target *ti)
568{ 579{
569 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 580 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
@@ -574,13 +585,7 @@ static void snapshot_dtr(struct dm_target *ti)
574 /* After this returns there can be no new kcopyd jobs. */ 585 /* After this returns there can be no new kcopyd jobs. */
575 unregister_snapshot(s); 586 unregister_snapshot(s);
576 587
577 kcopyd_client_destroy(s->kcopyd_client); 588 __free_exceptions(s);
578
579 exit_exception_table(&s->pending, pending_cache);
580 exit_exception_table(&s->complete, exception_cache);
581
582 /* Deallocate memory used */
583 s->store.destroy(&s->store);
584 589
585 dm_put_device(ti, s->origin); 590 dm_put_device(ti, s->origin);
586 dm_put_device(ti, s->cow); 591 dm_put_device(ti, s->cow);
@@ -868,7 +873,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
868{ 873{
869 struct exception *e; 874 struct exception *e;
870 struct dm_snapshot *s = (struct dm_snapshot *) ti->private; 875 struct dm_snapshot *s = (struct dm_snapshot *) ti->private;
871 int r = 1; 876 int r = DM_MAPIO_REMAPPED;
872 chunk_t chunk; 877 chunk_t chunk;
873 struct pending_exception *pe = NULL; 878 struct pending_exception *pe = NULL;
874 879
@@ -914,7 +919,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
914 remap_exception(s, &pe->e, bio); 919 remap_exception(s, &pe->e, bio);
915 bio_list_add(&pe->snapshot_bios, bio); 920 bio_list_add(&pe->snapshot_bios, bio);
916 921
917 r = 0; 922 r = DM_MAPIO_SUBMITTED;
918 923
919 if (!pe->started) { 924 if (!pe->started) {
920 /* this is protected by snap->lock */ 925 /* this is protected by snap->lock */
@@ -992,7 +997,7 @@ static int snapshot_status(struct dm_target *ti, status_type_t type,
992 *---------------------------------------------------------------*/ 997 *---------------------------------------------------------------*/
993static int __origin_write(struct list_head *snapshots, struct bio *bio) 998static int __origin_write(struct list_head *snapshots, struct bio *bio)
994{ 999{
995 int r = 1, first = 0; 1000 int r = DM_MAPIO_REMAPPED, first = 0;
996 struct dm_snapshot *snap; 1001 struct dm_snapshot *snap;
997 struct exception *e; 1002 struct exception *e;
998 struct pending_exception *pe, *next_pe, *primary_pe = NULL; 1003 struct pending_exception *pe, *next_pe, *primary_pe = NULL;
@@ -1050,7 +1055,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1050 1055
1051 bio_list_add(&primary_pe->origin_bios, bio); 1056 bio_list_add(&primary_pe->origin_bios, bio);
1052 1057
1053 r = 0; 1058 r = DM_MAPIO_SUBMITTED;
1054 } 1059 }
1055 1060
1056 if (!pe->primary_pe) { 1061 if (!pe->primary_pe) {
@@ -1099,7 +1104,7 @@ static int __origin_write(struct list_head *snapshots, struct bio *bio)
1099static int do_origin(struct dm_dev *origin, struct bio *bio) 1104static int do_origin(struct dm_dev *origin, struct bio *bio)
1100{ 1105{
1101 struct origin *o; 1106 struct origin *o;
1102 int r = 1; 1107 int r = DM_MAPIO_REMAPPED;
1103 1108
1104 down_read(&_origins_lock); 1109 down_read(&_origins_lock);
1105 o = __lookup_origin(origin->bdev); 1110 o = __lookup_origin(origin->bdev);
@@ -1156,7 +1161,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio,
1156 return -EOPNOTSUPP; 1161 return -EOPNOTSUPP;
1157 1162
1158 /* Only tell snapshots if this is a write */ 1163 /* Only tell snapshots if this is a write */
1159 return (bio_rw(bio) == WRITE) ? do_origin(dev, bio) : 1; 1164 return (bio_rw(bio) == WRITE) ? do_origin(dev, bio) : DM_MAPIO_REMAPPED;
1160} 1165}
1161 1166
1162#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r)) 1167#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index 6c29fcecd892..51f5e0760012 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -186,7 +186,7 @@ static int stripe_map(struct dm_target *ti, struct bio *bio,
186 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 186 bio->bi_bdev = sc->stripe[stripe].dev->bdev;
187 bio->bi_sector = sc->stripe[stripe].physical_start + 187 bio->bi_sector = sc->stripe[stripe].physical_start +
188 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask); 188 (chunk << sc->chunk_shift) + (offset & sc->chunk_mask);
189 return 1; 189 return DM_MAPIO_REMAPPED;
190} 190}
191 191
192static int stripe_status(struct dm_target *ti, 192static int stripe_status(struct dm_target *ti,
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c
index ea569f7348d2..f314d7dc9c26 100644
--- a/drivers/md/dm-zero.c
+++ b/drivers/md/dm-zero.c
@@ -46,7 +46,7 @@ static int zero_map(struct dm_target *ti, struct bio *bio,
46 bio_endio(bio, bio->bi_size, 0); 46 bio_endio(bio, bio->bi_size, 0);
47 47
48 /* accepted bio, don't make new request */ 48 /* accepted bio, don't make new request */
49 return 0; 49 return DM_MAPIO_SUBMITTED;
50} 50}
51 51
52static struct target_type zero_target = { 52static struct target_type zero_target = {
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 7ec1b112a6d5..fe7c56e10435 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -68,10 +68,12 @@ union map_info *dm_get_mapinfo(struct bio *bio)
68#define DMF_FROZEN 2 68#define DMF_FROZEN 2
69#define DMF_FREEING 3 69#define DMF_FREEING 3
70#define DMF_DELETING 4 70#define DMF_DELETING 4
71#define DMF_NOFLUSH_SUSPENDING 5
71 72
72struct mapped_device { 73struct mapped_device {
73 struct rw_semaphore io_lock; 74 struct rw_semaphore io_lock;
74 struct semaphore suspend_lock; 75 struct semaphore suspend_lock;
76 spinlock_t pushback_lock;
75 rwlock_t map_lock; 77 rwlock_t map_lock;
76 atomic_t holders; 78 atomic_t holders;
77 atomic_t open_count; 79 atomic_t open_count;
@@ -89,7 +91,8 @@ struct mapped_device {
89 */ 91 */
90 atomic_t pending; 92 atomic_t pending;
91 wait_queue_head_t wait; 93 wait_queue_head_t wait;
92 struct bio_list deferred; 94 struct bio_list deferred;
95 struct bio_list pushback;
93 96
94 /* 97 /*
95 * The current mapping. 98 * The current mapping.
@@ -444,23 +447,50 @@ int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo)
444 * you this clearly demarcated crap. 447 * you this clearly demarcated crap.
445 *---------------------------------------------------------------*/ 448 *---------------------------------------------------------------*/
446 449
450static int __noflush_suspending(struct mapped_device *md)
451{
452 return test_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
453}
454
447/* 455/*
448 * Decrements the number of outstanding ios that a bio has been 456 * Decrements the number of outstanding ios that a bio has been
449 * cloned into, completing the original io if necc. 457 * cloned into, completing the original io if necc.
450 */ 458 */
451static void dec_pending(struct dm_io *io, int error) 459static void dec_pending(struct dm_io *io, int error)
452{ 460{
453 if (error) 461 unsigned long flags;
462
463 /* Push-back supersedes any I/O errors */
464 if (error && !(io->error > 0 && __noflush_suspending(io->md)))
454 io->error = error; 465 io->error = error;
455 466
456 if (atomic_dec_and_test(&io->io_count)) { 467 if (atomic_dec_and_test(&io->io_count)) {
468 if (io->error == DM_ENDIO_REQUEUE) {
469 /*
470 * Target requested pushing back the I/O.
471 * This must be handled before the sleeper on
472 * suspend queue merges the pushback list.
473 */
474 spin_lock_irqsave(&io->md->pushback_lock, flags);
475 if (__noflush_suspending(io->md))
476 bio_list_add(&io->md->pushback, io->bio);
477 else
478 /* noflush suspend was interrupted. */
479 io->error = -EIO;
480 spin_unlock_irqrestore(&io->md->pushback_lock, flags);
481 }
482
457 if (end_io_acct(io)) 483 if (end_io_acct(io))
458 /* nudge anyone waiting on suspend queue */ 484 /* nudge anyone waiting on suspend queue */
459 wake_up(&io->md->wait); 485 wake_up(&io->md->wait);
460 486
461 blk_add_trace_bio(io->md->queue, io->bio, BLK_TA_COMPLETE); 487 if (io->error != DM_ENDIO_REQUEUE) {
488 blk_add_trace_bio(io->md->queue, io->bio,
489 BLK_TA_COMPLETE);
490
491 bio_endio(io->bio, io->bio->bi_size, io->error);
492 }
462 493
463 bio_endio(io->bio, io->bio->bi_size, io->error);
464 free_io(io->md, io); 494 free_io(io->md, io);
465 } 495 }
466} 496}
@@ -480,12 +510,19 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
480 510
481 if (endio) { 511 if (endio) {
482 r = endio(tio->ti, bio, error, &tio->info); 512 r = endio(tio->ti, bio, error, &tio->info);
483 if (r < 0) 513 if (r < 0 || r == DM_ENDIO_REQUEUE)
514 /*
515 * error and requeue request are handled
516 * in dec_pending().
517 */
484 error = r; 518 error = r;
485 519 else if (r == DM_ENDIO_INCOMPLETE)
486 else if (r > 0) 520 /* The target will handle the io */
487 /* the target wants another shot at the io */
488 return 1; 521 return 1;
522 else if (r) {
523 DMWARN("unimplemented target endio return value: %d", r);
524 BUG();
525 }
489 } 526 }
490 527
491 dec_pending(tio->io, error); 528 dec_pending(tio->io, error);
@@ -543,7 +580,7 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
543 atomic_inc(&tio->io->io_count); 580 atomic_inc(&tio->io->io_count);
544 sector = clone->bi_sector; 581 sector = clone->bi_sector;
545 r = ti->type->map(ti, clone, &tio->info); 582 r = ti->type->map(ti, clone, &tio->info);
546 if (r > 0) { 583 if (r == DM_MAPIO_REMAPPED) {
547 /* the bio has been remapped so dispatch it */ 584 /* the bio has been remapped so dispatch it */
548 585
549 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone, 586 blk_add_trace_remap(bdev_get_queue(clone->bi_bdev), clone,
@@ -551,10 +588,8 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
551 clone->bi_sector); 588 clone->bi_sector);
552 589
553 generic_make_request(clone); 590 generic_make_request(clone);
554 } 591 } else if (r < 0 || r == DM_MAPIO_REQUEUE) {
555 592 /* error the io and bail out, or requeue it if needed */
556 else if (r < 0) {
557 /* error the io and bail out */
558 md = tio->io->md; 593 md = tio->io->md;
559 dec_pending(tio->io, r); 594 dec_pending(tio->io, r);
560 /* 595 /*
@@ -563,6 +598,9 @@ static void __map_bio(struct dm_target *ti, struct bio *clone,
563 clone->bi_private = md->bs; 598 clone->bi_private = md->bs;
564 bio_put(clone); 599 bio_put(clone);
565 free_tio(md, tio); 600 free_tio(md, tio);
601 } else if (r) {
602 DMWARN("unimplemented target map return value: %d", r);
603 BUG();
566 } 604 }
567} 605}
568 606
@@ -948,6 +986,7 @@ static struct mapped_device *alloc_dev(int minor)
948 memset(md, 0, sizeof(*md)); 986 memset(md, 0, sizeof(*md));
949 init_rwsem(&md->io_lock); 987 init_rwsem(&md->io_lock);
950 init_MUTEX(&md->suspend_lock); 988 init_MUTEX(&md->suspend_lock);
989 spin_lock_init(&md->pushback_lock);
951 rwlock_init(&md->map_lock); 990 rwlock_init(&md->map_lock);
952 atomic_set(&md->holders, 1); 991 atomic_set(&md->holders, 1);
953 atomic_set(&md->open_count, 0); 992 atomic_set(&md->open_count, 0);
@@ -966,8 +1005,8 @@ static struct mapped_device *alloc_dev(int minor)
966 md->queue->issue_flush_fn = dm_flush_all; 1005 md->queue->issue_flush_fn = dm_flush_all;
967 1006
968 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache); 1007 md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
969 if (!md->io_pool) 1008 if (!md->io_pool)
970 goto bad2; 1009 goto bad2;
971 1010
972 md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache); 1011 md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
973 if (!md->tio_pool) 1012 if (!md->tio_pool)
@@ -1275,12 +1314,15 @@ static void unlock_fs(struct mapped_device *md)
1275 * dm_bind_table, dm_suspend must be called to flush any in 1314 * dm_bind_table, dm_suspend must be called to flush any in
1276 * flight bios and ensure that any further io gets deferred. 1315 * flight bios and ensure that any further io gets deferred.
1277 */ 1316 */
1278int dm_suspend(struct mapped_device *md, int do_lockfs) 1317int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
1279{ 1318{
1280 struct dm_table *map = NULL; 1319 struct dm_table *map = NULL;
1320 unsigned long flags;
1281 DECLARE_WAITQUEUE(wait, current); 1321 DECLARE_WAITQUEUE(wait, current);
1282 struct bio *def; 1322 struct bio *def;
1283 int r = -EINVAL; 1323 int r = -EINVAL;
1324 int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
1325 int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
1284 1326
1285 down(&md->suspend_lock); 1327 down(&md->suspend_lock);
1286 1328
@@ -1289,6 +1331,13 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1289 1331
1290 map = dm_get_table(md); 1332 map = dm_get_table(md);
1291 1333
1334 /*
1335 * DMF_NOFLUSH_SUSPENDING must be set before presuspend.
1336 * This flag is cleared before dm_suspend returns.
1337 */
1338 if (noflush)
1339 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
1340
1292 /* This does not get reverted if there's an error later. */ 1341 /* This does not get reverted if there's an error later. */
1293 dm_table_presuspend_targets(map); 1342 dm_table_presuspend_targets(map);
1294 1343
@@ -1296,11 +1345,14 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1296 if (!md->suspended_bdev) { 1345 if (!md->suspended_bdev) {
1297 DMWARN("bdget failed in dm_suspend"); 1346 DMWARN("bdget failed in dm_suspend");
1298 r = -ENOMEM; 1347 r = -ENOMEM;
1299 goto out; 1348 goto flush_and_out;
1300 } 1349 }
1301 1350
1302 /* Flush I/O to the device. */ 1351 /*
1303 if (do_lockfs) { 1352 * Flush I/O to the device.
1353 * noflush supersedes do_lockfs, because lock_fs() needs to flush I/Os.
1354 */
1355 if (do_lockfs && !noflush) {
1304 r = lock_fs(md); 1356 r = lock_fs(md);
1305 if (r) 1357 if (r)
1306 goto out; 1358 goto out;
@@ -1336,6 +1388,14 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1336 down_write(&md->io_lock); 1388 down_write(&md->io_lock);
1337 remove_wait_queue(&md->wait, &wait); 1389 remove_wait_queue(&md->wait, &wait);
1338 1390
1391 if (noflush) {
1392 spin_lock_irqsave(&md->pushback_lock, flags);
1393 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
1394 bio_list_merge_head(&md->deferred, &md->pushback);
1395 bio_list_init(&md->pushback);
1396 spin_unlock_irqrestore(&md->pushback_lock, flags);
1397 }
1398
1339 /* were we interrupted ? */ 1399 /* were we interrupted ? */
1340 r = -EINTR; 1400 r = -EINTR;
1341 if (atomic_read(&md->pending)) { 1401 if (atomic_read(&md->pending)) {
@@ -1344,7 +1404,7 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1344 __flush_deferred_io(md, def); 1404 __flush_deferred_io(md, def);
1345 up_write(&md->io_lock); 1405 up_write(&md->io_lock);
1346 unlock_fs(md); 1406 unlock_fs(md);
1347 goto out; 1407 goto out; /* pushback list is already flushed, so skip flush */
1348 } 1408 }
1349 up_write(&md->io_lock); 1409 up_write(&md->io_lock);
1350 1410
@@ -1354,6 +1414,25 @@ int dm_suspend(struct mapped_device *md, int do_lockfs)
1354 1414
1355 r = 0; 1415 r = 0;
1356 1416
1417flush_and_out:
1418 if (r && noflush) {
1419 /*
1420 * Because there may be already I/Os in the pushback list,
1421 * flush them before return.
1422 */
1423 down_write(&md->io_lock);
1424
1425 spin_lock_irqsave(&md->pushback_lock, flags);
1426 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
1427 bio_list_merge_head(&md->deferred, &md->pushback);
1428 bio_list_init(&md->pushback);
1429 spin_unlock_irqrestore(&md->pushback_lock, flags);
1430
1431 def = bio_list_get(&md->deferred);
1432 __flush_deferred_io(md, def);
1433 up_write(&md->io_lock);
1434 }
1435
1357out: 1436out:
1358 if (r && md->suspended_bdev) { 1437 if (r && md->suspended_bdev) {
1359 bdput(md->suspended_bdev); 1438 bdput(md->suspended_bdev);
@@ -1440,6 +1519,17 @@ int dm_suspended(struct mapped_device *md)
1440 return test_bit(DMF_SUSPENDED, &md->flags); 1519 return test_bit(DMF_SUSPENDED, &md->flags);
1441} 1520}
1442 1521
1522int dm_noflush_suspending(struct dm_target *ti)
1523{
1524 struct mapped_device *md = dm_table_get_md(ti->table);
1525 int r = __noflush_suspending(md);
1526
1527 dm_put(md);
1528
1529 return r;
1530}
1531EXPORT_SYMBOL_GPL(dm_noflush_suspending);
1532
1443static struct block_device_operations dm_blk_dops = { 1533static struct block_device_operations dm_blk_dops = {
1444 .open = dm_blk_open, 1534 .open = dm_blk_open,
1445 .release = dm_blk_close, 1535 .release = dm_blk_close,
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index a48ec5e3c1f4..2f796b1436b2 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -33,6 +33,25 @@
33#define SECTOR_SHIFT 9 33#define SECTOR_SHIFT 9
34 34
35/* 35/*
36 * Definitions of return values from target end_io function.
37 */
38#define DM_ENDIO_INCOMPLETE 1
39#define DM_ENDIO_REQUEUE 2
40
41/*
42 * Definitions of return values from target map function.
43 */
44#define DM_MAPIO_SUBMITTED 0
45#define DM_MAPIO_REMAPPED 1
46#define DM_MAPIO_REQUEUE DM_ENDIO_REQUEUE
47
48/*
49 * Suspend feature flags
50 */
51#define DM_SUSPEND_LOCKFS_FLAG (1 << 0)
52#define DM_SUSPEND_NOFLUSH_FLAG (1 << 1)
53
54/*
36 * List of devices that a metadevice uses and should open/close. 55 * List of devices that a metadevice uses and should open/close.
37 */ 56 */
38struct dm_dev { 57struct dm_dev {
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 6c4345bde07e..21e2a7b08841 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1413,7 +1413,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
1413 struct block_device *bdev; 1413 struct block_device *bdev;
1414 char b[BDEVNAME_SIZE]; 1414 char b[BDEVNAME_SIZE];
1415 1415
1416 bdev = open_partition_by_devnum(dev, FMODE_READ|FMODE_WRITE); 1416 bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE);
1417 if (IS_ERR(bdev)) { 1417 if (IS_ERR(bdev)) {
1418 printk(KERN_ERR "md: could not open %s.\n", 1418 printk(KERN_ERR "md: could not open %s.\n",
1419 __bdevname(dev, b)); 1419 __bdevname(dev, b));
@@ -1423,7 +1423,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev)
1423 if (err) { 1423 if (err) {
1424 printk(KERN_ERR "md: could not bd_claim %s.\n", 1424 printk(KERN_ERR "md: could not bd_claim %s.\n",
1425 bdevname(bdev, b)); 1425 bdevname(bdev, b));
1426 blkdev_put_partition(bdev); 1426 blkdev_put(bdev);
1427 return err; 1427 return err;
1428 } 1428 }
1429 rdev->bdev = bdev; 1429 rdev->bdev = bdev;
@@ -1437,7 +1437,7 @@ static void unlock_rdev(mdk_rdev_t *rdev)
1437 if (!bdev) 1437 if (!bdev)
1438 MD_BUG(); 1438 MD_BUG();
1439 bd_release(bdev); 1439 bd_release(bdev);
1440 blkdev_put_partition(bdev); 1440 blkdev_put(bdev);
1441} 1441}
1442 1442
1443void md_autodetect_dev(dev_t dev); 1443void md_autodetect_dev(dev_t dev);
@@ -3314,6 +3314,10 @@ static int do_md_stop(mddev_t * mddev, int mode)
3314 3314
3315 module_put(mddev->pers->owner); 3315 module_put(mddev->pers->owner);
3316 mddev->pers = NULL; 3316 mddev->pers = NULL;
3317
3318 set_capacity(disk, 0);
3319 mddev->changed = 1;
3320
3317 if (mddev->ro) 3321 if (mddev->ro)
3318 mddev->ro = 0; 3322 mddev->ro = 0;
3319 } 3323 }
@@ -3333,7 +3337,7 @@ static int do_md_stop(mddev_t * mddev, int mode)
3333 if (mode == 0) { 3337 if (mode == 0) {
3334 mdk_rdev_t *rdev; 3338 mdk_rdev_t *rdev;
3335 struct list_head *tmp; 3339 struct list_head *tmp;
3336 struct gendisk *disk; 3340
3337 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev)); 3341 printk(KERN_INFO "md: %s stopped.\n", mdname(mddev));
3338 3342
3339 bitmap_destroy(mddev); 3343 bitmap_destroy(mddev);
@@ -3358,10 +3362,6 @@ static int do_md_stop(mddev_t * mddev, int mode)
3358 mddev->raid_disks = 0; 3362 mddev->raid_disks = 0;
3359 mddev->recovery_cp = 0; 3363 mddev->recovery_cp = 0;
3360 3364
3361 disk = mddev->gendisk;
3362 if (disk)
3363 set_capacity(disk, 0);
3364 mddev->changed = 1;
3365 } else if (mddev->pers) 3365 } else if (mddev->pers)
3366 printk(KERN_INFO "md: %s switched to read-only mode.\n", 3366 printk(KERN_INFO "md: %s switched to read-only mode.\n",
3367 mdname(mddev)); 3367 mdname(mddev));
@@ -3371,6 +3371,7 @@ out:
3371 return err; 3371 return err;
3372} 3372}
3373 3373
3374#ifndef MODULE
3374static void autorun_array(mddev_t *mddev) 3375static void autorun_array(mddev_t *mddev)
3375{ 3376{
3376 mdk_rdev_t *rdev; 3377 mdk_rdev_t *rdev;
@@ -3485,6 +3486,7 @@ static void autorun_devices(int part)
3485 } 3486 }
3486 printk(KERN_INFO "md: ... autorun DONE.\n"); 3487 printk(KERN_INFO "md: ... autorun DONE.\n");
3487} 3488}
3489#endif /* !MODULE */
3488 3490
3489static int get_version(void __user * arg) 3491static int get_version(void __user * arg)
3490{ 3492{
@@ -3722,6 +3724,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
3722 if (err) 3724 if (err)
3723 export_rdev(rdev); 3725 export_rdev(rdev);
3724 3726
3727 md_update_sb(mddev, 1);
3725 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); 3728 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
3726 md_wakeup_thread(mddev->thread); 3729 md_wakeup_thread(mddev->thread);
3727 return err; 3730 return err;
@@ -4423,7 +4426,7 @@ static int md_open(struct inode *inode, struct file *file)
4423 mddev_t *mddev = inode->i_bdev->bd_disk->private_data; 4426 mddev_t *mddev = inode->i_bdev->bd_disk->private_data;
4424 int err; 4427 int err;
4425 4428
4426 if ((err = mddev_lock(mddev))) 4429 if ((err = mutex_lock_interruptible_nested(&mddev->reconfig_mutex, 1)))
4427 goto out; 4430 goto out;
4428 4431
4429 err = 0; 4432 err = 0;
@@ -4846,8 +4849,8 @@ static int md_seq_show(struct seq_file *seq, void *v)
4846 chunk_kb ? "KB" : "B"); 4849 chunk_kb ? "KB" : "B");
4847 if (bitmap->file) { 4850 if (bitmap->file) {
4848 seq_printf(seq, ", file: "); 4851 seq_printf(seq, ", file: ");
4849 seq_path(seq, bitmap->file->f_vfsmnt, 4852 seq_path(seq, bitmap->file->f_path.mnt,
4850 bitmap->file->f_dentry," \t\n"); 4853 bitmap->file->f_path.dentry," \t\n");
4851 } 4854 }
4852 4855
4853 seq_printf(seq, "\n"); 4856 seq_printf(seq, "\n");
@@ -5273,7 +5276,6 @@ void md_do_sync(mddev_t *mddev)
5273 mddev->pers->sync_request(mddev, max_sectors, &skipped, 1); 5276 mddev->pers->sync_request(mddev, max_sectors, &skipped, 1);
5274 5277
5275 if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) && 5278 if (!test_bit(MD_RECOVERY_ERR, &mddev->recovery) &&
5276 test_bit(MD_RECOVERY_SYNC, &mddev->recovery) &&
5277 !test_bit(MD_RECOVERY_CHECK, &mddev->recovery) && 5279 !test_bit(MD_RECOVERY_CHECK, &mddev->recovery) &&
5278 mddev->curr_resync > 2) { 5280 mddev->curr_resync > 2) {
5279 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) { 5281 if (test_bit(MD_RECOVERY_SYNC, &mddev->recovery)) {
@@ -5297,6 +5299,7 @@ void md_do_sync(mddev_t *mddev)
5297 rdev->recovery_offset = mddev->curr_resync; 5299 rdev->recovery_offset = mddev->curr_resync;
5298 } 5300 }
5299 } 5301 }
5302 set_bit(MD_CHANGE_DEVS, &mddev->flags);
5300 5303
5301 skip: 5304 skip:
5302 mddev->curr_resync = 0; 5305 mddev->curr_resync = 0;
@@ -5593,7 +5596,7 @@ static void autostart_arrays(int part)
5593 autorun_devices(part); 5596 autorun_devices(part);
5594} 5597}
5595 5598
5596#endif 5599#endif /* !MODULE */
5597 5600
5598static __exit void md_exit(void) 5601static __exit void md_exit(void)
5599{ 5602{
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 656fae912fe3..b3c5e12f081d 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1951,6 +1951,7 @@ static int run(mddev_t *mddev)
1951 !test_bit(In_sync, &disk->rdev->flags)) { 1951 !test_bit(In_sync, &disk->rdev->flags)) {
1952 disk->head_position = 0; 1952 disk->head_position = 0;
1953 mddev->degraded++; 1953 mddev->degraded++;
1954 conf->fullsync = 1;
1954 } 1955 }
1955 } 1956 }
1956 if (mddev->degraded == conf->raid_disks) { 1957 if (mddev->degraded == conf->raid_disks) {
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 52914d5cec76..377f8bc9b78b 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -134,6 +134,8 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh)
134 if (!test_bit(STRIPE_EXPANDING, &sh->state)) { 134 if (!test_bit(STRIPE_EXPANDING, &sh->state)) {
135 list_add_tail(&sh->lru, &conf->inactive_list); 135 list_add_tail(&sh->lru, &conf->inactive_list);
136 wake_up(&conf->wait_for_stripe); 136 wake_up(&conf->wait_for_stripe);
137 if (conf->retry_read_aligned)
138 md_wakeup_thread(conf->mddev->thread);
137 } 139 }
138 } 140 }
139 } 141 }
@@ -542,35 +544,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
542 } 544 }
543 545
544 if (uptodate) { 546 if (uptodate) {
545#if 0
546 struct bio *bio;
547 unsigned long flags;
548 spin_lock_irqsave(&conf->device_lock, flags);
549 /* we can return a buffer if we bypassed the cache or
550 * if the top buffer is not in highmem. If there are
551 * multiple buffers, leave the extra work to
552 * handle_stripe
553 */
554 buffer = sh->bh_read[i];
555 if (buffer &&
556 (!PageHighMem(buffer->b_page)
557 || buffer->b_page == bh->b_page )
558 ) {
559 sh->bh_read[i] = buffer->b_reqnext;
560 buffer->b_reqnext = NULL;
561 } else
562 buffer = NULL;
563 spin_unlock_irqrestore(&conf->device_lock, flags);
564 if (sh->bh_page[i]==bh->b_page)
565 set_buffer_uptodate(bh);
566 if (buffer) {
567 if (buffer->b_page != bh->b_page)
568 memcpy(buffer->b_data, bh->b_data, bh->b_size);
569 buffer->b_end_io(buffer, 1);
570 }
571#else
572 set_bit(R5_UPTODATE, &sh->dev[i].flags); 547 set_bit(R5_UPTODATE, &sh->dev[i].flags);
573#endif
574 if (test_bit(R5_ReadError, &sh->dev[i].flags)) { 548 if (test_bit(R5_ReadError, &sh->dev[i].flags)) {
575 rdev = conf->disks[i].rdev; 549 rdev = conf->disks[i].rdev;
576 printk(KERN_INFO "raid5:%s: read error corrected (%lu sectors at %llu on %s)\n", 550 printk(KERN_INFO "raid5:%s: read error corrected (%lu sectors at %llu on %s)\n",
@@ -616,14 +590,6 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
616 } 590 }
617 } 591 }
618 rdev_dec_pending(conf->disks[i].rdev, conf->mddev); 592 rdev_dec_pending(conf->disks[i].rdev, conf->mddev);
619#if 0
620 /* must restore b_page before unlocking buffer... */
621 if (sh->bh_page[i] != bh->b_page) {
622 bh->b_page = sh->bh_page[i];
623 bh->b_data = page_address(bh->b_page);
624 clear_buffer_uptodate(bh);
625 }
626#endif
627 clear_bit(R5_LOCKED, &sh->dev[i].flags); 593 clear_bit(R5_LOCKED, &sh->dev[i].flags);
628 set_bit(STRIPE_HANDLE, &sh->state); 594 set_bit(STRIPE_HANDLE, &sh->state);
629 release_stripe(sh); 595 release_stripe(sh);
@@ -821,7 +787,8 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
821static sector_t compute_blocknr(struct stripe_head *sh, int i) 787static sector_t compute_blocknr(struct stripe_head *sh, int i)
822{ 788{
823 raid5_conf_t *conf = sh->raid_conf; 789 raid5_conf_t *conf = sh->raid_conf;
824 int raid_disks = sh->disks, data_disks = raid_disks - 1; 790 int raid_disks = sh->disks;
791 int data_disks = raid_disks - conf->max_degraded;
825 sector_t new_sector = sh->sector, check; 792 sector_t new_sector = sh->sector, check;
826 int sectors_per_chunk = conf->chunk_size >> 9; 793 int sectors_per_chunk = conf->chunk_size >> 9;
827 sector_t stripe; 794 sector_t stripe;
@@ -857,7 +824,6 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
857 } 824 }
858 break; 825 break;
859 case 6: 826 case 6:
860 data_disks = raid_disks - 2;
861 if (i == raid6_next_disk(sh->pd_idx, raid_disks)) 827 if (i == raid6_next_disk(sh->pd_idx, raid_disks))
862 return 0; /* It is the Q disk */ 828 return 0; /* It is the Q disk */
863 switch (conf->algorithm) { 829 switch (conf->algorithm) {
@@ -1353,8 +1319,10 @@ static int stripe_to_pdidx(sector_t stripe, raid5_conf_t *conf, int disks)
1353 int pd_idx, dd_idx; 1319 int pd_idx, dd_idx;
1354 int chunk_offset = sector_div(stripe, sectors_per_chunk); 1320 int chunk_offset = sector_div(stripe, sectors_per_chunk);
1355 1321
1356 raid5_compute_sector(stripe*(disks-1)*sectors_per_chunk 1322 raid5_compute_sector(stripe * (disks - conf->max_degraded)
1357 + chunk_offset, disks, disks-1, &dd_idx, &pd_idx, conf); 1323 *sectors_per_chunk + chunk_offset,
1324 disks, disks - conf->max_degraded,
1325 &dd_idx, &pd_idx, conf);
1358 return pd_idx; 1326 return pd_idx;
1359} 1327}
1360 1328
@@ -1615,15 +1583,6 @@ static void handle_stripe5(struct stripe_head *sh)
1615 } else if (test_bit(R5_Insync, &dev->flags)) { 1583 } else if (test_bit(R5_Insync, &dev->flags)) {
1616 set_bit(R5_LOCKED, &dev->flags); 1584 set_bit(R5_LOCKED, &dev->flags);
1617 set_bit(R5_Wantread, &dev->flags); 1585 set_bit(R5_Wantread, &dev->flags);
1618#if 0
1619 /* if I am just reading this block and we don't have
1620 a failed drive, or any pending writes then sidestep the cache */
1621 if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext &&
1622 ! syncing && !failed && !to_write) {
1623 sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page;
1624 sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data;
1625 }
1626#endif
1627 locked++; 1586 locked++;
1628 PRINTK("Reading block %d (sync=%d)\n", 1587 PRINTK("Reading block %d (sync=%d)\n",
1629 i, syncing); 1588 i, syncing);
@@ -1641,9 +1600,6 @@ static void handle_stripe5(struct stripe_head *sh)
1641 dev = &sh->dev[i]; 1600 dev = &sh->dev[i];
1642 if ((dev->towrite || i == sh->pd_idx) && 1601 if ((dev->towrite || i == sh->pd_idx) &&
1643 (!test_bit(R5_LOCKED, &dev->flags) 1602 (!test_bit(R5_LOCKED, &dev->flags)
1644#if 0
1645|| sh->bh_page[i]!=bh->b_page
1646#endif
1647 ) && 1603 ) &&
1648 !test_bit(R5_UPTODATE, &dev->flags)) { 1604 !test_bit(R5_UPTODATE, &dev->flags)) {
1649 if (test_bit(R5_Insync, &dev->flags) 1605 if (test_bit(R5_Insync, &dev->flags)
@@ -1655,9 +1611,6 @@ static void handle_stripe5(struct stripe_head *sh)
1655 /* Would I have to read this buffer for reconstruct_write */ 1611 /* Would I have to read this buffer for reconstruct_write */
1656 if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx && 1612 if (!test_bit(R5_OVERWRITE, &dev->flags) && i != sh->pd_idx &&
1657 (!test_bit(R5_LOCKED, &dev->flags) 1613 (!test_bit(R5_LOCKED, &dev->flags)
1658#if 0
1659|| sh->bh_page[i] != bh->b_page
1660#endif
1661 ) && 1614 ) &&
1662 !test_bit(R5_UPTODATE, &dev->flags)) { 1615 !test_bit(R5_UPTODATE, &dev->flags)) {
1663 if (test_bit(R5_Insync, &dev->flags)) rcw++; 1616 if (test_bit(R5_Insync, &dev->flags)) rcw++;
@@ -1865,7 +1818,9 @@ static void handle_stripe5(struct stripe_head *sh)
1865 return_bi = bi->bi_next; 1818 return_bi = bi->bi_next;
1866 bi->bi_next = NULL; 1819 bi->bi_next = NULL;
1867 bi->bi_size = 0; 1820 bi->bi_size = 0;
1868 bi->bi_end_io(bi, bytes, 0); 1821 bi->bi_end_io(bi, bytes,
1822 test_bit(BIO_UPTODATE, &bi->bi_flags)
1823 ? 0 : -EIO);
1869 } 1824 }
1870 for (i=disks; i-- ;) { 1825 for (i=disks; i-- ;) {
1871 int rw; 1826 int rw;
@@ -2193,15 +2148,6 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2193 } else if (test_bit(R5_Insync, &dev->flags)) { 2148 } else if (test_bit(R5_Insync, &dev->flags)) {
2194 set_bit(R5_LOCKED, &dev->flags); 2149 set_bit(R5_LOCKED, &dev->flags);
2195 set_bit(R5_Wantread, &dev->flags); 2150 set_bit(R5_Wantread, &dev->flags);
2196#if 0
2197 /* if I am just reading this block and we don't have
2198 a failed drive, or any pending writes then sidestep the cache */
2199 if (sh->bh_read[i] && !sh->bh_read[i]->b_reqnext &&
2200 ! syncing && !failed && !to_write) {
2201 sh->bh_cache[i]->b_page = sh->bh_read[i]->b_page;
2202 sh->bh_cache[i]->b_data = sh->bh_read[i]->b_data;
2203 }
2204#endif
2205 locked++; 2151 locked++;
2206 PRINTK("Reading block %d (sync=%d)\n", 2152 PRINTK("Reading block %d (sync=%d)\n",
2207 i, syncing); 2153 i, syncing);
@@ -2220,9 +2166,6 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2220 if (!test_bit(R5_OVERWRITE, &dev->flags) 2166 if (!test_bit(R5_OVERWRITE, &dev->flags)
2221 && i != pd_idx && i != qd_idx 2167 && i != pd_idx && i != qd_idx
2222 && (!test_bit(R5_LOCKED, &dev->flags) 2168 && (!test_bit(R5_LOCKED, &dev->flags)
2223#if 0
2224 || sh->bh_page[i] != bh->b_page
2225#endif
2226 ) && 2169 ) &&
2227 !test_bit(R5_UPTODATE, &dev->flags)) { 2170 !test_bit(R5_UPTODATE, &dev->flags)) {
2228 if (test_bit(R5_Insync, &dev->flags)) rcw++; 2171 if (test_bit(R5_Insync, &dev->flags)) rcw++;
@@ -2418,7 +2361,9 @@ static void handle_stripe6(struct stripe_head *sh, struct page *tmp_page)
2418 return_bi = bi->bi_next; 2361 return_bi = bi->bi_next;
2419 bi->bi_next = NULL; 2362 bi->bi_next = NULL;
2420 bi->bi_size = 0; 2363 bi->bi_size = 0;
2421 bi->bi_end_io(bi, bytes, 0); 2364 bi->bi_end_io(bi, bytes,
2365 test_bit(BIO_UPTODATE, &bi->bi_flags)
2366 ? 0 : -EIO);
2422 } 2367 }
2423 for (i=disks; i-- ;) { 2368 for (i=disks; i-- ;) {
2424 int rw; 2369 int rw;
@@ -2611,6 +2556,180 @@ static int raid5_congested(void *data, int bits)
2611 return 0; 2556 return 0;
2612} 2557}
2613 2558
2559/* We want read requests to align with chunks where possible,
2560 * but write requests don't need to.
2561 */
2562static int raid5_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *biovec)
2563{
2564 mddev_t *mddev = q->queuedata;
2565 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
2566 int max;
2567 unsigned int chunk_sectors = mddev->chunk_size >> 9;
2568 unsigned int bio_sectors = bio->bi_size >> 9;
2569
2570 if (bio_data_dir(bio))
2571 return biovec->bv_len; /* always allow writes to be mergeable */
2572
2573 max = (chunk_sectors - ((sector & (chunk_sectors - 1)) + bio_sectors)) << 9;
2574 if (max < 0) max = 0;
2575 if (max <= biovec->bv_len && bio_sectors == 0)
2576 return biovec->bv_len;
2577 else
2578 return max;
2579}
2580
2581
2582static int in_chunk_boundary(mddev_t *mddev, struct bio *bio)
2583{
2584 sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
2585 unsigned int chunk_sectors = mddev->chunk_size >> 9;
2586 unsigned int bio_sectors = bio->bi_size >> 9;
2587
2588 return chunk_sectors >=
2589 ((sector & (chunk_sectors - 1)) + bio_sectors);
2590}
2591
2592/*
2593 * add bio to the retry LIFO ( in O(1) ... we are in interrupt )
2594 * later sampled by raid5d.
2595 */
2596static void add_bio_to_retry(struct bio *bi,raid5_conf_t *conf)
2597{
2598 unsigned long flags;
2599
2600 spin_lock_irqsave(&conf->device_lock, flags);
2601
2602 bi->bi_next = conf->retry_read_aligned_list;
2603 conf->retry_read_aligned_list = bi;
2604
2605 spin_unlock_irqrestore(&conf->device_lock, flags);
2606 md_wakeup_thread(conf->mddev->thread);
2607}
2608
2609
2610static struct bio *remove_bio_from_retry(raid5_conf_t *conf)
2611{
2612 struct bio *bi;
2613
2614 bi = conf->retry_read_aligned;
2615 if (bi) {
2616 conf->retry_read_aligned = NULL;
2617 return bi;
2618 }
2619 bi = conf->retry_read_aligned_list;
2620 if(bi) {
2621 conf->retry_read_aligned = bi->bi_next;
2622 bi->bi_next = NULL;
2623 bi->bi_phys_segments = 1; /* biased count of active stripes */
2624 bi->bi_hw_segments = 0; /* count of processed stripes */
2625 }
2626
2627 return bi;
2628}
2629
2630
2631/*
2632 * The "raid5_align_endio" should check if the read succeeded and if it
2633 * did, call bio_endio on the original bio (having bio_put the new bio
2634 * first).
2635 * If the read failed..
2636 */
2637static int raid5_align_endio(struct bio *bi, unsigned int bytes, int error)
2638{
2639 struct bio* raid_bi = bi->bi_private;
2640 mddev_t *mddev;
2641 raid5_conf_t *conf;
2642 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
2643 mdk_rdev_t *rdev;
2644
2645 if (bi->bi_size)
2646 return 1;
2647 bio_put(bi);
2648
2649 mddev = raid_bi->bi_bdev->bd_disk->queue->queuedata;
2650 conf = mddev_to_conf(mddev);
2651 rdev = (void*)raid_bi->bi_next;
2652 raid_bi->bi_next = NULL;
2653
2654 rdev_dec_pending(rdev, conf->mddev);
2655
2656 if (!error && uptodate) {
2657 bio_endio(raid_bi, bytes, 0);
2658 if (atomic_dec_and_test(&conf->active_aligned_reads))
2659 wake_up(&conf->wait_for_stripe);
2660 return 0;
2661 }
2662
2663
2664 PRINTK("raid5_align_endio : io error...handing IO for a retry\n");
2665
2666 add_bio_to_retry(raid_bi, conf);
2667 return 0;
2668}
2669
2670static int chunk_aligned_read(request_queue_t *q, struct bio * raid_bio)
2671{
2672 mddev_t *mddev = q->queuedata;
2673 raid5_conf_t *conf = mddev_to_conf(mddev);
2674 const unsigned int raid_disks = conf->raid_disks;
2675 const unsigned int data_disks = raid_disks - conf->max_degraded;
2676 unsigned int dd_idx, pd_idx;
2677 struct bio* align_bi;
2678 mdk_rdev_t *rdev;
2679
2680 if (!in_chunk_boundary(mddev, raid_bio)) {
2681 printk("chunk_aligned_read : non aligned\n");
2682 return 0;
2683 }
2684 /*
2685 * use bio_clone to make a copy of the bio
2686 */
2687 align_bi = bio_clone(raid_bio, GFP_NOIO);
2688 if (!align_bi)
2689 return 0;
2690 /*
2691 * set bi_end_io to a new function, and set bi_private to the
2692 * original bio.
2693 */
2694 align_bi->bi_end_io = raid5_align_endio;
2695 align_bi->bi_private = raid_bio;
2696 /*
2697 * compute position
2698 */
2699 align_bi->bi_sector = raid5_compute_sector(raid_bio->bi_sector,
2700 raid_disks,
2701 data_disks,
2702 &dd_idx,
2703 &pd_idx,
2704 conf);
2705
2706 rcu_read_lock();
2707 rdev = rcu_dereference(conf->disks[dd_idx].rdev);
2708 if (rdev && test_bit(In_sync, &rdev->flags)) {
2709 atomic_inc(&rdev->nr_pending);
2710 rcu_read_unlock();
2711 raid_bio->bi_next = (void*)rdev;
2712 align_bi->bi_bdev = rdev->bdev;
2713 align_bi->bi_flags &= ~(1 << BIO_SEG_VALID);
2714 align_bi->bi_sector += rdev->data_offset;
2715
2716 spin_lock_irq(&conf->device_lock);
2717 wait_event_lock_irq(conf->wait_for_stripe,
2718 conf->quiesce == 0,
2719 conf->device_lock, /* nothing */);
2720 atomic_inc(&conf->active_aligned_reads);
2721 spin_unlock_irq(&conf->device_lock);
2722
2723 generic_make_request(align_bi);
2724 return 1;
2725 } else {
2726 rcu_read_unlock();
2727 bio_put(align_bi);
2728 return 0;
2729 }
2730}
2731
2732
2614static int make_request(request_queue_t *q, struct bio * bi) 2733static int make_request(request_queue_t *q, struct bio * bi)
2615{ 2734{
2616 mddev_t *mddev = q->queuedata; 2735 mddev_t *mddev = q->queuedata;
@@ -2632,6 +2751,11 @@ static int make_request(request_queue_t *q, struct bio * bi)
2632 disk_stat_inc(mddev->gendisk, ios[rw]); 2751 disk_stat_inc(mddev->gendisk, ios[rw]);
2633 disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi)); 2752 disk_stat_add(mddev->gendisk, sectors[rw], bio_sectors(bi));
2634 2753
2754 if (bio_data_dir(bi) == READ &&
2755 mddev->reshape_position == MaxSector &&
2756 chunk_aligned_read(q,bi))
2757 return 0;
2758
2635 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); 2759 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
2636 last_sector = bi->bi_sector + (bi->bi_size>>9); 2760 last_sector = bi->bi_sector + (bi->bi_size>>9);
2637 bi->bi_next = NULL; 2761 bi->bi_next = NULL;
@@ -2739,7 +2863,9 @@ static int make_request(request_queue_t *q, struct bio * bi)
2739 if ( rw == WRITE ) 2863 if ( rw == WRITE )
2740 md_write_end(mddev); 2864 md_write_end(mddev);
2741 bi->bi_size = 0; 2865 bi->bi_size = 0;
2742 bi->bi_end_io(bi, bytes, 0); 2866 bi->bi_end_io(bi, bytes,
2867 test_bit(BIO_UPTODATE, &bi->bi_flags)
2868 ? 0 : -EIO);
2743 } 2869 }
2744 return 0; 2870 return 0;
2745} 2871}
@@ -2950,6 +3076,74 @@ static inline sector_t sync_request(mddev_t *mddev, sector_t sector_nr, int *ski
2950 return STRIPE_SECTORS; 3076 return STRIPE_SECTORS;
2951} 3077}
2952 3078
3079static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
3080{
3081 /* We may not be able to submit a whole bio at once as there
3082 * may not be enough stripe_heads available.
3083 * We cannot pre-allocate enough stripe_heads as we may need
3084 * more than exist in the cache (if we allow ever large chunks).
3085 * So we do one stripe head at a time and record in
3086 * ->bi_hw_segments how many have been done.
3087 *
3088 * We *know* that this entire raid_bio is in one chunk, so
3089 * it will be only one 'dd_idx' and only need one call to raid5_compute_sector.
3090 */
3091 struct stripe_head *sh;
3092 int dd_idx, pd_idx;
3093 sector_t sector, logical_sector, last_sector;
3094 int scnt = 0;
3095 int remaining;
3096 int handled = 0;
3097
3098 logical_sector = raid_bio->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
3099 sector = raid5_compute_sector( logical_sector,
3100 conf->raid_disks,
3101 conf->raid_disks - conf->max_degraded,
3102 &dd_idx,
3103 &pd_idx,
3104 conf);
3105 last_sector = raid_bio->bi_sector + (raid_bio->bi_size>>9);
3106
3107 for (; logical_sector < last_sector;
3108 logical_sector += STRIPE_SECTORS, scnt++) {
3109
3110 if (scnt < raid_bio->bi_hw_segments)
3111 /* already done this stripe */
3112 continue;
3113
3114 sh = get_active_stripe(conf, sector, conf->raid_disks, pd_idx, 1);
3115
3116 if (!sh) {
3117 /* failed to get a stripe - must wait */
3118 raid_bio->bi_hw_segments = scnt;
3119 conf->retry_read_aligned = raid_bio;
3120 return handled;
3121 }
3122
3123 set_bit(R5_ReadError, &sh->dev[dd_idx].flags);
3124 add_stripe_bio(sh, raid_bio, dd_idx, 0);
3125 handle_stripe(sh, NULL);
3126 release_stripe(sh);
3127 handled++;
3128 }
3129 spin_lock_irq(&conf->device_lock);
3130 remaining = --raid_bio->bi_phys_segments;
3131 spin_unlock_irq(&conf->device_lock);
3132 if (remaining == 0) {
3133 int bytes = raid_bio->bi_size;
3134
3135 raid_bio->bi_size = 0;
3136 raid_bio->bi_end_io(raid_bio, bytes,
3137 test_bit(BIO_UPTODATE, &raid_bio->bi_flags)
3138 ? 0 : -EIO);
3139 }
3140 if (atomic_dec_and_test(&conf->active_aligned_reads))
3141 wake_up(&conf->wait_for_stripe);
3142 return handled;
3143}
3144
3145
3146
2953/* 3147/*
2954 * This is our raid5 kernel thread. 3148 * This is our raid5 kernel thread.
2955 * 3149 *
@@ -2971,6 +3165,7 @@ static void raid5d (mddev_t *mddev)
2971 spin_lock_irq(&conf->device_lock); 3165 spin_lock_irq(&conf->device_lock);
2972 while (1) { 3166 while (1) {
2973 struct list_head *first; 3167 struct list_head *first;
3168 struct bio *bio;
2974 3169
2975 if (conf->seq_flush != conf->seq_write) { 3170 if (conf->seq_flush != conf->seq_write) {
2976 int seq = conf->seq_flush; 3171 int seq = conf->seq_flush;
@@ -2987,6 +3182,16 @@ static void raid5d (mddev_t *mddev)
2987 !list_empty(&conf->delayed_list)) 3182 !list_empty(&conf->delayed_list))
2988 raid5_activate_delayed(conf); 3183 raid5_activate_delayed(conf);
2989 3184
3185 while ((bio = remove_bio_from_retry(conf))) {
3186 int ok;
3187 spin_unlock_irq(&conf->device_lock);
3188 ok = retry_aligned_read(conf, bio);
3189 spin_lock_irq(&conf->device_lock);
3190 if (!ok)
3191 break;
3192 handled++;
3193 }
3194
2990 if (list_empty(&conf->handle_list)) 3195 if (list_empty(&conf->handle_list))
2991 break; 3196 break;
2992 3197
@@ -3174,6 +3379,7 @@ static int run(mddev_t *mddev)
3174 INIT_LIST_HEAD(&conf->inactive_list); 3379 INIT_LIST_HEAD(&conf->inactive_list);
3175 atomic_set(&conf->active_stripes, 0); 3380 atomic_set(&conf->active_stripes, 0);
3176 atomic_set(&conf->preread_active_stripes, 0); 3381 atomic_set(&conf->preread_active_stripes, 0);
3382 atomic_set(&conf->active_aligned_reads, 0);
3177 3383
3178 PRINTK("raid5: run(%s) called.\n", mdname(mddev)); 3384 PRINTK("raid5: run(%s) called.\n", mdname(mddev));
3179 3385
@@ -3320,6 +3526,8 @@ static int run(mddev_t *mddev)
3320 mddev->array_size = mddev->size * (conf->previous_raid_disks - 3526 mddev->array_size = mddev->size * (conf->previous_raid_disks -
3321 conf->max_degraded); 3527 conf->max_degraded);
3322 3528
3529 blk_queue_merge_bvec(mddev->queue, raid5_mergeable_bvec);
3530
3323 return 0; 3531 return 0;
3324abort: 3532abort:
3325 if (conf) { 3533 if (conf) {
@@ -3694,7 +3902,8 @@ static void raid5_quiesce(mddev_t *mddev, int state)
3694 spin_lock_irq(&conf->device_lock); 3902 spin_lock_irq(&conf->device_lock);
3695 conf->quiesce = 1; 3903 conf->quiesce = 1;
3696 wait_event_lock_irq(conf->wait_for_stripe, 3904 wait_event_lock_irq(conf->wait_for_stripe,
3697 atomic_read(&conf->active_stripes) == 0, 3905 atomic_read(&conf->active_stripes) == 0 &&
3906 atomic_read(&conf->active_aligned_reads) == 0,
3698 conf->device_lock, /* nothing */); 3907 conf->device_lock, /* nothing */);
3699 spin_unlock_irq(&conf->device_lock); 3908 spin_unlock_irq(&conf->device_lock);
3700 break; 3909 break;
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 9f7e1fe8c97e..87410dbd3df4 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -67,6 +67,7 @@ source "drivers/media/common/Kconfig"
67 67
68config VIDEO_TUNER 68config VIDEO_TUNER
69 tristate 69 tristate
70 depends on I2C
70 71
71config VIDEO_BUF 72config VIDEO_BUF
72 tristate 73 tristate
@@ -82,6 +83,7 @@ config VIDEO_IR
82 83
83config VIDEO_TVEEPROM 84config VIDEO_TVEEPROM
84 tristate 85 tristate
86 depends on I2C
85 87
86config USB_DABUSB 88config USB_DABUSB
87 tristate "DABUSB driver" 89 tristate "DABUSB driver"
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index db753443587a..f51e02fe3655 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -1552,3 +1552,58 @@ IR_KEYTAB_TYPE ir_codes_norwood[IR_KEYTAB_SIZE] = {
1552}; 1552};
1553 1553
1554EXPORT_SYMBOL_GPL(ir_codes_norwood); 1554EXPORT_SYMBOL_GPL(ir_codes_norwood);
1555
1556/* From reading the following remotes:
1557 * Zenith Universal 7 / TV Mode 807 / VCR Mode 837
1558 * Hauppauge (from NOVA-CI-s box product)
1559 * This is a "middle of the road" approach, differences are noted
1560 */
1561IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE] = {
1562 [ 0x00 ] = KEY_0,
1563 [ 0x01 ] = KEY_1,
1564 [ 0x02 ] = KEY_2,
1565 [ 0x03 ] = KEY_3,
1566 [ 0x04 ] = KEY_4,
1567 [ 0x05 ] = KEY_5,
1568 [ 0x06 ] = KEY_6,
1569 [ 0x07 ] = KEY_7,
1570 [ 0x08 ] = KEY_8,
1571 [ 0x09 ] = KEY_9,
1572 [ 0x0a ] = KEY_ENTER,
1573 [ 0x0b ] = KEY_RED,
1574 [ 0x0c ] = KEY_POWER, /* RADIO on Hauppauge */
1575 [ 0x0d ] = KEY_MUTE,
1576 [ 0x0f ] = KEY_A, /* TV on Hauppauge */
1577 [ 0x10 ] = KEY_VOLUMEUP,
1578 [ 0x11 ] = KEY_VOLUMEDOWN,
1579 [ 0x14 ] = KEY_B,
1580 [ 0x1c ] = KEY_UP,
1581 [ 0x1d ] = KEY_DOWN,
1582 [ 0x1e ] = KEY_OPTION, /* RESERVED on Hauppauge */
1583 [ 0x1f ] = KEY_BREAK,
1584 [ 0x20 ] = KEY_CHANNELUP,
1585 [ 0x21 ] = KEY_CHANNELDOWN,
1586 [ 0x22 ] = KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
1587 [ 0x24 ] = KEY_RESTART,
1588 [ 0x25 ] = KEY_OK,
1589 [ 0x26 ] = KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
1590 [ 0x28 ] = KEY_ENTER, /* VCR mode on Zenith */
1591 [ 0x29 ] = KEY_PAUSE,
1592 [ 0x2b ] = KEY_RIGHT,
1593 [ 0x2c ] = KEY_LEFT,
1594 [ 0x2e ] = KEY_MENU, /* FULL SCREEN on Hauppauge */
1595 [ 0x30 ] = KEY_SLOW,
1596 [ 0x31 ] = KEY_PREVIOUS, /* VCR mode on Zenith */
1597 [ 0x32 ] = KEY_REWIND,
1598 [ 0x34 ] = KEY_FASTFORWARD,
1599 [ 0x35 ] = KEY_PLAY,
1600 [ 0x36 ] = KEY_STOP,
1601 [ 0x37 ] = KEY_RECORD,
1602 [ 0x38 ] = KEY_TUNER, /* TV/VCR on Zenith */
1603 [ 0x3a ] = KEY_C,
1604 [ 0x3c ] = KEY_EXIT,
1605 [ 0x3d ] = KEY_POWER2,
1606 [ 0x3e ] = KEY_TUNER,
1607};
1608
1609EXPORT_SYMBOL_GPL(ir_codes_budget_ci_old);
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 5297a365c928..8c85efc26527 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -189,13 +189,21 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
189 saa7146_write(dev, I2C_TRANSFER, *dword); 189 saa7146_write(dev, I2C_TRANSFER, *dword);
190 190
191 dev->i2c_op = 1; 191 dev->i2c_op = 1;
192 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17);
192 SAA7146_IER_ENABLE(dev, MASK_16|MASK_17); 193 SAA7146_IER_ENABLE(dev, MASK_16|MASK_17);
193 saa7146_write(dev, MC2, (MASK_00 | MASK_16)); 194 saa7146_write(dev, MC2, (MASK_00 | MASK_16));
194 195
195 wait_event_interruptible(dev->i2c_wq, dev->i2c_op == 0); 196 timeout = HZ/100 + 1; /* 10ms */
196 if (signal_pending (current)) { 197 timeout = wait_event_interruptible_timeout(dev->i2c_wq, dev->i2c_op == 0, timeout);
197 /* a signal arrived */ 198 if (timeout == -ERESTARTSYS || dev->i2c_op) {
198 return -ERESTARTSYS; 199 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
200 SAA7146_ISR_CLEAR(dev, MASK_16|MASK_17);
201 if (timeout == -ERESTARTSYS)
202 /* a signal arrived */
203 return -ERESTARTSYS;
204
205 printk(KERN_WARNING "saa7146_i2c_writeout: timed out waiting for end of xfer\n");
206 return -EIO;
199 } 207 }
200 status = saa7146_read(dev, I2C_STATUS); 208 status = saa7146_read(dev, I2C_STATUS);
201 } else { 209 } else {
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index a0dcd59da76e..79875958930e 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -9,6 +9,7 @@ config DVB_B2C2_FLEXCOP
9 select DVB_STV0297 if !DVB_FE_CUSTOMISE 9 select DVB_STV0297 if !DVB_FE_CUSTOMISE
10 select DVB_BCM3510 if !DVB_FE_CUSTOMISE 10 select DVB_BCM3510 if !DVB_FE_CUSTOMISE
11 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 11 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
12 select DVB_TUNER_LGH06XF if !DVB_FE_CUSTOMISE
12 help 13 help
13 Support for the digital TV receiver chip made by B2C2 Inc. included in 14 Support for the digital TV receiver chip made by B2C2 Inc. included in
14 Technisats PCI cards and USB boxes. 15 Technisats PCI cards and USB boxes.
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index b8ba87863457..c2b35e366242 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -14,7 +14,7 @@
14#include "stv0297.h" 14#include "stv0297.h"
15#include "mt312.h" 15#include "mt312.h"
16#include "lgdt330x.h" 16#include "lgdt330x.h"
17#include "lg_h06xf.h" 17#include "lgh06xf.h"
18#include "dvb-pll.h" 18#include "dvb-pll.h"
19 19
20/* lnb control */ 20/* lnb control */
@@ -303,12 +303,6 @@ static int flexcop_fe_request_firmware(struct dvb_frontend* fe, const struct fir
303 return request_firmware(fw, name, fc->dev); 303 return request_firmware(fw, name, fc->dev);
304} 304}
305 305
306static int lgdt3303_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters *params)
307{
308 struct flexcop_device *fc = fe->dvb->priv;
309 return lg_h06xf_pll_set(fe, &fc->i2c_adap, params);
310}
311
312static struct lgdt330x_config air2pc_atsc_hd5000_config = { 306static struct lgdt330x_config air2pc_atsc_hd5000_config = {
313 .demod_address = 0x59, 307 .demod_address = 0x59,
314 .demod_chip = LGDT3303, 308 .demod_chip = LGDT3303,
@@ -533,7 +527,7 @@ int flexcop_frontend_init(struct flexcop_device *fc)
533 /* try the air atsc 3nd generation (lgdt3303) */ 527 /* try the air atsc 3nd generation (lgdt3303) */
534 if ((fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, &fc->i2c_adap)) != NULL) { 528 if ((fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, &fc->i2c_adap)) != NULL) {
535 fc->dev_type = FC_AIR_ATSC3; 529 fc->dev_type = FC_AIR_ATSC3;
536 fc->fe->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 530 dvb_attach(lgh06xf_attach, fc->fe, &fc->i2c_adap);
537 info("found the lgdt3303 at i2c address: 0x%02x",air2pc_atsc_hd5000_config.demod_address); 531 info("found the lgdt3303 at i2c address: 0x%02x",air2pc_atsc_hd5000_config.demod_address);
538 } else 532 } else
539 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */ 533 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index ae2ff5dc238d..dd66b60fbc98 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -1,13 +1,13 @@
1config DVB_BT8XX 1config DVB_BT8XX
2 tristate "BT8xx based PCI cards" 2 tristate "BT8xx based PCI cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848 3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848
4 select DVB_PLL
5 select DVB_MT352 if !DVB_FE_CUSTOMISE 4 select DVB_MT352 if !DVB_FE_CUSTOMISE
6 select DVB_SP887X if !DVB_FE_CUSTOMISE 5 select DVB_SP887X if !DVB_FE_CUSTOMISE
7 select DVB_NXT6000 if !DVB_FE_CUSTOMISE 6 select DVB_NXT6000 if !DVB_FE_CUSTOMISE
8 select DVB_CX24110 if !DVB_FE_CUSTOMISE 7 select DVB_CX24110 if !DVB_FE_CUSTOMISE
9 select DVB_OR51211 if !DVB_FE_CUSTOMISE 8 select DVB_OR51211 if !DVB_FE_CUSTOMISE
10 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
10 select DVB_TUNER_LGH06XF if !DVB_FE_CUSTOMISE
11 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 11 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
12 select FW_LOADER 12 select FW_LOADER
13 help 13 help
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 14e69a736eda..80a85cb4975f 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -34,7 +34,6 @@
34#include "dvb_frontend.h" 34#include "dvb_frontend.h"
35#include "dvb-bt8xx.h" 35#include "dvb-bt8xx.h"
36#include "bt878.h" 36#include "bt878.h"
37#include "dvb-pll.h"
38 37
39static int debug; 38static int debug;
40 39
@@ -568,12 +567,6 @@ static struct mt352_config digitv_alps_tded4_config = {
568 .demod_init = digitv_alps_tded4_demod_init, 567 .demod_init = digitv_alps_tded4_demod_init,
569}; 568};
570 569
571static int tdvs_tua6034_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
572{
573 struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv;
574 return lg_h06xf_pll_set(fe, card->i2c_adapter, params);
575}
576
577static struct lgdt330x_config tdvs_tua6034_config = { 570static struct lgdt330x_config tdvs_tua6034_config = {
578 .demod_address = 0x0e, 571 .demod_address = 0x0e,
579 .demod_chip = LGDT3303, 572 .demod_chip = LGDT3303,
@@ -616,7 +609,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
616 lgdt330x_reset(card); 609 lgdt330x_reset(card);
617 card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter); 610 card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter);
618 if (card->fe != NULL) { 611 if (card->fe != NULL) {
619 card->fe->ops.tuner_ops.set_params = tdvs_tua6034_tuner_set_params; 612 dvb_attach(lgh06xf_attach, card->fe, card->i2c_adapter);
620 dprintk ("dvb_bt8xx: lgdt330x detected\n"); 613 dprintk ("dvb_bt8xx: lgdt330x detected\n");
621 } 614 }
622 break; 615 break;
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
index 4745a9017a19..e75f4173c059 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.h
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
@@ -37,7 +37,7 @@
37#include "cx24110.h" 37#include "cx24110.h"
38#include "or51211.h" 38#include "or51211.h"
39#include "lgdt330x.h" 39#include "lgdt330x.h"
40#include "lg_h06xf.h" 40#include "lgh06xf.h"
41#include "zl10353.h" 41#include "zl10353.h"
42 42
43struct dvb_bt8xx_card { 43struct dvb_bt8xx_card {
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 9123147e376f..d64b96cb0c46 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -746,6 +746,7 @@ static void cinergyt2_query_rc (struct work_struct *work)
746 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event); 746 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
747 input_report_key(cinergyt2->rc_input_dev, 747 input_report_key(cinergyt2->rc_input_dev,
748 cinergyt2->rc_input_event, 0); 748 cinergyt2->rc_input_event, 0);
749 input_sync(cinergyt2->rc_input_dev);
749 cinergyt2->rc_input_event = KEY_MAX; 750 cinergyt2->rc_input_event = KEY_MAX;
750 } 751 }
751 cinergyt2->rc_last_code = ~0; 752 cinergyt2->rc_last_code = ~0;
@@ -783,6 +784,7 @@ static void cinergyt2_query_rc (struct work_struct *work)
783 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event); 784 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
784 input_report_key(cinergyt2->rc_input_dev, 785 input_report_key(cinergyt2->rc_input_dev,
785 cinergyt2->rc_input_event, 1); 786 cinergyt2->rc_input_event, 1);
787 input_sync(cinergyt2->rc_input_dev);
786 cinergyt2->rc_last_code = rc_events[n].value; 788 cinergyt2->rc_last_code = rc_events[n].value;
787 } 789 }
788 } 790 }
@@ -798,8 +800,9 @@ static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
798{ 800{
799 struct input_dev *input_dev; 801 struct input_dev *input_dev;
800 int i; 802 int i;
803 int err;
801 804
802 cinergyt2->rc_input_dev = input_dev = input_allocate_device(); 805 input_dev = input_allocate_device();
803 if (!input_dev) 806 if (!input_dev)
804 return -ENOMEM; 807 return -ENOMEM;
805 808
@@ -817,7 +820,13 @@ static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
817 input_dev->keycodesize = 0; 820 input_dev->keycodesize = 0;
818 input_dev->keycodemax = 0; 821 input_dev->keycodemax = 0;
819 822
820 input_register_device(cinergyt2->rc_input_dev); 823 err = input_register_device(input_dev);
824 if (err) {
825 input_free_device(input_dev);
826 return err;
827 }
828
829 cinergyt2->rc_input_dev = input_dev;
821 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2); 830 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
822 831
823 return 0; 832 return 0;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index a263b3f3c21d..ad52143602cd 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -69,6 +69,8 @@ config DVB_USB_DIBUSB_MC
69config DVB_USB_DIB0700 69config DVB_USB_DIB0700
70 tristate "DiBcom DiB0700 USB DVB devices (see help for supported devices)" 70 tristate "DiBcom DiB0700 USB DVB devices (see help for supported devices)"
71 depends on DVB_USB 71 depends on DVB_USB
72 select DVB_DIB7000P
73 select DVB_DIB7000M
72 select DVB_DIB3000MC 74 select DVB_DIB3000MC
73 select DVB_TUNER_MT2060 if !DVB_FE_CUSTOMISE 75 select DVB_TUNER_MT2060 if !DVB_FE_CUSTOMISE
74 help 76 help
@@ -96,6 +98,7 @@ config DVB_USB_CXUSB
96 depends on DVB_USB 98 depends on DVB_USB
97 select DVB_CX22702 if !DVB_FE_CUSTOMISE 99 select DVB_CX22702 if !DVB_FE_CUSTOMISE
98 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 100 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
101 select DVB_TUNER_LGH06XF if !DVB_FE_CUSTOMISE
99 select DVB_MT352 if !DVB_FE_CUSTOMISE 102 select DVB_MT352 if !DVB_FE_CUSTOMISE
100 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 103 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
101 help 104 help
@@ -157,6 +160,17 @@ config DVB_USB_NOVA_T_USB2
157 help 160 help
158 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver. 161 Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver.
159 162
163config DVB_USB_TTUSB2
164 tristate "Pinnacle 400e DVB-S USB2.0 support"
165 depends on DVB_USB
166 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
167 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
168 select DVB_TDA826X if !DVB_FE_CUSTOMISE
169 help
170 Say Y here to support the Pinnacle 400e DVB-S USB2.0 receiver. The
171 firmware protocol used by this module is similar to the one used by the
172 old ttusb-driver - that's why the module is called dvb-usb-ttusb2.ko.
173
160config DVB_USB_DTT200U 174config DVB_USB_DTT200U
161 tristate "WideView WT-200U and WT-220U (pen) DVB-T USB2.0 support (Yakumo/Hama/Typhoon/Yuan)" 175 tristate "WideView WT-200U and WT-220U (pen) DVB-T USB2.0 support (Yakumo/Hama/Typhoon/Yuan)"
162 depends on DVB_USB 176 depends on DVB_USB
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index e239107998e5..154d593bbb02 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -36,6 +36,9 @@ obj-$(CONFIG_DVB_USB_DIGITV) += dvb-usb-digitv.o
36dvb-usb-cxusb-objs = cxusb.o 36dvb-usb-cxusb-objs = cxusb.o
37obj-$(CONFIG_DVB_USB_CXUSB) += dvb-usb-cxusb.o 37obj-$(CONFIG_DVB_USB_CXUSB) += dvb-usb-cxusb.o
38 38
39dvb-usb-ttusb2-objs = ttusb2.o
40obj-$(CONFIG_DVB_USB_TTUSB2) += dvb-usb-ttusb2.o
41
39dvb-usb-dib0700-objs = dib0700_core.o dib0700_devices.o 42dvb-usb-dib0700-objs = dib0700_core.o dib0700_devices.o
40obj-$(CONFIG_DVB_USB_DIB0700) += dvb-usb-dib0700.o 43obj-$(CONFIG_DVB_USB_DIB0700) += dvb-usb-dib0700.o
41 44
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index 2ed3eb62d787..a6c5f19f680d 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -116,24 +116,24 @@ static struct dvb_usb_device_properties a800_properties = {
116 { 116 {
117 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 117 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
118 .pid_filter_count = 32, 118 .pid_filter_count = 32,
119 .streaming_ctrl = dibusb2_0_streaming_ctrl, 119 .streaming_ctrl = dibusb2_0_streaming_ctrl,
120 .pid_filter = dibusb_pid_filter, 120 .pid_filter = dibusb_pid_filter,
121 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 121 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
122 122
123 .frontend_attach = dibusb_dib3000mc_frontend_attach, 123 .frontend_attach = dibusb_dib3000mc_frontend_attach,
124 .tuner_attach = dibusb_dib3000mc_tuner_attach, 124 .tuner_attach = dibusb_dib3000mc_tuner_attach,
125 125
126 /* parameter for the MPEG2-data transfer */ 126 /* parameter for the MPEG2-data transfer */
127 .stream = { 127 .stream = {
128 .type = USB_BULK, 128 .type = USB_BULK,
129 .count = 7, 129 .count = 7,
130 .endpoint = 0x06, 130 .endpoint = 0x06,
131 .u = { 131 .u = {
132 .bulk = { 132 .bulk = {
133 .buffersize = 4096, 133 .buffersize = 4096,
134 } 134 }
135 } 135 }
136 }, 136 },
137 137
138 .size_of_priv = sizeof(struct dibusb_state), 138 .size_of_priv = sizeof(struct dibusb_state),
139 }, 139 },
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 43f39069ef34..15d12fce34df 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -14,12 +14,12 @@
14 * TODO: Use the cx25840-driver for the analogue part 14 * TODO: Use the cx25840-driver for the analogue part
15 * 15 *
16 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de) 16 * Copyright (C) 2005 Patrick Boettcher (patrick.boettcher@desy.de)
17 * Copyright (C) 2005 Michael Krufky (mkrufky@m1k.net) 17 * Copyright (C) 2006 Michael Krufky (mkrufky@linuxtv.org)
18 * Copyright (C) 2006 Chris Pascoe (c.pascoe@itee.uq.edu.au) 18 * Copyright (C) 2006 Chris Pascoe (c.pascoe@itee.uq.edu.au)
19 * 19 *
20 * This program is free software; you can redistribute it and/or modify it 20 * This program is free software; you can redistribute it and/or modify it
21 * under the terms of the GNU General Public License as published by the Free 21 * under the terms of the GNU General Public License as published by the Free
22 * Software Foundation, version 2. 22 * Software Foundation, version 2.
23 * 23 *
24 * see Documentation/dvb/README.dvb-usb for more information 24 * see Documentation/dvb/README.dvb-usb for more information
25 */ 25 */
@@ -27,29 +27,29 @@
27 27
28#include "cx22702.h" 28#include "cx22702.h"
29#include "lgdt330x.h" 29#include "lgdt330x.h"
30#include "lg_h06xf.h" 30#include "lgh06xf.h"
31#include "mt352.h" 31#include "mt352.h"
32#include "mt352_priv.h" 32#include "mt352_priv.h"
33#include "zl10353.h" 33#include "zl10353.h"
34 34
35/* debug */ 35/* debug */
36int dvb_usb_cxusb_debug; 36int dvb_usb_cxusb_debug;
37module_param_named(debug,dvb_usb_cxusb_debug, int, 0644); 37module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 38MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
39 39
40static int cxusb_ctrl_msg(struct dvb_usb_device *d, 40static int cxusb_ctrl_msg(struct dvb_usb_device *d,
41 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen) 41 u8 cmd, u8 *wbuf, int wlen, u8 *rbuf, int rlen)
42{ 42{
43 int wo = (rbuf == NULL || rlen == 0); /* write-only */ 43 int wo = (rbuf == NULL || rlen == 0); /* write-only */
44 u8 sndbuf[1+wlen]; 44 u8 sndbuf[1+wlen];
45 memset(sndbuf,0,1+wlen); 45 memset(sndbuf, 0, 1+wlen);
46 46
47 sndbuf[0] = cmd; 47 sndbuf[0] = cmd;
48 memcpy(&sndbuf[1],wbuf,wlen); 48 memcpy(&sndbuf[1], wbuf, wlen);
49 if (wo) 49 if (wo)
50 dvb_usb_generic_write(d,sndbuf,1+wlen); 50 dvb_usb_generic_write(d, sndbuf, 1+wlen);
51 else 51 else
52 dvb_usb_generic_rw(d,sndbuf,1+wlen,rbuf,rlen,0); 52 dvb_usb_generic_rw(d, sndbuf, 1+wlen, rbuf, rlen, 0);
53 53
54 return 0; 54 return 0;
55} 55}
@@ -58,14 +58,14 @@ static int cxusb_ctrl_msg(struct dvb_usb_device *d,
58static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff) 58static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
59{ 59{
60 struct cxusb_state *st = d->priv; 60 struct cxusb_state *st = d->priv;
61 u8 o[2],i; 61 u8 o[2], i;
62 62
63 if (st->gpio_write_state[GPIO_TUNER] == onoff) 63 if (st->gpio_write_state[GPIO_TUNER] == onoff)
64 return; 64 return;
65 65
66 o[0] = GPIO_TUNER; 66 o[0] = GPIO_TUNER;
67 o[1] = onoff; 67 o[1] = onoff;
68 cxusb_ctrl_msg(d,CMD_GPIO_WRITE,o,2,&i,1); 68 cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
69 69
70 if (i != 0x01) 70 if (i != 0x01)
71 deb_info("gpio_write failed.\n"); 71 deb_info("gpio_write failed.\n");
@@ -74,7 +74,8 @@ static void cxusb_gpio_tuner(struct dvb_usb_device *d, int onoff)
74} 74}
75 75
76/* I2C */ 76/* I2C */
77static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num) 77static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
78 int num)
78{ 79{
79 struct dvb_usb_device *d = i2c_get_adapdata(adap); 80 struct dvb_usb_device *d = i2c_get_adapdata(adap);
80 int i; 81 int i;
@@ -89,12 +90,12 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
89 90
90 if (d->udev->descriptor.idVendor == USB_VID_MEDION) 91 if (d->udev->descriptor.idVendor == USB_VID_MEDION)
91 switch (msg[i].addr) { 92 switch (msg[i].addr) {
92 case 0x63: 93 case 0x63:
93 cxusb_gpio_tuner(d,0); 94 cxusb_gpio_tuner(d, 0);
94 break; 95 break;
95 default: 96 default:
96 cxusb_gpio_tuner(d,1); 97 cxusb_gpio_tuner(d, 1);
97 break; 98 break;
98 } 99 }
99 100
100 /* read request */ 101 /* read request */
@@ -103,26 +104,27 @@ static int cxusb_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
103 obuf[0] = msg[i].len; 104 obuf[0] = msg[i].len;
104 obuf[1] = msg[i+1].len; 105 obuf[1] = msg[i+1].len;
105 obuf[2] = msg[i].addr; 106 obuf[2] = msg[i].addr;
106 memcpy(&obuf[3],msg[i].buf,msg[i].len); 107 memcpy(&obuf[3], msg[i].buf, msg[i].len);
107 108
108 if (cxusb_ctrl_msg(d, CMD_I2C_READ, 109 if (cxusb_ctrl_msg(d, CMD_I2C_READ,
109 obuf, 3+msg[i].len, 110 obuf, 3+msg[i].len,
110 ibuf, 1+msg[i+1].len) < 0) 111 ibuf, 1+msg[i+1].len) < 0)
111 break; 112 break;
112 113
113 if (ibuf[0] != 0x08) 114 if (ibuf[0] != 0x08)
114 deb_i2c("i2c read may have failed\n"); 115 deb_i2c("i2c read may have failed\n");
115 116
116 memcpy(msg[i+1].buf,&ibuf[1],msg[i+1].len); 117 memcpy(msg[i+1].buf, &ibuf[1], msg[i+1].len);
117 118
118 i++; 119 i++;
119 } else { /* write */ 120 } else { /* write */
120 u8 obuf[2+msg[i].len], ibuf; 121 u8 obuf[2+msg[i].len], ibuf;
121 obuf[0] = msg[i].addr; 122 obuf[0] = msg[i].addr;
122 obuf[1] = msg[i].len; 123 obuf[1] = msg[i].len;
123 memcpy(&obuf[2],msg[i].buf,msg[i].len); 124 memcpy(&obuf[2], msg[i].buf, msg[i].len);
124 125
125 if (cxusb_ctrl_msg(d,CMD_I2C_WRITE, obuf, 2+msg[i].len, &ibuf,1) < 0) 126 if (cxusb_ctrl_msg(d, CMD_I2C_WRITE, obuf,
127 2+msg[i].len, &ibuf,1) < 0)
126 break; 128 break;
127 if (ibuf != 0x08) 129 if (ibuf != 0x08)
128 deb_i2c("i2c write may have failed\n"); 130 deb_i2c("i2c write may have failed\n");
@@ -324,16 +326,8 @@ static int cxusb_mt352_demod_init(struct dvb_frontend* fe)
324 return 0; 326 return 0;
325} 327}
326 328
327static int cxusb_lgh064f_tuner_set_params(struct dvb_frontend *fe,
328 struct dvb_frontend_parameters *fep)
329{
330 struct dvb_usb_adapter *adap = fe->dvb->priv;
331 return lg_h06xf_pll_set(fe, &adap->dev->i2c_adap, fep);
332}
333
334static struct cx22702_config cxusb_cx22702_config = { 329static struct cx22702_config cxusb_cx22702_config = {
335 .demod_address = 0x63, 330 .demod_address = 0x63,
336
337 .output_mode = CX22702_PARALLEL_OUTPUT, 331 .output_mode = CX22702_PARALLEL_OUTPUT,
338}; 332};
339 333
@@ -374,31 +368,27 @@ static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
374 368
375static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap) 369static int cxusb_dee1601_tuner_attach(struct dvb_usb_adapter *adap)
376{ 370{
377 adap->pll_addr = 0x61; 371 dvb_attach(dvb_pll_attach, adap->fe, 0x61,
378 adap->pll_desc = &dvb_pll_thomson_dtt7579; 372 NULL, &dvb_pll_thomson_dtt7579);
379 adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
380 return 0; 373 return 0;
381} 374}
382 375
383static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap) 376static int cxusb_lgz201_tuner_attach(struct dvb_usb_adapter *adap)
384{ 377{
385 adap->pll_addr = 0x61; 378 dvb_attach(dvb_pll_attach, adap->fe, 0x61, NULL, &dvb_pll_lg_z201);
386 adap->pll_desc = &dvb_pll_lg_z201;
387 adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
388 return 0; 379 return 0;
389} 380}
390 381
391static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap) 382static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
392{ 383{
393 adap->pll_addr = 0x60; 384 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
394 adap->pll_desc = &dvb_pll_thomson_dtt7579; 385 NULL, &dvb_pll_thomson_dtt7579);
395 adap->fe->ops.tuner_ops.calc_regs = dvb_usb_tuner_calc_regs;
396 return 0; 386 return 0;
397} 387}
398 388
399static int cxusb_lgdt3303_tuner_attach(struct dvb_usb_adapter *adap) 389static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
400{ 390{
401 adap->fe->ops.tuner_ops.set_params = cxusb_lgh064f_tuner_set_params; 391 dvb_attach(lgh06xf_attach, adap->fe, &adap->dev->i2c_adap);
402 return 0; 392 return 0;
403} 393}
404 394
@@ -410,7 +400,8 @@ static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
410 400
411 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1); 401 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, &b, 1);
412 402
413 if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config, &adap->dev->i2c_adap)) != NULL) 403 if ((adap->fe = dvb_attach(cx22702_attach, &cxusb_cx22702_config,
404 &adap->dev->i2c_adap)) != NULL)
414 return 0; 405 return 0;
415 406
416 return -EIO; 407 return -EIO;
@@ -423,7 +414,8 @@ static int cxusb_lgdt3303_frontend_attach(struct dvb_usb_adapter *adap)
423 414
424 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); 415 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
425 416
426 if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config, &adap->dev->i2c_adap)) != NULL) 417 if ((adap->fe = dvb_attach(lgdt330x_attach, &cxusb_lgdt3303_config,
418 &adap->dev->i2c_adap)) != NULL)
427 return 0; 419 return 0;
428 420
429 return -EIO; 421 return -EIO;
@@ -437,7 +429,8 @@ static int cxusb_mt352_frontend_attach(struct dvb_usb_adapter *adap)
437 429
438 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); 430 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
439 431
440 if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config, &adap->dev->i2c_adap)) != NULL) 432 if ((adap->fe = dvb_attach(mt352_attach, &cxusb_mt352_config,
433 &adap->dev->i2c_adap)) != NULL)
441 return 0; 434 return 0;
442 435
443 return -EIO; 436 return -EIO;
@@ -450,8 +443,11 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
450 443
451 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0); 444 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
452 445
453 if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config, &adap->dev->i2c_adap)) != NULL) || 446 if (((adap->fe = dvb_attach(mt352_attach, &cxusb_dee1601_config,
454 ((adap->fe = dvb_attach(zl10353_attach, &cxusb_zl10353_dee1601_config, &adap->dev->i2c_adap)) != NULL)) 447 &adap->dev->i2c_adap)) != NULL) ||
448 ((adap->fe = dvb_attach(zl10353_attach,
449 &cxusb_zl10353_dee1601_config,
450 &adap->dev->i2c_adap)) != NULL))
455 return 0; 451 return 0;
456 452
457 return -EIO; 453 return -EIO;
@@ -463,7 +459,8 @@ static int cxusb_dee1601_frontend_attach(struct dvb_usb_adapter *adap)
463 */ 459 */
464 460
465#define BLUEBIRD_01_ID_OFFSET 6638 461#define BLUEBIRD_01_ID_OFFSET 6638
466static int bluebird_patch_dvico_firmware_download(struct usb_device *udev, const struct firmware *fw) 462static int bluebird_patch_dvico_firmware_download(struct usb_device *udev,
463 const struct firmware *fw)
467{ 464{
468 if (fw->size < BLUEBIRD_01_ID_OFFSET + 4) 465 if (fw->size < BLUEBIRD_01_ID_OFFSET + 4)
469 return -EINVAL; 466 return -EINVAL;
@@ -471,10 +468,12 @@ static int bluebird_patch_dvico_firmware_download(struct usb_device *udev, const
471 if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) && 468 if (fw->data[BLUEBIRD_01_ID_OFFSET] == (USB_VID_DVICO & 0xff) &&
472 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) { 469 fw->data[BLUEBIRD_01_ID_OFFSET + 1] == USB_VID_DVICO >> 8) {
473 470
474 fw->data[BLUEBIRD_01_ID_OFFSET + 2] = udev->descriptor.idProduct + 1; 471 fw->data[BLUEBIRD_01_ID_OFFSET + 2] =
475 fw->data[BLUEBIRD_01_ID_OFFSET + 3] = udev->descriptor.idProduct >> 8; 472 udev->descriptor.idProduct + 1;
473 fw->data[BLUEBIRD_01_ID_OFFSET + 3] =
474 udev->descriptor.idProduct >> 8;
476 475
477 return usb_cypress_load_firmware(udev,fw,CYPRESS_FX2); 476 return usb_cypress_load_firmware(udev, fw, CYPRESS_FX2);
478 } 477 }
479 478
480 return -EINVAL; 479 return -EINVAL;
@@ -488,7 +487,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
488static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties; 487static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
489 488
490static int cxusb_probe(struct usb_interface *intf, 489static int cxusb_probe(struct usb_interface *intf,
491 const struct usb_device_id *id) 490 const struct usb_device_id *id)
492{ 491{
493 if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 || 492 if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 ||
494 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 || 493 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 ||
@@ -502,20 +501,20 @@ static int cxusb_probe(struct usb_interface *intf,
502} 501}
503 502
504static struct usb_device_id cxusb_table [] = { 503static struct usb_device_id cxusb_table [] = {
505 { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) }, 504 { USB_DEVICE(USB_VID_MEDION, USB_PID_MEDION_MD95700) },
506 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) }, 505 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_COLD) },
507 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) }, 506 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LG064F_WARM) },
508 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD) }, 507 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_COLD) },
509 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM) }, 508 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM) },
510 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) }, 509 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_COLD) },
511 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) }, 510 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_LGZ201_WARM) },
512 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) }, 511 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_COLD) },
513 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) }, 512 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_TH7579_WARM) },
514 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD) }, 513 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD) },
515 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) }, 514 { USB_DEVICE(USB_VID_DVICO, USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM) },
516 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) }, 515 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD) },
517 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) }, 516 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM) },
518 {} /* Terminating entry */ 517 {} /* Terminating entry */
519}; 518};
520MODULE_DEVICE_TABLE (usb, cxusb_table); 519MODULE_DEVICE_TABLE (usb, cxusb_table);
521 520
@@ -529,20 +528,20 @@ static struct dvb_usb_device_properties cxusb_medion_properties = {
529 .num_adapters = 1, 528 .num_adapters = 1,
530 .adapter = { 529 .adapter = {
531 { 530 {
532 .streaming_ctrl = cxusb_streaming_ctrl, 531 .streaming_ctrl = cxusb_streaming_ctrl,
533 .frontend_attach = cxusb_cx22702_frontend_attach, 532 .frontend_attach = cxusb_cx22702_frontend_attach,
534 .tuner_attach = cxusb_fmd1216me_tuner_attach, 533 .tuner_attach = cxusb_fmd1216me_tuner_attach,
535 /* parameter for the MPEG2-data transfer */ 534 /* parameter for the MPEG2-data transfer */
536 .stream = { 535 .stream = {
537 .type = USB_BULK, 536 .type = USB_BULK,
538 .count = 5, 537 .count = 5,
539 .endpoint = 0x02, 538 .endpoint = 0x02,
540 .u = { 539 .u = {
541 .bulk = { 540 .bulk = {
542 .buffersize = 8192, 541 .buffersize = 8192,
543 } 542 }
544 } 543 }
545 }, 544 },
546 545
547 }, 546 },
548 }, 547 },
@@ -575,21 +574,21 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
575 .num_adapters = 1, 574 .num_adapters = 1,
576 .adapter = { 575 .adapter = {
577 { 576 {
578 .streaming_ctrl = cxusb_streaming_ctrl, 577 .streaming_ctrl = cxusb_streaming_ctrl,
579 .frontend_attach = cxusb_lgdt3303_frontend_attach, 578 .frontend_attach = cxusb_lgdt3303_frontend_attach,
580 .tuner_attach = cxusb_lgdt3303_tuner_attach, 579 .tuner_attach = cxusb_lgh064f_tuner_attach,
581 580
582 /* parameter for the MPEG2-data transfer */ 581 /* parameter for the MPEG2-data transfer */
583 .stream = { 582 .stream = {
584 .type = USB_BULK, 583 .type = USB_BULK,
585 .count = 5, 584 .count = 5,
586 .endpoint = 0x02, 585 .endpoint = 0x02,
587 .u = { 586 .u = {
588 .bulk = { 587 .bulk = {
589 .buffersize = 8192, 588 .buffersize = 8192,
590 } 589 }
591 } 590 }
592 }, 591 },
593 }, 592 },
594 }, 593 },
595 594
@@ -627,20 +626,20 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
627 .num_adapters = 1, 626 .num_adapters = 1,
628 .adapter = { 627 .adapter = {
629 { 628 {
630 .streaming_ctrl = cxusb_streaming_ctrl, 629 .streaming_ctrl = cxusb_streaming_ctrl,
631 .frontend_attach = cxusb_dee1601_frontend_attach, 630 .frontend_attach = cxusb_dee1601_frontend_attach,
632 .tuner_attach = cxusb_dee1601_tuner_attach, 631 .tuner_attach = cxusb_dee1601_tuner_attach,
633 /* parameter for the MPEG2-data transfer */ 632 /* parameter for the MPEG2-data transfer */
634 .stream = { 633 .stream = {
635 .type = USB_BULK, 634 .type = USB_BULK,
636 .count = 5, 635 .count = 5,
637 .endpoint = 0x04, 636 .endpoint = 0x04,
638 .u = { 637 .u = {
639 .bulk = { 638 .bulk = {
640 .buffersize = 8192, 639 .buffersize = 8192,
641 } 640 }
642 } 641 }
643 }, 642 },
644 }, 643 },
645 }, 644 },
646 645
@@ -686,21 +685,21 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
686 .num_adapters = 2, 685 .num_adapters = 2,
687 .adapter = { 686 .adapter = {
688 { 687 {
689 .streaming_ctrl = cxusb_streaming_ctrl, 688 .streaming_ctrl = cxusb_streaming_ctrl,
690 .frontend_attach = cxusb_mt352_frontend_attach, 689 .frontend_attach = cxusb_mt352_frontend_attach,
691 .tuner_attach = cxusb_lgz201_tuner_attach, 690 .tuner_attach = cxusb_lgz201_tuner_attach,
692 691
693 /* parameter for the MPEG2-data transfer */ 692 /* parameter for the MPEG2-data transfer */
694 .stream = { 693 .stream = {
695 .type = USB_BULK, 694 .type = USB_BULK,
696 .count = 5, 695 .count = 5,
697 .endpoint = 0x04, 696 .endpoint = 0x04,
698 .u = { 697 .u = {
699 .bulk = { 698 .bulk = {
700 .buffersize = 8192, 699 .buffersize = 8192,
701 } 700 }
702 } 701 }
703 }, 702 },
704 }, 703 },
705 }, 704 },
706 .power_ctrl = cxusb_bluebird_power_ctrl, 705 .power_ctrl = cxusb_bluebird_power_ctrl,
@@ -736,21 +735,21 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
736 .num_adapters = 1, 735 .num_adapters = 1,
737 .adapter = { 736 .adapter = {
738 { 737 {
739 .streaming_ctrl = cxusb_streaming_ctrl, 738 .streaming_ctrl = cxusb_streaming_ctrl,
740 .frontend_attach = cxusb_mt352_frontend_attach, 739 .frontend_attach = cxusb_mt352_frontend_attach,
741 .tuner_attach = cxusb_dtt7579_tuner_attach, 740 .tuner_attach = cxusb_dtt7579_tuner_attach,
742 741
743 /* parameter for the MPEG2-data transfer */ 742 /* parameter for the MPEG2-data transfer */
744 .stream = { 743 .stream = {
745 .type = USB_BULK, 744 .type = USB_BULK,
746 .count = 5, 745 .count = 5,
747 .endpoint = 0x04, 746 .endpoint = 0x04,
748 .u = { 747 .u = {
749 .bulk = { 748 .bulk = {
750 .buffersize = 8192, 749 .buffersize = 8192,
751 } 750 }
752 } 751 }
753 }, 752 },
754 }, 753 },
755 }, 754 },
756 .power_ctrl = cxusb_bluebird_power_ctrl, 755 .power_ctrl = cxusb_bluebird_power_ctrl,
@@ -776,7 +775,7 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
776static struct usb_driver cxusb_driver = { 775static struct usb_driver cxusb_driver = {
777 .name = "dvb_usb_cxusb", 776 .name = "dvb_usb_cxusb",
778 .probe = cxusb_probe, 777 .probe = cxusb_probe,
779 .disconnect = dvb_usb_device_exit, 778 .disconnect = dvb_usb_device_exit,
780 .id_table = cxusb_table, 779 .id_table = cxusb_table,
781}; 780};
782 781
@@ -802,7 +801,7 @@ module_init (cxusb_module_init);
802module_exit (cxusb_module_exit); 801module_exit (cxusb_module_exit);
803 802
804MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 803MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
805MODULE_AUTHOR("Michael Krufky <mkrufky@m1k.net>"); 804MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
806MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); 805MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
807MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design"); 806MODULE_DESCRIPTION("Driver for Conexant USB2.0 hybrid reference design");
808MODULE_VERSION("1.0-alpha"); 807MODULE_VERSION("1.0-alpha");
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index ac84347f9d4c..cda3adea24fb 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -24,18 +24,23 @@ extern int dvb_usb_dib0700_debug;
24#define REQUEST_I2C_WRITE 0x3 24#define REQUEST_I2C_WRITE 0x3
25#define REQUEST_POLL_RC 0x4 25#define REQUEST_POLL_RC 0x4
26#define REQUEST_JUMPRAM 0x8 26#define REQUEST_JUMPRAM 0x8
27#define REQUEST_SET_CLOCK 0xB
27#define REQUEST_SET_GPIO 0xC 28#define REQUEST_SET_GPIO 0xC
28#define REQUEST_ENABLE_VIDEO 0xF 29#define REQUEST_ENABLE_VIDEO 0xF
29 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog) 30 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog)
30 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1) 31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
31 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " ) 32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " )
33#define REQUEST_GET_VERSION 0x15
32 34
33struct dib0700_state { 35struct dib0700_state {
34 u8 channel_state; 36 u8 channel_state;
35 u16 mt2060_if1[2]; 37 u16 mt2060_if1[2];
38
39 u8 is_dib7000pc;
36}; 40};
37 41
38extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); 42extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val);
43extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3);
39extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw); 44extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw);
40extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff); 45extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
41extern struct i2c_algorithm dib0700_i2c_algo; 46extern struct i2c_algorithm dib0700_i2c_algo;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index dca6c6985661..6a4d150784a6 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -135,14 +135,46 @@ struct i2c_algorithm dib0700_i2c_algo = {
135int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, 135int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
136 struct dvb_usb_device_description **desc, int *cold) 136 struct dvb_usb_device_description **desc, int *cold)
137{ 137{
138 u8 buf[3] = { REQUEST_SET_GPIO, 4, (GPIO_IN << 7) | (0 << 6) }; // GPIO4 is save - used for I2C 138 u8 b[16];
139 *cold = usb_control_msg(udev, usb_sndctrlpipe(udev,0), 139 s16 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev,0),
140 buf[0], USB_TYPE_VENDOR | USB_DIR_OUT, 0, 0, buf, 3, USB_CTRL_GET_TIMEOUT) != 3; 140 REQUEST_GET_VERSION, USB_TYPE_VENDOR | USB_DIR_IN, 0, 0, b, 16, USB_CTRL_GET_TIMEOUT);
141
142 deb_info("FW GET_VERSION length: %d\n",ret);
143
144 *cold = ret <= 0;
141 145
142 deb_info("cold: %d\n", *cold); 146 deb_info("cold: %d\n", *cold);
143 return 0; 147 return 0;
144} 148}
145 149
150static int dib0700_set_clock(struct dvb_usb_device *d, u8 en_pll,
151 u8 pll_src, u8 pll_range, u8 clock_gpio3, u16 pll_prediv,
152 u16 pll_loopdiv, u16 free_div, u16 dsuScaler)
153{
154 u8 b[10];
155 b[0] = REQUEST_SET_CLOCK;
156 b[1] = (en_pll << 7) | (pll_src << 6) | (pll_range << 5) | (clock_gpio3 << 4);
157 b[2] = (pll_prediv >> 8) & 0xff; // MSB
158 b[3] = pll_prediv & 0xff; // LSB
159 b[4] = (pll_loopdiv >> 8) & 0xff; // MSB
160 b[5] = pll_loopdiv & 0xff; // LSB
161 b[6] = (free_div >> 8) & 0xff; // MSB
162 b[7] = free_div & 0xff; // LSB
163 b[8] = (dsuScaler >> 8) & 0xff; // MSB
164 b[9] = dsuScaler & 0xff; // LSB
165
166 return dib0700_ctrl_wr(d, b, 10);
167}
168
169int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3)
170{
171 switch (clk_MHz) {
172 case 72: dib0700_set_clock(d, 1, 0, 1, clock_out_gp3, 2, 24, 0, 0x4c); break;
173 default: return -EINVAL;
174 }
175 return 0;
176}
177
146static int dib0700_jumpram(struct usb_device *udev, u32 address) 178static int dib0700_jumpram(struct usb_device *udev, u32 address)
147{ 179{
148 int ret, actlen; 180 int ret, actlen;
@@ -197,7 +229,7 @@ int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw
197 /* start the firmware */ 229 /* start the firmware */
198 if ((ret = dib0700_jumpram(udev, 0x70000000)) == 0) { 230 if ((ret = dib0700_jumpram(udev, 0x70000000)) == 0) {
199 info("firmware started successfully."); 231 info("firmware started successfully.");
200 msleep(100); 232 msleep(500);
201 } 233 }
202 } else 234 } else
203 ret = -EIO; 235 ret = -EIO;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index e473bfed226b..2208757d9017 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -9,6 +9,8 @@
9#include "dib0700.h" 9#include "dib0700.h"
10 10
11#include "dib3000mc.h" 11#include "dib3000mc.h"
12#include "dib7000m.h"
13#include "dib7000p.h"
12#include "mt2060.h" 14#include "mt2060.h"
13 15
14static int force_lna_activation; 16static int force_lna_activation;
@@ -95,37 +97,189 @@ static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
95} 97}
96 98
97/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */ 99/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
98/* 100static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
99static struct mt2060_config stk7000p_mt2060_config = { 101 BAND_UHF | BAND_VHF, // band_caps
100 0x60 102
103 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
104 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
105 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
106
107 712, // inv_gain
108 41, // time_stabiliz
109
110 0, // alpha_level
111 118, // thlock
112
113 0, // wbd_inv
114 4095, // wbd_ref
115 0, // wbd_sel
116 0, // wbd_alpha
117
118 42598, // agc1_max
119 17694, // agc1_min
120 45875, // agc2_max
121 2621, // agc2_min
122 0, // agc1_pt1
123 76, // agc1_pt2
124 139, // agc1_pt3
125 52, // agc1_slope1
126 59, // agc1_slope2
127 107, // agc2_pt1
128 172, // agc2_pt2
129 57, // agc2_slope1
130 70, // agc2_slope2
131
132 21, // alpha_mant
133 25, // alpha_exp
134 28, // beta_mant
135 48, // beta_exp
136
137 1, // perform_agc_softsplit
138 { 0, // split_min
139 107, // split_max
140 51800, // global_split_min
141 24700 // global_split_max
142 },
143};
144
145static struct dibx000_agc_config stk7700p_7000p_mt2060_agc_config = {
146 BAND_UHF | BAND_VHF,
147
148 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
149 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
150 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
151
152 712, // inv_gain
153 41, // time_stabiliz
154
155 0, // alpha_level
156 118, // thlock
157
158 0, // wbd_inv
159 4095, // wbd_ref
160 0, // wbd_sel
161 0, // wbd_alpha
162
163 42598, // agc1_max
164 16384, // agc1_min
165 42598, // agc2_max
166 0, // agc2_min
167
168 0, // agc1_pt1
169 137, // agc1_pt2
170 255, // agc1_pt3
171
172 0, // agc1_slope1
173 255, // agc1_slope2
174
175 0, // agc2_pt1
176 0, // agc2_pt2
177
178 0, // agc2_slope1
179 41, // agc2_slope2
180
181 15, // alpha_mant
182 25, // alpha_exp
183
184 28, // beta_mant
185 48, // beta_exp
186
187 0, // perform_agc_softsplit
188};
189
190static struct dibx000_bandwidth_config stk7700p_pll_config = {
191 60000, 30000, // internal, sampling
192 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
193 0, 0, 1, 1, 0, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
194 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
195 60258167, // ifreq
196 20452225, // timf
197};
198
199static struct dib7000m_config stk7700p_dib7000m_config = {
200 .dvbt_mode = 1,
201 .output_mpeg2_in_188_bytes = 1,
202 .quartz_direct = 1,
203
204 .agc_config_count = 1,
205 .agc = &stk7700p_7000m_mt2060_agc_config,
206 .bw = &stk7700p_pll_config,
207
208 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
209 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
210 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
211};
212
213static struct dib7000p_config stk7700p_dib7000p_config = {
214 .output_mpeg2_in_188_bytes = 1,
215
216 .agc = &stk7700p_7000p_mt2060_agc_config,
217 .bw = &stk7700p_pll_config,
218
219 .gpio_dir = DIB7000M_GPIO_DEFAULT_DIRECTIONS,
220 .gpio_val = DIB7000M_GPIO_DEFAULT_VALUES,
221 .gpio_pwm_pos = DIB7000M_GPIO_DEFAULT_PWM_POS,
101}; 222};
102*/
103 223
104static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap) 224static int stk7700p_frontend_attach(struct dvb_usb_adapter *adap)
105{ 225{
226 struct dib0700_state *st = adap->dev->priv;
106 /* unless there is no real power management in DVB - we leave the device on GPIO6 */ 227 /* unless there is no real power management in DVB - we leave the device on GPIO6 */
107 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(10); 228
108 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10); 229 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
109 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(10); 230 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); msleep(50);
231
232 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); msleep(10);
233 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
234
110 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10); 235 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); msleep(10);
236 dib0700_ctrl_clock(adap->dev, 72, 1);
237 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); msleep(100);
238
239 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
240
241 st->mt2060_if1[0] = 1220;
242
243 if (dib7000pc_detection(&adap->dev->i2c_adap)) {
244 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000p_config);
245 st->is_dib7000pc = 1;
246 } else
247 adap->fe = dvb_attach(dib7000m_attach, &adap->dev->i2c_adap, 18, &stk7700p_dib7000m_config);
111 248
112// adap->fe = dib7000m_attach(&adap->dev->i2c_adap, &stk7700p_dib7000m_config, 18); 249 return adap->fe == NULL ? -ENODEV : 0;
113 return 0;
114} 250}
115 251
252static struct mt2060_config stk7700p_mt2060_config = {
253 0x60
254};
255
116static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap) 256static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
117{ 257{
118// tun_i2c = dib7000m_get_tuner_i2c_master(adap->fe, 1); 258 struct dib0700_state *st = adap->dev->priv;
119// return mt2060_attach(adap->fe, tun_i2c, &stk3000p_mt2060_config, if1); 259 struct i2c_adapter *tun_i2c;
120 return 0; 260
261 if (st->is_dib7000pc)
262 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
263 else
264 tun_i2c = dib7000m_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
265
266 return dvb_attach(mt2060_attach, adap->fe, tun_i2c, &stk7700p_mt2060_config,
267 st->mt2060_if1[0]) == NULL ? -ENODEV : 0;
121} 268}
122 269
123struct usb_device_id dib0700_usb_id_table[] = { 270struct usb_device_id dib0700_usb_id_table[] = {
124 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, 271 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
272 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
273
125 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) }, 274 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
126 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) }, 275 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
127 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) }, 276 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
128 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) }, 277 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
278 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
279 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) },
280 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
281 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
282 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
129 { } /* Terminating entry */ 283 { } /* Terminating entry */
130}; 284};
131MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 285MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -167,20 +321,32 @@ struct dvb_usb_device_properties dib0700_devices[] = {
167 }, 321 },
168 }, 322 },
169 323
170 .num_device_descs = 3, 324 .num_device_descs = 6,
171 .devices = { 325 .devices = {
172 { "DiBcom STK7700P reference design", 326 { "DiBcom STK7700P reference design",
173 { &dib0700_usb_id_table[0], NULL }, 327 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
174 { NULL }, 328 { NULL },
175 }, 329 },
176 { "Hauppauge Nova-T Stick", 330 { "Hauppauge Nova-T Stick",
177 { &dib0700_usb_id_table[3], NULL }, 331 { &dib0700_usb_id_table[4], &dib0700_usb_id_table[9], NULL },
178 { NULL }, 332 { NULL },
179 }, 333 },
180 { "AVerMedia AVerTV DVB-T Volar", 334 { "AVerMedia AVerTV DVB-T Volar",
181 { &dib0700_usb_id_table[4], NULL }, 335 { &dib0700_usb_id_table[5], &dib0700_usb_id_table[10] },
182 { NULL }, 336 { NULL },
183 }, 337 },
338 { "Compro Videomate U500",
339 { &dib0700_usb_id_table[6], NULL },
340 { NULL },
341 },
342 { "Uniwill STK7700P based (Hama and others)",
343 { &dib0700_usb_id_table[7], NULL },
344 { NULL },
345 },
346 { "Leadtek Winfast DTV Dongle (STK7700P based)",
347 { &dib0700_usb_id_table[8], NULL },
348 { NULL },
349 }
184 } 350 }
185 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 351 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
186 352
@@ -202,7 +368,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
202 .num_device_descs = 1, 368 .num_device_descs = 1,
203 .devices = { 369 .devices = {
204 { "Hauppauge Nova-T 500 Dual DVB-T", 370 { "Hauppauge Nova-T 500 Dual DVB-T",
205 { &dib0700_usb_id_table[1], &dib0700_usb_id_table[2], NULL }, 371 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
206 { NULL }, 372 { NULL },
207 }, 373 },
208 } 374 }
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index 4fe363e48352..7a6ae8f482e0 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -163,23 +163,23 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
163 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 163 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
164 .pid_filter_count = 16, 164 .pid_filter_count = 16,
165 165
166 .streaming_ctrl = dibusb_streaming_ctrl, 166 .streaming_ctrl = dibusb_streaming_ctrl,
167 .pid_filter = dibusb_pid_filter, 167 .pid_filter = dibusb_pid_filter,
168 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 168 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
169 .frontend_attach = dibusb_dib3000mb_frontend_attach, 169 .frontend_attach = dibusb_dib3000mb_frontend_attach,
170 .tuner_attach = dibusb_tuner_probe_and_attach, 170 .tuner_attach = dibusb_tuner_probe_and_attach,
171 171
172 /* parameter for the MPEG2-data transfer */ 172 /* parameter for the MPEG2-data transfer */
173 .stream = { 173 .stream = {
174 .type = USB_BULK, 174 .type = USB_BULK,
175 .count = 7, 175 .count = 7,
176 .endpoint = 0x02, 176 .endpoint = 0x02,
177 .u = { 177 .u = {
178 .bulk = { 178 .bulk = {
179 .buffersize = 4096, 179 .buffersize = 4096,
180 } 180 }
181 } 181 }
182 }, 182 },
183 .size_of_priv = sizeof(struct dibusb_state), 183 .size_of_priv = sizeof(struct dibusb_state),
184 } 184 }
185 }, 185 },
@@ -248,23 +248,23 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
248 .caps = DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_ADAP_HAS_PID_FILTER, 248 .caps = DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF | DVB_USB_ADAP_HAS_PID_FILTER,
249 .pid_filter_count = 16, 249 .pid_filter_count = 16,
250 250
251 .streaming_ctrl = dibusb_streaming_ctrl, 251 .streaming_ctrl = dibusb_streaming_ctrl,
252 .pid_filter = dibusb_pid_filter, 252 .pid_filter = dibusb_pid_filter,
253 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 253 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
254 .frontend_attach = dibusb_dib3000mb_frontend_attach, 254 .frontend_attach = dibusb_dib3000mb_frontend_attach,
255 .tuner_attach = dibusb_tuner_probe_and_attach, 255 .tuner_attach = dibusb_tuner_probe_and_attach,
256 256
257 /* parameter for the MPEG2-data transfer */ 257 /* parameter for the MPEG2-data transfer */
258 .stream = { 258 .stream = {
259 .type = USB_BULK, 259 .type = USB_BULK,
260 .count = 7, 260 .count = 7,
261 .endpoint = 0x02, 261 .endpoint = 0x02,
262 .u = { 262 .u = {
263 .bulk = { 263 .bulk = {
264 .buffersize = 4096, 264 .buffersize = 4096,
265 } 265 }
266 } 266 }
267 }, 267 },
268 .size_of_priv = sizeof(struct dibusb_state), 268 .size_of_priv = sizeof(struct dibusb_state),
269 }, 269 },
270 }, 270 },
@@ -312,22 +312,23 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
312 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 312 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
313 .pid_filter_count = 16, 313 .pid_filter_count = 16,
314 314
315 .streaming_ctrl = dibusb2_0_streaming_ctrl, 315 .streaming_ctrl = dibusb2_0_streaming_ctrl,
316 .pid_filter = dibusb_pid_filter, 316 .pid_filter = dibusb_pid_filter,
317 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 317 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
318 .frontend_attach = dibusb_dib3000mb_frontend_attach, 318 .frontend_attach = dibusb_dib3000mb_frontend_attach,
319 .tuner_attach = dibusb_thomson_tuner_attach, 319 .tuner_attach = dibusb_thomson_tuner_attach,
320 /* parameter for the MPEG2-data transfer */ 320
321 /* parameter for the MPEG2-data transfer */
321 .stream = { 322 .stream = {
322 .type = USB_BULK, 323 .type = USB_BULK,
323 .count = 7, 324 .count = 7,
324 .endpoint = 0x06, 325 .endpoint = 0x06,
325 .u = { 326 .u = {
326 .bulk = { 327 .bulk = {
327 .buffersize = 4096, 328 .buffersize = 4096,
328 } 329 }
329 } 330 }
330 }, 331 },
331 .size_of_priv = sizeof(struct dibusb_state), 332 .size_of_priv = sizeof(struct dibusb_state),
332 } 333 }
333 }, 334 },
@@ -369,22 +370,22 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
369 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 370 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
370 .pid_filter_count = 16, 371 .pid_filter_count = 16,
371 372
372 .streaming_ctrl = dibusb2_0_streaming_ctrl, 373 .streaming_ctrl = dibusb2_0_streaming_ctrl,
373 .pid_filter = dibusb_pid_filter, 374 .pid_filter = dibusb_pid_filter,
374 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 375 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
375 .frontend_attach = dibusb_dib3000mb_frontend_attach, 376 .frontend_attach = dibusb_dib3000mb_frontend_attach,
376 .tuner_attach = dibusb_tuner_probe_and_attach, 377 .tuner_attach = dibusb_tuner_probe_and_attach,
377 /* parameter for the MPEG2-data transfer */ 378 /* parameter for the MPEG2-data transfer */
378 .stream = { 379 .stream = {
379 .type = USB_BULK, 380 .type = USB_BULK,
380 .count = 7, 381 .count = 7,
381 .endpoint = 0x06, 382 .endpoint = 0x06,
382 .u = { 383 .u = {
383 .bulk = { 384 .bulk = {
384 .buffersize = 4096, 385 .buffersize = 4096,
385 } 386 }
386 } 387 }
387 }, 388 },
388 .size_of_priv = sizeof(struct dibusb_state), 389 .size_of_priv = sizeof(struct dibusb_state),
389 } 390 }
390 }, 391 },
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index a0fd37efc04b..e7ea3e753d6d 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -54,23 +54,23 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
54 { 54 {
55 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 55 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
56 .pid_filter_count = 32, 56 .pid_filter_count = 32,
57 .streaming_ctrl = dibusb2_0_streaming_ctrl, 57 .streaming_ctrl = dibusb2_0_streaming_ctrl,
58 .pid_filter = dibusb_pid_filter, 58 .pid_filter = dibusb_pid_filter,
59 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 59 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
60 .frontend_attach = dibusb_dib3000mc_frontend_attach, 60 .frontend_attach = dibusb_dib3000mc_frontend_attach,
61 .tuner_attach = dibusb_dib3000mc_tuner_attach, 61 .tuner_attach = dibusb_dib3000mc_tuner_attach,
62 62
63 /* parameter for the MPEG2-data transfer */ 63 /* parameter for the MPEG2-data transfer */
64 .stream = { 64 .stream = {
65 .type = USB_BULK, 65 .type = USB_BULK,
66 .count = 7, 66 .count = 7,
67 .endpoint = 0x06, 67 .endpoint = 0x06,
68 .u = { 68 .u = {
69 .bulk = { 69 .bulk = {
70 .buffersize = 4096, 70 .buffersize = 4096,
71 } 71 }
72 } 72 }
73 }, 73 },
74 .size_of_priv = sizeof(struct dibusb_state), 74 .size_of_priv = sizeof(struct dibusb_state),
75 } 75 }
76 }, 76 },
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 8fb34375c1fb..4a198d4755b0 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -274,20 +274,20 @@ static struct dvb_usb_device_properties digitv_properties = {
274 .num_adapters = 1, 274 .num_adapters = 1,
275 .adapter = { 275 .adapter = {
276 { 276 {
277 .frontend_attach = digitv_frontend_attach, 277 .frontend_attach = digitv_frontend_attach,
278 .tuner_attach = digitv_tuner_attach, 278 .tuner_attach = digitv_tuner_attach,
279 279
280 /* parameter for the MPEG2-data transfer */ 280 /* parameter for the MPEG2-data transfer */
281 .stream = { 281 .stream = {
282 .type = USB_BULK, 282 .type = USB_BULK,
283 .count = 7, 283 .count = 7,
284 .endpoint = 0x02, 284 .endpoint = 0x02,
285 .u = { 285 .u = {
286 .bulk = { 286 .bulk = {
287 .buffersize = 4096, 287 .buffersize = 4096,
288 } 288 }
289 } 289 }
290 }, 290 },
291 } 291 }
292 }, 292 },
293 .identify_state = digitv_identify_state, 293 .identify_state = digitv_identify_state,
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index fa43a41d753b..7dbe14321019 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -268,20 +268,20 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
268 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING, 268 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_NEED_PID_FILTERING,
269 .pid_filter_count = 15, 269 .pid_filter_count = 15,
270 270
271 .streaming_ctrl = dtt200u_streaming_ctrl, 271 .streaming_ctrl = dtt200u_streaming_ctrl,
272 .pid_filter = dtt200u_pid_filter, 272 .pid_filter = dtt200u_pid_filter,
273 .frontend_attach = dtt200u_frontend_attach, 273 .frontend_attach = dtt200u_frontend_attach,
274 /* parameter for the MPEG2-data transfer */ 274 /* parameter for the MPEG2-data transfer */
275 .stream = { 275 .stream = {
276 .type = USB_BULK, 276 .type = USB_BULK,
277 .count = 7, 277 .count = 7,
278 .endpoint = 0x02, 278 .endpoint = 0x02,
279 .u = { 279 .u = {
280 .bulk = { 280 .bulk = {
281 .buffersize = 4096, 281 .buffersize = 4096,
282 } 282 }
283 } 283 }
284 }, 284 },
285 } 285 }
286 }, 286 },
287 .power_ctrl = dtt200u_power_ctrl, 287 .power_ctrl = dtt200u_power_ctrl,
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 4d6b069536ce..299382dcb81d 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -33,6 +33,7 @@
33#define USB_VID_VISIONPLUS 0x13d3 33#define USB_VID_VISIONPLUS 0x13d3
34#define USB_VID_TWINHAN 0x1822 34#define USB_VID_TWINHAN 0x1822
35#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 35#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
36#define USB_VID_UNIWILL 0x1584
36#define USB_VID_WIDEVIEW 0x14aa 37#define USB_VID_WIDEVIEW 0x14aa
37 38
38/* Product IDs */ 39/* Product IDs */
@@ -46,6 +47,7 @@
46#define USB_PID_COMPRO_DVBU2000_WARM 0xd001 47#define USB_PID_COMPRO_DVBU2000_WARM 0xd001
47#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c 48#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c
48#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d 49#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
50#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78
49#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 51#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
50#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 52#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
51#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 53#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
@@ -53,7 +55,9 @@
53#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6 55#define USB_PID_DIBCOM_MOD3001_COLD 0x0bc6
54#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7 56#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7
55#define USB_PID_DIBCOM_STK7700P 0x1e14 57#define USB_PID_DIBCOM_STK7700P 0x1e14
58#define USB_PID_DIBCOM_STK7700P_PC 0x1e78
56#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 59#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
60#define USB_PID_UNIWILL_STK7700P 0x6003
57#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 61#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
58#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 62#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
59#define USB_PID_KWORLD_VSTREAM_COLD 0x17de 63#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
@@ -97,7 +101,9 @@
97#define USB_PID_HAUPPAUGE_NOVA_T_500 0x9941 101#define USB_PID_HAUPPAUGE_NOVA_T_500 0x9941
98#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950 102#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950
99#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050 103#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050
100#define USB_PID_AVERMEDIA_VOLAR 0x1234 104#define USB_PID_HAUPPAUGE_NOVA_T_STICK_2 0x7060
105#define USB_PID_AVERMEDIA_VOLAR 0xa807
106#define USB_PID_AVERMEDIA_VOLAR_2 0xb808
101#define USB_PID_NEBULA_DIGITV 0x0201 107#define USB_PID_NEBULA_DIGITV 0x0201
102#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820 108#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820
103#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500 109#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500
@@ -110,8 +116,8 @@
110#define USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM 0xdb51 116#define USB_PID_DVICO_BLUEBIRD_DUAL_1_WARM 0xdb51
111#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58 117#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58
112#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59 118#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59
113#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54 119#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54
114#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55 120#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_WARM 0xdb55
115#define USB_PID_MEDION_MD95700 0x0932 121#define USB_PID_MEDION_MD95700 0x0932
116#define USB_PID_KYE_DVB_T_COLD 0x701e 122#define USB_PID_KYE_DVB_T_COLD 0x701e
117#define USB_PID_KYE_DVB_T_WARM 0x701f 123#define USB_PID_KYE_DVB_T_WARM 0x701f
@@ -125,7 +131,9 @@
125#define USB_PID_GRANDTEC_DVBT_USB2_WARM 0x0bc7 131#define USB_PID_GRANDTEC_DVBT_USB2_WARM 0x0bc7
126#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025 132#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025
127#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026 133#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
134#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
128#define USB_PID_GENPIX_8PSK_COLD 0x0200 135#define USB_PID_GENPIX_8PSK_COLD 0x0200
129#define USB_PID_GENPIX_8PSK_WARM 0x0201 136#define USB_PID_GENPIX_8PSK_WARM 0x0201
130 137
138
131#endif 139#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 794e4471561c..19ff5978bc91 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -90,7 +90,9 @@ schedule:
90 90
91int dvb_usb_remote_init(struct dvb_usb_device *d) 91int dvb_usb_remote_init(struct dvb_usb_device *d)
92{ 92{
93 struct input_dev *input_dev;
93 int i; 94 int i;
95 int err;
94 96
95 if (d->props.rc_key_map == NULL || 97 if (d->props.rc_key_map == NULL ||
96 d->props.rc_query == NULL || 98 d->props.rc_query == NULL ||
@@ -100,23 +102,24 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
100 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys)); 102 usb_make_path(d->udev, d->rc_phys, sizeof(d->rc_phys));
101 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys)); 103 strlcat(d->rc_phys, "/ir0", sizeof(d->rc_phys));
102 104
103 d->rc_input_dev = input_allocate_device(); 105 input_dev = input_allocate_device();
104 if (!d->rc_input_dev) 106 if (!input_dev)
105 return -ENOMEM; 107 return -ENOMEM;
106 108
107 d->rc_input_dev->evbit[0] = BIT(EV_KEY); 109 input_dev->evbit[0] = BIT(EV_KEY);
108 d->rc_input_dev->keycodesize = sizeof(unsigned char); 110 input_dev->keycodesize = sizeof(unsigned char);
109 d->rc_input_dev->keycodemax = KEY_MAX; 111 input_dev->keycodemax = KEY_MAX;
110 d->rc_input_dev->name = "IR-receiver inside an USB DVB receiver"; 112 input_dev->name = "IR-receiver inside an USB DVB receiver";
111 d->rc_input_dev->phys = d->rc_phys; 113 input_dev->phys = d->rc_phys;
112 usb_to_input_id(d->udev, &d->rc_input_dev->id); 114 usb_to_input_id(d->udev, &input_dev->id);
113 d->rc_input_dev->cdev.dev = &d->udev->dev; 115 input_dev->cdev.dev = &d->udev->dev;
114 116
115 /* set the bits for the keys */ 117 /* set the bits for the keys */
116 deb_rc("key map size: %d\n", d->props.rc_key_map_size); 118 deb_rc("key map size: %d\n", d->props.rc_key_map_size);
117 for (i = 0; i < d->props.rc_key_map_size; i++) { 119 for (i = 0; i < d->props.rc_key_map_size; i++) {
118 deb_rc("setting bit for event %d item %d\n",d->props.rc_key_map[i].event, i); 120 deb_rc("setting bit for event %d item %d\n",
119 set_bit(d->props.rc_key_map[i].event, d->rc_input_dev->keybit); 121 d->props.rc_key_map[i].event, i);
122 set_bit(d->props.rc_key_map[i].event, input_dev->keybit);
120 } 123 }
121 124
122 /* Start the remote-control polling. */ 125 /* Start the remote-control polling. */
@@ -124,10 +127,16 @@ int dvb_usb_remote_init(struct dvb_usb_device *d)
124 d->props.rc_interval = 100; /* default */ 127 d->props.rc_interval = 100; /* default */
125 128
126 /* setting these two values to non-zero, we have to manage key repeats */ 129 /* setting these two values to non-zero, we have to manage key repeats */
127 d->rc_input_dev->rep[REP_PERIOD] = d->props.rc_interval; 130 input_dev->rep[REP_PERIOD] = d->props.rc_interval;
128 d->rc_input_dev->rep[REP_DELAY] = d->props.rc_interval + 150; 131 input_dev->rep[REP_DELAY] = d->props.rc_interval + 150;
129 132
130 input_register_device(d->rc_input_dev); 133 err = input_register_device(input_dev);
134 if (err) {
135 input_free_device(input_dev);
136 return err;
137 }
138
139 d->rc_input_dev = input_dev;
131 140
132 INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control); 141 INIT_DELAYED_WORK(&d->rc_query_work, dvb_usb_read_remote_control);
133 142
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index 7375eb20166d..518d67fca5e8 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -194,19 +194,19 @@ static struct dvb_usb_device_properties gp8psk_properties = {
194 .num_adapters = 1, 194 .num_adapters = 1,
195 .adapter = { 195 .adapter = {
196 { 196 {
197 .streaming_ctrl = gp8psk_streaming_ctrl, 197 .streaming_ctrl = gp8psk_streaming_ctrl,
198 .frontend_attach = gp8psk_frontend_attach, 198 .frontend_attach = gp8psk_frontend_attach,
199 /* parameter for the MPEG2-data transfer */ 199 /* parameter for the MPEG2-data transfer */
200 .stream = { 200 .stream = {
201 .type = USB_BULK, 201 .type = USB_BULK,
202 .count = 7, 202 .count = 7,
203 .endpoint = 0x82, 203 .endpoint = 0x82,
204 .u = { 204 .u = {
205 .bulk = { 205 .bulk = {
206 .buffersize = 8192, 206 .buffersize = 8192,
207 } 207 }
208 } 208 }
209 }, 209 },
210 } 210 }
211 }, 211 },
212 .power_ctrl = gp8psk_power_ctrl, 212 .power_ctrl = gp8psk_power_ctrl,
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index a58874c790b2..d48622e76b1b 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -163,23 +163,23 @@ static struct dvb_usb_device_properties nova_t_properties = {
163 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 163 .caps = DVB_USB_ADAP_HAS_PID_FILTER | DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
164 .pid_filter_count = 32, 164 .pid_filter_count = 32,
165 165
166 .streaming_ctrl = dibusb2_0_streaming_ctrl, 166 .streaming_ctrl = dibusb2_0_streaming_ctrl,
167 .pid_filter = dibusb_pid_filter, 167 .pid_filter = dibusb_pid_filter,
168 .pid_filter_ctrl = dibusb_pid_filter_ctrl, 168 .pid_filter_ctrl = dibusb_pid_filter_ctrl,
169 .frontend_attach = dibusb_dib3000mc_frontend_attach, 169 .frontend_attach = dibusb_dib3000mc_frontend_attach,
170 .tuner_attach = dibusb_dib3000mc_tuner_attach, 170 .tuner_attach = dibusb_dib3000mc_tuner_attach,
171 171
172 /* parameter for the MPEG2-data transfer */ 172 /* parameter for the MPEG2-data transfer */
173 .stream = { 173 .stream = {
174 .type = USB_BULK, 174 .type = USB_BULK,
175 .count = 7, 175 .count = 7,
176 .endpoint = 0x06, 176 .endpoint = 0x06,
177 .u = { 177 .u = {
178 .bulk = { 178 .bulk = {
179 .buffersize = 4096, 179 .buffersize = 4096,
180 } 180 }
181 } 181 }
182 }, 182 },
183 183
184 .size_of_priv = sizeof(struct dibusb_state), 184 .size_of_priv = sizeof(struct dibusb_state),
185 } 185 }
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.c b/drivers/media/dvb/dvb-usb/ttusb2.c
new file mode 100644
index 000000000000..95d29976ed78
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/ttusb2.c
@@ -0,0 +1,270 @@
1/* DVB USB compliant linux driver for Technotrend DVB USB boxes and clones
2 * (e.g. Pinnacle 400e DVB-S USB2.0).
3 *
4 * The Pinnacle 400e uses the same protocol as the Technotrend USB1.1 boxes.
5 *
6 * TDA8263 + TDA10086
7 *
8 * I2C addresses:
9 * 0x08 - LNBP21PD - LNB power supply
10 * 0x0e - TDA10086 - Demodulator
11 * 0x50 - FX2 eeprom
12 * 0x60 - TDA8263 - Tuner
13 * 0x78 ???
14 *
15 * Copyright (c) 2002 Holger Waechtler <holger@convergence.de>
16 * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net>
17 * Copyright (C) 2005-6 Patrick Boettcher <pb@linuxtv.org>
18 *
19 * This program is free software; you can redistribute it and/or modify it
20 * under the terms of the GNU General Public License as published by the Free
21 * Software Foundation, version 2.
22 *
23 * see Documentation/dvb/README.dvb-usb for more information
24 */
25#define DVB_USB_LOG_PREFIX "ttusb2"
26#include "dvb-usb.h"
27
28#include "ttusb2.h"
29
30#include "tda826x.h"
31#include "tda10086.h"
32#include "lnbp21.h"
33
34/* debug */
35static int dvb_usb_ttusb2_debug;
36#define deb_info(args...) dprintk(dvb_usb_ttusb2_debug,0x01,args)
37module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
39
40struct ttusb2_state {
41 u8 id;
42};
43
44static int ttusb2_msg(struct dvb_usb_device *d, u8 cmd,
45 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
46{
47 struct ttusb2_state *st = d->priv;
48 u8 s[wlen+4],r[64] = { 0 };
49 int ret = 0;
50
51 memset(s,0,wlen+4);
52
53 s[0] = 0xaa;
54 s[1] = ++st->id;
55 s[2] = cmd;
56 s[3] = wlen;
57 memcpy(&s[4],wbuf,wlen);
58
59 ret = dvb_usb_generic_rw(d, s, wlen+4, r, 64, 0);
60
61 if (ret != 0 ||
62 r[0] != 0x55 ||
63 r[1] != s[1] ||
64 r[2] != cmd ||
65 (rlen > 0 && r[3] != rlen)) {
66 warn("there might have been an error during control message transfer. (rlen = %d, was %d)",rlen,r[3]);
67 return -EIO;
68 }
69
70 if (rlen > 0)
71 memcpy(rbuf, &r[4], rlen);
72
73 return 0;
74}
75
76static int ttusb2_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg msg[],int num)
77{
78 struct dvb_usb_device *d = i2c_get_adapdata(adap);
79 static u8 obuf[60], ibuf[60];
80 int i,read;
81
82 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
83 return -EAGAIN;
84
85 if (num > 2)
86 warn("more than 2 i2c messages at a time is not handled yet. TODO.");
87
88 for (i = 0; i < num; i++) {
89 read = i+1 < num && (msg[i+1].flags & I2C_M_RD);
90
91 obuf[0] = (msg[i].addr << 1) | read;
92 obuf[1] = msg[i].len;
93
94 /* read request */
95 if (read)
96 obuf[2] = msg[i+1].len;
97 else
98 obuf[2] = 0;
99
100 memcpy(&obuf[3],msg[i].buf,msg[i].len);
101
102 if (ttusb2_msg(d, CMD_I2C_XFER, obuf, msg[i].len+3, ibuf, obuf[2] + 3) < 0) {
103 err("i2c transfer failed.");
104 break;
105 }
106
107 if (read) {
108 memcpy(msg[i+1].buf,&ibuf[3],msg[i+1].len);
109 i++;
110 }
111 }
112
113 mutex_unlock(&d->i2c_mutex);
114 return i;
115}
116
117static u32 ttusb2_i2c_func(struct i2c_adapter *adapter)
118{
119 return I2C_FUNC_I2C;
120}
121
122static struct i2c_algorithm ttusb2_i2c_algo = {
123 .master_xfer = ttusb2_i2c_xfer,
124 .functionality = ttusb2_i2c_func,
125};
126
127/* Callbacks for DVB USB */
128static int ttusb2_identify_state (struct usb_device *udev, struct
129 dvb_usb_device_properties *props, struct dvb_usb_device_description **desc,
130 int *cold)
131{
132 *cold = udev->descriptor.iManufacturer == 0 && udev->descriptor.iProduct == 0;
133 return 0;
134}
135
136static int ttusb2_power_ctrl(struct dvb_usb_device *d, int onoff)
137{
138 u8 b = onoff;
139 ttusb2_msg(d, CMD_POWER, &b, 0, NULL, 0);
140 return ttusb2_msg(d, CMD_POWER, &b, 1, NULL, 0);
141}
142
143
144static struct tda10086_config tda10086_config = {
145 .demod_address = 0x0e,
146 .invert = 0,
147};
148
149static int ttusb2_frontend_attach(struct dvb_usb_adapter *adap)
150{
151 if (usb_set_interface(adap->dev->udev,0,3) < 0)
152 err("set interface to alts=3 failed");
153
154 if ((adap->fe = dvb_attach(tda10086_attach, &tda10086_config, &adap->dev->i2c_adap)) == NULL) {
155 deb_info("TDA10086 attach failed\n");
156 return -ENODEV;
157 }
158
159 return 0;
160}
161
162static int ttusb2_tuner_attach(struct dvb_usb_adapter *adap)
163{
164 if (dvb_attach(tda826x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 0) == NULL) {
165 deb_info("TDA8263 attach failed\n");
166 return -ENODEV;
167 }
168
169 if (dvb_attach(lnbp21_attach, adap->fe, &adap->dev->i2c_adap, 0, 0) == NULL) {
170 deb_info("LNBP21 attach failed\n");
171 return -ENODEV;
172 }
173 return 0;
174}
175
176/* DVB USB Driver stuff */
177static struct dvb_usb_device_properties ttusb2_properties;
178
179static int ttusb2_probe(struct usb_interface *intf,
180 const struct usb_device_id *id)
181{
182 return dvb_usb_device_init(intf,&ttusb2_properties,THIS_MODULE,NULL);
183}
184
185static struct usb_device_id ttusb2_table [] = {
186 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
187 {} /* Terminating entry */
188};
189MODULE_DEVICE_TABLE (usb, ttusb2_table);
190
191static struct dvb_usb_device_properties ttusb2_properties = {
192 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
193
194 .usb_ctrl = CYPRESS_FX2,
195 .firmware = "dvb-usb-pctv-400e-01.fw",
196
197 .size_of_priv = sizeof(struct ttusb2_state),
198
199 .num_adapters = 1,
200 .adapter = {
201 {
202 .streaming_ctrl = NULL, // ttusb2_streaming_ctrl,
203
204 .frontend_attach = ttusb2_frontend_attach,
205 .tuner_attach = ttusb2_tuner_attach,
206
207 /* parameter for the MPEG2-data transfer */
208 .stream = {
209 .type = USB_ISOC,
210 .count = 5,
211 .endpoint = 0x02,
212 .u = {
213 .isoc = {
214 .framesperurb = 4,
215 .framesize = 940,
216 .interval = 1,
217 }
218 }
219 }
220 }
221 },
222
223 .power_ctrl = ttusb2_power_ctrl,
224 .identify_state = ttusb2_identify_state,
225
226 .i2c_algo = &ttusb2_i2c_algo,
227
228 .generic_bulk_ctrl_endpoint = 0x01,
229
230 .num_device_descs = 1,
231 .devices = {
232 { "Pinnacle 400e DVB-S USB2.0",
233 { &ttusb2_table[0], NULL },
234 { NULL },
235 },
236 }
237};
238
239static struct usb_driver ttusb2_driver = {
240 .name = "dvb_usb_ttusb2",
241 .probe = ttusb2_probe,
242 .disconnect = dvb_usb_device_exit,
243 .id_table = ttusb2_table,
244};
245
246/* module stuff */
247static int __init ttusb2_module_init(void)
248{
249 int result;
250 if ((result = usb_register(&ttusb2_driver))) {
251 err("usb_register failed. Error number %d",result);
252 return result;
253 }
254
255 return 0;
256}
257
258static void __exit ttusb2_module_exit(void)
259{
260 /* deregister this driver from the USB subsystem */
261 usb_deregister(&ttusb2_driver);
262}
263
264module_init (ttusb2_module_init);
265module_exit (ttusb2_module_exit);
266
267MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
268MODULE_DESCRIPTION("Driver for Pinnacle PCTV 400e DVB-S USB2.0");
269MODULE_VERSION("1.0");
270MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.h b/drivers/media/dvb/dvb-usb/ttusb2.h
new file mode 100644
index 000000000000..52a63af40896
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/ttusb2.h
@@ -0,0 +1,70 @@
1/* DVB USB compliant linux driver for Technotrend DVB USB boxes and clones
2 * (e.g. Pinnacle 400e DVB-S USB2.0).
3 *
4 * Copyright (c) 2002 Holger Waechtler <holger@convergence.de>
5 * Copyright (c) 2003 Felix Domke <tmbinc@elitedvb.net>
6 * Copyright (C) 2005-6 Patrick Boettcher <pb@linuxtv.de>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation, version 2.
11 *
12 * see Documentation/dvb/README.dvb-usb for more information
13 */
14#ifndef _DVB_USB_TTUSB2_H_
15#define _DVB_USB_TTUSB2_H_
16
17/* TTUSB protocol
18 *
19 * always to messages (out/in)
20 * out message:
21 * 0xaa <id> <cmdbyte> <datalen> <data...>
22 *
23 * in message (complete block is always 0x40 bytes long)
24 * 0x55 <id> <cmdbyte> <datalen> <data...>
25 *
26 * id is incremented for each transaction
27 */
28
29#define CMD_DSP_DOWNLOAD 0x13
30/* out data: <byte>[28]
31 * last block must be empty */
32
33#define CMD_DSP_BOOT 0x14
34/* out data: nothing */
35
36#define CMD_POWER 0x15
37/* out data: <on=1/off=0> */
38
39#define CMD_LNB 0x16
40/* out data: <power=1> <18V=0,13V=1> <tone> <??=1> <??=1> */
41
42#define CMD_GET_VERSION 0x17
43/* in data: <version_byte>[5] */
44
45#define CMD_DISEQC 0x18
46/* out data: <master=0xff/burst=??> <cmdlen> <cmdbytes>[cmdlen] */
47
48#define CMD_PID_ENABLE 0x22
49/* out data: <index> <type: ts=1/sec=2> <pid msb> <pid lsb> */
50
51#define CMD_PID_DISABLE 0x23
52/* out data: <index> */
53
54#define CMD_FILTER_ENABLE 0x24
55/* out data: <index> <pid_idx> <filter>[12] <mask>[12] */
56
57#define CMD_FILTER_DISABLE 0x25
58/* out data: <index> */
59
60#define CMD_GET_DSP_VERSION 0x26
61/* in data: <version_byte>[28] */
62
63#define CMD_I2C_XFER 0x31
64/* out data: <addr << 1> <sndlen> <rcvlen> <data>[sndlen]
65 * in data: <addr << 1> <sndlen> <rcvlen> <data>[rcvlen] */
66
67#define CMD_I2C_BITRATE 0x32
68/* out data: <default=0> */
69
70#endif
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
index f9941ea88b3e..f77b48f76582 100644
--- a/drivers/media/dvb/dvb-usb/umt-010.c
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -99,21 +99,21 @@ static struct dvb_usb_device_properties umt_properties = {
99 .num_adapters = 1, 99 .num_adapters = 1,
100 .adapter = { 100 .adapter = {
101 { 101 {
102 .streaming_ctrl = dibusb2_0_streaming_ctrl, 102 .streaming_ctrl = dibusb2_0_streaming_ctrl,
103 .frontend_attach = umt_mt352_frontend_attach, 103 .frontend_attach = umt_mt352_frontend_attach,
104 .tuner_attach = umt_tuner_attach, 104 .tuner_attach = umt_tuner_attach,
105 105
106 /* parameter for the MPEG2-data transfer */ 106 /* parameter for the MPEG2-data transfer */
107 .stream = { 107 .stream = {
108 .type = USB_BULK, 108 .type = USB_BULK,
109 .count = 20, 109 .count = 20,
110 .endpoint = 0x06, 110 .endpoint = 0x06,
111 .u = { 111 .u = {
112 .bulk = { 112 .bulk = {
113 .buffersize = 512, 113 .buffersize = 512,
114 } 114 }
115 } 115 }
116 }, 116 },
117 117
118 .size_of_priv = sizeof(struct dibusb_state), 118 .size_of_priv = sizeof(struct dibusb_state),
119 } 119 }
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index 02bd61aaac66..16533b31a82d 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -275,22 +275,22 @@ static struct dvb_usb_device_properties vp702x_properties = {
275 .caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS, 275 .caps = DVB_USB_ADAP_RECEIVES_204_BYTE_TS,
276 276
277 .streaming_ctrl = vp702x_streaming_ctrl, 277 .streaming_ctrl = vp702x_streaming_ctrl,
278 .frontend_attach = vp702x_frontend_attach, 278 .frontend_attach = vp702x_frontend_attach,
279 279
280 /* parameter for the MPEG2-data transfer */ 280 /* parameter for the MPEG2-data transfer */
281 .stream = { 281 .stream = {
282 .type = USB_BULK, 282 .type = USB_BULK,
283 .count = 10, 283 .count = 10,
284 .endpoint = 0x02, 284 .endpoint = 0x02,
285 .u = { 285 .u = {
286 .bulk = { 286 .bulk = {
287 .buffersize = 4096, 287 .buffersize = 4096,
288 } 288 }
289 } 289 }
290 }, 290 },
291 .size_of_priv = sizeof(struct vp702x_state), 291 .size_of_priv = sizeof(struct vp702x_state),
292 } 292 }
293 }, 293 },
294 .read_mac_address = vp702x_read_mac_addr, 294 .read_mac_address = vp702x_read_mac_addr,
295 295
296 .rc_key_map = vp702x_rc_keys, 296 .rc_key_map = vp702x_rc_keys,
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index b4cf002703a7..69a46b3607a2 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -125,7 +125,25 @@ static struct dvb_usb_rc_key vp7045_rc_keys[] = {
125 { 0x00, 0x00, KEY_TAB }, /* Tab */ 125 { 0x00, 0x00, KEY_TAB }, /* Tab */
126 { 0x00, 0x48, KEY_INFO }, /* Preview */ 126 { 0x00, 0x48, KEY_INFO }, /* Preview */
127 { 0x00, 0x04, KEY_LIST }, /* RecordList */ 127 { 0x00, 0x04, KEY_LIST }, /* RecordList */
128 { 0x00, 0x0f, KEY_TEXT } /* Teletext */ 128 { 0x00, 0x0f, KEY_TEXT }, /* Teletext */
129 { 0x00, 0x41, KEY_PREVIOUSSONG },
130 { 0x00, 0x42, KEY_NEXTSONG },
131 { 0x00, 0x4b, KEY_UP },
132 { 0x00, 0x51, KEY_DOWN },
133 { 0x00, 0x4e, KEY_LEFT },
134 { 0x00, 0x52, KEY_RIGHT },
135 { 0x00, 0x4f, KEY_ENTER },
136 { 0x00, 0x13, KEY_CANCEL },
137 { 0x00, 0x4a, KEY_CLEAR },
138 { 0x00, 0x54, KEY_PRINT }, /* Capture */
139 { 0x00, 0x43, KEY_SUBTITLE }, /* Subtitle/CC */
140 { 0x00, 0x08, KEY_VIDEO }, /* A/V */
141 { 0x00, 0x07, KEY_SLEEP }, /* Hibernate */
142 { 0x00, 0x45, KEY_ZOOM }, /* Zoom+ */
143 { 0x00, 0x18, KEY_RED},
144 { 0x00, 0x53, KEY_GREEN},
145 { 0x00, 0x5e, KEY_YELLOW},
146 { 0x00, 0x5f, KEY_BLUE}
129}; 147};
130 148
131static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 149static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
@@ -217,18 +235,18 @@ static struct dvb_usb_device_properties vp7045_properties = {
217 .num_adapters = 1, 235 .num_adapters = 1,
218 .adapter = { 236 .adapter = {
219 { 237 {
220 .frontend_attach = vp7045_frontend_attach, 238 .frontend_attach = vp7045_frontend_attach,
221 /* parameter for the MPEG2-data transfer */ 239 /* parameter for the MPEG2-data transfer */
222 .stream = { 240 .stream = {
223 .type = USB_BULK, 241 .type = USB_BULK,
224 .count = 7, 242 .count = 7,
225 .endpoint = 0x02, 243 .endpoint = 0x02,
226 .u = { 244 .u = {
227 .bulk = { 245 .bulk = {
228 .buffersize = 4096, 246 .buffersize = 4096,
229 } 247 }
230 } 248 }
231 }, 249 },
232 } 250 }
233 }, 251 },
234 .power_ctrl = vp7045_power_ctrl, 252 .power_ctrl = vp7045_power_ctrl,
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index aebb8d6f26f8..af314bb1dcac 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -172,6 +172,22 @@ config DVB_DIB3000MC
172 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 172 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
173 to support this frontend. 173 to support this frontend.
174 174
175config DVB_DIB7000M
176 tristate "DiBcom 7000MA/MB/PA/PB/MC"
177 depends on DVB_CORE && I2C
178 default m if DVB_FE_CUSTOMISE
179 help
180 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
181 to support this frontend.
182
183config DVB_DIB7000P
184 tristate "DiBcom 7000PC"
185 depends on DVB_CORE && I2C
186 default m if DVB_FE_CUSTOMISE
187 help
188 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
189 to support this frontend.
190
175comment "DVB-C (cable) frontends" 191comment "DVB-C (cable) frontends"
176 depends on DVB_CORE 192 depends on DVB_CORE
177 193
@@ -281,6 +297,14 @@ config DVB_TUNER_MT2060
281 help 297 help
282 A driver for the silicon IF tuner MT2060 from Microtune. 298 A driver for the silicon IF tuner MT2060 from Microtune.
283 299
300config DVB_TUNER_LGH06XF
301 tristate "LG TDVS-H06xF ATSC tuner"
302 depends on DVB_CORE && I2C
303 select DVB_PLL
304 default m if DVB_FE_CUSTOMISE
305 help
306 A driver for the LG TDVS-H06xF ATSC tuner family.
307
284comment "Miscellaneous devices" 308comment "Miscellaneous devices"
285 depends on DVB_CORE 309 depends on DVB_CORE
286 310
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index dce9cf0c75c0..3fa6e5d32a9c 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -13,6 +13,8 @@ obj-$(CONFIG_DVB_TDA8083) += tda8083.o
13obj-$(CONFIG_DVB_L64781) += l64781.o 13obj-$(CONFIG_DVB_L64781) += l64781.o
14obj-$(CONFIG_DVB_DIB3000MB) += dib3000mb.o 14obj-$(CONFIG_DVB_DIB3000MB) += dib3000mb.o
15obj-$(CONFIG_DVB_DIB3000MC) += dib3000mc.o dibx000_common.o 15obj-$(CONFIG_DVB_DIB3000MC) += dib3000mc.o dibx000_common.o
16obj-$(CONFIG_DVB_DIB7000M) += dib7000m.o dibx000_common.o
17obj-$(CONFIG_DVB_DIB7000P) += dib7000p.o dibx000_common.o
16obj-$(CONFIG_DVB_MT312) += mt312.o 18obj-$(CONFIG_DVB_MT312) += mt312.o
17obj-$(CONFIG_DVB_VES1820) += ves1820.o 19obj-$(CONFIG_DVB_VES1820) += ves1820.o
18obj-$(CONFIG_DVB_VES1X93) += ves1x93.o 20obj-$(CONFIG_DVB_VES1X93) += ves1x93.o
@@ -37,3 +39,4 @@ obj-$(CONFIG_DVB_TDA10086) += tda10086.o
37obj-$(CONFIG_DVB_TDA826X) += tda826x.o 39obj-$(CONFIG_DVB_TDA826X) += tda826x.o
38obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o 40obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o
39obj-$(CONFIG_DVB_TUA6100) += tua6100.o 41obj-$(CONFIG_DVB_TUA6100) += tua6100.o
42obj-$(CONFIG_DVB_TUNER_LGH06XF) += lgh06xf.o
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 3561a777568c..5da66178006c 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -511,16 +511,11 @@ static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dibx000
511 511
512 512
513 /* a channel for autosearch */ 513 /* a channel for autosearch */
514 reg = 0;
515 if (chan->nfft == -1 && chan->guard == -1) reg = 7;
516 if (chan->nfft == -1 && chan->guard != -1) reg = 2;
517 if (chan->nfft != -1 && chan->guard == -1) reg = 3;
518
519 fchan.nfft = 1; fchan.guard = 0; fchan.nqam = 2; 514 fchan.nfft = 1; fchan.guard = 0; fchan.nqam = 2;
520 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2; 515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2;
521 fchan.vit_hrch = 0; fchan.vit_select_hp = 1; 516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1;
522 517
523 dib3000mc_set_channel_cfg(state, &fchan, reg); 518 dib3000mc_set_channel_cfg(state, &fchan, 7);
524 519
525 reg = dib3000mc_read_word(state, 0); 520 reg = dib3000mc_read_word(state, 0);
526 dib3000mc_write_word(state, 0, reg | (1 << 8)); 521 dib3000mc_write_word(state, 0, reg | (1 << 8));
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
new file mode 100644
index 000000000000..f5d40aa3d27f
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -0,0 +1,1191 @@
1/*
2 * Linux-DVB Driver for DiBcom's DiB7000M and
3 * first generation DiB7000P-demodulator-family.
4 *
5 * Copyright (C) 2005-6 DiBcom (http://www.dibcom.fr/)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 */
11#include <linux/kernel.h>
12#include <linux/i2c.h>
13
14#include "dvb_frontend.h"
15
16#include "dib7000m.h"
17
18static int debug;
19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
21
22#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000M:"); printk(args); } } while (0)
23
24struct dib7000m_state {
25 struct dvb_frontend demod;
26 struct dib7000m_config cfg;
27
28 u8 i2c_addr;
29 struct i2c_adapter *i2c_adap;
30
31 struct dibx000_i2c_master i2c_master;
32
33/* offset is 1 in case of the 7000MC */
34 u8 reg_offs;
35
36 u16 wbd_ref;
37
38 u8 current_band;
39 fe_bandwidth_t current_bandwidth;
40 struct dibx000_agc_config *current_agc;
41 u32 timf;
42
43 u16 revision;
44};
45
46enum dib7000m_power_mode {
47 DIB7000M_POWER_ALL = 0,
48
49 DIB7000M_POWER_NO,
50 DIB7000M_POWER_INTERF_ANALOG_AGC,
51 DIB7000M_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD,
52 DIB7000M_POWER_COR4_CRY_ESRAM_MOUT_NUD,
53 DIB7000M_POWER_INTERFACE_ONLY,
54};
55
56static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg)
57{
58 u8 wb[2] = { (reg >> 8) | 0x80, reg & 0xff };
59 u8 rb[2];
60 struct i2c_msg msg[2] = {
61 { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 },
62 { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 },
63 };
64
65 if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
66 dprintk("i2c read error on %d\n",reg);
67
68 return (rb[0] << 8) | rb[1];
69}
70
71static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val)
72{
73 u8 b[4] = {
74 (reg >> 8) & 0xff, reg & 0xff,
75 (val >> 8) & 0xff, val & 0xff,
76 };
77 struct i2c_msg msg = {
78 .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4
79 };
80 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
81}
82static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode)
83{
84 int ret = 0;
85 u16 outreg, fifo_threshold, smo_mode,
86 sram = 0x0005; /* by default SRAM output is disabled */
87
88 outreg = 0;
89 fifo_threshold = 1792;
90 smo_mode = (dib7000m_read_word(state, 294 + state->reg_offs) & 0x0010) | (1 << 1);
91
92 dprintk("-I- Setting output mode for demod %p to %d\n",
93 &state->demod, mode);
94
95 switch (mode) {
96 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
97 outreg = (1 << 10); /* 0x0400 */
98 break;
99 case OUTMODE_MPEG2_PAR_CONT_CLK: // STBs with parallel continues clock
100 outreg = (1 << 10) | (1 << 6); /* 0x0440 */
101 break;
102 case OUTMODE_MPEG2_SERIAL: // STBs with serial input
103 outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0482 */
104 break;
105 case OUTMODE_DIVERSITY:
106 if (state->cfg.hostbus_diversity)
107 outreg = (1 << 10) | (4 << 6); /* 0x0500 */
108 else
109 sram |= 0x0c00;
110 break;
111 case OUTMODE_MPEG2_FIFO: // e.g. USB feeding
112 smo_mode |= (3 << 1);
113 fifo_threshold = 512;
114 outreg = (1 << 10) | (5 << 6);
115 break;
116 case OUTMODE_HIGH_Z: // disable
117 outreg = 0;
118 break;
119 default:
120 dprintk("Unhandled output_mode passed to be set for demod %p\n",&state->demod);
121 break;
122 }
123
124 if (state->cfg.output_mpeg2_in_188_bytes)
125 smo_mode |= (1 << 5) ;
126
127 ret |= dib7000m_write_word(state, 294 + state->reg_offs, smo_mode);
128 ret |= dib7000m_write_word(state, 295 + state->reg_offs, fifo_threshold); /* synchronous fread */
129 ret |= dib7000m_write_word(state, 1795, outreg);
130 ret |= dib7000m_write_word(state, 1805, sram);
131
132 return ret;
133}
134
135static int dib7000m_set_power_mode(struct dib7000m_state *state, enum dib7000m_power_mode mode)
136{
137 /* by default everything is going to be powered off */
138 u16 reg_903 = 0xffff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906 = 0x3fff;
139
140 /* now, depending on the requested mode, we power on */
141 switch (mode) {
142 /* power up everything in the demod */
143 case DIB7000M_POWER_ALL:
144 reg_903 = 0x0000; reg_904 = 0x0000; reg_905 = 0x0000; reg_906 = 0x0000;
145 break;
146
147 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO or SRAM) */
148 case DIB7000M_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C or SRAM */
149 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 2));
150 break;
151
152 case DIB7000M_POWER_INTERF_ANALOG_AGC:
153 reg_903 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10));
154 reg_905 &= ~((1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 2));
155 reg_906 &= ~((1 << 0));
156 break;
157
158 case DIB7000M_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD:
159 reg_903 = 0x0000; reg_904 = 0x801f; reg_905 = 0x0000; reg_906 = 0x0000;
160 break;
161
162 case DIB7000M_POWER_COR4_CRY_ESRAM_MOUT_NUD:
163 reg_903 = 0x0000; reg_904 = 0x8000; reg_905 = 0x010b; reg_906 = 0x0000;
164 break;
165 case DIB7000M_POWER_NO:
166 break;
167 }
168
169 /* always power down unused parts */
170 if (!state->cfg.mobile_mode)
171 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1);
172
173 /* P_sdio_select_clk = 0 on MC */
174 if (state->revision != 0x4000)
175 reg_906 <<= 1;
176
177 dib7000m_write_word(state, 903, reg_903);
178 dib7000m_write_word(state, 904, reg_904);
179 dib7000m_write_word(state, 905, reg_905);
180 dib7000m_write_word(state, 906, reg_906);
181
182 return 0;
183}
184
185static int dib7000m_set_adc_state(struct dib7000m_state *state, enum dibx000_adc_states no)
186{
187 int ret = 0;
188 u16 reg_913 = dib7000m_read_word(state, 913),
189 reg_914 = dib7000m_read_word(state, 914);
190
191 switch (no) {
192 case DIBX000_SLOW_ADC_ON:
193 reg_914 |= (1 << 1) | (1 << 0);
194 ret |= dib7000m_write_word(state, 914, reg_914);
195 reg_914 &= ~(1 << 1);
196 break;
197
198 case DIBX000_SLOW_ADC_OFF:
199 reg_914 |= (1 << 1) | (1 << 0);
200 break;
201
202 case DIBX000_ADC_ON:
203 if (state->revision == 0x4000) { // workaround for PA/MA
204 // power-up ADC
205 dib7000m_write_word(state, 913, 0);
206 dib7000m_write_word(state, 914, reg_914 & 0x3);
207 // power-down bandgag
208 dib7000m_write_word(state, 913, (1 << 15));
209 dib7000m_write_word(state, 914, reg_914 & 0x3);
210 }
211
212 reg_913 &= 0x0fff;
213 reg_914 &= 0x0003;
214 break;
215
216 case DIBX000_ADC_OFF: // leave the VBG voltage on
217 reg_913 |= (1 << 14) | (1 << 13) | (1 << 12);
218 reg_914 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
219 break;
220
221 case DIBX000_VBG_ENABLE:
222 reg_913 &= ~(1 << 15);
223 break;
224
225 case DIBX000_VBG_DISABLE:
226 reg_913 |= (1 << 15);
227 break;
228
229 default:
230 break;
231 }
232
233// dprintk("-D- 913: %x, 914: %x\n", reg_913, reg_914);
234
235 ret |= dib7000m_write_word(state, 913, reg_913);
236 ret |= dib7000m_write_word(state, 914, reg_914);
237
238 return ret;
239}
240
241static int dib7000m_set_bandwidth(struct dvb_frontend *demod, u8 bw_idx)
242{
243 struct dib7000m_state *state = demod->demodulator_priv;
244 u32 timf;
245
246 // store the current bandwidth for later use
247 state->current_bandwidth = bw_idx;
248
249 if (state->timf == 0) {
250 dprintk("-D- Using default timf\n");
251 timf = state->cfg.bw->timf;
252 } else {
253 dprintk("-D- Using updated timf\n");
254 timf = state->timf;
255 }
256
257 timf = timf * (BW_INDEX_TO_KHZ(bw_idx) / 100) / 80;
258
259 dib7000m_write_word(state, 23, (timf >> 16) & 0xffff);
260 dib7000m_write_word(state, 24, (timf ) & 0xffff);
261
262 return 0;
263}
264
265static int dib7000m_sad_calib(struct dib7000m_state *state)
266{
267
268/* internal */
269// dib7000m_write_word(state, 928, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth
270 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0));
271 dib7000m_write_word(state, 930, 776); // 0.625*3.3 / 4096
272
273 /* do the calibration */
274 dib7000m_write_word(state, 929, (1 << 0));
275 dib7000m_write_word(state, 929, (0 << 0));
276
277 msleep(1);
278
279 return 0;
280}
281
282static void dib7000m_reset_pll_common(struct dib7000m_state *state, const struct dibx000_bandwidth_config *bw)
283{
284 dib7000m_write_word(state, 18, ((bw->internal*1000) >> 16) & 0xffff);
285 dib7000m_write_word(state, 19, (bw->internal*1000) & 0xffff);
286 dib7000m_write_word(state, 21, (bw->ifreq >> 16) & 0xffff);
287 dib7000m_write_word(state, 22, bw->ifreq & 0xffff);
288
289 dib7000m_write_word(state, 928, bw->sad_cfg);
290}
291
292static void dib7000m_reset_pll(struct dib7000m_state *state)
293{
294 const struct dibx000_bandwidth_config *bw = state->cfg.bw;
295 u16 reg_907,reg_910;
296
297 /* default */
298 reg_907 = (bw->pll_bypass << 15) | (bw->modulo << 7) |
299 (bw->ADClkSrc << 6) | (bw->IO_CLK_en_core << 5) | (bw->bypclk_div << 2) |
300 (bw->enable_refdiv << 1) | (0 << 0);
301 reg_910 = (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset;
302
303 // for this oscillator frequency should be 30 MHz for the Master (default values in the board_parameters give that value)
304 // this is only working only for 30 MHz crystals
305 if (!state->cfg.quartz_direct) {
306 reg_910 |= (1 << 5); // forcing the predivider to 1
307
308 // if the previous front-end is baseband, its output frequency is 15 MHz (prev freq divided by 2)
309 if(state->cfg.input_clk_is_div_2)
310 reg_907 |= (16 << 9);
311 else // otherwise the previous front-end puts out its input (default 30MHz) - no extra division necessary
312 reg_907 |= (8 << 9);
313 } else {
314 reg_907 |= (bw->pll_ratio & 0x3f) << 9;
315 reg_910 |= (bw->pll_prediv << 5);
316 }
317
318 dib7000m_write_word(state, 910, reg_910); // pll cfg
319 dib7000m_write_word(state, 907, reg_907); // clk cfg0
320 dib7000m_write_word(state, 908, 0x0006); // clk_cfg1
321
322 dib7000m_reset_pll_common(state, bw);
323}
324
325static void dib7000mc_reset_pll(struct dib7000m_state *state)
326{
327 const struct dibx000_bandwidth_config *bw = state->cfg.bw;
328
329 // clk_cfg0
330 dib7000m_write_word(state, 907, (bw->pll_prediv << 8) | (bw->pll_ratio << 0));
331
332 // clk_cfg1
333 //dib7000m_write_word(state, 908, (1 << 14) | (3 << 12) |(0 << 11) |
334 dib7000m_write_word(state, 908, (0 << 14) | (3 << 12) |(0 << 11) |
335 (bw->IO_CLK_en_core << 10) | (bw->bypclk_div << 5) | (bw->enable_refdiv << 4) |
336 (bw->pll_bypass << 3) | (bw->pll_range << 1) | (bw->pll_reset << 0));
337
338 // smpl_cfg
339 dib7000m_write_word(state, 910, (1 << 12) | (2 << 10) | (bw->modulo << 8) | (bw->ADClkSrc << 7));
340
341 dib7000m_reset_pll_common(state, bw);
342}
343
344static int dib7000m_reset_gpio(struct dib7000m_state *st)
345{
346 /* reset the GPIOs */
347 dprintk("-D- gpio dir: %x: gpio val: %x, gpio pwm pos: %x\n",
348 st->cfg.gpio_dir, st->cfg.gpio_val,st->cfg.gpio_pwm_pos);
349
350 dib7000m_write_word(st, 773, st->cfg.gpio_dir);
351 dib7000m_write_word(st, 774, st->cfg.gpio_val);
352
353 /* TODO 782 is P_gpio_od */
354
355 dib7000m_write_word(st, 775, st->cfg.gpio_pwm_pos);
356
357 dib7000m_write_word(st, 780, st->cfg.pwm_freq_div);
358 return 0;
359}
360
361static int dib7000m_demod_reset(struct dib7000m_state *state)
362{
363 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL);
364
365 /* always leave the VBG voltage on - it consumes almost nothing but takes a long time to start */
366 dib7000m_set_adc_state(state, DIBX000_VBG_ENABLE);
367
368 /* restart all parts */
369 dib7000m_write_word(state, 898, 0xffff);
370 dib7000m_write_word(state, 899, 0xffff);
371 dib7000m_write_word(state, 900, 0xff0f);
372 dib7000m_write_word(state, 901, 0xfffc);
373
374 dib7000m_write_word(state, 898, 0);
375 dib7000m_write_word(state, 899, 0);
376 dib7000m_write_word(state, 900, 0);
377 dib7000m_write_word(state, 901, 0);
378
379 if (state->revision == 0x4000)
380 dib7000m_reset_pll(state);
381 else
382 dib7000mc_reset_pll(state);
383
384 if (dib7000m_reset_gpio(state) != 0)
385 dprintk("-E- GPIO reset was not successful.\n");
386
387 if (dib7000m_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
388 dprintk("-E- OUTPUT_MODE could not be resetted.\n");
389
390 /* unforce divstr regardless whether i2c enumeration was done or not */
391 dib7000m_write_word(state, 1794, dib7000m_read_word(state, 1794) & ~(1 << 1) );
392
393 dib7000m_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ);
394
395 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON);
396 dib7000m_sad_calib(state);
397 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
398
399 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERFACE_ONLY);
400
401 return 0;
402}
403
404static void dib7000m_restart_agc(struct dib7000m_state *state)
405{
406 // P_restart_iqc & P_restart_agc
407 dib7000m_write_word(state, 898, 0x0c00);
408 dib7000m_write_word(state, 898, 0x0000);
409}
410
411static int dib7000m_agc_soft_split(struct dib7000m_state *state)
412{
413 u16 agc,split_offset;
414
415 if(!state->current_agc || !state->current_agc->perform_agc_softsplit || state->current_agc->split.max == 0)
416 return 0;
417
418 // n_agc_global
419 agc = dib7000m_read_word(state, 390);
420
421 if (agc > state->current_agc->split.min_thres)
422 split_offset = state->current_agc->split.min;
423 else if (agc < state->current_agc->split.max_thres)
424 split_offset = state->current_agc->split.max;
425 else
426 split_offset = state->current_agc->split.max *
427 (agc - state->current_agc->split.min_thres) /
428 (state->current_agc->split.max_thres - state->current_agc->split.min_thres);
429
430 dprintk("AGC split_offset: %d\n",split_offset);
431
432 // P_agc_force_split and P_agc_split_offset
433 return dib7000m_write_word(state, 103, (dib7000m_read_word(state, 103) & 0xff00) | split_offset);
434}
435
436static int dib7000m_update_lna(struct dib7000m_state *state)
437{
438 int i;
439 u16 dyn_gain;
440
441 // when there is no LNA to program return immediatly
442 if (state->cfg.update_lna == NULL)
443 return 0;
444
445 msleep(60);
446 for (i = 0; i < 20; i++) {
447 // read dyn_gain here (because it is demod-dependent and not tuner)
448 dyn_gain = dib7000m_read_word(state, 390);
449
450 dprintk("agc global: %d\n", dyn_gain);
451
452 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed
453 dib7000m_restart_agc(state);
454 msleep(60);
455 } else
456 break;
457 }
458 return 0;
459}
460
461static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
462{
463 struct dibx000_agc_config *agc = NULL;
464 int i;
465 if (state->current_band == band)
466 return;
467 state->current_band = band;
468
469 for (i = 0; i < state->cfg.agc_config_count; i++)
470 if (state->cfg.agc[i].band_caps & band) {
471 agc = &state->cfg.agc[i];
472 break;
473 }
474
475 if (agc == NULL) {
476 dprintk("-E- No valid AGC configuration found for band 0x%02x\n",band);
477 return;
478 }
479
480 state->current_agc = agc;
481
482 /* AGC */
483 dib7000m_write_word(state, 72 , agc->setup);
484 dib7000m_write_word(state, 73 , agc->inv_gain);
485 dib7000m_write_word(state, 74 , agc->time_stabiliz);
486 dib7000m_write_word(state, 97 , (agc->alpha_level << 12) | agc->thlock);
487
488 // Demod AGC loop configuration
489 dib7000m_write_word(state, 98, (agc->alpha_mant << 5) | agc->alpha_exp);
490 dib7000m_write_word(state, 99, (agc->beta_mant << 6) | agc->beta_exp);
491
492 dprintk("-D- WBD: ref: %d, sel: %d, active: %d, alpha: %d\n",
493 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
494
495 /* AGC continued */
496 if (state->wbd_ref != 0)
497 dib7000m_write_word(state, 102, state->wbd_ref);
498 else // use default
499 dib7000m_write_word(state, 102, agc->wbd_ref);
500
501 dib7000m_write_word(state, 103, (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8) );
502 dib7000m_write_word(state, 104, agc->agc1_max);
503 dib7000m_write_word(state, 105, agc->agc1_min);
504 dib7000m_write_word(state, 106, agc->agc2_max);
505 dib7000m_write_word(state, 107, agc->agc2_min);
506 dib7000m_write_word(state, 108, (agc->agc1_pt1 << 8) | agc->agc1_pt2 );
507 dib7000m_write_word(state, 109, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
508 dib7000m_write_word(state, 110, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
509 dib7000m_write_word(state, 111, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
510
511 if (state->revision > 0x4000) { // settings for the MC
512 dib7000m_write_word(state, 71, agc->agc1_pt3);
513// dprintk("-D- 929: %x %d %d\n",
514// (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2), agc->wbd_inv, agc->wbd_sel);
515 dib7000m_write_word(state, 929, (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2));
516 } else {
517 // wrong default values
518 u16 b[9] = { 676, 696, 717, 737, 758, 778, 799, 819, 840 };
519 for (i = 0; i < 9; i++)
520 dib7000m_write_word(state, 88 + i, b[i]);
521 }
522}
523
524static void dib7000m_update_timf_freq(struct dib7000m_state *state)
525{
526 u32 timf = (dib7000m_read_word(state, 436) << 16) | dib7000m_read_word(state, 437);
527 state->timf = timf * 80 / (BW_INDEX_TO_KHZ(state->current_bandwidth) / 100);
528 dib7000m_write_word(state, 23, (u16) (timf >> 16));
529 dib7000m_write_word(state, 24, (u16) (timf & 0xffff));
530 dprintk("-D- Updated timf_frequency: %d (default: %d)\n",state->timf, state->cfg.bw->timf);
531}
532
533static void dib7000m_set_channel(struct dib7000m_state *state, struct dibx000_ofdm_channel *ch, u8 seq)
534{
535 u16 value, est[4];
536
537 dib7000m_set_agc_config(state, BAND_OF_FREQUENCY(ch->RF_kHz));
538
539 /* nfft, guard, qam, alpha */
540 dib7000m_write_word(state, 0, (ch->nfft << 7) | (ch->guard << 5) | (ch->nqam << 3) | (ch->vit_alpha));
541 dib7000m_write_word(state, 5, (seq << 4));
542
543 /* P_dintl_native, P_dintlv_inv, P_vit_hrch, P_vit_code_rate, P_vit_select_hp */
544 value = (ch->intlv_native << 6) | (ch->vit_hrch << 4) | (ch->vit_select_hp & 0x1);
545 if (ch->vit_hrch == 0 || ch->vit_select_hp == 1)
546 value |= (ch->vit_code_rate_hp << 1);
547 else
548 value |= (ch->vit_code_rate_lp << 1);
549 dib7000m_write_word(state, 267 + state->reg_offs, value);
550
551 /* offset loop parameters */
552
553 /* P_timf_alpha = 6, P_corm_alpha=6, P_corm_thres=0x80 */
554 dib7000m_write_word(state, 26, (6 << 12) | (6 << 8) | 0x80);
555
556 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=1, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
557 dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (1 << 9) | (3 << 5) | (1 << 4) | (0x3));
558
559 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max=3 */
560 dib7000m_write_word(state, 32, (0 << 4) | 0x3);
561
562 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step=5 */
563 dib7000m_write_word(state, 33, (0 << 4) | 0x5);
564
565 /* P_dvsy_sync_wait */
566 switch (ch->nfft) {
567 case 1: value = 256; break;
568 case 2: value = 128; break;
569 case 0:
570 default: value = 64; break;
571 }
572 value *= ((1 << (ch->guard)) * 3 / 2); // add 50% SFN margin
573 value <<= 4;
574
575 /* deactive the possibility of diversity reception if extended interleave - not for 7000MC */
576 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */
577 if (ch->intlv_native || state->revision > 0x4000)
578 value |= (1 << 2) | (2 << 0);
579 else
580 value |= 0;
581 dib7000m_write_word(state, 266 + state->reg_offs, value);
582
583 /* channel estimation fine configuration */
584 switch (ch->nqam) {
585 case 2:
586 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
587 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
588 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
589 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
590 break;
591 case 1:
592 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
593 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
594 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
595 est[3] = 0xfff0; /* P_adp_noise_ext -0.002 */
596 break;
597 default:
598 est[0] = 0x099a; /* P_adp_regul_cnt 0.3 */
599 est[1] = 0xffae; /* P_adp_noise_cnt -0.01 */
600 est[2] = 0x0333; /* P_adp_regul_ext 0.1 */
601 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
602 break;
603 }
604 for (value = 0; value < 4; value++)
605 dib7000m_write_word(state, 214 + value + state->reg_offs, est[value]);
606
607 // set power-up level: interf+analog+AGC
608 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERF_ANALOG_AGC);
609 dib7000m_set_adc_state(state, DIBX000_ADC_ON);
610
611 msleep(7);
612
613 //AGC initialization
614 if (state->cfg.agc_control)
615 state->cfg.agc_control(&state->demod, 1);
616
617 dib7000m_restart_agc(state);
618
619 // wait AGC rough lock time
620 msleep(5);
621
622 dib7000m_update_lna(state);
623 dib7000m_agc_soft_split(state);
624
625 // wait AGC accurate lock time
626 msleep(7);
627
628 if (state->cfg.agc_control)
629 state->cfg.agc_control(&state->demod, 0);
630
631 // set power-up level: autosearch
632 dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD);
633}
634
635static int dib7000m_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch)
636{
637 struct dib7000m_state *state = demod->demodulator_priv;
638 struct dibx000_ofdm_channel auto_ch;
639 int ret = 0;
640 u32 value;
641
642 INIT_OFDM_CHANNEL(&auto_ch);
643 auto_ch.RF_kHz = ch->RF_kHz;
644 auto_ch.Bw = ch->Bw;
645 auto_ch.nqam = 2;
646 auto_ch.guard = 0;
647 auto_ch.nfft = 1;
648 auto_ch.vit_alpha = 1;
649 auto_ch.vit_select_hp = 1;
650 auto_ch.vit_code_rate_hp = 2;
651 auto_ch.vit_code_rate_lp = 3;
652 auto_ch.vit_hrch = 0;
653 auto_ch.intlv_native = 1;
654
655 dib7000m_set_channel(state, &auto_ch, 7);
656
657 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer
658 value = 30 * state->cfg.bw->internal;
659 ret |= dib7000m_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time
660 ret |= dib7000m_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time
661 value = 100 * state->cfg.bw->internal;
662 ret |= dib7000m_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time
663 ret |= dib7000m_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time
664 value = 500 * state->cfg.bw->internal;
665 ret |= dib7000m_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time
666 ret |= dib7000m_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time
667
668 // start search
669 value = dib7000m_read_word(state, 0);
670 ret |= dib7000m_write_word(state, 0, value | (1 << 9));
671
672 /* clear n_irq_pending */
673 if (state->revision == 0x4000)
674 dib7000m_write_word(state, 1793, 0);
675 else
676 dib7000m_read_word(state, 537);
677
678 ret |= dib7000m_write_word(state, 0, (u16) value);
679
680 return ret;
681}
682
683static int dib7000m_autosearch_irq(struct dib7000m_state *state, u16 reg)
684{
685 u16 irq_pending = dib7000m_read_word(state, reg);
686
687 if (irq_pending & 0x1) { // failed
688 dprintk("#\n");
689 return 1;
690 }
691
692 if (irq_pending & 0x2) { // succeeded
693 dprintk("!\n");
694 return 2;
695 }
696 return 0; // still pending
697}
698
699static int dib7000m_autosearch_is_irq(struct dvb_frontend *demod)
700{
701 struct dib7000m_state *state = demod->demodulator_priv;
702 if (state->revision == 0x4000)
703 return dib7000m_autosearch_irq(state, 1793);
704 else
705 return dib7000m_autosearch_irq(state, 537);
706}
707
708static int dib7000m_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch)
709{
710 struct dib7000m_state *state = demod->demodulator_priv;
711 int ret = 0;
712 u16 value;
713
714 // we are already tuned - just resuming from suspend
715 if (ch != NULL)
716 dib7000m_set_channel(state, ch, 0);
717 else
718 return -EINVAL;
719
720 // restart demod
721 ret |= dib7000m_write_word(state, 898, 0x4000);
722 ret |= dib7000m_write_word(state, 898, 0x0000);
723 msleep(45);
724
725 ret |= dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_CRY_ESRAM_MOUT_NUD);
726 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
727 ret |= dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3));
728
729 // never achieved a lock with that bandwidth so far - wait for timfreq to update
730 if (state->timf == 0)
731 msleep(200);
732
733 //dump_reg(state);
734 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
735 value = (6 << 8) | 0x80;
736 switch (ch->nfft) {
737 case 0: value |= (7 << 12); break;
738 case 1: value |= (9 << 12); break;
739 case 2: value |= (8 << 12); break;
740 }
741 ret |= dib7000m_write_word(state, 26, value);
742
743 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
744 value = (0 << 4);
745 switch (ch->nfft) {
746 case 0: value |= 0x6; break;
747 case 1: value |= 0x8; break;
748 case 2: value |= 0x7; break;
749 }
750 ret |= dib7000m_write_word(state, 32, value);
751
752 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
753 value = (0 << 4);
754 switch (ch->nfft) {
755 case 0: value |= 0x6; break;
756 case 1: value |= 0x8; break;
757 case 2: value |= 0x7; break;
758 }
759 ret |= dib7000m_write_word(state, 33, value);
760
761 // we achieved a lock - it's time to update the osc freq
762 if ((dib7000m_read_word(state, 535) >> 6) & 0x1)
763 dib7000m_update_timf_freq(state);
764
765 return ret;
766}
767
768static int dib7000m_init(struct dvb_frontend *demod)
769{
770 struct dib7000m_state *state = demod->demodulator_priv;
771 int ret = 0;
772 u8 o = state->reg_offs;
773
774 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL);
775
776 if (dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0)
777 dprintk("-E- could not start Slow ADC\n");
778
779 if (state->cfg.dvbt_mode)
780 dib7000m_write_word(state, 1796, 0x0); // select DVB-T output
781
782 if (state->cfg.mobile_mode)
783 ret |= dib7000m_write_word(state, 261 + o, 2);
784 else
785 ret |= dib7000m_write_word(state, 224 + o, 1);
786
787 ret |= dib7000m_write_word(state, 173 + o, 0);
788 ret |= dib7000m_write_word(state, 174 + o, 0);
789 ret |= dib7000m_write_word(state, 175 + o, 0);
790 ret |= dib7000m_write_word(state, 176 + o, 0);
791 ret |= dib7000m_write_word(state, 177 + o, 0);
792 ret |= dib7000m_write_word(state, 178 + o, 0);
793 ret |= dib7000m_write_word(state, 179 + o, 0);
794 ret |= dib7000m_write_word(state, 180 + o, 0);
795
796 // P_corm_thres Lock algorithms configuration
797 ret |= dib7000m_write_word(state, 26, 0x6680);
798
799 // P_palf_alpha_regul, P_palf_filter_freeze, P_palf_filter_on
800 ret |= dib7000m_write_word(state, 170 + o, 0x0410);
801 // P_fft_nb_to_cut
802 ret |= dib7000m_write_word(state, 182 + o, 8192);
803 // P_pha3_thres
804 ret |= dib7000m_write_word(state, 195 + o, 0x0ccd);
805 // P_cti_use_cpe, P_cti_use_prog
806 ret |= dib7000m_write_word(state, 196 + o, 0);
807 // P_cspu_regul, P_cspu_win_cut
808 ret |= dib7000m_write_word(state, 205 + o, 0x200f);
809 // P_adp_regul_cnt
810 ret |= dib7000m_write_word(state, 214 + o, 0x023d);
811 // P_adp_noise_cnt
812 ret |= dib7000m_write_word(state, 215 + o, 0x00a4);
813 // P_adp_regul_ext
814 ret |= dib7000m_write_word(state, 216 + o, 0x00a4);
815 // P_adp_noise_ext
816 ret |= dib7000m_write_word(state, 217 + o, 0x7ff0);
817 // P_adp_fil
818 ret |= dib7000m_write_word(state, 218 + o, 0x3ccc);
819
820 // P_2d_byp_ti_num
821 ret |= dib7000m_write_word(state, 226 + o, 0);
822
823 // P_fec_*
824 ret |= dib7000m_write_word(state, 281 + o, 0x0010);
825 // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
826 ret |= dib7000m_write_word(state, 294 + o,0x0062);
827
828 // P_iqc_alpha_pha, P_iqc_alpha_amp, P_iqc_dcc_alpha, ...
829 if(state->cfg.tuner_is_baseband)
830 ret |= dib7000m_write_word(state, 36, 0x0755);
831 else
832 ret |= dib7000m_write_word(state, 36, 0x1f55);
833
834 // auto search configuration
835 ret |= dib7000m_write_word(state, 2, 0x0004);
836 ret |= dib7000m_write_word(state, 3, 0x1000);
837 ret |= dib7000m_write_word(state, 4, 0x0814);
838 ret |= dib7000m_write_word(state, 6, 0x001b);
839 ret |= dib7000m_write_word(state, 7, 0x7740);
840 ret |= dib7000m_write_word(state, 8, 0x005b);
841 ret |= dib7000m_write_word(state, 9, 0x8d80);
842 ret |= dib7000m_write_word(state, 10, 0x01c9);
843 ret |= dib7000m_write_word(state, 11, 0xc380);
844 ret |= dib7000m_write_word(state, 12, 0x0000);
845 ret |= dib7000m_write_word(state, 13, 0x0080);
846 ret |= dib7000m_write_word(state, 14, 0x0000);
847 ret |= dib7000m_write_word(state, 15, 0x0090);
848 ret |= dib7000m_write_word(state, 16, 0x0001);
849 ret |= dib7000m_write_word(state, 17, 0xd4c0);
850 ret |= dib7000m_write_word(state, 263 + o,0x0001);
851
852 // P_divclksel=3 P_divbitsel=1
853 if (state->revision == 0x4000)
854 dib7000m_write_word(state, 909, (3 << 10) | (1 << 6));
855 else
856 dib7000m_write_word(state, 909, (3 << 4) | 1);
857
858 // Tuner IO bank: max drive (14mA)
859 ret |= dib7000m_write_word(state, 912 ,0x2c8a);
860
861 ret |= dib7000m_write_word(state, 1817, 1);
862
863 return ret;
864}
865
866static int dib7000m_sleep(struct dvb_frontend *demod)
867{
868 struct dib7000m_state *st = demod->demodulator_priv;
869 dib7000m_set_output_mode(st, OUTMODE_HIGH_Z);
870 return dib7000m_set_power_mode(st, DIB7000M_POWER_INTERFACE_ONLY) |
871 dib7000m_set_adc_state(st, DIBX000_SLOW_ADC_OFF) |
872 dib7000m_set_adc_state(st, DIBX000_ADC_OFF);
873}
874
875static int dib7000m_identify(struct dib7000m_state *state)
876{
877 u16 value;
878 if ((value = dib7000m_read_word(state, 896)) != 0x01b3) {
879 dprintk("-E- DiB7000M: wrong Vendor ID (read=0x%x)\n",value);
880 return -EREMOTEIO;
881 }
882
883 state->revision = dib7000m_read_word(state, 897);
884 if (state->revision != 0x4000 &&
885 state->revision != 0x4001 &&
886 state->revision != 0x4002) {
887 dprintk("-E- DiB7000M: wrong Device ID (%x)\n",value);
888 return -EREMOTEIO;
889 }
890
891 /* protect this driver to be used with 7000PC */
892 if (state->revision == 0x4000 && dib7000m_read_word(state, 769) == 0x4000) {
893 dprintk("-E- DiB7000M: this driver does not work with DiB7000PC\n");
894 return -EREMOTEIO;
895 }
896
897 switch (state->revision) {
898 case 0x4000: dprintk("-I- found DiB7000MA/PA/MB/PB\n"); break;
899 case 0x4001: state->reg_offs = 1; dprintk("-I- found DiB7000HC\n"); break;
900 case 0x4002: state->reg_offs = 1; dprintk("-I- found DiB7000MC\n"); break;
901 }
902
903 return 0;
904}
905
906
907static int dib7000m_get_frontend(struct dvb_frontend* fe,
908 struct dvb_frontend_parameters *fep)
909{
910 struct dib7000m_state *state = fe->demodulator_priv;
911 u16 tps = dib7000m_read_word(state,480);
912
913 fep->inversion = INVERSION_AUTO;
914
915 fep->u.ofdm.bandwidth = state->current_bandwidth;
916
917 switch ((tps >> 8) & 0x3) {
918 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break;
919 case 1: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; break;
920 /* case 2: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_4K; break; */
921 }
922
923 switch (tps & 0x3) {
924 case 0: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_32; break;
925 case 1: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_16; break;
926 case 2: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_8; break;
927 case 3: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_4; break;
928 }
929
930 switch ((tps >> 14) & 0x3) {
931 case 0: fep->u.ofdm.constellation = QPSK; break;
932 case 1: fep->u.ofdm.constellation = QAM_16; break;
933 case 2:
934 default: fep->u.ofdm.constellation = QAM_64; break;
935 }
936
937 /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */
938 /* (tps >> 13) & 0x1 == hrch is used, (tps >> 10) & 0x7 == alpha */
939
940 fep->u.ofdm.hierarchy_information = HIERARCHY_NONE;
941 switch ((tps >> 5) & 0x7) {
942 case 1: fep->u.ofdm.code_rate_HP = FEC_1_2; break;
943 case 2: fep->u.ofdm.code_rate_HP = FEC_2_3; break;
944 case 3: fep->u.ofdm.code_rate_HP = FEC_3_4; break;
945 case 5: fep->u.ofdm.code_rate_HP = FEC_5_6; break;
946 case 7:
947 default: fep->u.ofdm.code_rate_HP = FEC_7_8; break;
948
949 }
950
951 switch ((tps >> 2) & 0x7) {
952 case 1: fep->u.ofdm.code_rate_LP = FEC_1_2; break;
953 case 2: fep->u.ofdm.code_rate_LP = FEC_2_3; break;
954 case 3: fep->u.ofdm.code_rate_LP = FEC_3_4; break;
955 case 5: fep->u.ofdm.code_rate_LP = FEC_5_6; break;
956 case 7:
957 default: fep->u.ofdm.code_rate_LP = FEC_7_8; break;
958 }
959
960 /* native interleaver: (dib7000m_read_word(state, 481) >> 5) & 0x1 */
961
962 return 0;
963}
964
965static int dib7000m_set_frontend(struct dvb_frontend* fe,
966 struct dvb_frontend_parameters *fep)
967{
968 struct dib7000m_state *state = fe->demodulator_priv;
969 struct dibx000_ofdm_channel ch;
970
971 INIT_OFDM_CHANNEL(&ch);
972 FEP2DIB(fep,&ch);
973
974 state->current_bandwidth = fep->u.ofdm.bandwidth;
975 dib7000m_set_bandwidth(fe, fep->u.ofdm.bandwidth);
976
977 if (fe->ops.tuner_ops.set_params)
978 fe->ops.tuner_ops.set_params(fe, fep);
979
980 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
981 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
982 fep->u.ofdm.constellation == QAM_AUTO ||
983 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
984 int i = 800, found;
985
986 dib7000m_autosearch_start(fe, &ch);
987 do {
988 msleep(1);
989 found = dib7000m_autosearch_is_irq(fe);
990 } while (found == 0 && i--);
991
992 dprintk("autosearch returns: %d\n",found);
993 if (found == 0 || found == 1)
994 return 0; // no channel found
995
996 dib7000m_get_frontend(fe, fep);
997 FEP2DIB(fep, &ch);
998 }
999
1000 /* make this a config parameter */
1001 dib7000m_set_output_mode(state, OUTMODE_MPEG2_FIFO);
1002
1003 return dib7000m_tune(fe, &ch);
1004}
1005
1006static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat)
1007{
1008 struct dib7000m_state *state = fe->demodulator_priv;
1009 u16 lock = dib7000m_read_word(state, 535);
1010
1011 *stat = 0;
1012
1013 if (lock & 0x8000)
1014 *stat |= FE_HAS_SIGNAL;
1015 if (lock & 0x3000)
1016 *stat |= FE_HAS_CARRIER;
1017 if (lock & 0x0100)
1018 *stat |= FE_HAS_VITERBI;
1019 if (lock & 0x0010)
1020 *stat |= FE_HAS_SYNC;
1021 if (lock & 0x0008)
1022 *stat |= FE_HAS_LOCK;
1023
1024 return 0;
1025}
1026
1027static int dib7000m_read_ber(struct dvb_frontend *fe, u32 *ber)
1028{
1029 struct dib7000m_state *state = fe->demodulator_priv;
1030 *ber = (dib7000m_read_word(state, 526) << 16) | dib7000m_read_word(state, 527);
1031 return 0;
1032}
1033
1034static int dib7000m_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
1035{
1036 struct dib7000m_state *state = fe->demodulator_priv;
1037 *unc = dib7000m_read_word(state, 534);
1038 return 0;
1039}
1040
1041static int dib7000m_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1042{
1043 struct dib7000m_state *state = fe->demodulator_priv;
1044 u16 val = dib7000m_read_word(state, 390);
1045 *strength = 65535 - val;
1046 return 0;
1047}
1048
1049static int dib7000m_read_snr(struct dvb_frontend* fe, u16 *snr)
1050{
1051 *snr = 0x0000;
1052 return 0;
1053}
1054
1055static int dib7000m_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
1056{
1057 tune->min_delay_ms = 1000;
1058 return 0;
1059}
1060
1061static void dib7000m_release(struct dvb_frontend *demod)
1062{
1063 struct dib7000m_state *st = demod->demodulator_priv;
1064 dibx000_exit_i2c_master(&st->i2c_master);
1065 kfree(st);
1066}
1067
1068struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating)
1069{
1070 struct dib7000m_state *st = demod->demodulator_priv;
1071 return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
1072}
1073EXPORT_SYMBOL(dib7000m_get_i2c_master);
1074
1075int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000m_config cfg[])
1076{
1077 struct dib7000m_state st = { .i2c_adap = i2c };
1078 int k = 0;
1079 u8 new_addr = 0;
1080
1081 for (k = no_of_demods-1; k >= 0; k--) {
1082 st.cfg = cfg[k];
1083
1084 /* designated i2c address */
1085 new_addr = (0x40 + k) << 1;
1086 st.i2c_addr = new_addr;
1087 if (dib7000m_identify(&st) != 0) {
1088 st.i2c_addr = default_addr;
1089 if (dib7000m_identify(&st) != 0) {
1090 dprintk("DiB7000M #%d: not identified\n", k);
1091 return -EIO;
1092 }
1093 }
1094
1095 /* start diversity to pull_down div_str - just for i2c-enumeration */
1096 dib7000m_set_output_mode(&st, OUTMODE_DIVERSITY);
1097
1098 dib7000m_write_word(&st, 1796, 0x0); // select DVB-T output
1099
1100 /* set new i2c address and force divstart */
1101 dib7000m_write_word(&st, 1794, (new_addr << 2) | 0x2);
1102
1103 dprintk("IC %d initialized (to i2c_address 0x%x)\n", k, new_addr);
1104 }
1105
1106 for (k = 0; k < no_of_demods; k++) {
1107 st.cfg = cfg[k];
1108 st.i2c_addr = (0x40 + k) << 1;
1109
1110 // unforce divstr
1111 dib7000m_write_word(&st,1794, st.i2c_addr << 2);
1112
1113 /* deactivate div - it was just for i2c-enumeration */
1114 dib7000m_set_output_mode(&st, OUTMODE_HIGH_Z);
1115 }
1116
1117 return 0;
1118}
1119EXPORT_SYMBOL(dib7000m_i2c_enumeration);
1120
1121static struct dvb_frontend_ops dib7000m_ops;
1122struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg)
1123{
1124 struct dvb_frontend *demod;
1125 struct dib7000m_state *st;
1126 st = kzalloc(sizeof(struct dib7000m_state), GFP_KERNEL);
1127 if (st == NULL)
1128 return NULL;
1129
1130 memcpy(&st->cfg, cfg, sizeof(struct dib7000m_config));
1131 st->i2c_adap = i2c_adap;
1132 st->i2c_addr = i2c_addr;
1133
1134 demod = &st->demod;
1135 demod->demodulator_priv = st;
1136 memcpy(&st->demod.ops, &dib7000m_ops, sizeof(struct dvb_frontend_ops));
1137
1138 if (dib7000m_identify(st) != 0)
1139 goto error;
1140
1141 if (st->revision == 0x4000)
1142 dibx000_init_i2c_master(&st->i2c_master, DIB7000, st->i2c_adap, st->i2c_addr);
1143 else
1144 dibx000_init_i2c_master(&st->i2c_master, DIB7000MC, st->i2c_adap, st->i2c_addr);
1145
1146 dib7000m_demod_reset(st);
1147
1148 return demod;
1149
1150error:
1151 kfree(st);
1152 return NULL;
1153}
1154EXPORT_SYMBOL(dib7000m_attach);
1155
1156static struct dvb_frontend_ops dib7000m_ops = {
1157 .info = {
1158 .name = "DiBcom 7000MA/MB/PA/PB/MC",
1159 .type = FE_OFDM,
1160 .frequency_min = 44250000,
1161 .frequency_max = 867250000,
1162 .frequency_stepsize = 62500,
1163 .caps = FE_CAN_INVERSION_AUTO |
1164 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1165 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1166 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
1167 FE_CAN_TRANSMISSION_MODE_AUTO |
1168 FE_CAN_GUARD_INTERVAL_AUTO |
1169 FE_CAN_RECOVER |
1170 FE_CAN_HIERARCHY_AUTO,
1171 },
1172
1173 .release = dib7000m_release,
1174
1175 .init = dib7000m_init,
1176 .sleep = dib7000m_sleep,
1177
1178 .set_frontend = dib7000m_set_frontend,
1179 .get_tune_settings = dib7000m_fe_get_tune_settings,
1180 .get_frontend = dib7000m_get_frontend,
1181
1182 .read_status = dib7000m_read_status,
1183 .read_ber = dib7000m_read_ber,
1184 .read_signal_strength = dib7000m_read_signal_strength,
1185 .read_snr = dib7000m_read_snr,
1186 .read_ucblocks = dib7000m_read_unc_blocks,
1187};
1188
1189MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
1190MODULE_DESCRIPTION("Driver for the DiBcom 7000MA/MB/PA/PB/MC COFDM demodulator");
1191MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib7000m.h b/drivers/media/dvb/frontends/dib7000m.h
new file mode 100644
index 000000000000..597e9cc2da62
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib7000m.h
@@ -0,0 +1,51 @@
1#ifndef DIB7000M_H
2#define DIB7000M_H
3
4#include "dibx000_common.h"
5
6struct dib7000m_config {
7 u8 dvbt_mode;
8 u8 output_mpeg2_in_188_bytes;
9 u8 hostbus_diversity;
10 u8 tuner_is_baseband;
11 u8 mobile_mode;
12 int (*update_lna) (struct dvb_frontend *, u16 agc_global);
13
14 u8 agc_config_count;
15 struct dibx000_agc_config *agc;
16
17 struct dibx000_bandwidth_config *bw;
18
19#define DIB7000M_GPIO_DEFAULT_DIRECTIONS 0xffff
20 u16 gpio_dir;
21#define DIB7000M_GPIO_DEFAULT_VALUES 0x0000
22 u16 gpio_val;
23#define DIB7000M_GPIO_PWM_POS0(v) ((v & 0xf) << 12)
24#define DIB7000M_GPIO_PWM_POS1(v) ((v & 0xf) << 8 )
25#define DIB7000M_GPIO_PWM_POS2(v) ((v & 0xf) << 4 )
26#define DIB7000M_GPIO_PWM_POS3(v) (v & 0xf)
27#define DIB7000M_GPIO_DEFAULT_PWM_POS 0xffff
28 u16 gpio_pwm_pos;
29
30 u16 pwm_freq_div;
31
32 u8 quartz_direct;
33
34 u8 input_clk_is_div_2;
35
36 int (*agc_control) (struct dvb_frontend *, u8 before);
37};
38
39#define DEFAULT_DIB7000M_I2C_ADDRESS 18
40
41extern struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg);
42extern struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
43
44/* TODO
45extern INT dib7000m_set_gpio(struct dibDemod *demod, UCHAR num, UCHAR dir, UCHAR val);
46extern INT dib7000m_enable_vbg_voltage(struct dibDemod *demod);
47extern void dib7000m_set_hostbus_diversity(struct dibDemod *demod, UCHAR onoff);
48extern USHORT dib7000m_get_current_agc_global(struct dibDemod *demod);
49*/
50
51#endif
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
new file mode 100644
index 000000000000..0349a4b5da3f
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -0,0 +1,1019 @@
1/*
2 * Linux-DVB Driver for DiBcom's second generation DiB7000P (PC).
3 *
4 * Copyright (C) 2005-6 DiBcom (http://www.dibcom.fr/)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10#include <linux/kernel.h>
11#include <linux/i2c.h>
12
13#include "dvb_frontend.h"
14
15#include "dib7000p.h"
16
17static int debug;
18module_param(debug, int, 0644);
19MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
20
21#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P:"); printk(args); } } while (0)
22
23struct dib7000p_state {
24 struct dvb_frontend demod;
25 struct dib7000p_config cfg;
26
27 u8 i2c_addr;
28 struct i2c_adapter *i2c_adap;
29
30 struct dibx000_i2c_master i2c_master;
31
32 u16 wbd_ref;
33
34 u8 current_band;
35 fe_bandwidth_t current_bandwidth;
36 struct dibx000_agc_config *current_agc;
37 u32 timf;
38
39 u16 gpio_dir;
40 u16 gpio_val;
41};
42
43enum dib7000p_power_mode {
44 DIB7000P_POWER_ALL = 0,
45 DIB7000P_POWER_INTERFACE_ONLY,
46};
47
48static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
49{
50 u8 wb[2] = { reg >> 8, reg & 0xff };
51 u8 rb[2];
52 struct i2c_msg msg[2] = {
53 { .addr = state->i2c_addr >> 1, .flags = 0, .buf = wb, .len = 2 },
54 { .addr = state->i2c_addr >> 1, .flags = I2C_M_RD, .buf = rb, .len = 2 },
55 };
56
57 if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
58 dprintk("i2c read error on %d\n",reg);
59
60 return (rb[0] << 8) | rb[1];
61}
62
63static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
64{
65 u8 b[4] = {
66 (reg >> 8) & 0xff, reg & 0xff,
67 (val >> 8) & 0xff, val & 0xff,
68 };
69 struct i2c_msg msg = {
70 .addr = state->i2c_addr >> 1, .flags = 0, .buf = b, .len = 4
71 };
72 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
73}
74static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
75{
76 int ret = 0;
77 u16 outreg, fifo_threshold, smo_mode;
78
79 outreg = 0;
80 fifo_threshold = 1792;
81 smo_mode = (dib7000p_read_word(state, 235) & 0x0010) | (1 << 1);
82
83 dprintk("-I- Setting output mode for demod %p to %d\n",
84 &state->demod, mode);
85
86 switch (mode) {
87 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
88 outreg = (1 << 10); /* 0x0400 */
89 break;
90 case OUTMODE_MPEG2_PAR_CONT_CLK: // STBs with parallel continues clock
91 outreg = (1 << 10) | (1 << 6); /* 0x0440 */
92 break;
93 case OUTMODE_MPEG2_SERIAL: // STBs with serial input
94 outreg = (1 << 10) | (2 << 6) | (0 << 1); /* 0x0480 */
95 break;
96 case OUTMODE_DIVERSITY:
97 if (state->cfg.hostbus_diversity)
98 outreg = (1 << 10) | (4 << 6); /* 0x0500 */
99 else
100 outreg = (1 << 11);
101 break;
102 case OUTMODE_MPEG2_FIFO: // e.g. USB feeding
103 smo_mode |= (3 << 1);
104 fifo_threshold = 512;
105 outreg = (1 << 10) | (5 << 6);
106 break;
107 case OUTMODE_HIGH_Z: // disable
108 outreg = 0;
109 break;
110 default:
111 dprintk("Unhandled output_mode passed to be set for demod %p\n",&state->demod);
112 break;
113 }
114
115 if (state->cfg.output_mpeg2_in_188_bytes)
116 smo_mode |= (1 << 5) ;
117
118 ret |= dib7000p_write_word(state, 235, smo_mode);
119 ret |= dib7000p_write_word(state, 236, fifo_threshold); /* synchronous fread */
120 ret |= dib7000p_write_word(state, 1286, outreg); /* P_Div_active */
121
122 return ret;
123}
124
125static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode)
126{
127 /* by default everything is powered off */
128 u16 reg_774 = 0xffff, reg_775 = 0xffff, reg_776 = 0x0007, reg_899 = 0x0003,
129 reg_1280 = (0xfe00) | (dib7000p_read_word(state, 1280) & 0x01ff);
130
131 /* now, depending on the requested mode, we power on */
132 switch (mode) {
133 /* power up everything in the demod */
134 case DIB7000P_POWER_ALL:
135 reg_774 = 0x0000; reg_775 = 0x0000; reg_776 = 0x0; reg_899 = 0x0; reg_1280 &= 0x01ff;
136 break;
137 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */
138 case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */
139 reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10));
140 break;
141/* TODO following stuff is just converted from the dib7000-driver - check when is used what */
142 }
143
144 dib7000p_write_word(state, 774, reg_774);
145 dib7000p_write_word(state, 775, reg_775);
146 dib7000p_write_word(state, 776, reg_776);
147 dib7000p_write_word(state, 899, reg_899);
148 dib7000p_write_word(state, 1280, reg_1280);
149
150 return 0;
151}
152
153static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_adc_states no)
154{
155 u16 reg_908 = dib7000p_read_word(state, 908),
156 reg_909 = dib7000p_read_word(state, 909);
157
158 switch (no) {
159 case DIBX000_SLOW_ADC_ON:
160 reg_909 |= (1 << 1) | (1 << 0);
161 dib7000p_write_word(state, 909, reg_909);
162 reg_909 &= ~(1 << 1);
163 break;
164
165 case DIBX000_SLOW_ADC_OFF:
166 reg_909 |= (1 << 1) | (1 << 0);
167 break;
168
169 case DIBX000_ADC_ON:
170 reg_908 &= 0x0fff;
171 reg_909 &= 0x0003;
172 break;
173
174 case DIBX000_ADC_OFF: // leave the VBG voltage on
175 reg_908 |= (1 << 14) | (1 << 13) | (1 << 12);
176 reg_909 |= (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
177 break;
178
179 case DIBX000_VBG_ENABLE:
180 reg_908 &= ~(1 << 15);
181 break;
182
183 case DIBX000_VBG_DISABLE:
184 reg_908 |= (1 << 15);
185 break;
186
187 default:
188 break;
189 }
190
191// dprintk("908: %x, 909: %x\n", reg_908, reg_909);
192
193 dib7000p_write_word(state, 908, reg_908);
194 dib7000p_write_word(state, 909, reg_909);
195}
196
197static int dib7000p_set_bandwidth(struct dvb_frontend *demod, u8 BW_Idx)
198{
199 struct dib7000p_state *state = demod->demodulator_priv;
200 u32 timf;
201
202 // store the current bandwidth for later use
203 state->current_bandwidth = BW_Idx;
204
205 if (state->timf == 0) {
206 dprintk("-D- Using default timf\n");
207 timf = state->cfg.bw->timf;
208 } else {
209 dprintk("-D- Using updated timf\n");
210 timf = state->timf;
211 }
212
213 timf = timf * (BW_INDEX_TO_KHZ(BW_Idx) / 100) / 80;
214
215 dprintk("timf: %d\n",timf);
216
217 dib7000p_write_word(state, 23, (timf >> 16) & 0xffff);
218 dib7000p_write_word(state, 24, (timf ) & 0xffff);
219
220 return 0;
221}
222
223static int dib7000p_sad_calib(struct dib7000p_state *state)
224{
225/* internal */
226// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth
227 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0));
228 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096
229
230 /* do the calibration */
231 dib7000p_write_word(state, 73, (1 << 0));
232 dib7000p_write_word(state, 73, (0 << 0));
233
234 msleep(1);
235
236 return 0;
237}
238
239static void dib7000p_reset_pll(struct dib7000p_state *state)
240{
241 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0];
242
243 dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset);
244 dib7000p_write_word(state, 900, ((bw->pll_ratio & 0x3f) << 9) | (bw->pll_bypass << 15) | (bw->modulo << 7) | (bw->ADClkSrc << 6) |
245 (bw->IO_CLK_en_core << 5) | (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0));
246
247 dib7000p_write_word(state, 18, ((bw->internal*1000) >> 16) & 0xffff);
248 dib7000p_write_word(state, 19, (bw->internal*1000 ) & 0xffff);
249 dib7000p_write_word(state, 21, (bw->ifreq >> 16) & 0xffff);
250 dib7000p_write_word(state, 22, (bw->ifreq ) & 0xffff);
251
252 dib7000p_write_word(state, 72, bw->sad_cfg);
253}
254
255static int dib7000p_reset_gpio(struct dib7000p_state *st)
256{
257 /* reset the GPIOs */
258 dprintk("-D- gpio dir: %x: gpio val: %x, gpio pwm pos: %x\n",st->gpio_dir, st->gpio_val,st->cfg.gpio_pwm_pos);
259
260 dib7000p_write_word(st, 1029, st->gpio_dir);
261 dib7000p_write_word(st, 1030, st->gpio_val);
262
263 /* TODO 1031 is P_gpio_od */
264
265 dib7000p_write_word(st, 1032, st->cfg.gpio_pwm_pos);
266
267 dib7000p_write_word(st, 1037, st->cfg.pwm_freq_div);
268 return 0;
269}
270
271static int dib7000p_demod_reset(struct dib7000p_state *state)
272{
273 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
274
275 dib7000p_set_adc_state(state, DIBX000_VBG_ENABLE);
276
277 /* restart all parts */
278 dib7000p_write_word(state, 770, 0xffff);
279 dib7000p_write_word(state, 771, 0xffff);
280 dib7000p_write_word(state, 772, 0x001f);
281 dib7000p_write_word(state, 898, 0x0003);
282 /* except i2c, sdio, gpio - control interfaces */
283 dib7000p_write_word(state, 1280, 0x01fc - ((1 << 7) | (1 << 6) | (1 << 5)) );
284
285 dib7000p_write_word(state, 770, 0);
286 dib7000p_write_word(state, 771, 0);
287 dib7000p_write_word(state, 772, 0);
288 dib7000p_write_word(state, 898, 0);
289 dib7000p_write_word(state, 1280, 0);
290
291 /* default */
292 dib7000p_reset_pll(state);
293
294 if (dib7000p_reset_gpio(state) != 0)
295 dprintk("-E- GPIO reset was not successful.\n");
296
297 if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
298 dprintk("-E- OUTPUT_MODE could not be resetted.\n");
299
300 /* unforce divstr regardless whether i2c enumeration was done or not */
301 dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1) );
302
303 dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
304
305 return 0;
306}
307
308static void dib7000p_restart_agc(struct dib7000p_state *state)
309{
310 // P_restart_iqc & P_restart_agc
311 dib7000p_write_word(state, 770, 0x0c00);
312 dib7000p_write_word(state, 770, 0x0000);
313}
314
315static void dib7000p_update_lna(struct dib7000p_state *state)
316{
317 int i;
318 u16 dyn_gain;
319
320 // when there is no LNA to program return immediatly
321 if (state->cfg.update_lna == NULL)
322 return;
323
324 for (i = 0; i < 5; i++) {
325 // read dyn_gain here (because it is demod-dependent and not tuner)
326 dyn_gain = dib7000p_read_word(state, 394);
327
328 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed
329 dib7000p_restart_agc(state);
330 msleep(5);
331 } else
332 break;
333 }
334}
335
336static void dib7000p_pll_clk_cfg(struct dib7000p_state *state)
337{
338 u16 tmp = 0;
339 tmp = dib7000p_read_word(state, 903);
340 dib7000p_write_word(state, 903, (tmp | 0x1)); //pwr-up pll
341 tmp = dib7000p_read_word(state, 900);
342 dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6)); //use High freq clock
343}
344
345static void dib7000p_update_timf_freq(struct dib7000p_state *state)
346{
347 u32 timf = (dib7000p_read_word(state, 427) << 16) | dib7000p_read_word(state, 428);
348 state->timf = timf * 80 / (BW_INDEX_TO_KHZ(state->current_bandwidth) / 100);
349 dib7000p_write_word(state, 23, (u16) (timf >> 16));
350 dib7000p_write_word(state, 24, (u16) (timf & 0xffff));
351 dprintk("-D- Updated timf_frequency: %d (default: %d)\n",state->timf, state->cfg.bw->timf);
352}
353
354static void dib7000p_set_channel(struct dib7000p_state *state, struct dibx000_ofdm_channel *ch, u8 seq)
355{
356 u16 tmp, est[4]; // reg_26, reg_32, reg_33, reg_187, reg_188, reg_189, reg_190, reg_207, reg_208;
357
358 /* nfft, guard, qam, alpha */
359 dib7000p_write_word(state, 0, (ch->nfft << 7) | (ch->guard << 5) | (ch->nqam << 3) | (ch->vit_alpha));
360 dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */
361
362 /* P_dintl_native, P_dintlv_inv, P_vit_hrch, P_vit_code_rate, P_vit_select_hp */
363 tmp = (ch->intlv_native << 6) | (ch->vit_hrch << 4) | (ch->vit_select_hp & 0x1);
364 if (ch->vit_hrch == 0 || ch->vit_select_hp == 1)
365 tmp |= (ch->vit_code_rate_hp << 1);
366 else
367 tmp |= (ch->vit_code_rate_lp << 1);
368 dib7000p_write_word(state, 208, tmp);
369
370 /* P_dvsy_sync_wait */
371 switch (ch->nfft) {
372 case 1: tmp = 256; break;
373 case 2: tmp = 128; break;
374 case 0:
375 default: tmp = 64; break;
376 }
377 tmp *= ((1 << (ch->guard)) * 3 / 2); // add 50% SFN margin
378 tmp <<= 4;
379
380 /* deactive the possibility of diversity reception if extended interleave */
381 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */
382 if (ch->intlv_native || ch->nfft == 1)
383 tmp |= (1 << 2) | (2 << 0);
384 dib7000p_write_word(state, 207, tmp);
385
386 dib7000p_write_word(state, 26, 0x6680); // timf(6xxx)
387 dib7000p_write_word(state, 29, 0x1273); // isi inh1273 on1073
388 dib7000p_write_word(state, 32, 0x0003); // pha_off_max(xxx3)
389 dib7000p_write_word(state, 33, 0x0005); // sfreq(xxx5)
390
391 /* channel estimation fine configuration */
392 switch (ch->nqam) {
393 case 2:
394 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
395 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
396 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
397 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
398 break;
399 case 1:
400 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
401 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
402 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
403 est[3] = 0xfff0; /* P_adp_noise_ext -0.002 */
404 break;
405 default:
406 est[0] = 0x099a; /* P_adp_regul_cnt 0.3 */
407 est[1] = 0xffae; /* P_adp_noise_cnt -0.01 */
408 est[2] = 0x0333; /* P_adp_regul_ext 0.1 */
409 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
410 break;
411 }
412 for (tmp = 0; tmp < 4; tmp++)
413 dib7000p_write_word(state, 187 + tmp, est[tmp]);
414
415 // set power-up level: interf+analog+AGC
416 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
417 dib7000p_set_adc_state(state, DIBX000_ADC_ON);
418 dib7000p_pll_clk_cfg(state);
419 msleep(7);
420
421 // AGC initialization
422 if (state->cfg.agc_control)
423 state->cfg.agc_control(&state->demod, 1);
424
425 dib7000p_restart_agc(state);
426
427 // wait AGC rough lock time
428 msleep(5);
429
430 dib7000p_update_lna(state);
431
432 // wait AGC accurate lock time
433 msleep(7);
434 if (state->cfg.agc_control)
435 state->cfg.agc_control(&state->demod, 0);
436}
437
438static int dib7000p_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch)
439{
440 struct dib7000p_state *state = demod->demodulator_priv;
441 struct dibx000_ofdm_channel auto_ch;
442 u32 value;
443
444 INIT_OFDM_CHANNEL(&auto_ch);
445 auto_ch.RF_kHz = ch->RF_kHz;
446 auto_ch.Bw = ch->Bw;
447 auto_ch.nqam = 2;
448 auto_ch.guard = 0;
449 auto_ch.nfft = 1;
450 auto_ch.vit_alpha = 1;
451 auto_ch.vit_select_hp = 1;
452 auto_ch.vit_code_rate_hp = 2;
453 auto_ch.vit_code_rate_lp = 3;
454 auto_ch.vit_hrch = 0;
455 auto_ch.intlv_native = 1;
456
457 dib7000p_set_channel(state, &auto_ch, 7);
458
459 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer
460 value = 30 * state->cfg.bw->internal;
461 dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time
462 dib7000p_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time
463 value = 100 * state->cfg.bw->internal;
464 dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time
465 dib7000p_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time
466 value = 500 * state->cfg.bw->internal;
467 dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time
468 dib7000p_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time
469
470 value = dib7000p_read_word(state, 0);
471 dib7000p_write_word(state, 0, (1 << 9) | value);
472 dib7000p_read_word(state, 1284);
473 dib7000p_write_word(state, 0, (u16) value);
474
475 return 0;
476}
477
478static int dib7000p_autosearch_is_irq(struct dvb_frontend *demod)
479{
480 struct dib7000p_state *state = demod->demodulator_priv;
481 u16 irq_pending = dib7000p_read_word(state, 1284);
482
483 if (irq_pending & 0x1) // failed
484 return 1;
485
486 if (irq_pending & 0x2) // succeeded
487 return 2;
488
489 return 0; // still pending
490}
491
492static int dib7000p_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch)
493{
494 struct dib7000p_state *state = demod->demodulator_priv;
495 u16 tmp = 0;
496
497 if (ch != NULL)
498 dib7000p_set_channel(state, ch, 0);
499 else
500 return -EINVAL;
501
502 // restart demod
503 dib7000p_write_word(state, 770, 0x4000);
504 dib7000p_write_word(state, 770, 0x0000);
505 msleep(45);
506
507 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
508 dib7000p_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3));
509
510 // never achieved a lock with that bandwidth so far - wait for osc-freq to update
511 if (state->timf == 0)
512 msleep(200);
513
514 /* offset loop parameters */
515
516 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
517 tmp = (6 << 8) | 0x80;
518 switch (ch->nfft) {
519 case 0: tmp |= (7 << 12); break;
520 case 1: tmp |= (9 << 12); break;
521 case 2: tmp |= (8 << 12); break;
522 }
523 dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */
524
525 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
526 tmp = (0 << 4);
527 switch (ch->nfft) {
528 case 0: tmp |= 0x6; break;
529 case 1: tmp |= 0x8; break;
530 case 2: tmp |= 0x7; break;
531 }
532 dib7000p_write_word(state, 32, tmp);
533
534 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
535 tmp = (0 << 4);
536 switch (ch->nfft) {
537 case 0: tmp |= 0x6; break;
538 case 1: tmp |= 0x8; break;
539 case 2: tmp |= 0x7; break;
540 }
541 dib7000p_write_word(state, 33, tmp);
542
543 tmp = dib7000p_read_word(state,509);
544 if (!((tmp >> 6) & 0x1)) {
545 /* restart the fec */
546 tmp = dib7000p_read_word(state,771);
547 dib7000p_write_word(state, 771, tmp | (1 << 1));
548 dib7000p_write_word(state, 771, tmp);
549 msleep(10);
550 tmp = dib7000p_read_word(state,509);
551 }
552
553 // we achieved a lock - it's time to update the osc freq
554 if ((tmp >> 6) & 0x1)
555 dib7000p_update_timf_freq(state);
556
557 return 0;
558}
559
560static int dib7000p_init(struct dvb_frontend *demod)
561{
562 struct dibx000_agc_config *agc;
563 struct dib7000p_state *state = demod->demodulator_priv;
564 int ret = 0;
565
566 // Demodulator default configuration
567 agc = state->cfg.agc;
568
569 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
570 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
571
572 /* AGC */
573 ret |= dib7000p_write_word(state, 75 , agc->setup );
574 ret |= dib7000p_write_word(state, 76 , agc->inv_gain );
575 ret |= dib7000p_write_word(state, 77 , agc->time_stabiliz );
576 ret |= dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock);
577
578 // Demod AGC loop configuration
579 ret |= dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp);
580 ret |= dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp);
581
582 /* AGC continued */
583 dprintk("-D- WBD: ref: %d, sel: %d, active: %d, alpha: %d\n",
584 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
585
586 if (state->wbd_ref != 0)
587 ret |= dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | state->wbd_ref);
588 else
589 ret |= dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | agc->wbd_ref);
590
591 ret |= dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8) );
592
593 ret |= dib7000p_write_word(state, 107, agc->agc1_max);
594 ret |= dib7000p_write_word(state, 108, agc->agc1_min);
595 ret |= dib7000p_write_word(state, 109, agc->agc2_max);
596 ret |= dib7000p_write_word(state, 110, agc->agc2_min);
597 ret |= dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2 );
598 ret |= dib7000p_write_word(state, 112, agc->agc1_pt3);
599 ret |= dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
600 ret |= dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
601 ret |= dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
602
603 /* disable power smoothing */
604 ret |= dib7000p_write_word(state, 145, 0);
605 ret |= dib7000p_write_word(state, 146, 0);
606 ret |= dib7000p_write_word(state, 147, 0);
607 ret |= dib7000p_write_word(state, 148, 0);
608 ret |= dib7000p_write_word(state, 149, 0);
609 ret |= dib7000p_write_word(state, 150, 0);
610 ret |= dib7000p_write_word(state, 151, 0);
611 ret |= dib7000p_write_word(state, 152, 0);
612
613 // P_timf_alpha=6, P_corm_alpha=6, P_corm_thres=128 default: 6,4,26
614 ret |= dib7000p_write_word(state, 26 ,0x6680);
615
616 // P_palf_filter_on=1, P_palf_filter_freeze=0, P_palf_alpha_regul=16
617 ret |= dib7000p_write_word(state, 142,0x0410);
618 // P_fft_freq_dir=1, P_fft_nb_to_cut=0
619 ret |= dib7000p_write_word(state, 154,1 << 13);
620 // P_pha3_thres, default 0x3000
621 ret |= dib7000p_write_word(state, 168,0x0ccd);
622 // P_cti_use_cpe=0, P_cti_use_prog=0, P_cti_win_len=16, default: 0x0010
623 //ret |= dib7000p_write_word(state, 169,0x0010);
624 // P_cspu_regul=512, P_cspu_win_cut=15, default: 0x2005
625 ret |= dib7000p_write_word(state, 183,0x200f);
626 // P_adp_regul_cnt=573, default: 410
627 ret |= dib7000p_write_word(state, 187,0x023d);
628 // P_adp_noise_cnt=
629 ret |= dib7000p_write_word(state, 188,0x00a4);
630 // P_adp_regul_ext
631 ret |= dib7000p_write_word(state, 189,0x00a4);
632 // P_adp_noise_ext
633 ret |= dib7000p_write_word(state, 190,0x7ff0);
634 // P_adp_fil
635 ret |= dib7000p_write_word(state, 191,0x3ccc);
636
637 ret |= dib7000p_write_word(state, 222,0x0010);
638 // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
639 ret |= dib7000p_write_word(state, 235,0x0062);
640
641 // P_iqc_alpha_pha, P_iqc_alpha_amp_dcc_alpha, ...
642 if(state->cfg.tuner_is_baseband)
643 ret |= dib7000p_write_word(state, 36,0x0755);
644 else
645 ret |= dib7000p_write_word(state, 36,0x1f55);
646
647 // auto search configuration
648 ret |= dib7000p_write_word(state, 2 ,0x0004);
649 ret |= dib7000p_write_word(state, 3 ,0x1000);
650
651 /* Equal Lock */
652 ret |= dib7000p_write_word(state, 4 ,0x0814);
653
654 ret |= dib7000p_write_word(state, 6 ,0x001b);
655 ret |= dib7000p_write_word(state, 7 ,0x7740);
656 ret |= dib7000p_write_word(state, 8 ,0x005b);
657 ret |= dib7000p_write_word(state, 9 ,0x8d80);
658 ret |= dib7000p_write_word(state, 10 ,0x01c9);
659 ret |= dib7000p_write_word(state, 11 ,0xc380);
660 ret |= dib7000p_write_word(state, 12 ,0x0000);
661 ret |= dib7000p_write_word(state, 13 ,0x0080);
662 ret |= dib7000p_write_word(state, 14 ,0x0000);
663 ret |= dib7000p_write_word(state, 15 ,0x0090);
664 ret |= dib7000p_write_word(state, 16 ,0x0001);
665 ret |= dib7000p_write_word(state, 17 ,0xd4c0);
666
667 // P_clk_cfg1
668 ret |= dib7000p_write_word(state, 901, 0x0006);
669
670 // P_divclksel=3 P_divbitsel=1
671 ret |= dib7000p_write_word(state, 902, (3 << 10) | (1 << 6));
672
673 // Tuner IO bank: max drive (14mA) + divout pads max drive
674 ret |= dib7000p_write_word(state, 905, 0x2c8e);
675
676 ret |= dib7000p_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ);
677 dib7000p_sad_calib(state);
678
679 return ret;
680}
681
682static int dib7000p_sleep(struct dvb_frontend *demod)
683{
684 struct dib7000p_state *state = demod->demodulator_priv;
685 return dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) | dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
686}
687
688static int dib7000p_identify(struct dib7000p_state *st)
689{
690 u16 value;
691 dprintk("-I- DiB7000PC: checking demod on I2C address: %d (%x)\n",
692 st->i2c_addr, st->i2c_addr);
693
694 if ((value = dib7000p_read_word(st, 768)) != 0x01b3) {
695 dprintk("-E- DiB7000PC: wrong Vendor ID (read=0x%x)\n",value);
696 return -EREMOTEIO;
697 }
698
699 if ((value = dib7000p_read_word(st, 769)) != 0x4000) {
700 dprintk("-E- DiB7000PC: wrong Device ID (%x)\n",value);
701 return -EREMOTEIO;
702 }
703
704 return 0;
705}
706
707
708static int dib7000p_get_frontend(struct dvb_frontend* fe,
709 struct dvb_frontend_parameters *fep)
710{
711 struct dib7000p_state *state = fe->demodulator_priv;
712 u16 tps = dib7000p_read_word(state,463);
713
714 fep->inversion = INVERSION_AUTO;
715
716 fep->u.ofdm.bandwidth = state->current_bandwidth;
717
718 switch ((tps >> 8) & 0x3) {
719 case 0: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; break;
720 case 1: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; break;
721 /* case 2: fep->u.ofdm.transmission_mode = TRANSMISSION_MODE_4K; break; */
722 }
723
724 switch (tps & 0x3) {
725 case 0: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_32; break;
726 case 1: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_16; break;
727 case 2: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_8; break;
728 case 3: fep->u.ofdm.guard_interval = GUARD_INTERVAL_1_4; break;
729 }
730
731 switch ((tps >> 14) & 0x3) {
732 case 0: fep->u.ofdm.constellation = QPSK; break;
733 case 1: fep->u.ofdm.constellation = QAM_16; break;
734 case 2:
735 default: fep->u.ofdm.constellation = QAM_64; break;
736 }
737
738 /* as long as the frontend_param structure is fixed for hierarchical transmission I refuse to use it */
739 /* (tps >> 13) & 0x1 == hrch is used, (tps >> 10) & 0x7 == alpha */
740
741 fep->u.ofdm.hierarchy_information = HIERARCHY_NONE;
742 switch ((tps >> 5) & 0x7) {
743 case 1: fep->u.ofdm.code_rate_HP = FEC_1_2; break;
744 case 2: fep->u.ofdm.code_rate_HP = FEC_2_3; break;
745 case 3: fep->u.ofdm.code_rate_HP = FEC_3_4; break;
746 case 5: fep->u.ofdm.code_rate_HP = FEC_5_6; break;
747 case 7:
748 default: fep->u.ofdm.code_rate_HP = FEC_7_8; break;
749
750 }
751
752 switch ((tps >> 2) & 0x7) {
753 case 1: fep->u.ofdm.code_rate_LP = FEC_1_2; break;
754 case 2: fep->u.ofdm.code_rate_LP = FEC_2_3; break;
755 case 3: fep->u.ofdm.code_rate_LP = FEC_3_4; break;
756 case 5: fep->u.ofdm.code_rate_LP = FEC_5_6; break;
757 case 7:
758 default: fep->u.ofdm.code_rate_LP = FEC_7_8; break;
759 }
760
761 /* native interleaver: (dib7000p_read_word(state, 464) >> 5) & 0x1 */
762
763 return 0;
764}
765
766static int dib7000p_set_frontend(struct dvb_frontend* fe,
767 struct dvb_frontend_parameters *fep)
768{
769 struct dib7000p_state *state = fe->demodulator_priv;
770 struct dibx000_ofdm_channel ch;
771
772 INIT_OFDM_CHANNEL(&ch);
773 FEP2DIB(fep,&ch);
774
775 state->current_bandwidth = fep->u.ofdm.bandwidth;
776 dib7000p_set_bandwidth(fe, fep->u.ofdm.bandwidth);
777
778 if (fe->ops.tuner_ops.set_params)
779 fe->ops.tuner_ops.set_params(fe, fep);
780
781 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
782 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
783 fep->u.ofdm.constellation == QAM_AUTO ||
784 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
785 int i = 800, found;
786
787 dib7000p_autosearch_start(fe, &ch);
788 do {
789 msleep(1);
790 found = dib7000p_autosearch_is_irq(fe);
791 } while (found == 0 && i--);
792
793 dprintk("autosearch returns: %d\n",found);
794 if (found == 0 || found == 1)
795 return 0; // no channel found
796
797 dib7000p_get_frontend(fe, fep);
798 FEP2DIB(fep, &ch);
799 }
800
801 /* make this a config parameter */
802 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO);
803
804 return dib7000p_tune(fe, &ch);
805}
806
807static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat)
808{
809 struct dib7000p_state *state = fe->demodulator_priv;
810 u16 lock = dib7000p_read_word(state, 509);
811
812 *stat = 0;
813
814 if (lock & 0x8000)
815 *stat |= FE_HAS_SIGNAL;
816 if (lock & 0x3000)
817 *stat |= FE_HAS_CARRIER;
818 if (lock & 0x0100)
819 *stat |= FE_HAS_VITERBI;
820 if (lock & 0x0010)
821 *stat |= FE_HAS_SYNC;
822 if (lock & 0x0008)
823 *stat |= FE_HAS_LOCK;
824
825 return 0;
826}
827
828static int dib7000p_read_ber(struct dvb_frontend *fe, u32 *ber)
829{
830 struct dib7000p_state *state = fe->demodulator_priv;
831 *ber = (dib7000p_read_word(state, 500) << 16) | dib7000p_read_word(state, 501);
832 return 0;
833}
834
835static int dib7000p_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
836{
837 struct dib7000p_state *state = fe->demodulator_priv;
838 *unc = dib7000p_read_word(state, 506);
839 return 0;
840}
841
842static int dib7000p_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
843{
844 struct dib7000p_state *state = fe->demodulator_priv;
845 u16 val = dib7000p_read_word(state, 394);
846 *strength = 65535 - val;
847 return 0;
848}
849
850static int dib7000p_read_snr(struct dvb_frontend* fe, u16 *snr)
851{
852 *snr = 0x0000;
853 return 0;
854}
855
856static int dib7000p_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
857{
858 tune->min_delay_ms = 1000;
859 return 0;
860}
861
862static void dib7000p_release(struct dvb_frontend *demod)
863{
864 struct dib7000p_state *st = demod->demodulator_priv;
865 dibx000_exit_i2c_master(&st->i2c_master);
866 kfree(st);
867}
868
869int dib7000pc_detection(struct i2c_adapter *i2c_adap)
870{
871 u8 tx[2], rx[2];
872 struct i2c_msg msg[2] = {
873 { .addr = 18 >> 1, .flags = 0, .buf = tx, .len = 2 },
874 { .addr = 18 >> 1, .flags = I2C_M_RD, .buf = rx, .len = 2 },
875 };
876
877 tx[0] = 0x03;
878 tx[1] = 0x00;
879
880 if (i2c_transfer(i2c_adap, msg, 2) == 2)
881 if (rx[0] == 0x01 && rx[1] == 0xb3) {
882 dprintk("-D- DiB7000PC detected\n");
883 return 1;
884 }
885
886 msg[0].addr = msg[1].addr = 0x40;
887
888 if (i2c_transfer(i2c_adap, msg, 2) == 2)
889 if (rx[0] == 0x01 && rx[1] == 0xb3) {
890 dprintk("-D- DiB7000PC detected\n");
891 return 1;
892 }
893
894 dprintk("-D- DiB7000PC not detected\n");
895 return 0;
896}
897EXPORT_SYMBOL(dib7000pc_detection);
898
899struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *demod, enum dibx000_i2c_interface intf, int gating)
900{
901 struct dib7000p_state *st = demod->demodulator_priv;
902 return dibx000_get_i2c_adapter(&st->i2c_master, intf, gating);
903}
904EXPORT_SYMBOL(dib7000p_get_i2c_master);
905
906int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
907{
908 struct dib7000p_state st = { .i2c_adap = i2c };
909 int k = 0;
910 u8 new_addr = 0;
911
912 for (k = no_of_demods-1; k >= 0; k--) {
913 st.cfg = cfg[k];
914
915 /* designated i2c address */
916 new_addr = (0x40 + k) << 1;
917 st.i2c_addr = new_addr;
918 if (dib7000p_identify(&st) != 0) {
919 st.i2c_addr = default_addr;
920 if (dib7000p_identify(&st) != 0) {
921 dprintk("DiB7000P #%d: not identified\n", k);
922 return -EIO;
923 }
924 }
925
926 /* start diversity to pull_down div_str - just for i2c-enumeration */
927 dib7000p_set_output_mode(&st, OUTMODE_DIVERSITY);
928
929 /* set new i2c address and force divstart */
930 dib7000p_write_word(&st, 1285, (new_addr << 2) | 0x2);
931
932 dprintk("IC %d initialized (to i2c_address 0x%x)\n", k, new_addr);
933 }
934
935 for (k = 0; k < no_of_demods; k++) {
936 st.cfg = cfg[k];
937 st.i2c_addr = (0x40 + k) << 1;
938
939 // unforce divstr
940 dib7000p_write_word(&st, 1285, st.i2c_addr << 2);
941
942 /* deactivate div - it was just for i2c-enumeration */
943 dib7000p_set_output_mode(&st, OUTMODE_HIGH_Z);
944 }
945
946 return 0;
947}
948EXPORT_SYMBOL(dib7000p_i2c_enumeration);
949
950static struct dvb_frontend_ops dib7000p_ops;
951struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg)
952{
953 struct dvb_frontend *demod;
954 struct dib7000p_state *st;
955 st = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
956 if (st == NULL)
957 return NULL;
958
959 memcpy(&st->cfg, cfg, sizeof(struct dib7000p_config));
960 st->i2c_adap = i2c_adap;
961 st->i2c_addr = i2c_addr;
962 st->gpio_val = cfg->gpio_val;
963 st->gpio_dir = cfg->gpio_dir;
964
965 demod = &st->demod;
966 demod->demodulator_priv = st;
967 memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
968
969 if (dib7000p_identify(st) != 0)
970 goto error;
971
972 dibx000_init_i2c_master(&st->i2c_master, DIB7000P, st->i2c_adap, st->i2c_addr);
973
974 dib7000p_demod_reset(st);
975
976 return demod;
977
978error:
979 kfree(st);
980 return NULL;
981}
982EXPORT_SYMBOL(dib7000p_attach);
983
984static struct dvb_frontend_ops dib7000p_ops = {
985 .info = {
986 .name = "DiBcom 7000PC",
987 .type = FE_OFDM,
988 .frequency_min = 44250000,
989 .frequency_max = 867250000,
990 .frequency_stepsize = 62500,
991 .caps = FE_CAN_INVERSION_AUTO |
992 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
993 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
994 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
995 FE_CAN_TRANSMISSION_MODE_AUTO |
996 FE_CAN_GUARD_INTERVAL_AUTO |
997 FE_CAN_RECOVER |
998 FE_CAN_HIERARCHY_AUTO,
999 },
1000
1001 .release = dib7000p_release,
1002
1003 .init = dib7000p_init,
1004 .sleep = dib7000p_sleep,
1005
1006 .set_frontend = dib7000p_set_frontend,
1007 .get_tune_settings = dib7000p_fe_get_tune_settings,
1008 .get_frontend = dib7000p_get_frontend,
1009
1010 .read_status = dib7000p_read_status,
1011 .read_ber = dib7000p_read_ber,
1012 .read_signal_strength = dib7000p_read_signal_strength,
1013 .read_snr = dib7000p_read_snr,
1014 .read_ucblocks = dib7000p_read_unc_blocks,
1015};
1016
1017MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
1018MODULE_DESCRIPTION("Driver for the DiBcom 7000PC COFDM demodulator");
1019MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
new file mode 100644
index 000000000000..79465cf1aced
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -0,0 +1,46 @@
1#ifndef DIB7000P_H
2#define DIB7000P_H
3
4#include "dibx000_common.h"
5
6struct dib7000p_config {
7 u8 output_mpeg2_in_188_bytes;
8 u8 hostbus_diversity;
9 u8 tuner_is_baseband;
10 int (*update_lna) (struct dvb_frontend *, u16 agc_global);
11
12 struct dibx000_agc_config *agc;
13 struct dibx000_bandwidth_config *bw;
14
15#define DIB7000P_GPIO_DEFAULT_DIRECTIONS 0xffff
16 u16 gpio_dir;
17#define DIB7000P_GPIO_DEFAULT_VALUES 0x0000
18 u16 gpio_val;
19#define DIB7000P_GPIO_PWM_POS0(v) ((v & 0xf) << 12)
20#define DIB7000P_GPIO_PWM_POS1(v) ((v & 0xf) << 8 )
21#define DIB7000P_GPIO_PWM_POS2(v) ((v & 0xf) << 4 )
22#define DIB7000P_GPIO_PWM_POS3(v) (v & 0xf)
23#define DIB7000P_GPIO_DEFAULT_PWM_POS 0xffff
24 u16 gpio_pwm_pos;
25
26 u16 pwm_freq_div;
27
28 u8 quartz_direct;
29
30 int (*agc_control) (struct dvb_frontend *, u8 before);
31};
32
33#define DEFAULT_DIB7000P_I2C_ADDRESS 18
34
35extern struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
36extern struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
37extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
38
39/* TODO
40extern INT dib7000p_set_gpio(struct dibDemod *demod, UCHAR num, UCHAR dir, UCHAR val);
41extern INT dib7000p_enable_vbg_voltage(struct dibDemod *demod);
42extern void dib7000p_set_hostbus_diversity(struct dibDemod *demod, UCHAR onoff);
43extern USHORT dib7000p_get_current_agc_global(struct dibDemod *demod);
44*/
45
46#endif
diff --git a/drivers/media/dvb/frontends/dibx000_common.h b/drivers/media/dvb/frontends/dibx000_common.h
index bb0c65f8aee8..a1df604366c3 100644
--- a/drivers/media/dvb/frontends/dibx000_common.h
+++ b/drivers/media/dvb/frontends/dibx000_common.h
@@ -32,6 +32,13 @@ extern void dibx000_exit_i2c_master(struct dibx000_i2c_master *mst);
32#define BAND_LBAND 0x01 32#define BAND_LBAND 0x01
33#define BAND_UHF 0x02 33#define BAND_UHF 0x02
34#define BAND_VHF 0x04 34#define BAND_VHF 0x04
35#define BAND_SBAND 0x08
36#define BAND_FM 0x10
37
38#define BAND_OF_FREQUENCY(freq_kHz) ( (freq_kHz) <= 115000 ? BAND_FM : \
39 (freq_kHz) <= 250000 ? BAND_VHF : \
40 (freq_kHz) <= 863000 ? BAND_UHF : \
41 (freq_kHz) <= 2000000 ? BAND_LBAND : BAND_SBAND )
35 42
36struct dibx000_agc_config { 43struct dibx000_agc_config {
37 /* defines the capabilities of this AGC-setting - using the BAND_-defines*/ 44 /* defines the capabilities of this AGC-setting - using the BAND_-defines*/
@@ -129,6 +136,7 @@ enum dibx000_adc_states {
129 136
130/* I hope I can get rid of the following kludge in the near future */ 137/* I hope I can get rid of the following kludge in the near future */
131struct dibx000_ofdm_channel { 138struct dibx000_ofdm_channel {
139 u32 RF_kHz;
132 u8 Bw; 140 u8 Bw;
133 s16 nfft; 141 s16 nfft;
134 s16 guard; 142 s16 guard;
@@ -138,9 +146,11 @@ struct dibx000_ofdm_channel {
138 s16 vit_alpha; 146 s16 vit_alpha;
139 s16 vit_code_rate_hp; 147 s16 vit_code_rate_hp;
140 s16 vit_code_rate_lp; 148 s16 vit_code_rate_lp;
149 u8 intlv_native;
141}; 150};
142 151
143#define FEP2DIB(fep,ch) \ 152#define FEP2DIB(fep,ch) \
153 (ch)->RF_kHz = (fep)->frequency / 1000; \
144 (ch)->Bw = (fep)->u.ofdm.bandwidth; \ 154 (ch)->Bw = (fep)->u.ofdm.bandwidth; \
145 (ch)->nfft = (fep)->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ? -1 : (fep)->u.ofdm.transmission_mode; \ 155 (ch)->nfft = (fep)->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ? -1 : (fep)->u.ofdm.transmission_mode; \
146 (ch)->guard = (fep)->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ? -1 : (fep)->u.ofdm.guard_interval; \ 156 (ch)->guard = (fep)->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ? -1 : (fep)->u.ofdm.guard_interval; \
@@ -149,7 +159,8 @@ struct dibx000_ofdm_channel {
149 (ch)->vit_select_hp = 1; \ 159 (ch)->vit_select_hp = 1; \
150 (ch)->vit_alpha = 1; \ 160 (ch)->vit_alpha = 1; \
151 (ch)->vit_code_rate_hp = (fep)->u.ofdm.code_rate_HP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_HP; \ 161 (ch)->vit_code_rate_hp = (fep)->u.ofdm.code_rate_HP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_HP; \
152 (ch)->vit_code_rate_lp = (fep)->u.ofdm.code_rate_LP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_LP; 162 (ch)->vit_code_rate_lp = (fep)->u.ofdm.code_rate_LP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_LP; \
163 (ch)->intlv_native = 1;
153 164
154#define INIT_OFDM_CHANNEL(ch) do {\ 165#define INIT_OFDM_CHANNEL(ch) do {\
155 (ch)->Bw = 0; \ 166 (ch)->Bw = 0; \
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index b7e7108ee5b3..62de760c844f 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -472,14 +472,14 @@ int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
472 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", 472 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
473 desc->name, div, buf[0], buf[1], buf[2], buf[3]); 473 desc->name, div, buf[0], buf[1], buf[2], buf[3]);
474 474
475 return 0; 475 // calculate the frequency we set it to
476 return (div * desc->entries[i].stepsize) - desc->entries[i].offset;
476} 477}
477EXPORT_SYMBOL(dvb_pll_configure); 478EXPORT_SYMBOL(dvb_pll_configure);
478 479
479static int dvb_pll_release(struct dvb_frontend *fe) 480static int dvb_pll_release(struct dvb_frontend *fe)
480{ 481{
481 if (fe->tuner_priv) 482 kfree(fe->tuner_priv);
482 kfree(fe->tuner_priv);
483 fe->tuner_priv = NULL; 483 fe->tuner_priv = NULL;
484 return 0; 484 return 0;
485} 485}
@@ -489,7 +489,8 @@ static int dvb_pll_sleep(struct dvb_frontend *fe)
489 struct dvb_pll_priv *priv = fe->tuner_priv; 489 struct dvb_pll_priv *priv = fe->tuner_priv;
490 u8 buf[4]; 490 u8 buf[4];
491 struct i2c_msg msg = 491 struct i2c_msg msg =
492 { .addr = priv->pll_i2c_address, .flags = 0, .buf = buf, .len = sizeof(buf) }; 492 { .addr = priv->pll_i2c_address, .flags = 0,
493 .buf = buf, .len = sizeof(buf) };
493 int i; 494 int i;
494 int result; 495 int result;
495 496
@@ -517,16 +518,16 @@ static int dvb_pll_sleep(struct dvb_frontend *fe)
517 return 0; 518 return 0;
518} 519}
519 520
520static int dvb_pll_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 521static int dvb_pll_set_params(struct dvb_frontend *fe,
522 struct dvb_frontend_parameters *params)
521{ 523{
522 struct dvb_pll_priv *priv = fe->tuner_priv; 524 struct dvb_pll_priv *priv = fe->tuner_priv;
523 u8 buf[4]; 525 u8 buf[4];
524 struct i2c_msg msg = 526 struct i2c_msg msg =
525 { .addr = priv->pll_i2c_address, .flags = 0, .buf = buf, .len = sizeof(buf) }; 527 { .addr = priv->pll_i2c_address, .flags = 0,
528 .buf = buf, .len = sizeof(buf) };
526 int result; 529 int result;
527 u32 div; 530 u32 bandwidth = 0, frequency = 0;
528 int i;
529 u32 bandwidth = 0;
530 531
531 if (priv->i2c == NULL) 532 if (priv->i2c == NULL)
532 return -EINVAL; 533 return -EINVAL;
@@ -536,8 +537,11 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
536 bandwidth = params->u.ofdm.bandwidth; 537 bandwidth = params->u.ofdm.bandwidth;
537 } 538 }
538 539
539 if ((result = dvb_pll_configure(priv->pll_desc, buf, params->frequency, bandwidth)) != 0) 540 if ((result = dvb_pll_configure(priv->pll_desc, buf,
541 params->frequency, bandwidth)) < 0)
540 return result; 542 return result;
543 else
544 frequency = result;
541 545
542 if (fe->ops.i2c_gate_ctrl) 546 if (fe->ops.i2c_gate_ctrl)
543 fe->ops.i2c_gate_ctrl(fe, 1); 547 fe->ops.i2c_gate_ctrl(fe, 1);
@@ -545,26 +549,19 @@ static int dvb_pll_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
545 return result; 549 return result;
546 } 550 }
547 551
548 // calculate the frequency we set it to 552 priv->frequency = frequency;
549 for (i = 0; i < priv->pll_desc->count; i++) {
550 if (params->frequency > priv->pll_desc->entries[i].limit)
551 continue;
552 break;
553 }
554 div = (params->frequency + priv->pll_desc->entries[i].offset) / priv->pll_desc->entries[i].stepsize;
555 priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - priv->pll_desc->entries[i].offset;
556 priv->bandwidth = bandwidth; 553 priv->bandwidth = bandwidth;
557 554
558 return 0; 555 return 0;
559} 556}
560 557
561static int dvb_pll_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parameters *params, u8 *buf, int buf_len) 558static int dvb_pll_calc_regs(struct dvb_frontend *fe,
559 struct dvb_frontend_parameters *params,
560 u8 *buf, int buf_len)
562{ 561{
563 struct dvb_pll_priv *priv = fe->tuner_priv; 562 struct dvb_pll_priv *priv = fe->tuner_priv;
564 int result; 563 int result;
565 u32 div; 564 u32 bandwidth = 0, frequency = 0;
566 int i;
567 u32 bandwidth = 0;
568 565
569 if (buf_len < 5) 566 if (buf_len < 5)
570 return -EINVAL; 567 return -EINVAL;
@@ -574,18 +571,15 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe, struct dvb_frontend_parame
574 bandwidth = params->u.ofdm.bandwidth; 571 bandwidth = params->u.ofdm.bandwidth;
575 } 572 }
576 573
577 if ((result = dvb_pll_configure(priv->pll_desc, buf+1, params->frequency, bandwidth)) != 0) 574 if ((result = dvb_pll_configure(priv->pll_desc, buf+1,
575 params->frequency, bandwidth)) < 0)
578 return result; 576 return result;
577 else
578 frequency = result;
579
579 buf[0] = priv->pll_i2c_address; 580 buf[0] = priv->pll_i2c_address;
580 581
581 // calculate the frequency we set it to 582 priv->frequency = frequency;
582 for (i = 0; i < priv->pll_desc->count; i++) {
583 if (params->frequency > priv->pll_desc->entries[i].limit)
584 continue;
585 break;
586 }
587 div = (params->frequency + priv->pll_desc->entries[i].offset) / priv->pll_desc->entries[i].stepsize;
588 priv->frequency = (div * priv->pll_desc->entries[i].stepsize) - priv->pll_desc->entries[i].offset;
589 priv->bandwidth = bandwidth; 583 priv->bandwidth = bandwidth;
590 584
591 return 5; 585 return 5;
@@ -614,10 +608,13 @@ static struct dvb_tuner_ops dvb_pll_tuner_ops = {
614 .get_bandwidth = dvb_pll_get_bandwidth, 608 .get_bandwidth = dvb_pll_get_bandwidth,
615}; 609};
616 610
617struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc) 611struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
612 struct i2c_adapter *i2c,
613 struct dvb_pll_desc *desc)
618{ 614{
619 u8 b1 [] = { 0 }; 615 u8 b1 [] = { 0 };
620 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD, .buf = b1, .len = 1 }; 616 struct i2c_msg msg = { .addr = pll_addr, .flags = I2C_M_RD,
617 .buf = b1, .len = 1 };
621 struct dvb_pll_priv *priv = NULL; 618 struct dvb_pll_priv *priv = NULL;
622 int ret; 619 int ret;
623 620
@@ -640,7 +637,9 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struc
640 priv->i2c = i2c; 637 priv->i2c = i2c;
641 priv->pll_desc = desc; 638 priv->pll_desc = desc;
642 639
643 memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops, sizeof(struct dvb_tuner_ops)); 640 memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
641 sizeof(struct dvb_tuner_ops));
642
644 strncpy(fe->ops.tuner_ops.info.name, desc->name, 128); 643 strncpy(fe->ops.tuner_ops.info.name, desc->name, 128);
645 fe->ops.tuner_ops.info.frequency_min = desc->min; 644 fe->ops.tuner_ops.info.frequency_min = desc->min;
646 fe->ops.tuner_ops.info.frequency_min = desc->max; 645 fe->ops.tuner_ops.info.frequency_min = desc->max;
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index ed5ac5a361ae..681186a5e5eb 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -48,7 +48,7 @@ extern struct dvb_pll_desc dvb_pll_philips_td1316;
48extern struct dvb_pll_desc dvb_pll_thomson_fe6600; 48extern struct dvb_pll_desc dvb_pll_thomson_fe6600;
49 49
50extern int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf, 50extern int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
51 u32 freq, int bandwidth); 51 u32 freq, int bandwidth);
52 52
53/** 53/**
54 * Attach a dvb-pll to the supplied frontend structure. 54 * Attach a dvb-pll to the supplied frontend structure.
@@ -59,6 +59,9 @@ extern int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
59 * @param desc dvb_pll_desc to use. 59 * @param desc dvb_pll_desc to use.
60 * @return Frontend pointer on success, NULL on failure 60 * @return Frontend pointer on success, NULL on failure
61 */ 61 */
62extern struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr, struct i2c_adapter *i2c, struct dvb_pll_desc *desc); 62extern struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe,
63 int pll_addr,
64 struct i2c_adapter *i2c,
65 struct dvb_pll_desc *desc);
63 66
64#endif 67#endif
diff --git a/drivers/media/dvb/frontends/lg_h06xf.h b/drivers/media/dvb/frontends/lg_h06xf.h
deleted file mode 100644
index 754d51d11120..000000000000
--- a/drivers/media/dvb/frontends/lg_h06xf.h
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * lg_h06xf.h - ATSC Tuner support for LG TDVS-H06xF
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#ifndef _LG_H06XF_H_
20#define _LG_H06XF_H_
21#include "dvb-pll.h"
22
23static int lg_h06xf_pll_set(struct dvb_frontend* fe, struct i2c_adapter* i2c_adap,
24 struct dvb_frontend_parameters* params)
25{
26 u8 buf[4];
27 struct i2c_msg msg = { .addr = 0x61, .flags = 0,
28 .buf = buf, .len = sizeof(buf) };
29 int err;
30
31 dvb_pll_configure(&dvb_pll_lg_tdvs_h06xf, buf, params->frequency, 0);
32 if (fe->ops.i2c_gate_ctrl)
33 fe->ops.i2c_gate_ctrl(fe, 1);
34 if ((err = i2c_transfer(i2c_adap, &msg, 1)) != 1) {
35 printk(KERN_WARNING "lg_h06xf: %s error "
36 "(addr %02x <- %02x, err = %i)\n",
37 __FUNCTION__, buf[0], buf[1], err);
38 if (err < 0)
39 return err;
40 else
41 return -EREMOTEIO;
42 }
43
44 /* Set the Auxiliary Byte. */
45 buf[0] = buf[2];
46 buf[0] &= ~0x20;
47 buf[0] |= 0x18;
48 buf[1] = 0x50;
49 msg.len = 2;
50 if (fe->ops.i2c_gate_ctrl)
51 fe->ops.i2c_gate_ctrl(fe, 1);
52 if ((err = i2c_transfer(i2c_adap, &msg, 1)) != 1) {
53 printk(KERN_WARNING "lg_h06xf: %s error "
54 "(addr %02x <- %02x, err = %i)\n",
55 __FUNCTION__, buf[0], buf[1], err);
56 if (err < 0)
57 return err;
58 else
59 return -EREMOTEIO;
60 }
61
62 return 0;
63}
64#endif
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index 9a354708bd20..68aad0f6519f 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -31,9 +31,6 @@
31 * Air2PC/AirStar 2 ATSC 3rd generation (HD5000) 31 * Air2PC/AirStar 2 ATSC 3rd generation (HD5000)
32 * pcHDTV HD5500 32 * pcHDTV HD5500
33 * 33 *
34 * TODO:
35 * signal strength always returns 0.
36 *
37 */ 34 */
38 35
39#include <linux/kernel.h> 36#include <linux/kernel.h>
@@ -46,9 +43,13 @@
46#include <asm/byteorder.h> 43#include <asm/byteorder.h>
47 44
48#include "dvb_frontend.h" 45#include "dvb_frontend.h"
46#include "dvb_math.h"
49#include "lgdt330x_priv.h" 47#include "lgdt330x_priv.h"
50#include "lgdt330x.h" 48#include "lgdt330x.h"
51 49
50/* Use Equalizer Mean Squared Error instead of Phaser Tracker MSE */
51/* #define USE_EQMSE */
52
52static int debug = 0; 53static int debug = 0;
53module_param(debug, int, 0644); 54module_param(debug, int, 0644);
54MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off)."); 55MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off).");
@@ -68,6 +69,7 @@ struct lgdt330x_state
68 69
69 /* Demodulator private data */ 70 /* Demodulator private data */
70 fe_modulation_t current_modulation; 71 fe_modulation_t current_modulation;
72 u32 snr; /* Result of last SNR calculation */
71 73
72 /* Tuner private data */ 74 /* Tuner private data */
73 u32 current_frequency; 75 u32 current_frequency;
@@ -302,10 +304,10 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
302 static u8 lgdt3303_8vsb_44_data[] = { 304 static u8 lgdt3303_8vsb_44_data[] = {
303 0x04, 0x00, 305 0x04, 0x00,
304 0x0d, 0x40, 306 0x0d, 0x40,
305 0x0e, 0x87, 307 0x0e, 0x87,
306 0x0f, 0x8e, 308 0x0f, 0x8e,
307 0x10, 0x01, 309 0x10, 0x01,
308 0x47, 0x8b }; 310 0x47, 0x8b };
309 311
310 /* 312 /*
311 * Array of byte pairs <address, value> 313 * Array of byte pairs <address, value>
@@ -435,9 +437,6 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
435 /* Test signal does not exist flag */ 437 /* Test signal does not exist flag */
436 /* as well as the AGC lock flag. */ 438 /* as well as the AGC lock flag. */
437 *status |= FE_HAS_SIGNAL; 439 *status |= FE_HAS_SIGNAL;
438 } else {
439 /* Without a signal all other status bits are meaningless */
440 return 0;
441 } 440 }
442 441
443 /* 442 /*
@@ -500,9 +499,6 @@ static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
500 /* Test input signal does not exist flag */ 499 /* Test input signal does not exist flag */
501 /* as well as the AGC lock flag. */ 500 /* as well as the AGC lock flag. */
502 *status |= FE_HAS_SIGNAL; 501 *status |= FE_HAS_SIGNAL;
503 } else {
504 /* Without a signal all other status bits are meaningless */
505 return 0;
506 } 502 }
507 503
508 /* Carrier Recovery Lock Status Register */ 504 /* Carrier Recovery Lock Status Register */
@@ -543,151 +539,150 @@ static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
543 return 0; 539 return 0;
544} 540}
545 541
546static int lgdt330x_read_signal_strength(struct dvb_frontend* fe, u16* strength) 542/* Calculate SNR estimation (scaled by 2^24)
543
544 8-VSB SNR equations from LGDT3302 and LGDT3303 datasheets, QAM
545 equations from LGDT3303 datasheet. VSB is the same between the '02
546 and '03, so maybe QAM is too? Perhaps someone with a newer datasheet
547 that has QAM information could verify?
548
549 For 8-VSB: (two ways, take your pick)
550 LGDT3302:
551 SNR_EQ = 10 * log10(25 * 24^2 / EQ_MSE)
552 LGDT3303:
553 SNR_EQ = 10 * log10(25 * 32^2 / EQ_MSE)
554 LGDT3302 & LGDT3303:
555 SNR_PT = 10 * log10(25 * 32^2 / PT_MSE) (we use this one)
556 For 64-QAM:
557 SNR = 10 * log10( 688128 / MSEQAM)
558 For 256-QAM:
559 SNR = 10 * log10( 696320 / MSEQAM)
560
561 We re-write the snr equation as:
562 SNR * 2^24 = 10*(c - intlog10(MSE))
563 Where for 256-QAM, c = log10(696320) * 2^24, and so on. */
564
565static u32 calculate_snr(u32 mse, u32 c)
547{ 566{
548 /* not directly available. */ 567 if (mse == 0) /* No signal */
549 *strength = 0; 568 return 0;
550 return 0; 569
570 mse = intlog10(mse);
571 if (mse > c) {
572 /* Negative SNR, which is possible, but realisticly the
573 demod will lose lock before the signal gets this bad. The
574 API only allows for unsigned values, so just return 0 */
575 return 0;
576 }
577 return 10*(c - mse);
551} 578}
552 579
553static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr) 580static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
554{ 581{
555#ifdef SNR_IN_DB
556 /*
557 * Spec sheet shows formula for SNR_EQ = 10 log10(25 * 24**2 / noise)
558 * and SNR_PH = 10 log10(25 * 32**2 / noise) for equalizer and phase tracker
559 * respectively. The following tables are built on these formulas.
560 * The usual definition is SNR = 20 log10(signal/noise)
561 * If the specification is wrong the value retuned is 1/2 the actual SNR in db.
562 *
563 * This table is a an ordered list of noise values computed by the
564 * formula from the spec sheet such that the index into the table
565 * starting at 43 or 45 is the SNR value in db. There are duplicate noise
566 * value entries at the beginning because the SNR varies more than
567 * 1 db for a change of 1 digit in noise at very small values of noise.
568 *
569 * Examples from SNR_EQ table:
570 * noise SNR
571 * 0 43
572 * 1 42
573 * 2 39
574 * 3 37
575 * 4 36
576 * 5 35
577 * 6 34
578 * 7 33
579 * 8 33
580 * 9 32
581 * 10 32
582 * 11 31
583 * 12 31
584 * 13 30
585 */
586
587 static const u32 SNR_EQ[] =
588 { 1, 2, 2, 2, 3, 3, 4, 4, 5, 7,
589 9, 11, 13, 17, 21, 26, 33, 41, 52, 65,
590 81, 102, 129, 162, 204, 257, 323, 406, 511, 644,
591 810, 1020, 1284, 1616, 2035, 2561, 3224, 4059, 5110, 6433,
592 8098, 10195, 12835, 16158, 20341, 25608, 32238, 40585, 51094, 64323,
593 80978, 101945, 128341, 161571, 203406, 256073, 0x40000
594 };
595
596 static const u32 SNR_PH[] =
597 { 1, 2, 2, 2, 3, 3, 4, 5, 6, 8,
598 10, 12, 15, 19, 23, 29, 37, 46, 58, 73,
599 91, 115, 144, 182, 229, 288, 362, 456, 574, 722,
600 909, 1144, 1440, 1813, 2282, 2873, 3617, 4553, 5732, 7216,
601 9084, 11436, 14396, 18124, 22817, 28724, 36161, 45524, 57312, 72151,
602 90833, 114351, 143960, 181235, 228161, 0x080000
603 };
604
605 static u8 buf[5];/* read data buffer */
606 static u32 noise; /* noise value */
607 static u32 snr_db; /* index into SNR_EQ[] */
608 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; 582 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
583 u8 buf[5]; /* read data buffer */
584 u32 noise; /* noise value */
585 u32 c; /* per-modulation SNR calculation constant */
609 586
610 /* read both equalizer and phase tracker noise data */ 587 switch(state->current_modulation) {
611 i2c_read_demod_bytes(state, EQPH_ERR0, buf, sizeof(buf)); 588 case VSB_8:
612 589 i2c_read_demod_bytes(state, LGDT3302_EQPH_ERR0, buf, 5);
613 if (state->current_modulation == VSB_8) { 590#ifdef USE_EQMSE
614 /* Equalizer Mean-Square Error Register for VSB */ 591 /* Use Equalizer Mean-Square Error Register */
592 /* SNR for ranges from -15.61 to +41.58 */
615 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2]; 593 noise = ((buf[0] & 7) << 16) | (buf[1] << 8) | buf[2];
616 594 c = 69765745; /* log10(25*24^2)*2^24 */
617 /*
618 * Look up noise value in table.
619 * A better search algorithm could be used...
620 * watch out there are duplicate entries.
621 */
622 for (snr_db = 0; snr_db < sizeof(SNR_EQ); snr_db++) {
623 if (noise < SNR_EQ[snr_db]) {
624 *snr = 43 - snr_db;
625 break;
626 }
627 }
628 } else {
629 /* Phase Tracker Mean-Square Error Register for QAM */
630 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
631
632 /* Look up noise value in table. */
633 for (snr_db = 0; snr_db < sizeof(SNR_PH); snr_db++) {
634 if (noise < SNR_PH[snr_db]) {
635 *snr = 45 - snr_db;
636 break;
637 }
638 }
639 }
640#else 595#else
641 /* Return the raw noise value */ 596 /* Use Phase Tracker Mean-Square Error Register */
642 static u8 buf[5];/* read data buffer */ 597 /* SNR for ranges from -13.11 to +44.08 */
643 static u32 noise; /* noise value */
644 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
645
646 /* read both equalizer and pase tracker noise data */
647 i2c_read_demod_bytes(state, EQPH_ERR0, buf, sizeof(buf));
648
649 if (state->current_modulation == VSB_8) {
650 /* Phase Tracker Mean-Square Error Register for VSB */
651 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4]; 598 noise = ((buf[0] & 7<<3) << 13) | (buf[3] << 8) | buf[4];
652 } else { 599 c = 73957994; /* log10(25*32^2)*2^24 */
653 600#endif
654 /* Carrier Recovery Mean-Square Error for QAM */ 601 break;
655 i2c_read_demod_bytes(state, 0x1a, buf, 2); 602 case QAM_64:
603 case QAM_256:
604 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
656 noise = ((buf[0] & 3) << 8) | buf[1]; 605 noise = ((buf[0] & 3) << 8) | buf[1];
606 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
607 /* log10(688128)*2^24 and log10(696320)*2^24 */
608 break;
609 default:
610 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
611 __FUNCTION__);
612 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
657 } 613 }
658 614
659 /* Small values for noise mean signal is better so invert noise */ 615 state->snr = calculate_snr(noise, c);
660 *snr = ~noise; 616 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
661#endif
662 617
663 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr); 618 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise,
619 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
664 620
665 return 0; 621 return 0;
666} 622}
667 623
668static int lgdt3303_read_snr(struct dvb_frontend* fe, u16* snr) 624static int lgdt3303_read_snr(struct dvb_frontend* fe, u16* snr)
669{ 625{
670 /* Return the raw noise value */
671 static u8 buf[5];/* read data buffer */
672 static u32 noise; /* noise value */
673 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv; 626 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
627 u8 buf[5]; /* read data buffer */
628 u32 noise; /* noise value */
629 u32 c; /* per-modulation SNR calculation constant */
674 630
675 if (state->current_modulation == VSB_8) { 631 switch(state->current_modulation) {
676 632 case VSB_8:
677 i2c_read_demod_bytes(state, 0x6e, buf, 5); 633 i2c_read_demod_bytes(state, LGDT3303_EQPH_ERR0, buf, 5);
678 /* Phase Tracker Mean-Square Error Register for VSB */ 634#ifdef USE_EQMSE
635 /* Use Equalizer Mean-Square Error Register */
636 /* SNR for ranges from -16.12 to +44.08 */
637 noise = ((buf[0] & 0x78) << 13) | (buf[1] << 8) | buf[2];
638 c = 73957994; /* log10(25*32^2)*2^24 */
639#else
640 /* Use Phase Tracker Mean-Square Error Register */
641 /* SNR for ranges from -13.11 to +44.08 */
679 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4]; 642 noise = ((buf[0] & 7) << 16) | (buf[3] << 8) | buf[4];
680 } else { 643 c = 73957994; /* log10(25*32^2)*2^24 */
681 644#endif
682 /* Carrier Recovery Mean-Square Error for QAM */ 645 break;
683 i2c_read_demod_bytes(state, 0x1a, buf, 2); 646 case QAM_64:
647 case QAM_256:
648 i2c_read_demod_bytes(state, CARRIER_MSEQAM1, buf, 2);
684 noise = (buf[0] << 8) | buf[1]; 649 noise = (buf[0] << 8) | buf[1];
650 c = state->current_modulation == QAM_64 ? 97939837 : 98026066;
651 /* log10(688128)*2^24 and log10(696320)*2^24 */
652 break;
653 default:
654 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
655 __FUNCTION__);
656 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
685 } 657 }
686 658
687 /* Small values for noise mean signal is better so invert noise */ 659 state->snr = calculate_snr(noise, c);
688 *snr = ~noise; 660 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
661
662 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise,
663 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
664
665 return 0;
666}
667
668static int lgdt330x_read_signal_strength(struct dvb_frontend* fe, u16* strength)
669{
670 /* Calculate Strength from SNR up to 35dB */
671 /* Even though the SNR can go higher than 35dB, there is some comfort */
672 /* factor in having a range of strong signals that can show at 100% */
673 struct lgdt330x_state* state = (struct lgdt330x_state*) fe->demodulator_priv;
674 u16 snr;
675 int ret;
689 676
690 dprintk("%s: noise = 0x%05x, snr = %idb\n",__FUNCTION__, noise, *snr); 677 ret = fe->ops.read_snr(fe, &snr);
678 if (ret != 0)
679 return ret;
680 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
681 /* scale the range 0 - 35*2^24 into 0 - 65535 */
682 if (state->snr >= 8960 * 0x10000)
683 *strength = 0xffff;
684 else
685 *strength = state->snr / 8960;
691 686
692 return 0; 687 return 0;
693} 688}
diff --git a/drivers/media/dvb/frontends/lgdt330x_priv.h b/drivers/media/dvb/frontends/lgdt330x_priv.h
index 59b7c5b9012d..38c76695abfe 100644
--- a/drivers/media/dvb/frontends/lgdt330x_priv.h
+++ b/drivers/media/dvb/frontends/lgdt330x_priv.h
@@ -51,14 +51,19 @@ enum I2C_REG {
51 AGC_RFIF_ACC2= 0x3b, 51 AGC_RFIF_ACC2= 0x3b,
52 AGC_STATUS= 0x3f, 52 AGC_STATUS= 0x3f,
53 SYNC_STATUS_VSB= 0x43, 53 SYNC_STATUS_VSB= 0x43,
54 EQPH_ERR0= 0x47,
55 EQ_ERR1= 0x48,
56 EQ_ERR2= 0x49,
57 PH_ERR1= 0x4a,
58 PH_ERR2= 0x4b,
59 DEMUX_CONTROL= 0x66, 54 DEMUX_CONTROL= 0x66,
55 LGDT3302_EQPH_ERR0= 0x47,
56 LGDT3302_EQ_ERR1= 0x48,
57 LGDT3302_EQ_ERR2= 0x49,
58 LGDT3302_PH_ERR1= 0x4a,
59 LGDT3302_PH_ERR2= 0x4b,
60 LGDT3302_PACKET_ERR_COUNTER1= 0x6a, 60 LGDT3302_PACKET_ERR_COUNTER1= 0x6a,
61 LGDT3302_PACKET_ERR_COUNTER2= 0x6b, 61 LGDT3302_PACKET_ERR_COUNTER2= 0x6b,
62 LGDT3303_EQPH_ERR0= 0x6e,
63 LGDT3303_EQ_ERR1= 0x6f,
64 LGDT3303_EQ_ERR2= 0x70,
65 LGDT3303_PH_ERR1= 0x71,
66 LGDT3303_PH_ERR2= 0x72,
62 LGDT3303_PACKET_ERR_COUNTER1= 0x8b, 67 LGDT3303_PACKET_ERR_COUNTER1= 0x8b,
63 LGDT3303_PACKET_ERR_COUNTER2= 0x8c, 68 LGDT3303_PACKET_ERR_COUNTER2= 0x8c,
64}; 69};
diff --git a/drivers/media/dvb/frontends/lgh06xf.c b/drivers/media/dvb/frontends/lgh06xf.c
new file mode 100644
index 000000000000..2202d0cc878b
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgh06xf.c
@@ -0,0 +1,134 @@
1/*
2 * lgh06xf.c - ATSC Tuner support for LG TDVS-H06xF
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#include "dvb-pll.h"
20#include "lgh06xf.h"
21
22#define LG_H06XF_PLL_I2C_ADDR 0x61
23
24struct lgh06xf_priv {
25 struct i2c_adapter *i2c;
26 u32 frequency;
27};
28
29static int lgh06xf_release(struct dvb_frontend *fe)
30{
31 kfree(fe->tuner_priv);
32 fe->tuner_priv = NULL;
33 return 0;
34}
35
36static int lgh06xf_set_params(struct dvb_frontend* fe,
37 struct dvb_frontend_parameters* params)
38{
39 struct lgh06xf_priv *priv = fe->tuner_priv;
40 u8 buf[4];
41 struct i2c_msg msg = { .addr = LG_H06XF_PLL_I2C_ADDR, .flags = 0,
42 .buf = buf, .len = sizeof(buf) };
43 u32 frequency;
44 int result;
45
46 if ((result = dvb_pll_configure(&dvb_pll_lg_tdvs_h06xf, buf,
47 params->frequency, 0)) < 0)
48 return result;
49 else
50 frequency = result;
51
52 if (fe->ops.i2c_gate_ctrl)
53 fe->ops.i2c_gate_ctrl(fe, 1);
54 if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
55 printk(KERN_WARNING "lgh06xf: %s error "
56 "(addr %02x <- %02x, result = %i)\n",
57 __FUNCTION__, buf[0], buf[1], result);
58 if (result < 0)
59 return result;
60 else
61 return -EREMOTEIO;
62 }
63
64 /* Set the Auxiliary Byte. */
65 buf[0] = buf[2];
66 buf[0] &= ~0x20;
67 buf[0] |= 0x18;
68 buf[1] = 0x50;
69 msg.len = 2;
70 if (fe->ops.i2c_gate_ctrl)
71 fe->ops.i2c_gate_ctrl(fe, 1);
72 if ((result = i2c_transfer(priv->i2c, &msg, 1)) != 1) {
73 printk(KERN_WARNING "lgh06xf: %s error "
74 "(addr %02x <- %02x, result = %i)\n",
75 __FUNCTION__, buf[0], buf[1], result);
76 if (result < 0)
77 return result;
78 else
79 return -EREMOTEIO;
80 }
81
82 priv->frequency = frequency;
83
84 return 0;
85}
86
87static int lgh06xf_get_frequency(struct dvb_frontend *fe, u32 *frequency)
88{
89 struct lgh06xf_priv *priv = fe->tuner_priv;
90 *frequency = priv->frequency;
91 return 0;
92}
93
94static struct dvb_tuner_ops lgh06xf_tuner_ops = {
95 .release = lgh06xf_release,
96 .set_params = lgh06xf_set_params,
97 .get_frequency = lgh06xf_get_frequency,
98};
99
100struct dvb_frontend* lgh06xf_attach(struct dvb_frontend *fe,
101 struct i2c_adapter *i2c)
102{
103 struct lgh06xf_priv *priv = NULL;
104
105 priv = kzalloc(sizeof(struct lgh06xf_priv), GFP_KERNEL);
106 if (priv == NULL)
107 return NULL;
108
109 priv->i2c = i2c;
110
111 memcpy(&fe->ops.tuner_ops, &lgh06xf_tuner_ops,
112 sizeof(struct dvb_tuner_ops));
113
114 strlcpy(fe->ops.tuner_ops.info.name, dvb_pll_lg_tdvs_h06xf.name,
115 sizeof(fe->ops.tuner_ops.info.name));
116
117 fe->ops.tuner_ops.info.frequency_min = dvb_pll_lg_tdvs_h06xf.min;
118 fe->ops.tuner_ops.info.frequency_max = dvb_pll_lg_tdvs_h06xf.max;
119
120 fe->tuner_priv = priv;
121 return fe;
122}
123
124EXPORT_SYMBOL(lgh06xf_attach);
125
126MODULE_DESCRIPTION("LG TDVS-H06xF ATSC Tuner support");
127MODULE_AUTHOR("Michael Krufky");
128MODULE_LICENSE("GPL");
129
130/*
131 * Local variables:
132 * c-basic-offset: 8
133 * End:
134 */
diff --git a/drivers/media/dvb/frontends/lgh06xf.h b/drivers/media/dvb/frontends/lgh06xf.h
new file mode 100644
index 000000000000..510b4bedfb24
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgh06xf.h
@@ -0,0 +1,35 @@
1/*
2 * lgh06xf.h - ATSC Tuner support for LG TDVS-H06xF
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#ifndef _LGH06XF_H_
20#define _LGH06XF_H_
21#include "dvb_frontend.h"
22
23#if defined(CONFIG_DVB_TUNER_LGH06XF) || (defined(CONFIG_DVB_TUNER_LGH06XF_MODULE) && defined(MODULE))
24extern struct dvb_frontend* lgh06xf_attach(struct dvb_frontend* fe,
25 struct i2c_adapter *i2c);
26#else
27static inline struct dvb_frontend* lgh06xf_attach(struct dvb_frontend* fe,
28 struct i2c_adapter *i2c)
29{
30 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
31 return NULL;
32}
33#endif /* CONFIG_DVB_TUNER_LGH06XF */
34
35#endif /* _LGH06XF_H_ */
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index d20ab30c1e83..5a3a6e53cda2 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -40,6 +40,7 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <asm/byteorder.h> 41#include <asm/byteorder.h>
42 42
43#include "dvb_math.h"
43#include "dvb_frontend.h" 44#include "dvb_frontend.h"
44#include "dvb-pll.h" 45#include "dvb-pll.h"
45#include "or51132.h" 46#include "or51132.h"
@@ -62,6 +63,7 @@ struct or51132_state
62 63
63 /* Demodulator private data */ 64 /* Demodulator private data */
64 fe_modulation_t current_modulation; 65 fe_modulation_t current_modulation;
66 u32 snr; /* Result of last SNR calculation */
65 67
66 /* Tuner private data */ 68 /* Tuner private data */
67 u32 current_frequency; 69 u32 current_frequency;
@@ -465,124 +467,128 @@ static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status)
465 return 0; 467 return 0;
466} 468}
467 469
468/* log10-1 table at .5 increments from 1 to 100.5 */ 470/* Calculate SNR estimation (scaled by 2^24)
469static unsigned int i100x20log10[] = {
470 0, 352, 602, 795, 954, 1088, 1204, 1306, 1397, 1480,
471 1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
472 2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
473 2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
474 2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
475 2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
476 2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
477 3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
478 3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
479 3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
480 3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
481 3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
482 3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
483 3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
484 3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
485 3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
486 3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
487 3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
488 3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
489 3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
490};
491 471
492static unsigned int denom[] = {1,1,100,1000,10000,100000,1000000,10000000,100000000}; 472 8-VSB SNR and QAM equations from Oren datasheets
493 473
494static unsigned int i20Log10(unsigned short val) 474 For 8-VSB:
495{ 475 SNR[dB] = 10 * log10(897152044.8282 / MSE^2 ) - K
496 unsigned int rntval = 100; 476
497 unsigned int tmp = val; 477 Where K = 0 if NTSC rejection filter is OFF; and
498 unsigned int exp = 1; 478 K = 3 if NTSC rejection filter is ON
479
480 For QAM64:
481 SNR[dB] = 10 * log10(897152044.8282 / MSE^2 )
499 482
500 while(tmp > 100) {tmp /= 100; exp++;} 483 For QAM256:
484 SNR[dB] = 10 * log10(907832426.314266 / MSE^2 )
501 485
502 val = (2 * val)/denom[exp]; 486 We re-write the snr equation as:
503 if (exp > 1) rntval = 2000*exp; 487 SNR * 2^24 = 10*(c - 2*intlog10(MSE))
488 Where for QAM256, c = log10(907832426.314266) * 2^24
489 and for 8-VSB and QAM64, c = log10(897152044.8282) * 2^24 */
504 490
505 rntval += i100x20log10[val]; 491static u32 calculate_snr(u32 mse, u32 c)
506 return rntval; 492{
493 if (mse == 0) /* No signal */
494 return 0;
495
496 mse = 2*intlog10(mse);
497 if (mse > c) {
498 /* Negative SNR, which is possible, but realisticly the
499 demod will lose lock before the signal gets this bad. The
500 API only allows for unsigned values, so just return 0 */
501 return 0;
502 }
503 return 10*(c - mse);
507} 504}
508 505
509static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength) 506static int or51132_read_snr(struct dvb_frontend* fe, u16* snr)
510{ 507{
511 struct or51132_state* state = fe->demodulator_priv; 508 struct or51132_state* state = fe->demodulator_priv;
512 unsigned char rec_buf[2]; 509 u8 rec_buf[2];
513 unsigned char snd_buf[2]; 510 u8 snd_buf[2];
514 u8 rcvr_stat; 511 u32 noise;
515 u16 snr_equ; 512 u32 c;
516 u32 signal_strength; 513 u32 usK;
517 int usK;
518 514
515 /* Register is same for VSB or QAM firmware */
519 snd_buf[0]=0x04; 516 snd_buf[0]=0x04;
520 snd_buf[1]=0x02; /* SNR after Equalizer */ 517 snd_buf[1]=0x02; /* SNR after Equalizer */
521 msleep(30); /* 30ms */ 518 msleep(30); /* 30ms */
522 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) { 519 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
523 printk(KERN_WARNING "or51132: read_status write error\n"); 520 printk(KERN_WARNING "or51132: snr write error\n");
524 return -1; 521 return -EREMOTEIO;
525 } 522 }
526 msleep(30); /* 30ms */ 523 msleep(30); /* 30ms */
527 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 524 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
528 printk(KERN_WARNING "or51132: read_status read error\n"); 525 printk(KERN_WARNING "or51132: snr read error\n");
529 return -1; 526 return -EREMOTEIO;
530 } 527 }
531 snr_equ = rec_buf[0] | (rec_buf[1] << 8); 528 noise = rec_buf[0] | (rec_buf[1] << 8);
532 dprintk("read_signal_strength snr_equ %x %x (%i)\n",rec_buf[0],rec_buf[1],snr_equ); 529 dprintk("read_snr noise %x %x (%i)\n",rec_buf[0],rec_buf[1],noise);
533 530
534 /* Receiver Status */ 531 /* Read status, contains modulation type for QAM_AUTO and
532 NTSC filter for VSB */
535 snd_buf[0]=0x04; 533 snd_buf[0]=0x04;
536 snd_buf[1]=0x00; 534 snd_buf[1]=0x00; /* Status register */
537 msleep(30); /* 30ms */ 535 msleep(30); /* 30ms */
538 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) { 536 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
539 printk(KERN_WARNING "or51132: read_signal_strength read_status write error\n"); 537 printk(KERN_WARNING "or51132: status write error\n");
540 return -1; 538 return -EREMOTEIO;
541 } 539 }
542 msleep(30); /* 30ms */ 540 msleep(30); /* 30ms */
543 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 541 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
544 printk(KERN_WARNING "or51132: read_signal_strength read_status read error\n"); 542 printk(KERN_WARNING "or51132: status read error\n");
545 return -1; 543 return -EREMOTEIO;
546 } 544 }
547 dprintk("read_signal_strength read_status %x %x\n",rec_buf[0],rec_buf[1]);
548 rcvr_stat = rec_buf[1];
549 usK = (rcvr_stat & 0x10) ? 3 : 0;
550 545
551 /* The value reported back from the frontend will be FFFF=100% 0000=0% */ 546 usK = 0;
552 signal_strength = (((8952 - i20Log10(snr_equ) - usK*100)/3+5)*65535)/1000; 547 switch (rec_buf[0]) {
553 if (signal_strength > 0xffff) 548 case 0x06:
554 *strength = 0xffff; 549 usK = (rec_buf[1] & 0x10) ? 0x03000000 : 0;
555 else 550 /* Fall through to QAM64 case */
556 *strength = signal_strength; 551 case 0x43:
557 dprintk("read_signal_strength %i\n",*strength); 552 c = 150204167;
553 break;
554 case 0x45:
555 c = 150290396;
556 break;
557 default:
558 printk(KERN_ERR "or51132: unknown status 0x%02x\n", rec_buf[0]);
559 return -EREMOTEIO;
560 }
561 dprintk("%s: modulation %02x, NTSC rej O%s\n", __FUNCTION__,
562 rec_buf[0], rec_buf[1]&0x10?"n":"ff");
563
564 /* Calculate SNR using noise, c, and NTSC rejection correction */
565 state->snr = calculate_snr(noise, c) - usK;
566 *snr = (state->snr) >> 16;
567
568 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise,
569 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
558 570
559 return 0; 571 return 0;
560} 572}
561 573
562static int or51132_read_snr(struct dvb_frontend* fe, u16* snr) 574static int or51132_read_signal_strength(struct dvb_frontend* fe, u16* strength)
563{ 575{
564 struct or51132_state* state = fe->demodulator_priv; 576 /* Calculate Strength from SNR up to 35dB */
565 unsigned char rec_buf[2]; 577 /* Even though the SNR can go higher than 35dB, there is some comfort */
566 unsigned char snd_buf[2]; 578 /* factor in having a range of strong signals that can show at 100% */
567 u16 snr_equ; 579 struct or51132_state* state = (struct or51132_state*) fe->demodulator_priv;
568 580 u16 snr;
569 snd_buf[0]=0x04; 581 int ret;
570 snd_buf[1]=0x02; /* SNR after Equalizer */
571 msleep(30); /* 30ms */
572 if (i2c_writebytes(state,state->config->demod_address,snd_buf,2)) {
573 printk(KERN_WARNING "or51132: read_snr write error\n");
574 return -1;
575 }
576 msleep(30); /* 30ms */
577 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
578 printk(KERN_WARNING "or51132: read_snr dvr read error\n");
579 return -1;
580 }
581 snr_equ = rec_buf[0] | (rec_buf[1] << 8);
582 dprintk("read_snr snr_equ %x %x (%i)\n",rec_buf[0],rec_buf[1],snr_equ);
583 582
584 *snr = 0xFFFF - snr_equ; 583 ret = fe->ops.read_snr(fe, &snr);
585 dprintk("read_snr %i\n",*snr); 584 if (ret != 0)
585 return ret;
586 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
587 /* scale the range 0 - 35*2^24 into 0 - 65535 */
588 if (state->snr >= 8960 * 0x10000)
589 *strength = 0xffff;
590 else
591 *strength = state->snr / 8960;
586 592
587 return 0; 593 return 0;
588} 594}
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index 2bf124b53689..048d7cfe12d3 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -39,6 +39,7 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <asm/byteorder.h> 40#include <asm/byteorder.h>
41 41
42#include "dvb_math.h"
42#include "dvb_frontend.h" 43#include "dvb_frontend.h"
43#include "or51211.h" 44#include "or51211.h"
44 45
@@ -63,6 +64,7 @@ struct or51211_state {
63 64
64 /* Demodulator private data */ 65 /* Demodulator private data */
65 u8 initialized:1; 66 u8 initialized:1;
67 u32 snr; /* Result of last SNR claculation */
66 68
67 /* Tuner private data */ 69 /* Tuner private data */
68 u32 current_frequency; 70 u32 current_frequency;
@@ -292,107 +294,81 @@ static int or51211_read_status(struct dvb_frontend* fe, fe_status_t* status)
292 return 0; 294 return 0;
293} 295}
294 296
295/* log10-1 table at .5 increments from 1 to 100.5 */ 297/* Calculate SNR estimation (scaled by 2^24)
296static unsigned int i100x20log10[] = {
297 0, 352, 602, 795, 954, 1088, 1204, 1306, 1397, 1480,
298 1556, 1625, 1690, 1750, 1806, 1858, 1908, 1955, 2000, 2042,
299 2082, 2121, 2158, 2193, 2227, 2260, 2292, 2322, 2352, 2380,
300 2408, 2434, 2460, 2486, 2510, 2534, 2557, 2580, 2602, 2623,
301 2644, 2664, 2684, 2704, 2723, 2742, 2760, 2778, 2795, 2813,
302 2829, 2846, 2862, 2878, 2894, 2909, 2924, 2939, 2954, 2968,
303 2982, 2996, 3010, 3023, 3037, 3050, 3062, 3075, 3088, 3100,
304 3112, 3124, 3136, 3148, 3159, 3170, 3182, 3193, 3204, 3214,
305 3225, 3236, 3246, 3256, 3266, 3276, 3286, 3296, 3306, 3316,
306 3325, 3334, 3344, 3353, 3362, 3371, 3380, 3389, 3397, 3406,
307 3415, 3423, 3432, 3440, 3448, 3456, 3464, 3472, 3480, 3488,
308 3496, 3504, 3511, 3519, 3526, 3534, 3541, 3549, 3556, 3563,
309 3570, 3577, 3584, 3591, 3598, 3605, 3612, 3619, 3625, 3632,
310 3639, 3645, 3652, 3658, 3665, 3671, 3677, 3683, 3690, 3696,
311 3702, 3708, 3714, 3720, 3726, 3732, 3738, 3744, 3750, 3755,
312 3761, 3767, 3772, 3778, 3784, 3789, 3795, 3800, 3806, 3811,
313 3816, 3822, 3827, 3832, 3838, 3843, 3848, 3853, 3858, 3863,
314 3868, 3874, 3879, 3884, 3888, 3893, 3898, 3903, 3908, 3913,
315 3918, 3922, 3927, 3932, 3936, 3941, 3946, 3950, 3955, 3960,
316 3964, 3969, 3973, 3978, 3982, 3986, 3991, 3995, 4000, 4004,
317};
318
319static unsigned int denom[] = {1,1,100,1000,10000,100000,1000000,10000000,100000000};
320 298
321static unsigned int i20Log10(unsigned short val) 299 8-VSB SNR equation from Oren datasheets
322{
323 unsigned int rntval = 100;
324 unsigned int tmp = val;
325 unsigned int exp = 1;
326 300
327 while(tmp > 100) {tmp /= 100; exp++;} 301 For 8-VSB:
302 SNR[dB] = 10 * log10(219037.9454 / MSE^2 )
328 303
329 val = (2 * val)/denom[exp]; 304 We re-write the snr equation as:
330 if (exp > 1) rntval = 2000*exp; 305 SNR * 2^24 = 10*(c - 2*intlog10(MSE))
306 Where for 8-VSB, c = log10(219037.9454) * 2^24 */
331 307
332 rntval += i100x20log10[val]; 308static u32 calculate_snr(u32 mse, u32 c)
333 return rntval; 309{
310 if (mse == 0) /* No signal */
311 return 0;
312
313 mse = 2*intlog10(mse);
314 if (mse > c) {
315 /* Negative SNR, which is possible, but realisticly the
316 demod will lose lock before the signal gets this bad. The
317 API only allows for unsigned values, so just return 0 */
318 return 0;
319 }
320 return 10*(c - mse);
334} 321}
335 322
336static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength) 323static int or51211_read_snr(struct dvb_frontend* fe, u16* snr)
337{ 324{
338 struct or51211_state* state = fe->demodulator_priv; 325 struct or51211_state* state = fe->demodulator_priv;
339 u8 rec_buf[2]; 326 u8 rec_buf[2];
340 u8 snd_buf[4]; 327 u8 snd_buf[3];
341 u8 snr_equ;
342 u32 signal_strength;
343 328
344 /* SNR after Equalizer */ 329 /* SNR after Equalizer */
345 snd_buf[0] = 0x04; 330 snd_buf[0] = 0x04;
346 snd_buf[1] = 0x00; 331 snd_buf[1] = 0x00;
347 snd_buf[2] = 0x04; 332 snd_buf[2] = 0x04;
348 snd_buf[3] = 0x00;
349 333
350 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { 334 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
351 printk(KERN_WARNING "or51211: read_status write error\n"); 335 printk(KERN_WARNING "%s: error writing snr reg\n",
336 __FUNCTION__);
352 return -1; 337 return -1;
353 } 338 }
354 msleep(3);
355 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 339 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
356 printk(KERN_WARNING "or51211: read_status read error\n"); 340 printk(KERN_WARNING "%s: read_status read error\n",
341 __FUNCTION__);
357 return -1; 342 return -1;
358 } 343 }
359 snr_equ = rec_buf[0] & 0xff;
360 344
361 /* The value reported back from the frontend will be FFFF=100% 0000=0% */ 345 state->snr = calculate_snr(rec_buf[0], 89599047);
362 signal_strength = (((5334 - i20Log10(snr_equ))/3+5)*65535)/1000; 346 *snr = (state->snr) >> 16;
363 if (signal_strength > 0xffff) 347
364 *strength = 0xffff; 348 dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __FUNCTION__, rec_buf[0],
365 else 349 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
366 *strength = signal_strength;
367 dprintk("read_signal_strength %i\n",*strength);
368 350
369 return 0; 351 return 0;
370} 352}
371 353
372static int or51211_read_snr(struct dvb_frontend* fe, u16* snr) 354static int or51211_read_signal_strength(struct dvb_frontend* fe, u16* strength)
373{ 355{
374 struct or51211_state* state = fe->demodulator_priv; 356 /* Calculate Strength from SNR up to 35dB */
375 u8 rec_buf[2]; 357 /* Even though the SNR can go higher than 35dB, there is some comfort */
376 u8 snd_buf[4]; 358 /* factor in having a range of strong signals that can show at 100% */
377 359 struct or51211_state* state = (struct or51211_state*)fe->demodulator_priv;
378 /* SNR after Equalizer */ 360 u16 snr;
379 snd_buf[0] = 0x04; 361 int ret;
380 snd_buf[1] = 0x00; 362
381 snd_buf[2] = 0x04; 363 ret = fe->ops.read_snr(fe, &snr);
382 snd_buf[3] = 0x00; 364 if (ret != 0)
383 365 return ret;
384 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { 366 /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */
385 printk(KERN_WARNING "or51211: read_status write error\n"); 367 /* scale the range 0 - 35*2^24 into 0 - 65535 */
386 return -1; 368 if (state->snr >= 8960 * 0x10000)
387 } 369 *strength = 0xffff;
388 msleep(3); 370 else
389 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 371 *strength = state->snr / 8960;
390 printk(KERN_WARNING "or51211: read_status read error\n");
391 return -1;
392 }
393 *snr = rec_buf[0] & 0xff;
394
395 dprintk("read_snr %i\n",*snr);
396 372
397 return 0; 373 return 0;
398} 374}
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 11e0dca9a2d7..00e4bcd9f1a4 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -648,18 +648,24 @@ static int tda10046_init(struct dvb_frontend* fe)
648 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x0a); // AGC setup 648 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x0a); // AGC setup
649 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x00); // set AGC polarities 649 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x00); // set AGC polarities
650 break; 650 break;
651 case TDA10046_AGC_TDA827X: 651 case TDA10046_AGC_TDA827X_GP11:
652 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup 652 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup
653 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold 653 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold
654 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize 654 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize
655 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x6a); // set AGC polarities 655 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x6a); // set AGC polarities
656 break; 656 break;
657 case TDA10046_AGC_TDA827X_GPL: 657 case TDA10046_AGC_TDA827X_GP00:
658 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup 658 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup
659 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold 659 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold
660 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize 660 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize
661 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities 661 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x60); // set AGC polarities
662 break; 662 break;
663 case TDA10046_AGC_TDA827X_GP01:
664 tda1004x_write_byteI(state, TDA10046H_AGC_CONF, 0x02); // AGC setup
665 tda1004x_write_byteI(state, TDA10046H_AGC_THR, 0x70); // AGC Threshold
666 tda1004x_write_byteI(state, TDA10046H_AGC_RENORM, 0x08); // Gain Renormalize
667 tda1004x_write_byteI(state, TDA10046H_CONF_POLARITY, 0x62); // set AGC polarities
668 break;
663 } 669 }
664 tda1004x_write_byteI(state, TDA1004X_CONFADC2, 0x38); 670 tda1004x_write_byteI(state, TDA1004X_CONFADC2, 0x38);
665 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on 671 tda1004x_write_byteI(state, TDA10046H_CONF_TRISTATE1, 0x61); // Turn both AGC outputs on
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index 605ad2dfc09d..ec502d71b83c 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -35,8 +35,9 @@ enum tda10046_agc {
35 TDA10046_AGC_DEFAULT, /* original configuration */ 35 TDA10046_AGC_DEFAULT, /* original configuration */
36 TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negtive */ 36 TDA10046_AGC_IFO_AUTO_NEG, /* IF AGC only, automatic, negtive */
37 TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */ 37 TDA10046_AGC_IFO_AUTO_POS, /* IF AGC only, automatic, positive */
38 TDA10046_AGC_TDA827X, /* IF AGC only, special setup for tda827x */ 38 TDA10046_AGC_TDA827X_GP11, /* IF AGC only, special setup for tda827x */
39 TDA10046_AGC_TDA827X_GPL, /* same as above, but GPIOs 0 */ 39 TDA10046_AGC_TDA827X_GP00, /* same as above, but GPIOs 0 */
40 TDA10046_AGC_TDA827X_GP01, /* same as above, but GPIO3=0 GPIO1=1*/
40}; 41};
41 42
42enum tda10046_if { 43enum tda10046_if {
diff --git a/drivers/media/dvb/frontends/tda8083.c b/drivers/media/dvb/frontends/tda8083.c
index 3aa45ebbac3d..67415c9db6f7 100644
--- a/drivers/media/dvb/frontends/tda8083.c
+++ b/drivers/media/dvb/frontends/tda8083.c
@@ -262,12 +262,29 @@ static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status)
262 if (sync & 0x10) 262 if (sync & 0x10)
263 *status |= FE_HAS_SYNC; 263 *status |= FE_HAS_SYNC;
264 264
265 if (sync & 0x20) /* frontend can not lock */
266 *status |= FE_TIMEDOUT;
267
265 if ((sync & 0x1f) == 0x1f) 268 if ((sync & 0x1f) == 0x1f)
266 *status |= FE_HAS_LOCK; 269 *status |= FE_HAS_LOCK;
267 270
268 return 0; 271 return 0;
269} 272}
270 273
274static int tda8083_read_ber(struct dvb_frontend* fe, u32* ber)
275{
276 struct tda8083_state* state = fe->demodulator_priv;
277 int ret;
278 u8 buf[3];
279
280 if ((ret = tda8083_readregs(state, 0x0b, buf, sizeof(buf))))
281 return ret;
282
283 *ber = ((buf[0] & 0x1f) << 16) | (buf[1] << 8) | buf[2];
284
285 return 0;
286}
287
271static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength) 288static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength)
272{ 289{
273 struct tda8083_state* state = fe->demodulator_priv; 290 struct tda8083_state* state = fe->demodulator_priv;
@@ -288,6 +305,17 @@ static int tda8083_read_snr(struct dvb_frontend* fe, u16* snr)
288 return 0; 305 return 0;
289} 306}
290 307
308static int tda8083_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
309{
310 struct tda8083_state* state = fe->demodulator_priv;
311
312 *ucblocks = tda8083_readreg(state, 0x0f);
313 if (*ucblocks == 0xff)
314 *ucblocks = 0xffffffff;
315
316 return 0;
317}
318
291static int tda8083_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 319static int tda8083_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
292{ 320{
293 struct tda8083_state* state = fe->demodulator_priv; 321 struct tda8083_state* state = fe->demodulator_priv;
@@ -440,6 +468,8 @@ static struct dvb_frontend_ops tda8083_ops = {
440 .read_status = tda8083_read_status, 468 .read_status = tda8083_read_status,
441 .read_signal_strength = tda8083_read_signal_strength, 469 .read_signal_strength = tda8083_read_signal_strength,
442 .read_snr = tda8083_read_snr, 470 .read_snr = tda8083_read_snr,
471 .read_ber = tda8083_read_ber,
472 .read_ucblocks = tda8083_read_ucblocks,
443 473
444 .diseqc_send_master_cmd = tda8083_send_diseqc_msg, 474 .diseqc_send_master_cmd = tda8083_send_diseqc_msg,
445 .diseqc_send_burst = tda8083_diseqc_send_burst, 475 .diseqc_send_burst = tda8083_diseqc_send_burst,
diff --git a/drivers/media/dvb/frontends/tda826x.c b/drivers/media/dvb/frontends/tda826x.c
index 34815b0b97e4..79f971dc52b6 100644
--- a/drivers/media/dvb/frontends/tda826x.c
+++ b/drivers/media/dvb/frontends/tda826x.c
@@ -42,8 +42,7 @@ struct tda826x_priv {
42 42
43static int tda826x_release(struct dvb_frontend *fe) 43static int tda826x_release(struct dvb_frontend *fe)
44{ 44{
45 if (fe->tuner_priv) 45 kfree(fe->tuner_priv);
46 kfree(fe->tuner_priv);
47 fe->tuner_priv = NULL; 46 fe->tuner_priv = NULL;
48 return 0; 47 return 0;
49} 48}
@@ -133,18 +132,21 @@ struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2
133{ 132{
134 struct tda826x_priv *priv = NULL; 133 struct tda826x_priv *priv = NULL;
135 u8 b1 [] = { 0, 0 }; 134 u8 b1 [] = { 0, 0 };
136 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }; 135 struct i2c_msg msg[2] = {
136 { .addr = addr, .flags = 0, .buf = NULL, .len = 0 },
137 { .addr = addr, .flags = I2C_M_RD, .buf = b1, .len = 2 }
138 };
137 int ret; 139 int ret;
138 140
139 dprintk("%s:\n", __FUNCTION__); 141 dprintk("%s:\n", __FUNCTION__);
140 142
141 if (fe->ops.i2c_gate_ctrl) 143 if (fe->ops.i2c_gate_ctrl)
142 fe->ops.i2c_gate_ctrl(fe, 1); 144 fe->ops.i2c_gate_ctrl(fe, 1);
143 ret = i2c_transfer (i2c, &msg, 1); 145 ret = i2c_transfer (i2c, msg, 2);
144 if (fe->ops.i2c_gate_ctrl) 146 if (fe->ops.i2c_gate_ctrl)
145 fe->ops.i2c_gate_ctrl(fe, 0); 147 fe->ops.i2c_gate_ctrl(fe, 0);
146 148
147 if (ret != 1) 149 if (ret != 2)
148 return NULL; 150 return NULL;
149 if (!(b1[1] & 0x80)) 151 if (!(b1[1] & 0x80))
150 return NULL; 152 return NULL;
diff --git a/drivers/media/dvb/frontends/tua6100.c b/drivers/media/dvb/frontends/tua6100.c
index 88554393a9bf..6ba0029dcf2e 100644
--- a/drivers/media/dvb/frontends/tua6100.c
+++ b/drivers/media/dvb/frontends/tua6100.c
@@ -43,8 +43,7 @@ struct tua6100_priv {
43 43
44static int tua6100_release(struct dvb_frontend *fe) 44static int tua6100_release(struct dvb_frontend *fe)
45{ 45{
46 if (fe->tuner_priv) 46 kfree(fe->tuner_priv);
47 kfree(fe->tuner_priv);
48 fe->tuner_priv = NULL; 47 fe->tuner_priv = NULL;
49 return 0; 48 return 0;
50} 49}
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 8e4ce101eb22..ffda71dfdd65 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -650,7 +650,7 @@ static int __devinit pluto2_probe(struct pci_dev *pdev,
650 /* dvb */ 650 /* dvb */
651 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME, THIS_MODULE, &pdev->dev); 651 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME, THIS_MODULE, &pdev->dev);
652 if (ret < 0) 652 if (ret < 0)
653 goto err_i2c_bit_del_bus; 653 goto err_i2c_del_adapter;
654 654
655 dvb_adapter = &pluto->dvb_adapter; 655 dvb_adapter = &pluto->dvb_adapter;
656 656
@@ -712,8 +712,8 @@ err_dvb_dmx_release:
712 dvb_dmx_release(dvbdemux); 712 dvb_dmx_release(dvbdemux);
713err_dvb_unregister_adapter: 713err_dvb_unregister_adapter:
714 dvb_unregister_adapter(dvb_adapter); 714 dvb_unregister_adapter(dvb_adapter);
715err_i2c_bit_del_bus: 715err_i2c_del_adapter:
716 i2c_bit_del_bus(&pluto->i2c_adap); 716 i2c_del_adapter(&pluto->i2c_adap);
717err_pluto_hw_exit: 717err_pluto_hw_exit:
718 pluto_hw_exit(pluto); 718 pluto_hw_exit(pluto);
719err_free_irq: 719err_free_irq:
@@ -748,7 +748,7 @@ static void __devexit pluto2_remove(struct pci_dev *pdev)
748 dvb_dmxdev_release(&pluto->dmxdev); 748 dvb_dmxdev_release(&pluto->dmxdev);
749 dvb_dmx_release(dvbdemux); 749 dvb_dmx_release(dvbdemux);
750 dvb_unregister_adapter(dvb_adapter); 750 dvb_unregister_adapter(dvb_adapter);
751 i2c_bit_del_bus(&pluto->i2c_adap); 751 i2c_del_adapter(&pluto->i2c_adap);
752 pluto_hw_exit(pluto); 752 pluto_hw_exit(pluto);
753 free_irq(pdev->irq, pluto); 753 free_irq(pdev->irq, pluto);
754 pci_iounmap(pdev, pluto->io_mem); 754 pci_iounmap(pdev, pluto->io_mem);
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 95531a624991..eec7ccf41f8b 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -92,6 +92,7 @@ config DVB_BUDGET_CI
92 select DVB_STV0299 if !DVB_FE_CUSTOMISE 92 select DVB_STV0299 if !DVB_FE_CUSTOMISE
93 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 93 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
94 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 94 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
95 select VIDEO_IR
95 help 96 help
96 Support for simple SAA7146 based DVB cards 97 Support for simple SAA7146 based DVB cards
97 (so called Budget- or Nova-PCI cards) without onboard 98 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index bba23bcd1b11..366c1371ee97 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -2828,7 +2828,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
2828 2828
2829static struct saa7146_extension av7110_extension = { 2829static struct saa7146_extension av7110_extension = {
2830 .name = "dvb", 2830 .name = "dvb",
2831 .flags = SAA7146_I2C_SHORT_DELAY, 2831 .flags = SAA7146_USE_I2C_IRQ,
2832 2832
2833 .module = THIS_MODULE, 2833 .module = THIS_MODULE,
2834 .pci_tbl = &pci_tbl[0], 2834 .pci_tbl = &pci_tbl[0],
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index d54bbcdde2cc..e4544ea2b89b 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -48,7 +48,8 @@ static void av7110_emit_keyup(unsigned long data)
48 if (!data || !test_bit(data, input_dev->key)) 48 if (!data || !test_bit(data, input_dev->key))
49 return; 49 return;
50 50
51 input_event(input_dev, EV_KEY, data, !!0); 51 input_report_key(input_dev, data, 0);
52 input_sync(input_dev);
52} 53}
53 54
54 55
@@ -115,14 +116,17 @@ static void av7110_emit_key(unsigned long parm)
115 del_timer(&keyup_timer); 116 del_timer(&keyup_timer);
116 if (keyup_timer.data != keycode || new_toggle != old_toggle) { 117 if (keyup_timer.data != keycode || new_toggle != old_toggle) {
117 delay_timer_finished = 0; 118 delay_timer_finished = 0;
118 input_event(input_dev, EV_KEY, keyup_timer.data, !!0); 119 input_event(input_dev, EV_KEY, keyup_timer.data, 0);
119 input_event(input_dev, EV_KEY, keycode, !0); 120 input_event(input_dev, EV_KEY, keycode, 1);
120 } else 121 input_sync(input_dev);
121 if (delay_timer_finished) 122 } else if (delay_timer_finished) {
122 input_event(input_dev, EV_KEY, keycode, 2); 123 input_event(input_dev, EV_KEY, keycode, 2);
124 input_sync(input_dev);
125 }
123 } else { 126 } else {
124 delay_timer_finished = 0; 127 delay_timer_finished = 0;
125 input_event(input_dev, EV_KEY, keycode, !0); 128 input_event(input_dev, EV_KEY, keycode, 1);
129 input_sync(input_dev);
126 } 130 }
127 131
128 keyup_timer.expires = jiffies + UP_TIMEOUT; 132 keyup_timer.expires = jiffies + UP_TIMEOUT;
@@ -211,6 +215,7 @@ static void ir_handler(struct av7110 *av7110, u32 ircom)
211int __devinit av7110_ir_init(struct av7110 *av7110) 215int __devinit av7110_ir_init(struct av7110 *av7110)
212{ 216{
213 static struct proc_dir_entry *e; 217 static struct proc_dir_entry *e;
218 int err;
214 219
215 if (av_cnt >= sizeof av_list/sizeof av_list[0]) 220 if (av_cnt >= sizeof av_list/sizeof av_list[0])
216 return -ENOSPC; 221 return -ENOSPC;
@@ -231,7 +236,11 @@ int __devinit av7110_ir_init(struct av7110 *av7110)
231 set_bit(EV_KEY, input_dev->evbit); 236 set_bit(EV_KEY, input_dev->evbit);
232 set_bit(EV_REP, input_dev->evbit); 237 set_bit(EV_REP, input_dev->evbit);
233 input_register_keys(); 238 input_register_keys();
234 input_register_device(input_dev); 239 err = input_register_device(input_dev);
240 if (err) {
241 input_free_device(input_dev);
242 return err;
243 }
235 input_dev->timer.function = input_repeat_key; 244 input_dev->timer.function = input_repeat_key;
236 245
237 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL); 246 e = create_proc_entry("av7110_ir", S_IFREG | S_IRUGO | S_IWUSR, NULL);
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 2235ff8b8a1d..89ab4b59155c 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -360,7 +360,7 @@ static int ciintf_init(struct budget_av *budget_av)
360 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); 360 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
361 361
362 /* Enable DEBI pins */ 362 /* Enable DEBI pins */
363 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800); 363 saa7146_write(saa, MC1, MASK_27 | MASK_11);
364 364
365 /* register CI interface */ 365 /* register CI interface */
366 budget_av->ca.owner = THIS_MODULE; 366 budget_av->ca.owner = THIS_MODULE;
@@ -386,7 +386,7 @@ static int ciintf_init(struct budget_av *budget_av)
386 return 0; 386 return 0;
387 387
388error: 388error:
389 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); 389 saa7146_write(saa, MC1, MASK_27);
390 return result; 390 return result;
391} 391}
392 392
@@ -403,7 +403,7 @@ static void ciintf_deinit(struct budget_av *budget_av)
403 dvb_ca_en50221_release(&budget_av->ca); 403 dvb_ca_en50221_release(&budget_av->ca);
404 404
405 /* disable DEBI pins */ 405 /* disable DEBI pins */
406 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); 406 saa7146_write(saa, MC1, MASK_27);
407} 407}
408 408
409 409
@@ -655,6 +655,10 @@ static struct tda10021_config philips_cu1216_config = {
655 .demod_address = 0x0c, 655 .demod_address = 0x0c,
656}; 656};
657 657
658static struct tda10021_config philips_cu1216_config_altaddress = {
659 .demod_address = 0x0d,
660};
661
658 662
659 663
660 664
@@ -831,7 +835,7 @@ static int philips_sd1878_tda8261_tuner_set_params(struct dvb_frontend *fe,
831 return -EINVAL; 835 return -EINVAL;
832 836
833 rc=dvb_pll_configure(&dvb_pll_philips_sd1878_tda8261, buf, 837 rc=dvb_pll_configure(&dvb_pll_philips_sd1878_tda8261, buf,
834 params->frequency, 0); 838 params->frequency, 0);
835 if(rc < 0) return rc; 839 if(rc < 0) return rc;
836 840
837 if (fe->ops.i2c_gate_ctrl) 841 if (fe->ops.i2c_gate_ctrl)
@@ -914,6 +918,7 @@ static u8 read_pwm(struct budget_av *budget_av)
914#define SUBID_DVBS_TV_STAR_CI 0x0016 918#define SUBID_DVBS_TV_STAR_CI 0x0016
915#define SUBID_DVBS_EASYWATCH_1 0x001a 919#define SUBID_DVBS_EASYWATCH_1 0x001a
916#define SUBID_DVBS_EASYWATCH 0x001e 920#define SUBID_DVBS_EASYWATCH 0x001e
921#define SUBID_DVBC_EASYWATCH 0x002a
917#define SUBID_DVBC_KNC1 0x0020 922#define SUBID_DVBC_KNC1 0x0020
918#define SUBID_DVBC_KNC1_PLUS 0x0021 923#define SUBID_DVBC_KNC1_PLUS 0x0021
919#define SUBID_DVBC_CINERGY1200 0x1156 924#define SUBID_DVBC_CINERGY1200 0x1156
@@ -947,11 +952,15 @@ static void frontend_init(struct budget_av *budget_av)
947 /* Enable / PowerON Frontend */ 952 /* Enable / PowerON Frontend */
948 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO); 953 saa7146_setgpio(saa, 0, SAA7146_GPIO_OUTLO);
949 954
955 /* Wait for PowerON */
956 msleep(100);
957
950 /* additional setup necessary for the PLUS cards */ 958 /* additional setup necessary for the PLUS cards */
951 switch (saa->pci->subsystem_device) { 959 switch (saa->pci->subsystem_device) {
952 case SUBID_DVBS_KNC1_PLUS: 960 case SUBID_DVBS_KNC1_PLUS:
953 case SUBID_DVBC_KNC1_PLUS: 961 case SUBID_DVBC_KNC1_PLUS:
954 case SUBID_DVBT_KNC1_PLUS: 962 case SUBID_DVBT_KNC1_PLUS:
963 case SUBID_DVBC_EASYWATCH:
955 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI); 964 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTHI);
956 break; 965 break;
957 } 966 }
@@ -1006,10 +1015,15 @@ static void frontend_init(struct budget_av *budget_av)
1006 case SUBID_DVBC_KNC1: 1015 case SUBID_DVBC_KNC1:
1007 case SUBID_DVBC_KNC1_PLUS: 1016 case SUBID_DVBC_KNC1_PLUS:
1008 case SUBID_DVBC_CINERGY1200: 1017 case SUBID_DVBC_CINERGY1200:
1018 case SUBID_DVBC_EASYWATCH:
1009 budget_av->reinitialise_demod = 1; 1019 budget_av->reinitialise_demod = 1;
1010 fe = dvb_attach(tda10021_attach, &philips_cu1216_config, 1020 fe = dvb_attach(tda10021_attach, &philips_cu1216_config,
1011 &budget_av->budget.i2c_adap, 1021 &budget_av->budget.i2c_adap,
1012 read_pwm(budget_av)); 1022 read_pwm(budget_av));
1023 if (fe == NULL)
1024 fe = dvb_attach(tda10021_attach, &philips_cu1216_config_altaddress,
1025 &budget_av->budget.i2c_adap,
1026 read_pwm(budget_av));
1013 if (fe) { 1027 if (fe) {
1014 budget_av->tda10021_poclkp = 1; 1028 budget_av->tda10021_poclkp = 1;
1015 budget_av->tda10021_set_frontend = fe->ops.set_frontend; 1029 budget_av->tda10021_set_frontend = fe->ops.set_frontend;
@@ -1242,6 +1256,7 @@ MAKE_BUDGET_INFO(knc1t, "KNC1 DVB-T", BUDGET_KNC1T);
1242MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR); 1256MAKE_BUDGET_INFO(kncxs, "KNC TV STAR DVB-S", BUDGET_TVSTAR);
1243MAKE_BUDGET_INFO(satewpls, "Satelco EasyWatch DVB-S light", BUDGET_TVSTAR); 1257MAKE_BUDGET_INFO(satewpls, "Satelco EasyWatch DVB-S light", BUDGET_TVSTAR);
1244MAKE_BUDGET_INFO(satewpls1, "Satelco EasyWatch DVB-S light", BUDGET_KNC1S); 1258MAKE_BUDGET_INFO(satewpls1, "Satelco EasyWatch DVB-S light", BUDGET_KNC1S);
1259MAKE_BUDGET_INFO(satewplc, "Satelco EasyWatch DVB-C", BUDGET_KNC1CP);
1245MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP); 1260MAKE_BUDGET_INFO(knc1sp, "KNC1 DVB-S Plus", BUDGET_KNC1SP);
1246MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP); 1261MAKE_BUDGET_INFO(knc1cp, "KNC1 DVB-C Plus", BUDGET_KNC1CP);
1247MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP); 1262MAKE_BUDGET_INFO(knc1tp, "KNC1 DVB-T Plus", BUDGET_KNC1TP);
@@ -1260,6 +1275,7 @@ static struct pci_device_id pci_tbl[] = {
1260 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016), 1275 MAKE_EXTENSION_PCI(kncxs, 0x1894, 0x0016),
1261 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e), 1276 MAKE_EXTENSION_PCI(satewpls, 0x1894, 0x001e),
1262 MAKE_EXTENSION_PCI(satewpls1, 0x1894, 0x001a), 1277 MAKE_EXTENSION_PCI(satewpls1, 0x1894, 0x001a),
1278 MAKE_EXTENSION_PCI(satewplc, 0x1894, 0x002a),
1263 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020), 1279 MAKE_EXTENSION_PCI(knc1c, 0x1894, 0x0020),
1264 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021), 1280 MAKE_EXTENSION_PCI(knc1cp, 0x1894, 0x0021),
1265 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030), 1281 MAKE_EXTENSION_PCI(knc1t, 0x1894, 0x0030),
@@ -1277,7 +1293,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
1277 1293
1278static struct saa7146_extension budget_extension = { 1294static struct saa7146_extension budget_extension = {
1279 .name = "budget_av", 1295 .name = "budget_av",
1280 .flags = SAA7146_I2C_SHORT_DELAY, 1296 .flags = SAA7146_USE_I2C_IRQ,
1281 1297
1282 .pci_tbl = pci_tbl, 1298 .pci_tbl = pci_tbl,
1283 1299
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index cd5ec489af1c..f2066b47baee 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -37,6 +37,7 @@
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/input.h> 38#include <linux/input.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <media/ir-common.h>
40 41
41#include "dvb_ca_en50221.h" 42#include "dvb_ca_en50221.h"
42#include "stv0299.h" 43#include "stv0299.h"
@@ -72,162 +73,218 @@
72#define SLOTSTATUS_READY 8 73#define SLOTSTATUS_READY 8
73#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY) 74#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
74 75
76/* Milliseconds during which key presses are regarded as key repeat and during
77 * which the debounce logic is active
78 */
79#define IR_REPEAT_TIMEOUT 350
80
81/* RC5 device wildcard */
82#define IR_DEVICE_ANY 255
83
84/* Some remotes sends multiple sequences per keypress (e.g. Zenith sends two),
85 * this setting allows the superflous sequences to be ignored
86 */
87static int debounce = 0;
88module_param(debounce, int, 0644);
89MODULE_PARM_DESC(debounce, "ignore repeated IR sequences (default: 0 = ignore no sequences)");
90
91static int rc5_device = -1;
92module_param(rc5_device, int, 0644);
93MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
94
95static int ir_debug = 0;
96module_param(ir_debug, int, 0644);
97MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
98
99struct budget_ci_ir {
100 struct input_dev *dev;
101 struct tasklet_struct msp430_irq_tasklet;
102 char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
103 char phys[32];
104 struct ir_input_state state;
105 int rc5_device;
106};
107
75struct budget_ci { 108struct budget_ci {
76 struct budget budget; 109 struct budget budget;
77 struct input_dev *input_dev;
78 struct tasklet_struct msp430_irq_tasklet;
79 struct tasklet_struct ciintf_irq_tasklet; 110 struct tasklet_struct ciintf_irq_tasklet;
80 int slot_status; 111 int slot_status;
81 int ci_irq; 112 int ci_irq;
82 struct dvb_ca_en50221 ca; 113 struct dvb_ca_en50221 ca;
83 char ir_dev_name[50]; 114 struct budget_ci_ir ir;
84 u8 tuner_pll_address; /* used for philips_tdm1316l configs */ 115 u8 tuner_pll_address; /* used for philips_tdm1316l configs */
85}; 116};
86 117
87/* from reading the following remotes: 118static void msp430_ir_keyup(unsigned long data)
88 Zenith Universal 7 / TV Mode 807 / VCR Mode 837
89 Hauppauge (from NOVA-CI-s box product)
90 i've taken a "middle of the road" approach and note the differences
91*/
92static u16 key_map[64] = {
93 /* 0x0X */
94 KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8,
95 KEY_9,
96 KEY_ENTER,
97 KEY_RED,
98 KEY_POWER, /* RADIO on Hauppauge */
99 KEY_MUTE,
100 0,
101 KEY_A, /* TV on Hauppauge */
102 /* 0x1X */
103 KEY_VOLUMEUP, KEY_VOLUMEDOWN,
104 0, 0,
105 KEY_B,
106 0, 0, 0, 0, 0, 0, 0,
107 KEY_UP, KEY_DOWN,
108 KEY_OPTION, /* RESERVED on Hauppauge */
109 KEY_BREAK,
110 /* 0x2X */
111 KEY_CHANNELUP, KEY_CHANNELDOWN,
112 KEY_PREVIOUS, /* Prev. Ch on Zenith, SOURCE on Hauppauge */
113 0, KEY_RESTART, KEY_OK,
114 KEY_CYCLEWINDOWS, /* MINIMIZE on Hauppauge */
115 0,
116 KEY_ENTER, /* VCR mode on Zenith */
117 KEY_PAUSE,
118 0,
119 KEY_RIGHT, KEY_LEFT,
120 0,
121 KEY_MENU, /* FULL SCREEN on Hauppauge */
122 0,
123 /* 0x3X */
124 KEY_SLOW,
125 KEY_PREVIOUS, /* VCR mode on Zenith */
126 KEY_REWIND,
127 0,
128 KEY_FASTFORWARD,
129 KEY_PLAY, KEY_STOP,
130 KEY_RECORD,
131 KEY_TUNER, /* TV/VCR on Zenith */
132 0,
133 KEY_C,
134 0,
135 KEY_EXIT,
136 KEY_POWER2,
137 KEY_TUNER, /* VCR mode on Zenith */
138 0,
139};
140
141static void msp430_ir_debounce(unsigned long data)
142{ 119{
143 struct input_dev *dev = (struct input_dev *) data; 120 struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
144 121 ir_input_nokey(ir->dev, &ir->state);
145 if (dev->rep[0] == 0 || dev->rep[0] == ~0) {
146 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
147 return;
148 }
149
150 dev->rep[0] = 0;
151 dev->timer.expires = jiffies + HZ * 350 / 1000;
152 add_timer(&dev->timer);
153 input_event(dev, EV_KEY, key_map[dev->repeat_key], 2); /* REPEAT */
154} 122}
155 123
156static void msp430_ir_interrupt(unsigned long data) 124static void msp430_ir_interrupt(unsigned long data)
157{ 125{
158 struct budget_ci *budget_ci = (struct budget_ci *) data; 126 struct budget_ci *budget_ci = (struct budget_ci *) data;
159 struct input_dev *dev = budget_ci->input_dev; 127 struct input_dev *dev = budget_ci->ir.dev;
160 unsigned int code = 128 static int bounces = 0;
161 ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8; 129 int device;
130 int toggle;
131 static int prev_toggle = -1;
132 static u32 ir_key;
133 u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
134
135 /*
136 * The msp430 chip can generate two different bytes, command and device
137 *
138 * type1: X1CCCCCC, C = command bits (0 - 63)
139 * type2: X0TDDDDD, D = device bits (0 - 31), T = RC5 toggle bit
140 *
141 * More than one command byte may be generated before the device byte
142 * Only when we have both, a correct keypress is generated
143 */
144
145 /* Is this a RC5 command byte? */
146 if (command & 0x40) {
147 if (ir_debug)
148 printk("budget_ci: received command byte 0x%02x\n", command);
149 ir_key = command & 0x3f;
150 return;
151 }
162 152
163 if (code & 0x40) { 153 /* It's a RC5 device byte */
164 code &= 0x3f; 154 if (ir_debug)
155 printk("budget_ci: received device byte 0x%02x\n", command);
156 device = command & 0x1f;
157 toggle = command & 0x20;
165 158
166 if (timer_pending(&dev->timer)) { 159 if (budget_ci->ir.rc5_device != IR_DEVICE_ANY && budget_ci->ir.rc5_device != device)
167 if (code == dev->repeat_key) { 160 return;
168 ++dev->rep[0];
169 return;
170 }
171 del_timer(&dev->timer);
172 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0);
173 }
174 161
175 if (!key_map[code]) { 162 /* Ignore repeated key sequences if requested */
176 printk("DVB (%s): no key for %02x!\n", __FUNCTION__, code); 163 if (toggle == prev_toggle && ir_key == dev->repeat_key &&
177 return; 164 bounces > 0 && timer_pending(&dev->timer)) {
178 } 165 if (ir_debug)
166 printk("budget_ci: debounce logic ignored IR command\n");
167 bounces--;
168 return;
169 }
170 prev_toggle = toggle;
179 171
180 /* initialize debounce and repeat */ 172 /* Are we still waiting for a keyup event? */
181 dev->repeat_key = code; 173 if (del_timer(&dev->timer))
182 /* Zenith remote _always_ sends 2 sequences */ 174 ir_input_nokey(dev, &budget_ci->ir.state);
183 dev->rep[0] = ~0; 175
184 /* 350 milliseconds */ 176 /* Generate keypress */
185 dev->timer.expires = jiffies + HZ * 350 / 1000; 177 if (ir_debug)
186 /* MAKE */ 178 printk("budget_ci: generating keypress 0x%02x\n", ir_key);
187 input_event(dev, EV_KEY, key_map[code], !0); 179 ir_input_keydown(dev, &budget_ci->ir.state, ir_key, (ir_key & (command << 8)));
188 add_timer(&dev->timer); 180
181 /* Do we want to delay the keyup event? */
182 if (debounce) {
183 bounces = debounce;
184 mod_timer(&dev->timer, jiffies + msecs_to_jiffies(IR_REPEAT_TIMEOUT));
185 } else {
186 ir_input_nokey(dev, &budget_ci->ir.state);
189 } 187 }
190} 188}
191 189
192static int msp430_ir_init(struct budget_ci *budget_ci) 190static int msp430_ir_init(struct budget_ci *budget_ci)
193{ 191{
194 struct saa7146_dev *saa = budget_ci->budget.dev; 192 struct saa7146_dev *saa = budget_ci->budget.dev;
195 struct input_dev *input_dev; 193 struct input_dev *input_dev = budget_ci->ir.dev;
196 int i; 194 int error;
195
196 budget_ci->ir.dev = input_dev = input_allocate_device();
197 if (!input_dev) {
198 printk(KERN_ERR "budget_ci: IR interface initialisation failed\n");
199 error = -ENOMEM;
200 goto out1;
201 }
202
203 snprintf(budget_ci->ir.name, sizeof(budget_ci->ir.name),
204 "Budget-CI dvb ir receiver %s", saa->name);
205 snprintf(budget_ci->ir.phys, sizeof(budget_ci->ir.phys),
206 "pci-%s/ir0", pci_name(saa->pci));
197 207
198 budget_ci->input_dev = input_dev = input_allocate_device(); 208 input_dev->name = budget_ci->ir.name;
199 if (!input_dev)
200 return -ENOMEM;
201 209
202 sprintf(budget_ci->ir_dev_name, "Budget-CI dvb ir receiver %s", saa->name); 210 input_dev->phys = budget_ci->ir.phys;
211 input_dev->id.bustype = BUS_PCI;
212 input_dev->id.version = 1;
213 if (saa->pci->subsystem_vendor) {
214 input_dev->id.vendor = saa->pci->subsystem_vendor;
215 input_dev->id.product = saa->pci->subsystem_device;
216 } else {
217 input_dev->id.vendor = saa->pci->vendor;
218 input_dev->id.product = saa->pci->device;
219 }
220 input_dev->cdev.dev = &saa->pci->dev;
203 221
204 input_dev->name = budget_ci->ir_dev_name; 222 /* Select keymap and address */
223 switch (budget_ci->budget.dev->pci->subsystem_device) {
224 case 0x100c:
225 case 0x100f:
226 case 0x1010:
227 case 0x1011:
228 case 0x1012:
229 case 0x1017:
230 /* The hauppauge keymap is a superset of these remotes */
231 ir_input_init(input_dev, &budget_ci->ir.state,
232 IR_TYPE_RC5, ir_codes_hauppauge_new);
233
234 if (rc5_device < 0)
235 budget_ci->ir.rc5_device = 0x1f;
236 else
237 budget_ci->ir.rc5_device = rc5_device;
238 break;
239 default:
240 /* unknown remote */
241 ir_input_init(input_dev, &budget_ci->ir.state,
242 IR_TYPE_RC5, ir_codes_budget_ci_old);
243
244 if (rc5_device < 0)
245 budget_ci->ir.rc5_device = IR_DEVICE_ANY;
246 else
247 budget_ci->ir.rc5_device = rc5_device;
248 break;
249 }
205 250
206 set_bit(EV_KEY, input_dev->evbit); 251 /* initialise the key-up debounce timeout handler */
207 for (i = 0; i < ARRAY_SIZE(key_map); i++) 252 input_dev->timer.function = msp430_ir_keyup;
208 if (key_map[i]) 253 input_dev->timer.data = (unsigned long) &budget_ci->ir;
209 set_bit(key_map[i], input_dev->keybit);
210 254
211 input_register_device(budget_ci->input_dev); 255 error = input_register_device(input_dev);
256 if (error) {
257 printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
258 goto out2;
259 }
212 260
213 input_dev->timer.function = msp430_ir_debounce; 261 tasklet_init(&budget_ci->ir.msp430_irq_tasklet, msp430_ir_interrupt,
262 (unsigned long) budget_ci);
214 263
215 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_06); 264 SAA7146_IER_ENABLE(saa, MASK_06);
216 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI); 265 saa7146_setgpio(saa, 3, SAA7146_GPIO_IRQHI);
217 266
218 return 0; 267 return 0;
268
269out2:
270 input_free_device(input_dev);
271out1:
272 return error;
219} 273}
220 274
221static void msp430_ir_deinit(struct budget_ci *budget_ci) 275static void msp430_ir_deinit(struct budget_ci *budget_ci)
222{ 276{
223 struct saa7146_dev *saa = budget_ci->budget.dev; 277 struct saa7146_dev *saa = budget_ci->budget.dev;
224 struct input_dev *dev = budget_ci->input_dev; 278 struct input_dev *dev = budget_ci->ir.dev;
225 279
226 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_06); 280 SAA7146_IER_DISABLE(saa, MASK_06);
227 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT); 281 saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
282 tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
228 283
229 if (del_timer(&dev->timer)) 284 if (del_timer(&dev->timer)) {
230 input_event(dev, EV_KEY, key_map[dev->repeat_key], !!0); 285 ir_input_nokey(dev, &budget_ci->ir.state);
286 input_sync(dev);
287 }
231 288
232 input_unregister_device(dev); 289 input_unregister_device(dev);
233} 290}
@@ -428,7 +485,7 @@ static int ciintf_init(struct budget_ci *budget_ci)
428 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221)); 485 memset(&budget_ci->ca, 0, sizeof(struct dvb_ca_en50221));
429 486
430 // enable DEBI pins 487 // enable DEBI pins
431 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16) | 0x800); 488 saa7146_write(saa, MC1, MASK_27 | MASK_11);
432 489
433 // test if it is there 490 // test if it is there
434 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0); 491 ci_version = ttpci_budget_debiread(&budget_ci->budget, DEBICICTL, DEBIADDR_CIVERSION, 1, 1, 0);
@@ -480,7 +537,7 @@ static int ciintf_init(struct budget_ci *budget_ci)
480 } else { 537 } else {
481 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI); 538 saa7146_setgpio(saa, 0, SAA7146_GPIO_IRQHI);
482 } 539 }
483 saa7146_write(saa, IER, saa7146_read(saa, IER) | MASK_03); 540 SAA7146_IER_ENABLE(saa, MASK_03);
484 } 541 }
485 542
486 // enable interface 543 // enable interface
@@ -502,7 +559,7 @@ static int ciintf_init(struct budget_ci *budget_ci)
502 return 0; 559 return 0;
503 560
504error: 561error:
505 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); 562 saa7146_write(saa, MC1, MASK_27);
506 return result; 563 return result;
507} 564}
508 565
@@ -512,7 +569,7 @@ static void ciintf_deinit(struct budget_ci *budget_ci)
512 569
513 // disable CI interrupts 570 // disable CI interrupts
514 if (budget_ci->ci_irq) { 571 if (budget_ci->ci_irq) {
515 saa7146_write(saa, IER, saa7146_read(saa, IER) & ~MASK_03); 572 SAA7146_IER_DISABLE(saa, MASK_03);
516 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT); 573 saa7146_setgpio(saa, 0, SAA7146_GPIO_INPUT);
517 tasklet_kill(&budget_ci->ciintf_irq_tasklet); 574 tasklet_kill(&budget_ci->ciintf_irq_tasklet);
518 } 575 }
@@ -530,7 +587,7 @@ static void ciintf_deinit(struct budget_ci *budget_ci)
530 dvb_ca_en50221_release(&budget_ci->ca); 587 dvb_ca_en50221_release(&budget_ci->ca);
531 588
532 // disable DEBI pins 589 // disable DEBI pins
533 saa7146_write(saa, MC1, saa7146_read(saa, MC1) | (0x800 << 16)); 590 saa7146_write(saa, MC1, MASK_27);
534} 591}
535 592
536static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr) 593static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
@@ -540,7 +597,7 @@ static void budget_ci_irq(struct saa7146_dev *dev, u32 * isr)
540 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci); 597 dprintk(8, "dev: %p, budget_ci: %p\n", dev, budget_ci);
541 598
542 if (*isr & MASK_06) 599 if (*isr & MASK_06)
543 tasklet_schedule(&budget_ci->msp430_irq_tasklet); 600 tasklet_schedule(&budget_ci->ir.msp430_irq_tasklet);
544 601
545 if (*isr & MASK_10) 602 if (*isr & MASK_10)
546 ttpci_budget_irq10_handler(dev, isr); 603 ttpci_budget_irq10_handler(dev, isr);
@@ -835,7 +892,7 @@ static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struc
835 band = 1; 892 band = 1;
836 } else if (tuner_frequency < 200000000) { 893 } else if (tuner_frequency < 200000000) {
837 cp = 6; 894 cp = 6;
838 band = 1; 895 band = 2;
839 } else if (tuner_frequency < 290000000) { 896 } else if (tuner_frequency < 290000000) {
840 cp = 3; 897 cp = 3;
841 band = 2; 898 band = 2;
@@ -1083,24 +1140,23 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1083 struct budget_ci *budget_ci; 1140 struct budget_ci *budget_ci;
1084 int err; 1141 int err;
1085 1142
1086 if (!(budget_ci = kmalloc(sizeof(struct budget_ci), GFP_KERNEL))) 1143 budget_ci = kzalloc(sizeof(struct budget_ci), GFP_KERNEL);
1087 return -ENOMEM; 1144 if (!budget_ci) {
1145 err = -ENOMEM;
1146 goto out1;
1147 }
1088 1148
1089 dprintk(2, "budget_ci: %p\n", budget_ci); 1149 dprintk(2, "budget_ci: %p\n", budget_ci);
1090 1150
1091 budget_ci->budget.ci_present = 0;
1092
1093 dev->ext_priv = budget_ci; 1151 dev->ext_priv = budget_ci;
1094 1152
1095 if ((err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE))) { 1153 err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE);
1096 kfree(budget_ci); 1154 if (err)
1097 return err; 1155 goto out2;
1098 }
1099
1100 tasklet_init(&budget_ci->msp430_irq_tasklet, msp430_ir_interrupt,
1101 (unsigned long) budget_ci);
1102 1156
1103 msp430_ir_init(budget_ci); 1157 err = msp430_ir_init(budget_ci);
1158 if (err)
1159 goto out3;
1104 1160
1105 ciintf_init(budget_ci); 1161 ciintf_init(budget_ci);
1106 1162
@@ -1110,6 +1166,13 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1110 ttpci_budget_init_hooks(&budget_ci->budget); 1166 ttpci_budget_init_hooks(&budget_ci->budget);
1111 1167
1112 return 0; 1168 return 0;
1169
1170out3:
1171 ttpci_budget_deinit(&budget_ci->budget);
1172out2:
1173 kfree(budget_ci);
1174out1:
1175 return err;
1113} 1176}
1114 1177
1115static int budget_ci_detach(struct saa7146_dev *dev) 1178static int budget_ci_detach(struct saa7146_dev *dev)
@@ -1120,16 +1183,13 @@ static int budget_ci_detach(struct saa7146_dev *dev)
1120 1183
1121 if (budget_ci->budget.ci_present) 1184 if (budget_ci->budget.ci_present)
1122 ciintf_deinit(budget_ci); 1185 ciintf_deinit(budget_ci);
1186 msp430_ir_deinit(budget_ci);
1123 if (budget_ci->budget.dvb_frontend) { 1187 if (budget_ci->budget.dvb_frontend) {
1124 dvb_unregister_frontend(budget_ci->budget.dvb_frontend); 1188 dvb_unregister_frontend(budget_ci->budget.dvb_frontend);
1125 dvb_frontend_detach(budget_ci->budget.dvb_frontend); 1189 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1126 } 1190 }
1127 err = ttpci_budget_deinit(&budget_ci->budget); 1191 err = ttpci_budget_deinit(&budget_ci->budget);
1128 1192
1129 tasklet_kill(&budget_ci->msp430_irq_tasklet);
1130
1131 msp430_ir_deinit(budget_ci);
1132
1133 // disable frontend and CI interface 1193 // disable frontend and CI interface
1134 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT); 1194 saa7146_setgpio(saa, 2, SAA7146_GPIO_INPUT);
1135 1195
@@ -1162,7 +1222,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
1162 1222
1163static struct saa7146_extension budget_extension = { 1223static struct saa7146_extension budget_extension = {
1164 .name = "budget_ci dvb", 1224 .name = "budget_ci dvb",
1165 .flags = SAA7146_I2C_SHORT_DELAY, 1225 .flags = SAA7146_USE_I2C_IRQ,
1166 1226
1167 .module = THIS_MODULE, 1227 .module = THIS_MODULE,
1168 .pci_tbl = &pci_tbl[0], 1228 .pci_tbl = &pci_tbl[0],
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 56f1c80defc6..9268a82bada6 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -555,7 +555,7 @@ MODULE_DEVICE_TABLE(pci, pci_tbl);
555 555
556static struct saa7146_extension budget_extension = { 556static struct saa7146_extension budget_extension = {
557 .name = "budget dvb", 557 .name = "budget dvb",
558 .flags = SAA7146_I2C_SHORT_DELAY, 558 .flags = SAA7146_USE_I2C_IRQ,
559 559
560 .module = THIS_MODULE, 560 .module = THIS_MODULE,
561 .pci_tbl = pci_tbl, 561 .pci_tbl = pci_tbl,
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 10b121ada833..bd6e7baae2ec 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -238,6 +238,7 @@ static void ttusb_dec_handle_irq( struct urb *urb)
238 * for now lets report each signal as a key down and up*/ 238 * for now lets report each signal as a key down and up*/
239 dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]); 239 dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]);
240 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1); 240 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1);
241 input_sync(dec->rc_input_dev);
241 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0); 242 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0);
242 input_sync(dec->rc_input_dev); 243 input_sync(dec->rc_input_dev);
243 } 244 }
@@ -1187,11 +1188,12 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
1187 struct input_dev *input_dev; 1188 struct input_dev *input_dev;
1188 u8 b[] = { 0x00, 0x01 }; 1189 u8 b[] = { 0x00, 0x01 };
1189 int i; 1190 int i;
1191 int err;
1190 1192
1191 usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys)); 1193 usb_make_path(dec->udev, dec->rc_phys, sizeof(dec->rc_phys));
1192 strlcpy(dec->rc_phys, "/input0", sizeof(dec->rc_phys)); 1194 strlcpy(dec->rc_phys, "/input0", sizeof(dec->rc_phys));
1193 1195
1194 dec->rc_input_dev = input_dev = input_allocate_device(); 1196 input_dev = input_allocate_device();
1195 if (!input_dev) 1197 if (!input_dev)
1196 return -ENOMEM; 1198 return -ENOMEM;
1197 1199
@@ -1205,8 +1207,13 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
1205 for (i = 0; i < ARRAY_SIZE(rc_keys); i++) 1207 for (i = 0; i < ARRAY_SIZE(rc_keys); i++)
1206 set_bit(rc_keys[i], input_dev->keybit); 1208 set_bit(rc_keys[i], input_dev->keybit);
1207 1209
1208 input_register_device(input_dev); 1210 err = input_register_device(input_dev);
1211 if (err) {
1212 input_free_device(input_dev);
1213 return err;
1214 }
1209 1215
1216 dec->rc_input_dev = input_dev;
1210 if (usb_submit_urb(dec->irq_urb, GFP_KERNEL)) 1217 if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1211 printk("%s: usb_submit_urb failed\n",__FUNCTION__); 1218 printk("%s: usb_submit_urb failed\n",__FUNCTION__);
1212 /* enable irq pipe */ 1219 /* enable irq pipe */
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index b8fde5cf4735..29a11c1db1b7 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -184,6 +184,14 @@ config VIDEO_KS0127
184 To compile this driver as a module, choose M here: the 184 To compile this driver as a module, choose M here: the
185 module will be called ks0127. 185 module will be called ks0127.
186 186
187config VIDEO_OV7670
188 tristate "OmniVision OV7670 sensor support"
189 depends on I2C && VIDEO_V4L2
190 ---help---
191 This is a Video4Linux2 sensor-level driver for the OmniVision
192 OV7670 VGA camera. It currently only works with the M88ALP01
193 controller.
194
187config VIDEO_SAA7110 195config VIDEO_SAA7110
188 tristate "Philips SAA7110 video decoder" 196 tristate "Philips SAA7110 video decoder"
189 depends on VIDEO_V4L1 && I2C 197 depends on VIDEO_V4L1 && I2C
@@ -567,18 +575,6 @@ config VIDEO_ZORAN_AVS6EYES
567 help 575 help
568 Support for the AverMedia 6 Eyes video surveillance card. 576 Support for the AverMedia 6 Eyes video surveillance card.
569 577
570config VIDEO_ZR36120
571 tristate "Zoran ZR36120/36125 Video For Linux"
572 depends on PCI && I2C && VIDEO_V4L1 && BROKEN
573 help
574 Support for ZR36120/ZR36125 based frame grabber/overlay boards.
575 This includes the Victor II, WaveWatcher, Video Wonder, Maxi-TV,
576 and Buster boards. Please read the material in
577 <file:Documentation/video4linux/zr36120.txt> for more information.
578
579 To compile this driver as a module, choose M here: the
580 module will be called zr36120.
581
582config VIDEO_MEYE 578config VIDEO_MEYE
583 tristate "Sony Vaio Picturebook Motion Eye Video For Linux" 579 tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
584 depends on PCI && SONYPI && VIDEO_V4L1 580 depends on PCI && SONYPI && VIDEO_V4L1
@@ -670,6 +666,15 @@ config VIDEO_M32R_AR_M64278
670 To compile this driver as a module, choose M here: the 666 To compile this driver as a module, choose M here: the
671 module will be called arv. 667 module will be called arv.
672 668
669config VIDEO_CAFE_CCIC
670 tristate "Marvell 88ALP01 (Cafe) CMOS Camera Controller support"
671 depends on I2C && VIDEO_V4L2
672 select VIDEO_OV7670
673 ---help---
674 This is a video4linux2 driver for the Marvell 88ALP01 integrated
675 CMOS camera controller. This is the controller found on first-
676 generation OLPC systems.
677
673# 678#
674# USB Multimedia device configuration 679# USB Multimedia device configuration
675# 680#
@@ -681,6 +686,8 @@ source "drivers/media/video/pvrusb2/Kconfig"
681 686
682source "drivers/media/video/em28xx/Kconfig" 687source "drivers/media/video/em28xx/Kconfig"
683 688
689source "drivers/media/video/usbvision/Kconfig"
690
684source "drivers/media/video/usbvideo/Kconfig" 691source "drivers/media/video/usbvideo/Kconfig"
685 692
686source "drivers/media/video/et61x251/Kconfig" 693source "drivers/media/video/et61x251/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index af57abce8a6e..9b1f3f06bb7c 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -2,7 +2,6 @@
2# Makefile for the video capture/playback device drivers. 2# Makefile for the video capture/playback device drivers.
3# 3#
4 4
5zoran-objs := zr36120.o zr36120_i2c.o zr36120_mem.o
6zr36067-objs := zoran_procfs.o zoran_device.o \ 5zr36067-objs := zoran_procfs.o zoran_device.o \
7 zoran_driver.o zoran_card.o 6 zoran_driver.o zoran_card.o
8tuner-objs := tuner-core.o tuner-types.o tuner-simple.o \ 7tuner-objs := tuner-core.o tuner-types.o tuner-simple.o \
@@ -23,7 +22,6 @@ obj-$(CONFIG_VIDEO_TDA7432) += tda7432.o
23obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o 22obj-$(CONFIG_VIDEO_TDA9875) += tda9875.o
24obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o 23obj-$(CONFIG_SOUND_TVMIXER) += tvmixer.o
25 24
26obj-$(CONFIG_VIDEO_ZR36120) += zoran.o
27obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o 25obj-$(CONFIG_VIDEO_SAA6588) += saa6588.o
28obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o 26obj-$(CONFIG_VIDEO_SAA5246A) += saa5246a.o
29obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o 27obj-$(CONFIG_VIDEO_SAA5249) += saa5249.o
@@ -64,6 +62,7 @@ obj-$(CONFIG_VIDEO_MEYE) += meye.o
64obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/ 62obj-$(CONFIG_VIDEO_SAA7134) += ir-kbd-i2c.o saa7134/
65obj-$(CONFIG_VIDEO_CX88) += cx88/ 63obj-$(CONFIG_VIDEO_CX88) += cx88/
66obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 64obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
65obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
67obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 66obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
68obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 67obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
69obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 68obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
@@ -92,6 +91,9 @@ obj-$(CONFIG_VIDEO_UPD64031A) += upd64031a.o
92obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o 91obj-$(CONFIG_VIDEO_UPD64083) += upd64083.o
93obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o 92obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
94 93
94obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
95obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
96
95obj-$(CONFIG_USB_DABUSB) += dabusb.o 97obj-$(CONFIG_USB_DABUSB) += dabusb.o
96obj-$(CONFIG_USB_OV511) += ov511.o 98obj-$(CONFIG_USB_OV511) += ov511.o
97obj-$(CONFIG_USB_SE401) += se401.o 99obj-$(CONFIG_USB_SE401) += se401.o
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 6e1ddad9f0c1..3c8e4742dccc 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -1793,7 +1793,7 @@ static int bttv_common_ioctls(struct bttv *btv, unsigned int cmd, void *arg)
1793 memset(i,0,sizeof(*i)); 1793 memset(i,0,sizeof(*i));
1794 i->index = n; 1794 i->index = n;
1795 i->type = V4L2_INPUT_TYPE_CAMERA; 1795 i->type = V4L2_INPUT_TYPE_CAMERA;
1796 i->audioset = 0; 1796 i->audioset = 1;
1797 if (i->index == bttv_tvcards[btv->c.type].tuner) { 1797 if (i->index == bttv_tvcards[btv->c.type].tuner) {
1798 sprintf(i->name, "Television"); 1798 sprintf(i->name, "Television");
1799 i->type = V4L2_INPUT_TYPE_TUNER; 1799 i->type = V4L2_INPUT_TYPE_TUNER;
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 70de6c96e201..62b873076e09 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -479,11 +479,7 @@ int __devexit fini_bttv_i2c(struct bttv *btv)
479 if (0 != btv->i2c_rc) 479 if (0 != btv->i2c_rc)
480 return 0; 480 return 0;
481 481
482 if (btv->use_i2c_hw) { 482 return i2c_del_adapter(&btv->c.i2c_adap);
483 return i2c_del_adapter(&btv->c.i2c_adap);
484 } else {
485 return i2c_bit_del_bus(&btv->c.i2c_adap);
486 }
487} 483}
488 484
489/* 485/*
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 933d6db09acb..cbc012f71f52 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -259,24 +259,59 @@ static void bttv_rc5_timer_keyup(unsigned long data)
259 259
260/* ---------------------------------------------------------------------- */ 260/* ---------------------------------------------------------------------- */
261 261
262static void bttv_ir_start(struct bttv *btv, struct bttv_ir *ir)
263{
264 if (ir->polling) {
265 init_timer(&ir->timer);
266 ir->timer.function = bttv_input_timer;
267 ir->timer.data = (unsigned long)btv;
268 ir->timer.expires = jiffies + HZ;
269 add_timer(&ir->timer);
270 } else if (ir->rc5_gpio) {
271 /* set timer_end for code completion */
272 init_timer(&ir->timer_end);
273 ir->timer_end.function = bttv_rc5_timer_end;
274 ir->timer_end.data = (unsigned long)ir;
275
276 init_timer(&ir->timer_keyup);
277 ir->timer_keyup.function = bttv_rc5_timer_keyup;
278 ir->timer_keyup.data = (unsigned long)ir;
279 }
280}
281
282static void bttv_ir_stop(struct bttv *btv)
283{
284 if (btv->remote->polling) {
285 del_timer_sync(&btv->remote->timer);
286 flush_scheduled_work();
287 }
288
289 if (btv->remote->rc5_gpio) {
290 u32 gpio;
291
292 del_timer_sync(&btv->remote->timer_end);
293 flush_scheduled_work();
294
295 gpio = bttv_gpio_read(&btv->c);
296 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
297 }
298}
299
262int bttv_input_init(struct bttv *btv) 300int bttv_input_init(struct bttv *btv)
263{ 301{
264 struct bttv_ir *ir; 302 struct bttv_ir *ir;
265 IR_KEYTAB_TYPE *ir_codes = NULL; 303 IR_KEYTAB_TYPE *ir_codes = NULL;
266 struct input_dev *input_dev; 304 struct input_dev *input_dev;
267 int ir_type = IR_TYPE_OTHER; 305 int ir_type = IR_TYPE_OTHER;
306 int err = -ENOMEM;
268 307
269 if (!btv->has_remote) 308 if (!btv->has_remote)
270 return -ENODEV; 309 return -ENODEV;
271 310
272 ir = kzalloc(sizeof(*ir),GFP_KERNEL); 311 ir = kzalloc(sizeof(*ir),GFP_KERNEL);
273 input_dev = input_allocate_device(); 312 input_dev = input_allocate_device();
274 if (!ir || !input_dev) { 313 if (!ir || !input_dev)
275 kfree(ir); 314 goto err_out_free;
276 input_free_device(input_dev);
277 return -ENOMEM;
278 }
279 memset(ir,0,sizeof(*ir));
280 315
281 /* detect & configure */ 316 /* detect & configure */
282 switch (btv->c.type) { 317 switch (btv->c.type) {
@@ -348,10 +383,9 @@ int bttv_input_init(struct bttv *btv)
348 break; 383 break;
349 } 384 }
350 if (NULL == ir_codes) { 385 if (NULL == ir_codes) {
351 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type); 386 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
352 kfree(ir); 387 err = -ENODEV;
353 input_free_device(input_dev); 388 goto err_out_free;
354 return -ENODEV;
355 } 389 }
356 390
357 if (ir->rc5_gpio) { 391 if (ir->rc5_gpio) {
@@ -389,32 +423,26 @@ int bttv_input_init(struct bttv *btv)
389 input_dev->cdev.dev = &btv->c.pci->dev; 423 input_dev->cdev.dev = &btv->c.pci->dev;
390 424
391 btv->remote = ir; 425 btv->remote = ir;
392 if (ir->polling) { 426 bttv_ir_start(btv, ir);
393 init_timer(&ir->timer);
394 ir->timer.function = bttv_input_timer;
395 ir->timer.data = (unsigned long)btv;
396 ir->timer.expires = jiffies + HZ;
397 add_timer(&ir->timer);
398 } else if (ir->rc5_gpio) {
399 /* set timer_end for code completion */
400 init_timer(&ir->timer_end);
401 ir->timer_end.function = bttv_rc5_timer_end;
402 ir->timer_end.data = (unsigned long)ir;
403
404 init_timer(&ir->timer_keyup);
405 ir->timer_keyup.function = bttv_rc5_timer_keyup;
406 ir->timer_keyup.data = (unsigned long)ir;
407 }
408 427
409 /* all done */ 428 /* all done */
410 input_register_device(btv->remote->dev); 429 err = input_register_device(btv->remote->dev);
411 printk(DEVNAME ": %s detected at %s\n",ir->name,ir->phys); 430 if (err)
431 goto err_out_stop;
412 432
413 /* the remote isn't as bouncy as a keyboard */ 433 /* the remote isn't as bouncy as a keyboard */
414 ir->dev->rep[REP_DELAY] = repeat_delay; 434 ir->dev->rep[REP_DELAY] = repeat_delay;
415 ir->dev->rep[REP_PERIOD] = repeat_period; 435 ir->dev->rep[REP_PERIOD] = repeat_period;
416 436
417 return 0; 437 return 0;
438
439 err_out_stop:
440 bttv_ir_stop(btv);
441 btv->remote = NULL;
442 err_out_free:
443 input_free_device(input_dev);
444 kfree(ir);
445 return err;
418} 446}
419 447
420void bttv_input_fini(struct bttv *btv) 448void bttv_input_fini(struct bttv *btv)
@@ -422,22 +450,7 @@ void bttv_input_fini(struct bttv *btv)
422 if (btv->remote == NULL) 450 if (btv->remote == NULL)
423 return; 451 return;
424 452
425 if (btv->remote->polling) { 453 bttv_ir_stop(btv);
426 del_timer_sync(&btv->remote->timer);
427 flush_scheduled_work();
428 }
429
430
431 if (btv->remote->rc5_gpio) {
432 u32 gpio;
433
434 del_timer_sync(&btv->remote->timer_end);
435 flush_scheduled_work();
436
437 gpio = bttv_gpio_read(&btv->c);
438 bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
439 }
440
441 input_unregister_device(btv->remote->dev); 454 input_unregister_device(btv->remote->dev);
442 kfree(btv->remote); 455 kfree(btv->remote);
443 btv->remote = NULL; 456 btv->remote = NULL;
diff --git a/drivers/media/video/cafe_ccic-regs.h b/drivers/media/video/cafe_ccic-regs.h
new file mode 100644
index 000000000000..b2c22a0d6643
--- /dev/null
+++ b/drivers/media/video/cafe_ccic-regs.h
@@ -0,0 +1,160 @@
1/*
2 * Register definitions for the m88alp01 camera interface. Offsets in bytes
3 * as given in the spec.
4 *
5 * Copyright 2006 One Laptop Per Child Association, Inc.
6 *
7 * Written by Jonathan Corbet, corbet@lwn.net.
8 *
9 * This file may be distributed under the terms of the GNU General
10 * Public License, version 2.
11 */
12#define REG_Y0BAR 0x00
13#define REG_Y1BAR 0x04
14#define REG_Y2BAR 0x08
15/* ... */
16
17#define REG_IMGPITCH 0x24 /* Image pitch register */
18#define IMGP_YP_SHFT 2 /* Y pitch params */
19#define IMGP_YP_MASK 0x00003ffc /* Y pitch field */
20#define IMGP_UVP_SHFT 18 /* UV pitch (planar) */
21#define IMGP_UVP_MASK 0x3ffc0000
22#define REG_IRQSTATRAW 0x28 /* RAW IRQ Status */
23#define IRQ_EOF0 0x00000001 /* End of frame 0 */
24#define IRQ_EOF1 0x00000002 /* End of frame 1 */
25#define IRQ_EOF2 0x00000004 /* End of frame 2 */
26#define IRQ_SOF0 0x00000008 /* Start of frame 0 */
27#define IRQ_SOF1 0x00000010 /* Start of frame 1 */
28#define IRQ_SOF2 0x00000020 /* Start of frame 2 */
29#define IRQ_OVERFLOW 0x00000040 /* FIFO overflow */
30#define IRQ_TWSIW 0x00010000 /* TWSI (smbus) write */
31#define IRQ_TWSIR 0x00020000 /* TWSI read */
32#define IRQ_TWSIE 0x00040000 /* TWSI error */
33#define TWSIIRQS (IRQ_TWSIW|IRQ_TWSIR|IRQ_TWSIE)
34#define FRAMEIRQS (IRQ_EOF0|IRQ_EOF1|IRQ_EOF2|IRQ_SOF0|IRQ_SOF1|IRQ_SOF2)
35#define ALLIRQS (TWSIIRQS|FRAMEIRQS|IRQ_OVERFLOW)
36#define REG_IRQMASK 0x2c /* IRQ mask - same bits as IRQSTAT */
37#define REG_IRQSTAT 0x30 /* IRQ status / clear */
38
39#define REG_IMGSIZE 0x34 /* Image size */
40#define IMGSZ_V_MASK 0x1fff0000
41#define IMGSZ_V_SHIFT 16
42#define IMGSZ_H_MASK 0x00003fff
43#define REG_IMGOFFSET 0x38 /* IMage offset */
44
45#define REG_CTRL0 0x3c /* Control 0 */
46#define C0_ENABLE 0x00000001 /* Makes the whole thing go */
47
48/* Mask for all the format bits */
49#define C0_DF_MASK 0x00fffffc /* Bits 2-23 */
50
51/* RGB ordering */
52#define C0_RGB4_RGBX 0x00000000
53#define C0_RGB4_XRGB 0x00000004
54#define C0_RGB4_BGRX 0x00000008
55#define C0_RGB4_XBGR 0x0000000c
56#define C0_RGB5_RGGB 0x00000000
57#define C0_RGB5_GRBG 0x00000004
58#define C0_RGB5_GBRG 0x00000008
59#define C0_RGB5_BGGR 0x0000000c
60
61/* Spec has two fields for DIN and DOUT, but they must match, so
62 combine them here. */
63#define C0_DF_YUV 0x00000000 /* Data is YUV */
64#define C0_DF_RGB 0x000000a0 /* ... RGB */
65#define C0_DF_BAYER 0x00000140 /* ... Bayer */
66/* 8-8-8 must be missing from the below - ask */
67#define C0_RGBF_565 0x00000000
68#define C0_RGBF_444 0x00000800
69#define C0_RGB_BGR 0x00001000 /* Blue comes first */
70#define C0_YUV_PLANAR 0x00000000 /* YUV 422 planar format */
71#define C0_YUV_PACKED 0x00008000 /* YUV 422 packed */
72#define C0_YUV_420PL 0x0000a000 /* YUV 420 planar */
73/* Think that 420 packed must be 111 - ask */
74#define C0_YUVE_YUYV 0x00000000 /* Y1CbY0Cr */
75#define C0_YUVE_YVYU 0x00010000 /* Y1CrY0Cb */
76#define C0_YUVE_VYUY 0x00020000 /* CrY1CbY0 */
77#define C0_YUVE_UYVY 0x00030000 /* CbY1CrY0 */
78#define C0_YUVE_XYUV 0x00000000 /* 420: .YUV */
79#define C0_YUVE_XYVU 0x00010000 /* 420: .YVU */
80#define C0_YUVE_XUVY 0x00020000 /* 420: .UVY */
81#define C0_YUVE_XVUY 0x00030000 /* 420: .VUY */
82/* Bayer bits 18,19 if needed */
83#define C0_HPOL_LOW 0x01000000 /* HSYNC polarity active low */
84#define C0_VPOL_LOW 0x02000000 /* VSYNC polarity active low */
85#define C0_VCLK_LOW 0x04000000 /* VCLK on falling edge */
86#define C0_DOWNSCALE 0x08000000 /* Enable downscaler */
87#define C0_SIFM_MASK 0xc0000000 /* SIF mode bits */
88#define C0_SIF_HVSYNC 0x00000000 /* Use H/VSYNC */
89#define CO_SOF_NOSYNC 0x40000000 /* Use inband active signaling */
90
91
92#define REG_CTRL1 0x40 /* Control 1 */
93#define C1_444ALPHA 0x00f00000 /* Alpha field in RGB444 */
94#define C1_ALPHA_SHFT 20
95#define C1_DMAB32 0x00000000 /* 32-byte DMA burst */
96#define C1_DMAB16 0x02000000 /* 16-byte DMA burst */
97#define C1_DMAB64 0x04000000 /* 64-byte DMA burst */
98#define C1_DMAB_MASK 0x06000000
99#define C1_TWOBUFS 0x08000000 /* Use only two DMA buffers */
100#define C1_PWRDWN 0x10000000 /* Power down */
101
102#define REG_CLKCTRL 0x88 /* Clock control */
103#define CLK_DIV_MASK 0x0000ffff /* Upper bits RW "reserved" */
104
105#define REG_GPR 0xb4 /* General purpose register. This
106 controls inputs to the power and reset
107 pins on the OV7670 used with OLPC;
108 other deployments could differ. */
109#define GPR_C1EN 0x00000020 /* Pad 1 (power down) enable */
110#define GPR_C0EN 0x00000010 /* Pad 0 (reset) enable */
111#define GPR_C1 0x00000002 /* Control 1 value */
112/*
113 * Control 0 is wired to reset on OLPC machines. For ov7x sensors,
114 * it is active low, for 0v6x, instead, it's active high. What
115 * fun.
116 */
117#define GPR_C0 0x00000001 /* Control 0 value */
118
119#define REG_TWSIC0 0xb8 /* TWSI (smbus) control 0 */
120#define TWSIC0_EN 0x00000001 /* TWSI enable */
121#define TWSIC0_MODE 0x00000002 /* 1 = 16-bit, 0 = 8-bit */
122#define TWSIC0_SID 0x000003fc /* Slave ID */
123#define TWSIC0_SID_SHIFT 2
124#define TWSIC0_CLKDIV 0x0007fc00 /* Clock divider */
125#define TWSIC0_MASKACK 0x00400000 /* Mask ack from sensor */
126#define TWSIC0_OVMAGIC 0x00800000 /* Make it work on OV sensors */
127
128#define REG_TWSIC1 0xbc /* TWSI control 1 */
129#define TWSIC1_DATA 0x0000ffff /* Data to/from camchip */
130#define TWSIC1_ADDR 0x00ff0000 /* Address (register) */
131#define TWSIC1_ADDR_SHIFT 16
132#define TWSIC1_READ 0x01000000 /* Set for read op */
133#define TWSIC1_WSTAT 0x02000000 /* Write status */
134#define TWSIC1_RVALID 0x04000000 /* Read data valid */
135#define TWSIC1_ERROR 0x08000000 /* Something screwed up */
136
137
138#define REG_UBAR 0xc4 /* Upper base address register */
139
140/*
141 * Here's the weird global control registers which are said to live
142 * way up here.
143 */
144#define REG_GL_CSR 0x3004 /* Control/status register */
145#define GCSR_SRS 0x00000001 /* SW Reset set */
146#define GCSR_SRC 0x00000002 /* SW Reset clear */
147#define GCSR_MRS 0x00000004 /* Master reset set */
148#define GCSR_MRC 0x00000008 /* HW Reset clear */
149#define GCSR_CCIC_EN 0x00004000 /* CCIC Clock enable */
150#define REG_GL_IMASK 0x300c /* Interrupt mask register */
151#define GIMSK_CCIC_EN 0x00000004 /* CCIC Interrupt enable */
152
153#define REG_LEN REG_GL_IMASK + 4
154
155
156/*
157 * Useful stuff that probably belongs somewhere global.
158 */
159#define VGA_WIDTH 640
160#define VGA_HEIGHT 480
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
new file mode 100644
index 000000000000..e347c7ebc984
--- /dev/null
+++ b/drivers/media/video/cafe_ccic.c
@@ -0,0 +1,2228 @@
1/*
2 * A driver for the CMOS camera controller in the Marvell 88ALP01 "cafe"
3 * multifunction chip. Currently works with the Omnivision OV7670
4 * sensor.
5 *
6 * Copyright 2006 One Laptop Per Child Association, Inc.
7 *
8 * Written by Jonathan Corbet, corbet@lwn.net.
9 *
10 * This file may be distributed under the terms of the GNU General
11 * Public License, version 2.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/fs.h>
19#include <linux/pci.h>
20#include <linux/i2c.h>
21#include <linux/interrupt.h>
22#include <linux/spinlock.h>
23#include <linux/videodev2.h>
24#include <media/v4l2-common.h>
25#include <linux/device.h>
26#include <linux/wait.h>
27#include <linux/list.h>
28#include <linux/dma-mapping.h>
29#include <linux/delay.h>
30#include <linux/debugfs.h>
31#include <linux/jiffies.h>
32#include <linux/vmalloc.h>
33
34#include <asm/uaccess.h>
35#include <asm/io.h>
36
37#include "cafe_ccic-regs.h"
38
39#define CAFE_VERSION 0x000001
40
41
42/*
43 * Parameters.
44 */
45MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>");
46MODULE_DESCRIPTION("Marvell 88ALP01 CMOS Camera Controller driver");
47MODULE_LICENSE("GPL");
48MODULE_SUPPORTED_DEVICE("Video");
49
50/*
51 * Internal DMA buffer management. Since the controller cannot do S/G I/O,
52 * we must have physically contiguous buffers to bring frames into.
53 * These parameters control how many buffers we use, whether we
54 * allocate them at load time (better chance of success, but nails down
55 * memory) or when somebody tries to use the camera (riskier), and,
56 * for load-time allocation, how big they should be.
57 *
58 * The controller can cycle through three buffers. We could use
59 * more by flipping pointers around, but it probably makes little
60 * sense.
61 */
62
63#define MAX_DMA_BUFS 3
64static int alloc_bufs_at_load = 0;
65module_param(alloc_bufs_at_load, bool, 0444);
66MODULE_PARM_DESC(alloc_bufs_at_load,
67 "Non-zero value causes DMA buffers to be allocated at module "
68 "load time. This increases the chances of successfully getting "
69 "those buffers, but at the cost of nailing down the memory from "
70 "the outset.");
71
72static int n_dma_bufs = 3;
73module_param(n_dma_bufs, uint, 0644);
74MODULE_PARM_DESC(n_dma_bufs,
75 "The number of DMA buffers to allocate. Can be either two "
76 "(saves memory, makes timing tighter) or three.");
77
78static int dma_buf_size = VGA_WIDTH * VGA_HEIGHT * 2; /* Worst case */
79module_param(dma_buf_size, uint, 0444);
80MODULE_PARM_DESC(dma_buf_size,
81 "The size of the allocated DMA buffers. If actual operating "
82 "parameters require larger buffers, an attempt to reallocate "
83 "will be made.");
84
85static int min_buffers = 1;
86module_param(min_buffers, uint, 0644);
87MODULE_PARM_DESC(min_buffers,
88 "The minimum number of streaming I/O buffers we are willing "
89 "to work with.");
90
91static int max_buffers = 10;
92module_param(max_buffers, uint, 0644);
93MODULE_PARM_DESC(max_buffers,
94 "The maximum number of streaming I/O buffers an application "
95 "will be allowed to allocate. These buffers are big and live "
96 "in vmalloc space.");
97
98static int flip = 0;
99module_param(flip, bool, 0444);
100MODULE_PARM_DESC(flip,
101 "If set, the sensor will be instructed to flip the image "
102 "vertically.");
103
104
105enum cafe_state {
106 S_NOTREADY, /* Not yet initialized */
107 S_IDLE, /* Just hanging around */
108 S_FLAKED, /* Some sort of problem */
109 S_SINGLEREAD, /* In read() */
110 S_SPECREAD, /* Speculative read (for future read()) */
111 S_STREAMING /* Streaming data */
112};
113
114/*
115 * Tracking of streaming I/O buffers.
116 */
117struct cafe_sio_buffer {
118 struct list_head list;
119 struct v4l2_buffer v4lbuf;
120 char *buffer; /* Where it lives in kernel space */
121 int mapcount;
122 struct cafe_camera *cam;
123};
124
125/*
126 * A description of one of our devices.
127 * Locking: controlled by s_mutex. Certain fields, however, require
128 * the dev_lock spinlock; they are marked as such by comments.
129 * dev_lock is also required for access to device registers.
130 */
131struct cafe_camera
132{
133 enum cafe_state state;
134 unsigned long flags; /* Buffer status, mainly (dev_lock) */
135 int users; /* How many open FDs */
136 struct file *owner; /* Who has data access (v4l2) */
137
138 /*
139 * Subsystem structures.
140 */
141 struct pci_dev *pdev;
142 struct video_device v4ldev;
143 struct i2c_adapter i2c_adapter;
144 struct i2c_client *sensor;
145
146 unsigned char __iomem *regs;
147 struct list_head dev_list; /* link to other devices */
148
149 /* DMA buffers */
150 unsigned int nbufs; /* How many are alloc'd */
151 int next_buf; /* Next to consume (dev_lock) */
152 unsigned int dma_buf_size; /* allocated size */
153 void *dma_bufs[MAX_DMA_BUFS]; /* Internal buffer addresses */
154 dma_addr_t dma_handles[MAX_DMA_BUFS]; /* Buffer bus addresses */
155 unsigned int specframes; /* Unconsumed spec frames (dev_lock) */
156 unsigned int sequence; /* Frame sequence number */
157 unsigned int buf_seq[MAX_DMA_BUFS]; /* Sequence for individual buffers */
158
159 /* Streaming buffers */
160 unsigned int n_sbufs; /* How many we have */
161 struct cafe_sio_buffer *sb_bufs; /* The array of housekeeping structs */
162 struct list_head sb_avail; /* Available for data (we own) (dev_lock) */
163 struct list_head sb_full; /* With data (user space owns) (dev_lock) */
164 struct tasklet_struct s_tasklet;
165
166 /* Current operating parameters */
167 enum v4l2_chip_ident sensor_type; /* Currently ov7670 only */
168 struct v4l2_pix_format pix_format;
169
170 /* Locks */
171 struct mutex s_mutex; /* Access to this structure */
172 spinlock_t dev_lock; /* Access to device */
173
174 /* Misc */
175 wait_queue_head_t smbus_wait; /* Waiting on i2c events */
176 wait_queue_head_t iowait; /* Waiting on frame data */
177#ifdef CONFIG_VIDEO_ADV_DEBUG
178 struct dentry *dfs_regs;
179 struct dentry *dfs_cam_regs;
180#endif
181};
182
183/*
184 * Status flags. Always manipulated with bit operations.
185 */
186#define CF_BUF0_VALID 0 /* Buffers valid - first three */
187#define CF_BUF1_VALID 1
188#define CF_BUF2_VALID 2
189#define CF_DMA_ACTIVE 3 /* A frame is incoming */
190#define CF_CONFIG_NEEDED 4 /* Must configure hardware */
191
192
193
194/*
195 * Start over with DMA buffers - dev_lock needed.
196 */
197static void cafe_reset_buffers(struct cafe_camera *cam)
198{
199 int i;
200
201 cam->next_buf = -1;
202 for (i = 0; i < cam->nbufs; i++)
203 clear_bit(i, &cam->flags);
204 cam->specframes = 0;
205}
206
207static inline int cafe_needs_config(struct cafe_camera *cam)
208{
209 return test_bit(CF_CONFIG_NEEDED, &cam->flags);
210}
211
212static void cafe_set_config_needed(struct cafe_camera *cam, int needed)
213{
214 if (needed)
215 set_bit(CF_CONFIG_NEEDED, &cam->flags);
216 else
217 clear_bit(CF_CONFIG_NEEDED, &cam->flags);
218}
219
220
221
222
223/*
224 * Debugging and related.
225 */
226#define cam_err(cam, fmt, arg...) \
227 dev_err(&(cam)->pdev->dev, fmt, ##arg);
228#define cam_warn(cam, fmt, arg...) \
229 dev_warn(&(cam)->pdev->dev, fmt, ##arg);
230#define cam_dbg(cam, fmt, arg...) \
231 dev_dbg(&(cam)->pdev->dev, fmt, ##arg);
232
233
234/* ---------------------------------------------------------------------*/
235/*
236 * We keep a simple list of known devices to search at open time.
237 */
238static LIST_HEAD(cafe_dev_list);
239static DEFINE_MUTEX(cafe_dev_list_lock);
240
241static void cafe_add_dev(struct cafe_camera *cam)
242{
243 mutex_lock(&cafe_dev_list_lock);
244 list_add_tail(&cam->dev_list, &cafe_dev_list);
245 mutex_unlock(&cafe_dev_list_lock);
246}
247
248static void cafe_remove_dev(struct cafe_camera *cam)
249{
250 mutex_lock(&cafe_dev_list_lock);
251 list_del(&cam->dev_list);
252 mutex_unlock(&cafe_dev_list_lock);
253}
254
255static struct cafe_camera *cafe_find_dev(int minor)
256{
257 struct cafe_camera *cam;
258
259 mutex_lock(&cafe_dev_list_lock);
260 list_for_each_entry(cam, &cafe_dev_list, dev_list) {
261 if (cam->v4ldev.minor == minor)
262 goto done;
263 }
264 cam = NULL;
265 done:
266 mutex_unlock(&cafe_dev_list_lock);
267 return cam;
268}
269
270
271static struct cafe_camera *cafe_find_by_pdev(struct pci_dev *pdev)
272{
273 struct cafe_camera *cam;
274
275 mutex_lock(&cafe_dev_list_lock);
276 list_for_each_entry(cam, &cafe_dev_list, dev_list) {
277 if (cam->pdev == pdev)
278 goto done;
279 }
280 cam = NULL;
281 done:
282 mutex_unlock(&cafe_dev_list_lock);
283 return cam;
284}
285
286
287/* ------------------------------------------------------------------------ */
288/*
289 * Device register I/O
290 */
291static inline void cafe_reg_write(struct cafe_camera *cam, unsigned int reg,
292 unsigned int val)
293{
294 iowrite32(val, cam->regs + reg);
295}
296
297static inline unsigned int cafe_reg_read(struct cafe_camera *cam,
298 unsigned int reg)
299{
300 return ioread32(cam->regs + reg);
301}
302
303
304static inline void cafe_reg_write_mask(struct cafe_camera *cam, unsigned int reg,
305 unsigned int val, unsigned int mask)
306{
307 unsigned int v = cafe_reg_read(cam, reg);
308
309 v = (v & ~mask) | (val & mask);
310 cafe_reg_write(cam, reg, v);
311}
312
313static inline void cafe_reg_clear_bit(struct cafe_camera *cam,
314 unsigned int reg, unsigned int val)
315{
316 cafe_reg_write_mask(cam, reg, 0, val);
317}
318
319static inline void cafe_reg_set_bit(struct cafe_camera *cam,
320 unsigned int reg, unsigned int val)
321{
322 cafe_reg_write_mask(cam, reg, val, val);
323}
324
325
326
327/* -------------------------------------------------------------------- */
328/*
329 * The I2C/SMBUS interface to the camera itself starts here. The
330 * controller handles SMBUS itself, presenting a relatively simple register
331 * interface; all we have to do is to tell it where to route the data.
332 */
333#define CAFE_SMBUS_TIMEOUT (HZ) /* generous */
334
335static int cafe_smbus_write_done(struct cafe_camera *cam)
336{
337 unsigned long flags;
338 int c1;
339
340 /*
341 * We must delay after the interrupt, or the controller gets confused
342 * and never does give us good status. Fortunately, we don't do this
343 * often.
344 */
345 udelay(20);
346 spin_lock_irqsave(&cam->dev_lock, flags);
347 c1 = cafe_reg_read(cam, REG_TWSIC1);
348 spin_unlock_irqrestore(&cam->dev_lock, flags);
349 return (c1 & (TWSIC1_WSTAT|TWSIC1_ERROR)) != TWSIC1_WSTAT;
350}
351
352static int cafe_smbus_write_data(struct cafe_camera *cam,
353 u16 addr, u8 command, u8 value)
354{
355 unsigned int rval;
356 unsigned long flags;
357
358 spin_lock_irqsave(&cam->dev_lock, flags);
359 rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
360 rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
361 /*
362 * Marvell sez set clkdiv to all 1's for now.
363 */
364 rval |= TWSIC0_CLKDIV;
365 cafe_reg_write(cam, REG_TWSIC0, rval);
366 (void) cafe_reg_read(cam, REG_TWSIC1); /* force write */
367 rval = value | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
368 cafe_reg_write(cam, REG_TWSIC1, rval);
369 spin_unlock_irqrestore(&cam->dev_lock, flags);
370 msleep(2); /* Required or things flake */
371
372 wait_event_timeout(cam->smbus_wait, cafe_smbus_write_done(cam),
373 CAFE_SMBUS_TIMEOUT);
374 spin_lock_irqsave(&cam->dev_lock, flags);
375 rval = cafe_reg_read(cam, REG_TWSIC1);
376 spin_unlock_irqrestore(&cam->dev_lock, flags);
377
378 if (rval & TWSIC1_WSTAT) {
379 cam_err(cam, "SMBUS write (%02x/%02x/%02x) timed out\n", addr,
380 command, value);
381 return -EIO;
382 }
383 if (rval & TWSIC1_ERROR) {
384 cam_err(cam, "SMBUS write (%02x/%02x/%02x) error\n", addr,
385 command, value);
386 return -EIO;
387 }
388 return 0;
389}
390
391
392
393static int cafe_smbus_read_done(struct cafe_camera *cam)
394{
395 unsigned long flags;
396 int c1;
397
398 /*
399 * We must delay after the interrupt, or the controller gets confused
400 * and never does give us good status. Fortunately, we don't do this
401 * often.
402 */
403 udelay(20);
404 spin_lock_irqsave(&cam->dev_lock, flags);
405 c1 = cafe_reg_read(cam, REG_TWSIC1);
406 spin_unlock_irqrestore(&cam->dev_lock, flags);
407 return c1 & (TWSIC1_RVALID|TWSIC1_ERROR);
408}
409
410
411
412static int cafe_smbus_read_data(struct cafe_camera *cam,
413 u16 addr, u8 command, u8 *value)
414{
415 unsigned int rval;
416 unsigned long flags;
417
418 spin_lock_irqsave(&cam->dev_lock, flags);
419 rval = TWSIC0_EN | ((addr << TWSIC0_SID_SHIFT) & TWSIC0_SID);
420 rval |= TWSIC0_OVMAGIC; /* Make OV sensors work */
421 /*
422 * Marvel sez set clkdiv to all 1's for now.
423 */
424 rval |= TWSIC0_CLKDIV;
425 cafe_reg_write(cam, REG_TWSIC0, rval);
426 (void) cafe_reg_read(cam, REG_TWSIC1); /* force write */
427 rval = TWSIC1_READ | ((command << TWSIC1_ADDR_SHIFT) & TWSIC1_ADDR);
428 cafe_reg_write(cam, REG_TWSIC1, rval);
429 spin_unlock_irqrestore(&cam->dev_lock, flags);
430
431 wait_event_timeout(cam->smbus_wait,
432 cafe_smbus_read_done(cam), CAFE_SMBUS_TIMEOUT);
433 spin_lock_irqsave(&cam->dev_lock, flags);
434 rval = cafe_reg_read(cam, REG_TWSIC1);
435 spin_unlock_irqrestore(&cam->dev_lock, flags);
436
437 if (rval & TWSIC1_ERROR) {
438 cam_err(cam, "SMBUS read (%02x/%02x) error\n", addr, command);
439 return -EIO;
440 }
441 if (! (rval & TWSIC1_RVALID)) {
442 cam_err(cam, "SMBUS read (%02x/%02x) timed out\n", addr,
443 command);
444 return -EIO;
445 }
446 *value = rval & 0xff;
447 return 0;
448}
449
450/*
451 * Perform a transfer over SMBUS. This thing is called under
452 * the i2c bus lock, so we shouldn't race with ourselves...
453 */
454static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
455 unsigned short flags, char rw, u8 command,
456 int size, union i2c_smbus_data *data)
457{
458 struct cafe_camera *cam = i2c_get_adapdata(adapter);
459 int ret = -EINVAL;
460
461 /*
462 * Refuse to talk to anything but OV cam chips. We should
463 * never even see an attempt to do so, but one never knows.
464 */
465 if (cam->sensor && addr != cam->sensor->addr) {
466 cam_err(cam, "funky smbus addr %d\n", addr);
467 return -EINVAL;
468 }
469 /*
470 * This interface would appear to only do byte data ops. OK
471 * it can do word too, but the cam chip has no use for that.
472 */
473 if (size != I2C_SMBUS_BYTE_DATA) {
474 cam_err(cam, "funky xfer size %d\n", size);
475 return -EINVAL;
476 }
477
478 if (rw == I2C_SMBUS_WRITE)
479 ret = cafe_smbus_write_data(cam, addr, command, data->byte);
480 else if (rw == I2C_SMBUS_READ)
481 ret = cafe_smbus_read_data(cam, addr, command, &data->byte);
482 return ret;
483}
484
485
486static void cafe_smbus_enable_irq(struct cafe_camera *cam)
487{
488 unsigned long flags;
489
490 spin_lock_irqsave(&cam->dev_lock, flags);
491 cafe_reg_set_bit(cam, REG_IRQMASK, TWSIIRQS);
492 spin_unlock_irqrestore(&cam->dev_lock, flags);
493}
494
495static u32 cafe_smbus_func(struct i2c_adapter *adapter)
496{
497 return I2C_FUNC_SMBUS_READ_BYTE_DATA |
498 I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
499}
500
501static struct i2c_algorithm cafe_smbus_algo = {
502 .smbus_xfer = cafe_smbus_xfer,
503 .functionality = cafe_smbus_func
504};
505
506/* Somebody is on the bus */
507static int cafe_cam_init(struct cafe_camera *cam);
508static void cafe_ctlr_stop_dma(struct cafe_camera *cam);
509static void cafe_ctlr_power_down(struct cafe_camera *cam);
510
511static int cafe_smbus_attach(struct i2c_client *client)
512{
513 struct cafe_camera *cam = i2c_get_adapdata(client->adapter);
514
515 /*
516 * Don't talk to chips we don't recognize.
517 */
518 if (client->driver->id == I2C_DRIVERID_OV7670) {
519 cam->sensor = client;
520 return cafe_cam_init(cam);
521 }
522 return -EINVAL;
523}
524
525static int cafe_smbus_detach(struct i2c_client *client)
526{
527 struct cafe_camera *cam = i2c_get_adapdata(client->adapter);
528
529 if (cam->sensor == client) {
530 cafe_ctlr_stop_dma(cam);
531 cafe_ctlr_power_down(cam);
532 cam_err(cam, "lost the sensor!\n");
533 cam->sensor = NULL; /* Bummer, no camera */
534 cam->state = S_NOTREADY;
535 }
536 return 0;
537}
538
539static int cafe_smbus_setup(struct cafe_camera *cam)
540{
541 struct i2c_adapter *adap = &cam->i2c_adapter;
542 int ret;
543
544 cafe_smbus_enable_irq(cam);
545 adap->id = I2C_HW_SMBUS_CAFE;
546 adap->class = I2C_CLASS_CAM_DIGITAL;
547 adap->owner = THIS_MODULE;
548 adap->client_register = cafe_smbus_attach;
549 adap->client_unregister = cafe_smbus_detach;
550 adap->algo = &cafe_smbus_algo;
551 strcpy(adap->name, "cafe_ccic");
552 i2c_set_adapdata(adap, cam);
553 ret = i2c_add_adapter(adap);
554 if (ret)
555 printk(KERN_ERR "Unable to register cafe i2c adapter\n");
556 return ret;
557}
558
559static void cafe_smbus_shutdown(struct cafe_camera *cam)
560{
561 i2c_del_adapter(&cam->i2c_adapter);
562}
563
564
565/* ------------------------------------------------------------------- */
566/*
567 * Deal with the controller.
568 */
569
570/*
571 * Do everything we think we need to have the interface operating
572 * according to the desired format.
573 */
574static void cafe_ctlr_dma(struct cafe_camera *cam)
575{
576 /*
577 * Store the first two Y buffers (we aren't supporting
578 * planar formats for now, so no UV bufs). Then either
579 * set the third if it exists, or tell the controller
580 * to just use two.
581 */
582 cafe_reg_write(cam, REG_Y0BAR, cam->dma_handles[0]);
583 cafe_reg_write(cam, REG_Y1BAR, cam->dma_handles[1]);
584 if (cam->nbufs > 2) {
585 cafe_reg_write(cam, REG_Y2BAR, cam->dma_handles[2]);
586 cafe_reg_clear_bit(cam, REG_CTRL1, C1_TWOBUFS);
587 }
588 else
589 cafe_reg_set_bit(cam, REG_CTRL1, C1_TWOBUFS);
590 cafe_reg_write(cam, REG_UBAR, 0); /* 32 bits only for now */
591}
592
593static void cafe_ctlr_image(struct cafe_camera *cam)
594{
595 int imgsz;
596 struct v4l2_pix_format *fmt = &cam->pix_format;
597
598 imgsz = ((fmt->height << IMGSZ_V_SHIFT) & IMGSZ_V_MASK) |
599 (fmt->bytesperline & IMGSZ_H_MASK);
600 cafe_reg_write(cam, REG_IMGSIZE, imgsz);
601 cafe_reg_write(cam, REG_IMGOFFSET, 0);
602 /* YPITCH just drops the last two bits */
603 cafe_reg_write_mask(cam, REG_IMGPITCH, fmt->bytesperline,
604 IMGP_YP_MASK);
605 /*
606 * Tell the controller about the image format we are using.
607 */
608 switch (cam->pix_format.pixelformat) {
609 case V4L2_PIX_FMT_YUYV:
610 cafe_reg_write_mask(cam, REG_CTRL0,
611 C0_DF_YUV|C0_YUV_PACKED|C0_YUVE_YUYV,
612 C0_DF_MASK);
613 break;
614
615 case V4L2_PIX_FMT_RGB444:
616 cafe_reg_write_mask(cam, REG_CTRL0,
617 C0_DF_RGB|C0_RGBF_444|C0_RGB4_XRGB,
618 C0_DF_MASK);
619 /* Alpha value? */
620 break;
621
622 case V4L2_PIX_FMT_RGB565:
623 cafe_reg_write_mask(cam, REG_CTRL0,
624 C0_DF_RGB|C0_RGBF_565|C0_RGB5_BGGR,
625 C0_DF_MASK);
626 break;
627
628 default:
629 cam_err(cam, "Unknown format %x\n", cam->pix_format.pixelformat);
630 break;
631 }
632 /*
633 * Make sure it knows we want to use hsync/vsync.
634 */
635 cafe_reg_write_mask(cam, REG_CTRL0, C0_SIF_HVSYNC,
636 C0_SIFM_MASK);
637}
638
639
640/*
641 * Configure the controller for operation; caller holds the
642 * device mutex.
643 */
644static int cafe_ctlr_configure(struct cafe_camera *cam)
645{
646 unsigned long flags;
647
648 spin_lock_irqsave(&cam->dev_lock, flags);
649 cafe_ctlr_dma(cam);
650 cafe_ctlr_image(cam);
651 cafe_set_config_needed(cam, 0);
652 spin_unlock_irqrestore(&cam->dev_lock, flags);
653 return 0;
654}
655
656static void cafe_ctlr_irq_enable(struct cafe_camera *cam)
657{
658 /*
659 * Clear any pending interrupts, since we do not
660 * expect to have I/O active prior to enabling.
661 */
662 cafe_reg_write(cam, REG_IRQSTAT, FRAMEIRQS);
663 cafe_reg_set_bit(cam, REG_IRQMASK, FRAMEIRQS);
664}
665
666static void cafe_ctlr_irq_disable(struct cafe_camera *cam)
667{
668 cafe_reg_clear_bit(cam, REG_IRQMASK, FRAMEIRQS);
669}
670
671/*
672 * Make the controller start grabbing images. Everything must
673 * be set up before doing this.
674 */
675static void cafe_ctlr_start(struct cafe_camera *cam)
676{
677 /* set_bit performs a read, so no other barrier should be
678 needed here */
679 cafe_reg_set_bit(cam, REG_CTRL0, C0_ENABLE);
680}
681
682static void cafe_ctlr_stop(struct cafe_camera *cam)
683{
684 cafe_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
685}
686
687static void cafe_ctlr_init(struct cafe_camera *cam)
688{
689 unsigned long flags;
690
691 spin_lock_irqsave(&cam->dev_lock, flags);
692 /*
693 * Added magic to bring up the hardware on the B-Test board
694 */
695 cafe_reg_write(cam, 0x3038, 0x8);
696 cafe_reg_write(cam, 0x315c, 0x80008);
697 /*
698 * Go through the dance needed to wake the device up.
699 * Note that these registers are global and shared
700 * with the NAND and SD devices. Interaction between the
701 * three still needs to be examined.
702 */
703 cafe_reg_write(cam, REG_GL_CSR, GCSR_SRS|GCSR_MRS); /* Needed? */
704 cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRC);
705 cafe_reg_write(cam, REG_GL_CSR, GCSR_SRC|GCSR_MRS);
706 mdelay(5); /* FIXME revisit this */
707 cafe_reg_write(cam, REG_GL_CSR, GCSR_CCIC_EN|GCSR_SRC|GCSR_MRC);
708 cafe_reg_set_bit(cam, REG_GL_IMASK, GIMSK_CCIC_EN);
709 /*
710 * Make sure it's not powered down.
711 */
712 cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN);
713 /*
714 * Turn off the enable bit. It sure should be off anyway,
715 * but it's good to be sure.
716 */
717 cafe_reg_clear_bit(cam, REG_CTRL0, C0_ENABLE);
718 /*
719 * Mask all interrupts.
720 */
721 cafe_reg_write(cam, REG_IRQMASK, 0);
722 /*
723 * Clock the sensor appropriately. Controller clock should
724 * be 48MHz, sensor "typical" value is half that.
725 */
726 cafe_reg_write_mask(cam, REG_CLKCTRL, 2, CLK_DIV_MASK);
727 spin_unlock_irqrestore(&cam->dev_lock, flags);
728}
729
730
731/*
732 * Stop the controller, and don't return until we're really sure that no
733 * further DMA is going on.
734 */
735static void cafe_ctlr_stop_dma(struct cafe_camera *cam)
736{
737 unsigned long flags;
738
739 /*
740 * Theory: stop the camera controller (whether it is operating
741 * or not). Delay briefly just in case we race with the SOF
742 * interrupt, then wait until no DMA is active.
743 */
744 spin_lock_irqsave(&cam->dev_lock, flags);
745 cafe_ctlr_stop(cam);
746 spin_unlock_irqrestore(&cam->dev_lock, flags);
747 mdelay(1);
748 wait_event_timeout(cam->iowait,
749 !test_bit(CF_DMA_ACTIVE, &cam->flags), HZ);
750 if (test_bit(CF_DMA_ACTIVE, &cam->flags))
751 cam_err(cam, "Timeout waiting for DMA to end\n");
752 /* This would be bad news - what now? */
753 spin_lock_irqsave(&cam->dev_lock, flags);
754 cam->state = S_IDLE;
755 cafe_ctlr_irq_disable(cam);
756 spin_unlock_irqrestore(&cam->dev_lock, flags);
757}
758
759/*
760 * Power up and down.
761 */
762static void cafe_ctlr_power_up(struct cafe_camera *cam)
763{
764 unsigned long flags;
765
766 spin_lock_irqsave(&cam->dev_lock, flags);
767 cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN);
768 /*
769 * Put the sensor into operational mode (assumes OLPC-style
770 * wiring). Control 0 is reset - set to 1 to operate.
771 * Control 1 is power down, set to 0 to operate.
772 */
773 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */
774 mdelay(1); /* Marvell says 1ms will do it */
775 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
776 mdelay(1); /* Enough? */
777 spin_unlock_irqrestore(&cam->dev_lock, flags);
778}
779
780static void cafe_ctlr_power_down(struct cafe_camera *cam)
781{
782 unsigned long flags;
783
784 spin_lock_irqsave(&cam->dev_lock, flags);
785 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1);
786 cafe_reg_set_bit(cam, REG_CTRL1, C1_PWRDWN);
787 spin_unlock_irqrestore(&cam->dev_lock, flags);
788}
789
790/* -------------------------------------------------------------------- */
791/*
792 * Communications with the sensor.
793 */
794
795static int __cafe_cam_cmd(struct cafe_camera *cam, int cmd, void *arg)
796{
797 struct i2c_client *sc = cam->sensor;
798 int ret;
799
800 if (sc == NULL || sc->driver == NULL || sc->driver->command == NULL)
801 return -EINVAL;
802 ret = sc->driver->command(sc, cmd, arg);
803 if (ret == -EPERM) /* Unsupported command */
804 return 0;
805 return ret;
806}
807
808static int __cafe_cam_reset(struct cafe_camera *cam)
809{
810 int zero = 0;
811 return __cafe_cam_cmd(cam, VIDIOC_INT_RESET, &zero);
812}
813
814/*
815 * We have found the sensor on the i2c. Let's try to have a
816 * conversation.
817 */
818static int cafe_cam_init(struct cafe_camera *cam)
819{
820 int ret;
821
822 mutex_lock(&cam->s_mutex);
823 if (cam->state != S_NOTREADY)
824 cam_warn(cam, "Cam init with device in funky state %d",
825 cam->state);
826 ret = __cafe_cam_reset(cam);
827 if (ret)
828 goto out;
829 ret = __cafe_cam_cmd(cam, VIDIOC_INT_G_CHIP_IDENT, &cam->sensor_type);
830 if (ret)
831 goto out;
832// if (cam->sensor->addr != OV7xx0_SID) {
833 if (cam->sensor_type != V4L2_IDENT_OV7670) {
834 cam_err(cam, "Unsupported sensor type %d", cam->sensor->addr);
835 ret = -EINVAL;
836 goto out;
837 }
838/* Get/set parameters? */
839 ret = 0;
840 cam->state = S_IDLE;
841 out:
842 mutex_unlock(&cam->s_mutex);
843 return ret;
844}
845
846/*
847 * Configure the sensor to match the parameters we have. Caller should
848 * hold s_mutex
849 */
850static int cafe_cam_set_flip(struct cafe_camera *cam)
851{
852 struct v4l2_control ctrl;
853
854 memset(&ctrl, 0, sizeof(ctrl));
855 ctrl.id = V4L2_CID_VFLIP;
856 ctrl.value = flip;
857 return __cafe_cam_cmd(cam, VIDIOC_S_CTRL, &ctrl);
858}
859
860
861static int cafe_cam_configure(struct cafe_camera *cam)
862{
863 struct v4l2_format fmt;
864 int ret, zero = 0;
865
866 if (cam->state != S_IDLE)
867 return -EINVAL;
868 fmt.fmt.pix = cam->pix_format;
869 ret = __cafe_cam_cmd(cam, VIDIOC_INT_INIT, &zero);
870 if (ret == 0)
871 ret = __cafe_cam_cmd(cam, VIDIOC_S_FMT, &fmt);
872 /*
873 * OV7670 does weird things if flip is set *before* format...
874 */
875 ret += cafe_cam_set_flip(cam);
876 return ret;
877}
878
879/* -------------------------------------------------------------------- */
880/*
881 * DMA buffer management. These functions need s_mutex held.
882 */
883
884/* FIXME: this is inefficient as hell, since dma_alloc_coherent just
885 * does a get_free_pages() call, and we waste a good chunk of an orderN
886 * allocation. Should try to allocate the whole set in one chunk.
887 */
888static int cafe_alloc_dma_bufs(struct cafe_camera *cam, int loadtime)
889{
890 int i;
891
892 cafe_set_config_needed(cam, 1);
893 if (loadtime)
894 cam->dma_buf_size = dma_buf_size;
895 else
896 cam->dma_buf_size = cam->pix_format.sizeimage;
897 if (n_dma_bufs > 3)
898 n_dma_bufs = 3;
899
900 cam->nbufs = 0;
901 for (i = 0; i < n_dma_bufs; i++) {
902 cam->dma_bufs[i] = dma_alloc_coherent(&cam->pdev->dev,
903 cam->dma_buf_size, cam->dma_handles + i,
904 GFP_KERNEL);
905 if (cam->dma_bufs[i] == NULL) {
906 cam_warn(cam, "Failed to allocate DMA buffer\n");
907 break;
908 }
909 /* For debug, remove eventually */
910 memset(cam->dma_bufs[i], 0xcc, cam->dma_buf_size);
911 (cam->nbufs)++;
912 }
913
914 switch (cam->nbufs) {
915 case 1:
916 dma_free_coherent(&cam->pdev->dev, cam->dma_buf_size,
917 cam->dma_bufs[0], cam->dma_handles[0]);
918 cam->nbufs = 0;
919 case 0:
920 cam_err(cam, "Insufficient DMA buffers, cannot operate\n");
921 return -ENOMEM;
922
923 case 2:
924 if (n_dma_bufs > 2)
925 cam_warn(cam, "Will limp along with only 2 buffers\n");
926 break;
927 }
928 return 0;
929}
930
931static void cafe_free_dma_bufs(struct cafe_camera *cam)
932{
933 int i;
934
935 for (i = 0; i < cam->nbufs; i++) {
936 dma_free_coherent(&cam->pdev->dev, cam->dma_buf_size,
937 cam->dma_bufs[i], cam->dma_handles[i]);
938 cam->dma_bufs[i] = NULL;
939 }
940 cam->nbufs = 0;
941}
942
943
944
945
946
947/* ----------------------------------------------------------------------- */
948/*
949 * Here starts the V4L2 interface code.
950 */
951
952/*
953 * Read an image from the device.
954 */
955static ssize_t cafe_deliver_buffer(struct cafe_camera *cam,
956 char __user *buffer, size_t len, loff_t *pos)
957{
958 int bufno;
959 unsigned long flags;
960
961 spin_lock_irqsave(&cam->dev_lock, flags);
962 if (cam->next_buf < 0) {
963 cam_err(cam, "deliver_buffer: No next buffer\n");
964 spin_unlock_irqrestore(&cam->dev_lock, flags);
965 return -EIO;
966 }
967 bufno = cam->next_buf;
968 clear_bit(bufno, &cam->flags);
969 if (++(cam->next_buf) >= cam->nbufs)
970 cam->next_buf = 0;
971 if (! test_bit(cam->next_buf, &cam->flags))
972 cam->next_buf = -1;
973 cam->specframes = 0;
974 spin_unlock_irqrestore(&cam->dev_lock, flags);
975
976 if (len > cam->pix_format.sizeimage)
977 len = cam->pix_format.sizeimage;
978 if (copy_to_user(buffer, cam->dma_bufs[bufno], len))
979 return -EFAULT;
980 (*pos) += len;
981 return len;
982}
983
984/*
985 * Get everything ready, and start grabbing frames.
986 */
987static int cafe_read_setup(struct cafe_camera *cam, enum cafe_state state)
988{
989 int ret;
990 unsigned long flags;
991
992 /*
993 * Configuration. If we still don't have DMA buffers,
994 * make one last, desperate attempt.
995 */
996 if (cam->nbufs == 0)
997 if (cafe_alloc_dma_bufs(cam, 0))
998 return -ENOMEM;
999
1000 if (cafe_needs_config(cam)) {
1001 cafe_cam_configure(cam);
1002 ret = cafe_ctlr_configure(cam);
1003 if (ret)
1004 return ret;
1005 }
1006
1007 /*
1008 * Turn it loose.
1009 */
1010 spin_lock_irqsave(&cam->dev_lock, flags);
1011 cafe_reset_buffers(cam);
1012 cafe_ctlr_irq_enable(cam);
1013 cam->state = state;
1014 cafe_ctlr_start(cam);
1015 spin_unlock_irqrestore(&cam->dev_lock, flags);
1016 return 0;
1017}
1018
1019
1020static ssize_t cafe_v4l_read(struct file *filp,
1021 char __user *buffer, size_t len, loff_t *pos)
1022{
1023 struct cafe_camera *cam = filp->private_data;
1024 int ret;
1025
1026 /*
1027 * Perhaps we're in speculative read mode and already
1028 * have data?
1029 */
1030 mutex_lock(&cam->s_mutex);
1031 if (cam->state == S_SPECREAD) {
1032 if (cam->next_buf >= 0) {
1033 ret = cafe_deliver_buffer(cam, buffer, len, pos);
1034 if (ret != 0)
1035 goto out_unlock;
1036 }
1037 } else if (cam->state == S_FLAKED || cam->state == S_NOTREADY) {
1038 ret = -EIO;
1039 goto out_unlock;
1040 } else if (cam->state != S_IDLE) {
1041 ret = -EBUSY;
1042 goto out_unlock;
1043 }
1044
1045 /*
1046 * v4l2: multiple processes can open the device, but only
1047 * one gets to grab data from it.
1048 */
1049 if (cam->owner && cam->owner != filp) {
1050 ret = -EBUSY;
1051 goto out_unlock;
1052 }
1053 cam->owner = filp;
1054
1055 /*
1056 * Do setup if need be.
1057 */
1058 if (cam->state != S_SPECREAD) {
1059 ret = cafe_read_setup(cam, S_SINGLEREAD);
1060 if (ret)
1061 goto out_unlock;
1062 }
1063 /*
1064 * Wait for something to happen. This should probably
1065 * be interruptible (FIXME).
1066 */
1067 wait_event_timeout(cam->iowait, cam->next_buf >= 0, HZ);
1068 if (cam->next_buf < 0) {
1069 cam_err(cam, "read() operation timed out\n");
1070 cafe_ctlr_stop_dma(cam);
1071 ret = -EIO;
1072 goto out_unlock;
1073 }
1074 /*
1075 * Give them their data and we should be done.
1076 */
1077 ret = cafe_deliver_buffer(cam, buffer, len, pos);
1078
1079 out_unlock:
1080 mutex_unlock(&cam->s_mutex);
1081 return ret;
1082}
1083
1084
1085
1086
1087
1088
1089
1090
1091/*
1092 * Streaming I/O support.
1093 */
1094
1095
1096
1097static int cafe_vidioc_streamon(struct file *filp, void *priv,
1098 enum v4l2_buf_type type)
1099{
1100 struct cafe_camera *cam = filp->private_data;
1101 int ret = -EINVAL;
1102
1103 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1104 goto out;
1105 mutex_lock(&cam->s_mutex);
1106 if (cam->state != S_IDLE || cam->n_sbufs == 0)
1107 goto out_unlock;
1108
1109 cam->sequence = 0;
1110 ret = cafe_read_setup(cam, S_STREAMING);
1111
1112 out_unlock:
1113 mutex_unlock(&cam->s_mutex);
1114 out:
1115 return ret;
1116}
1117
1118
1119static int cafe_vidioc_streamoff(struct file *filp, void *priv,
1120 enum v4l2_buf_type type)
1121{
1122 struct cafe_camera *cam = filp->private_data;
1123 int ret = -EINVAL;
1124
1125 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1126 goto out;
1127 mutex_lock(&cam->s_mutex);
1128 if (cam->state != S_STREAMING)
1129 goto out_unlock;
1130
1131 cafe_ctlr_stop_dma(cam);
1132 ret = 0;
1133
1134 out_unlock:
1135 mutex_unlock(&cam->s_mutex);
1136 out:
1137 return ret;
1138}
1139
1140
1141
1142static int cafe_setup_siobuf(struct cafe_camera *cam, int index)
1143{
1144 struct cafe_sio_buffer *buf = cam->sb_bufs + index;
1145
1146 INIT_LIST_HEAD(&buf->list);
1147 buf->v4lbuf.length = PAGE_ALIGN(cam->pix_format.sizeimage);
1148 buf->buffer = vmalloc_user(buf->v4lbuf.length);
1149 if (buf->buffer == NULL)
1150 return -ENOMEM;
1151 buf->mapcount = 0;
1152 buf->cam = cam;
1153
1154 buf->v4lbuf.index = index;
1155 buf->v4lbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1156 buf->v4lbuf.field = V4L2_FIELD_NONE;
1157 buf->v4lbuf.memory = V4L2_MEMORY_MMAP;
1158 /*
1159 * Offset: must be 32-bit even on a 64-bit system. video-buf
1160 * just uses the length times the index, but the spec warns
1161 * against doing just that - vma merging problems. So we
1162 * leave a gap between each pair of buffers.
1163 */
1164 buf->v4lbuf.m.offset = 2*index*buf->v4lbuf.length;
1165 return 0;
1166}
1167
1168static int cafe_free_sio_buffers(struct cafe_camera *cam)
1169{
1170 int i;
1171
1172 /*
1173 * If any buffers are mapped, we cannot free them at all.
1174 */
1175 for (i = 0; i < cam->n_sbufs; i++)
1176 if (cam->sb_bufs[i].mapcount > 0)
1177 return -EBUSY;
1178 /*
1179 * OK, let's do it.
1180 */
1181 for (i = 0; i < cam->n_sbufs; i++)
1182 vfree(cam->sb_bufs[i].buffer);
1183 cam->n_sbufs = 0;
1184 kfree(cam->sb_bufs);
1185 cam->sb_bufs = NULL;
1186 INIT_LIST_HEAD(&cam->sb_avail);
1187 INIT_LIST_HEAD(&cam->sb_full);
1188 return 0;
1189}
1190
1191
1192
1193static int cafe_vidioc_reqbufs(struct file *filp, void *priv,
1194 struct v4l2_requestbuffers *req)
1195{
1196 struct cafe_camera *cam = filp->private_data;
1197 int ret;
1198
1199 /*
1200 * Make sure it's something we can do. User pointers could be
1201 * implemented without great pain, but that's not been done yet.
1202 */
1203 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1204 return -EINVAL;
1205 if (req->memory != V4L2_MEMORY_MMAP)
1206 return -EINVAL;
1207 /*
1208 * If they ask for zero buffers, they really want us to stop streaming
1209 * (if it's happening) and free everything. Should we check owner?
1210 */
1211 mutex_lock(&cam->s_mutex);
1212 if (req->count == 0) {
1213 if (cam->state == S_STREAMING)
1214 cafe_ctlr_stop_dma(cam);
1215 ret = cafe_free_sio_buffers (cam);
1216 goto out;
1217 }
1218 /*
1219 * Device needs to be idle and working. We *could* try to do the
1220 * right thing in S_SPECREAD by shutting things down, but it
1221 * probably doesn't matter.
1222 */
1223 if (cam->state != S_IDLE || (cam->owner && cam->owner != filp)) {
1224 ret = -EBUSY;
1225 goto out;
1226 }
1227 cam->owner = filp;
1228
1229 if (req->count < min_buffers)
1230 req->count = min_buffers;
1231 else if (req->count > max_buffers)
1232 req->count = max_buffers;
1233 if (cam->n_sbufs > 0) {
1234 ret = cafe_free_sio_buffers(cam);
1235 if (ret)
1236 goto out;
1237 }
1238
1239 cam->sb_bufs = kzalloc(req->count*sizeof(struct cafe_sio_buffer),
1240 GFP_KERNEL);
1241 if (cam->sb_bufs == NULL) {
1242 ret = -ENOMEM;
1243 goto out;
1244 }
1245 for (cam->n_sbufs = 0; cam->n_sbufs < req->count; (cam->n_sbufs++)) {
1246 ret = cafe_setup_siobuf(cam, cam->n_sbufs);
1247 if (ret)
1248 break;
1249 }
1250
1251 if (cam->n_sbufs == 0) /* no luck at all - ret already set */
1252 kfree(cam->sb_bufs);
1253 else
1254 ret = 0;
1255 req->count = cam->n_sbufs; /* In case of partial success */
1256
1257 out:
1258 mutex_unlock(&cam->s_mutex);
1259 return ret;
1260}
1261
1262
1263static int cafe_vidioc_querybuf(struct file *filp, void *priv,
1264 struct v4l2_buffer *buf)
1265{
1266 struct cafe_camera *cam = filp->private_data;
1267 int ret = -EINVAL;
1268
1269 mutex_lock(&cam->s_mutex);
1270 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1271 goto out;
1272 if (buf->index < 0 || buf->index >= cam->n_sbufs)
1273 goto out;
1274 *buf = cam->sb_bufs[buf->index].v4lbuf;
1275 ret = 0;
1276 out:
1277 mutex_unlock(&cam->s_mutex);
1278 return ret;
1279}
1280
1281static int cafe_vidioc_qbuf(struct file *filp, void *priv,
1282 struct v4l2_buffer *buf)
1283{
1284 struct cafe_camera *cam = filp->private_data;
1285 struct cafe_sio_buffer *sbuf;
1286 int ret = -EINVAL;
1287 unsigned long flags;
1288
1289 mutex_lock(&cam->s_mutex);
1290 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1291 goto out;
1292 if (buf->index < 0 || buf->index >= cam->n_sbufs)
1293 goto out;
1294 sbuf = cam->sb_bufs + buf->index;
1295 if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_QUEUED) {
1296 ret = 0; /* Already queued?? */
1297 goto out;
1298 }
1299 if (sbuf->v4lbuf.flags & V4L2_BUF_FLAG_DONE) {
1300 /* Spec doesn't say anything, seems appropriate tho */
1301 ret = -EBUSY;
1302 goto out;
1303 }
1304 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_QUEUED;
1305 spin_lock_irqsave(&cam->dev_lock, flags);
1306 list_add(&sbuf->list, &cam->sb_avail);
1307 spin_unlock_irqrestore(&cam->dev_lock, flags);
1308 ret = 0;
1309 out:
1310 mutex_unlock(&cam->s_mutex);
1311 return ret;
1312}
1313
1314static int cafe_vidioc_dqbuf(struct file *filp, void *priv,
1315 struct v4l2_buffer *buf)
1316{
1317 struct cafe_camera *cam = filp->private_data;
1318 struct cafe_sio_buffer *sbuf;
1319 int ret = -EINVAL;
1320 unsigned long flags;
1321
1322 mutex_lock(&cam->s_mutex);
1323 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1324 goto out_unlock;
1325 if (cam->state != S_STREAMING)
1326 goto out_unlock;
1327 if (list_empty(&cam->sb_full) && filp->f_flags & O_NONBLOCK) {
1328 ret = -EAGAIN;
1329 goto out_unlock;
1330 }
1331
1332 while (list_empty(&cam->sb_full) && cam->state == S_STREAMING) {
1333 mutex_unlock(&cam->s_mutex);
1334 if (wait_event_interruptible(cam->iowait,
1335 !list_empty(&cam->sb_full))) {
1336 ret = -ERESTARTSYS;
1337 goto out;
1338 }
1339 mutex_lock(&cam->s_mutex);
1340 }
1341
1342 if (cam->state != S_STREAMING)
1343 ret = -EINTR;
1344 else {
1345 spin_lock_irqsave(&cam->dev_lock, flags);
1346 /* Should probably recheck !list_empty() here */
1347 sbuf = list_entry(cam->sb_full.next,
1348 struct cafe_sio_buffer, list);
1349 list_del_init(&sbuf->list);
1350 spin_unlock_irqrestore(&cam->dev_lock, flags);
1351 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_DONE;
1352 *buf = sbuf->v4lbuf;
1353 ret = 0;
1354 }
1355
1356 out_unlock:
1357 mutex_unlock(&cam->s_mutex);
1358 out:
1359 return ret;
1360}
1361
1362
1363
1364static void cafe_v4l_vm_open(struct vm_area_struct *vma)
1365{
1366 struct cafe_sio_buffer *sbuf = vma->vm_private_data;
1367 /*
1368 * Locking: done under mmap_sem, so we don't need to
1369 * go back to the camera lock here.
1370 */
1371 sbuf->mapcount++;
1372}
1373
1374
1375static void cafe_v4l_vm_close(struct vm_area_struct *vma)
1376{
1377 struct cafe_sio_buffer *sbuf = vma->vm_private_data;
1378
1379 mutex_lock(&sbuf->cam->s_mutex);
1380 sbuf->mapcount--;
1381 /* Docs say we should stop I/O too... */
1382 if (sbuf->mapcount == 0)
1383 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_MAPPED;
1384 mutex_unlock(&sbuf->cam->s_mutex);
1385}
1386
1387static struct vm_operations_struct cafe_v4l_vm_ops = {
1388 .open = cafe_v4l_vm_open,
1389 .close = cafe_v4l_vm_close
1390};
1391
1392
1393static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma)
1394{
1395 struct cafe_camera *cam = filp->private_data;
1396 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1397 int ret = -EINVAL;
1398 int i;
1399 struct cafe_sio_buffer *sbuf = NULL;
1400
1401 if (! (vma->vm_flags & VM_WRITE) || ! (vma->vm_flags & VM_SHARED))
1402 return -EINVAL;
1403 /*
1404 * Find the buffer they are looking for.
1405 */
1406 mutex_lock(&cam->s_mutex);
1407 for (i = 0; i < cam->n_sbufs; i++)
1408 if (cam->sb_bufs[i].v4lbuf.m.offset == offset) {
1409 sbuf = cam->sb_bufs + i;
1410 break;
1411 }
1412 if (sbuf == NULL)
1413 goto out;
1414
1415 ret = remap_vmalloc_range(vma, sbuf->buffer, 0);
1416 if (ret)
1417 goto out;
1418 vma->vm_flags |= VM_DONTEXPAND;
1419 vma->vm_private_data = sbuf;
1420 vma->vm_ops = &cafe_v4l_vm_ops;
1421 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_MAPPED;
1422 cafe_v4l_vm_open(vma);
1423 ret = 0;
1424 out:
1425 mutex_unlock(&cam->s_mutex);
1426 return ret;
1427}
1428
1429
1430
1431static int cafe_v4l_open(struct inode *inode, struct file *filp)
1432{
1433 struct cafe_camera *cam;
1434
1435 cam = cafe_find_dev(iminor(inode));
1436 if (cam == NULL)
1437 return -ENODEV;
1438 filp->private_data = cam;
1439
1440 mutex_lock(&cam->s_mutex);
1441 if (cam->users == 0) {
1442 cafe_ctlr_power_up(cam);
1443 __cafe_cam_reset(cam);
1444 cafe_set_config_needed(cam, 1);
1445 /* FIXME make sure this is complete */
1446 }
1447 (cam->users)++;
1448 mutex_unlock(&cam->s_mutex);
1449 return 0;
1450}
1451
1452
1453static int cafe_v4l_release(struct inode *inode, struct file *filp)
1454{
1455 struct cafe_camera *cam = filp->private_data;
1456
1457 mutex_lock(&cam->s_mutex);
1458 (cam->users)--;
1459 if (filp == cam->owner) {
1460 cafe_ctlr_stop_dma(cam);
1461 cafe_free_sio_buffers(cam);
1462 cam->owner = NULL;
1463 }
1464 if (cam->users == 0) {
1465 cafe_ctlr_power_down(cam);
1466 if (! alloc_bufs_at_load)
1467 cafe_free_dma_bufs(cam);
1468 }
1469 mutex_unlock(&cam->s_mutex);
1470 return 0;
1471}
1472
1473
1474
1475static unsigned int cafe_v4l_poll(struct file *filp,
1476 struct poll_table_struct *pt)
1477{
1478 struct cafe_camera *cam = filp->private_data;
1479
1480 poll_wait(filp, &cam->iowait, pt);
1481 if (cam->next_buf >= 0)
1482 return POLLIN | POLLRDNORM;
1483 return 0;
1484}
1485
1486
1487
1488static int cafe_vidioc_queryctrl(struct file *filp, void *priv,
1489 struct v4l2_queryctrl *qc)
1490{
1491 struct cafe_camera *cam = filp->private_data;
1492 int ret;
1493
1494 mutex_lock(&cam->s_mutex);
1495 ret = __cafe_cam_cmd(cam, VIDIOC_QUERYCTRL, qc);
1496 mutex_unlock(&cam->s_mutex);
1497 return ret;
1498}
1499
1500
1501static int cafe_vidioc_g_ctrl(struct file *filp, void *priv,
1502 struct v4l2_control *ctrl)
1503{
1504 struct cafe_camera *cam = filp->private_data;
1505 int ret;
1506
1507 mutex_lock(&cam->s_mutex);
1508 ret = __cafe_cam_cmd(cam, VIDIOC_G_CTRL, ctrl);
1509 mutex_unlock(&cam->s_mutex);
1510 return ret;
1511}
1512
1513
1514static int cafe_vidioc_s_ctrl(struct file *filp, void *priv,
1515 struct v4l2_control *ctrl)
1516{
1517 struct cafe_camera *cam = filp->private_data;
1518 int ret;
1519
1520 mutex_lock(&cam->s_mutex);
1521 ret = __cafe_cam_cmd(cam, VIDIOC_S_CTRL, ctrl);
1522 mutex_unlock(&cam->s_mutex);
1523 return ret;
1524}
1525
1526
1527
1528
1529
1530static int cafe_vidioc_querycap(struct file *file, void *priv,
1531 struct v4l2_capability *cap)
1532{
1533 strcpy(cap->driver, "cafe_ccic");
1534 strcpy(cap->card, "cafe_ccic");
1535 cap->version = CAFE_VERSION;
1536 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1537 V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
1538 return 0;
1539}
1540
1541
1542/*
1543 * The default format we use until somebody says otherwise.
1544 */
1545static struct v4l2_pix_format cafe_def_pix_format = {
1546 .width = VGA_WIDTH,
1547 .height = VGA_HEIGHT,
1548 .pixelformat = V4L2_PIX_FMT_YUYV,
1549 .field = V4L2_FIELD_NONE,
1550 .bytesperline = VGA_WIDTH*2,
1551 .sizeimage = VGA_WIDTH*VGA_HEIGHT*2,
1552};
1553
1554static int cafe_vidioc_enum_fmt_cap(struct file *filp,
1555 void *priv, struct v4l2_fmtdesc *fmt)
1556{
1557 struct cafe_camera *cam = priv;
1558 int ret;
1559
1560 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1561 return -EINVAL;
1562 mutex_lock(&cam->s_mutex);
1563 ret = __cafe_cam_cmd(cam, VIDIOC_ENUM_FMT, fmt);
1564 mutex_unlock(&cam->s_mutex);
1565 return ret;
1566}
1567
1568
1569static int cafe_vidioc_try_fmt_cap (struct file *filp, void *priv,
1570 struct v4l2_format *fmt)
1571{
1572 struct cafe_camera *cam = priv;
1573 int ret;
1574
1575 mutex_lock(&cam->s_mutex);
1576 ret = __cafe_cam_cmd(cam, VIDIOC_TRY_FMT, fmt);
1577 mutex_unlock(&cam->s_mutex);
1578 return ret;
1579}
1580
1581static int cafe_vidioc_s_fmt_cap(struct file *filp, void *priv,
1582 struct v4l2_format *fmt)
1583{
1584 struct cafe_camera *cam = priv;
1585 int ret;
1586
1587 /*
1588 * Can't do anything if the device is not idle
1589 * Also can't if there are streaming buffers in place.
1590 */
1591 if (cam->state != S_IDLE || cam->n_sbufs > 0)
1592 return -EBUSY;
1593 /*
1594 * See if the formatting works in principle.
1595 */
1596 ret = cafe_vidioc_try_fmt_cap(filp, priv, fmt);
1597 if (ret)
1598 return ret;
1599 /*
1600 * Now we start to change things for real, so let's do it
1601 * under lock.
1602 */
1603 mutex_lock(&cam->s_mutex);
1604 cam->pix_format = fmt->fmt.pix;
1605 /*
1606 * Make sure we have appropriate DMA buffers.
1607 */
1608 ret = -ENOMEM;
1609 if (cam->nbufs > 0 && cam->dma_buf_size < cam->pix_format.sizeimage)
1610 cafe_free_dma_bufs(cam);
1611 if (cam->nbufs == 0) {
1612 if (cafe_alloc_dma_bufs(cam, 0))
1613 goto out;
1614 }
1615 /*
1616 * It looks like this might work, so let's program the sensor.
1617 */
1618 ret = cafe_cam_configure(cam);
1619 if (! ret)
1620 ret = cafe_ctlr_configure(cam);
1621 out:
1622 mutex_unlock(&cam->s_mutex);
1623 return ret;
1624}
1625
1626/*
1627 * Return our stored notion of how the camera is/should be configured.
1628 * The V4l2 spec wants us to be smarter, and actually get this from
1629 * the camera (and not mess with it at open time). Someday.
1630 */
1631static int cafe_vidioc_g_fmt_cap(struct file *filp, void *priv,
1632 struct v4l2_format *f)
1633{
1634 struct cafe_camera *cam = priv;
1635
1636 f->fmt.pix = cam->pix_format;
1637 return 0;
1638}
1639
1640/*
1641 * We only have one input - the sensor - so minimize the nonsense here.
1642 */
1643static int cafe_vidioc_enum_input(struct file *filp, void *priv,
1644 struct v4l2_input *input)
1645{
1646 if (input->index != 0)
1647 return -EINVAL;
1648
1649 input->type = V4L2_INPUT_TYPE_CAMERA;
1650 input->std = V4L2_STD_ALL; /* Not sure what should go here */
1651 strcpy(input->name, "Camera");
1652 return 0;
1653}
1654
1655static int cafe_vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
1656{
1657 *i = 0;
1658 return 0;
1659}
1660
1661static int cafe_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1662{
1663 if (i != 0)
1664 return -EINVAL;
1665 return 0;
1666}
1667
1668/* from vivi.c */
1669static int cafe_vidioc_s_std(struct file *filp, void *priv, v4l2_std_id *a)
1670{
1671 return 0;
1672}
1673
1674/*
1675 * G/S_PARM. Most of this is done by the sensor, but we are
1676 * the level which controls the number of read buffers.
1677 */
1678static int cafe_vidioc_g_parm(struct file *filp, void *priv,
1679 struct v4l2_streamparm *parms)
1680{
1681 struct cafe_camera *cam = priv;
1682 int ret;
1683
1684 mutex_lock(&cam->s_mutex);
1685 ret = __cafe_cam_cmd(cam, VIDIOC_G_PARM, parms);
1686 mutex_unlock(&cam->s_mutex);
1687 parms->parm.capture.readbuffers = n_dma_bufs;
1688 return ret;
1689}
1690
1691static int cafe_vidioc_s_parm(struct file *filp, void *priv,
1692 struct v4l2_streamparm *parms)
1693{
1694 struct cafe_camera *cam = priv;
1695 int ret;
1696
1697 mutex_lock(&cam->s_mutex);
1698 ret = __cafe_cam_cmd(cam, VIDIOC_S_PARM, parms);
1699 mutex_unlock(&cam->s_mutex);
1700 parms->parm.capture.readbuffers = n_dma_bufs;
1701 return ret;
1702}
1703
1704
1705static void cafe_v4l_dev_release(struct video_device *vd)
1706{
1707 struct cafe_camera *cam = container_of(vd, struct cafe_camera, v4ldev);
1708
1709 kfree(cam);
1710}
1711
1712
1713/*
1714 * This template device holds all of those v4l2 methods; we
1715 * clone it for specific real devices.
1716 */
1717
1718static struct file_operations cafe_v4l_fops = {
1719 .owner = THIS_MODULE,
1720 .open = cafe_v4l_open,
1721 .release = cafe_v4l_release,
1722 .read = cafe_v4l_read,
1723 .poll = cafe_v4l_poll,
1724 .mmap = cafe_v4l_mmap,
1725 .ioctl = video_ioctl2,
1726 .llseek = no_llseek,
1727};
1728
1729static struct video_device cafe_v4l_template = {
1730 .name = "cafe",
1731 .type = VFL_TYPE_GRABBER,
1732 .type2 = VID_TYPE_CAPTURE,
1733 .minor = -1, /* Get one dynamically */
1734 .tvnorms = V4L2_STD_NTSC_M,
1735 .current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */
1736
1737 .fops = &cafe_v4l_fops,
1738 .release = cafe_v4l_dev_release,
1739
1740 .vidioc_querycap = cafe_vidioc_querycap,
1741 .vidioc_enum_fmt_cap = cafe_vidioc_enum_fmt_cap,
1742 .vidioc_try_fmt_cap = cafe_vidioc_try_fmt_cap,
1743 .vidioc_s_fmt_cap = cafe_vidioc_s_fmt_cap,
1744 .vidioc_g_fmt_cap = cafe_vidioc_g_fmt_cap,
1745 .vidioc_enum_input = cafe_vidioc_enum_input,
1746 .vidioc_g_input = cafe_vidioc_g_input,
1747 .vidioc_s_input = cafe_vidioc_s_input,
1748 .vidioc_s_std = cafe_vidioc_s_std,
1749 .vidioc_reqbufs = cafe_vidioc_reqbufs,
1750 .vidioc_querybuf = cafe_vidioc_querybuf,
1751 .vidioc_qbuf = cafe_vidioc_qbuf,
1752 .vidioc_dqbuf = cafe_vidioc_dqbuf,
1753 .vidioc_streamon = cafe_vidioc_streamon,
1754 .vidioc_streamoff = cafe_vidioc_streamoff,
1755 .vidioc_queryctrl = cafe_vidioc_queryctrl,
1756 .vidioc_g_ctrl = cafe_vidioc_g_ctrl,
1757 .vidioc_s_ctrl = cafe_vidioc_s_ctrl,
1758 .vidioc_g_parm = cafe_vidioc_g_parm,
1759 .vidioc_s_parm = cafe_vidioc_s_parm,
1760};
1761
1762
1763
1764
1765
1766
1767
1768/* ---------------------------------------------------------------------- */
1769/*
1770 * Interrupt handler stuff
1771 */
1772
1773
1774
1775static void cafe_frame_tasklet(unsigned long data)
1776{
1777 struct cafe_camera *cam = (struct cafe_camera *) data;
1778 int i;
1779 unsigned long flags;
1780 struct cafe_sio_buffer *sbuf;
1781
1782 spin_lock_irqsave(&cam->dev_lock, flags);
1783 for (i = 0; i < cam->nbufs; i++) {
1784 int bufno = cam->next_buf;
1785 if (bufno < 0) { /* "will never happen" */
1786 cam_err(cam, "No valid bufs in tasklet!\n");
1787 break;
1788 }
1789 if (++(cam->next_buf) >= cam->nbufs)
1790 cam->next_buf = 0;
1791 if (! test_bit(bufno, &cam->flags))
1792 continue;
1793 if (list_empty(&cam->sb_avail))
1794 break; /* Leave it valid, hope for better later */
1795 clear_bit(bufno, &cam->flags);
1796 /*
1797 * We could perhaps drop the spinlock during this
1798 * big copy. Something to consider.
1799 */
1800 sbuf = list_entry(cam->sb_avail.next,
1801 struct cafe_sio_buffer, list);
1802 memcpy(sbuf->buffer, cam->dma_bufs[bufno],
1803 cam->pix_format.sizeimage);
1804 sbuf->v4lbuf.bytesused = cam->pix_format.sizeimage;
1805 sbuf->v4lbuf.sequence = cam->buf_seq[bufno];
1806 sbuf->v4lbuf.flags &= ~V4L2_BUF_FLAG_QUEUED;
1807 sbuf->v4lbuf.flags |= V4L2_BUF_FLAG_DONE;
1808 list_move_tail(&sbuf->list, &cam->sb_full);
1809 }
1810 if (! list_empty(&cam->sb_full))
1811 wake_up(&cam->iowait);
1812 spin_unlock_irqrestore(&cam->dev_lock, flags);
1813}
1814
1815
1816
1817static void cafe_frame_complete(struct cafe_camera *cam, int frame)
1818{
1819 /*
1820 * Basic frame housekeeping.
1821 */
1822 if (test_bit(frame, &cam->flags) && printk_ratelimit())
1823 cam_err(cam, "Frame overrun on %d, frames lost\n", frame);
1824 set_bit(frame, &cam->flags);
1825 clear_bit(CF_DMA_ACTIVE, &cam->flags);
1826 if (cam->next_buf < 0)
1827 cam->next_buf = frame;
1828 cam->buf_seq[frame] = ++(cam->sequence);
1829
1830 switch (cam->state) {
1831 /*
1832 * If in single read mode, try going speculative.
1833 */
1834 case S_SINGLEREAD:
1835 cam->state = S_SPECREAD;
1836 cam->specframes = 0;
1837 wake_up(&cam->iowait);
1838 break;
1839
1840 /*
1841 * If we are already doing speculative reads, and nobody is
1842 * reading them, just stop.
1843 */
1844 case S_SPECREAD:
1845 if (++(cam->specframes) >= cam->nbufs) {
1846 cafe_ctlr_stop(cam);
1847 cafe_ctlr_irq_disable(cam);
1848 cam->state = S_IDLE;
1849 }
1850 wake_up(&cam->iowait);
1851 break;
1852 /*
1853 * For the streaming case, we defer the real work to the
1854 * camera tasklet.
1855 *
1856 * FIXME: if the application is not consuming the buffers,
1857 * we should eventually put things on hold and restart in
1858 * vidioc_dqbuf().
1859 */
1860 case S_STREAMING:
1861 tasklet_schedule(&cam->s_tasklet);
1862 break;
1863
1864 default:
1865 cam_err(cam, "Frame interrupt in non-operational state\n");
1866 break;
1867 }
1868}
1869
1870
1871
1872
1873static void cafe_frame_irq(struct cafe_camera *cam, unsigned int irqs)
1874{
1875 unsigned int frame;
1876
1877 cafe_reg_write(cam, REG_IRQSTAT, FRAMEIRQS); /* Clear'em all */
1878 /*
1879 * Handle any frame completions. There really should
1880 * not be more than one of these, or we have fallen
1881 * far behind.
1882 */
1883 for (frame = 0; frame < cam->nbufs; frame++)
1884 if (irqs & (IRQ_EOF0 << frame))
1885 cafe_frame_complete(cam, frame);
1886 /*
1887 * If a frame starts, note that we have DMA active. This
1888 * code assumes that we won't get multiple frame interrupts
1889 * at once; may want to rethink that.
1890 */
1891 if (irqs & (IRQ_SOF0 | IRQ_SOF1 | IRQ_SOF2))
1892 set_bit(CF_DMA_ACTIVE, &cam->flags);
1893}
1894
1895
1896
1897static irqreturn_t cafe_irq(int irq, void *data)
1898{
1899 struct cafe_camera *cam = data;
1900 unsigned int irqs;
1901
1902 spin_lock(&cam->dev_lock);
1903 irqs = cafe_reg_read(cam, REG_IRQSTAT);
1904 if ((irqs & ALLIRQS) == 0) {
1905 spin_unlock(&cam->dev_lock);
1906 return IRQ_NONE;
1907 }
1908 if (irqs & FRAMEIRQS)
1909 cafe_frame_irq(cam, irqs);
1910 if (irqs & TWSIIRQS) {
1911 cafe_reg_write(cam, REG_IRQSTAT, TWSIIRQS);
1912 wake_up(&cam->smbus_wait);
1913 }
1914 spin_unlock(&cam->dev_lock);
1915 return IRQ_HANDLED;
1916}
1917
1918
1919/* -------------------------------------------------------------------------- */
1920#ifdef CONFIG_VIDEO_ADV_DEBUG
1921/*
1922 * Debugfs stuff.
1923 */
1924
1925static char cafe_debug_buf[1024];
1926static struct dentry *cafe_dfs_root;
1927
1928static void cafe_dfs_setup(void)
1929{
1930 cafe_dfs_root = debugfs_create_dir("cafe_ccic", NULL);
1931 if (IS_ERR(cafe_dfs_root)) {
1932 cafe_dfs_root = NULL; /* Never mind */
1933 printk(KERN_NOTICE "cafe_ccic unable to set up debugfs\n");
1934 }
1935}
1936
1937static void cafe_dfs_shutdown(void)
1938{
1939 if (cafe_dfs_root)
1940 debugfs_remove(cafe_dfs_root);
1941}
1942
1943static int cafe_dfs_open(struct inode *inode, struct file *file)
1944{
1945 file->private_data = inode->i_private;
1946 return 0;
1947}
1948
1949static ssize_t cafe_dfs_read_regs(struct file *file,
1950 char __user *buf, size_t count, loff_t *ppos)
1951{
1952 struct cafe_camera *cam = file->private_data;
1953 char *s = cafe_debug_buf;
1954 int offset;
1955
1956 for (offset = 0; offset < 0x44; offset += 4)
1957 s += sprintf(s, "%02x: %08x\n", offset,
1958 cafe_reg_read(cam, offset));
1959 for (offset = 0x88; offset <= 0x90; offset += 4)
1960 s += sprintf(s, "%02x: %08x\n", offset,
1961 cafe_reg_read(cam, offset));
1962 for (offset = 0xb4; offset <= 0xbc; offset += 4)
1963 s += sprintf(s, "%02x: %08x\n", offset,
1964 cafe_reg_read(cam, offset));
1965 for (offset = 0x3000; offset <= 0x300c; offset += 4)
1966 s += sprintf(s, "%04x: %08x\n", offset,
1967 cafe_reg_read(cam, offset));
1968 return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
1969 s - cafe_debug_buf);
1970}
1971
1972static struct file_operations cafe_dfs_reg_ops = {
1973 .owner = THIS_MODULE,
1974 .read = cafe_dfs_read_regs,
1975 .open = cafe_dfs_open
1976};
1977
1978static ssize_t cafe_dfs_read_cam(struct file *file,
1979 char __user *buf, size_t count, loff_t *ppos)
1980{
1981 struct cafe_camera *cam = file->private_data;
1982 char *s = cafe_debug_buf;
1983 int offset;
1984
1985 if (! cam->sensor)
1986 return -EINVAL;
1987 for (offset = 0x0; offset < 0x8a; offset++)
1988 {
1989 u8 v;
1990
1991 cafe_smbus_read_data(cam, cam->sensor->addr, offset, &v);
1992 s += sprintf(s, "%02x: %02x\n", offset, v);
1993 }
1994 return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf,
1995 s - cafe_debug_buf);
1996}
1997
1998static struct file_operations cafe_dfs_cam_ops = {
1999 .owner = THIS_MODULE,
2000 .read = cafe_dfs_read_cam,
2001 .open = cafe_dfs_open
2002};
2003
2004
2005
2006static void cafe_dfs_cam_setup(struct cafe_camera *cam)
2007{
2008 char fname[40];
2009
2010 if (!cafe_dfs_root)
2011 return;
2012 sprintf(fname, "regs-%d", cam->v4ldev.minor);
2013 cam->dfs_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
2014 cam, &cafe_dfs_reg_ops);
2015 sprintf(fname, "cam-%d", cam->v4ldev.minor);
2016 cam->dfs_cam_regs = debugfs_create_file(fname, 0444, cafe_dfs_root,
2017 cam, &cafe_dfs_cam_ops);
2018}
2019
2020
2021static void cafe_dfs_cam_shutdown(struct cafe_camera *cam)
2022{
2023 if (! IS_ERR(cam->dfs_regs))
2024 debugfs_remove(cam->dfs_regs);
2025 if (! IS_ERR(cam->dfs_cam_regs))
2026 debugfs_remove(cam->dfs_cam_regs);
2027}
2028
2029#else
2030
2031#define cafe_dfs_setup()
2032#define cafe_dfs_shutdown()
2033#define cafe_dfs_cam_setup(cam)
2034#define cafe_dfs_cam_shutdown(cam)
2035#endif /* CONFIG_VIDEO_ADV_DEBUG */
2036
2037
2038
2039
2040/* ------------------------------------------------------------------------*/
2041/*
2042 * PCI interface stuff.
2043 */
2044
2045static int cafe_pci_probe(struct pci_dev *pdev,
2046 const struct pci_device_id *id)
2047{
2048 int ret;
2049 u16 classword;
2050 struct cafe_camera *cam;
2051 /*
2052 * Make sure we have a camera here - we'll get calls for
2053 * the other cafe devices as well.
2054 */
2055 pci_read_config_word(pdev, PCI_CLASS_DEVICE, &classword);
2056 if (classword != PCI_CLASS_MULTIMEDIA_VIDEO)
2057 return -ENODEV;
2058 /*
2059 * Start putting together one of our big camera structures.
2060 */
2061 ret = -ENOMEM;
2062 cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL);
2063 if (cam == NULL)
2064 goto out;
2065 mutex_init(&cam->s_mutex);
2066 mutex_lock(&cam->s_mutex);
2067 spin_lock_init(&cam->dev_lock);
2068 cam->state = S_NOTREADY;
2069 cafe_set_config_needed(cam, 1);
2070 init_waitqueue_head(&cam->smbus_wait);
2071 init_waitqueue_head(&cam->iowait);
2072 cam->pdev = pdev;
2073 cam->pix_format = cafe_def_pix_format;
2074 INIT_LIST_HEAD(&cam->dev_list);
2075 INIT_LIST_HEAD(&cam->sb_avail);
2076 INIT_LIST_HEAD(&cam->sb_full);
2077 tasklet_init(&cam->s_tasklet, cafe_frame_tasklet, (unsigned long) cam);
2078 /*
2079 * Get set up on the PCI bus.
2080 */
2081 ret = pci_enable_device(pdev);
2082 if (ret)
2083 goto out_free;
2084 pci_set_master(pdev);
2085
2086 ret = -EIO;
2087 cam->regs = pci_iomap(pdev, 0, 0);
2088 if (! cam->regs) {
2089 printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n");
2090 goto out_free;
2091 }
2092 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
2093 if (ret)
2094 goto out_iounmap;
2095 cafe_ctlr_init(cam);
2096 cafe_ctlr_power_up(cam);
2097 /*
2098 * Set up I2C/SMBUS communications
2099 */
2100 mutex_unlock(&cam->s_mutex); /* attach can deadlock */
2101 ret = cafe_smbus_setup(cam);
2102 if (ret)
2103 goto out_freeirq;
2104 /*
2105 * Get the v4l2 setup done.
2106 */
2107 mutex_lock(&cam->s_mutex);
2108 cam->v4ldev = cafe_v4l_template;
2109 cam->v4ldev.debug = 0;
2110// cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG;
2111 ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1);
2112 if (ret)
2113 goto out_smbus;
2114 /*
2115 * If so requested, try to get our DMA buffers now.
2116 */
2117 if (alloc_bufs_at_load) {
2118 if (cafe_alloc_dma_bufs(cam, 1))
2119 cam_warn(cam, "Unable to alloc DMA buffers at load"
2120 " will try again later.");
2121 }
2122
2123 cafe_dfs_cam_setup(cam);
2124 mutex_unlock(&cam->s_mutex);
2125 cafe_add_dev(cam);
2126 return 0;
2127
2128 out_smbus:
2129 cafe_smbus_shutdown(cam);
2130 out_freeirq:
2131 cafe_ctlr_power_down(cam);
2132 free_irq(pdev->irq, cam);
2133 out_iounmap:
2134 pci_iounmap(pdev, cam->regs);
2135 out_free:
2136 kfree(cam);
2137 out:
2138 return ret;
2139}
2140
2141
2142/*
2143 * Shut down an initialized device
2144 */
2145static void cafe_shutdown(struct cafe_camera *cam)
2146{
2147/* FIXME: Make sure we take care of everything here */
2148 cafe_dfs_cam_shutdown(cam);
2149 if (cam->n_sbufs > 0)
2150 /* What if they are still mapped? Shouldn't be, but... */
2151 cafe_free_sio_buffers(cam);
2152 cafe_remove_dev(cam);
2153 cafe_ctlr_stop_dma(cam);
2154 cafe_ctlr_power_down(cam);
2155 cafe_smbus_shutdown(cam);
2156 cafe_free_dma_bufs(cam);
2157 free_irq(cam->pdev->irq, cam);
2158 pci_iounmap(cam->pdev, cam->regs);
2159 video_unregister_device(&cam->v4ldev);
2160 /* kfree(cam); done in v4l_release () */
2161}
2162
2163
2164static void cafe_pci_remove(struct pci_dev *pdev)
2165{
2166 struct cafe_camera *cam = cafe_find_by_pdev(pdev);
2167
2168 if (cam == NULL) {
2169 cam_warn(cam, "pci_remove on unknown pdev %p\n", pdev);
2170 return;
2171 }
2172 mutex_lock(&cam->s_mutex);
2173 if (cam->users > 0)
2174 cam_warn(cam, "Removing a device with users!\n");
2175 cafe_shutdown(cam);
2176/* No unlock - it no longer exists */
2177}
2178
2179
2180
2181
2182static struct pci_device_id cafe_ids[] = {
2183 { PCI_DEVICE(0x1148, 0x4340) }, /* Temporary ID on devel board */
2184 { PCI_DEVICE(0x11ab, 0x4100) }, /* Eventual real ID */
2185 { PCI_DEVICE(0x11ab, 0x4102) }, /* Really eventual real ID */
2186 { 0, }
2187};
2188
2189MODULE_DEVICE_TABLE(pci, cafe_ids);
2190
2191static struct pci_driver cafe_pci_driver = {
2192 .name = "cafe1000-ccic",
2193 .id_table = cafe_ids,
2194 .probe = cafe_pci_probe,
2195 .remove = cafe_pci_remove,
2196};
2197
2198
2199
2200
2201static int __init cafe_init(void)
2202{
2203 int ret;
2204
2205 printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n",
2206 CAFE_VERSION);
2207 cafe_dfs_setup();
2208 ret = pci_register_driver(&cafe_pci_driver);
2209 if (ret) {
2210 printk(KERN_ERR "Unable to register cafe_ccic driver\n");
2211 goto out;
2212 }
2213 request_module("ov7670"); /* FIXME want something more general */
2214 ret = 0;
2215
2216 out:
2217 return ret;
2218}
2219
2220
2221static void __exit cafe_exit(void)
2222{
2223 pci_unregister_driver(&cafe_pci_driver);
2224 cafe_dfs_shutdown();
2225}
2226
2227module_init(cafe_init);
2228module_exit(cafe_exit);
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index d82a488f12a6..f065ad12cc61 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -118,7 +118,7 @@ static int native_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
118 ret = file->f_op->unlocked_ioctl(file, cmd, arg); 118 ret = file->f_op->unlocked_ioctl(file, cmd, arg);
119 else if (file->f_op->ioctl) { 119 else if (file->f_op->ioctl) {
120 lock_kernel(); 120 lock_kernel();
121 ret = file->f_op->ioctl(file->f_dentry->d_inode, file, cmd, arg); 121 ret = file->f_op->ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
122 unlock_kernel(); 122 unlock_kernel();
123 } 123 }
124 124
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 0f9d96963618..b2a66ba625f9 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -53,6 +53,7 @@ config VIDEO_CX88_DVB
53 select DVB_OR51132 if !DVB_FE_CUSTOMISE 53 select DVB_OR51132 if !DVB_FE_CUSTOMISE
54 select DVB_CX22702 if !DVB_FE_CUSTOMISE 54 select DVB_CX22702 if !DVB_FE_CUSTOMISE
55 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 55 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
56 select DVB_TUNER_LGH06XF if !DVB_FE_CUSTOMISE
56 select DVB_NXT200X if !DVB_FE_CUSTOMISE 57 select DVB_NXT200X if !DVB_FE_CUSTOMISE
57 select DVB_CX24123 if !DVB_FE_CUSTOMISE 58 select DVB_CX24123 if !DVB_FE_CUSTOMISE
58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 59 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 46738321adaf..0cf0360588e6 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -50,7 +50,6 @@ MODULE_PARM_DESC(debug,"enable debug messages [blackbird]");
50#define dprintk(level,fmt, arg...) if (debug >= level) \ 50#define dprintk(level,fmt, arg...) if (debug >= level) \
51 printk(KERN_DEBUG "%s/2-bb: " fmt, dev->core->name , ## arg) 51 printk(KERN_DEBUG "%s/2-bb: " fmt, dev->core->name , ## arg)
52 52
53static LIST_HEAD(cx8802_devlist);
54 53
55/* ------------------------------------------------------------------ */ 54/* ------------------------------------------------------------------ */
56 55
@@ -882,7 +881,7 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file,
882 BLACKBIRD_MPEG_CAPTURE, 881 BLACKBIRD_MPEG_CAPTURE,
883 BLACKBIRD_RAW_BITS_NONE); 882 BLACKBIRD_RAW_BITS_NONE);
884 883
885 cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl); 884 cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook);
886 885
887 blackbird_initialize_codec(dev); 886 blackbird_initialize_codec(dev);
888 cx88_set_scale(dev->core, dev->width, dev->height, 887 cx88_set_scale(dev->core, dev->width, dev->height,
@@ -914,11 +913,15 @@ static int mpeg_do_ioctl(struct inode *inode, struct file *file,
914 } 913 }
915 914
916 default: 915 default:
917 return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, mpeg_do_ioctl); 916 return cx88_do_ioctl(inode, file, 0, dev->core, cmd, arg, cx88_ioctl_hook);
918 } 917 }
919 return 0; 918 return 0;
920} 919}
921 920
921int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
922 unsigned int cmd, void *arg);
923unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
924
922static unsigned int mpeg_translate_ioctl(unsigned int cmd) 925static unsigned int mpeg_translate_ioctl(unsigned int cmd)
923{ 926{
924 return cmd; 927 return cmd;
@@ -927,33 +930,49 @@ static unsigned int mpeg_translate_ioctl(unsigned int cmd)
927static int mpeg_ioctl(struct inode *inode, struct file *file, 930static int mpeg_ioctl(struct inode *inode, struct file *file,
928 unsigned int cmd, unsigned long arg) 931 unsigned int cmd, unsigned long arg)
929{ 932{
930 cmd = mpeg_translate_ioctl( cmd ); 933 cmd = cx88_ioctl_translator( cmd );
931 return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl); 934 return video_usercopy(inode, file, cmd, arg, cx88_ioctl_hook);
932} 935}
933 936
934static int mpeg_open(struct inode *inode, struct file *file) 937static int mpeg_open(struct inode *inode, struct file *file)
935{ 938{
936 int minor = iminor(inode); 939 int minor = iminor(inode);
937 struct cx8802_dev *h,*dev = NULL; 940 struct cx8802_dev *dev = NULL;
938 struct cx8802_fh *fh; 941 struct cx8802_fh *fh;
939 struct list_head *list; 942 struct cx8802_driver *drv = NULL;
943 int err;
940 944
941 list_for_each(list,&cx8802_devlist) { 945 dev = cx8802_get_device(inode);
942 h = list_entry(list, struct cx8802_dev, devlist); 946
943 if (h->mpeg_dev->minor == minor) 947 dprintk( 1, "%s\n", __FUNCTION__);
944 dev = h; 948
945 } 949 if (dev == NULL)
946 if (NULL == dev)
947 return -ENODEV; 950 return -ENODEV;
948 951
949 if (blackbird_initialize_codec(dev) < 0) 952 /* Make sure we can acquire the hardware */
953 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
954 if (drv) {
955 err = drv->request_acquire(drv);
956 if(err != 0) {
957 dprintk(1,"%s: Unable to acquire hardware, %d\n", __FUNCTION__, err);
958 return err;
959 }
960 }
961
962 if (blackbird_initialize_codec(dev) < 0) {
963 if (drv)
964 drv->request_release(drv);
950 return -EINVAL; 965 return -EINVAL;
966 }
951 dprintk(1,"open minor=%d\n",minor); 967 dprintk(1,"open minor=%d\n",minor);
952 968
953 /* allocate + initialize per filehandle data */ 969 /* allocate + initialize per filehandle data */
954 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 970 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
955 if (NULL == fh) 971 if (NULL == fh) {
972 if (drv)
973 drv->request_release(drv);
956 return -ENOMEM; 974 return -ENOMEM;
975 }
957 file->private_data = fh; 976 file->private_data = fh;
958 fh->dev = dev; 977 fh->dev = dev;
959 978
@@ -974,6 +993,8 @@ static int mpeg_open(struct inode *inode, struct file *file)
974static int mpeg_release(struct inode *inode, struct file *file) 993static int mpeg_release(struct inode *inode, struct file *file)
975{ 994{
976 struct cx8802_fh *fh = file->private_data; 995 struct cx8802_fh *fh = file->private_data;
996 struct cx8802_dev *dev = NULL;
997 struct cx8802_driver *drv = NULL;
977 998
978 /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */ 999 /* blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, BLACKBIRD_END_NOW, 0, 0x13); */
979 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0, 1000 blackbird_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
@@ -992,6 +1013,16 @@ static int mpeg_release(struct inode *inode, struct file *file)
992 videobuf_mmap_free(&fh->mpegq); 1013 videobuf_mmap_free(&fh->mpegq);
993 file->private_data = NULL; 1014 file->private_data = NULL;
994 kfree(fh); 1015 kfree(fh);
1016
1017 /* Make sure we release the hardware */
1018 dev = cx8802_get_device(inode);
1019 if (dev == NULL)
1020 return -ENODEV;
1021
1022 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
1023 if (drv)
1024 drv->request_release(drv);
1025
995 return 0; 1026 return 0;
996} 1027}
997 1028
@@ -1043,6 +1074,44 @@ static struct video_device cx8802_mpeg_template =
1043 1074
1044/* ------------------------------------------------------------------ */ 1075/* ------------------------------------------------------------------ */
1045 1076
1077/* The CX8802 MPEG API will call this when we can use the hardware */
1078static int cx8802_blackbird_advise_acquire(struct cx8802_driver *drv)
1079{
1080 struct cx88_core *core = drv->core;
1081 int err = 0;
1082
1083 switch (core->board) {
1084 case CX88_BOARD_HAUPPAUGE_HVR1300:
1085 /* By default, core setup will leave the cx22702 out of reset, on the bus.
1086 * We left the hardware on power up with the cx22702 active.
1087 * We're being given access to re-arrange the GPIOs.
1088 * Take the bus off the cx22702 and put the cx23416 on it.
1089 */
1090 cx_clear(MO_GP0_IO, 0x00000080); /* cx22702 in reset */
1091 cx_set(MO_GP0_IO, 0x00000004); /* Disable the cx22702 */
1092 break;
1093 default:
1094 err = -ENODEV;
1095 }
1096 return err;
1097}
1098
1099/* The CX8802 MPEG API will call this when we need to release the hardware */
1100static int cx8802_blackbird_advise_release(struct cx8802_driver *drv)
1101{
1102 struct cx88_core *core = drv->core;
1103 int err = 0;
1104
1105 switch (core->board) {
1106 case CX88_BOARD_HAUPPAUGE_HVR1300:
1107 /* Exit leaving the cx23416 on the bus */
1108 break;
1109 default:
1110 err = -ENODEV;
1111 }
1112 return err;
1113}
1114
1046static void blackbird_unregister_video(struct cx8802_dev *dev) 1115static void blackbird_unregister_video(struct cx8802_dev *dev)
1047{ 1116{
1048 if (dev->mpeg_dev) { 1117 if (dev->mpeg_dev) {
@@ -1073,28 +1142,23 @@ static int blackbird_register_video(struct cx8802_dev *dev)
1073 1142
1074/* ----------------------------------------------------------- */ 1143/* ----------------------------------------------------------- */
1075 1144
1076static int __devinit blackbird_probe(struct pci_dev *pci_dev, 1145static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1077 const struct pci_device_id *pci_id)
1078{ 1146{
1079 struct cx8802_dev *dev; 1147 struct cx88_core *core = drv->core;
1080 struct cx88_core *core; 1148 struct cx8802_dev *dev = core->dvbdev;
1081 int err; 1149 int err;
1082 1150
1083 /* general setup */ 1151 dprintk( 1, "%s\n", __FUNCTION__);
1084 core = cx88_core_get(pci_dev); 1152 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
1085 if (NULL == core) 1153 core->board,
1086 return -EINVAL; 1154 core->name,
1155 core->pci_bus,
1156 core->pci_slot);
1087 1157
1088 err = -ENODEV; 1158 err = -ENODEV;
1089 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD)) 1159 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD))
1090 goto fail_core; 1160 goto fail_core;
1091 1161
1092 err = -ENOMEM;
1093 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
1094 if (NULL == dev)
1095 goto fail_core;
1096 dev->pci = pci_dev;
1097 dev->core = core;
1098 dev->width = 720; 1162 dev->width = 720;
1099 dev->height = 576; 1163 dev->height = 576;
1100 cx2341x_fill_defaults(&dev->params); 1164 cx2341x_fill_defaults(&dev->params);
@@ -1106,64 +1170,36 @@ static int __devinit blackbird_probe(struct pci_dev *pci_dev,
1106 dev->height = 576; 1170 dev->height = 576;
1107 } 1171 }
1108 1172
1109 err = cx8802_init_common(dev);
1110 if (0 != err)
1111 goto fail_free;
1112
1113 /* blackbird stuff */ 1173 /* blackbird stuff */
1114 printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n", 1174 printk("%s/2: cx23416 based mpeg encoder (blackbird reference design)\n",
1115 core->name); 1175 core->name);
1116 host_setup(dev->core); 1176 host_setup(dev->core);
1117 1177
1118 list_add_tail(&dev->devlist,&cx8802_devlist);
1119 blackbird_register_video(dev); 1178 blackbird_register_video(dev);
1120 1179
1121 /* initial device configuration: needed ? */ 1180 /* initial device configuration: needed ? */
1122 1181
1123 return 0; 1182 return 0;
1124 1183
1125 fail_free:
1126 kfree(dev);
1127 fail_core: 1184 fail_core:
1128 cx88_core_put(core,pci_dev);
1129 return err; 1185 return err;
1130} 1186}
1131 1187
1132static void __devexit blackbird_remove(struct pci_dev *pci_dev) 1188static int cx8802_blackbird_remove(struct cx8802_driver *drv)
1133{ 1189{
1134 struct cx8802_dev *dev = pci_get_drvdata(pci_dev);
1135
1136 /* blackbird */ 1190 /* blackbird */
1137 blackbird_unregister_video(dev); 1191 blackbird_unregister_video(drv->core->dvbdev);
1138 list_del(&dev->devlist);
1139 1192
1140 /* common */ 1193 return 0;
1141 cx8802_fini_common(dev);
1142 cx88_core_put(dev->core,dev->pci);
1143 kfree(dev);
1144} 1194}
1145 1195
1146static struct pci_device_id cx8802_pci_tbl[] = { 1196static struct cx8802_driver cx8802_blackbird_driver = {
1147 { 1197 .type_id = CX88_MPEG_BLACKBIRD,
1148 .vendor = 0x14f1, 1198 .hw_access = CX8802_DRVCTL_SHARED,
1149 .device = 0x8802, 1199 .probe = cx8802_blackbird_probe,
1150 .subvendor = PCI_ANY_ID, 1200 .remove = cx8802_blackbird_remove,
1151 .subdevice = PCI_ANY_ID, 1201 .advise_acquire = cx8802_blackbird_advise_acquire,
1152 },{ 1202 .advise_release = cx8802_blackbird_advise_release,
1153 /* --- end of list --- */
1154 }
1155};
1156MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
1157
1158static struct pci_driver blackbird_pci_driver = {
1159 .name = "cx88-blackbird",
1160 .id_table = cx8802_pci_tbl,
1161 .probe = blackbird_probe,
1162 .remove = __devexit_p(blackbird_remove),
1163#ifdef CONFIG_PM
1164 .suspend = cx8802_suspend_common,
1165 .resume = cx8802_resume_common,
1166#endif
1167}; 1203};
1168 1204
1169static int blackbird_init(void) 1205static int blackbird_init(void)
@@ -1176,17 +1212,22 @@ static int blackbird_init(void)
1176 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", 1212 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
1177 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); 1213 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1178#endif 1214#endif
1179 return pci_register_driver(&blackbird_pci_driver); 1215 cx88_ioctl_hook = mpeg_do_ioctl;
1216 cx88_ioctl_translator = mpeg_translate_ioctl;
1217 return cx8802_register_driver(&cx8802_blackbird_driver);
1180} 1218}
1181 1219
1182static void blackbird_fini(void) 1220static void blackbird_fini(void)
1183{ 1221{
1184 pci_unregister_driver(&blackbird_pci_driver); 1222 cx8802_unregister_driver(&cx8802_blackbird_driver);
1185} 1223}
1186 1224
1187module_init(blackbird_init); 1225module_init(blackbird_init);
1188module_exit(blackbird_fini); 1226module_exit(blackbird_fini);
1189 1227
1228EXPORT_SYMBOL(cx88_ioctl_hook);
1229EXPORT_SYMBOL(cx88_ioctl_translator);
1230
1190/* ----------------------------------------------------------- */ 1231/* ----------------------------------------------------------- */
1191/* 1232/*
1192 * Local variables: 1233 * Local variables:
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index f764a57c56be..c791708b1336 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -281,18 +281,22 @@ struct cx88_board cx88_boards[] = {
281 .type = CX88_VMUX_TELEVISION, 281 .type = CX88_VMUX_TELEVISION,
282 .vmux = 0, 282 .vmux = 0,
283 .gpio0 = 0x0000bde2, 283 .gpio0 = 0x0000bde2,
284 .extadc = 1,
284 },{ 285 },{
285 .type = CX88_VMUX_COMPOSITE1, 286 .type = CX88_VMUX_COMPOSITE1,
286 .vmux = 1, 287 .vmux = 1,
287 .gpio0 = 0x0000bde6, 288 .gpio0 = 0x0000bde6,
289 .extadc = 1,
288 },{ 290 },{
289 .type = CX88_VMUX_SVIDEO, 291 .type = CX88_VMUX_SVIDEO,
290 .vmux = 2, 292 .vmux = 2,
291 .gpio0 = 0x0000bde6, 293 .gpio0 = 0x0000bde6,
294 .extadc = 1,
292 }}, 295 }},
293 .radio = { 296 .radio = {
294 .type = CX88_RADIO, 297 .type = CX88_RADIO,
295 .gpio0 = 0x0000bd62, 298 .gpio0 = 0x0000bd62,
299 .extadc = 1,
296 }, 300 },
297 .mpeg = CX88_MPEG_BLACKBIRD, 301 .mpeg = CX88_MPEG_BLACKBIRD,
298 }, 302 },
@@ -353,6 +357,7 @@ struct cx88_board cx88_boards[] = {
353 .type = CX88_VMUX_SVIDEO, 357 .type = CX88_VMUX_SVIDEO,
354 .vmux = 2, 358 .vmux = 2,
355 .gpio0 = 0x0000fde6, // 0x0000fda6 L,R RCA audio in? 359 .gpio0 = 0x0000fde6, // 0x0000fda6 L,R RCA audio in?
360 .extadc = 1,
356 }}, 361 }},
357 .radio = { 362 .radio = {
358 .type = CX88_RADIO, 363 .type = CX88_RADIO,
@@ -523,6 +528,7 @@ struct cx88_board cx88_boards[] = {
523 .input = {{ 528 .input = {{
524 .type = CX88_VMUX_TELEVISION, 529 .type = CX88_VMUX_TELEVISION,
525 .vmux = 0, 530 .vmux = 0,
531 .extadc = 1,
526 }}, 532 }},
527 .mpeg = CX88_MPEG_BLACKBIRD, 533 .mpeg = CX88_MPEG_BLACKBIRD,
528 }, 534 },
@@ -646,18 +652,22 @@ struct cx88_board cx88_boards[] = {
646 .type = CX88_VMUX_TELEVISION, 652 .type = CX88_VMUX_TELEVISION,
647 .vmux = 0, 653 .vmux = 0,
648 .gpio0 = 0x00009d80, 654 .gpio0 = 0x00009d80,
655 .extadc = 1,
649 },{ 656 },{
650 .type = CX88_VMUX_COMPOSITE1, 657 .type = CX88_VMUX_COMPOSITE1,
651 .vmux = 1, 658 .vmux = 1,
652 .gpio0 = 0x00009d76, 659 .gpio0 = 0x00009d76,
660 .extadc = 1,
653 },{ 661 },{
654 .type = CX88_VMUX_SVIDEO, 662 .type = CX88_VMUX_SVIDEO,
655 .vmux = 2, 663 .vmux = 2,
656 .gpio0 = 0x00009d76, 664 .gpio0 = 0x00009d76,
665 .extadc = 1,
657 }}, 666 }},
658 .radio = { 667 .radio = {
659 .type = CX88_RADIO, 668 .type = CX88_RADIO,
660 .gpio0 = 0x00009d00, 669 .gpio0 = 0x00009d00,
670 .extadc = 1,
661 }, 671 },
662 .mpeg = CX88_MPEG_BLACKBIRD, 672 .mpeg = CX88_MPEG_BLACKBIRD,
663 }, 673 },
@@ -786,25 +796,29 @@ struct cx88_board cx88_boards[] = {
786 .tuner_addr = ADDR_UNSET, 796 .tuner_addr = ADDR_UNSET,
787 .radio_addr = ADDR_UNSET, 797 .radio_addr = ADDR_UNSET,
788 .tda9887_conf = TDA9887_PRESENT, 798 .tda9887_conf = TDA9887_PRESENT,
789 .mpeg = CX88_MPEG_BLACKBIRD,
790 .input = {{ 799 .input = {{
791 .type = CX88_VMUX_COMPOSITE1, 800 .type = CX88_VMUX_COMPOSITE1,
792 .vmux = 0, 801 .vmux = 0,
793 .gpio0 = 0x0000cd73, 802 .gpio0 = 0x0000cd73,
803 .extadc = 1,
794 },{ 804 },{
795 .type = CX88_VMUX_SVIDEO, 805 .type = CX88_VMUX_SVIDEO,
796 .vmux = 1, 806 .vmux = 1,
797 .gpio0 = 0x0000cd73, 807 .gpio0 = 0x0000cd73,
808 .extadc = 1,
798 },{ 809 },{
799 .type = CX88_VMUX_TELEVISION, 810 .type = CX88_VMUX_TELEVISION,
800 .vmux = 3, 811 .vmux = 3,
801 .gpio0 = 0x0000cdb3, 812 .gpio0 = 0x0000cdb3,
813 .extadc = 1,
802 }}, 814 }},
803 .radio = { 815 .radio = {
804 .type = CX88_RADIO, 816 .type = CX88_RADIO,
805 .vmux = 2, 817 .vmux = 2,
806 .gpio0 = 0x0000cdf3, 818 .gpio0 = 0x0000cdf3,
819 .extadc = 1,
807 }, 820 },
821 .mpeg = CX88_MPEG_BLACKBIRD,
808 }, 822 },
809 [CX88_BOARD_KWORLD_VSTREAM_EXPERT_DVD] = { 823 [CX88_BOARD_KWORLD_VSTREAM_EXPERT_DVD] = {
810 /* Alexander Wold <awold@bigfoot.com> */ 824 /* Alexander Wold <awold@bigfoot.com> */
@@ -1050,7 +1064,6 @@ struct cx88_board cx88_boards[] = {
1050 .mpeg = CX88_MPEG_DVB, 1064 .mpeg = CX88_MPEG_DVB,
1051 }, 1065 },
1052 [CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT] = { 1066 [CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT] = {
1053 /* FIXME: Audio not working for s-video / composite inputs. */
1054 .name = "KWorld HardwareMpegTV XPert", 1067 .name = "KWorld HardwareMpegTV XPert",
1055 .tuner_type = TUNER_PHILIPS_TDA8290, 1068 .tuner_type = TUNER_PHILIPS_TDA8290,
1056 .radio_type = UNSET, 1069 .radio_type = UNSET,
@@ -1065,10 +1078,12 @@ struct cx88_board cx88_boards[] = {
1065 .type = CX88_VMUX_COMPOSITE1, 1078 .type = CX88_VMUX_COMPOSITE1,
1066 .vmux = 1, 1079 .vmux = 1,
1067 .gpio0 = 0x3de6, 1080 .gpio0 = 0x3de6,
1081 .extadc = 1,
1068 },{ 1082 },{
1069 .type = CX88_VMUX_SVIDEO, 1083 .type = CX88_VMUX_SVIDEO,
1070 .vmux = 2, 1084 .vmux = 2,
1071 .gpio0 = 0x3de6, 1085 .gpio0 = 0x3de6,
1086 .extadc = 1,
1072 }}, 1087 }},
1073 .radio = { 1088 .radio = {
1074 .type = CX88_RADIO, 1089 .type = CX88_RADIO,
@@ -1252,35 +1267,35 @@ struct cx88_board cx88_boards[] = {
1252 .gpio0 = 0x070b, 1267 .gpio0 = 0x070b,
1253 }}, 1268 }},
1254 }, 1269 },
1255 [CX88_BOARD_TE_DTV_250_OEM_SWANN] = { 1270 [CX88_BOARD_TE_DTV_250_OEM_SWANN] = {
1256 .name = "Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM", 1271 .name = "Shenzhen Tungsten Ages Tech TE-DTV-250 / Swann OEM",
1257 .tuner_type = TUNER_LG_PAL_NEW_TAPC, 1272 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1258 .radio_type = UNSET, 1273 .radio_type = UNSET,
1259 .tuner_addr = ADDR_UNSET, 1274 .tuner_addr = ADDR_UNSET,
1260 .radio_addr = ADDR_UNSET, 1275 .radio_addr = ADDR_UNSET,
1261 .input = {{ 1276 .input = {{
1262 .type = CX88_VMUX_TELEVISION, 1277 .type = CX88_VMUX_TELEVISION,
1263 .vmux = 0, 1278 .vmux = 0,
1264 .gpio0 = 0x003fffff, 1279 .gpio0 = 0x003fffff,
1265 .gpio1 = 0x00e00000, 1280 .gpio1 = 0x00e00000,
1266 .gpio2 = 0x003fffff, 1281 .gpio2 = 0x003fffff,
1267 .gpio3 = 0x02000000, 1282 .gpio3 = 0x02000000,
1268 },{ 1283 },{
1269 .type = CX88_VMUX_COMPOSITE1, 1284 .type = CX88_VMUX_COMPOSITE1,
1270 .vmux = 1, 1285 .vmux = 1,
1271 .gpio0 = 0x003fffff, 1286 .gpio0 = 0x003fffff,
1272 .gpio1 = 0x00e00000, 1287 .gpio1 = 0x00e00000,
1273 .gpio2 = 0x003fffff, 1288 .gpio2 = 0x003fffff,
1274 .gpio3 = 0x02000000, 1289 .gpio3 = 0x02000000,
1275 },{ 1290 },{
1276 .type = CX88_VMUX_SVIDEO, 1291 .type = CX88_VMUX_SVIDEO,
1277 .vmux = 2, 1292 .vmux = 2,
1278 .gpio0 = 0x003fffff, 1293 .gpio0 = 0x003fffff,
1279 .gpio1 = 0x00e00000, 1294 .gpio1 = 0x00e00000,
1280 .gpio2 = 0x003fffff, 1295 .gpio2 = 0x003fffff,
1281 .gpio3 = 0x02000000, 1296 .gpio3 = 0x02000000,
1282 }}, 1297 }},
1283 }, 1298 },
1284 [CX88_BOARD_HAUPPAUGE_HVR1300] = { 1299 [CX88_BOARD_HAUPPAUGE_HVR1300] = {
1285 .name = "Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder", 1300 .name = "Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder",
1286 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3, 1301 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
@@ -1293,17 +1308,20 @@ struct cx88_board cx88_boards[] = {
1293 .type = CX88_VMUX_TELEVISION, 1308 .type = CX88_VMUX_TELEVISION,
1294 .vmux = 0, 1309 .vmux = 0,
1295 .gpio0 = 0xe780, 1310 .gpio0 = 0xe780,
1311 .extadc = 1,
1296 },{ 1312 },{
1297 .type = CX88_VMUX_COMPOSITE1, 1313 .type = CX88_VMUX_COMPOSITE1,
1298 .vmux = 1, 1314 .vmux = 1,
1299 .gpio0 = 0xe780, 1315 .gpio0 = 0xe780,
1316 .extadc = 1,
1300 },{ 1317 },{
1301 .type = CX88_VMUX_SVIDEO, 1318 .type = CX88_VMUX_SVIDEO,
1302 .vmux = 2, 1319 .vmux = 2,
1303 .gpio0 = 0xe780, 1320 .gpio0 = 0xe780,
1321 .extadc = 1,
1304 }}, 1322 }},
1305 /* fixme: Add radio support */ 1323 /* fixme: Add radio support */
1306 .mpeg = CX88_MPEG_DVB, 1324 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD,
1307 }, 1325 },
1308}; 1326};
1309const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards); 1327const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
@@ -1513,6 +1531,10 @@ struct cx88_subid cx88_subids[] = {
1513 },{ 1531 },{
1514 .subvendor = 0x17de, 1532 .subvendor = 0x17de,
1515 .subdevice = 0x0840, 1533 .subdevice = 0x0840,
1534 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT,
1535 },{
1536 .subvendor = 0x1421,
1537 .subdevice = 0x0305,
1516 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT, 1538 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT,
1517 },{ 1539 },{
1518 .subvendor = 0x18ac, 1540 .subvendor = 0x18ac,
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 4b655f2ef278..453af5e943ff 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -1153,7 +1153,7 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
1153 mutex_lock(&devlist); 1153 mutex_lock(&devlist);
1154 cx88_ir_fini(core); 1154 cx88_ir_fini(core);
1155 if (0 == core->i2c_rc) 1155 if (0 == core->i2c_rc)
1156 i2c_bit_del_bus(&core->i2c_adap); 1156 i2c_del_adapter(&core->i2c_adap);
1157 list_del(&core->devlist); 1157 list_del(&core->devlist);
1158 iounmap(core->lmmio); 1158 iounmap(core->lmmio);
1159 cx88_devcount--; 1159 cx88_devcount--;
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 0ef13e7efa2e..8b203354fccd 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -42,7 +42,7 @@
42#include "cx22702.h" 42#include "cx22702.h"
43#include "or51132.h" 43#include "or51132.h"
44#include "lgdt330x.h" 44#include "lgdt330x.h"
45#include "lg_h06xf.h" 45#include "lgh06xf.h"
46#include "nxt200x.h" 46#include "nxt200x.h"
47#include "cx24123.h" 47#include "cx24123.h"
48#include "isl6421.h" 48#include "isl6421.h"
@@ -57,7 +57,7 @@ module_param(debug, int, 0644);
57MODULE_PARM_DESC(debug,"enable debug messages [dvb]"); 57MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
58 58
59#define dprintk(level,fmt, arg...) if (debug >= level) \ 59#define dprintk(level,fmt, arg...) if (debug >= level) \
60 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->core->name , ## arg) 60 printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
61 61
62/* ------------------------------------------------------------------ */ 62/* ------------------------------------------------------------------ */
63 63
@@ -74,8 +74,8 @@ static int dvb_buf_setup(struct videobuf_queue *q,
74 return 0; 74 return 0;
75} 75}
76 76
77static int dvb_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 77static int dvb_buf_prepare(struct videobuf_queue *q,
78 enum v4l2_field field) 78 struct videobuf_buffer *vb, enum v4l2_field field)
79{ 79{
80 struct cx8802_dev *dev = q->priv_data; 80 struct cx8802_dev *dev = q->priv_data;
81 return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field); 81 return cx8802_buf_prepare(q, dev, (struct cx88_buffer*)vb,field);
@@ -87,7 +87,8 @@ static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
87 cx8802_buf_queue(dev, (struct cx88_buffer*)vb); 87 cx8802_buf_queue(dev, (struct cx88_buffer*)vb);
88} 88}
89 89
90static void dvb_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 90static void dvb_buf_release(struct videobuf_queue *q,
91 struct videobuf_buffer *vb)
91{ 92{
92 cx88_free_buffer(q, (struct cx88_buffer*)vb); 93 cx88_free_buffer(q, (struct cx88_buffer*)vb);
93} 94}
@@ -100,6 +101,26 @@ static struct videobuf_queue_ops dvb_qops = {
100}; 101};
101 102
102/* ------------------------------------------------------------------ */ 103/* ------------------------------------------------------------------ */
104
105static int cx88_dvb_bus_ctrl(struct dvb_frontend* fe, int acquire)
106{
107 struct cx8802_dev *dev= fe->dvb->priv;
108 struct cx8802_driver *drv = NULL;
109 int ret = 0;
110
111 drv = cx8802_get_driver(dev, CX88_MPEG_DVB);
112 if (drv) {
113 if (acquire)
114 ret = drv->request_acquire(drv);
115 else
116 ret = drv->request_release(drv);
117 }
118
119 return ret;
120}
121
122/* ------------------------------------------------------------------ */
123
103static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe) 124static int dvico_fusionhdtv_demod_init(struct dvb_frontend* fe)
104{ 125{
105 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 }; 126 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x39 };
@@ -268,35 +289,6 @@ static struct mt352_config dntv_live_dvbt_pro_config = {
268}; 289};
269#endif 290#endif
270 291
271static int dvico_hybrid_tuner_set_params(struct dvb_frontend *fe,
272 struct dvb_frontend_parameters *params)
273{
274 u8 pllbuf[4];
275 struct cx8802_dev *dev= fe->dvb->priv;
276 struct i2c_msg msg =
277 { .addr = dev->core->pll_addr, .flags = 0,
278 .buf = pllbuf, .len = 4 };
279 int err;
280
281 dvb_pll_configure(dev->core->pll_desc, pllbuf,
282 params->frequency,
283 params->u.ofdm.bandwidth);
284
285 if (fe->ops.i2c_gate_ctrl)
286 fe->ops.i2c_gate_ctrl(fe, 1);
287 if ((err = i2c_transfer(&dev->core->i2c_adap, &msg, 1)) != 1) {
288 printk(KERN_WARNING "cx88-dvb: %s error "
289 "(addr %02x <- %02x, err = %i)\n",
290 __FUNCTION__, pllbuf[0], pllbuf[1], err);
291 if (err < 0)
292 return err;
293 else
294 return -EREMOTEIO;
295 }
296
297 return 0;
298}
299
300static struct zl10353_config dvico_fusionhdtv_hybrid = { 292static struct zl10353_config dvico_fusionhdtv_hybrid = {
301 .demod_address = 0x0f, 293 .demod_address = 0x0f,
302 .no_tuner = 1, 294 .no_tuner = 1,
@@ -311,28 +303,12 @@ static struct cx22702_config connexant_refboard_config = {
311 .output_mode = CX22702_SERIAL_OUTPUT, 303 .output_mode = CX22702_SERIAL_OUTPUT,
312}; 304};
313 305
314static struct cx22702_config hauppauge_novat_config = { 306static struct cx22702_config hauppauge_hvr_config = {
315 .demod_address = 0x43,
316 .output_mode = CX22702_SERIAL_OUTPUT,
317};
318
319static struct cx22702_config hauppauge_hvr1100_config = {
320 .demod_address = 0x63, 307 .demod_address = 0x63,
321 .output_mode = CX22702_SERIAL_OUTPUT, 308 .output_mode = CX22702_SERIAL_OUTPUT,
322}; 309};
323 310
324static struct cx22702_config hauppauge_hvr1300_config = { 311static int or51132_set_ts_param(struct dvb_frontend* fe, int is_punctured)
325 .demod_address = 0x63,
326 .output_mode = CX22702_SERIAL_OUTPUT,
327};
328
329static struct cx22702_config hauppauge_hvr3000_config = {
330 .demod_address = 0x63,
331 .output_mode = CX22702_SERIAL_OUTPUT,
332};
333
334static int or51132_set_ts_param(struct dvb_frontend* fe,
335 int is_punctured)
336{ 312{
337 struct cx8802_dev *dev= fe->dvb->priv; 313 struct cx8802_dev *dev= fe->dvb->priv;
338 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00; 314 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
@@ -344,50 +320,6 @@ static struct or51132_config pchdtv_hd3000 = {
344 .set_ts_params = or51132_set_ts_param, 320 .set_ts_params = or51132_set_ts_param,
345}; 321};
346 322
347static int lgdt3302_tuner_set_params(struct dvb_frontend* fe,
348 struct dvb_frontend_parameters* params)
349{
350 /* FIXME make this routine use the tuner-simple code.
351 * It could probably be shared with a number of ATSC
352 * frontends. Many share the same tuner with analog TV. */
353
354 struct cx8802_dev *dev= fe->dvb->priv;
355 struct cx88_core *core = dev->core;
356 u8 buf[4];
357 struct i2c_msg msg =
358 { .addr = dev->core->pll_addr, .flags = 0, .buf = buf, .len = 4 };
359 int err;
360
361 dvb_pll_configure(core->pll_desc, buf, params->frequency, 0);
362 dprintk(1, "%s: tuner at 0x%02x bytes: 0x%02x 0x%02x 0x%02x 0x%02x\n",
363 __FUNCTION__, msg.addr, buf[0],buf[1],buf[2],buf[3]);
364
365 if (fe->ops.i2c_gate_ctrl)
366 fe->ops.i2c_gate_ctrl(fe, 1);
367 if ((err = i2c_transfer(&core->i2c_adap, &msg, 1)) != 1) {
368 printk(KERN_WARNING "cx88-dvb: %s error "
369 "(addr %02x <- %02x, err = %i)\n",
370 __FUNCTION__, buf[0], buf[1], err);
371 if (err < 0)
372 return err;
373 else
374 return -EREMOTEIO;
375 }
376 return 0;
377}
378
379static int lgdt3303_tuner_set_params(struct dvb_frontend* fe,
380 struct dvb_frontend_parameters* params)
381{
382 struct cx8802_dev *dev= fe->dvb->priv;
383 struct cx88_core *core = dev->core;
384
385 /* Put the analog decoder in standby to keep it quiet */
386 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
387
388 return lg_h06xf_pll_set(fe, &core->i2c_adap, params);
389}
390
391static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index) 323static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
392{ 324{
393 struct cx8802_dev *dev= fe->dvb->priv; 325 struct cx8802_dev *dev= fe->dvb->priv;
@@ -432,8 +364,7 @@ static struct lgdt330x_config pchdtv_hd5500 = {
432 .set_ts_params = lgdt330x_set_ts_param, 364 .set_ts_params = lgdt330x_set_ts_param,
433}; 365};
434 366
435static int nxt200x_set_ts_param(struct dvb_frontend* fe, 367static int nxt200x_set_ts_param(struct dvb_frontend* fe, int is_punctured)
436 int is_punctured)
437{ 368{
438 struct cx8802_dev *dev= fe->dvb->priv; 369 struct cx8802_dev *dev= fe->dvb->priv;
439 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00; 370 dev->ts_gen_cntrl = is_punctured ? 0x04 : 0x00;
@@ -469,11 +400,10 @@ static int kworld_dvbs_100_set_voltage(struct dvb_frontend* fe,
469 struct cx8802_dev *dev= fe->dvb->priv; 400 struct cx8802_dev *dev= fe->dvb->priv;
470 struct cx88_core *core = dev->core; 401 struct cx88_core *core = dev->core;
471 402
472 if (voltage == SEC_VOLTAGE_OFF) { 403 if (voltage == SEC_VOLTAGE_OFF)
473 cx_write(MO_GP0_IO, 0x000006fb); 404 cx_write(MO_GP0_IO, 0x000006fb);
474 } else { 405 else
475 cx_write(MO_GP0_IO, 0x000006f9); 406 cx_write(MO_GP0_IO, 0x000006f9);
476 }
477 407
478 if (core->prev_set_voltage) 408 if (core->prev_set_voltage)
479 return core->prev_set_voltage(fe, voltage); 409 return core->prev_set_voltage(fe, voltage);
@@ -522,7 +452,7 @@ static int dvb_register(struct cx8802_dev *dev)
522 switch (dev->core->board) { 452 switch (dev->core->board) {
523 case CX88_BOARD_HAUPPAUGE_DVB_T1: 453 case CX88_BOARD_HAUPPAUGE_DVB_T1:
524 dev->dvb.frontend = dvb_attach(cx22702_attach, 454 dev->dvb.frontend = dvb_attach(cx22702_attach,
525 &hauppauge_novat_config, 455 &connexant_refboard_config,
526 &dev->core->i2c_adap); 456 &dev->core->i2c_adap);
527 if (dev->dvb.frontend != NULL) { 457 if (dev->dvb.frontend != NULL) {
528 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 458 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
@@ -547,32 +477,11 @@ static int dvb_register(struct cx8802_dev *dev)
547 case CX88_BOARD_HAUPPAUGE_HVR1100: 477 case CX88_BOARD_HAUPPAUGE_HVR1100:
548 case CX88_BOARD_HAUPPAUGE_HVR1100LP: 478 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
549 dev->dvb.frontend = dvb_attach(cx22702_attach, 479 dev->dvb.frontend = dvb_attach(cx22702_attach,
550 &hauppauge_hvr1100_config, 480 &hauppauge_hvr_config,
551 &dev->core->i2c_adap);
552 if (dev->dvb.frontend != NULL) {
553 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
554 &dev->core->i2c_adap,
555 &dvb_pll_fmd1216me);
556 }
557 break;
558 case CX88_BOARD_HAUPPAUGE_HVR1300:
559 dev->dvb.frontend = dvb_attach(cx22702_attach,
560 &hauppauge_hvr1300_config,
561 &dev->core->i2c_adap);
562 if (dev->dvb.frontend != NULL) {
563 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
564 &dev->core->i2c_adap,
565 &dvb_pll_fmd1216me);
566 }
567 break;
568 case CX88_BOARD_HAUPPAUGE_HVR3000:
569 dev->dvb.frontend = dvb_attach(cx22702_attach,
570 &hauppauge_hvr3000_config,
571 &dev->core->i2c_adap); 481 &dev->core->i2c_adap);
572 if (dev->dvb.frontend != NULL) { 482 if (dev->dvb.frontend != NULL) {
573 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 483 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
574 &dev->core->i2c_adap, 484 &dev->core->i2c_adap, &dvb_pll_fmd1216me);
575 &dvb_pll_fmd1216me);
576 } 485 }
577 break; 486 break;
578 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 487 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
@@ -647,18 +556,17 @@ static int dvb_register(struct cx8802_dev *dev)
647#endif 556#endif
648 break; 557 break;
649 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID: 558 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
650 dev->core->pll_addr = 0x61;
651 dev->core->pll_desc = &dvb_pll_thomson_fe6600;
652 dev->dvb.frontend = dvb_attach(zl10353_attach, 559 dev->dvb.frontend = dvb_attach(zl10353_attach,
653 &dvico_fusionhdtv_hybrid, 560 &dvico_fusionhdtv_hybrid,
654 &dev->core->i2c_adap); 561 &dev->core->i2c_adap);
655 if (dev->dvb.frontend != NULL) { 562 if (dev->dvb.frontend != NULL) {
656 dev->dvb.frontend->ops.tuner_ops.set_params = dvico_hybrid_tuner_set_params; 563 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
564 &dev->core->i2c_adap,
565 &dvb_pll_thomson_fe6600);
657 } 566 }
658 break; 567 break;
659 case CX88_BOARD_PCHDTV_HD3000: 568 case CX88_BOARD_PCHDTV_HD3000:
660 dev->dvb.frontend = dvb_attach(or51132_attach, 569 dev->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
661 &pchdtv_hd3000,
662 &dev->core->i2c_adap); 570 &dev->core->i2c_adap);
663 if (dev->dvb.frontend != NULL) { 571 if (dev->dvb.frontend != NULL) {
664 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 572 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
@@ -679,13 +587,13 @@ static int dvb_register(struct cx8802_dev *dev)
679 587
680 /* Select RF connector callback */ 588 /* Select RF connector callback */
681 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set; 589 fusionhdtv_3_gold.pll_rf_set = lgdt330x_pll_rf_set;
682 dev->core->pll_addr = 0x61;
683 dev->core->pll_desc = &dvb_pll_microtune_4042;
684 dev->dvb.frontend = dvb_attach(lgdt330x_attach, 590 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
685 &fusionhdtv_3_gold, 591 &fusionhdtv_3_gold,
686 &dev->core->i2c_adap); 592 &dev->core->i2c_adap);
687 if (dev->dvb.frontend != NULL) { 593 if (dev->dvb.frontend != NULL) {
688 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params; 594 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
595 &dev->core->i2c_adap,
596 &dvb_pll_microtune_4042);
689 } 597 }
690 } 598 }
691 break; 599 break;
@@ -699,13 +607,13 @@ static int dvb_register(struct cx8802_dev *dev)
699 mdelay(100); 607 mdelay(100);
700 cx_set(MO_GP0_IO, 9); 608 cx_set(MO_GP0_IO, 9);
701 mdelay(200); 609 mdelay(200);
702 dev->core->pll_addr = 0x61;
703 dev->core->pll_desc = &dvb_pll_thomson_dtt761x;
704 dev->dvb.frontend = dvb_attach(lgdt330x_attach, 610 dev->dvb.frontend = dvb_attach(lgdt330x_attach,
705 &fusionhdtv_3_gold, 611 &fusionhdtv_3_gold,
706 &dev->core->i2c_adap); 612 &dev->core->i2c_adap);
707 if (dev->dvb.frontend != NULL) { 613 if (dev->dvb.frontend != NULL) {
708 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3302_tuner_set_params; 614 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
615 &dev->core->i2c_adap,
616 &dvb_pll_thomson_dtt761x);
709 } 617 }
710 } 618 }
711 break; 619 break;
@@ -723,7 +631,8 @@ static int dvb_register(struct cx8802_dev *dev)
723 &fusionhdtv_5_gold, 631 &fusionhdtv_5_gold,
724 &dev->core->i2c_adap); 632 &dev->core->i2c_adap);
725 if (dev->dvb.frontend != NULL) { 633 if (dev->dvb.frontend != NULL) {
726 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 634 dvb_attach(lgh06xf_attach, dev->dvb.frontend,
635 &dev->core->i2c_adap);
727 } 636 }
728 } 637 }
729 break; 638 break;
@@ -741,7 +650,8 @@ static int dvb_register(struct cx8802_dev *dev)
741 &pchdtv_hd5500, 650 &pchdtv_hd5500,
742 &dev->core->i2c_adap); 651 &dev->core->i2c_adap);
743 if (dev->dvb.frontend != NULL) { 652 if (dev->dvb.frontend != NULL) {
744 dev->dvb.frontend->ops.tuner_ops.set_params = lgdt3303_tuner_set_params; 653 dvb_attach(lgh06xf_attach, dev->dvb.frontend,
654 &dev->core->i2c_adap);
745 } 655 }
746 } 656 }
747 break; 657 break;
@@ -782,6 +692,24 @@ static int dvb_register(struct cx8802_dev *dev)
782 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage; 692 dev->dvb.frontend->ops.set_voltage = geniatech_dvbs_set_voltage;
783 } 693 }
784 break; 694 break;
695 case CX88_BOARD_HAUPPAUGE_HVR1300:
696 dev->dvb.frontend = dvb_attach(cx22702_attach,
697 &hauppauge_hvr_config,
698 &dev->core->i2c_adap);
699 if (dev->dvb.frontend != NULL) {
700 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
701 &dev->core->i2c_adap, &dvb_pll_fmd1216me);
702 }
703 break;
704 case CX88_BOARD_HAUPPAUGE_HVR3000:
705 dev->dvb.frontend = dvb_attach(cx22702_attach,
706 &hauppauge_hvr_config,
707 &dev->core->i2c_adap);
708 if (dev->dvb.frontend != NULL) {
709 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
710 &dev->core->i2c_adap, &dvb_pll_fmd1216me);
711 }
712 break;
785 default: 713 default:
786 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 714 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
787 dev->core->name); 715 dev->core->name);
@@ -796,6 +724,8 @@ static int dvb_register(struct cx8802_dev *dev)
796 dev->dvb.frontend->ops.info.frequency_min = dev->core->pll_desc->min; 724 dev->dvb.frontend->ops.info.frequency_min = dev->core->pll_desc->min;
797 dev->dvb.frontend->ops.info.frequency_max = dev->core->pll_desc->max; 725 dev->dvb.frontend->ops.info.frequency_max = dev->core->pll_desc->max;
798 } 726 }
727 /* Ensure all frontends negotiate bus access */
728 dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
799 729
800 /* Put the analog decoder in standby to keep it quiet */ 730 /* Put the analog decoder in standby to keep it quiet */
801 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL); 731 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
@@ -806,37 +736,67 @@ static int dvb_register(struct cx8802_dev *dev)
806 736
807/* ----------------------------------------------------------- */ 737/* ----------------------------------------------------------- */
808 738
809static int __devinit dvb_probe(struct pci_dev *pci_dev, 739/* CX8802 MPEG -> mini driver - We have been given the hardware */
810 const struct pci_device_id *pci_id) 740static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
811{ 741{
812 struct cx8802_dev *dev; 742 struct cx88_core *core = drv->core;
813 struct cx88_core *core; 743 int err = 0;
744 dprintk( 1, "%s\n", __FUNCTION__);
745
746 switch (core->board) {
747 case CX88_BOARD_HAUPPAUGE_HVR1300:
748 /* We arrive here with either the cx23416 or the cx22702
749 * on the bus. Take the bus from the cx23416 and enable the
750 * cx22702 demod
751 */
752 cx_set(MO_GP0_IO, 0x00000080); /* cx22702 out of reset and enable */
753 cx_clear(MO_GP0_IO, 0x00000004);
754 udelay(1000);
755 break;
756 default:
757 err = -ENODEV;
758 }
759 return err;
760}
761
762/* CX8802 MPEG -> mini driver - We no longer have the hardware */
763static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
764{
765 struct cx88_core *core = drv->core;
766 int err = 0;
767 dprintk( 1, "%s\n", __FUNCTION__);
768
769 switch (core->board) {
770 case CX88_BOARD_HAUPPAUGE_HVR1300:
771 /* Do Nothing, leave the cx22702 on the bus. */
772 break;
773 default:
774 err = -ENODEV;
775 }
776 return err;
777}
778
779static int cx8802_dvb_probe(struct cx8802_driver *drv)
780{
781 struct cx88_core *core = drv->core;
782 struct cx8802_dev *dev = drv->core->dvbdev;
814 int err; 783 int err;
815 784
816 /* general setup */ 785 dprintk( 1, "%s\n", __FUNCTION__);
817 core = cx88_core_get(pci_dev); 786 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
818 if (NULL == core) 787 core->board,
819 return -EINVAL; 788 core->name,
789 core->pci_bus,
790 core->pci_slot);
820 791
821 err = -ENODEV; 792 err = -ENODEV;
822 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB)) 793 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB))
823 goto fail_core; 794 goto fail_core;
824 795
825 err = -ENOMEM;
826 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
827 if (NULL == dev)
828 goto fail_core;
829 dev->pci = pci_dev;
830 dev->core = core;
831
832 err = cx8802_init_common(dev);
833 if (0 != err)
834 goto fail_free;
835
836#ifdef HAVE_VP3054_I2C 796#ifdef HAVE_VP3054_I2C
837 err = vp3054_i2c_probe(dev); 797 err = vp3054_i2c_probe(dev);
838 if (0 != err) 798 if (0 != err)
839 goto fail_free; 799 goto fail_core;
840#endif 800#endif
841 801
842 /* dvb stuff */ 802 /* dvb stuff */
@@ -848,28 +808,16 @@ static int __devinit dvb_probe(struct pci_dev *pci_dev,
848 sizeof(struct cx88_buffer), 808 sizeof(struct cx88_buffer),
849 dev); 809 dev);
850 err = dvb_register(dev); 810 err = dvb_register(dev);
851 if (0 != err) 811 if (err != 0)
852 goto fail_fini; 812 printk("%s dvb_register failed err = %d\n", __FUNCTION__, err);
853 813
854 /* Maintain a reference to cx88-video can query the 8802 device. */
855 core->dvbdev = dev;
856 return 0;
857
858 fail_fini:
859 cx8802_fini_common(dev);
860 fail_free:
861 kfree(dev);
862 fail_core: 814 fail_core:
863 cx88_core_put(core,pci_dev);
864 return err; 815 return err;
865} 816}
866 817
867static void __devexit dvb_remove(struct pci_dev *pci_dev) 818static int cx8802_dvb_remove(struct cx8802_driver *drv)
868{ 819{
869 struct cx8802_dev *dev = pci_get_drvdata(pci_dev); 820 struct cx8802_dev *dev = drv->core->dvbdev;
870
871 /* Destroy any 8802 reference. */
872 dev->core->dvbdev = NULL;
873 821
874 /* dvb */ 822 /* dvb */
875 videobuf_dvb_unregister(&dev->dvb); 823 videobuf_dvb_unregister(&dev->dvb);
@@ -878,33 +826,16 @@ static void __devexit dvb_remove(struct pci_dev *pci_dev)
878 vp3054_i2c_remove(dev); 826 vp3054_i2c_remove(dev);
879#endif 827#endif
880 828
881 /* common */ 829 return 0;
882 cx8802_fini_common(dev);
883 cx88_core_put(dev->core,dev->pci);
884 kfree(dev);
885} 830}
886 831
887static struct pci_device_id cx8802_pci_tbl[] = { 832static struct cx8802_driver cx8802_dvb_driver = {
888 { 833 .type_id = CX88_MPEG_DVB,
889 .vendor = 0x14f1, 834 .hw_access = CX8802_DRVCTL_SHARED,
890 .device = 0x8802, 835 .probe = cx8802_dvb_probe,
891 .subvendor = PCI_ANY_ID, 836 .remove = cx8802_dvb_remove,
892 .subdevice = PCI_ANY_ID, 837 .advise_acquire = cx8802_dvb_advise_acquire,
893 },{ 838 .advise_release = cx8802_dvb_advise_release,
894 /* --- end of list --- */
895 }
896};
897MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
898
899static struct pci_driver dvb_pci_driver = {
900 .name = "cx88-dvb",
901 .id_table = cx8802_pci_tbl,
902 .probe = dvb_probe,
903 .remove = __devexit_p(dvb_remove),
904#ifdef CONFIG_PM
905 .suspend = cx8802_suspend_common,
906 .resume = cx8802_resume_common,
907#endif
908}; 839};
909 840
910static int dvb_init(void) 841static int dvb_init(void)
@@ -917,12 +848,12 @@ static int dvb_init(void)
917 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n", 848 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
918 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100); 849 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
919#endif 850#endif
920 return pci_register_driver(&dvb_pci_driver); 851 return cx8802_register_driver(&cx8802_dvb_driver);
921} 852}
922 853
923static void dvb_fini(void) 854static void dvb_fini(void)
924{ 855{
925 pci_unregister_driver(&dvb_pci_driver); 856 cx8802_unregister_driver(&cx8802_dvb_driver);
926} 857}
927 858
928module_init(dvb_init); 859module_init(dvb_init);
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index e60a0a52e4b2..8136673fe9e8 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -155,6 +155,35 @@ static void cx88_ir_work(struct work_struct *work)
155 mod_timer(&ir->timer, timeout); 155 mod_timer(&ir->timer, timeout);
156} 156}
157 157
158static void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
159{
160 if (ir->polling) {
161 INIT_WORK(&ir->work, cx88_ir_work);
162 init_timer(&ir->timer);
163 ir->timer.function = ir_timer;
164 ir->timer.data = (unsigned long)ir;
165 schedule_work(&ir->work);
166 }
167 if (ir->sampling) {
168 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
169 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
170 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
171 }
172}
173
174static void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
175{
176 if (ir->sampling) {
177 cx_write(MO_DDSCFG_IO, 0x0);
178 core->pci_irqmask &= ~(1 << 18);
179 }
180
181 if (ir->polling) {
182 del_timer_sync(&ir->timer);
183 flush_scheduled_work();
184 }
185}
186
158/* ---------------------------------------------------------------------- */ 187/* ---------------------------------------------------------------------- */
159 188
160int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) 189int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
@@ -163,14 +192,12 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
163 struct input_dev *input_dev; 192 struct input_dev *input_dev;
164 IR_KEYTAB_TYPE *ir_codes = NULL; 193 IR_KEYTAB_TYPE *ir_codes = NULL;
165 int ir_type = IR_TYPE_OTHER; 194 int ir_type = IR_TYPE_OTHER;
195 int err = -ENOMEM;
166 196
167 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 197 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
168 input_dev = input_allocate_device(); 198 input_dev = input_allocate_device();
169 if (!ir || !input_dev) { 199 if (!ir || !input_dev)
170 kfree(ir); 200 goto err_out_free;
171 input_free_device(input_dev);
172 return -ENOMEM;
173 }
174 201
175 ir->input = input_dev; 202 ir->input = input_dev;
176 203
@@ -280,9 +307,8 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
280 } 307 }
281 308
282 if (NULL == ir_codes) { 309 if (NULL == ir_codes) {
283 kfree(ir); 310 err = -ENODEV;
284 input_free_device(input_dev); 311 goto err_out_free;
285 return -ENODEV;
286 } 312 }
287 313
288 /* init input device */ 314 /* init input device */
@@ -307,23 +333,22 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
307 ir->core = core; 333 ir->core = core;
308 core->ir = ir; 334 core->ir = ir;
309 335
310 if (ir->polling) { 336 cx88_ir_start(core, ir);
311 INIT_WORK(&ir->work, cx88_ir_work);
312 init_timer(&ir->timer);
313 ir->timer.function = ir_timer;
314 ir->timer.data = (unsigned long)ir;
315 schedule_work(&ir->work);
316 }
317 if (ir->sampling) {
318 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
319 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
320 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
321 }
322 337
323 /* all done */ 338 /* all done */
324 input_register_device(ir->input); 339 err = input_register_device(ir->input);
340 if (err)
341 goto err_out_stop;
325 342
326 return 0; 343 return 0;
344
345 err_out_stop:
346 cx88_ir_stop(core, ir);
347 core->ir = NULL;
348 err_out_free:
349 input_free_device(input_dev);
350 kfree(ir);
351 return err;
327} 352}
328 353
329int cx88_ir_fini(struct cx88_core *core) 354int cx88_ir_fini(struct cx88_core *core)
@@ -334,15 +359,7 @@ int cx88_ir_fini(struct cx88_core *core)
334 if (NULL == ir) 359 if (NULL == ir)
335 return 0; 360 return 0;
336 361
337 if (ir->sampling) { 362 cx88_ir_stop(core, ir);
338 cx_write(MO_DDSCFG_IO, 0x0);
339 core->pci_irqmask &= ~(1 << 18);
340 }
341 if (ir->polling) {
342 del_timer(&ir->timer);
343 flush_scheduled_work();
344 }
345
346 input_unregister_device(ir->input); 363 input_unregister_device(ir->input);
347 kfree(ir); 364 kfree(ir);
348 365
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 6b23a4e6f66d..1fe1a833c7c7 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -44,8 +44,12 @@ module_param(debug,int,0644);
44MODULE_PARM_DESC(debug,"enable debug messages [mpeg]"); 44MODULE_PARM_DESC(debug,"enable debug messages [mpeg]");
45 45
46#define dprintk(level,fmt, arg...) if (debug >= level) \ 46#define dprintk(level,fmt, arg...) if (debug >= level) \
47 printk(KERN_DEBUG "%s/2: " fmt, dev->core->name , ## arg) 47 printk(KERN_DEBUG "%s/2-mpeg: " fmt, dev->core->name, ## arg)
48 48
49#define mpeg_dbg(level,fmt, arg...) if (debug >= level) \
50 printk(KERN_DEBUG "%s/2-mpeg: " fmt, core->name, ## arg)
51
52static LIST_HEAD(cx8802_devlist);
49/* ------------------------------------------------------------------ */ 53/* ------------------------------------------------------------------ */
50 54
51static int cx8802_start_dma(struct cx8802_dev *dev, 55static int cx8802_start_dma(struct cx8802_dev *dev,
@@ -65,17 +69,13 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
65 69
66 /* FIXME: this needs a review. 70 /* FIXME: this needs a review.
67 * also: move to cx88-blackbird + cx88-dvb source files? */ 71 * also: move to cx88-blackbird + cx88-dvb source files? */
68 if (cx88_boards[core->board].mpeg == (CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD) ) {
69 /* Report a warning until the mini driver patch is applied,
70 * else the following conditions will set the dma registers incorrectly.
71 * This will be removed in the next major patch and changes to the conditions
72 * will be made.
73 */
74 printk(KERN_INFO "%s() board->(CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD) is invalid\n", __FUNCTION__);
75 return -EINVAL;
76 }
77 72
78 if (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) { 73 dprintk( 1, "core->active_type_id = 0x%08x\n", core->active_type_id);
74
75 if ( (core->active_type_id == CX88_MPEG_DVB) &&
76 (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) ) {
77
78 dprintk( 1, "cx8802_start_dma doing .dvb\n");
79 /* negedge driven & software reset */ 79 /* negedge driven & software reset */
80 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl); 80 cx_write(TS_GEN_CNTRL, 0x0040 | dev->ts_gen_cntrl);
81 udelay(100); 81 udelay(100);
@@ -93,15 +93,17 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
93 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */ 93 cx_write(MO_PINMUX_IO, 0x88); /* Enable MPEG parallel IO and video signal pins */
94 udelay(100); 94 udelay(100);
95 break; 95 break;
96 case CX88_BOARD_HAUPPAUGE_HVR1300:
97 break;
96 default: 98 default:
97 cx_write(TS_SOP_STAT, 0x00); 99 cx_write(TS_SOP_STAT, 0x00);
98 break; 100 break;
99 } 101 }
100 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl); 102 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
101 udelay(100); 103 udelay(100);
102 } 104 } else if ( (core->active_type_id == CX88_MPEG_BLACKBIRD) &&
103 105 (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) ) {
104 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) { 106 dprintk( 1, "cx8802_start_dma doing .blackbird\n");
105 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */ 107 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
106 108
107 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */ 109 cx_write(TS_GEN_CNTRL, 0x46); /* punctured clock TS & posedge driven & software reset */
@@ -112,6 +114,10 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
112 114
113 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 115 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
114 udelay(100); 116 udelay(100);
117 } else {
118 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__,
119 cx88_boards[core->board].mpeg );
120 return -EINVAL;
115 } 121 }
116 122
117 /* reset counter */ 123 /* reset counter */
@@ -542,8 +548,315 @@ int cx8802_resume_common(struct pci_dev *pci_dev)
542 return 0; 548 return 0;
543} 549}
544 550
551struct cx8802_dev * cx8802_get_device(struct inode *inode)
552{
553 int minor = iminor(inode);
554 struct cx8802_dev *h = NULL;
555 struct list_head *list;
556
557 list_for_each(list,&cx8802_devlist) {
558 h = list_entry(list, struct cx8802_dev, devlist);
559 if (h->mpeg_dev->minor == minor)
560 return h;
561 }
562
563 return NULL;
564}
565
566struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype)
567{
568 struct cx8802_dev *h = NULL;
569 struct cx8802_driver *d = NULL;
570 struct list_head *list;
571 struct list_head *list2;
572
573 list_for_each(list,&cx8802_devlist) {
574 h = list_entry(list, struct cx8802_dev, devlist);
575 if (h != dev)
576 continue;
577
578 list_for_each(list2, &h->drvlist.devlist) {
579 d = list_entry(list2, struct cx8802_driver, devlist);
580
581 /* only unregister the correct driver type */
582 if (d->type_id == btype) {
583 return d;
584 }
585 }
586 }
587
588 return NULL;
589}
590
591/* Driver asked for hardware access. */
592int cx8802_request_acquire(struct cx8802_driver *drv)
593{
594 struct cx88_core *core = drv->core;
595
596 /* Fail a request for hardware if the device is busy. */
597 if (core->active_type_id != CX88_BOARD_NONE)
598 return -EBUSY;
599
600 if (drv->advise_acquire)
601 {
602 core->active_type_id = drv->type_id;
603 drv->advise_acquire(drv);
604
605 mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
606 }
607
608 return 0;
609}
610
611/* Driver asked to release hardware. */
612int cx8802_request_release(struct cx8802_driver *drv)
613{
614 struct cx88_core *core = drv->core;
615
616 if (drv->advise_release)
617 {
618 drv->advise_release(drv);
619 core->active_type_id = CX88_BOARD_NONE;
620 mpeg_dbg(1,"%s() Post release GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO));
621 }
622
623 return 0;
624}
625
626static int cx8802_check_driver(struct cx8802_driver *drv)
627{
628 if (drv == NULL)
629 return -ENODEV;
630
631 if ((drv->type_id != CX88_MPEG_DVB) &&
632 (drv->type_id != CX88_MPEG_BLACKBIRD))
633 return -EINVAL;
634
635 if ((drv->hw_access != CX8802_DRVCTL_SHARED) &&
636 (drv->hw_access != CX8802_DRVCTL_EXCLUSIVE))
637 return -EINVAL;
638
639 if ((drv->probe == NULL) ||
640 (drv->remove == NULL) ||
641 (drv->advise_acquire == NULL) ||
642 (drv->advise_release == NULL))
643 return -EINVAL;
644
645 return 0;
646}
647
648int cx8802_register_driver(struct cx8802_driver *drv)
649{
650 struct cx8802_dev *h;
651 struct cx8802_driver *driver;
652 struct list_head *list;
653 int err = 0, i = 0;
654
655 printk(KERN_INFO "%s() ->registering driver type=%s access=%s\n", __FUNCTION__ ,
656 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
657 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
658
659 if ((err = cx8802_check_driver(drv)) != 0) {
660 printk(KERN_INFO "%s() cx8802_driver is invalid\n", __FUNCTION__ );
661 return err;
662 }
663
664 list_for_each(list,&cx8802_devlist) {
665 h = list_entry(list, struct cx8802_dev, devlist);
666
667 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
668 h->core->name,h->pci->subsystem_vendor,
669 h->pci->subsystem_device,cx88_boards[h->core->board].name,
670 h->core->board);
671
672 /* Bring up a new struct for each driver instance */
673 driver = kzalloc(sizeof(*drv),GFP_KERNEL);
674 if (driver == NULL)
675 return -ENOMEM;
676
677 /* Snapshot of the driver registration data */
678 drv->core = h->core;
679 drv->suspend = cx8802_suspend_common;
680 drv->resume = cx8802_resume_common;
681 drv->request_acquire = cx8802_request_acquire;
682 drv->request_release = cx8802_request_release;
683 memcpy(driver, drv, sizeof(*driver));
684
685 err = drv->probe(driver);
686 if (err == 0) {
687 i++;
688 mutex_lock(&drv->core->lock);
689 list_add_tail(&driver->devlist,&h->drvlist.devlist);
690 mutex_unlock(&drv->core->lock);
691 } else {
692 printk(KERN_ERR "%s() ->probe failed err = %d\n", __FUNCTION__, err);
693 }
694
695 }
696 if (i == 0)
697 err = -ENODEV;
698 else
699 err = 0;
700
701 return err;
702}
703
704int cx8802_unregister_driver(struct cx8802_driver *drv)
705{
706 struct cx8802_dev *h;
707 struct cx8802_driver *d;
708 struct list_head *list;
709 struct list_head *list2, *q;
710 int err = 0, i = 0;
711
712 printk(KERN_INFO "%s() ->unregistering driver type=%s\n", __FUNCTION__ ,
713 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird");
714
715 list_for_each(list,&cx8802_devlist) {
716 i++;
717 h = list_entry(list, struct cx8802_dev, devlist);
718
719 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n",
720 h->core->name,h->pci->subsystem_vendor,
721 h->pci->subsystem_device,cx88_boards[h->core->board].name,
722 h->core->board);
723
724 list_for_each_safe(list2, q, &h->drvlist.devlist) {
725 d = list_entry(list2, struct cx8802_driver, devlist);
726
727 /* only unregister the correct driver type */
728 if (d->type_id != drv->type_id)
729 continue;
730
731 err = d->remove(d);
732 if (err == 0) {
733 mutex_lock(&drv->core->lock);
734 list_del(list2);
735 mutex_unlock(&drv->core->lock);
736 } else
737 printk(KERN_ERR "%s() ->remove failed err = %d\n", __FUNCTION__, err);
738
739 }
740
741 }
742
743 return err;
744}
745
545/* ----------------------------------------------------------- */ 746/* ----------------------------------------------------------- */
747static int __devinit cx8802_probe(struct pci_dev *pci_dev,
748 const struct pci_device_id *pci_id)
749{
750 struct cx8802_dev *dev;
751 struct cx88_core *core;
752 int err;
753
754 /* general setup */
755 core = cx88_core_get(pci_dev);
756 if (NULL == core)
757 return -EINVAL;
546 758
759 printk("%s/2: cx2388x 8802 Driver Manager\n", core->name);
760
761 err = -ENODEV;
762 if (!cx88_boards[core->board].mpeg)
763 goto fail_core;
764
765 err = -ENOMEM;
766 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
767 if (NULL == dev)
768 goto fail_core;
769 dev->pci = pci_dev;
770 dev->core = core;
771
772 err = cx8802_init_common(dev);
773 if (err != 0)
774 goto fail_free;
775
776 INIT_LIST_HEAD(&dev->drvlist.devlist);
777 list_add_tail(&dev->devlist,&cx8802_devlist);
778
779 /* Maintain a reference so cx88-video can query the 8802 device. */
780 core->dvbdev = dev;
781 return 0;
782
783 fail_free:
784 kfree(dev);
785 fail_core:
786 cx88_core_put(core,pci_dev);
787 return err;
788}
789
790static void __devexit cx8802_remove(struct pci_dev *pci_dev)
791{
792 struct cx8802_dev *dev;
793 struct cx8802_driver *h;
794 struct list_head *list;
795
796 dev = pci_get_drvdata(pci_dev);
797
798 dprintk( 1, "%s\n", __FUNCTION__);
799
800 list_for_each(list,&dev->drvlist.devlist) {
801 h = list_entry(list, struct cx8802_driver, devlist);
802 dprintk( 1, " ->driver\n");
803 if (h->remove == NULL) {
804 printk(KERN_ERR "%s .. skipping driver, no probe function\n", __FUNCTION__);
805 continue;
806 }
807 printk(KERN_INFO "%s .. Removing driver type %d\n", __FUNCTION__, h->type_id);
808 cx8802_unregister_driver(h);
809 list_del(&dev->drvlist.devlist);
810 }
811
812 /* Destroy any 8802 reference. */
813 dev->core->dvbdev = NULL;
814
815 /* common */
816 cx8802_fini_common(dev);
817 cx88_core_put(dev->core,dev->pci);
818 kfree(dev);
819}
820
821static struct pci_device_id cx8802_pci_tbl[] = {
822 {
823 .vendor = 0x14f1,
824 .device = 0x8802,
825 .subvendor = PCI_ANY_ID,
826 .subdevice = PCI_ANY_ID,
827 },{
828 /* --- end of list --- */
829 }
830};
831MODULE_DEVICE_TABLE(pci, cx8802_pci_tbl);
832
833static struct pci_driver cx8802_pci_driver = {
834 .name = "cx88-mpeg driver manager",
835 .id_table = cx8802_pci_tbl,
836 .probe = cx8802_probe,
837 .remove = __devexit_p(cx8802_remove),
838};
839
840static int cx8802_init(void)
841{
842 printk(KERN_INFO "cx2388x cx88-mpeg Driver Manager version %d.%d.%d loaded\n",
843 (CX88_VERSION_CODE >> 16) & 0xff,
844 (CX88_VERSION_CODE >> 8) & 0xff,
845 CX88_VERSION_CODE & 0xff);
846#ifdef SNAPSHOT
847 printk(KERN_INFO "cx2388x: snapshot date %04d-%02d-%02d\n",
848 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
849#endif
850 return pci_register_driver(&cx8802_pci_driver);
851}
852
853static void cx8802_fini(void)
854{
855 pci_unregister_driver(&cx8802_pci_driver);
856}
857
858module_init(cx8802_init);
859module_exit(cx8802_fini);
547EXPORT_SYMBOL(cx8802_buf_prepare); 860EXPORT_SYMBOL(cx8802_buf_prepare);
548EXPORT_SYMBOL(cx8802_buf_queue); 861EXPORT_SYMBOL(cx8802_buf_queue);
549EXPORT_SYMBOL(cx8802_cancel_buffers); 862EXPORT_SYMBOL(cx8802_cancel_buffers);
@@ -551,9 +864,10 @@ EXPORT_SYMBOL(cx8802_cancel_buffers);
551EXPORT_SYMBOL(cx8802_init_common); 864EXPORT_SYMBOL(cx8802_init_common);
552EXPORT_SYMBOL(cx8802_fini_common); 865EXPORT_SYMBOL(cx8802_fini_common);
553 866
554EXPORT_SYMBOL(cx8802_suspend_common); 867EXPORT_SYMBOL(cx8802_register_driver);
555EXPORT_SYMBOL(cx8802_resume_common); 868EXPORT_SYMBOL(cx8802_unregister_driver);
556 869EXPORT_SYMBOL(cx8802_get_device);
870EXPORT_SYMBOL(cx8802_get_driver);
557/* ----------------------------------------------------------- */ 871/* ----------------------------------------------------------- */
558/* 872/*
559 * Local variables: 873 * Local variables:
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 58ba9f773524..3482e0114d43 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -143,19 +143,6 @@ static void set_audio_finish(struct cx88_core *core, u32 ctl)
143 cx88_start_audio_dma(core); 143 cx88_start_audio_dma(core);
144 144
145 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) { 145 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) {
146 /* sets sound input from external adc */
147 switch (core->board) {
148 case CX88_BOARD_HAUPPAUGE_ROSLYN:
149 case CX88_BOARD_KWORLD_MCE200_DELUXE:
150 case CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT:
151 case CX88_BOARD_PIXELVIEW_PLAYTV_P7000:
152 case CX88_BOARD_ASUS_PVR_416:
153 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
154 break;
155 default:
156 cx_set(AUD_CTL, EN_I2SIN_ENABLE);
157 }
158
159 cx_write(AUD_I2SINPUTCNTL, 4); 146 cx_write(AUD_I2SINPUTCNTL, 4);
160 cx_write(AUD_BAUDRATE, 1); 147 cx_write(AUD_BAUDRATE, 1);
161 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */ 148 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 90e298d074d1..8613378428fd 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -454,6 +454,14 @@ static int video_mux(struct cx88_core *core, unsigned int input)
454 cx_clear(MO_FILTER_ODD, 0x00002020); 454 cx_clear(MO_FILTER_ODD, 0x00002020);
455 break; 455 break;
456 } 456 }
457
458 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) {
459 /* sets sound input from external adc */
460 if (INPUT(input)->extadc)
461 cx_set(AUD_CTL, EN_I2SIN_ENABLE);
462 else
463 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
464 }
457 return 0; 465 return 0;
458} 466}
459 467
@@ -1490,6 +1498,30 @@ int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
1490 mutex_unlock(&core->lock); 1498 mutex_unlock(&core->lock);
1491 return 0; 1499 return 0;
1492 } 1500 }
1501#ifdef CONFIG_VIDEO_ADV_DEBUG
1502 /* ioctls to allow direct acces to the cx2388x registers */
1503 case VIDIOC_INT_G_REGISTER:
1504 {
1505 struct v4l2_register *reg = arg;
1506
1507 if (reg->i2c_id != 0)
1508 return -EINVAL;
1509 /* cx2388x has a 24-bit register space */
1510 reg->val = cx_read(reg->reg&0xffffff);
1511 return 0;
1512 }
1513 case VIDIOC_INT_S_REGISTER:
1514 {
1515 struct v4l2_register *reg = arg;
1516
1517 if (reg->i2c_id != 0)
1518 return -EINVAL;
1519 if (!capable(CAP_SYS_ADMIN))
1520 return -EPERM;
1521 cx_write(reg->reg&0xffffff, reg->val);
1522 return 0;
1523 }
1524#endif
1493 1525
1494 default: 1526 default:
1495 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 1527 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index 2b4f1970c7df..6068c9bf82cd 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -168,7 +168,7 @@ void vp3054_i2c_remove(struct cx8802_dev *dev)
168 dev->core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) 168 dev->core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
169 return; 169 return;
170 170
171 i2c_bit_del_bus(&vp3054_i2c->adap); 171 i2c_del_adapter(&vp3054_i2c->adap);
172 kfree(vp3054_i2c); 172 kfree(vp3054_i2c);
173} 173}
174 174
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 3bc91aad4fe5..7054e941f1d7 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -74,6 +74,11 @@ enum cx88_board_type {
74 CX88_MPEG_BLACKBIRD 74 CX88_MPEG_BLACKBIRD
75}; 75};
76 76
77enum cx8802_board_access {
78 CX8802_DRVCTL_SHARED = 1,
79 CX8802_DRVCTL_EXCLUSIVE = 2,
80};
81
77/* ----------------------------------------------------------- */ 82/* ----------------------------------------------------------- */
78/* tv norms */ 83/* tv norms */
79 84
@@ -220,6 +225,7 @@ struct cx88_input {
220 enum cx88_itype type; 225 enum cx88_itype type;
221 unsigned int vmux; 226 unsigned int vmux;
222 u32 gpio0, gpio1, gpio2, gpio3; 227 u32 gpio0, gpio1, gpio2, gpio3;
228 unsigned int extadc:1;
223}; 229};
224 230
225struct cx88_board { 231struct cx88_board {
@@ -330,6 +336,7 @@ struct cx88_core {
330 336
331 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */ 337 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */
332 struct cx8802_dev *dvbdev; 338 struct cx8802_dev *dvbdev;
339 enum cx88_board_type active_type_id;
333}; 340};
334 341
335struct cx8800_dev; 342struct cx8800_dev;
@@ -405,6 +412,31 @@ struct cx8802_suspend_state {
405 int disabled; 412 int disabled;
406}; 413};
407 414
415struct cx8802_driver {
416 struct cx88_core *core;
417 struct list_head devlist;
418
419 /* Type of driver and access required */
420 enum cx88_board_type type_id;
421 enum cx8802_board_access hw_access;
422
423 /* MPEG 8802 internal only */
424 int (*suspend)(struct pci_dev *pci_dev, pm_message_t state);
425 int (*resume)(struct pci_dev *pci_dev);
426
427 /* MPEG 8802 -> mini driver - Driver probe and configuration */
428 int (*probe)(struct cx8802_driver *drv);
429 int (*remove)(struct cx8802_driver *drv);
430
431 /* MPEG 8802 -> mini driver - Access for hardware control */
432 int (*advise_acquire)(struct cx8802_driver *drv);
433 int (*advise_release)(struct cx8802_driver *drv);
434
435 /* MPEG 8802 <- mini driver - Access for hardware control */
436 int (*request_acquire)(struct cx8802_driver *drv);
437 int (*request_release)(struct cx8802_driver *drv);
438};
439
408struct cx8802_dev { 440struct cx8802_dev {
409 struct cx88_core *core; 441 struct cx88_core *core;
410 spinlock_t slock; 442 spinlock_t slock;
@@ -439,6 +471,9 @@ struct cx8802_dev {
439 471
440 /* mpeg params */ 472 /* mpeg params */
441 struct cx2341x_mpeg_params params; 473 struct cx2341x_mpeg_params params;
474
475 /* List of attached drivers */
476 struct cx8802_driver drvlist;
442}; 477};
443 478
444/* ----------------------------------------------------------- */ 479/* ----------------------------------------------------------- */
@@ -571,6 +606,11 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t);
571void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual); 606void cx88_set_stereo(struct cx88_core *core, u32 mode, int manual);
572int cx88_audio_thread(void *data); 607int cx88_audio_thread(void *data);
573 608
609int cx8802_register_driver(struct cx8802_driver *drv);
610int cx8802_unregister_driver(struct cx8802_driver *drv);
611struct cx8802_dev * cx8802_get_device(struct inode *inode);
612struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board_type btype);
613
574/* ----------------------------------------------------------- */ 614/* ----------------------------------------------------------- */
575/* cx88-input.c */ 615/* cx88-input.c */
576 616
@@ -600,6 +640,13 @@ extern int cx88_do_ioctl(struct inode *inode, struct file *file, int radio,
600extern const u32 cx88_user_ctrls[]; 640extern const u32 cx88_user_ctrls[];
601extern int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl); 641extern int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl);
602 642
643/* ----------------------------------------------------------- */
644/* cx88-blackbird.c */
645/* used by cx88-ivtv ioctl emulation layer */
646extern int (*cx88_ioctl_hook)(struct inode *inode, struct file *file,
647 unsigned int cmd, void *arg);
648extern unsigned int (*cx88_ioctl_translator)(unsigned int cmd);
649
603/* 650/*
604 * Local variables: 651 * Local variables:
605 * c-basic-offset: 8 652 * c-basic-offset: 8
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index ab87e7bfe84f..59edf58204de 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -305,15 +305,14 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
305 int ir_type; 305 int ir_type;
306 struct IR_i2c *ir; 306 struct IR_i2c *ir;
307 struct input_dev *input_dev; 307 struct input_dev *input_dev;
308 int err;
308 309
309 ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL); 310 ir = kzalloc(sizeof(struct IR_i2c),GFP_KERNEL);
310 input_dev = input_allocate_device(); 311 input_dev = input_allocate_device();
311 if (!ir || !input_dev) { 312 if (!ir || !input_dev) {
312 input_free_device(input_dev); 313 err = -ENOMEM;
313 kfree(ir); 314 goto err_out_free;
314 return -ENOMEM;
315 } 315 }
316 memset(ir,0,sizeof(*ir));
317 316
318 ir->c = client_template; 317 ir->c = client_template;
319 ir->input = input_dev; 318 ir->input = input_dev;
@@ -355,32 +354,34 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
355 break; 354 break;
356 case 0x7a: 355 case 0x7a:
357 case 0x47: 356 case 0x47:
357 case 0x71:
358 /* Handled by saa7134-input */ 358 /* Handled by saa7134-input */
359 name = "SAA713x remote"; 359 name = "SAA713x remote";
360 ir_type = IR_TYPE_OTHER; 360 ir_type = IR_TYPE_OTHER;
361 break; 361 break;
362 default: 362 default:
363 /* shouldn't happen */ 363 /* shouldn't happen */
364 printk(DEVNAME ": Huh? unknown i2c address (0x%02x)?\n",addr); 364 printk(DEVNAME ": Huh? unknown i2c address (0x%02x)?\n", addr);
365 kfree(ir); 365 err = -ENODEV;
366 return -1; 366 goto err_out_free;
367 } 367 }
368 368
369 /* Sets name */ 369 /* Sets name */
370 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (%s)", name); 370 snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (%s)", name);
371 ir->ir_codes=ir_codes; 371 ir->ir_codes = ir_codes;
372 372
373 /* register i2c device 373 /* register i2c device
374 * At device register, IR codes may be changed to be 374 * At device register, IR codes may be changed to be
375 * board dependent. 375 * board dependent.
376 */ 376 */
377 i2c_attach_client(&ir->c); 377 err = i2c_attach_client(&ir->c);
378 if (err)
379 goto err_out_free;
378 380
379 /* If IR not supported or disabled, unregisters driver */ 381 /* If IR not supported or disabled, unregisters driver */
380 if (ir->get_key == NULL) { 382 if (ir->get_key == NULL) {
381 i2c_detach_client(&ir->c); 383 err = -ENODEV;
382 kfree(ir); 384 goto err_out_detach;
383 return -1;
384 } 385 }
385 386
386 /* Phys addr can only be set after attaching (for ir->c.dev.bus_id) */ 387 /* Phys addr can only be set after attaching (for ir->c.dev.bus_id) */
@@ -389,15 +390,17 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
389 ir->c.dev.bus_id); 390 ir->c.dev.bus_id);
390 391
391 /* init + register input device */ 392 /* init + register input device */
392 ir_input_init(input_dev,&ir->ir,ir_type,ir->ir_codes); 393 ir_input_init(input_dev, &ir->ir, ir_type, ir->ir_codes);
393 input_dev->id.bustype = BUS_I2C; 394 input_dev->id.bustype = BUS_I2C;
394 input_dev->name = ir->c.name; 395 input_dev->name = ir->c.name;
395 input_dev->phys = ir->phys; 396 input_dev->phys = ir->phys;
396 397
397 /* register event device */ 398 err = input_register_device(ir->input);
398 input_register_device(ir->input); 399 if (err)
400 goto err_out_detach;
401
399 printk(DEVNAME ": %s detected at %s [%s]\n", 402 printk(DEVNAME ": %s detected at %s [%s]\n",
400 ir->input->name,ir->input->phys,adap->name); 403 ir->input->name, ir->input->phys, adap->name);
401 404
402 /* start polling via eventd */ 405 /* start polling via eventd */
403 INIT_WORK(&ir->work, ir_work); 406 INIT_WORK(&ir->work, ir_work);
@@ -407,6 +410,13 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
407 schedule_work(&ir->work); 410 schedule_work(&ir->work);
408 411
409 return 0; 412 return 0;
413
414 err_out_detach:
415 i2c_detach_client(&ir->c);
416 err_out_free:
417 input_free_device(input_dev);
418 kfree(ir);
419 return err;
410} 420}
411 421
412static int ir_detach(struct i2c_client *client) 422static int ir_detach(struct i2c_client *client)
@@ -414,7 +424,7 @@ static int ir_detach(struct i2c_client *client)
414 struct IR_i2c *ir = i2c_get_clientdata(client); 424 struct IR_i2c *ir = i2c_get_clientdata(client);
415 425
416 /* kill outstanding polls */ 426 /* kill outstanding polls */
417 del_timer(&ir->timer); 427 del_timer_sync(&ir->timer);
418 flush_scheduled_work(); 428 flush_scheduled_work();
419 429
420 /* unregister devices */ 430 /* unregister devices */
@@ -439,7 +449,7 @@ static int ir_probe(struct i2c_adapter *adap)
439 */ 449 */
440 450
441 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1}; 451 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1};
442 static const int probe_saa7134[] = { 0x7a, 0x47, -1 }; 452 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, -1 };
443 static const int probe_em28XX[] = { 0x30, 0x47, -1 }; 453 static const int probe_em28XX[] = { 0x30, 0x47, -1 };
444 const int *probe = NULL; 454 const int *probe = NULL;
445 struct i2c_client c; 455 struct i2c_client c;
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index b0aea4002d11..152cc6b3e152 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -160,10 +160,6 @@ static int mxb_probe(struct saa7146_dev* dev)
160 printk("mxb: saa7111 i2c module not available.\n"); 160 printk("mxb: saa7111 i2c module not available.\n");
161 return -ENODEV; 161 return -ENODEV;
162 } 162 }
163 if ((result = request_module("tuner")) < 0) {
164 printk("mxb: tuner i2c module not available.\n");
165 return -ENODEV;
166 }
167 if ((result = request_module("tea6420")) < 0) { 163 if ((result = request_module("tea6420")) < 0) {
168 printk("mxb: tea6420 i2c module not available.\n"); 164 printk("mxb: tea6420 i2c module not available.\n");
169 return -ENODEV; 165 return -ENODEV;
@@ -176,6 +172,10 @@ static int mxb_probe(struct saa7146_dev* dev)
176 printk("mxb: tda9840 i2c module not available.\n"); 172 printk("mxb: tda9840 i2c module not available.\n");
177 return -ENODEV; 173 return -ENODEV;
178 } 174 }
175 if ((result = request_module("tuner")) < 0) {
176 printk("mxb: tuner i2c module not available.\n");
177 return -ENODEV;
178 }
179 179
180 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL); 180 mxb = kzalloc(sizeof(struct mxb), GFP_KERNEL);
181 if( NULL == mxb ) { 181 if( NULL == mxb ) {
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
new file mode 100644
index 000000000000..89dd18c3c5cc
--- /dev/null
+++ b/drivers/media/video/ov7670.c
@@ -0,0 +1,1333 @@
1/*
2 * A V4L2 driver for OmniVision OV7670 cameras.
3 *
4 * Copyright 2006 One Laptop Per Child Association, Inc. Written
5 * by Jonathan Corbet with substantial inspiration from Mark
6 * McClelland's ovcamchip code.
7 *
8 * This file may be distributed under the terms of the GNU General
9 * Public License, version 2.
10 */
11#include <linux/init.h>
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/slab.h>
15#include <linux/delay.h>
16#include <linux/videodev.h>
17#include <media/v4l2-common.h>
18#include <linux/i2c.h>
19
20
21MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net.");
22MODULE_DESCRIPTION("A low-level driver for OmniVision ov7670 sensors");
23MODULE_LICENSE("GPL");
24
25/*
26 * Basic window sizes. These probably belong somewhere more globally
27 * useful.
28 */
29#define VGA_WIDTH 640
30#define VGA_HEIGHT 480
31#define QVGA_WIDTH 320
32#define QVGA_HEIGHT 240
33#define CIF_WIDTH 352
34#define CIF_HEIGHT 288
35#define QCIF_WIDTH 176
36#define QCIF_HEIGHT 144
37
38/*
39 * Our nominal (default) frame rate.
40 */
41#define OV7670_FRAME_RATE 30
42
43/*
44 * The 7670 sits on i2c with ID 0x42
45 */
46#define OV7670_I2C_ADDR 0x42
47
48/* Registers */
49#define REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
50#define REG_BLUE 0x01 /* blue gain */
51#define REG_RED 0x02 /* red gain */
52#define REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
53#define REG_COM1 0x04 /* Control 1 */
54#define COM1_CCIR656 0x40 /* CCIR656 enable */
55#define REG_BAVE 0x05 /* U/B Average level */
56#define REG_GbAVE 0x06 /* Y/Gb Average level */
57#define REG_AECHH 0x07 /* AEC MS 5 bits */
58#define REG_RAVE 0x08 /* V/R Average level */
59#define REG_COM2 0x09 /* Control 2 */
60#define COM2_SSLEEP 0x10 /* Soft sleep mode */
61#define REG_PID 0x0a /* Product ID MSB */
62#define REG_VER 0x0b /* Product ID LSB */
63#define REG_COM3 0x0c /* Control 3 */
64#define COM3_SWAP 0x40 /* Byte swap */
65#define COM3_SCALEEN 0x08 /* Enable scaling */
66#define COM3_DCWEN 0x04 /* Enable downsamp/crop/window */
67#define REG_COM4 0x0d /* Control 4 */
68#define REG_COM5 0x0e /* All "reserved" */
69#define REG_COM6 0x0f /* Control 6 */
70#define REG_AECH 0x10 /* More bits of AEC value */
71#define REG_CLKRC 0x11 /* Clocl control */
72#define CLK_EXT 0x40 /* Use external clock directly */
73#define CLK_SCALE 0x3f /* Mask for internal clock scale */
74#define REG_COM7 0x12 /* Control 7 */
75#define COM7_RESET 0x80 /* Register reset */
76#define COM7_FMT_MASK 0x38
77#define COM7_FMT_VGA 0x00
78#define COM7_FMT_CIF 0x20 /* CIF format */
79#define COM7_FMT_QVGA 0x10 /* QVGA format */
80#define COM7_FMT_QCIF 0x08 /* QCIF format */
81#define COM7_RGB 0x04 /* bits 0 and 2 - RGB format */
82#define COM7_YUV 0x00 /* YUV */
83#define COM7_BAYER 0x01 /* Bayer format */
84#define COM7_PBAYER 0x05 /* "Processed bayer" */
85#define REG_COM8 0x13 /* Control 8 */
86#define COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
87#define COM8_AECSTEP 0x40 /* Unlimited AEC step size */
88#define COM8_BFILT 0x20 /* Band filter enable */
89#define COM8_AGC 0x04 /* Auto gain enable */
90#define COM8_AWB 0x02 /* White balance enable */
91#define COM8_AEC 0x01 /* Auto exposure enable */
92#define REG_COM9 0x14 /* Control 9 - gain ceiling */
93#define REG_COM10 0x15 /* Control 10 */
94#define COM10_HSYNC 0x40 /* HSYNC instead of HREF */
95#define COM10_PCLK_HB 0x20 /* Suppress PCLK on horiz blank */
96#define COM10_HREF_REV 0x08 /* Reverse HREF */
97#define COM10_VS_LEAD 0x04 /* VSYNC on clock leading edge */
98#define COM10_VS_NEG 0x02 /* VSYNC negative */
99#define COM10_HS_NEG 0x01 /* HSYNC negative */
100#define REG_HSTART 0x17 /* Horiz start high bits */
101#define REG_HSTOP 0x18 /* Horiz stop high bits */
102#define REG_VSTART 0x19 /* Vert start high bits */
103#define REG_VSTOP 0x1a /* Vert stop high bits */
104#define REG_PSHFT 0x1b /* Pixel delay after HREF */
105#define REG_MIDH 0x1c /* Manuf. ID high */
106#define REG_MIDL 0x1d /* Manuf. ID low */
107#define REG_MVFP 0x1e /* Mirror / vflip */
108#define MVFP_MIRROR 0x20 /* Mirror image */
109#define MVFP_FLIP 0x10 /* Vertical flip */
110
111#define REG_AEW 0x24 /* AGC upper limit */
112#define REG_AEB 0x25 /* AGC lower limit */
113#define REG_VPT 0x26 /* AGC/AEC fast mode op region */
114#define REG_HSYST 0x30 /* HSYNC rising edge delay */
115#define REG_HSYEN 0x31 /* HSYNC falling edge delay */
116#define REG_HREF 0x32 /* HREF pieces */
117#define REG_TSLB 0x3a /* lots of stuff */
118#define TSLB_YLAST 0x04 /* UYVY or VYUY - see com13 */
119#define REG_COM11 0x3b /* Control 11 */
120#define COM11_NIGHT 0x80 /* NIght mode enable */
121#define COM11_NMFR 0x60 /* Two bit NM frame rate */
122#define COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
123#define COM11_50HZ 0x08 /* Manual 50Hz select */
124#define COM11_EXP 0x02
125#define REG_COM12 0x3c /* Control 12 */
126#define COM12_HREF 0x80 /* HREF always */
127#define REG_COM13 0x3d /* Control 13 */
128#define COM13_GAMMA 0x80 /* Gamma enable */
129#define COM13_UVSAT 0x40 /* UV saturation auto adjustment */
130#define COM13_UVSWAP 0x01 /* V before U - w/TSLB */
131#define REG_COM14 0x3e /* Control 14 */
132#define COM14_DCWEN 0x10 /* DCW/PCLK-scale enable */
133#define REG_EDGE 0x3f /* Edge enhancement factor */
134#define REG_COM15 0x40 /* Control 15 */
135#define COM15_R10F0 0x00 /* Data range 10 to F0 */
136#define COM15_R01FE 0x80 /* 01 to FE */
137#define COM15_R00FF 0xc0 /* 00 to FF */
138#define COM15_RGB565 0x10 /* RGB565 output */
139#define COM15_RGB555 0x30 /* RGB555 output */
140#define REG_COM16 0x41 /* Control 16 */
141#define COM16_AWBGAIN 0x08 /* AWB gain enable */
142#define REG_COM17 0x42 /* Control 17 */
143#define COM17_AECWIN 0xc0 /* AEC window - must match COM4 */
144#define COM17_CBAR 0x08 /* DSP Color bar */
145
146/*
147 * This matrix defines how the colors are generated, must be
148 * tweaked to adjust hue and saturation.
149 *
150 * Order: v-red, v-green, v-blue, u-red, u-green, u-blue
151 *
152 * They are nine-bit signed quantities, with the sign bit
153 * stored in 0x58. Sign for v-red is bit 0, and up from there.
154 */
155#define REG_CMATRIX_BASE 0x4f
156#define CMATRIX_LEN 6
157#define REG_CMATRIX_SIGN 0x58
158
159
160#define REG_BRIGHT 0x55 /* Brightness */
161#define REG_CONTRAS 0x56 /* Contrast control */
162
163#define REG_GFIX 0x69 /* Fix gain control */
164
165#define REG_RGB444 0x8c /* RGB 444 control */
166#define R444_ENABLE 0x02 /* Turn on RGB444, overrides 5x5 */
167#define R444_RGBX 0x01 /* Empty nibble at end */
168
169#define REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
170#define REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
171
172#define REG_BD50MAX 0xa5 /* 50hz banding step limit */
173#define REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
174#define REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
175#define REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
176#define REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
177#define REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
178#define REG_BD60MAX 0xab /* 60hz banding step limit */
179
180
181/*
182 * Information we maintain about a known sensor.
183 */
184struct ov7670_format_struct; /* coming later */
185struct ov7670_info {
186 struct ov7670_format_struct *fmt; /* Current format */
187 unsigned char sat; /* Saturation value */
188 int hue; /* Hue value */
189};
190
191
192
193
194/*
195 * The default register settings, as obtained from OmniVision. There
196 * is really no making sense of most of these - lots of "reserved" values
197 * and such.
198 *
199 * These settings give VGA YUYV.
200 */
201
202struct regval_list {
203 unsigned char reg_num;
204 unsigned char value;
205};
206
207static struct regval_list ov7670_default_regs[] = {
208 { REG_COM7, COM7_RESET },
209/*
210 * Clock scale: 3 = 15fps
211 * 2 = 20fps
212 * 1 = 30fps
213 */
214 { REG_CLKRC, 0x1 }, /* OV: clock scale (30 fps) */
215 { REG_TSLB, 0x04 }, /* OV */
216 { REG_COM7, 0 }, /* VGA */
217 /*
218 * Set the hardware window. These values from OV don't entirely
219 * make sense - hstop is less than hstart. But they work...
220 */
221 { REG_HSTART, 0x13 }, { REG_HSTOP, 0x01 },
222 { REG_HREF, 0xb6 }, { REG_VSTART, 0x02 },
223 { REG_VSTOP, 0x7a }, { REG_VREF, 0x0a },
224
225 { REG_COM3, 0 }, { REG_COM14, 0 },
226 /* Mystery scaling numbers */
227 { 0x70, 0x3a }, { 0x71, 0x35 },
228 { 0x72, 0x11 }, { 0x73, 0xf0 },
229 { 0xa2, 0x02 }, { REG_COM10, 0x0 },
230
231 /* Gamma curve values */
232 { 0x7a, 0x20 }, { 0x7b, 0x10 },
233 { 0x7c, 0x1e }, { 0x7d, 0x35 },
234 { 0x7e, 0x5a }, { 0x7f, 0x69 },
235 { 0x80, 0x76 }, { 0x81, 0x80 },
236 { 0x82, 0x88 }, { 0x83, 0x8f },
237 { 0x84, 0x96 }, { 0x85, 0xa3 },
238 { 0x86, 0xaf }, { 0x87, 0xc4 },
239 { 0x88, 0xd7 }, { 0x89, 0xe8 },
240
241 /* AGC and AEC parameters. Note we start by disabling those features,
242 then turn them only after tweaking the values. */
243 { REG_COM8, COM8_FASTAEC | COM8_AECSTEP | COM8_BFILT },
244 { REG_GAIN, 0 }, { REG_AECH, 0 },
245 { REG_COM4, 0x40 }, /* magic reserved bit */
246 { REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
247 { REG_BD50MAX, 0x05 }, { REG_BD60MAX, 0x07 },
248 { REG_AEW, 0x95 }, { REG_AEB, 0x33 },
249 { REG_VPT, 0xe3 }, { REG_HAECC1, 0x78 },
250 { REG_HAECC2, 0x68 }, { 0xa1, 0x03 }, /* magic */
251 { REG_HAECC3, 0xd8 }, { REG_HAECC4, 0xd8 },
252 { REG_HAECC5, 0xf0 }, { REG_HAECC6, 0x90 },
253 { REG_HAECC7, 0x94 },
254 { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC },
255
256 /* Almost all of these are magic "reserved" values. */
257 { REG_COM5, 0x61 }, { REG_COM6, 0x4b },
258 { 0x16, 0x02 }, { REG_MVFP, 0x07|MVFP_MIRROR },
259 { 0x21, 0x02 }, { 0x22, 0x91 },
260 { 0x29, 0x07 }, { 0x33, 0x0b },
261 { 0x35, 0x0b }, { 0x37, 0x1d },
262 { 0x38, 0x71 }, { 0x39, 0x2a },
263 { REG_COM12, 0x78 }, { 0x4d, 0x40 },
264 { 0x4e, 0x20 }, { REG_GFIX, 0 },
265 { 0x6b, 0x4a }, { 0x74, 0x10 },
266 { 0x8d, 0x4f }, { 0x8e, 0 },
267 { 0x8f, 0 }, { 0x90, 0 },
268 { 0x91, 0 }, { 0x96, 0 },
269 { 0x9a, 0 }, { 0xb0, 0x84 },
270 { 0xb1, 0x0c }, { 0xb2, 0x0e },
271 { 0xb3, 0x82 }, { 0xb8, 0x0a },
272
273 /* More reserved magic, some of which tweaks white balance */
274 { 0x43, 0x0a }, { 0x44, 0xf0 },
275 { 0x45, 0x34 }, { 0x46, 0x58 },
276 { 0x47, 0x28 }, { 0x48, 0x3a },
277 { 0x59, 0x88 }, { 0x5a, 0x88 },
278 { 0x5b, 0x44 }, { 0x5c, 0x67 },
279 { 0x5d, 0x49 }, { 0x5e, 0x0e },
280 { 0x6c, 0x0a }, { 0x6d, 0x55 },
281 { 0x6e, 0x11 }, { 0x6f, 0x9f }, /* "9e for advance AWB" */
282 { 0x6a, 0x40 }, { REG_BLUE, 0x40 },
283 { REG_RED, 0x60 },
284 { REG_COM8, COM8_FASTAEC|COM8_AECSTEP|COM8_BFILT|COM8_AGC|COM8_AEC|COM8_AWB },
285
286 /* Matrix coefficients */
287 { 0x4f, 0x80 }, { 0x50, 0x80 },
288 { 0x51, 0 }, { 0x52, 0x22 },
289 { 0x53, 0x5e }, { 0x54, 0x80 },
290 { 0x58, 0x9e },
291
292 { REG_COM16, COM16_AWBGAIN }, { REG_EDGE, 0 },
293 { 0x75, 0x05 }, { 0x76, 0xe1 },
294 { 0x4c, 0 }, { 0x77, 0x01 },
295 { REG_COM13, 0xc3 }, { 0x4b, 0x09 },
296 { 0xc9, 0x60 }, { REG_COM16, 0x38 },
297 { 0x56, 0x40 },
298
299 { 0x34, 0x11 }, { REG_COM11, COM11_EXP|COM11_HZAUTO },
300 { 0xa4, 0x88 }, { 0x96, 0 },
301 { 0x97, 0x30 }, { 0x98, 0x20 },
302 { 0x99, 0x30 }, { 0x9a, 0x84 },
303 { 0x9b, 0x29 }, { 0x9c, 0x03 },
304 { 0x9d, 0x4c }, { 0x9e, 0x3f },
305 { 0x78, 0x04 },
306
307 /* Extra-weird stuff. Some sort of multiplexor register */
308 { 0x79, 0x01 }, { 0xc8, 0xf0 },
309 { 0x79, 0x0f }, { 0xc8, 0x00 },
310 { 0x79, 0x10 }, { 0xc8, 0x7e },
311 { 0x79, 0x0a }, { 0xc8, 0x80 },
312 { 0x79, 0x0b }, { 0xc8, 0x01 },
313 { 0x79, 0x0c }, { 0xc8, 0x0f },
314 { 0x79, 0x0d }, { 0xc8, 0x20 },
315 { 0x79, 0x09 }, { 0xc8, 0x80 },
316 { 0x79, 0x02 }, { 0xc8, 0xc0 },
317 { 0x79, 0x03 }, { 0xc8, 0x40 },
318 { 0x79, 0x05 }, { 0xc8, 0x30 },
319 { 0x79, 0x26 },
320
321 { 0xff, 0xff }, /* END MARKER */
322};
323
324
325/*
326 * Here we'll try to encapsulate the changes for just the output
327 * video format.
328 *
329 * RGB656 and YUV422 come from OV; RGB444 is homebrewed.
330 *
331 * IMPORTANT RULE: the first entry must be for COM7, see ov7670_s_fmt for why.
332 */
333
334
335static struct regval_list ov7670_fmt_yuv422[] = {
336 { REG_COM7, 0x0 }, /* Selects YUV mode */
337 { REG_RGB444, 0 }, /* No RGB444 please */
338 { REG_COM1, 0 },
339 { REG_COM15, COM15_R00FF },
340 { REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */
341 { 0x4f, 0x80 }, /* "matrix coefficient 1" */
342 { 0x50, 0x80 }, /* "matrix coefficient 2" */
343 { 0x51, 0 }, /* vb */
344 { 0x52, 0x22 }, /* "matrix coefficient 4" */
345 { 0x53, 0x5e }, /* "matrix coefficient 5" */
346 { 0x54, 0x80 }, /* "matrix coefficient 6" */
347 { REG_COM13, COM13_GAMMA|COM13_UVSAT },
348 { 0xff, 0xff },
349};
350
351static struct regval_list ov7670_fmt_rgb565[] = {
352 { REG_COM7, COM7_RGB }, /* Selects RGB mode */
353 { REG_RGB444, 0 }, /* No RGB444 please */
354 { REG_COM1, 0x0 },
355 { REG_COM15, COM15_RGB565 },
356 { REG_COM9, 0x38 }, /* 16x gain ceiling; 0x8 is reserved bit */
357 { 0x4f, 0xb3 }, /* "matrix coefficient 1" */
358 { 0x50, 0xb3 }, /* "matrix coefficient 2" */
359 { 0x51, 0 }, /* vb */
360 { 0x52, 0x3d }, /* "matrix coefficient 4" */
361 { 0x53, 0xa7 }, /* "matrix coefficient 5" */
362 { 0x54, 0xe4 }, /* "matrix coefficient 6" */
363 { REG_COM13, COM13_GAMMA|COM13_UVSAT },
364 { 0xff, 0xff },
365};
366
367static struct regval_list ov7670_fmt_rgb444[] = {
368 { REG_COM7, COM7_RGB }, /* Selects RGB mode */
369 { REG_RGB444, R444_ENABLE }, /* Enable xxxxrrrr ggggbbbb */
370 { REG_COM1, 0x40 }, /* Magic reserved bit */
371 { REG_COM15, COM15_R01FE|COM15_RGB565 }, /* Data range needed? */
372 { REG_COM9, 0x38 }, /* 16x gain ceiling; 0x8 is reserved bit */
373 { 0x4f, 0xb3 }, /* "matrix coefficient 1" */
374 { 0x50, 0xb3 }, /* "matrix coefficient 2" */
375 { 0x51, 0 }, /* vb */
376 { 0x52, 0x3d }, /* "matrix coefficient 4" */
377 { 0x53, 0xa7 }, /* "matrix coefficient 5" */
378 { 0x54, 0xe4 }, /* "matrix coefficient 6" */
379 { REG_COM13, COM13_GAMMA|COM13_UVSAT|0x2 }, /* Magic rsvd bit */
380 { 0xff, 0xff },
381};
382
383
384
385
386/*
387 * Low-level register I/O.
388 */
389
390static int ov7670_read(struct i2c_client *c, unsigned char reg,
391 unsigned char *value)
392{
393 int ret;
394
395 ret = i2c_smbus_read_byte_data(c, reg);
396 if (ret >= 0)
397 *value = (unsigned char) ret;
398 return ret;
399}
400
401
402static int ov7670_write(struct i2c_client *c, unsigned char reg,
403 unsigned char value)
404{
405 return i2c_smbus_write_byte_data(c, reg, value);
406}
407
408
409/*
410 * Write a list of register settings; ff/ff stops the process.
411 */
412static int ov7670_write_array(struct i2c_client *c, struct regval_list *vals)
413{
414 while (vals->reg_num != 0xff || vals->value != 0xff) {
415 int ret = ov7670_write(c, vals->reg_num, vals->value);
416 if (ret < 0)
417 return ret;
418 vals++;
419 }
420 return 0;
421}
422
423
424/*
425 * Stuff that knows about the sensor.
426 */
427static void ov7670_reset(struct i2c_client *client)
428{
429 ov7670_write(client, REG_COM7, COM7_RESET);
430 msleep(1);
431}
432
433
434static int ov7670_init(struct i2c_client *client)
435{
436 return ov7670_write_array(client, ov7670_default_regs);
437}
438
439
440
441static int ov7670_detect(struct i2c_client *client)
442{
443 unsigned char v;
444 int ret;
445
446 ret = ov7670_init(client);
447 if (ret < 0)
448 return ret;
449 ret = ov7670_read(client, REG_MIDH, &v);
450 if (ret < 0)
451 return ret;
452 if (v != 0x7f) /* OV manuf. id. */
453 return -ENODEV;
454 ret = ov7670_read(client, REG_MIDL, &v);
455 if (ret < 0)
456 return ret;
457 if (v != 0xa2)
458 return -ENODEV;
459 /*
460 * OK, we know we have an OmniVision chip...but which one?
461 */
462 ret = ov7670_read(client, REG_PID, &v);
463 if (ret < 0)
464 return ret;
465 if (v != 0x76) /* PID + VER = 0x76 / 0x73 */
466 return -ENODEV;
467 ret = ov7670_read(client, REG_VER, &v);
468 if (ret < 0)
469 return ret;
470 if (v != 0x73) /* PID + VER = 0x76 / 0x73 */
471 return -ENODEV;
472 return 0;
473}
474
475
476/*
477 * Store information about the video data format. The color matrix
478 * is deeply tied into the format, so keep the relevant values here.
479 * The magic matrix nubmers come from OmniVision.
480 */
481static struct ov7670_format_struct {
482 __u8 *desc;
483 __u32 pixelformat;
484 struct regval_list *regs;
485 int cmatrix[CMATRIX_LEN];
486} ov7670_formats[] = {
487 {
488 .desc = "YUYV 4:2:2",
489 .pixelformat = V4L2_PIX_FMT_YUYV,
490 .regs = ov7670_fmt_yuv422,
491 .cmatrix = { 128, -128, 0, -34, -94, 128 },
492 },
493 {
494 .desc = "RGB 444",
495 .pixelformat = V4L2_PIX_FMT_RGB444,
496 .regs = ov7670_fmt_rgb444,
497 .cmatrix = { 179, -179, 0, -61, -176, 228 },
498 },
499 {
500 .desc = "RGB 565",
501 .pixelformat = V4L2_PIX_FMT_RGB565,
502 .regs = ov7670_fmt_rgb565,
503 .cmatrix = { 179, -179, 0, -61, -176, 228 },
504 },
505};
506#define N_OV7670_FMTS (sizeof(ov7670_formats)/sizeof(ov7670_formats[0]))
507
508/*
509 * All formats we support are 2 bytes/pixel.
510 */
511#define BYTES_PER_PIXEL 2
512
513/*
514 * Then there is the issue of window sizes. Try to capture the info here.
515 */
516
517/*
518 * QCIF mode is done (by OV) in a very strange way - it actually looks like
519 * VGA with weird scaling options - they do *not* use the canned QCIF mode
520 * which is allegedly provided by the sensor. So here's the weird register
521 * settings.
522 */
523static struct regval_list ov7670_qcif_regs[] = {
524 { REG_COM3, COM3_SCALEEN|COM3_DCWEN },
525 { REG_COM3, COM3_DCWEN },
526 { REG_COM14, COM14_DCWEN | 0x01},
527 { 0x73, 0xf1 },
528 { 0xa2, 0x52 },
529 { 0x7b, 0x1c },
530 { 0x7c, 0x28 },
531 { 0x7d, 0x3c },
532 { 0x7f, 0x69 },
533 { REG_COM9, 0x38 },
534 { 0xa1, 0x0b },
535 { 0x74, 0x19 },
536 { 0x9a, 0x80 },
537 { 0x43, 0x14 },
538 { REG_COM13, 0xc0 },
539 { 0xff, 0xff },
540};
541
542static struct ov7670_win_size {
543 int width;
544 int height;
545 unsigned char com7_bit;
546 int hstart; /* Start/stop values for the camera. Note */
547 int hstop; /* that they do not always make complete */
548 int vstart; /* sense to humans, but evidently the sensor */
549 int vstop; /* will do the right thing... */
550 struct regval_list *regs; /* Regs to tweak */
551/* h/vref stuff */
552} ov7670_win_sizes[] = {
553 /* VGA */
554 {
555 .width = VGA_WIDTH,
556 .height = VGA_HEIGHT,
557 .com7_bit = COM7_FMT_VGA,
558 .hstart = 158, /* These values from */
559 .hstop = 14, /* Omnivision */
560 .vstart = 10,
561 .vstop = 490,
562 .regs = NULL,
563 },
564 /* CIF */
565 {
566 .width = CIF_WIDTH,
567 .height = CIF_HEIGHT,
568 .com7_bit = COM7_FMT_CIF,
569 .hstart = 170, /* Empirically determined */
570 .hstop = 90,
571 .vstart = 14,
572 .vstop = 494,
573 .regs = NULL,
574 },
575 /* QVGA */
576 {
577 .width = QVGA_WIDTH,
578 .height = QVGA_HEIGHT,
579 .com7_bit = COM7_FMT_QVGA,
580 .hstart = 164, /* Empirically determined */
581 .hstop = 20,
582 .vstart = 14,
583 .vstop = 494,
584 .regs = NULL,
585 },
586 /* QCIF */
587 {
588 .width = QCIF_WIDTH,
589 .height = QCIF_HEIGHT,
590 .com7_bit = COM7_FMT_VGA, /* see comment above */
591 .hstart = 456, /* Empirically determined */
592 .hstop = 24,
593 .vstart = 14,
594 .vstop = 494,
595 .regs = ov7670_qcif_regs,
596 },
597};
598
599#define N_WIN_SIZES (sizeof(ov7670_win_sizes)/sizeof(ov7670_win_sizes[0]))
600
601
602/*
603 * Store a set of start/stop values into the camera.
604 */
605static int ov7670_set_hw(struct i2c_client *client, int hstart, int hstop,
606 int vstart, int vstop)
607{
608 int ret;
609 unsigned char v;
610/*
611 * Horizontal: 11 bits, top 8 live in hstart and hstop. Bottom 3 of
612 * hstart are in href[2:0], bottom 3 of hstop in href[5:3]. There is
613 * a mystery "edge offset" value in the top two bits of href.
614 */
615 ret = ov7670_write(client, REG_HSTART, (hstart >> 3) & 0xff);
616 ret += ov7670_write(client, REG_HSTOP, (hstop >> 3) & 0xff);
617 ret += ov7670_read(client, REG_HREF, &v);
618 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7);
619 msleep(10);
620 ret += ov7670_write(client, REG_HREF, v);
621/*
622 * Vertical: similar arrangement, but only 10 bits.
623 */
624 ret += ov7670_write(client, REG_VSTART, (vstart >> 2) & 0xff);
625 ret += ov7670_write(client, REG_VSTOP, (vstop >> 2) & 0xff);
626 ret += ov7670_read(client, REG_VREF, &v);
627 v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3);
628 msleep(10);
629 ret += ov7670_write(client, REG_VREF, v);
630 return ret;
631}
632
633
634static int ov7670_enum_fmt(struct i2c_client *c, struct v4l2_fmtdesc *fmt)
635{
636 struct ov7670_format_struct *ofmt;
637
638 if (fmt->index >= N_OV7670_FMTS)
639 return -EINVAL;
640
641 ofmt = ov7670_formats + fmt->index;
642 fmt->flags = 0;
643 strcpy(fmt->description, ofmt->desc);
644 fmt->pixelformat = ofmt->pixelformat;
645 return 0;
646}
647
648
649static int ov7670_try_fmt(struct i2c_client *c, struct v4l2_format *fmt,
650 struct ov7670_format_struct **ret_fmt,
651 struct ov7670_win_size **ret_wsize)
652{
653 int index;
654 struct ov7670_win_size *wsize;
655 struct v4l2_pix_format *pix = &fmt->fmt.pix;
656
657 for (index = 0; index < N_OV7670_FMTS; index++)
658 if (ov7670_formats[index].pixelformat == pix->pixelformat)
659 break;
660 if (index >= N_OV7670_FMTS)
661 return -EINVAL;
662 if (ret_fmt != NULL)
663 *ret_fmt = ov7670_formats + index;
664 /*
665 * Fields: the OV devices claim to be progressive.
666 */
667 if (pix->field == V4L2_FIELD_ANY)
668 pix->field = V4L2_FIELD_NONE;
669 else if (pix->field != V4L2_FIELD_NONE)
670 return -EINVAL;
671 /*
672 * Round requested image size down to the nearest
673 * we support, but not below the smallest.
674 */
675 for (wsize = ov7670_win_sizes; wsize < ov7670_win_sizes + N_WIN_SIZES;
676 wsize++)
677 if (pix->width >= wsize->width && pix->height >= wsize->height)
678 break;
679 if (wsize >= ov7670_win_sizes + N_WIN_SIZES)
680 wsize--; /* Take the smallest one */
681 if (ret_wsize != NULL)
682 *ret_wsize = wsize;
683 /*
684 * Note the size we'll actually handle.
685 */
686 pix->width = wsize->width;
687 pix->height = wsize->height;
688 pix->bytesperline = pix->width*BYTES_PER_PIXEL;
689 pix->sizeimage = pix->height*pix->bytesperline;
690 return 0;
691}
692
693/*
694 * Set a format.
695 */
696static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
697{
698 int ret;
699 struct ov7670_format_struct *ovfmt;
700 struct ov7670_win_size *wsize;
701 struct ov7670_info *info = i2c_get_clientdata(c);
702 unsigned char com7;
703
704 ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize);
705 if (ret)
706 return ret;
707 /*
708 * COM7 is a pain in the ass, it doesn't like to be read then
709 * quickly written afterward. But we have everything we need
710 * to set it absolutely here, as long as the format-specific
711 * register sets list it first.
712 */
713 com7 = ovfmt->regs[0].value;
714 com7 |= wsize->com7_bit;
715 ov7670_write(c, REG_COM7, com7);
716 /*
717 * Now write the rest of the array. Also store start/stops
718 */
719 ov7670_write_array(c, ovfmt->regs + 1);
720 ov7670_set_hw(c, wsize->hstart, wsize->hstop, wsize->vstart,
721 wsize->vstop);
722 ret = 0;
723 if (wsize->regs)
724 ret = ov7670_write_array(c, wsize->regs);
725 info->fmt = ovfmt;
726 return 0;
727}
728
729/*
730 * Implement G/S_PARM. There is a "high quality" mode we could try
731 * to do someday; for now, we just do the frame rate tweak.
732 */
733static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
734{
735 struct v4l2_captureparm *cp = &parms->parm.capture;
736 unsigned char clkrc;
737 int ret;
738
739 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
740 return -EINVAL;
741 ret = ov7670_read(c, REG_CLKRC, &clkrc);
742 if (ret < 0)
743 return ret;
744 memset(cp, 0, sizeof(struct v4l2_captureparm));
745 cp->capability = V4L2_CAP_TIMEPERFRAME;
746 cp->timeperframe.numerator = 1;
747 cp->timeperframe.denominator = OV7670_FRAME_RATE;
748 if ((clkrc & CLK_EXT) == 0 && (clkrc & CLK_SCALE) > 1)
749 cp->timeperframe.denominator /= (clkrc & CLK_SCALE);
750 return 0;
751}
752
753static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms)
754{
755 struct v4l2_captureparm *cp = &parms->parm.capture;
756 struct v4l2_fract *tpf = &cp->timeperframe;
757 unsigned char clkrc;
758 int ret, div;
759
760 if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
761 return -EINVAL;
762 if (cp->extendedmode != 0)
763 return -EINVAL;
764 /*
765 * CLKRC has a reserved bit, so let's preserve it.
766 */
767 ret = ov7670_read(c, REG_CLKRC, &clkrc);
768 if (ret < 0)
769 return ret;
770 if (tpf->numerator == 0 || tpf->denominator == 0)
771 div = 1; /* Reset to full rate */
772 else
773 div = (tpf->numerator*OV7670_FRAME_RATE)/tpf->denominator;
774 if (div == 0)
775 div = 1;
776 else if (div > CLK_SCALE)
777 div = CLK_SCALE;
778 clkrc = (clkrc & 0x80) | div;
779 tpf->numerator = 1;
780 tpf->denominator = OV7670_FRAME_RATE/div;
781 return ov7670_write(c, REG_CLKRC, clkrc);
782}
783
784
785
786/*
787 * Code for dealing with controls.
788 */
789
790
791
792
793
794static int ov7670_store_cmatrix(struct i2c_client *client,
795 int matrix[CMATRIX_LEN])
796{
797 int i, ret;
798 unsigned char signbits;
799
800 /*
801 * Weird crap seems to exist in the upper part of
802 * the sign bits register, so let's preserve it.
803 */
804 ret = ov7670_read(client, REG_CMATRIX_SIGN, &signbits);
805 signbits &= 0xc0;
806
807 for (i = 0; i < CMATRIX_LEN; i++) {
808 unsigned char raw;
809
810 if (matrix[i] < 0) {
811 signbits |= (1 << i);
812 if (matrix[i] < -255)
813 raw = 0xff;
814 else
815 raw = (-1 * matrix[i]) & 0xff;
816 }
817 else {
818 if (matrix[i] > 255)
819 raw = 0xff;
820 else
821 raw = matrix[i] & 0xff;
822 }
823 ret += ov7670_write(client, REG_CMATRIX_BASE + i, raw);
824 }
825 ret += ov7670_write(client, REG_CMATRIX_SIGN, signbits);
826 return ret;
827}
828
829
830/*
831 * Hue also requires messing with the color matrix. It also requires
832 * trig functions, which tend not to be well supported in the kernel.
833 * So here is a simple table of sine values, 0-90 degrees, in steps
834 * of five degrees. Values are multiplied by 1000.
835 *
836 * The following naive approximate trig functions require an argument
837 * carefully limited to -180 <= theta <= 180.
838 */
839#define SIN_STEP 5
840static const int ov7670_sin_table[] = {
841 0, 87, 173, 258, 342, 422,
842 499, 573, 642, 707, 766, 819,
843 866, 906, 939, 965, 984, 996,
844 1000
845};
846
847static int ov7670_sine(int theta)
848{
849 int chs = 1;
850 int sine;
851
852 if (theta < 0) {
853 theta = -theta;
854 chs = -1;
855 }
856 if (theta <= 90)
857 sine = ov7670_sin_table[theta/SIN_STEP];
858 else {
859 theta -= 90;
860 sine = 1000 - ov7670_sin_table[theta/SIN_STEP];
861 }
862 return sine*chs;
863}
864
865static int ov7670_cosine(int theta)
866{
867 theta = 90 - theta;
868 if (theta > 180)
869 theta -= 360;
870 else if (theta < -180)
871 theta += 360;
872 return ov7670_sine(theta);
873}
874
875
876
877
878static void ov7670_calc_cmatrix(struct ov7670_info *info,
879 int matrix[CMATRIX_LEN])
880{
881 int i;
882 /*
883 * Apply the current saturation setting first.
884 */
885 for (i = 0; i < CMATRIX_LEN; i++)
886 matrix[i] = (info->fmt->cmatrix[i]*info->sat) >> 7;
887 /*
888 * Then, if need be, rotate the hue value.
889 */
890 if (info->hue != 0) {
891 int sinth, costh, tmpmatrix[CMATRIX_LEN];
892
893 memcpy(tmpmatrix, matrix, CMATRIX_LEN*sizeof(int));
894 sinth = ov7670_sine(info->hue);
895 costh = ov7670_cosine(info->hue);
896
897 matrix[0] = (matrix[3]*sinth + matrix[0]*costh)/1000;
898 matrix[1] = (matrix[4]*sinth + matrix[1]*costh)/1000;
899 matrix[2] = (matrix[5]*sinth + matrix[2]*costh)/1000;
900 matrix[3] = (matrix[3]*costh - matrix[0]*sinth)/1000;
901 matrix[4] = (matrix[4]*costh - matrix[1]*sinth)/1000;
902 matrix[5] = (matrix[5]*costh - matrix[2]*sinth)/1000;
903 }
904}
905
906
907
908static int ov7670_t_sat(struct i2c_client *client, int value)
909{
910 struct ov7670_info *info = i2c_get_clientdata(client);
911 int matrix[CMATRIX_LEN];
912 int ret;
913
914 info->sat = value;
915 ov7670_calc_cmatrix(info, matrix);
916 ret = ov7670_store_cmatrix(client, matrix);
917 return ret;
918}
919
920static int ov7670_q_sat(struct i2c_client *client, __s32 *value)
921{
922 struct ov7670_info *info = i2c_get_clientdata(client);
923
924 *value = info->sat;
925 return 0;
926}
927
928static int ov7670_t_hue(struct i2c_client *client, int value)
929{
930 struct ov7670_info *info = i2c_get_clientdata(client);
931 int matrix[CMATRIX_LEN];
932 int ret;
933
934 if (value < -180 || value > 180)
935 return -EINVAL;
936 info->hue = value;
937 ov7670_calc_cmatrix(info, matrix);
938 ret = ov7670_store_cmatrix(client, matrix);
939 return ret;
940}
941
942
943static int ov7670_q_hue(struct i2c_client *client, __s32 *value)
944{
945 struct ov7670_info *info = i2c_get_clientdata(client);
946
947 *value = info->hue;
948 return 0;
949}
950
951
952/*
953 * Some weird registers seem to store values in a sign/magnitude format!
954 */
955static unsigned char ov7670_sm_to_abs(unsigned char v)
956{
957 if ((v & 0x80) == 0)
958 return v + 128;
959 else
960 return 128 - (v & 0x7f);
961}
962
963
964static unsigned char ov7670_abs_to_sm(unsigned char v)
965{
966 if (v > 127)
967 return v & 0x7f;
968 else
969 return (128 - v) | 0x80;
970}
971
972static int ov7670_t_brightness(struct i2c_client *client, int value)
973{
974 unsigned char com8, v;
975 int ret;
976
977 ov7670_read(client, REG_COM8, &com8);
978 com8 &= ~COM8_AEC;
979 ov7670_write(client, REG_COM8, com8);
980 v = ov7670_abs_to_sm(value);
981 ret = ov7670_write(client, REG_BRIGHT, v);
982 return ret;
983}
984
985static int ov7670_q_brightness(struct i2c_client *client, __s32 *value)
986{
987 unsigned char v;
988 int ret = ov7670_read(client, REG_BRIGHT, &v);
989
990 *value = ov7670_sm_to_abs(v);
991 return ret;
992}
993
994static int ov7670_t_contrast(struct i2c_client *client, int value)
995{
996 return ov7670_write(client, REG_CONTRAS, (unsigned char) value);
997}
998
999static int ov7670_q_contrast(struct i2c_client *client, __s32 *value)
1000{
1001 unsigned char v;
1002 int ret = ov7670_read(client, REG_CONTRAS, &v);
1003
1004 *value = v;
1005 return ret;
1006}
1007
1008static int ov7670_q_hflip(struct i2c_client *client, __s32 *value)
1009{
1010 int ret;
1011 unsigned char v;
1012
1013 ret = ov7670_read(client, REG_MVFP, &v);
1014 *value = (v & MVFP_MIRROR) == MVFP_MIRROR;
1015 return ret;
1016}
1017
1018
1019static int ov7670_t_hflip(struct i2c_client *client, int value)
1020{
1021 unsigned char v;
1022 int ret;
1023
1024 ret = ov7670_read(client, REG_MVFP, &v);
1025 if (value)
1026 v |= MVFP_MIRROR;
1027 else
1028 v &= ~MVFP_MIRROR;
1029 msleep(10); /* FIXME */
1030 ret += ov7670_write(client, REG_MVFP, v);
1031 return ret;
1032}
1033
1034
1035
1036static int ov7670_q_vflip(struct i2c_client *client, __s32 *value)
1037{
1038 int ret;
1039 unsigned char v;
1040
1041 ret = ov7670_read(client, REG_MVFP, &v);
1042 *value = (v & MVFP_FLIP) == MVFP_FLIP;
1043 return ret;
1044}
1045
1046
1047static int ov7670_t_vflip(struct i2c_client *client, int value)
1048{
1049 unsigned char v;
1050 int ret;
1051
1052 ret = ov7670_read(client, REG_MVFP, &v);
1053 if (value)
1054 v |= MVFP_FLIP;
1055 else
1056 v &= ~MVFP_FLIP;
1057 msleep(10); /* FIXME */
1058 ret += ov7670_write(client, REG_MVFP, v);
1059 return ret;
1060}
1061
1062
1063static struct ov7670_control {
1064 struct v4l2_queryctrl qc;
1065 int (*query)(struct i2c_client *c, __s32 *value);
1066 int (*tweak)(struct i2c_client *c, int value);
1067} ov7670_controls[] =
1068{
1069 {
1070 .qc = {
1071 .id = V4L2_CID_BRIGHTNESS,
1072 .type = V4L2_CTRL_TYPE_INTEGER,
1073 .name = "Brightness",
1074 .minimum = 0,
1075 .maximum = 255,
1076 .step = 1,
1077 .default_value = 0x80,
1078 .flags = V4L2_CTRL_FLAG_SLIDER
1079 },
1080 .tweak = ov7670_t_brightness,
1081 .query = ov7670_q_brightness,
1082 },
1083 {
1084 .qc = {
1085 .id = V4L2_CID_CONTRAST,
1086 .type = V4L2_CTRL_TYPE_INTEGER,
1087 .name = "Contrast",
1088 .minimum = 0,
1089 .maximum = 127,
1090 .step = 1,
1091 .default_value = 0x40, /* XXX ov7670 spec */
1092 .flags = V4L2_CTRL_FLAG_SLIDER
1093 },
1094 .tweak = ov7670_t_contrast,
1095 .query = ov7670_q_contrast,
1096 },
1097 {
1098 .qc = {
1099 .id = V4L2_CID_SATURATION,
1100 .type = V4L2_CTRL_TYPE_INTEGER,
1101 .name = "Saturation",
1102 .minimum = 0,
1103 .maximum = 256,
1104 .step = 1,
1105 .default_value = 0x80,
1106 .flags = V4L2_CTRL_FLAG_SLIDER
1107 },
1108 .tweak = ov7670_t_sat,
1109 .query = ov7670_q_sat,
1110 },
1111 {
1112 .qc = {
1113 .id = V4L2_CID_HUE,
1114 .type = V4L2_CTRL_TYPE_INTEGER,
1115 .name = "HUE",
1116 .minimum = -180,
1117 .maximum = 180,
1118 .step = 5,
1119 .default_value = 0,
1120 .flags = V4L2_CTRL_FLAG_SLIDER
1121 },
1122 .tweak = ov7670_t_hue,
1123 .query = ov7670_q_hue,
1124 },
1125 {
1126 .qc = {
1127 .id = V4L2_CID_VFLIP,
1128 .type = V4L2_CTRL_TYPE_BOOLEAN,
1129 .name = "Vertical flip",
1130 .minimum = 0,
1131 .maximum = 1,
1132 .step = 1,
1133 .default_value = 0,
1134 },
1135 .tweak = ov7670_t_vflip,
1136 .query = ov7670_q_vflip,
1137 },
1138 {
1139 .qc = {
1140 .id = V4L2_CID_HFLIP,
1141 .type = V4L2_CTRL_TYPE_BOOLEAN,
1142 .name = "Horizontal mirror",
1143 .minimum = 0,
1144 .maximum = 1,
1145 .step = 1,
1146 .default_value = 0,
1147 },
1148 .tweak = ov7670_t_hflip,
1149 .query = ov7670_q_hflip,
1150 },
1151};
1152#define N_CONTROLS (sizeof(ov7670_controls)/sizeof(ov7670_controls[0]))
1153
1154static struct ov7670_control *ov7670_find_control(__u32 id)
1155{
1156 int i;
1157
1158 for (i = 0; i < N_CONTROLS; i++)
1159 if (ov7670_controls[i].qc.id == id)
1160 return ov7670_controls + i;
1161 return NULL;
1162}
1163
1164
1165static int ov7670_queryctrl(struct i2c_client *client,
1166 struct v4l2_queryctrl *qc)
1167{
1168 struct ov7670_control *ctrl = ov7670_find_control(qc->id);
1169
1170 if (ctrl == NULL)
1171 return -EINVAL;
1172 *qc = ctrl->qc;
1173 return 0;
1174}
1175
1176static int ov7670_g_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
1177{
1178 struct ov7670_control *octrl = ov7670_find_control(ctrl->id);
1179 int ret;
1180
1181 if (octrl == NULL)
1182 return -EINVAL;
1183 ret = octrl->query(client, &ctrl->value);
1184 if (ret >= 0)
1185 return 0;
1186 return ret;
1187}
1188
1189static int ov7670_s_ctrl(struct i2c_client *client, struct v4l2_control *ctrl)
1190{
1191 struct ov7670_control *octrl = ov7670_find_control(ctrl->id);
1192 int ret;
1193
1194 if (octrl == NULL)
1195 return -EINVAL;
1196 ret = octrl->tweak(client, ctrl->value);
1197 if (ret >= 0)
1198 return 0;
1199 return ret;
1200}
1201
1202
1203
1204
1205
1206
1207/*
1208 * Basic i2c stuff.
1209 */
1210static struct i2c_driver ov7670_driver;
1211
1212static int ov7670_attach(struct i2c_adapter *adapter)
1213{
1214 int ret;
1215 struct i2c_client *client;
1216 struct ov7670_info *info;
1217
1218 /*
1219 * For now: only deal with adapters we recognize.
1220 */
1221 if (adapter->id != I2C_HW_SMBUS_CAFE)
1222 return -ENODEV;
1223
1224 client = kzalloc(sizeof (struct i2c_client), GFP_KERNEL);
1225 if (! client)
1226 return -ENOMEM;
1227 client->adapter = adapter;
1228 client->addr = OV7670_I2C_ADDR;
1229 client->driver = &ov7670_driver,
1230 strcpy(client->name, "OV7670");
1231 /*
1232 * Set up our info structure.
1233 */
1234 info = kzalloc(sizeof (struct ov7670_info), GFP_KERNEL);
1235 if (! info) {
1236 ret = -ENOMEM;
1237 goto out_free;
1238 }
1239 info->fmt = &ov7670_formats[0];
1240 info->sat = 128; /* Review this */
1241 i2c_set_clientdata(client, info);
1242
1243 /*
1244 * Make sure it's an ov7670
1245 */
1246 ret = ov7670_detect(client);
1247 if (ret)
1248 goto out_free_info;
1249 i2c_attach_client(client);
1250 return 0;
1251
1252 out_free_info:
1253 kfree(info);
1254 out_free:
1255 kfree(client);
1256 return ret;
1257}
1258
1259
1260static int ov7670_detach(struct i2c_client *client)
1261{
1262 i2c_detach_client(client);
1263 kfree(i2c_get_clientdata(client));
1264 kfree(client);
1265 return 0;
1266}
1267
1268
1269static int ov7670_command(struct i2c_client *client, unsigned int cmd,
1270 void *arg)
1271{
1272 switch (cmd) {
1273 case VIDIOC_INT_G_CHIP_IDENT:
1274 * (enum v4l2_chip_ident *) arg = V4L2_IDENT_OV7670;
1275 return 0;
1276
1277 case VIDIOC_INT_RESET:
1278 ov7670_reset(client);
1279 return 0;
1280
1281 case VIDIOC_INT_INIT:
1282 return ov7670_init(client);
1283
1284 case VIDIOC_ENUM_FMT:
1285 return ov7670_enum_fmt(client, (struct v4l2_fmtdesc *) arg);
1286 case VIDIOC_TRY_FMT:
1287 return ov7670_try_fmt(client, (struct v4l2_format *) arg, NULL, NULL);
1288 case VIDIOC_S_FMT:
1289 return ov7670_s_fmt(client, (struct v4l2_format *) arg);
1290 case VIDIOC_QUERYCTRL:
1291 return ov7670_queryctrl(client, (struct v4l2_queryctrl *) arg);
1292 case VIDIOC_S_CTRL:
1293 return ov7670_s_ctrl(client, (struct v4l2_control *) arg);
1294 case VIDIOC_G_CTRL:
1295 return ov7670_g_ctrl(client, (struct v4l2_control *) arg);
1296 case VIDIOC_S_PARM:
1297 return ov7670_s_parm(client, (struct v4l2_streamparm *) arg);
1298 case VIDIOC_G_PARM:
1299 return ov7670_g_parm(client, (struct v4l2_streamparm *) arg);
1300 }
1301 return -EINVAL;
1302}
1303
1304
1305
1306static struct i2c_driver ov7670_driver = {
1307 .driver = {
1308 .name = "ov7670",
1309 },
1310 .id = I2C_DRIVERID_OV7670,
1311 .class = I2C_CLASS_CAM_DIGITAL,
1312 .attach_adapter = ov7670_attach,
1313 .detach_client = ov7670_detach,
1314 .command = ov7670_command,
1315};
1316
1317
1318/*
1319 * Module initialization
1320 */
1321static int __init ov7670_mod_init(void)
1322{
1323 printk(KERN_NOTICE "OmniVision ov7670 sensor driver, at your service\n");
1324 return i2c_add_driver(&ov7670_driver);
1325}
1326
1327static void __exit ov7670_mod_exit(void)
1328{
1329 i2c_del_driver(&ov7670_driver);
1330}
1331
1332module_init(ov7670_mod_init);
1333module_exit(ov7670_mod_exit);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index c80c26be6e4d..848fb233d808 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -260,6 +260,22 @@ int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw,
260 sizeof(decoder_ops[0]))) - 1; 260 sizeof(decoder_ops[0]))) - 1;
261 hdw->decoder_ctrl = &ctxt->ctrl; 261 hdw->decoder_ctrl = &ctxt->ctrl;
262 cp->handler = &ctxt->handler; 262 cp->handler = &ctxt->handler;
263 {
264 /*
265 Mike Isely <isely@pobox.com> 19-Nov-2006 - This bit
266 of nuttiness for cx25840 causes that module to
267 correctly set up its video scaling. This is really
268 a problem in the cx25840 module itself, but we work
269 around it here. The problem has not been seen in
270 ivtv because there VBI is supported and set up. We
271 don't do VBI here (at least not yet) and thus we
272 never attempted to even set it up.
273 */
274 struct v4l2_format fmt;
275 memset(&fmt,0,sizeof(fmt));
276 fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
277 pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_FMT,&fmt);
278 }
263 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x cx2584x V4L2 handler set up", 279 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x cx2584x V4L2 handler set up",
264 cp->client->addr); 280 cp->client->addr);
265 return !0; 281 return !0;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 1f787333d18c..d2004965187b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -356,28 +356,6 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
356 return 0; 356 return 0;
357} 357}
358 358
359static int ctrl_hres_max_get(struct pvr2_ctrl *cptr,int *vp)
360{
361 /* If we're dealing with a 24xxx device, force the horizontal
362 maximum to be 720 no matter what, since we can't get the device
363 to work properly with any other value. Otherwise just return
364 the normal value. */
365 *vp = cptr->info->def.type_int.max_value;
366 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
367 return 0;
368}
369
370static int ctrl_hres_min_get(struct pvr2_ctrl *cptr,int *vp)
371{
372 /* If we're dealing with a 24xxx device, force the horizontal
373 minimum to be 720 no matter what, since we can't get the device
374 to work properly with any other value. Otherwise just return
375 the normal value. */
376 *vp = cptr->info->def.type_int.min_value;
377 if (cptr->hdw->hdw_type == PVR2_HDW_TYPE_24XXX) *vp = 720;
378 return 0;
379}
380
381static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp) 359static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
382{ 360{
383 /* Actual maximum depends on the video standard in effect. */ 361 /* Actual maximum depends on the video standard in effect. */
@@ -758,10 +736,6 @@ static const struct pvr2_ctl_info control_defs[] = {
758 .default_value = 720, 736 .default_value = 720,
759 DEFREF(res_hor), 737 DEFREF(res_hor),
760 DEFINT(19,720), 738 DEFINT(19,720),
761 /* Hook in check for clamp on horizontal resolution in
762 order to avoid unsolved problem involving cx25840. */
763 .get_max_value = ctrl_hres_max_get,
764 .get_min_value = ctrl_hres_min_get,
765 },{ 739 },{
766 .desc = "Vertical capture resolution", 740 .desc = "Vertical capture resolution",
767 .name = "resolution_ver", 741 .name = "resolution_ver",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 3b9012f8e380..f9bb41d8f4f3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -185,6 +185,79 @@ static int pvr2_i2c_basic_op(struct pvr2_hdw *hdw,
185 } 185 }
186} 186}
187 187
188
189/* This is a special entry point for cases of I2C transaction attempts to
190 the IR receiver. The implementation here simulates the IR receiver by
191 issuing a command to the FX2 firmware and using that response to return
192 what the real I2C receiver would have returned. We use this for 24xxx
193 devices, where the IR receiver chip has been removed and replaced with
194 FX2 related logic. */
195static int i2c_24xxx_ir(struct pvr2_hdw *hdw,
196 u8 i2c_addr,u8 *wdata,u16 wlen,u8 *rdata,u16 rlen)
197{
198 u8 dat[4];
199 unsigned int stat;
200
201 if (!(rlen || wlen)) {
202 /* This is a probe attempt. Just let it succeed. */
203 return 0;
204 }
205
206 /* We don't understand this kind of transaction */
207 if ((wlen != 0) || (rlen == 0)) return -EIO;
208
209 if (rlen < 3) {
210 /* Mike Isely <isely@pobox.com> Appears to be a probe
211 attempt from lirc. Just fill in zeroes and return. If
212 we try instead to do the full transaction here, then bad
213 things seem to happen within the lirc driver module
214 (version 0.8.0-7 sources from Debian, when run under
215 vanilla 2.6.17.6 kernel) - and I don't have the patience
216 to chase it down. */
217 if (rlen > 0) rdata[0] = 0;
218 if (rlen > 1) rdata[1] = 0;
219 return 0;
220 }
221
222 /* Issue a command to the FX2 to read the IR receiver. */
223 LOCK_TAKE(hdw->ctl_lock); do {
224 hdw->cmd_buffer[0] = 0xec;
225 stat = pvr2_send_request(hdw,
226 hdw->cmd_buffer,1,
227 hdw->cmd_buffer,4);
228 dat[0] = hdw->cmd_buffer[0];
229 dat[1] = hdw->cmd_buffer[1];
230 dat[2] = hdw->cmd_buffer[2];
231 dat[3] = hdw->cmd_buffer[3];
232 } while (0); LOCK_GIVE(hdw->ctl_lock);
233
234 /* Give up if that operation failed. */
235 if (stat != 0) return stat;
236
237 /* Mangle the results into something that looks like the real IR
238 receiver. */
239 rdata[2] = 0xc1;
240 if (dat[0] != 1) {
241 /* No code received. */
242 rdata[0] = 0;
243 rdata[1] = 0;
244 } else {
245 u16 val;
246 /* Mash the FX2 firmware-provided IR code into something
247 that the normal i2c chip-level driver expects. */
248 val = dat[1];
249 val <<= 8;
250 val |= dat[2];
251 val >>= 1;
252 val &= ~0x0003;
253 val |= 0x8000;
254 rdata[0] = (val >> 8) & 0xffu;
255 rdata[1] = val & 0xffu;
256 }
257
258 return 0;
259}
260
188/* This is a special entry point that is entered if an I2C operation is 261/* This is a special entry point that is entered if an I2C operation is
189 attempted to a wm8775 chip on model 24xxx hardware. Autodetect of this 262 attempted to a wm8775 chip on model 24xxx hardware. Autodetect of this
190 part doesn't work, but we know it is really there. So let's look for 263 part doesn't work, but we know it is really there. So let's look for
@@ -887,17 +960,17 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
887{ 960{
888 unsigned int idx; 961 unsigned int idx;
889 962
890 // The default action for all possible I2C addresses is just to do 963 /* The default action for all possible I2C addresses is just to do
891 // the transfer normally. 964 the transfer normally. */
892 for (idx = 0; idx < PVR2_I2C_FUNC_CNT; idx++) { 965 for (idx = 0; idx < PVR2_I2C_FUNC_CNT; idx++) {
893 hdw->i2c_func[idx] = pvr2_i2c_basic_op; 966 hdw->i2c_func[idx] = pvr2_i2c_basic_op;
894 } 967 }
895 968
896 // If however we're dealing with new hardware, insert some hacks in 969 /* However, deal with various special cases for 24xxx hardware. */
897 // the I2C transfer stack to let things work better.
898 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 970 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
899 hdw->i2c_func[0x1b] = i2c_hack_wm8775; 971 hdw->i2c_func[0x1b] = i2c_hack_wm8775;
900 hdw->i2c_func[0x44] = i2c_hack_cx25840; 972 hdw->i2c_func[0x44] = i2c_hack_cx25840;
973 hdw->i2c_func[0x18] = i2c_24xxx_ir;
901 } 974 }
902 975
903 // Configure the adapter and set up everything else related to it. 976 // Configure the adapter and set up everything else related to it.
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index f28398dd9d93..c2374ed7ba9f 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -851,7 +851,7 @@ static int saa711x_set_size(struct i2c_client *client, int width, int height)
851 851
852 /* On 60Hz, it is using a higher Vertical Output Size */ 852 /* On 60Hz, it is using a higher Vertical Output Size */
853 if (!is_50hz) 853 if (!is_50hz)
854 res+=(VRES_60HZ-480)>>1; 854 res += (VRES_60HZ - 480) >> 1;
855 855
856 /* height */ 856 /* height */
857 saa711x_write(client, R_CE_B_VERT_OUTPUT_WINDOW_LENGTH, 857 saa711x_write(client, R_CE_B_VERT_OUTPUT_WINDOW_LENGTH,
@@ -907,7 +907,7 @@ static int saa711x_set_size(struct i2c_client *client, int width, int height)
907 907
908 /* Activates task "B" */ 908 /* Activates task "B" */
909 saa711x_write(client, R_80_GLOBAL_CNTL_1, 909 saa711x_write(client, R_80_GLOBAL_CNTL_1,
910 saa711x_read(client,R_80_GLOBAL_CNTL_1)|0x20); 910 saa711x_read(client,R_80_GLOBAL_CNTL_1) | 0x20);
911 911
912 return 0; 912 return 0;
913} 913}
@@ -932,11 +932,11 @@ static void saa711x_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
932 if (std & V4L2_STD_525_60) { 932 if (std & V4L2_STD_525_60) {
933 v4l_dbg(1, debug, client, "decoder set standard 60 Hz\n"); 933 v4l_dbg(1, debug, client, "decoder set standard 60 Hz\n");
934 saa711x_writeregs(client, saa7115_cfg_60hz_video); 934 saa711x_writeregs(client, saa7115_cfg_60hz_video);
935 saa711x_set_size(client,720,480); 935 saa711x_set_size(client, 720, 480);
936 } else { 936 } else {
937 v4l_dbg(1, debug, client, "decoder set standard 50 Hz\n"); 937 v4l_dbg(1, debug, client, "decoder set standard 50 Hz\n");
938 saa711x_writeregs(client, saa7115_cfg_50hz_video); 938 saa711x_writeregs(client, saa7115_cfg_50hz_video);
939 saa711x_set_size(client,720,576); 939 saa711x_set_size(client, 720, 576);
940 } 940 }
941 941
942 /* Register 0E - Bits D6-D4 on NO-AUTO mode 942 /* Register 0E - Bits D6-D4 on NO-AUTO mode
@@ -1464,13 +1464,13 @@ static int saa711x_attach(struct i2c_adapter *adapter, int address, int kind)
1464 client->driver = &i2c_driver_saa711x; 1464 client->driver = &i2c_driver_saa711x;
1465 snprintf(client->name, sizeof(client->name) - 1, "saa7115"); 1465 snprintf(client->name, sizeof(client->name) - 1, "saa7115");
1466 1466
1467 for (i=0;i<0x0f;i++) { 1467 for (i = 0; i < 0x0f; i++) {
1468 saa711x_write(client, 0, i); 1468 saa711x_write(client, 0, i);
1469 name[i] = (saa711x_read(client, 0) &0x0f) +'0'; 1469 name[i] = (saa711x_read(client, 0) & 0x0f) + '0';
1470 if (name[i]>'9') 1470 if (name[i] > '9')
1471 name[i]+='a'-'9'-1; 1471 name[i] += 'a' - '9' - 1;
1472 } 1472 }
1473 name[i]='\0'; 1473 name[i] = '\0';
1474 1474
1475 saa711x_write(client, 0, 5); 1475 saa711x_write(client, 0, 5);
1476 chip_id = saa711x_read(client, 0) & 0x0f; 1476 chip_id = saa711x_read(client, 0) & 0x0f;
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 4abf5c03a740..ffb0f647a86d 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -1,10 +1,6 @@
1/* 1/*
2 * SAA713x ALSA support for V4L 2 * SAA713x ALSA support for V4L
3 * 3 *
4 *
5 * Caveats:
6 * - Volume doesn't work (it's always at max)
7 *
8 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, version 2 6 * the Free Software Foundation, version 2
@@ -614,13 +610,18 @@ static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream)
614 snd_card_saa7134_pcm_t *pcm; 610 snd_card_saa7134_pcm_t *pcm;
615 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); 611 snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream);
616 struct saa7134_dev *dev = saa7134->dev; 612 struct saa7134_dev *dev = saa7134->dev;
617 int err; 613 int amux, err;
618 614
619 mutex_lock(&dev->dmasound.lock); 615 mutex_lock(&dev->dmasound.lock);
620 616
621 dev->dmasound.read_count = 0; 617 dev->dmasound.read_count = 0;
622 dev->dmasound.read_offset = 0; 618 dev->dmasound.read_offset = 0;
623 619
620 amux = dev->input->amux;
621 if ((amux < 1) || (amux > 3))
622 amux = 1;
623 dev->dmasound.input = amux - 1;
624
624 mutex_unlock(&dev->dmasound.lock); 625 mutex_unlock(&dev->dmasound.lock);
625 626
626 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); 627 pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
@@ -713,6 +714,8 @@ static int snd_saa7134_volume_put(struct snd_kcontrol * kcontrol,
713 struct snd_ctl_elem_value * ucontrol) 714 struct snd_ctl_elem_value * ucontrol)
714{ 715{
715 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); 716 snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol);
717 struct saa7134_dev *dev = chip->dev;
718
716 int change, addr = kcontrol->private_value; 719 int change, addr = kcontrol->private_value;
717 int left, right; 720 int left, right;
718 721
@@ -727,10 +730,52 @@ static int snd_saa7134_volume_put(struct snd_kcontrol * kcontrol,
727 if (right > 20) 730 if (right > 20)
728 right = 20; 731 right = 20;
729 spin_lock_irq(&chip->mixer_lock); 732 spin_lock_irq(&chip->mixer_lock);
730 change = chip->mixer_volume[addr][0] != left || 733 change = 0;
731 chip->mixer_volume[addr][1] != right; 734 if (chip->mixer_volume[addr][0] != left) {
732 chip->mixer_volume[addr][0] = left; 735 change = 1;
733 chip->mixer_volume[addr][1] = right; 736 right = left;
737 }
738 if (chip->mixer_volume[addr][1] != right) {
739 change = 1;
740 left = right;
741 }
742 if (change) {
743 switch (dev->pci->device) {
744 case PCI_DEVICE_ID_PHILIPS_SAA7134:
745 switch (addr) {
746 case MIXER_ADDR_TVTUNER:
747 left = 20;
748 break;
749 case MIXER_ADDR_LINE1:
750 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10,
751 (left > 10) ? 0x00 : 0x10);
752 break;
753 case MIXER_ADDR_LINE2:
754 saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20,
755 (left > 10) ? 0x00 : 0x20);
756 break;
757 }
758 break;
759 case PCI_DEVICE_ID_PHILIPS_SAA7133:
760 case PCI_DEVICE_ID_PHILIPS_SAA7135:
761 switch (addr) {
762 case MIXER_ADDR_TVTUNER:
763 left = 20;
764 break;
765 case MIXER_ADDR_LINE1:
766 saa_andorb(0x0594, 0x10,
767 (left > 10) ? 0x00 : 0x10);
768 break;
769 case MIXER_ADDR_LINE2:
770 saa_andorb(0x0594, 0x20,
771 (left > 10) ? 0x00 : 0x20);
772 break;
773 }
774 break;
775 }
776 chip->mixer_volume[addr][0] = left;
777 chip->mixer_volume[addr][1] = right;
778 }
734 spin_unlock_irq(&chip->mixer_lock); 779 spin_unlock_irq(&chip->mixer_lock);
735 return change; 780 return change;
736} 781}
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 51f0cfdcb680..4dead84aff46 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -2462,14 +2462,17 @@ struct saa7134_board saa7134_boards[] = {
2462 .vmux = 1, 2462 .vmux = 1,
2463 .amux = TV, 2463 .amux = TV,
2464 .tv = 1, 2464 .tv = 1,
2465 .gpio = 0x0000000,
2465 },{ 2466 },{
2466 .name = name_comp1, 2467 .name = name_comp1,
2467 .vmux = 3, 2468 .vmux = 3,
2468 .amux = LINE2, 2469 .amux = LINE2,
2470 .gpio = 0x0200000,
2469 },{ 2471 },{
2470 .name = name_svideo, 2472 .name = name_svideo,
2471 .vmux = 8, 2473 .vmux = 8,
2472 .amux = LINE2, 2474 .amux = LINE2,
2475 .gpio = 0x0200000,
2473 }}, 2476 }},
2474 .radio = { 2477 .radio = {
2475 .name = name_radio, 2478 .name = name_radio,
@@ -3022,6 +3025,158 @@ struct saa7134_board saa7134_boards[] = {
3022 .amux = LINE1, 3025 .amux = LINE1,
3023 }, 3026 },
3024 }, 3027 },
3028 [SAA7134_BOARD_PINNACLE_PCTV_310i] = {
3029 .name = "Pinnacle PCTV 310i",
3030 .audio_clock = 0x00187de7,
3031 .tuner_type = TUNER_PHILIPS_TDA8290,
3032 .radio_type = UNSET,
3033 .tuner_addr = ADDR_UNSET,
3034 .radio_addr = ADDR_UNSET,
3035 .mpeg = SAA7134_MPEG_DVB,
3036 .gpiomask = 0x000200000,
3037 .inputs = {{
3038 .name = name_tv,
3039 .vmux = 4,
3040 .amux = TV,
3041 .tv = 1,
3042 },{
3043 .name = name_comp1,
3044 .vmux = 1,
3045 .amux = LINE2,
3046 },{
3047 .name = name_comp2,
3048 .vmux = 0,
3049 .amux = LINE2,
3050 },{
3051 .name = name_svideo,
3052 .vmux = 8,
3053 .amux = LINE2,
3054 }},
3055 .radio = {
3056 .name = name_radio,
3057 .amux = TV,
3058 .gpio = 0x0200000,
3059 },
3060 },
3061 [SAA7134_BOARD_AVERMEDIA_STUDIO_507] = {
3062 /* Mikhail Fedotov <mo_fedotov@mail.ru> */
3063 .name = "Avermedia AVerTV Studio 507",
3064 .audio_clock = 0x00187de7,
3065 .tuner_type = TUNER_PHILIPS_FM1256_IH3,
3066 .radio_type = UNSET,
3067 .tuner_addr = ADDR_UNSET,
3068 .radio_addr = ADDR_UNSET,
3069 .tda9887_conf = TDA9887_PRESENT,
3070 .gpiomask = 0x03,
3071 .inputs = {{
3072 .name = name_tv,
3073 .vmux = 1,
3074 .amux = TV,
3075 .tv = 1,
3076 .gpio = 0x00,
3077 },{
3078 .name = name_comp1,
3079 .vmux = 0,
3080 .amux = LINE2,
3081 .gpio = 0x00,
3082 },{
3083 .name = name_comp2,
3084 .vmux = 3,
3085 .amux = LINE2,
3086 .gpio = 0x00,
3087 },{
3088 .name = name_svideo,
3089 .vmux = 8,
3090 .amux = LINE2,
3091 .gpio = 0x00,
3092 }},
3093 .radio = {
3094 .name = name_radio,
3095 .amux = LINE2,
3096 .gpio = 0x01,
3097 },
3098 .mute = {
3099 .name = name_mute,
3100 .amux = LINE1,
3101 .gpio = 0x00,
3102 },
3103 },
3104 [SAA7134_BOARD_VIDEOMATE_DVBT_200A] = {
3105 /* Francis Barber <fedora@barber-family.id.au> */
3106 .name = "Compro Videomate DVB-T200A",
3107 .audio_clock = 0x00187de7,
3108 .tuner_type = TUNER_ABSENT,
3109 .radio_type = UNSET,
3110 .tuner_addr = ADDR_UNSET,
3111 .radio_addr = ADDR_UNSET,
3112 .tda9887_conf = TDA9887_PRESENT | TDA9887_PORT1_ACTIVE,
3113 .mpeg = SAA7134_MPEG_DVB,
3114 .inputs = {{
3115 .name = name_tv,
3116 .vmux = 3,
3117 .amux = TV,
3118 .tv = 1,
3119 },{
3120 .name = name_comp1,
3121 .vmux = 1,
3122 .amux = LINE2,
3123 },{
3124 .name = name_svideo,
3125 .vmux = 8,
3126 .amux = LINE2,
3127 }},
3128 },
3129 [SAA7134_BOARD_HAUPPAUGE_HVR1110] = {
3130 /* Thomas Genty <tomlohave@gmail.com> */
3131 .name = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid",
3132 .audio_clock = 0x00187de7,
3133 .tuner_type = TUNER_PHILIPS_TDA8290,
3134 .radio_type = UNSET,
3135 .tuner_addr = ADDR_UNSET,
3136 .radio_addr = ADDR_UNSET,
3137 .mpeg = SAA7134_MPEG_DVB,
3138 .inputs = {{
3139 .name = name_tv,
3140 .vmux = 1,
3141 .amux = TV,
3142 .tv = 1,
3143 },{
3144 .name = name_comp1,
3145 .vmux = 3,
3146 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */
3147 },{
3148 .name = name_svideo,
3149 .vmux = 8,
3150 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */
3151 }},
3152 .radio = {
3153 .name = name_radio,
3154 .amux = TV,
3155 },
3156 },
3157 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = {
3158 .name = "Terratec Cinergy HT PCMCIA",
3159 .audio_clock = 0x00187de7,
3160 .tuner_type = TUNER_PHILIPS_TDA8290,
3161 .radio_type = UNSET,
3162 .tuner_addr = ADDR_UNSET,
3163 .radio_addr = ADDR_UNSET,
3164 .mpeg = SAA7134_MPEG_DVB,
3165 .inputs = {{
3166 .name = name_tv,
3167 .vmux = 1,
3168 .amux = TV,
3169 .tv = 1,
3170 },{
3171 .name = name_comp1,
3172 .vmux = 0,
3173 .amux = LINE1,
3174 },{
3175 .name = name_svideo,
3176 .vmux = 6,
3177 .amux = LINE1,
3178 }},
3179 },
3025}; 3180};
3026 3181
3027const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 3182const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -3631,6 +3786,36 @@ struct pci_device_id saa7134_pci_tbl[] = {
3631 .subdevice = 0x4860, 3786 .subdevice = 0x4860,
3632 .driver_data = SAA7134_BOARD_ASUS_EUROPA2_HYBRID, 3787 .driver_data = SAA7134_BOARD_ASUS_EUROPA2_HYBRID,
3633 },{ 3788 },{
3789 .vendor = PCI_VENDOR_ID_PHILIPS,
3790 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3791 .subvendor = 0x11bd,
3792 .subdevice = 0x002f,
3793 .driver_data = SAA7134_BOARD_PINNACLE_PCTV_310i,
3794 },{
3795 .vendor = PCI_VENDOR_ID_PHILIPS,
3796 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3797 .subvendor = 0x1461, /* Avermedia Technologies Inc */
3798 .subdevice = 0x9715,
3799 .driver_data = SAA7134_BOARD_AVERMEDIA_STUDIO_507,
3800 },{
3801 .vendor = PCI_VENDOR_ID_PHILIPS,
3802 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3803 .subvendor = 0x1043,
3804 .subdevice = 0x4876,
3805 .driver_data = SAA7134_BOARD_ASUSTeK_P7131_DUAL,
3806 },{
3807 .vendor = PCI_VENDOR_ID_PHILIPS,
3808 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3809 .subvendor = 0x0070,
3810 .subdevice = 0x6701,
3811 .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1110,
3812 },{
3813 .vendor = PCI_VENDOR_ID_PHILIPS,
3814 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3815 .subvendor = 0x153b,
3816 .subdevice = 0x1172,
3817 .driver_data = SAA7134_BOARD_CINERGY_HT_PCMCIA,
3818 },{
3634 /* --- boards without eeprom + subsystem ID --- */ 3819 /* --- boards without eeprom + subsystem ID --- */
3635 .vendor = PCI_VENDOR_ID_PHILIPS, 3820 .vendor = PCI_VENDOR_ID_PHILIPS,
3636 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 3821 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -3717,6 +3902,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3717 case SAA7134_BOARD_AVERMEDIA_305: 3902 case SAA7134_BOARD_AVERMEDIA_305:
3718 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 3903 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
3719 case SAA7134_BOARD_AVERMEDIA_307: 3904 case SAA7134_BOARD_AVERMEDIA_307:
3905 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
3720 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 3906 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
3721 case SAA7134_BOARD_AVERMEDIA_777: 3907 case SAA7134_BOARD_AVERMEDIA_777:
3722/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */ 3908/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */
@@ -3725,6 +3911,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3725 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: 3911 case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
3726 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 3912 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
3727 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 3913 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
3914 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
3728 case SAA7134_BOARD_MANLI_MTV001: 3915 case SAA7134_BOARD_MANLI_MTV001:
3729 case SAA7134_BOARD_MANLI_MTV002: 3916 case SAA7134_BOARD_MANLI_MTV002:
3730 case SAA7134_BOARD_BEHOLD_409FM: 3917 case SAA7134_BOARD_BEHOLD_409FM:
@@ -3793,7 +3980,9 @@ int saa7134_board_init1(struct saa7134_dev *dev)
3793 break; 3980 break;
3794 /* i2c remotes */ 3981 /* i2c remotes */
3795 case SAA7134_BOARD_PINNACLE_PCTV_110i: 3982 case SAA7134_BOARD_PINNACLE_PCTV_110i:
3983 case SAA7134_BOARD_PINNACLE_PCTV_310i:
3796 case SAA7134_BOARD_UPMOST_PURPLE_TV: 3984 case SAA7134_BOARD_UPMOST_PURPLE_TV:
3985 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
3797 dev->has_remote = SAA7134_REMOTE_I2C; 3986 dev->has_remote = SAA7134_REMOTE_I2C;
3798 break; 3987 break;
3799 case SAA7134_BOARD_AVERMEDIA_A169_B: 3988 case SAA7134_BOARD_AVERMEDIA_A169_B:
@@ -3924,9 +4113,11 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3924 } 4113 }
3925 break; 4114 break;
3926 case SAA7134_BOARD_PHILIPS_TIGER: 4115 case SAA7134_BOARD_PHILIPS_TIGER:
4116 case SAA7134_BOARD_PINNACLE_PCTV_310i:
3927 case SAA7134_BOARD_TEVION_DVBT_220RF: 4117 case SAA7134_BOARD_TEVION_DVBT_220RF:
3928 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 4118 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
3929 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 4119 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
4120 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
3930 /* this is a hybrid board, initialize to analog mode 4121 /* this is a hybrid board, initialize to analog mode
3931 * and configure firmware eeprom address 4122 * and configure firmware eeprom address
3932 */ 4123 */
@@ -3952,6 +4143,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3952 i2c_transfer(&dev->i2c_adap, &msg, 1); 4143 i2c_transfer(&dev->i2c_adap, &msg, 1);
3953 } 4144 }
3954 break; 4145 break;
4146 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
4147 /* make the tda10046 find its eeprom */
4148 {
4149 u8 data[] = { 0x3c, 0x33, 0x60};
4150 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
4151 i2c_transfer(&dev->i2c_adap, &msg, 1);
4152 }
4153 break;
3955 case SAA7134_BOARD_KWORLD_ATSC110: 4154 case SAA7134_BOARD_KWORLD_ATSC110:
3956 { 4155 {
3957 /* enable tuner */ 4156 /* enable tuner */
@@ -3964,6 +4163,29 @@ int saa7134_board_init2(struct saa7134_dev *dev)
3964 dev->name, i); 4163 dev->name, i);
3965 } 4164 }
3966 break; 4165 break;
4166 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
4167 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
4168 /* The T200 and the T200A share the same pci id. Consequently,
4169 * we are going to query eeprom to try to find out which one we
4170 * are actually looking at. */
4171
4172 /* Don't do this if the board was specifically selected with an
4173 * insmod option or if we have the default configuration T200*/
4174 if(!dev->autodetected || (dev->eedata[0x41] == 0xd0))
4175 break;
4176 if(dev->eedata[0x41] == 0x02) {
4177 /* Reconfigure board as T200A */
4178 dev->board = SAA7134_BOARD_VIDEOMATE_DVBT_200A;
4179 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
4180 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
4181 printk(KERN_INFO "%s: Reconfigured board as %s\n",
4182 dev->name, saa7134_boards[dev->board].name);
4183 } else {
4184 printk(KERN_WARNING "%s: Unexpected tuner type info: %x in eeprom\n",
4185 dev->name, dev->eedata[0x41]);
4186 break;
4187 }
4188 break;
3967 } 4189 }
3968 return 0; 4190 return 0;
3969} 4191}
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 5c9e63dfbea6..ed038fff3b4f 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -889,15 +889,16 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
889 must_configure_manually(); 889 must_configure_manually();
890 dev->board = SAA7134_BOARD_UNKNOWN; 890 dev->board = SAA7134_BOARD_UNKNOWN;
891 } 891 }
892 dev->autodetected = card[dev->nr] != dev->board;
892 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 893 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
893 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 894 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
894 if (UNSET != tuner[dev->nr]) 895 if (UNSET != tuner[dev->nr])
895 dev->tuner_type = tuner[dev->nr]; 896 dev->tuner_type = tuner[dev->nr];
896 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 897 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
897 dev->name,pci_dev->subsystem_vendor, 898 dev->name,pci_dev->subsystem_vendor,
898 pci_dev->subsystem_device,saa7134_boards[dev->board].name, 899 pci_dev->subsystem_device,saa7134_boards[dev->board].name,
899 dev->board, card[dev->nr] == dev->board ? 900 dev->board, dev->autodetected ?
900 "insmod option" : "autodetected"); 901 "autodetected" : "insmod option");
901 902
902 /* get mmio */ 903 /* get mmio */
903 if (!request_mem_region(pci_resource_start(pci_dev,0), 904 if (!request_mem_region(pci_resource_start(pci_dev,0),
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 6b61d9b2fcb5..fa8339879095 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -50,6 +50,10 @@ static unsigned int antenna_pwr = 0;
50module_param(antenna_pwr, int, 0444); 50module_param(antenna_pwr, int, 0444);
51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 51MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
52 52
53static int use_frontent = 0;
54module_param(use_frontent, int, 0644);
55MODULE_PARM_DESC(use_frontent,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
56
53/* ------------------------------------------------------------------ */ 57/* ------------------------------------------------------------------ */
54static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on) 58static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
55{ 59{
@@ -293,7 +297,7 @@ static int philips_tu1216_tuner_60_set_params(struct dvb_frontend *fe, struct dv
293 return philips_tda6651_pll_set(0x60, fe, params); 297 return philips_tda6651_pll_set(0x60, fe, params);
294} 298}
295 299
296static int philips_tu1216_request_firmware(struct dvb_frontend *fe, 300static int philips_tda1004x_request_firmware(struct dvb_frontend *fe,
297 const struct firmware **fw, char *name) 301 const struct firmware **fw, char *name)
298{ 302{
299 struct saa7134_dev *dev = fe->dvb->priv; 303 struct saa7134_dev *dev = fe->dvb->priv;
@@ -308,7 +312,7 @@ static struct tda1004x_config philips_tu1216_60_config = {
308 .xtal_freq = TDA10046_XTAL_4M, 312 .xtal_freq = TDA10046_XTAL_4M,
309 .agc_config = TDA10046_AGC_DEFAULT, 313 .agc_config = TDA10046_AGC_DEFAULT,
310 .if_freq = TDA10046_FREQ_3617, 314 .if_freq = TDA10046_FREQ_3617,
311 .request_firmware = philips_tu1216_request_firmware, 315 .request_firmware = philips_tda1004x_request_firmware,
312}; 316};
313 317
314/* ------------------------------------------------------------------ */ 318/* ------------------------------------------------------------------ */
@@ -331,12 +335,12 @@ static struct tda1004x_config philips_tu1216_61_config = {
331 .xtal_freq = TDA10046_XTAL_4M, 335 .xtal_freq = TDA10046_XTAL_4M,
332 .agc_config = TDA10046_AGC_DEFAULT, 336 .agc_config = TDA10046_AGC_DEFAULT,
333 .if_freq = TDA10046_FREQ_3617, 337 .if_freq = TDA10046_FREQ_3617,
334 .request_firmware = philips_tu1216_request_firmware, 338 .request_firmware = philips_tda1004x_request_firmware,
335}; 339};
336 340
337/* ------------------------------------------------------------------ */ 341/* ------------------------------------------------------------------ */
338 342
339static int philips_europa_tuner_init(struct dvb_frontend *fe) 343static int philips_td1316_tuner_init(struct dvb_frontend *fe)
340{ 344{
341 struct saa7134_dev *dev = fe->dvb->priv; 345 struct saa7134_dev *dev = fe->dvb->priv;
342 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab }; 346 static u8 msg[] = { 0x0b, 0xf5, 0x86, 0xab };
@@ -347,18 +351,8 @@ static int philips_europa_tuner_init(struct dvb_frontend *fe)
347 fe->ops.i2c_gate_ctrl(fe, 1); 351 fe->ops.i2c_gate_ctrl(fe, 1);
348 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1) 352 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
349 return -EIO; 353 return -EIO;
350 msleep(1);
351
352 /* switch the board to dvb mode */
353 init_msg.addr = 0x43;
354 init_msg.len = 0x02;
355 msg[0] = 0x00;
356 msg[1] = 0x40;
357 if (fe->ops.i2c_gate_ctrl) 354 if (fe->ops.i2c_gate_ctrl)
358 fe->ops.i2c_gate_ctrl(fe, 1); 355 fe->ops.i2c_gate_ctrl(fe, 0);
359 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
360 return -EIO;
361
362 return 0; 356 return 0;
363} 357}
364 358
@@ -367,6 +361,22 @@ static int philips_td1316_tuner_set_params(struct dvb_frontend *fe, struct dvb_f
367 return philips_tda6651_pll_set(0x61, fe, params); 361 return philips_tda6651_pll_set(0x61, fe, params);
368} 362}
369 363
364static int philips_europa_tuner_init(struct dvb_frontend *fe)
365{
366 struct saa7134_dev *dev = fe->dvb->priv;
367 static u8 msg[] = { 0x00, 0x40};
368 struct i2c_msg init_msg = {.addr = 0x43,.flags = 0,.buf = msg,.len = sizeof(msg) };
369
370
371 if (philips_td1316_tuner_init(fe))
372 return -EIO;
373 msleep(1);
374 if (i2c_transfer(&dev->i2c_adap, &init_msg, 1) != 1)
375 return -EIO;
376
377 return 0;
378}
379
370static int philips_europa_tuner_sleep(struct dvb_frontend *fe) 380static int philips_europa_tuner_sleep(struct dvb_frontend *fe)
371{ 381{
372 struct saa7134_dev *dev = fe->dvb->priv; 382 struct saa7134_dev *dev = fe->dvb->priv;
@@ -671,7 +681,7 @@ static struct tda1004x_config tda827x_lifeview_config = {
671 .invert = 1, 681 .invert = 1,
672 .invert_oclk = 0, 682 .invert_oclk = 0,
673 .xtal_freq = TDA10046_XTAL_16M, 683 .xtal_freq = TDA10046_XTAL_16M,
674 .agc_config = TDA10046_AGC_TDA827X, 684 .agc_config = TDA10046_AGC_TDA827X_GP11,
675 .if_freq = TDA10046_FREQ_045, 685 .if_freq = TDA10046_FREQ_045,
676 .request_firmware = NULL, 686 .request_firmware = NULL,
677}; 687};
@@ -812,32 +822,40 @@ static int philips_tda827xa_tuner_sleep(u8 addr, struct dvb_frontend *fe)
812 if (fe->ops.i2c_gate_ctrl) 822 if (fe->ops.i2c_gate_ctrl)
813 fe->ops.i2c_gate_ctrl(fe, 1); 823 fe->ops.i2c_gate_ctrl(fe, 1);
814 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1); 824 i2c_transfer(&dev->i2c_adap, &tuner_msg, 1);
825 if (fe->ops.i2c_gate_ctrl)
826 fe->ops.i2c_gate_ctrl(fe, 0);
815 return 0; 827 return 0;
816} 828}
817 829
818/* ------------------------------------------------------------------ */ 830/* ------------------------------------------------------------------ */
819 831
820static int philips_tiger_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) 832static int tda8290_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
821{ 833{
822 int ret;
823 struct saa7134_dev *dev = fe->dvb->priv; 834 struct saa7134_dev *dev = fe->dvb->priv;
824 static u8 tda8290_close[] = { 0x21, 0xc0}; 835 static u8 tda8290_close[] = { 0x21, 0xc0};
825 static u8 tda8290_open[] = { 0x21, 0x80}; 836 static u8 tda8290_open[] = { 0x21, 0x80};
826 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2}; 837 struct i2c_msg tda8290_msg = {.addr = 0x4b,.flags = 0, .len = 2};
827 838 if (enable) {
828 /* close tda8290 i2c bridge */ 839 tda8290_msg.buf = tda8290_close;
829 tda8290_msg.buf = tda8290_close; 840 } else {
830 ret = i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1); 841 tda8290_msg.buf = tda8290_open;
831 if (ret != 1) 842 }
843 if (i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1) != 1)
832 return -EIO; 844 return -EIO;
833 msleep(20); 845 msleep(20);
846 return 0;
847}
848
849/* ------------------------------------------------------------------ */
850
851static int philips_tiger_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
852{
853 int ret;
854
834 ret = philips_tda827xa_pll_set(0x61, fe, params); 855 ret = philips_tda827xa_pll_set(0x61, fe, params);
835 if (ret != 0) 856 if (ret != 0)
836 return ret; 857 return ret;
837 /* open tda8290 i2c bridge */ 858 return 0;
838 tda8290_msg.buf = tda8290_open;
839 i2c_transfer(&dev->i2c_adap, &tda8290_msg, 1);
840 return ret;
841} 859}
842 860
843static int philips_tiger_tuner_init(struct dvb_frontend *fe) 861static int philips_tiger_tuner_init(struct dvb_frontend *fe)
@@ -867,13 +885,80 @@ static struct tda1004x_config philips_tiger_config = {
867 .invert = 1, 885 .invert = 1,
868 .invert_oclk = 0, 886 .invert_oclk = 0,
869 .xtal_freq = TDA10046_XTAL_16M, 887 .xtal_freq = TDA10046_XTAL_16M,
870 .agc_config = TDA10046_AGC_TDA827X, 888 .agc_config = TDA10046_AGC_TDA827X_GP11,
889 .if_freq = TDA10046_FREQ_045,
890 .request_firmware = NULL,
891};
892/* ------------------------------------------------------------------ */
893
894static int cinergy_ht_tuner_init(struct dvb_frontend *fe)
895{
896 struct saa7134_dev *dev = fe->dvb->priv;
897 static u8 data[] = { 0x3c, 0x33, 0x62};
898 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
899
900 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
901 return -EIO;
902 return 0;
903}
904
905static int cinergy_ht_tuner_sleep(struct dvb_frontend *fe)
906{
907 struct saa7134_dev *dev = fe->dvb->priv;
908 static u8 data[] = { 0x3c, 0x33, 0x60};
909 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
910
911 i2c_transfer(&dev->i2c_adap, &msg, 1);
912 philips_tda827xa_tuner_sleep( 0x61, fe);
913 return 0;
914}
915
916static struct tda1004x_config cinergy_ht_config = {
917 .demod_address = 0x08,
918 .invert = 1,
919 .invert_oclk = 0,
920 .xtal_freq = TDA10046_XTAL_16M,
921 .agc_config = TDA10046_AGC_TDA827X_GP01,
871 .if_freq = TDA10046_FREQ_045, 922 .if_freq = TDA10046_FREQ_045,
872 .request_firmware = NULL, 923 .request_firmware = NULL,
873}; 924};
874 925
875/* ------------------------------------------------------------------ */ 926/* ------------------------------------------------------------------ */
876 927
928static struct tda1004x_config pinnacle_pctv_310i_config = {
929 .demod_address = 0x08,
930 .invert = 1,
931 .invert_oclk = 0,
932 .xtal_freq = TDA10046_XTAL_16M,
933 .agc_config = TDA10046_AGC_TDA827X_GP11,
934 .if_freq = TDA10046_FREQ_045,
935 .request_firmware = philips_tda1004x_request_firmware,
936};
937
938/* ------------------------------------------------------------------ */
939
940static struct tda1004x_config hauppauge_hvr_1110_config = {
941 .demod_address = 0x08,
942 .invert = 1,
943 .invert_oclk = 0,
944 .xtal_freq = TDA10046_XTAL_16M,
945 .agc_config = TDA10046_AGC_TDA827X_GP11,
946 .if_freq = TDA10046_FREQ_045,
947 .request_firmware = philips_tda1004x_request_firmware,
948};
949
950/* ------------------------------------------------------------------ */
951
952static struct tda1004x_config asus_p7131_dual_config = {
953 .demod_address = 0x08,
954 .invert = 1,
955 .invert_oclk = 0,
956 .xtal_freq = TDA10046_XTAL_16M,
957 .agc_config = TDA10046_AGC_TDA827X_GP11,
958 .if_freq = TDA10046_FREQ_045,
959 .request_firmware = philips_tda1004x_request_firmware,
960};
961
877static int asus_p7131_dual_tuner_init(struct dvb_frontend *fe) 962static int asus_p7131_dual_tuner_init(struct dvb_frontend *fe)
878{ 963{
879 struct saa7134_dev *dev = fe->dvb->priv; 964 struct saa7134_dev *dev = fe->dvb->priv;
@@ -921,7 +1006,7 @@ static struct tda1004x_config lifeview_trio_config = {
921 .invert = 1, 1006 .invert = 1,
922 .invert_oclk = 0, 1007 .invert_oclk = 0,
923 .xtal_freq = TDA10046_XTAL_16M, 1008 .xtal_freq = TDA10046_XTAL_16M,
924 .agc_config = TDA10046_AGC_TDA827X_GPL, 1009 .agc_config = TDA10046_AGC_TDA827X_GP00,
925 .if_freq = TDA10046_FREQ_045, 1010 .if_freq = TDA10046_FREQ_045,
926 .request_firmware = NULL, 1011 .request_firmware = NULL,
927}; 1012};
@@ -958,7 +1043,7 @@ static struct tda1004x_config ads_tech_duo_config = {
958 .invert = 1, 1043 .invert = 1,
959 .invert_oclk = 0, 1044 .invert_oclk = 0,
960 .xtal_freq = TDA10046_XTAL_16M, 1045 .xtal_freq = TDA10046_XTAL_16M,
961 .agc_config = TDA10046_AGC_TDA827X_GPL, 1046 .agc_config = TDA10046_AGC_TDA827X_GP00,
962 .if_freq = TDA10046_FREQ_045, 1047 .if_freq = TDA10046_FREQ_045,
963 .request_firmware = NULL, 1048 .request_firmware = NULL,
964}; 1049};
@@ -983,7 +1068,7 @@ static struct tda1004x_config tevion_dvbt220rf_config = {
983 .invert = 1, 1068 .invert = 1,
984 .invert_oclk = 0, 1069 .invert_oclk = 0,
985 .xtal_freq = TDA10046_XTAL_16M, 1070 .xtal_freq = TDA10046_XTAL_16M,
986 .agc_config = TDA10046_AGC_TDA827X, 1071 .agc_config = TDA10046_AGC_TDA827X_GP11,
987 .if_freq = TDA10046_FREQ_045, 1072 .if_freq = TDA10046_FREQ_045,
988 .request_firmware = NULL, 1073 .request_firmware = NULL,
989}; 1074};
@@ -1028,7 +1113,7 @@ static struct tda1004x_config md8800_dvbt_config = {
1028 .invert = 1, 1113 .invert = 1,
1029 .invert_oclk = 0, 1114 .invert_oclk = 0,
1030 .xtal_freq = TDA10046_XTAL_16M, 1115 .xtal_freq = TDA10046_XTAL_16M,
1031 .agc_config = TDA10046_AGC_TDA827X, 1116 .agc_config = TDA10046_AGC_TDA827X_GP11,
1032 .if_freq = TDA10046_FREQ_045, 1117 .if_freq = TDA10046_FREQ_045,
1033 .request_firmware = NULL, 1118 .request_firmware = NULL,
1034}; 1119};
@@ -1168,6 +1253,29 @@ static int dvb_init(struct saa7134_dev *dev)
1168 &philips_tiger_config, 1253 &philips_tiger_config,
1169 &dev->i2c_adap); 1254 &dev->i2c_adap);
1170 if (dev->dvb.frontend) { 1255 if (dev->dvb.frontend) {
1256 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1257 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1258 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep;
1259 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params;
1260 }
1261 break;
1262 case SAA7134_BOARD_PINNACLE_PCTV_310i:
1263 dev->dvb.frontend = dvb_attach(tda10046_attach,
1264 &pinnacle_pctv_310i_config,
1265 &dev->i2c_adap);
1266 if (dev->dvb.frontend) {
1267 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1268 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1269 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep;
1270 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params;
1271 }
1272 break;
1273 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
1274 dev->dvb.frontend = dvb_attach(tda10046_attach,
1275 &hauppauge_hvr_1110_config,
1276 &dev->i2c_adap);
1277 if (dev->dvb.frontend) {
1278 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1171 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init; 1279 dev->dvb.frontend->ops.tuner_ops.init = philips_tiger_tuner_init;
1172 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep; 1280 dev->dvb.frontend->ops.tuner_ops.sleep = philips_tiger_tuner_sleep;
1173 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params; 1281 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params;
@@ -1175,9 +1283,10 @@ static int dvb_init(struct saa7134_dev *dev)
1175 break; 1283 break;
1176 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 1284 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
1177 dev->dvb.frontend = dvb_attach(tda10046_attach, 1285 dev->dvb.frontend = dvb_attach(tda10046_attach,
1178 &philips_tiger_config, 1286 &asus_p7131_dual_config,
1179 &dev->i2c_adap); 1287 &dev->i2c_adap);
1180 if (dev->dvb.frontend) { 1288 if (dev->dvb.frontend) {
1289 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1181 dev->dvb.frontend->ops.tuner_ops.init = asus_p7131_dual_tuner_init; 1290 dev->dvb.frontend->ops.tuner_ops.init = asus_p7131_dual_tuner_init;
1182 dev->dvb.frontend->ops.tuner_ops.sleep = asus_p7131_dual_tuner_sleep; 1291 dev->dvb.frontend->ops.tuner_ops.sleep = asus_p7131_dual_tuner_sleep;
1183 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params; 1292 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params;
@@ -1194,12 +1303,27 @@ static int dvb_init(struct saa7134_dev *dev)
1194 } 1303 }
1195 break; 1304 break;
1196 case SAA7134_BOARD_FLYDVB_TRIO: 1305 case SAA7134_BOARD_FLYDVB_TRIO:
1197 dev->dvb.frontend = dvb_attach(tda10046_attach, 1306 if(! use_frontent) { //terrestrial
1198 &lifeview_trio_config, 1307 dev->dvb.frontend = dvb_attach(tda10046_attach,
1199 &dev->i2c_adap); 1308 &lifeview_trio_config,
1200 if (dev->dvb.frontend) { 1309 &dev->i2c_adap);
1201 dev->dvb.frontend->ops.tuner_ops.sleep = lifeview_trio_tuner_sleep; 1310 if (dev->dvb.frontend) {
1202 dev->dvb.frontend->ops.tuner_ops.set_params = lifeview_trio_tuner_set_params; 1311 dev->dvb.frontend->ops.tuner_ops.sleep = lifeview_trio_tuner_sleep;
1312 dev->dvb.frontend->ops.tuner_ops.set_params =
1313 lifeview_trio_tuner_set_params;
1314 }
1315 } else { //satellite
1316 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
1317 if (dev->dvb.frontend) {
1318 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
1319 &dev->i2c_adap, 0) == NULL) {
1320 printk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__);
1321 }
1322 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
1323 0x08, 0, 0) == NULL) {
1324 printk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__);
1325 }
1326 }
1203 } 1327 }
1204 break; 1328 break;
1205 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331: 1329 case SAA7134_BOARD_ADS_DUO_CARDBUS_PTV331:
@@ -1281,7 +1405,27 @@ static int dvb_init(struct saa7134_dev *dev)
1281 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params; 1405 dev->dvb.frontend->ops.tuner_ops.set_params = philips_fmd1216_tuner_set_params;
1282 } 1406 }
1283 break; 1407 break;
1408 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
1409 dev->dvb.frontend = dvb_attach(tda10046_attach,
1410 &philips_europa_config,
1411 &dev->i2c_adap);
1412 if (dev->dvb.frontend) {
1413 dev->dvb.frontend->ops.tuner_ops.init = philips_td1316_tuner_init;
1414 dev->dvb.frontend->ops.tuner_ops.set_params = philips_td1316_tuner_set_params;
1415 }
1416 break;
1417 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1418 dev->dvb.frontend = dvb_attach(tda10046_attach,
1419 &cinergy_ht_config,
1420 &dev->i2c_adap);
1421 if (dev->dvb.frontend) {
1422 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
1423 dev->dvb.frontend->ops.tuner_ops.init = cinergy_ht_tuner_init;
1424 dev->dvb.frontend->ops.tuner_ops.sleep = cinergy_ht_tuner_sleep;
1425 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tiger_tuner_set_params;
1284 1426
1427 }
1428 break;
1285 default: 1429 default:
1286 printk("%s: Huh? unknown DVB card?\n",dev->name); 1430 printk("%s: Huh? unknown DVB card?\n",dev->name);
1287 break; 1431 break;
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 6162550c4136..6f9fe86fed98 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -341,6 +341,7 @@ static int attach_inform(struct i2c_client *client)
341 switch (client->addr) { 341 switch (client->addr) {
342 case 0x7a: 342 case 0x7a:
343 case 0x47: 343 case 0x47:
344 case 0x71:
344 { 345 {
345 struct IR_i2c *ir = i2c_get_clientdata(client); 346 struct IR_i2c *ir = i2c_get_clientdata(client);
346 d1printk("%s i2c IR detected (%s).\n", 347 d1printk("%s i2c IR detected (%s).\n",
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index dee83552e681..60b38defd9bc 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -112,6 +112,27 @@ static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
112 return 1; 112 return 1;
113} 113}
114 114
115static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
116{
117 unsigned char buf[5], cod4, code3, code4;
118
119 /* poll IR chip */
120 if (5 != i2c_master_recv(&ir->c,buf,5))
121 return -EIO;
122
123 cod4 = buf[4];
124 code4 = (cod4 >> 2);
125 code3 = buf[3];
126 if (code3 == 0)
127 /* no key pressed */
128 return 0;
129
130 /* return key */
131 *ir_key = code4;
132 *ir_raw = code4;
133 return 1;
134}
135
115void saa7134_input_irq(struct saa7134_dev *dev) 136void saa7134_input_irq(struct saa7134_dev *dev)
116{ 137{
117 struct saa7134_ir *ir = dev->remote; 138 struct saa7134_ir *ir = dev->remote;
@@ -131,6 +152,23 @@ static void saa7134_input_timer(unsigned long data)
131 mod_timer(&ir->timer, timeout); 152 mod_timer(&ir->timer, timeout);
132} 153}
133 154
155static void saa7134_ir_start(struct saa7134_dev *dev, struct saa7134_ir *ir)
156{
157 if (ir->polling) {
158 init_timer(&ir->timer);
159 ir->timer.function = saa7134_input_timer;
160 ir->timer.data = (unsigned long)dev;
161 ir->timer.expires = jiffies + HZ;
162 add_timer(&ir->timer);
163 }
164}
165
166static void saa7134_ir_stop(struct saa7134_dev *dev)
167{
168 if (dev->remote->polling)
169 del_timer_sync(&dev->remote->timer);
170}
171
134int saa7134_input_init1(struct saa7134_dev *dev) 172int saa7134_input_init1(struct saa7134_dev *dev)
135{ 173{
136 struct saa7134_ir *ir; 174 struct saa7134_ir *ir;
@@ -141,6 +179,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
141 u32 mask_keyup = 0; 179 u32 mask_keyup = 0;
142 int polling = 0; 180 int polling = 0;
143 int ir_type = IR_TYPE_OTHER; 181 int ir_type = IR_TYPE_OTHER;
182 int err;
144 183
145 if (dev->has_remote != SAA7134_REMOTE_GPIO) 184 if (dev->has_remote != SAA7134_REMOTE_GPIO)
146 return -ENODEV; 185 return -ENODEV;
@@ -184,6 +223,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
184 case SAA7134_BOARD_AVERMEDIA_307: 223 case SAA7134_BOARD_AVERMEDIA_307:
185 case SAA7134_BOARD_AVERMEDIA_STUDIO_305: 224 case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
186 case SAA7134_BOARD_AVERMEDIA_STUDIO_307: 225 case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
226 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
187 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 227 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
188 ir_codes = ir_codes_avermedia; 228 ir_codes = ir_codes_avermedia;
189 mask_keycode = 0x0007C8; 229 mask_keycode = 0x0007C8;
@@ -266,9 +306,8 @@ int saa7134_input_init1(struct saa7134_dev *dev)
266 ir = kzalloc(sizeof(*ir), GFP_KERNEL); 306 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
267 input_dev = input_allocate_device(); 307 input_dev = input_allocate_device();
268 if (!ir || !input_dev) { 308 if (!ir || !input_dev) {
269 kfree(ir); 309 err = -ENOMEM;
270 input_free_device(input_dev); 310 goto err_out_free;
271 return -ENOMEM;
272 } 311 }
273 312
274 ir->dev = input_dev; 313 ir->dev = input_dev;
@@ -299,18 +338,22 @@ int saa7134_input_init1(struct saa7134_dev *dev)
299 } 338 }
300 input_dev->cdev.dev = &dev->pci->dev; 339 input_dev->cdev.dev = &dev->pci->dev;
301 340
302 /* all done */
303 dev->remote = ir; 341 dev->remote = ir;
304 if (ir->polling) { 342 saa7134_ir_start(dev, ir);
305 init_timer(&ir->timer); 343
306 ir->timer.function = saa7134_input_timer; 344 err = input_register_device(ir->dev);
307 ir->timer.data = (unsigned long)dev; 345 if (err)
308 ir->timer.expires = jiffies + HZ; 346 goto err_out_stop;
309 add_timer(&ir->timer);
310 }
311 347
312 input_register_device(ir->dev);
313 return 0; 348 return 0;
349
350 err_out_stop:
351 saa7134_ir_stop(dev);
352 dev->remote = NULL;
353 err_out_free:
354 input_free_device(input_dev);
355 kfree(ir);
356 return err;
314} 357}
315 358
316void saa7134_input_fini(struct saa7134_dev *dev) 359void saa7134_input_fini(struct saa7134_dev *dev)
@@ -318,8 +361,7 @@ void saa7134_input_fini(struct saa7134_dev *dev)
318 if (NULL == dev->remote) 361 if (NULL == dev->remote)
319 return; 362 return;
320 363
321 if (dev->remote->polling) 364 saa7134_ir_stop(dev);
322 del_timer_sync(&dev->remote->timer);
323 input_unregister_device(dev->remote->dev); 365 input_unregister_device(dev->remote->dev);
324 kfree(dev->remote); 366 kfree(dev->remote);
325 dev->remote = NULL; 367 dev->remote = NULL;
@@ -335,6 +377,7 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
335 377
336 switch (dev->board) { 378 switch (dev->board) {
337 case SAA7134_BOARD_PINNACLE_PCTV_110i: 379 case SAA7134_BOARD_PINNACLE_PCTV_110i:
380 case SAA7134_BOARD_PINNACLE_PCTV_310i:
338 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV"); 381 snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
339 if (pinnacle_remote == 0) { 382 if (pinnacle_remote == 0) {
340 ir->get_key = get_key_pinnacle_color; 383 ir->get_key = get_key_pinnacle_color;
@@ -349,6 +392,11 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
349 ir->get_key = get_key_purpletv; 392 ir->get_key = get_key_purpletv;
350 ir->ir_codes = ir_codes_purpletv; 393 ir->ir_codes = ir_codes_purpletv;
351 break; 394 break;
395 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
396 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
397 ir->get_key = get_key_hvr1110;
398 ir->ir_codes = ir_codes_hauppauge_new;
399 break;
352 default: 400 default:
353 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board); 401 dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
354 break; 402 break;
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 7cf96b430250..e88ad7b40c47 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -227,6 +227,11 @@ struct saa7134_format {
227#define SAA7134_BOARD_PROTEUS_2309 98 227#define SAA7134_BOARD_PROTEUS_2309 98
228#define SAA7134_BOARD_AVERMEDIA_A16AR 99 228#define SAA7134_BOARD_AVERMEDIA_A16AR 99
229#define SAA7134_BOARD_ASUS_EUROPA2_HYBRID 100 229#define SAA7134_BOARD_ASUS_EUROPA2_HYBRID 100
230#define SAA7134_BOARD_PINNACLE_PCTV_310i 101
231#define SAA7134_BOARD_AVERMEDIA_STUDIO_507 102
232#define SAA7134_BOARD_VIDEOMATE_DVBT_200A 103
233#define SAA7134_BOARD_HAUPPAUGE_HVR1110 104
234#define SAA7134_BOARD_CINERGY_HT_PCMCIA 105
230 235
231#define SAA7134_MAXBOARDS 8 236#define SAA7134_MAXBOARDS 8
232#define SAA7134_INPUT_MAX 8 237#define SAA7134_INPUT_MAX 8
@@ -446,6 +451,9 @@ struct saa7134_dev {
446 struct v4l2_prio_state prio; 451 struct v4l2_prio_state prio;
447#endif 452#endif
448 453
454 /* insmod option/autodetected */
455 int autodetected;
456
449 /* various device info */ 457 /* various device info */
450 unsigned int resources; 458 unsigned int resources;
451 struct video_device *video_dev; 459 struct video_device *video_dev;
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index 6d1ef1e2e8ef..a1ec3aca3f91 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -687,7 +687,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
687 stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL); 687 stv680->sbuf[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
688 if (stv680->sbuf[i].data == NULL) { 688 if (stv680->sbuf[i].data == NULL) {
689 PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i); 689 PDEBUG (0, "STV(e): Could not kmalloc raw data buffer %i", i);
690 return -1; 690 goto nomem_err;
691 } 691 }
692 } 692 }
693 693
@@ -698,7 +698,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
698 stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL); 698 stv680->scratch[i].data = kmalloc (stv680->rawbufsize, GFP_KERNEL);
699 if (stv680->scratch[i].data == NULL) { 699 if (stv680->scratch[i].data == NULL) {
700 PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i); 700 PDEBUG (0, "STV(e): Could not kmalloc raw scratch buffer %i", i);
701 return -1; 701 goto nomem_err;
702 } 702 }
703 stv680->scratch[i].state = BUFFER_UNUSED; 703 stv680->scratch[i].state = BUFFER_UNUSED;
704 } 704 }
@@ -706,7 +706,7 @@ static int stv680_start_stream (struct usb_stv *stv680)
706 for (i = 0; i < STV680_NUMSBUF; i++) { 706 for (i = 0; i < STV680_NUMSBUF; i++) {
707 urb = usb_alloc_urb (0, GFP_KERNEL); 707 urb = usb_alloc_urb (0, GFP_KERNEL);
708 if (!urb) 708 if (!urb)
709 return -ENOMEM; 709 goto nomem_err;
710 710
711 /* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */ 711 /* sbuf is urb->transfer_buffer, later gets memcpyed to scratch */
712 usb_fill_bulk_urb (urb, stv680->udev, 712 usb_fill_bulk_urb (urb, stv680->udev,
@@ -721,6 +721,21 @@ static int stv680_start_stream (struct usb_stv *stv680)
721 721
722 stv680->framecount = 0; 722 stv680->framecount = 0;
723 return 0; 723 return 0;
724
725 nomem_err:
726 for (i = 0; i < STV680_NUMSCRATCH; i++) {
727 kfree(stv680->scratch[i].data);
728 stv680->scratch[i].data = NULL;
729 }
730 for (i = 0; i < STV680_NUMSBUF; i++) {
731 usb_kill_urb(stv680->urb[i]);
732 usb_free_urb(stv680->urb[i]);
733 stv680->urb[i] = NULL;
734 kfree(stv680->sbuf[i].data);
735 stv680->sbuf[i].data = NULL;
736 }
737 return -ENOMEM;
738
724} 739}
725 740
726static int stv680_stop_stream (struct usb_stv *stv680) 741static int stv680_stop_stream (struct usb_stv *stv680)
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 87ffb0e84a7a..fde576f1101c 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -482,6 +482,12 @@ static int tda9887_set_config(struct tuner *t, char *buf)
482 buf[1] &= ~cQSS; 482 buf[1] &= ~cQSS;
483 if (t->tda9887_config & TDA9887_GATING_18) 483 if (t->tda9887_config & TDA9887_GATING_18)
484 buf[3] &= ~cGating_36; 484 buf[3] &= ~cGating_36;
485
486 if (t->tda9887_config & TDA9887_GAIN_NORMAL) {
487 radio_stereo.e &= ~cTunerGainLow;
488 radio_mono.e &= ~cTunerGainLow;
489 }
490
485 return 0; 491 return 0;
486} 492}
487 493
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 40590bae5ff7..705daaa2a4ff 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -443,6 +443,10 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
443 printk("%02x ",buffer[i]); 443 printk("%02x ",buffer[i]);
444 printk("\n"); 444 printk("\n");
445 } 445 }
446 /* HACK: This test were added to avoid tuner to probe tda9840 and tea6415c on the MXB card */
447 if (adap->id == I2C_HW_SAA7146 && addr < 0x4a)
448 return -ENODEV;
449
446 /* autodetection code based on the i2c addr */ 450 /* autodetection code based on the i2c addr */
447 if (!no_autodetect) { 451 if (!no_autodetect) {
448 switch (addr) { 452 switch (addr) {
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 63db4e97ae6c..1b9b0742f753 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -108,6 +108,7 @@ static int tuner_stereo(struct i2c_client *c)
108 case TUNER_PHILIPS_FM1216ME_MK3: 108 case TUNER_PHILIPS_FM1216ME_MK3:
109 case TUNER_PHILIPS_FM1236_MK3: 109 case TUNER_PHILIPS_FM1236_MK3:
110 case TUNER_PHILIPS_FM1256_IH3: 110 case TUNER_PHILIPS_FM1256_IH3:
111 case TUNER_LG_NTSC_TAPE:
111 stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 112 stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
112 break; 113 break;
113 default: 114 default:
@@ -421,6 +422,7 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
421 case TUNER_PHILIPS_FM1216ME_MK3: 422 case TUNER_PHILIPS_FM1216ME_MK3:
422 case TUNER_PHILIPS_FM1236_MK3: 423 case TUNER_PHILIPS_FM1236_MK3:
423 case TUNER_PHILIPS_FMD1216ME_MK3: 424 case TUNER_PHILIPS_FMD1216ME_MK3:
425 case TUNER_LG_NTSC_TAPE:
424 buffer[3] = 0x19; 426 buffer[3] = 0x19;
425 break; 427 break;
426 case TUNER_TNF_5335MF: 428 case TUNER_TNF_5335MF:
@@ -465,6 +467,8 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
465 config |= TDA9887_INTERCARRIER; 467 config |= TDA9887_INTERCARRIER;
466/* if (params->port1_set_for_fm_mono) 468/* if (params->port1_set_for_fm_mono)
467 config &= ~TDA9887_PORT1_ACTIVE;*/ 469 config &= ~TDA9887_PORT1_ACTIVE;*/
470 if (params->fm_gain_normal)
471 config |= TDA9887_GAIN_NORMAL;
468 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); 472 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config);
469 } 473 }
470 if (4 != (rc = i2c_master_send(c,buffer,4))) 474 if (4 != (rc = i2c_master_send(c,buffer,4)))
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 781682373b61..74c3e6f96f1a 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -651,6 +651,7 @@ static struct tuner_params tuner_microtune_4049_fm5_params[] = {
651 .has_tda9887 = 1, 651 .has_tda9887 = 1,
652 .port1_invert_for_secam_lc = 1, 652 .port1_invert_for_secam_lc = 1,
653 .default_pll_gating_18 = 1, 653 .default_pll_gating_18 = 1,
654 .fm_gain_normal=1,
654 }, 655 },
655}; 656};
656 657
@@ -672,16 +673,6 @@ static struct tuner_params tuner_panasonic_vp27_params[] = {
672 }, 673 },
673}; 674};
674 675
675/* ------------ TUNER_LG_NTSC_TAPE - LGINNOTEK NTSC ------------ */
676
677static struct tuner_params tuner_lg_ntsc_tape_params[] = {
678 {
679 .type = TUNER_PARAM_TYPE_NTSC,
680 .ranges = tuner_fm1236_mk3_ntsc_ranges,
681 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
682 },
683};
684
685/* ------------ TUNER_TNF_8831BGFF - Philips PAL ------------ */ 676/* ------------ TUNER_TNF_8831BGFF - Philips PAL ------------ */
686 677
687static struct tuner_range tuner_tnf_8831bgff_pal_ranges[] = { 678static struct tuner_range tuner_tnf_8831bgff_pal_ranges[] = {
@@ -1331,8 +1322,8 @@ struct tunertype tuners[] = {
1331 }, 1322 },
1332 [TUNER_LG_NTSC_TAPE] = { /* LGINNOTEK NTSC */ 1323 [TUNER_LG_NTSC_TAPE] = { /* LGINNOTEK NTSC */
1333 .name = "LG NTSC (TAPE series)", 1324 .name = "LG NTSC (TAPE series)",
1334 .params = tuner_lg_ntsc_tape_params, 1325 .params = tuner_fm1236_mk3_params,
1335 .count = ARRAY_SIZE(tuner_lg_ntsc_tape_params), 1326 .count = ARRAY_SIZE(tuner_fm1236_mk3_params),
1336 }, 1327 },
1337 [TUNER_TNF_8831BGFF] = { /* Philips PAL */ 1328 [TUNER_TNF_8831BGFF] = { /* Philips PAL */
1338 .name = "Tenna TNF 8831 BGFF)", 1329 .name = "Tenna TNF 8831 BGFF)",
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 6b9ef731b83a..2624e3f7dd29 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -430,7 +430,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
430 tvee->has_radio = eeprom_data[i+len-1]; 430 tvee->has_radio = eeprom_data[i+len-1];
431 /* old style tag, don't know how to detect 431 /* old style tag, don't know how to detect
432 IR presence, mark as unknown. */ 432 IR presence, mark as unknown. */
433 tvee->has_ir = 2; 433 tvee->has_ir = -1;
434 tvee->model = 434 tvee->model =
435 eeprom_data[i+8] + 435 eeprom_data[i+8] +
436 (eeprom_data[i+9] << 8); 436 (eeprom_data[i+9] << 8);
@@ -653,13 +653,14 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
653 STRM(decoderIC, tvee->decoder_processor), 653 STRM(decoderIC, tvee->decoder_processor),
654 tvee->decoder_processor); 654 tvee->decoder_processor);
655 } 655 }
656 if (tvee->has_ir == 2) 656 if (tvee->has_ir == -1)
657 tveeprom_info("has %sradio\n", 657 tveeprom_info("has %sradio\n",
658 tvee->has_radio ? "" : "no "); 658 tvee->has_radio ? "" : "no ");
659 else 659 else
660 tveeprom_info("has %sradio, has %sIR remote\n", 660 tveeprom_info("has %sradio, has %sIR receiver, has %sIR transmitter\n",
661 tvee->has_radio ? "" : "no ", 661 tvee->has_radio ? "" : "no ",
662 tvee->has_ir ? "" : "no "); 662 (tvee->has_ir & 1) ? "" : "no ",
663 (tvee->has_ir & 2) ? "" : "no ");
663} 664}
664EXPORT_SYMBOL(tveeprom_hauppauge_analog); 665EXPORT_SYMBOL(tveeprom_hauppauge_analog);
665 666
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
index bbf2beeeb449..ec0ff2247f06 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -86,6 +86,7 @@ MODULE_DEVICE_TABLE(usb, qcm_table);
86static void qcm_register_input(struct qcm *cam, struct usb_device *dev) 86static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
87{ 87{
88 struct input_dev *input_dev; 88 struct input_dev *input_dev;
89 int error;
89 90
90 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname)); 91 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
91 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname)); 92 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
@@ -106,7 +107,13 @@ static void qcm_register_input(struct qcm *cam, struct usb_device *dev)
106 107
107 input_dev->private = cam; 108 input_dev->private = cam;
108 109
109 input_register_device(cam->input); 110 error = input_register_device(cam->input);
111 if (error) {
112 warn("Failed to register camera's input device, err: %d\n",
113 error);
114 input_free_device(cam->input);
115 cam->input = NULL;
116 }
110} 117}
111 118
112static void qcm_unregister_input(struct qcm *cam) 119static void qcm_unregister_input(struct qcm *cam)
diff --git a/drivers/media/video/usbvision/Kconfig b/drivers/media/video/usbvision/Kconfig
new file mode 100644
index 000000000000..fc24ef05b3f3
--- /dev/null
+++ b/drivers/media/video/usbvision/Kconfig
@@ -0,0 +1,12 @@
1config VIDEO_USBVISION
2 tristate "USB video devices based on Nogatech NT1003/1004/1005"
3 depends on I2C && VIDEO_V4L2
4 select VIDEO_TUNER
5 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
6 ---help---
7 There are more than 50 different USB video devices based on
8 NT1003/1004/1005 USB Bridges. This driver enables using those
9 devices.
10
11 To compile this driver as a module, choose M here: the
12 module will be called usbvision.
diff --git a/drivers/media/video/usbvision/Makefile b/drivers/media/video/usbvision/Makefile
new file mode 100644
index 000000000000..9ac92a80c645
--- /dev/null
+++ b/drivers/media/video/usbvision/Makefile
@@ -0,0 +1,5 @@
1usbvision-objs := usbvision-core.o usbvision-video.o usbvision-i2c.o usbvision-cards.o
2
3obj-$(CONFIG_VIDEO_USBVISION) += usbvision.o
4
5EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
new file mode 100644
index 000000000000..134eb9865df6
--- /dev/null
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -0,0 +1,157 @@
1/*
2 * USBVISION.H
3 * usbvision header file
4 *
5 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 *
7 * This module is part of usbvision driver project.
8 * Updates to driver completed by Dwaine P. Garden
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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25
26#include <linux/list.h>
27#include <linux/i2c.h>
28#include <media/v4l2-dev.h>
29#include <media/tuner.h>
30#include "usbvision.h"
31
32/* Supported Devices: A table for usbvision.c*/
33struct usbvision_device_data_st usbvision_device_data[] = {
34 {0xFFF0, 0xFFF0, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Custom Dummy USBVision Device"},
35 {0x0A6F, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "Xanboo"},
36 {0x050D, 0x0208, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Belkin USBView II"},
37 {0x0571, 0x0002, 0, CODEC_SAA7111, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, -1, -1, 7, "echoFX InterView Lite"},
38 {0x0573, 0x0003, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "USBGear USBG-V1 resp. HAMA USB"},
39 {0x0573, 0x0400, -1, CODEC_SAA7113, 4, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "D-Link V100"},
40 {0x0573, 0x2000, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, -1, -1, -1, "X10 USB Camera"},
41 {0x0573, 0x2d00, -1, CODEC_SAA7111, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, -1, 3, 7, "Osprey 50"},
42 {0x0573, 0x2d01, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Hauppauge USB-Live Model 600"},
43 {0x0573, 0x2101, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 2, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Zoran Co. PMD (Nogatech) AV-grabber Manhattan"},
44 {0x0573, 0x4100, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Nogatech USB-TV (NTSC) FM"},
45 {0x0573, 0x4110, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "PNY USB-TV (NTSC) FM"},
46 {0x0573, 0x4450, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "PixelView PlayTv-USB PRO (PAL) FM"},
47 {0x0573, 0x4550, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "ZTV ZT-721 2.4GHz USB A/V Receiver"},
48 {0x0573, 0x4d00, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, 20, -1, "Hauppauge WinTv-USB USA"},
49 {0x0573, 0x4d01, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"},
50 {0x0573, 0x4d02, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB (NTSC)"},
51 {0x0573, 0x4d03, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB (SECAM) "},
52 {0x0573, 0x4d10, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB (NTSC) FM"},
53 {0x0573, 0x4d11, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB (PAL) FM"},
54 {0x0573, 0x4d12, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB (PAL) FM"},
55 {0x0573, 0x4d2a, 0, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_MICROTUNE_4049FM5, -1, -1, 0, 3, 7, "Hauppauge WinTv USB (NTSC) FM Model 602 40201 Rev B285"},
56 {0x0573, 0x4d2b, 0, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_MICROTUNE_4049FM5, -1, -1, 0, 3, 7, "Hauppauge WinTv USB (NTSC) FM Model 602 40201 Rev B282"},
57 {0x0573, 0x4d2c, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTv USB (PAL/SECAM) 40209 Rev E1A5"},
58 {0x0573, 0x4d20, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB II (PAL) FM Model 40201 Rev B226"},
59 {0x0573, 0x4d21, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB II (PAL)"},
60 {0x0573, 0x4d22, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB II (PAL) MODEL 566"},
61 {0x0573, 0x4d23, -1, CODEC_SAA7113, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB (SECAM) 4D23"},
62 {0x0573, 0x4d25, -1, CODEC_SAA7113, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB (SECAM) Model 40209 Rev B234"},
63 {0x0573, 0x4d26, -1, CODEC_SAA7113, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB (SECAM) Model 40209 Rev B243"},
64 {0x0573, 0x4d27, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_ALPS_TSBE1_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB Model 40204 Rev B281"},
65 {0x0573, 0x4d28, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_ALPS_TSBE1_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB Model 40204 Rev B283"},
66 {0x0573, 0x4d29, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB Model 40205 Rev B298"},
67 {0x0573, 0x4d30, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB FM Model 40211 Rev B123"},
68 {0x0573, 0x4d31, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB III (PAL) FM Model 568"},
69 {0x0573, 0x4d32, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB III (PAL) FM Model 573"},
70 {0x0573, 0x4d35, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_MICROTUNE_4049FM5, -1, -1, 0, 3, 7, "Hauppauge WinTv-USB III (PAL) FM Model 40219 Rev B252"},
71 {0x0573, 0x4d37, 0, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_FM1216ME_MK3, -1, -1, 0, 3, 7, "Hauppauge WinTV USB device Model 40219 Rev E189"},
72 {0x0768, 0x0006, -1, CODEC_SAA7113, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, 5, 5, -1, "Camtel Technology USB TV Genie Pro FM Model TVB330"},
73 {0x07d0, 0x0001, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Digital Video Creator I"},
74 {0x07d0, 0x0002, -1, CODEC_SAA7111, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 82, 20, 7, "Global Village GV-007 (NTSC)"},
75 {0x07d0, 0x0003, 0, CODEC_SAA7113, 2, V4L2_STD_NTSC, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-50 Rev 1 (NTSC)"},
76 {0x07d0, 0x0004, 0, CODEC_SAA7113, 2, V4L2_STD_PAL, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-80 Rev 1 (PAL)"},
77 {0x07d0, 0x0005, 0, CODEC_SAA7113, 2, V4L2_STD_SECAM, 0, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)"},
78 {0x2304, 0x010d, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 0, 1, TUNER_TEMIC_4066FY5_PAL_I, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (PAL)"},
79 {0x2304, 0x0109, -1, CODEC_SAA7111, 3, V4L2_STD_SECAM, 1, 0, 1, 1, TUNER_PHILIPS_SECAM, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (SECAM)"},
80 {0x2304, 0x0110, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_PHILIPS_PAL, -1, -1,128, 23, -1, "Pinnacle Studio PCTV USB (PAL) FM"},
81 {0x2304, 0x0111, -1, CODEC_SAA7111, 3, V4L2_STD_PAL, 1, 0, 1, 1, TUNER_PHILIPS_PAL, -1, -1, -1, -1, -1, "Miro PCTV USB"},
82 {0x2304, 0x0112, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Pinnacle Studio PCTV USB (NTSC) FM"},
83 {0x2304, 0x0210, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle Studio PCTV USB (PAL) FM"},
84 {0x2304, 0x0212, -1, CODEC_SAA7111, 3, V4L2_STD_NTSC, 1, 1, 1, 1, TUNER_TEMIC_4039FR5_NTSC, -1, -1, 0, 3, 7, "Pinnacle Studio PCTV USB (NTSC) FM"},
85 {0x2304, 0x0214, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle Studio PCTV USB (PAL) FM"},
86 {0x2304, 0x0300, -1, CODEC_SAA7113, 2, V4L2_STD_NTSC, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (NTSC)"},
87 {0x2304, 0x0301, -1, CODEC_SAA7113, 2, V4L2_STD_PAL, 1, 0, 1, 0, 0, -1, -1, 0, 3, 7, "Pinnacle Studio Linx Video input cable (PAL)"},
88 {0x2304, 0x0419, -1, CODEC_SAA7113, 3, V4L2_STD_PAL, 1, 1, 1, 1, TUNER_TEMIC_4009FR5_PAL, -1, -1, 0, 3, 7, "Pinnacle PCTV Bungee USB (PAL) FM"},
89 {0x2400, 0x4200, -1, CODEC_SAA7111, 3, VIDEO_MODE_NTSC, 1, 0, 1, 1, TUNER_PHILIPS_NTSC_M, -1, -1, -1, -1, -1, "Hauppauge WinTv-USB"},
90 {} /* Terminating entry */
91};
92
93/* Supported Devices */
94
95struct usb_device_id usbvision_table [] = {
96 { USB_DEVICE(0xFFF0, 0xFFF0) }, /* Custom Dummy USBVision Device */
97 { USB_DEVICE(0x0A6F, 0x0400) }, /* Xanboo */
98 { USB_DEVICE(0x050d, 0x0208) }, /* Belkin USBView II */
99 { USB_DEVICE(0x0571, 0x0002) }, /* echoFX InterView Lite */
100 { USB_DEVICE(0x0573, 0x0003) }, /* USBGear USBG-V1 */
101 { USB_DEVICE(0x0573, 0x0400) }, /* D-Link V100 */
102 { USB_DEVICE(0x0573, 0x2000) }, /* X10 USB Camera */
103 { USB_DEVICE(0x0573, 0x2d00) }, /* Osprey 50 */
104 { USB_DEVICE(0x0573, 0x2d01) }, /* Hauppauge USB-Live Model 600 */
105 { USB_DEVICE(0x0573, 0x2101) }, /* Zoran Co. PMD (Nogatech) AV-grabber Manhattan */
106 { USB_DEVICE(0x0573, 0x4100) }, /* Nogatech USB-TV FM (NTSC) */
107 { USB_DEVICE(0x0573, 0x4110) }, /* PNY USB-TV (NTSC) FM */
108 { USB_DEVICE(0x0573, 0x4450) }, /* PixelView PlayTv-USB PRO (PAL) FM */
109 { USB_DEVICE(0x0573, 0x4550) }, /* ZTV ZT-721 2.4GHz USB A/V Receiver */
110 { USB_DEVICE(0x0573, 0x4d00) }, /* Hauppauge WinTv-USB USA */
111 { USB_DEVICE(0x0573, 0x4d01) }, /* Hauppauge WinTv-USB */
112 { USB_DEVICE(0x0573, 0x4d02) }, /* Hauppauge WinTv-USB UK */
113 { USB_DEVICE(0x0573, 0x4d03) }, /* Hauppauge WinTv-USB France */
114 { USB_DEVICE(0x0573, 0x4d10) }, /* Hauppauge WinTv-USB with FM USA radio */
115 { USB_DEVICE(0x0573, 0x4d11) }, /* Hauppauge WinTv-USB (PAL) with FM radio */
116 { USB_DEVICE(0x0573, 0x4d12) }, /* Hauppauge WinTv-USB UK with FM Radio */
117 { USB_DEVICE(0x0573, 0x4d2a) }, /* Hauppague WinTv USB Model 602 40201 Rev B285 */
118 { USB_DEVICE(0x0573, 0x4d2b) }, /* Hauppague WinTv USB Model 602 40201 Rev B282 */
119 { USB_DEVICE(0x0573, 0x4d2c) }, /* Hauppague WinTv USB Model 40209 Rev. E1A5 PAL*/
120 { USB_DEVICE(0x0573, 0x4d20) }, /* Hauppauge WinTv-USB II (PAL) FM Model 40201 Rev B226 */
121 { USB_DEVICE(0x0573, 0x4d21) }, /* Hauppauge WinTv-USB II (PAL) with FM radio*/
122 { USB_DEVICE(0x0573, 0x4d22) }, /* Hauppauge WinTv-USB II (PAL) Model 566 */
123 { USB_DEVICE(0x0573, 0x4d23) }, /* Hauppauge WinTv-USB France 4D23*/
124 { USB_DEVICE(0x0573, 0x4d25) }, /* Hauppauge WinTv-USB Model 40209 rev B234 */
125 { USB_DEVICE(0x0573, 0x4d26) }, /* Hauppauge WinTv-USB Model 40209 Rev B243 */
126 { USB_DEVICE(0x0573, 0x4d27) }, /* Hauppauge WinTv-USB Model 40204 Rev B281 */
127 { USB_DEVICE(0x0573, 0x4d28) }, /* Hauppauge WinTv-USB Model 40204 Rev B283 */
128 { USB_DEVICE(0x0573, 0x4d29) }, /* Hauppauge WinTv-USB Model 40205 Rev B298 */
129 { USB_DEVICE(0x0573, 0x4d30) }, /* Hauppauge WinTv-USB FM Model 40211 Rev B123 */
130 { USB_DEVICE(0x0573, 0x4d31) }, /* Hauppauge WinTv-USB III (PAL) with FM radio Model 568 */
131 { USB_DEVICE(0x0573, 0x4d32) }, /* Hauppauge WinTv-USB III (PAL) FM Model 573 */
132 { USB_DEVICE(0x0573, 0x4d35) }, /* Hauppauge WinTv-USB III (SECAM) FM Model 40219 Rev B252 */
133 { USB_DEVICE(0x0573, 0x4d37) }, /* Hauppauge WinTv-USB Model 40219 Rev E189 */
134 { USB_DEVICE(0x0768, 0x0006) }, /* Camtel Technology USB TV Genie Pro FM Model TVB330 */
135 { USB_DEVICE(0x07d0, 0x0001) }, /* Digital Video Creator I */
136 { USB_DEVICE(0x07d0, 0x0002) }, /* Global Village GV-007 (NTSC) */
137 { USB_DEVICE(0x07d0, 0x0003) }, /* Dazzle Fusion Model DVC-50 Rev 1 (NTSC) */
138 { USB_DEVICE(0x07d0, 0x0004) }, /* Dazzle Fusion Model DVC-80 Rev 1 (PAL) */
139 { USB_DEVICE(0x07d0, 0x0005) }, /* Dazzle Fusion Model DVC-90 Rev 1 (SECAM) */
140 { USB_DEVICE(0x2304, 0x010d) }, /* Pinnacle Studio PCTV USB (PAL) */
141 { USB_DEVICE(0x2304, 0x0109) }, /* Pinnacle Studio PCTV USB (SECAM) */
142 { USB_DEVICE(0x2304, 0x0110) }, /* Pinnacle Studio PCTV USB (PAL) */
143 { USB_DEVICE(0x2304, 0x0111) }, /* Miro PCTV USB */
144 { USB_DEVICE(0x2304, 0x0112) }, /* Pinnacle Studio PCTV USB (NTSC) with FM radio */
145 { USB_DEVICE(0x2304, 0x0210) }, /* Pinnacle Studio PCTV USB (PAL) with FM radio */
146 { USB_DEVICE(0x2304, 0x0212) }, /* Pinnacle Studio PCTV USB (NTSC) with FM radio */
147 { USB_DEVICE(0x2304, 0x0214) }, /* Pinnacle Studio PCTV USB (PAL) with FM radio */
148 { USB_DEVICE(0x2304, 0x0300) }, /* Pinnacle Studio Linx Video input cable (NTSC) */
149 { USB_DEVICE(0x2304, 0x0301) }, /* Pinnacle Studio Linx Video input cable (PAL) */
150 { USB_DEVICE(0x2304, 0x0419) }, /* Pinnacle PCTV Bungee USB (PAL) FM */
151
152 { USB_DEVICE(0x2400, 0x4200) }, /* Hauppauge WinTv-USB2 Model 42012 */
153
154 { } /* Terminating entry */
155};
156
157MODULE_DEVICE_TABLE (usb, usbvision_table);
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
new file mode 100644
index 000000000000..797b97baf9ed
--- /dev/null
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -0,0 +1,2554 @@
1/*
2 * usbvision-core.c - driver for NT100x USB video capture devices
3 *
4 *
5 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 * Dwaine Garden <dwainegarden@rogers.com>
7 *
8 * This module is part of usbvision driver project.
9 * Updates to driver completed by Dwaine P. Garden
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
27#include <linux/sched.h>
28#include <linux/list.h>
29#include <linux/timer.h>
30#include <linux/slab.h>
31#include <linux/mm.h>
32#include <linux/utsname.h>
33#include <linux/highmem.h>
34#include <linux/smp_lock.h>
35#include <linux/videodev.h>
36#include <linux/vmalloc.h>
37#include <linux/module.h>
38#include <linux/init.h>
39#include <linux/spinlock.h>
40#include <asm/io.h>
41#include <linux/videodev2.h>
42#include <linux/video_decoder.h>
43#include <linux/i2c.h>
44
45#include <media/saa7115.h>
46#include <media/v4l2-common.h>
47#include <media/tuner.h>
48#include <media/audiochip.h>
49
50#include <linux/moduleparam.h>
51#include <linux/workqueue.h>
52
53#ifdef CONFIG_KMOD
54#include <linux/kmod.h>
55#endif
56
57#include "usbvision.h"
58
59static unsigned int core_debug = 0;
60module_param(core_debug,int,0644);
61MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
62
63static unsigned int force_testpattern = 0;
64module_param(force_testpattern,int,0644);
65MODULE_PARM_DESC(force_testpattern,"enable test pattern display [core]");
66
67static int adjustCompression = 1; // Set the compression to be adaptive
68module_param(adjustCompression, int, 0444);
69MODULE_PARM_DESC(adjustCompression, " Set the ADPCM compression for the device. Default: 1 (On)");
70
71static int SwitchSVideoInput = 0; // To help people with Black and White output with using s-video input. Some cables and input device are wired differently.
72module_param(SwitchSVideoInput, int, 0444);
73MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)");
74
75#define ENABLE_HEXDUMP 0 /* Enable if you need it */
76
77
78#ifdef USBVISION_DEBUG
79 #define PDEBUG(level, fmt, args...) \
80 if (core_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
81#else
82 #define PDEBUG(level, fmt, args...) do {} while(0)
83#endif
84
85#define DBG_HEADER 1<<0
86#define DBG_IRQ 1<<1
87#define DBG_ISOC 1<<2
88#define DBG_PARSE 1<<3
89#define DBG_SCRATCH 1<<4
90#define DBG_FUNC 1<<5
91
92static const int max_imgwidth = MAX_FRAME_WIDTH;
93static const int max_imgheight = MAX_FRAME_HEIGHT;
94static const int min_imgwidth = MIN_FRAME_WIDTH;
95static const int min_imgheight = MIN_FRAME_HEIGHT;
96
97/* The value of 'scratch_buf_size' affects quality of the picture
98 * in many ways. Shorter buffers may cause loss of data when client
99 * is too slow. Larger buffers are memory-consuming and take longer
100 * to work with. This setting can be adjusted, but the default value
101 * should be OK for most desktop users.
102 */
103#define DEFAULT_SCRATCH_BUF_SIZE (0x20000) // 128kB memory scratch buffer
104static const int scratch_buf_size = DEFAULT_SCRATCH_BUF_SIZE;
105
106// Function prototypes
107static int usbvision_request_intra (struct usb_usbvision *usbvision);
108static int usbvision_unrequest_intra (struct usb_usbvision *usbvision);
109static int usbvision_adjust_compression (struct usb_usbvision *usbvision);
110static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision);
111
112/*******************************/
113/* Memory management functions */
114/*******************************/
115
116/*
117 * Here we want the physical address of the memory.
118 * This is used when initializing the contents of the area.
119 */
120
121void *usbvision_rvmalloc(unsigned long size)
122{
123 void *mem;
124 unsigned long adr;
125
126 size = PAGE_ALIGN(size);
127 mem = vmalloc_32(size);
128 if (!mem)
129 return NULL;
130
131 memset(mem, 0, size); /* Clear the ram out, no junk to the user */
132 adr = (unsigned long) mem;
133 while (size > 0) {
134 SetPageReserved(vmalloc_to_page((void *)adr));
135 adr += PAGE_SIZE;
136 size -= PAGE_SIZE;
137 }
138
139 return mem;
140}
141
142void usbvision_rvfree(void *mem, unsigned long size)
143{
144 unsigned long adr;
145
146 if (!mem)
147 return;
148
149 size = PAGE_ALIGN(size);
150
151 adr = (unsigned long) mem;
152 while ((long) size > 0) {
153 ClearPageReserved(vmalloc_to_page((void *)adr));
154 adr += PAGE_SIZE;
155 size -= PAGE_SIZE;
156 }
157
158 vfree(mem);
159}
160
161
162
163#if ENABLE_HEXDUMP
164static void usbvision_hexdump(const unsigned char *data, int len)
165{
166 char tmp[80];
167 int i, k;
168
169 for (i = k = 0; len > 0; i++, len--) {
170 if (i > 0 && (i % 16 == 0)) {
171 printk("%s\n", tmp);
172 k = 0;
173 }
174 k += sprintf(&tmp[k], "%02x ", data[i]);
175 }
176 if (k > 0)
177 printk("%s\n", tmp);
178}
179#endif
180
181/********************************
182 * scratch ring buffer handling
183 ********************************/
184int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */
185{
186 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
187 if (len < 0) {
188 len += scratch_buf_size;
189 }
190 PDEBUG(DBG_SCRATCH, "scratch_len() = %d\n", len);
191
192 return len;
193}
194
195
196/* This returns the free space left in the buffer */
197int scratch_free(struct usb_usbvision *usbvision)
198{
199 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
200 if (free <= 0) {
201 free += scratch_buf_size;
202 }
203 if (free) {
204 free -= 1; /* at least one byte in the buffer must */
205 /* left blank, otherwise there is no chance to differ between full and empty */
206 }
207 PDEBUG(DBG_SCRATCH, "return %d\n", free);
208
209 return free;
210}
211
212
213/* This puts data into the buffer */
214int scratch_put(struct usb_usbvision *usbvision, unsigned char *data, int len)
215{
216 int len_part;
217
218 if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
219 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
220 usbvision->scratch_write_ptr += len;
221 }
222 else {
223 len_part = scratch_buf_size - usbvision->scratch_write_ptr;
224 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part);
225 if (len == len_part) {
226 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */
227 }
228 else {
229 memcpy(usbvision->scratch, data + len_part, len - len_part);
230 usbvision->scratch_write_ptr = len - len_part;
231 }
232 }
233
234 PDEBUG(DBG_SCRATCH, "len=%d, new write_ptr=%d\n", len, usbvision->scratch_write_ptr);
235
236 return len;
237}
238
239/* This marks the write_ptr as position of new frame header */
240void scratch_mark_header(struct usb_usbvision *usbvision)
241{
242 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
243
244 usbvision->scratch_headermarker[usbvision->scratch_headermarker_write_ptr] =
245 usbvision->scratch_write_ptr;
246 usbvision->scratch_headermarker_write_ptr += 1;
247 usbvision->scratch_headermarker_write_ptr %= USBVISION_NUM_HEADERMARKER;
248}
249
250/* This gets data from the buffer at the given "ptr" position */
251int scratch_get_extra(struct usb_usbvision *usbvision, unsigned char *data, int *ptr, int len)
252{
253 int len_part;
254 if (*ptr + len < scratch_buf_size) {
255 memcpy(data, usbvision->scratch + *ptr, len);
256 *ptr += len;
257 }
258 else {
259 len_part = scratch_buf_size - *ptr;
260 memcpy(data, usbvision->scratch + *ptr, len_part);
261 if (len == len_part) {
262 *ptr = 0; /* just set the y_ptr to zero */
263 }
264 else {
265 memcpy(data + len_part, usbvision->scratch, len - len_part);
266 *ptr = len - len_part;
267 }
268 }
269
270 PDEBUG(DBG_SCRATCH, "len=%d, new ptr=%d\n", len, *ptr);
271
272 return len;
273}
274
275
276/* This sets the scratch extra read pointer */
277void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr, int len)
278{
279 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size;
280
281 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
282}
283
284
285/*This increments the scratch extra read pointer */
286void scratch_inc_extra_ptr(int *ptr, int len)
287{
288 *ptr = (*ptr + len) % scratch_buf_size;
289
290 PDEBUG(DBG_SCRATCH, "ptr=%d\n", *ptr);
291}
292
293
294/* This gets data from the buffer */
295int scratch_get(struct usb_usbvision *usbvision, unsigned char *data, int len)
296{
297 int len_part;
298 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
299 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
300 usbvision->scratch_read_ptr += len;
301 }
302 else {
303 len_part = scratch_buf_size - usbvision->scratch_read_ptr;
304 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part);
305 if (len == len_part) {
306 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */
307 }
308 else {
309 memcpy(data + len_part, usbvision->scratch, len - len_part);
310 usbvision->scratch_read_ptr = len - len_part;
311 }
312 }
313
314 PDEBUG(DBG_SCRATCH, "len=%d, new read_ptr=%d\n", len, usbvision->scratch_read_ptr);
315
316 return len;
317}
318
319
320/* This sets read pointer to next header and returns it */
321int scratch_get_header(struct usb_usbvision *usbvision,struct usbvision_frame_header *header)
322{
323 int errCode = 0;
324
325 PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr);
326
327 while (usbvision->scratch_headermarker_write_ptr -
328 usbvision->scratch_headermarker_read_ptr != 0) {
329 usbvision->scratch_read_ptr =
330 usbvision->scratch_headermarker[usbvision->scratch_headermarker_read_ptr];
331 usbvision->scratch_headermarker_read_ptr += 1;
332 usbvision->scratch_headermarker_read_ptr %= USBVISION_NUM_HEADERMARKER;
333 scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH);
334 if ((header->magic_1 == USBVISION_MAGIC_1)
335 && (header->magic_2 == USBVISION_MAGIC_2)
336 && (header->headerLength == USBVISION_HEADER_LENGTH)) {
337 errCode = USBVISION_HEADER_LENGTH;
338 header->frameWidth = header->frameWidthLo + (header->frameWidthHi << 8);
339 header->frameHeight = header->frameHeightLo + (header->frameHeightHi << 8);
340 break;
341 }
342 }
343
344 return errCode;
345}
346
347
348/*This removes len bytes of old data from the buffer */
349void scratch_rm_old(struct usb_usbvision *usbvision, int len)
350{
351
352 usbvision->scratch_read_ptr += len;
353 usbvision->scratch_read_ptr %= scratch_buf_size;
354 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr);
355}
356
357
358/*This resets the buffer - kills all data in it too */
359void scratch_reset(struct usb_usbvision *usbvision)
360{
361 PDEBUG(DBG_SCRATCH, "\n");
362
363 usbvision->scratch_read_ptr = 0;
364 usbvision->scratch_write_ptr = 0;
365 usbvision->scratch_headermarker_read_ptr = 0;
366 usbvision->scratch_headermarker_write_ptr = 0;
367 usbvision->isocstate = IsocState_NoFrame;
368}
369
370int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
371{
372 usbvision->scratch = vmalloc(scratch_buf_size);
373 scratch_reset(usbvision);
374 if(usbvision->scratch == NULL) {
375 err("%s: unable to allocate %d bytes for scratch",
376 __FUNCTION__, scratch_buf_size);
377 return -ENOMEM;
378 }
379 return 0;
380}
381
382void usbvision_scratch_free(struct usb_usbvision *usbvision)
383{
384 if (usbvision->scratch != NULL) {
385 vfree(usbvision->scratch);
386 usbvision->scratch = NULL;
387 }
388}
389
390/*
391 * usbvision_testpattern()
392 *
393 * Procedure forms a test pattern (yellow grid on blue background).
394 *
395 * Parameters:
396 * fullframe: if TRUE then entire frame is filled, otherwise the procedure
397 * continues from the current scanline.
398 * pmode 0: fill the frame with solid blue color (like on VCR or TV)
399 * 1: Draw a colored grid
400 *
401 */
402void usbvision_testpattern(struct usb_usbvision *usbvision, int fullframe,
403 int pmode)
404{
405 static const char proc[] = "usbvision_testpattern";
406 struct usbvision_frame *frame;
407 unsigned char *f;
408 int num_cell = 0;
409 int scan_length = 0;
410 static int num_pass = 0;
411
412 if (usbvision == NULL) {
413 printk(KERN_ERR "%s: usbvision == NULL\n", proc);
414 return;
415 }
416 if (usbvision->curFrame == NULL) {
417 printk(KERN_ERR "%s: usbvision->curFrame is NULL.\n", proc);
418 return;
419 }
420
421 /* Grab the current frame */
422 frame = usbvision->curFrame;
423
424 /* Optionally start at the beginning */
425 if (fullframe) {
426 frame->curline = 0;
427 frame->scanlength = 0;
428 }
429
430 /* Form every scan line */
431 for (; frame->curline < frame->frmheight; frame->curline++) {
432 int i;
433
434 f = frame->data + (usbvision->curwidth * 3 * frame->curline);
435 for (i = 0; i < usbvision->curwidth; i++) {
436 unsigned char cb = 0x80;
437 unsigned char cg = 0;
438 unsigned char cr = 0;
439
440 if (pmode == 1) {
441 if (frame->curline % 32 == 0)
442 cb = 0, cg = cr = 0xFF;
443 else if (i % 32 == 0) {
444 if (frame->curline % 32 == 1)
445 num_cell++;
446 cb = 0, cg = cr = 0xFF;
447 } else {
448 cb =
449 ((num_cell * 7) +
450 num_pass) & 0xFF;
451 cg =
452 ((num_cell * 5) +
453 num_pass * 2) & 0xFF;
454 cr =
455 ((num_cell * 3) +
456 num_pass * 3) & 0xFF;
457 }
458 } else {
459 /* Just the blue screen */
460 }
461
462 *f++ = cb;
463 *f++ = cg;
464 *f++ = cr;
465 scan_length += 3;
466 }
467 }
468
469 frame->grabstate = FrameState_Done;
470 frame->scanlength += scan_length;
471 ++num_pass;
472
473}
474
475/*
476 * usbvision_decompress_alloc()
477 *
478 * allocates intermediate buffer for decompression
479 */
480int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
481{
482 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
483 usbvision->IntraFrameBuffer = vmalloc(IFB_size);
484 if (usbvision->IntraFrameBuffer == NULL) {
485 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size);
486 return -ENOMEM;
487 }
488 return 0;
489}
490
491/*
492 * usbvision_decompress_free()
493 *
494 * frees intermediate buffer for decompression
495 */
496void usbvision_decompress_free(struct usb_usbvision *usbvision)
497{
498 if (usbvision->IntraFrameBuffer != NULL) {
499 vfree(usbvision->IntraFrameBuffer);
500 usbvision->IntraFrameBuffer = NULL;
501 }
502}
503
504/************************************************************
505 * Here comes the data parsing stuff that is run as interrupt
506 ************************************************************/
507/*
508 * usbvision_find_header()
509 *
510 * Locate one of supported header markers in the scratch buffer.
511 */
512static enum ParseState usbvision_find_header(struct usb_usbvision *usbvision)
513{
514 struct usbvision_frame *frame;
515 int foundHeader = 0;
516
517 frame = usbvision->curFrame;
518
519 while (scratch_get_header(usbvision, &frame->isocHeader) == USBVISION_HEADER_LENGTH) {
520 // found header in scratch
521 PDEBUG(DBG_HEADER, "found header: 0x%02x%02x %d %d %d %d %#x 0x%02x %u %u",
522 frame->isocHeader.magic_2,
523 frame->isocHeader.magic_1,
524 frame->isocHeader.headerLength,
525 frame->isocHeader.frameNum,
526 frame->isocHeader.framePhase,
527 frame->isocHeader.frameLatency,
528 frame->isocHeader.dataFormat,
529 frame->isocHeader.formatParam,
530 frame->isocHeader.frameWidth,
531 frame->isocHeader.frameHeight);
532
533 if (usbvision->requestIntra) {
534 if (frame->isocHeader.formatParam & 0x80) {
535 foundHeader = 1;
536 usbvision->lastIsocFrameNum = -1; // do not check for lost frames this time
537 usbvision_unrequest_intra(usbvision);
538 break;
539 }
540 }
541 else {
542 foundHeader = 1;
543 break;
544 }
545 }
546
547 if (foundHeader) {
548 frame->frmwidth = frame->isocHeader.frameWidth * usbvision->stretch_width;
549 frame->frmheight = frame->isocHeader.frameHeight * usbvision->stretch_height;
550 frame->v4l2_linesize = (frame->frmwidth * frame->v4l2_format.depth)>> 3;
551 }
552 else { // no header found
553 PDEBUG(DBG_HEADER, "skipping scratch data, no header");
554 scratch_reset(usbvision);
555 return ParseState_EndParse;
556 }
557
558 // found header
559 if (frame->isocHeader.dataFormat==ISOC_MODE_COMPRESS) {
560 //check isocHeader.frameNum for lost frames
561 if (usbvision->lastIsocFrameNum >= 0) {
562 if (((usbvision->lastIsocFrameNum + 1) % 32) != frame->isocHeader.frameNum) {
563 // unexpected frame drop: need to request new intra frame
564 PDEBUG(DBG_HEADER, "Lost frame before %d on USB", frame->isocHeader.frameNum);
565 usbvision_request_intra(usbvision);
566 return ParseState_NextFrame;
567 }
568 }
569 usbvision->lastIsocFrameNum = frame->isocHeader.frameNum;
570 }
571 usbvision->header_count++;
572 frame->scanstate = ScanState_Lines;
573 frame->curline = 0;
574
575 if (force_testpattern) {
576 usbvision_testpattern(usbvision, 1, 1);
577 return ParseState_NextFrame;
578 }
579 return ParseState_Continue;
580}
581
582static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision,
583 long *pcopylen)
584{
585 volatile struct usbvision_frame *frame;
586 unsigned char *f;
587 int len;
588 int i;
589 unsigned char yuyv[4]={180, 128, 10, 128}; // YUV components
590 unsigned char rv, gv, bv; // RGB components
591 int clipmask_index, bytes_per_pixel;
592 int stretch_bytes, clipmask_add;
593
594 frame = usbvision->curFrame;
595 f = frame->data + (frame->v4l2_linesize * frame->curline);
596
597 /* Make sure there's enough data for the entire line */
598 len = (frame->isocHeader.frameWidth * 2)+5;
599 if (scratch_len(usbvision) < len) {
600 PDEBUG(DBG_PARSE, "out of data in line %d, need %u.\n", frame->curline, len);
601 return ParseState_Out;
602 }
603
604 if ((frame->curline + 1) >= frame->frmheight) {
605 return ParseState_NextFrame;
606 }
607
608 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
609 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
610 clipmask_index = frame->curline * MAX_FRAME_WIDTH;
611 clipmask_add = usbvision->stretch_width;
612
613 for (i = 0; i < frame->frmwidth; i+=(2 * usbvision->stretch_width)) {
614
615 scratch_get(usbvision, &yuyv[0], 4);
616
617 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
618 *f++ = yuyv[0]; // Y
619 *f++ = yuyv[3]; // U
620 }
621 else {
622
623 YUV_TO_RGB_BY_THE_BOOK(yuyv[0], yuyv[1], yuyv[3], rv, gv, bv);
624 switch (frame->v4l2_format.format) {
625 case V4L2_PIX_FMT_RGB565:
626 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3));
627 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv);
628 break;
629 case V4L2_PIX_FMT_RGB24:
630 *f++ = bv;
631 *f++ = gv;
632 *f++ = rv;
633 break;
634 case V4L2_PIX_FMT_RGB32:
635 *f++ = bv;
636 *f++ = gv;
637 *f++ = rv;
638 f++;
639 break;
640 case V4L2_PIX_FMT_RGB555:
641 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2));
642 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1));
643 break;
644 }
645 }
646 clipmask_index += clipmask_add;
647 f += stretch_bytes;
648
649 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
650 *f++ = yuyv[2]; // Y
651 *f++ = yuyv[1]; // V
652 }
653 else {
654
655 YUV_TO_RGB_BY_THE_BOOK(yuyv[2], yuyv[1], yuyv[3], rv, gv, bv);
656 switch (frame->v4l2_format.format) {
657 case V4L2_PIX_FMT_RGB565:
658 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3));
659 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv);
660 break;
661 case V4L2_PIX_FMT_RGB24:
662 *f++ = bv;
663 *f++ = gv;
664 *f++ = rv;
665 break;
666 case V4L2_PIX_FMT_RGB32:
667 *f++ = bv;
668 *f++ = gv;
669 *f++ = rv;
670 f++;
671 break;
672 case V4L2_PIX_FMT_RGB555:
673 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2));
674 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1));
675 break;
676 }
677 }
678 clipmask_index += clipmask_add;
679 f += stretch_bytes;
680 }
681
682 frame->curline += usbvision->stretch_height;
683 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
684
685 if (frame->curline >= frame->frmheight) {
686 return ParseState_NextFrame;
687 }
688 else {
689 return ParseState_Continue;
690 }
691}
692
693/* The decompression routine */
694static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *Compressed,
695 unsigned char *Decompressed, int *StartPos,
696 int *BlockTypeStartPos, int Len)
697{
698 int RestPixel, Idx, MaxPos, Pos, ExtraPos, BlockLen, BlockTypePos, BlockTypeLen;
699 unsigned char BlockByte, BlockCode, BlockType, BlockTypeByte, Integrator;
700
701 Integrator = 0;
702 Pos = *StartPos;
703 BlockTypePos = *BlockTypeStartPos;
704 MaxPos = 396; //Pos + Len;
705 ExtraPos = Pos;
706 BlockLen = 0;
707 BlockByte = 0;
708 BlockCode = 0;
709 BlockType = 0;
710 BlockTypeByte = 0;
711 BlockTypeLen = 0;
712 RestPixel = Len;
713
714 for (Idx = 0; Idx < Len; Idx++) {
715
716 if (BlockLen == 0) {
717 if (BlockTypeLen==0) {
718 BlockTypeByte = Compressed[BlockTypePos];
719 BlockTypePos++;
720 BlockTypeLen = 4;
721 }
722 BlockType = (BlockTypeByte & 0xC0) >> 6;
723
724 //statistic:
725 usbvision->ComprBlockTypes[BlockType]++;
726
727 Pos = ExtraPos;
728 if (BlockType == 0) {
729 if(RestPixel >= 24) {
730 Idx += 23;
731 RestPixel -= 24;
732 Integrator = Decompressed[Idx];
733 } else {
734 Idx += RestPixel - 1;
735 RestPixel = 0;
736 }
737 } else {
738 BlockCode = Compressed[Pos];
739 Pos++;
740 if (RestPixel >= 24) {
741 BlockLen = 24;
742 } else {
743 BlockLen = RestPixel;
744 }
745 RestPixel -= BlockLen;
746 ExtraPos = Pos + (BlockLen / 4);
747 }
748 BlockTypeByte <<= 2;
749 BlockTypeLen -= 1;
750 }
751 if (BlockLen > 0) {
752 if ((BlockLen%4) == 0) {
753 BlockByte = Compressed[Pos];
754 Pos++;
755 }
756 if (BlockType == 1) { //inter Block
757 Integrator = Decompressed[Idx];
758 }
759 switch (BlockByte & 0xC0) {
760 case 0x03<<6:
761 Integrator += Compressed[ExtraPos];
762 ExtraPos++;
763 break;
764 case 0x02<<6:
765 Integrator += BlockCode;
766 break;
767 case 0x00:
768 Integrator -= BlockCode;
769 break;
770 }
771 Decompressed[Idx] = Integrator;
772 BlockByte <<= 2;
773 BlockLen -= 1;
774 }
775 }
776 *StartPos = ExtraPos;
777 *BlockTypeStartPos = BlockTypePos;
778 return Idx;
779}
780
781
782/*
783 * usbvision_parse_compress()
784 *
785 * Parse compressed frame from the scratch buffer, put
786 * decoded RGB value into the current frame buffer and add the written
787 * number of bytes (RGB) to the *pcopylen.
788 *
789 */
790static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
791 long *pcopylen)
792{
793#define USBVISION_STRIP_MAGIC 0x5A
794#define USBVISION_STRIP_LEN_MAX 400
795#define USBVISION_STRIP_HEADER_LEN 3
796
797 struct usbvision_frame *frame;
798 unsigned char *f,*u = NULL ,*v = NULL;
799 unsigned char StripData[USBVISION_STRIP_LEN_MAX];
800 unsigned char StripHeader[USBVISION_STRIP_HEADER_LEN];
801 int Idx, IdxEnd, StripLen, StripPtr, StartBlockPos, BlockPos, BlockTypePos;
802 int clipmask_index, bytes_per_pixel, rc;
803 int imageSize;
804 unsigned char rv, gv, bv;
805 static unsigned char *Y, *U, *V;
806
807 frame = usbvision->curFrame;
808 imageSize = frame->frmwidth * frame->frmheight;
809 if ( (frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) ||
810 (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) ) { // this is a planar format
811 //... v4l2_linesize not used here.
812 f = frame->data + (frame->width * frame->curline);
813 } else
814 f = frame->data + (frame->v4l2_linesize * frame->curline);
815
816 if (frame->v4l2_format.format == V4L2_PIX_FMT_YUYV){ //initialise u and v pointers
817 // get base of u and b planes add halfoffset
818
819 u = frame->data
820 + imageSize
821 + (frame->frmwidth >>1) * frame->curline ;
822 v = u + (imageSize >>1 );
823
824 } else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420){
825
826 v = frame->data + imageSize + ((frame->curline* (frame->width))>>2) ;
827 u = v + (imageSize >>2) ;
828 }
829
830 if (frame->curline == 0) {
831 usbvision_adjust_compression(usbvision);
832 }
833
834 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) {
835 return ParseState_Out;
836 }
837
838 //get strip header without changing the scratch_read_ptr
839 scratch_set_extra_ptr(usbvision, &StripPtr, 0);
840 scratch_get_extra(usbvision, &StripHeader[0], &StripPtr,
841 USBVISION_STRIP_HEADER_LEN);
842
843 if (StripHeader[0] != USBVISION_STRIP_MAGIC) {
844 // wrong strip magic
845 usbvision->stripMagicErrors++;
846 return ParseState_NextFrame;
847 }
848
849 if (frame->curline != (int)StripHeader[2]) {
850 //line number missmatch error
851 usbvision->stripLineNumberErrors++;
852 }
853
854 StripLen = 2 * (unsigned int)StripHeader[1];
855 if (StripLen > USBVISION_STRIP_LEN_MAX) {
856 // strip overrun
857 // I think this never happens
858 usbvision_request_intra(usbvision);
859 }
860
861 if (scratch_len(usbvision) < StripLen) {
862 //there is not enough data for the strip
863 return ParseState_Out;
864 }
865
866 if (usbvision->IntraFrameBuffer) {
867 Y = usbvision->IntraFrameBuffer + frame->frmwidth * frame->curline;
868 U = usbvision->IntraFrameBuffer + imageSize + (frame->frmwidth / 2) * (frame->curline / 2);
869 V = usbvision->IntraFrameBuffer + imageSize / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2);
870 }
871 else {
872 return ParseState_NextFrame;
873 }
874
875 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
876 clipmask_index = frame->curline * MAX_FRAME_WIDTH;
877
878 scratch_get(usbvision, StripData, StripLen);
879
880 IdxEnd = frame->frmwidth;
881 BlockTypePos = USBVISION_STRIP_HEADER_LEN;
882 StartBlockPos = BlockTypePos + (IdxEnd - 1) / 96 + (IdxEnd / 2 - 1) / 96 + 2;
883 BlockPos = StartBlockPos;
884
885 usbvision->BlockPos = BlockPos;
886
887 if ((rc = usbvision_decompress(usbvision, StripData, Y, &BlockPos, &BlockTypePos, IdxEnd)) != IdxEnd) {
888 //return ParseState_Continue;
889 }
890 if (StripLen > usbvision->maxStripLen) {
891 usbvision->maxStripLen = StripLen;
892 }
893
894 if (frame->curline%2) {
895 if ((rc = usbvision_decompress(usbvision, StripData, V, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) {
896 //return ParseState_Continue;
897 }
898 }
899 else {
900 if ((rc = usbvision_decompress(usbvision, StripData, U, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) {
901 //return ParseState_Continue;
902 }
903 }
904
905 if (BlockPos > usbvision->comprBlockPos) {
906 usbvision->comprBlockPos = BlockPos;
907 }
908 if (BlockPos > StripLen) {
909 usbvision->stripLenErrors++;
910 }
911
912 for (Idx = 0; Idx < IdxEnd; Idx++) {
913 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
914 *f++ = Y[Idx];
915 *f++ = Idx & 0x01 ? U[Idx/2] : V[Idx/2];
916 }
917 else if(frame->v4l2_format.format == V4L2_PIX_FMT_YUV422P) {
918 *f++ = Y[Idx];
919 if ( Idx & 0x01)
920 *u++ = U[Idx>>1] ;
921 else
922 *v++ = V[Idx>>1];
923 }
924 else if (frame->v4l2_format.format == V4L2_PIX_FMT_YVU420) {
925 *f++ = Y [Idx];
926 if ( !(( Idx & 0x01 ) | ( frame->curline & 0x01 )) ){
927
928/* only need do this for 1 in 4 pixels */
929/* intraframe buffer is YUV420 format */
930
931 *u++ = U[Idx >>1];
932 *v++ = V[Idx >>1];
933 }
934
935 }
936 else {
937 YUV_TO_RGB_BY_THE_BOOK(Y[Idx], U[Idx/2], V[Idx/2], rv, gv, bv);
938 switch (frame->v4l2_format.format) {
939 case V4L2_PIX_FMT_GREY:
940 *f++ = Y[Idx];
941 break;
942 case V4L2_PIX_FMT_RGB555:
943 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 2));
944 *f++ = (0x03 & (gv >> 6)) | (0x7C & (rv >> 1));
945 break;
946 case V4L2_PIX_FMT_RGB565:
947 *f++ = (0x1F & (bv >> 3)) | (0xE0 & (gv << 3));
948 *f++ = (0x07 & (gv >> 5)) | (0xF8 & rv);
949 break;
950 case V4L2_PIX_FMT_RGB24:
951 *f++ = bv;
952 *f++ = gv;
953 *f++ = rv;
954 break;
955 case V4L2_PIX_FMT_RGB32:
956 *f++ = bv;
957 *f++ = gv;
958 *f++ = rv;
959 f++;
960 break;
961 }
962 }
963 clipmask_index++;
964 }
965 /* Deal with non-integer no. of bytes for YUV420P */
966 if (frame->v4l2_format.format != V4L2_PIX_FMT_YVU420 )
967 *pcopylen += frame->v4l2_linesize;
968 else
969 *pcopylen += frame->curline & 0x01 ? frame->v4l2_linesize : frame->v4l2_linesize << 1;
970
971 frame->curline += 1;
972
973 if (frame->curline >= frame->frmheight) {
974 return ParseState_NextFrame;
975 }
976 else {
977 return ParseState_Continue;
978 }
979
980}
981
982
983/*
984 * usbvision_parse_lines_420()
985 *
986 * Parse two lines from the scratch buffer, put
987 * decoded RGB value into the current frame buffer and add the written
988 * number of bytes (RGB) to the *pcopylen.
989 *
990 */
991static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision,
992 long *pcopylen)
993{
994 struct usbvision_frame *frame;
995 unsigned char *f_even = NULL, *f_odd = NULL;
996 unsigned int pixel_per_line, block;
997 int pixel, block_split;
998 int y_ptr, u_ptr, v_ptr, y_odd_offset;
999 const int y_block_size = 128;
1000 const int uv_block_size = 64;
1001 const int sub_block_size = 32;
1002 const int y_step[] = { 0, 0, 0, 2 }, y_step_size = 4;
1003 const int uv_step[]= { 0, 0, 0, 4 }, uv_step_size = 4;
1004 unsigned char y[2], u, v; /* YUV components */
1005 int y_, u_, v_, vb, uvg, ur;
1006 int r_, g_, b_; /* RGB components */
1007 unsigned char g;
1008 int clipmask_even_index, clipmask_odd_index, bytes_per_pixel;
1009 int clipmask_add, stretch_bytes;
1010
1011 frame = usbvision->curFrame;
1012 f_even = frame->data + (frame->v4l2_linesize * frame->curline);
1013 f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height;
1014
1015 /* Make sure there's enough data for the entire line */
1016 /* In this mode usbvision transfer 3 bytes for every 2 pixels */
1017 /* I need two lines to decode the color */
1018 bytes_per_pixel = frame->v4l2_format.bytes_per_pixel;
1019 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
1020 clipmask_even_index = frame->curline * MAX_FRAME_WIDTH;
1021 clipmask_odd_index = clipmask_even_index + MAX_FRAME_WIDTH;
1022 clipmask_add = usbvision->stretch_width;
1023 pixel_per_line = frame->isocHeader.frameWidth;
1024
1025 if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
1026 //printk(KERN_DEBUG "out of data, need %d\n", len);
1027 return ParseState_Out;
1028 }
1029
1030 if ((frame->curline + 1) >= frame->frmheight) {
1031 return ParseState_NextFrame;
1032 }
1033
1034 block_split = (pixel_per_line%y_block_size) ? 1 : 0; //are some blocks splitted into different lines?
1035
1036 y_odd_offset = (pixel_per_line / y_block_size) * (y_block_size + uv_block_size)
1037 + block_split * uv_block_size;
1038
1039 scratch_set_extra_ptr(usbvision, &y_ptr, y_odd_offset);
1040 scratch_set_extra_ptr(usbvision, &u_ptr, y_block_size);
1041 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
1042 + (4 - block_split) * sub_block_size);
1043
1044 for (block = 0; block < (pixel_per_line / sub_block_size);
1045 block++) {
1046
1047
1048 for (pixel = 0; pixel < sub_block_size; pixel +=2) {
1049 scratch_get(usbvision, &y[0], 2);
1050 scratch_get_extra(usbvision, &u, &u_ptr, 1);
1051 scratch_get_extra(usbvision, &v, &v_ptr, 1);
1052
1053 //I don't use the YUV_TO_RGB macro for better performance
1054 v_ = v - 128;
1055 u_ = u - 128;
1056 vb = 132252 * v_;
1057 uvg= -53281 * u_ - 25625 * v_;
1058 ur = 104595 * u_;
1059
1060 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1061 *f_even++ = y[0];
1062 *f_even++ = v;
1063 }
1064 else {
1065 y_ = 76284 * (y[0] - 16);
1066
1067 b_ = (y_ + vb) >> 16;
1068 g_ = (y_ + uvg)>> 16;
1069 r_ = (y_ + ur) >> 16;
1070
1071 switch (frame->v4l2_format.format) {
1072 case V4L2_PIX_FMT_RGB565:
1073 g = LIMIT_RGB(g_);
1074 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3));
1075 *f_even++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_));
1076 break;
1077 case V4L2_PIX_FMT_RGB24:
1078 *f_even++ = LIMIT_RGB(b_);
1079 *f_even++ = LIMIT_RGB(g_);
1080 *f_even++ = LIMIT_RGB(r_);
1081 break;
1082 case V4L2_PIX_FMT_RGB32:
1083 *f_even++ = LIMIT_RGB(b_);
1084 *f_even++ = LIMIT_RGB(g_);
1085 *f_even++ = LIMIT_RGB(r_);
1086 f_even++;
1087 break;
1088 case V4L2_PIX_FMT_RGB555:
1089 g = LIMIT_RGB(g_);
1090 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2));
1091 *f_even++ = (0x03 & ( g >> 6)) |
1092 (0x7C & (LIMIT_RGB(r_) >> 1));
1093 break;
1094 }
1095 }
1096 clipmask_even_index += clipmask_add;
1097 f_even += stretch_bytes;
1098
1099 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1100 *f_even++ = y[1];
1101 *f_even++ = u;
1102 }
1103 else {
1104 y_ = 76284 * (y[1] - 16);
1105
1106 b_ = (y_ + vb) >> 16;
1107 g_ = (y_ + uvg)>> 16;
1108 r_ = (y_ + ur) >> 16;
1109
1110 switch (frame->v4l2_format.format) {
1111 case V4L2_PIX_FMT_RGB565:
1112 g = LIMIT_RGB(g_);
1113 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3));
1114 *f_even++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_));
1115 break;
1116 case V4L2_PIX_FMT_RGB24:
1117 *f_even++ = LIMIT_RGB(b_);
1118 *f_even++ = LIMIT_RGB(g_);
1119 *f_even++ = LIMIT_RGB(r_);
1120 break;
1121 case V4L2_PIX_FMT_RGB32:
1122 *f_even++ = LIMIT_RGB(b_);
1123 *f_even++ = LIMIT_RGB(g_);
1124 *f_even++ = LIMIT_RGB(r_);
1125 f_even++;
1126 break;
1127 case V4L2_PIX_FMT_RGB555:
1128 g = LIMIT_RGB(g_);
1129 *f_even++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2));
1130 *f_even++ = (0x03 & ( g >> 6)) |
1131 (0x7C & (LIMIT_RGB(r_) >> 1));
1132 break;
1133 }
1134 }
1135 clipmask_even_index += clipmask_add;
1136 f_even += stretch_bytes;
1137
1138 scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
1139
1140 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1141 *f_odd++ = y[0];
1142 *f_odd++ = v;
1143 }
1144 else {
1145 y_ = 76284 * (y[0] - 16);
1146
1147 b_ = (y_ + vb) >> 16;
1148 g_ = (y_ + uvg)>> 16;
1149 r_ = (y_ + ur) >> 16;
1150
1151 switch (frame->v4l2_format.format) {
1152 case V4L2_PIX_FMT_RGB565:
1153 g = LIMIT_RGB(g_);
1154 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3));
1155 *f_odd++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_));
1156 break;
1157 case V4L2_PIX_FMT_RGB24:
1158 *f_odd++ = LIMIT_RGB(b_);
1159 *f_odd++ = LIMIT_RGB(g_);
1160 *f_odd++ = LIMIT_RGB(r_);
1161 break;
1162 case V4L2_PIX_FMT_RGB32:
1163 *f_odd++ = LIMIT_RGB(b_);
1164 *f_odd++ = LIMIT_RGB(g_);
1165 *f_odd++ = LIMIT_RGB(r_);
1166 f_odd++;
1167 break;
1168 case V4L2_PIX_FMT_RGB555:
1169 g = LIMIT_RGB(g_);
1170 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2));
1171 *f_odd++ = (0x03 & ( g >> 6)) |
1172 (0x7C & (LIMIT_RGB(r_) >> 1));
1173 break;
1174 }
1175 }
1176 clipmask_odd_index += clipmask_add;
1177 f_odd += stretch_bytes;
1178
1179 if(frame->v4l2_format.format == V4L2_PIX_FMT_YUYV) {
1180 *f_odd++ = y[1];
1181 *f_odd++ = u;
1182 }
1183 else {
1184 y_ = 76284 * (y[1] - 16);
1185
1186 b_ = (y_ + vb) >> 16;
1187 g_ = (y_ + uvg)>> 16;
1188 r_ = (y_ + ur) >> 16;
1189
1190 switch (frame->v4l2_format.format) {
1191 case V4L2_PIX_FMT_RGB565:
1192 g = LIMIT_RGB(g_);
1193 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 3));
1194 *f_odd++ = (0x07 & ( g >> 5)) | (0xF8 & LIMIT_RGB(r_));
1195 break;
1196 case V4L2_PIX_FMT_RGB24:
1197 *f_odd++ = LIMIT_RGB(b_);
1198 *f_odd++ = LIMIT_RGB(g_);
1199 *f_odd++ = LIMIT_RGB(r_);
1200 break;
1201 case V4L2_PIX_FMT_RGB32:
1202 *f_odd++ = LIMIT_RGB(b_);
1203 *f_odd++ = LIMIT_RGB(g_);
1204 *f_odd++ = LIMIT_RGB(r_);
1205 f_odd++;
1206 break;
1207 case V4L2_PIX_FMT_RGB555:
1208 g = LIMIT_RGB(g_);
1209 *f_odd++ = (0x1F & (LIMIT_RGB(b_) >> 3)) | (0xE0 & (g << 2));
1210 *f_odd++ = (0x03 & ( g >> 6)) |
1211 (0x7C & (LIMIT_RGB(r_) >> 1));
1212 break;
1213 }
1214 }
1215 clipmask_odd_index += clipmask_add;
1216 f_odd += stretch_bytes;
1217 }
1218
1219 scratch_rm_old(usbvision,y_step[block % y_step_size] * sub_block_size);
1220 scratch_inc_extra_ptr(&y_ptr, y_step[(block + 2 * block_split) % y_step_size]
1221 * sub_block_size);
1222 scratch_inc_extra_ptr(&u_ptr, uv_step[block % uv_step_size]
1223 * sub_block_size);
1224 scratch_inc_extra_ptr(&v_ptr, uv_step[(block + 2 * block_split) % uv_step_size]
1225 * sub_block_size);
1226 }
1227
1228 scratch_rm_old(usbvision, pixel_per_line * 3 / 2
1229 + block_split * sub_block_size);
1230
1231 frame->curline += 2 * usbvision->stretch_height;
1232 *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height;
1233
1234 if (frame->curline >= frame->frmheight)
1235 return ParseState_NextFrame;
1236 else
1237 return ParseState_Continue;
1238}
1239
1240/*
1241 * usbvision_parse_data()
1242 *
1243 * Generic routine to parse the scratch buffer. It employs either
1244 * usbvision_find_header() or usbvision_parse_lines() to do most
1245 * of work.
1246 *
1247 */
1248static void usbvision_parse_data(struct usb_usbvision *usbvision)
1249{
1250 struct usbvision_frame *frame;
1251 enum ParseState newstate;
1252 long copylen = 0;
1253 unsigned long lock_flags;
1254
1255 frame = usbvision->curFrame;
1256
1257 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
1258
1259 while (1) {
1260
1261 newstate = ParseState_Out;
1262 if (scratch_len(usbvision)) {
1263 if (frame->scanstate == ScanState_Scanning) {
1264 newstate = usbvision_find_header(usbvision);
1265 }
1266 else if (frame->scanstate == ScanState_Lines) {
1267 if (usbvision->isocMode == ISOC_MODE_YUV420) {
1268 newstate = usbvision_parse_lines_420(usbvision, &copylen);
1269 }
1270 else if (usbvision->isocMode == ISOC_MODE_YUV422) {
1271 newstate = usbvision_parse_lines_422(usbvision, &copylen);
1272 }
1273 else if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
1274 newstate = usbvision_parse_compress(usbvision, &copylen);
1275 }
1276
1277 }
1278 }
1279 if (newstate == ParseState_Continue) {
1280 continue;
1281 }
1282 else if ((newstate == ParseState_NextFrame) || (newstate == ParseState_Out)) {
1283 break;
1284 }
1285 else {
1286 return; /* ParseState_EndParse */
1287 }
1288 }
1289
1290 if (newstate == ParseState_NextFrame) {
1291 frame->grabstate = FrameState_Done;
1292 do_gettimeofday(&(frame->timestamp));
1293 frame->sequence = usbvision->frame_num;
1294
1295 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1296 list_move_tail(&(frame->frame), &usbvision->outqueue);
1297 usbvision->curFrame = NULL;
1298 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1299
1300 usbvision->frame_num++;
1301
1302 /* This will cause the process to request another frame. */
1303 if (waitqueue_active(&usbvision->wait_frame)) {
1304 PDEBUG(DBG_PARSE, "Wake up !");
1305 wake_up_interruptible(&usbvision->wait_frame);
1306 }
1307 }
1308 else
1309 frame->grabstate = FrameState_Grabbing;
1310
1311
1312 /* Update the frame's uncompressed length. */
1313 frame->scanlength += copylen;
1314}
1315
1316
1317/*
1318 * Make all of the blocks of data contiguous
1319 */
1320static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1321 struct urb *urb)
1322{
1323 unsigned char *packet_data;
1324 int i, totlen = 0;
1325
1326 for (i = 0; i < urb->number_of_packets; i++) {
1327 int packet_len = urb->iso_frame_desc[i].actual_length;
1328 int packet_stat = urb->iso_frame_desc[i].status;
1329
1330 packet_data = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
1331
1332 /* Detect and ignore errored packets */
1333 if (packet_stat) { // packet_stat != 0 ?????????????
1334 PDEBUG(DBG_ISOC, "data error: [%d] len=%d, status=%X", i, packet_len, packet_stat);
1335 usbvision->isocErrCount++;
1336 continue;
1337 }
1338
1339 /* Detect and ignore empty packets */
1340 if (packet_len < 0) {
1341 PDEBUG(DBG_ISOC, "error packet [%d]", i);
1342 usbvision->isocSkipCount++;
1343 continue;
1344 }
1345 else if (packet_len == 0) { /* Frame end ????? */
1346 PDEBUG(DBG_ISOC, "null packet [%d]", i);
1347 usbvision->isocstate=IsocState_NoFrame;
1348 usbvision->isocSkipCount++;
1349 continue;
1350 }
1351 else if (packet_len > usbvision->isocPacketSize) {
1352 PDEBUG(DBG_ISOC, "packet[%d] > isocPacketSize", i);
1353 usbvision->isocSkipCount++;
1354 continue;
1355 }
1356
1357 PDEBUG(DBG_ISOC, "packet ok [%d] len=%d", i, packet_len);
1358
1359 if (usbvision->isocstate==IsocState_NoFrame) { //new frame begins
1360 usbvision->isocstate=IsocState_InFrame;
1361 scratch_mark_header(usbvision);
1362 usbvision_measure_bandwidth(usbvision);
1363 PDEBUG(DBG_ISOC, "packet with header");
1364 }
1365
1366 /*
1367 * If usbvision continues to feed us with data but there is no
1368 * consumption (if, for example, V4L client fell asleep) we
1369 * may overflow the buffer. We have to move old data over to
1370 * free room for new data. This is bad for old data. If we
1371 * just drop new data then it's bad for new data... choose
1372 * your favorite evil here.
1373 */
1374 if (scratch_free(usbvision) < packet_len) {
1375
1376 usbvision->scratch_ovf_count++;
1377 PDEBUG(DBG_ISOC, "scratch buf overflow! scr_len: %d, n: %d",
1378 scratch_len(usbvision), packet_len);
1379 scratch_rm_old(usbvision, packet_len - scratch_free(usbvision));
1380 }
1381
1382 /* Now we know that there is enough room in scratch buffer */
1383 scratch_put(usbvision, packet_data, packet_len);
1384 totlen += packet_len;
1385 usbvision->isocDataCount += packet_len;
1386 usbvision->isocPacketCount++;
1387 }
1388#if ENABLE_HEXDUMP
1389 if (totlen > 0) {
1390 static int foo = 0;
1391 if (foo < 1) {
1392 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
1393 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
1394 ++foo;
1395 }
1396 }
1397#endif
1398 return totlen;
1399}
1400
1401static void usbvision_isocIrq(struct urb *urb)
1402{
1403 int errCode = 0;
1404 int len;
1405 struct usb_usbvision *usbvision = urb->context;
1406 int i;
1407 unsigned long startTime = jiffies;
1408 struct usbvision_frame **f;
1409
1410 /* We don't want to do anything if we are about to be removed! */
1411 if (!USBVISION_IS_OPERATIONAL(usbvision))
1412 return;
1413
1414 f = &usbvision->curFrame;
1415
1416 /* Manage streaming interruption */
1417 if (usbvision->streaming == Stream_Interrupt) {
1418 usbvision->streaming = Stream_Idle;
1419 if ((*f)) {
1420 (*f)->grabstate = FrameState_Ready;
1421 (*f)->scanstate = ScanState_Scanning;
1422 }
1423 PDEBUG(DBG_IRQ, "stream interrupted");
1424 wake_up_interruptible(&usbvision->wait_stream);
1425 }
1426
1427 /* Copy the data received into our scratch buffer */
1428 len = usbvision_compress_isochronous(usbvision, urb);
1429
1430 usbvision->isocUrbCount++;
1431 usbvision->urb_length = len;
1432
1433 if (usbvision->streaming == Stream_On) {
1434
1435 /* If we collected enough data let's parse! */
1436 if (scratch_len(usbvision) > USBVISION_HEADER_LENGTH) { /* 12 == header_length */
1437 /*If we don't have a frame we're current working on, complain */
1438 if(!list_empty(&(usbvision->inqueue))) {
1439 if (!(*f)) {
1440 (*f) = list_entry(usbvision->inqueue.next,struct usbvision_frame, frame);
1441 }
1442 usbvision_parse_data(usbvision);
1443 }
1444 else {
1445 PDEBUG(DBG_IRQ, "received data, but no one needs it");
1446 scratch_reset(usbvision);
1447 }
1448 }
1449 }
1450 else {
1451 PDEBUG(DBG_IRQ, "received data, but no one needs it");
1452 scratch_reset(usbvision);
1453 }
1454
1455 usbvision->timeInIrq += jiffies - startTime;
1456
1457 for (i = 0; i < USBVISION_URB_FRAMES; i++) {
1458 urb->iso_frame_desc[i].status = 0;
1459 urb->iso_frame_desc[i].actual_length = 0;
1460 }
1461
1462 urb->status = 0;
1463 urb->dev = usbvision->dev;
1464 errCode = usb_submit_urb (urb, GFP_ATOMIC);
1465
1466 /* Disable this warning. By design of the driver. */
1467 // if(errCode) {
1468 // err("%s: usb_submit_urb failed: error %d", __FUNCTION__, errCode);
1469 // }
1470
1471 return;
1472}
1473
1474/*************************************/
1475/* Low level usbvision access functions */
1476/*************************************/
1477
1478/*
1479 * usbvision_read_reg()
1480 *
1481 * return < 0 -> Error
1482 * >= 0 -> Data
1483 */
1484
1485int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1486{
1487 int errCode = 0;
1488 unsigned char buffer[1];
1489
1490 if (!USBVISION_IS_OPERATIONAL(usbvision))
1491 return -1;
1492
1493 errCode = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1),
1494 USBVISION_OP_CODE,
1495 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1496 0, (__u16) reg, buffer, 1, HZ);
1497
1498 if (errCode < 0) {
1499 err("%s: failed: error %d", __FUNCTION__, errCode);
1500 return errCode;
1501 }
1502 return buffer[0];
1503}
1504
1505/*
1506 * usbvision_write_reg()
1507 *
1508 * return 1 -> Reg written
1509 * 0 -> usbvision is not yet ready
1510 * -1 -> Something went wrong
1511 */
1512
1513int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
1514 unsigned char value)
1515{
1516 int errCode = 0;
1517
1518 if (!USBVISION_IS_OPERATIONAL(usbvision))
1519 return 0;
1520
1521 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1522 USBVISION_OP_CODE,
1523 USB_DIR_OUT | USB_TYPE_VENDOR |
1524 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ);
1525
1526 if (errCode < 0) {
1527 err("%s: failed: error %d", __FUNCTION__, errCode);
1528 }
1529 return errCode;
1530}
1531
1532
1533static void usbvision_ctrlUrb_complete(struct urb *urb)
1534{
1535 struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context;
1536
1537 PDEBUG(DBG_IRQ, "");
1538 usbvision->ctrlUrbBusy = 0;
1539 if (waitqueue_active(&usbvision->ctrlUrb_wq)) {
1540 wake_up_interruptible(&usbvision->ctrlUrb_wq);
1541 }
1542}
1543
1544
1545static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address,
1546 unsigned char *data, int len)
1547{
1548 int errCode = 0;
1549
1550 PDEBUG(DBG_IRQ, "");
1551 if (len > 8) {
1552 return -EFAULT;
1553 }
1554// down(&usbvision->ctrlUrbLock);
1555 if (usbvision->ctrlUrbBusy) {
1556// up(&usbvision->ctrlUrbLock);
1557 return -EBUSY;
1558 }
1559 usbvision->ctrlUrbBusy = 1;
1560// up(&usbvision->ctrlUrbLock);
1561
1562 usbvision->ctrlUrbSetup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
1563 usbvision->ctrlUrbSetup.bRequest = USBVISION_OP_CODE;
1564 usbvision->ctrlUrbSetup.wValue = 0;
1565 usbvision->ctrlUrbSetup.wIndex = cpu_to_le16(address);
1566 usbvision->ctrlUrbSetup.wLength = cpu_to_le16(len);
1567 usb_fill_control_urb (usbvision->ctrlUrb, usbvision->dev,
1568 usb_sndctrlpipe(usbvision->dev, 1),
1569 (unsigned char *)&usbvision->ctrlUrbSetup,
1570 (void *)usbvision->ctrlUrbBuffer, len,
1571 usbvision_ctrlUrb_complete,
1572 (void *)usbvision);
1573
1574 memcpy(usbvision->ctrlUrbBuffer, data, len);
1575
1576 errCode = usb_submit_urb(usbvision->ctrlUrb, GFP_ATOMIC);
1577 if (errCode < 0) {
1578 // error in usb_submit_urb()
1579 usbvision->ctrlUrbBusy = 0;
1580 }
1581 PDEBUG(DBG_IRQ, "submit %d byte: error %d", len, errCode);
1582 return errCode;
1583}
1584
1585
1586static int usbvision_init_compression(struct usb_usbvision *usbvision)
1587{
1588 int errCode = 0;
1589
1590 usbvision->lastIsocFrameNum = -1;
1591 usbvision->isocDataCount = 0;
1592 usbvision->isocPacketCount = 0;
1593 usbvision->isocSkipCount = 0;
1594 usbvision->comprLevel = 50;
1595 usbvision->lastComprLevel = -1;
1596 usbvision->isocUrbCount = 0;
1597 usbvision->requestIntra = 1;
1598 usbvision->isocMeasureBandwidthCount = 0;
1599
1600 return errCode;
1601}
1602
1603/* this function measures the used bandwidth since last call
1604 * return: 0 : no error
1605 * sets usedBandwidth to 1-100 : 1-100% of full bandwidth resp. to isocPacketSize
1606 */
1607static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision)
1608{
1609 int errCode = 0;
1610
1611 if (usbvision->isocMeasureBandwidthCount < 2) { // this gives an average bandwidth of 3 frames
1612 usbvision->isocMeasureBandwidthCount++;
1613 return errCode;
1614 }
1615 if ((usbvision->isocPacketSize > 0) && (usbvision->isocPacketCount > 0)) {
1616 usbvision->usedBandwidth = usbvision->isocDataCount /
1617 (usbvision->isocPacketCount + usbvision->isocSkipCount) *
1618 100 / usbvision->isocPacketSize;
1619 }
1620 usbvision->isocMeasureBandwidthCount = 0;
1621 usbvision->isocDataCount = 0;
1622 usbvision->isocPacketCount = 0;
1623 usbvision->isocSkipCount = 0;
1624 return errCode;
1625}
1626
1627static int usbvision_adjust_compression (struct usb_usbvision *usbvision)
1628{
1629 int errCode = 0;
1630 unsigned char buffer[6];
1631
1632 PDEBUG(DBG_IRQ, "");
1633 if ((adjustCompression) && (usbvision->usedBandwidth > 0)) {
1634 usbvision->comprLevel += (usbvision->usedBandwidth - 90) / 2;
1635 RESTRICT_TO_RANGE(usbvision->comprLevel, 0, 100);
1636 if (usbvision->comprLevel != usbvision->lastComprLevel) {
1637 int distorsion;
1638 if (usbvision->bridgeType == BRIDGE_NT1004 || usbvision->bridgeType == BRIDGE_NT1005) {
1639 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM Threshold 1
1640 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM Threshold 2
1641 distorsion = 7 + 248 * usbvision->comprLevel / 100;
1642 buffer[2] = (unsigned char)(distorsion & 0xFF); // Average distorsion Threshold (inter)
1643 buffer[3] = (unsigned char)(distorsion & 0xFF); // Average distorsion Threshold (intra)
1644 distorsion = 1 + 42 * usbvision->comprLevel / 100;
1645 buffer[4] = (unsigned char)(distorsion & 0xFF); // Maximum distorsion Threshold (inter)
1646 buffer[5] = (unsigned char)(distorsion & 0xFF); // Maximum distorsion Threshold (intra)
1647 }
1648 else { //BRIDGE_NT1003
1649 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM threshold 1
1650 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM threshold 2
1651 distorsion = 2 + 253 * usbvision->comprLevel / 100;
1652 buffer[2] = (unsigned char)(distorsion & 0xFF); // distorsion threshold bit0-7
1653 buffer[3] = 0; //(unsigned char)((distorsion >> 8) & 0x0F); // distorsion threshold bit 8-11
1654 distorsion = 0 + 43 * usbvision->comprLevel / 100;
1655 buffer[4] = (unsigned char)(distorsion & 0xFF); // maximum distorsion bit0-7
1656 buffer[5] = 0; //(unsigned char)((distorsion >> 8) & 0x01); // maximum distorsion bit 8
1657 }
1658 errCode = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
1659 if (errCode == 0){
1660 PDEBUG(DBG_IRQ, "new compr params %#02x %#02x %#02x %#02x %#02x %#02x", buffer[0],
1661 buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
1662 usbvision->lastComprLevel = usbvision->comprLevel;
1663 }
1664 }
1665 }
1666 return errCode;
1667}
1668
1669static int usbvision_request_intra (struct usb_usbvision *usbvision)
1670{
1671 int errCode = 0;
1672 unsigned char buffer[1];
1673
1674 PDEBUG(DBG_IRQ, "");
1675 usbvision->requestIntra = 1;
1676 buffer[0] = 1;
1677 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1678 return errCode;
1679}
1680
1681static int usbvision_unrequest_intra (struct usb_usbvision *usbvision)
1682{
1683 int errCode = 0;
1684 unsigned char buffer[1];
1685
1686 PDEBUG(DBG_IRQ, "");
1687 usbvision->requestIntra = 0;
1688 buffer[0] = 0;
1689 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1690 return errCode;
1691}
1692
1693/*******************************
1694 * usbvision utility functions
1695 *******************************/
1696
1697int usbvision_power_off(struct usb_usbvision *usbvision)
1698{
1699 int errCode = 0;
1700
1701 PDEBUG(DBG_FUNC, "");
1702
1703 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
1704 if (errCode == 1) {
1705 usbvision->power = 0;
1706 }
1707 PDEBUG(DBG_FUNC, "%s: errCode %d", (errCode!=1)?"ERROR":"power is off", errCode);
1708 return errCode;
1709}
1710
1711/*
1712 * usbvision_set_video_format()
1713 *
1714 */
1715static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format)
1716{
1717 static const char proc[] = "usbvision_set_video_format";
1718 int rc;
1719 unsigned char value[2];
1720
1721 if (!USBVISION_IS_OPERATIONAL(usbvision))
1722 return 0;
1723
1724 PDEBUG(DBG_FUNC, "isocMode %#02x", format);
1725
1726 if ((format != ISOC_MODE_YUV422)
1727 && (format != ISOC_MODE_YUV420)
1728 && (format != ISOC_MODE_COMPRESS)) {
1729 printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420",
1730 format);
1731 format = ISOC_MODE_YUV420;
1732 }
1733 value[0] = 0x0A; //TODO: See the effect of the filter
1734 value[1] = format;
1735 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1736 USBVISION_OP_CODE,
1737 USB_DIR_OUT | USB_TYPE_VENDOR |
1738 USB_RECIP_ENDPOINT, 0,
1739 (__u16) USBVISION_FILT_CONT, value, 2, HZ);
1740
1741 if (rc < 0) {
1742 printk(KERN_ERR "%s: ERROR=%d. USBVISION stopped - "
1743 "reconnect or reload driver.\n", proc, rc);
1744 }
1745 usbvision->isocMode = format;
1746 return rc;
1747}
1748
1749/*
1750 * usbvision_set_output()
1751 *
1752 */
1753
1754int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1755 int height)
1756{
1757 int errCode = 0;
1758 int UsbWidth, UsbHeight;
1759 unsigned int frameRate=0, frameDrop=0;
1760 unsigned char value[4];
1761
1762 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
1763 return 0;
1764 }
1765
1766 if (width > MAX_USB_WIDTH) {
1767 UsbWidth = width / 2;
1768 usbvision->stretch_width = 2;
1769 }
1770 else {
1771 UsbWidth = width;
1772 usbvision->stretch_width = 1;
1773 }
1774
1775 if (height > MAX_USB_HEIGHT) {
1776 UsbHeight = height / 2;
1777 usbvision->stretch_height = 2;
1778 }
1779 else {
1780 UsbHeight = height;
1781 usbvision->stretch_height = 1;
1782 }
1783
1784 RESTRICT_TO_RANGE(UsbWidth, MIN_FRAME_WIDTH, MAX_USB_WIDTH);
1785 UsbWidth &= ~(MIN_FRAME_WIDTH-1);
1786 RESTRICT_TO_RANGE(UsbHeight, MIN_FRAME_HEIGHT, MAX_USB_HEIGHT);
1787 UsbHeight &= ~(1);
1788
1789 PDEBUG(DBG_FUNC, "usb %dx%d; screen %dx%d; stretch %dx%d",
1790 UsbWidth, UsbHeight, width, height,
1791 usbvision->stretch_width, usbvision->stretch_height);
1792
1793 /* I'll not rewrite the same values */
1794 if ((UsbWidth != usbvision->curwidth) || (UsbHeight != usbvision->curheight)) {
1795 value[0] = UsbWidth & 0xff; //LSB
1796 value[1] = (UsbWidth >> 8) & 0x03; //MSB
1797 value[2] = UsbHeight & 0xff; //LSB
1798 value[3] = (UsbHeight >> 8) & 0x03; //MSB
1799
1800 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1801 USBVISION_OP_CODE,
1802 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT,
1803 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
1804
1805 if (errCode < 0) {
1806 err("%s failed: error %d", __FUNCTION__, errCode);
1807 return errCode;
1808 }
1809 usbvision->curwidth = usbvision->stretch_width * UsbWidth;
1810 usbvision->curheight = usbvision->stretch_height * UsbHeight;
1811 }
1812
1813 if (usbvision->isocMode == ISOC_MODE_YUV422) {
1814 frameRate = (usbvision->isocPacketSize * 1000) / (UsbWidth * UsbHeight * 2);
1815 }
1816 else if (usbvision->isocMode == ISOC_MODE_YUV420) {
1817 frameRate = (usbvision->isocPacketSize * 1000) / ((UsbWidth * UsbHeight * 12) / 8);
1818 }
1819 else {
1820 frameRate = FRAMERATE_MAX;
1821 }
1822
1823 if (usbvision->tvnorm->id & V4L2_STD_625_50) {
1824 frameDrop = frameRate * 32 / 25 - 1;
1825 }
1826 else if (usbvision->tvnorm->id & V4L2_STD_525_60) {
1827 frameDrop = frameRate * 32 / 30 - 1;
1828 }
1829
1830 RESTRICT_TO_RANGE(frameDrop, FRAMERATE_MIN, FRAMERATE_MAX);
1831
1832 PDEBUG(DBG_FUNC, "frameRate %d fps, frameDrop %d", frameRate, frameDrop);
1833
1834 frameDrop = FRAMERATE_MAX; // We can allow the maximum here, because dropping is controlled
1835
1836 /* frameDrop = 7; => framePhase = 1, 5, 9, 13, 17, 21, 25, 0, 4, 8, ...
1837 => frameSkip = 4;
1838 => frameRate = (7 + 1) * 25 / 32 = 200 / 32 = 6.25;
1839
1840 frameDrop = 9; => framePhase = 1, 5, 8, 11, 14, 17, 21, 24, 27, 1, 4, 8, ...
1841 => frameSkip = 4, 3, 3, 3, 3, 4, 3, 3, 3, 3, 4, ...
1842 => frameRate = (9 + 1) * 25 / 32 = 250 / 32 = 7.8125;
1843 */
1844 errCode = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frameDrop);
1845 return errCode;
1846}
1847
1848
1849/*
1850 * usbvision_frames_alloc
1851 * allocate the maximum frames this driver can manage
1852 */
1853int usbvision_frames_alloc(struct usb_usbvision *usbvision)
1854{
1855 int i;
1856
1857 /* Allocate memory for the frame buffers */
1858 usbvision->max_frame_size = MAX_FRAME_SIZE;
1859 usbvision->fbuf_size = USBVISION_NUMFRAMES * usbvision->max_frame_size;
1860 usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size);
1861
1862 if(usbvision->fbuf == NULL) {
1863 err("%s: unable to allocate %d bytes for fbuf ",
1864 __FUNCTION__, usbvision->fbuf_size);
1865 return -ENOMEM;
1866 }
1867 spin_lock_init(&usbvision->queue_lock);
1868 init_waitqueue_head(&usbvision->wait_frame);
1869 init_waitqueue_head(&usbvision->wait_stream);
1870
1871 /* Allocate all buffers */
1872 for (i = 0; i < USBVISION_NUMFRAMES; i++) {
1873 usbvision->frame[i].index = i;
1874 usbvision->frame[i].grabstate = FrameState_Unused;
1875 usbvision->frame[i].data = usbvision->fbuf +
1876 i * usbvision->max_frame_size;
1877 /*
1878 * Set default sizes for read operation.
1879 */
1880 usbvision->stretch_width = 1;
1881 usbvision->stretch_height = 1;
1882 usbvision->frame[i].width = usbvision->curwidth;
1883 usbvision->frame[i].height = usbvision->curheight;
1884 usbvision->frame[i].bytes_read = 0;
1885 }
1886 return 0;
1887}
1888
1889/*
1890 * usbvision_frames_free
1891 * frees memory allocated for the frames
1892 */
1893void usbvision_frames_free(struct usb_usbvision *usbvision)
1894{
1895 /* Have to free all that memory */
1896 if (usbvision->fbuf != NULL) {
1897 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
1898 usbvision->fbuf = NULL;
1899 }
1900}
1901/*
1902 * usbvision_empty_framequeues()
1903 * prepare queues for incoming and outgoing frames
1904 */
1905void usbvision_empty_framequeues(struct usb_usbvision *usbvision)
1906{
1907 u32 i;
1908
1909 INIT_LIST_HEAD(&(usbvision->inqueue));
1910 INIT_LIST_HEAD(&(usbvision->outqueue));
1911
1912 for (i = 0; i < USBVISION_NUMFRAMES; i++) {
1913 usbvision->frame[i].grabstate = FrameState_Unused;
1914 usbvision->frame[i].bytes_read = 0;
1915 }
1916}
1917
1918/*
1919 * usbvision_stream_interrupt()
1920 * stops streaming
1921 */
1922int usbvision_stream_interrupt(struct usb_usbvision *usbvision)
1923{
1924 int ret = 0;
1925
1926 /* stop reading from the device */
1927
1928 usbvision->streaming = Stream_Interrupt;
1929 ret = wait_event_timeout(usbvision->wait_stream,
1930 (usbvision->streaming == Stream_Idle),
1931 msecs_to_jiffies(USBVISION_NUMSBUF*USBVISION_URB_FRAMES));
1932 return ret;
1933}
1934
1935/*
1936 * usbvision_set_compress_params()
1937 *
1938 */
1939
1940static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
1941{
1942 static const char proc[] = "usbvision_set_compresion_params: ";
1943 int rc;
1944 unsigned char value[6];
1945
1946 value[0] = 0x0F; // Intra-Compression cycle
1947 value[1] = 0x01; // Reg.45 one line per strip
1948 value[2] = 0x00; // Reg.46 Force intra mode on all new frames
1949 value[3] = 0x00; // Reg.47 FORCE_UP <- 0 normal operation (not force)
1950 value[4] = 0xA2; // Reg.48 BUF_THR I'm not sure if this does something in not compressed mode.
1951 value[5] = 0x00; // Reg.49 DVI_YUV This has nothing to do with compression
1952
1953 //catched values for NT1004
1954 // value[0] = 0xFF; // Never apply intra mode automatically
1955 // value[1] = 0xF1; // Use full frame height for virtual strip width; One line per strip
1956 // value[2] = 0x01; // Force intra mode on all new frames
1957 // value[3] = 0x00; // Strip size 400 Bytes; do not force up
1958 // value[4] = 0xA2; //
1959 if (!USBVISION_IS_OPERATIONAL(usbvision))
1960 return 0;
1961
1962 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1963 USBVISION_OP_CODE,
1964 USB_DIR_OUT | USB_TYPE_VENDOR |
1965 USB_RECIP_ENDPOINT, 0,
1966 (__u16) USBVISION_INTRA_CYC, value, 5, HZ);
1967
1968 if (rc < 0) {
1969 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
1970 "reconnect or reload driver.\n", proc, rc);
1971 return rc;
1972 }
1973
1974 if (usbvision->bridgeType == BRIDGE_NT1004) {
1975 value[0] = 20; // PCM Threshold 1
1976 value[1] = 12; // PCM Threshold 2
1977 value[2] = 255; // Distorsion Threshold inter
1978 value[3] = 255; // Distorsion Threshold intra
1979 value[4] = 43; // Max Distorsion inter
1980 value[5] = 43; // Max Distorsion intra
1981 }
1982 else {
1983 value[0] = 20; // PCM Threshold 1
1984 value[1] = 12; // PCM Threshold 2
1985 value[2] = 255; // Distorsion Threshold d7-d0
1986 value[3] = 0; // Distorsion Threshold d11-d8
1987 value[4] = 43; // Max Distorsion d7-d0
1988 value[5] = 0; // Max Distorsion d8
1989 }
1990
1991 if (!USBVISION_IS_OPERATIONAL(usbvision))
1992 return 0;
1993
1994 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1995 USBVISION_OP_CODE,
1996 USB_DIR_OUT | USB_TYPE_VENDOR |
1997 USB_RECIP_ENDPOINT, 0,
1998 (__u16) USBVISION_PCM_THR1, value, 6, HZ);
1999
2000 if (rc < 0) {
2001 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
2002 "reconnect or reload driver.\n", proc, rc);
2003 return rc;
2004 }
2005
2006
2007 return rc;
2008}
2009
2010
2011/*
2012 * usbvision_set_input()
2013 *
2014 * Set the input (saa711x, ...) size x y and other misc input params
2015 * I've no idea if this parameters are right
2016 *
2017 */
2018int usbvision_set_input(struct usb_usbvision *usbvision)
2019{
2020 static const char proc[] = "usbvision_set_input: ";
2021 int rc;
2022 unsigned char value[8];
2023 unsigned char dvi_yuv_value;
2024
2025 if (!USBVISION_IS_OPERATIONAL(usbvision))
2026 return 0;
2027
2028 /* Set input format expected from decoder*/
2029 if (usbvision_device_data[usbvision->DevModel].Vin_Reg1 >= 0) {
2030 value[0] = usbvision_device_data[usbvision->DevModel].Vin_Reg1 & 0xff;
2031 } else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) {
2032 /* SAA7113 uses 8 bit output */
2033 value[0] = USBVISION_8_422_SYNC;
2034 } else {
2035 /* I'm sure only about d2-d0 [010] 16 bit 4:2:2 usin sync pulses
2036 * as that is how saa7111 is configured */
2037 value[0] = USBVISION_16_422_SYNC;
2038 /* | USBVISION_VSNC_POL | USBVISION_VCLK_POL);*/
2039 }
2040
2041 rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]);
2042 if (rc < 0) {
2043 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
2044 "reconnect or reload driver.\n", proc, rc);
2045 return rc;
2046 }
2047
2048
2049 if (usbvision->tvnorm->id & V4L2_STD_PAL) {
2050 value[0] = 0xC0;
2051 value[1] = 0x02; //0x02C0 -> 704 Input video line length
2052 value[2] = 0x20;
2053 value[3] = 0x01; //0x0120 -> 288 Input video n. of lines
2054 value[4] = 0x60;
2055 value[5] = 0x00; //0x0060 -> 96 Input video h offset
2056 value[6] = 0x16;
2057 value[7] = 0x00; //0x0016 -> 22 Input video v offset
2058 } else if (usbvision->tvnorm->id & V4L2_STD_SECAM) {
2059 value[0] = 0xC0;
2060 value[1] = 0x02; //0x02C0 -> 704 Input video line length
2061 value[2] = 0x20;
2062 value[3] = 0x01; //0x0120 -> 288 Input video n. of lines
2063 value[4] = 0x01;
2064 value[5] = 0x00; //0x0001 -> 01 Input video h offset
2065 value[6] = 0x01;
2066 value[7] = 0x00; //0x0001 -> 01 Input video v offset
2067 } else { /* V4L2_STD_NTSC */
2068 value[0] = 0xD0;
2069 value[1] = 0x02; //0x02D0 -> 720 Input video line length
2070 value[2] = 0xF0;
2071 value[3] = 0x00; //0x00F0 -> 240 Input video number of lines
2072 value[4] = 0x50;
2073 value[5] = 0x00; //0x0050 -> 80 Input video h offset
2074 value[6] = 0x10;
2075 value[7] = 0x00; //0x0010 -> 16 Input video v offset
2076 }
2077
2078 if (usbvision_device_data[usbvision->DevModel].X_Offset >= 0) {
2079 value[4]=usbvision_device_data[usbvision->DevModel].X_Offset & 0xff;
2080 value[5]=(usbvision_device_data[usbvision->DevModel].X_Offset & 0x0300) >> 8;
2081 }
2082
2083 if (usbvision_device_data[usbvision->DevModel].Y_Offset >= 0) {
2084 value[6]=usbvision_device_data[usbvision->DevModel].Y_Offset & 0xff;
2085 value[7]=(usbvision_device_data[usbvision->DevModel].Y_Offset & 0x0300) >> 8;
2086 }
2087
2088 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2089 USBVISION_OP_CODE, /* USBVISION specific code */
2090 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0,
2091 (__u16) USBVISION_LXSIZE_I, value, 8, HZ);
2092 if (rc < 0) {
2093 printk(KERN_ERR "%sERROR=%d. USBVISION stopped - "
2094 "reconnect or reload driver.\n", proc, rc);
2095 return rc;
2096 }
2097
2098
2099 dvi_yuv_value = 0x00; /* U comes after V, Ya comes after U/V, Yb comes after Yb */
2100
2101 if(usbvision_device_data[usbvision->DevModel].Dvi_yuv >= 0){
2102 dvi_yuv_value = usbvision_device_data[usbvision->DevModel].Dvi_yuv & 0xff;
2103 }
2104 else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) {
2105 /* This changes as the fine sync control changes. Further investigation necessary */
2106 dvi_yuv_value = 0x06;
2107 }
2108
2109 return (usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value));
2110}
2111
2112
2113/*
2114 * usbvision_set_dram_settings()
2115 *
2116 * Set the buffer address needed by the usbvision dram to operate
2117 * This values has been taken with usbsnoop.
2118 *
2119 */
2120
2121static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2122{
2123 int rc;
2124 unsigned char value[8];
2125
2126 if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
2127 value[0] = 0x42;
2128 value[1] = 0x71;
2129 value[2] = 0xff;
2130 value[3] = 0x00;
2131 value[4] = 0x98;
2132 value[5] = 0xe0;
2133 value[6] = 0x71;
2134 value[7] = 0xff;
2135 // UR: 0x0E200-0x3FFFF = 204288 Words (1 Word = 2 Byte)
2136 // FDL: 0x00000-0x0E099 = 57498 Words
2137 // VDW: 0x0E3FF-0x3FFFF
2138 }
2139 else {
2140 value[0] = 0x42;
2141 value[1] = 0x00;
2142 value[2] = 0xff;
2143 value[3] = 0x00;
2144 value[4] = 0x00;
2145 value[5] = 0x00;
2146 value[6] = 0x00;
2147 value[7] = 0xff;
2148 }
2149 /* These are the values of the address of the video buffer,
2150 * they have to be loaded into the USBVISION_DRM_PRM1-8
2151 *
2152 * Start address of video output buffer for read: drm_prm1-2 -> 0x00000
2153 * End address of video output buffer for read: drm_prm1-3 -> 0x1ffff
2154 * Start address of video frame delay buffer: drm_prm1-4 -> 0x20000
2155 * Only used in compressed mode
2156 * End address of video frame delay buffer: drm_prm1-5-6 -> 0x3ffff
2157 * Only used in compressed mode
2158 * Start address of video output buffer for write: drm_prm1-7 -> 0x00000
2159 * End address of video output buffer for write: drm_prm1-8 -> 0x1ffff
2160 */
2161
2162 if (!USBVISION_IS_OPERATIONAL(usbvision))
2163 return 0;
2164
2165 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2166 USBVISION_OP_CODE, /* USBVISION specific code */
2167 USB_DIR_OUT | USB_TYPE_VENDOR |
2168 USB_RECIP_ENDPOINT, 0,
2169 (__u16) USBVISION_DRM_PRM1, value, 8, HZ);
2170
2171 if (rc < 0) {
2172 err("%sERROR=%d", __FUNCTION__, rc);
2173 return rc;
2174 }
2175
2176 /* Restart the video buffer logic */
2177 if ((rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
2178 USBVISION_RES_FDL | USBVISION_RES_VDW)) < 0)
2179 return rc;
2180 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
2181
2182 return rc;
2183}
2184
2185/*
2186 * ()
2187 *
2188 * Power on the device, enables suspend-resume logic
2189 * & reset the isoc End-Point
2190 *
2191 */
2192
2193int usbvision_power_on(struct usb_usbvision *usbvision)
2194{
2195 int errCode = 0;
2196
2197 PDEBUG(DBG_FUNC, "");
2198
2199 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2200 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2201 USBVISION_SSPND_EN | USBVISION_RES2);
2202 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2203 USBVISION_SSPND_EN | USBVISION_PWR_VID);
2204 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2205 USBVISION_SSPND_EN | USBVISION_PWR_VID | USBVISION_RES2);
2206 if (errCode == 1) {
2207 usbvision->power = 1;
2208 }
2209 PDEBUG(DBG_FUNC, "%s: errCode %d", (errCode<0)?"ERROR":"power is on", errCode);
2210 return errCode;
2211}
2212
2213
2214/*
2215 * usbvision timer stuff
2216 */
2217
2218// to call usbvision_power_off from task queue
2219static void call_usbvision_power_off(struct work_struct *work)
2220{
2221 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, powerOffWork);
2222
2223 PDEBUG(DBG_FUNC, "");
2224 down_interruptible(&usbvision->lock);
2225 if(usbvision->user == 0) {
2226 usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
2227
2228 usbvision_power_off(usbvision);
2229 usbvision->initialized = 0;
2230 }
2231 up(&usbvision->lock);
2232}
2233
2234static void usbvision_powerOffTimer(unsigned long data)
2235{
2236 struct usb_usbvision *usbvision = (void *) data;
2237
2238 PDEBUG(DBG_FUNC, "");
2239 del_timer(&usbvision->powerOffTimer);
2240 INIT_WORK(&usbvision->powerOffWork, call_usbvision_power_off);
2241 (void) schedule_work(&usbvision->powerOffWork);
2242
2243}
2244
2245void usbvision_init_powerOffTimer(struct usb_usbvision *usbvision)
2246{
2247 init_timer(&usbvision->powerOffTimer);
2248 usbvision->powerOffTimer.data = (long) usbvision;
2249 usbvision->powerOffTimer.function = usbvision_powerOffTimer;
2250}
2251
2252void usbvision_set_powerOffTimer(struct usb_usbvision *usbvision)
2253{
2254 mod_timer(&usbvision->powerOffTimer, jiffies + USBVISION_POWEROFF_TIME);
2255}
2256
2257void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision)
2258{
2259 if (timer_pending(&usbvision->powerOffTimer)) {
2260 del_timer(&usbvision->powerOffTimer);
2261 }
2262}
2263
2264/*
2265 * usbvision_begin_streaming()
2266 * Sure you have to put bit 7 to 0, if not incoming frames are droped, but no
2267 * idea about the rest
2268 */
2269int usbvision_begin_streaming(struct usb_usbvision *usbvision)
2270{
2271 int errCode = 0;
2272
2273 if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
2274 usbvision_init_compression(usbvision);
2275 }
2276 errCode = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, USBVISION_NOHVALID |
2277 usbvision->Vin_Reg2_Preset);
2278 return errCode;
2279}
2280
2281/*
2282 * usbvision_restart_isoc()
2283 * Not sure yet if touching here PWR_REG make loose the config
2284 */
2285
2286int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2287{
2288 int ret;
2289
2290 if (
2291 (ret =
2292 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2293 USBVISION_SSPND_EN | USBVISION_PWR_VID)) < 0)
2294 return ret;
2295 if (
2296 (ret =
2297 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2298 USBVISION_SSPND_EN | USBVISION_PWR_VID |
2299 USBVISION_RES2)) < 0)
2300 return ret;
2301 if (
2302 (ret =
2303 usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2304 USBVISION_KEEP_BLANK | USBVISION_NOHVALID |
2305 usbvision->Vin_Reg2_Preset)) < 0) return ret;
2306
2307 /* TODO: schedule timeout */
2308 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) && 0x01) != 1);
2309
2310 return 0;
2311}
2312
2313int usbvision_audio_off(struct usb_usbvision *usbvision)
2314{
2315 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
2316 printk(KERN_ERR "usbvision_audio_off: can't wirte reg\n");
2317 return -1;
2318 }
2319 usbvision->AudioMute = 0;
2320 usbvision->AudioChannel = USBVISION_AUDIO_MUTE;
2321 return 0;
2322}
2323
2324int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel)
2325{
2326 if (!usbvision->AudioMute) {
2327 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, AudioChannel) < 0) {
2328 printk(KERN_ERR "usbvision_set_audio: can't write iopin register for audio switching\n");
2329 return -1;
2330 }
2331 }
2332 usbvision->AudioChannel = AudioChannel;
2333 return 0;
2334}
2335
2336int usbvision_setup(struct usb_usbvision *usbvision,int format)
2337{
2338 usbvision_set_video_format(usbvision, format);
2339 usbvision_set_dram_settings(usbvision);
2340 usbvision_set_compress_params(usbvision);
2341 usbvision_set_input(usbvision);
2342 usbvision_set_output(usbvision, MAX_USB_WIDTH, MAX_USB_HEIGHT);
2343 usbvision_restart_isoc(usbvision);
2344
2345 /* cosas del PCM */
2346 return USBVISION_IS_OPERATIONAL(usbvision);
2347}
2348
2349
2350int usbvision_sbuf_alloc(struct usb_usbvision *usbvision)
2351{
2352 int i, errCode = 0;
2353 const int sb_size = USBVISION_URB_FRAMES * USBVISION_MAX_ISOC_PACKET_SIZE;
2354
2355 /* Clean pointers so we know if we allocated something */
2356 for (i = 0; i < USBVISION_NUMSBUF; i++)
2357 usbvision->sbuf[i].data = NULL;
2358
2359 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2360 usbvision->sbuf[i].data = kzalloc(sb_size, GFP_KERNEL);
2361 if (usbvision->sbuf[i].data == NULL) {
2362 err("%s: unable to allocate %d bytes for sbuf", __FUNCTION__, sb_size);
2363 errCode = -ENOMEM;
2364 break;
2365 }
2366 }
2367 return errCode;
2368}
2369
2370
2371void usbvision_sbuf_free(struct usb_usbvision *usbvision)
2372{
2373 int i;
2374
2375 for (i = 0; i < USBVISION_NUMSBUF; i++) {
2376 if (usbvision->sbuf[i].data != NULL) {
2377 kfree(usbvision->sbuf[i].data);
2378 usbvision->sbuf[i].data = NULL;
2379 }
2380 }
2381}
2382
2383/*
2384 * usbvision_init_isoc()
2385 *
2386 */
2387int usbvision_init_isoc(struct usb_usbvision *usbvision)
2388{
2389 struct usb_device *dev = usbvision->dev;
2390 int bufIdx, errCode, regValue;
2391
2392 if (!USBVISION_IS_OPERATIONAL(usbvision))
2393 return -EFAULT;
2394
2395 usbvision->curFrame = NULL;
2396 scratch_reset(usbvision);
2397
2398 /* Alternate interface 1 is is the biggest frame size */
2399 errCode = usb_set_interface(dev, usbvision->iface, usbvision->ifaceAltActive);
2400 if (errCode < 0) {
2401 usbvision->last_error = errCode;
2402 return -EBUSY;
2403 }
2404
2405 regValue = (16 - usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
2406 usbvision->isocPacketSize = (regValue == 0) ? 0 : (regValue * 64) - 1;
2407 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", usbvision->isocPacketSize);
2408
2409 usbvision->usb_bandwidth = regValue >> 1;
2410 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", usbvision->usb_bandwidth);
2411
2412
2413
2414 /* We double buffer the Iso lists */
2415
2416 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2417 int j, k;
2418 struct urb *urb;
2419
2420 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
2421 if (urb == NULL) {
2422 err("%s: usb_alloc_urb() failed", __FUNCTION__);
2423 return -ENOMEM;
2424 }
2425 usbvision->sbuf[bufIdx].urb = urb;
2426 urb->dev = dev;
2427 urb->context = usbvision;
2428 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
2429 urb->transfer_flags = URB_ISO_ASAP;
2430 urb->interval = 1;
2431 urb->transfer_buffer = usbvision->sbuf[bufIdx].data;
2432 urb->complete = usbvision_isocIrq;
2433 urb->number_of_packets = USBVISION_URB_FRAMES;
2434 urb->transfer_buffer_length =
2435 usbvision->isocPacketSize * USBVISION_URB_FRAMES;
2436 for (j = k = 0; j < USBVISION_URB_FRAMES; j++,
2437 k += usbvision->isocPacketSize) {
2438 urb->iso_frame_desc[j].offset = k;
2439 urb->iso_frame_desc[j].length = usbvision->isocPacketSize;
2440 }
2441 }
2442
2443
2444 /* Submit all URBs */
2445 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2446 errCode = usb_submit_urb(usbvision->sbuf[bufIdx].urb, GFP_KERNEL);
2447 if (errCode) {
2448 err("%s: usb_submit_urb(%d) failed: error %d", __FUNCTION__, bufIdx, errCode);
2449 }
2450 }
2451
2452 usbvision->streaming = Stream_Idle;
2453 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x", __FUNCTION__, usbvision->video_endp);
2454 return 0;
2455}
2456
2457/*
2458 * usbvision_stop_isoc()
2459 *
2460 * This procedure stops streaming and deallocates URBs. Then it
2461 * activates zero-bandwidth alt. setting of the video interface.
2462 *
2463 */
2464void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2465{
2466 int bufIdx, errCode, regValue;
2467
2468 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
2469 return;
2470
2471 /* Unschedule all of the iso td's */
2472 for (bufIdx = 0; bufIdx < USBVISION_NUMSBUF; bufIdx++) {
2473 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2474 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2475 usbvision->sbuf[bufIdx].urb = NULL;
2476 }
2477
2478
2479 PDEBUG(DBG_ISOC, "%s: streaming=Stream_Off\n", __FUNCTION__);
2480 usbvision->streaming = Stream_Off;
2481
2482 if (!usbvision->remove_pending) {
2483
2484 /* Set packet size to 0 */
2485 errCode = usb_set_interface(usbvision->dev, usbvision->iface,
2486 usbvision->ifaceAltInactive);
2487 if (errCode < 0) {
2488 err("%s: usb_set_interface() failed: error %d", __FUNCTION__, errCode);
2489 usbvision->last_error = errCode;
2490 }
2491 regValue = (16 - usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
2492 usbvision->isocPacketSize = (regValue == 0) ? 0 : (regValue * 64) - 1;
2493 PDEBUG(DBG_ISOC, "ISO Packet Length:%d", usbvision->isocPacketSize);
2494
2495 usbvision->usb_bandwidth = regValue >> 1;
2496 PDEBUG(DBG_ISOC, "USB Bandwidth Usage: %dMbit/Sec", usbvision->usb_bandwidth);
2497 }
2498}
2499
2500int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2501{
2502 int mode[4];
2503 int audio[]= {1, 0, 0, 0};
2504 struct v4l2_routing route;
2505 //channel 0 is TV with audiochannel 1 (tuner mono)
2506 //channel 1 is Composite with audio channel 0 (line in)
2507 //channel 2 is S-Video with audio channel 0 (line in)
2508 //channel 3 is additional video inputs to the device with audio channel 0 (line in)
2509
2510 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
2511 usbvision->ctl_input = channel;
2512 route.input = SAA7115_COMPOSITE1;
2513 call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route);
2514 call_i2c_clients(usbvision, VIDIOC_S_INPUT, &usbvision->ctl_input);
2515
2516 // set the new channel
2517 // Regular USB TV Tuners -> channel: 0 = Television, 1 = Composite, 2 = S-Video
2518 // Four video input devices -> channel: 0 = Chan White, 1 = Chan Green, 2 = Chan Yellow, 3 = Chan Red
2519
2520 switch (usbvision_device_data[usbvision->DevModel].Codec) {
2521 case CODEC_SAA7113:
2522 if (SwitchSVideoInput) { // To handle problems with S-Video Input for some devices. Use SwitchSVideoInput parameter when loading the module.
2523 mode[2] = 1;
2524 }
2525 else {
2526 mode[2] = 7;
2527 }
2528 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
2529 mode[0] = 0; mode[1] = 2; mode[3] = 3; // Special for four input devices
2530 }
2531 else {
2532 mode[0] = 0; mode[1] = 2; //modes for regular saa7113 devices
2533 }
2534 break;
2535 case CODEC_SAA7111:
2536 mode[0] = 0; mode[1] = 1; mode[2] = 7; //modes for saa7111
2537 break;
2538 default:
2539 mode[0] = 0; mode[1] = 1; mode[2] = 7; //default modes
2540 }
2541 route.input = mode[channel];
2542 call_i2c_clients(usbvision, VIDIOC_INT_S_VIDEO_ROUTING,&route);
2543 usbvision->channel = channel;
2544 usbvision_set_audio(usbvision, audio[channel]);
2545 return 0;
2546}
2547
2548/*
2549 * Overrides for Emacs so that we follow Linus's tabbing style.
2550 * ---------------------------------------------------------------------------
2551 * Local variables:
2552 * c-basic-offset: 8
2553 * End:
2554 */
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
new file mode 100644
index 000000000000..0f3fba7ea6fe
--- /dev/null
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -0,0 +1,571 @@
1/*
2 * I2C_ALGO_USB.C
3 * i2c algorithm for USB-I2C Bridges
4 *
5 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 * Dwaine Garden <dwainegarden@rogers.com>
7 *
8 * This module is part of usbvision driver project.
9 * Updates to driver completed by Dwaine P. Garden
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/version.h>
32#include <linux/utsname.h>
33#include <linux/init.h>
34#include <asm/uaccess.h>
35#include <linux/ioport.h>
36#include <linux/errno.h>
37#include <linux/sched.h>
38#include <linux/usb.h>
39#include <linux/i2c.h>
40#include "usbvision.h"
41
42#define DBG_I2C 1<<0
43#define DBG_ALGO 1<<1
44
45static int i2c_debug = 0;
46
47module_param (i2c_debug, int, 0644); // debug_i2c_usb mode of the device driver
48MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
49
50#define PDEBUG(level, fmt, args...) \
51 if (i2c_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
52
53static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
54 short len);
55static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
56 short len);
57
58static inline int try_write_address(struct i2c_adapter *i2c_adap,
59 unsigned char addr, int retries)
60{
61 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
62 void *data;
63 int i, ret = -1;
64 char buf[4];
65
66 data = i2c_get_adapdata(i2c_adap);
67 buf[0] = 0x00;
68 for (i = 0; i <= retries; i++) {
69 ret = (usbvision_i2c_write(data, addr, buf, 1));
70 if (ret == 1)
71 break; /* success! */
72 udelay(5 /*adap->udelay */ );
73 if (i == retries) /* no success */
74 break;
75 udelay(adap->udelay);
76 }
77 if (i) {
78 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
79 PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
80 }
81 return ret;
82}
83
84static inline int try_read_address(struct i2c_adapter *i2c_adap,
85 unsigned char addr, int retries)
86{
87 struct i2c_algo_usb_data *adap = i2c_adap->algo_data;
88 void *data;
89 int i, ret = -1;
90 char buf[4];
91
92 data = i2c_get_adapdata(i2c_adap);
93 for (i = 0; i <= retries; i++) {
94 ret = (usbvision_i2c_read(data, addr, buf, 1));
95 if (ret == 1)
96 break; /* success! */
97 udelay(5 /*adap->udelay */ );
98 if (i == retries) /* no success */
99 break;
100 udelay(adap->udelay);
101 }
102 if (i) {
103 PDEBUG(DBG_ALGO,"Needed %d retries for address %#2x", i, addr);
104 PDEBUG(DBG_ALGO,"Maybe there's no device at this address");
105 }
106 return ret;
107}
108
109static inline int usb_find_address(struct i2c_adapter *i2c_adap,
110 struct i2c_msg *msg, int retries,
111 unsigned char *add)
112{
113 unsigned short flags = msg->flags;
114
115 unsigned char addr;
116 int ret;
117 if ((flags & I2C_M_TEN)) {
118 /* a ten bit address */
119 addr = 0xf0 | ((msg->addr >> 7) & 0x03);
120 /* try extended address code... */
121 ret = try_write_address(i2c_adap, addr, retries);
122 if (ret != 1) {
123 err("died at extended address code, while writing");
124 return -EREMOTEIO;
125 }
126 add[0] = addr;
127 if (flags & I2C_M_RD) {
128 /* okay, now switch into reading mode */
129 addr |= 0x01;
130 ret = try_read_address(i2c_adap, addr, retries);
131 if (ret != 1) {
132 err("died at extended address code, while reading");
133 return -EREMOTEIO;
134 }
135 }
136
137 } else { /* normal 7bit address */
138 addr = (msg->addr << 1);
139 if (flags & I2C_M_RD)
140 addr |= 1;
141 if (flags & I2C_M_REV_DIR_ADDR)
142 addr ^= 1;
143
144 add[0] = addr;
145 if (flags & I2C_M_RD)
146 ret = try_read_address(i2c_adap, addr, retries);
147 else
148 ret = try_write_address(i2c_adap, addr, retries);
149
150 if (ret != 1) {
151 return -EREMOTEIO;
152 }
153 }
154 return 0;
155}
156
157static int
158usb_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
159{
160 struct i2c_msg *pmsg;
161 void *data;
162 int i, ret;
163 unsigned char addr;
164
165 data = i2c_get_adapdata(i2c_adap);
166
167 for (i = 0; i < num; i++) {
168 pmsg = &msgs[i];
169 ret = usb_find_address(i2c_adap, pmsg, i2c_adap->retries, &addr);
170 if (ret != 0) {
171 PDEBUG(DBG_ALGO,"got NAK from device, message #%d", i);
172 return (ret < 0) ? ret : -EREMOTEIO;
173 }
174
175 if (pmsg->flags & I2C_M_RD) {
176 /* read bytes into buffer */
177 ret = (usbvision_i2c_read(data, addr, pmsg->buf, pmsg->len));
178 if (ret < pmsg->len) {
179 return (ret < 0) ? ret : -EREMOTEIO;
180 }
181 } else {
182 /* write bytes from buffer */
183 ret = (usbvision_i2c_write(data, addr, pmsg->buf, pmsg->len));
184 if (ret < pmsg->len) {
185 return (ret < 0) ? ret : -EREMOTEIO;
186 }
187 }
188 }
189 return num;
190}
191
192static int algo_control(struct i2c_adapter *adapter, unsigned int cmd, unsigned long arg)
193{
194 return 0;
195}
196
197static u32 usb_func(struct i2c_adapter *adap)
198{
199 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING;
200}
201
202
203/* -----exported algorithm data: ------------------------------------- */
204
205static struct i2c_algorithm i2c_usb_algo = {
206 .master_xfer = usb_xfer,
207 .smbus_xfer = NULL,
208 .algo_control = algo_control,
209 .functionality = usb_func,
210};
211
212
213/*
214 * registering functions to load algorithms at runtime
215 */
216int usbvision_i2c_usb_add_bus(struct i2c_adapter *adap)
217{
218 PDEBUG(DBG_I2C, "I2C debugging is enabled [i2c]");
219 PDEBUG(DBG_ALGO, "ALGO debugging is enabled [i2c]");
220
221 /* register new adapter to i2c module... */
222
223 adap->algo = &i2c_usb_algo;
224
225 adap->timeout = 100; /* default values, should */
226 adap->retries = 3; /* be replaced by defines */
227
228 i2c_add_adapter(adap);
229
230 PDEBUG(DBG_ALGO,"i2c bus for %s registered", adap->name);
231
232 return 0;
233}
234
235
236int usbvision_i2c_usb_del_bus(struct i2c_adapter *adap)
237{
238
239 i2c_del_adapter(adap);
240
241 PDEBUG(DBG_ALGO,"i2c bus for %s unregistered", adap->name);
242
243 return 0;
244}
245
246
247/* ----------------------------------------------------------------------- */
248/* usbvision specific I2C functions */
249/* ----------------------------------------------------------------------- */
250static struct i2c_adapter i2c_adap_template;
251static struct i2c_algo_usb_data i2c_algo_template;
252static struct i2c_client i2c_client_template;
253
254int usbvision_init_i2c(struct usb_usbvision *usbvision)
255{
256 memcpy(&usbvision->i2c_adap, &i2c_adap_template,
257 sizeof(struct i2c_adapter));
258 memcpy(&usbvision->i2c_algo, &i2c_algo_template,
259 sizeof(struct i2c_algo_usb_data));
260 memcpy(&usbvision->i2c_client, &i2c_client_template,
261 sizeof(struct i2c_client));
262
263 sprintf(usbvision->i2c_adap.name + strlen(usbvision->i2c_adap.name),
264 " #%d", usbvision->vdev->minor & 0x1f);
265 PDEBUG(DBG_I2C,"Adaptername: %s", usbvision->i2c_adap.name);
266
267 i2c_set_adapdata(&usbvision->i2c_adap, usbvision);
268 i2c_set_clientdata(&usbvision->i2c_client, usbvision);
269 i2c_set_algo_usb_data(&usbvision->i2c_algo, usbvision);
270
271 usbvision->i2c_adap.algo_data = &usbvision->i2c_algo;
272 usbvision->i2c_client.adapter = &usbvision->i2c_adap;
273
274 if (usbvision_write_reg(usbvision, USBVISION_SER_MODE, USBVISION_IIC_LRNACK) < 0) {
275 printk(KERN_ERR "usbvision_init_i2c: can't write reg\n");
276 return -EBUSY;
277 }
278
279#ifdef CONFIG_MODULES
280 /* Request the load of the i2c modules we need */
281 switch (usbvision_device_data[usbvision->DevModel].Codec) {
282 case CODEC_SAA7113:
283 request_module("saa7115");
284 break;
285 case CODEC_SAA7111:
286 request_module("saa7115");
287 break;
288 }
289 if (usbvision_device_data[usbvision->DevModel].Tuner == 1) {
290 request_module("tuner");
291 }
292#endif
293
294 return usbvision_i2c_usb_add_bus(&usbvision->i2c_adap);
295}
296
297void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,
298 void *arg)
299{
300 BUG_ON(NULL == usbvision->i2c_adap.algo_data);
301 i2c_clients_command(&usbvision->i2c_adap, cmd, arg);
302}
303
304static int attach_inform(struct i2c_client *client)
305{
306 struct usb_usbvision *usbvision;
307
308 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
309
310 switch (client->addr << 1) {
311 case 0x43:
312 case 0x4b:
313 {
314 struct tuner_setup tun_setup;
315
316 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
317 tun_setup.type = TUNER_TDA9887;
318 tun_setup.addr = client->addr;
319
320 call_i2c_clients(usbvision, TUNER_SET_TYPE_ADDR, &tun_setup);
321
322 break;
323 }
324 case 0x42:
325 PDEBUG(DBG_I2C,"attach_inform: saa7114 detected.");
326 break;
327 case 0x4a:
328 PDEBUG(DBG_I2C,"attach_inform: saa7113 detected.");
329 break;
330 case 0xa0:
331 PDEBUG(DBG_I2C,"attach_inform: eeprom detected.");
332 break;
333
334 default:
335 {
336 struct tuner_setup tun_setup;
337
338 PDEBUG(DBG_I2C,"attach inform: detected I2C address %x", client->addr << 1);
339 usbvision->tuner_addr = client->addr;
340
341 if ((usbvision->have_tuner) && (usbvision->tuner_type != -1)) {
342 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
343 tun_setup.type = usbvision->tuner_type;
344 tun_setup.addr = usbvision->tuner_addr;
345 call_i2c_clients(usbvision, TUNER_SET_TYPE_ADDR, &tun_setup);
346 }
347 }
348 break;
349 }
350 return 0;
351}
352
353static int detach_inform(struct i2c_client *client)
354{
355 struct usb_usbvision *usbvision;
356
357 usbvision = (struct usb_usbvision *)i2c_get_adapdata(client->adapter);
358
359 PDEBUG(DBG_I2C,"usbvision[%d] detaches %s", usbvision->nr, client->name);
360 return 0;
361}
362
363static int
364usbvision_i2c_read_max4(struct usb_usbvision *usbvision, unsigned char addr,
365 char *buf, short len)
366{
367 int rc, retries;
368
369 for (retries = 5;;) {
370 rc = usbvision_write_reg(usbvision, USBVISION_SER_ADRS, addr);
371 if (rc < 0)
372 return rc;
373
374 /* Initiate byte read cycle */
375 /* USBVISION_SER_CONT <- d0-d2 n. of bytes to r/w */
376 /* d3 0=Wr 1=Rd */
377 rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT,
378 (len & 0x07) | 0x18);
379 if (rc < 0)
380 return rc;
381
382 /* Test for Busy and ACK */
383 do {
384 /* USBVISION_SER_CONT -> d4 == 0 busy */
385 rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT);
386 } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */
387 if (rc < 0)
388 return rc;
389
390 /* USBVISION_SER_CONT -> d5 == 1 Not ack */
391 if ((rc & 0x20) == 0) /* Ack? */
392 break;
393
394 /* I2C abort */
395 rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00);
396 if (rc < 0)
397 return rc;
398
399 if (--retries < 0)
400 return -1;
401 }
402
403 switch (len) {
404 case 4:
405 buf[3] = usbvision_read_reg(usbvision, USBVISION_SER_DAT4);
406 case 3:
407 buf[2] = usbvision_read_reg(usbvision, USBVISION_SER_DAT3);
408 case 2:
409 buf[1] = usbvision_read_reg(usbvision, USBVISION_SER_DAT2);
410 case 1:
411 buf[0] = usbvision_read_reg(usbvision, USBVISION_SER_DAT1);
412 break;
413 default:
414 printk(KERN_ERR
415 "usbvision_i2c_read_max4: buffer length > 4\n");
416 }
417
418 if (i2c_debug & DBG_I2C) {
419 int idx;
420 for (idx = 0; idx < len; idx++) {
421 PDEBUG(DBG_I2C,"read %x from address %x", (unsigned char)buf[idx], addr);
422 }
423 }
424 return len;
425}
426
427
428static int usbvision_i2c_write_max4(struct usb_usbvision *usbvision,
429 unsigned char addr, const char *buf,
430 short len)
431{
432 int rc, retries;
433 int i;
434 unsigned char value[6];
435 unsigned char ser_cont;
436
437 ser_cont = (len & 0x07) | 0x10;
438
439 value[0] = addr;
440 value[1] = ser_cont;
441 for (i = 0; i < len; i++)
442 value[i + 2] = buf[i];
443
444 for (retries = 5;;) {
445 rc = usb_control_msg(usbvision->dev,
446 usb_sndctrlpipe(usbvision->dev, 1),
447 USBVISION_OP_CODE,
448 USB_DIR_OUT | USB_TYPE_VENDOR |
449 USB_RECIP_ENDPOINT, 0,
450 (__u16) USBVISION_SER_ADRS, value,
451 len + 2, HZ);
452
453 if (rc < 0)
454 return rc;
455
456 rc = usbvision_write_reg(usbvision, USBVISION_SER_CONT,
457 (len & 0x07) | 0x10);
458 if (rc < 0)
459 return rc;
460
461 /* Test for Busy and ACK */
462 do {
463 rc = usbvision_read_reg(usbvision, USBVISION_SER_CONT);
464 } while (rc > 0 && ((rc & 0x10) != 0)); /* Retry while busy */
465 if (rc < 0)
466 return rc;
467
468 if ((rc & 0x20) == 0) /* Ack? */
469 break;
470
471 /* I2C abort */
472 usbvision_write_reg(usbvision, USBVISION_SER_CONT, 0x00);
473
474 if (--retries < 0)
475 return -1;
476
477 }
478
479 if (i2c_debug & DBG_I2C) {
480 int idx;
481 for (idx = 0; idx < len; idx++) {
482 PDEBUG(DBG_I2C,"wrote %x at address %x", (unsigned char)buf[idx], addr);
483 }
484 }
485 return len;
486}
487
488static int usbvision_i2c_write(void *data, unsigned char addr, char *buf,
489 short len)
490{
491 char *bufPtr = buf;
492 int retval;
493 int wrcount = 0;
494 int count;
495 int maxLen = 4;
496 struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
497
498 while (len > 0) {
499 count = (len > maxLen) ? maxLen : len;
500 retval = usbvision_i2c_write_max4(usbvision, addr, bufPtr, count);
501 if (retval > 0) {
502 len -= count;
503 bufPtr += count;
504 wrcount += count;
505 } else
506 return (retval < 0) ? retval : -EFAULT;
507 }
508 return wrcount;
509}
510
511static int usbvision_i2c_read(void *data, unsigned char addr, char *buf,
512 short len)
513{
514 char temp[4];
515 int retval, i;
516 int rdcount = 0;
517 int count;
518 struct usb_usbvision *usbvision = (struct usb_usbvision *) data;
519
520 while (len > 0) {
521 count = (len > 3) ? 4 : len;
522 retval = usbvision_i2c_read_max4(usbvision, addr, temp, count);
523 if (retval > 0) {
524 for (i = 0; i < len; i++)
525 buf[rdcount + i] = temp[i];
526 len -= count;
527 rdcount += count;
528 } else
529 return (retval < 0) ? retval : -EFAULT;
530 }
531 return rdcount;
532}
533
534static struct i2c_algo_usb_data i2c_algo_template = {
535 .data = NULL,
536 .inb = usbvision_i2c_read,
537 .outb = usbvision_i2c_write,
538 .udelay = 10,
539 .mdelay = 10,
540 .timeout = 100,
541};
542
543static struct i2c_adapter i2c_adap_template = {
544 .owner = THIS_MODULE,
545 .name = "usbvision",
546 .id = I2C_HW_B_BT848, /* FIXME */
547 .algo = NULL,
548 .algo_data = NULL,
549 .client_register = attach_inform,
550 .client_unregister = detach_inform,
551#ifdef I2C_ADAP_CLASS_TV_ANALOG
552 .class = I2C_ADAP_CLASS_TV_ANALOG,
553#else
554 .class = I2C_CLASS_TV_ANALOG,
555#endif
556};
557
558static struct i2c_client i2c_client_template = {
559 .name = "usbvision internal",
560};
561
562EXPORT_SYMBOL(usbvision_i2c_usb_add_bus);
563EXPORT_SYMBOL(usbvision_i2c_usb_del_bus);
564
565/*
566 * Overrides for Emacs so that we follow Linus's tabbing style.
567 * ---------------------------------------------------------------------------
568 * Local variables:
569 * c-basic-offset: 8
570 * End:
571 */
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
new file mode 100644
index 000000000000..864446c012eb
--- /dev/null
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -0,0 +1,2051 @@
1/*
2 * USB USBVISION Video device driver 0.9.9
3 *
4 *
5 *
6 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
7 *
8 * This module is part of usbvision driver project.
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 as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Let's call the version 0.... until compression decoding is completely
25 * implemented.
26 *
27 * This driver is written by Jose Ignacio Gijon and Joerg Heckenbach.
28 * It was based on USB CPiA driver written by Peter Pregler,
29 * Scott J. Bertin and Johannes Erdfelt
30 * Ideas are taken from bttv driver by Ralph Metzler, Marcus Metzler &
31 * Gerd Knorr and zoran 36120/36125 driver by Pauline Middelink
32 * Updates to driver completed by Dwaine P. Garden
33 *
34 *
35 * TODO:
36 * - use submit_urb for all setup packets
37 * - Fix memory settings for nt1004. It is 4 times as big as the
38 * nt1003 memory.
39 * - Add audio on endpoint 3 for nt1004 chip. Seems impossible, needs a codec interface. Which one?
40 * - Clean up the driver.
41 * - optimization for performance.
42 * - Add Videotext capability (VBI). Working on it.....
43 * - Check audio for other devices
44 *
45 */
46
47#include <linux/version.h>
48#include <linux/kernel.h>
49#include <linux/sched.h>
50#include <linux/list.h>
51#include <linux/timer.h>
52#include <linux/slab.h>
53#include <linux/mm.h>
54#include <linux/utsname.h>
55#include <linux/highmem.h>
56#include <linux/smp_lock.h>
57#include <linux/videodev.h>
58#include <linux/vmalloc.h>
59#include <linux/module.h>
60#include <linux/init.h>
61#include <linux/spinlock.h>
62#include <asm/io.h>
63#include <linux/videodev2.h>
64#include <linux/video_decoder.h>
65#include <linux/i2c.h>
66
67#include <media/saa7115.h>
68#include <media/v4l2-common.h>
69#include <media/tuner.h>
70#include <media/audiochip.h>
71
72#include <linux/moduleparam.h>
73#include <linux/workqueue.h>
74
75#ifdef CONFIG_KMOD
76#include <linux/kmod.h>
77#endif
78
79#include "usbvision.h"
80
81#define DRIVER_AUTHOR "Joerg Heckenbach <joerg@heckenbach-aw.de>, Dwaine Garden <DwaineGarden@rogers.com>"
82#define DRIVER_NAME "usbvision"
83#define DRIVER_ALIAS "USBVision"
84#define DRIVER_DESC "USBVision USB Video Device Driver for Linux"
85#define DRIVER_LICENSE "GPL"
86#define USBVISION_DRIVER_VERSION_MAJOR 0
87#define USBVISION_DRIVER_VERSION_MINOR 9
88#define USBVISION_DRIVER_VERSION_PATCHLEVEL 9
89#define USBVISION_DRIVER_VERSION KERNEL_VERSION(USBVISION_DRIVER_VERSION_MAJOR,USBVISION_DRIVER_VERSION_MINOR,USBVISION_DRIVER_VERSION_PATCHLEVEL)
90#define USBVISION_VERSION_STRING __stringify(USBVISION_DRIVER_VERSION_MAJOR) "." __stringify(USBVISION_DRIVER_VERSION_MINOR) "." __stringify(USBVISION_DRIVER_VERSION_PATCHLEVEL)
91
92#define ENABLE_HEXDUMP 0 /* Enable if you need it */
93
94
95#ifdef USBVISION_DEBUG
96 #define PDEBUG(level, fmt, args...) \
97 if (video_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args)
98#else
99 #define PDEBUG(level, fmt, args...) do {} while(0)
100#endif
101
102#define DBG_IOCTL 1<<0
103#define DBG_IO 1<<1
104#define DBG_PROBE 1<<2
105#define DBG_MMAP 1<<3
106
107//String operations
108#define rmspace(str) while(*str==' ') str++;
109#define goto2next(str) while(*str!=' ') str++; while(*str==' ') str++;
110
111
112static int usbvision_nr = 0; // sequential number of usbvision device
113
114static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
115 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
116 { 1, 2, 16, V4L2_PIX_FMT_RGB565 , "RGB565" },
117 { 1, 3, 24, V4L2_PIX_FMT_RGB24 , "RGB24" },
118 { 1, 4, 32, V4L2_PIX_FMT_RGB32 , "RGB32" },
119 { 1, 2, 16, V4L2_PIX_FMT_RGB555 , "RGB555" },
120 { 1, 2, 16, V4L2_PIX_FMT_YUYV , "YUV422" },
121 { 1, 2, 12, V4L2_PIX_FMT_YVU420 , "YUV420P" }, // 1.5 !
122 { 1, 2, 16, V4L2_PIX_FMT_YUV422P , "YUV422P" }
123};
124
125/* supported tv norms */
126static struct usbvision_tvnorm tvnorms[] = {
127 {
128 .name = "PAL",
129 .id = V4L2_STD_PAL,
130 }, {
131 .name = "NTSC",
132 .id = V4L2_STD_NTSC,
133 }, {
134 .name = "SECAM",
135 .id = V4L2_STD_SECAM,
136 }, {
137 .name = "PAL-M",
138 .id = V4L2_STD_PAL_M,
139 }
140};
141
142#define TVNORMS ARRAY_SIZE(tvnorms)
143
144// Function prototypes
145static void usbvision_release(struct usb_usbvision *usbvision);
146
147// Default initalization of device driver parameters
148static int isocMode = ISOC_MODE_COMPRESS; // Set the default format for ISOC endpoint
149static int video_debug = 0; // Set the default Debug Mode of the device driver
150static int PowerOnAtOpen = 1; // Set the default device to power on at startup
151static int video_nr = -1; // Sequential Number of Video Device
152static int radio_nr = -1; // Sequential Number of Radio Device
153static int vbi_nr = -1; // Sequential Number of VBI Device
154static char *CustomDevice=NULL; // Set as nothing....
155
156// Grab parameters for the device driver
157
158#if defined(module_param) // Showing parameters under SYSFS
159module_param(isocMode, int, 0444);
160module_param(video_debug, int, 0444);
161module_param(PowerOnAtOpen, int, 0444);
162module_param(video_nr, int, 0444);
163module_param(radio_nr, int, 0444);
164module_param(vbi_nr, int, 0444);
165module_param(CustomDevice, charp, 0444);
166#else // Old Style
167MODULE_PARAM(isocMode, "i");
168MODULE_PARM(video_debug, "i"); // Grab the Debug Mode of the device driver
169MODULE_PARM(adjustCompression, "i"); // Grab the compression to be adaptive
170MODULE_PARM(PowerOnAtOpen, "i"); // Grab the device to power on at startup
171MODULE_PARM(SwitchSVideoInput, "i"); // To help people with Black and White output with using s-video input. Some cables and input device are wired differently.
172MODULE_PARM(video_nr, "i"); // video_nr option allows to specify a certain /dev/videoX device (like /dev/video0 or /dev/video1 ...)
173MODULE_PARM(radio_nr, "i"); // radio_nr option allows to specify a certain /dev/radioX device (like /dev/radio0 or /dev/radio1 ...)
174MODULE_PARM(vbi_nr, "i"); // vbi_nr option allows to specify a certain /dev/vbiX device (like /dev/vbi0 or /dev/vbi1 ...)
175MODULE_PARM(CustomDevice, "s"); // .... CustomDevice
176#endif
177
178MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint. Default: 0x60 (Compression On)");
179MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver. Default: 0 (Off)");
180MODULE_PARM_DESC(PowerOnAtOpen, " Set the default device to power on when device is opened. Default: 1 (On)");
181MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX). Default: -1 (autodetect)");
182MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX). Default: -1 (autodetect)");
183MODULE_PARM_DESC(vbi_nr, "Set vbi device number (/dev/vbiX). Default: -1 (autodetect)");
184MODULE_PARM_DESC(CustomDevice, " Define the fine tuning parameters for the device. Default: null");
185
186
187// Misc stuff
188MODULE_AUTHOR(DRIVER_AUTHOR);
189MODULE_DESCRIPTION(DRIVER_DESC);
190MODULE_LICENSE(DRIVER_LICENSE);
191MODULE_VERSION(USBVISION_VERSION_STRING);
192MODULE_ALIAS(DRIVER_ALIAS);
193
194
195/****************************************************************************************/
196/* SYSFS Code - Copied from the stv680.c usb module. */
197/* Device information is located at /sys/class/video4linux/video0 */
198/* Device parameters information is located at /sys/module/usbvision */
199/* Device USB Information is located at /sys/bus/usb/drivers/USBVision Video Grabber */
200/****************************************************************************************/
201
202
203#define YES_NO(x) ((x) ? "Yes" : "No")
204
205static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd)
206{
207 struct video_device *vdev = to_video_device(cd);
208 return video_get_drvdata(vdev);
209}
210
211static ssize_t show_version(struct class_device *cd, char *buf)
212{
213 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
214}
215static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
216
217static ssize_t show_model(struct class_device *class_dev, char *buf)
218{
219 struct video_device *vdev = to_video_device(class_dev);
220 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
221 return sprintf(buf, "%s\n", usbvision_device_data[usbvision->DevModel].ModelString);
222}
223static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
224
225static ssize_t show_hue(struct class_device *class_dev, char *buf)
226{
227 struct video_device *vdev = to_video_device(class_dev);
228 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
229 struct v4l2_control ctrl;
230 ctrl.id = V4L2_CID_HUE;
231 ctrl.value = 0;
232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
233 return sprintf(buf, "%d\n", ctrl.value >> 8);
234}
235static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
236
237static ssize_t show_contrast(struct class_device *class_dev, char *buf)
238{
239 struct video_device *vdev = to_video_device(class_dev);
240 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
241 struct v4l2_control ctrl;
242 ctrl.id = V4L2_CID_CONTRAST;
243 ctrl.value = 0;
244 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
245 return sprintf(buf, "%d\n", ctrl.value >> 8);
246}
247static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
248
249static ssize_t show_brightness(struct class_device *class_dev, char *buf)
250{
251 struct video_device *vdev = to_video_device(class_dev);
252 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
253 struct v4l2_control ctrl;
254 ctrl.id = V4L2_CID_BRIGHTNESS;
255 ctrl.value = 0;
256 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
257 return sprintf(buf, "%d\n", ctrl.value >> 8);
258}
259static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
260
261static ssize_t show_saturation(struct class_device *class_dev, char *buf)
262{
263 struct video_device *vdev = to_video_device(class_dev);
264 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
265 struct v4l2_control ctrl;
266 ctrl.id = V4L2_CID_SATURATION;
267 ctrl.value = 0;
268 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
269 return sprintf(buf, "%d\n", ctrl.value >> 8);
270}
271static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
272
273static ssize_t show_streaming(struct class_device *class_dev, char *buf)
274{
275 struct video_device *vdev = to_video_device(class_dev);
276 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
277 return sprintf(buf, "%s\n", YES_NO(usbvision->streaming==Stream_On?1:0));
278}
279static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
280
281static ssize_t show_compression(struct class_device *class_dev, char *buf)
282{
283 struct video_device *vdev = to_video_device(class_dev);
284 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
285 return sprintf(buf, "%s\n", YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
286}
287static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
288
289static ssize_t show_device_bridge(struct class_device *class_dev, char *buf)
290{
291 struct video_device *vdev = to_video_device(class_dev);
292 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
293 return sprintf(buf, "%d\n", usbvision->bridgeType);
294}
295static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
296
297static void usbvision_create_sysfs(struct video_device *vdev)
298{
299 int res;
300 if (vdev) {
301 res=video_device_create_file(vdev, &class_device_attr_version);
302 res=video_device_create_file(vdev, &class_device_attr_model);
303 res=video_device_create_file(vdev, &class_device_attr_hue);
304 res=video_device_create_file(vdev, &class_device_attr_contrast);
305 res=video_device_create_file(vdev, &class_device_attr_brightness);
306 res=video_device_create_file(vdev, &class_device_attr_saturation);
307 res=video_device_create_file(vdev, &class_device_attr_streaming);
308 res=video_device_create_file(vdev, &class_device_attr_compression);
309 res=video_device_create_file(vdev, &class_device_attr_bridge);
310 }
311}
312
313static void usbvision_remove_sysfs(struct video_device *vdev)
314{
315 if (vdev) {
316 video_device_remove_file(vdev, &class_device_attr_version);
317 video_device_remove_file(vdev, &class_device_attr_model);
318 video_device_remove_file(vdev, &class_device_attr_hue);
319 video_device_remove_file(vdev, &class_device_attr_contrast);
320 video_device_remove_file(vdev, &class_device_attr_brightness);
321 video_device_remove_file(vdev, &class_device_attr_saturation);
322 video_device_remove_file(vdev, &class_device_attr_streaming);
323 video_device_remove_file(vdev, &class_device_attr_compression);
324 video_device_remove_file(vdev, &class_device_attr_bridge);
325 }
326}
327
328
329/*
330 * usbvision_open()
331 *
332 * This is part of Video 4 Linux API. The driver can be opened by one
333 * client only (checks internal counter 'usbvision->user'). The procedure
334 * then allocates buffers needed for video processing.
335 *
336 */
337static int usbvision_v4l2_open(struct inode *inode, struct file *file)
338{
339 struct video_device *dev = video_devdata(file);
340 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
341 int errCode = 0;
342
343 PDEBUG(DBG_IO, "open");
344
345
346 usbvision_reset_powerOffTimer(usbvision);
347
348 if (usbvision->user)
349 errCode = -EBUSY;
350 else {
351 /* Allocate memory for the frame buffers */
352 errCode = usbvision_frames_alloc(usbvision);
353 if(!errCode) {
354 /* Allocate memory for the scratch ring buffer */
355 errCode = usbvision_scratch_alloc(usbvision);
356 if(!errCode) {
357 /* Allocate memory for the USB S buffers */
358 errCode = usbvision_sbuf_alloc(usbvision);
359 if ((!errCode) && (usbvision->isocMode==ISOC_MODE_COMPRESS)) {
360 /* Allocate intermediate decompression buffers only if needed */
361 errCode = usbvision_decompress_alloc(usbvision);
362 }
363 }
364 }
365 if (errCode) {
366 /* Deallocate all buffers if trouble */
367 usbvision_frames_free(usbvision);
368 usbvision_scratch_free(usbvision);
369 usbvision_sbuf_free(usbvision);
370 usbvision_decompress_free(usbvision);
371 }
372 }
373
374 /* If so far no errors then we shall start the camera */
375 if (!errCode) {
376 down(&usbvision->lock);
377 if (usbvision->power == 0) {
378 usbvision_power_on(usbvision);
379 usbvision_init_i2c(usbvision);
380 }
381
382 /* Send init sequence only once, it's large! */
383 if (!usbvision->initialized) {
384 int setup_ok = 0;
385 setup_ok = usbvision_setup(usbvision,isocMode);
386 if (setup_ok)
387 usbvision->initialized = 1;
388 else
389 errCode = -EBUSY;
390 }
391
392 if (!errCode) {
393 usbvision_begin_streaming(usbvision);
394 errCode = usbvision_init_isoc(usbvision);
395 /* device needs to be initialized before isoc transfer */
396 usbvision_muxsel(usbvision,0);
397 usbvision->user++;
398 }
399 else {
400 if (PowerOnAtOpen) {
401 usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
402 usbvision_power_off(usbvision);
403 usbvision->initialized = 0;
404 }
405 }
406 up(&usbvision->lock);
407 }
408
409 if (errCode) {
410 }
411
412 /* prepare queues */
413 usbvision_empty_framequeues(usbvision);
414
415 PDEBUG(DBG_IO, "success");
416 return errCode;
417}
418
419/*
420 * usbvision_v4l2_close()
421 *
422 * This is part of Video 4 Linux API. The procedure
423 * stops streaming and deallocates all buffers that were earlier
424 * allocated in usbvision_v4l2_open().
425 *
426 */
427static int usbvision_v4l2_close(struct inode *inode, struct file *file)
428{
429 struct video_device *dev = video_devdata(file);
430 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
431
432 PDEBUG(DBG_IO, "close");
433 down(&usbvision->lock);
434
435 usbvision_audio_off(usbvision);
436 usbvision_restart_isoc(usbvision);
437 usbvision_stop_isoc(usbvision);
438
439 usbvision_decompress_free(usbvision);
440 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
441 usbvision_scratch_free(usbvision);
442 usbvision_sbuf_free(usbvision);
443
444 usbvision->user--;
445
446 if (PowerOnAtOpen) {
447 /* power off in a little while to avoid off/on every close/open short sequences */
448 usbvision_set_powerOffTimer(usbvision);
449 usbvision->initialized = 0;
450 }
451
452 up(&usbvision->lock);
453
454 if (usbvision->remove_pending) {
455 info("%s: Final disconnect", __FUNCTION__);
456 usbvision_release(usbvision);
457 }
458
459 PDEBUG(DBG_IO, "success");
460
461
462 return 0;
463}
464
465
466/*
467 * usbvision_ioctl()
468 *
469 * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
470 *
471 */
472static int usbvision_v4l2_do_ioctl(struct inode *inode, struct file *file,
473 unsigned int cmd, void *arg)
474{
475 struct video_device *dev = video_devdata(file);
476 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
477
478 if (!USBVISION_IS_OPERATIONAL(usbvision))
479 return -EFAULT;
480
481 switch (cmd) {
482
483#ifdef CONFIG_VIDEO_ADV_DEBUG
484 /* ioctls to allow direct acces to the NT100x registers */
485 case VIDIOC_INT_G_REGISTER:
486 {
487 struct v4l2_register *reg = arg;
488 int errCode;
489
490 if (reg->i2c_id != 0)
491 return -EINVAL;
492 /* NT100x has a 8-bit register space */
493 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
494 if (errCode < 0) {
495 err("%s: VIDIOC_INT_G_REGISTER failed: error %d", __FUNCTION__, errCode);
496 }
497 else {
498 reg->val=(unsigned char)errCode;
499 PDEBUG(DBG_IOCTL, "VIDIOC_INT_G_REGISTER reg=0x%02X, value=0x%02X",
500 (unsigned int)reg->reg, reg->val);
501 errCode = 0; // No error
502 }
503 return errCode;
504 }
505 case VIDIOC_INT_S_REGISTER:
506 {
507 struct v4l2_register *reg = arg;
508 int errCode;
509
510 if (reg->i2c_id != 0)
511 return -EINVAL;
512 if (!capable(CAP_SYS_ADMIN))
513 return -EPERM;
514 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
515 if (errCode < 0) {
516 err("%s: VIDIOC_INT_S_REGISTER failed: error %d", __FUNCTION__, errCode);
517 }
518 else {
519 PDEBUG(DBG_IOCTL, "VIDIOC_INT_S_REGISTER reg=0x%02X, value=0x%02X",
520 (unsigned int)reg->reg, reg->val);
521 errCode = 0;
522 }
523 return 0;
524 }
525#endif
526 case VIDIOC_QUERYCAP:
527 {
528 struct v4l2_capability *vc=arg;
529
530 memset(vc, 0, sizeof(*vc));
531 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
532 strlcpy(vc->card, usbvision_device_data[usbvision->DevModel].ModelString,
533 sizeof(vc->card));
534 strlcpy(vc->bus_info, usbvision->dev->dev.bus_id,
535 sizeof(vc->bus_info));
536 vc->version = USBVISION_DRIVER_VERSION;
537 vc->capabilities = V4L2_CAP_VIDEO_CAPTURE |
538 V4L2_CAP_AUDIO |
539 V4L2_CAP_READWRITE |
540 V4L2_CAP_STREAMING |
541 (usbvision->have_tuner ? V4L2_CAP_TUNER : 0);
542 PDEBUG(DBG_IOCTL, "VIDIOC_QUERYCAP");
543 return 0;
544 }
545 case VIDIOC_ENUMINPUT:
546 {
547 struct v4l2_input *vi = arg;
548 int chan;
549
550 if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) )
551 return -EINVAL;
552 if (usbvision->have_tuner) {
553 chan = vi->index;
554 }
555 else {
556 chan = vi->index + 1; //skip Television string
557 }
558 switch(chan) {
559 case 0:
560 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
561 strcpy(vi->name, "White Video Input");
562 }
563 else {
564 strcpy(vi->name, "Television");
565 vi->type = V4L2_INPUT_TYPE_TUNER;
566 vi->audioset = 1;
567 vi->tuner = chan;
568 vi->std = V4L2_STD_PAL | V4L2_STD_NTSC | V4L2_STD_SECAM;
569 }
570 break;
571 case 1:
572 vi->type = V4L2_INPUT_TYPE_CAMERA;
573 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
574 strcpy(vi->name, "Green Video Input");
575 }
576 else {
577 strcpy(vi->name, "Composite Video Input");
578 }
579 vi->std = V4L2_STD_PAL;
580 break;
581 case 2:
582 vi->type = V4L2_INPUT_TYPE_CAMERA;
583 if (usbvision_device_data[usbvision->DevModel].VideoChannels == 4) {
584 strcpy(vi->name, "Yellow Video Input");
585 }
586 else {
587 strcpy(vi->name, "S-Video Input");
588 }
589 vi->std = V4L2_STD_PAL;
590 break;
591 case 3:
592 vi->type = V4L2_INPUT_TYPE_CAMERA;
593 strcpy(vi->name, "Red Video Input");
594 vi->std = V4L2_STD_PAL;
595 break;
596 }
597 PDEBUG(DBG_IOCTL, "VIDIOC_ENUMINPUT name=%s:%d tuners=%d type=%d norm=%x",
598 vi->name, vi->index, vi->tuner,vi->type,(int)vi->std);
599 return 0;
600 }
601 case VIDIOC_ENUMSTD:
602 {
603 struct v4l2_standard *e = arg;
604 unsigned int i;
605 int ret;
606
607 i = e->index;
608 if (i >= TVNORMS)
609 return -EINVAL;
610 ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
611 tvnorms[e->index].name);
612 e->index = i;
613 if (ret < 0)
614 return ret;
615 return 0;
616 }
617 case VIDIOC_G_INPUT:
618 {
619 int *input = arg;
620 *input = usbvision->ctl_input;
621 return 0;
622 }
623 case VIDIOC_S_INPUT:
624 {
625 int *input = arg;
626 if ((*input >= usbvision->video_inputs) || (*input < 0) )
627 return -EINVAL;
628 usbvision->ctl_input = *input;
629
630 down(&usbvision->lock);
631 usbvision_muxsel(usbvision, usbvision->ctl_input);
632 usbvision_set_input(usbvision);
633 usbvision_set_output(usbvision, usbvision->curwidth, usbvision->curheight);
634 up(&usbvision->lock);
635 return 0;
636 }
637 case VIDIOC_G_STD:
638 {
639 v4l2_std_id *id = arg;
640
641 *id = usbvision->tvnorm->id;
642
643 PDEBUG(DBG_IOCTL, "VIDIOC_G_STD std_id=%s", usbvision->tvnorm->name);
644 return 0;
645 }
646 case VIDIOC_S_STD:
647 {
648 v4l2_std_id *id = arg;
649 unsigned int i;
650
651 for (i = 0; i < TVNORMS; i++)
652 if (*id == tvnorms[i].id)
653 break;
654 if (i == TVNORMS)
655 for (i = 0; i < TVNORMS; i++)
656 if (*id & tvnorms[i].id)
657 break;
658 if (i == TVNORMS)
659 return -EINVAL;
660
661 down(&usbvision->lock);
662 usbvision->tvnorm = &tvnorms[i];
663
664 call_i2c_clients(usbvision, VIDIOC_S_STD,
665 &usbvision->tvnorm->id);
666
667 up(&usbvision->lock);
668
669 PDEBUG(DBG_IOCTL, "VIDIOC_S_STD std_id=%s", usbvision->tvnorm->name);
670 return 0;
671 }
672 case VIDIOC_G_TUNER:
673 {
674 struct v4l2_tuner *vt = arg;
675
676 if (!usbvision->have_tuner || vt->index) // Only tuner 0
677 return -EINVAL;
678 strcpy(vt->name, "Television");
679 /* Let clients fill in the remainder of this struct */
680 call_i2c_clients(usbvision,VIDIOC_G_TUNER,vt);
681
682 PDEBUG(DBG_IOCTL, "VIDIOC_G_TUNER signal=%x, afc=%x",vt->signal,vt->afc);
683 return 0;
684 }
685 case VIDIOC_S_TUNER:
686 {
687 struct v4l2_tuner *vt = arg;
688
689 // Only no or one tuner for now
690 if (!usbvision->have_tuner || vt->index)
691 return -EINVAL;
692 /* let clients handle this */
693 call_i2c_clients(usbvision,VIDIOC_S_TUNER,vt);
694
695 PDEBUG(DBG_IOCTL, "VIDIOC_S_TUNER");
696 return 0;
697 }
698 case VIDIOC_G_FREQUENCY:
699 {
700 struct v4l2_frequency *freq = arg;
701
702 freq->tuner = 0; // Only one tuner
703 freq->type = V4L2_TUNER_ANALOG_TV;
704 freq->frequency = usbvision->freq;
705 PDEBUG(DBG_IOCTL, "VIDIOC_G_FREQUENCY freq=0x%X", (unsigned)freq->frequency);
706 return 0;
707 }
708 case VIDIOC_S_FREQUENCY:
709 {
710 struct v4l2_frequency *freq = arg;
711
712 // Only no or one tuner for now
713 if (!usbvision->have_tuner || freq->tuner)
714 return -EINVAL;
715
716 usbvision->freq = freq->frequency;
717 call_i2c_clients(usbvision, cmd, freq);
718 PDEBUG(DBG_IOCTL, "VIDIOC_S_FREQUENCY freq=0x%X", (unsigned)freq->frequency);
719 return 0;
720 }
721 case VIDIOC_G_AUDIO:
722 {
723 struct v4l2_audio *v = arg;
724 memset(v,0, sizeof(v));
725 strcpy(v->name, "TV");
726 PDEBUG(DBG_IOCTL, "VIDIOC_G_AUDIO");
727 return 0;
728 }
729 case VIDIOC_S_AUDIO:
730 {
731 struct v4l2_audio *v = arg;
732 if(v->index) {
733 return -EINVAL;
734 }
735 PDEBUG(DBG_IOCTL, "VIDIOC_S_AUDIO");
736 return 0;
737 }
738 case VIDIOC_QUERYCTRL:
739 {
740 struct v4l2_queryctrl *ctrl = arg;
741 int id=ctrl->id;
742
743 memset(ctrl,0,sizeof(*ctrl));
744 ctrl->id=id;
745
746 call_i2c_clients(usbvision, cmd, arg);
747
748 if (ctrl->type)
749 return 0;
750 else
751 return -EINVAL;
752
753 PDEBUG(DBG_IOCTL,"VIDIOC_QUERYCTRL id=%x value=%x",ctrl->id,ctrl->type);
754 }
755 case VIDIOC_G_CTRL:
756 {
757 struct v4l2_control *ctrl = arg;
758 PDEBUG(DBG_IOCTL,"VIDIOC_G_CTRL id=%x value=%x",ctrl->id,ctrl->value);
759 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
760 return 0;
761 }
762 case VIDIOC_S_CTRL:
763 {
764 struct v4l2_control *ctrl = arg;
765
766 PDEBUG(DBG_IOCTL, "VIDIOC_S_CTRL id=%x value=%x",ctrl->id,ctrl->value);
767 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl);
768 return 0;
769 }
770 case VIDIOC_REQBUFS:
771 {
772 struct v4l2_requestbuffers *vr = arg;
773 int ret;
774
775 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES);
776
777 // Check input validity : the user must do a VIDEO CAPTURE and MMAP method.
778 if((vr->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) ||
779 (vr->memory != V4L2_MEMORY_MMAP))
780 return -EINVAL;
781
782 if(usbvision->streaming == Stream_On) {
783 if ((ret = usbvision_stream_interrupt(usbvision)))
784 return ret;
785 }
786
787 usbvision_empty_framequeues(usbvision);
788
789 usbvision->curFrame = NULL;
790
791 PDEBUG(DBG_IOCTL, "VIDIOC_REQBUFS count=%d",vr->count);
792 return 0;
793 }
794 case VIDIOC_QUERYBUF:
795 {
796 struct v4l2_buffer *vb = arg;
797 struct usbvision_frame *frame;
798
799 // FIXME : must control that buffers are mapped (VIDIOC_REQBUFS has been called)
800
801 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
802 return -EINVAL;
803 }
804 if(vb->index>=USBVISION_NUMFRAMES) {
805 return -EINVAL;
806 }
807 // Updating the corresponding frame state
808 vb->flags = 0;
809 frame = &usbvision->frame[vb->index];
810 if(frame->grabstate >= FrameState_Ready)
811 vb->flags |= V4L2_BUF_FLAG_QUEUED;
812 if(frame->grabstate >= FrameState_Done)
813 vb->flags |= V4L2_BUF_FLAG_DONE;
814 if(frame->grabstate == FrameState_Unused)
815 vb->flags |= V4L2_BUF_FLAG_MAPPED;
816 vb->memory = V4L2_MEMORY_MMAP;
817
818 vb->m.offset = vb->index*usbvision->max_frame_size;
819
820 vb->memory = V4L2_MEMORY_MMAP;
821 vb->field = V4L2_FIELD_NONE;
822 vb->length = usbvision->curwidth*usbvision->curheight*usbvision->palette.bytes_per_pixel;
823 vb->timestamp = usbvision->frame[vb->index].timestamp;
824 vb->sequence = usbvision->frame[vb->index].sequence;
825 return 0;
826 }
827 case VIDIOC_QBUF:
828 {
829 struct v4l2_buffer *vb = arg;
830 struct usbvision_frame *frame;
831 unsigned long lock_flags;
832
833 // FIXME : works only on VIDEO_CAPTURE MODE, MMAP.
834 if(vb->type != V4L2_CAP_VIDEO_CAPTURE) {
835 return -EINVAL;
836 }
837 if(vb->index>=USBVISION_NUMFRAMES) {
838 return -EINVAL;
839 }
840
841 frame = &usbvision->frame[vb->index];
842
843 if (frame->grabstate != FrameState_Unused) {
844 return -EAGAIN;
845 }
846
847 /* Mark it as ready and enqueue frame */
848 frame->grabstate = FrameState_Ready;
849 frame->scanstate = ScanState_Scanning;
850 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
851
852 vb->flags &= ~V4L2_BUF_FLAG_DONE;
853
854 /* set v4l2_format index */
855 frame->v4l2_format = usbvision->palette;
856
857 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
858 list_add_tail(&usbvision->frame[vb->index].frame, &usbvision->inqueue);
859 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
860
861 PDEBUG(DBG_IOCTL, "VIDIOC_QBUF frame #%d",vb->index);
862 return 0;
863 }
864 case VIDIOC_DQBUF:
865 {
866 struct v4l2_buffer *vb = arg;
867 int ret;
868 struct usbvision_frame *f;
869 unsigned long lock_flags;
870
871 if (vb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
872 return -EINVAL;
873
874 if (list_empty(&(usbvision->outqueue))) {
875 if (usbvision->streaming == Stream_Idle)
876 return -EINVAL;
877 ret = wait_event_interruptible
878 (usbvision->wait_frame,
879 !list_empty(&(usbvision->outqueue)));
880 if (ret)
881 return ret;
882 }
883
884 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
885 f = list_entry(usbvision->outqueue.next,
886 struct usbvision_frame, frame);
887 list_del(usbvision->outqueue.next);
888 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
889
890 f->grabstate = FrameState_Unused;
891
892 vb->memory = V4L2_MEMORY_MMAP;
893 vb->flags = V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE;
894 vb->index = f->index;
895 vb->sequence = f->sequence;
896 vb->timestamp = f->timestamp;
897 vb->field = V4L2_FIELD_NONE;
898 vb->bytesused = f->scanlength;
899
900 return 0;
901 }
902 case VIDIOC_STREAMON:
903 {
904 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
905
906 usbvision->streaming = Stream_On;
907
908 call_i2c_clients(usbvision,VIDIOC_STREAMON , &b);
909
910 PDEBUG(DBG_IOCTL, "VIDIOC_STREAMON");
911
912 return 0;
913 }
914 case VIDIOC_STREAMOFF:
915 {
916 int *type = arg;
917 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
918
919 if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
920 return -EINVAL;
921
922 if(usbvision->streaming == Stream_On) {
923 usbvision_stream_interrupt(usbvision);
924 // Stop all video streamings
925 call_i2c_clients(usbvision,VIDIOC_STREAMOFF , &b);
926 }
927 usbvision_empty_framequeues(usbvision);
928
929 PDEBUG(DBG_IOCTL, "VIDIOC_STREAMOFF");
930 return 0;
931 }
932 case VIDIOC_ENUM_FMT:
933 {
934 struct v4l2_fmtdesc *vfd = arg;
935
936 if(vfd->index>=USBVISION_SUPPORTED_PALETTES-1) {
937 return -EINVAL;
938 }
939 vfd->flags = 0;
940 vfd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
941 strcpy(vfd->description,usbvision_v4l2_format[vfd->index].desc);
942 vfd->pixelformat = usbvision_v4l2_format[vfd->index].format;
943 memset(vfd->reserved, 0, sizeof(vfd->reserved));
944 return 0;
945 }
946 case VIDIOC_G_FMT:
947 {
948 struct v4l2_format *vf = arg;
949
950 switch (vf->type) {
951 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
952 {
953 vf->fmt.pix.width = usbvision->curwidth;
954 vf->fmt.pix.height = usbvision->curheight;
955 vf->fmt.pix.pixelformat = usbvision->palette.format;
956 vf->fmt.pix.bytesperline = usbvision->curwidth*usbvision->palette.bytes_per_pixel;
957 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*usbvision->curheight;
958 vf->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
959 vf->fmt.pix.field = V4L2_FIELD_NONE; /* Always progressive image */
960 PDEBUG(DBG_IOCTL, "VIDIOC_G_FMT w=%d, h=%d, format=%s",
961 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc);
962 return 0;
963 }
964 default:
965 PDEBUG(DBG_IOCTL, "VIDIOC_G_FMT invalid type %d",vf->type);
966 return -EINVAL;
967 }
968 return 0;
969 }
970 case VIDIOC_TRY_FMT:
971 case VIDIOC_S_FMT:
972 {
973 struct v4l2_format *vf = arg;
974 int formatIdx,ret;
975
976 switch(vf->type) {
977 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
978 {
979 /* Find requested format in available ones */
980 for(formatIdx=0;formatIdx<USBVISION_SUPPORTED_PALETTES;formatIdx++) {
981 if(vf->fmt.pix.pixelformat == usbvision_v4l2_format[formatIdx].format) {
982 usbvision->palette = usbvision_v4l2_format[formatIdx];
983 break;
984 }
985 }
986 /* robustness */
987 if(formatIdx == USBVISION_SUPPORTED_PALETTES) {
988 return -EINVAL;
989 }
990 RESTRICT_TO_RANGE(vf->fmt.pix.width, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
991 RESTRICT_TO_RANGE(vf->fmt.pix.height, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
992
993 vf->fmt.pix.bytesperline = vf->fmt.pix.width*usbvision->palette.bytes_per_pixel;
994 vf->fmt.pix.sizeimage = vf->fmt.pix.bytesperline*vf->fmt.pix.height;
995
996 if(cmd == VIDIOC_TRY_FMT) {
997 PDEBUG(DBG_IOCTL, "VIDIOC_TRY_FMT grabdisplay w=%d, h=%d, format=%s",
998 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc);
999 return 0;
1000 }
1001
1002 /* stop io in case it is already in progress */
1003 if(usbvision->streaming == Stream_On) {
1004 if ((ret = usbvision_stream_interrupt(usbvision)))
1005 return ret;
1006 }
1007 usbvision_empty_framequeues(usbvision);
1008
1009 usbvision->curFrame = NULL;
1010
1011 // by now we are committed to the new data...
1012 down(&usbvision->lock);
1013 usbvision_set_output(usbvision, vf->fmt.pix.width, vf->fmt.pix.height);
1014 up(&usbvision->lock);
1015
1016 PDEBUG(DBG_IOCTL, "VIDIOC_S_FMT grabdisplay w=%d, h=%d, format=%s",
1017 vf->fmt.pix.width, vf->fmt.pix.height,usbvision->palette.desc);
1018 return 0;
1019 }
1020 default:
1021 return -EINVAL;
1022 }
1023 }
1024 default:
1025 return -ENOIOCTLCMD;
1026 }
1027 return 0;
1028}
1029
1030static int usbvision_v4l2_ioctl(struct inode *inode, struct file *file,
1031 unsigned int cmd, unsigned long arg)
1032{
1033 return video_usercopy(inode, file, cmd, arg, usbvision_v4l2_do_ioctl);
1034}
1035
1036
1037static ssize_t usbvision_v4l2_read(struct file *file, char *buf,
1038 size_t count, loff_t *ppos)
1039{
1040 struct video_device *dev = video_devdata(file);
1041 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1042 int noblock = file->f_flags & O_NONBLOCK;
1043 unsigned long lock_flags;
1044
1045 int frmx = -1;
1046 int ret,i;
1047 struct usbvision_frame *frame;
1048
1049 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __FUNCTION__, (unsigned long)count, noblock);
1050
1051 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
1052 return -EFAULT;
1053
1054 /* no stream is running, make it running ! */
1055 usbvision->streaming = Stream_On;
1056 call_i2c_clients(usbvision,VIDIOC_STREAMON , NULL);
1057
1058 /* First, enqueue as many frames as possible (like a user of VIDIOC_QBUF would do) */
1059 for(i=0;i<USBVISION_NUMFRAMES;i++) {
1060 frame = &usbvision->frame[i];
1061 if(frame->grabstate == FrameState_Unused) {
1062 /* Mark it as ready and enqueue frame */
1063 frame->grabstate = FrameState_Ready;
1064 frame->scanstate = ScanState_Scanning;
1065 frame->scanlength = 0; /* Accumulated in usbvision_parse_data() */
1066
1067 /* set v4l2_format index */
1068 frame->v4l2_format = usbvision->palette;
1069
1070 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1071 list_add_tail(&frame->frame, &usbvision->inqueue);
1072 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1073 }
1074 }
1075
1076 /* Then try to steal a frame (like a VIDIOC_DQBUF would do) */
1077 if (list_empty(&(usbvision->outqueue))) {
1078 if(noblock)
1079 return -EAGAIN;
1080
1081 ret = wait_event_interruptible
1082 (usbvision->wait_frame,
1083 !list_empty(&(usbvision->outqueue)));
1084 if (ret)
1085 return ret;
1086 }
1087
1088 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1089 frame = list_entry(usbvision->outqueue.next,
1090 struct usbvision_frame, frame);
1091 list_del(usbvision->outqueue.next);
1092 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1093
1094 /* An error returns an empty frame */
1095 if (frame->grabstate == FrameState_Error) {
1096 frame->bytes_read = 0;
1097 return 0;
1098 }
1099
1100 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", __FUNCTION__,
1101 frame->index, frame->bytes_read, frame->scanlength);
1102
1103 /* copy bytes to user space; we allow for partials reads */
1104 if ((count + frame->bytes_read) > (unsigned long)frame->scanlength)
1105 count = frame->scanlength - frame->bytes_read;
1106
1107 if (copy_to_user(buf, frame->data + frame->bytes_read, count)) {
1108 return -EFAULT;
1109 }
1110
1111 frame->bytes_read += count;
1112 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", __FUNCTION__,
1113 (unsigned long)count, frame->bytes_read);
1114
1115 // For now, forget the frame if it has not been read in one shot.
1116/* if (frame->bytes_read >= frame->scanlength) {// All data has been read */
1117 frame->bytes_read = 0;
1118
1119 /* Mark it as available to be used again. */
1120 usbvision->frame[frmx].grabstate = FrameState_Unused;
1121/* } */
1122
1123 return count;
1124}
1125
1126static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1127{
1128 unsigned long size = vma->vm_end - vma->vm_start,
1129 start = vma->vm_start;
1130 void *pos;
1131 u32 i;
1132
1133 struct video_device *dev = video_devdata(file);
1134 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1135
1136 down(&usbvision->lock);
1137
1138 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
1139 up(&usbvision->lock);
1140 return -EFAULT;
1141 }
1142
1143 if (!(vma->vm_flags & VM_WRITE) ||
1144 size != PAGE_ALIGN(usbvision->curwidth*usbvision->curheight*usbvision->palette.bytes_per_pixel)) {
1145 up(&usbvision->lock);
1146 return -EINVAL;
1147 }
1148
1149 for (i = 0; i < USBVISION_NUMFRAMES; i++) {
1150 if (((usbvision->max_frame_size*i) >> PAGE_SHIFT) == vma->vm_pgoff)
1151 break;
1152 }
1153 if (i == USBVISION_NUMFRAMES) {
1154 PDEBUG(DBG_MMAP, "mmap: user supplied mapping address is out of range");
1155 up(&usbvision->lock);
1156 return -EINVAL;
1157 }
1158
1159 /* VM_IO is eventually going to replace PageReserved altogether */
1160 vma->vm_flags |= VM_IO;
1161 vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
1162
1163 pos = usbvision->frame[i].data;
1164 while (size > 0) {
1165
1166 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1167 PDEBUG(DBG_MMAP, "mmap: vm_insert_page failed");
1168 up(&usbvision->lock);
1169 return -EAGAIN;
1170 }
1171 start += PAGE_SIZE;
1172 pos += PAGE_SIZE;
1173 size -= PAGE_SIZE;
1174 }
1175
1176 up(&usbvision->lock);
1177 return 0;
1178}
1179
1180
1181/*
1182 * Here comes the stuff for radio on usbvision based devices
1183 *
1184 */
1185static int usbvision_radio_open(struct inode *inode, struct file *file)
1186{
1187 struct video_device *dev = video_devdata(file);
1188 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1189 struct v4l2_frequency freq;
1190 int errCode = 0;
1191
1192 PDEBUG(DBG_IO, "%s:", __FUNCTION__);
1193
1194 down(&usbvision->lock);
1195
1196 if (usbvision->user) {
1197 err("%s: Someone tried to open an already opened USBVision Radio!", __FUNCTION__);
1198 errCode = -EBUSY;
1199 }
1200 else {
1201 if(PowerOnAtOpen) {
1202 usbvision_reset_powerOffTimer(usbvision);
1203 if (usbvision->power == 0) {
1204 usbvision_power_on(usbvision);
1205 usbvision_init_i2c(usbvision);
1206 }
1207 }
1208
1209 // If so far no errors then we shall start the radio
1210 usbvision->radio = 1;
1211 call_i2c_clients(usbvision,AUDC_SET_RADIO,&usbvision->tuner_type);
1212 freq.frequency = 1517; //SWR3 @ 94.8MHz
1213 call_i2c_clients(usbvision, VIDIOC_S_FREQUENCY, &freq);
1214 usbvision_set_audio(usbvision, USBVISION_AUDIO_RADIO);
1215 usbvision->user++;
1216 }
1217
1218 if (errCode) {
1219 if (PowerOnAtOpen) {
1220 usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
1221 usbvision_power_off(usbvision);
1222 usbvision->initialized = 0;
1223 }
1224 }
1225 up(&usbvision->lock);
1226 return errCode;
1227}
1228
1229
1230static int usbvision_radio_close(struct inode *inode, struct file *file)
1231{
1232 struct video_device *dev = video_devdata(file);
1233 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1234 int errCode = 0;
1235
1236 PDEBUG(DBG_IO, "");
1237
1238 down(&usbvision->lock);
1239
1240 usbvision_audio_off(usbvision);
1241 usbvision->radio=0;
1242 usbvision->user--;
1243
1244 if (PowerOnAtOpen) {
1245 usbvision_set_powerOffTimer(usbvision);
1246 usbvision->initialized = 0;
1247 }
1248
1249 up(&usbvision->lock);
1250
1251 if (usbvision->remove_pending) {
1252 info("%s: Final disconnect", __FUNCTION__);
1253 usbvision_release(usbvision);
1254 }
1255
1256
1257 PDEBUG(DBG_IO, "success");
1258
1259 return errCode;
1260}
1261
1262static int usbvision_do_radio_ioctl(struct inode *inode, struct file *file,
1263 unsigned int cmd, void *arg)
1264{
1265 struct video_device *dev = video_devdata(file);
1266 struct usb_usbvision *usbvision = (struct usb_usbvision *) video_get_drvdata(dev);
1267
1268 if (!USBVISION_IS_OPERATIONAL(usbvision))
1269 return -EIO;
1270
1271 switch (cmd) {
1272 case VIDIOC_QUERYCAP:
1273 {
1274 struct v4l2_capability *vc=arg;
1275
1276 memset(vc, 0, sizeof(*vc));
1277 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
1278 strlcpy(vc->card, usbvision_device_data[usbvision->DevModel].ModelString,
1279 sizeof(vc->card));
1280 strlcpy(vc->bus_info, usbvision->dev->dev.bus_id,
1281 sizeof(vc->bus_info));
1282 vc->version = USBVISION_DRIVER_VERSION;
1283 vc->capabilities = (usbvision->have_tuner ? V4L2_CAP_TUNER : 0);
1284 PDEBUG(DBG_IO, "VIDIOC_QUERYCAP");
1285 return 0;
1286 }
1287 case VIDIOC_QUERYCTRL:
1288 {
1289 struct v4l2_queryctrl *ctrl = arg;
1290 int id=ctrl->id;
1291
1292 memset(ctrl,0,sizeof(*ctrl));
1293 ctrl->id=id;
1294
1295 call_i2c_clients(usbvision, cmd, arg);
1296 PDEBUG(DBG_IO,"VIDIOC_QUERYCTRL id=%x value=%x",ctrl->id,ctrl->type);
1297
1298 if (ctrl->type)
1299 return 0;
1300 else
1301 return -EINVAL;
1302
1303 }
1304 case VIDIOC_G_CTRL:
1305 {
1306 struct v4l2_control *ctrl = arg;
1307
1308 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
1309 PDEBUG(DBG_IO,"VIDIOC_G_CTRL id=%x value=%x",ctrl->id,ctrl->value);
1310 return 0;
1311 }
1312 case VIDIOC_S_CTRL:
1313 {
1314 struct v4l2_control *ctrl = arg;
1315
1316 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl);
1317 PDEBUG(DBG_IO, "VIDIOC_S_CTRL id=%x value=%x",ctrl->id,ctrl->value);
1318 return 0;
1319 }
1320 case VIDIOC_G_TUNER:
1321 {
1322 struct v4l2_tuner *t = arg;
1323
1324 if (t->index > 0)
1325 return -EINVAL;
1326
1327 memset(t,0,sizeof(*t));
1328 strcpy(t->name, "Radio");
1329 t->type = V4L2_TUNER_RADIO;
1330
1331 /* Let clients fill in the remainder of this struct */
1332 call_i2c_clients(usbvision,VIDIOC_G_TUNER,t);
1333 PDEBUG(DBG_IO, "VIDIOC_G_TUNER signal=%x, afc=%x",t->signal,t->afc);
1334 return 0;
1335 }
1336 case VIDIOC_S_TUNER:
1337 {
1338 struct v4l2_tuner *vt = arg;
1339
1340 // Only no or one tuner for now
1341 if (!usbvision->have_tuner || vt->index)
1342 return -EINVAL;
1343 /* let clients handle this */
1344 call_i2c_clients(usbvision,VIDIOC_S_TUNER,vt);
1345
1346 PDEBUG(DBG_IO, "VIDIOC_S_TUNER");
1347 return 0;
1348 }
1349 case VIDIOC_G_AUDIO:
1350 {
1351 struct v4l2_audio *a = arg;
1352
1353 memset(a,0,sizeof(*a));
1354 strcpy(a->name,"Radio");
1355 PDEBUG(DBG_IO, "VIDIOC_G_AUDIO");
1356 return 0;
1357 }
1358 case VIDIOC_S_AUDIO:
1359 case VIDIOC_S_INPUT:
1360 case VIDIOC_S_STD:
1361 return 0;
1362
1363 case VIDIOC_G_FREQUENCY:
1364 {
1365 struct v4l2_frequency *f = arg;
1366
1367 memset(f,0,sizeof(*f));
1368
1369 f->type = V4L2_TUNER_RADIO;
1370 f->frequency = usbvision->freq;
1371 call_i2c_clients(usbvision, cmd, f);
1372 PDEBUG(DBG_IO, "VIDIOC_G_FREQUENCY freq=0x%X", (unsigned)f->frequency);
1373
1374 return 0;
1375 }
1376 case VIDIOC_S_FREQUENCY:
1377 {
1378 struct v4l2_frequency *f = arg;
1379
1380 if (f->tuner != 0)
1381 return -EINVAL;
1382 usbvision->freq = f->frequency;
1383 call_i2c_clients(usbvision, cmd, f);
1384 PDEBUG(DBG_IO, "VIDIOC_S_FREQUENCY freq=0x%X", (unsigned)f->frequency);
1385
1386 return 0;
1387 }
1388 default:
1389 {
1390 PDEBUG(DBG_IO, "%s: Unknown command %x", __FUNCTION__, cmd);
1391 return -ENOIOCTLCMD;
1392 }
1393 }
1394 return 0;
1395}
1396
1397
1398static int usbvision_radio_ioctl(struct inode *inode, struct file *file,
1399 unsigned int cmd, unsigned long arg)
1400{
1401 return video_usercopy(inode, file, cmd, arg, usbvision_do_radio_ioctl);
1402}
1403
1404
1405/*
1406 * Here comes the stuff for vbi on usbvision based devices
1407 *
1408 */
1409static int usbvision_vbi_open(struct inode *inode, struct file *file)
1410{
1411 /* TODO */
1412 return -EINVAL;
1413
1414}
1415
1416static int usbvision_vbi_close(struct inode *inode, struct file *file)
1417{
1418 /* TODO */
1419 return -EINVAL;
1420}
1421
1422static int usbvision_do_vbi_ioctl(struct inode *inode, struct file *file,
1423 unsigned int cmd, void *arg)
1424{
1425 /* TODO */
1426 return -EINVAL;
1427}
1428
1429static int usbvision_vbi_ioctl(struct inode *inode, struct file *file,
1430 unsigned int cmd, unsigned long arg)
1431{
1432 return video_usercopy(inode, file, cmd, arg, usbvision_do_vbi_ioctl);
1433}
1434
1435
1436//
1437// Video registration stuff
1438//
1439
1440// Video template
1441static struct file_operations usbvision_fops = {
1442 .owner = THIS_MODULE,
1443 .open = usbvision_v4l2_open,
1444 .release = usbvision_v4l2_close,
1445 .read = usbvision_v4l2_read,
1446 .mmap = usbvision_v4l2_mmap,
1447 .ioctl = usbvision_v4l2_ioctl,
1448 .llseek = no_llseek,
1449};
1450static struct video_device usbvision_video_template = {
1451 .owner = THIS_MODULE,
1452 .type = VID_TYPE_TUNER | VID_TYPE_CAPTURE,
1453 .hardware = VID_HARDWARE_USBVISION,
1454 .fops = &usbvision_fops,
1455 .name = "usbvision-video",
1456 .release = video_device_release,
1457 .minor = -1,
1458};
1459
1460
1461// Radio template
1462static struct file_operations usbvision_radio_fops = {
1463 .owner = THIS_MODULE,
1464 .open = usbvision_radio_open,
1465 .release = usbvision_radio_close,
1466 .ioctl = usbvision_radio_ioctl,
1467 .llseek = no_llseek,
1468};
1469
1470static struct video_device usbvision_radio_template=
1471{
1472 .owner = THIS_MODULE,
1473 .type = VID_TYPE_TUNER,
1474 .hardware = VID_HARDWARE_USBVISION,
1475 .fops = &usbvision_radio_fops,
1476 .release = video_device_release,
1477 .name = "usbvision-radio",
1478 .minor = -1,
1479};
1480
1481
1482// vbi template
1483static struct file_operations usbvision_vbi_fops = {
1484 .owner = THIS_MODULE,
1485 .open = usbvision_vbi_open,
1486 .release = usbvision_vbi_close,
1487 .ioctl = usbvision_vbi_ioctl,
1488 .llseek = no_llseek,
1489};
1490
1491static struct video_device usbvision_vbi_template=
1492{
1493 .owner = THIS_MODULE,
1494 .type = VID_TYPE_TUNER,
1495 .hardware = VID_HARDWARE_USBVISION,
1496 .fops = &usbvision_vbi_fops,
1497 .release = video_device_release,
1498 .name = "usbvision-vbi",
1499 .minor = -1,
1500};
1501
1502
1503static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1504 struct video_device *vdev_template,
1505 char *name)
1506{
1507 struct usb_device *usb_dev = usbvision->dev;
1508 struct video_device *vdev;
1509
1510 if (usb_dev == NULL) {
1511 err("%s: usbvision->dev is not set", __FUNCTION__);
1512 return NULL;
1513 }
1514
1515 vdev = video_device_alloc();
1516 if (NULL == vdev) {
1517 return NULL;
1518 }
1519 *vdev = *vdev_template;
1520// vdev->minor = -1;
1521 vdev->dev = &usb_dev->dev;
1522 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1523 video_set_drvdata(vdev, usbvision);
1524 return vdev;
1525}
1526
1527// unregister video4linux devices
1528static void usbvision_unregister_video(struct usb_usbvision *usbvision)
1529{
1530 // vbi Device:
1531 if (usbvision->vbi) {
1532 PDEBUG(DBG_PROBE, "unregister /dev/vbi%d [v4l2]", usbvision->vbi->minor & 0x1f);
1533 if (usbvision->vbi->minor != -1) {
1534 video_unregister_device(usbvision->vbi);
1535 }
1536 else {
1537 video_device_release(usbvision->vbi);
1538 }
1539 usbvision->vbi = NULL;
1540 }
1541
1542 // Radio Device:
1543 if (usbvision->rdev) {
1544 PDEBUG(DBG_PROBE, "unregister /dev/radio%d [v4l2]", usbvision->rdev->minor & 0x1f);
1545 if (usbvision->rdev->minor != -1) {
1546 video_unregister_device(usbvision->rdev);
1547 }
1548 else {
1549 video_device_release(usbvision->rdev);
1550 }
1551 usbvision->rdev = NULL;
1552 }
1553
1554 // Video Device:
1555 if (usbvision->vdev) {
1556 PDEBUG(DBG_PROBE, "unregister /dev/video%d [v4l2]", usbvision->vdev->minor & 0x1f);
1557 if (usbvision->vdev->minor != -1) {
1558 video_unregister_device(usbvision->vdev);
1559 }
1560 else {
1561 video_device_release(usbvision->vdev);
1562 }
1563 usbvision->vdev = NULL;
1564 }
1565}
1566
1567// register video4linux devices
1568static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
1569{
1570 // Video Device:
1571 usbvision->vdev = usbvision_vdev_init(usbvision, &usbvision_video_template, "USBVision Video");
1572 if (usbvision->vdev == NULL) {
1573 goto err_exit;
1574 }
1575 if (video_register_device(usbvision->vdev, VFL_TYPE_GRABBER, video_nr)<0) {
1576 goto err_exit;
1577 }
1578 info("USBVision[%d]: registered USBVision Video device /dev/video%d [v4l2]", usbvision->nr,usbvision->vdev->minor & 0x1f);
1579
1580 // Radio Device:
1581 if (usbvision_device_data[usbvision->DevModel].Radio) {
1582 // usbvision has radio
1583 usbvision->rdev = usbvision_vdev_init(usbvision, &usbvision_radio_template, "USBVision Radio");
1584 if (usbvision->rdev == NULL) {
1585 goto err_exit;
1586 }
1587 if (video_register_device(usbvision->rdev, VFL_TYPE_RADIO, radio_nr)<0) {
1588 goto err_exit;
1589 }
1590 info("USBVision[%d]: registered USBVision Radio device /dev/radio%d [v4l2]", usbvision->nr, usbvision->rdev->minor & 0x1f);
1591 }
1592 // vbi Device:
1593 if (usbvision_device_data[usbvision->DevModel].vbi) {
1594 usbvision->vbi = usbvision_vdev_init(usbvision, &usbvision_vbi_template, "USBVision VBI");
1595 if (usbvision->vdev == NULL) {
1596 goto err_exit;
1597 }
1598 if (video_register_device(usbvision->vbi, VFL_TYPE_VBI, vbi_nr)<0) {
1599 goto err_exit;
1600 }
1601 info("USBVision[%d]: registered USBVision VBI device /dev/vbi%d [v4l2] (Not Working Yet!)", usbvision->nr,usbvision->vbi->minor & 0x1f);
1602 }
1603 // all done
1604 return 0;
1605
1606 err_exit:
1607 err("USBVision[%d]: video_register_device() failed", usbvision->nr);
1608 usbvision_unregister_video(usbvision);
1609 return -1;
1610}
1611
1612/*
1613 * usbvision_alloc()
1614 *
1615 * This code allocates the struct usb_usbvision. It is filled with default values.
1616 *
1617 * Returns NULL on error, a pointer to usb_usbvision else.
1618 *
1619 */
1620static struct usb_usbvision *usbvision_alloc(struct usb_device *dev)
1621{
1622 struct usb_usbvision *usbvision;
1623
1624 if ((usbvision = kzalloc(sizeof(struct usb_usbvision), GFP_KERNEL)) == NULL) {
1625 goto err_exit;
1626 }
1627
1628 usbvision->dev = dev;
1629
1630 init_MUTEX(&usbvision->lock); /* to 1 == available */
1631
1632 // prepare control urb for control messages during interrupts
1633 usbvision->ctrlUrb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
1634 if (usbvision->ctrlUrb == NULL) {
1635 goto err_exit;
1636 }
1637 init_waitqueue_head(&usbvision->ctrlUrb_wq);
1638 init_MUTEX(&usbvision->ctrlUrbLock); /* to 1 == available */
1639
1640 usbvision_init_powerOffTimer(usbvision);
1641
1642 return usbvision;
1643
1644err_exit:
1645 if (usbvision && usbvision->ctrlUrb) {
1646 usb_free_urb(usbvision->ctrlUrb);
1647 }
1648 if (usbvision) {
1649 kfree(usbvision);
1650 }
1651 return NULL;
1652}
1653
1654/*
1655 * usbvision_release()
1656 *
1657 * This code does final release of struct usb_usbvision. This happens
1658 * after the device is disconnected -and- all clients closed their files.
1659 *
1660 */
1661static void usbvision_release(struct usb_usbvision *usbvision)
1662{
1663 PDEBUG(DBG_PROBE, "");
1664
1665 down(&usbvision->lock);
1666
1667 usbvision_reset_powerOffTimer(usbvision);
1668
1669 usbvision->initialized = 0;
1670
1671 up(&usbvision->lock);
1672
1673 usbvision_remove_sysfs(usbvision->vdev);
1674 usbvision_unregister_video(usbvision);
1675
1676 if (usbvision->ctrlUrb) {
1677 usb_free_urb(usbvision->ctrlUrb);
1678 }
1679
1680 kfree(usbvision);
1681
1682 PDEBUG(DBG_PROBE, "success");
1683}
1684
1685
1686/******************************** usb interface *****************************************/
1687
1688static void usbvision_configure_video(struct usb_usbvision *usbvision)
1689{
1690 int model,i;
1691
1692 if (usbvision == NULL)
1693 return;
1694
1695 model = usbvision->DevModel;
1696 usbvision->palette = usbvision_v4l2_format[2]; // V4L2_PIX_FMT_RGB24;
1697
1698 if (usbvision_device_data[usbvision->DevModel].Vin_Reg2 >= 0) {
1699 usbvision->Vin_Reg2_Preset = usbvision_device_data[usbvision->DevModel].Vin_Reg2 & 0xff;
1700 } else {
1701 usbvision->Vin_Reg2_Preset = 0;
1702 }
1703
1704 for (i = 0; i < TVNORMS; i++)
1705 if (usbvision_device_data[model].VideoNorm == tvnorms[i].mode)
1706 break;
1707 if (i == TVNORMS)
1708 i = 0;
1709 usbvision->tvnorm = &tvnorms[i]; /* set default norm */
1710
1711 usbvision->video_inputs = usbvision_device_data[model].VideoChannels;
1712 usbvision->ctl_input = 0;
1713
1714 /* This should be here to make i2c clients to be able to register */
1715 usbvision_audio_off(usbvision); //first switch off audio
1716 if (!PowerOnAtOpen) {
1717 usbvision_power_on(usbvision); //and then power up the noisy tuner
1718 usbvision_init_i2c(usbvision);
1719 }
1720}
1721
1722/*
1723 * usbvision_probe()
1724 *
1725 * This procedure queries device descriptor and accepts the interface
1726 * if it looks like USBVISION video device
1727 *
1728 */
1729static int __devinit usbvision_probe(struct usb_interface *intf, const struct usb_device_id *devid)
1730{
1731 struct usb_device *dev = interface_to_usbdev(intf);
1732 __u8 ifnum = intf->altsetting->desc.bInterfaceNumber;
1733 const struct usb_host_interface *interface;
1734 struct usb_usbvision *usbvision = NULL;
1735 const struct usb_endpoint_descriptor *endpoint;
1736 int model;
1737
1738 PDEBUG(DBG_PROBE, "VID=%#04x, PID=%#04x, ifnum=%u",
1739 dev->descriptor.idVendor, dev->descriptor.idProduct, ifnum);
1740 /* Is it an USBVISION video dev? */
1741 model = 0;
1742 for(model = 0; usbvision_device_data[model].idVendor; model++) {
1743 if (le16_to_cpu(dev->descriptor.idVendor) != usbvision_device_data[model].idVendor) {
1744 continue;
1745 }
1746 if (le16_to_cpu(dev->descriptor.idProduct) != usbvision_device_data[model].idProduct) {
1747 continue;
1748 }
1749
1750 info("%s: %s found", __FUNCTION__, usbvision_device_data[model].ModelString);
1751 break;
1752 }
1753
1754 if (usbvision_device_data[model].idVendor == 0) {
1755 return -ENODEV; //no matching device
1756 }
1757 if (usbvision_device_data[model].Interface >= 0) {
1758 interface = &dev->actconfig->interface[usbvision_device_data[model].Interface]->altsetting[0];
1759 }
1760 else {
1761 interface = &dev->actconfig->interface[ifnum]->altsetting[0];
1762 }
1763 endpoint = &interface->endpoint[1].desc;
1764 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_ISOC) {
1765 err("%s: interface %d. has non-ISO endpoint!", __FUNCTION__, ifnum);
1766 err("%s: Endpoint attribures %d", __FUNCTION__, endpoint->bmAttributes);
1767 return -ENODEV;
1768 }
1769 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
1770 err("%s: interface %d. has ISO OUT endpoint!", __FUNCTION__, ifnum);
1771 return -ENODEV;
1772 }
1773
1774 usb_get_dev(dev);
1775
1776 if ((usbvision = usbvision_alloc(dev)) == NULL) {
1777 err("%s: couldn't allocate USBVision struct", __FUNCTION__);
1778 return -ENOMEM;
1779 }
1780 if (dev->descriptor.bNumConfigurations > 1) {
1781 usbvision->bridgeType = BRIDGE_NT1004;
1782 }
1783 else if (usbvision_device_data[model].ModelString == "Dazzle Fusion Model DVC-90 Rev 1 (SECAM)") {
1784 usbvision->bridgeType = BRIDGE_NT1005;
1785 }
1786 else {
1787 usbvision->bridgeType = BRIDGE_NT1003;
1788 }
1789 PDEBUG(DBG_PROBE, "bridgeType %d", usbvision->bridgeType);
1790
1791 down(&usbvision->lock);
1792
1793 usbvision->nr = usbvision_nr++;
1794
1795 usbvision->have_tuner = usbvision_device_data[model].Tuner;
1796 if (usbvision->have_tuner) {
1797 usbvision->tuner_type = usbvision_device_data[model].TunerType;
1798 }
1799
1800 usbvision->tuner_addr = ADDR_UNSET;
1801
1802 usbvision->DevModel = model;
1803 usbvision->remove_pending = 0;
1804 usbvision->iface = ifnum;
1805 usbvision->ifaceAltInactive = 0;
1806 usbvision->ifaceAltActive = 1;
1807 usbvision->video_endp = endpoint->bEndpointAddress;
1808 usbvision->isocPacketSize = 0;
1809 usbvision->usb_bandwidth = 0;
1810 usbvision->user = 0;
1811 usbvision->streaming = Stream_Off;
1812 usbvision_register_video(usbvision);
1813 usbvision_configure_video(usbvision);
1814 up(&usbvision->lock);
1815
1816
1817 usb_set_intfdata (intf, usbvision);
1818 usbvision_create_sysfs(usbvision->vdev);
1819
1820 PDEBUG(DBG_PROBE, "success");
1821 return 0;
1822}
1823
1824
1825/*
1826 * usbvision_disconnect()
1827 *
1828 * This procedure stops all driver activity, deallocates interface-private
1829 * structure (pointed by 'ptr') and after that driver should be removable
1830 * with no ill consequences.
1831 *
1832 */
1833static void __devexit usbvision_disconnect(struct usb_interface *intf)
1834{
1835 struct usb_usbvision *usbvision = usb_get_intfdata(intf);
1836
1837 PDEBUG(DBG_PROBE, "");
1838
1839 if (usbvision == NULL) {
1840 err("%s: usb_get_intfdata() failed", __FUNCTION__);
1841 return;
1842 }
1843 usb_set_intfdata (intf, NULL);
1844
1845 down(&usbvision->lock);
1846
1847 // At this time we ask to cancel outstanding URBs
1848 usbvision_stop_isoc(usbvision);
1849
1850 if (usbvision->power) {
1851 usbvision_i2c_usb_del_bus(&usbvision->i2c_adap);
1852 usbvision_power_off(usbvision);
1853 }
1854 usbvision->remove_pending = 1; // Now all ISO data will be ignored
1855
1856 usb_put_dev(usbvision->dev);
1857 usbvision->dev = NULL; // USB device is no more
1858
1859 up(&usbvision->lock);
1860
1861 if (usbvision->user) {
1862 info("%s: In use, disconnect pending", __FUNCTION__);
1863 wake_up_interruptible(&usbvision->wait_frame);
1864 wake_up_interruptible(&usbvision->wait_stream);
1865 }
1866 else {
1867 usbvision_release(usbvision);
1868 }
1869
1870 PDEBUG(DBG_PROBE, "success");
1871
1872}
1873
1874static struct usb_driver usbvision_driver = {
1875 .name = "usbvision",
1876 .id_table = usbvision_table,
1877 .probe = usbvision_probe,
1878 .disconnect = usbvision_disconnect
1879};
1880
1881/*
1882 * customdevice_process()
1883 *
1884 * This procedure preprocesses CustomDevice parameter if any
1885 *
1886 */
1887void customdevice_process(void)
1888{
1889 usbvision_device_data[0]=usbvision_device_data[1];
1890 usbvision_table[0]=usbvision_table[1];
1891
1892 if(CustomDevice)
1893 {
1894 char *parse=CustomDevice;
1895
1896 PDEBUG(DBG_PROBE, "CustomDevide=%s", CustomDevice);
1897
1898 /*format is CustomDevice="0x0573 0x4D31 0 7113 3 PAL 1 1 1 5 -1 -1 -1 -1 -1"
1899 usbvision_device_data[0].idVendor;
1900 usbvision_device_data[0].idProduct;
1901 usbvision_device_data[0].Interface;
1902 usbvision_device_data[0].Codec;
1903 usbvision_device_data[0].VideoChannels;
1904 usbvision_device_data[0].VideoNorm;
1905 usbvision_device_data[0].AudioChannels;
1906 usbvision_device_data[0].Radio;
1907 usbvision_device_data[0].Tuner;
1908 usbvision_device_data[0].TunerType;
1909 usbvision_device_data[0].Vin_Reg1;
1910 usbvision_device_data[0].Vin_Reg2;
1911 usbvision_device_data[0].X_Offset;
1912 usbvision_device_data[0].Y_Offset;
1913 usbvision_device_data[0].Dvi_yuv;
1914 usbvision_device_data[0].ModelString;
1915 */
1916
1917 rmspace(parse);
1918 usbvision_device_data[0].ModelString="USBVISION Custom Device";
1919
1920 parse+=2;
1921 sscanf(parse,"%x",&usbvision_device_data[0].idVendor);
1922 goto2next(parse);
1923 PDEBUG(DBG_PROBE, "idVendor=0x%.4X", usbvision_device_data[0].idVendor);
1924 parse+=2;
1925 sscanf(parse,"%x",&usbvision_device_data[0].idProduct);
1926 goto2next(parse);
1927 PDEBUG(DBG_PROBE, "idProduct=0x%.4X", usbvision_device_data[0].idProduct);
1928 sscanf(parse,"%d",&usbvision_device_data[0].Interface);
1929 goto2next(parse);
1930 PDEBUG(DBG_PROBE, "Interface=%d", usbvision_device_data[0].Interface);
1931 sscanf(parse,"%d",&usbvision_device_data[0].Codec);
1932 goto2next(parse);
1933 PDEBUG(DBG_PROBE, "Codec=%d", usbvision_device_data[0].Codec);
1934 sscanf(parse,"%d",&usbvision_device_data[0].VideoChannels);
1935 goto2next(parse);
1936 PDEBUG(DBG_PROBE, "VideoChannels=%d", usbvision_device_data[0].VideoChannels);
1937
1938 switch(*parse)
1939 {
1940 case 'P':
1941 PDEBUG(DBG_PROBE, "VideoNorm=PAL");
1942 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL;
1943 break;
1944
1945 case 'S':
1946 PDEBUG(DBG_PROBE, "VideoNorm=SECAM");
1947 usbvision_device_data[0].VideoNorm=VIDEO_MODE_SECAM;
1948 break;
1949
1950 case 'N':
1951 PDEBUG(DBG_PROBE, "VideoNorm=NTSC");
1952 usbvision_device_data[0].VideoNorm=VIDEO_MODE_NTSC;
1953 break;
1954
1955 default:
1956 PDEBUG(DBG_PROBE, "VideoNorm=PAL (by default)");
1957 usbvision_device_data[0].VideoNorm=VIDEO_MODE_PAL;
1958 break;
1959 }
1960 goto2next(parse);
1961
1962 sscanf(parse,"%d",&usbvision_device_data[0].AudioChannels);
1963 goto2next(parse);
1964 PDEBUG(DBG_PROBE, "AudioChannels=%d", usbvision_device_data[0].AudioChannels);
1965 sscanf(parse,"%d",&usbvision_device_data[0].Radio);
1966 goto2next(parse);
1967 PDEBUG(DBG_PROBE, "Radio=%d", usbvision_device_data[0].Radio);
1968 sscanf(parse,"%d",&usbvision_device_data[0].Tuner);
1969 goto2next(parse);
1970 PDEBUG(DBG_PROBE, "Tuner=%d", usbvision_device_data[0].Tuner);
1971 sscanf(parse,"%d",&usbvision_device_data[0].TunerType);
1972 goto2next(parse);
1973 PDEBUG(DBG_PROBE, "TunerType=%d", usbvision_device_data[0].TunerType);
1974 sscanf(parse,"%d",&usbvision_device_data[0].Vin_Reg1);
1975 goto2next(parse);
1976 PDEBUG(DBG_PROBE, "Vin_Reg1=%d", usbvision_device_data[0].Vin_Reg1);
1977 sscanf(parse,"%d",&usbvision_device_data[0].Vin_Reg2);
1978 goto2next(parse);
1979 PDEBUG(DBG_PROBE, "Vin_Reg2=%d", usbvision_device_data[0].Vin_Reg2);
1980 sscanf(parse,"%d",&usbvision_device_data[0].X_Offset);
1981 goto2next(parse);
1982 PDEBUG(DBG_PROBE, "X_Offset=%d", usbvision_device_data[0].X_Offset);
1983 sscanf(parse,"%d",&usbvision_device_data[0].Y_Offset);
1984 goto2next(parse);
1985 PDEBUG(DBG_PROBE, "Y_Offset=%d", usbvision_device_data[0].Y_Offset);
1986 sscanf(parse,"%d",&usbvision_device_data[0].Dvi_yuv);
1987 PDEBUG(DBG_PROBE, "Dvi_yuv=%d", usbvision_device_data[0].Dvi_yuv);
1988
1989 //add to usbvision_table also
1990 usbvision_table[0].match_flags=USB_DEVICE_ID_MATCH_DEVICE;
1991 usbvision_table[0].idVendor=usbvision_device_data[0].idVendor;
1992 usbvision_table[0].idProduct=usbvision_device_data[0].idProduct;
1993
1994 }
1995}
1996
1997
1998
1999/*
2000 * usbvision_init()
2001 *
2002 * This code is run to initialize the driver.
2003 *
2004 */
2005static int __init usbvision_init(void)
2006{
2007 int errCode;
2008
2009 PDEBUG(DBG_PROBE, "");
2010
2011 PDEBUG(DBG_IOCTL, "IOCTL debugging is enabled [video]");
2012 PDEBUG(DBG_IO, "IO debugging is enabled [video]");
2013 PDEBUG(DBG_PROBE, "PROBE debugging is enabled [video]");
2014 PDEBUG(DBG_MMAP, "MMAP debugging is enabled [video]");
2015
2016 /* disable planar mode support unless compression enabled */
2017 if (isocMode != ISOC_MODE_COMPRESS ) {
2018 // FIXME : not the right way to set supported flag
2019 usbvision_v4l2_format[6].supported = 0; // V4L2_PIX_FMT_YVU420
2020 usbvision_v4l2_format[7].supported = 0; // V4L2_PIX_FMT_YUV422P
2021 }
2022
2023 customdevice_process();
2024
2025 errCode = usb_register(&usbvision_driver);
2026
2027 if (errCode == 0) {
2028 info(DRIVER_DESC " : " USBVISION_VERSION_STRING);
2029 PDEBUG(DBG_PROBE, "success");
2030 }
2031 return errCode;
2032}
2033
2034static void __exit usbvision_exit(void)
2035{
2036 PDEBUG(DBG_PROBE, "");
2037
2038 usb_deregister(&usbvision_driver);
2039 PDEBUG(DBG_PROBE, "success");
2040}
2041
2042module_init(usbvision_init);
2043module_exit(usbvision_exit);
2044
2045/*
2046 * Overrides for Emacs so that we follow Linus's tabbing style.
2047 * ---------------------------------------------------------------------------
2048 * Local variables:
2049 * c-basic-offset: 8
2050 * End:
2051 */
diff --git a/drivers/media/video/usbvision/usbvision.h b/drivers/media/video/usbvision/usbvision.h
new file mode 100644
index 000000000000..0e7e3d653cac
--- /dev/null
+++ b/drivers/media/video/usbvision/usbvision.h
@@ -0,0 +1,558 @@
1/*
2 * USBVISION.H
3 * usbvision header file
4 *
5 * Copyright (c) 1999-2005 Joerg Heckenbach <joerg@heckenbach-aw.de>
6 * Dwaine Garden <dwainegarden@rogers.com>
7 *
8 *
9 * Report problems to v4l MailingList : http://www.redhat.com/mailman/listinfo/video4linux-list
10 *
11 * This module is part of usbvision driver project.
12 * Updates to driver completed by Dwaine P. Garden
13 * v4l2 conversion by Thierry Merle <thierry.merle@free.fr>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 */
29
30
31#ifndef __LINUX_USBVISION_H
32#define __LINUX_USBVISION_H
33
34#include <linux/list.h>
35#include <linux/usb.h>
36#include <media/v4l2-common.h>
37#include <media/tuner.h>
38#include <linux/videodev2.h>
39
40#define USBVISION_DEBUG /* Turn on debug messages */
41
42#ifndef VID_HARDWARE_USBVISION
43 #define VID_HARDWARE_USBVISION 34 /* USBVision Video Grabber */
44#endif
45
46#define USBVISION_PWR_REG 0x00
47 #define USBVISION_SSPND_EN (1 << 1)
48 #define USBVISION_RES2 (1 << 2)
49 #define USBVISION_PWR_VID (1 << 5)
50 #define USBVISION_E2_EN (1 << 7)
51#define USBVISION_CONFIG_REG 0x01
52#define USBVISION_ADRS_REG 0x02
53#define USBVISION_ALTER_REG 0x03
54#define USBVISION_FORCE_ALTER_REG 0x04
55#define USBVISION_STATUS_REG 0x05
56#define USBVISION_IOPIN_REG 0x06
57 #define USBVISION_IO_1 (1 << 0)
58 #define USBVISION_IO_2 (1 << 1)
59 #define USBVISION_AUDIO_IN 0
60 #define USBVISION_AUDIO_TV 1
61 #define USBVISION_AUDIO_RADIO 2
62 #define USBVISION_AUDIO_MUTE 3
63#define USBVISION_SER_MODE 0x07
64#define USBVISION_SER_ADRS 0x08
65#define USBVISION_SER_CONT 0x09
66#define USBVISION_SER_DAT1 0x0A
67#define USBVISION_SER_DAT2 0x0B
68#define USBVISION_SER_DAT3 0x0C
69#define USBVISION_SER_DAT4 0x0D
70#define USBVISION_EE_DATA 0x0E
71#define USBVISION_EE_LSBAD 0x0F
72#define USBVISION_EE_CONT 0x10
73#define USBVISION_DRM_CONT 0x12
74 #define USBVISION_REF (1 << 0)
75 #define USBVISION_RES_UR (1 << 2)
76 #define USBVISION_RES_FDL (1 << 3)
77 #define USBVISION_RES_VDW (1 << 4)
78#define USBVISION_DRM_PRM1 0x13
79#define USBVISION_DRM_PRM2 0x14
80#define USBVISION_DRM_PRM3 0x15
81#define USBVISION_DRM_PRM4 0x16
82#define USBVISION_DRM_PRM5 0x17
83#define USBVISION_DRM_PRM6 0x18
84#define USBVISION_DRM_PRM7 0x19
85#define USBVISION_DRM_PRM8 0x1A
86#define USBVISION_VIN_REG1 0x1B
87 #define USBVISION_8_422_SYNC 0x01
88 #define USBVISION_16_422_SYNC 0x02
89 #define USBVISION_VSNC_POL (1 << 3)
90 #define USBVISION_HSNC_POL (1 << 4)
91 #define USBVISION_FID_POL (1 << 5)
92 #define USBVISION_HVALID_PO (1 << 6)
93 #define USBVISION_VCLK_POL (1 << 7)
94#define USBVISION_VIN_REG2 0x1C
95 #define USBVISION_AUTO_FID (1 << 0)
96 #define USBVISION_NONE_INTER (1 << 1)
97 #define USBVISION_NOHVALID (1 << 2)
98 #define USBVISION_UV_ID (1 << 3)
99 #define USBVISION_FIX_2C (1 << 4)
100 #define USBVISION_SEND_FID (1 << 5)
101 #define USBVISION_KEEP_BLANK (1 << 7)
102#define USBVISION_LXSIZE_I 0x1D
103#define USBVISION_MXSIZE_I 0x1E
104#define USBVISION_LYSIZE_I 0x1F
105#define USBVISION_MYSIZE_I 0x20
106#define USBVISION_LX_OFFST 0x21
107#define USBVISION_MX_OFFST 0x22
108#define USBVISION_LY_OFFST 0x23
109#define USBVISION_MY_OFFST 0x24
110#define USBVISION_FRM_RATE 0x25
111#define USBVISION_LXSIZE_O 0x26
112#define USBVISION_MXSIZE_O 0x27
113#define USBVISION_LYSIZE_O 0x28
114#define USBVISION_MYSIZE_O 0x29
115#define USBVISION_FILT_CONT 0x2A
116#define USBVISION_VO_MODE 0x2B
117#define USBVISION_INTRA_CYC 0x2C
118#define USBVISION_STRIP_SZ 0x2D
119#define USBVISION_FORCE_INTRA 0x2E
120#define USBVISION_FORCE_UP 0x2F
121#define USBVISION_BUF_THR 0x30
122#define USBVISION_DVI_YUV 0x31
123#define USBVISION_AUDIO_CONT 0x32
124#define USBVISION_AUD_PK_LEN 0x33
125#define USBVISION_BLK_PK_LEN 0x34
126#define USBVISION_PCM_THR1 0x38
127#define USBVISION_PCM_THR2 0x39
128#define USBVISION_DIST_THR_L 0x3A
129#define USBVISION_DIST_THR_H 0x3B
130#define USBVISION_MAX_DIST_L 0x3C
131#define USBVISION_MAX_DIST_H 0x3D
132#define USBVISION_OP_CODE 0x33
133
134#define MAX_BYTES_PER_PIXEL 4
135
136#define MIN_FRAME_WIDTH 64
137#define MAX_USB_WIDTH 320 //384
138#define MAX_FRAME_WIDTH 320 //384 /*streching sometimes causes crashes*/
139
140#define MIN_FRAME_HEIGHT 48
141#define MAX_USB_HEIGHT 240 //288
142#define MAX_FRAME_HEIGHT 240 //288 /*Streching sometimes causes crashes*/
143
144#define MAX_FRAME_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL)
145#define USBVISION_CLIPMASK_SIZE (MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) //bytesize of clipmask
146
147#define USBVISION_URB_FRAMES 32
148#define USBVISION_MAX_ISOC_PACKET_SIZE 959 // NT1003 Specs Document says 1023
149
150#define USBVISION_NUM_HEADERMARKER 20
151#define USBVISION_NUMFRAMES 3 /* Maximum number of frames an application can get */
152#define USBVISION_NUMSBUF 2 /* Dimensioning the USB S buffering */
153
154#define USBVISION_POWEROFF_TIME 3 * (HZ) // 3 seconds
155
156
157#define FRAMERATE_MIN 0
158#define FRAMERATE_MAX 31
159
160enum {
161 ISOC_MODE_YUV422 = 0x03,
162 ISOC_MODE_YUV420 = 0x14,
163 ISOC_MODE_COMPRESS = 0x60,
164};
165
166/* This macro restricts an int variable to an inclusive range */
167#define RESTRICT_TO_RANGE(v,mi,ma) { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }
168
169/*
170 * We use macros to do YUV -> RGB conversion because this is
171 * very important for speed and totally unimportant for size.
172 *
173 * YUV -> RGB Conversion
174 * ---------------------
175 *
176 * B = 1.164*(Y-16) + 2.018*(V-128)
177 * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128)
178 * R = 1.164*(Y-16) + 1.596*(U-128)
179 *
180 * If you fancy integer arithmetics (as you should), hear this:
181 *
182 * 65536*B = 76284*(Y-16) + 132252*(V-128)
183 * 65536*G = 76284*(Y-16) - 53281*(U-128) - 25625*(V-128)
184 * 65536*R = 76284*(Y-16) + 104595*(U-128)
185 *
186 * Make sure the output values are within [0..255] range.
187 */
188#define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)))
189#define YUV_TO_RGB_BY_THE_BOOK(my,mu,mv,mr,mg,mb) { \
190 int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \
191 mm_y = (my) - 16; \
192 mm_u = (mu) - 128; \
193 mm_v = (mv) - 128; \
194 mm_yc= mm_y * 76284; \
195 mm_b = (mm_yc + 132252*mm_v ) >> 16; \
196 mm_g = (mm_yc - 53281*mm_u - 25625*mm_v ) >> 16; \
197 mm_r = (mm_yc + 104595*mm_u ) >> 16; \
198 mb = LIMIT_RGB(mm_b); \
199 mg = LIMIT_RGB(mm_g); \
200 mr = LIMIT_RGB(mm_r); \
201}
202
203/* Debugging aid */
204#define USBVISION_SAY_AND_WAIT(what) { \
205 wait_queue_head_t wq; \
206 init_waitqueue_head(&wq); \
207 printk(KERN_INFO "Say: %s\n", what); \
208 interruptible_sleep_on_timeout (&wq, HZ*3); \
209}
210
211/*
212 * This macro checks if usbvision is still operational. The 'usbvision'
213 * pointer must be valid, usbvision->dev must be valid, we are not
214 * removing the device and the device has not erred on us.
215 */
216#define USBVISION_IS_OPERATIONAL(udevice) (\
217 (udevice != NULL) && \
218 ((udevice)->dev != NULL) && \
219 ((udevice)->last_error == 0) && \
220 (!(udevice)->remove_pending))
221
222/* I2C structures */
223struct i2c_algo_usb_data {
224 void *data; /* private data for lowlevel routines */
225 int (*inb) (void *data, unsigned char addr, char *buf, short len);
226 int (*outb) (void *data, unsigned char addr, char *buf, short len);
227
228 /* local settings */
229 int udelay;
230 int mdelay;
231 int timeout;
232};
233
234#define I2C_USB_ADAP_MAX 16
235
236/* ----------------------------------------------------------------- */
237/* usbvision video structures */
238/* ----------------------------------------------------------------- */
239enum ScanState {
240 ScanState_Scanning, /* Scanning for header */
241 ScanState_Lines /* Parsing lines */
242};
243
244/* Completion states of the data parser */
245enum ParseState {
246 ParseState_Continue, /* Just parse next item */
247 ParseState_NextFrame, /* Frame done, send it to V4L */
248 ParseState_Out, /* Not enough data for frame */
249 ParseState_EndParse /* End parsing */
250};
251
252enum FrameState {
253 FrameState_Unused, /* Unused (no MCAPTURE) */
254 FrameState_Ready, /* Ready to start grabbing */
255 FrameState_Grabbing, /* In the process of being grabbed into */
256 FrameState_Done, /* Finished grabbing, but not been synced yet */
257 FrameState_DoneHold, /* Are syncing or reading */
258 FrameState_Error, /* Something bad happened while processing */
259};
260
261/* stream states */
262enum StreamState {
263 Stream_Off, /* Driver streaming is completely OFF */
264 Stream_Idle, /* Driver streaming is ready to be put ON by the application */
265 Stream_Interrupt, /* Driver streaming must be interrupted */
266 Stream_On, /* Driver streaming is put ON by the application */
267};
268
269enum IsocState {
270 IsocState_InFrame, /* Isoc packet is member of frame */
271 IsocState_NoFrame, /* Isoc packet is not member of any frame */
272};
273
274struct usb_device;
275
276struct usbvision_sbuf {
277 char *data;
278 struct urb *urb;
279};
280
281#define USBVISION_MAGIC_1 0x55
282#define USBVISION_MAGIC_2 0xAA
283#define USBVISION_HEADER_LENGTH 0x0c
284#define USBVISION_SAA7111_ADDR 0x48
285#define USBVISION_SAA7113_ADDR 0x4a
286#define USBVISION_IIC_LRACK 0x20
287#define USBVISION_IIC_LRNACK 0x30
288#define USBVISION_FRAME_FORMAT_PARAM_INTRA (1<<7)
289
290struct usbvision_v4l2_format_st {
291 int supported;
292 int bytes_per_pixel;
293 int depth;
294 int format;
295 char *desc;
296};
297#define USBVISION_SUPPORTED_PALETTES ARRAY_SIZE(usbvision_v4l2_format)
298
299struct usbvision_frame_header {
300 unsigned char magic_1; /* 0 magic */
301 unsigned char magic_2; /* 1 magic */
302 unsigned char headerLength; /* 2 */
303 unsigned char frameNum; /* 3 */
304 unsigned char framePhase; /* 4 */
305 unsigned char frameLatency; /* 5 */
306 unsigned char dataFormat; /* 6 */
307 unsigned char formatParam; /* 7 */
308 unsigned char frameWidthLo; /* 8 */
309 unsigned char frameWidthHi; /* 9 */
310 unsigned char frameHeightLo; /* 10 */
311 unsigned char frameHeightHi; /* 11 */
312 __u16 frameWidth; /* 8 - 9 after endian correction*/
313 __u16 frameHeight; /* 10 - 11 after endian correction*/
314};
315
316/* tvnorms */
317struct usbvision_tvnorm {
318 char *name;
319 v4l2_std_id id;
320 /* mode for saa7113h */
321 int mode;
322};
323
324struct usbvision_frame {
325 char *data; /* Frame buffer */
326 struct usbvision_frame_header isocHeader; /* Header from stream */
327
328 int width; /* Width application is expecting */
329 int height; /* Height */
330 int index; /* Frame index */
331 int frmwidth; /* Width the frame actually is */
332 int frmheight; /* Height */
333
334 volatile int grabstate; /* State of grabbing */
335 int scanstate; /* State of scanning */
336
337 struct list_head frame;
338
339 int curline; /* Line of frame we're working on */
340
341 long scanlength; /* uncompressed, raw data length of frame */
342 long bytes_read; /* amount of scanlength that has been read from data */
343 struct usbvision_v4l2_format_st v4l2_format; /* format the user needs*/
344 int v4l2_linesize; /* bytes for one videoline*/
345 struct timeval timestamp;
346 int sequence; // How many video frames we send to user
347};
348
349#define CODEC_SAA7113 7113
350#define CODEC_SAA7111 7111
351#define BRIDGE_NT1003 1003
352#define BRIDGE_NT1004 1004
353#define BRIDGE_NT1005 1005
354
355struct usbvision_device_data_st {
356 int idVendor;
357 int idProduct;
358 int Interface; /* to handle special interface number like BELKIN and Hauppauge WinTV-USB II */
359 int Codec;
360 int VideoChannels;
361 __u64 VideoNorm;
362 int AudioChannels;
363 int Radio;
364 int vbi;
365 int Tuner;
366 int TunerType;
367 int Vin_Reg1;
368 int Vin_Reg2;
369 int X_Offset;
370 int Y_Offset;
371 int Dvi_yuv;
372 char *ModelString;
373};
374
375/* Declared on usbvision-cards.c */
376extern struct usbvision_device_data_st usbvision_device_data[];
377extern struct usb_device_id usbvision_table[];
378
379struct usb_usbvision {
380 struct video_device *vdev; /* Video Device */
381 struct video_device *rdev; /* Radio Device */
382 struct video_device *vbi; /* VBI Device */
383
384 /* i2c Declaration Section*/
385 struct i2c_adapter i2c_adap;
386 struct i2c_algo_usb_data i2c_algo;
387 struct i2c_client i2c_client;
388
389 struct urb *ctrlUrb;
390 unsigned char ctrlUrbBuffer[8];
391 int ctrlUrbBusy;
392 struct usb_ctrlrequest ctrlUrbSetup;
393 wait_queue_head_t ctrlUrb_wq; // Processes waiting
394 struct semaphore ctrlUrbLock;
395
396 /* configuration part */
397 int have_tuner;
398 int tuner_type;
399 int tuner_addr;
400 int bridgeType; // NT1003, NT1004, NT1005
401 int channel;
402 int radio;
403 int video_inputs; // # of inputs
404 unsigned long freq;
405 int AudioMute;
406 int AudioChannel;
407 int isocMode; // format of video data for the usb isoc-transfer
408 unsigned int nr; // Number of the device
409
410 /* Device structure */
411 struct usb_device *dev;
412 unsigned char iface; /* Video interface number */
413 unsigned char ifaceAltActive, ifaceAltInactive; /* Alt settings */
414 unsigned char Vin_Reg2_Preset;
415 struct semaphore lock;
416 struct timer_list powerOffTimer;
417 struct work_struct powerOffWork;
418 int power; /* is the device powered on? */
419 int user; /* user count for exclusive use */
420 int initialized; /* Had we already sent init sequence? */
421 int DevModel; /* What type of USBVISION device we got? */
422 enum StreamState streaming; /* Are we streaming Isochronous? */
423 int last_error; /* What calamity struck us? */
424 int curwidth; /* width of the frame the device is currently set to*/
425 int curheight; /* height of the frame the device is currently set to*/
426 int stretch_width; /* stretch-factor for frame width (from usb to screen)*/
427 int stretch_height; /* stretch-factor for frame height (from usb to screen)*/
428 char *fbuf; /* Videodev buffer area for mmap*/
429 int max_frame_size; /* Bytes in one video frame */
430 int fbuf_size; /* Videodev buffer size */
431 spinlock_t queue_lock; /* spinlock for protecting mods on inqueue and outqueue */
432 struct list_head inqueue, outqueue; /* queued frame list and ready to dequeue frame list */
433 wait_queue_head_t wait_frame; /* Processes waiting */
434 wait_queue_head_t wait_stream; /* Processes waiting */
435 struct usbvision_frame *curFrame; // pointer to current frame, set by usbvision_find_header
436 struct usbvision_frame frame[USBVISION_NUMFRAMES]; // frame buffer
437 struct usbvision_sbuf sbuf[USBVISION_NUMSBUF]; // S buffering
438 volatile int remove_pending; /* If set then about to exit */
439
440 /* Scratch space from the Isochronous Pipe.*/
441 unsigned char *scratch;
442 int scratch_read_ptr;
443 int scratch_write_ptr;
444 int scratch_headermarker[USBVISION_NUM_HEADERMARKER];
445 int scratch_headermarker_read_ptr;
446 int scratch_headermarker_write_ptr;
447 enum IsocState isocstate;
448 struct usbvision_v4l2_format_st palette;
449
450 struct v4l2_capability vcap; /* Video capabilities */
451 unsigned int ctl_input; /* selected input */
452 struct usbvision_tvnorm *tvnorm; /* selected tv norm */
453 unsigned char video_endp; /* 0x82 for USBVISION devices based */
454
455 // Decompression stuff:
456 unsigned char *IntraFrameBuffer; /* Buffer for reference frame */
457 int BlockPos; //for test only
458 int requestIntra; // 0 = normal; 1 = intra frame is requested;
459 int lastIsocFrameNum; // check for lost isoc frames
460 int isocPacketSize; // need to calculate usedBandwidth
461 int usedBandwidth; // used bandwidth 0-100%, need to set comprLevel
462 int comprLevel; // How strong (100) or weak (0) is compression
463 int lastComprLevel; // How strong (100) or weak (0) was compression
464 int usb_bandwidth; /* Mbit/s */
465
466 /* Statistics that can be overlayed on the screen */
467 unsigned long isocUrbCount; // How many URBs we received so far
468 unsigned long urb_length; /* Length of last URB */
469 unsigned long isocDataCount; /* How many bytes we received */
470 unsigned long header_count; /* How many frame headers we found */
471 unsigned long scratch_ovf_count; /* How many times we overflowed scratch */
472 unsigned long isocSkipCount; /* How many empty ISO packets received */
473 unsigned long isocErrCount; /* How many bad ISO packets received */
474 unsigned long isocPacketCount; // How many packets we totally got
475 unsigned long timeInIrq; // How long do we need for interrupt
476 int isocMeasureBandwidthCount;
477 int frame_num; // How many video frames we send to user
478 int maxStripLen; // How big is the biggest strip
479 int comprBlockPos;
480 int stripLenErrors; // How many times was BlockPos greater than StripLen
481 int stripMagicErrors;
482 int stripLineNumberErrors;
483 int ComprBlockTypes[4];
484};
485
486
487/* --------------------------------------------------------------- */
488/* defined in usbvision-i2c.c */
489/* i2c-algo-usb declaration */
490/* --------------------------------------------------------------- */
491
492int usbvision_i2c_usb_add_bus(struct i2c_adapter *);
493int usbvision_i2c_usb_del_bus(struct i2c_adapter *);
494
495static inline void *i2c_get_algo_usb_data (struct i2c_algo_usb_data *dev)
496{
497 return dev->data;
498}
499
500static inline void i2c_set_algo_usb_data (struct i2c_algo_usb_data *dev, void *data)
501{
502 dev->data = data;
503}
504
505
506/* ----------------------------------------------------------------------- */
507/* usbvision specific I2C functions */
508/* ----------------------------------------------------------------------- */
509int usbvision_init_i2c(struct usb_usbvision *usbvision);
510void call_i2c_clients(struct usb_usbvision *usbvision, unsigned int cmd,void *arg);
511
512/* defined in usbvision-core.c */
513void *usbvision_rvmalloc(unsigned long size);
514void usbvision_rvfree(void *mem, unsigned long size);
515int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg);
516int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
517 unsigned char value);
518
519int usbvision_frames_alloc(struct usb_usbvision *usbvision);
520void usbvision_frames_free(struct usb_usbvision *usbvision);
521int usbvision_scratch_alloc(struct usb_usbvision *usbvision);
522void usbvision_scratch_free(struct usb_usbvision *usbvision);
523int usbvision_sbuf_alloc(struct usb_usbvision *usbvision);
524void usbvision_sbuf_free(struct usb_usbvision *usbvision);
525int usbvision_decompress_alloc(struct usb_usbvision *usbvision);
526void usbvision_decompress_free(struct usb_usbvision *usbvision);
527
528int usbvision_setup(struct usb_usbvision *usbvision,int format);
529int usbvision_init_isoc(struct usb_usbvision *usbvision);
530int usbvision_restart_isoc(struct usb_usbvision *usbvision);
531void usbvision_stop_isoc(struct usb_usbvision *usbvision);
532
533int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel);
534int usbvision_audio_off(struct usb_usbvision *usbvision);
535
536int usbvision_begin_streaming(struct usb_usbvision *usbvision);
537void usbvision_empty_framequeues(struct usb_usbvision *dev);
538int usbvision_stream_interrupt(struct usb_usbvision *dev);
539
540int usbvision_muxsel(struct usb_usbvision *usbvision, int channel);
541int usbvision_set_input(struct usb_usbvision *usbvision);
542int usbvision_set_output(struct usb_usbvision *usbvision, int width, int height);
543
544void usbvision_init_powerOffTimer(struct usb_usbvision *usbvision);
545void usbvision_set_powerOffTimer(struct usb_usbvision *usbvision);
546void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision);
547int usbvision_power_off(struct usb_usbvision *usbvision);
548int usbvision_power_on(struct usb_usbvision *usbvision);
549
550#endif /* __LINUX_USBVISION_H */
551
552/*
553 * Overrides for Emacs so that we follow Linus's tabbing style.
554 * ---------------------------------------------------------------------------
555 * Local variables:
556 * c-basic-offset: 8
557 * End:
558 */
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 1d899e2db394..8a13e595304e 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -350,6 +350,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
350 struct video_buffer *buffer = arg; 350 struct video_buffer *buffer = arg;
351 351
352 memset(buffer, 0, sizeof(*buffer)); 352 memset(buffer, 0, sizeof(*buffer));
353 memset(&fbuf2, 0, sizeof(fbuf2));
353 354
354 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2); 355 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
355 if (err < 0) { 356 if (err < 0) {
@@ -616,6 +617,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
616 case VIDIOCSPICT: /* set tone controls & partial capture format */ 617 case VIDIOCSPICT: /* set tone controls & partial capture format */
617 { 618 {
618 struct video_picture *pict = arg; 619 struct video_picture *pict = arg;
620 memset(&fbuf2, 0, sizeof(fbuf2));
619 621
620 set_v4l_control(inode, file, 622 set_v4l_control(inode, file,
621 V4L2_CID_BRIGHTNESS, pict->brightness, drv); 623 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
@@ -708,12 +710,22 @@ v4l_compat_translate_ioctl(struct inode *inode,
708 } 710 }
709 case VIDIOCSTUNER: /* select a tuner input */ 711 case VIDIOCSTUNER: /* select a tuner input */
710 { 712 {
711 err = 0; 713 struct video_tuner *tun = arg;
714 struct v4l2_tuner t;
715 memset(&t,0,sizeof(t));
716
717 t.index=tun->tuner;
718
719 err = drv(inode, file, VIDIOC_S_INPUT, &t);
720 if (err < 0)
721 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err);
722
712 break; 723 break;
713 } 724 }
714 case VIDIOCGFREQ: /* get frequency */ 725 case VIDIOCGFREQ: /* get frequency */
715 { 726 {
716 unsigned long *freq = arg; 727 unsigned long *freq = arg;
728 memset(&freq2,0,sizeof(freq2));
717 729
718 freq2.tuner = 0; 730 freq2.tuner = 0;
719 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2); 731 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
@@ -726,8 +738,8 @@ v4l_compat_translate_ioctl(struct inode *inode,
726 case VIDIOCSFREQ: /* set frequency */ 738 case VIDIOCSFREQ: /* set frequency */
727 { 739 {
728 unsigned long *freq = arg; 740 unsigned long *freq = arg;
741 memset(&freq2,0,sizeof(freq2));
729 742
730 freq2.tuner = 0;
731 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2); 743 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
732 freq2.frequency = *freq; 744 freq2.frequency = *freq;
733 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2); 745 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
@@ -738,6 +750,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
738 case VIDIOCGAUDIO: /* get audio properties/controls */ 750 case VIDIOCGAUDIO: /* get audio properties/controls */
739 { 751 {
740 struct video_audio *aud = arg; 752 struct video_audio *aud = arg;
753 memset(&aud2,0,sizeof(aud2));
741 754
742 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2); 755 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
743 if (err < 0) { 756 if (err < 0) {
@@ -898,6 +911,7 @@ v4l_compat_translate_ioctl(struct inode *inode,
898 { 911 {
899 int *i = arg; 912 int *i = arg;
900 913
914 memset(&buf2,0,sizeof(buf2));
901 buf2.index = *i; 915 buf2.index = *i;
902 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 916 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
903 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2); 917 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 78d28b03ec93..752c82c37f55 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -87,6 +87,78 @@ MODULE_LICENSE("GPL");
87 */ 87 */
88 88
89 89
90char *v4l2_norm_to_name(v4l2_std_id id)
91{
92 char *name;
93
94 switch (id) {
95 case V4L2_STD_PAL:
96 name="PAL"; break;
97 case V4L2_STD_PAL_BG:
98 name="PAL-BG"; break;
99 case V4L2_STD_PAL_DK:
100 name="PAL-DK"; break;
101 case V4L2_STD_PAL_B:
102 name="PAL-B"; break;
103 case V4L2_STD_PAL_B1:
104 name="PAL-B1"; break;
105 case V4L2_STD_PAL_G:
106 name="PAL-G"; break;
107 case V4L2_STD_PAL_H:
108 name="PAL-H"; break;
109 case V4L2_STD_PAL_I:
110 name="PAL-I"; break;
111 case V4L2_STD_PAL_D:
112 name="PAL-D"; break;
113 case V4L2_STD_PAL_D1:
114 name="PAL-D1"; break;
115 case V4L2_STD_PAL_K:
116 name="PAL-K"; break;
117 case V4L2_STD_PAL_M:
118 name="PAL-M"; break;
119 case V4L2_STD_PAL_N:
120 name="PAL-N"; break;
121 case V4L2_STD_PAL_Nc:
122 name="PAL-Nc"; break;
123 case V4L2_STD_PAL_60:
124 name="PAL-60"; break;
125 case V4L2_STD_NTSC:
126 name="NTSC"; break;
127 case V4L2_STD_NTSC_M:
128 name="NTSC-M"; break;
129 case V4L2_STD_NTSC_M_JP:
130 name="NTSC-M-JP"; break;
131 case V4L2_STD_NTSC_443:
132 name="NTSC-443"; break;
133 case V4L2_STD_NTSC_M_KR:
134 name="NTSC-M-KR"; break;
135 case V4L2_STD_SECAM:
136 name="SECAM"; break;
137 case V4L2_STD_SECAM_DK:
138 name="SECAM-DK"; break;
139 case V4L2_STD_SECAM_B:
140 name="SECAM-B"; break;
141 case V4L2_STD_SECAM_D:
142 name="SECAM-D"; break;
143 case V4L2_STD_SECAM_G:
144 name="SECAM-G"; break;
145 case V4L2_STD_SECAM_H:
146 name="SECAM-H"; break;
147 case V4L2_STD_SECAM_K:
148 name="SECAM-K"; break;
149 case V4L2_STD_SECAM_K1:
150 name="SECAM-K1"; break;
151 case V4L2_STD_SECAM_L:
152 name="SECAM-L"; break;
153 case V4L2_STD_SECAM_LC:
154 name="SECAM-LC"; break;
155 default:
156 name="Unknown"; break;
157 }
158
159 return name;
160}
161
90/* Fill in the fields of a v4l2_standard structure according to the 162/* Fill in the fields of a v4l2_standard structure according to the
91 'id' and 'transmission' parameters. Returns negative on error. */ 163 'id' and 'transmission' parameters. Returns negative on error. */
92int v4l2_video_std_construct(struct v4l2_standard *vs, 164int v4l2_video_std_construct(struct v4l2_standard *vs,
@@ -184,11 +256,13 @@ char *v4l2_field_names[] = {
184}; 256};
185 257
186char *v4l2_type_names[] = { 258char *v4l2_type_names[] = {
187 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap", 259 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "video-cap",
188 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over", 260 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "video-over",
189 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out", 261 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "video-out",
190 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap", 262 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
191 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out", 263 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
264 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
265 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "slicec-vbi-out",
192}; 266};
193 267
194static char *v4l2_memory_names[] = { 268static char *v4l2_memory_names[] = {
@@ -1451,6 +1525,7 @@ u32 v4l2_ctrl_next(const u32 * const * ctrl_classes, u32 id)
1451 1525
1452/* ----------------------------------------------------------------- */ 1526/* ----------------------------------------------------------------- */
1453 1527
1528EXPORT_SYMBOL(v4l2_norm_to_name);
1454EXPORT_SYMBOL(v4l2_video_std_construct); 1529EXPORT_SYMBOL(v4l2_video_std_construct);
1455 1530
1456EXPORT_SYMBOL(v4l2_prio_init); 1531EXPORT_SYMBOL(v4l2_prio_init);
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index d424a4129d69..6a0e8ca72948 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -105,7 +105,7 @@ static DEFINE_MUTEX(videodev_lock);
105 105
106struct video_device* video_devdata(struct file *file) 106struct video_device* video_devdata(struct file *file)
107{ 107{
108 return video_device[iminor(file->f_dentry->d_inode)]; 108 return video_device[iminor(file->f_path.dentry->d_inode)];
109} 109}
110 110
111/* 111/*
@@ -342,7 +342,7 @@ static void dbgbuf(unsigned int cmd, struct video_device *vfd,
342 342
343 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, " 343 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
344 "bytesused=%d, flags=0x%08d, " 344 "bytesused=%d, flags=0x%08d, "
345 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx\n", 345 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
346 (p->timestamp.tv_sec/3600), 346 (p->timestamp.tv_sec/3600),
347 (int)(p->timestamp.tv_sec/60)%60, 347 (int)(p->timestamp.tv_sec/60)%60,
348 (int)(p->timestamp.tv_sec%60), 348 (int)(p->timestamp.tv_sec%60),
@@ -352,7 +352,7 @@ static void dbgbuf(unsigned int cmd, struct video_device *vfd,
352 p->bytesused,p->flags, 352 p->bytesused,p->flags,
353 p->field,p->sequence, 353 p->field,p->sequence,
354 prt_names(p->memory,v4l2_memory_names), 354 prt_names(p->memory,v4l2_memory_names),
355 p->m.userptr); 355 p->m.userptr, p->length);
356 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, " 356 dbgarg2 ("timecode= %02d:%02d:%02d type=%d, "
357 "flags=0x%08d, frames=%d, userbits=0x%08x\n", 357 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
358 tc->hours,tc->minutes,tc->seconds, 358 tc->hours,tc->minutes,tc->seconds,
@@ -369,9 +369,13 @@ static inline void dbgrect(struct video_device *vfd, char *s,
369static inline void v4l_print_pix_fmt (struct video_device *vfd, 369static inline void v4l_print_pix_fmt (struct video_device *vfd,
370 struct v4l2_pix_format *fmt) 370 struct v4l2_pix_format *fmt)
371{ 371{
372 dbgarg2 ("width=%d, height=%d, format=0x%08x, field=%s, " 372 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
373 "bytesperline=%d sizeimage=%d, colorspace=%d\n", 373 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
374 fmt->width,fmt->height,fmt->pixelformat, 374 fmt->width,fmt->height,
375 (fmt->pixelformat & 0xff),
376 (fmt->pixelformat >> 8) & 0xff,
377 (fmt->pixelformat >> 16) & 0xff,
378 (fmt->pixelformat >> 24) & 0xff,
375 prt_names(fmt->field,v4l2_field_names_FIXME), 379 prt_names(fmt->field,v4l2_field_names_FIXME),
376 fmt->bytesperline,fmt->sizeimage,fmt->colorspace); 380 fmt->bytesperline,fmt->sizeimage,fmt->colorspace);
377}; 381};
@@ -428,6 +432,10 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
428 v4l_print_ioctl(vfd->name, cmd); 432 v4l_print_ioctl(vfd->name, cmd);
429 } 433 }
430 434
435 if (_IOC_TYPE(cmd)=='v')
436 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
437 __video_do_ioctl);
438
431 switch(cmd) { 439 switch(cmd) {
432 /* --- capabilities ------------------------------------------ */ 440 /* --- capabilities ------------------------------------------ */
433 case VIDIOC_QUERYCAP: 441 case VIDIOC_QUERYCAP:
@@ -526,12 +534,13 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
526 } 534 }
527 if (!ret) 535 if (!ret)
528 dbgarg (cmd, "index=%d, type=%d, flags=%d, " 536 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
529 "description=%s," 537 "pixelformat=%c%c%c%c, description='%s'\n",
530 " pixelformat=0x%8x\n",
531 f->index, f->type, f->flags, 538 f->index, f->type, f->flags,
532 f->description, 539 (f->pixelformat & 0xff),
533 f->pixelformat); 540 (f->pixelformat >> 8) & 0xff,
534 541 (f->pixelformat >> 16) & 0xff,
542 (f->pixelformat >> 24) & 0xff,
543 f->description);
535 break; 544 break;
536 } 545 }
537 case VIDIOC_G_FMT: 546 case VIDIOC_G_FMT:
@@ -829,20 +838,85 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
829 case VIDIOC_ENUMSTD: 838 case VIDIOC_ENUMSTD:
830 { 839 {
831 struct v4l2_standard *p = arg; 840 struct v4l2_standard *p = arg;
832 unsigned int index = p->index; 841 v4l2_std_id id = vfd->tvnorms,curr_id=0;
842 unsigned int index = p->index,i;
833 843
834 if (!vfd->tvnormsize) { 844 if (index<0) {
835 printk (KERN_WARNING "%s: no TV norms defined!\n", 845 ret=-EINVAL;
836 vfd->name);
837 break; 846 break;
838 } 847 }
839 848
840 if (index<0 || index >= vfd->tvnormsize) { 849 /* Return norm array on a canonical way */
841 ret=-EINVAL; 850 for (i=0;i<= index && id; i++) {
842 break; 851 if ( (id & V4L2_STD_PAL) == V4L2_STD_PAL) {
852 curr_id = V4L2_STD_PAL;
853 } else if ( (id & V4L2_STD_PAL_BG) == V4L2_STD_PAL_BG) {
854 curr_id = V4L2_STD_PAL_BG;
855 } else if ( (id & V4L2_STD_PAL_DK) == V4L2_STD_PAL_DK) {
856 curr_id = V4L2_STD_PAL_DK;
857 } else if ( (id & V4L2_STD_PAL_B) == V4L2_STD_PAL_B) {
858 curr_id = V4L2_STD_PAL_B;
859 } else if ( (id & V4L2_STD_PAL_B1) == V4L2_STD_PAL_B1) {
860 curr_id = V4L2_STD_PAL_B1;
861 } else if ( (id & V4L2_STD_PAL_G) == V4L2_STD_PAL_G) {
862 curr_id = V4L2_STD_PAL_G;
863 } else if ( (id & V4L2_STD_PAL_H) == V4L2_STD_PAL_H) {
864 curr_id = V4L2_STD_PAL_H;
865 } else if ( (id & V4L2_STD_PAL_I) == V4L2_STD_PAL_I) {
866 curr_id = V4L2_STD_PAL_I;
867 } else if ( (id & V4L2_STD_PAL_D) == V4L2_STD_PAL_D) {
868 curr_id = V4L2_STD_PAL_D;
869 } else if ( (id & V4L2_STD_PAL_D1) == V4L2_STD_PAL_D1) {
870 curr_id = V4L2_STD_PAL_D1;
871 } else if ( (id & V4L2_STD_PAL_K) == V4L2_STD_PAL_K) {
872 curr_id = V4L2_STD_PAL_K;
873 } else if ( (id & V4L2_STD_PAL_M) == V4L2_STD_PAL_M) {
874 curr_id = V4L2_STD_PAL_M;
875 } else if ( (id & V4L2_STD_PAL_N) == V4L2_STD_PAL_N) {
876 curr_id = V4L2_STD_PAL_N;
877 } else if ( (id & V4L2_STD_PAL_Nc) == V4L2_STD_PAL_Nc) {
878 curr_id = V4L2_STD_PAL_Nc;
879 } else if ( (id & V4L2_STD_PAL_60) == V4L2_STD_PAL_60) {
880 curr_id = V4L2_STD_PAL_60;
881 } else if ( (id & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
882 curr_id = V4L2_STD_NTSC;
883 } else if ( (id & V4L2_STD_NTSC_M) == V4L2_STD_NTSC_M) {
884 curr_id = V4L2_STD_NTSC_M;
885 } else if ( (id & V4L2_STD_NTSC_M_JP) == V4L2_STD_NTSC_M_JP) {
886 curr_id = V4L2_STD_NTSC_M_JP;
887 } else if ( (id & V4L2_STD_NTSC_443) == V4L2_STD_NTSC_443) {
888 curr_id = V4L2_STD_NTSC_443;
889 } else if ( (id & V4L2_STD_NTSC_M_KR) == V4L2_STD_NTSC_M_KR) {
890 curr_id = V4L2_STD_NTSC_M_KR;
891 } else if ( (id & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
892 curr_id = V4L2_STD_SECAM;
893 } else if ( (id & V4L2_STD_SECAM_DK) == V4L2_STD_SECAM_DK) {
894 curr_id = V4L2_STD_SECAM_DK;
895 } else if ( (id & V4L2_STD_SECAM_B) == V4L2_STD_SECAM_B) {
896 curr_id = V4L2_STD_SECAM_B;
897 } else if ( (id & V4L2_STD_SECAM_D) == V4L2_STD_SECAM_D) {
898 curr_id = V4L2_STD_SECAM_D;
899 } else if ( (id & V4L2_STD_SECAM_G) == V4L2_STD_SECAM_G) {
900 curr_id = V4L2_STD_SECAM_G;
901 } else if ( (id & V4L2_STD_SECAM_H) == V4L2_STD_SECAM_H) {
902 curr_id = V4L2_STD_SECAM_H;
903 } else if ( (id & V4L2_STD_SECAM_K) == V4L2_STD_SECAM_K) {
904 curr_id = V4L2_STD_SECAM_K;
905 } else if ( (id & V4L2_STD_SECAM_K1) == V4L2_STD_SECAM_K1) {
906 curr_id = V4L2_STD_SECAM_K1;
907 } else if ( (id & V4L2_STD_SECAM_L) == V4L2_STD_SECAM_L) {
908 curr_id = V4L2_STD_SECAM_L;
909 } else if ( (id & V4L2_STD_SECAM_LC) == V4L2_STD_SECAM_LC) {
910 curr_id = V4L2_STD_SECAM_LC;
911 } else {
912 break;
913 }
914 id &= ~curr_id;
843 } 915 }
844 v4l2_video_std_construct(p, vfd->tvnorms[p->index].id, 916 if (i<=index)
845 vfd->tvnorms[p->index].name); 917 return -EINVAL;
918
919 v4l2_video_std_construct(p, curr_id,v4l2_norm_to_name(curr_id));
846 p->index = index; 920 p->index = index;
847 921
848 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, " 922 dbgarg (cmd, "index=%d, id=%Ld, name=%s, fps=%d/%d, "
@@ -868,39 +942,23 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
868 } 942 }
869 case VIDIOC_S_STD: 943 case VIDIOC_S_STD:
870 { 944 {
871 v4l2_std_id *id = arg; 945 v4l2_std_id *id = arg,norm;
872 unsigned int i;
873
874 if (!vfd->tvnormsize) {
875 printk (KERN_WARNING "%s: no TV norms defined!\n",
876 vfd->name);
877 break;
878 }
879 946
880 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id); 947 dbgarg (cmd, "value=%Lu\n", (long long unsigned) *id);
881 948
882 /* First search for exact match */ 949 norm = (*id) & vfd->tvnorms;
883 for (i = 0; i < vfd->tvnormsize; i++) 950 if ( vfd->tvnorms && !norm) /* Check if std is supported */
884 if (*id == vfd->tvnorms[i].id)
885 break;
886 /* Then for a generic video std that contains desired std */
887 if (i == vfd->tvnormsize)
888 for (i = 0; i < vfd->tvnormsize; i++)
889 if (*id & vfd->tvnorms[i].id)
890 break;
891 if (i == vfd->tvnormsize) {
892 break; 951 break;
893 }
894 952
895 /* Calls the specific handler */ 953 /* Calls the specific handler */
896 if (vfd->vidioc_s_std) 954 if (vfd->vidioc_s_std)
897 ret=vfd->vidioc_s_std(file, fh, i); 955 ret=vfd->vidioc_s_std(file, fh, &norm);
898 else 956 else
899 ret=-EINVAL; 957 ret=-EINVAL;
900 958
901 /* Updates standard information */ 959 /* Updates standard information */
902 if (!ret) 960 if (ret>=0)
903 vfd->current_norm=*id; 961 vfd->current_norm=norm;
904 962
905 break; 963 break;
906 } 964 }
@@ -1088,9 +1146,13 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1088 case VIDIOC_G_AUDIO: 1146 case VIDIOC_G_AUDIO:
1089 { 1147 {
1090 struct v4l2_audio *p=arg; 1148 struct v4l2_audio *p=arg;
1149 __u32 index=p->index;
1091 1150
1092 if (!vfd->vidioc_g_audio) 1151 if (!vfd->vidioc_g_audio)
1093 break; 1152 break;
1153
1154 memset(p,0,sizeof(*p));
1155 p->index=index;
1094 dbgarg(cmd, "Get for index=%d\n", p->index); 1156 dbgarg(cmd, "Get for index=%d\n", p->index);
1095 ret=vfd->vidioc_g_audio(file, fh, p); 1157 ret=vfd->vidioc_g_audio(file, fh, p);
1096 if (!ret) 1158 if (!ret)
@@ -1288,25 +1350,12 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1288 ret=vfd->vidioc_g_parm(file, fh, p); 1350 ret=vfd->vidioc_g_parm(file, fh, p);
1289 } else { 1351 } else {
1290 struct v4l2_standard s; 1352 struct v4l2_standard s;
1291 int i;
1292
1293 if (!vfd->tvnormsize) {
1294 printk (KERN_WARNING "%s: no TV norms defined!\n",
1295 vfd->name);
1296 break;
1297 }
1298 1353
1299 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1354 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1300 return -EINVAL; 1355 return -EINVAL;
1301 1356
1302 for (i = 0; i < vfd->tvnormsize; i++)
1303 if (vfd->tvnorms[i].id == vfd->current_norm)
1304 break;
1305 if (i >= vfd->tvnormsize)
1306 return -EINVAL;
1307
1308 v4l2_video_std_construct(&s, vfd->current_norm, 1357 v4l2_video_std_construct(&s, vfd->current_norm,
1309 vfd->tvnorms[i].name); 1358 v4l2_norm_to_name(vfd->current_norm));
1310 1359
1311 memset(p,0,sizeof(*p)); 1360 memset(p,0,sizeof(*p));
1312 1361
@@ -1329,8 +1378,14 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1329 case VIDIOC_G_TUNER: 1378 case VIDIOC_G_TUNER:
1330 { 1379 {
1331 struct v4l2_tuner *p=arg; 1380 struct v4l2_tuner *p=arg;
1381 __u32 index=p->index;
1382
1332 if (!vfd->vidioc_g_tuner) 1383 if (!vfd->vidioc_g_tuner)
1333 break; 1384 break;
1385
1386 memset(p,0,sizeof(*p));
1387 p->index=index;
1388
1334 ret=vfd->vidioc_g_tuner(file, fh, p); 1389 ret=vfd->vidioc_g_tuner(file, fh, p);
1335 if (!ret) 1390 if (!ret)
1336 dbgarg (cmd, "index=%d, name=%s, type=%d, " 1391 dbgarg (cmd, "index=%d, name=%s, type=%d, "
@@ -1363,6 +1418,9 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1363 struct v4l2_frequency *p=arg; 1418 struct v4l2_frequency *p=arg;
1364 if (!vfd->vidioc_g_frequency) 1419 if (!vfd->vidioc_g_frequency)
1365 break; 1420 break;
1421
1422 memset(p,0,sizeof(*p));
1423
1366 ret=vfd->vidioc_g_frequency(file, fh, p); 1424 ret=vfd->vidioc_g_frequency(file, fh, p);
1367 if (!ret) 1425 if (!ret)
1368 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n", 1426 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
@@ -1396,12 +1454,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1396 ret=vfd->vidioc_log_status(file, fh); 1454 ret=vfd->vidioc_log_status(file, fh);
1397 break; 1455 break;
1398 } 1456 }
1399 1457 } /* switch */
1400 /* --- Others --------------------------------------------- */
1401
1402 default:
1403 ret=v4l_compat_translate_ioctl(inode,file,cmd,arg,__video_do_ioctl);
1404 }
1405 1458
1406 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { 1459 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1407 if (ret<0) { 1460 if (ret<0) {
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 6b6dff4d236a..a373c142e742 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -782,7 +782,7 @@ static int vino_i2c_add_bus(void)
782 782
783static int vino_i2c_del_bus(void) 783static int vino_i2c_del_bus(void)
784{ 784{
785 return i2c_sgi_del_bus(&vino_i2c_adapter); 785 return i2c_del_adapter(&vino_i2c_adapter);
786} 786}
787 787
788static int i2c_camera_command(unsigned int cmd, void *arg) 788static int i2c_camera_command(unsigned int cmd, void *arg)
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 9986de5cb3d6..474ddb779643 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1044,16 +1044,8 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1044 return (0); 1044 return (0);
1045} 1045}
1046 1046
1047static struct v4l2_tvnorm tvnorms[] = { 1047static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *i)
1048 {
1049 .name = "NTSC-M",
1050 .id = V4L2_STD_NTSC_M,
1051 }
1052};
1053
1054static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id a)
1055{ 1048{
1056
1057 return 0; 1049 return 0;
1058} 1050}
1059 1051
@@ -1333,8 +1325,8 @@ static struct video_device vivi = {
1333#ifdef CONFIG_VIDEO_V4L1_COMPAT 1325#ifdef CONFIG_VIDEO_V4L1_COMPAT
1334 .vidiocgmbuf = vidiocgmbuf, 1326 .vidiocgmbuf = vidiocgmbuf,
1335#endif 1327#endif
1336 .tvnorms = tvnorms, 1328 .tvnorms = V4L2_STD_NTSC_M,
1337 .tvnormsize = ARRAY_SIZE(tvnorms), 1329 .current_norm = V4L2_STD_NTSC_M,
1338}; 1330};
1339/* ----------------------------------------------------------------- 1331/* -----------------------------------------------------------------
1340 Initialization and module stuff 1332 Initialization and module stuff
@@ -1361,8 +1353,6 @@ static int __init vivi_init(void)
1361 dev->vidq.timeout.data = (unsigned long)dev; 1353 dev->vidq.timeout.data = (unsigned long)dev;
1362 init_timer(&dev->vidq.timeout); 1354 init_timer(&dev->vidq.timeout);
1363 1355
1364 vivi.current_norm = tvnorms[0].id;
1365
1366 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr); 1356 ret = video_register_device(&vivi, VFL_TYPE_GRABBER, video_nr);
1367 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret); 1357 printk(KERN_INFO "Video Technology Magazine Virtual Video Capture Board (Load status: %d)\n", ret);
1368 return ret; 1358 return ret;
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 653822ce391c..4d1eb2fba34a 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -849,7 +849,7 @@ zoran_register_i2c (struct zoran *zr)
849static void 849static void
850zoran_unregister_i2c (struct zoran *zr) 850zoran_unregister_i2c (struct zoran *zr)
851{ 851{
852 i2c_bit_del_bus((&zr->i2c_adapter)); 852 i2c_del_adapter(&zr->i2c_adapter);
853} 853}
854 854
855/* Check a zoran_params struct for correctness, insert default params */ 855/* Check a zoran_params struct for correctness, insert default params */
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran_procfs.c
index c7f6f6488360..c374c76b3753 100644
--- a/drivers/media/video/zoran_procfs.c
+++ b/drivers/media/video/zoran_procfs.c
@@ -144,7 +144,7 @@ static int zoran_open(struct inode *inode, struct file *file)
144static ssize_t zoran_write(struct file *file, const char __user *buffer, 144static ssize_t zoran_write(struct file *file, const char __user *buffer,
145 size_t count, loff_t *ppos) 145 size_t count, loff_t *ppos)
146{ 146{
147 struct zoran *zr = PDE(file->f_dentry->d_inode)->data; 147 struct zoran *zr = PDE(file->f_path.dentry->d_inode)->data;
148 char *string, *sp; 148 char *string, *sp;
149 char *line, *ldelim, *varname, *svar, *tdelim; 149 char *line, *ldelim, *varname, *svar, *tdelim;
150 150
@@ -165,7 +165,7 @@ static ssize_t zoran_write(struct file *file, const char __user *buffer,
165 } 165 }
166 string[count] = 0; 166 string[count] = 0;
167 dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n", 167 dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n",
168 ZR_DEVNAME(zr), file->f_dentry->d_name.name, count, zr); 168 ZR_DEVNAME(zr), file->f_path.dentry->d_name.name, count, zr);
169 ldelim = " \t\n"; 169 ldelim = " \t\n";
170 tdelim = "="; 170 tdelim = "=";
171 line = strpbrk(sp, ldelim); 171 line = strpbrk(sp, ldelim);
diff --git a/drivers/media/video/zr36120.c b/drivers/media/video/zr36120.c
deleted file mode 100644
index 0cbf564388a6..000000000000
--- a/drivers/media/video/zr36120.c
+++ /dev/null
@@ -1,2079 +0,0 @@
1/*
2 zr36120.c - Zoran 36120/36125 based framegrabbers
3
4 Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/module.h>
22#include <linux/delay.h>
23#include <linux/init.h>
24#include <linux/errno.h>
25#include <linux/fs.h>
26#include <linux/kernel.h>
27#include <linux/major.h>
28#include <linux/slab.h>
29#include <linux/vmalloc.h>
30#include <linux/mm.h>
31#include <linux/pci.h>
32#include <linux/signal.h>
33#include <linux/wait.h>
34#include <asm/io.h>
35#include <asm/pgtable.h>
36#include <asm/page.h>
37#include <linux/sched.h>
38#include <linux/video_decoder.h>
39
40#include <asm/uaccess.h>
41
42#include "tuner.h"
43#include "zr36120.h"
44#include "zr36120_mem.h"
45
46/* mark an required function argument unused - lintism */
47#define UNUSED(x) (void)(x)
48
49/* sensible default */
50#ifndef CARDTYPE
51#define CARDTYPE 0
52#endif
53
54/* Anybody who uses more than four? */
55#define ZORAN_MAX 4
56
57static unsigned int triton1=0; /* triton1 chipset? */
58static unsigned int cardtype[ZORAN_MAX]={ [ 0 ... ZORAN_MAX-1 ] = CARDTYPE };
59static int video_nr = -1;
60static int vbi_nr = -1;
61
62static struct pci_device_id zr36120_pci_tbl[] = {
63 { PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120,
64 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
65 { 0 }
66};
67MODULE_DEVICE_TABLE(pci, zr36120_pci_tbl);
68
69MODULE_AUTHOR("Pauline Middelink <middelin@polyware.nl>");
70MODULE_DESCRIPTION("Zoran ZR36120 based framegrabber");
71MODULE_LICENSE("GPL");
72
73module_param(triton1, uint, 0);
74module_param_array(cardtype, uint, NULL, 0);
75module_param(video_nr, int, 0);
76module_param(vbi_nr, int, 0);
77
78static int zoran_cards;
79static struct zoran zorans[ZORAN_MAX];
80
81/*
82 * the meaning of each element can be found in zr36120.h
83 * Determining the value of gpdir/gpval can be tricky. The
84 * best way is to run the card under the original software
85 * and read the values from the general purpose registers
86 * 0x28 and 0x2C. How you do that is left as an exercise
87 * to the impatient reader :)
88 */
89#define T 1 /* to separate the bools from the ints */
90#define F 0
91static struct tvcard tvcards[] = {
92 /* reported working by <middelin@polyware.nl> */
93/*0*/ { "Trust Victor II",
94 2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },
95 /* reported working by <Michael.Paxton@aihw.gov.au> */
96/*1*/ { "Aitech WaveWatcher TV-PCI",
97 3, 0, T, F, T, T, 0x7F, 0x80, { 1, TUNER(3), SVHS(6) }, { 0 } },
98 /* reported working by ? */
99/*2*/ { "Genius Video Wonder PCI Video Capture Card",
100 2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },
101 /* reported working by <Pascal.Gabriel@wanadoo.fr> */
102/*3*/ { "Guillemot Maxi-TV PCI",
103 2, 0, T, T, T, T, 0x7F, 0x80, { 1, SVHS(6) }, { 0 } },
104 /* reported working by "Craig Whitmore <lennon@igrin.co.nz> */
105/*4*/ { "Quadrant Buster",
106 3, 3, T, F, T, T, 0x7F, 0x80, { SVHS(1), TUNER(2), 3 }, { 1, 2, 3 } },
107 /* a debug entry which has all inputs mapped */
108/*5*/ { "ZR36120 based framegrabber (all inputs enabled)",
109 6, 0, T, T, T, T, 0x7F, 0x80, { 1, 2, 3, 4, 5, 6 }, { 0 } }
110};
111#undef T
112#undef F
113#define NRTVCARDS (sizeof(tvcards)/sizeof(tvcards[0]))
114
115#ifdef __sparc__
116#define ENDIANESS 0
117#else
118#define ENDIANESS ZORAN_VFEC_LE
119#endif
120
121static struct { const char name[8]; uint mode; uint bpp; } palette2fmt[] = {
122/* n/a */ { "n/a", 0, 0 },
123/* GREY */ { "GRAY", 0, 0 },
124/* HI240 */ { "HI240", 0, 0 },
125/* RGB565 */ { "RGB565", ZORAN_VFEC_RGB_RGB565|ENDIANESS, 2 },
126/* RGB24 */ { "RGB24", ZORAN_VFEC_RGB_RGB888|ENDIANESS|ZORAN_VFEC_PACK24, 3 },
127/* RGB32 */ { "RGB32", ZORAN_VFEC_RGB_RGB888|ENDIANESS, 4 },
128/* RGB555 */ { "RGB555", ZORAN_VFEC_RGB_RGB555|ENDIANESS, 2 },
129/* YUV422 */ { "YUV422", ZORAN_VFEC_RGB_YUV422|ENDIANESS, 2 },
130/* YUYV */ { "YUYV", 0, 0 },
131/* UYVY */ { "UYVY", 0, 0 },
132/* YUV420 */ { "YUV420", 0, 0 },
133/* YUV411 */ { "YUV411", 0, 0 },
134/* RAW */ { "RAW", 0, 0 },
135/* YUV422P */ { "YUV422P", 0, 0 },
136/* YUV411P */ { "YUV411P", 0, 0 }};
137#define NRPALETTES (sizeof(palette2fmt)/sizeof(palette2fmt[0]))
138#undef ENDIANESS
139
140/* ----------------------------------------------------------------------- */
141/* ZORAN chipset detector */
142/* shamelessly stolen from bttv.c */
143/* Reason for beeing here: we need to detect if we are running on a */
144/* Triton based chipset, and if so, enable a certain bit */
145/* ----------------------------------------------------------------------- */
146static
147void __init handle_chipset(void)
148{
149 /* Just in case some nut set this to something dangerous */
150 if (triton1)
151 triton1 = ZORAN_VDC_TRICOM;
152
153 if (pci_pci_problems & PCIPCI_TRITON) {
154 printk(KERN_INFO "zoran: Host bridge 82437FX Triton PIIX\n");
155 triton1 = ZORAN_VDC_TRICOM;
156 }
157}
158
159/* ----------------------------------------------------------------------- */
160/* ZORAN functions */
161/* ----------------------------------------------------------------------- */
162
163static void zoran_set_geo(struct zoran* ztv, struct vidinfo* i);
164
165#if 0 /* unused */
166static
167void zoran_dump(struct zoran *ztv)
168{
169 char str[256];
170 char *p=str; /* shut up, gcc! */
171 int i;
172
173 for (i=0; i<0x60; i+=4) {
174 if ((i % 16) == 0) {
175 if (i) printk("%s\n",str);
176 p = str;
177 p+= sprintf(str, KERN_DEBUG " %04x: ",i);
178 }
179 p += sprintf(p, "%08x ",zrread(i));
180 }
181}
182#endif /* unused */
183
184static
185void reap_states(struct zoran* ztv)
186{
187 /* count frames */
188 ztv->fieldnr++;
189
190 /*
191 * Are we busy at all?
192 * This depends on if there is a workqueue AND the
193 * videotransfer is enabled on the chip...
194 */
195 if (ztv->workqueue && (zrread(ZORAN_VDC) & ZORAN_VDC_VIDEN))
196 {
197 struct vidinfo* newitem;
198
199 /* did we get a complete frame? */
200 if (zrread(ZORAN_VSTR) & ZORAN_VSTR_GRAB)
201 return;
202
203DEBUG(printk(CARD_DEBUG "completed %s at %p\n",CARD,ztv->workqueue->kindof==FBUFFER_GRAB?"grab":"read",ztv->workqueue));
204
205 /* we are done with this buffer, tell everyone */
206 ztv->workqueue->status = FBUFFER_DONE;
207 ztv->workqueue->fieldnr = ztv->fieldnr;
208 /* not good, here for BTTV_FIELDNR reasons */
209 ztv->lastfieldnr = ztv->fieldnr;
210
211 switch (ztv->workqueue->kindof) {
212 case FBUFFER_GRAB:
213 wake_up_interruptible(&ztv->grabq);
214 break;
215 case FBUFFER_VBI:
216 wake_up_interruptible(&ztv->vbiq);
217 break;
218 default:
219 printk(CARD_INFO "somebody killed the workqueue (kindof=%d)!\n",CARD,ztv->workqueue->kindof);
220 }
221
222 /* item completed, skip to next item in queue */
223 write_lock(&ztv->lock);
224 newitem = ztv->workqueue->next;
225 ztv->workqueue->next = 0; /* mark completed */
226 ztv->workqueue = newitem;
227 write_unlock(&ztv->lock);
228 }
229
230 /*
231 * ok, so it seems we have nothing in progress right now.
232 * Lets see if we can find some work.
233 */
234 if (ztv->workqueue)
235 {
236 struct vidinfo* newitem;
237again:
238
239DEBUG(printk(CARD_DEBUG "starting %s at %p\n",CARD,ztv->workqueue->kindof==FBUFFER_GRAB?"grab":"read",ztv->workqueue));
240
241 /* loadup the frame settings */
242 read_lock(&ztv->lock);
243 zoran_set_geo(ztv,ztv->workqueue);
244 read_unlock(&ztv->lock);
245
246 switch (ztv->workqueue->kindof) {
247 case FBUFFER_GRAB:
248 case FBUFFER_VBI:
249 zrand(~ZORAN_OCR_OVLEN, ZORAN_OCR);
250 zror(ZORAN_VSTR_SNAPSHOT,ZORAN_VSTR);
251 zror(ZORAN_VDC_VIDEN,ZORAN_VDC);
252
253 /* start single-shot grab */
254 zror(ZORAN_VSTR_GRAB, ZORAN_VSTR);
255 break;
256 default:
257 printk(CARD_INFO "what is this doing on the queue? (kindof=%d)\n",CARD,ztv->workqueue->kindof);
258 write_lock(&ztv->lock);
259 newitem = ztv->workqueue->next;
260 ztv->workqueue->next = 0;
261 ztv->workqueue = newitem;
262 write_unlock(&ztv->lock);
263 if (newitem)
264 goto again; /* yeah, sure.. */
265 }
266 /* bye for now */
267 return;
268 }
269DEBUG(printk(CARD_DEBUG "nothing in queue\n",CARD));
270
271 /*
272 * What? Even the workqueue is empty? Am i really here
273 * for nothing? Did i come all that way to... do nothing?
274 */
275
276 /* do we need to overlay? */
277 if (test_bit(STATE_OVERLAY, &ztv->state))
278 {
279 /* are we already overlaying? */
280 if (!(zrread(ZORAN_OCR) & ZORAN_OCR_OVLEN) ||
281 !(zrread(ZORAN_VDC) & ZORAN_VDC_VIDEN))
282 {
283DEBUG(printk(CARD_DEBUG "starting overlay\n",CARD));
284
285 read_lock(&ztv->lock);
286 zoran_set_geo(ztv,&ztv->overinfo);
287 read_unlock(&ztv->lock);
288
289 zror(ZORAN_OCR_OVLEN, ZORAN_OCR);
290 zrand(~ZORAN_VSTR_SNAPSHOT,ZORAN_VSTR);
291 zror(ZORAN_VDC_VIDEN,ZORAN_VDC);
292 }
293
294 /*
295 * leave overlaying on, but turn interrupts off.
296 */
297 zrand(~ZORAN_ICR_EN,ZORAN_ICR);
298 return;
299 }
300
301 /* do we have any VBI idle time processing? */
302 if (test_bit(STATE_VBI, &ztv->state))
303 {
304 struct vidinfo* item;
305 struct vidinfo* lastitem;
306
307 /* protect the workqueue */
308 write_lock(&ztv->lock);
309 lastitem = ztv->workqueue;
310 if (lastitem)
311 while (lastitem->next) lastitem = lastitem->next;
312 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)
313 if (item->next == 0 && item->status == FBUFFER_FREE)
314 {
315DEBUG(printk(CARD_DEBUG "%p added to queue\n",CARD,item));
316 item->status = FBUFFER_BUSY;
317 if (!lastitem)
318 ztv->workqueue = item;
319 else
320 lastitem->next = item;
321 lastitem = item;
322 }
323 write_unlock(&ztv->lock);
324 if (ztv->workqueue)
325 goto again; /* hey, _i_ graduated :) */
326 }
327
328 /*
329 * Then we must be realy IDLE
330 */
331DEBUG(printk(CARD_DEBUG "turning off\n",CARD));
332 /* nothing further to do, disable DMA and further IRQs */
333 zrand(~ZORAN_VDC_VIDEN,ZORAN_VDC);
334 zrand(~ZORAN_ICR_EN,ZORAN_ICR);
335}
336
337static
338void zoran_irq(int irq, void *dev_id)
339{
340 u32 stat,estat;
341 int count = 0;
342 struct zoran *ztv = dev_id;
343
344 UNUSED(irq);
345 for (;;) {
346 /* get/clear interrupt status bits */
347 stat=zrread(ZORAN_ISR);
348 estat=stat & zrread(ZORAN_ICR);
349 if (!estat)
350 return;
351 zrwrite(estat,ZORAN_ISR);
352 IDEBUG(printk(CARD_DEBUG "estat %08x\n",CARD,estat));
353 IDEBUG(printk(CARD_DEBUG " stat %08x\n",CARD,stat));
354
355 if (estat & ZORAN_ISR_CODE)
356 {
357 IDEBUG(printk(CARD_DEBUG "CodReplIRQ\n",CARD));
358 }
359 if (estat & ZORAN_ISR_GIRQ0)
360 {
361 IDEBUG(printk(CARD_DEBUG "GIRQ0\n",CARD));
362 if (!ztv->card->usegirq1)
363 reap_states(ztv);
364 }
365 if (estat & ZORAN_ISR_GIRQ1)
366 {
367 IDEBUG(printk(CARD_DEBUG "GIRQ1\n",CARD));
368 if (ztv->card->usegirq1)
369 reap_states(ztv);
370 }
371
372 count++;
373 if (count > 10)
374 printk(CARD_ERR "irq loop %d (%x)\n",CARD,count,estat);
375 if (count > 20)
376 {
377 zrwrite(0, ZORAN_ICR);
378 printk(CARD_ERR "IRQ lockup, cleared int mask\n",CARD);
379 }
380 }
381}
382
383static
384int zoran_muxsel(struct zoran* ztv, int channel, int norm)
385{
386 int rv;
387
388 /* set the new video norm */
389 rv = i2c_control_device(&(ztv->i2c), I2C_DRIVERID_VIDEODECODER, DECODER_SET_NORM, &norm);
390 if (rv)
391 return rv;
392 ztv->norm = norm;
393
394 /* map the given channel to the cards decoder's channel */
395 channel = ztv->card->video_mux[channel] & CHANNEL_MASK;
396
397 /* set the new channel */
398 rv = i2c_control_device(&(ztv->i2c), I2C_DRIVERID_VIDEODECODER, DECODER_SET_INPUT, &channel);
399 return rv;
400}
401
402/* Tell the interrupt handler what to to. */
403static
404void zoran_cap(struct zoran* ztv, int on)
405{
406DEBUG(printk(CARD_DEBUG "zoran_cap(%d) state=%x\n",CARD,on,ztv->state));
407
408 if (on) {
409 ztv->running = 1;
410
411 /*
412 * turn interrupts (back) on. The DMA will be enabled
413 * inside the irq handler when it detects a restart.
414 */
415 zror(ZORAN_ICR_EN,ZORAN_ICR);
416 }
417 else {
418 /*
419 * turn both interrupts and DMA off
420 */
421 zrand(~ZORAN_VDC_VIDEN,ZORAN_VDC);
422 zrand(~ZORAN_ICR_EN,ZORAN_ICR);
423
424 ztv->running = 0;
425 }
426}
427
428static ulong dmask[] = {
429 0xFFFFFFFF, 0xFFFFFFFE, 0xFFFFFFFC, 0xFFFFFFF8,
430 0xFFFFFFF0, 0xFFFFFFE0, 0xFFFFFFC0, 0xFFFFFF80,
431 0xFFFFFF00, 0xFFFFFE00, 0xFFFFFC00, 0xFFFFF800,
432 0xFFFFF000, 0xFFFFE000, 0xFFFFC000, 0xFFFF8000,
433 0xFFFF0000, 0xFFFE0000, 0xFFFC0000, 0xFFF80000,
434 0xFFF00000, 0xFFE00000, 0xFFC00000, 0xFF800000,
435 0xFF000000, 0xFE000000, 0xFC000000, 0xF8000000,
436 0xF0000000, 0xE0000000, 0xC0000000, 0x80000000
437};
438
439static
440void zoran_built_overlay(struct zoran* ztv, int count, struct video_clip *vcp)
441{
442 ulong* mtop;
443 int ystep = (ztv->vidXshift + ztv->vidWidth+31)/32; /* next DWORD */
444 int i;
445
446DEBUG(printk(KERN_DEBUG " overlay at %p, ystep=%d, clips=%d\n",ztv->overinfo.overlay,ystep,count));
447
448 for (i=0; i<count; i++) {
449 struct video_clip *vp = vcp+i;
450 UNUSED(vp);
451DEBUG(printk(KERN_DEBUG " %d: clip(%d,%d,%d,%d)\n", i,vp->x,vp->y,vp->width,vp->height));
452 }
453
454 /*
455 * activate the visible portion of the screen
456 * Note we take some shortcuts here, because we
457 * know the width can never be < 32. (I.e. a DWORD)
458 * We also assume the overlay starts somewhere in
459 * the FIRST dword.
460 */
461 {
462 int start = ztv->vidXshift;
463 ulong firstd = dmask[start];
464 ulong lastd = ~dmask[(start + ztv->overinfo.w) & 31];
465 mtop = ztv->overinfo.overlay;
466 for (i=0; i<ztv->overinfo.h; i++) {
467 int w = ztv->vidWidth;
468 ulong* line = mtop;
469 if (start & 31) {
470 *line++ = firstd;
471 w -= 32-(start&31);
472 }
473 memset(line, ~0, w/8);
474 if (w & 31)
475 line[w/32] = lastd;
476 mtop += ystep;
477 }
478 }
479
480 /* process clipping regions */
481 for (i=0; i<count; i++) {
482 int h;
483 if (vcp->x < 0 || (uint)vcp->x > ztv->overinfo.w ||
484 vcp->y < 0 || vcp->y > ztv->overinfo.h ||
485 vcp->width < 0 || (uint)(vcp->x+vcp->width) > ztv->overinfo.w ||
486 vcp->height < 0 || (vcp->y+vcp->height) > ztv->overinfo.h)
487 {
488 DEBUG(printk(CARD_DEBUG "invalid clipzone (%d,%d,%d,%d) not in (0,0,%d,%d), adapting\n",CARD,vcp->x,vcp->y,vcp->width,vcp->height,ztv->overinfo.w,ztv->overinfo.h));
489 if (vcp->x < 0) vcp->x = 0;
490 if ((uint)vcp->x > ztv->overinfo.w) vcp->x = ztv->overinfo.w;
491 if (vcp->y < 0) vcp->y = 0;
492 if (vcp->y > ztv->overinfo.h) vcp->y = ztv->overinfo.h;
493 if (vcp->width < 0) vcp->width = 0;
494 if ((uint)(vcp->x+vcp->width) > ztv->overinfo.w) vcp->width = ztv->overinfo.w - vcp->x;
495 if (vcp->height < 0) vcp->height = 0;
496 if (vcp->y+vcp->height > ztv->overinfo.h) vcp->height = ztv->overinfo.h - vcp->y;
497// continue;
498 }
499
500 mtop = &ztv->overinfo.overlay[vcp->y*ystep];
501 for (h=0; h<=vcp->height; h++) {
502 int w;
503 int x = ztv->vidXshift + vcp->x;
504 for (w=0; w<=vcp->width; w++) {
505 clear_bit(x&31, &mtop[x/32]);
506 x++;
507 }
508 mtop += ystep;
509 }
510 ++vcp;
511 }
512
513 mtop = ztv->overinfo.overlay;
514 zrwrite(virt_to_bus(mtop), ZORAN_MTOP);
515 zrwrite(virt_to_bus(mtop+ystep), ZORAN_MBOT);
516 zraor((ztv->vidInterlace*ystep)<<0,~ZORAN_OCR_MASKSTRIDE,ZORAN_OCR);
517}
518
519struct tvnorm
520{
521 u16 Wt, Wa, Ht, Ha, HStart, VStart;
522};
523
524static struct tvnorm tvnorms[] = {
525 /* PAL-BDGHI */
526/* { 864, 720, 625, 576, 131, 21 },*/
527/*00*/ { 864, 768, 625, 576, 81, 17 },
528 /* NTSC */
529/*01*/ { 858, 720, 525, 480, 121, 10 },
530 /* SECAM */
531/*02*/ { 864, 720, 625, 576, 131, 21 },
532 /* BW50 */
533/*03*/ { 864, 720, 625, 576, 131, 21 },
534 /* BW60 */
535/*04*/ { 858, 720, 525, 480, 121, 10 }
536};
537#define TVNORMS (sizeof(tvnorms)/sizeof(tvnorm))
538
539/*
540 * Program the chip for a setup as described in the vidinfo struct.
541 *
542 * Side-effects: calculates vidXshift, vidInterlace,
543 * vidHeight, vidWidth which are used in a later stage
544 * to calculate the overlay mask
545 *
546 * This is an internal function, as such it does not check the
547 * validity of the struct members... Spectaculair crashes will
548 * follow /very/ quick when you're wrong and the chip right :)
549 */
550static
551void zoran_set_geo(struct zoran* ztv, struct vidinfo* i)
552{
553 ulong top, bot;
554 int stride;
555 int winWidth, winHeight;
556 int maxWidth, maxHeight, maxXOffset, maxYOffset;
557 long vfec;
558
559DEBUG(printk(CARD_DEBUG "set_geo(rect=(%d,%d,%d,%d), norm=%d, format=%d, bpp=%d, bpl=%d, busadr=%lx, overlay=%p)\n",CARD,i->x,i->y,i->w,i->h,ztv->norm,i->format,i->bpp,i->bpl,i->busadr,i->overlay));
560
561 /*
562 * make sure the DMA transfers are inhibited during our
563 * reprogramming of the chip
564 */
565 zrand(~ZORAN_VDC_VIDEN,ZORAN_VDC);
566
567 maxWidth = tvnorms[ztv->norm].Wa;
568 maxHeight = tvnorms[ztv->norm].Ha/2;
569 maxXOffset = tvnorms[ztv->norm].HStart;
570 maxYOffset = tvnorms[ztv->norm].VStart;
571
572 /* setup vfec register (keep ExtFl,TopField and VCLKPol settings) */
573 vfec = (zrread(ZORAN_VFEC) & (ZORAN_VFEC_EXTFL|ZORAN_VFEC_TOPFIELD|ZORAN_VFEC_VCLKPOL)) |
574 (palette2fmt[i->format].mode & (ZORAN_VFEC_RGB|ZORAN_VFEC_ERRDIF|ZORAN_VFEC_LE|ZORAN_VFEC_PACK24));
575
576 /*
577 * Set top, bottom ptrs. Since these must be DWORD aligned,
578 * possible adjust the x and the width of the window.
579 * so the endposition stay the same. The vidXshift will make
580 * sure we are not writing pixels before the requested x.
581 */
582 ztv->vidXshift = 0;
583 winWidth = i->w;
584 if (winWidth < 0)
585 winWidth = -winWidth;
586 top = i->busadr + i->x*i->bpp + i->y*i->bpl;
587 if (top & 3) {
588 ztv->vidXshift = (top & 3) / i->bpp;
589 winWidth += ztv->vidXshift;
590 DEBUG(printk(KERN_DEBUG " window-x shifted %d pixels left\n",ztv->vidXshift));
591 top &= ~3;
592 }
593
594 /*
595 * bottom points to next frame but in interleaved mode we want
596 * to 'mix' the 2 frames to one capture, so 'bot' points to one
597 * (physical) line below the top line.
598 */
599 bot = top + i->bpl;
600 zrwrite(top,ZORAN_VTOP);
601 zrwrite(bot,ZORAN_VBOT);
602
603 /*
604 * Make sure the winWidth is DWORD aligned too,
605 * thereby automaticly making sure the stride to the
606 * next line is DWORD aligned too (as required by spec).
607 */
608 if ((winWidth*i->bpp) & 3) {
609DEBUG(printk(KERN_DEBUG " window-width enlarged by %d pixels\n",(winWidth*i->bpp) & 3));
610 winWidth += (winWidth*i->bpp) & 3;
611 }
612
613 /* determine the DispMode and stride */
614 if (i->h >= 0 && i->h <= maxHeight) {
615 /* single frame grab suffices for this height. */
616 vfec |= ZORAN_VFEC_DISPMOD;
617 ztv->vidInterlace = 0;
618 stride = i->bpl - (winWidth*i->bpp);
619 winHeight = i->h;
620 }
621 else {
622 /* interleaving needed for this height */
623 ztv->vidInterlace = 1;
624 stride = i->bpl*2 - (winWidth*i->bpp);
625 winHeight = i->h/2;
626 }
627 if (winHeight < 0) /* can happen for VBI! */
628 winHeight = -winHeight;
629
630 /* safety net, sometimes bpl is too short??? */
631 if (stride<0) {
632DEBUG(printk(CARD_DEBUG "WARNING stride = %d\n",CARD,stride));
633 stride = 0;
634 }
635
636 zraor((winHeight<<12)|(winWidth<<0),~(ZORAN_VDC_VIDWINHT|ZORAN_VDC_VIDWINWID), ZORAN_VDC);
637 zraor(stride<<16,~ZORAN_VSTR_DISPSTRIDE,ZORAN_VSTR);
638
639 /* remember vidWidth, vidHeight for overlay calculations */
640 ztv->vidWidth = winWidth;
641 ztv->vidHeight = winHeight;
642DEBUG(printk(KERN_DEBUG " top=%08lx, bottom=%08lx\n",top,bot));
643DEBUG(printk(KERN_DEBUG " winWidth=%d, winHeight=%d\n",winWidth,winHeight));
644DEBUG(printk(KERN_DEBUG " maxWidth=%d, maxHeight=%d\n",maxWidth,maxHeight));
645DEBUG(printk(KERN_DEBUG " stride=%d\n",stride));
646
647 /*
648 * determine horizontal scales and crops
649 */
650 if (i->w < 0) {
651 int Hstart = 1;
652 int Hend = Hstart + winWidth;
653DEBUG(printk(KERN_DEBUG " Y: scale=0, start=%d, end=%d\n", Hstart, Hend));
654 zraor((Hstart<<10)|(Hend<<0),~(ZORAN_VFEH_HSTART|ZORAN_VFEH_HEND),ZORAN_VFEH);
655 }
656 else {
657 int Wa = maxWidth;
658 int X = (winWidth*64+Wa-1)/Wa;
659 int We = winWidth*64/X;
660 int HorDcm = 64-X;
661 int hcrop1 = 2*(Wa-We)/4;
662 /*
663 * BUGFIX: Juha Nurmela <junki@qn-lpr2-165.quicknet.inet.fi>
664 * found the solution to the color phase shift.
665 * See ChangeLog for the full explanation)
666 */
667 int Hstart = (maxXOffset + hcrop1) | 1;
668 int Hend = Hstart + We - 1;
669
670DEBUG(printk(KERN_DEBUG " X: scale=%d, start=%d, end=%d\n", HorDcm, Hstart, Hend));
671
672 zraor((Hstart<<10)|(Hend<<0),~(ZORAN_VFEH_HSTART|ZORAN_VFEH_HEND),ZORAN_VFEH);
673 vfec |= HorDcm<<14;
674
675 if (HorDcm<16)
676 vfec |= ZORAN_VFEC_HFILTER_1; /* no filter */
677 else if (HorDcm<32)
678 vfec |= ZORAN_VFEC_HFILTER_3; /* 3 tap filter */
679 else if (HorDcm<48)
680 vfec |= ZORAN_VFEC_HFILTER_4; /* 4 tap filter */
681 else vfec |= ZORAN_VFEC_HFILTER_5; /* 5 tap filter */
682 }
683
684 /*
685 * Determine vertical scales and crops
686 *
687 * when height is negative, we want to read starting at line 0
688 * One day someone might need access to these lines...
689 */
690 if (i->h < 0) {
691 int Vstart = 0;
692 int Vend = Vstart + winHeight;
693DEBUG(printk(KERN_DEBUG " Y: scale=0, start=%d, end=%d\n", Vstart, Vend));
694 zraor((Vstart<<10)|(Vend<<0),~(ZORAN_VFEV_VSTART|ZORAN_VFEV_VEND),ZORAN_VFEV);
695 }
696 else {
697 int Ha = maxHeight;
698 int Y = (winHeight*64+Ha-1)/Ha;
699 int He = winHeight*64/Y;
700 int VerDcm = 64-Y;
701 int vcrop1 = 2*(Ha-He)/4;
702 int Vstart = maxYOffset + vcrop1;
703 int Vend = Vstart + He - 1;
704
705DEBUG(printk(KERN_DEBUG " Y: scale=%d, start=%d, end=%d\n", VerDcm, Vstart, Vend));
706 zraor((Vstart<<10)|(Vend<<0),~(ZORAN_VFEV_VSTART|ZORAN_VFEV_VEND),ZORAN_VFEV);
707 vfec |= VerDcm<<8;
708 }
709
710DEBUG(printk(KERN_DEBUG " F: format=%d(=%s)\n",i->format,palette2fmt[i->format].name));
711
712 /* setup the requested format */
713 zrwrite(vfec, ZORAN_VFEC);
714}
715
716static
717void zoran_common_open(struct zoran* ztv, int flags)
718{
719 UNUSED(flags);
720
721 /* already opened? */
722 if (ztv->users++ != 0)
723 return;
724
725 /* unmute audio */
726 /* /what/ audio? */
727
728 ztv->state = 0;
729
730 /* setup the encoder to the initial values */
731 ztv->picture.colour=254<<7;
732 ztv->picture.brightness=128<<8;
733 ztv->picture.hue=128<<8;
734 ztv->picture.contrast=216<<7;
735 i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_SET_PICTURE, &ztv->picture);
736
737 /* default to the composite input since my camera is there */
738 zoran_muxsel(ztv, 0, VIDEO_MODE_PAL);
739}
740
741static
742void zoran_common_close(struct zoran* ztv)
743{
744 if (--ztv->users != 0)
745 return;
746
747 /* mute audio */
748 /* /what/ audio? */
749
750 /* stop the chip */
751 zoran_cap(ztv, 0);
752}
753
754/*
755 * Open a zoran card. Right now the flags are just a hack
756 */
757static int zoran_open(struct video_device *dev, int flags)
758{
759 struct zoran *ztv = (struct zoran*)dev;
760 struct vidinfo* item;
761 char* pos;
762
763 DEBUG(printk(CARD_DEBUG "open(dev,%d)\n",CARD,flags));
764
765 /*********************************************
766 * We really should be doing lazy allocing...
767 *********************************************/
768 /* allocate a frame buffer */
769 if (!ztv->fbuffer)
770 ztv->fbuffer = bmalloc(ZORAN_MAX_FBUFSIZE);
771 if (!ztv->fbuffer) {
772 /* could not get a buffer, bail out */
773 return -ENOBUFS;
774 }
775 /* at this time we _always_ have a framebuffer */
776 memset(ztv->fbuffer,0,ZORAN_MAX_FBUFSIZE);
777
778 if (!ztv->overinfo.overlay)
779 ztv->overinfo.overlay = kmalloc(1024*1024/8, GFP_KERNEL);
780 if (!ztv->overinfo.overlay) {
781 /* could not get an overlay buffer, bail out */
782 bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE);
783 return -ENOBUFS;
784 }
785 /* at this time we _always_ have a overlay */
786
787 /* clear buffer status, and give them a DMAable address */
788 pos = ztv->fbuffer;
789 for (item=ztv->grabinfo; item!=ztv->grabinfo+ZORAN_MAX_FBUFFERS; item++)
790 {
791 item->status = FBUFFER_FREE;
792 item->memadr = pos;
793 item->busadr = virt_to_bus(pos);
794 pos += ZORAN_MAX_FBUFFER;
795 }
796
797 /* do the common part of all open's */
798 zoran_common_open(ztv, flags);
799
800 return 0;
801}
802
803static
804void zoran_close(struct video_device* dev)
805{
806 struct zoran *ztv = (struct zoran*)dev;
807
808 DEBUG(printk(CARD_DEBUG "close(dev)\n",CARD));
809
810 /* driver specific closure */
811 clear_bit(STATE_OVERLAY, &ztv->state);
812
813 zoran_common_close(ztv);
814
815 /*
816 * This is sucky but right now I can't find a good way to
817 * be sure its safe to free the buffer. We wait 5-6 fields
818 * which is more than sufficient to be sure.
819 */
820 msleep(100); /* Wait 1/10th of a second */
821
822 /* free the allocated framebuffer */
823 bfree(ztv->fbuffer, ZORAN_MAX_FBUFSIZE);
824 ztv->fbuffer = 0;
825 kfree(ztv->overinfo.overlay);
826 ztv->overinfo.overlay = 0;
827
828}
829
830/*
831 * This read function could be used reentrant in a SMP situation.
832 *
833 * This is made possible by the spinlock which is kept till we
834 * found and marked a buffer for our own use. The lock must
835 * be released as soon as possible to prevent lock contention.
836 */
837static
838long zoran_read(struct video_device* dev, char* buf, unsigned long count, int nonblock)
839{
840 struct zoran *ztv = (struct zoran*)dev;
841 unsigned long max;
842 struct vidinfo* unused = 0;
843 struct vidinfo* done = 0;
844
845 DEBUG(printk(CARD_DEBUG "zoran_read(%p,%ld,%d)\n",CARD,buf,count,nonblock));
846
847 /* find ourself a free or completed buffer */
848 for (;;) {
849 struct vidinfo* item;
850
851 write_lock_irq(&ztv->lock);
852 for (item=ztv->grabinfo; item!=ztv->grabinfo+ZORAN_MAX_FBUFFERS; item++)
853 {
854 if (!unused && item->status == FBUFFER_FREE)
855 unused = item;
856 if (!done && item->status == FBUFFER_DONE)
857 done = item;
858 }
859 if (done || unused)
860 break;
861
862 /* no more free buffers, wait for them. */
863 write_unlock_irq(&ztv->lock);
864 if (nonblock)
865 return -EWOULDBLOCK;
866 interruptible_sleep_on(&ztv->grabq);
867 if (signal_pending(current))
868 return -EINTR;
869 }
870
871 /* Do we have 'ready' data? */
872 if (!done) {
873 /* no? than this will take a while... */
874 if (nonblock) {
875 write_unlock_irq(&ztv->lock);
876 return -EWOULDBLOCK;
877 }
878
879 /* mark the unused buffer as wanted */
880 unused->status = FBUFFER_BUSY;
881 unused->w = 320;
882 unused->h = 240;
883 unused->format = VIDEO_PALETTE_RGB24;
884 unused->bpp = palette2fmt[unused->format].bpp;
885 unused->bpl = unused->w * unused->bpp;
886 unused->next = 0;
887 { /* add to tail of queue */
888 struct vidinfo* oldframe = ztv->workqueue;
889 if (!oldframe) ztv->workqueue = unused;
890 else {
891 while (oldframe->next) oldframe = oldframe->next;
892 oldframe->next = unused;
893 }
894 }
895 write_unlock_irq(&ztv->lock);
896
897 /* tell the state machine we want it filled /NOW/ */
898 zoran_cap(ztv, 1);
899
900 /* wait till this buffer gets grabbed */
901 wait_event_interruptible(ztv->grabq,
902 (unused->status != FBUFFER_BUSY));
903 /* see if a signal did it */
904 if (signal_pending(current))
905 return -EINTR;
906 done = unused;
907 }
908 else
909 write_unlock_irq(&ztv->lock);
910
911 /* Yes! we got data! */
912 max = done->bpl * done->h;
913 if (count > max)
914 count = max;
915 if (copy_to_user((void*)buf, done->memadr, count))
916 count = -EFAULT;
917
918 /* keep the engine running */
919 done->status = FBUFFER_FREE;
920// zoran_cap(ztv,1);
921
922 /* tell listeners this buffer became free */
923 wake_up_interruptible(&ztv->grabq);
924
925 /* goodbye */
926 DEBUG(printk(CARD_DEBUG "zoran_read() returns %lu\n",CARD,count));
927 return count;
928}
929
930static
931long zoran_write(struct video_device* dev, const char* buf, unsigned long count, int nonblock)
932{
933 struct zoran *ztv = (struct zoran *)dev;
934 UNUSED(ztv); UNUSED(dev); UNUSED(buf); UNUSED(count); UNUSED(nonblock);
935 DEBUG(printk(CARD_DEBUG "zoran_write\n",CARD));
936 return -EINVAL;
937}
938
939static
940unsigned int zoran_poll(struct video_device *dev, struct file *file, poll_table *wait)
941{
942 struct zoran *ztv = (struct zoran *)dev;
943 struct vidinfo* item;
944 unsigned int mask = 0;
945
946 poll_wait(file, &ztv->grabq, wait);
947
948 for (item=ztv->grabinfo; item!=ztv->grabinfo+ZORAN_MAX_FBUFFERS; item++)
949 if (item->status == FBUFFER_DONE)
950 {
951 mask |= (POLLIN | POLLRDNORM);
952 break;
953 }
954
955 DEBUG(printk(CARD_DEBUG "zoran_poll()=%x\n",CARD,mask));
956
957 return mask;
958}
959
960/* append a new clipregion to the vector of video_clips */
961static
962void new_clip(struct video_window* vw, struct video_clip* vcp, int x, int y, int w, int h)
963{
964 vcp[vw->clipcount].x = x;
965 vcp[vw->clipcount].y = y;
966 vcp[vw->clipcount].width = w;
967 vcp[vw->clipcount].height = h;
968 vw->clipcount++;
969}
970
971static
972int zoran_ioctl(struct video_device* dev, unsigned int cmd, void *arg)
973{
974 struct zoran* ztv = (struct zoran*)dev;
975
976 switch (cmd) {
977 case VIDIOCGCAP:
978 {
979 struct video_capability c;
980 DEBUG(printk(CARD_DEBUG "VIDIOCGCAP\n",CARD));
981
982 strcpy(c.name,ztv->video_dev.name);
983 c.type = VID_TYPE_CAPTURE|
984 VID_TYPE_OVERLAY|
985 VID_TYPE_CLIPPING|
986 VID_TYPE_FRAMERAM|
987 VID_TYPE_SCALES;
988 if (ztv->have_tuner)
989 c.type |= VID_TYPE_TUNER;
990 if (pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL))
991 c.type &= ~VID_TYPE_OVERLAY;
992 if (ztv->have_decoder) {
993 c.channels = ztv->card->video_inputs;
994 c.audios = ztv->card->audio_inputs;
995 } else
996 /* no decoder -> no channels */
997 c.channels = c.audios = 0;
998 c.maxwidth = 768;
999 c.maxheight = 576;
1000 c.minwidth = 32;
1001 c.minheight = 32;
1002 if (copy_to_user(arg,&c,sizeof(c)))
1003 return -EFAULT;
1004 break;
1005 }
1006
1007 case VIDIOCGCHAN:
1008 {
1009 struct video_channel v;
1010 int mux;
1011 if (copy_from_user(&v, arg,sizeof(v)))
1012 return -EFAULT;
1013 DEBUG(printk(CARD_DEBUG "VIDIOCGCHAN(%d)\n",CARD,v.channel));
1014 v.flags=VIDEO_VC_AUDIO
1015#ifdef VIDEO_VC_NORM
1016 |VIDEO_VC_NORM
1017#endif
1018 ;
1019 v.tuners=0;
1020 v.type=VIDEO_TYPE_CAMERA;
1021#ifdef I_EXPECT_POSSIBLE_NORMS_IN_THE_API
1022 v.norm=VIDEO_MODE_PAL|
1023 VIDEO_MODE_NTSC|
1024 VIDEO_MODE_SECAM;
1025#else
1026 v.norm=VIDEO_MODE_PAL;
1027#endif
1028 /* too many inputs? no decoder -> no channels */
1029 if (!ztv->have_decoder || v.channel < 0 || v.channel >= ztv->card->video_inputs)
1030 return -EINVAL;
1031
1032 /* now determine the name of the channel */
1033 mux = ztv->card->video_mux[v.channel];
1034 if (mux & IS_TUNER) {
1035 /* lets assume only one tuner, yes? */
1036 strcpy(v.name,"Television");
1037 v.type = VIDEO_TYPE_TV;
1038 if (ztv->have_tuner) {
1039 v.flags |= VIDEO_VC_TUNER;
1040 v.tuners = 1;
1041 }
1042 }
1043 else if (mux & IS_SVHS)
1044 sprintf(v.name,"S-Video-%d",v.channel);
1045 else
1046 sprintf(v.name,"CVBS-%d",v.channel);
1047
1048 if (copy_to_user(arg,&v,sizeof(v)))
1049 return -EFAULT;
1050 break;
1051 }
1052 case VIDIOCSCHAN:
1053 { /* set video channel */
1054 struct video_channel v;
1055 if (copy_from_user(&v, arg,sizeof(v)))
1056 return -EFAULT;
1057 DEBUG(printk(CARD_DEBUG "VIDIOCSCHAN(%d,%d)\n",CARD,v.channel,v.norm));
1058
1059 /* too many inputs? no decoder -> no channels */
1060 if (!ztv->have_decoder || v.channel >= ztv->card->video_inputs || v.channel < 0)
1061 return -EINVAL;
1062
1063 if (v.norm != VIDEO_MODE_PAL &&
1064 v.norm != VIDEO_MODE_NTSC &&
1065 v.norm != VIDEO_MODE_SECAM &&
1066 v.norm != VIDEO_MODE_AUTO)
1067 return -EOPNOTSUPP;
1068
1069 /* make it happen, nr1! */
1070 return zoran_muxsel(ztv,v.channel,v.norm);
1071 }
1072
1073 case VIDIOCGTUNER:
1074 {
1075 struct video_tuner v;
1076 if (copy_from_user(&v, arg,sizeof(v)))
1077 return -EFAULT;
1078 DEBUG(printk(CARD_DEBUG "VIDIOCGTUNER(%d)\n",CARD,v.tuner));
1079
1080 /* Only no or one tuner for now */
1081 if (!ztv->have_tuner || v.tuner)
1082 return -EINVAL;
1083
1084 strcpy(v.name,"Television");
1085 v.rangelow = 0;
1086 v.rangehigh = ~0;
1087 v.flags = VIDEO_TUNER_PAL|VIDEO_TUNER_NTSC|VIDEO_TUNER_SECAM;
1088 v.mode = ztv->norm;
1089 v.signal = 0xFFFF; /* unknown */
1090
1091 if (copy_to_user(arg,&v,sizeof(v)))
1092 return -EFAULT;
1093 break;
1094 }
1095 case VIDIOCSTUNER:
1096 {
1097 struct video_tuner v;
1098 if (copy_from_user(&v, arg, sizeof(v)))
1099 return -EFAULT;
1100 DEBUG(printk(CARD_DEBUG "VIDIOCSTUNER(%d,%d)\n",CARD,v.tuner,v.mode));
1101
1102 /* Only no or one tuner for now */
1103 if (!ztv->have_tuner || v.tuner)
1104 return -EINVAL;
1105
1106 /* and it only has certain valid modes */
1107 if( v.mode != VIDEO_MODE_PAL &&
1108 v.mode != VIDEO_MODE_NTSC &&
1109 v.mode != VIDEO_MODE_SECAM)
1110 return -EOPNOTSUPP;
1111
1112 /* engage! */
1113 return zoran_muxsel(ztv,v.tuner,v.mode);
1114 }
1115
1116 case VIDIOCGPICT:
1117 {
1118 struct video_picture p = ztv->picture;
1119 DEBUG(printk(CARD_DEBUG "VIDIOCGPICT\n",CARD));
1120 p.depth = ztv->depth;
1121 switch (p.depth) {
1122 case 8: p.palette=VIDEO_PALETTE_YUV422;
1123 break;
1124 case 15: p.palette=VIDEO_PALETTE_RGB555;
1125 break;
1126 case 16: p.palette=VIDEO_PALETTE_RGB565;
1127 break;
1128 case 24: p.palette=VIDEO_PALETTE_RGB24;
1129 break;
1130 case 32: p.palette=VIDEO_PALETTE_RGB32;
1131 break;
1132 }
1133 if (copy_to_user(arg, &p, sizeof(p)))
1134 return -EFAULT;
1135 break;
1136 }
1137 case VIDIOCSPICT:
1138 {
1139 struct video_picture p;
1140 if (copy_from_user(&p, arg,sizeof(p)))
1141 return -EFAULT;
1142 DEBUG(printk(CARD_DEBUG "VIDIOCSPICT(%d,%d,%d,%d,%d,%d,%d)\n",CARD,p.brightness,p.hue,p.colour,p.contrast,p.whiteness,p.depth,p.palette));
1143
1144 /* depth must match with framebuffer */
1145 if (p.depth != ztv->depth)
1146 return -EINVAL;
1147
1148 /* check if palette matches this bpp */
1149 if (p.palette>NRPALETTES ||
1150 palette2fmt[p.palette].bpp != ztv->overinfo.bpp)
1151 return -EINVAL;
1152
1153 write_lock_irq(&ztv->lock);
1154 ztv->overinfo.format = p.palette;
1155 ztv->picture = p;
1156 write_unlock_irq(&ztv->lock);
1157
1158 /* tell the decoder */
1159 i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_SET_PICTURE, &p);
1160 break;
1161 }
1162
1163 case VIDIOCGWIN:
1164 {
1165 struct video_window vw;
1166 DEBUG(printk(CARD_DEBUG "VIDIOCGWIN\n",CARD));
1167 read_lock(&ztv->lock);
1168 vw.x = ztv->overinfo.x;
1169 vw.y = ztv->overinfo.y;
1170 vw.width = ztv->overinfo.w;
1171 vw.height = ztv->overinfo.h;
1172 vw.chromakey= 0;
1173 vw.flags = 0;
1174 if (ztv->vidInterlace)
1175 vw.flags|=VIDEO_WINDOW_INTERLACE;
1176 read_unlock(&ztv->lock);
1177 if (copy_to_user(arg,&vw,sizeof(vw)))
1178 return -EFAULT;
1179 break;
1180 }
1181 case VIDIOCSWIN:
1182 {
1183 struct video_window vw;
1184 struct video_clip *vcp;
1185 int on;
1186 if (copy_from_user(&vw,arg,sizeof(vw)))
1187 return -EFAULT;
1188 DEBUG(printk(CARD_DEBUG "VIDIOCSWIN(%d,%d,%d,%d,%x,%d)\n",CARD,vw.x,vw.y,vw.width,vw.height,vw.flags,vw.clipcount));
1189
1190 if (vw.flags)
1191 return -EINVAL;
1192
1193 if (vw.clipcount <0 || vw.clipcount>256)
1194 return -EDOM; /* Too many! */
1195
1196 /*
1197 * Do any clips.
1198 */
1199 vcp = vmalloc(sizeof(struct video_clip)*(vw.clipcount+4));
1200 if (vcp==NULL)
1201 return -ENOMEM;
1202 if (vw.clipcount && copy_from_user(vcp,vw.clips,sizeof(struct video_clip)*vw.clipcount)) {
1203 vfree(vcp);
1204 return -EFAULT;
1205 }
1206
1207 on = ztv->running;
1208 if (on)
1209 zoran_cap(ztv, 0);
1210
1211 /*
1212 * strange, it seems xawtv sometimes calls us with 0
1213 * width and/or height. Ignore these values
1214 */
1215 if (vw.x == 0)
1216 vw.x = ztv->overinfo.x;
1217 if (vw.y == 0)
1218 vw.y = ztv->overinfo.y;
1219
1220 /* by now we are committed to the new data... */
1221 write_lock_irq(&ztv->lock);
1222 ztv->overinfo.x = vw.x;
1223 ztv->overinfo.y = vw.y;
1224 ztv->overinfo.w = vw.width;
1225 ztv->overinfo.h = vw.height;
1226 write_unlock_irq(&ztv->lock);
1227
1228 /*
1229 * Impose display clips
1230 */
1231 if (vw.x+vw.width > ztv->swidth)
1232 new_clip(&vw, vcp, ztv->swidth-vw.x, 0, vw.width-1, vw.height-1);
1233 if (vw.y+vw.height > ztv->sheight)
1234 new_clip(&vw, vcp, 0, ztv->sheight-vw.y, vw.width-1, vw.height-1);
1235
1236 /* built the requested clipping zones */
1237 zoran_set_geo(ztv, &ztv->overinfo);
1238 zoran_built_overlay(ztv, vw.clipcount, vcp);
1239 vfree(vcp);
1240
1241 /* if we were on, restart the video engine */
1242 if (on)
1243 zoran_cap(ztv, 1);
1244 break;
1245 }
1246
1247 case VIDIOCCAPTURE:
1248 {
1249 int v;
1250 if (get_user(v, (int *)arg))
1251 return -EFAULT;
1252 DEBUG(printk(CARD_DEBUG "VIDIOCCAPTURE(%d)\n",CARD,v));
1253
1254 if (v==0) {
1255 clear_bit(STATE_OVERLAY, &ztv->state);
1256 zoran_cap(ztv, 1);
1257 }
1258 else {
1259 /* is VIDIOCSFBUF, VIDIOCSWIN done? */
1260 if (ztv->overinfo.busadr==0 || ztv->overinfo.w==0 || ztv->overinfo.h==0)
1261 return -EINVAL;
1262
1263 set_bit(STATE_OVERLAY, &ztv->state);
1264 zoran_cap(ztv, 1);
1265 }
1266 break;
1267 }
1268
1269 case VIDIOCGFBUF:
1270 {
1271 struct video_buffer v;
1272 DEBUG(printk(CARD_DEBUG "VIDIOCGFBUF\n",CARD));
1273 read_lock(&ztv->lock);
1274 v.base = (void *)ztv->overinfo.busadr;
1275 v.height = ztv->sheight;
1276 v.width = ztv->swidth;
1277 v.depth = ztv->depth;
1278 v.bytesperline = ztv->overinfo.bpl;
1279 read_unlock(&ztv->lock);
1280 if(copy_to_user(arg, &v,sizeof(v)))
1281 return -EFAULT;
1282 break;
1283 }
1284 case VIDIOCSFBUF:
1285 {
1286 struct video_buffer v;
1287 if(!capable(CAP_SYS_ADMIN))
1288 return -EPERM;
1289 if (pcipci_problems & (PCIPCI_FAIL|PCIAGP_FAIL))
1290 return -ENXIO;
1291 if (copy_from_user(&v, arg,sizeof(v)))
1292 return -EFAULT;
1293 DEBUG(printk(CARD_DEBUG "VIDIOCSFBUF(%p,%d,%d,%d,%d)\n",CARD,v.base, v.width,v.height,v.depth,v.bytesperline));
1294
1295 if (v.depth!=15 && v.depth!=16 && v.depth!=24 && v.depth!=32)
1296 return -EINVAL;
1297 if (v.bytesperline<1)
1298 return -EINVAL;
1299 if (ztv->running)
1300 return -EBUSY;
1301 write_lock_irq(&ztv->lock);
1302 ztv->overinfo.busadr = (ulong)v.base;
1303 ztv->sheight = v.height;
1304 ztv->swidth = v.width;
1305 ztv->depth = v.depth; /* bits per pixel */
1306 ztv->overinfo.bpp = ((v.depth+1)&0x38)/8;/* bytes per pixel */
1307 ztv->overinfo.bpl = v.bytesperline; /* bytes per line */
1308 write_unlock_irq(&ztv->lock);
1309 break;
1310 }
1311
1312 case VIDIOCKEY:
1313 {
1314 /* Will be handled higher up .. */
1315 break;
1316 }
1317
1318 case VIDIOCSYNC:
1319 {
1320 int i;
1321 if (get_user(i, (int *) arg))
1322 return -EFAULT;
1323 DEBUG(printk(CARD_DEBUG "VIDEOCSYNC(%d)\n",CARD,i));
1324 if (i<0 || i>ZORAN_MAX_FBUFFERS)
1325 return -EINVAL;
1326 switch (ztv->grabinfo[i].status) {
1327 case FBUFFER_FREE:
1328 return -EINVAL;
1329 case FBUFFER_BUSY:
1330 /* wait till this buffer gets grabbed */
1331 wait_event_interruptible(ztv->grabq,
1332 (ztv->grabinfo[i].status != FBUFFER_BUSY));
1333 /* see if a signal did it */
1334 if (signal_pending(current))
1335 return -EINTR;
1336 /* don't fall through; a DONE buffer is not UNUSED */
1337 break;
1338 case FBUFFER_DONE:
1339 ztv->grabinfo[i].status = FBUFFER_FREE;
1340 /* tell ppl we have a spare buffer */
1341 wake_up_interruptible(&ztv->grabq);
1342 break;
1343 }
1344 DEBUG(printk(CARD_DEBUG "VIDEOCSYNC(%d) returns\n",CARD,i));
1345 break;
1346 }
1347
1348 case VIDIOCMCAPTURE:
1349 {
1350 struct video_mmap vm;
1351 struct vidinfo* frame;
1352 if (copy_from_user(&vm,arg,sizeof(vm)))
1353 return -EFAULT;
1354 DEBUG(printk(CARD_DEBUG "VIDIOCMCAPTURE(%d,(%d,%d),%d)\n",CARD,vm.frame,vm.width,vm.height,vm.format));
1355 if (vm.frame<0 || vm.frame>ZORAN_MAX_FBUFFERS ||
1356 vm.width<32 || vm.width>768 ||
1357 vm.height<32 || vm.height>576 ||
1358 vm.format>NRPALETTES ||
1359 palette2fmt[vm.format].mode == 0)
1360 return -EINVAL;
1361
1362 /* we are allowed to take over UNUSED and DONE buffers */
1363 frame = &ztv->grabinfo[vm.frame];
1364 if (frame->status == FBUFFER_BUSY)
1365 return -EBUSY;
1366
1367 /* setup the other parameters if they are given */
1368 write_lock_irq(&ztv->lock);
1369 frame->w = vm.width;
1370 frame->h = vm.height;
1371 frame->format = vm.format;
1372 frame->bpp = palette2fmt[frame->format].bpp;
1373 frame->bpl = frame->w*frame->bpp;
1374 frame->status = FBUFFER_BUSY;
1375 frame->next = 0;
1376 { /* add to tail of queue */
1377 struct vidinfo* oldframe = ztv->workqueue;
1378 if (!oldframe) ztv->workqueue = frame;
1379 else {
1380 while (oldframe->next) oldframe = oldframe->next;
1381 oldframe->next = frame;
1382 }
1383 }
1384 write_unlock_irq(&ztv->lock);
1385 zoran_cap(ztv, 1);
1386 break;
1387 }
1388
1389 case VIDIOCGMBUF:
1390 {
1391 struct video_mbuf mb;
1392 int i;
1393 DEBUG(printk(CARD_DEBUG "VIDIOCGMBUF\n",CARD));
1394 mb.size = ZORAN_MAX_FBUFSIZE;
1395 mb.frames = ZORAN_MAX_FBUFFERS;
1396 for (i=0; i<ZORAN_MAX_FBUFFERS; i++)
1397 mb.offsets[i] = i*ZORAN_MAX_FBUFFER;
1398 if(copy_to_user(arg, &mb,sizeof(mb)))
1399 return -EFAULT;
1400 break;
1401 }
1402
1403 case VIDIOCGUNIT:
1404 {
1405 struct video_unit vu;
1406 DEBUG(printk(CARD_DEBUG "VIDIOCGUNIT\n",CARD));
1407 vu.video = ztv->video_dev.minor;
1408 vu.vbi = ztv->vbi_dev.minor;
1409 vu.radio = VIDEO_NO_UNIT;
1410 vu.audio = VIDEO_NO_UNIT;
1411 vu.teletext = VIDEO_NO_UNIT;
1412 if(copy_to_user(arg, &vu,sizeof(vu)))
1413 return -EFAULT;
1414 break;
1415 }
1416
1417 case VIDIOCGFREQ:
1418 {
1419 unsigned long v = ztv->tuner_freq;
1420 if (copy_to_user(arg,&v,sizeof(v)))
1421 return -EFAULT;
1422 DEBUG(printk(CARD_DEBUG "VIDIOCGFREQ\n",CARD));
1423 break;
1424 }
1425 case VIDIOCSFREQ:
1426 {
1427 unsigned long v;
1428 if (copy_from_user(&v, arg, sizeof(v)))
1429 return -EFAULT;
1430 DEBUG(printk(CARD_DEBUG "VIDIOCSFREQ\n",CARD));
1431
1432 if (ztv->have_tuner) {
1433 int fixme = v;
1434 if (i2c_control_device(&(ztv->i2c), I2C_DRIVERID_TUNER, TUNER_SET_TVFREQ, &fixme) < 0)
1435 return -EAGAIN;
1436 }
1437 ztv->tuner_freq = v;
1438 break;
1439 }
1440
1441 /* Why isn't this in the API?
1442 * And why doesn't it take a buffer number?
1443 case BTTV_FIELDNR:
1444 {
1445 unsigned long v = ztv->lastfieldnr;
1446 if (copy_to_user(arg,&v,sizeof(v)))
1447 return -EFAULT;
1448 DEBUG(printk(CARD_DEBUG "BTTV_FIELDNR\n",CARD));
1449 break;
1450 }
1451 */
1452
1453 default:
1454 return -ENOIOCTLCMD;
1455 }
1456 return 0;
1457}
1458
1459static
1460int zoran_mmap(struct vm_area_struct *vma, struct video_device* dev, const char* adr, unsigned long size)
1461{
1462 struct zoran* ztv = (struct zoran*)dev;
1463 unsigned long start = (unsigned long)adr;
1464 unsigned long pos;
1465
1466 DEBUG(printk(CARD_DEBUG "zoran_mmap(0x%p,%ld)\n",CARD,adr,size));
1467
1468 /* sanity checks */
1469 if (size > ZORAN_MAX_FBUFSIZE || !ztv->fbuffer)
1470 return -EINVAL;
1471
1472 /* start mapping the whole shabang to user memory */
1473 pos = (unsigned long)ztv->fbuffer;
1474 while (size>0) {
1475 unsigned long pfn = virt_to_phys((void*)pos) >> PAGE_SHIFT;
1476 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED))
1477 return -EAGAIN;
1478 start += PAGE_SIZE;
1479 pos += PAGE_SIZE;
1480 size -= PAGE_SIZE;
1481 }
1482 return 0;
1483}
1484
1485static struct video_device zr36120_template=
1486{
1487 .owner = THIS_MODULE,
1488 .name = "UNSET",
1489 .type = VID_TYPE_TUNER|VID_TYPE_CAPTURE|VID_TYPE_OVERLAY,
1490 .hardware = VID_HARDWARE_ZR36120,
1491 .open = zoran_open,
1492 .close = zoran_close,
1493 .read = zoran_read,
1494 .write = zoran_write,
1495 .poll = zoran_poll,
1496 .ioctl = zoran_ioctl,
1497 .compat_ioctl = v4l_compat_ioctl32,
1498 .mmap = zoran_mmap,
1499 .minor = -1,
1500};
1501
1502static
1503int vbi_open(struct video_device *dev, int flags)
1504{
1505 struct zoran *ztv = dev->priv;
1506 struct vidinfo* item;
1507
1508 DEBUG(printk(CARD_DEBUG "vbi_open(dev,%d)\n",CARD,flags));
1509
1510 /*
1511 * During VBI device open, we continiously grab VBI-like
1512 * data in the vbi buffer when we have nothing to do.
1513 * Only when there is an explicit request for VBI data
1514 * (read call) we /force/ a read.
1515 */
1516
1517 /* allocate buffers */
1518 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)
1519 {
1520 item->status = FBUFFER_FREE;
1521
1522 /* alloc */
1523 if (!item->memadr) {
1524 item->memadr = bmalloc(ZORAN_VBI_BUFSIZE);
1525 if (!item->memadr) {
1526 /* could not get a buffer, bail out */
1527 while (item != ztv->readinfo) {
1528 item--;
1529 bfree(item->memadr, ZORAN_VBI_BUFSIZE);
1530 item->memadr = 0;
1531 item->busadr = 0;
1532 }
1533 return -ENOBUFS;
1534 }
1535 }
1536
1537 /* determine the DMAable address */
1538 item->busadr = virt_to_bus(item->memadr);
1539 }
1540
1541 /* do the common part of all open's */
1542 zoran_common_open(ztv, flags);
1543
1544 set_bit(STATE_VBI, &ztv->state);
1545 /* start read-ahead */
1546 zoran_cap(ztv, 1);
1547
1548 return 0;
1549}
1550
1551static
1552void vbi_close(struct video_device *dev)
1553{
1554 struct zoran *ztv = dev->priv;
1555 struct vidinfo* item;
1556
1557 DEBUG(printk(CARD_DEBUG "vbi_close(dev)\n",CARD));
1558
1559 /* driver specific closure */
1560 clear_bit(STATE_VBI, &ztv->state);
1561
1562 zoran_common_close(ztv);
1563
1564 /*
1565 * This is sucky but right now I can't find a good way to
1566 * be sure its safe to free the buffer. We wait 5-6 fields
1567 * which is more than sufficient to be sure.
1568 */
1569 msleep(100); /* Wait 1/10th of a second */
1570
1571 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)
1572 {
1573 if (item->memadr)
1574 bfree(item->memadr, ZORAN_VBI_BUFSIZE);
1575 item->memadr = 0;
1576 }
1577
1578}
1579
1580/*
1581 * This read function could be used reentrant in a SMP situation.
1582 *
1583 * This is made possible by the spinlock which is kept till we
1584 * found and marked a buffer for our own use. The lock must
1585 * be released as soon as possible to prevent lock contention.
1586 */
1587static
1588long vbi_read(struct video_device* dev, char* buf, unsigned long count, int nonblock)
1589{
1590 struct zoran *ztv = dev->priv;
1591 unsigned long max;
1592 struct vidinfo* unused = 0;
1593 struct vidinfo* done = 0;
1594
1595 DEBUG(printk(CARD_DEBUG "vbi_read(0x%p,%ld,%d)\n",CARD,buf,count,nonblock));
1596
1597 /* find ourself a free or completed buffer */
1598 for (;;) {
1599 struct vidinfo* item;
1600
1601 write_lock_irq(&ztv->lock);
1602 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++) {
1603 if (!unused && item->status == FBUFFER_FREE)
1604 unused = item;
1605 if (!done && item->status == FBUFFER_DONE)
1606 done = item;
1607 }
1608 if (done || unused)
1609 break;
1610
1611 /* no more free buffers, wait for them. */
1612 write_unlock_irq(&ztv->lock);
1613 if (nonblock)
1614 return -EWOULDBLOCK;
1615 interruptible_sleep_on(&ztv->vbiq);
1616 if (signal_pending(current))
1617 return -EINTR;
1618 }
1619
1620 /* Do we have 'ready' data? */
1621 if (!done) {
1622 /* no? than this will take a while... */
1623 if (nonblock) {
1624 write_unlock_irq(&ztv->lock);
1625 return -EWOULDBLOCK;
1626 }
1627
1628 /* mark the unused buffer as wanted */
1629 unused->status = FBUFFER_BUSY;
1630 unused->next = 0;
1631 { /* add to tail of queue */
1632 struct vidinfo* oldframe = ztv->workqueue;
1633 if (!oldframe) ztv->workqueue = unused;
1634 else {
1635 while (oldframe->next) oldframe = oldframe->next;
1636 oldframe->next = unused;
1637 }
1638 }
1639 write_unlock_irq(&ztv->lock);
1640
1641 /* tell the state machine we want it filled /NOW/ */
1642 zoran_cap(ztv, 1);
1643
1644 /* wait till this buffer gets grabbed */
1645 wait_event_interruptible(ztv->vbiq,
1646 (unused->status != FBUFFER_BUSY));
1647 /* see if a signal did it */
1648 if (signal_pending(current))
1649 return -EINTR;
1650 done = unused;
1651 }
1652 else
1653 write_unlock_irq(&ztv->lock);
1654
1655 /* Yes! we got data! */
1656 max = done->bpl * -done->h;
1657 if (count > max)
1658 count = max;
1659
1660 /* check if the user gave us enough room to write the data */
1661 if (!access_ok(VERIFY_WRITE, buf, count)) {
1662 count = -EFAULT;
1663 goto out;
1664 }
1665
1666 /*
1667 * Now transform/strip the data from YUV to Y-only
1668 * NB. Assume the Y is in the LSB of the YUV data.
1669 */
1670 {
1671 unsigned char* optr = buf;
1672 unsigned char* eptr = buf+count;
1673
1674 /* are we beeing accessed from an old driver? */
1675 if (count == 2*19*2048) {
1676 /*
1677 * Extreme HACK, old VBI programs expect 2048 points
1678 * of data, and we only got 864 orso. Double each
1679 * datapoint and clear the rest of the line.
1680 * This way we have appear to have a
1681 * sample_frequency of 29.5 Mc.
1682 */
1683 int x,y;
1684 unsigned char* iptr = done->memadr+1;
1685 for (y=done->h; optr<eptr && y<0; y++)
1686 {
1687 /* copy to doubled data to userland */
1688 for (x=0; optr+1<eptr && x<-done->w; x++)
1689 {
1690 unsigned char a = iptr[x*2];
1691 __put_user(a, optr++);
1692 __put_user(a, optr++);
1693 }
1694 /* and clear the rest of the line */
1695 for (x*=2; optr<eptr && x<done->bpl; x++)
1696 __put_user(0, optr++);
1697 /* next line */
1698 iptr += done->bpl;
1699 }
1700 }
1701 else {
1702 /*
1703 * Other (probably newer) programs asked
1704 * us what geometry we are using, and are
1705 * reading the correct size.
1706 */
1707 int x,y;
1708 unsigned char* iptr = done->memadr+1;
1709 for (y=done->h; optr<eptr && y<0; y++)
1710 {
1711 /* copy to doubled data to userland */
1712 for (x=0; optr<eptr && x<-done->w; x++)
1713 __put_user(iptr[x*2], optr++);
1714 /* and clear the rest of the line */
1715 for (;optr<eptr && x<done->bpl; x++)
1716 __put_user(0, optr++);
1717 /* next line */
1718 iptr += done->bpl;
1719 }
1720 }
1721
1722 /* API compliance:
1723 * place the framenumber (half fieldnr) in the last long
1724 */
1725 __put_user(done->fieldnr/2, ((ulong*)eptr)[-1]);
1726 }
1727
1728 /* keep the engine running */
1729 done->status = FBUFFER_FREE;
1730 zoran_cap(ztv, 1);
1731
1732 /* tell listeners this buffer just became free */
1733 wake_up_interruptible(&ztv->vbiq);
1734
1735 /* goodbye */
1736out:
1737 DEBUG(printk(CARD_DEBUG "vbi_read() returns %lu\n",CARD,count));
1738 return count;
1739}
1740
1741static
1742unsigned int vbi_poll(struct video_device *dev, struct file *file, poll_table *wait)
1743{
1744 struct zoran *ztv = dev->priv;
1745 struct vidinfo* item;
1746 unsigned int mask = 0;
1747
1748 poll_wait(file, &ztv->vbiq, wait);
1749
1750 for (item=ztv->readinfo; item!=ztv->readinfo+ZORAN_VBI_BUFFERS; item++)
1751 if (item->status == FBUFFER_DONE)
1752 {
1753 mask |= (POLLIN | POLLRDNORM);
1754 break;
1755 }
1756
1757 DEBUG(printk(CARD_DEBUG "vbi_poll()=%x\n",CARD,mask));
1758
1759 return mask;
1760}
1761
1762static
1763int vbi_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1764{
1765 struct zoran* ztv = dev->priv;
1766
1767 switch (cmd) {
1768 case VIDIOCGVBIFMT:
1769 {
1770 struct vbi_format f;
1771 DEBUG(printk(CARD_DEBUG "VIDIOCGVBIINFO\n",CARD));
1772 f.sampling_rate = 14750000UL;
1773 f.samples_per_line = -ztv->readinfo[0].w;
1774 f.sample_format = VIDEO_PALETTE_RAW;
1775 f.start[0] = f.start[1] = ztv->readinfo[0].y;
1776 f.start[1] += 312;
1777 f.count[0] = f.count[1] = -ztv->readinfo[0].h;
1778 f.flags = VBI_INTERLACED;
1779 if (copy_to_user(arg,&f,sizeof(f)))
1780 return -EFAULT;
1781 break;
1782 }
1783 case VIDIOCSVBIFMT:
1784 {
1785 struct vbi_format f;
1786 int i;
1787 if (copy_from_user(&f, arg,sizeof(f)))
1788 return -EFAULT;
1789 DEBUG(printk(CARD_DEBUG "VIDIOCSVBIINFO(%d,%d,%d,%d,%d,%d,%d,%x)\n",CARD,f.sampling_rate,f.samples_per_line,f.sample_format,f.start[0],f.start[1],f.count[0],f.count[1],f.flags));
1790
1791 /* lots of parameters are fixed... (PAL) */
1792 if (f.sampling_rate != 14750000UL ||
1793 f.samples_per_line > 864 ||
1794 f.sample_format != VIDEO_PALETTE_RAW ||
1795 f.start[0] < 0 ||
1796 f.start[0] != f.start[1]-312 ||
1797 f.count[0] != f.count[1] ||
1798 f.start[0]+f.count[0] >= 288 ||
1799 f.flags != VBI_INTERLACED)
1800 return -EINVAL;
1801
1802 write_lock_irq(&ztv->lock);
1803 ztv->readinfo[0].y = f.start[0];
1804 ztv->readinfo[0].w = -f.samples_per_line;
1805 ztv->readinfo[0].h = -f.count[0];
1806 ztv->readinfo[0].bpl = f.samples_per_line*ztv->readinfo[0].bpp;
1807 for (i=1; i<ZORAN_VBI_BUFFERS; i++)
1808 ztv->readinfo[i] = ztv->readinfo[i];
1809 write_unlock_irq(&ztv->lock);
1810 break;
1811 }
1812 default:
1813 return -ENOIOCTLCMD;
1814 }
1815 return 0;
1816}
1817
1818static struct video_device vbi_template=
1819{
1820 .owner = THIS_MODULE,
1821 .name = "UNSET",
1822 .type = VID_TYPE_CAPTURE|VID_TYPE_TELETEXT,
1823 .hardware = VID_HARDWARE_ZR36120,
1824 .open = vbi_open,
1825 .close = vbi_close,
1826 .read = vbi_read,
1827 .write = zoran_write,
1828 .poll = vbi_poll,
1829 .ioctl = vbi_ioctl,
1830 .minor = -1,
1831};
1832
1833/*
1834 * Scan for a Zoran chip, request the irq and map the io memory
1835 */
1836static
1837int __init find_zoran(void)
1838{
1839 int result;
1840 struct zoran *ztv;
1841 struct pci_dev *dev = NULL;
1842 unsigned char revision;
1843 int zoran_num = 0;
1844
1845 while ((dev = pci_get_device(PCI_VENDOR_ID_ZORAN,PCI_DEVICE_ID_ZORAN_36120, dev)))
1846 {
1847 /* Ok, a ZR36120/ZR36125 found! */
1848 ztv = &zorans[zoran_num];
1849 ztv->dev = dev;
1850
1851 if (pci_enable_device(dev))
1852 continue;
1853
1854 pci_read_config_byte(dev, PCI_CLASS_REVISION, &revision);
1855 printk(KERN_INFO "zoran: Zoran %x (rev %d) ",
1856 dev->device, revision);
1857 printk("bus: %d, devfn: %d, irq: %d, ",
1858 dev->bus->number, dev->devfn, dev->irq);
1859 printk("memory: 0x%08lx.\n", ztv->zoran_adr);
1860
1861 ztv->zoran_mem = ioremap(ztv->zoran_adr, 0x1000);
1862 DEBUG(printk(KERN_DEBUG "zoran: mapped-memory at 0x%p\n",ztv->zoran_mem));
1863
1864 result = request_irq(dev->irq, zoran_irq,
1865 IRQF_SHARED|IRQF_DISABLED,"zoran", ztv);
1866 if (result==-EINVAL)
1867 {
1868 iounmap(ztv->zoran_mem);
1869 printk(KERN_ERR "zoran: Bad irq number or handler\n");
1870 continue;
1871 }
1872 if (result==-EBUSY)
1873 printk(KERN_ERR "zoran: IRQ %d busy, change your PnP config in BIOS\n",dev->irq);
1874 if (result < 0) {
1875 iounmap(ztv->zoran_mem);
1876 continue;
1877 }
1878 /* Enable bus-mastering */
1879 pci_set_master(dev);
1880 /* Keep a reference */
1881 pci_dev_get(dev);
1882 zoran_num++;
1883 }
1884 if(zoran_num)
1885 printk(KERN_INFO "zoran: %d Zoran card(s) found.\n",zoran_num);
1886 return zoran_num;
1887}
1888
1889static
1890int __init init_zoran(int card)
1891{
1892 struct zoran *ztv = &zorans[card];
1893 int i;
1894
1895 /* if the given cardtype valid? */
1896 if (cardtype[card]>=NRTVCARDS) {
1897 printk(KERN_INFO "invalid cardtype(%d) detected\n",cardtype[card]);
1898 return -1;
1899 }
1900
1901 /* reset the zoran */
1902 zrand(~ZORAN_PCI_SOFTRESET,ZORAN_PCI);
1903 udelay(10);
1904 zror(ZORAN_PCI_SOFTRESET,ZORAN_PCI);
1905 udelay(10);
1906
1907 /* zoran chip specific details */
1908 ztv->card = tvcards+cardtype[card]; /* point to the selected card */
1909 ztv->norm = 0; /* PAL */
1910 ztv->tuner_freq = 0;
1911
1912 /* videocard details */
1913 ztv->swidth = 800;
1914 ztv->sheight = 600;
1915 ztv->depth = 16;
1916
1917 /* State details */
1918 ztv->fbuffer = 0;
1919 ztv->overinfo.kindof = FBUFFER_OVERLAY;
1920 ztv->overinfo.status = FBUFFER_FREE;
1921 ztv->overinfo.x = 0;
1922 ztv->overinfo.y = 0;
1923 ztv->overinfo.w = 768; /* 640 */
1924 ztv->overinfo.h = 576; /* 480 */
1925 ztv->overinfo.format = VIDEO_PALETTE_RGB565;
1926 ztv->overinfo.bpp = palette2fmt[ztv->overinfo.format].bpp;
1927 ztv->overinfo.bpl = ztv->overinfo.bpp*ztv->swidth;
1928 ztv->overinfo.busadr = 0;
1929 ztv->overinfo.memadr = 0;
1930 ztv->overinfo.overlay = 0;
1931 for (i=0; i<ZORAN_MAX_FBUFFERS; i++) {
1932 ztv->grabinfo[i] = ztv->overinfo;
1933 ztv->grabinfo[i].kindof = FBUFFER_GRAB;
1934 }
1935 init_waitqueue_head(&ztv->grabq);
1936
1937 /* VBI details */
1938 ztv->readinfo[0] = ztv->overinfo;
1939 ztv->readinfo[0].kindof = FBUFFER_VBI;
1940 ztv->readinfo[0].w = -864;
1941 ztv->readinfo[0].h = -38;
1942 ztv->readinfo[0].format = VIDEO_PALETTE_YUV422;
1943 ztv->readinfo[0].bpp = palette2fmt[ztv->readinfo[0].format].bpp;
1944 ztv->readinfo[0].bpl = 1024*ztv->readinfo[0].bpp;
1945 for (i=1; i<ZORAN_VBI_BUFFERS; i++)
1946 ztv->readinfo[i] = ztv->readinfo[0];
1947 init_waitqueue_head(&ztv->vbiq);
1948
1949 /* maintenance data */
1950 ztv->have_decoder = 0;
1951 ztv->have_tuner = 0;
1952 ztv->tuner_type = 0;
1953 ztv->running = 0;
1954 ztv->users = 0;
1955 rwlock_init(&ztv->lock);
1956 ztv->workqueue = 0;
1957 ztv->fieldnr = 0;
1958 ztv->lastfieldnr = 0;
1959
1960 if (triton1)
1961 zrand(~ZORAN_VDC_TRICOM, ZORAN_VDC);
1962
1963 /* external FL determines TOP frame */
1964 zror(ZORAN_VFEC_EXTFL, ZORAN_VFEC);
1965
1966 /* set HSpol */
1967 if (ztv->card->hsync_pos)
1968 zrwrite(ZORAN_VFEH_HSPOL, ZORAN_VFEH);
1969 /* set VSpol */
1970 if (ztv->card->vsync_pos)
1971 zrwrite(ZORAN_VFEV_VSPOL, ZORAN_VFEV);
1972
1973 /* Set the proper General Purpuse register bits */
1974 /* implicit: no softreset, 0 waitstates */
1975 zrwrite(ZORAN_PCI_SOFTRESET|(ztv->card->gpdir<<0),ZORAN_PCI);
1976 /* implicit: 3 duration and recovery PCI clocks on guest 0-3 */
1977 zrwrite(ztv->card->gpval<<24,ZORAN_GUEST);
1978
1979 /* clear interrupt status */
1980 zrwrite(~0, ZORAN_ISR);
1981
1982 /*
1983 * i2c template
1984 */
1985 ztv->i2c = zoran_i2c_bus_template;
1986 sprintf(ztv->i2c.name,"zoran-%d",card);
1987 ztv->i2c.data = ztv;
1988
1989 /*
1990 * Now add the template and register the device unit
1991 */
1992 ztv->video_dev = zr36120_template;
1993 strcpy(ztv->video_dev.name, ztv->i2c.name);
1994 ztv->video_dev.priv = ztv;
1995 if (video_register_device(&ztv->video_dev, VFL_TYPE_GRABBER, video_nr) < 0)
1996 return -1;
1997
1998 ztv->vbi_dev = vbi_template;
1999 strcpy(ztv->vbi_dev.name, ztv->i2c.name);
2000 ztv->vbi_dev.priv = ztv;
2001 if (video_register_device(&ztv->vbi_dev, VFL_TYPE_VBI, vbi_nr) < 0) {
2002 video_unregister_device(&ztv->video_dev);
2003 return -1;
2004 }
2005 i2c_register_bus(&ztv->i2c);
2006
2007 /* set interrupt mask - the PIN enable will be set later */
2008 zrwrite(ZORAN_ICR_GIRQ0|ZORAN_ICR_GIRQ1|ZORAN_ICR_CODE, ZORAN_ICR);
2009
2010 printk(KERN_INFO "%s: installed %s\n",ztv->i2c.name,ztv->card->name);
2011 return 0;
2012}
2013
2014static
2015void release_zoran(int max)
2016{
2017 struct zoran *ztv;
2018 int i;
2019
2020 for (i=0;i<max; i++)
2021 {
2022 ztv = &zorans[i];
2023
2024 /* turn off all capturing, DMA and IRQs */
2025 /* reset the zoran */
2026 zrand(~ZORAN_PCI_SOFTRESET,ZORAN_PCI);
2027 udelay(10);
2028 zror(ZORAN_PCI_SOFTRESET,ZORAN_PCI);
2029 udelay(10);
2030
2031 /* first disable interrupts before unmapping the memory! */
2032 zrwrite(0, ZORAN_ICR);
2033 zrwrite(0xffffffffUL,ZORAN_ISR);
2034
2035 /* free it */
2036 free_irq(ztv->dev->irq,ztv);
2037
2038 /* unregister i2c_bus */
2039 i2c_unregister_bus((&ztv->i2c));
2040
2041 /* unmap and free memory */
2042 if (ztv->zoran_mem)
2043 iounmap(ztv->zoran_mem);
2044
2045 /* Drop PCI device */
2046 pci_dev_put(ztv->dev);
2047
2048 video_unregister_device(&ztv->video_dev);
2049 video_unregister_device(&ztv->vbi_dev);
2050 }
2051}
2052
2053void __exit zr36120_exit(void)
2054{
2055 release_zoran(zoran_cards);
2056}
2057
2058int __init zr36120_init(void)
2059{
2060 int card;
2061
2062 handle_chipset();
2063 zoran_cards = find_zoran();
2064 if (zoran_cards <= 0)
2065 return -EIO;
2066
2067 /* initialize Zorans */
2068 for (card=0; card<zoran_cards; card++) {
2069 if (init_zoran(card) < 0) {
2070 /* only release the zorans we have registered */
2071 release_zoran(card);
2072 return -EIO;
2073 }
2074 }
2075 return 0;
2076}
2077
2078module_init(zr36120_init);
2079module_exit(zr36120_exit);
diff --git a/drivers/media/video/zr36120.h b/drivers/media/video/zr36120.h
deleted file mode 100644
index a71e485b0f98..000000000000
--- a/drivers/media/video/zr36120.h
+++ /dev/null
@@ -1,279 +0,0 @@
1/*
2 zr36120.h - Zoran 36120/36125 based framegrabbers
3
4 Copyright (C) 1998-1999 Pauline Middelink (middelin@polyware.nl)
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef _ZR36120_H
22#define _ZR36120_H
23
24#ifdef __KERNEL__
25
26#include <linux/types.h>
27#include <linux/wait.h>
28
29#include <linux/i2c-old.h>
30#include <linux/videodev.h>
31
32#include <asm/io.h>
33
34/*
35 * Debug macro's, place an x behind the ) for actual debug-compilation
36 * E.g. #define DEBUG(x...) x
37 */
38#define DEBUG(x...) /* Debug driver */
39#define IDEBUG(x...) /* Debug interrupt handler */
40#define PDEBUG 0 /* Debug PCI writes */
41
42/* defined in zr36120_i2c */
43extern struct i2c_bus zoran_i2c_bus_template;
44
45#define ZORAN_MAX_FBUFFERS 2
46#define ZORAN_MAX_FBUFFER (768*576*2)
47#define ZORAN_MAX_FBUFSIZE (ZORAN_MAX_FBUFFERS*ZORAN_MAX_FBUFFER)
48
49#define ZORAN_VBI_BUFFERS 2
50#define ZORAN_VBI_BUFSIZE (22*1024*2)
51
52struct tvcard {
53 char* name; /* name of the cardtype */
54 int video_inputs; /* number of channels defined in video_mux */
55 int audio_inputs; /* number of channels defined in audio_mux */
56 __u32 swapi2c:1, /* need to swap i2c wires SDA/SCL? */
57 usegirq1:1, /* VSYNC at GIRQ1 instead of GIRQ0? */
58 vsync_pos:1, /* positive VSYNC signal? */
59 hsync_pos:1, /* positive HSYNC signal? */
60 gpdir:8, /* General Purpose Direction register */
61 gpval:8; /* General Purpose Value register */
62 int video_mux[6]; /* mapping channel number to physical input */
63#define IS_TUNER 0x80
64#define IS_SVHS 0x40
65#define CHANNEL_MASK 0x3F
66 int audio_mux[6]; /* mapping channel number to physical input */
67};
68#define TUNER(x) ((x)|IS_TUNER)
69#define SVHS(x) ((x)|IS_SVHS)
70
71struct vidinfo {
72 struct vidinfo* next; /* next active buffer */
73 uint kindof;
74#define FBUFFER_OVERLAY 0
75#define FBUFFER_GRAB 1
76#define FBUFFER_VBI 2
77 uint status;
78#define FBUFFER_FREE 0
79#define FBUFFER_BUSY 1
80#define FBUFFER_DONE 2
81 ulong fieldnr; /* # of field, not framer! */
82 uint x,y;
83 int w,h; /* w,h can be negative! */
84 uint format; /* index in palette2fmt[] */
85 uint bpp; /* lookup from palette2fmt[] */
86 uint bpl; /* calc: width * bpp */
87 ulong busadr; /* bus addr for DMA engine */
88 char* memadr; /* kernel addr for making copies */
89 ulong* overlay; /* kernel addr of overlay mask */
90};
91
92struct zoran
93{
94 struct video_device video_dev;
95#define CARD_DEBUG KERN_DEBUG "%s(%lu): "
96#define CARD_INFO KERN_INFO "%s(%lu): "
97#define CARD_ERR KERN_ERR "%s(%lu): "
98#define CARD ztv->video_dev.name,ztv->fieldnr
99
100 /* zoran chip specific details */
101 struct i2c_bus i2c; /* i2c registration data */
102 struct pci_dev* dev; /* ptr to PCI device */
103 ulong zoran_adr; /* bus address of IO memory */
104 char* zoran_mem; /* kernel address of IO memory */
105 struct tvcard* card; /* the cardtype */
106 uint norm; /* 0=PAL, 1=NTSC, 2=SECAM */
107 uint tuner_freq; /* Current freq in kHz */
108 struct video_picture picture; /* Current picture params */
109
110 /* videocard details */
111 uint swidth; /* screen width */
112 uint sheight; /* screen height */
113 uint depth; /* depth in bits */
114
115 /* State details */
116 char* fbuffer; /* framebuffers for mmap */
117 struct vidinfo overinfo; /* overlay data */
118 struct vidinfo grabinfo[ZORAN_MAX_FBUFFERS]; /* grabbing data*/
119 wait_queue_head_t grabq; /* grabbers queue */
120
121 /* VBI details */
122 struct video_device vbi_dev;
123 struct vidinfo readinfo[2]; /* VBI data - flip buffers */
124 wait_queue_head_t vbiq; /* vbi queue */
125
126 /* maintenance data */
127 int have_decoder; /* did we detect a mux? */
128 int have_tuner; /* did we detect a tuner? */
129 int users; /* howmany video/vbi open? */
130 int tuner_type; /* tuner type, when found */
131 int running; /* are we rolling? */
132 rwlock_t lock;
133 long state; /* what is requested of us? */
134#define STATE_OVERLAY 0
135#define STATE_VBI 1
136 struct vidinfo* workqueue; /* buffers to grab, head is active */
137 ulong fieldnr; /* #field, ticked every VSYNC */
138 ulong lastfieldnr; /* #field, ticked every GRAB */
139
140 int vidInterlace; /* calculated */
141 int vidXshift; /* calculated */
142 uint vidWidth; /* calculated */
143 uint vidHeight; /* calculated */
144};
145
146#define zrwrite(dat,adr) writel((dat),(char *) (ztv->zoran_mem+(adr)))
147#define zrread(adr) readl(ztv->zoran_mem+(adr))
148
149#if PDEBUG == 0
150#define zrand(dat,adr) zrwrite((dat) & zrread(adr), adr)
151#define zror(dat,adr) zrwrite((dat) | zrread(adr), adr)
152#define zraor(dat,mask,adr) zrwrite( ((dat)&~(mask)) | ((mask)&zrread(adr)), adr)
153#else
154#define zrand(dat, adr) \
155do { \
156 ulong data = (dat) & zrread((adr)); \
157 zrwrite(data, (adr)); \
158 if (0 != (~(dat) & zrread((adr)))) \
159 printk(KERN_DEBUG "zoran: zrand at %d(%d) detected set bits(%x)\n", __LINE__, (adr), (dat)); \
160} while(0)
161
162#define zror(dat, adr) \
163do { \
164 ulong data = (dat) | zrread((adr)); \
165 zrwrite(data, (adr)); \
166 if ((dat) != ((dat) & zrread(adr))) \
167 printk(KERN_DEBUG "zoran: zror at %d(%d) detected unset bits(%x)\n", __LINE__, (adr), (dat)); \
168} while(0)
169
170#define zraor(dat, mask, adr) \
171do { \
172 ulong data; \
173 if ((dat) & (mask)) \
174 printk(KERN_DEBUG "zoran: zraor at %d(%d) detected bits(%x:%x)\n", __LINE__, (adr), (dat), (mask)); \
175 data = ((dat)&~(mask)) | ((mask) & zrread((adr))); \
176 zrwrite(data,(adr)); \
177 if ( (dat) != (~(mask) & zrread((adr))) ) \
178 printk(KERN_DEBUG "zoran: zraor at %d(%d) could not set all bits(%x:%x)\n", __LINE__, (adr), (dat), (mask)); \
179} while(0)
180#endif
181
182#endif
183
184/* zoran PCI address space */
185#define ZORAN_VFEH 0x000 /* Video Front End Horizontal Conf. */
186#define ZORAN_VFEH_HSPOL (1<<30)
187#define ZORAN_VFEH_HSTART (0x3FF<<10)
188#define ZORAN_VFEH_HEND (0x3FF<<0)
189
190#define ZORAN_VFEV 0x004 /* Video Front End Vertical Conf. */
191#define ZORAN_VFEV_VSPOL (1<<30)
192#define ZORAN_VFEV_VSTART (0x3FF<<10)
193#define ZORAN_VFEV_VEND (0x3FF<<0)
194
195#define ZORAN_VFEC 0x008 /* Video Front End Scaler and Pixel */
196#define ZORAN_VFEC_EXTFL (1<<26)
197#define ZORAN_VFEC_TOPFIELD (1<<25)
198#define ZORAN_VFEC_VCLKPOL (1<<24)
199#define ZORAN_VFEC_HFILTER (7<<21)
200#define ZORAN_VFEC_HFILTER_1 (0<<21) /* no lumi, 3-tap chromo */
201#define ZORAN_VFEC_HFILTER_2 (1<<21) /* 3-tap lumi, 3-tap chromo */
202#define ZORAN_VFEC_HFILTER_3 (2<<21) /* 4-tap lumi, 4-tap chromo */
203#define ZORAN_VFEC_HFILTER_4 (3<<21) /* 5-tap lumi, 4-tap chromo */
204#define ZORAN_VFEC_HFILTER_5 (4<<21) /* 4-tap lumi, 4-tap chromo */
205#define ZORAN_VFEC_DUPFLD (1<<20)
206#define ZORAN_VFEC_HORDCM (63<<14)
207#define ZORAN_VFEC_VERDCM (63<<8)
208#define ZORAN_VFEC_DISPMOD (1<<6)
209#define ZORAN_VFEC_RGB (3<<3)
210#define ZORAN_VFEC_RGB_YUV422 (0<<3)
211#define ZORAN_VFEC_RGB_RGB888 (1<<3)
212#define ZORAN_VFEC_RGB_RGB565 (2<<3)
213#define ZORAN_VFEC_RGB_RGB555 (3<<3)
214#define ZORAN_VFEC_ERRDIF (1<<2)
215#define ZORAN_VFEC_PACK24 (1<<1)
216#define ZORAN_VFEC_LE (1<<0)
217
218#define ZORAN_VTOP 0x00C /* Video Display "Top" */
219
220#define ZORAN_VBOT 0x010 /* Video Display "Bottom" */
221
222#define ZORAN_VSTR 0x014 /* Video Display Stride */
223#define ZORAN_VSTR_DISPSTRIDE (0xFFFF<<16)
224#define ZORAN_VSTR_VIDOVF (1<<8)
225#define ZORAN_VSTR_SNAPSHOT (1<<1)
226#define ZORAN_VSTR_GRAB (1<<0)
227
228#define ZORAN_VDC 0x018 /* Video Display Conf. */
229#define ZORAN_VDC_VIDEN (1<<31)
230#define ZORAN_VDC_MINPIX (0x1F<<25)
231#define ZORAN_VDC_TRICOM (1<<24)
232#define ZORAN_VDC_VIDWINHT (0x3FF<<12)
233#define ZORAN_VDC_VIDWINWID (0x3FF<<0)
234
235#define ZORAN_MTOP 0x01C /* Masking Map "Top" */
236
237#define ZORAN_MBOT 0x020 /* Masking Map "Bottom" */
238
239#define ZORAN_OCR 0x024 /* Overlay Control */
240#define ZORAN_OCR_OVLEN (1<<15)
241#define ZORAN_OCR_MASKSTRIDE (0xFF<<0)
242
243#define ZORAN_PCI 0x028 /* System, PCI and GPP Control */
244#define ZORAN_PCI_SOFTRESET (1<<24)
245#define ZORAN_PCI_WAITSTATE (3<<16)
246#define ZORAN_PCI_GENPURDIR (0xFF<<0)
247
248#define ZORAN_GUEST 0x02C /* GuestBus Control */
249
250#define ZORAN_CSOURCE 0x030 /* Code Source Address */
251
252#define ZORAN_CTRANS 0x034 /* Code Transfer Control */
253
254#define ZORAN_CMEM 0x038 /* Code Memory Pointer */
255
256#define ZORAN_ISR 0x03C /* Interrupt Status Register */
257#define ZORAN_ISR_CODE (1<<28)
258#define ZORAN_ISR_GIRQ0 (1<<29)
259#define ZORAN_ISR_GIRQ1 (1<<30)
260
261#define ZORAN_ICR 0x040 /* Interrupt Control Register */
262#define ZORAN_ICR_EN (1<<24)
263#define ZORAN_ICR_CODE (1<<28)
264#define ZORAN_ICR_GIRQ0 (1<<29)
265#define ZORAN_ICR_GIRQ1 (1<<30)
266
267#define ZORAN_I2C 0x044 /* I2C-Bus */
268#define ZORAN_I2C_SCL (1<<1)
269#define ZORAN_I2C_SDA (1<<0)
270
271#define ZORAN_POST 0x48 /* PostOffice */
272#define ZORAN_POST_PEN (1<<25)
273#define ZORAN_POST_TIME (1<<24)
274#define ZORAN_POST_DIR (1<<23)
275#define ZORAN_POST_GUESTID (3<<20)
276#define ZORAN_POST_GUEST (7<<16)
277#define ZORAN_POST_DATA (0xFF<<0)
278
279#endif
diff --git a/drivers/media/video/zr36120_i2c.c b/drivers/media/video/zr36120_i2c.c
deleted file mode 100644
index 21fde43a6aed..000000000000
--- a/drivers/media/video/zr36120_i2c.c
+++ /dev/null
@@ -1,132 +0,0 @@
1/*
2 zr36120_i2c.c - Zoran 36120/36125 based framegrabbers
3
4 Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/types.h>
22#include <linux/delay.h>
23#include <asm/io.h>
24
25#include <linux/video_decoder.h>
26#include <asm/uaccess.h>
27
28#include "tuner.h"
29#include "zr36120.h"
30
31/* ----------------------------------------------------------------------- */
32/* I2C functions */
33/* ----------------------------------------------------------------------- */
34
35/* software I2C functions */
36
37#define I2C_DELAY 10
38
39static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
40{
41 struct zoran *ztv = (struct zoran*)bus->data;
42 unsigned int b = 0;
43 if (data) b |= ztv->card->swapi2c ? ZORAN_I2C_SCL : ZORAN_I2C_SDA;
44 if (ctrl) b |= ztv->card->swapi2c ? ZORAN_I2C_SDA : ZORAN_I2C_SCL;
45 zrwrite(b, ZORAN_I2C);
46 udelay(I2C_DELAY);
47}
48
49static int i2c_getdataline(struct i2c_bus *bus)
50{
51 struct zoran *ztv = (struct zoran*)bus->data;
52 if (ztv->card->swapi2c)
53 return zrread(ZORAN_I2C) & ZORAN_I2C_SCL;
54 return zrread(ZORAN_I2C) & ZORAN_I2C_SDA;
55}
56
57static
58void attach_inform(struct i2c_bus *bus, int id)
59{
60 struct zoran *ztv = (struct zoran*)bus->data;
61 struct video_decoder_capability dc;
62 int rv;
63
64 switch (id) {
65 case I2C_DRIVERID_VIDEODECODER:
66 DEBUG(printk(CARD_INFO "decoder attached\n",CARD));
67
68 /* fetch the capabilities of the decoder */
69 rv = i2c_control_device(&ztv->i2c, I2C_DRIVERID_VIDEODECODER, DECODER_GET_CAPABILITIES, &dc);
70 if (rv) {
71 DEBUG(printk(CARD_DEBUG "decoder is not V4L aware!\n",CARD));
72 break;
73 }
74 DEBUG(printk(CARD_DEBUG "capabilities %d %d %d\n",CARD,dc.flags,dc.inputs,dc.outputs));
75
76 /* Test if the decoder can de VBI transfers */
77 if (dc.flags & 16 /*VIDEO_DECODER_VBI*/)
78 ztv->have_decoder = 2;
79 else
80 ztv->have_decoder = 1;
81 break;
82 case I2C_DRIVERID_TUNER:
83 ztv->have_tuner = 1;
84 DEBUG(printk(CARD_INFO "tuner attached\n",CARD));
85 if (ztv->tuner_type >= 0)
86 {
87 if (i2c_control_device(&ztv->i2c,I2C_DRIVERID_TUNER,TUNER_SET_TYPE,&ztv->tuner_type)<0)
88 DEBUG(printk(CARD_INFO "attach_inform; tuner won't be set to type %d\n",CARD,ztv->tuner_type));
89 }
90 break;
91 default:
92 DEBUG(printk(CARD_INFO "attach_inform; unknown device id=%d\n",CARD,id));
93 break;
94 }
95}
96
97static
98void detach_inform(struct i2c_bus *bus, int id)
99{
100 struct zoran *ztv = (struct zoran*)bus->data;
101
102 switch (id) {
103 case I2C_DRIVERID_VIDEODECODER:
104 ztv->have_decoder = 0;
105 DEBUG(printk(CARD_INFO "decoder detached\n",CARD));
106 break;
107 case I2C_DRIVERID_TUNER:
108 ztv->have_tuner = 0;
109 DEBUG(printk(CARD_INFO "tuner detached\n",CARD));
110 break;
111 default:
112 DEBUG(printk(CARD_INFO "detach_inform; unknown device id=%d\n",CARD,id));
113 break;
114 }
115}
116
117struct i2c_bus zoran_i2c_bus_template =
118{
119 "ZR36120",
120 I2C_BUSID_ZORAN,
121 NULL,
122
123 SPIN_LOCK_UNLOCKED,
124
125 attach_inform,
126 detach_inform,
127
128 i2c_setlines,
129 i2c_getdataline,
130 NULL,
131 NULL
132};
diff --git a/drivers/media/video/zr36120_mem.c b/drivers/media/video/zr36120_mem.c
deleted file mode 100644
index 416eaa93b8a4..000000000000
--- a/drivers/media/video/zr36120_mem.c
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 zr36120_mem.c - Zoran 36120/36125 based framegrabbers
3
4 Copyright (C) 1998-1999 Pauline Middelink <middelin@polyware.nl>
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 as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/mm.h>
22#include <linux/pci.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <asm/io.h>
26#ifdef CONFIG_BIGPHYS_AREA
27#include <linux/bigphysarea.h>
28#endif
29
30#include "zr36120.h"
31#include "zr36120_mem.h"
32
33/*******************************/
34/* Memory management functions */
35/*******************************/
36
37void* bmalloc(unsigned long size)
38{
39 void* mem;
40#ifdef CONFIG_BIGPHYS_AREA
41 mem = bigphysarea_alloc_pages(size/PAGE_SIZE, 1, GFP_KERNEL);
42#else
43 /*
44 * The following function got a lot of memory at boottime,
45 * so we know its always there...
46 */
47 mem = (void*)__get_free_pages(GFP_USER|GFP_DMA,get_order(size));
48#endif
49 if (mem) {
50 unsigned long adr = (unsigned long)mem;
51 while (size > 0) {
52 SetPageReserved(virt_to_page(phys_to_virt(adr)));
53 adr += PAGE_SIZE;
54 size -= PAGE_SIZE;
55 }
56 }
57 return mem;
58}
59
60void bfree(void* mem, unsigned long size)
61{
62 if (mem) {
63 unsigned long adr = (unsigned long)mem;
64 unsigned long siz = size;
65 while (siz > 0) {
66 ClearPageReserved(virt_to_page(phys_to_virt(adr)));
67 adr += PAGE_SIZE;
68 siz -= PAGE_SIZE;
69 }
70#ifdef CONFIG_BIGPHYS_AREA
71 bigphysarea_free_pages(mem);
72#else
73 free_pages((unsigned long)mem,get_order(size));
74#endif
75 }
76}
77
78MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zr36120_mem.h b/drivers/media/video/zr36120_mem.h
deleted file mode 100644
index aad117acc91d..000000000000
--- a/drivers/media/video/zr36120_mem.h
+++ /dev/null
@@ -1,3 +0,0 @@
1/* either kmalloc() or bigphysarea() alloced memory - continuous */
2void* bmalloc(unsigned long size);
3void bfree(void* mem, unsigned long size);
diff --git a/drivers/mmc/at91_mci.c b/drivers/mmc/at91_mci.c
index 4633dbc9a90f..08a33c33f6ed 100644
--- a/drivers/mmc/at91_mci.c
+++ b/drivers/mmc/at91_mci.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/mmc/at91_mci.c - ATMEL AT91RM9200 MCI Driver 2 * linux/drivers/mmc/at91_mci.c - ATMEL AT91 MCI Driver
3 * 3 *
4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved 4 * Copyright (C) 2005 Cougar Creek Computing Devices Ltd, All Rights Reserved
5 * 5 *
@@ -11,7 +11,7 @@
11 */ 11 */
12 12
13/* 13/*
14 This is the AT91RM9200 MCI driver that has been tested with both MMC cards 14 This is the AT91 MCI driver that has been tested with both MMC cards
15 and SD-cards. Boards that support write protect are now supported. 15 and SD-cards. Boards that support write protect are now supported.
16 The CCAT91SBC001 board does not support SD cards. 16 The CCAT91SBC001 board does not support SD cards.
17 17
@@ -38,8 +38,8 @@
38 controller to manage the transfers. 38 controller to manage the transfers.
39 39
40 A read is done from the controller directly to the scatterlist passed in from the request. 40 A read is done from the controller directly to the scatterlist passed in from the request.
41 Due to a bug in the controller, when a read is completed, all the words are byte 41 Due to a bug in the AT91RM9200 controller, when a read is completed, all the words are byte
42 swapped in the scatterlist buffers. 42 swapped in the scatterlist buffers. AT91SAM926x are not affected by this bug.
43 43
44 The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY 44 The sequence of read interrupts is: ENDRX, RXBUFF, CMDRDY
45 45
@@ -72,6 +72,7 @@
72#include <asm/irq.h> 72#include <asm/irq.h>
73#include <asm/mach/mmc.h> 73#include <asm/mach/mmc.h>
74#include <asm/arch/board.h> 74#include <asm/arch/board.h>
75#include <asm/arch/cpu.h>
75#include <asm/arch/gpio.h> 76#include <asm/arch/gpio.h>
76#include <asm/arch/at91_mci.h> 77#include <asm/arch/at91_mci.h>
77#include <asm/arch/at91_pdc.h> 78#include <asm/arch/at91_pdc.h>
@@ -80,34 +81,18 @@
80 81
81#undef SUPPORT_4WIRE 82#undef SUPPORT_4WIRE
82 83
83static struct clk *mci_clk; 84#define FL_SENT_COMMAND (1 << 0)
85#define FL_SENT_STOP (1 << 1)
84 86
85#define FL_SENT_COMMAND (1 << 0) 87#define AT91_MCI_ERRORS (AT91_MCI_RINDE | AT91_MCI_RDIRE | AT91_MCI_RCRCE \
86#define FL_SENT_STOP (1 << 1) 88 | AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE \
89 | AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)
87 90
91#define at91_mci_read(host, reg) __raw_readl((host)->baseaddr + (reg))
92#define at91_mci_write(host, reg, val) __raw_writel((val), (host)->baseaddr + (reg))
88 93
89 94
90/* 95/*
91 * Read from a MCI register.
92 */
93static inline unsigned long at91_mci_read(unsigned int reg)
94{
95 void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI;
96
97 return __raw_readl(mci_base + reg);
98}
99
100/*
101 * Write to a MCI register.
102 */
103static inline void at91_mci_write(unsigned int reg, unsigned long value)
104{
105 void __iomem *mci_base = (void __iomem *)AT91_VA_BASE_MCI;
106
107 __raw_writel(value, mci_base + reg);
108}
109
110/*
111 * Low level type for this driver 96 * Low level type for this driver
112 */ 97 */
113struct at91mci_host 98struct at91mci_host
@@ -116,9 +101,14 @@ struct at91mci_host
116 struct mmc_command *cmd; 101 struct mmc_command *cmd;
117 struct mmc_request *request; 102 struct mmc_request *request;
118 103
104 void __iomem *baseaddr;
105 int irq;
106
119 struct at91_mmc_data *board; 107 struct at91_mmc_data *board;
120 int present; 108 int present;
121 109
110 struct clk *mci_clk;
111
122 /* 112 /*
123 * Flag indicating when the command has been sent. This is used to 113 * Flag indicating when the command has been sent. This is used to
124 * work out whether or not to send the stop 114 * work out whether or not to send the stop
@@ -158,7 +148,6 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
158 for (i = 0; i < len; i++) { 148 for (i = 0; i < len; i++) {
159 struct scatterlist *sg; 149 struct scatterlist *sg;
160 int amount; 150 int amount;
161 int index;
162 unsigned int *sgbuffer; 151 unsigned int *sgbuffer;
163 152
164 sg = &data->sg[i]; 153 sg = &data->sg[i];
@@ -166,10 +155,15 @@ static inline void at91mci_sg_to_dma(struct at91mci_host *host, struct mmc_data
166 sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset; 155 sgbuffer = kmap_atomic(sg->page, KM_BIO_SRC_IRQ) + sg->offset;
167 amount = min(size, sg->length); 156 amount = min(size, sg->length);
168 size -= amount; 157 size -= amount;
169 amount /= 4;
170 158
171 for (index = 0; index < amount; index++) 159 if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
172 *dmabuf++ = swab32(sgbuffer[index]); 160 int index;
161
162 for (index = 0; index < (amount / 4); index++)
163 *dmabuf++ = swab32(sgbuffer[index]);
164 }
165 else
166 memcpy(dmabuf, sgbuffer, amount);
173 167
174 kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ); 168 kunmap_atomic(sgbuffer, KM_BIO_SRC_IRQ);
175 169
@@ -217,13 +211,13 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
217 211
218 /* Check to see if this needs filling */ 212 /* Check to see if this needs filling */
219 if (i == 0) { 213 if (i == 0) {
220 if (at91_mci_read(AT91_PDC_RCR) != 0) { 214 if (at91_mci_read(host, AT91_PDC_RCR) != 0) {
221 pr_debug("Transfer active in current\n"); 215 pr_debug("Transfer active in current\n");
222 continue; 216 continue;
223 } 217 }
224 } 218 }
225 else { 219 else {
226 if (at91_mci_read(AT91_PDC_RNCR) != 0) { 220 if (at91_mci_read(host, AT91_PDC_RNCR) != 0) {
227 pr_debug("Transfer active in next\n"); 221 pr_debug("Transfer active in next\n");
228 continue; 222 continue;
229 } 223 }
@@ -240,12 +234,12 @@ static void at91mci_pre_dma_read(struct at91mci_host *host)
240 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length); 234 pr_debug("dma address = %08X, length = %d\n", sg->dma_address, sg->length);
241 235
242 if (i == 0) { 236 if (i == 0) {
243 at91_mci_write(AT91_PDC_RPR, sg->dma_address); 237 at91_mci_write(host, AT91_PDC_RPR, sg->dma_address);
244 at91_mci_write(AT91_PDC_RCR, sg->length / 4); 238 at91_mci_write(host, AT91_PDC_RCR, sg->length / 4);
245 } 239 }
246 else { 240 else {
247 at91_mci_write(AT91_PDC_RNPR, sg->dma_address); 241 at91_mci_write(host, AT91_PDC_RNPR, sg->dma_address);
248 at91_mci_write(AT91_PDC_RNCR, sg->length / 4); 242 at91_mci_write(host, AT91_PDC_RNCR, sg->length / 4);
249 } 243 }
250 } 244 }
251 245
@@ -276,8 +270,6 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
276 270
277 while (host->in_use_index < host->transfer_index) { 271 while (host->in_use_index < host->transfer_index) {
278 unsigned int *buffer; 272 unsigned int *buffer;
279 int index;
280 int len;
281 273
282 struct scatterlist *sg; 274 struct scatterlist *sg;
283 275
@@ -295,11 +287,13 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
295 287
296 data->bytes_xfered += sg->length; 288 data->bytes_xfered += sg->length;
297 289
298 len = sg->length / 4; 290 if (cpu_is_at91rm9200()) { /* AT91RM9200 errata */
291 int index;
299 292
300 for (index = 0; index < len; index++) { 293 for (index = 0; index < (sg->length / 4); index++)
301 buffer[index] = swab32(buffer[index]); 294 buffer[index] = swab32(buffer[index]);
302 } 295 }
296
303 kunmap_atomic(buffer, KM_BIO_SRC_IRQ); 297 kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
304 flush_dcache_page(sg->page); 298 flush_dcache_page(sg->page);
305 } 299 }
@@ -308,8 +302,8 @@ static void at91mci_post_dma_read(struct at91mci_host *host)
308 if (host->transfer_index < data->sg_len) 302 if (host->transfer_index < data->sg_len)
309 at91mci_pre_dma_read(host); 303 at91mci_pre_dma_read(host);
310 else { 304 else {
311 at91_mci_write(AT91_MCI_IER, AT91_MCI_RXBUFF); 305 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_RXBUFF);
312 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 306 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
313 } 307 }
314 308
315 pr_debug("post dma read done\n"); 309 pr_debug("post dma read done\n");
@@ -326,11 +320,11 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
326 pr_debug("Handling the transmit\n"); 320 pr_debug("Handling the transmit\n");
327 321
328 /* Disable the transfer */ 322 /* Disable the transfer */
329 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 323 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
330 324
331 /* Now wait for cmd ready */ 325 /* Now wait for cmd ready */
332 at91_mci_write(AT91_MCI_IDR, AT91_MCI_TXBUFE); 326 at91_mci_write(host, AT91_MCI_IDR, AT91_MCI_TXBUFE);
333 at91_mci_write(AT91_MCI_IER, AT91_MCI_NOTBUSY); 327 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_NOTBUSY);
334 328
335 cmd = host->cmd; 329 cmd = host->cmd;
336 if (!cmd) return; 330 if (!cmd) return;
@@ -344,21 +338,23 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
344/* 338/*
345 * Enable the controller 339 * Enable the controller
346 */ 340 */
347static void at91_mci_enable(void) 341static void at91_mci_enable(struct at91mci_host *host)
348{ 342{
349 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN); 343 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
350 at91_mci_write(AT91_MCI_IDR, 0xFFFFFFFF); 344 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
351 at91_mci_write(AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC); 345 at91_mci_write(host, AT91_MCI_DTOR, AT91_MCI_DTOMUL_1M | AT91_MCI_DTOCYC);
352 at91_mci_write(AT91_MCI_MR, 0x834A); 346 at91_mci_write(host, AT91_MCI_MR, AT91_MCI_PDCMODE | 0x34a);
353 at91_mci_write(AT91_MCI_SDCR, 0x0); 347
348 /* use Slot A or B (only one at same time) */
349 at91_mci_write(host, AT91_MCI_SDCR, host->board->slot_b);
354} 350}
355 351
356/* 352/*
357 * Disable the controller 353 * Disable the controller
358 */ 354 */
359static void at91_mci_disable(void) 355static void at91_mci_disable(struct at91mci_host *host)
360{ 356{
361 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST); 357 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS | AT91_MCI_SWRST);
362} 358}
363 359
364/* 360/*
@@ -378,13 +374,13 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
378 374
379 /* Not sure if this is needed */ 375 /* Not sure if this is needed */
380#if 0 376#if 0
381 if ((at91_mci_read(AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) { 377 if ((at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_RTOE) && (cmd->opcode == 1)) {
382 pr_debug("Clearing timeout\n"); 378 pr_debug("Clearing timeout\n");
383 at91_mci_write(AT91_MCI_ARGR, 0); 379 at91_mci_write(host, AT91_MCI_ARGR, 0);
384 at91_mci_write(AT91_MCI_CMDR, AT91_MCI_OPDCMD); 380 at91_mci_write(host, AT91_MCI_CMDR, AT91_MCI_OPDCMD);
385 while (!(at91_mci_read(AT91_MCI_SR) & AT91_MCI_CMDRDY)) { 381 while (!(at91_mci_read(host, AT91_MCI_SR) & AT91_MCI_CMDRDY)) {
386 /* spin */ 382 /* spin */
387 pr_debug("Clearing: SR = %08X\n", at91_mci_read(AT91_MCI_SR)); 383 pr_debug("Clearing: SR = %08X\n", at91_mci_read(host, AT91_MCI_SR));
388 } 384 }
389 } 385 }
390#endif 386#endif
@@ -431,32 +427,32 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
431 /* 427 /*
432 * Set the arguments and send the command 428 * Set the arguments and send the command
433 */ 429 */
434 pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08lX)\n", 430 pr_debug("Sending command %d as %08X, arg = %08X, blocks = %d, length = %d (MR = %08X)\n",
435 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(AT91_MCI_MR)); 431 cmd->opcode, cmdr, cmd->arg, blocks, block_length, at91_mci_read(host, AT91_MCI_MR));
436 432
437 if (!data) { 433 if (!data) {
438 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS); 434 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTDIS | AT91_PDC_RXTDIS);
439 at91_mci_write(AT91_PDC_RPR, 0); 435 at91_mci_write(host, AT91_PDC_RPR, 0);
440 at91_mci_write(AT91_PDC_RCR, 0); 436 at91_mci_write(host, AT91_PDC_RCR, 0);
441 at91_mci_write(AT91_PDC_RNPR, 0); 437 at91_mci_write(host, AT91_PDC_RNPR, 0);
442 at91_mci_write(AT91_PDC_RNCR, 0); 438 at91_mci_write(host, AT91_PDC_RNCR, 0);
443 at91_mci_write(AT91_PDC_TPR, 0); 439 at91_mci_write(host, AT91_PDC_TPR, 0);
444 at91_mci_write(AT91_PDC_TCR, 0); 440 at91_mci_write(host, AT91_PDC_TCR, 0);
445 at91_mci_write(AT91_PDC_TNPR, 0); 441 at91_mci_write(host, AT91_PDC_TNPR, 0);
446 at91_mci_write(AT91_PDC_TNCR, 0); 442 at91_mci_write(host, AT91_PDC_TNCR, 0);
447 443
448 at91_mci_write(AT91_MCI_ARGR, cmd->arg); 444 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
449 at91_mci_write(AT91_MCI_CMDR, cmdr); 445 at91_mci_write(host, AT91_MCI_CMDR, cmdr);
450 return AT91_MCI_CMDRDY; 446 return AT91_MCI_CMDRDY;
451 } 447 }
452 448
453 mr = at91_mci_read(AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */ 449 mr = at91_mci_read(host, AT91_MCI_MR) & 0x7fff; /* zero block length and PDC mode */
454 at91_mci_write(AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE); 450 at91_mci_write(host, AT91_MCI_MR, mr | (block_length << 16) | AT91_MCI_PDCMODE);
455 451
456 /* 452 /*
457 * Disable the PDC controller 453 * Disable the PDC controller
458 */ 454 */
459 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS); 455 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTDIS | AT91_PDC_TXTDIS);
460 456
461 if (cmdr & AT91_MCI_TRCMD_START) { 457 if (cmdr & AT91_MCI_TRCMD_START) {
462 data->bytes_xfered = 0; 458 data->bytes_xfered = 0;
@@ -485,8 +481,8 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
485 481
486 pr_debug("Transmitting %d bytes\n", host->total_length); 482 pr_debug("Transmitting %d bytes\n", host->total_length);
487 483
488 at91_mci_write(AT91_PDC_TPR, host->physical_address); 484 at91_mci_write(host, AT91_PDC_TPR, host->physical_address);
489 at91_mci_write(AT91_PDC_TCR, host->total_length / 4); 485 at91_mci_write(host, AT91_PDC_TCR, host->total_length / 4);
490 ier = AT91_MCI_TXBUFE; 486 ier = AT91_MCI_TXBUFE;
491 } 487 }
492 } 488 }
@@ -496,14 +492,14 @@ static unsigned int at91_mci_send_command(struct at91mci_host *host, struct mmc_
496 * the data sheet says 492 * the data sheet says
497 */ 493 */
498 494
499 at91_mci_write(AT91_MCI_ARGR, cmd->arg); 495 at91_mci_write(host, AT91_MCI_ARGR, cmd->arg);
500 at91_mci_write(AT91_MCI_CMDR, cmdr); 496 at91_mci_write(host, AT91_MCI_CMDR, cmdr);
501 497
502 if (cmdr & AT91_MCI_TRCMD_START) { 498 if (cmdr & AT91_MCI_TRCMD_START) {
503 if (cmdr & AT91_MCI_TRDIR) 499 if (cmdr & AT91_MCI_TRDIR)
504 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_RXTEN); 500 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_RXTEN);
505 else 501 else
506 at91_mci_write(AT91_PDC_PTCR, AT91_PDC_TXTEN); 502 at91_mci_write(host, AT91_PDC_PTCR, AT91_PDC_TXTEN);
507 } 503 }
508 return ier; 504 return ier;
509} 505}
@@ -520,7 +516,7 @@ static void at91mci_process_command(struct at91mci_host *host, struct mmc_comman
520 pr_debug("setting ier to %08X\n", ier); 516 pr_debug("setting ier to %08X\n", ier);
521 517
522 /* Stop on errors or the required value */ 518 /* Stop on errors or the required value */
523 at91_mci_write(AT91_MCI_IER, 0xffff0000 | ier); 519 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_ERRORS | ier);
524} 520}
525 521
526/* 522/*
@@ -548,19 +544,19 @@ static void at91mci_completed_command(struct at91mci_host *host)
548 struct mmc_command *cmd = host->cmd; 544 struct mmc_command *cmd = host->cmd;
549 unsigned int status; 545 unsigned int status;
550 546
551 at91_mci_write(AT91_MCI_IDR, 0xffffffff); 547 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
552 548
553 cmd->resp[0] = at91_mci_read(AT91_MCI_RSPR(0)); 549 cmd->resp[0] = at91_mci_read(host, AT91_MCI_RSPR(0));
554 cmd->resp[1] = at91_mci_read(AT91_MCI_RSPR(1)); 550 cmd->resp[1] = at91_mci_read(host, AT91_MCI_RSPR(1));
555 cmd->resp[2] = at91_mci_read(AT91_MCI_RSPR(2)); 551 cmd->resp[2] = at91_mci_read(host, AT91_MCI_RSPR(2));
556 cmd->resp[3] = at91_mci_read(AT91_MCI_RSPR(3)); 552 cmd->resp[3] = at91_mci_read(host, AT91_MCI_RSPR(3));
557 553
558 if (host->buffer) { 554 if (host->buffer) {
559 dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address); 555 dma_free_coherent(NULL, host->total_length, host->buffer, host->physical_address);
560 host->buffer = NULL; 556 host->buffer = NULL;
561 } 557 }
562 558
563 status = at91_mci_read(AT91_MCI_SR); 559 status = at91_mci_read(host, AT91_MCI_SR);
564 560
565 pr_debug("Status = %08X [%08X %08X %08X %08X]\n", 561 pr_debug("Status = %08X [%08X %08X %08X %08X]\n",
566 status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); 562 status, cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
@@ -611,18 +607,18 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
611{ 607{
612 int clkdiv; 608 int clkdiv;
613 struct at91mci_host *host = mmc_priv(mmc); 609 struct at91mci_host *host = mmc_priv(mmc);
614 unsigned long at91_master_clock = clk_get_rate(mci_clk); 610 unsigned long at91_master_clock = clk_get_rate(host->mci_clk);
615 611
616 host->bus_mode = ios->bus_mode; 612 host->bus_mode = ios->bus_mode;
617 613
618 if (ios->clock == 0) { 614 if (ios->clock == 0) {
619 /* Disable the MCI controller */ 615 /* Disable the MCI controller */
620 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIDIS); 616 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIDIS);
621 clkdiv = 0; 617 clkdiv = 0;
622 } 618 }
623 else { 619 else {
624 /* Enable the MCI controller */ 620 /* Enable the MCI controller */
625 at91_mci_write(AT91_MCI_CR, AT91_MCI_MCIEN); 621 at91_mci_write(host, AT91_MCI_CR, AT91_MCI_MCIEN);
626 622
627 if ((at91_master_clock % (ios->clock * 2)) == 0) 623 if ((at91_master_clock % (ios->clock * 2)) == 0)
628 clkdiv = ((at91_master_clock / ios->clock) / 2) - 1; 624 clkdiv = ((at91_master_clock / ios->clock) / 2) - 1;
@@ -634,25 +630,25 @@ static void at91_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
634 } 630 }
635 if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) { 631 if (ios->bus_width == MMC_BUS_WIDTH_4 && host->board->wire4) {
636 pr_debug("MMC: Setting controller bus width to 4\n"); 632 pr_debug("MMC: Setting controller bus width to 4\n");
637 at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) | AT91_MCI_SDCBUS); 633 at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) | AT91_MCI_SDCBUS);
638 } 634 }
639 else { 635 else {
640 pr_debug("MMC: Setting controller bus width to 1\n"); 636 pr_debug("MMC: Setting controller bus width to 1\n");
641 at91_mci_write(AT91_MCI_SDCR, at91_mci_read(AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS); 637 at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
642 } 638 }
643 639
644 /* Set the clock divider */ 640 /* Set the clock divider */
645 at91_mci_write(AT91_MCI_MR, (at91_mci_read(AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv); 641 at91_mci_write(host, AT91_MCI_MR, (at91_mci_read(host, AT91_MCI_MR) & ~AT91_MCI_CLKDIV) | clkdiv);
646 642
647 /* maybe switch power to the card */ 643 /* maybe switch power to the card */
648 if (host->board->vcc_pin) { 644 if (host->board->vcc_pin) {
649 switch (ios->power_mode) { 645 switch (ios->power_mode) {
650 case MMC_POWER_OFF: 646 case MMC_POWER_OFF:
651 at91_set_gpio_output(host->board->vcc_pin, 0); 647 at91_set_gpio_value(host->board->vcc_pin, 0);
652 break; 648 break;
653 case MMC_POWER_UP: 649 case MMC_POWER_UP:
654 case MMC_POWER_ON: 650 case MMC_POWER_ON:
655 at91_set_gpio_output(host->board->vcc_pin, 1); 651 at91_set_gpio_value(host->board->vcc_pin, 1);
656 break; 652 break;
657 } 653 }
658 } 654 }
@@ -665,39 +661,40 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
665{ 661{
666 struct at91mci_host *host = devid; 662 struct at91mci_host *host = devid;
667 int completed = 0; 663 int completed = 0;
664 unsigned int int_status, int_mask;
668 665
669 unsigned int int_status; 666 int_status = at91_mci_read(host, AT91_MCI_SR);
667 int_mask = at91_mci_read(host, AT91_MCI_IMR);
668
669 pr_debug("MCI irq: status = %08X, %08X, %08X\n", int_status, int_mask,
670 int_status & int_mask);
671
672 int_status = int_status & int_mask;
670 673
671 int_status = at91_mci_read(AT91_MCI_SR); 674 if (int_status & AT91_MCI_ERRORS) {
672 pr_debug("MCI irq: status = %08X, %08lX, %08lX\n", int_status, at91_mci_read(AT91_MCI_IMR),
673 int_status & at91_mci_read(AT91_MCI_IMR));
674
675 if ((int_status & at91_mci_read(AT91_MCI_IMR)) & 0xffff0000)
676 completed = 1; 675 completed = 1;
676
677 if (int_status & AT91_MCI_UNRE)
678 pr_debug("MMC: Underrun error\n");
679 if (int_status & AT91_MCI_OVRE)
680 pr_debug("MMC: Overrun error\n");
681 if (int_status & AT91_MCI_DTOE)
682 pr_debug("MMC: Data timeout\n");
683 if (int_status & AT91_MCI_DCRCE)
684 pr_debug("MMC: CRC error in data\n");
685 if (int_status & AT91_MCI_RTOE)
686 pr_debug("MMC: Response timeout\n");
687 if (int_status & AT91_MCI_RENDE)
688 pr_debug("MMC: Response end bit error\n");
689 if (int_status & AT91_MCI_RCRCE)
690 pr_debug("MMC: Response CRC error\n");
691 if (int_status & AT91_MCI_RDIRE)
692 pr_debug("MMC: Response direction error\n");
693 if (int_status & AT91_MCI_RINDE)
694 pr_debug("MMC: Response index error\n");
695 } else {
696 /* Only continue processing if no errors */
677 697
678 int_status &= at91_mci_read(AT91_MCI_IMR);
679
680 if (int_status & AT91_MCI_UNRE)
681 pr_debug("MMC: Underrun error\n");
682 if (int_status & AT91_MCI_OVRE)
683 pr_debug("MMC: Overrun error\n");
684 if (int_status & AT91_MCI_DTOE)
685 pr_debug("MMC: Data timeout\n");
686 if (int_status & AT91_MCI_DCRCE)
687 pr_debug("MMC: CRC error in data\n");
688 if (int_status & AT91_MCI_RTOE)
689 pr_debug("MMC: Response timeout\n");
690 if (int_status & AT91_MCI_RENDE)
691 pr_debug("MMC: Response end bit error\n");
692 if (int_status & AT91_MCI_RCRCE)
693 pr_debug("MMC: Response CRC error\n");
694 if (int_status & AT91_MCI_RDIRE)
695 pr_debug("MMC: Response direction error\n");
696 if (int_status & AT91_MCI_RINDE)
697 pr_debug("MMC: Response index error\n");
698
699 /* Only continue processing if no errors */
700 if (!completed) {
701 if (int_status & AT91_MCI_TXBUFE) { 698 if (int_status & AT91_MCI_TXBUFE) {
702 pr_debug("TX buffer empty\n"); 699 pr_debug("TX buffer empty\n");
703 at91_mci_handle_transmitted(host); 700 at91_mci_handle_transmitted(host);
@@ -705,12 +702,11 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
705 702
706 if (int_status & AT91_MCI_RXBUFF) { 703 if (int_status & AT91_MCI_RXBUFF) {
707 pr_debug("RX buffer full\n"); 704 pr_debug("RX buffer full\n");
708 at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY); 705 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
709 } 706 }
710 707
711 if (int_status & AT91_MCI_ENDTX) { 708 if (int_status & AT91_MCI_ENDTX)
712 pr_debug("Transmit has ended\n"); 709 pr_debug("Transmit has ended\n");
713 }
714 710
715 if (int_status & AT91_MCI_ENDRX) { 711 if (int_status & AT91_MCI_ENDRX) {
716 pr_debug("Receive has ended\n"); 712 pr_debug("Receive has ended\n");
@@ -719,37 +715,33 @@ static irqreturn_t at91_mci_irq(int irq, void *devid)
719 715
720 if (int_status & AT91_MCI_NOTBUSY) { 716 if (int_status & AT91_MCI_NOTBUSY) {
721 pr_debug("Card is ready\n"); 717 pr_debug("Card is ready\n");
722 at91_mci_write(AT91_MCI_IER, AT91_MCI_CMDRDY); 718 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_CMDRDY);
723 } 719 }
724 720
725 if (int_status & AT91_MCI_DTIP) { 721 if (int_status & AT91_MCI_DTIP)
726 pr_debug("Data transfer in progress\n"); 722 pr_debug("Data transfer in progress\n");
727 }
728 723
729 if (int_status & AT91_MCI_BLKE) { 724 if (int_status & AT91_MCI_BLKE)
730 pr_debug("Block transfer has ended\n"); 725 pr_debug("Block transfer has ended\n");
731 }
732 726
733 if (int_status & AT91_MCI_TXRDY) { 727 if (int_status & AT91_MCI_TXRDY)
734 pr_debug("Ready to transmit\n"); 728 pr_debug("Ready to transmit\n");
735 }
736 729
737 if (int_status & AT91_MCI_RXRDY) { 730 if (int_status & AT91_MCI_RXRDY)
738 pr_debug("Ready to receive\n"); 731 pr_debug("Ready to receive\n");
739 }
740 732
741 if (int_status & AT91_MCI_CMDRDY) { 733 if (int_status & AT91_MCI_CMDRDY) {
742 pr_debug("Command ready\n"); 734 pr_debug("Command ready\n");
743 completed = 1; 735 completed = 1;
744 } 736 }
745 } 737 }
746 at91_mci_write(AT91_MCI_IDR, int_status);
747 738
748 if (completed) { 739 if (completed) {
749 pr_debug("Completed command\n"); 740 pr_debug("Completed command\n");
750 at91_mci_write(AT91_MCI_IDR, 0xffffffff); 741 at91_mci_write(host, AT91_MCI_IDR, 0xffffffff);
751 at91mci_completed_command(host); 742 at91mci_completed_command(host);
752 } 743 } else
744 at91_mci_write(host, AT91_MCI_IDR, int_status);
753 745
754 return IRQ_HANDLED; 746 return IRQ_HANDLED;
755} 747}
@@ -769,7 +761,7 @@ static irqreturn_t at91_mmc_det_irq(int irq, void *_host)
769 present ? "insert" : "remove"); 761 present ? "insert" : "remove");
770 if (!present) { 762 if (!present) {
771 pr_debug("****** Resetting SD-card bus width ******\n"); 763 pr_debug("****** Resetting SD-card bus width ******\n");
772 at91_mci_write(AT91_MCI_SDCR, 0); 764 at91_mci_write(host, AT91_MCI_SDCR, at91_mci_read(host, AT91_MCI_SDCR) & ~AT91_MCI_SDCBUS);
773 } 765 }
774 mmc_detect_change(host->mmc, msecs_to_jiffies(100)); 766 mmc_detect_change(host->mmc, msecs_to_jiffies(100));
775 } 767 }
@@ -806,15 +798,22 @@ static int at91_mci_probe(struct platform_device *pdev)
806{ 798{
807 struct mmc_host *mmc; 799 struct mmc_host *mmc;
808 struct at91mci_host *host; 800 struct at91mci_host *host;
801 struct resource *res;
809 int ret; 802 int ret;
810 803
811 pr_debug("Probe MCI devices\n"); 804 pr_debug("Probe MCI devices\n");
812 at91_mci_disable(); 805
813 at91_mci_enable(); 806 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
807 if (!res)
808 return -ENXIO;
809
810 if (!request_mem_region(res->start, res->end - res->start + 1, DRIVER_NAME))
811 return -EBUSY;
814 812
815 mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev); 813 mmc = mmc_alloc_host(sizeof(struct at91mci_host), &pdev->dev);
816 if (!mmc) { 814 if (!mmc) {
817 pr_debug("Failed to allocate mmc host\n"); 815 pr_debug("Failed to allocate mmc host\n");
816 release_mem_region(res->start, res->end - res->start + 1);
818 return -ENOMEM; 817 return -ENOMEM;
819 } 818 }
820 819
@@ -833,30 +832,51 @@ static int at91_mci_probe(struct platform_device *pdev)
833#ifdef SUPPORT_4WIRE 832#ifdef SUPPORT_4WIRE
834 mmc->caps |= MMC_CAP_4_BIT_DATA; 833 mmc->caps |= MMC_CAP_4_BIT_DATA;
835#else 834#else
836 printk("MMC: 4 wire bus mode not supported by this driver - using 1 wire\n"); 835 printk("AT91 MMC: 4 wire bus mode not supported by this driver - using 1 wire\n");
837#endif 836#endif
838 } 837 }
839 838
840 /* 839 /*
841 * Get Clock 840 * Get Clock
842 */ 841 */
843 mci_clk = clk_get(&pdev->dev, "mci_clk"); 842 host->mci_clk = clk_get(&pdev->dev, "mci_clk");
844 if (IS_ERR(mci_clk)) { 843 if (IS_ERR(host->mci_clk)) {
845 printk(KERN_ERR "AT91 MMC: no clock defined.\n"); 844 printk(KERN_ERR "AT91 MMC: no clock defined.\n");
846 mmc_free_host(mmc); 845 mmc_free_host(mmc);
846 release_mem_region(res->start, res->end - res->start + 1);
847 return -ENODEV; 847 return -ENODEV;
848 } 848 }
849 clk_enable(mci_clk); /* Enable the peripheral clock */ 849
850 /*
851 * Map I/O region
852 */
853 host->baseaddr = ioremap(res->start, res->end - res->start + 1);
854 if (!host->baseaddr) {
855 clk_put(host->mci_clk);
856 mmc_free_host(mmc);
857 release_mem_region(res->start, res->end - res->start + 1);
858 return -ENOMEM;
859 }
860
861 /*
862 * Reset hardware
863 */
864 clk_enable(host->mci_clk); /* Enable the peripheral clock */
865 at91_mci_disable(host);
866 at91_mci_enable(host);
850 867
851 /* 868 /*
852 * Allocate the MCI interrupt 869 * Allocate the MCI interrupt
853 */ 870 */
854 ret = request_irq(AT91RM9200_ID_MCI, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host); 871 host->irq = platform_get_irq(pdev, 0);
872 ret = request_irq(host->irq, at91_mci_irq, IRQF_SHARED, DRIVER_NAME, host);
855 if (ret) { 873 if (ret) {
856 printk(KERN_ERR "Failed to request MCI interrupt\n"); 874 printk(KERN_ERR "AT91 MMC: Failed to request MCI interrupt\n");
857 clk_disable(mci_clk); 875 clk_disable(host->mci_clk);
858 clk_put(mci_clk); 876 clk_put(host->mci_clk);
859 mmc_free_host(mmc); 877 mmc_free_host(mmc);
878 iounmap(host->baseaddr);
879 release_mem_region(res->start, res->end - res->start + 1);
860 return ret; 880 return ret;
861 } 881 }
862 882
@@ -879,10 +899,10 @@ static int at91_mci_probe(struct platform_device *pdev)
879 ret = request_irq(host->board->det_pin, at91_mmc_det_irq, 899 ret = request_irq(host->board->det_pin, at91_mmc_det_irq,
880 0, DRIVER_NAME, host); 900 0, DRIVER_NAME, host);
881 if (ret) 901 if (ret)
882 printk(KERN_ERR "couldn't allocate MMC detect irq\n"); 902 printk(KERN_ERR "AT91 MMC: Couldn't allocate MMC detect irq\n");
883 } 903 }
884 904
885 pr_debug(KERN_INFO "Added MCI driver\n"); 905 pr_debug("Added MCI driver\n");
886 906
887 return 0; 907 return 0;
888} 908}
@@ -894,6 +914,7 @@ static int at91_mci_remove(struct platform_device *pdev)
894{ 914{
895 struct mmc_host *mmc = platform_get_drvdata(pdev); 915 struct mmc_host *mmc = platform_get_drvdata(pdev);
896 struct at91mci_host *host; 916 struct at91mci_host *host;
917 struct resource *res;
897 918
898 if (!mmc) 919 if (!mmc)
899 return -1; 920 return -1;
@@ -905,16 +926,19 @@ static int at91_mci_remove(struct platform_device *pdev)
905 cancel_delayed_work(&host->mmc->detect); 926 cancel_delayed_work(&host->mmc->detect);
906 } 927 }
907 928
929 at91_mci_disable(host);
908 mmc_remove_host(mmc); 930 mmc_remove_host(mmc);
909 at91_mci_disable(); 931 free_irq(host->irq, host);
910 free_irq(AT91RM9200_ID_MCI, host);
911 mmc_free_host(mmc);
912 932
913 clk_disable(mci_clk); /* Disable the peripheral clock */ 933 clk_disable(host->mci_clk); /* Disable the peripheral clock */
914 clk_put(mci_clk); 934 clk_put(host->mci_clk);
915 935
916 platform_set_drvdata(pdev, NULL); 936 iounmap(host->baseaddr);
937 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
938 release_mem_region(res->start, res->end - res->start + 1);
917 939
940 mmc_free_host(mmc);
941 platform_set_drvdata(pdev, NULL);
918 pr_debug("MCI Removed\n"); 942 pr_debug("MCI Removed\n");
919 943
920 return 0; 944 return 0;
diff --git a/drivers/mmc/au1xmmc.c b/drivers/mmc/au1xmmc.c
index 447fba5825fd..800527cf40d5 100644
--- a/drivers/mmc/au1xmmc.c
+++ b/drivers/mmc/au1xmmc.c
@@ -875,7 +875,7 @@ static void au1xmmc_init_dma(struct au1xmmc_host *host)
875 host->rx_chan = rxchan; 875 host->rx_chan = rxchan;
876} 876}
877 877
878struct const mmc_host_ops au1xmmc_ops = { 878static const struct mmc_host_ops au1xmmc_ops = {
879 .request = au1xmmc_request, 879 .request = au1xmmc_request,
880 .set_ios = au1xmmc_set_ios, 880 .set_ios = au1xmmc_set_ios,
881}; 881};
diff --git a/drivers/mmc/mmc_queue.c b/drivers/mmc/mmc_queue.c
index a17423a4ed8f..3e35a43819fb 100644
--- a/drivers/mmc/mmc_queue.c
+++ b/drivers/mmc/mmc_queue.c
@@ -78,8 +78,10 @@ static int mmc_queue_thread(void *d)
78 spin_unlock_irq(q->queue_lock); 78 spin_unlock_irq(q->queue_lock);
79 79
80 if (!req) { 80 if (!req) {
81 if (kthread_should_stop()) 81 if (kthread_should_stop()) {
82 set_current_state(TASK_RUNNING);
82 break; 83 break;
84 }
83 up(&mq->thread_sem); 85 up(&mq->thread_sem);
84 schedule(); 86 schedule();
85 down(&mq->thread_sem); 87 down(&mq->thread_sem);
diff --git a/drivers/mmc/pxamci.c b/drivers/mmc/pxamci.c
index 471e9f4e0530..45a9283ce498 100644
--- a/drivers/mmc/pxamci.c
+++ b/drivers/mmc/pxamci.c
@@ -355,7 +355,7 @@ static int pxamci_get_ro(struct mmc_host *mmc)
355 struct pxamci_host *host = mmc_priv(mmc); 355 struct pxamci_host *host = mmc_priv(mmc);
356 356
357 if (host->pdata && host->pdata->get_ro) 357 if (host->pdata && host->pdata->get_ro)
358 return host->pdata->get_ro(mmc->dev); 358 return host->pdata->get_ro(mmc_dev(mmc));
359 /* Host doesn't support read only detection so assume writeable */ 359 /* Host doesn't support read only detection so assume writeable */
360 return 0; 360 return 0;
361} 361}
@@ -383,7 +383,7 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
383 host->power_mode = ios->power_mode; 383 host->power_mode = ios->power_mode;
384 384
385 if (host->pdata && host->pdata->setpower) 385 if (host->pdata && host->pdata->setpower)
386 host->pdata->setpower(mmc->dev, ios->vdd); 386 host->pdata->setpower(mmc_dev(mmc), ios->vdd);
387 387
388 if (ios->power_mode == MMC_POWER_ON) 388 if (ios->power_mode == MMC_POWER_ON)
389 host->cmdat |= CMDAT_INIT; 389 host->cmdat |= CMDAT_INIT;
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index cd98117632d3..c2d13d7e9911 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -1170,8 +1170,8 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1170 } 1170 }
1171 1171
1172 if (pci_resource_len(pdev, first_bar + slot) != 0x100) { 1172 if (pci_resource_len(pdev, first_bar + slot) != 0x100) {
1173 printk(KERN_ERR DRIVER_NAME ": Invalid iomem size. Aborting.\n"); 1173 printk(KERN_ERR DRIVER_NAME ": Invalid iomem size. "
1174 return -ENODEV; 1174 "You may experience problems.\n");
1175 } 1175 }
1176 1176
1177 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) { 1177 if ((pdev->class & 0x0000FF) == PCI_SDHCI_IFVENDOR) {
diff --git a/drivers/mmc/tifm_sd.c b/drivers/mmc/tifm_sd.c
index e846499a004c..f18ad998b3cb 100644
--- a/drivers/mmc/tifm_sd.c
+++ b/drivers/mmc/tifm_sd.c
@@ -387,7 +387,7 @@ static void tifm_sd_prepare_data(struct tifm_sd *card, struct mmc_command *cmd)
387 387
388 writel(TIFM_FIFO_INT_SETALL, 388 writel(TIFM_FIFO_INT_SETALL,
389 sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); 389 sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
390 writel(long_log2(cmd->data->blksz) - 2, 390 writel(ilog2(cmd->data->blksz) - 2,
391 sock->addr + SOCK_FIFO_PAGE_SIZE); 391 sock->addr + SOCK_FIFO_PAGE_SIZE);
392 writel(TIFM_FIFO_ENABLE, sock->addr + SOCK_FIFO_CONTROL); 392 writel(TIFM_FIFO_ENABLE, sock->addr + SOCK_FIFO_CONTROL);
393 writel(TIFM_FIFO_INTMASK, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET); 393 writel(TIFM_FIFO_INTMASK, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET);
diff --git a/drivers/net/7990.c b/drivers/net/7990.c
index 7733697f7776..2d5ba076471c 100644
--- a/drivers/net/7990.c
+++ b/drivers/net/7990.c
@@ -500,7 +500,7 @@ int lance_open (struct net_device *dev)
500 int res; 500 int res;
501 501
502 /* Install the Interrupt handler. Or we could shunt this out to specific drivers? */ 502 /* Install the Interrupt handler. Or we could shunt this out to specific drivers? */
503 if (request_irq(lp->irq, lance_interrupt, 0, lp->name, dev)) 503 if (request_irq(lp->irq, lance_interrupt, SA_SHIRQ, lp->name, dev))
504 return -EAGAIN; 504 return -EAGAIN;
505 505
506 res = lance_reset(dev); 506 res = lance_reset(dev);
diff --git a/drivers/net/8139too.c b/drivers/net/8139too.c
index 931028f672de..35ad5cff18e6 100644
--- a/drivers/net/8139too.c
+++ b/drivers/net/8139too.c
@@ -2131,14 +2131,15 @@ static int rtl8139_poll(struct net_device *dev, int *budget)
2131 } 2131 }
2132 2132
2133 if (done) { 2133 if (done) {
2134 unsigned long flags;
2134 /* 2135 /*
2135 * Order is important since data can get interrupted 2136 * Order is important since data can get interrupted
2136 * again when we think we are done. 2137 * again when we think we are done.
2137 */ 2138 */
2138 local_irq_disable(); 2139 local_irq_save(flags);
2139 RTL_W16_F(IntrMask, rtl8139_intr_mask); 2140 RTL_W16_F(IntrMask, rtl8139_intr_mask);
2140 __netif_rx_complete(dev); 2141 __netif_rx_complete(dev);
2141 local_irq_enable(); 2142 local_irq_restore(flags);
2142 } 2143 }
2143 spin_unlock(&tp->rx_lock); 2144 spin_unlock(&tp->rx_lock);
2144 2145
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 9de0eed6755b..8aa8dd02b910 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2384,6 +2384,14 @@ config CHELSIO_T1_1G
2384 Enables support for Chelsio's gigabit Ethernet PCI cards. If you 2384 Enables support for Chelsio's gigabit Ethernet PCI cards. If you
2385 are using only 10G cards say 'N' here. 2385 are using only 10G cards say 'N' here.
2386 2386
2387config CHELSIO_T1_NAPI
2388 bool "Use Rx Polling (NAPI)"
2389 depends on CHELSIO_T1
2390 default y
2391 help
2392 NAPI is a driver API designed to reduce CPU and interrupt load
2393 when the driver is receiving lots of packets from the card.
2394
2387config EHEA 2395config EHEA
2388 tristate "eHEA Ethernet support" 2396 tristate "eHEA Ethernet support"
2389 depends on IBMEBUS 2397 depends on IBMEBUS
diff --git a/drivers/net/apne.c b/drivers/net/apne.c
index d4e408169073..954191119d35 100644
--- a/drivers/net/apne.c
+++ b/drivers/net/apne.c
@@ -311,9 +311,10 @@ static int __init apne_probe1(struct net_device *dev, int ioaddr)
311#endif 311#endif
312 312
313 dev->base_addr = ioaddr; 313 dev->base_addr = ioaddr;
314 dev->irq = IRQ_AMIGA_PORTS;
314 315
315 /* Install the Interrupt handler */ 316 /* Install the Interrupt handler */
316 i = request_irq(IRQ_AMIGA_PORTS, apne_interrupt, IRQF_SHARED, DRV_NAME, dev); 317 i = request_irq(dev->irq, apne_interrupt, IRQF_SHARED, DRV_NAME, dev);
317 if (i) return i; 318 if (i) return i;
318 319
319 for(i = 0; i < ETHER_ADDR_LEN; i++) { 320 for(i = 0; i < ETHER_ADDR_LEN; i++) {
diff --git a/drivers/net/bnx2.c b/drivers/net/bnx2.c
index 5bacb7587df4..7d824cf8ee2d 100644
--- a/drivers/net/bnx2.c
+++ b/drivers/net/bnx2.c
@@ -2510,7 +2510,7 @@ bnx2_init_cpus(struct bnx2 *bp)
2510 if (CHIP_NUM(bp) == CHIP_NUM_5709) { 2510 if (CHIP_NUM(bp) == CHIP_NUM_5709) {
2511 fw = &bnx2_cp_fw_09; 2511 fw = &bnx2_cp_fw_09;
2512 2512
2513 load_cpu_fw(bp, &cpu_reg, fw); 2513 rc = load_cpu_fw(bp, &cpu_reg, fw);
2514 if (rc) 2514 if (rc)
2515 goto init_cpu_err; 2515 goto init_cpu_err;
2516 } 2516 }
diff --git a/drivers/net/chelsio/cxgb2.c b/drivers/net/chelsio/cxgb2.c
index de48eadddbc4..fd5d821f3f2a 100644
--- a/drivers/net/chelsio/cxgb2.c
+++ b/drivers/net/chelsio/cxgb2.c
@@ -220,9 +220,8 @@ static int cxgb_up(struct adapter *adapter)
220 220
221 t1_interrupts_clear(adapter); 221 t1_interrupts_clear(adapter);
222 222
223 adapter->params.has_msi = !disable_msi && pci_enable_msi(adapter->pdev) == 0; 223 adapter->params.has_msi = !disable_msi && !pci_enable_msi(adapter->pdev);
224 err = request_irq(adapter->pdev->irq, 224 err = request_irq(adapter->pdev->irq, t1_interrupt,
225 t1_select_intr_handler(adapter),
226 adapter->params.has_msi ? 0 : IRQF_SHARED, 225 adapter->params.has_msi ? 0 : IRQF_SHARED,
227 adapter->name, adapter); 226 adapter->name, adapter);
228 if (err) { 227 if (err) {
@@ -764,18 +763,7 @@ static int set_coalesce(struct net_device *dev, struct ethtool_coalesce *c)
764{ 763{
765 struct adapter *adapter = dev->priv; 764 struct adapter *adapter = dev->priv;
766 765
767 /* 766 adapter->params.sge.rx_coalesce_usecs = c->rx_coalesce_usecs;
768 * If RX coalescing is requested we use NAPI, otherwise interrupts.
769 * This choice can be made only when all ports and the TOE are off.
770 */
771 if (adapter->open_device_map == 0)
772 adapter->params.sge.polling = c->use_adaptive_rx_coalesce;
773
774 if (adapter->params.sge.polling) {
775 adapter->params.sge.rx_coalesce_usecs = 0;
776 } else {
777 adapter->params.sge.rx_coalesce_usecs = c->rx_coalesce_usecs;
778 }
779 adapter->params.sge.coalesce_enable = c->use_adaptive_rx_coalesce; 767 adapter->params.sge.coalesce_enable = c->use_adaptive_rx_coalesce;
780 adapter->params.sge.sample_interval_usecs = c->rate_sample_interval; 768 adapter->params.sge.sample_interval_usecs = c->rate_sample_interval;
781 t1_sge_set_coalesce_params(adapter->sge, &adapter->params.sge); 769 t1_sge_set_coalesce_params(adapter->sge, &adapter->params.sge);
@@ -944,7 +932,7 @@ static void t1_netpoll(struct net_device *dev)
944 struct adapter *adapter = dev->priv; 932 struct adapter *adapter = dev->priv;
945 933
946 local_irq_save(flags); 934 local_irq_save(flags);
947 t1_select_intr_handler(adapter)(adapter->pdev->irq, adapter); 935 t1_interrupt(adapter->pdev->irq, adapter);
948 local_irq_restore(flags); 936 local_irq_restore(flags);
949} 937}
950#endif 938#endif
@@ -1165,7 +1153,10 @@ static int __devinit init_one(struct pci_dev *pdev,
1165#ifdef CONFIG_NET_POLL_CONTROLLER 1153#ifdef CONFIG_NET_POLL_CONTROLLER
1166 netdev->poll_controller = t1_netpoll; 1154 netdev->poll_controller = t1_netpoll;
1167#endif 1155#endif
1156#ifdef CONFIG_CHELSIO_T1_NAPI
1168 netdev->weight = 64; 1157 netdev->weight = 64;
1158 netdev->poll = t1_poll;
1159#endif
1169 1160
1170 SET_ETHTOOL_OPS(netdev, &t1_ethtool_ops); 1161 SET_ETHTOOL_OPS(netdev, &t1_ethtool_ops);
1171 } 1162 }
diff --git a/drivers/net/chelsio/sge.c b/drivers/net/chelsio/sge.c
index 0ca8d876e16f..659cb2252e44 100644
--- a/drivers/net/chelsio/sge.c
+++ b/drivers/net/chelsio/sge.c
@@ -1413,16 +1413,20 @@ static int sge_rx(struct sge *sge, struct freelQ *fl, unsigned int len)
1413 1413
1414 if (unlikely(adapter->vlan_grp && p->vlan_valid)) { 1414 if (unlikely(adapter->vlan_grp && p->vlan_valid)) {
1415 st->vlan_xtract++; 1415 st->vlan_xtract++;
1416 if (adapter->params.sge.polling) 1416#ifdef CONFIG_CHELSIO_T1_NAPI
1417 vlan_hwaccel_receive_skb(skb, adapter->vlan_grp, 1417 vlan_hwaccel_receive_skb(skb, adapter->vlan_grp,
1418 ntohs(p->vlan)); 1418 ntohs(p->vlan));
1419 else 1419#else
1420 vlan_hwaccel_rx(skb, adapter->vlan_grp, 1420 vlan_hwaccel_rx(skb, adapter->vlan_grp,
1421 ntohs(p->vlan)); 1421 ntohs(p->vlan));
1422 } else if (adapter->params.sge.polling) 1422#endif
1423 } else {
1424#ifdef CONFIG_CHELSIO_T1_NAPI
1423 netif_receive_skb(skb); 1425 netif_receive_skb(skb);
1424 else 1426#else
1425 netif_rx(skb); 1427 netif_rx(skb);
1428#endif
1429 }
1426 return 0; 1430 return 0;
1427} 1431}
1428 1432
@@ -1572,6 +1576,7 @@ static int process_responses(struct adapter *adapter, int budget)
1572 return budget; 1576 return budget;
1573} 1577}
1574 1578
1579#ifdef CONFIG_CHELSIO_T1_NAPI
1575/* 1580/*
1576 * A simpler version of process_responses() that handles only pure (i.e., 1581 * A simpler version of process_responses() that handles only pure (i.e.,
1577 * non data-carrying) responses. Such respones are too light-weight to justify 1582 * non data-carrying) responses. Such respones are too light-weight to justify
@@ -1619,92 +1624,76 @@ static int process_pure_responses(struct adapter *adapter, struct respQ_e *e)
1619 * or protection from interrupts as data interrupts are off at this point and 1624 * or protection from interrupts as data interrupts are off at this point and
1620 * other adapter interrupts do not interfere. 1625 * other adapter interrupts do not interfere.
1621 */ 1626 */
1622static int t1_poll(struct net_device *dev, int *budget) 1627int t1_poll(struct net_device *dev, int *budget)
1623{ 1628{
1624 struct adapter *adapter = dev->priv; 1629 struct adapter *adapter = dev->priv;
1625 int effective_budget = min(*budget, dev->quota); 1630 int effective_budget = min(*budget, dev->quota);
1626
1627 int work_done = process_responses(adapter, effective_budget); 1631 int work_done = process_responses(adapter, effective_budget);
1632
1628 *budget -= work_done; 1633 *budget -= work_done;
1629 dev->quota -= work_done; 1634 dev->quota -= work_done;
1630 1635
1631 if (work_done >= effective_budget) 1636 if (work_done >= effective_budget)
1632 return 1; 1637 return 1;
1633 1638
1639 spin_lock_irq(&adapter->async_lock);
1634 __netif_rx_complete(dev); 1640 __netif_rx_complete(dev);
1635
1636 /*
1637 * Because we don't atomically flush the following write it is
1638 * possible that in very rare cases it can reach the device in a way
1639 * that races with a new response being written plus an error interrupt
1640 * causing the NAPI interrupt handler below to return unhandled status
1641 * to the OS. To protect against this would require flushing the write
1642 * and doing both the write and the flush with interrupts off. Way too
1643 * expensive and unjustifiable given the rarity of the race.
1644 */
1645 writel(adapter->sge->respQ.cidx, adapter->regs + A_SG_SLEEPING); 1641 writel(adapter->sge->respQ.cidx, adapter->regs + A_SG_SLEEPING);
1646 return 0; 1642 writel(adapter->slow_intr_mask | F_PL_INTR_SGE_DATA,
1647} 1643 adapter->regs + A_PL_ENABLE);
1644 spin_unlock_irq(&adapter->async_lock);
1648 1645
1649/* 1646 return 0;
1650 * Returns true if the device is already scheduled for polling.
1651 */
1652static inline int napi_is_scheduled(struct net_device *dev)
1653{
1654 return test_bit(__LINK_STATE_RX_SCHED, &dev->state);
1655} 1647}
1656 1648
1657/* 1649/*
1658 * NAPI version of the main interrupt handler. 1650 * NAPI version of the main interrupt handler.
1659 */ 1651 */
1660static irqreturn_t t1_interrupt_napi(int irq, void *data) 1652irqreturn_t t1_interrupt(int irq, void *data)
1661{ 1653{
1662 int handled;
1663 struct adapter *adapter = data; 1654 struct adapter *adapter = data;
1655 struct net_device *dev = adapter->sge->netdev;
1664 struct sge *sge = adapter->sge; 1656 struct sge *sge = adapter->sge;
1665 struct respQ *q = &adapter->sge->respQ; 1657 u32 cause;
1658 int handled = 0;
1666 1659
1667 /* 1660 cause = readl(adapter->regs + A_PL_CAUSE);
1668 * Clear the SGE_DATA interrupt first thing. Normally the NAPI 1661 if (cause == 0 || cause == ~0)
1669 * handler has control of the response queue and the interrupt handler 1662 return IRQ_NONE;
1670 * can look at the queue reliably only once it knows NAPI is off.
1671 * We can't wait that long to clear the SGE_DATA interrupt because we
1672 * could race with t1_poll rearming the SGE interrupt, so we need to
1673 * clear the interrupt speculatively and really early on.
1674 */
1675 writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
1676 1663
1677 spin_lock(&adapter->async_lock); 1664 spin_lock(&adapter->async_lock);
1678 if (!napi_is_scheduled(sge->netdev)) { 1665 if (cause & F_PL_INTR_SGE_DATA) {
1666 struct respQ *q = &adapter->sge->respQ;
1679 struct respQ_e *e = &q->entries[q->cidx]; 1667 struct respQ_e *e = &q->entries[q->cidx];
1680 1668
1681 if (e->GenerationBit == q->genbit) { 1669 handled = 1;
1682 if (e->DataValid || 1670 writel(F_PL_INTR_SGE_DATA, adapter->regs + A_PL_CAUSE);
1683 process_pure_responses(adapter, e)) { 1671
1684 if (likely(__netif_rx_schedule_prep(sge->netdev))) 1672 if (e->GenerationBit == q->genbit &&
1685 __netif_rx_schedule(sge->netdev); 1673 __netif_rx_schedule_prep(dev)) {
1686 else if (net_ratelimit()) 1674 if (e->DataValid || process_pure_responses(adapter, e)) {
1687 printk(KERN_INFO 1675 /* mask off data IRQ */
1688 "NAPI schedule failure!\n"); 1676 writel(adapter->slow_intr_mask,
1689 } else 1677 adapter->regs + A_PL_ENABLE);
1690 writel(q->cidx, adapter->regs + A_SG_SLEEPING); 1678 __netif_rx_schedule(sge->netdev);
1691 1679 goto unlock;
1692 handled = 1; 1680 }
1693 goto unlock; 1681 /* no data, no NAPI needed */
1694 } else 1682 netif_poll_enable(dev);
1695 writel(q->cidx, adapter->regs + A_SG_SLEEPING); 1683
1696 } else if (readl(adapter->regs + A_PL_CAUSE) & F_PL_INTR_SGE_DATA) { 1684 }
1697 printk(KERN_ERR "data interrupt while NAPI running\n"); 1685 writel(q->cidx, adapter->regs + A_SG_SLEEPING);
1698 } 1686 } else
1699 1687 handled = t1_slow_intr_handler(adapter);
1700 handled = t1_slow_intr_handler(adapter); 1688
1701 if (!handled) 1689 if (!handled)
1702 sge->stats.unhandled_irqs++; 1690 sge->stats.unhandled_irqs++;
1703 unlock: 1691unlock:
1704 spin_unlock(&adapter->async_lock); 1692 spin_unlock(&adapter->async_lock);
1705 return IRQ_RETVAL(handled != 0); 1693 return IRQ_RETVAL(handled != 0);
1706} 1694}
1707 1695
1696#else
1708/* 1697/*
1709 * Main interrupt handler, optimized assuming that we took a 'DATA' 1698 * Main interrupt handler, optimized assuming that we took a 'DATA'
1710 * interrupt. 1699 * interrupt.
@@ -1720,7 +1709,7 @@ static irqreturn_t t1_interrupt_napi(int irq, void *data)
1720 * 5. If we took an interrupt, but no valid respQ descriptors was found we 1709 * 5. If we took an interrupt, but no valid respQ descriptors was found we
1721 * let the slow_intr_handler run and do error handling. 1710 * let the slow_intr_handler run and do error handling.
1722 */ 1711 */
1723static irqreturn_t t1_interrupt(int irq, void *cookie) 1712irqreturn_t t1_interrupt(int irq, void *cookie)
1724{ 1713{
1725 int work_done; 1714 int work_done;
1726 struct respQ_e *e; 1715 struct respQ_e *e;
@@ -1752,11 +1741,7 @@ static irqreturn_t t1_interrupt(int irq, void *cookie)
1752 spin_unlock(&adapter->async_lock); 1741 spin_unlock(&adapter->async_lock);
1753 return IRQ_RETVAL(work_done != 0); 1742 return IRQ_RETVAL(work_done != 0);
1754} 1743}
1755 1744#endif
1756irq_handler_t t1_select_intr_handler(adapter_t *adapter)
1757{
1758 return adapter->params.sge.polling ? t1_interrupt_napi : t1_interrupt;
1759}
1760 1745
1761/* 1746/*
1762 * Enqueues the sk_buff onto the cmdQ[qid] and has hardware fetch it. 1747 * Enqueues the sk_buff onto the cmdQ[qid] and has hardware fetch it.
@@ -2033,7 +2018,6 @@ static void sge_tx_reclaim_cb(unsigned long data)
2033 */ 2018 */
2034int t1_sge_set_coalesce_params(struct sge *sge, struct sge_params *p) 2019int t1_sge_set_coalesce_params(struct sge *sge, struct sge_params *p)
2035{ 2020{
2036 sge->netdev->poll = t1_poll;
2037 sge->fixed_intrtimer = p->rx_coalesce_usecs * 2021 sge->fixed_intrtimer = p->rx_coalesce_usecs *
2038 core_ticks_per_usec(sge->adapter); 2022 core_ticks_per_usec(sge->adapter);
2039 writel(sge->fixed_intrtimer, sge->adapter->regs + A_SG_INTRTIMER); 2023 writel(sge->fixed_intrtimer, sge->adapter->regs + A_SG_INTRTIMER);
@@ -2234,7 +2218,6 @@ struct sge * __devinit t1_sge_create(struct adapter *adapter,
2234 2218
2235 p->coalesce_enable = 0; 2219 p->coalesce_enable = 0;
2236 p->sample_interval_usecs = 0; 2220 p->sample_interval_usecs = 0;
2237 p->polling = 0;
2238 2221
2239 return sge; 2222 return sge;
2240nomem_port: 2223nomem_port:
diff --git a/drivers/net/chelsio/sge.h b/drivers/net/chelsio/sge.h
index 7ceb0117d039..d132a0ef2a22 100644
--- a/drivers/net/chelsio/sge.h
+++ b/drivers/net/chelsio/sge.h
@@ -76,7 +76,9 @@ struct sge *t1_sge_create(struct adapter *, struct sge_params *);
76int t1_sge_configure(struct sge *, struct sge_params *); 76int t1_sge_configure(struct sge *, struct sge_params *);
77int t1_sge_set_coalesce_params(struct sge *, struct sge_params *); 77int t1_sge_set_coalesce_params(struct sge *, struct sge_params *);
78void t1_sge_destroy(struct sge *); 78void t1_sge_destroy(struct sge *);
79irq_handler_t t1_select_intr_handler(adapter_t *adapter); 79irqreturn_t t1_interrupt(int irq, void *cookie);
80int t1_poll(struct net_device *, int *);
81
80int t1_start_xmit(struct sk_buff *skb, struct net_device *dev); 82int t1_start_xmit(struct sk_buff *skb, struct net_device *dev);
81void t1_set_vlan_accel(struct adapter *adapter, int on_off); 83void t1_set_vlan_accel(struct adapter *adapter, int on_off);
82void t1_sge_start(struct sge *); 84void t1_sge_start(struct sge *);
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 92420f007b97..760d04a671f9 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -325,11 +325,6 @@ static int sp_rebuild_header(struct sk_buff *skb)
325 325
326static void sp_setup(struct net_device *dev) 326static void sp_setup(struct net_device *dev)
327{ 327{
328 static char ax25_bcast[AX25_ADDR_LEN] =
329 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
330 static char ax25_test[AX25_ADDR_LEN] =
331 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
332
333 /* Finish setting up the DEVICE info. */ 328 /* Finish setting up the DEVICE info. */
334 dev->mtu = SIXP_MTU; 329 dev->mtu = SIXP_MTU;
335 dev->hard_start_xmit = sp_xmit; 330 dev->hard_start_xmit = sp_xmit;
@@ -347,8 +342,8 @@ static void sp_setup(struct net_device *dev)
347 dev->tx_timeout = NULL; 342 dev->tx_timeout = NULL;
348 343
349 /* Only activated in AX.25 mode */ 344 /* Only activated in AX.25 mode */
350 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 345 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
351 memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); 346 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
352 347
353 SET_MODULE_OWNER(dev); 348 SET_MODULE_OWNER(dev);
354 349
diff --git a/drivers/net/hamradio/baycom_epp.c b/drivers/net/hamradio/baycom_epp.c
index 3c33d6f6a6a6..153b6dc80af4 100644
--- a/drivers/net/hamradio/baycom_epp.c
+++ b/drivers/net/hamradio/baycom_epp.c
@@ -1141,12 +1141,6 @@ static int baycom_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1141 */ 1141 */
1142static void baycom_probe(struct net_device *dev) 1142static void baycom_probe(struct net_device *dev)
1143{ 1143{
1144 static char ax25_bcast[AX25_ADDR_LEN] = {
1145 'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1
1146 };
1147 static char ax25_nocall[AX25_ADDR_LEN] = {
1148 'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1
1149 };
1150 const struct hdlcdrv_channel_params dflt_ch_params = { 1144 const struct hdlcdrv_channel_params dflt_ch_params = {
1151 20, 2, 10, 40, 0 1145 20, 2, 10, 40, 0
1152 }; 1146 };
@@ -1182,8 +1176,8 @@ static void baycom_probe(struct net_device *dev)
1182 dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN; 1176 dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN;
1183 dev->mtu = AX25_DEF_PACLEN; /* eth_mtu is the default */ 1177 dev->mtu = AX25_DEF_PACLEN; /* eth_mtu is the default */
1184 dev->addr_len = AX25_ADDR_LEN; /* sizeof an ax.25 address */ 1178 dev->addr_len = AX25_ADDR_LEN; /* sizeof an ax.25 address */
1185 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 1179 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
1186 memcpy(dev->dev_addr, ax25_nocall, AX25_ADDR_LEN); 1180 memcpy(dev->dev_addr, &null_ax25_address, AX25_ADDR_LEN);
1187 dev->tx_queue_len = 16; 1181 dev->tx_queue_len = 16;
1188 1182
1189 /* New style flags */ 1183 /* New style flags */
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index 889f338132fa..5b788d84011f 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -88,11 +88,6 @@
88 88
89static char banner[] __initdata = KERN_INFO "AX.25: bpqether driver version 004\n"; 89static char banner[] __initdata = KERN_INFO "AX.25: bpqether driver version 004\n";
90 90
91static unsigned char ax25_bcast[AX25_ADDR_LEN] =
92 {'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
93static unsigned char ax25_defaddr[AX25_ADDR_LEN] =
94 {'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
95
96static char bcast_addr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; 91static char bcast_addr[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
97 92
98static char bpq_eth_addr[6]; 93static char bpq_eth_addr[6];
@@ -487,8 +482,8 @@ static void bpq_setup(struct net_device *dev)
487 dev->do_ioctl = bpq_ioctl; 482 dev->do_ioctl = bpq_ioctl;
488 dev->destructor = free_netdev; 483 dev->destructor = free_netdev;
489 484
490 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 485 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
491 memcpy(dev->dev_addr, ax25_defaddr, AX25_ADDR_LEN); 486 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
492 487
493 dev->flags = 0; 488 dev->flags = 0;
494 489
diff --git a/drivers/net/hamradio/dmascc.c b/drivers/net/hamradio/dmascc.c
index e6e721aff6f6..0fbb414b5a4d 100644
--- a/drivers/net/hamradio/dmascc.c
+++ b/drivers/net/hamradio/dmascc.c
@@ -264,12 +264,6 @@ static int io[MAX_NUM_DEVS] __initdata = { 0, };
264 264
265/* Beware! hw[] is also used in cleanup_module(). */ 265/* Beware! hw[] is also used in cleanup_module(). */
266static struct scc_hardware hw[NUM_TYPES] __initdata_or_module = HARDWARE; 266static struct scc_hardware hw[NUM_TYPES] __initdata_or_module = HARDWARE;
267static char ax25_broadcast[7] __initdata =
268 { 'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1,
269'0' << 1 };
270static char ax25_test[7] __initdata =
271 { 'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1,
272'1' << 1 };
273 267
274 268
275/* Global variables */ 269/* Global variables */
@@ -443,8 +437,8 @@ static void __init dev_setup(struct net_device *dev)
443 dev->mtu = 1500; 437 dev->mtu = 1500;
444 dev->addr_len = AX25_ADDR_LEN; 438 dev->addr_len = AX25_ADDR_LEN;
445 dev->tx_queue_len = 64; 439 dev->tx_queue_len = 64;
446 memcpy(dev->broadcast, ax25_broadcast, AX25_ADDR_LEN); 440 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
447 memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); 441 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
448} 442}
449 443
450static int __init setup_adapter(int card_base, int type, int n) 444static int __init setup_adapter(int card_base, int type, int n)
diff --git a/drivers/net/hamradio/hdlcdrv.c b/drivers/net/hamradio/hdlcdrv.c
index dacc7687b97f..452873e7c68f 100644
--- a/drivers/net/hamradio/hdlcdrv.c
+++ b/drivers/net/hamradio/hdlcdrv.c
@@ -63,18 +63,6 @@
63 63
64/* --------------------------------------------------------------------- */ 64/* --------------------------------------------------------------------- */
65 65
66/*
67 * The name of the card. Is used for messages and in the requests for
68 * io regions, irqs and dma channels
69 */
70
71static char ax25_bcast[AX25_ADDR_LEN] =
72{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
73static char ax25_nocall[AX25_ADDR_LEN] =
74{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
75
76/* --------------------------------------------------------------------- */
77
78#define KISS_VERBOSE 66#define KISS_VERBOSE
79 67
80/* --------------------------------------------------------------------- */ 68/* --------------------------------------------------------------------- */
@@ -709,8 +697,8 @@ static void hdlcdrv_setup(struct net_device *dev)
709 dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN; 697 dev->hard_header_len = AX25_MAX_HEADER_LEN + AX25_BPQ_HEADER_LEN;
710 dev->mtu = AX25_DEF_PACLEN; /* eth_mtu is the default */ 698 dev->mtu = AX25_DEF_PACLEN; /* eth_mtu is the default */
711 dev->addr_len = AX25_ADDR_LEN; /* sizeof an ax.25 address */ 699 dev->addr_len = AX25_ADDR_LEN; /* sizeof an ax.25 address */
712 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 700 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
713 memcpy(dev->dev_addr, ax25_nocall, AX25_ADDR_LEN); 701 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
714 dev->tx_queue_len = 16; 702 dev->tx_queue_len = 16;
715} 703}
716 704
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index d8715b200c17..d08fbc396648 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -672,11 +672,6 @@ static struct net_device_stats *ax_get_stats(struct net_device *dev)
672 672
673static void ax_setup(struct net_device *dev) 673static void ax_setup(struct net_device *dev)
674{ 674{
675 static char ax25_bcast[AX25_ADDR_LEN] =
676 {'Q'<<1,'S'<<1,'T'<<1,' '<<1,' '<<1,' '<<1,'0'<<1};
677 static char ax25_test[AX25_ADDR_LEN] =
678 {'L'<<1,'I'<<1,'N'<<1,'U'<<1,'X'<<1,' '<<1,'1'<<1};
679
680 /* Finish setting up the DEVICE info. */ 675 /* Finish setting up the DEVICE info. */
681 dev->mtu = AX_MTU; 676 dev->mtu = AX_MTU;
682 dev->hard_start_xmit = ax_xmit; 677 dev->hard_start_xmit = ax_xmit;
@@ -691,8 +686,8 @@ static void ax_setup(struct net_device *dev)
691 dev->hard_header = ax_header; 686 dev->hard_header = ax_header;
692 dev->rebuild_header = ax_rebuild_header; 687 dev->rebuild_header = ax_rebuild_header;
693 688
694 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 689 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
695 memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); 690 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
696 691
697 dev->flags = IFF_BROADCAST | IFF_MULTICAST; 692 dev->flags = IFF_BROADCAST | IFF_MULTICAST;
698} 693}
diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c
index ec9b6d9b6f05..2ce047e9d262 100644
--- a/drivers/net/hamradio/scc.c
+++ b/drivers/net/hamradio/scc.c
@@ -1540,11 +1540,6 @@ static int scc_net_alloc(const char *name, struct scc_channel *scc)
1540/* * Network driver methods * */ 1540/* * Network driver methods * */
1541/* ******************************************************************** */ 1541/* ******************************************************************** */
1542 1542
1543static unsigned char ax25_bcast[AX25_ADDR_LEN] =
1544{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
1545static unsigned char ax25_nocall[AX25_ADDR_LEN] =
1546{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
1547
1548/* ----> Initialize device <----- */ 1543/* ----> Initialize device <----- */
1549 1544
1550static void scc_net_setup(struct net_device *dev) 1545static void scc_net_setup(struct net_device *dev)
@@ -1562,8 +1557,8 @@ static void scc_net_setup(struct net_device *dev)
1562 dev->do_ioctl = scc_net_ioctl; 1557 dev->do_ioctl = scc_net_ioctl;
1563 dev->tx_timeout = NULL; 1558 dev->tx_timeout = NULL;
1564 1559
1565 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 1560 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
1566 memcpy(dev->dev_addr, ax25_nocall, AX25_ADDR_LEN); 1561 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
1567 1562
1568 dev->flags = 0; 1563 dev->flags = 0;
1569 1564
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 3c4455bd466d..6d74f08720d5 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -156,11 +156,6 @@ static struct net_device *yam_devs[NR_PORTS];
156 156
157static struct yam_mcs *yam_data; 157static struct yam_mcs *yam_data;
158 158
159static char ax25_bcast[7] =
160{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
161static char ax25_test[7] =
162{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
163
164static DEFINE_TIMER(yam_timer, NULL, 0, 0); 159static DEFINE_TIMER(yam_timer, NULL, 0, 0);
165 160
166/* --------------------------------------------------------------------- */ 161/* --------------------------------------------------------------------- */
@@ -1115,8 +1110,8 @@ static void yam_setup(struct net_device *dev)
1115 dev->hard_header_len = AX25_MAX_HEADER_LEN; 1110 dev->hard_header_len = AX25_MAX_HEADER_LEN;
1116 dev->mtu = AX25_MTU; 1111 dev->mtu = AX25_MTU;
1117 dev->addr_len = AX25_ADDR_LEN; 1112 dev->addr_len = AX25_ADDR_LEN;
1118 memcpy(dev->broadcast, ax25_bcast, AX25_ADDR_LEN); 1113 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
1119 memcpy(dev->dev_addr, ax25_test, AX25_ADDR_LEN); 1114 memcpy(dev->dev_addr, &ax25_defaddr, AX25_ADDR_LEN);
1120} 1115}
1121 1116
1122static int __init yam_init_driver(void) 1117static int __init yam_init_driver(void)
diff --git a/drivers/net/hplance.c b/drivers/net/hplance.c
index 9c643f2a8d54..c991cb82ff22 100644
--- a/drivers/net/hplance.c
+++ b/drivers/net/hplance.c
@@ -77,6 +77,7 @@ static int __devinit hplance_init_one(struct dio_dev *d,
77{ 77{
78 struct net_device *dev; 78 struct net_device *dev;
79 int err = -ENOMEM; 79 int err = -ENOMEM;
80 int i;
80 81
81 dev = alloc_etherdev(sizeof(struct hplance_private)); 82 dev = alloc_etherdev(sizeof(struct hplance_private));
82 if (!dev) 83 if (!dev)
@@ -93,6 +94,15 @@ static int __devinit hplance_init_one(struct dio_dev *d,
93 goto out_release_mem_region; 94 goto out_release_mem_region;
94 95
95 dio_set_drvdata(d, dev); 96 dio_set_drvdata(d, dev);
97
98 printk(KERN_INFO "%s: %s; select code %d, addr %2.2x", dev->name, d->name, d->scode, dev->dev_addr[0]);
99
100 for (i=1; i<6; i++) {
101 printk(":%2.2x", dev->dev_addr[i]);
102 }
103
104 printk(", irq %d\n", d->ipl);
105
96 return 0; 106 return 0;
97 107
98 out_release_mem_region: 108 out_release_mem_region:
@@ -119,8 +129,6 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
119 struct hplance_private *lp; 129 struct hplance_private *lp;
120 int i; 130 int i;
121 131
122 printk(KERN_INFO "%s: %s; select code %d, addr", dev->name, d->name, d->scode);
123
124 /* reset the board */ 132 /* reset the board */
125 out_8(va+DIO_IDOFF, 0xff); 133 out_8(va+DIO_IDOFF, 0xff);
126 udelay(100); /* ariba! ariba! udelay! udelay! */ 134 udelay(100); /* ariba! ariba! udelay! udelay! */
@@ -143,7 +151,6 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
143 */ 151 */
144 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4) 152 dev->dev_addr[i] = ((in_8(va + HPLANCE_NVRAMOFF + i*4 + 1) & 0xF) << 4)
145 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF); 153 | (in_8(va + HPLANCE_NVRAMOFF + i*4 + 3) & 0xF);
146 printk("%c%2.2x", i == 0 ? ' ' : ':', dev->dev_addr[i]);
147 } 154 }
148 155
149 lp = netdev_priv(dev); 156 lp = netdev_priv(dev);
@@ -160,7 +167,6 @@ static void __init hplance_init(struct net_device *dev, struct dio_dev *d)
160 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS; 167 lp->lance.lance_log_tx_bufs = LANCE_LOG_TX_BUFFERS;
161 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK; 168 lp->lance.rx_ring_mod_mask = RX_RING_MOD_MASK;
162 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK; 169 lp->lance.tx_ring_mod_mask = TX_RING_MOD_MASK;
163 printk(", irq %d\n", lp->lance.irq);
164} 170}
165 171
166/* This is disgusting. We have to check the DIO status register for ack every 172/* This is disgusting. We have to check the DIO status register for ack every
diff --git a/drivers/net/irda/irtty-sir.c b/drivers/net/irda/irtty-sir.c
index 6a98b7ae4975..ad1857364d51 100644
--- a/drivers/net/irda/irtty-sir.c
+++ b/drivers/net/irda/irtty-sir.c
@@ -117,7 +117,7 @@ static int irtty_change_speed(struct sir_dev *dev, unsigned speed)
117{ 117{
118 struct sirtty_cb *priv = dev->priv; 118 struct sirtty_cb *priv = dev->priv;
119 struct tty_struct *tty; 119 struct tty_struct *tty;
120 struct termios old_termios; 120 struct ktermios old_termios;
121 int cflag; 121 int cflag;
122 122
123 IRDA_ASSERT(priv != NULL, return -1;); 123 IRDA_ASSERT(priv != NULL, return -1;);
@@ -318,7 +318,7 @@ static void irtty_write_wakeup(struct tty_struct *tty)
318 318
319static inline void irtty_stop_receiver(struct tty_struct *tty, int stop) 319static inline void irtty_stop_receiver(struct tty_struct *tty, int stop)
320{ 320{
321 struct termios old_termios; 321 struct ktermios old_termios;
322 int cflag; 322 int cflag;
323 323
324 lock_kernel(); 324 lock_kernel();
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index bd0ce98c939c..25b559b5d5ed 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -264,12 +264,12 @@ static void macb_update_stats(struct macb *bp)
264 WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4); 264 WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4);
265 265
266 for(; p < end; p++, reg++) 266 for(; p < end; p++, reg++)
267 *p += readl(reg); 267 *p += __raw_readl(reg);
268} 268}
269 269
270static void macb_periodic_task(void *arg) 270static void macb_periodic_task(struct work_struct *work)
271{ 271{
272 struct macb *bp = arg; 272 struct macb *bp = container_of(work, struct macb, periodic_task.work);
273 273
274 macb_update_stats(bp); 274 macb_update_stats(bp);
275 macb_check_media(bp, 1, 0); 275 macb_check_media(bp, 1, 0);
@@ -1088,7 +1088,7 @@ static int __devinit macb_probe(struct platform_device *pdev)
1088 1088
1089 dev->base_addr = regs->start; 1089 dev->base_addr = regs->start;
1090 1090
1091 INIT_WORK(&bp->periodic_task, macb_periodic_task, bp); 1091 INIT_DELAYED_WORK(&bp->periodic_task, macb_periodic_task);
1092 mutex_init(&bp->mdio_mutex); 1092 mutex_init(&bp->mdio_mutex);
1093 init_completion(&bp->mdio_complete); 1093 init_completion(&bp->mdio_complete);
1094 1094
diff --git a/drivers/net/macb.h b/drivers/net/macb.h
index 8c253db69881..27bf0ae0f0bb 100644
--- a/drivers/net/macb.h
+++ b/drivers/net/macb.h
@@ -250,9 +250,9 @@
250 250
251/* Register access macros */ 251/* Register access macros */
252#define macb_readl(port,reg) \ 252#define macb_readl(port,reg) \
253 readl((port)->regs + MACB_##reg) 253 __raw_readl((port)->regs + MACB_##reg)
254#define macb_writel(port,reg,value) \ 254#define macb_writel(port,reg,value) \
255 writel((value), (port)->regs + MACB_##reg) 255 __raw_writel((value), (port)->regs + MACB_##reg)
256 256
257struct dma_desc { 257struct dma_desc {
258 u32 addr; 258 u32 addr;
@@ -377,7 +377,7 @@ struct macb {
377 377
378 unsigned int rx_pending, tx_pending; 378 unsigned int rx_pending, tx_pending;
379 379
380 struct work_struct periodic_task; 380 struct delayed_work periodic_task;
381 381
382 struct mutex mdio_mutex; 382 struct mutex mdio_mutex;
383 struct completion mdio_complete; 383 struct completion mdio_complete;
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 81f127a78afa..94ac168be593 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -71,7 +71,7 @@
71#include "myri10ge_mcp.h" 71#include "myri10ge_mcp.h"
72#include "myri10ge_mcp_gen_header.h" 72#include "myri10ge_mcp_gen_header.h"
73 73
74#define MYRI10GE_VERSION_STR "1.0.0" 74#define MYRI10GE_VERSION_STR "1.1.0"
75 75
76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)"); 76MODULE_DESCRIPTION("Myricom 10G driver (10GbE)");
77MODULE_AUTHOR("Maintainer: help@myri.com"); 77MODULE_AUTHOR("Maintainer: help@myri.com");
@@ -92,8 +92,13 @@ MODULE_LICENSE("Dual BSD/GPL");
92#define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff) 92#define MYRI10GE_NO_CONFIRM_DATA htonl(0xffffffff)
93#define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff 93#define MYRI10GE_NO_RESPONSE_RESULT 0xffffffff
94 94
95#define MYRI10GE_ALLOC_ORDER 0
96#define MYRI10GE_ALLOC_SIZE ((1 << MYRI10GE_ALLOC_ORDER) * PAGE_SIZE)
97#define MYRI10GE_MAX_FRAGS_PER_FRAME (MYRI10GE_MAX_ETHER_MTU/MYRI10GE_ALLOC_SIZE + 1)
98
95struct myri10ge_rx_buffer_state { 99struct myri10ge_rx_buffer_state {
96 struct sk_buff *skb; 100 struct page *page;
101 int page_offset;
97 DECLARE_PCI_UNMAP_ADDR(bus) 102 DECLARE_PCI_UNMAP_ADDR(bus)
98 DECLARE_PCI_UNMAP_LEN(len) 103 DECLARE_PCI_UNMAP_LEN(len)
99}; 104};
@@ -116,9 +121,14 @@ struct myri10ge_rx_buf {
116 u8 __iomem *wc_fifo; /* w/c rx dma addr fifo address */ 121 u8 __iomem *wc_fifo; /* w/c rx dma addr fifo address */
117 struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */ 122 struct mcp_kreq_ether_recv *shadow; /* host shadow of recv ring */
118 struct myri10ge_rx_buffer_state *info; 123 struct myri10ge_rx_buffer_state *info;
124 struct page *page;
125 dma_addr_t bus;
126 int page_offset;
119 int cnt; 127 int cnt;
128 int fill_cnt;
120 int alloc_fail; 129 int alloc_fail;
121 int mask; /* number of rx slots -1 */ 130 int mask; /* number of rx slots -1 */
131 int watchdog_needed;
122}; 132};
123 133
124struct myri10ge_tx_buf { 134struct myri10ge_tx_buf {
@@ -150,6 +160,7 @@ struct myri10ge_priv {
150 struct myri10ge_rx_buf rx_big; 160 struct myri10ge_rx_buf rx_big;
151 struct myri10ge_rx_done rx_done; 161 struct myri10ge_rx_done rx_done;
152 int small_bytes; 162 int small_bytes;
163 int big_bytes;
153 struct net_device *dev; 164 struct net_device *dev;
154 struct net_device_stats stats; 165 struct net_device_stats stats;
155 u8 __iomem *sram; 166 u8 __iomem *sram;
@@ -238,11 +249,6 @@ module_param(myri10ge_force_firmware, int, S_IRUGO);
238MODULE_PARM_DESC(myri10ge_force_firmware, 249MODULE_PARM_DESC(myri10ge_force_firmware,
239 "Force firmware to assume aligned completions\n"); 250 "Force firmware to assume aligned completions\n");
240 251
241static int myri10ge_skb_cross_4k = 0;
242module_param(myri10ge_skb_cross_4k, int, S_IRUGO | S_IWUSR);
243MODULE_PARM_DESC(myri10ge_skb_cross_4k,
244 "Can a small skb cross a 4KB boundary?\n");
245
246static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN; 252static int myri10ge_initial_mtu = MYRI10GE_MAX_ETHER_MTU - ETH_HLEN;
247module_param(myri10ge_initial_mtu, int, S_IRUGO); 253module_param(myri10ge_initial_mtu, int, S_IRUGO);
248MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU\n"); 254MODULE_PARM_DESC(myri10ge_initial_mtu, "Initial MTU\n");
@@ -266,6 +272,10 @@ static int myri10ge_debug = -1; /* defaults above */
266module_param(myri10ge_debug, int, 0); 272module_param(myri10ge_debug, int, 0);
267MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)"); 273MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)");
268 274
275static int myri10ge_fill_thresh = 256;
276module_param(myri10ge_fill_thresh, int, S_IRUGO | S_IWUSR);
277MODULE_PARM_DESC(myri10ge_fill_thresh, "Number of empty rx slots allowed\n");
278
269#define MYRI10GE_FW_OFFSET 1024*1024 279#define MYRI10GE_FW_OFFSET 1024*1024
270#define MYRI10GE_HIGHPART_TO_U32(X) \ 280#define MYRI10GE_HIGHPART_TO_U32(X) \
271(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0) 281(sizeof (X) == 8) ? ((u32)((u64)(X) >> 32)) : (0)
@@ -273,9 +283,9 @@ MODULE_PARM_DESC(myri10ge_debug, "Debug level (0=none,...,16=all)");
273 283
274#define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8) 284#define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8)
275 285
276static inline void put_be32(__be32 val, __be32 __iomem *p) 286static inline void put_be32(__be32 val, __be32 __iomem * p)
277{ 287{
278 __raw_writel((__force __u32)val, (__force void __iomem *)p); 288 __raw_writel((__force __u32) val, (__force void __iomem *)p);
279} 289}
280 290
281static int 291static int
@@ -804,194 +814,179 @@ myri10ge_submit_8rx(struct mcp_kreq_ether_recv __iomem * dst,
804 mb(); 814 mb();
805} 815}
806 816
807/* 817static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum)
808 * Set of routines to get a new receive buffer. Any buffer which
809 * crosses a 4KB boundary must start on a 4KB boundary due to PCIe
810 * wdma restrictions. We also try to align any smaller allocation to
811 * at least a 16 byte boundary for efficiency. We assume the linux
812 * memory allocator works by powers of 2, and will not return memory
813 * smaller than 2KB which crosses a 4KB boundary. If it does, we fall
814 * back to allocating 2x as much space as required.
815 *
816 * We intend to replace large (>4KB) skb allocations by using
817 * pages directly and building a fraglist in the near future.
818 */
819
820static inline struct sk_buff *myri10ge_alloc_big(struct net_device *dev,
821 int bytes)
822{
823 struct sk_buff *skb;
824 unsigned long data, roundup;
825
826 skb = netdev_alloc_skb(dev, bytes + 4096 + MXGEFW_PAD);
827 if (skb == NULL)
828 return NULL;
829
830 /* Correct skb->truesize so that socket buffer
831 * accounting is not confused the rounding we must
832 * do to satisfy alignment constraints.
833 */
834 skb->truesize -= 4096;
835
836 data = (unsigned long)(skb->data);
837 roundup = (-data) & (4095);
838 skb_reserve(skb, roundup);
839 return skb;
840}
841
842/* Allocate 2x as much space as required and use whichever portion
843 * does not cross a 4KB boundary */
844static inline struct sk_buff *myri10ge_alloc_small_safe(struct net_device *dev,
845 unsigned int bytes)
846{ 818{
847 struct sk_buff *skb; 819 struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data);
848 unsigned long data, boundary;
849
850 skb = netdev_alloc_skb(dev, 2 * (bytes + MXGEFW_PAD) - 1);
851 if (unlikely(skb == NULL))
852 return NULL;
853
854 /* Correct skb->truesize so that socket buffer
855 * accounting is not confused the rounding we must
856 * do to satisfy alignment constraints.
857 */
858 skb->truesize -= bytes + MXGEFW_PAD;
859
860 data = (unsigned long)(skb->data);
861 boundary = (data + 4095UL) & ~4095UL;
862 if ((boundary - data) >= (bytes + MXGEFW_PAD))
863 return skb;
864 820
865 skb_reserve(skb, boundary - data); 821 if ((skb->protocol == htons(ETH_P_8021Q)) &&
866 return skb; 822 (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) ||
823 vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) {
824 skb->csum = hw_csum;
825 skb->ip_summed = CHECKSUM_COMPLETE;
826 }
867} 827}
868 828
869/* Allocate just enough space, and verify that the allocated 829static inline void
870 * space does not cross a 4KB boundary */ 830myri10ge_rx_skb_build(struct sk_buff *skb, u8 * va,
871static inline struct sk_buff *myri10ge_alloc_small(struct net_device *dev, 831 struct skb_frag_struct *rx_frags, int len, int hlen)
872 int bytes)
873{ 832{
874 struct sk_buff *skb; 833 struct skb_frag_struct *skb_frags;
875 unsigned long roundup, data, end; 834
876 835 skb->len = skb->data_len = len;
877 skb = netdev_alloc_skb(dev, bytes + 16 + MXGEFW_PAD); 836 skb->truesize = len + sizeof(struct sk_buff);
878 if (unlikely(skb == NULL)) 837 /* attach the page(s) */
879 return NULL; 838
880 839 skb_frags = skb_shinfo(skb)->frags;
881 /* Round allocated buffer to 16 byte boundary */ 840 while (len > 0) {
882 data = (unsigned long)(skb->data); 841 memcpy(skb_frags, rx_frags, sizeof(*skb_frags));
883 roundup = (-data) & 15UL; 842 len -= rx_frags->size;
884 skb_reserve(skb, roundup); 843 skb_frags++;
885 /* Verify that the data buffer does not cross a page boundary */ 844 rx_frags++;
886 data = (unsigned long)(skb->data); 845 skb_shinfo(skb)->nr_frags++;
887 end = data + bytes + MXGEFW_PAD - 1; 846 }
888 if (unlikely(((end >> 12) != (data >> 12)) && (data & 4095UL))) { 847
889 printk(KERN_NOTICE 848 /* pskb_may_pull is not available in irq context, but
890 "myri10ge_alloc_small: small skb crossed 4KB boundary\n"); 849 * skb_pull() (for ether_pad and eth_type_trans()) requires
891 myri10ge_skb_cross_4k = 1; 850 * the beginning of the packet in skb_headlen(), move it
892 dev_kfree_skb_any(skb); 851 * manually */
893 skb = myri10ge_alloc_small_safe(dev, bytes); 852 memcpy(skb->data, va, hlen);
894 } 853 skb_shinfo(skb)->frags[0].page_offset += hlen;
895 return skb; 854 skb_shinfo(skb)->frags[0].size -= hlen;
855 skb->data_len -= hlen;
856 skb->tail += hlen;
857 skb_pull(skb, MXGEFW_PAD);
896} 858}
897 859
898static inline int 860static void
899myri10ge_getbuf(struct myri10ge_rx_buf *rx, struct myri10ge_priv *mgp, 861myri10ge_alloc_rx_pages(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
900 int bytes, int idx) 862 int bytes, int watchdog)
901{ 863{
902 struct net_device *dev = mgp->dev; 864 struct page *page;
903 struct pci_dev *pdev = mgp->pdev; 865 int idx;
904 struct sk_buff *skb;
905 dma_addr_t bus;
906 int len, retval = 0;
907 866
908 bytes += VLAN_HLEN; /* account for 802.1q vlan tag */ 867 if (unlikely(rx->watchdog_needed && !watchdog))
868 return;
909 869
910 if ((bytes + MXGEFW_PAD) > (4096 - 16) /* linux overhead */ ) 870 /* try to refill entire ring */
911 skb = myri10ge_alloc_big(dev, bytes); 871 while (rx->fill_cnt != (rx->cnt + rx->mask + 1)) {
912 else if (myri10ge_skb_cross_4k) 872 idx = rx->fill_cnt & rx->mask;
913 skb = myri10ge_alloc_small_safe(dev, bytes);
914 else
915 skb = myri10ge_alloc_small(dev, bytes);
916 873
917 if (unlikely(skb == NULL)) { 874 if ((bytes < MYRI10GE_ALLOC_SIZE / 2) &&
918 rx->alloc_fail++; 875 (rx->page_offset + bytes <= MYRI10GE_ALLOC_SIZE)) {
919 retval = -ENOBUFS; 876 /* we can use part of previous page */
920 goto done; 877 get_page(rx->page);
921 } 878 } else {
922 879 /* we need a new page */
923 /* set len so that it only covers the area we 880 page =
924 * need mapped for DMA */ 881 alloc_pages(GFP_ATOMIC | __GFP_COMP,
925 len = bytes + MXGEFW_PAD; 882 MYRI10GE_ALLOC_ORDER);
926 883 if (unlikely(page == NULL)) {
927 bus = pci_map_single(pdev, skb->data, len, PCI_DMA_FROMDEVICE); 884 if (rx->fill_cnt - rx->cnt < 16)
928 rx->info[idx].skb = skb; 885 rx->watchdog_needed = 1;
929 pci_unmap_addr_set(&rx->info[idx], bus, bus); 886 return;
930 pci_unmap_len_set(&rx->info[idx], len, len); 887 }
931 rx->shadow[idx].addr_low = htonl(MYRI10GE_LOWPART_TO_U32(bus)); 888 rx->page = page;
932 rx->shadow[idx].addr_high = htonl(MYRI10GE_HIGHPART_TO_U32(bus)); 889 rx->page_offset = 0;
933 890 rx->bus = pci_map_page(mgp->pdev, page, 0,
934done: 891 MYRI10GE_ALLOC_SIZE,
935 /* copy 8 descriptors (64-bytes) to the mcp at a time */ 892 PCI_DMA_FROMDEVICE);
936 if ((idx & 7) == 7) { 893 }
937 if (rx->wc_fifo == NULL) 894 rx->info[idx].page = rx->page;
938 myri10ge_submit_8rx(&rx->lanai[idx - 7], 895 rx->info[idx].page_offset = rx->page_offset;
939 &rx->shadow[idx - 7]); 896 /* note that this is the address of the start of the
940 else { 897 * page */
941 mb(); 898 pci_unmap_addr_set(&rx->info[idx], bus, rx->bus);
942 myri10ge_pio_copy(rx->wc_fifo, 899 rx->shadow[idx].addr_low =
943 &rx->shadow[idx - 7], 64); 900 htonl(MYRI10GE_LOWPART_TO_U32(rx->bus) + rx->page_offset);
901 rx->shadow[idx].addr_high =
902 htonl(MYRI10GE_HIGHPART_TO_U32(rx->bus));
903
904 /* start next packet on a cacheline boundary */
905 rx->page_offset += SKB_DATA_ALIGN(bytes);
906 rx->fill_cnt++;
907
908 /* copy 8 descriptors to the firmware at a time */
909 if ((idx & 7) == 7) {
910 if (rx->wc_fifo == NULL)
911 myri10ge_submit_8rx(&rx->lanai[idx - 7],
912 &rx->shadow[idx - 7]);
913 else {
914 mb();
915 myri10ge_pio_copy(rx->wc_fifo,
916 &rx->shadow[idx - 7], 64);
917 }
944 } 918 }
945 } 919 }
946 return retval;
947} 920}
948 921
949static inline void myri10ge_vlan_ip_csum(struct sk_buff *skb, __wsum hw_csum) 922static inline void
923myri10ge_unmap_rx_page(struct pci_dev *pdev,
924 struct myri10ge_rx_buffer_state *info, int bytes)
950{ 925{
951 struct vlan_hdr *vh = (struct vlan_hdr *)(skb->data); 926 /* unmap the recvd page if we're the only or last user of it */
952 927 if (bytes >= MYRI10GE_ALLOC_SIZE / 2 ||
953 if ((skb->protocol == htons(ETH_P_8021Q)) && 928 (info->page_offset + 2 * bytes) > MYRI10GE_ALLOC_SIZE) {
954 (vh->h_vlan_encapsulated_proto == htons(ETH_P_IP) || 929 pci_unmap_page(pdev, (pci_unmap_addr(info, bus)
955 vh->h_vlan_encapsulated_proto == htons(ETH_P_IPV6))) { 930 & ~(MYRI10GE_ALLOC_SIZE - 1)),
956 skb->csum = hw_csum; 931 MYRI10GE_ALLOC_SIZE, PCI_DMA_FROMDEVICE);
957 skb->ip_summed = CHECKSUM_COMPLETE;
958 } 932 }
959} 933}
960 934
961static inline unsigned long 935#define MYRI10GE_HLEN 64 /* The number of bytes to copy from a
936 * page into an skb */
937
938static inline int
962myri10ge_rx_done(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx, 939myri10ge_rx_done(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
963 int bytes, int len, __wsum csum) 940 int bytes, int len, __wsum csum)
964{ 941{
965 dma_addr_t bus;
966 struct sk_buff *skb; 942 struct sk_buff *skb;
967 int idx, unmap_len; 943 struct skb_frag_struct rx_frags[MYRI10GE_MAX_FRAGS_PER_FRAME];
944 int i, idx, hlen, remainder;
945 struct pci_dev *pdev = mgp->pdev;
946 struct net_device *dev = mgp->dev;
947 u8 *va;
968 948
949 len += MXGEFW_PAD;
969 idx = rx->cnt & rx->mask; 950 idx = rx->cnt & rx->mask;
970 rx->cnt++; 951 va = page_address(rx->info[idx].page) + rx->info[idx].page_offset;
952 prefetch(va);
953 /* Fill skb_frag_struct(s) with data from our receive */
954 for (i = 0, remainder = len; remainder > 0; i++) {
955 myri10ge_unmap_rx_page(pdev, &rx->info[idx], bytes);
956 rx_frags[i].page = rx->info[idx].page;
957 rx_frags[i].page_offset = rx->info[idx].page_offset;
958 if (remainder < MYRI10GE_ALLOC_SIZE)
959 rx_frags[i].size = remainder;
960 else
961 rx_frags[i].size = MYRI10GE_ALLOC_SIZE;
962 rx->cnt++;
963 idx = rx->cnt & rx->mask;
964 remainder -= MYRI10GE_ALLOC_SIZE;
965 }
966
967 hlen = MYRI10GE_HLEN > len ? len : MYRI10GE_HLEN;
971 968
972 /* save a pointer to the received skb */ 969 /* allocate an skb to attach the page(s) to. */
973 skb = rx->info[idx].skb;
974 bus = pci_unmap_addr(&rx->info[idx], bus);
975 unmap_len = pci_unmap_len(&rx->info[idx], len);
976 970
977 /* try to replace the received skb */ 971 skb = netdev_alloc_skb(dev, MYRI10GE_HLEN + 16);
978 if (myri10ge_getbuf(rx, mgp, bytes, idx)) { 972 if (unlikely(skb == NULL)) {
979 /* drop the frame -- the old skbuf is re-cycled */ 973 mgp->stats.rx_dropped++;
980 mgp->stats.rx_dropped += 1; 974 do {
975 i--;
976 put_page(rx_frags[i].page);
977 } while (i != 0);
981 return 0; 978 return 0;
982 } 979 }
983 980
984 /* unmap the recvd skb */ 981 /* Attach the pages to the skb, and trim off any padding */
985 pci_unmap_single(mgp->pdev, bus, unmap_len, PCI_DMA_FROMDEVICE); 982 myri10ge_rx_skb_build(skb, va, rx_frags, len, hlen);
986 983 if (skb_shinfo(skb)->frags[0].size <= 0) {
987 /* mcp implicitly skips 1st bytes so that packet is properly 984 put_page(skb_shinfo(skb)->frags[0].page);
988 * aligned */ 985 skb_shinfo(skb)->nr_frags = 0;
989 skb_reserve(skb, MXGEFW_PAD); 986 }
990 987 skb->protocol = eth_type_trans(skb, dev);
991 /* set the length of the frame */ 988 skb->dev = dev;
992 skb_put(skb, len);
993 989
994 skb->protocol = eth_type_trans(skb, mgp->dev);
995 if (mgp->csum_flag) { 990 if (mgp->csum_flag) {
996 if ((skb->protocol == htons(ETH_P_IP)) || 991 if ((skb->protocol == htons(ETH_P_IP)) ||
997 (skb->protocol == htons(ETH_P_IPV6))) { 992 (skb->protocol == htons(ETH_P_IPV6))) {
@@ -1000,9 +995,8 @@ myri10ge_rx_done(struct myri10ge_priv *mgp, struct myri10ge_rx_buf *rx,
1000 } else 995 } else
1001 myri10ge_vlan_ip_csum(skb, csum); 996 myri10ge_vlan_ip_csum(skb, csum);
1002 } 997 }
1003
1004 netif_receive_skb(skb); 998 netif_receive_skb(skb);
1005 mgp->dev->last_rx = jiffies; 999 dev->last_rx = jiffies;
1006 return 1; 1000 return 1;
1007} 1001}
1008 1002
@@ -1079,7 +1073,7 @@ static inline void myri10ge_clean_rx_done(struct myri10ge_priv *mgp, int *limit)
1079 length, checksum); 1073 length, checksum);
1080 else 1074 else
1081 rx_ok = myri10ge_rx_done(mgp, &mgp->rx_big, 1075 rx_ok = myri10ge_rx_done(mgp, &mgp->rx_big,
1082 mgp->dev->mtu + ETH_HLEN, 1076 mgp->big_bytes,
1083 length, checksum); 1077 length, checksum);
1084 rx_packets += rx_ok; 1078 rx_packets += rx_ok;
1085 rx_bytes += rx_ok * (unsigned long)length; 1079 rx_bytes += rx_ok * (unsigned long)length;
@@ -1094,6 +1088,14 @@ static inline void myri10ge_clean_rx_done(struct myri10ge_priv *mgp, int *limit)
1094 rx_done->cnt = cnt; 1088 rx_done->cnt = cnt;
1095 mgp->stats.rx_packets += rx_packets; 1089 mgp->stats.rx_packets += rx_packets;
1096 mgp->stats.rx_bytes += rx_bytes; 1090 mgp->stats.rx_bytes += rx_bytes;
1091
1092 /* restock receive rings if needed */
1093 if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt < myri10ge_fill_thresh)
1094 myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
1095 mgp->small_bytes + MXGEFW_PAD, 0);
1096 if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt < myri10ge_fill_thresh)
1097 myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0);
1098
1097} 1099}
1098 1100
1099static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp) 1101static inline void myri10ge_check_statblock(struct myri10ge_priv *mgp)
@@ -1484,56 +1486,48 @@ static int myri10ge_allocate_rings(struct net_device *dev)
1484 goto abort_with_rx_small_info; 1486 goto abort_with_rx_small_info;
1485 1487
1486 /* Fill the receive rings */ 1488 /* Fill the receive rings */
1489 mgp->rx_big.cnt = 0;
1490 mgp->rx_small.cnt = 0;
1491 mgp->rx_big.fill_cnt = 0;
1492 mgp->rx_small.fill_cnt = 0;
1493 mgp->rx_small.page_offset = MYRI10GE_ALLOC_SIZE;
1494 mgp->rx_big.page_offset = MYRI10GE_ALLOC_SIZE;
1495 mgp->rx_small.watchdog_needed = 0;
1496 mgp->rx_big.watchdog_needed = 0;
1497 myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
1498 mgp->small_bytes + MXGEFW_PAD, 0);
1487 1499
1488 for (i = 0; i <= mgp->rx_small.mask; i++) { 1500 if (mgp->rx_small.fill_cnt < mgp->rx_small.mask + 1) {
1489 status = myri10ge_getbuf(&mgp->rx_small, mgp, 1501 printk(KERN_ERR "myri10ge: %s: alloced only %d small bufs\n",
1490 mgp->small_bytes, i); 1502 dev->name, mgp->rx_small.fill_cnt);
1491 if (status) { 1503 goto abort_with_rx_small_ring;
1492 printk(KERN_ERR
1493 "myri10ge: %s: alloced only %d small bufs\n",
1494 dev->name, i);
1495 goto abort_with_rx_small_ring;
1496 }
1497 } 1504 }
1498 1505
1499 for (i = 0; i <= mgp->rx_big.mask; i++) { 1506 myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 0);
1500 status = 1507 if (mgp->rx_big.fill_cnt < mgp->rx_big.mask + 1) {
1501 myri10ge_getbuf(&mgp->rx_big, mgp, dev->mtu + ETH_HLEN, i); 1508 printk(KERN_ERR "myri10ge: %s: alloced only %d big bufs\n",
1502 if (status) { 1509 dev->name, mgp->rx_big.fill_cnt);
1503 printk(KERN_ERR 1510 goto abort_with_rx_big_ring;
1504 "myri10ge: %s: alloced only %d big bufs\n",
1505 dev->name, i);
1506 goto abort_with_rx_big_ring;
1507 }
1508 } 1511 }
1509 1512
1510 return 0; 1513 return 0;
1511 1514
1512abort_with_rx_big_ring: 1515abort_with_rx_big_ring:
1513 for (i = 0; i <= mgp->rx_big.mask; i++) { 1516 for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) {
1514 if (mgp->rx_big.info[i].skb != NULL) 1517 int idx = i & mgp->rx_big.mask;
1515 dev_kfree_skb_any(mgp->rx_big.info[i].skb); 1518 myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx],
1516 if (pci_unmap_len(&mgp->rx_big.info[i], len)) 1519 mgp->big_bytes);
1517 pci_unmap_single(mgp->pdev, 1520 put_page(mgp->rx_big.info[idx].page);
1518 pci_unmap_addr(&mgp->rx_big.info[i],
1519 bus),
1520 pci_unmap_len(&mgp->rx_big.info[i],
1521 len),
1522 PCI_DMA_FROMDEVICE);
1523 } 1521 }
1524 1522
1525abort_with_rx_small_ring: 1523abort_with_rx_small_ring:
1526 for (i = 0; i <= mgp->rx_small.mask; i++) { 1524 for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) {
1527 if (mgp->rx_small.info[i].skb != NULL) 1525 int idx = i & mgp->rx_small.mask;
1528 dev_kfree_skb_any(mgp->rx_small.info[i].skb); 1526 myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx],
1529 if (pci_unmap_len(&mgp->rx_small.info[i], len)) 1527 mgp->small_bytes + MXGEFW_PAD);
1530 pci_unmap_single(mgp->pdev, 1528 put_page(mgp->rx_small.info[idx].page);
1531 pci_unmap_addr(&mgp->rx_small.info[i],
1532 bus),
1533 pci_unmap_len(&mgp->rx_small.info[i],
1534 len),
1535 PCI_DMA_FROMDEVICE);
1536 } 1529 }
1530
1537 kfree(mgp->rx_big.info); 1531 kfree(mgp->rx_big.info);
1538 1532
1539abort_with_rx_small_info: 1533abort_with_rx_small_info:
@@ -1566,30 +1560,24 @@ static void myri10ge_free_rings(struct net_device *dev)
1566 1560
1567 mgp = netdev_priv(dev); 1561 mgp = netdev_priv(dev);
1568 1562
1569 for (i = 0; i <= mgp->rx_big.mask; i++) { 1563 for (i = mgp->rx_big.cnt; i < mgp->rx_big.fill_cnt; i++) {
1570 if (mgp->rx_big.info[i].skb != NULL) 1564 idx = i & mgp->rx_big.mask;
1571 dev_kfree_skb_any(mgp->rx_big.info[i].skb); 1565 if (i == mgp->rx_big.fill_cnt - 1)
1572 if (pci_unmap_len(&mgp->rx_big.info[i], len)) 1566 mgp->rx_big.info[idx].page_offset = MYRI10GE_ALLOC_SIZE;
1573 pci_unmap_single(mgp->pdev, 1567 myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_big.info[idx],
1574 pci_unmap_addr(&mgp->rx_big.info[i], 1568 mgp->big_bytes);
1575 bus), 1569 put_page(mgp->rx_big.info[idx].page);
1576 pci_unmap_len(&mgp->rx_big.info[i],
1577 len),
1578 PCI_DMA_FROMDEVICE);
1579 }
1580
1581 for (i = 0; i <= mgp->rx_small.mask; i++) {
1582 if (mgp->rx_small.info[i].skb != NULL)
1583 dev_kfree_skb_any(mgp->rx_small.info[i].skb);
1584 if (pci_unmap_len(&mgp->rx_small.info[i], len))
1585 pci_unmap_single(mgp->pdev,
1586 pci_unmap_addr(&mgp->rx_small.info[i],
1587 bus),
1588 pci_unmap_len(&mgp->rx_small.info[i],
1589 len),
1590 PCI_DMA_FROMDEVICE);
1591 } 1570 }
1592 1571
1572 for (i = mgp->rx_small.cnt; i < mgp->rx_small.fill_cnt; i++) {
1573 idx = i & mgp->rx_small.mask;
1574 if (i == mgp->rx_small.fill_cnt - 1)
1575 mgp->rx_small.info[idx].page_offset =
1576 MYRI10GE_ALLOC_SIZE;
1577 myri10ge_unmap_rx_page(mgp->pdev, &mgp->rx_small.info[idx],
1578 mgp->small_bytes + MXGEFW_PAD);
1579 put_page(mgp->rx_small.info[idx].page);
1580 }
1593 tx = &mgp->tx; 1581 tx = &mgp->tx;
1594 while (tx->done != tx->req) { 1582 while (tx->done != tx->req) {
1595 idx = tx->done & tx->mask; 1583 idx = tx->done & tx->mask;
@@ -1657,19 +1645,18 @@ static int myri10ge_open(struct net_device *dev)
1657 */ 1645 */
1658 1646
1659 if (dev->mtu <= ETH_DATA_LEN) 1647 if (dev->mtu <= ETH_DATA_LEN)
1660 mgp->small_bytes = 128; /* enough for a TCP header */ 1648 /* enough for a TCP header */
1649 mgp->small_bytes = (128 > SMP_CACHE_BYTES)
1650 ? (128 - MXGEFW_PAD)
1651 : (SMP_CACHE_BYTES - MXGEFW_PAD);
1661 else 1652 else
1662 mgp->small_bytes = ETH_FRAME_LEN; /* enough for an ETH_DATA_LEN frame */ 1653 /* enough for a vlan encapsulated ETH_DATA_LEN frame */
1654 mgp->small_bytes = VLAN_ETH_FRAME_LEN;
1663 1655
1664 /* Override the small buffer size? */ 1656 /* Override the small buffer size? */
1665 if (myri10ge_small_bytes > 0) 1657 if (myri10ge_small_bytes > 0)
1666 mgp->small_bytes = myri10ge_small_bytes; 1658 mgp->small_bytes = myri10ge_small_bytes;
1667 1659
1668 /* If the user sets an obscenely small MTU, adjust the small
1669 * bytes down to nearly nothing */
1670 if (mgp->small_bytes >= (dev->mtu + ETH_HLEN))
1671 mgp->small_bytes = 64;
1672
1673 /* get the lanai pointers to the send and receive rings */ 1660 /* get the lanai pointers to the send and receive rings */
1674 1661
1675 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET, &cmd, 0); 1662 status |= myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_SEND_OFFSET, &cmd, 0);
@@ -1705,17 +1692,23 @@ static int myri10ge_open(struct net_device *dev)
1705 mgp->rx_big.wc_fifo = NULL; 1692 mgp->rx_big.wc_fifo = NULL;
1706 } 1693 }
1707 1694
1708 status = myri10ge_allocate_rings(dev);
1709 if (status != 0)
1710 goto abort_with_nothing;
1711
1712 /* Firmware needs the big buff size as a power of 2. Lie and 1695 /* Firmware needs the big buff size as a power of 2. Lie and
1713 * tell him the buffer is larger, because we only use 1 1696 * tell him the buffer is larger, because we only use 1
1714 * buffer/pkt, and the mtu will prevent overruns. 1697 * buffer/pkt, and the mtu will prevent overruns.
1715 */ 1698 */
1716 big_pow2 = dev->mtu + ETH_HLEN + MXGEFW_PAD; 1699 big_pow2 = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
1717 while ((big_pow2 & (big_pow2 - 1)) != 0) 1700 if (big_pow2 < MYRI10GE_ALLOC_SIZE / 2) {
1718 big_pow2++; 1701 while ((big_pow2 & (big_pow2 - 1)) != 0)
1702 big_pow2++;
1703 mgp->big_bytes = dev->mtu + ETH_HLEN + VLAN_HLEN + MXGEFW_PAD;
1704 } else {
1705 big_pow2 = MYRI10GE_ALLOC_SIZE;
1706 mgp->big_bytes = big_pow2;
1707 }
1708
1709 status = myri10ge_allocate_rings(dev);
1710 if (status != 0)
1711 goto abort_with_nothing;
1719 1712
1720 /* now give firmware buffers sizes, and MTU */ 1713 /* now give firmware buffers sizes, and MTU */
1721 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN; 1714 cmd.data0 = dev->mtu + ETH_HLEN + VLAN_HLEN;
@@ -2206,7 +2199,7 @@ static void myri10ge_set_multicast_list(struct net_device *dev)
2206 struct myri10ge_cmd cmd; 2199 struct myri10ge_cmd cmd;
2207 struct myri10ge_priv *mgp; 2200 struct myri10ge_priv *mgp;
2208 struct dev_mc_list *mc_list; 2201 struct dev_mc_list *mc_list;
2209 __be32 data[2] = {0, 0}; 2202 __be32 data[2] = { 0, 0 };
2210 int err; 2203 int err;
2211 2204
2212 mgp = netdev_priv(dev); 2205 mgp = netdev_priv(dev);
@@ -2625,7 +2618,7 @@ static u32 myri10ge_read_reboot(struct myri10ge_priv *mgp)
2625static void myri10ge_watchdog(struct work_struct *work) 2618static void myri10ge_watchdog(struct work_struct *work)
2626{ 2619{
2627 struct myri10ge_priv *mgp = 2620 struct myri10ge_priv *mgp =
2628 container_of(work, struct myri10ge_priv, watchdog_work); 2621 container_of(work, struct myri10ge_priv, watchdog_work);
2629 u32 reboot; 2622 u32 reboot;
2630 int status; 2623 int status;
2631 u16 cmd, vendor; 2624 u16 cmd, vendor;
@@ -2698,6 +2691,21 @@ static void myri10ge_watchdog_timer(unsigned long arg)
2698 struct myri10ge_priv *mgp; 2691 struct myri10ge_priv *mgp;
2699 2692
2700 mgp = (struct myri10ge_priv *)arg; 2693 mgp = (struct myri10ge_priv *)arg;
2694
2695 if (mgp->rx_small.watchdog_needed) {
2696 myri10ge_alloc_rx_pages(mgp, &mgp->rx_small,
2697 mgp->small_bytes + MXGEFW_PAD, 1);
2698 if (mgp->rx_small.fill_cnt - mgp->rx_small.cnt >=
2699 myri10ge_fill_thresh)
2700 mgp->rx_small.watchdog_needed = 0;
2701 }
2702 if (mgp->rx_big.watchdog_needed) {
2703 myri10ge_alloc_rx_pages(mgp, &mgp->rx_big, mgp->big_bytes, 1);
2704 if (mgp->rx_big.fill_cnt - mgp->rx_big.cnt >=
2705 myri10ge_fill_thresh)
2706 mgp->rx_big.watchdog_needed = 0;
2707 }
2708
2701 if (mgp->tx.req != mgp->tx.done && 2709 if (mgp->tx.req != mgp->tx.done &&
2702 mgp->tx.done == mgp->watchdog_tx_done && 2710 mgp->tx.done == mgp->watchdog_tx_done &&
2703 mgp->watchdog_tx_req != mgp->watchdog_tx_done) 2711 mgp->watchdog_tx_req != mgp->watchdog_tx_done)
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 9367c574477a..d2767e6584a9 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -362,96 +362,6 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
362 362
363#define SMC_IRQ_FLAGS (0) 363#define SMC_IRQ_FLAGS (0)
364 364
365#elif defined(CONFIG_ARCH_VERSATILE)
366
367#define SMC_CAN_USE_8BIT 1
368#define SMC_CAN_USE_16BIT 1
369#define SMC_CAN_USE_32BIT 1
370#define SMC_NOWAIT 1
371
372#define SMC_inb(a, r) readb((a) + (r))
373#define SMC_inw(a, r) readw((a) + (r))
374#define SMC_inl(a, r) readl((a) + (r))
375#define SMC_outb(v, a, r) writeb(v, (a) + (r))
376#define SMC_outw(v, a, r) writew(v, (a) + (r))
377#define SMC_outl(v, a, r) writel(v, (a) + (r))
378#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
379#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
380
381#define SMC_IRQ_FLAGS (0)
382
383#elif defined(CONFIG_ARCH_VERSATILE)
384
385#define SMC_CAN_USE_8BIT 1
386#define SMC_CAN_USE_16BIT 1
387#define SMC_CAN_USE_32BIT 1
388#define SMC_NOWAIT 1
389
390#define SMC_inb(a, r) readb((a) + (r))
391#define SMC_inw(a, r) readw((a) + (r))
392#define SMC_inl(a, r) readl((a) + (r))
393#define SMC_outb(v, a, r) writeb(v, (a) + (r))
394#define SMC_outw(v, a, r) writew(v, (a) + (r))
395#define SMC_outl(v, a, r) writel(v, (a) + (r))
396#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
397#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
398
399#define SMC_IRQ_FLAGS (0)
400
401#elif defined(CONFIG_ARCH_VERSATILE)
402
403#define SMC_CAN_USE_8BIT 1
404#define SMC_CAN_USE_16BIT 1
405#define SMC_CAN_USE_32BIT 1
406#define SMC_NOWAIT 1
407
408#define SMC_inb(a, r) readb((a) + (r))
409#define SMC_inw(a, r) readw((a) + (r))
410#define SMC_inl(a, r) readl((a) + (r))
411#define SMC_outb(v, a, r) writeb(v, (a) + (r))
412#define SMC_outw(v, a, r) writew(v, (a) + (r))
413#define SMC_outl(v, a, r) writel(v, (a) + (r))
414#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
415#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
416
417#define SMC_IRQ_FLAGS (0)
418
419#elif defined(CONFIG_ARCH_VERSATILE)
420
421#define SMC_CAN_USE_8BIT 1
422#define SMC_CAN_USE_16BIT 1
423#define SMC_CAN_USE_32BIT 1
424#define SMC_NOWAIT 1
425
426#define SMC_inb(a, r) readb((a) + (r))
427#define SMC_inw(a, r) readw((a) + (r))
428#define SMC_inl(a, r) readl((a) + (r))
429#define SMC_outb(v, a, r) writeb(v, (a) + (r))
430#define SMC_outw(v, a, r) writew(v, (a) + (r))
431#define SMC_outl(v, a, r) writel(v, (a) + (r))
432#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
433#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
434
435#define SMC_IRQ_FLAGS (0)
436
437#elif defined(CONFIG_ARCH_VERSATILE)
438
439#define SMC_CAN_USE_8BIT 1
440#define SMC_CAN_USE_16BIT 1
441#define SMC_CAN_USE_32BIT 1
442#define SMC_NOWAIT 1
443
444#define SMC_inb(a, r) readb((a) + (r))
445#define SMC_inw(a, r) readw((a) + (r))
446#define SMC_inl(a, r) readl((a) + (r))
447#define SMC_outb(v, a, r) writeb(v, (a) + (r))
448#define SMC_outw(v, a, r) writew(v, (a) + (r))
449#define SMC_outl(v, a, r) writel(v, (a) + (r))
450#define SMC_insl(a, r, p, l) readsl((a) + (r), p, l)
451#define SMC_outsl(a, r, p, l) writesl((a) + (r), p, l)
452
453#define SMC_IRQ_FLAGS (0)
454
455#else 365#else
456 366
457#define SMC_CAN_USE_8BIT 1 367#define SMC_CAN_USE_8BIT 1
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 1f05511fa390..8243150f5b05 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -194,9 +194,9 @@ static void enqueue(struct list_head *node, struct list_head *lh)
194{ 194{
195 unsigned long flags; 195 unsigned long flags;
196 196
197 spin_lock_irqsave(ugeth_lock, flags); 197 spin_lock_irqsave(&ugeth_lock, flags);
198 list_add_tail(node, lh); 198 list_add_tail(node, lh);
199 spin_unlock_irqrestore(ugeth_lock, flags); 199 spin_unlock_irqrestore(&ugeth_lock, flags);
200} 200}
201#endif /* CONFIG_UGETH_FILTERING */ 201#endif /* CONFIG_UGETH_FILTERING */
202 202
@@ -204,14 +204,14 @@ static struct list_head *dequeue(struct list_head *lh)
204{ 204{
205 unsigned long flags; 205 unsigned long flags;
206 206
207 spin_lock_irqsave(ugeth_lock, flags); 207 spin_lock_irqsave(&ugeth_lock, flags);
208 if (!list_empty(lh)) { 208 if (!list_empty(lh)) {
209 struct list_head *node = lh->next; 209 struct list_head *node = lh->next;
210 list_del(node); 210 list_del(node);
211 spin_unlock_irqrestore(ugeth_lock, flags); 211 spin_unlock_irqrestore(&ugeth_lock, flags);
212 return node; 212 return node;
213 } else { 213 } else {
214 spin_unlock_irqrestore(ugeth_lock, flags); 214 spin_unlock_irqrestore(&ugeth_lock, flags);
215 return NULL; 215 return NULL;
216 } 216 }
217} 217}
@@ -1852,6 +1852,8 @@ static int init_phy(struct net_device *dev)
1852 mii_info->mdio_read = &read_phy_reg; 1852 mii_info->mdio_read = &read_phy_reg;
1853 mii_info->mdio_write = &write_phy_reg; 1853 mii_info->mdio_write = &write_phy_reg;
1854 1854
1855 spin_lock_init(&mii_info->mdio_lock);
1856
1855 ugeth->mii_info = mii_info; 1857 ugeth->mii_info = mii_info;
1856 1858
1857 spin_lock_irq(&ugeth->lock); 1859 spin_lock_irq(&ugeth->lock);
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index 74f894795a1b..4587f23f4e4b 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -3132,7 +3132,7 @@ static u16 wol_calc_crc(int size, u8 * pattern, u8 *mask_pattern)
3132 } 3132 }
3133 /* Finally, invert the result once to get the correct data */ 3133 /* Finally, invert the result once to get the correct data */
3134 crc = ~crc; 3134 crc = ~crc;
3135 return bitreverse(crc) >> 16; 3135 return bitrev32(crc) >> 16;
3136} 3136}
3137 3137
3138/** 3138/**
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index d5ab9cf13257..21f76f51c95e 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -382,7 +382,7 @@ config SDLA
382 382
383# Wan router core. 383# Wan router core.
384config WAN_ROUTER_DRIVERS 384config WAN_ROUTER_DRIVERS
385 bool "WAN router drivers" 385 tristate "WAN router drivers"
386 depends on WAN && WAN_ROUTER 386 depends on WAN && WAN_ROUTER
387 ---help--- 387 ---help---
388 Connect LAN to WAN via Linux box. 388 Connect LAN to WAN via Linux box.
@@ -393,7 +393,8 @@ config WAN_ROUTER_DRIVERS
393 <file:Documentation/networking/wan-router.txt>. 393 <file:Documentation/networking/wan-router.txt>.
394 394
395 Note that the answer to this question won't directly affect the 395 Note that the answer to this question won't directly affect the
396 kernel: saying N will just cause the configurator to skip all 396 kernel except for how subordinate drivers may be built:
397 saying N will just cause the configurator to skip all
397 the questions about WAN router drivers. 398 the questions about WAN router drivers.
398 399
399 If unsure, say N. 400 If unsure, say N.
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index e1bf8b93f958..6c7dfb50143f 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -974,12 +974,12 @@ static int cosa_open(struct inode *inode, struct file *file)
974 unsigned long flags; 974 unsigned long flags;
975 int n; 975 int n;
976 976
977 if ((n=iminor(file->f_dentry->d_inode)>>CARD_MINOR_BITS) 977 if ((n=iminor(file->f_path.dentry->d_inode)>>CARD_MINOR_BITS)
978 >= nr_cards) 978 >= nr_cards)
979 return -ENODEV; 979 return -ENODEV;
980 cosa = cosa_cards+n; 980 cosa = cosa_cards+n;
981 981
982 if ((n=iminor(file->f_dentry->d_inode) 982 if ((n=iminor(file->f_path.dentry->d_inode)
983 & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) 983 & ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels)
984 return -ENODEV; 984 return -ENODEV;
985 chan = cosa->chan + n; 985 chan = cosa->chan + n;
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index 337c692f6fd6..ce3a8bac66ff 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -798,7 +798,7 @@ static unsigned int get_baud(struct tty_struct *tty)
798 */ 798 */
799static void set_baud(struct tty_struct *tty, unsigned int baudcode) 799static void set_baud(struct tty_struct *tty, unsigned int baudcode)
800{ 800{
801 struct termios old_termios = *(tty->termios); 801 struct ktermios old_termios = *(tty->termios);
802 tty->termios->c_cflag &= ~CBAUD; /* Clear the old baud setting */ 802 tty->termios->c_cflag &= ~CBAUD; /* Clear the old baud setting */
803 tty->termios->c_cflag |= baudcode; /* Set the new baud setting */ 803 tty->termios->c_cflag |= baudcode; /* Set the new baud setting */
804 tty->driver->set_termios(tty, &old_termios); 804 tty->driver->set_termios(tty, &old_termios);
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 43e521e99126..78c2e6e4b42e 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -220,8 +220,8 @@ static unsigned long get_exec_dcookie(struct mm_struct * mm)
220 continue; 220 continue;
221 if (!(vma->vm_flags & VM_EXECUTABLE)) 221 if (!(vma->vm_flags & VM_EXECUTABLE))
222 continue; 222 continue;
223 cookie = fast_get_dcookie(vma->vm_file->f_dentry, 223 cookie = fast_get_dcookie(vma->vm_file->f_path.dentry,
224 vma->vm_file->f_vfsmnt); 224 vma->vm_file->f_path.mnt);
225 break; 225 break;
226 } 226 }
227 227
@@ -246,8 +246,8 @@ static unsigned long lookup_dcookie(struct mm_struct * mm, unsigned long addr, o
246 continue; 246 continue;
247 247
248 if (vma->vm_file) { 248 if (vma->vm_file) {
249 cookie = fast_get_dcookie(vma->vm_file->f_dentry, 249 cookie = fast_get_dcookie(vma->vm_file->f_path.dentry,
250 vma->vm_file->f_vfsmnt); 250 vma->vm_file->f_path.mnt);
251 *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr - 251 *offset = (vma->vm_pgoff << PAGE_SHIFT) + addr -
252 vma->vm_start; 252 vma->vm_start;
253 } else { 253 } else {
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig
index c7fa28a28b9f..36c6a1bfe558 100644
--- a/drivers/parport/Kconfig
+++ b/drivers/parport/Kconfig
@@ -82,9 +82,6 @@ config PARPORT_PC_PCMCIA
82 Say Y here if you need PCMCIA support for your PC-style parallel 82 Say Y here if you need PCMCIA support for your PC-style parallel
83 ports. If unsure, say N. 83 ports. If unsure, say N.
84 84
85config PARPORT_NOT_PC
86 bool
87
88config PARPORT_IP32 85config PARPORT_IP32
89 tristate "SGI IP32 builtin port (EXPERIMENTAL)" 86 tristate "SGI IP32 builtin port (EXPERIMENTAL)"
90 depends on SGI_IP32 && PARPORT && EXPERIMENTAL 87 depends on SGI_IP32 && PARPORT && EXPERIMENTAL
@@ -158,5 +155,8 @@ config PARPORT_1284
158 transfer modes. Also say Y if you want device ID information to 155 transfer modes. Also say Y if you want device ID information to
159 appear in /proc/sys/dev/parport/*/autoprobe*. It is safe to say N. 156 appear in /proc/sys/dev/parport/*/autoprobe*. It is safe to say N.
160 157
158config PARPORT_NOT_PC
159 bool
160
161endmenu 161endmenu
162 162
diff --git a/drivers/pci/hotplug/Kconfig b/drivers/pci/hotplug/Kconfig
index 6e780db9454d..adce4204d87d 100644
--- a/drivers/pci/hotplug/Kconfig
+++ b/drivers/pci/hotplug/Kconfig
@@ -76,7 +76,8 @@ config HOTPLUG_PCI_IBM
76 76
77config HOTPLUG_PCI_ACPI 77config HOTPLUG_PCI_ACPI
78 tristate "ACPI PCI Hotplug driver" 78 tristate "ACPI PCI Hotplug driver"
79 depends on (!ACPI_DOCK && ACPI && HOTPLUG_PCI) || (ACPI_DOCK && HOTPLUG_PCI) 79 depends on HOTPLUG_PCI
80 depends on (!ACPI_DOCK && ACPI) || (ACPI_DOCK)
80 help 81 help
81 Say Y here if you have a system that supports PCI Hotplug using 82 Say Y here if you have a system that supports PCI Hotplug using
82 ACPI. 83 ACPI.
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 99cf33379769..4a6760a3b31f 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -23,7 +23,7 @@ static loff_t
23proc_bus_pci_lseek(struct file *file, loff_t off, int whence) 23proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
24{ 24{
25 loff_t new = -1; 25 loff_t new = -1;
26 struct inode *inode = file->f_dentry->d_inode; 26 struct inode *inode = file->f_path.dentry->d_inode;
27 27
28 mutex_lock(&inode->i_mutex); 28 mutex_lock(&inode->i_mutex);
29 switch (whence) { 29 switch (whence) {
@@ -48,7 +48,7 @@ proc_bus_pci_lseek(struct file *file, loff_t off, int whence)
48static ssize_t 48static ssize_t
49proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 49proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
50{ 50{
51 const struct inode *ino = file->f_dentry->d_inode; 51 const struct inode *ino = file->f_path.dentry->d_inode;
52 const struct proc_dir_entry *dp = PDE(ino); 52 const struct proc_dir_entry *dp = PDE(ino);
53 struct pci_dev *dev = dp->data; 53 struct pci_dev *dev = dp->data;
54 unsigned int pos = *ppos; 54 unsigned int pos = *ppos;
@@ -130,7 +130,7 @@ proc_bus_pci_read(struct file *file, char __user *buf, size_t nbytes, loff_t *pp
130static ssize_t 130static ssize_t
131proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos) 131proc_bus_pci_write(struct file *file, const char __user *buf, size_t nbytes, loff_t *ppos)
132{ 132{
133 const struct inode *ino = file->f_dentry->d_inode; 133 const struct inode *ino = file->f_path.dentry->d_inode;
134 const struct proc_dir_entry *dp = PDE(ino); 134 const struct proc_dir_entry *dp = PDE(ino);
135 struct pci_dev *dev = dp->data; 135 struct pci_dev *dev = dp->data;
136 int pos = *ppos; 136 int pos = *ppos;
@@ -245,7 +245,7 @@ static int proc_bus_pci_ioctl(struct inode *inode, struct file *file, unsigned i
245#ifdef HAVE_PCI_MMAP 245#ifdef HAVE_PCI_MMAP
246static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma) 246static int proc_bus_pci_mmap(struct file *file, struct vm_area_struct *vma)
247{ 247{
248 struct inode *inode = file->f_dentry->d_inode; 248 struct inode *inode = file->f_path.dentry->d_inode;
249 const struct proc_dir_entry *dp = PDE(inode); 249 const struct proc_dir_entry *dp = PDE(inode);
250 struct pci_dev *dev = dp->data; 250 struct pci_dev *dev = dp->data;
251 struct pci_filp_private *fpriv = file->private_data; 251 struct pci_filp_private *fpriv = file->private_data;
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index d077870c6731..327372b7a54e 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -486,7 +486,7 @@ static ssize_t ds_read(struct file *file, char __user *buf,
486 user_info_t *user; 486 user_info_t *user;
487 int ret; 487 int ret;
488 488
489 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_dentry->d_inode)); 489 ds_dbg(2, "ds_read(socket %d)\n", iminor(file->f_path.dentry->d_inode));
490 490
491 if (count < 4) 491 if (count < 4)
492 return -EINVAL; 492 return -EINVAL;
@@ -511,7 +511,7 @@ static ssize_t ds_read(struct file *file, char __user *buf,
511static ssize_t ds_write(struct file *file, const char __user *buf, 511static ssize_t ds_write(struct file *file, const char __user *buf,
512 size_t count, loff_t *ppos) 512 size_t count, loff_t *ppos)
513{ 513{
514 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_dentry->d_inode)); 514 ds_dbg(2, "ds_write(socket %d)\n", iminor(file->f_path.dentry->d_inode));
515 515
516 if (count != 4) 516 if (count != 4)
517 return -EINVAL; 517 return -EINVAL;
@@ -529,7 +529,7 @@ static u_int ds_poll(struct file *file, poll_table *wait)
529 struct pcmcia_socket *s; 529 struct pcmcia_socket *s;
530 user_info_t *user; 530 user_info_t *user;
531 531
532 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_dentry->d_inode)); 532 ds_dbg(2, "ds_poll(socket %d)\n", iminor(file->f_path.dentry->d_inode));
533 533
534 user = file->private_data; 534 user = file->private_data;
535 if (CHECK_USER(user)) 535 if (CHECK_USER(user))
diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c
index 958c11bedd0d..d21f3c1e72fc 100644
--- a/drivers/pnp/isapnp/proc.c
+++ b/drivers/pnp/isapnp/proc.c
@@ -56,7 +56,7 @@ static loff_t isapnp_proc_bus_lseek(struct file *file, loff_t off, int whence)
56 56
57static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 57static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
58{ 58{
59 struct inode *ino = file->f_dentry->d_inode; 59 struct inode *ino = file->f_path.dentry->d_inode;
60 struct proc_dir_entry *dp = PDE(ino); 60 struct proc_dir_entry *dp = PDE(ino);
61 struct pnp_dev *dev = dp->data; 61 struct pnp_dev *dev = dp->data;
62 int pos = *ppos; 62 int pos = *ppos;
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index b52d547b7a78..8433eb7562cb 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1 +1,2 @@
1obj-y += system-bus.o 1obj-y += system-bus.o
2obj-$(CONFIG_PS3_VUART) += vuart.o
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
new file mode 100644
index 000000000000..6974f65bcda5
--- /dev/null
+++ b/drivers/ps3/vuart.c
@@ -0,0 +1,965 @@
1/*
2 * PS3 virtual uart
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/interrupt.h>
24#include <asm/ps3.h>
25
26#include <asm/lv1call.h>
27#include <asm/bitops.h>
28
29#include "vuart.h"
30
31MODULE_AUTHOR("Sony Corporation");
32MODULE_LICENSE("GPL v2");
33MODULE_DESCRIPTION("ps3 vuart");
34
35/**
36 * vuart - An inter-partition data link service.
37 * port 0: PS3 AV Settings.
38 * port 2: PS3 System Manager.
39 *
40 * The vuart provides a bi-directional byte stream data link between logical
41 * partitions. Its primary role is as a communications link between the guest
42 * OS and the system policy module. The current HV does not support any
43 * connections other than those listed.
44 */
45
46enum {PORT_COUNT = 3,};
47
48enum vuart_param {
49 PARAM_TX_TRIGGER = 0,
50 PARAM_RX_TRIGGER = 1,
51 PARAM_INTERRUPT_MASK = 2,
52 PARAM_RX_BUF_SIZE = 3, /* read only */
53 PARAM_RX_BYTES = 4, /* read only */
54 PARAM_TX_BUF_SIZE = 5, /* read only */
55 PARAM_TX_BYTES = 6, /* read only */
56 PARAM_INTERRUPT_STATUS = 7, /* read only */
57};
58
59enum vuart_interrupt_bit {
60 INTERRUPT_BIT_TX = 0,
61 INTERRUPT_BIT_RX = 1,
62 INTERRUPT_BIT_DISCONNECT = 2,
63};
64
65enum vuart_interrupt_mask {
66 INTERRUPT_MASK_TX = 1,
67 INTERRUPT_MASK_RX = 2,
68 INTERRUPT_MASK_DISCONNECT = 4,
69};
70
71/**
72 * struct ports_bmp - bitmap indicating ports needing service.
73 *
74 * A 256 bit read only bitmap indicating ports needing service. Do not write
75 * to these bits. Must not cross a page boundary.
76 */
77
78struct ports_bmp {
79 u64 status;
80 u64 unused[3];
81} __attribute__ ((aligned (32)));
82
83/* redefine dev_dbg to do a syntax check */
84
85#if !defined(DEBUG)
86#undef dev_dbg
87static inline int __attribute__ ((format (printf, 2, 3))) dev_dbg(
88 const struct device *_dev, const char *fmt, ...) {return 0;}
89#endif
90
91#define dump_ports_bmp(_b) _dump_ports_bmp(_b, __func__, __LINE__)
92static void __attribute__ ((unused)) _dump_ports_bmp(
93 const struct ports_bmp* bmp, const char* func, int line)
94{
95 pr_debug("%s:%d: ports_bmp: %016lxh\n", func, line, bmp->status);
96}
97
98static int ps3_vuart_match_id_to_port(enum ps3_match_id match_id,
99 unsigned int *port_number)
100{
101 switch(match_id) {
102 case PS3_MATCH_ID_AV_SETTINGS:
103 *port_number = 0;
104 return 0;
105 case PS3_MATCH_ID_SYSTEM_MANAGER:
106 *port_number = 2;
107 return 0;
108 default:
109 WARN_ON(1);
110 *port_number = UINT_MAX;
111 return -EINVAL;
112 };
113}
114
115#define dump_port_params(_b) _dump_port_params(_b, __func__, __LINE__)
116static void __attribute__ ((unused)) _dump_port_params(unsigned int port_number,
117 const char* func, int line)
118{
119#if defined(DEBUG)
120 static const char *strings[] = {
121 "tx_trigger ",
122 "rx_trigger ",
123 "interrupt_mask ",
124 "rx_buf_size ",
125 "rx_bytes ",
126 "tx_buf_size ",
127 "tx_bytes ",
128 "interrupt_status",
129 };
130 int result;
131 unsigned int i;
132 u64 value;
133
134 for (i = 0; i < ARRAY_SIZE(strings); i++) {
135 result = lv1_get_virtual_uart_param(port_number, i, &value);
136
137 if (result) {
138 pr_debug("%s:%d: port_%u: %s failed: %s\n", func, line,
139 port_number, strings[i], ps3_result(result));
140 continue;
141 }
142 pr_debug("%s:%d: port_%u: %s = %lxh\n",
143 func, line, port_number, strings[i], value);
144 }
145#endif
146}
147
148struct vuart_triggers {
149 unsigned long rx;
150 unsigned long tx;
151};
152
153int ps3_vuart_get_triggers(struct ps3_vuart_port_device *dev,
154 struct vuart_triggers *trig)
155{
156 int result;
157 unsigned long size;
158 unsigned long val;
159
160 result = lv1_get_virtual_uart_param(dev->port_number,
161 PARAM_TX_TRIGGER, &trig->tx);
162
163 if (result) {
164 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
165 __func__, __LINE__, ps3_result(result));
166 return result;
167 }
168
169 result = lv1_get_virtual_uart_param(dev->port_number,
170 PARAM_RX_BUF_SIZE, &size);
171
172 if (result) {
173 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
174 __func__, __LINE__, ps3_result(result));
175 return result;
176 }
177
178 result = lv1_get_virtual_uart_param(dev->port_number,
179 PARAM_RX_TRIGGER, &val);
180
181 if (result) {
182 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
183 __func__, __LINE__, ps3_result(result));
184 return result;
185 }
186
187 trig->rx = size - val;
188
189 dev_dbg(&dev->core, "%s:%d: tx %lxh, rx %lxh\n", __func__, __LINE__,
190 trig->tx, trig->rx);
191
192 return result;
193}
194
195int ps3_vuart_set_triggers(struct ps3_vuart_port_device *dev, unsigned int tx,
196 unsigned int rx)
197{
198 int result;
199 unsigned long size;
200
201 result = lv1_set_virtual_uart_param(dev->port_number,
202 PARAM_TX_TRIGGER, tx);
203
204 if (result) {
205 dev_dbg(&dev->core, "%s:%d: tx_trigger failed: %s\n",
206 __func__, __LINE__, ps3_result(result));
207 return result;
208 }
209
210 result = lv1_get_virtual_uart_param(dev->port_number,
211 PARAM_RX_BUF_SIZE, &size);
212
213 if (result) {
214 dev_dbg(&dev->core, "%s:%d: tx_buf_size failed: %s\n",
215 __func__, __LINE__, ps3_result(result));
216 return result;
217 }
218
219 result = lv1_set_virtual_uart_param(dev->port_number,
220 PARAM_RX_TRIGGER, size - rx);
221
222 if (result) {
223 dev_dbg(&dev->core, "%s:%d: rx_trigger failed: %s\n",
224 __func__, __LINE__, ps3_result(result));
225 return result;
226 }
227
228 dev_dbg(&dev->core, "%s:%d: tx %xh, rx %xh\n", __func__, __LINE__,
229 tx, rx);
230
231 return result;
232}
233
234static int ps3_vuart_get_rx_bytes_waiting(struct ps3_vuart_port_device *dev,
235 unsigned long *bytes_waiting)
236{
237 int result = lv1_get_virtual_uart_param(dev->port_number,
238 PARAM_RX_BYTES, bytes_waiting);
239
240 if (result)
241 dev_dbg(&dev->core, "%s:%d: rx_bytes failed: %s\n",
242 __func__, __LINE__, ps3_result(result));
243
244 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__,
245 *bytes_waiting);
246 return result;
247}
248
249static int ps3_vuart_set_interrupt_mask(struct ps3_vuart_port_device *dev,
250 unsigned long mask)
251{
252 int result;
253
254 dev_dbg(&dev->core, "%s:%d: %lxh\n", __func__, __LINE__, mask);
255
256 dev->interrupt_mask = mask;
257
258 result = lv1_set_virtual_uart_param(dev->port_number,
259 PARAM_INTERRUPT_MASK, dev->interrupt_mask);
260
261 if (result)
262 dev_dbg(&dev->core, "%s:%d: interrupt_mask failed: %s\n",
263 __func__, __LINE__, ps3_result(result));
264
265 return result;
266}
267
268static int ps3_vuart_get_interrupt_mask(struct ps3_vuart_port_device *dev,
269 unsigned long *status)
270{
271 int result = lv1_get_virtual_uart_param(dev->port_number,
272 PARAM_INTERRUPT_STATUS, status);
273
274 if (result)
275 dev_dbg(&dev->core, "%s:%d: interrupt_status failed: %s\n",
276 __func__, __LINE__, ps3_result(result));
277
278 dev_dbg(&dev->core, "%s:%d: m %lxh, s %lxh, m&s %lxh\n",
279 __func__, __LINE__, dev->interrupt_mask, *status,
280 dev->interrupt_mask & *status);
281
282 return result;
283}
284
285int ps3_vuart_enable_interrupt_tx(struct ps3_vuart_port_device *dev)
286{
287 return (dev->interrupt_mask & INTERRUPT_MASK_TX) ? 0
288 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
289 | INTERRUPT_MASK_TX);
290}
291
292int ps3_vuart_enable_interrupt_rx(struct ps3_vuart_port_device *dev)
293{
294 return (dev->interrupt_mask & INTERRUPT_MASK_RX) ? 0
295 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
296 | INTERRUPT_MASK_RX);
297}
298
299int ps3_vuart_enable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
300{
301 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT) ? 0
302 : ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
303 | INTERRUPT_MASK_DISCONNECT);
304}
305
306int ps3_vuart_disable_interrupt_tx(struct ps3_vuart_port_device *dev)
307{
308 return (dev->interrupt_mask & INTERRUPT_MASK_TX)
309 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
310 & ~INTERRUPT_MASK_TX) : 0;
311}
312
313int ps3_vuart_disable_interrupt_rx(struct ps3_vuart_port_device *dev)
314{
315 return (dev->interrupt_mask & INTERRUPT_MASK_RX)
316 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
317 & ~INTERRUPT_MASK_RX) : 0;
318}
319
320int ps3_vuart_disable_interrupt_disconnect(struct ps3_vuart_port_device *dev)
321{
322 return (dev->interrupt_mask & INTERRUPT_MASK_DISCONNECT)
323 ? ps3_vuart_set_interrupt_mask(dev, dev->interrupt_mask
324 & ~INTERRUPT_MASK_DISCONNECT) : 0;
325}
326
327/**
328 * ps3_vuart_raw_write - Low level write helper.
329 *
330 * Do not call ps3_vuart_raw_write directly, use ps3_vuart_write.
331 */
332
333static int ps3_vuart_raw_write(struct ps3_vuart_port_device *dev,
334 const void* buf, unsigned int bytes, unsigned long *bytes_written)
335{
336 int result;
337
338 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
339
340 result = lv1_write_virtual_uart(dev->port_number,
341 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_written);
342
343 if (result) {
344 dev_dbg(&dev->core, "%s:%d: lv1_write_virtual_uart failed: "
345 "%s\n", __func__, __LINE__, ps3_result(result));
346 return result;
347 }
348
349 dev->stats.bytes_written += *bytes_written;
350
351 dev_dbg(&dev->core, "%s:%d: wrote %lxh/%xh=>%lxh\n", __func__,
352 __LINE__, *bytes_written, bytes, dev->stats.bytes_written);
353
354 return result;
355}
356
357/**
358 * ps3_vuart_raw_read - Low level read helper.
359 *
360 * Do not call ps3_vuart_raw_read directly, use ps3_vuart_read.
361 */
362
363static int ps3_vuart_raw_read(struct ps3_vuart_port_device *dev, void* buf,
364 unsigned int bytes, unsigned long *bytes_read)
365{
366 int result;
367
368 dev_dbg(&dev->core, "%s:%d: %xh\n", __func__, __LINE__, bytes);
369
370 result = lv1_read_virtual_uart(dev->port_number,
371 ps3_mm_phys_to_lpar(__pa(buf)), bytes, bytes_read);
372
373 if (result) {
374 dev_dbg(&dev->core, "%s:%d: lv1_read_virtual_uart failed: %s\n",
375 __func__, __LINE__, ps3_result(result));
376 return result;
377 }
378
379 dev->stats.bytes_read += *bytes_read;
380
381 dev_dbg(&dev->core, "%s:%d: read %lxh/%xh=>%lxh\n", __func__, __LINE__,
382 *bytes_read, bytes, dev->stats.bytes_read);
383
384 return result;
385}
386
387/**
388 * struct list_buffer - An element for a port device fifo buffer list.
389 */
390
391struct list_buffer {
392 struct list_head link;
393 const unsigned char *head;
394 const unsigned char *tail;
395 unsigned long dbg_number;
396 unsigned char data[];
397};
398
399/**
400 * ps3_vuart_write - the entry point for writing data to a port
401 *
402 * If the port is idle on entry as much of the incoming data is written to
403 * the port as the port will accept. Otherwise a list buffer is created
404 * and any remaning incoming data is copied to that buffer. The buffer is
405 * then enqueued for transmision via the transmit interrupt.
406 */
407
408int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
409 unsigned int bytes)
410{
411 static unsigned long dbg_number;
412 int result;
413 unsigned long flags;
414 struct list_buffer *lb;
415
416 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
417 bytes, bytes);
418
419 spin_lock_irqsave(&dev->tx_list.lock, flags);
420
421 if (list_empty(&dev->tx_list.head)) {
422 unsigned long bytes_written;
423
424 result = ps3_vuart_raw_write(dev, buf, bytes, &bytes_written);
425
426 spin_unlock_irqrestore(&dev->tx_list.lock, flags);
427
428 if (result) {
429 dev_dbg(&dev->core,
430 "%s:%d: ps3_vuart_raw_write failed\n",
431 __func__, __LINE__);
432 return result;
433 }
434
435 if (bytes_written == bytes) {
436 dev_dbg(&dev->core, "%s:%d: wrote %xh bytes\n",
437 __func__, __LINE__, bytes);
438 return 0;
439 }
440
441 bytes -= bytes_written;
442 buf += bytes_written;
443 } else
444 spin_unlock_irqrestore(&dev->tx_list.lock, flags);
445
446 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_KERNEL);
447
448 if (!lb) {
449 return -ENOMEM;
450 }
451
452 memcpy(lb->data, buf, bytes);
453 lb->head = lb->data;
454 lb->tail = lb->data + bytes;
455 lb->dbg_number = ++dbg_number;
456
457 spin_lock_irqsave(&dev->tx_list.lock, flags);
458 list_add_tail(&lb->link, &dev->tx_list.head);
459 ps3_vuart_enable_interrupt_tx(dev);
460 spin_unlock_irqrestore(&dev->tx_list.lock, flags);
461
462 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %xh bytes\n",
463 __func__, __LINE__, lb->dbg_number, bytes);
464
465 return 0;
466}
467
468/**
469 * ps3_vuart_read - the entry point for reading data from a port
470 *
471 * If enough bytes to satisfy the request are held in the buffer list those
472 * bytes are dequeued and copied to the caller's buffer. Emptied list buffers
473 * are retiered. If the request cannot be statified by bytes held in the list
474 * buffers -EAGAIN is returned.
475 */
476
477int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
478 unsigned int bytes)
479{
480 unsigned long flags;
481 struct list_buffer *lb, *n;
482 unsigned long bytes_read;
483
484 dev_dbg(&dev->core, "%s:%d: %u(%xh) bytes\n", __func__, __LINE__,
485 bytes, bytes);
486
487 spin_lock_irqsave(&dev->rx_list.lock, flags);
488
489 if (dev->rx_list.bytes_held < bytes) {
490 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
491 dev_dbg(&dev->core, "%s:%d: starved for %lxh bytes\n",
492 __func__, __LINE__, bytes - dev->rx_list.bytes_held);
493 return -EAGAIN;
494 }
495
496 list_for_each_entry_safe(lb, n, &dev->rx_list.head, link) {
497 bytes_read = min((unsigned int)(lb->tail - lb->head), bytes);
498
499 memcpy(buf, lb->head, bytes_read);
500 buf += bytes_read;
501 bytes -= bytes_read;
502 dev->rx_list.bytes_held -= bytes_read;
503
504 if (bytes_read < lb->tail - lb->head) {
505 lb->head += bytes_read;
506 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
507
508 dev_dbg(&dev->core,
509 "%s:%d: dequeued buf_%lu, %lxh bytes\n",
510 __func__, __LINE__, lb->dbg_number, bytes_read);
511 return 0;
512 }
513
514 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
515 lb->dbg_number);
516
517 list_del(&lb->link);
518 kfree(lb);
519 }
520 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
521
522 dev_dbg(&dev->core, "%s:%d: dequeued buf_%lu, %xh bytes\n",
523 __func__, __LINE__, lb->dbg_number, bytes);
524
525 return 0;
526}
527
528/**
529 * ps3_vuart_handle_interrupt_tx - third stage transmit interrupt handler
530 *
531 * Services the transmit interrupt for the port. Writes as much data from the
532 * buffer list as the port will accept. Retires any emptied list buffers and
533 * adjusts the final list buffer state for a partial write.
534 */
535
536static int ps3_vuart_handle_interrupt_tx(struct ps3_vuart_port_device *dev)
537{
538 int result = 0;
539 unsigned long flags;
540 struct list_buffer *lb, *n;
541 unsigned long bytes_total = 0;
542
543 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
544
545 spin_lock_irqsave(&dev->tx_list.lock, flags);
546
547 list_for_each_entry_safe(lb, n, &dev->tx_list.head, link) {
548
549 unsigned long bytes_written;
550
551 result = ps3_vuart_raw_write(dev, lb->head, lb->tail - lb->head,
552 &bytes_written);
553
554 if (result) {
555 dev_dbg(&dev->core,
556 "%s:%d: ps3_vuart_raw_write failed\n",
557 __func__, __LINE__);
558 break;
559 }
560
561 bytes_total += bytes_written;
562
563 if (bytes_written < lb->tail - lb->head) {
564 lb->head += bytes_written;
565 dev_dbg(&dev->core,
566 "%s:%d cleared buf_%lu, %lxh bytes\n",
567 __func__, __LINE__, lb->dbg_number,
568 bytes_written);
569 goto port_full;
570 }
571
572 dev_dbg(&dev->core, "%s:%d free buf_%lu\n", __func__, __LINE__,
573 lb->dbg_number);
574
575 list_del(&lb->link);
576 kfree(lb);
577 }
578
579 ps3_vuart_disable_interrupt_tx(dev);
580port_full:
581 spin_unlock_irqrestore(&dev->tx_list.lock, flags);
582 dev_dbg(&dev->core, "%s:%d wrote %lxh bytes total\n",
583 __func__, __LINE__, bytes_total);
584 return result;
585}
586
587/**
588 * ps3_vuart_handle_interrupt_rx - third stage receive interrupt handler
589 *
590 * Services the receive interrupt for the port. Creates a list buffer and
591 * copies all waiting port data to that buffer and enqueues the buffer in the
592 * buffer list. Buffer list data is dequeued via ps3_vuart_read.
593 */
594
595static int ps3_vuart_handle_interrupt_rx(struct ps3_vuart_port_device *dev)
596{
597 static unsigned long dbg_number;
598 int result = 0;
599 unsigned long flags;
600 struct list_buffer *lb;
601 unsigned long bytes;
602
603 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
604
605 result = ps3_vuart_get_rx_bytes_waiting(dev, &bytes);
606
607 if (result)
608 return -EIO;
609
610 BUG_ON(!bytes);
611
612 /* add some extra space for recently arrived data */
613
614 bytes += 128;
615
616 lb = kmalloc(sizeof(struct list_buffer) + bytes, GFP_ATOMIC);
617
618 if (!lb)
619 return -ENOMEM;
620
621 ps3_vuart_raw_read(dev, lb->data, bytes, &bytes);
622
623 lb->head = lb->data;
624 lb->tail = lb->data + bytes;
625 lb->dbg_number = ++dbg_number;
626
627 spin_lock_irqsave(&dev->rx_list.lock, flags);
628 list_add_tail(&lb->link, &dev->rx_list.head);
629 dev->rx_list.bytes_held += bytes;
630 spin_unlock_irqrestore(&dev->rx_list.lock, flags);
631
632 dev_dbg(&dev->core, "%s:%d: queued buf_%lu, %lxh bytes\n",
633 __func__, __LINE__, lb->dbg_number, bytes);
634
635 return 0;
636}
637
638static int ps3_vuart_handle_interrupt_disconnect(
639 struct ps3_vuart_port_device *dev)
640{
641 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
642 BUG_ON("no support");
643 return -1;
644}
645
646/**
647 * ps3_vuart_handle_port_interrupt - second stage interrupt handler
648 *
649 * Services any pending interrupt types for the port. Passes control to the
650 * third stage type specific interrupt handler. Returns control to the first
651 * stage handler after one iteration.
652 */
653
654static int ps3_vuart_handle_port_interrupt(struct ps3_vuart_port_device *dev)
655{
656 int result;
657 unsigned long status;
658
659 result = ps3_vuart_get_interrupt_mask(dev, &status);
660
661 if (result)
662 return result;
663
664 dev_dbg(&dev->core, "%s:%d: status: %lxh\n", __func__, __LINE__,
665 status);
666
667 if (status & INTERRUPT_MASK_DISCONNECT) {
668 dev->stats.disconnect_interrupts++;
669 result = ps3_vuart_handle_interrupt_disconnect(dev);
670 if (result)
671 ps3_vuart_disable_interrupt_disconnect(dev);
672 }
673
674 if (status & INTERRUPT_MASK_TX) {
675 dev->stats.tx_interrupts++;
676 result = ps3_vuart_handle_interrupt_tx(dev);
677 if (result)
678 ps3_vuart_disable_interrupt_tx(dev);
679 }
680
681 if (status & INTERRUPT_MASK_RX) {
682 dev->stats.rx_interrupts++;
683 result = ps3_vuart_handle_interrupt_rx(dev);
684 if (result)
685 ps3_vuart_disable_interrupt_rx(dev);
686 }
687
688 return 0;
689}
690
691struct vuart_private {
692 unsigned int in_use;
693 unsigned int virq;
694 struct ps3_vuart_port_device *devices[PORT_COUNT];
695 const struct ports_bmp bmp;
696};
697
698/**
699 * ps3_vuart_irq_handler - first stage interrupt handler
700 *
701 * Loops finding any interrupting port and its associated instance data.
702 * Passes control to the second stage port specific interrupt handler. Loops
703 * until all outstanding interrupts are serviced.
704 */
705
706static irqreturn_t ps3_vuart_irq_handler(int irq, void *_private)
707{
708 struct vuart_private *private;
709
710 BUG_ON(!_private);
711 private = (struct vuart_private *)_private;
712
713 while (1) {
714 unsigned int port;
715
716 dump_ports_bmp(&private->bmp);
717
718 port = (BITS_PER_LONG - 1) - __ilog2(private->bmp.status);
719
720 if (port == BITS_PER_LONG)
721 break;
722
723 BUG_ON(port >= PORT_COUNT);
724 BUG_ON(!private->devices[port]);
725
726 ps3_vuart_handle_port_interrupt(private->devices[port]);
727 }
728
729 return IRQ_HANDLED;
730}
731
732static int ps3_vuart_match(struct device *_dev, struct device_driver *_drv)
733{
734 int result;
735 struct ps3_vuart_port_driver *drv = to_ps3_vuart_port_driver(_drv);
736 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
737
738 result = dev->match_id == drv->match_id;
739
740 dev_info(&dev->core, "%s:%d: dev=%u(%s), drv=%u(%s): %s\n", __func__,
741 __LINE__, dev->match_id, dev->core.bus_id, drv->match_id,
742 drv->core.name, (result ? "match" : "miss"));
743
744 return result;
745}
746
747static struct vuart_private vuart_private;
748
749static int ps3_vuart_probe(struct device *_dev)
750{
751 int result;
752 unsigned long tmp;
753 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
754 struct ps3_vuart_port_driver *drv =
755 to_ps3_vuart_port_driver(_dev->driver);
756
757 dev_dbg(&dev->core, "%s:%d\n", __func__, __LINE__);
758
759 BUG_ON(!drv);
760
761 result = ps3_vuart_match_id_to_port(dev->match_id, &dev->port_number);
762
763 if (result) {
764 dev_dbg(&dev->core, "%s:%d: unknown match_id (%d)\n",
765 __func__, __LINE__, dev->match_id);
766 result = -EINVAL;
767 goto fail_match;
768 }
769
770 if (vuart_private.devices[dev->port_number]) {
771 dev_dbg(&dev->core, "%s:%d: port busy (%d)\n", __func__,
772 __LINE__, dev->port_number);
773 result = -EBUSY;
774 goto fail_match;
775 }
776
777 vuart_private.devices[dev->port_number] = dev;
778
779 INIT_LIST_HEAD(&dev->tx_list.head);
780 spin_lock_init(&dev->tx_list.lock);
781 INIT_LIST_HEAD(&dev->rx_list.head);
782 spin_lock_init(&dev->rx_list.lock);
783
784 vuart_private.in_use++;
785 if (vuart_private.in_use == 1) {
786 result = ps3_alloc_vuart_irq((void*)&vuart_private.bmp.status,
787 &vuart_private.virq);
788
789 if (result) {
790 dev_dbg(&dev->core,
791 "%s:%d: ps3_alloc_vuart_irq failed (%d)\n",
792 __func__, __LINE__, result);
793 result = -EPERM;
794 goto fail_alloc_irq;
795 }
796
797 result = request_irq(vuart_private.virq, ps3_vuart_irq_handler,
798 IRQF_DISABLED, "vuart", &vuart_private);
799
800 if (result) {
801 dev_info(&dev->core, "%s:%d: request_irq failed (%d)\n",
802 __func__, __LINE__, result);
803 goto fail_request_irq;
804 }
805 }
806
807 ps3_vuart_set_interrupt_mask(dev, INTERRUPT_MASK_RX);
808
809 /* clear stale pending interrupts */
810 ps3_vuart_get_interrupt_mask(dev, &tmp);
811
812 ps3_vuart_set_triggers(dev, 1, 1);
813
814 if (drv->probe)
815 result = drv->probe(dev);
816 else {
817 result = 0;
818 dev_info(&dev->core, "%s:%d: no probe method\n", __func__,
819 __LINE__);
820 }
821
822 if (result) {
823 dev_dbg(&dev->core, "%s:%d: drv->probe failed\n",
824 __func__, __LINE__);
825 goto fail_probe;
826 }
827
828 return result;
829
830fail_probe:
831fail_request_irq:
832 vuart_private.in_use--;
833 if (!vuart_private.in_use) {
834 ps3_free_vuart_irq(vuart_private.virq);
835 vuart_private.virq = NO_IRQ;
836 }
837fail_alloc_irq:
838fail_match:
839 dev_dbg(&dev->core, "%s:%d failed\n", __func__, __LINE__);
840 return result;
841}
842
843static int ps3_vuart_remove(struct device *_dev)
844{
845 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
846 struct ps3_vuart_port_driver *drv =
847 to_ps3_vuart_port_driver(_dev->driver);
848
849 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
850 dev->core.bus_id);
851
852 BUG_ON(vuart_private.in_use < 1);
853
854 if (drv->remove)
855 drv->remove(dev);
856 else
857 dev_dbg(&dev->core, "%s:%d: %s no remove method\n", __func__,
858 __LINE__, dev->core.bus_id);
859
860 vuart_private.in_use--;
861
862 if (!vuart_private.in_use) {
863 free_irq(vuart_private.virq, &vuart_private);
864 ps3_free_vuart_irq(vuart_private.virq);
865 vuart_private.virq = NO_IRQ;
866 }
867 return 0;
868}
869
870/**
871 * ps3_vuart - The vuart instance.
872 *
873 * The vuart is managed as a bus that port devices connect to.
874 */
875
876struct bus_type ps3_vuart = {
877 .name = "ps3_vuart",
878 .match = ps3_vuart_match,
879 .probe = ps3_vuart_probe,
880 .remove = ps3_vuart_remove,
881};
882
883int __init ps3_vuart_init(void)
884{
885 int result;
886
887 pr_debug("%s:%d:\n", __func__, __LINE__);
888 result = bus_register(&ps3_vuart);
889 BUG_ON(result);
890 return result;
891}
892
893void __exit ps3_vuart_exit(void)
894{
895 pr_debug("%s:%d:\n", __func__, __LINE__);
896 bus_unregister(&ps3_vuart);
897}
898
899core_initcall(ps3_vuart_init);
900module_exit(ps3_vuart_exit);
901
902/**
903 * ps3_vuart_port_release_device - Remove a vuart port device.
904 */
905
906static void ps3_vuart_port_release_device(struct device *_dev)
907{
908 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
909#if defined(DEBUG)
910 memset(dev, 0xad, sizeof(struct ps3_vuart_port_device));
911#endif
912 kfree(dev);
913}
914
915/**
916 * ps3_vuart_port_device_register - Add a vuart port device.
917 */
918
919int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev)
920{
921 int result;
922 static unsigned int dev_count = 1;
923
924 dev->core.parent = NULL;
925 dev->core.bus = &ps3_vuart;
926 dev->core.release = ps3_vuart_port_release_device;
927
928 snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "vuart_%02x",
929 dev_count++);
930
931 dev_dbg(&dev->core, "%s:%d register\n", __func__, __LINE__);
932
933 result = device_register(&dev->core);
934
935 return result;
936}
937
938EXPORT_SYMBOL_GPL(ps3_vuart_port_device_register);
939
940/**
941 * ps3_vuart_port_driver_register - Add a vuart port device driver.
942 */
943
944int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv)
945{
946 int result;
947
948 pr_debug("%s:%d: (%s)\n", __func__, __LINE__, drv->core.name);
949 drv->core.bus = &ps3_vuart;
950 result = driver_register(&drv->core);
951 return result;
952}
953
954EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_register);
955
956/**
957 * ps3_vuart_port_driver_unregister - Remove a vuart port device driver.
958 */
959
960void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv)
961{
962 driver_unregister(&drv->core);
963}
964
965EXPORT_SYMBOL_GPL(ps3_vuart_port_driver_unregister);
diff --git a/drivers/ps3/vuart.h b/drivers/ps3/vuart.h
new file mode 100644
index 000000000000..28fd89f0c8aa
--- /dev/null
+++ b/drivers/ps3/vuart.h
@@ -0,0 +1,94 @@
1/*
2 * PS3 virtual uart
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#if !defined(_PS3_VUART_H)
22#define _PS3_VUART_H
23
24struct ps3_vuart_stats {
25 unsigned long bytes_written;
26 unsigned long bytes_read;
27 unsigned long tx_interrupts;
28 unsigned long rx_interrupts;
29 unsigned long disconnect_interrupts;
30};
31
32/**
33 * struct ps3_vuart_port_device - a device on a vuart port
34 */
35
36struct ps3_vuart_port_device {
37 enum ps3_match_id match_id;
38 struct device core;
39
40 /* private driver variables */
41 unsigned int port_number;
42 unsigned long interrupt_mask;
43 struct {
44 spinlock_t lock;
45 struct list_head head;
46 } tx_list;
47 struct {
48 unsigned long bytes_held;
49 spinlock_t lock;
50 struct list_head head;
51 } rx_list;
52 struct ps3_vuart_stats stats;
53};
54
55/**
56 * struct ps3_vuart_port_driver - a driver for a device on a vuart port
57 */
58
59struct ps3_vuart_port_driver {
60 enum ps3_match_id match_id;
61 struct device_driver core;
62 int (*probe)(struct ps3_vuart_port_device *);
63 int (*remove)(struct ps3_vuart_port_device *);
64 int (*tx_event)(struct ps3_vuart_port_device *dev);
65 int (*rx_event)(struct ps3_vuart_port_device *dev);
66 int (*disconnect_event)(struct ps3_vuart_port_device *dev);
67 /* int (*suspend)(struct ps3_vuart_port_device *, pm_message_t); */
68 /* int (*resume)(struct ps3_vuart_port_device *); */
69};
70
71int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev);
72int ps3_vuart_port_driver_register(struct ps3_vuart_port_driver *drv);
73void ps3_vuart_port_driver_unregister(struct ps3_vuart_port_driver *drv);
74int ps3_vuart_write(struct ps3_vuart_port_device *dev,
75 const void* buf, unsigned int bytes);
76int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
77 unsigned int bytes);
78static inline struct ps3_vuart_port_driver *to_ps3_vuart_port_driver(
79 struct device_driver *_drv)
80{
81 return container_of(_drv, struct ps3_vuart_port_driver, core);
82}
83static inline struct ps3_vuart_port_device *to_ps3_vuart_port_device(
84 struct device *_dev)
85{
86 return container_of(_dev, struct ps3_vuart_port_device, core);
87}
88
89int ps3_vuart_write(struct ps3_vuart_port_device *dev, const void* buf,
90 unsigned int bytes);
91int ps3_vuart_read(struct ps3_vuart_port_device *dev, void* buf,
92 unsigned int bytes);
93
94#endif
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 2a63ab2b47f4..09660e2ab051 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -288,7 +288,7 @@ config RTC_DRV_PL031
288 To compile this driver as a module, choose M here: the 288 To compile this driver as a module, choose M here: the
289 module will be called rtc-pl031. 289 module will be called rtc-pl031.
290 290
291config RTC_DRV_AT91 291config RTC_DRV_AT91RM9200
292 tristate "AT91RM9200" 292 tristate "AT91RM9200"
293 depends on RTC_CLASS && ARCH_AT91RM9200 293 depends on RTC_CLASS && ARCH_AT91RM9200
294 help 294 help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index bd4c45d333f0..e6beedacc966 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -35,5 +35,5 @@ obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
35obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 35obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
36obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 36obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
37obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 37obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
38obj-$(CONFIG_RTC_DRV_AT91) += rtc-at91.o 38obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
39obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o 39obj-$(CONFIG_RTC_DRV_SH) += rtc-sh.o
diff --git a/drivers/rtc/rtc-at91.c b/drivers/rtc/rtc-at91rm9200.c
index 5c8addcaf1fb..5c8addcaf1fb 100644
--- a/drivers/rtc/rtc-at91.c
+++ b/drivers/rtc/rtc-at91rm9200.c
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index dfef1637bfb8..205fa28593b7 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -199,7 +199,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
199 struct i2c_client *client; 199 struct i2c_client *client;
200 struct rtc_device *rtc; 200 struct rtc_device *rtc;
201 201
202 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 202 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__);
203 203
204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
205 err = -ENODEV; 205 err = -ENODEV;
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index ba795a4db1e9..7bbc26a34bd2 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -117,4 +117,85 @@ int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
117} 117}
118EXPORT_SYMBOL(rtc_tm_to_time); 118EXPORT_SYMBOL(rtc_tm_to_time);
119 119
120
121/* Merge the valid (i.e. non-negative) fields of alarm into the current
122 * time. If the valid alarm fields are earlier than the equivalent
123 * fields in the time, carry one into the least significant invalid
124 * field, so that the alarm expiry is in the future. It assumes that the
125 * least significant invalid field is more significant than the most
126 * significant valid field, and that the seconds field is valid.
127 *
128 * This is used by alarms that take relative (rather than absolute)
129 * times, and/or have a simple binary second counter instead of
130 * day/hour/minute/sec registers.
131 */
132void rtc_merge_alarm(struct rtc_time *now, struct rtc_time *alarm)
133{
134 int *alarmp = &alarm->tm_sec;
135 int *timep = &now->tm_sec;
136 int carry_into, i;
137
138 /* Ignore everything past the 6th element (tm_year). */
139 for (i = 5; i > 0; i--) {
140 if (alarmp[i] < 0)
141 alarmp[i] = timep[i];
142 else
143 break;
144 }
145
146 /* No carry needed if all fields are valid. */
147 if (i == 5)
148 return;
149
150 for (carry_into = i + 1; i >= 0; i--) {
151 if (alarmp[i] < timep[i])
152 break;
153
154 if (alarmp[i] > timep[i])
155 return;
156 }
157
158 switch (carry_into) {
159 case 1:
160 alarm->tm_min++;
161
162 if (alarm->tm_min < 60)
163 return;
164
165 alarm->tm_min = 0;
166 /* fall-through */
167
168 case 2:
169 alarm->tm_hour++;
170
171 if (alarm->tm_hour < 60)
172 return;
173
174 alarm->tm_hour = 0;
175 /* fall-through */
176
177 case 3:
178 alarm->tm_mday++;
179
180 if (alarm->tm_mday <= rtc_days_in_month[alarm->tm_mon])
181 return;
182
183 alarm->tm_mday = 1;
184 /* fall-through */
185
186 case 4:
187 alarm->tm_mon++;
188
189 if (alarm->tm_mon <= 12)
190 return;
191
192 alarm->tm_mon = 1;
193 /* fall-through */
194
195 case 5:
196 alarm->tm_year++;
197 }
198}
199EXPORT_SYMBOL(rtc_merge_alarm);
200
120MODULE_LICENSE("GPL"); 201MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index a760cf69af90..4b72b8ef5d66 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -192,7 +192,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
192 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 192 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
193 193
194 if (xfer != ARRAY_SIZE(msgs)) { 194 if (xfer != ARRAY_SIZE(msgs)) {
195 dev_err(&client->adapter->dev, 195 dev_err(&client->dev,
196 "%s: could not read register 0x%02X\n", 196 "%s: could not read register 0x%02X\n",
197 __FUNCTION__, pattern[i].reg); 197 __FUNCTION__, pattern[i].reg);
198 198
@@ -203,7 +203,7 @@ static int pcf8563_validate_client(struct i2c_client *client)
203 203
204 if (value > pattern[i].max || 204 if (value > pattern[i].max ||
205 value < pattern[i].min) { 205 value < pattern[i].min) {
206 dev_dbg(&client->adapter->dev, 206 dev_dbg(&client->dev,
207 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, " 207 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
208 "max=%d, value=%d, raw=0x%02X\n", 208 "max=%d, value=%d, raw=0x%02X\n",
209 __FUNCTION__, i, pattern[i].reg, pattern[i].mask, 209 __FUNCTION__, i, pattern[i].reg, pattern[i].mask,
@@ -253,7 +253,7 @@ static int pcf8563_probe(struct i2c_adapter *adapter, int address, int kind)
253 253
254 int err = 0; 254 int err = 0;
255 255
256 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 256 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__);
257 257
258 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 258 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
259 err = -ENODEV; 259 err = -ENODEV;
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index e2c7698fdba3..1460f6b769f2 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -200,7 +200,7 @@ static int rs5c372_probe(struct i2c_adapter *adapter, int address, int kind)
200 struct i2c_client *client; 200 struct i2c_client *client;
201 struct rs5c372 *rs5c372; 201 struct rs5c372 *rs5c372;
202 202
203 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 203 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__);
204 204
205 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 205 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
206 err = -ENODEV; 206 err = -ENODEV;
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 143302a8e79c..72ba1a70f35f 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -2,6 +2,7 @@
2 * SuperH On-Chip RTC Support 2 * SuperH On-Chip RTC Support
3 * 3 *
4 * Copyright (C) 2006 Paul Mundt 4 * Copyright (C) 2006 Paul Mundt
5 * Copyright (C) 2006 Jamie Lenehan
5 * 6 *
6 * Based on the old arch/sh/kernel/cpu/rtc.c by: 7 * Based on the old arch/sh/kernel/cpu/rtc.c by:
7 * 8 *
@@ -21,7 +22,10 @@
21#include <linux/seq_file.h> 22#include <linux/seq_file.h>
22#include <linux/interrupt.h> 23#include <linux/interrupt.h>
23#include <linux/spinlock.h> 24#include <linux/spinlock.h>
24#include <asm/io.h> 25#include <linux/io.h>
26
27#define DRV_NAME "sh-rtc"
28#define DRV_VERSION "0.1.2"
25 29
26#ifdef CONFIG_CPU_SH3 30#ifdef CONFIG_CPU_SH3
27#define rtc_reg_size sizeof(u16) 31#define rtc_reg_size sizeof(u16)
@@ -33,22 +37,26 @@
33 37
34#define RTC_REG(r) ((r) * rtc_reg_size) 38#define RTC_REG(r) ((r) * rtc_reg_size)
35 39
36#define R64CNT RTC_REG(0) 40#define R64CNT RTC_REG(0)
37#define RSECCNT RTC_REG(1) 41
38#define RMINCNT RTC_REG(2) 42#define RSECCNT RTC_REG(1) /* RTC sec */
39#define RHRCNT RTC_REG(3) 43#define RMINCNT RTC_REG(2) /* RTC min */
40#define RWKCNT RTC_REG(4) 44#define RHRCNT RTC_REG(3) /* RTC hour */
41#define RDAYCNT RTC_REG(5) 45#define RWKCNT RTC_REG(4) /* RTC week */
42#define RMONCNT RTC_REG(6) 46#define RDAYCNT RTC_REG(5) /* RTC day */
43#define RYRCNT RTC_REG(7) 47#define RMONCNT RTC_REG(6) /* RTC month */
44#define RSECAR RTC_REG(8) 48#define RYRCNT RTC_REG(7) /* RTC year */
45#define RMINAR RTC_REG(9) 49#define RSECAR RTC_REG(8) /* ALARM sec */
46#define RHRAR RTC_REG(10) 50#define RMINAR RTC_REG(9) /* ALARM min */
47#define RWKAR RTC_REG(11) 51#define RHRAR RTC_REG(10) /* ALARM hour */
48#define RDAYAR RTC_REG(12) 52#define RWKAR RTC_REG(11) /* ALARM week */
49#define RMONAR RTC_REG(13) 53#define RDAYAR RTC_REG(12) /* ALARM day */
50#define RCR1 RTC_REG(14) 54#define RMONAR RTC_REG(13) /* ALARM month */
51#define RCR2 RTC_REG(15) 55#define RCR1 RTC_REG(14) /* Control */
56#define RCR2 RTC_REG(15) /* Control */
57
58/* ALARM Bits - or with BCD encoded value */
59#define AR_ENB 0x80 /* Enable for alarm cmp */
52 60
53/* RCR1 Bits */ 61/* RCR1 Bits */
54#define RCR1_CF 0x80 /* Carry Flag */ 62#define RCR1_CF 0x80 /* Carry Flag */
@@ -71,22 +79,28 @@ struct sh_rtc {
71 unsigned int alarm_irq, periodic_irq, carry_irq; 79 unsigned int alarm_irq, periodic_irq, carry_irq;
72 struct rtc_device *rtc_dev; 80 struct rtc_device *rtc_dev;
73 spinlock_t lock; 81 spinlock_t lock;
82 int rearm_aie;
74}; 83};
75 84
76static irqreturn_t sh_rtc_interrupt(int irq, void *id) 85static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id)
77{ 86{
78 struct platform_device *pdev = id; 87 struct platform_device *pdev = to_platform_device(dev_id);
79 struct sh_rtc *rtc = platform_get_drvdata(pdev); 88 struct sh_rtc *rtc = platform_get_drvdata(pdev);
80 unsigned int tmp, events = 0; 89 unsigned int tmp, events = 0;
81 90
82 spin_lock(&rtc->lock); 91 spin_lock(&rtc->lock);
83 92
84 tmp = readb(rtc->regbase + RCR1); 93 tmp = readb(rtc->regbase + RCR1);
94 tmp &= ~RCR1_CF;
85 95
86 if (tmp & RCR1_AF) 96 if (rtc->rearm_aie) {
87 events |= RTC_AF | RTC_IRQF; 97 if (tmp & RCR1_AF)
88 98 tmp &= ~RCR1_AF; /* try to clear AF again */
89 tmp &= ~(RCR1_CF | RCR1_AF); 99 else {
100 tmp |= RCR1_AIE; /* AF has cleared, rearm IRQ */
101 rtc->rearm_aie = 0;
102 }
103 }
90 104
91 writeb(tmp, rtc->regbase + RCR1); 105 writeb(tmp, rtc->regbase + RCR1);
92 106
@@ -97,9 +111,45 @@ static irqreturn_t sh_rtc_interrupt(int irq, void *id)
97 return IRQ_HANDLED; 111 return IRQ_HANDLED;
98} 112}
99 113
100static irqreturn_t sh_rtc_periodic(int irq, void *id) 114static irqreturn_t sh_rtc_alarm(int irq, void *dev_id)
115{
116 struct platform_device *pdev = to_platform_device(dev_id);
117 struct sh_rtc *rtc = platform_get_drvdata(pdev);
118 unsigned int tmp, events = 0;
119
120 spin_lock(&rtc->lock);
121
122 tmp = readb(rtc->regbase + RCR1);
123
124 /*
125 * If AF is set then the alarm has triggered. If we clear AF while
126 * the alarm time still matches the RTC time then AF will
127 * immediately be set again, and if AIE is enabled then the alarm
128 * interrupt will immediately be retrigger. So we clear AIE here
129 * and use rtc->rearm_aie so that the carry interrupt will keep
130 * trying to clear AF and once it stays cleared it'll re-enable
131 * AIE.
132 */
133 if (tmp & RCR1_AF) {
134 events |= RTC_AF | RTC_IRQF;
135
136 tmp &= ~(RCR1_AF|RCR1_AIE);
137
138 writeb(tmp, rtc->regbase + RCR1);
139
140 rtc->rearm_aie = 1;
141
142 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, events);
143 }
144
145 spin_unlock(&rtc->lock);
146 return IRQ_HANDLED;
147}
148
149static irqreturn_t sh_rtc_periodic(int irq, void *dev_id)
101{ 150{
102 struct sh_rtc *rtc = dev_get_drvdata(id); 151 struct platform_device *pdev = to_platform_device(dev_id);
152 struct sh_rtc *rtc = platform_get_drvdata(pdev);
103 153
104 spin_lock(&rtc->lock); 154 spin_lock(&rtc->lock);
105 155
@@ -139,10 +189,11 @@ static inline void sh_rtc_setaie(struct device *dev, unsigned int enable)
139 189
140 tmp = readb(rtc->regbase + RCR1); 190 tmp = readb(rtc->regbase + RCR1);
141 191
142 if (enable) 192 if (!enable) {
143 tmp |= RCR1_AIE;
144 else
145 tmp &= ~RCR1_AIE; 193 tmp &= ~RCR1_AIE;
194 rtc->rearm_aie = 0;
195 } else if (rtc->rearm_aie == 0)
196 tmp |= RCR1_AIE;
146 197
147 writeb(tmp, rtc->regbase + RCR1); 198 writeb(tmp, rtc->regbase + RCR1);
148 199
@@ -177,7 +228,7 @@ static int sh_rtc_open(struct device *dev)
177 goto err_bad_carry; 228 goto err_bad_carry;
178 } 229 }
179 230
180 ret = request_irq(rtc->alarm_irq, sh_rtc_interrupt, IRQF_DISABLED, 231 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, IRQF_DISABLED,
181 "sh-rtc alarm", dev); 232 "sh-rtc alarm", dev);
182 if (unlikely(ret)) { 233 if (unlikely(ret)) {
183 dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n", 234 dev_err(dev, "request alarm IRQ failed with %d, IRQ %d\n",
@@ -200,6 +251,7 @@ static void sh_rtc_release(struct device *dev)
200 struct sh_rtc *rtc = dev_get_drvdata(dev); 251 struct sh_rtc *rtc = dev_get_drvdata(dev);
201 252
202 sh_rtc_setpie(dev, 0); 253 sh_rtc_setpie(dev, 0);
254 sh_rtc_setaie(dev, 0);
203 255
204 free_irq(rtc->periodic_irq, dev); 256 free_irq(rtc->periodic_irq, dev);
205 free_irq(rtc->carry_irq, dev); 257 free_irq(rtc->carry_irq, dev);
@@ -267,7 +319,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
267 tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT)); 319 tm->tm_hour = BCD2BIN(readb(rtc->regbase + RHRCNT));
268 tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT)); 320 tm->tm_wday = BCD2BIN(readb(rtc->regbase + RWKCNT));
269 tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT)); 321 tm->tm_mday = BCD2BIN(readb(rtc->regbase + RDAYCNT));
270 tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)); 322 tm->tm_mon = BCD2BIN(readb(rtc->regbase + RMONCNT)) - 1;
271 323
272#if defined(CONFIG_CPU_SH4) 324#if defined(CONFIG_CPU_SH4)
273 yr = readw(rtc->regbase + RYRCNT); 325 yr = readw(rtc->regbase + RYRCNT);
@@ -295,7 +347,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
295 "mday=%d, mon=%d, year=%d, wday=%d\n", 347 "mday=%d, mon=%d, year=%d, wday=%d\n",
296 __FUNCTION__, 348 __FUNCTION__,
297 tm->tm_sec, tm->tm_min, tm->tm_hour, 349 tm->tm_sec, tm->tm_min, tm->tm_hour,
298 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 350 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
299 351
300 if (rtc_valid_tm(tm) < 0) 352 if (rtc_valid_tm(tm) < 0)
301 dev_err(dev, "invalid date\n"); 353 dev_err(dev, "invalid date\n");
@@ -322,7 +374,7 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
322 writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT); 374 writeb(BIN2BCD(tm->tm_hour), rtc->regbase + RHRCNT);
323 writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT); 375 writeb(BIN2BCD(tm->tm_wday), rtc->regbase + RWKCNT);
324 writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT); 376 writeb(BIN2BCD(tm->tm_mday), rtc->regbase + RDAYCNT);
325 writeb(BIN2BCD(tm->tm_mon), rtc->regbase + RMONCNT); 377 writeb(BIN2BCD(tm->tm_mon + 1), rtc->regbase + RMONCNT);
326 378
327#ifdef CONFIG_CPU_SH3 379#ifdef CONFIG_CPU_SH3
328 year = tm->tm_year % 100; 380 year = tm->tm_year % 100;
@@ -344,12 +396,136 @@ static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
344 return 0; 396 return 0;
345} 397}
346 398
399static inline int sh_rtc_read_alarm_value(struct sh_rtc *rtc, int reg_off)
400{
401 unsigned int byte;
402 int value = 0xff; /* return 0xff for ignored values */
403
404 byte = readb(rtc->regbase + reg_off);
405 if (byte & AR_ENB) {
406 byte &= ~AR_ENB; /* strip the enable bit */
407 value = BCD2BIN(byte);
408 }
409
410 return value;
411}
412
413static int sh_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
414{
415 struct platform_device *pdev = to_platform_device(dev);
416 struct sh_rtc *rtc = platform_get_drvdata(pdev);
417 struct rtc_time* tm = &wkalrm->time;
418
419 spin_lock_irq(&rtc->lock);
420
421 tm->tm_sec = sh_rtc_read_alarm_value(rtc, RSECAR);
422 tm->tm_min = sh_rtc_read_alarm_value(rtc, RMINAR);
423 tm->tm_hour = sh_rtc_read_alarm_value(rtc, RHRAR);
424 tm->tm_wday = sh_rtc_read_alarm_value(rtc, RWKAR);
425 tm->tm_mday = sh_rtc_read_alarm_value(rtc, RDAYAR);
426 tm->tm_mon = sh_rtc_read_alarm_value(rtc, RMONAR);
427 if (tm->tm_mon > 0)
428 tm->tm_mon -= 1; /* RTC is 1-12, tm_mon is 0-11 */
429 tm->tm_year = 0xffff;
430
431 spin_unlock_irq(&rtc->lock);
432
433 return 0;
434}
435
436static inline void sh_rtc_write_alarm_value(struct sh_rtc *rtc,
437 int value, int reg_off)
438{
439 /* < 0 for a value that is ignored */
440 if (value < 0)
441 writeb(0, rtc->regbase + reg_off);
442 else
443 writeb(BIN2BCD(value) | AR_ENB, rtc->regbase + reg_off);
444}
445
446static int sh_rtc_check_alarm(struct rtc_time* tm)
447{
448 /*
449 * The original rtc says anything > 0xc0 is "don't care" or "match
450 * all" - most users use 0xff but rtc-dev uses -1 for the same thing.
451 * The original rtc doesn't support years - some things use -1 and
452 * some 0xffff. We use -1 to make out tests easier.
453 */
454 if (tm->tm_year == 0xffff)
455 tm->tm_year = -1;
456 if (tm->tm_mon >= 0xff)
457 tm->tm_mon = -1;
458 if (tm->tm_mday >= 0xff)
459 tm->tm_mday = -1;
460 if (tm->tm_wday >= 0xff)
461 tm->tm_wday = -1;
462 if (tm->tm_hour >= 0xff)
463 tm->tm_hour = -1;
464 if (tm->tm_min >= 0xff)
465 tm->tm_min = -1;
466 if (tm->tm_sec >= 0xff)
467 tm->tm_sec = -1;
468
469 if (tm->tm_year > 9999 ||
470 tm->tm_mon >= 12 ||
471 tm->tm_mday == 0 || tm->tm_mday >= 32 ||
472 tm->tm_wday >= 7 ||
473 tm->tm_hour >= 24 ||
474 tm->tm_min >= 60 ||
475 tm->tm_sec >= 60)
476 return -EINVAL;
477
478 return 0;
479}
480
481static int sh_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
482{
483 struct platform_device *pdev = to_platform_device(dev);
484 struct sh_rtc *rtc = platform_get_drvdata(pdev);
485 unsigned int rcr1;
486 struct rtc_time *tm = &wkalrm->time;
487 int mon, err;
488
489 err = sh_rtc_check_alarm(tm);
490 if (unlikely(err < 0))
491 return err;
492
493 spin_lock_irq(&rtc->lock);
494
495 /* disable alarm interrupt and clear flag */
496 rcr1 = readb(rtc->regbase + RCR1);
497 rcr1 &= ~RCR1_AF;
498 writeb(rcr1 & ~RCR1_AIE, rtc->regbase + RCR1);
499
500 rtc->rearm_aie = 0;
501
502 /* set alarm time */
503 sh_rtc_write_alarm_value(rtc, tm->tm_sec, RSECAR);
504 sh_rtc_write_alarm_value(rtc, tm->tm_min, RMINAR);
505 sh_rtc_write_alarm_value(rtc, tm->tm_hour, RHRAR);
506 sh_rtc_write_alarm_value(rtc, tm->tm_wday, RWKAR);
507 sh_rtc_write_alarm_value(rtc, tm->tm_mday, RDAYAR);
508 mon = tm->tm_mon;
509 if (mon >= 0)
510 mon += 1;
511 sh_rtc_write_alarm_value(rtc, mon, RMONAR);
512
513 /* Restore interrupt activation status */
514 writeb(rcr1, rtc->regbase + RCR1);
515
516 spin_unlock_irq(&rtc->lock);
517
518 return 0;
519}
520
347static struct rtc_class_ops sh_rtc_ops = { 521static struct rtc_class_ops sh_rtc_ops = {
348 .open = sh_rtc_open, 522 .open = sh_rtc_open,
349 .release = sh_rtc_release, 523 .release = sh_rtc_release,
350 .ioctl = sh_rtc_ioctl, 524 .ioctl = sh_rtc_ioctl,
351 .read_time = sh_rtc_read_time, 525 .read_time = sh_rtc_read_time,
352 .set_time = sh_rtc_set_time, 526 .set_time = sh_rtc_set_time,
527 .read_alarm = sh_rtc_read_alarm,
528 .set_alarm = sh_rtc_set_alarm,
353 .proc = sh_rtc_proc, 529 .proc = sh_rtc_proc,
354}; 530};
355 531
@@ -442,7 +618,7 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev)
442} 618}
443static struct platform_driver sh_rtc_platform_driver = { 619static struct platform_driver sh_rtc_platform_driver = {
444 .driver = { 620 .driver = {
445 .name = "sh-rtc", 621 .name = DRV_NAME,
446 .owner = THIS_MODULE, 622 .owner = THIS_MODULE,
447 }, 623 },
448 .probe = sh_rtc_probe, 624 .probe = sh_rtc_probe,
@@ -463,5 +639,6 @@ module_init(sh_rtc_init);
463module_exit(sh_rtc_exit); 639module_exit(sh_rtc_exit);
464 640
465MODULE_DESCRIPTION("SuperH on-chip RTC driver"); 641MODULE_DESCRIPTION("SuperH on-chip RTC driver");
466MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>"); 642MODULE_VERSION(DRV_VERSION);
643MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, Jamie Lenehan <lenehan@twibble.org>");
467MODULE_LICENSE("GPL"); 644MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index 9a67487d086b..019ae255b0c8 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -372,7 +372,7 @@ static int x1205_validate_client(struct i2c_client *client)
372 }; 372 };
373 373
374 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 374 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
375 dev_err(&client->adapter->dev, 375 dev_err(&client->dev,
376 "%s: could not read register %x\n", 376 "%s: could not read register %x\n",
377 __FUNCTION__, probe_zero_pattern[i]); 377 __FUNCTION__, probe_zero_pattern[i]);
378 378
@@ -380,7 +380,7 @@ static int x1205_validate_client(struct i2c_client *client)
380 } 380 }
381 381
382 if ((buf & probe_zero_pattern[i+1]) != 0) { 382 if ((buf & probe_zero_pattern[i+1]) != 0) {
383 dev_err(&client->adapter->dev, 383 dev_err(&client->dev,
384 "%s: register=%02x, zero pattern=%d, value=%x\n", 384 "%s: register=%02x, zero pattern=%d, value=%x\n",
385 __FUNCTION__, probe_zero_pattern[i], i, buf); 385 __FUNCTION__, probe_zero_pattern[i], i, buf);
386 386
@@ -400,7 +400,7 @@ static int x1205_validate_client(struct i2c_client *client)
400 }; 400 };
401 401
402 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 402 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) {
403 dev_err(&client->adapter->dev, 403 dev_err(&client->dev,
404 "%s: could not read register %x\n", 404 "%s: could not read register %x\n",
405 __FUNCTION__, probe_limits_pattern[i].reg); 405 __FUNCTION__, probe_limits_pattern[i].reg);
406 406
@@ -411,7 +411,7 @@ static int x1205_validate_client(struct i2c_client *client)
411 411
412 if (value > probe_limits_pattern[i].max || 412 if (value > probe_limits_pattern[i].max ||
413 value < probe_limits_pattern[i].min) { 413 value < probe_limits_pattern[i].min) {
414 dev_dbg(&client->adapter->dev, 414 dev_dbg(&client->dev,
415 "%s: register=%x, lim pattern=%d, value=%d\n", 415 "%s: register=%x, lim pattern=%d, value=%d\n",
416 __FUNCTION__, probe_limits_pattern[i].reg, 416 __FUNCTION__, probe_limits_pattern[i].reg,
417 i, value); 417 i, value);
@@ -506,7 +506,7 @@ static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
506 struct i2c_client *client; 506 struct i2c_client *client;
507 struct rtc_device *rtc; 507 struct rtc_device *rtc;
508 508
509 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__); 509 dev_dbg(adapter->class_dev.dev, "%s\n", __FUNCTION__);
510 510
511 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 511 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
512 err = -ENODEV; 512 err = -ENODEV;
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 2af2d9b53d18..492b68bcd7cc 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -1050,10 +1050,10 @@ dasd_int_handler(struct ccw_device *cdev, unsigned long intparm,
1050 } 1050 }
1051 } else { /* error */ 1051 } else { /* error */
1052 memcpy(&cqr->irb, irb, sizeof (struct irb)); 1052 memcpy(&cqr->irb, irb, sizeof (struct irb));
1053#ifdef ERP_DEBUG 1053 if (device->features & DASD_FEATURE_ERPLOG) {
1054 /* dump sense data */ 1054 /* dump sense data */
1055 dasd_log_sense(cqr, irb); 1055 dasd_log_sense(cqr, irb);
1056#endif 1056 }
1057 switch (era) { 1057 switch (era) {
1058 case dasd_era_fatal: 1058 case dasd_era_fatal:
1059 cqr->status = DASD_CQR_FAILED; 1059 cqr->status = DASD_CQR_FAILED;
diff --git a/drivers/s390/block/dasd_3990_erp.c b/drivers/s390/block/dasd_3990_erp.c
index 669805d4402d..4d01040c2c63 100644
--- a/drivers/s390/block/dasd_3990_erp.c
+++ b/drivers/s390/block/dasd_3990_erp.c
@@ -2641,14 +2641,12 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
2641 struct dasd_ccw_req *erp = NULL; 2641 struct dasd_ccw_req *erp = NULL;
2642 struct dasd_device *device = cqr->device; 2642 struct dasd_device *device = cqr->device;
2643 __u32 cpa = cqr->irb.scsw.cpa; 2643 __u32 cpa = cqr->irb.scsw.cpa;
2644 struct dasd_ccw_req *temp_erp = NULL;
2644 2645
2645#ifdef ERP_DEBUG 2646 if (device->features & DASD_FEATURE_ERPLOG) {
2646 /* print current erp_chain */ 2647 /* print current erp_chain */
2647 DEV_MESSAGE(KERN_ERR, device, "%s", 2648 DEV_MESSAGE(KERN_ERR, device, "%s",
2648 "ERP chain at BEGINNING of ERP-ACTION"); 2649 "ERP chain at BEGINNING of ERP-ACTION");
2649 {
2650 struct dasd_ccw_req *temp_erp = NULL;
2651
2652 for (temp_erp = cqr; 2650 for (temp_erp = cqr;
2653 temp_erp != NULL; temp_erp = temp_erp->refers) { 2651 temp_erp != NULL; temp_erp = temp_erp->refers) {
2654 2652
@@ -2658,7 +2656,6 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
2658 temp_erp->refers); 2656 temp_erp->refers);
2659 } 2657 }
2660 } 2658 }
2661#endif /* ERP_DEBUG */
2662 2659
2663 /* double-check if current erp/cqr was successfull */ 2660 /* double-check if current erp/cqr was successfull */
2664 if ((cqr->irb.scsw.cstat == 0x00) && 2661 if ((cqr->irb.scsw.cstat == 0x00) &&
@@ -2695,11 +2692,10 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
2695 erp = dasd_3990_erp_handle_match_erp(cqr, erp); 2692 erp = dasd_3990_erp_handle_match_erp(cqr, erp);
2696 } 2693 }
2697 2694
2698#ifdef ERP_DEBUG 2695 if (device->features & DASD_FEATURE_ERPLOG) {
2699 /* print current erp_chain */ 2696 /* print current erp_chain */
2700 DEV_MESSAGE(KERN_ERR, device, "%s", "ERP chain at END of ERP-ACTION"); 2697 DEV_MESSAGE(KERN_ERR, device, "%s",
2701 { 2698 "ERP chain at END of ERP-ACTION");
2702 struct dasd_ccw_req *temp_erp = NULL;
2703 for (temp_erp = erp; 2699 for (temp_erp = erp;
2704 temp_erp != NULL; temp_erp = temp_erp->refers) { 2700 temp_erp != NULL; temp_erp = temp_erp->refers) {
2705 2701
@@ -2709,7 +2705,6 @@ dasd_3990_erp_action(struct dasd_ccw_req * cqr)
2709 temp_erp->refers); 2705 temp_erp->refers);
2710 } 2706 }
2711 } 2707 }
2712#endif /* ERP_DEBUG */
2713 2708
2714 if (erp->status == DASD_CQR_FAILED) 2709 if (erp->status == DASD_CQR_FAILED)
2715 dasd_log_ccw(erp, 1, cpa); 2710 dasd_log_ccw(erp, 1, cpa);
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index cf28ccc57948..5943266152f5 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -202,6 +202,8 @@ dasd_feature_list(char *str, char **endp)
202 features |= DASD_FEATURE_READONLY; 202 features |= DASD_FEATURE_READONLY;
203 else if (len == 4 && !strncmp(str, "diag", 4)) 203 else if (len == 4 && !strncmp(str, "diag", 4))
204 features |= DASD_FEATURE_USEDIAG; 204 features |= DASD_FEATURE_USEDIAG;
205 else if (len == 6 && !strncmp(str, "erplog", 6))
206 features |= DASD_FEATURE_ERPLOG;
205 else { 207 else {
206 MESSAGE(KERN_WARNING, 208 MESSAGE(KERN_WARNING,
207 "unsupported feature: %*s, " 209 "unsupported feature: %*s, "
@@ -709,6 +711,52 @@ dasd_ro_store(struct device *dev, struct device_attribute *attr,
709} 711}
710 712
711static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store); 713static DEVICE_ATTR(readonly, 0644, dasd_ro_show, dasd_ro_store);
714/*
715 * erplog controls the logging of ERP related data
716 * (e.g. failing channel programs).
717 */
718static ssize_t
719dasd_erplog_show(struct device *dev, struct device_attribute *attr, char *buf)
720{
721 struct dasd_devmap *devmap;
722 int erplog;
723
724 devmap = dasd_find_busid(dev->bus_id);
725 if (!IS_ERR(devmap))
726 erplog = (devmap->features & DASD_FEATURE_ERPLOG) != 0;
727 else
728 erplog = (DASD_FEATURE_DEFAULT & DASD_FEATURE_ERPLOG) != 0;
729 return snprintf(buf, PAGE_SIZE, erplog ? "1\n" : "0\n");
730}
731
732static ssize_t
733dasd_erplog_store(struct device *dev, struct device_attribute *attr,
734 const char *buf, size_t count)
735{
736 struct dasd_devmap *devmap;
737 int val;
738 char *endp;
739
740 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
741 if (IS_ERR(devmap))
742 return PTR_ERR(devmap);
743
744 val = simple_strtoul(buf, &endp, 0);
745 if (((endp + 1) < (buf + count)) || (val > 1))
746 return -EINVAL;
747
748 spin_lock(&dasd_devmap_lock);
749 if (val)
750 devmap->features |= DASD_FEATURE_ERPLOG;
751 else
752 devmap->features &= ~DASD_FEATURE_ERPLOG;
753 if (devmap->device)
754 devmap->device->features = devmap->features;
755 spin_unlock(&dasd_devmap_lock);
756 return count;
757}
758
759static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
712 760
713/* 761/*
714 * use_diag controls whether the driver should use diag rather than ssch 762 * use_diag controls whether the driver should use diag rather than ssch
@@ -896,6 +944,7 @@ static struct attribute * dasd_attrs[] = {
896 &dev_attr_uid.attr, 944 &dev_attr_uid.attr,
897 &dev_attr_use_diag.attr, 945 &dev_attr_use_diag.attr,
898 &dev_attr_eer_enabled.attr, 946 &dev_attr_eer_enabled.attr,
947 &dev_attr_erplog.attr,
899 NULL, 948 NULL,
900}; 949};
901 950
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index dc5dd509434d..fb725e3b08fe 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -13,10 +13,6 @@
13 13
14#ifdef __KERNEL__ 14#ifdef __KERNEL__
15 15
16/* erp debugging in dasd.c and dasd_3990_erp.c */
17#define ERP_DEBUG
18
19
20/* we keep old device allocation scheme; IOW, minors are still in 0..255 */ 16/* we keep old device allocation scheme; IOW, minors are still in 0..255 */
21#define DASD_PER_MAJOR (1U << (MINORBITS - DASD_PARTN_BITS)) 17#define DASD_PER_MAJOR (1U << (MINORBITS - DASD_PARTN_BITS))
22#define DASD_PARTN_MASK ((1 << DASD_PARTN_BITS) - 1) 18#define DASD_PARTN_MASK ((1 << DASD_PARTN_BITS) - 1)
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 8fed3603e9ea..758cfb542865 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -430,7 +430,7 @@ dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
430 int rval; 430 int rval;
431 431
432 lock_kernel(); 432 lock_kernel();
433 rval = dasd_ioctl(filp->f_dentry->d_inode, filp, cmd, arg); 433 rval = dasd_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
434 unlock_kernel(); 434 unlock_kernel();
435 435
436 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval; 436 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
diff --git a/drivers/s390/char/ctrlchar.c b/drivers/s390/char/ctrlchar.c
index 49e9628d9297..c6cbcb3f925e 100644
--- a/drivers/s390/char/ctrlchar.c
+++ b/drivers/s390/char/ctrlchar.c
@@ -16,14 +16,15 @@
16 16
17#ifdef CONFIG_MAGIC_SYSRQ 17#ifdef CONFIG_MAGIC_SYSRQ
18static int ctrlchar_sysrq_key; 18static int ctrlchar_sysrq_key;
19static struct tty_struct *sysrq_tty;
19 20
20static void 21static void
21ctrlchar_handle_sysrq(void *tty) 22ctrlchar_handle_sysrq(struct work_struct *work)
22{ 23{
23 handle_sysrq(ctrlchar_sysrq_key, (struct tty_struct *) tty); 24 handle_sysrq(ctrlchar_sysrq_key, sysrq_tty);
24} 25}
25 26
26static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq, NULL); 27static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
27#endif 28#endif
28 29
29 30
@@ -53,7 +54,7 @@ ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
53 /* racy */ 54 /* racy */
54 if (len == 3 && buf[1] == '-') { 55 if (len == 3 && buf[1] == '-') {
55 ctrlchar_sysrq_key = buf[2]; 56 ctrlchar_sysrq_key = buf[2];
56 ctrlchar_work.data = tty; 57 sysrq_tty = tty;
57 schedule_work(&ctrlchar_work); 58 schedule_work(&ctrlchar_work);
58 return CTRLCHAR_SYSRQ; 59 return CTRLCHAR_SYSRQ;
59 } 60 }
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index 78f8bda81dae..0893d306ae80 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -419,16 +419,20 @@ fs3270_open(struct inode *inode, struct file *filp)
419 struct idal_buffer *ib; 419 struct idal_buffer *ib;
420 int minor, rc; 420 int minor, rc;
421 421
422 if (imajor(filp->f_dentry->d_inode) != IBM_FS3270_MAJOR) 422 if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR)
423 return -ENODEV; 423 return -ENODEV;
424 minor = iminor(filp->f_dentry->d_inode); 424 minor = iminor(filp->f_path.dentry->d_inode);
425 /* Check for minor 0 multiplexer. */ 425 /* Check for minor 0 multiplexer. */
426 if (minor == 0) { 426 if (minor == 0) {
427 if (!current->signal->tty) 427 struct tty_struct *tty;
428 mutex_lock(&tty_mutex);
429 tty = get_current_tty();
430 if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
431 mutex_unlock(&tty_mutex);
428 return -ENODEV; 432 return -ENODEV;
429 if (current->signal->tty->driver->major != IBM_TTY3270_MAJOR) 433 }
430 return -ENODEV; 434 minor = tty->index + RAW3270_FIRSTMINOR;
431 minor = current->signal->tty->index + RAW3270_FIRSTMINOR; 435 mutex_unlock(&tty_mutex);
432 } 436 }
433 /* Check if some other program is already using fullscreen mode. */ 437 /* Check if some other program is already using fullscreen mode. */
434 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor); 438 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index 6f43e04dbefd..2d173e5c8a09 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -60,8 +60,6 @@ static unsigned short int sclp_tty_chars_count;
60 60
61struct tty_driver *sclp_tty_driver; 61struct tty_driver *sclp_tty_driver;
62 62
63extern struct termios tty_std_termios;
64
65static struct sclp_ioctls sclp_ioctls; 63static struct sclp_ioctls sclp_ioctls;
66static struct sclp_ioctls sclp_ioctls_init = 64static struct sclp_ioctls sclp_ioctls_init =
67{ 65{
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h
index 1f4c89967be4..c9f1c4c8bb13 100644
--- a/drivers/s390/char/tape.h
+++ b/drivers/s390/char/tape.h
@@ -179,6 +179,7 @@ struct tape_char_data {
179/* Block Frontend Data */ 179/* Block Frontend Data */
180struct tape_blk_data 180struct tape_blk_data
181{ 181{
182 struct tape_device * device;
182 /* Block device request queue. */ 183 /* Block device request queue. */
183 request_queue_t * request_queue; 184 request_queue_t * request_queue;
184 spinlock_t request_queue_lock; 185 spinlock_t request_queue_lock;
@@ -240,7 +241,7 @@ struct tape_device {
240#endif 241#endif
241 242
242 /* Function to start or stop the next request later. */ 243 /* Function to start or stop the next request later. */
243 struct work_struct tape_dnr; 244 struct delayed_work tape_dnr;
244}; 245};
245 246
246/* Externals from tape_core.c */ 247/* Externals from tape_core.c */
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c
index 7b95dab913d0..e765875e8db2 100644
--- a/drivers/s390/char/tape_34xx.c
+++ b/drivers/s390/char/tape_34xx.c
@@ -95,6 +95,12 @@ tape_34xx_medium_sense(struct tape_device *device)
95 return rc; 95 return rc;
96} 96}
97 97
98struct tape_34xx_work {
99 struct tape_device *device;
100 enum tape_op op;
101 struct work_struct work;
102};
103
98/* 104/*
99 * These functions are currently used only to schedule a medium_sense for 105 * These functions are currently used only to schedule a medium_sense for
100 * later execution. This is because we get an interrupt whenever a medium 106 * later execution. This is because we get an interrupt whenever a medium
@@ -103,13 +109,10 @@ tape_34xx_medium_sense(struct tape_device *device)
103 * interrupt handler. 109 * interrupt handler.
104 */ 110 */
105static void 111static void
106tape_34xx_work_handler(void *data) 112tape_34xx_work_handler(struct work_struct *work)
107{ 113{
108 struct { 114 struct tape_34xx_work *p =
109 struct tape_device *device; 115 container_of(work, struct tape_34xx_work, work);
110 enum tape_op op;
111 struct work_struct work;
112 } *p = data;
113 116
114 switch(p->op) { 117 switch(p->op) {
115 case TO_MSEN: 118 case TO_MSEN:
@@ -126,17 +129,13 @@ tape_34xx_work_handler(void *data)
126static int 129static int
127tape_34xx_schedule_work(struct tape_device *device, enum tape_op op) 130tape_34xx_schedule_work(struct tape_device *device, enum tape_op op)
128{ 131{
129 struct { 132 struct tape_34xx_work *p;
130 struct tape_device *device;
131 enum tape_op op;
132 struct work_struct work;
133 } *p;
134 133
135 if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL) 134 if ((p = kmalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
136 return -ENOMEM; 135 return -ENOMEM;
137 136
138 memset(p, 0, sizeof(*p)); 137 memset(p, 0, sizeof(*p));
139 INIT_WORK(&p->work, tape_34xx_work_handler, p); 138 INIT_WORK(&p->work, tape_34xx_work_handler);
140 139
141 p->device = tape_get_device_reference(device); 140 p->device = tape_get_device_reference(device);
142 p->op = op; 141 p->op = op;
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c
index 928cbefc49d5..9df912f63188 100644
--- a/drivers/s390/char/tape_3590.c
+++ b/drivers/s390/char/tape_3590.c
@@ -236,9 +236,10 @@ struct work_handler_data {
236}; 236};
237 237
238static void 238static void
239tape_3590_work_handler(void *data) 239tape_3590_work_handler(struct work_struct *work)
240{ 240{
241 struct work_handler_data *p = data; 241 struct work_handler_data *p =
242 container_of(work, struct work_handler_data, work);
242 243
243 switch (p->op) { 244 switch (p->op) {
244 case TO_MSEN: 245 case TO_MSEN:
@@ -263,7 +264,7 @@ tape_3590_schedule_work(struct tape_device *device, enum tape_op op)
263 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL) 264 if ((p = kzalloc(sizeof(*p), GFP_ATOMIC)) == NULL)
264 return -ENOMEM; 265 return -ENOMEM;
265 266
266 INIT_WORK(&p->work, tape_3590_work_handler, p); 267 INIT_WORK(&p->work, tape_3590_work_handler);
267 268
268 p->device = tape_get_device_reference(device); 269 p->device = tape_get_device_reference(device);
269 p->op = op; 270 p->op = op;
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index 3225fcd1dcb4..c8a89b3b87d4 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -15,6 +15,7 @@
15#include <linux/blkdev.h> 15#include <linux/blkdev.h>
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/kernel.h>
18 19
19#include <asm/debug.h> 20#include <asm/debug.h>
20 21
@@ -143,7 +144,8 @@ tapeblock_start_request(struct tape_device *device, struct request *req)
143 * queue. 144 * queue.
144 */ 145 */
145static void 146static void
146tapeblock_requeue(void *data) { 147tapeblock_requeue(struct work_struct *work) {
148 struct tape_blk_data * blkdat;
147 struct tape_device * device; 149 struct tape_device * device;
148 request_queue_t * queue; 150 request_queue_t * queue;
149 int nr_queued; 151 int nr_queued;
@@ -151,7 +153,8 @@ tapeblock_requeue(void *data) {
151 struct list_head * l; 153 struct list_head * l;
152 int rc; 154 int rc;
153 155
154 device = (struct tape_device *) data; 156 blkdat = container_of(work, struct tape_blk_data, requeue_task);
157 device = blkdat->device;
155 if (!device) 158 if (!device)
156 return; 159 return;
157 160
@@ -212,6 +215,7 @@ tapeblock_setup_device(struct tape_device * device)
212 int rc; 215 int rc;
213 216
214 blkdat = &device->blk_data; 217 blkdat = &device->blk_data;
218 blkdat->device = device;
215 spin_lock_init(&blkdat->request_queue_lock); 219 spin_lock_init(&blkdat->request_queue_lock);
216 atomic_set(&blkdat->requeue_scheduled, 0); 220 atomic_set(&blkdat->requeue_scheduled, 0);
217 221
@@ -255,8 +259,8 @@ tapeblock_setup_device(struct tape_device * device)
255 259
256 add_disk(disk); 260 add_disk(disk);
257 261
258 INIT_WORK(&blkdat->requeue_task, tapeblock_requeue, 262 tape_get_device_reference(device);
259 tape_get_device_reference(device)); 263 INIT_WORK(&blkdat->requeue_task, tapeblock_requeue);
260 264
261 return 0; 265 return 0;
262 266
@@ -271,7 +275,7 @@ void
271tapeblock_cleanup_device(struct tape_device *device) 275tapeblock_cleanup_device(struct tape_device *device)
272{ 276{
273 flush_scheduled_work(); 277 flush_scheduled_work();
274 device->blk_data.requeue_task.data = tape_put_device(device); 278 tape_put_device(device);
275 279
276 if (!device->blk_data.disk) { 280 if (!device->blk_data.disk) {
277 PRINT_ERR("(%s): No gendisk to clean up!\n", 281 PRINT_ERR("(%s): No gendisk to clean up!\n",
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 97f75237bed6..31198c8f2718 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -298,13 +298,13 @@ tapechar_open (struct inode *inode, struct file *filp)
298 int minor, rc; 298 int minor, rc;
299 299
300 DBF_EVENT(6, "TCHAR:open: %i:%i\n", 300 DBF_EVENT(6, "TCHAR:open: %i:%i\n",
301 imajor(filp->f_dentry->d_inode), 301 imajor(filp->f_path.dentry->d_inode),
302 iminor(filp->f_dentry->d_inode)); 302 iminor(filp->f_path.dentry->d_inode));
303 303
304 if (imajor(filp->f_dentry->d_inode) != tapechar_major) 304 if (imajor(filp->f_path.dentry->d_inode) != tapechar_major)
305 return -ENODEV; 305 return -ENODEV;
306 306
307 minor = iminor(filp->f_dentry->d_inode); 307 minor = iminor(filp->f_path.dentry->d_inode);
308 device = tape_get_device(minor / TAPE_MINORS_PER_DEV); 308 device = tape_get_device(minor / TAPE_MINORS_PER_DEV);
309 if (IS_ERR(device)) { 309 if (IS_ERR(device)) {
310 DBF_EVENT(3, "TCHAR:open: tape_get_device() failed\n"); 310 DBF_EVENT(3, "TCHAR:open: tape_get_device() failed\n");
diff --git a/drivers/s390/char/tape_core.c b/drivers/s390/char/tape_core.c
index 2826aed91043..c6c2e918b990 100644
--- a/drivers/s390/char/tape_core.c
+++ b/drivers/s390/char/tape_core.c
@@ -28,7 +28,7 @@
28#define PRINTK_HEADER "TAPE_CORE: " 28#define PRINTK_HEADER "TAPE_CORE: "
29 29
30static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *); 30static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *);
31static void tape_delayed_next_request(void * data); 31static void tape_delayed_next_request(struct work_struct *);
32 32
33/* 33/*
34 * One list to contain all tape devices of all disciplines, so 34 * One list to contain all tape devices of all disciplines, so
@@ -272,7 +272,7 @@ __tape_cancel_io(struct tape_device *device, struct tape_request *request)
272 return 0; 272 return 0;
273 case -EBUSY: 273 case -EBUSY:
274 request->status = TAPE_REQUEST_CANCEL; 274 request->status = TAPE_REQUEST_CANCEL;
275 schedule_work(&device->tape_dnr); 275 schedule_delayed_work(&device->tape_dnr, 0);
276 return 0; 276 return 0;
277 case -ENODEV: 277 case -ENODEV:
278 DBF_EXCEPTION(2, "device gone, retry\n"); 278 DBF_EXCEPTION(2, "device gone, retry\n");
@@ -470,7 +470,7 @@ tape_alloc_device(void)
470 *device->modeset_byte = 0; 470 *device->modeset_byte = 0;
471 device->first_minor = -1; 471 device->first_minor = -1;
472 atomic_set(&device->ref_count, 1); 472 atomic_set(&device->ref_count, 1);
473 INIT_WORK(&device->tape_dnr, tape_delayed_next_request, device); 473 INIT_DELAYED_WORK(&device->tape_dnr, tape_delayed_next_request);
474 474
475 return device; 475 return device;
476} 476}
@@ -724,7 +724,7 @@ __tape_start_io(struct tape_device *device, struct tape_request *request)
724 } else if (rc == -EBUSY) { 724 } else if (rc == -EBUSY) {
725 /* The common I/O subsystem is currently busy. Retry later. */ 725 /* The common I/O subsystem is currently busy. Retry later. */
726 request->status = TAPE_REQUEST_QUEUED; 726 request->status = TAPE_REQUEST_QUEUED;
727 schedule_work(&device->tape_dnr); 727 schedule_delayed_work(&device->tape_dnr, 0);
728 rc = 0; 728 rc = 0;
729 } else { 729 } else {
730 /* Start failed. Remove request and indicate failure. */ 730 /* Start failed. Remove request and indicate failure. */
@@ -790,11 +790,11 @@ __tape_start_next_request(struct tape_device *device)
790} 790}
791 791
792static void 792static void
793tape_delayed_next_request(void *data) 793tape_delayed_next_request(struct work_struct *work)
794{ 794{
795 struct tape_device * device; 795 struct tape_device *device =
796 container_of(work, struct tape_device, tape_dnr.work);
796 797
797 device = (struct tape_device *) data;
798 DBF_LH(6, "tape_delayed_next_request(%p)\n", device); 798 DBF_LH(6, "tape_delayed_next_request(%p)\n", device);
799 spin_lock_irq(get_ccwdev_lock(device->cdev)); 799 spin_lock_irq(get_ccwdev_lock(device->cdev));
800 __tape_start_next_request(device); 800 __tape_start_next_request(device);
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 4717c3611601..09844621edc0 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1659,7 +1659,7 @@ tty3270_flush_buffer(struct tty_struct *tty)
1659 * Check for visible/invisible input switches 1659 * Check for visible/invisible input switches
1660 */ 1660 */
1661static void 1661static void
1662tty3270_set_termios(struct tty_struct *tty, struct termios *old) 1662tty3270_set_termios(struct tty_struct *tty, struct ktermios *old)
1663{ 1663{
1664 struct tty3270 *tp; 1664 struct tty3270 *tp;
1665 int new; 1665 int new;
diff --git a/drivers/s390/cio/chsc.c b/drivers/s390/cio/chsc.c
index dbfb77b03928..cbab8d2ce5cf 100644
--- a/drivers/s390/cio/chsc.c
+++ b/drivers/s390/cio/chsc.c
@@ -183,7 +183,7 @@ css_get_ssd_info(struct subchannel *sch)
183 page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA); 183 page = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
184 if (!page) 184 if (!page)
185 return -ENOMEM; 185 return -ENOMEM;
186 spin_lock_irq(&sch->lock); 186 spin_lock_irq(sch->lock);
187 ret = chsc_get_sch_desc_irq(sch, page); 187 ret = chsc_get_sch_desc_irq(sch, page);
188 if (ret) { 188 if (ret) {
189 static int cio_chsc_err_msg; 189 static int cio_chsc_err_msg;
@@ -197,7 +197,7 @@ css_get_ssd_info(struct subchannel *sch)
197 cio_chsc_err_msg = 1; 197 cio_chsc_err_msg = 1;
198 } 198 }
199 } 199 }
200 spin_unlock_irq(&sch->lock); 200 spin_unlock_irq(sch->lock);
201 free_page((unsigned long)page); 201 free_page((unsigned long)page);
202 if (!ret) { 202 if (!ret) {
203 int j, chpid, mask; 203 int j, chpid, mask;
@@ -233,7 +233,7 @@ s390_subchannel_remove_chpid(struct device *dev, void *data)
233 if (j >= 8) 233 if (j >= 8)
234 return 0; 234 return 0;
235 235
236 spin_lock_irq(&sch->lock); 236 spin_lock_irq(sch->lock);
237 237
238 stsch(sch->schid, &schib); 238 stsch(sch->schid, &schib);
239 if (!schib.pmcw.dnv) 239 if (!schib.pmcw.dnv)
@@ -265,10 +265,10 @@ s390_subchannel_remove_chpid(struct device *dev, void *data)
265 else if (sch->lpm == mask) 265 else if (sch->lpm == mask)
266 goto out_unreg; 266 goto out_unreg;
267out_unlock: 267out_unlock:
268 spin_unlock_irq(&sch->lock); 268 spin_unlock_irq(sch->lock);
269 return 0; 269 return 0;
270out_unreg: 270out_unreg:
271 spin_unlock_irq(&sch->lock); 271 spin_unlock_irq(sch->lock);
272 sch->lpm = 0; 272 sch->lpm = 0;
273 if (css_enqueue_subchannel_slow(sch->schid)) { 273 if (css_enqueue_subchannel_slow(sch->schid)) {
274 css_clear_subchannel_slow_list(); 274 css_clear_subchannel_slow_list();
@@ -378,12 +378,12 @@ __s390_process_res_acc(struct subchannel_id schid, void *data)
378 /* Check if a subchannel is newly available. */ 378 /* Check if a subchannel is newly available. */
379 return s390_process_res_acc_new_sch(schid); 379 return s390_process_res_acc_new_sch(schid);
380 380
381 spin_lock_irq(&sch->lock); 381 spin_lock_irq(sch->lock);
382 382
383 chp_mask = s390_process_res_acc_sch(res_data, sch); 383 chp_mask = s390_process_res_acc_sch(res_data, sch);
384 384
385 if (chp_mask == 0) { 385 if (chp_mask == 0) {
386 spin_unlock_irq(&sch->lock); 386 spin_unlock_irq(sch->lock);
387 put_device(&sch->dev); 387 put_device(&sch->dev);
388 return 0; 388 return 0;
389 } 389 }
@@ -397,7 +397,7 @@ __s390_process_res_acc(struct subchannel_id schid, void *data)
397 else if (sch->driver && sch->driver->verify) 397 else if (sch->driver && sch->driver->verify)
398 sch->driver->verify(&sch->dev); 398 sch->driver->verify(&sch->dev);
399 399
400 spin_unlock_irq(&sch->lock); 400 spin_unlock_irq(sch->lock);
401 put_device(&sch->dev); 401 put_device(&sch->dev);
402 return 0; 402 return 0;
403} 403}
@@ -635,21 +635,21 @@ __chp_add(struct subchannel_id schid, void *data)
635 if (!sch) 635 if (!sch)
636 /* Check if the subchannel is now available. */ 636 /* Check if the subchannel is now available. */
637 return __chp_add_new_sch(schid); 637 return __chp_add_new_sch(schid);
638 spin_lock_irq(&sch->lock); 638 spin_lock_irq(sch->lock);
639 for (i=0; i<8; i++) { 639 for (i=0; i<8; i++) {
640 mask = 0x80 >> i; 640 mask = 0x80 >> i;
641 if ((sch->schib.pmcw.pim & mask) && 641 if ((sch->schib.pmcw.pim & mask) &&
642 (sch->schib.pmcw.chpid[i] == chp->id)) { 642 (sch->schib.pmcw.chpid[i] == chp->id)) {
643 if (stsch(sch->schid, &sch->schib) != 0) { 643 if (stsch(sch->schid, &sch->schib) != 0) {
644 /* Endgame. */ 644 /* Endgame. */
645 spin_unlock_irq(&sch->lock); 645 spin_unlock_irq(sch->lock);
646 return -ENXIO; 646 return -ENXIO;
647 } 647 }
648 break; 648 break;
649 } 649 }
650 } 650 }
651 if (i==8) { 651 if (i==8) {
652 spin_unlock_irq(&sch->lock); 652 spin_unlock_irq(sch->lock);
653 return 0; 653 return 0;
654 } 654 }
655 sch->lpm = ((sch->schib.pmcw.pim & 655 sch->lpm = ((sch->schib.pmcw.pim &
@@ -660,7 +660,7 @@ __chp_add(struct subchannel_id schid, void *data)
660 if (sch->driver && sch->driver->verify) 660 if (sch->driver && sch->driver->verify)
661 sch->driver->verify(&sch->dev); 661 sch->driver->verify(&sch->dev);
662 662
663 spin_unlock_irq(&sch->lock); 663 spin_unlock_irq(sch->lock);
664 put_device(&sch->dev); 664 put_device(&sch->dev);
665 return 0; 665 return 0;
666} 666}
@@ -750,7 +750,7 @@ __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
750 if (!sch->ssd_info.valid) 750 if (!sch->ssd_info.valid)
751 return; 751 return;
752 752
753 spin_lock_irqsave(&sch->lock, flags); 753 spin_lock_irqsave(sch->lock, flags);
754 old_lpm = sch->lpm; 754 old_lpm = sch->lpm;
755 for (chp = 0; chp < 8; chp++) { 755 for (chp = 0; chp < 8; chp++) {
756 if (sch->ssd_info.chpid[chp] != chpid) 756 if (sch->ssd_info.chpid[chp] != chpid)
@@ -785,7 +785,7 @@ __s390_subchannel_vary_chpid(struct subchannel *sch, __u8 chpid, int on)
785 sch->driver->verify(&sch->dev); 785 sch->driver->verify(&sch->dev);
786 break; 786 break;
787 } 787 }
788 spin_unlock_irqrestore(&sch->lock, flags); 788 spin_unlock_irqrestore(sch->lock, flags);
789} 789}
790 790
791static int 791static int
diff --git a/drivers/s390/cio/cio.c b/drivers/s390/cio/cio.c
index 20aee2783847..7835a714a405 100644
--- a/drivers/s390/cio/cio.c
+++ b/drivers/s390/cio/cio.c
@@ -143,11 +143,11 @@ cio_tpi(void)
143 return 1; 143 return 1;
144 local_bh_disable(); 144 local_bh_disable();
145 irq_enter (); 145 irq_enter ();
146 spin_lock(&sch->lock); 146 spin_lock(sch->lock);
147 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw)); 147 memcpy (&sch->schib.scsw, &irb->scsw, sizeof (struct scsw));
148 if (sch->driver && sch->driver->irq) 148 if (sch->driver && sch->driver->irq)
149 sch->driver->irq(&sch->dev); 149 sch->driver->irq(&sch->dev);
150 spin_unlock(&sch->lock); 150 spin_unlock(sch->lock);
151 irq_exit (); 151 irq_exit ();
152 _local_bh_enable(); 152 _local_bh_enable();
153 return 1; 153 return 1;
@@ -415,6 +415,8 @@ cio_enable_subchannel (struct subchannel *sch, unsigned int isc)
415 CIO_TRACE_EVENT (2, "ensch"); 415 CIO_TRACE_EVENT (2, "ensch");
416 CIO_TRACE_EVENT (2, sch->dev.bus_id); 416 CIO_TRACE_EVENT (2, sch->dev.bus_id);
417 417
418 if (sch_is_pseudo_sch(sch))
419 return -EINVAL;
418 ccode = stsch (sch->schid, &sch->schib); 420 ccode = stsch (sch->schid, &sch->schib);
419 if (ccode) 421 if (ccode)
420 return -ENODEV; 422 return -ENODEV;
@@ -462,6 +464,8 @@ cio_disable_subchannel (struct subchannel *sch)
462 CIO_TRACE_EVENT (2, "dissch"); 464 CIO_TRACE_EVENT (2, "dissch");
463 CIO_TRACE_EVENT (2, sch->dev.bus_id); 465 CIO_TRACE_EVENT (2, sch->dev.bus_id);
464 466
467 if (sch_is_pseudo_sch(sch))
468 return 0;
465 ccode = stsch (sch->schid, &sch->schib); 469 ccode = stsch (sch->schid, &sch->schib);
466 if (ccode == 3) /* Not operational. */ 470 if (ccode == 3) /* Not operational. */
467 return -ENODEV; 471 return -ENODEV;
@@ -496,6 +500,15 @@ cio_disable_subchannel (struct subchannel *sch)
496 return ret; 500 return ret;
497} 501}
498 502
503int cio_create_sch_lock(struct subchannel *sch)
504{
505 sch->lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
506 if (!sch->lock)
507 return -ENOMEM;
508 spin_lock_init(sch->lock);
509 return 0;
510}
511
499/* 512/*
500 * cio_validate_subchannel() 513 * cio_validate_subchannel()
501 * 514 *
@@ -513,6 +526,7 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
513{ 526{
514 char dbf_txt[15]; 527 char dbf_txt[15];
515 int ccode; 528 int ccode;
529 int err;
516 530
517 sprintf (dbf_txt, "valsch%x", schid.sch_no); 531 sprintf (dbf_txt, "valsch%x", schid.sch_no);
518 CIO_TRACE_EVENT (4, dbf_txt); 532 CIO_TRACE_EVENT (4, dbf_txt);
@@ -520,9 +534,15 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
520 /* Nuke all fields. */ 534 /* Nuke all fields. */
521 memset(sch, 0, sizeof(struct subchannel)); 535 memset(sch, 0, sizeof(struct subchannel));
522 536
523 spin_lock_init(&sch->lock); 537 sch->schid = schid;
538 if (cio_is_console(schid)) {
539 sch->lock = cio_get_console_lock();
540 } else {
541 err = cio_create_sch_lock(sch);
542 if (err)
543 goto out;
544 }
524 mutex_init(&sch->reg_mutex); 545 mutex_init(&sch->reg_mutex);
525
526 /* Set a name for the subchannel */ 546 /* Set a name for the subchannel */
527 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid, 547 snprintf (sch->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x", schid.ssid,
528 schid.sch_no); 548 schid.sch_no);
@@ -534,10 +554,10 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
534 * is not valid. 554 * is not valid.
535 */ 555 */
536 ccode = stsch_err (schid, &sch->schib); 556 ccode = stsch_err (schid, &sch->schib);
537 if (ccode) 557 if (ccode) {
538 return (ccode == 3) ? -ENXIO : ccode; 558 err = (ccode == 3) ? -ENXIO : ccode;
539 559 goto out;
540 sch->schid = schid; 560 }
541 /* Copy subchannel type from path management control word. */ 561 /* Copy subchannel type from path management control word. */
542 sch->st = sch->schib.pmcw.st; 562 sch->st = sch->schib.pmcw.st;
543 563
@@ -550,14 +570,16 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
550 "non-I/O subchannel type %04X\n", 570 "non-I/O subchannel type %04X\n",
551 sch->schid.ssid, sch->schid.sch_no, sch->st); 571 sch->schid.ssid, sch->schid.sch_no, sch->st);
552 /* We stop here for non-io subchannels. */ 572 /* We stop here for non-io subchannels. */
553 return sch->st; 573 err = sch->st;
574 goto out;
554 } 575 }
555 576
556 /* Initialization for io subchannels. */ 577 /* Initialization for io subchannels. */
557 if (!sch->schib.pmcw.dnv) 578 if (!sch->schib.pmcw.dnv) {
558 /* io subchannel but device number is invalid. */ 579 /* io subchannel but device number is invalid. */
559 return -ENODEV; 580 err = -ENODEV;
560 581 goto out;
582 }
561 /* Devno is valid. */ 583 /* Devno is valid. */
562 if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) { 584 if (is_blacklisted (sch->schid.ssid, sch->schib.pmcw.dev)) {
563 /* 585 /*
@@ -567,7 +589,8 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
567 CIO_MSG_EVENT(0, "Blacklisted device detected " 589 CIO_MSG_EVENT(0, "Blacklisted device detected "
568 "at devno %04X, subchannel set %x\n", 590 "at devno %04X, subchannel set %x\n",
569 sch->schib.pmcw.dev, sch->schid.ssid); 591 sch->schib.pmcw.dev, sch->schid.ssid);
570 return -ENODEV; 592 err = -ENODEV;
593 goto out;
571 } 594 }
572 sch->opm = 0xff; 595 sch->opm = 0xff;
573 if (!cio_is_console(sch->schid)) 596 if (!cio_is_console(sch->schid))
@@ -595,6 +618,11 @@ cio_validate_subchannel (struct subchannel *sch, struct subchannel_id schid)
595 if ((sch->lpm & (sch->lpm - 1)) != 0) 618 if ((sch->lpm & (sch->lpm - 1)) != 0)
596 sch->schib.pmcw.mp = 1; /* multipath mode */ 619 sch->schib.pmcw.mp = 1; /* multipath mode */
597 return 0; 620 return 0;
621out:
622 if (!cio_is_console(schid))
623 kfree(sch->lock);
624 sch->lock = NULL;
625 return err;
598} 626}
599 627
600/* 628/*
@@ -637,7 +665,7 @@ do_IRQ (struct pt_regs *regs)
637 } 665 }
638 sch = (struct subchannel *)(unsigned long)tpi_info->intparm; 666 sch = (struct subchannel *)(unsigned long)tpi_info->intparm;
639 if (sch) 667 if (sch)
640 spin_lock(&sch->lock); 668 spin_lock(sch->lock);
641 /* Store interrupt response block to lowcore. */ 669 /* Store interrupt response block to lowcore. */
642 if (tsch (tpi_info->schid, irb) == 0 && sch) { 670 if (tsch (tpi_info->schid, irb) == 0 && sch) {
643 /* Keep subchannel information word up to date. */ 671 /* Keep subchannel information word up to date. */
@@ -648,7 +676,7 @@ do_IRQ (struct pt_regs *regs)
648 sch->driver->irq(&sch->dev); 676 sch->driver->irq(&sch->dev);
649 } 677 }
650 if (sch) 678 if (sch)
651 spin_unlock(&sch->lock); 679 spin_unlock(sch->lock);
652 /* 680 /*
653 * Are more interrupts pending? 681 * Are more interrupts pending?
654 * If so, the tpi instruction will update the lowcore 682 * If so, the tpi instruction will update the lowcore
@@ -687,10 +715,10 @@ wait_cons_dev (void)
687 __ctl_load (cr6, 6, 6); 715 __ctl_load (cr6, 6, 6);
688 716
689 do { 717 do {
690 spin_unlock(&console_subchannel.lock); 718 spin_unlock(console_subchannel.lock);
691 if (!cio_tpi()) 719 if (!cio_tpi())
692 cpu_relax(); 720 cpu_relax();
693 spin_lock(&console_subchannel.lock); 721 spin_lock(console_subchannel.lock);
694 } while (console_subchannel.schib.scsw.actl != 0); 722 } while (console_subchannel.schib.scsw.actl != 0);
695 /* 723 /*
696 * restore previous isc value 724 * restore previous isc value
diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h
index 4541c1af4b66..35154a210357 100644
--- a/drivers/s390/cio/cio.h
+++ b/drivers/s390/cio/cio.h
@@ -87,7 +87,7 @@ struct orb {
87/* subchannel data structure used by I/O subroutines */ 87/* subchannel data structure used by I/O subroutines */
88struct subchannel { 88struct subchannel {
89 struct subchannel_id schid; 89 struct subchannel_id schid;
90 spinlock_t lock; /* subchannel lock */ 90 spinlock_t *lock; /* subchannel lock */
91 struct mutex reg_mutex; 91 struct mutex reg_mutex;
92 enum { 92 enum {
93 SUBCHANNEL_TYPE_IO = 0, 93 SUBCHANNEL_TYPE_IO = 0,
@@ -131,15 +131,19 @@ extern int cio_set_options (struct subchannel *, int);
131extern int cio_get_options (struct subchannel *); 131extern int cio_get_options (struct subchannel *);
132extern int cio_modify (struct subchannel *); 132extern int cio_modify (struct subchannel *);
133 133
134int cio_create_sch_lock(struct subchannel *);
135
134/* Use with care. */ 136/* Use with care. */
135#ifdef CONFIG_CCW_CONSOLE 137#ifdef CONFIG_CCW_CONSOLE
136extern struct subchannel *cio_probe_console(void); 138extern struct subchannel *cio_probe_console(void);
137extern void cio_release_console(void); 139extern void cio_release_console(void);
138extern int cio_is_console(struct subchannel_id); 140extern int cio_is_console(struct subchannel_id);
139extern struct subchannel *cio_get_console_subchannel(void); 141extern struct subchannel *cio_get_console_subchannel(void);
142extern spinlock_t * cio_get_console_lock(void);
140#else 143#else
141#define cio_is_console(schid) 0 144#define cio_is_console(schid) 0
142#define cio_get_console_subchannel() NULL 145#define cio_get_console_subchannel() NULL
146#define cio_get_console_lock() NULL;
143#endif 147#endif
144 148
145extern int cio_show_msg; 149extern int cio_show_msg;
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 26cf2f5ae2e7..4c81d890791e 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -91,9 +91,9 @@ css_free_subchannel(struct subchannel *sch)
91 /* Reset intparm to zeroes. */ 91 /* Reset intparm to zeroes. */
92 sch->schib.pmcw.intparm = 0; 92 sch->schib.pmcw.intparm = 0;
93 cio_modify(sch); 93 cio_modify(sch);
94 kfree(sch->lock);
94 kfree(sch); 95 kfree(sch);
95 } 96 }
96
97} 97}
98 98
99static void 99static void
@@ -102,8 +102,10 @@ css_subchannel_release(struct device *dev)
102 struct subchannel *sch; 102 struct subchannel *sch;
103 103
104 sch = to_subchannel(dev); 104 sch = to_subchannel(dev);
105 if (!cio_is_console(sch->schid)) 105 if (!cio_is_console(sch->schid)) {
106 kfree(sch->lock);
106 kfree(sch); 107 kfree(sch);
108 }
107} 109}
108 110
109extern int css_get_ssd_info(struct subchannel *sch); 111extern int css_get_ssd_info(struct subchannel *sch);
@@ -135,14 +137,16 @@ css_register_subchannel(struct subchannel *sch)
135 sch->dev.parent = &css[0]->device; 137 sch->dev.parent = &css[0]->device;
136 sch->dev.bus = &css_bus_type; 138 sch->dev.bus = &css_bus_type;
137 sch->dev.release = &css_subchannel_release; 139 sch->dev.release = &css_subchannel_release;
138 140 sch->dev.groups = subch_attr_groups;
141
139 /* make it known to the system */ 142 /* make it known to the system */
140 ret = css_sch_device_register(sch); 143 ret = css_sch_device_register(sch);
141 if (ret) 144 if (ret) {
142 printk (KERN_WARNING "%s: could not register %s\n", 145 printk (KERN_WARNING "%s: could not register %s\n",
143 __func__, sch->dev.bus_id); 146 __func__, sch->dev.bus_id);
144 else 147 return ret;
145 css_get_ssd_info(sch); 148 }
149 css_get_ssd_info(sch);
146 return ret; 150 return ret;
147} 151}
148 152
@@ -201,18 +205,18 @@ static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
201 unsigned long flags; 205 unsigned long flags;
202 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action; 206 enum { NONE, UNREGISTER, UNREGISTER_PROBE, REPROBE } action;
203 207
204 spin_lock_irqsave(&sch->lock, flags); 208 spin_lock_irqsave(sch->lock, flags);
205 disc = device_is_disconnected(sch); 209 disc = device_is_disconnected(sch);
206 if (disc && slow) { 210 if (disc && slow) {
207 /* Disconnected devices are evaluated directly only.*/ 211 /* Disconnected devices are evaluated directly only.*/
208 spin_unlock_irqrestore(&sch->lock, flags); 212 spin_unlock_irqrestore(sch->lock, flags);
209 return 0; 213 return 0;
210 } 214 }
211 /* No interrupt after machine check - kill pending timers. */ 215 /* No interrupt after machine check - kill pending timers. */
212 device_kill_pending_timer(sch); 216 device_kill_pending_timer(sch);
213 if (!disc && !slow) { 217 if (!disc && !slow) {
214 /* Non-disconnected devices are evaluated on the slow path. */ 218 /* Non-disconnected devices are evaluated on the slow path. */
215 spin_unlock_irqrestore(&sch->lock, flags); 219 spin_unlock_irqrestore(sch->lock, flags);
216 return -EAGAIN; 220 return -EAGAIN;
217 } 221 }
218 event = css_get_subchannel_status(sch); 222 event = css_get_subchannel_status(sch);
@@ -237,9 +241,9 @@ static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
237 /* Ask driver what to do with device. */ 241 /* Ask driver what to do with device. */
238 action = UNREGISTER; 242 action = UNREGISTER;
239 if (sch->driver && sch->driver->notify) { 243 if (sch->driver && sch->driver->notify) {
240 spin_unlock_irqrestore(&sch->lock, flags); 244 spin_unlock_irqrestore(sch->lock, flags);
241 ret = sch->driver->notify(&sch->dev, event); 245 ret = sch->driver->notify(&sch->dev, event);
242 spin_lock_irqsave(&sch->lock, flags); 246 spin_lock_irqsave(sch->lock, flags);
243 if (ret) 247 if (ret)
244 action = NONE; 248 action = NONE;
245 } 249 }
@@ -264,9 +268,9 @@ static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
264 case UNREGISTER: 268 case UNREGISTER:
265 case UNREGISTER_PROBE: 269 case UNREGISTER_PROBE:
266 /* Unregister device (will use subchannel lock). */ 270 /* Unregister device (will use subchannel lock). */
267 spin_unlock_irqrestore(&sch->lock, flags); 271 spin_unlock_irqrestore(sch->lock, flags);
268 css_sch_device_unregister(sch); 272 css_sch_device_unregister(sch);
269 spin_lock_irqsave(&sch->lock, flags); 273 spin_lock_irqsave(sch->lock, flags);
270 274
271 /* Reset intparm to zeroes. */ 275 /* Reset intparm to zeroes. */
272 sch->schib.pmcw.intparm = 0; 276 sch->schib.pmcw.intparm = 0;
@@ -278,7 +282,7 @@ static int css_evaluate_known_subchannel(struct subchannel *sch, int slow)
278 default: 282 default:
279 break; 283 break;
280 } 284 }
281 spin_unlock_irqrestore(&sch->lock, flags); 285 spin_unlock_irqrestore(sch->lock, flags);
282 /* Probe if necessary. */ 286 /* Probe if necessary. */
283 if (action == UNREGISTER_PROBE) 287 if (action == UNREGISTER_PROBE)
284 ret = css_probe_device(sch->schid); 288 ret = css_probe_device(sch->schid);
@@ -573,12 +577,24 @@ css_cm_enable_store(struct device *dev, struct device_attribute *attr,
573 577
574static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store); 578static DEVICE_ATTR(cm_enable, 0644, css_cm_enable_show, css_cm_enable_store);
575 579
576static inline void __init 580static inline int __init setup_css(int nr)
577setup_css(int nr)
578{ 581{
579 u32 tod_high; 582 u32 tod_high;
583 int ret;
580 584
581 memset(css[nr], 0, sizeof(struct channel_subsystem)); 585 memset(css[nr], 0, sizeof(struct channel_subsystem));
586 css[nr]->pseudo_subchannel =
587 kzalloc(sizeof(*css[nr]->pseudo_subchannel), GFP_KERNEL);
588 if (!css[nr]->pseudo_subchannel)
589 return -ENOMEM;
590 css[nr]->pseudo_subchannel->dev.parent = &css[nr]->device;
591 css[nr]->pseudo_subchannel->dev.release = css_subchannel_release;
592 sprintf(css[nr]->pseudo_subchannel->dev.bus_id, "defunct");
593 ret = cio_create_sch_lock(css[nr]->pseudo_subchannel);
594 if (ret) {
595 kfree(css[nr]->pseudo_subchannel);
596 return ret;
597 }
582 mutex_init(&css[nr]->mutex); 598 mutex_init(&css[nr]->mutex);
583 css[nr]->valid = 1; 599 css[nr]->valid = 1;
584 css[nr]->cssid = nr; 600 css[nr]->cssid = nr;
@@ -586,6 +602,7 @@ setup_css(int nr)
586 css[nr]->device.release = channel_subsystem_release; 602 css[nr]->device.release = channel_subsystem_release;
587 tod_high = (u32) (get_clock() >> 32); 603 tod_high = (u32) (get_clock() >> 32);
588 css_generate_pgid(css[nr], tod_high); 604 css_generate_pgid(css[nr], tod_high);
605 return 0;
589} 606}
590 607
591/* 608/*
@@ -622,10 +639,12 @@ init_channel_subsystem (void)
622 ret = -ENOMEM; 639 ret = -ENOMEM;
623 goto out_unregister; 640 goto out_unregister;
624 } 641 }
625 setup_css(i); 642 ret = setup_css(i);
626 ret = device_register(&css[i]->device);
627 if (ret) 643 if (ret)
628 goto out_free; 644 goto out_free;
645 ret = device_register(&css[i]->device);
646 if (ret)
647 goto out_free_all;
629 if (css_characteristics_avail && 648 if (css_characteristics_avail &&
630 css_chsc_characteristics.secm) { 649 css_chsc_characteristics.secm) {
631 ret = device_create_file(&css[i]->device, 650 ret = device_create_file(&css[i]->device,
@@ -633,6 +652,9 @@ init_channel_subsystem (void)
633 if (ret) 652 if (ret)
634 goto out_device; 653 goto out_device;
635 } 654 }
655 ret = device_register(&css[i]->pseudo_subchannel->dev);
656 if (ret)
657 goto out_file;
636 } 658 }
637 css_init_done = 1; 659 css_init_done = 1;
638 660
@@ -640,13 +662,19 @@ init_channel_subsystem (void)
640 662
641 for_each_subchannel(__init_channel_subsystem, NULL); 663 for_each_subchannel(__init_channel_subsystem, NULL);
642 return 0; 664 return 0;
665out_file:
666 device_remove_file(&css[i]->device, &dev_attr_cm_enable);
643out_device: 667out_device:
644 device_unregister(&css[i]->device); 668 device_unregister(&css[i]->device);
669out_free_all:
670 kfree(css[i]->pseudo_subchannel->lock);
671 kfree(css[i]->pseudo_subchannel);
645out_free: 672out_free:
646 kfree(css[i]); 673 kfree(css[i]);
647out_unregister: 674out_unregister:
648 while (i > 0) { 675 while (i > 0) {
649 i--; 676 i--;
677 device_unregister(&css[i]->pseudo_subchannel->dev);
650 if (css_characteristics_avail && css_chsc_characteristics.secm) 678 if (css_characteristics_avail && css_chsc_characteristics.secm)
651 device_remove_file(&css[i]->device, 679 device_remove_file(&css[i]->device,
652 &dev_attr_cm_enable); 680 &dev_attr_cm_enable);
@@ -658,6 +686,11 @@ out:
658 return ret; 686 return ret;
659} 687}
660 688
689int sch_is_pseudo_sch(struct subchannel *sch)
690{
691 return sch == to_css(sch->dev.parent)->pseudo_subchannel;
692}
693
661/* 694/*
662 * find a driver for a subchannel. They identify by the subchannel 695 * find a driver for a subchannel. They identify by the subchannel
663 * type with the exception that the console subchannel driver has its own 696 * type with the exception that the console subchannel driver has its own
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index 9ff064e71767..3464c5b875c4 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -73,6 +73,8 @@ struct senseid {
73} __attribute__ ((packed,aligned(4))); 73} __attribute__ ((packed,aligned(4)));
74 74
75struct ccw_device_private { 75struct ccw_device_private {
76 struct ccw_device *cdev;
77 struct subchannel *sch;
76 int state; /* device state */ 78 int state; /* device state */
77 atomic_t onoff; 79 atomic_t onoff;
78 unsigned long registered; 80 unsigned long registered;
@@ -158,6 +160,8 @@ struct channel_subsystem {
158 int cm_enabled; 160 int cm_enabled;
159 void *cub_addr1; 161 void *cub_addr1;
160 void *cub_addr2; 162 void *cub_addr2;
163 /* for orphaned ccw devices */
164 struct subchannel *pseudo_subchannel;
161}; 165};
162#define to_css(dev) container_of(dev, struct channel_subsystem, device) 166#define to_css(dev) container_of(dev, struct channel_subsystem, device)
163 167
@@ -185,6 +189,11 @@ void css_clear_subchannel_slow_list(void);
185int css_slow_subchannels_exist(void); 189int css_slow_subchannels_exist(void);
186extern int need_rescan; 190extern int need_rescan;
187 191
192int sch_is_pseudo_sch(struct subchannel *);
193
188extern struct workqueue_struct *slow_path_wq; 194extern struct workqueue_struct *slow_path_wq;
189extern struct work_struct slow_path_work; 195extern struct work_struct slow_path_work;
196
197int subchannel_add_files (struct device *);
198extern struct attribute_group *subch_attr_groups[];
190#endif 199#endif
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index d3d3716ff84b..803579053c2f 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -23,6 +23,7 @@
23#include <asm/param.h> /* HZ */ 23#include <asm/param.h> /* HZ */
24 24
25#include "cio.h" 25#include "cio.h"
26#include "cio_debug.h"
26#include "css.h" 27#include "css.h"
27#include "device.h" 28#include "device.h"
28#include "ioasm.h" 29#include "ioasm.h"
@@ -234,9 +235,11 @@ chpids_show (struct device * dev, struct device_attribute *attr, char * buf)
234 ssize_t ret = 0; 235 ssize_t ret = 0;
235 int chp; 236 int chp;
236 237
237 for (chp = 0; chp < 8; chp++) 238 if (ssd)
238 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]); 239 for (chp = 0; chp < 8; chp++)
239 240 ret += sprintf (buf+ret, "%02x ", ssd->chpid[chp]);
241 else
242 ret += sprintf (buf, "n/a");
240 ret += sprintf (buf+ret, "\n"); 243 ret += sprintf (buf+ret, "\n");
241 return min((ssize_t)PAGE_SIZE, ret); 244 return min((ssize_t)PAGE_SIZE, ret);
242} 245}
@@ -294,14 +297,44 @@ online_show (struct device *dev, struct device_attribute *attr, char *buf)
294 return sprintf(buf, cdev->online ? "1\n" : "0\n"); 297 return sprintf(buf, cdev->online ? "1\n" : "0\n");
295} 298}
296 299
300int ccw_device_is_orphan(struct ccw_device *cdev)
301{
302 return sch_is_pseudo_sch(to_subchannel(cdev->dev.parent));
303}
304
305static void ccw_device_unregister(struct work_struct *work)
306{
307 struct ccw_device_private *priv;
308 struct ccw_device *cdev;
309
310 priv = container_of(work, struct ccw_device_private, kick_work);
311 cdev = priv->cdev;
312 if (test_and_clear_bit(1, &cdev->private->registered))
313 device_unregister(&cdev->dev);
314 put_device(&cdev->dev);
315}
316
297static void 317static void
298ccw_device_remove_disconnected(struct ccw_device *cdev) 318ccw_device_remove_disconnected(struct ccw_device *cdev)
299{ 319{
300 struct subchannel *sch; 320 struct subchannel *sch;
321 unsigned long flags;
301 /* 322 /*
302 * Forced offline in disconnected state means 323 * Forced offline in disconnected state means
303 * 'throw away device'. 324 * 'throw away device'.
304 */ 325 */
326 if (ccw_device_is_orphan(cdev)) {
327 /* Deregister ccw device. */
328 spin_lock_irqsave(cdev->ccwlock, flags);
329 cdev->private->state = DEV_STATE_NOT_OPER;
330 spin_unlock_irqrestore(cdev->ccwlock, flags);
331 if (get_device(&cdev->dev)) {
332 PREPARE_WORK(&cdev->private->kick_work,
333 ccw_device_unregister);
334 queue_work(ccw_device_work, &cdev->private->kick_work);
335 }
336 return ;
337 }
305 sch = to_subchannel(cdev->dev.parent); 338 sch = to_subchannel(cdev->dev.parent);
306 css_sch_device_unregister(sch); 339 css_sch_device_unregister(sch);
307 /* Reset intparm to zeroes. */ 340 /* Reset intparm to zeroes. */
@@ -462,6 +495,8 @@ available_show (struct device *dev, struct device_attribute *attr, char *buf)
462 struct ccw_device *cdev = to_ccwdev(dev); 495 struct ccw_device *cdev = to_ccwdev(dev);
463 struct subchannel *sch; 496 struct subchannel *sch;
464 497
498 if (ccw_device_is_orphan(cdev))
499 return sprintf(buf, "no device\n");
465 switch (cdev->private->state) { 500 switch (cdev->private->state) {
466 case DEV_STATE_BOXED: 501 case DEV_STATE_BOXED:
467 return sprintf(buf, "boxed\n"); 502 return sprintf(buf, "boxed\n");
@@ -498,11 +533,10 @@ static struct attribute_group subch_attr_group = {
498 .attrs = subch_attrs, 533 .attrs = subch_attrs,
499}; 534};
500 535
501static inline int 536struct attribute_group *subch_attr_groups[] = {
502subchannel_add_files (struct device *dev) 537 &subch_attr_group,
503{ 538 NULL,
504 return sysfs_create_group(&dev->kobj, &subch_attr_group); 539};
505}
506 540
507static struct attribute * ccwdev_attrs[] = { 541static struct attribute * ccwdev_attrs[] = {
508 &dev_attr_devtype.attr, 542 &dev_attr_devtype.attr,
@@ -563,11 +597,10 @@ match_devno(struct device * dev, void * data)
563 597
564 cdev = to_ccwdev(dev); 598 cdev = to_ccwdev(dev);
565 if ((cdev->private->state == DEV_STATE_DISCONNECTED) && 599 if ((cdev->private->state == DEV_STATE_DISCONNECTED) &&
600 !ccw_device_is_orphan(cdev) &&
566 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) && 601 ccw_dev_id_is_equal(&cdev->private->dev_id, &d->dev_id) &&
567 (cdev != d->sibling)) { 602 (cdev != d->sibling))
568 cdev->private->state = DEV_STATE_NOT_OPER;
569 return 1; 603 return 1;
570 }
571 return 0; 604 return 0;
572} 605}
573 606
@@ -584,13 +617,36 @@ static struct ccw_device * get_disc_ccwdev_by_dev_id(struct ccw_dev_id *dev_id,
584 return dev ? to_ccwdev(dev) : NULL; 617 return dev ? to_ccwdev(dev) : NULL;
585} 618}
586 619
587static void 620static int match_orphan(struct device *dev, void *data)
588ccw_device_add_changed(void *data) 621{
622 struct ccw_dev_id *dev_id;
623 struct ccw_device *cdev;
624
625 dev_id = data;
626 cdev = to_ccwdev(dev);
627 return ccw_dev_id_is_equal(&cdev->private->dev_id, dev_id);
628}
629
630static struct ccw_device *
631get_orphaned_ccwdev_by_dev_id(struct channel_subsystem *css,
632 struct ccw_dev_id *dev_id)
589{ 633{
634 struct device *dev;
590 635
636 dev = device_find_child(&css->pseudo_subchannel->dev, dev_id,
637 match_orphan);
638
639 return dev ? to_ccwdev(dev) : NULL;
640}
641
642static void
643ccw_device_add_changed(struct work_struct *work)
644{
645 struct ccw_device_private *priv;
591 struct ccw_device *cdev; 646 struct ccw_device *cdev;
592 647
593 cdev = data; 648 priv = container_of(work, struct ccw_device_private, kick_work);
649 cdev = priv->cdev;
594 if (device_add(&cdev->dev)) { 650 if (device_add(&cdev->dev)) {
595 put_device(&cdev->dev); 651 put_device(&cdev->dev);
596 return; 652 return;
@@ -602,64 +658,21 @@ ccw_device_add_changed(void *data)
602 } 658 }
603} 659}
604 660
605extern int css_get_ssd_info(struct subchannel *sch); 661void ccw_device_do_unreg_rereg(struct work_struct *work)
606
607void
608ccw_device_do_unreg_rereg(void *data)
609{ 662{
663 struct ccw_device_private *priv;
610 struct ccw_device *cdev; 664 struct ccw_device *cdev;
611 struct subchannel *sch; 665 struct subchannel *sch;
612 int need_rename;
613 666
614 cdev = data; 667 priv = container_of(work, struct ccw_device_private, kick_work);
668 cdev = priv->cdev;
615 sch = to_subchannel(cdev->dev.parent); 669 sch = to_subchannel(cdev->dev.parent);
616 if (cdev->private->dev_id.devno != sch->schib.pmcw.dev) { 670
617 /*
618 * The device number has changed. This is usually only when
619 * a device has been detached under VM and then re-appeared
620 * on another subchannel because of a different attachment
621 * order than before. Ideally, we should should just switch
622 * subchannels, but unfortunately, this is not possible with
623 * the current implementation.
624 * Instead, we search for the old subchannel for this device
625 * number and deregister so there are no collisions with the
626 * newly registered ccw_device.
627 * FIXME: Find another solution so the block layer doesn't
628 * get possibly sick...
629 */
630 struct ccw_device *other_cdev;
631 struct ccw_dev_id dev_id;
632
633 need_rename = 1;
634 dev_id.devno = sch->schib.pmcw.dev;
635 dev_id.ssid = sch->schid.ssid;
636 other_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
637 if (other_cdev) {
638 struct subchannel *other_sch;
639
640 other_sch = to_subchannel(other_cdev->dev.parent);
641 if (get_device(&other_sch->dev)) {
642 stsch(other_sch->schid, &other_sch->schib);
643 if (other_sch->schib.pmcw.dnv) {
644 other_sch->schib.pmcw.intparm = 0;
645 cio_modify(other_sch);
646 }
647 css_sch_device_unregister(other_sch);
648 }
649 }
650 /* Update ssd info here. */
651 css_get_ssd_info(sch);
652 cdev->private->dev_id.devno = sch->schib.pmcw.dev;
653 } else
654 need_rename = 0;
655 device_remove_files(&cdev->dev); 671 device_remove_files(&cdev->dev);
656 if (test_and_clear_bit(1, &cdev->private->registered)) 672 if (test_and_clear_bit(1, &cdev->private->registered))
657 device_del(&cdev->dev); 673 device_del(&cdev->dev);
658 if (need_rename)
659 snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.%x.%04x",
660 sch->schid.ssid, sch->schib.pmcw.dev);
661 PREPARE_WORK(&cdev->private->kick_work, 674 PREPARE_WORK(&cdev->private->kick_work,
662 ccw_device_add_changed, cdev); 675 ccw_device_add_changed);
663 queue_work(ccw_device_work, &cdev->private->kick_work); 676 queue_work(ccw_device_work, &cdev->private->kick_work);
664} 677}
665 678
@@ -673,18 +686,194 @@ ccw_device_release(struct device *dev)
673 kfree(cdev); 686 kfree(cdev);
674} 687}
675 688
689static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch)
690{
691 struct ccw_device *cdev;
692
693 cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
694 if (cdev) {
695 cdev->private = kzalloc(sizeof(struct ccw_device_private),
696 GFP_KERNEL | GFP_DMA);
697 if (cdev->private)
698 return cdev;
699 }
700 kfree(cdev);
701 return ERR_PTR(-ENOMEM);
702}
703
704static int io_subchannel_initialize_dev(struct subchannel *sch,
705 struct ccw_device *cdev)
706{
707 cdev->private->cdev = cdev;
708 atomic_set(&cdev->private->onoff, 0);
709 cdev->dev.parent = &sch->dev;
710 cdev->dev.release = ccw_device_release;
711 INIT_LIST_HEAD(&cdev->private->kick_work.entry);
712 /* Do first half of device_register. */
713 device_initialize(&cdev->dev);
714 if (!get_device(&sch->dev)) {
715 if (cdev->dev.release)
716 cdev->dev.release(&cdev->dev);
717 return -ENODEV;
718 }
719 return 0;
720}
721
722static struct ccw_device * io_subchannel_create_ccwdev(struct subchannel *sch)
723{
724 struct ccw_device *cdev;
725 int ret;
726
727 cdev = io_subchannel_allocate_dev(sch);
728 if (!IS_ERR(cdev)) {
729 ret = io_subchannel_initialize_dev(sch, cdev);
730 if (ret) {
731 kfree(cdev);
732 cdev = ERR_PTR(ret);
733 }
734 }
735 return cdev;
736}
737
738static int io_subchannel_recog(struct ccw_device *, struct subchannel *);
739
740static void sch_attach_device(struct subchannel *sch,
741 struct ccw_device *cdev)
742{
743 spin_lock_irq(sch->lock);
744 sch->dev.driver_data = cdev;
745 cdev->private->schid = sch->schid;
746 cdev->ccwlock = sch->lock;
747 device_trigger_reprobe(sch);
748 spin_unlock_irq(sch->lock);
749}
750
751static void sch_attach_disconnected_device(struct subchannel *sch,
752 struct ccw_device *cdev)
753{
754 struct subchannel *other_sch;
755 int ret;
756
757 other_sch = to_subchannel(get_device(cdev->dev.parent));
758 ret = device_move(&cdev->dev, &sch->dev);
759 if (ret) {
760 CIO_MSG_EVENT(2, "Moving disconnected device 0.%x.%04x failed "
761 "(ret=%d)!\n", cdev->private->dev_id.ssid,
762 cdev->private->dev_id.devno, ret);
763 put_device(&other_sch->dev);
764 return;
765 }
766 other_sch->dev.driver_data = NULL;
767 /* No need to keep a subchannel without ccw device around. */
768 css_sch_device_unregister(other_sch);
769 put_device(&other_sch->dev);
770 sch_attach_device(sch, cdev);
771}
772
773static void sch_attach_orphaned_device(struct subchannel *sch,
774 struct ccw_device *cdev)
775{
776 int ret;
777
778 /* Try to move the ccw device to its new subchannel. */
779 ret = device_move(&cdev->dev, &sch->dev);
780 if (ret) {
781 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
782 "failed (ret=%d)!\n",
783 cdev->private->dev_id.ssid,
784 cdev->private->dev_id.devno, ret);
785 return;
786 }
787 sch_attach_device(sch, cdev);
788}
789
790static void sch_create_and_recog_new_device(struct subchannel *sch)
791{
792 struct ccw_device *cdev;
793
794 /* Need to allocate a new ccw device. */
795 cdev = io_subchannel_create_ccwdev(sch);
796 if (IS_ERR(cdev)) {
797 /* OK, we did everything we could... */
798 css_sch_device_unregister(sch);
799 return;
800 }
801 spin_lock_irq(sch->lock);
802 sch->dev.driver_data = cdev;
803 spin_unlock_irq(sch->lock);
804 /* Start recognition for the new ccw device. */
805 if (io_subchannel_recog(cdev, sch)) {
806 spin_lock_irq(sch->lock);
807 sch->dev.driver_data = NULL;
808 spin_unlock_irq(sch->lock);
809 if (cdev->dev.release)
810 cdev->dev.release(&cdev->dev);
811 css_sch_device_unregister(sch);
812 }
813}
814
815
816void ccw_device_move_to_orphanage(struct work_struct *work)
817{
818 struct ccw_device_private *priv;
819 struct ccw_device *cdev;
820 struct ccw_device *replacing_cdev;
821 struct subchannel *sch;
822 int ret;
823 struct channel_subsystem *css;
824 struct ccw_dev_id dev_id;
825
826 priv = container_of(work, struct ccw_device_private, kick_work);
827 cdev = priv->cdev;
828 sch = to_subchannel(cdev->dev.parent);
829 css = to_css(sch->dev.parent);
830 dev_id.devno = sch->schib.pmcw.dev;
831 dev_id.ssid = sch->schid.ssid;
832
833 /*
834 * Move the orphaned ccw device to the orphanage so the replacing
835 * ccw device can take its place on the subchannel.
836 */
837 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev);
838 if (ret) {
839 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
840 "(ret=%d)!\n", cdev->private->dev_id.ssid,
841 cdev->private->dev_id.devno, ret);
842 return;
843 }
844 cdev->ccwlock = css->pseudo_subchannel->lock;
845 /*
846 * Search for the replacing ccw device
847 * - among the disconnected devices
848 * - in the orphanage
849 */
850 replacing_cdev = get_disc_ccwdev_by_dev_id(&dev_id, cdev);
851 if (replacing_cdev) {
852 sch_attach_disconnected_device(sch, replacing_cdev);
853 return;
854 }
855 replacing_cdev = get_orphaned_ccwdev_by_dev_id(css, &dev_id);
856 if (replacing_cdev) {
857 sch_attach_orphaned_device(sch, replacing_cdev);
858 return;
859 }
860 sch_create_and_recog_new_device(sch);
861}
862
676/* 863/*
677 * Register recognized device. 864 * Register recognized device.
678 */ 865 */
679static void 866static void
680io_subchannel_register(void *data) 867io_subchannel_register(struct work_struct *work)
681{ 868{
869 struct ccw_device_private *priv;
682 struct ccw_device *cdev; 870 struct ccw_device *cdev;
683 struct subchannel *sch; 871 struct subchannel *sch;
684 int ret; 872 int ret;
685 unsigned long flags; 873 unsigned long flags;
686 874
687 cdev = data; 875 priv = container_of(work, struct ccw_device_private, kick_work);
876 cdev = priv->cdev;
688 sch = to_subchannel(cdev->dev.parent); 877 sch = to_subchannel(cdev->dev.parent);
689 878
690 /* 879 /*
@@ -709,9 +898,9 @@ io_subchannel_register(void *data)
709 printk (KERN_WARNING "%s: could not register %s\n", 898 printk (KERN_WARNING "%s: could not register %s\n",
710 __func__, cdev->dev.bus_id); 899 __func__, cdev->dev.bus_id);
711 put_device(&cdev->dev); 900 put_device(&cdev->dev);
712 spin_lock_irqsave(&sch->lock, flags); 901 spin_lock_irqsave(sch->lock, flags);
713 sch->dev.driver_data = NULL; 902 sch->dev.driver_data = NULL;
714 spin_unlock_irqrestore(&sch->lock, flags); 903 spin_unlock_irqrestore(sch->lock, flags);
715 kfree (cdev->private); 904 kfree (cdev->private);
716 kfree (cdev); 905 kfree (cdev);
717 put_device(&sch->dev); 906 put_device(&sch->dev);
@@ -719,11 +908,6 @@ io_subchannel_register(void *data)
719 wake_up(&ccw_device_init_wq); 908 wake_up(&ccw_device_init_wq);
720 return; 909 return;
721 } 910 }
722
723 ret = subchannel_add_files(cdev->dev.parent);
724 if (ret)
725 printk(KERN_WARNING "%s: could not add attributes to %s\n",
726 __func__, sch->dev.bus_id);
727 put_device(&cdev->dev); 911 put_device(&cdev->dev);
728out: 912out:
729 cdev->private->flags.recog_done = 1; 913 cdev->private->flags.recog_done = 1;
@@ -734,11 +918,14 @@ out:
734} 918}
735 919
736void 920void
737ccw_device_call_sch_unregister(void *data) 921ccw_device_call_sch_unregister(struct work_struct *work)
738{ 922{
739 struct ccw_device *cdev = data; 923 struct ccw_device_private *priv;
924 struct ccw_device *cdev;
740 struct subchannel *sch; 925 struct subchannel *sch;
741 926
927 priv = container_of(work, struct ccw_device_private, kick_work);
928 cdev = priv->cdev;
742 sch = to_subchannel(cdev->dev.parent); 929 sch = to_subchannel(cdev->dev.parent);
743 css_sch_device_unregister(sch); 930 css_sch_device_unregister(sch);
744 /* Reset intparm to zeroes. */ 931 /* Reset intparm to zeroes. */
@@ -768,7 +955,7 @@ io_subchannel_recog_done(struct ccw_device *cdev)
768 break; 955 break;
769 sch = to_subchannel(cdev->dev.parent); 956 sch = to_subchannel(cdev->dev.parent);
770 PREPARE_WORK(&cdev->private->kick_work, 957 PREPARE_WORK(&cdev->private->kick_work,
771 ccw_device_call_sch_unregister, cdev); 958 ccw_device_call_sch_unregister);
772 queue_work(slow_path_wq, &cdev->private->kick_work); 959 queue_work(slow_path_wq, &cdev->private->kick_work);
773 if (atomic_dec_and_test(&ccw_device_init_count)) 960 if (atomic_dec_and_test(&ccw_device_init_count))
774 wake_up(&ccw_device_init_wq); 961 wake_up(&ccw_device_init_wq);
@@ -783,7 +970,7 @@ io_subchannel_recog_done(struct ccw_device *cdev)
783 if (!get_device(&cdev->dev)) 970 if (!get_device(&cdev->dev))
784 break; 971 break;
785 PREPARE_WORK(&cdev->private->kick_work, 972 PREPARE_WORK(&cdev->private->kick_work,
786 io_subchannel_register, cdev); 973 io_subchannel_register);
787 queue_work(slow_path_wq, &cdev->private->kick_work); 974 queue_work(slow_path_wq, &cdev->private->kick_work);
788 break; 975 break;
789 } 976 }
@@ -797,7 +984,7 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
797 984
798 sch->dev.driver_data = cdev; 985 sch->dev.driver_data = cdev;
799 sch->driver = &io_subchannel_driver; 986 sch->driver = &io_subchannel_driver;
800 cdev->ccwlock = &sch->lock; 987 cdev->ccwlock = sch->lock;
801 988
802 /* Init private data. */ 989 /* Init private data. */
803 priv = cdev->private; 990 priv = cdev->private;
@@ -817,9 +1004,9 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
817 atomic_inc(&ccw_device_init_count); 1004 atomic_inc(&ccw_device_init_count);
818 1005
819 /* Start async. device sensing. */ 1006 /* Start async. device sensing. */
820 spin_lock_irq(&sch->lock); 1007 spin_lock_irq(sch->lock);
821 rc = ccw_device_recognition(cdev); 1008 rc = ccw_device_recognition(cdev);
822 spin_unlock_irq(&sch->lock); 1009 spin_unlock_irq(sch->lock);
823 if (rc) { 1010 if (rc) {
824 if (atomic_dec_and_test(&ccw_device_init_count)) 1011 if (atomic_dec_and_test(&ccw_device_init_count))
825 wake_up(&ccw_device_init_wq); 1012 wake_up(&ccw_device_init_wq);
@@ -827,12 +1014,55 @@ io_subchannel_recog(struct ccw_device *cdev, struct subchannel *sch)
827 return rc; 1014 return rc;
828} 1015}
829 1016
1017static void ccw_device_move_to_sch(struct work_struct *work)
1018{
1019 struct ccw_device_private *priv;
1020 int rc;
1021 struct subchannel *sch;
1022 struct ccw_device *cdev;
1023 struct subchannel *former_parent;
1024
1025 priv = container_of(work, struct ccw_device_private, kick_work);
1026 sch = priv->sch;
1027 cdev = priv->cdev;
1028 former_parent = ccw_device_is_orphan(cdev) ?
1029 NULL : to_subchannel(get_device(cdev->dev.parent));
1030 mutex_lock(&sch->reg_mutex);
1031 /* Try to move the ccw device to its new subchannel. */
1032 rc = device_move(&cdev->dev, &sch->dev);
1033 mutex_unlock(&sch->reg_mutex);
1034 if (rc) {
1035 CIO_MSG_EVENT(2, "Moving device 0.%x.%04x to subchannel "
1036 "0.%x.%04x failed (ret=%d)!\n",
1037 cdev->private->dev_id.ssid,
1038 cdev->private->dev_id.devno, sch->schid.ssid,
1039 sch->schid.sch_no, rc);
1040 css_sch_device_unregister(sch);
1041 goto out;
1042 }
1043 if (former_parent) {
1044 spin_lock_irq(former_parent->lock);
1045 former_parent->dev.driver_data = NULL;
1046 spin_unlock_irq(former_parent->lock);
1047 css_sch_device_unregister(former_parent);
1048 /* Reset intparm to zeroes. */
1049 former_parent->schib.pmcw.intparm = 0;
1050 cio_modify(former_parent);
1051 }
1052 sch_attach_device(sch, cdev);
1053out:
1054 if (former_parent)
1055 put_device(&former_parent->dev);
1056 put_device(&cdev->dev);
1057}
1058
830static int 1059static int
831io_subchannel_probe (struct subchannel *sch) 1060io_subchannel_probe (struct subchannel *sch)
832{ 1061{
833 struct ccw_device *cdev; 1062 struct ccw_device *cdev;
834 int rc; 1063 int rc;
835 unsigned long flags; 1064 unsigned long flags;
1065 struct ccw_dev_id dev_id;
836 1066
837 if (sch->dev.driver_data) { 1067 if (sch->dev.driver_data) {
838 /* 1068 /*
@@ -843,7 +1073,6 @@ io_subchannel_probe (struct subchannel *sch)
843 cdev = sch->dev.driver_data; 1073 cdev = sch->dev.driver_data;
844 device_initialize(&cdev->dev); 1074 device_initialize(&cdev->dev);
845 ccw_device_register(cdev); 1075 ccw_device_register(cdev);
846 subchannel_add_files(&sch->dev);
847 /* 1076 /*
848 * Check if the device is already online. If it is 1077 * Check if the device is already online. If it is
849 * the reference count needs to be corrected 1078 * the reference count needs to be corrected
@@ -856,33 +1085,37 @@ io_subchannel_probe (struct subchannel *sch)
856 get_device(&cdev->dev); 1085 get_device(&cdev->dev);
857 return 0; 1086 return 0;
858 } 1087 }
859 cdev = kzalloc (sizeof(*cdev), GFP_KERNEL); 1088 /*
1089 * First check if a fitting device may be found amongst the
1090 * disconnected devices or in the orphanage.
1091 */
1092 dev_id.devno = sch->schib.pmcw.dev;
1093 dev_id.ssid = sch->schid.ssid;
1094 cdev = get_disc_ccwdev_by_dev_id(&dev_id, NULL);
860 if (!cdev) 1095 if (!cdev)
861 return -ENOMEM; 1096 cdev = get_orphaned_ccwdev_by_dev_id(to_css(sch->dev.parent),
862 cdev->private = kzalloc(sizeof(struct ccw_device_private), 1097 &dev_id);
863 GFP_KERNEL | GFP_DMA); 1098 if (cdev) {
864 if (!cdev->private) { 1099 /*
865 kfree(cdev); 1100 * Schedule moving the device until when we have a registered
866 return -ENOMEM; 1101 * subchannel to move to and succeed the probe. We can
867 } 1102 * unregister later again, when the probe is through.
868 atomic_set(&cdev->private->onoff, 0); 1103 */
869 cdev->dev.parent = &sch->dev; 1104 cdev->private->sch = sch;
870 cdev->dev.release = ccw_device_release; 1105 PREPARE_WORK(&cdev->private->kick_work,
871 INIT_LIST_HEAD(&cdev->private->kick_work.entry); 1106 ccw_device_move_to_sch);
872 /* Do first half of device_register. */ 1107 queue_work(slow_path_wq, &cdev->private->kick_work);
873 device_initialize(&cdev->dev); 1108 return 0;
874
875 if (!get_device(&sch->dev)) {
876 if (cdev->dev.release)
877 cdev->dev.release(&cdev->dev);
878 return -ENODEV;
879 } 1109 }
1110 cdev = io_subchannel_create_ccwdev(sch);
1111 if (IS_ERR(cdev))
1112 return PTR_ERR(cdev);
880 1113
881 rc = io_subchannel_recog(cdev, sch); 1114 rc = io_subchannel_recog(cdev, sch);
882 if (rc) { 1115 if (rc) {
883 spin_lock_irqsave(&sch->lock, flags); 1116 spin_lock_irqsave(sch->lock, flags);
884 sch->dev.driver_data = NULL; 1117 sch->dev.driver_data = NULL;
885 spin_unlock_irqrestore(&sch->lock, flags); 1118 spin_unlock_irqrestore(sch->lock, flags);
886 if (cdev->dev.release) 1119 if (cdev->dev.release)
887 cdev->dev.release(&cdev->dev); 1120 cdev->dev.release(&cdev->dev);
888 } 1121 }
@@ -890,17 +1123,6 @@ io_subchannel_probe (struct subchannel *sch)
890 return rc; 1123 return rc;
891} 1124}
892 1125
893static void
894ccw_device_unregister(void *data)
895{
896 struct ccw_device *cdev;
897
898 cdev = (struct ccw_device *)data;
899 if (test_and_clear_bit(1, &cdev->private->registered))
900 device_unregister(&cdev->dev);
901 put_device(&cdev->dev);
902}
903
904static int 1126static int
905io_subchannel_remove (struct subchannel *sch) 1127io_subchannel_remove (struct subchannel *sch)
906{ 1128{
@@ -921,7 +1143,7 @@ io_subchannel_remove (struct subchannel *sch)
921 */ 1143 */
922 if (get_device(&cdev->dev)) { 1144 if (get_device(&cdev->dev)) {
923 PREPARE_WORK(&cdev->private->kick_work, 1145 PREPARE_WORK(&cdev->private->kick_work,
924 ccw_device_unregister, cdev); 1146 ccw_device_unregister);
925 queue_work(ccw_device_work, &cdev->private->kick_work); 1147 queue_work(ccw_device_work, &cdev->private->kick_work);
926 } 1148 }
927 return 0; 1149 return 0;
@@ -1003,6 +1225,13 @@ static struct ccw_device console_cdev;
1003static struct ccw_device_private console_private; 1225static struct ccw_device_private console_private;
1004static int console_cdev_in_use; 1226static int console_cdev_in_use;
1005 1227
1228static DEFINE_SPINLOCK(ccw_console_lock);
1229
1230spinlock_t * cio_get_console_lock(void)
1231{
1232 return &ccw_console_lock;
1233}
1234
1006static int 1235static int
1007ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch) 1236ccw_device_console_enable (struct ccw_device *cdev, struct subchannel *sch)
1008{ 1237{
@@ -1048,6 +1277,7 @@ ccw_device_probe_console(void)
1048 memset(&console_cdev, 0, sizeof(struct ccw_device)); 1277 memset(&console_cdev, 0, sizeof(struct ccw_device));
1049 memset(&console_private, 0, sizeof(struct ccw_device_private)); 1278 memset(&console_private, 0, sizeof(struct ccw_device_private));
1050 console_cdev.private = &console_private; 1279 console_cdev.private = &console_private;
1280 console_private.cdev = &console_cdev;
1051 ret = ccw_device_console_enable(&console_cdev, sch); 1281 ret = ccw_device_console_enable(&console_cdev, sch);
1052 if (ret) { 1282 if (ret) {
1053 cio_release_console(); 1283 cio_release_console();
diff --git a/drivers/s390/cio/device.h b/drivers/s390/cio/device.h
index 9233b5c0bcc8..29db6341d632 100644
--- a/drivers/s390/cio/device.h
+++ b/drivers/s390/cio/device.h
@@ -78,8 +78,10 @@ void io_subchannel_recog_done(struct ccw_device *cdev);
78 78
79int ccw_device_cancel_halt_clear(struct ccw_device *); 79int ccw_device_cancel_halt_clear(struct ccw_device *);
80 80
81void ccw_device_do_unreg_rereg(void *); 81void ccw_device_do_unreg_rereg(struct work_struct *);
82void ccw_device_call_sch_unregister(void *); 82void ccw_device_call_sch_unregister(struct work_struct *);
83void ccw_device_move_to_orphanage(struct work_struct *);
84int ccw_device_is_orphan(struct ccw_device *);
83 85
84int ccw_device_recognition(struct ccw_device *); 86int ccw_device_recognition(struct ccw_device *);
85int ccw_device_online(struct ccw_device *); 87int ccw_device_online(struct ccw_device *);
diff --git a/drivers/s390/cio/device_fsm.c b/drivers/s390/cio/device_fsm.c
index 09c7672eb3f3..eed14572fc3b 100644
--- a/drivers/s390/cio/device_fsm.c
+++ b/drivers/s390/cio/device_fsm.c
@@ -186,15 +186,14 @@ ccw_device_handle_oper(struct ccw_device *cdev)
186 /* 186 /*
187 * Check if cu type and device type still match. If 187 * Check if cu type and device type still match. If
188 * not, it is certainly another device and we have to 188 * not, it is certainly another device and we have to
189 * de- and re-register. Also check here for non-matching devno. 189 * de- and re-register.
190 */ 190 */
191 if (cdev->id.cu_type != cdev->private->senseid.cu_type || 191 if (cdev->id.cu_type != cdev->private->senseid.cu_type ||
192 cdev->id.cu_model != cdev->private->senseid.cu_model || 192 cdev->id.cu_model != cdev->private->senseid.cu_model ||
193 cdev->id.dev_type != cdev->private->senseid.dev_type || 193 cdev->id.dev_type != cdev->private->senseid.dev_type ||
194 cdev->id.dev_model != cdev->private->senseid.dev_model || 194 cdev->id.dev_model != cdev->private->senseid.dev_model) {
195 cdev->private->dev_id.devno != sch->schib.pmcw.dev) {
196 PREPARE_WORK(&cdev->private->kick_work, 195 PREPARE_WORK(&cdev->private->kick_work,
197 ccw_device_do_unreg_rereg, cdev); 196 ccw_device_do_unreg_rereg);
198 queue_work(ccw_device_work, &cdev->private->kick_work); 197 queue_work(ccw_device_work, &cdev->private->kick_work);
199 return 0; 198 return 0;
200 } 199 }
@@ -329,19 +328,21 @@ ccw_device_sense_id_done(struct ccw_device *cdev, int err)
329} 328}
330 329
331static void 330static void
332ccw_device_oper_notify(void *data) 331ccw_device_oper_notify(struct work_struct *work)
333{ 332{
333 struct ccw_device_private *priv;
334 struct ccw_device *cdev; 334 struct ccw_device *cdev;
335 struct subchannel *sch; 335 struct subchannel *sch;
336 int ret; 336 int ret;
337 337
338 cdev = data; 338 priv = container_of(work, struct ccw_device_private, kick_work);
339 cdev = priv->cdev;
339 sch = to_subchannel(cdev->dev.parent); 340 sch = to_subchannel(cdev->dev.parent);
340 ret = (sch->driver && sch->driver->notify) ? 341 ret = (sch->driver && sch->driver->notify) ?
341 sch->driver->notify(&sch->dev, CIO_OPER) : 0; 342 sch->driver->notify(&sch->dev, CIO_OPER) : 0;
342 if (!ret) 343 if (!ret)
343 /* Driver doesn't want device back. */ 344 /* Driver doesn't want device back. */
344 ccw_device_do_unreg_rereg(cdev); 345 ccw_device_do_unreg_rereg(work);
345 else { 346 else {
346 /* Reenable channel measurements, if needed. */ 347 /* Reenable channel measurements, if needed. */
347 cmf_reenable(cdev); 348 cmf_reenable(cdev);
@@ -377,8 +378,7 @@ ccw_device_done(struct ccw_device *cdev, int state)
377 378
378 if (cdev->private->flags.donotify) { 379 if (cdev->private->flags.donotify) {
379 cdev->private->flags.donotify = 0; 380 cdev->private->flags.donotify = 0;
380 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify, 381 PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify);
381 cdev);
382 queue_work(ccw_device_notify_work, &cdev->private->kick_work); 382 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
383 } 383 }
384 wake_up(&cdev->private->wait_q); 384 wake_up(&cdev->private->wait_q);
@@ -528,13 +528,15 @@ ccw_device_recog_timeout(struct ccw_device *cdev, enum dev_event dev_event)
528 528
529 529
530static void 530static void
531ccw_device_nopath_notify(void *data) 531ccw_device_nopath_notify(struct work_struct *work)
532{ 532{
533 struct ccw_device_private *priv;
533 struct ccw_device *cdev; 534 struct ccw_device *cdev;
534 struct subchannel *sch; 535 struct subchannel *sch;
535 int ret; 536 int ret;
536 537
537 cdev = data; 538 priv = container_of(work, struct ccw_device_private, kick_work);
539 cdev = priv->cdev;
538 sch = to_subchannel(cdev->dev.parent); 540 sch = to_subchannel(cdev->dev.parent);
539 /* Extra sanity. */ 541 /* Extra sanity. */
540 if (sch->lpm) 542 if (sch->lpm)
@@ -547,8 +549,7 @@ ccw_device_nopath_notify(void *data)
547 cio_disable_subchannel(sch); 549 cio_disable_subchannel(sch);
548 if (get_device(&cdev->dev)) { 550 if (get_device(&cdev->dev)) {
549 PREPARE_WORK(&cdev->private->kick_work, 551 PREPARE_WORK(&cdev->private->kick_work,
550 ccw_device_call_sch_unregister, 552 ccw_device_call_sch_unregister);
551 cdev);
552 queue_work(ccw_device_work, 553 queue_work(ccw_device_work,
553 &cdev->private->kick_work); 554 &cdev->private->kick_work);
554 } else 555 } else
@@ -607,7 +608,7 @@ ccw_device_verify_done(struct ccw_device *cdev, int err)
607 /* Reset oper notify indication after verify error. */ 608 /* Reset oper notify indication after verify error. */
608 cdev->private->flags.donotify = 0; 609 cdev->private->flags.donotify = 0;
609 PREPARE_WORK(&cdev->private->kick_work, 610 PREPARE_WORK(&cdev->private->kick_work,
610 ccw_device_nopath_notify, cdev); 611 ccw_device_nopath_notify);
611 queue_work(ccw_device_notify_work, &cdev->private->kick_work); 612 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
612 ccw_device_done(cdev, DEV_STATE_NOT_OPER); 613 ccw_device_done(cdev, DEV_STATE_NOT_OPER);
613 break; 614 break;
@@ -674,6 +675,10 @@ ccw_device_offline(struct ccw_device *cdev)
674{ 675{
675 struct subchannel *sch; 676 struct subchannel *sch;
676 677
678 if (ccw_device_is_orphan(cdev)) {
679 ccw_device_done(cdev, DEV_STATE_OFFLINE);
680 return 0;
681 }
677 sch = to_subchannel(cdev->dev.parent); 682 sch = to_subchannel(cdev->dev.parent);
678 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv) 683 if (stsch(sch->schid, &sch->schib) || !sch->schib.pmcw.dnv)
679 return -ENODEV; 684 return -ENODEV;
@@ -738,7 +743,7 @@ ccw_device_offline_notoper(struct ccw_device *cdev, enum dev_event dev_event)
738 sch = to_subchannel(cdev->dev.parent); 743 sch = to_subchannel(cdev->dev.parent);
739 if (get_device(&cdev->dev)) { 744 if (get_device(&cdev->dev)) {
740 PREPARE_WORK(&cdev->private->kick_work, 745 PREPARE_WORK(&cdev->private->kick_work,
741 ccw_device_call_sch_unregister, cdev); 746 ccw_device_call_sch_unregister);
742 queue_work(ccw_device_work, &cdev->private->kick_work); 747 queue_work(ccw_device_work, &cdev->private->kick_work);
743 } 748 }
744 wake_up(&cdev->private->wait_q); 749 wake_up(&cdev->private->wait_q);
@@ -769,7 +774,7 @@ ccw_device_online_notoper(struct ccw_device *cdev, enum dev_event dev_event)
769 } 774 }
770 if (get_device(&cdev->dev)) { 775 if (get_device(&cdev->dev)) {
771 PREPARE_WORK(&cdev->private->kick_work, 776 PREPARE_WORK(&cdev->private->kick_work,
772 ccw_device_call_sch_unregister, cdev); 777 ccw_device_call_sch_unregister);
773 queue_work(ccw_device_work, &cdev->private->kick_work); 778 queue_work(ccw_device_work, &cdev->private->kick_work);
774 } 779 }
775 wake_up(&cdev->private->wait_q); 780 wake_up(&cdev->private->wait_q);
@@ -874,7 +879,7 @@ ccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
874 sch = to_subchannel(cdev->dev.parent); 879 sch = to_subchannel(cdev->dev.parent);
875 if (!sch->lpm) { 880 if (!sch->lpm) {
876 PREPARE_WORK(&cdev->private->kick_work, 881 PREPARE_WORK(&cdev->private->kick_work,
877 ccw_device_nopath_notify, cdev); 882 ccw_device_nopath_notify);
878 queue_work(ccw_device_notify_work, 883 queue_work(ccw_device_notify_work,
879 &cdev->private->kick_work); 884 &cdev->private->kick_work);
880 } else 885 } else
@@ -969,7 +974,7 @@ ccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
969 ERR_PTR(-EIO)); 974 ERR_PTR(-EIO));
970 if (!sch->lpm) { 975 if (!sch->lpm) {
971 PREPARE_WORK(&cdev->private->kick_work, 976 PREPARE_WORK(&cdev->private->kick_work,
972 ccw_device_nopath_notify, cdev); 977 ccw_device_nopath_notify);
973 queue_work(ccw_device_notify_work, &cdev->private->kick_work); 978 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
974 } else if (cdev->private->flags.doverify) 979 } else if (cdev->private->flags.doverify)
975 /* Start delayed path verification. */ 980 /* Start delayed path verification. */
@@ -992,7 +997,7 @@ ccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
992 sch = to_subchannel(cdev->dev.parent); 997 sch = to_subchannel(cdev->dev.parent);
993 if (!sch->lpm) { 998 if (!sch->lpm) {
994 PREPARE_WORK(&cdev->private->kick_work, 999 PREPARE_WORK(&cdev->private->kick_work,
995 ccw_device_nopath_notify, cdev); 1000 ccw_device_nopath_notify);
996 queue_work(ccw_device_notify_work, 1001 queue_work(ccw_device_notify_work,
997 &cdev->private->kick_work); 1002 &cdev->private->kick_work);
998 } else 1003 } else
@@ -1021,7 +1026,7 @@ void device_kill_io(struct subchannel *sch)
1021 if (ret == -ENODEV) { 1026 if (ret == -ENODEV) {
1022 if (!sch->lpm) { 1027 if (!sch->lpm) {
1023 PREPARE_WORK(&cdev->private->kick_work, 1028 PREPARE_WORK(&cdev->private->kick_work,
1024 ccw_device_nopath_notify, cdev); 1029 ccw_device_nopath_notify);
1025 queue_work(ccw_device_notify_work, 1030 queue_work(ccw_device_notify_work,
1026 &cdev->private->kick_work); 1031 &cdev->private->kick_work);
1027 } else 1032 } else
@@ -1033,7 +1038,7 @@ void device_kill_io(struct subchannel *sch)
1033 ERR_PTR(-EIO)); 1038 ERR_PTR(-EIO));
1034 if (!sch->lpm) { 1039 if (!sch->lpm) {
1035 PREPARE_WORK(&cdev->private->kick_work, 1040 PREPARE_WORK(&cdev->private->kick_work,
1036 ccw_device_nopath_notify, cdev); 1041 ccw_device_nopath_notify);
1037 queue_work(ccw_device_notify_work, &cdev->private->kick_work); 1042 queue_work(ccw_device_notify_work, &cdev->private->kick_work);
1038 } else 1043 } else
1039 /* Start delayed path verification. */ 1044 /* Start delayed path verification. */
@@ -1104,7 +1109,8 @@ device_trigger_reprobe(struct subchannel *sch)
1104 /* Update some values. */ 1109 /* Update some values. */
1105 if (stsch(sch->schid, &sch->schib)) 1110 if (stsch(sch->schid, &sch->schib))
1106 return; 1111 return;
1107 1112 if (!sch->schib.pmcw.dnv)
1113 return;
1108 /* 1114 /*
1109 * The pim, pam, pom values may not be accurate, but they are the best 1115 * The pim, pam, pom values may not be accurate, but they are the best
1110 * we have before performing device selection :/ 1116 * we have before performing device selection :/
@@ -1118,7 +1124,13 @@ device_trigger_reprobe(struct subchannel *sch)
1118 sch->schib.pmcw.mp = 1; 1124 sch->schib.pmcw.mp = 1;
1119 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch; 1125 sch->schib.pmcw.intparm = (__u32)(unsigned long)sch;
1120 /* We should also udate ssd info, but this has to wait. */ 1126 /* We should also udate ssd info, but this has to wait. */
1121 ccw_device_start_id(cdev, 0); 1127 /* Check if this is another device which appeared on the same sch. */
1128 if (sch->schib.pmcw.dev != cdev->private->dev_id.devno) {
1129 PREPARE_WORK(&cdev->private->kick_work,
1130 ccw_device_move_to_orphanage);
1131 queue_work(ccw_device_work, &cdev->private->kick_work);
1132 } else
1133 ccw_device_start_id(cdev, 0);
1122} 1134}
1123 1135
1124static void 1136static void
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index b39c1fa48acd..d269607336ec 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -316,9 +316,9 @@ __ccw_device_retry_loop(struct ccw_device *cdev, struct ccw1 *ccw, long magic, _
316 ccw_device_set_timeout(cdev, 0); 316 ccw_device_set_timeout(cdev, 0);
317 if (ret == -EBUSY) { 317 if (ret == -EBUSY) {
318 /* Try again later. */ 318 /* Try again later. */
319 spin_unlock_irq(&sch->lock); 319 spin_unlock_irq(sch->lock);
320 msleep(10); 320 msleep(10);
321 spin_lock_irq(&sch->lock); 321 spin_lock_irq(sch->lock);
322 continue; 322 continue;
323 } 323 }
324 if (ret != 0) 324 if (ret != 0)
@@ -326,12 +326,12 @@ __ccw_device_retry_loop(struct ccw_device *cdev, struct ccw1 *ccw, long magic, _
326 break; 326 break;
327 /* Wait for end of request. */ 327 /* Wait for end of request. */
328 cdev->private->intparm = magic; 328 cdev->private->intparm = magic;
329 spin_unlock_irq(&sch->lock); 329 spin_unlock_irq(sch->lock);
330 wait_event(cdev->private->wait_q, 330 wait_event(cdev->private->wait_q,
331 (cdev->private->intparm == -EIO) || 331 (cdev->private->intparm == -EIO) ||
332 (cdev->private->intparm == -EAGAIN) || 332 (cdev->private->intparm == -EAGAIN) ||
333 (cdev->private->intparm == 0)); 333 (cdev->private->intparm == 0));
334 spin_lock_irq(&sch->lock); 334 spin_lock_irq(sch->lock);
335 /* Check at least for channel end / device end */ 335 /* Check at least for channel end / device end */
336 if (cdev->private->intparm == -EIO) { 336 if (cdev->private->intparm == -EIO) {
337 /* Non-retryable error. */ 337 /* Non-retryable error. */
@@ -342,9 +342,9 @@ __ccw_device_retry_loop(struct ccw_device *cdev, struct ccw1 *ccw, long magic, _
342 /* Success. */ 342 /* Success. */
343 break; 343 break;
344 /* Try again later. */ 344 /* Try again later. */
345 spin_unlock_irq(&sch->lock); 345 spin_unlock_irq(sch->lock);
346 msleep(10); 346 msleep(10);
347 spin_lock_irq(&sch->lock); 347 spin_lock_irq(sch->lock);
348 } while (1); 348 } while (1);
349 349
350 return ret; 350 return ret;
@@ -389,7 +389,7 @@ read_dev_chars (struct ccw_device *cdev, void **buffer, int length)
389 return ret; 389 return ret;
390 } 390 }
391 391
392 spin_lock_irq(&sch->lock); 392 spin_lock_irq(sch->lock);
393 /* Save interrupt handler. */ 393 /* Save interrupt handler. */
394 handler = cdev->handler; 394 handler = cdev->handler;
395 /* Temporarily install own handler. */ 395 /* Temporarily install own handler. */
@@ -406,7 +406,7 @@ read_dev_chars (struct ccw_device *cdev, void **buffer, int length)
406 406
407 /* Restore interrupt handler. */ 407 /* Restore interrupt handler. */
408 cdev->handler = handler; 408 cdev->handler = handler;
409 spin_unlock_irq(&sch->lock); 409 spin_unlock_irq(sch->lock);
410 410
411 clear_normalized_cda (rdc_ccw); 411 clear_normalized_cda (rdc_ccw);
412 kfree(rdc_ccw); 412 kfree(rdc_ccw);
@@ -463,7 +463,7 @@ read_conf_data_lpm (struct ccw_device *cdev, void **buffer, int *length, __u8 lp
463 rcd_ccw->count = ciw->count; 463 rcd_ccw->count = ciw->count;
464 rcd_ccw->flags = CCW_FLAG_SLI; 464 rcd_ccw->flags = CCW_FLAG_SLI;
465 465
466 spin_lock_irq(&sch->lock); 466 spin_lock_irq(sch->lock);
467 /* Save interrupt handler. */ 467 /* Save interrupt handler. */
468 handler = cdev->handler; 468 handler = cdev->handler;
469 /* Temporarily install own handler. */ 469 /* Temporarily install own handler. */
@@ -480,7 +480,7 @@ read_conf_data_lpm (struct ccw_device *cdev, void **buffer, int *length, __u8 lp
480 480
481 /* Restore interrupt handler. */ 481 /* Restore interrupt handler. */
482 cdev->handler = handler; 482 cdev->handler = handler;
483 spin_unlock_irq(&sch->lock); 483 spin_unlock_irq(sch->lock);
484 484
485 /* 485 /*
486 * on success we update the user input parms 486 * on success we update the user input parms
@@ -537,7 +537,7 @@ ccw_device_stlck(struct ccw_device *cdev)
537 kfree(buf); 537 kfree(buf);
538 return -ENOMEM; 538 return -ENOMEM;
539 } 539 }
540 spin_lock_irqsave(&sch->lock, flags); 540 spin_lock_irqsave(sch->lock, flags);
541 ret = cio_enable_subchannel(sch, 3); 541 ret = cio_enable_subchannel(sch, 3);
542 if (ret) 542 if (ret)
543 goto out_unlock; 543 goto out_unlock;
@@ -559,9 +559,9 @@ ccw_device_stlck(struct ccw_device *cdev)
559 goto out_unlock; 559 goto out_unlock;
560 } 560 }
561 cdev->private->irb.scsw.actl |= SCSW_ACTL_START_PEND; 561 cdev->private->irb.scsw.actl |= SCSW_ACTL_START_PEND;
562 spin_unlock_irqrestore(&sch->lock, flags); 562 spin_unlock_irqrestore(sch->lock, flags);
563 wait_event(cdev->private->wait_q, cdev->private->irb.scsw.actl == 0); 563 wait_event(cdev->private->wait_q, cdev->private->irb.scsw.actl == 0);
564 spin_lock_irqsave(&sch->lock, flags); 564 spin_lock_irqsave(sch->lock, flags);
565 cio_disable_subchannel(sch); //FIXME: return code? 565 cio_disable_subchannel(sch); //FIXME: return code?
566 if ((cdev->private->irb.scsw.dstat != 566 if ((cdev->private->irb.scsw.dstat !=
567 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) || 567 (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||
@@ -572,7 +572,7 @@ ccw_device_stlck(struct ccw_device *cdev)
572out_unlock: 572out_unlock:
573 kfree(buf); 573 kfree(buf);
574 kfree(buf2); 574 kfree(buf2);
575 spin_unlock_irqrestore(&sch->lock, flags); 575 spin_unlock_irqrestore(sch->lock, flags);
576 return ret; 576 return ret;
577} 577}
578 578
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index 8d5fa1b4d11f..9d4ea449a608 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -46,6 +46,7 @@
46#include <asm/timex.h> 46#include <asm/timex.h>
47 47
48#include <asm/debug.h> 48#include <asm/debug.h>
49#include <asm/s390_rdev.h>
49#include <asm/qdio.h> 50#include <asm/qdio.h>
50 51
51#include "cio.h" 52#include "cio.h"
@@ -65,12 +66,12 @@ MODULE_LICENSE("GPL");
65/******************** HERE WE GO ***********************************/ 66/******************** HERE WE GO ***********************************/
66 67
67static const char version[] = "QDIO base support version 2"; 68static const char version[] = "QDIO base support version 2";
69extern struct bus_type ccw_bus_type;
68 70
69#ifdef QDIO_PERFORMANCE_STATS 71static int qdio_performance_stats = 0;
70static int proc_perf_file_registration; 72static int proc_perf_file_registration;
71static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc; 73static unsigned long i_p_c, i_p_nc, o_p_c, o_p_nc, ii_p_c, ii_p_nc;
72static struct qdio_perf_stats perf_stats; 74static struct qdio_perf_stats perf_stats;
73#endif /* QDIO_PERFORMANCE_STATS */
74 75
75static int hydra_thinints; 76static int hydra_thinints;
76static int is_passthrough = 0; 77static int is_passthrough = 0;
@@ -275,9 +276,8 @@ qdio_siga_sync(struct qdio_q *q, unsigned int gpr2,
275 QDIO_DBF_TEXT4(0,trace,"sigasync"); 276 QDIO_DBF_TEXT4(0,trace,"sigasync");
276 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 277 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
277 278
278#ifdef QDIO_PERFORMANCE_STATS 279 if (qdio_performance_stats)
279 perf_stats.siga_syncs++; 280 perf_stats.siga_syncs++;
280#endif /* QDIO_PERFORMANCE_STATS */
281 281
282 cc = do_siga_sync(q->schid, gpr2, gpr3); 282 cc = do_siga_sync(q->schid, gpr2, gpr3);
283 if (cc) 283 if (cc)
@@ -322,9 +322,8 @@ qdio_siga_output(struct qdio_q *q)
322 __u32 busy_bit; 322 __u32 busy_bit;
323 __u64 start_time=0; 323 __u64 start_time=0;
324 324
325#ifdef QDIO_PERFORMANCE_STATS 325 if (qdio_performance_stats)
326 perf_stats.siga_outs++; 326 perf_stats.siga_outs++;
327#endif /* QDIO_PERFORMANCE_STATS */
328 327
329 QDIO_DBF_TEXT4(0,trace,"sigaout"); 328 QDIO_DBF_TEXT4(0,trace,"sigaout");
330 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 329 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
@@ -358,9 +357,8 @@ qdio_siga_input(struct qdio_q *q)
358 QDIO_DBF_TEXT4(0,trace,"sigain"); 357 QDIO_DBF_TEXT4(0,trace,"sigain");
359 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*)); 358 QDIO_DBF_HEX4(0,trace,&q,sizeof(void*));
360 359
361#ifdef QDIO_PERFORMANCE_STATS 360 if (qdio_performance_stats)
362 perf_stats.siga_ins++; 361 perf_stats.siga_ins++;
363#endif /* QDIO_PERFORMANCE_STATS */
364 362
365 cc = do_siga_input(q->schid, q->mask); 363 cc = do_siga_input(q->schid, q->mask);
366 364
@@ -954,9 +952,8 @@ __qdio_outbound_processing(struct qdio_q *q)
954 952
955 if (unlikely(qdio_reserve_q(q))) { 953 if (unlikely(qdio_reserve_q(q))) {
956 qdio_release_q(q); 954 qdio_release_q(q);
957#ifdef QDIO_PERFORMANCE_STATS 955 if (qdio_performance_stats)
958 o_p_c++; 956 o_p_c++;
959#endif /* QDIO_PERFORMANCE_STATS */
960 /* as we're sissies, we'll check next time */ 957 /* as we're sissies, we'll check next time */
961 if (likely(!atomic_read(&q->is_in_shutdown))) { 958 if (likely(!atomic_read(&q->is_in_shutdown))) {
962 qdio_mark_q(q); 959 qdio_mark_q(q);
@@ -964,10 +961,10 @@ __qdio_outbound_processing(struct qdio_q *q)
964 } 961 }
965 return; 962 return;
966 } 963 }
967#ifdef QDIO_PERFORMANCE_STATS 964 if (qdio_performance_stats) {
968 o_p_nc++; 965 o_p_nc++;
969 perf_stats.tl_runs++; 966 perf_stats.tl_runs++;
970#endif /* QDIO_PERFORMANCE_STATS */ 967 }
971 968
972 /* see comment in qdio_kick_outbound_q */ 969 /* see comment in qdio_kick_outbound_q */
973 siga_attempts=atomic_read(&q->busy_siga_counter); 970 siga_attempts=atomic_read(&q->busy_siga_counter);
@@ -1142,15 +1139,16 @@ qdio_has_inbound_q_moved(struct qdio_q *q)
1142{ 1139{
1143 int i; 1140 int i;
1144 1141
1145#ifdef QDIO_PERFORMANCE_STATS
1146 static int old_pcis=0; 1142 static int old_pcis=0;
1147 static int old_thinints=0; 1143 static int old_thinints=0;
1148 1144
1149 if ((old_pcis==perf_stats.pcis)&&(old_thinints==perf_stats.thinints)) 1145 if (qdio_performance_stats) {
1150 perf_stats.start_time_inbound=NOW; 1146 if ((old_pcis==perf_stats.pcis)&&
1151 else 1147 (old_thinints==perf_stats.thinints))
1152 old_pcis=perf_stats.pcis; 1148 perf_stats.start_time_inbound=NOW;
1153#endif /* QDIO_PERFORMANCE_STATS */ 1149 else
1150 old_pcis=perf_stats.pcis;
1151 }
1154 1152
1155 i=qdio_get_inbound_buffer_frontier(q); 1153 i=qdio_get_inbound_buffer_frontier(q);
1156 if ( (i!=GET_SAVED_FRONTIER(q)) || 1154 if ( (i!=GET_SAVED_FRONTIER(q)) ||
@@ -1340,10 +1338,10 @@ qdio_kick_inbound_handler(struct qdio_q *q)
1340 q->siga_error=0; 1338 q->siga_error=0;
1341 q->error_status_flags=0; 1339 q->error_status_flags=0;
1342 1340
1343#ifdef QDIO_PERFORMANCE_STATS 1341 if (qdio_performance_stats) {
1344 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound; 1342 perf_stats.inbound_time+=NOW-perf_stats.start_time_inbound;
1345 perf_stats.inbound_cnt++; 1343 perf_stats.inbound_cnt++;
1346#endif /* QDIO_PERFORMANCE_STATS */ 1344 }
1347} 1345}
1348 1346
1349static inline void 1347static inline void
@@ -1363,9 +1361,8 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1363 */ 1361 */
1364 if (unlikely(qdio_reserve_q(q))) { 1362 if (unlikely(qdio_reserve_q(q))) {
1365 qdio_release_q(q); 1363 qdio_release_q(q);
1366#ifdef QDIO_PERFORMANCE_STATS 1364 if (qdio_performance_stats)
1367 ii_p_c++; 1365 ii_p_c++;
1368#endif /* QDIO_PERFORMANCE_STATS */
1369 /* 1366 /*
1370 * as we might just be about to stop polling, we make 1367 * as we might just be about to stop polling, we make
1371 * sure that we check again at least once more 1368 * sure that we check again at least once more
@@ -1373,9 +1370,8 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1373 tiqdio_sched_tl(); 1370 tiqdio_sched_tl();
1374 return; 1371 return;
1375 } 1372 }
1376#ifdef QDIO_PERFORMANCE_STATS 1373 if (qdio_performance_stats)
1377 ii_p_nc++; 1374 ii_p_nc++;
1378#endif /* QDIO_PERFORMANCE_STATS */
1379 if (unlikely(atomic_read(&q->is_in_shutdown))) { 1375 if (unlikely(atomic_read(&q->is_in_shutdown))) {
1380 qdio_unmark_q(q); 1376 qdio_unmark_q(q);
1381 goto out; 1377 goto out;
@@ -1416,11 +1412,11 @@ __tiqdio_inbound_processing(struct qdio_q *q, int spare_ind_was_set)
1416 irq_ptr = (struct qdio_irq*)q->irq_ptr; 1412 irq_ptr = (struct qdio_irq*)q->irq_ptr;
1417 for (i=0;i<irq_ptr->no_output_qs;i++) { 1413 for (i=0;i<irq_ptr->no_output_qs;i++) {
1418 oq = irq_ptr->output_qs[i]; 1414 oq = irq_ptr->output_qs[i];
1419#ifdef QDIO_PERFORMANCE_STATS 1415 if (!qdio_is_outbound_q_done(oq)) {
1420 perf_stats.tl_runs--; 1416 if (qdio_performance_stats)
1421#endif /* QDIO_PERFORMANCE_STATS */ 1417 perf_stats.tl_runs--;
1422 if (!qdio_is_outbound_q_done(oq))
1423 __qdio_outbound_processing(oq); 1418 __qdio_outbound_processing(oq);
1419 }
1424 } 1420 }
1425 } 1421 }
1426 1422
@@ -1457,9 +1453,8 @@ __qdio_inbound_processing(struct qdio_q *q)
1457 1453
1458 if (unlikely(qdio_reserve_q(q))) { 1454 if (unlikely(qdio_reserve_q(q))) {
1459 qdio_release_q(q); 1455 qdio_release_q(q);
1460#ifdef QDIO_PERFORMANCE_STATS 1456 if (qdio_performance_stats)
1461 i_p_c++; 1457 i_p_c++;
1462#endif /* QDIO_PERFORMANCE_STATS */
1463 /* as we're sissies, we'll check next time */ 1458 /* as we're sissies, we'll check next time */
1464 if (likely(!atomic_read(&q->is_in_shutdown))) { 1459 if (likely(!atomic_read(&q->is_in_shutdown))) {
1465 qdio_mark_q(q); 1460 qdio_mark_q(q);
@@ -1467,10 +1462,10 @@ __qdio_inbound_processing(struct qdio_q *q)
1467 } 1462 }
1468 return; 1463 return;
1469 } 1464 }
1470#ifdef QDIO_PERFORMANCE_STATS 1465 if (qdio_performance_stats) {
1471 i_p_nc++; 1466 i_p_nc++;
1472 perf_stats.tl_runs++; 1467 perf_stats.tl_runs++;
1473#endif /* QDIO_PERFORMANCE_STATS */ 1468 }
1474 1469
1475again: 1470again:
1476 if (qdio_has_inbound_q_moved(q)) { 1471 if (qdio_has_inbound_q_moved(q)) {
@@ -1516,9 +1511,8 @@ tiqdio_reset_processing_state(struct qdio_q *q, int q_laps)
1516 1511
1517 if (unlikely(qdio_reserve_q(q))) { 1512 if (unlikely(qdio_reserve_q(q))) {
1518 qdio_release_q(q); 1513 qdio_release_q(q);
1519#ifdef QDIO_PERFORMANCE_STATS 1514 if (qdio_performance_stats)
1520 ii_p_c++; 1515 ii_p_c++;
1521#endif /* QDIO_PERFORMANCE_STATS */
1522 /* 1516 /*
1523 * as we might just be about to stop polling, we make 1517 * as we might just be about to stop polling, we make
1524 * sure that we check again at least once more 1518 * sure that we check again at least once more
@@ -1609,9 +1603,8 @@ tiqdio_tl(unsigned long data)
1609{ 1603{
1610 QDIO_DBF_TEXT4(0,trace,"iqdio_tl"); 1604 QDIO_DBF_TEXT4(0,trace,"iqdio_tl");
1611 1605
1612#ifdef QDIO_PERFORMANCE_STATS 1606 if (qdio_performance_stats)
1613 perf_stats.tl_runs++; 1607 perf_stats.tl_runs++;
1614#endif /* QDIO_PERFORMANCE_STATS */
1615 1608
1616 tiqdio_inbound_checks(); 1609 tiqdio_inbound_checks();
1617} 1610}
@@ -1918,10 +1911,10 @@ tiqdio_thinint_handler(void)
1918{ 1911{
1919 QDIO_DBF_TEXT4(0,trace,"thin_int"); 1912 QDIO_DBF_TEXT4(0,trace,"thin_int");
1920 1913
1921#ifdef QDIO_PERFORMANCE_STATS 1914 if (qdio_performance_stats) {
1922 perf_stats.thinints++; 1915 perf_stats.thinints++;
1923 perf_stats.start_time_inbound=NOW; 1916 perf_stats.start_time_inbound=NOW;
1924#endif /* QDIO_PERFORMANCE_STATS */ 1917 }
1925 1918
1926 /* SVS only when needed: 1919 /* SVS only when needed:
1927 * issue SVS to benefit from iqdio interrupt avoidance 1920 * issue SVS to benefit from iqdio interrupt avoidance
@@ -1976,18 +1969,17 @@ qdio_handle_pci(struct qdio_irq *irq_ptr)
1976 int i; 1969 int i;
1977 struct qdio_q *q; 1970 struct qdio_q *q;
1978 1971
1979#ifdef QDIO_PERFORMANCE_STATS 1972 if (qdio_performance_stats) {
1980 perf_stats.pcis++; 1973 perf_stats.pcis++;
1981 perf_stats.start_time_inbound=NOW; 1974 perf_stats.start_time_inbound=NOW;
1982#endif /* QDIO_PERFORMANCE_STATS */ 1975 }
1983 for (i=0;i<irq_ptr->no_input_qs;i++) { 1976 for (i=0;i<irq_ptr->no_input_qs;i++) {
1984 q=irq_ptr->input_qs[i]; 1977 q=irq_ptr->input_qs[i];
1985 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) 1978 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1986 qdio_mark_q(q); 1979 qdio_mark_q(q);
1987 else { 1980 else {
1988#ifdef QDIO_PERFORMANCE_STATS 1981 if (qdio_performance_stats)
1989 perf_stats.tl_runs--; 1982 perf_stats.tl_runs--;
1990#endif /* QDIO_PERFORMANCE_STATS */
1991 __qdio_inbound_processing(q); 1983 __qdio_inbound_processing(q);
1992 } 1984 }
1993 } 1985 }
@@ -1995,11 +1987,10 @@ qdio_handle_pci(struct qdio_irq *irq_ptr)
1995 return; 1987 return;
1996 for (i=0;i<irq_ptr->no_output_qs;i++) { 1988 for (i=0;i<irq_ptr->no_output_qs;i++) {
1997 q=irq_ptr->output_qs[i]; 1989 q=irq_ptr->output_qs[i];
1998#ifdef QDIO_PERFORMANCE_STATS
1999 perf_stats.tl_runs--;
2000#endif /* QDIO_PERFORMANCE_STATS */
2001 if (qdio_is_outbound_q_done(q)) 1990 if (qdio_is_outbound_q_done(q))
2002 continue; 1991 continue;
1992 if (qdio_performance_stats)
1993 perf_stats.tl_runs--;
2003 if (!irq_ptr->sync_done_on_outb_pcis) 1994 if (!irq_ptr->sync_done_on_outb_pcis)
2004 SYNC_MEMORY; 1995 SYNC_MEMORY;
2005 __qdio_outbound_processing(q); 1996 __qdio_outbound_processing(q);
@@ -2045,11 +2036,13 @@ omit_handler_call:
2045} 2036}
2046 2037
2047static void 2038static void
2048qdio_call_shutdown(void *data) 2039qdio_call_shutdown(struct work_struct *work)
2049{ 2040{
2041 struct ccw_device_private *priv;
2050 struct ccw_device *cdev; 2042 struct ccw_device *cdev;
2051 2043
2052 cdev = (struct ccw_device *)data; 2044 priv = container_of(work, struct ccw_device_private, kick_work);
2045 cdev = priv->cdev;
2053 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR); 2046 qdio_shutdown(cdev, QDIO_FLAG_CLEANUP_USING_CLEAR);
2054 put_device(&cdev->dev); 2047 put_device(&cdev->dev);
2055} 2048}
@@ -2091,7 +2084,7 @@ qdio_timeout_handler(struct ccw_device *cdev)
2091 if (get_device(&cdev->dev)) { 2084 if (get_device(&cdev->dev)) {
2092 /* Can't call shutdown from interrupt context. */ 2085 /* Can't call shutdown from interrupt context. */
2093 PREPARE_WORK(&cdev->private->kick_work, 2086 PREPARE_WORK(&cdev->private->kick_work,
2094 qdio_call_shutdown, (void *)cdev); 2087 qdio_call_shutdown);
2095 queue_work(ccw_device_work, &cdev->private->kick_work); 2088 queue_work(ccw_device_work, &cdev->private->kick_work);
2096 } 2089 }
2097 break; 2090 break;
@@ -3458,19 +3451,18 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3458 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr; 3451 struct qdio_irq *irq = (struct qdio_irq *) q->irq_ptr;
3459 3452
3460 /* This is the outbound handling of queues */ 3453 /* This is the outbound handling of queues */
3461#ifdef QDIO_PERFORMANCE_STATS 3454 if (qdio_performance_stats)
3462 perf_stats.start_time_outbound=NOW; 3455 perf_stats.start_time_outbound=NOW;
3463#endif /* QDIO_PERFORMANCE_STATS */
3464 3456
3465 qdio_do_qdio_fill_output(q,qidx,count,buffers); 3457 qdio_do_qdio_fill_output(q,qidx,count,buffers);
3466 3458
3467 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count; 3459 used_elements=atomic_add_return(count, &q->number_of_buffers_used) - count;
3468 3460
3469 if (callflags&QDIO_FLAG_DONT_SIGA) { 3461 if (callflags&QDIO_FLAG_DONT_SIGA) {
3470#ifdef QDIO_PERFORMANCE_STATS 3462 if (qdio_performance_stats) {
3471 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound; 3463 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3472 perf_stats.outbound_cnt++; 3464 perf_stats.outbound_cnt++;
3473#endif /* QDIO_PERFORMANCE_STATS */ 3465 }
3474 return; 3466 return;
3475 } 3467 }
3476 if (q->is_iqdio_q) { 3468 if (q->is_iqdio_q) {
@@ -3500,9 +3492,8 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3500 qdio_kick_outbound_q(q); 3492 qdio_kick_outbound_q(q);
3501 } else { 3493 } else {
3502 QDIO_DBF_TEXT3(0,trace, "fast-req"); 3494 QDIO_DBF_TEXT3(0,trace, "fast-req");
3503#ifdef QDIO_PERFORMANCE_STATS 3495 if (qdio_performance_stats)
3504 perf_stats.fast_reqs++; 3496 perf_stats.fast_reqs++;
3505#endif /* QDIO_PERFORMANCE_STATS */
3506 } 3497 }
3507 } 3498 }
3508 /* 3499 /*
@@ -3513,10 +3504,10 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3513 __qdio_outbound_processing(q); 3504 __qdio_outbound_processing(q);
3514 } 3505 }
3515 3506
3516#ifdef QDIO_PERFORMANCE_STATS 3507 if (qdio_performance_stats) {
3517 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound; 3508 perf_stats.outbound_time+=NOW-perf_stats.start_time_outbound;
3518 perf_stats.outbound_cnt++; 3509 perf_stats.outbound_cnt++;
3519#endif /* QDIO_PERFORMANCE_STATS */ 3510 }
3520} 3511}
3521 3512
3522/* count must be 1 in iqdio */ 3513/* count must be 1 in iqdio */
@@ -3574,7 +3565,6 @@ do_QDIO(struct ccw_device *cdev,unsigned int callflags,
3574 return 0; 3565 return 0;
3575} 3566}
3576 3567
3577#ifdef QDIO_PERFORMANCE_STATS
3578static int 3568static int
3579qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset, 3569qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3580 int buffer_length, int *eof, void *data) 3570 int buffer_length, int *eof, void *data)
@@ -3590,29 +3580,29 @@ qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3590 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c); 3580 _OUTP_IT("i_p_nc/c=%lu/%lu\n",i_p_nc,i_p_c);
3591 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c); 3581 _OUTP_IT("ii_p_nc/c=%lu/%lu\n",ii_p_nc,ii_p_c);
3592 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c); 3582 _OUTP_IT("o_p_nc/c=%lu/%lu\n",o_p_nc,o_p_c);
3593 _OUTP_IT("Number of tasklet runs (total) : %u\n", 3583 _OUTP_IT("Number of tasklet runs (total) : %lu\n",
3594 perf_stats.tl_runs); 3584 perf_stats.tl_runs);
3595 _OUTP_IT("\n"); 3585 _OUTP_IT("\n");
3596 _OUTP_IT("Number of SIGA sync's issued : %u\n", 3586 _OUTP_IT("Number of SIGA sync's issued : %lu\n",
3597 perf_stats.siga_syncs); 3587 perf_stats.siga_syncs);
3598 _OUTP_IT("Number of SIGA in's issued : %u\n", 3588 _OUTP_IT("Number of SIGA in's issued : %lu\n",
3599 perf_stats.siga_ins); 3589 perf_stats.siga_ins);
3600 _OUTP_IT("Number of SIGA out's issued : %u\n", 3590 _OUTP_IT("Number of SIGA out's issued : %lu\n",
3601 perf_stats.siga_outs); 3591 perf_stats.siga_outs);
3602 _OUTP_IT("Number of PCIs caught : %u\n", 3592 _OUTP_IT("Number of PCIs caught : %lu\n",
3603 perf_stats.pcis); 3593 perf_stats.pcis);
3604 _OUTP_IT("Number of adapter interrupts caught : %u\n", 3594 _OUTP_IT("Number of adapter interrupts caught : %lu\n",
3605 perf_stats.thinints); 3595 perf_stats.thinints);
3606 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %u\n", 3596 _OUTP_IT("Number of fast requeues (outg. SBALs w/o SIGA) : %lu\n",
3607 perf_stats.fast_reqs); 3597 perf_stats.fast_reqs);
3608 _OUTP_IT("\n"); 3598 _OUTP_IT("\n");
3609 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %u\n", 3599 _OUTP_IT("Total time of all inbound actions (us) incl. UL : %lu\n",
3610 perf_stats.inbound_time); 3600 perf_stats.inbound_time);
3611 _OUTP_IT("Number of inbound transfers : %u\n", 3601 _OUTP_IT("Number of inbound transfers : %lu\n",
3612 perf_stats.inbound_cnt); 3602 perf_stats.inbound_cnt);
3613 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %u\n", 3603 _OUTP_IT("Total time of all outbound do_QDIOs (us) : %lu\n",
3614 perf_stats.outbound_time); 3604 perf_stats.outbound_time);
3615 _OUTP_IT("Number of do_QDIOs outbound : %u\n", 3605 _OUTP_IT("Number of do_QDIOs outbound : %lu\n",
3616 perf_stats.outbound_cnt); 3606 perf_stats.outbound_cnt);
3617 _OUTP_IT("\n"); 3607 _OUTP_IT("\n");
3618 3608
@@ -3620,12 +3610,10 @@ qdio_perf_procfile_read(char *buffer, char **buffer_location, off_t offset,
3620} 3610}
3621 3611
3622static struct proc_dir_entry *qdio_perf_proc_file; 3612static struct proc_dir_entry *qdio_perf_proc_file;
3623#endif /* QDIO_PERFORMANCE_STATS */
3624 3613
3625static void 3614static void
3626qdio_add_procfs_entry(void) 3615qdio_add_procfs_entry(void)
3627{ 3616{
3628#ifdef QDIO_PERFORMANCE_STATS
3629 proc_perf_file_registration=0; 3617 proc_perf_file_registration=0;
3630 qdio_perf_proc_file=create_proc_entry(QDIO_PERF, 3618 qdio_perf_proc_file=create_proc_entry(QDIO_PERF,
3631 S_IFREG|0444,&proc_root); 3619 S_IFREG|0444,&proc_root);
@@ -3637,20 +3625,58 @@ qdio_add_procfs_entry(void)
3637 QDIO_PRINT_WARN("was not able to register perf. " \ 3625 QDIO_PRINT_WARN("was not able to register perf. " \
3638 "proc-file (%i).\n", 3626 "proc-file (%i).\n",
3639 proc_perf_file_registration); 3627 proc_perf_file_registration);
3640#endif /* QDIO_PERFORMANCE_STATS */
3641} 3628}
3642 3629
3643static void 3630static void
3644qdio_remove_procfs_entry(void) 3631qdio_remove_procfs_entry(void)
3645{ 3632{
3646#ifdef QDIO_PERFORMANCE_STATS
3647 perf_stats.tl_runs=0; 3633 perf_stats.tl_runs=0;
3648 3634
3649 if (!proc_perf_file_registration) /* means if it went ok earlier */ 3635 if (!proc_perf_file_registration) /* means if it went ok earlier */
3650 remove_proc_entry(QDIO_PERF,&proc_root); 3636 remove_proc_entry(QDIO_PERF,&proc_root);
3651#endif /* QDIO_PERFORMANCE_STATS */
3652} 3637}
3653 3638
3639/**
3640 * attributes in sysfs
3641 *****************************************************************************/
3642
3643static ssize_t
3644qdio_performance_stats_show(struct bus_type *bus, char *buf)
3645{
3646 return sprintf(buf, "%i\n", qdio_performance_stats ? 1 : 0);
3647}
3648
3649static ssize_t
3650qdio_performance_stats_store(struct bus_type *bus, const char *buf, size_t count)
3651{
3652 char *tmp;
3653 int i;
3654
3655 i = simple_strtoul(buf, &tmp, 16);
3656 if ((i == 0) || (i == 1)) {
3657 if (i == qdio_performance_stats)
3658 return count;
3659 qdio_performance_stats = i;
3660 if (i==0) {
3661 /* reset perf. stat. info */
3662 i_p_nc = 0;
3663 i_p_c = 0;
3664 ii_p_nc = 0;
3665 ii_p_c = 0;
3666 o_p_nc = 0;
3667 o_p_c = 0;
3668 memset(&perf_stats, 0, sizeof(struct qdio_perf_stats));
3669 }
3670 } else {
3671 QDIO_PRINT_WARN("QDIO performance_stats: write 0 or 1 to this file!\n");
3672 return -EINVAL;
3673 }
3674 return count;
3675}
3676
3677static BUS_ATTR(qdio_performance_stats, 0644, qdio_performance_stats_show,
3678 qdio_performance_stats_store);
3679
3654static void 3680static void
3655tiqdio_register_thinints(void) 3681tiqdio_register_thinints(void)
3656{ 3682{
@@ -3695,6 +3721,7 @@ qdio_release_qdio_memory(void)
3695 kfree(indicators); 3721 kfree(indicators);
3696} 3722}
3697 3723
3724
3698static void 3725static void
3699qdio_unregister_dbf_views(void) 3726qdio_unregister_dbf_views(void)
3700{ 3727{
@@ -3796,9 +3823,7 @@ static int __init
3796init_QDIO(void) 3823init_QDIO(void)
3797{ 3824{
3798 int res; 3825 int res;
3799#ifdef QDIO_PERFORMANCE_STATS
3800 void *ptr; 3826 void *ptr;
3801#endif /* QDIO_PERFORMANCE_STATS */
3802 3827
3803 printk("qdio: loading %s\n",version); 3828 printk("qdio: loading %s\n",version);
3804 3829
@@ -3811,13 +3836,12 @@ init_QDIO(void)
3811 return res; 3836 return res;
3812 3837
3813 QDIO_DBF_TEXT0(0,setup,"initQDIO"); 3838 QDIO_DBF_TEXT0(0,setup,"initQDIO");
3839 res = bus_create_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3814 3840
3815#ifdef QDIO_PERFORMANCE_STATS 3841 memset((void*)&perf_stats,0,sizeof(perf_stats));
3816 memset((void*)&perf_stats,0,sizeof(perf_stats));
3817 QDIO_DBF_TEXT0(0,setup,"perfstat"); 3842 QDIO_DBF_TEXT0(0,setup,"perfstat");
3818 ptr=&perf_stats; 3843 ptr=&perf_stats;
3819 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*)); 3844 QDIO_DBF_HEX0(0,setup,&ptr,sizeof(void*));
3820#endif /* QDIO_PERFORMANCE_STATS */
3821 3845
3822 qdio_add_procfs_entry(); 3846 qdio_add_procfs_entry();
3823 3847
@@ -3841,7 +3865,7 @@ cleanup_QDIO(void)
3841 qdio_release_qdio_memory(); 3865 qdio_release_qdio_memory();
3842 qdio_unregister_dbf_views(); 3866 qdio_unregister_dbf_views();
3843 mempool_destroy(qdio_mempool_scssc); 3867 mempool_destroy(qdio_mempool_scssc);
3844 3868 bus_remove_file(&ccw_bus_type, &bus_attr_qdio_performance_stats);
3845 printk("qdio: %s: module removed\n",version); 3869 printk("qdio: %s: module removed\n",version);
3846} 3870}
3847 3871
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 42927c1b7451..ec9af72b2afc 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -12,10 +12,6 @@
12#endif /* CONFIG_QDIO_DEBUG */ 12#endif /* CONFIG_QDIO_DEBUG */
13#define QDIO_USE_PROCESSING_STATE 13#define QDIO_USE_PROCESSING_STATE
14 14
15#ifdef CONFIG_QDIO_PERF_STATS
16#define QDIO_PERFORMANCE_STATS
17#endif /* CONFIG_QDIO_PERF_STATS */
18
19#define QDIO_MINIMAL_BH_RELIEF_TIME 16 15#define QDIO_MINIMAL_BH_RELIEF_TIME 16
20#define QDIO_TIMER_POLL_VALUE 1 16#define QDIO_TIMER_POLL_VALUE 1
21#define IQDIO_TIMER_POLL_VALUE 1 17#define IQDIO_TIMER_POLL_VALUE 1
@@ -409,25 +405,23 @@ do_clear_global_summary(void)
409#define CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS 0x08 405#define CHSC_FLAG_SIGA_SYNC_DONE_ON_THININTS 0x08
410#define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04 406#define CHSC_FLAG_SIGA_SYNC_DONE_ON_OUTB_PCIS 0x04
411 407
412#ifdef QDIO_PERFORMANCE_STATS
413struct qdio_perf_stats { 408struct qdio_perf_stats {
414 unsigned int tl_runs; 409 unsigned long tl_runs;
415 410
416 unsigned int siga_outs; 411 unsigned long siga_outs;
417 unsigned int siga_ins; 412 unsigned long siga_ins;
418 unsigned int siga_syncs; 413 unsigned long siga_syncs;
419 unsigned int pcis; 414 unsigned long pcis;
420 unsigned int thinints; 415 unsigned long thinints;
421 unsigned int fast_reqs; 416 unsigned long fast_reqs;
422 417
423 __u64 start_time_outbound; 418 __u64 start_time_outbound;
424 unsigned int outbound_cnt; 419 unsigned long outbound_cnt;
425 unsigned int outbound_time; 420 unsigned long outbound_time;
426 __u64 start_time_inbound; 421 __u64 start_time_inbound;
427 unsigned int inbound_cnt; 422 unsigned long inbound_cnt;
428 unsigned int inbound_time; 423 unsigned long inbound_time;
429}; 424};
430#endif /* QDIO_PERFORMANCE_STATS */
431 425
432/* unlikely as the later the better */ 426/* unlikely as the later the better */
433#define SYNC_MEMORY if (unlikely(q->siga_sync)) qdio_siga_sync_q(q) 427#define SYNC_MEMORY if (unlikely(q->siga_sync)) qdio_siga_sync_q(q)
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index e4dc947e74e9..ad60afe5dd11 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -33,6 +33,7 @@
33#include <linux/kthread.h> 33#include <linux/kthread.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <asm/s390_rdev.h> 35#include <asm/s390_rdev.h>
36#include <asm/reset.h>
36 37
37#include "ap_bus.h" 38#include "ap_bus.h"
38 39
@@ -1128,6 +1129,19 @@ static void ap_poll_thread_stop(void)
1128 mutex_unlock(&ap_poll_thread_mutex); 1129 mutex_unlock(&ap_poll_thread_mutex);
1129} 1130}
1130 1131
1132static void ap_reset(void)
1133{
1134 int i, j;
1135
1136 for (i = 0; i < AP_DOMAINS; i++)
1137 for (j = 0; j < AP_DEVICES; j++)
1138 ap_reset_queue(AP_MKQID(j, i));
1139}
1140
1141static struct reset_call ap_reset_call = {
1142 .fn = ap_reset,
1143};
1144
1131/** 1145/**
1132 * The module initialization code. 1146 * The module initialization code.
1133 */ 1147 */
@@ -1144,6 +1158,7 @@ int __init ap_module_init(void)
1144 printk(KERN_WARNING "AP instructions not installed.\n"); 1158 printk(KERN_WARNING "AP instructions not installed.\n");
1145 return -ENODEV; 1159 return -ENODEV;
1146 } 1160 }
1161 register_reset_call(&ap_reset_call);
1147 1162
1148 /* Create /sys/bus/ap. */ 1163 /* Create /sys/bus/ap. */
1149 rc = bus_register(&ap_bus_type); 1164 rc = bus_register(&ap_bus_type);
@@ -1197,6 +1212,7 @@ out_bus:
1197 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); 1212 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1198 bus_unregister(&ap_bus_type); 1213 bus_unregister(&ap_bus_type);
1199out: 1214out:
1215 unregister_reset_call(&ap_reset_call);
1200 return rc; 1216 return rc;
1201} 1217}
1202 1218
@@ -1227,6 +1243,7 @@ void ap_module_exit(void)
1227 for (i = 0; ap_bus_attrs[i]; i++) 1243 for (i = 0; ap_bus_attrs[i]; i++)
1228 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]); 1244 bus_remove_file(&ap_bus_type, ap_bus_attrs[i]);
1229 bus_unregister(&ap_bus_type); 1245 bus_unregister(&ap_bus_type);
1246 unregister_reset_call(&ap_reset_call);
1230} 1247}
1231 1248
1232#ifndef CONFIG_ZCRYPT_MONOLITHIC 1249#ifndef CONFIG_ZCRYPT_MONOLITHIC
diff --git a/drivers/sbus/char/bpp.c b/drivers/sbus/char/bpp.c
index 385f4f768311..ac7d1258efee 100644
--- a/drivers/sbus/char/bpp.c
+++ b/drivers/sbus/char/bpp.c
@@ -621,7 +621,7 @@ static long read_ecp(unsigned minor, char __user *c, unsigned long cnt)
621static ssize_t bpp_read(struct file *f, char __user *c, size_t cnt, loff_t * ppos) 621static ssize_t bpp_read(struct file *f, char __user *c, size_t cnt, loff_t * ppos)
622{ 622{
623 long rc; 623 long rc;
624 unsigned minor = iminor(f->f_dentry->d_inode); 624 unsigned minor = iminor(f->f_path.dentry->d_inode);
625 if (minor >= BPP_NO) return -ENODEV; 625 if (minor >= BPP_NO) return -ENODEV;
626 if (!instances[minor].present) return -ENODEV; 626 if (!instances[minor].present) return -ENODEV;
627 627
@@ -774,7 +774,7 @@ static long write_ecp(unsigned minor, const char __user *c, unsigned long cnt)
774static ssize_t bpp_write(struct file *f, const char __user *c, size_t cnt, loff_t * ppos) 774static ssize_t bpp_write(struct file *f, const char __user *c, size_t cnt, loff_t * ppos)
775{ 775{
776 long errno = 0; 776 long errno = 0;
777 unsigned minor = iminor(f->f_dentry->d_inode); 777 unsigned minor = iminor(f->f_path.dentry->d_inode);
778 if (minor >= BPP_NO) return -ENODEV; 778 if (minor >= BPP_NO) return -ENODEV;
779 if (!instances[minor].present) return -ENODEV; 779 if (!instances[minor].present) return -ENODEV;
780 780
diff --git a/drivers/sbus/char/cpwatchdog.c b/drivers/sbus/char/cpwatchdog.c
index f5803ecb1999..ad1c7db96cb4 100644
--- a/drivers/sbus/char/cpwatchdog.c
+++ b/drivers/sbus/char/cpwatchdog.c
@@ -404,7 +404,7 @@ static long wd_compat_ioctl(struct file *file, unsigned int cmd,
404 case WIOCSTOP: 404 case WIOCSTOP:
405 case WIOCGSTAT: 405 case WIOCGSTAT:
406 lock_kernel(); 406 lock_kernel();
407 rval = wd_ioctl(file->f_dentry->d_inode, file, cmd, arg); 407 rval = wd_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
408 unlock_kernel(); 408 unlock_kernel();
409 break; 409 break;
410 /* everything else is handled by the generic compat layer */ 410 /* everything else is handled by the generic compat layer */
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index d92bc8827a9e..a4909e0c7f83 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -121,7 +121,7 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
121 __u8 ireg = 0; 121 __u8 ireg = 0;
122 int error = 0; 122 int error = 0;
123 123
124 if (D7S_MINOR != iminor(file->f_dentry->d_inode)) 124 if (D7S_MINOR != iminor(file->f_path.dentry->d_inode))
125 return -ENODEV; 125 return -ENODEV;
126 126
127 lock_kernel(); 127 lock_kernel();
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 81ba2d71cee2..4e2a0e2dcc2e 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -676,7 +676,7 @@ static long openprom_compat_ioctl(struct file *file, unsigned int cmd,
676 case OPROMSETCUR: 676 case OPROMSETCUR:
677 case OPROMPCI2NODE: 677 case OPROMPCI2NODE:
678 case OPROMPATH2NODE: 678 case OPROMPATH2NODE:
679 rval = openprom_ioctl(file->f_dentry->d_inode, file, cmd, arg); 679 rval = openprom_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
680 break; 680 break;
681 } 681 }
682 682
diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c
index 55b2b31bd7ab..2722af5d3404 100644
--- a/drivers/sbus/char/vfc_dev.c
+++ b/drivers/sbus/char/vfc_dev.c
@@ -610,7 +610,7 @@ static int vfc_mmap(struct file *file, struct vm_area_struct *vma)
610 unsigned int map_size, ret, map_offset; 610 unsigned int map_size, ret, map_offset;
611 struct vfc_dev *dev; 611 struct vfc_dev *dev;
612 612
613 dev = vfc_get_dev_ptr(iminor(file->f_dentry->d_inode)); 613 dev = vfc_get_dev_ptr(iminor(file->f_path.dentry->d_inode));
614 if(dev == NULL) 614 if(dev == NULL)
615 return -ENODEV; 615 return -ENODEV;
616 616
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 69569096dae5..60f582727185 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1737,7 +1737,7 @@ config SCSI_NCR53C7xx_FAST
1737 1737
1738config SUN3_SCSI 1738config SUN3_SCSI
1739 tristate "Sun3 NCR5380 SCSI" 1739 tristate "Sun3 NCR5380 SCSI"
1740 depends on SUN3 && SCSI && BROKEN 1740 depends on SUN3 && SCSI
1741 select SCSI_SPI_ATTRS 1741 select SCSI_SPI_ATTRS
1742 help 1742 help
1743 This option will enable support for the OBIO (onboard io) NCR5380 1743 This option will enable support for the OBIO (onboard io) NCR5380
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index f6a452846fab..978bfc1e0c6a 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -863,7 +863,7 @@ static void sd_rescan(struct device *dev)
863 */ 863 */
864static long sd_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 864static long sd_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
865{ 865{
866 struct block_device *bdev = file->f_dentry->d_inode->i_bdev; 866 struct block_device *bdev = file->f_path.dentry->d_inode->i_bdev;
867 struct gendisk *disk = bdev->bd_disk; 867 struct gendisk *disk = bdev->bd_disk;
868 struct scsi_device *sdev = scsi_disk(disk)->device; 868 struct scsi_device *sdev = scsi_disk(disk)->device;
869 869
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 587274dd7059..e016e0906e1a 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -922,7 +922,7 @@ static int check_tape(struct scsi_tape *STp, struct file *filp)
922 struct st_modedef *STm; 922 struct st_modedef *STm;
923 struct st_partstat *STps; 923 struct st_partstat *STps;
924 char *name = tape_name(STp); 924 char *name = tape_name(STp);
925 struct inode *inode = filp->f_dentry->d_inode; 925 struct inode *inode = filp->f_path.dentry->d_inode;
926 int mode = TAPE_MODE(inode); 926 int mode = TAPE_MODE(inode);
927 927
928 STp->ready = ST_READY; 928 STp->ready = ST_READY;
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
index 3b3f3050a877..43f5b6aa7dc4 100644
--- a/drivers/scsi/sun3_NCR5380.c
+++ b/drivers/scsi/sun3_NCR5380.c
@@ -1271,7 +1271,7 @@ static irqreturn_t NCR5380_intr (int irq, void *dev_id)
1271 NCR_PRINT(NDEBUG_INTR); 1271 NCR_PRINT(NDEBUG_INTR);
1272 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) { 1272 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
1273 done = 0; 1273 done = 0;
1274 ENABLE_IRQ(); 1274// ENABLE_IRQ();
1275 INT_PRINTK("scsi%d: SEL interrupt\n", HOSTNO); 1275 INT_PRINTK("scsi%d: SEL interrupt\n", HOSTNO);
1276 NCR5380_reselect(instance); 1276 NCR5380_reselect(instance);
1277 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1277 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
@@ -1304,7 +1304,7 @@ static irqreturn_t NCR5380_intr (int irq, void *dev_id)
1304 INT_PRINTK("scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO); 1304 INT_PRINTK("scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO);
1305 NCR5380_dma_complete( instance ); 1305 NCR5380_dma_complete( instance );
1306 done = 0; 1306 done = 0;
1307 ENABLE_IRQ(); 1307// ENABLE_IRQ();
1308 } else 1308 } else
1309#endif /* REAL_DMA */ 1309#endif /* REAL_DMA */
1310 { 1310 {
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index d56d85dd9ba0..69ee3e4a820e 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -75,9 +75,9 @@
75#define REAL_DMA 75#define REAL_DMA
76 76
77#include "scsi.h" 77#include "scsi.h"
78#include "initio.h"
78#include <scsi/scsi_host.h> 79#include <scsi/scsi_host.h>
79#include "sun3_scsi.h" 80#include "sun3_scsi.h"
80#include "NCR5380.h"
81 81
82static void NCR5380_print(struct Scsi_Host *instance); 82static void NCR5380_print(struct Scsi_Host *instance);
83 83
diff --git a/drivers/scsi/sun3_scsi.h b/drivers/scsi/sun3_scsi.h
index a1103b3e2034..b29a9d661ca4 100644
--- a/drivers/scsi/sun3_scsi.h
+++ b/drivers/scsi/sun3_scsi.h
@@ -221,7 +221,7 @@ struct sun3_udc_regs {
221 * 221 *
222 */ 222 */
223 223
224 224#include "NCR5380.h"
225 225
226#if NDEBUG & NDEBUG_ARBITRATION 226#if NDEBUG & NDEBUG_ARBITRATION
227#define ARB_PRINTK(format, args...) \ 227#define ARB_PRINTK(format, args...) \
diff --git a/drivers/scsi/sun3_scsi_vme.c b/drivers/scsi/sun3_scsi_vme.c
index 92def310a84c..bb0c9fd99e68 100644
--- a/drivers/scsi/sun3_scsi_vme.c
+++ b/drivers/scsi/sun3_scsi_vme.c
@@ -41,9 +41,9 @@
41#define REAL_DMA 41#define REAL_DMA
42 42
43#include "scsi.h" 43#include "scsi.h"
44#include "initio.h"
44#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
45#include "sun3_scsi.h" 46#include "sun3_scsi.h"
46#include "NCR5380.h"
47 47
48extern int sun3_map_test(unsigned long, char *); 48extern int sun3_map_test(unsigned long, char *);
49 49
diff --git a/drivers/serial/21285.c b/drivers/serial/21285.c
index 6a1a568ca649..facb67855619 100644
--- a/drivers/serial/21285.c
+++ b/drivers/serial/21285.c
@@ -214,8 +214,8 @@ static void serial21285_shutdown(struct uart_port *port)
214} 214}
215 215
216static void 216static void
217serial21285_set_termios(struct uart_port *port, struct termios *termios, 217serial21285_set_termios(struct uart_port *port, struct ktermios *termios,
218 struct termios *old) 218 struct ktermios *old)
219{ 219{
220 unsigned long flags; 220 unsigned long flags;
221 unsigned int baud, quot, h_lcr; 221 unsigned int baud, quot, h_lcr;
diff --git a/drivers/serial/68328serial.c b/drivers/serial/68328serial.c
index 9b8b585513ec..cad426c9711e 100644
--- a/drivers/serial/68328serial.c
+++ b/drivers/serial/68328serial.c
@@ -1061,7 +1061,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1061 return 0; 1061 return 0;
1062} 1062}
1063 1063
1064static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1064static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1065{ 1065{
1066 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data; 1066 struct m68k_serial *info = (struct m68k_serial *)tty->driver_data;
1067 1067
diff --git a/drivers/serial/68360serial.c b/drivers/serial/68360serial.c
index 634ecca36a77..68817a7d8c0d 100644
--- a/drivers/serial/68360serial.c
+++ b/drivers/serial/68360serial.c
@@ -1523,7 +1523,7 @@ static int rs_360_ioctl(struct tty_struct *tty, struct file * file,
1523 1523
1524/* FIX UP modem control here someday...... 1524/* FIX UP modem control here someday......
1525*/ 1525*/
1526static void rs_360_set_termios(struct tty_struct *tty, struct termios *old_termios) 1526static void rs_360_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1527{ 1527{
1528 ser_info_t *info = (ser_info_t *)tty->driver_data; 1528 ser_info_t *info = (ser_info_t *)tty->driver_data;
1529 1529
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index e34bd03cfce7..51f3c739f7e1 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -1763,8 +1763,8 @@ static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int
1763} 1763}
1764 1764
1765static void 1765static void
1766serial8250_set_termios(struct uart_port *port, struct termios *termios, 1766serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
1767 struct termios *old) 1767 struct ktermios *old)
1768{ 1768{
1769 struct uart_8250_port *up = (struct uart_8250_port *)port; 1769 struct uart_8250_port *up = (struct uart_8250_port *)port;
1770 unsigned char cval, fcr = 0; 1770 unsigned char cval, fcr = 0;
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index fc12d5df10e2..0b36dd5cdac2 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -151,32 +151,6 @@ config SERIAL_8250_MANY_PORTS
151 say N here to save some memory. You can also say Y if you have an 151 say N here to save some memory. You can also say Y if you have an
152 "intelligent" multiport card such as Cyclades, Digiboards, etc. 152 "intelligent" multiport card such as Cyclades, Digiboards, etc.
153 153
154config SERIAL_8250_SHARE_IRQ
155 bool "Support for sharing serial interrupts"
156 depends on SERIAL_8250_EXTENDED
157 help
158 Some serial boards have hardware support which allows multiple dumb
159 serial ports on the same board to share a single IRQ. To enable
160 support for this in the serial driver, say Y here.
161
162config SERIAL_8250_DETECT_IRQ
163 bool "Autodetect IRQ on standard ports (unsafe)"
164 depends on SERIAL_8250_EXTENDED
165 help
166 Say Y here if you want the kernel to try to guess which IRQ
167 to use for your serial port.
168
169 This is considered unsafe; it is far better to configure the IRQ in
170 a boot script using the setserial command.
171
172 If unsure, say N.
173
174config SERIAL_8250_RSA
175 bool "Support RSA serial ports"
176 depends on SERIAL_8250_EXTENDED
177 help
178 ::: To be written :::
179
180# 154#
181# Multi-port serial cards 155# Multi-port serial cards
182# 156#
@@ -199,7 +173,6 @@ config SERIAL_8250_ACCENT
199 To compile this driver as a module, choose M here: the module 173 To compile this driver as a module, choose M here: the module
200 will be called 8250_accent. 174 will be called 8250_accent.
201 175
202
203config SERIAL_8250_BOCA 176config SERIAL_8250_BOCA
204 tristate "Support Boca cards" 177 tristate "Support Boca cards"
205 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS 178 depends on SERIAL_8250 != n && ISA && SERIAL_8250_MANY_PORTS
@@ -230,6 +203,32 @@ config SERIAL_8250_HUB6
230 To compile this driver as a module, choose M here: the module 203 To compile this driver as a module, choose M here: the module
231 will be called 8250_hub6. 204 will be called 8250_hub6.
232 205
206config SERIAL_8250_SHARE_IRQ
207 bool "Support for sharing serial interrupts"
208 depends on SERIAL_8250_EXTENDED
209 help
210 Some serial boards have hardware support which allows multiple dumb
211 serial ports on the same board to share a single IRQ. To enable
212 support for this in the serial driver, say Y here.
213
214config SERIAL_8250_DETECT_IRQ
215 bool "Autodetect IRQ on standard ports (unsafe)"
216 depends on SERIAL_8250_EXTENDED
217 help
218 Say Y here if you want the kernel to try to guess which IRQ
219 to use for your serial port.
220
221 This is considered unsafe; it is far better to configure the IRQ in
222 a boot script using the setserial command.
223
224 If unsure, say N.
225
226config SERIAL_8250_RSA
227 bool "Support RSA serial ports"
228 depends on SERIAL_8250_EXTENDED
229 help
230 ::: To be written :::
231
233config SERIAL_8250_MCA 232config SERIAL_8250_MCA
234 tristate "Support 8250-type ports on MCA buses" 233 tristate "Support 8250-type ports on MCA buses"
235 depends on SERIAL_8250 != n && MCA 234 depends on SERIAL_8250 != n && MCA
diff --git a/drivers/serial/amba-pl010.c b/drivers/serial/amba-pl010.c
index 4d3626ef4643..61db6973755a 100644
--- a/drivers/serial/amba-pl010.c
+++ b/drivers/serial/amba-pl010.c
@@ -345,8 +345,8 @@ static void pl010_shutdown(struct uart_port *port)
345} 345}
346 346
347static void 347static void
348pl010_set_termios(struct uart_port *port, struct termios *termios, 348pl010_set_termios(struct uart_port *port, struct ktermios *termios,
349 struct termios *old) 349 struct ktermios *old)
350{ 350{
351 unsigned int lcr_h, old_cr; 351 unsigned int lcr_h, old_cr;
352 unsigned long flags; 352 unsigned long flags;
diff --git a/drivers/serial/amba-pl011.c b/drivers/serial/amba-pl011.c
index d503625730df..9a3b374b2a08 100644
--- a/drivers/serial/amba-pl011.c
+++ b/drivers/serial/amba-pl011.c
@@ -412,8 +412,8 @@ static void pl011_shutdown(struct uart_port *port)
412} 412}
413 413
414static void 414static void
415pl011_set_termios(struct uart_port *port, struct termios *termios, 415pl011_set_termios(struct uart_port *port, struct ktermios *termios,
416 struct termios *old) 416 struct ktermios *old)
417{ 417{
418 unsigned int lcr_h, old_cr; 418 unsigned int lcr_h, old_cr;
419 unsigned long flags; 419 unsigned long flags;
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index 9217ee6c7865..ed7f7209ea59 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -478,7 +478,7 @@ static void atmel_serial_pm(struct uart_port *port, unsigned int state, unsigned
478/* 478/*
479 * Change the port parameters 479 * Change the port parameters
480 */ 480 */
481static void atmel_set_termios(struct uart_port *port, struct termios * termios, struct termios * old) 481static void atmel_set_termios(struct uart_port *port, struct ktermios * termios, struct ktermios * old)
482{ 482{
483 unsigned long flags; 483 unsigned long flags;
484 unsigned int mode, imr, quot, baud; 484 unsigned int mode, imr, quot, baud;
diff --git a/drivers/serial/clps711x.c b/drivers/serial/clps711x.c
index 598012714882..23827189ec0e 100644
--- a/drivers/serial/clps711x.c
+++ b/drivers/serial/clps711x.c
@@ -286,8 +286,8 @@ static void clps711xuart_shutdown(struct uart_port *port)
286} 286}
287 287
288static void 288static void
289clps711xuart_set_termios(struct uart_port *port, struct termios *termios, 289clps711xuart_set_termios(struct uart_port *port, struct ktermios *termios,
290 struct termios *old) 290 struct ktermios *old)
291{ 291{
292 unsigned int ubrlcr, baud, quot; 292 unsigned int ubrlcr, baud, quot;
293 unsigned long flags; 293 unsigned long flags;
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 7a24e53546c7..42b050c46abe 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -804,8 +804,8 @@ static struct e100_serial rs_table[] = {
804 804
805#define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial)) 805#define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial))
806 806
807static struct termios *serial_termios[NR_PORTS]; 807static struct ktermios *serial_termios[NR_PORTS];
808static struct termios *serial_termios_locked[NR_PORTS]; 808static struct ktermios *serial_termios_locked[NR_PORTS];
809#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER 809#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
810static struct fast_timer fast_timers[NR_PORTS]; 810static struct fast_timer fast_timers[NR_PORTS];
811#endif 811#endif
@@ -4223,7 +4223,7 @@ rs_ioctl(struct tty_struct *tty, struct file * file,
4223} 4223}
4224 4224
4225static void 4225static void
4226rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 4226rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4227{ 4227{
4228 struct e100_serial *info = (struct e100_serial *)tty->driver_data; 4228 struct e100_serial *info = (struct e100_serial *)tty->driver_data;
4229 4229
@@ -4877,6 +4877,8 @@ rs_init(void)
4877 driver->init_termios = tty_std_termios; 4877 driver->init_termios = tty_std_termios;
4878 driver->init_termios.c_cflag = 4878 driver->init_termios.c_cflag =
4879 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */ 4879 B115200 | CS8 | CREAD | HUPCL | CLOCAL; /* is normally B9600 default... */
4880 driver->init_termios.c_ispeed = 115200;
4881 driver->init_termios.c_ospeed = 115200;
4880 driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 4882 driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4881 driver->termios = serial_termios; 4883 driver->termios = serial_termios;
4882 driver->termios_locked = serial_termios_locked; 4884 driver->termios_locked = serial_termios_locked;
diff --git a/drivers/serial/crisv10.h b/drivers/serial/crisv10.h
index f30b93d6ef79..4a23340663aa 100644
--- a/drivers/serial/crisv10.h
+++ b/drivers/serial/crisv10.h
@@ -93,8 +93,8 @@ struct e100_serial {
93 93
94 struct work_struct work; 94 struct work_struct work;
95 struct async_icount icount; /* error-statistics etc.*/ 95 struct async_icount icount; /* error-statistics etc.*/
96 struct termios normal_termios; 96 struct ktermios normal_termios;
97 struct termios callout_termios; 97 struct ktermios callout_termios;
98#ifdef DECLARE_WAITQUEUE 98#ifdef DECLARE_WAITQUEUE
99 wait_queue_head_t open_wait; 99 wait_queue_head_t open_wait;
100 wait_queue_head_t close_wait; 100 wait_queue_head_t close_wait;
diff --git a/drivers/serial/dz.c b/drivers/serial/dz.c
index af1544f3356f..587d87b9eb3c 100644
--- a/drivers/serial/dz.c
+++ b/drivers/serial/dz.c
@@ -461,8 +461,8 @@ static void dz_break_ctl(struct uart_port *uport, int break_state)
461 spin_unlock_irqrestore(&uport->lock, flags); 461 spin_unlock_irqrestore(&uport->lock, flags);
462} 462}
463 463
464static void dz_set_termios(struct uart_port *uport, struct termios *termios, 464static void dz_set_termios(struct uart_port *uport, struct ktermios *termios,
465 struct termios *old_termios) 465 struct ktermios *old_termios)
466{ 466{
467 struct dz_port *dport = (struct dz_port *)uport; 467 struct dz_port *dport = (struct dz_port *)uport;
468 unsigned long flags; 468 unsigned long flags;
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 8aa0f641866b..7d623003e65e 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -1087,8 +1087,8 @@ static void icom_close(struct uart_port *port)
1087} 1087}
1088 1088
1089static void icom_set_termios(struct uart_port *port, 1089static void icom_set_termios(struct uart_port *port,
1090 struct termios *termios, 1090 struct ktermios *termios,
1091 struct termios *old_termios) 1091 struct ktermios *old_termios)
1092{ 1092{
1093 int baud; 1093 int baud;
1094 unsigned cflag, iflag; 1094 unsigned cflag, iflag;
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index ee5c782597dd..e216dcf29376 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -459,8 +459,8 @@ static void imx_shutdown(struct uart_port *port)
459} 459}
460 460
461static void 461static void
462imx_set_termios(struct uart_port *port, struct termios *termios, 462imx_set_termios(struct uart_port *port, struct ktermios *termios,
463 struct termios *old) 463 struct ktermios *old)
464{ 464{
465 struct imx_port *sport = (struct imx_port *)port; 465 struct imx_port *sport = (struct imx_port *)port;
466 unsigned long flags; 466 unsigned long flags;
diff --git a/drivers/serial/ioc3_serial.c b/drivers/serial/ioc3_serial.c
index 2308d26c8629..9cc0be932316 100644
--- a/drivers/serial/ioc3_serial.c
+++ b/drivers/serial/ioc3_serial.c
@@ -950,7 +950,7 @@ static void transmit_chars(struct uart_port *the_port)
950 */ 950 */
951static void 951static void
952ioc3_change_speed(struct uart_port *the_port, 952ioc3_change_speed(struct uart_port *the_port,
953 struct termios *new_termios, struct termios *old_termios) 953 struct ktermios *new_termios, struct ktermios *old_termios)
954{ 954{
955 struct ioc3_port *port = get_ioc3_port(the_port); 955 struct ioc3_port *port = get_ioc3_port(the_port);
956 unsigned int cflag; 956 unsigned int cflag;
@@ -1853,7 +1853,7 @@ static int ic3_startup(struct uart_port *the_port)
1853 */ 1853 */
1854static void 1854static void
1855ic3_set_termios(struct uart_port *the_port, 1855ic3_set_termios(struct uart_port *the_port,
1856 struct termios *termios, struct termios *old_termios) 1856 struct ktermios *termios, struct ktermios *old_termios)
1857{ 1857{
1858 unsigned long port_flags; 1858 unsigned long port_flags;
1859 1859
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index 711bd1511439..c862f67c985a 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -1681,7 +1681,7 @@ static void transmit_chars(struct uart_port *the_port)
1681 */ 1681 */
1682static void 1682static void
1683ioc4_change_speed(struct uart_port *the_port, 1683ioc4_change_speed(struct uart_port *the_port,
1684 struct termios *new_termios, struct termios *old_termios) 1684 struct ktermios *new_termios, struct ktermios *old_termios)
1685{ 1685{
1686 struct ioc4_port *port = get_ioc4_port(the_port, 0); 1686 struct ioc4_port *port = get_ioc4_port(the_port, 0);
1687 int baud, bits; 1687 int baud, bits;
@@ -1802,7 +1802,7 @@ static inline int ic4_startup_local(struct uart_port *the_port)
1802 ioc4_set_proto(port, the_port->mapbase); 1802 ioc4_set_proto(port, the_port->mapbase);
1803 1803
1804 /* set the speed of the serial port */ 1804 /* set the speed of the serial port */
1805 ioc4_change_speed(the_port, info->tty->termios, (struct termios *)0); 1805 ioc4_change_speed(the_port, info->tty->termios, (struct ktermios *)0);
1806 1806
1807 return 0; 1807 return 0;
1808} 1808}
@@ -2570,7 +2570,7 @@ static int ic4_startup(struct uart_port *the_port)
2570 */ 2570 */
2571static void 2571static void
2572ic4_set_termios(struct uart_port *the_port, 2572ic4_set_termios(struct uart_port *the_port,
2573 struct termios *termios, struct termios *old_termios) 2573 struct ktermios *termios, struct ktermios *old_termios)
2574{ 2574{
2575 unsigned long port_flags; 2575 unsigned long port_flags;
2576 2576
diff --git a/drivers/serial/ip22zilog.c b/drivers/serial/ip22zilog.c
index dca6c1bde8f9..0746c9446ae0 100644
--- a/drivers/serial/ip22zilog.c
+++ b/drivers/serial/ip22zilog.c
@@ -840,8 +840,8 @@ ip22zilog_convert_to_zs(struct uart_ip22zilog_port *up, unsigned int cflag,
840 840
841/* The port lock is not held. */ 841/* The port lock is not held. */
842static void 842static void
843ip22zilog_set_termios(struct uart_port *port, struct termios *termios, 843ip22zilog_set_termios(struct uart_port *port, struct ktermios *termios,
844 struct termios *old) 844 struct ktermios *old)
845{ 845{
846 struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port; 846 struct uart_ip22zilog_port *up = (struct uart_ip22zilog_port *) port;
847 unsigned long flags; 847 unsigned long flags;
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index f8262e6ad8d3..7cf1c60027f8 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -142,7 +142,7 @@ static void jsm_tty_send_xchar(struct uart_port *port, char ch)
142{ 142{
143 unsigned long lock_flags; 143 unsigned long lock_flags;
144 struct jsm_channel *channel = (struct jsm_channel *)port; 144 struct jsm_channel *channel = (struct jsm_channel *)port;
145 struct termios *termios; 145 struct ktermios *termios;
146 146
147 spin_lock_irqsave(&port->lock, lock_flags); 147 spin_lock_irqsave(&port->lock, lock_flags);
148 termios = port->info->tty->termios; 148 termios = port->info->tty->termios;
@@ -180,7 +180,7 @@ static int jsm_tty_open(struct uart_port *port)
180 struct jsm_board *brd; 180 struct jsm_board *brd;
181 int rc = 0; 181 int rc = 0;
182 struct jsm_channel *channel = (struct jsm_channel *)port; 182 struct jsm_channel *channel = (struct jsm_channel *)port;
183 struct termios *termios; 183 struct ktermios *termios;
184 184
185 /* Get board pointer from our array of majors we have allocated */ 185 /* Get board pointer from our array of majors we have allocated */
186 brd = channel->ch_bd; 186 brd = channel->ch_bd;
@@ -269,7 +269,7 @@ static int jsm_tty_open(struct uart_port *port)
269static void jsm_tty_close(struct uart_port *port) 269static void jsm_tty_close(struct uart_port *port)
270{ 270{
271 struct jsm_board *bd; 271 struct jsm_board *bd;
272 struct termios *ts; 272 struct ktermios *ts;
273 struct jsm_channel *channel = (struct jsm_channel *)port; 273 struct jsm_channel *channel = (struct jsm_channel *)port;
274 274
275 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n"); 275 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n");
@@ -302,8 +302,8 @@ static void jsm_tty_close(struct uart_port *port)
302} 302}
303 303
304static void jsm_tty_set_termios(struct uart_port *port, 304static void jsm_tty_set_termios(struct uart_port *port,
305 struct termios *termios, 305 struct ktermios *termios,
306 struct termios *old_termios) 306 struct ktermios *old_termios)
307{ 307{
308 unsigned long lock_flags; 308 unsigned long lock_flags;
309 struct jsm_channel *channel = (struct jsm_channel *)port; 309 struct jsm_channel *channel = (struct jsm_channel *)port;
diff --git a/drivers/serial/m32r_sio.c b/drivers/serial/m32r_sio.c
index 7656a35f5e2f..6e09c8b395e8 100644
--- a/drivers/serial/m32r_sio.c
+++ b/drivers/serial/m32r_sio.c
@@ -699,7 +699,7 @@ static unsigned int m32r_sio_get_divisor(struct uart_port *port,
699} 699}
700 700
701static void m32r_sio_set_termios(struct uart_port *port, 701static void m32r_sio_set_termios(struct uart_port *port,
702 struct termios *termios, struct termios *old) 702 struct ktermios *termios, struct ktermios *old)
703{ 703{
704 struct uart_sio_port *up = (struct uart_sio_port *)port; 704 struct uart_sio_port *up = (struct uart_sio_port *)port;
705 unsigned char cval = 0; 705 unsigned char cval = 0;
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
index 3db206d29b33..08430961a895 100644
--- a/drivers/serial/mcfserial.c
+++ b/drivers/serial/mcfserial.c
@@ -1132,7 +1132,7 @@ static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1132 return 0; 1132 return 0;
1133} 1133}
1134 1134
1135static void mcfrs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1135static void mcfrs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1136{ 1136{
1137 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data; 1137 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1138 1138
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 6dd579ed9777..9d11a75663e6 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -270,8 +270,8 @@ mpc52xx_uart_shutdown(struct uart_port *port)
270} 270}
271 271
272static void 272static void
273mpc52xx_uart_set_termios(struct uart_port *port, struct termios *new, 273mpc52xx_uart_set_termios(struct uart_port *port, struct ktermios *new,
274 struct termios *old) 274 struct ktermios *old)
275{ 275{
276 struct mpc52xx_psc __iomem *psc = PSC(port); 276 struct mpc52xx_psc __iomem *psc = PSC(port);
277 unsigned long flags; 277 unsigned long flags;
diff --git a/drivers/serial/mpsc.c b/drivers/serial/mpsc.c
index 29823bd60fb0..3d2fcc57b1ce 100644
--- a/drivers/serial/mpsc.c
+++ b/drivers/serial/mpsc.c
@@ -1440,8 +1440,8 @@ mpsc_shutdown(struct uart_port *port)
1440} 1440}
1441 1441
1442static void 1442static void
1443mpsc_set_termios(struct uart_port *port, struct termios *termios, 1443mpsc_set_termios(struct uart_port *port, struct ktermios *termios,
1444 struct termios *old) 1444 struct ktermios *old)
1445{ 1445{
1446 struct mpsc_port_info *pi = (struct mpsc_port_info *)port; 1446 struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
1447 u32 baud; 1447 u32 baud;
diff --git a/drivers/serial/mux.c b/drivers/serial/mux.c
index 8ad1b8c5ec5d..ccb8fa1800a5 100644
--- a/drivers/serial/mux.c
+++ b/drivers/serial/mux.c
@@ -273,8 +273,8 @@ static void mux_shutdown(struct uart_port *port)
273 * The Serial Mux does not support this function. 273 * The Serial Mux does not support this function.
274 */ 274 */
275static void 275static void
276mux_set_termios(struct uart_port *port, struct termios *termios, 276mux_set_termios(struct uart_port *port, struct ktermios *termios,
277 struct termios *old) 277 struct ktermios *old)
278{ 278{
279} 279}
280 280
diff --git a/drivers/serial/netx-serial.c b/drivers/serial/netx-serial.c
index 062bad457b1a..b56f7db45031 100644
--- a/drivers/serial/netx-serial.c
+++ b/drivers/serial/netx-serial.c
@@ -337,8 +337,8 @@ static void netx_shutdown(struct uart_port *port)
337} 337}
338 338
339static void 339static void
340netx_set_termios(struct uart_port *port, struct termios *termios, 340netx_set_termios(struct uart_port *port, struct ktermios *termios,
341 struct termios *old) 341 struct ktermios *old)
342{ 342{
343 unsigned int baud, quot; 343 unsigned int baud, quot;
344 unsigned char old_cr; 344 unsigned char old_cr;
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index bf9809ed9c0b..752ef07516b9 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -1262,8 +1262,8 @@ static void pmz_irda_setup(struct uart_pmac_port *uap, unsigned long *baud)
1262} 1262}
1263 1263
1264 1264
1265static void __pmz_set_termios(struct uart_port *port, struct termios *termios, 1265static void __pmz_set_termios(struct uart_port *port, struct ktermios *termios,
1266 struct termios *old) 1266 struct ktermios *old)
1267{ 1267{
1268 struct uart_pmac_port *uap = to_pmz(port); 1268 struct uart_pmac_port *uap = to_pmz(port);
1269 unsigned long baud; 1269 unsigned long baud;
@@ -1273,7 +1273,7 @@ static void __pmz_set_termios(struct uart_port *port, struct termios *termios,
1273 if (ZS_IS_ASLEEP(uap)) 1273 if (ZS_IS_ASLEEP(uap))
1274 return; 1274 return;
1275 1275
1276 memcpy(&uap->termios_cache, termios, sizeof(struct termios)); 1276 memcpy(&uap->termios_cache, termios, sizeof(struct ktermios));
1277 1277
1278 /* XXX Check which revs of machines actually allow 1 and 4Mb speeds 1278 /* XXX Check which revs of machines actually allow 1 and 4Mb speeds
1279 * on the IR dongle. Note that the IRTTY driver currently doesn't know 1279 * on the IR dongle. Note that the IRTTY driver currently doesn't know
@@ -1313,8 +1313,8 @@ static void __pmz_set_termios(struct uart_port *port, struct termios *termios,
1313} 1313}
1314 1314
1315/* The port lock is not held. */ 1315/* The port lock is not held. */
1316static void pmz_set_termios(struct uart_port *port, struct termios *termios, 1316static void pmz_set_termios(struct uart_port *port, struct ktermios *termios,
1317 struct termios *old) 1317 struct ktermios *old)
1318{ 1318{
1319 struct uart_pmac_port *uap = to_pmz(port); 1319 struct uart_pmac_port *uap = to_pmz(port);
1320 unsigned long flags; 1320 unsigned long flags;
diff --git a/drivers/serial/pmac_zilog.h b/drivers/serial/pmac_zilog.h
index c03f9bfacdd8..570b0d925e83 100644
--- a/drivers/serial/pmac_zilog.h
+++ b/drivers/serial/pmac_zilog.h
@@ -60,7 +60,7 @@ struct uart_pmac_port {
60 volatile struct dbdma_regs __iomem *tx_dma_regs; 60 volatile struct dbdma_regs __iomem *tx_dma_regs;
61 volatile struct dbdma_regs __iomem *rx_dma_regs; 61 volatile struct dbdma_regs __iomem *rx_dma_regs;
62 62
63 struct termios termios_cache; 63 struct ktermios termios_cache;
64}; 64};
65 65
66#define to_pmz(p) ((struct uart_pmac_port *)(p)) 66#define to_pmz(p) ((struct uart_pmac_port *)(p))
diff --git a/drivers/serial/pxa.c b/drivers/serial/pxa.c
index 415fe9633a9b..d403aaa55092 100644
--- a/drivers/serial/pxa.c
+++ b/drivers/serial/pxa.c
@@ -433,8 +433,8 @@ static void serial_pxa_shutdown(struct uart_port *port)
433} 433}
434 434
435static void 435static void
436serial_pxa_set_termios(struct uart_port *port, struct termios *termios, 436serial_pxa_set_termios(struct uart_port *port, struct ktermios *termios,
437 struct termios *old) 437 struct ktermios *old)
438{ 438{
439 struct uart_pxa_port *up = (struct uart_pxa_port *)port; 439 struct uart_pxa_port *up = (struct uart_pxa_port *)port;
440 unsigned char cval, fcr = 0; 440 unsigned char cval, fcr = 0;
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 8dfc2dd058ca..3ba9208ebd0c 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -738,8 +738,8 @@ static unsigned int s3c24xx_serial_getclk(struct uart_port *port,
738} 738}
739 739
740static void s3c24xx_serial_set_termios(struct uart_port *port, 740static void s3c24xx_serial_set_termios(struct uart_port *port,
741 struct termios *termios, 741 struct ktermios *termios,
742 struct termios *old) 742 struct ktermios *old)
743{ 743{
744 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port); 744 struct s3c2410_uartcfg *cfg = s3c24xx_port_to_cfg(port);
745 struct s3c24xx_uart_port *ourport = to_ourport(port); 745 struct s3c24xx_uart_port *ourport = to_ourport(port);
diff --git a/drivers/serial/sa1100.c b/drivers/serial/sa1100.c
index d4065266b6fc..58a83c27e14b 100644
--- a/drivers/serial/sa1100.c
+++ b/drivers/serial/sa1100.c
@@ -408,8 +408,8 @@ static void sa1100_shutdown(struct uart_port *port)
408} 408}
409 409
410static void 410static void
411sa1100_set_termios(struct uart_port *port, struct termios *termios, 411sa1100_set_termios(struct uart_port *port, struct ktermios *termios,
412 struct termios *old) 412 struct ktermios *old)
413{ 413{
414 struct sa1100_port *sport = (struct sa1100_port *)port; 414 struct sa1100_port *sport = (struct sa1100_port *)port;
415 unsigned long flags; 415 unsigned long flags;
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index c67b05e9a451..f84982e508c7 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -65,7 +65,7 @@ static struct lock_class_key port_lock_key;
65#define uart_console(port) (0) 65#define uart_console(port) (0)
66#endif 66#endif
67 67
68static void uart_change_speed(struct uart_state *state, struct termios *old_termios); 68static void uart_change_speed(struct uart_state *state, struct ktermios *old_termios);
69static void uart_wait_until_sent(struct tty_struct *tty, int timeout); 69static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
70static void uart_change_pm(struct uart_state *state, int pm_state); 70static void uart_change_pm(struct uart_state *state, int pm_state);
71 71
@@ -338,8 +338,8 @@ EXPORT_SYMBOL(uart_update_timeout);
338 * we're actually going to be using. 338 * we're actually going to be using.
339 */ 339 */
340unsigned int 340unsigned int
341uart_get_baud_rate(struct uart_port *port, struct termios *termios, 341uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
342 struct termios *old, unsigned int min, unsigned int max) 342 struct ktermios *old, unsigned int min, unsigned int max)
343{ 343{
344 unsigned int try, baud, altbaud = 38400; 344 unsigned int try, baud, altbaud = 38400;
345 upf_t flags = port->flags & UPF_SPD_MASK; 345 upf_t flags = port->flags & UPF_SPD_MASK;
@@ -421,11 +421,11 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
421EXPORT_SYMBOL(uart_get_divisor); 421EXPORT_SYMBOL(uart_get_divisor);
422 422
423static void 423static void
424uart_change_speed(struct uart_state *state, struct termios *old_termios) 424uart_change_speed(struct uart_state *state, struct ktermios *old_termios)
425{ 425{
426 struct tty_struct *tty = state->info->tty; 426 struct tty_struct *tty = state->info->tty;
427 struct uart_port *port = state->port; 427 struct uart_port *port = state->port;
428 struct termios *termios; 428 struct ktermios *termios;
429 429
430 /* 430 /*
431 * If we have no tty, termios, or the port does not exist, 431 * If we have no tty, termios, or the port does not exist,
@@ -1139,7 +1139,7 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
1139 return ret; 1139 return ret;
1140} 1140}
1141 1141
1142static void uart_set_termios(struct tty_struct *tty, struct termios *old_termios) 1142static void uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1143{ 1143{
1144 struct uart_state *state = tty->driver_data; 1144 struct uart_state *state = tty->driver_data;
1145 unsigned long flags; 1145 unsigned long flags;
@@ -1866,7 +1866,7 @@ int __init
1866uart_set_options(struct uart_port *port, struct console *co, 1866uart_set_options(struct uart_port *port, struct console *co,
1867 int baud, int parity, int bits, int flow) 1867 int baud, int parity, int bits, int flow)
1868{ 1868{
1869 struct termios termios; 1869 struct ktermios termios;
1870 int i; 1870 int i;
1871 1871
1872 /* 1872 /*
@@ -1876,7 +1876,7 @@ uart_set_options(struct uart_port *port, struct console *co,
1876 spin_lock_init(&port->lock); 1876 spin_lock_init(&port->lock);
1877 lockdep_set_class(&port->lock, &port_lock_key); 1877 lockdep_set_class(&port->lock, &port_lock_key);
1878 1878
1879 memset(&termios, 0, sizeof(struct termios)); 1879 memset(&termios, 0, sizeof(struct ktermios));
1880 1880
1881 termios.c_cflag = CREAD | HUPCL | CLOCAL; 1881 termios.c_cflag = CREAD | HUPCL | CLOCAL;
1882 1882
@@ -1991,12 +1991,12 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *port)
1991 * Re-enable the console device after suspending. 1991 * Re-enable the console device after suspending.
1992 */ 1992 */
1993 if (uart_console(port)) { 1993 if (uart_console(port)) {
1994 struct termios termios; 1994 struct ktermios termios;
1995 1995
1996 /* 1996 /*
1997 * First try to use the console cflag setting. 1997 * First try to use the console cflag setting.
1998 */ 1998 */
1999 memset(&termios, 0, sizeof(struct termios)); 1999 memset(&termios, 0, sizeof(struct ktermios));
2000 termios.c_cflag = port->cons->cflag; 2000 termios.c_cflag = port->cons->cflag;
2001 2001
2002 /* 2002 /*
@@ -2189,6 +2189,7 @@ int uart_register_driver(struct uart_driver *drv)
2189 normal->subtype = SERIAL_TYPE_NORMAL; 2189 normal->subtype = SERIAL_TYPE_NORMAL;
2190 normal->init_termios = tty_std_termios; 2190 normal->init_termios = tty_std_termios;
2191 normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 2191 normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2192 normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600;
2192 normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 2193 normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
2193 normal->driver_state = drv; 2194 normal->driver_state = drv;
2194 tty_set_operations(normal, &uart_ops); 2195 tty_set_operations(normal, &uart_ops);
diff --git a/drivers/serial/serial_lh7a40x.c b/drivers/serial/serial_lh7a40x.c
index 5e1ac356bbb0..eb18d429752d 100644
--- a/drivers/serial/serial_lh7a40x.c
+++ b/drivers/serial/serial_lh7a40x.c
@@ -348,8 +348,8 @@ static void lh7a40xuart_shutdown (struct uart_port* port)
348} 348}
349 349
350static void lh7a40xuart_set_termios (struct uart_port* port, 350static void lh7a40xuart_set_termios (struct uart_port* port,
351 struct termios* termios, 351 struct ktermios* termios,
352 struct termios* old) 352 struct ktermios* old)
353{ 353{
354 unsigned int con; 354 unsigned int con;
355 unsigned int inten; 355 unsigned int inten;
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 2a48289ac722..7186a82c4759 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -556,8 +556,8 @@ static void serial_txx9_shutdown(struct uart_port *port)
556} 556}
557 557
558static void 558static void
559serial_txx9_set_termios(struct uart_port *port, struct termios *termios, 559serial_txx9_set_termios(struct uart_port *port, struct ktermios *termios,
560 struct termios *old) 560 struct ktermios *old)
561{ 561{
562 struct uart_txx9_port *up = (struct uart_txx9_port *)port; 562 struct uart_txx9_port *up = (struct uart_txx9_port *)port;
563 unsigned int cval, fcr = 0; 563 unsigned int cval, fcr = 0;
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 3b5f19ec2126..c53b69610a51 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -319,6 +319,28 @@ static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
319 319
320 sci_out(port, SCFCR, fcr_val); 320 sci_out(port, SCFCR, fcr_val);
321} 321}
322#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
323static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
324{
325 unsigned int fcr_val = 0;
326
327 if (cflag & CRTSCTS) {
328 fcr_val |= SCFCR_MCE;
329
330 ctrl_outw(0x0000, PORT_PSCR);
331 } else {
332 unsigned short data;
333
334 data = ctrl_inw(PORT_PSCR);
335 data &= 0x033f;
336 data |= 0x0400;
337 ctrl_outw(data, PORT_PSCR);
338
339 ctrl_outw(ctrl_inw(SCSPTR0) & 0x17, SCSPTR0);
340 }
341
342 sci_out(port, SCFCR, fcr_val);
343}
322#else 344#else
323/* For SH7750 */ 345/* For SH7750 */
324static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag) 346static void sci_init_pins_scif(struct uart_port *port, unsigned int cflag)
@@ -943,8 +965,8 @@ static void sci_shutdown(struct uart_port *port)
943 s->disable(port); 965 s->disable(port);
944} 966}
945 967
946static void sci_set_termios(struct uart_port *port, struct termios *termios, 968static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
947 struct termios *old) 969 struct ktermios *old)
948{ 970{
949 struct sci_port *s = &sci_ports[port->line]; 971 struct sci_port *s = &sci_ports[port->line];
950 unsigned int status, baud, smr_val; 972 unsigned int status, baud, smr_val;
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index e4557cc4f74b..77f7d6351ab1 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -90,6 +90,13 @@
90# define SCSPTR3 0xffe30010 /* 16 bit SCIF */ 90# define SCSPTR3 0xffe30010 /* 16 bit SCIF */
91# define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */ 91# define SCSCR_INIT(port) 0x32 /* TIE=0,RIE=0,TE=1,RE=1,REIE=0,CKE=1 */
92# define SCIF_ONLY 92# define SCIF_ONLY
93#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
94# define SCPDR0 0xA405013E /* 16 bit SCIF0 PSDR */
95# define SCSPTR0 SCPDR0
96# define SCIF_ORER 0x0001 /* overrun error bit */
97# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
98# define SCIF_ONLY
99# define PORT_PSCR 0xA405011E
93#elif defined(CONFIG_CPU_SUBTYPE_SH4_202) 100#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
94# define SCSPTR2 0xffe80020 /* 16 bit SCIF */ 101# define SCSPTR2 0xffe80020 /* 16 bit SCIF */
95# define SCIF_ORER 0x0001 /* overrun error bit */ 102# define SCIF_ORER 0x0001 /* overrun error bit */
@@ -495,6 +502,7 @@ static inline int sci_rxd_in(struct uart_port *port)
495 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */ 502 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
496 if (port->mapbase == 0xfe620000) 503 if (port->mapbase == 0xfe620000)
497 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */ 504 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
505 return 1;
498} 506}
499#elif defined(CONFIG_CPU_SUBTYPE_SH7300) 507#elif defined(CONFIG_CPU_SUBTYPE_SH7300)
500static inline int sci_rxd_in(struct uart_port *port) 508static inline int sci_rxd_in(struct uart_port *port)
@@ -521,6 +529,13 @@ static inline int sci_rxd_in(struct uart_port *port)
521 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */ 529 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
522 return 1; 530 return 1;
523} 531}
532#elif defined(CONFIG_CPU_SUBTYPE_SH7722)
533static inline int sci_rxd_in(struct uart_port *port)
534{
535 if (port->mapbase == 0xffe00000)
536 return ctrl_inb(SCPDR0) & 0x0001 ? 1 : 0; /* SCIF0 */
537 return 1;
538}
524#elif defined(CONFIG_CPU_SUBTYPE_ST40STB1) 539#elif defined(CONFIG_CPU_SUBTYPE_ST40STB1)
525static inline int sci_rxd_in(struct uart_port *port) 540static inline int sci_rxd_in(struct uart_port *port)
526{ 541{
@@ -550,6 +565,7 @@ static inline int sci_rxd_in(struct uart_port *port)
550 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */ 565 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
551 if (port->mapbase == 0xff925000) 566 if (port->mapbase == 0xff925000)
552 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */ 567 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
568 return 1;
553} 569}
554#elif defined(CONFIG_CPU_SUBTYPE_SH7780) 570#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
555static inline int sci_rxd_in(struct uart_port *port) 571static inline int sci_rxd_in(struct uart_port *port)
@@ -558,6 +574,7 @@ static inline int sci_rxd_in(struct uart_port *port)
558 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */ 574 return ctrl_inw(SCSPTR0) & 0x0001 ? 1 : 0; /* SCIF */
559 if (port->mapbase == 0xffe10000) 575 if (port->mapbase == 0xffe10000)
560 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */ 576 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
577 return 1;
561} 578}
562#elif defined(CONFIG_CPU_SUBTYPE_SH7206) 579#elif defined(CONFIG_CPU_SUBTYPE_SH7206)
563static inline int sci_rxd_in(struct uart_port *port) 580static inline int sci_rxd_in(struct uart_port *port)
@@ -570,6 +587,7 @@ static inline int sci_rxd_in(struct uart_port *port)
570 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */ 587 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
571 if (port->mapbase == 0xfffe9800) 588 if (port->mapbase == 0xfffe9800)
572 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */ 589 return ctrl_inw(SCSPTR3) & 0x0001 ? 1 : 0; /* SCIF */
590 return 1;
573} 591}
574#elif defined(CONFIG_CPU_SUBTYPE_SH7619) 592#elif defined(CONFIG_CPU_SUBTYPE_SH7619)
575static inline int sci_rxd_in(struct uart_port *port) 593static inline int sci_rxd_in(struct uart_port *port)
@@ -580,6 +598,7 @@ static inline int sci_rxd_in(struct uart_port *port)
580 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */ 598 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
581 if (port->mapbase == 0xf8420000) 599 if (port->mapbase == 0xf8420000)
582 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */ 600 return ctrl_inw(SCSPTR2) & 0x0001 ? 1 : 0; /* SCIF */
601 return 1;
583} 602}
584#endif 603#endif
585 604
diff --git a/drivers/serial/sn_console.c b/drivers/serial/sn_console.c
index 956b2cf08e1e..253ceb895ca7 100644
--- a/drivers/serial/sn_console.c
+++ b/drivers/serial/sn_console.c
@@ -361,8 +361,8 @@ static int snp_startup(struct uart_port *port)
361 * 361 *
362 */ 362 */
363static void 363static void
364snp_set_termios(struct uart_port *port, struct termios *termios, 364snp_set_termios(struct uart_port *port, struct ktermios *termios,
365 struct termios *old) 365 struct ktermios *old)
366{ 366{
367} 367}
368 368
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index 03941d27d15d..40d48566215c 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -281,8 +281,8 @@ static void sunhv_shutdown(struct uart_port *port)
281} 281}
282 282
283/* port->lock is not held. */ 283/* port->lock is not held. */
284static void sunhv_set_termios(struct uart_port *port, struct termios *termios, 284static void sunhv_set_termios(struct uart_port *port, struct ktermios *termios,
285 struct termios *old) 285 struct ktermios *old)
286{ 286{
287 unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000); 287 unsigned int baud = uart_get_baud_rate(port, termios, old, 0, 4000000);
288 unsigned int quot = uart_get_divisor(port, baud); 288 unsigned int quot = uart_get_divisor(port, baud);
diff --git a/drivers/serial/sunsab.c b/drivers/serial/sunsab.c
index 08a7cd6a3a0c..493d5bbb661b 100644
--- a/drivers/serial/sunsab.c
+++ b/drivers/serial/sunsab.c
@@ -786,8 +786,8 @@ static void sunsab_convert_to_sab(struct uart_sunsab_port *up, unsigned int cfla
786} 786}
787 787
788/* port->lock is not held. */ 788/* port->lock is not held. */
789static void sunsab_set_termios(struct uart_port *port, struct termios *termios, 789static void sunsab_set_termios(struct uart_port *port, struct ktermios *termios,
790 struct termios *old) 790 struct ktermios *old)
791{ 791{
792 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port; 792 struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
793 unsigned long flags; 793 unsigned long flags;
diff --git a/drivers/serial/sunsu.c b/drivers/serial/sunsu.c
index c577faea60e8..564592b2b2ba 100644
--- a/drivers/serial/sunsu.c
+++ b/drivers/serial/sunsu.c
@@ -893,8 +893,8 @@ sunsu_change_speed(struct uart_port *port, unsigned int cflag,
893} 893}
894 894
895static void 895static void
896sunsu_set_termios(struct uart_port *port, struct termios *termios, 896sunsu_set_termios(struct uart_port *port, struct ktermios *termios,
897 struct termios *old) 897 struct ktermios *old)
898{ 898{
899 unsigned int baud, quot; 899 unsigned int baud, quot;
900 900
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index b2cc703b2b9e..75de919a9471 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -922,8 +922,8 @@ sunzilog_convert_to_zs(struct uart_sunzilog_port *up, unsigned int cflag,
922 922
923/* The port lock is not held. */ 923/* The port lock is not held. */
924static void 924static void
925sunzilog_set_termios(struct uart_port *port, struct termios *termios, 925sunzilog_set_termios(struct uart_port *port, struct ktermios *termios,
926 struct termios *old) 926 struct ktermios *old)
927{ 927{
928 struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port; 928 struct uart_sunzilog_port *up = (struct uart_sunzilog_port *) port;
929 unsigned long flags; 929 unsigned long flags;
diff --git a/drivers/serial/uartlite.c b/drivers/serial/uartlite.c
index 83690653b78b..92eba893559d 100644
--- a/drivers/serial/uartlite.c
+++ b/drivers/serial/uartlite.c
@@ -214,8 +214,8 @@ static void ulite_shutdown(struct uart_port *port)
214 free_irq(port->irq, port); 214 free_irq(port->irq, port);
215} 215}
216 216
217static void ulite_set_termios(struct uart_port *port, struct termios *termios, 217static void ulite_set_termios(struct uart_port *port, struct ktermios *termios,
218 struct termios *old) 218 struct ktermios *old)
219{ 219{
220 unsigned long flags; 220 unsigned long flags;
221 unsigned int baud; 221 unsigned int baud;
diff --git a/drivers/serial/v850e_uart.c b/drivers/serial/v850e_uart.c
index 28f3bbff87bf..dd98aca6ed08 100644
--- a/drivers/serial/v850e_uart.c
+++ b/drivers/serial/v850e_uart.c
@@ -404,8 +404,8 @@ static void v850e_uart_shutdown (struct uart_port *port)
404} 404}
405 405
406static void 406static void
407v850e_uart_set_termios (struct uart_port *port, struct termios *termios, 407v850e_uart_set_termios (struct uart_port *port, struct ktermios *termios,
408 struct termios *old) 408 struct ktermios *old)
409{ 409{
410 unsigned cflags = termios->c_cflag; 410 unsigned cflags = termios->c_cflag;
411 411
diff --git a/drivers/serial/vr41xx_siu.c b/drivers/serial/vr41xx_siu.c
index fd51f8182dec..cf0e663b42ed 100644
--- a/drivers/serial/vr41xx_siu.c
+++ b/drivers/serial/vr41xx_siu.c
@@ -562,8 +562,8 @@ static void siu_shutdown(struct uart_port *port)
562 free_irq(port->irq, port); 562 free_irq(port->irq, port);
563} 563}
564 564
565static void siu_set_termios(struct uart_port *port, struct termios *new, 565static void siu_set_termios(struct uart_port *port, struct ktermios *new,
566 struct termios *old) 566 struct ktermios *old)
567{ 567{
568 tcflag_t c_cflag, c_iflag; 568 tcflag_t c_cflag, c_iflag;
569 uint8_t lcr, fcr, ier; 569 uint8_t lcr, fcr, ier;
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 494d9b856488..6ed3f1da9296 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -49,6 +49,14 @@ MODULE_LICENSE("GPL");
49#define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK) 49#define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)
50#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0) 50#define IS_DMA_ALIGNED(x) (((u32)(x)&0x07)==0)
51 51
52/* for testing SSCR1 changes that require SSP restart, basically
53 * everything except the service and interrupt enables */
54#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_EBCEI | SSCR1_SCFR \
55 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
56 | SSCR1_RWOT | SSCR1_TRAIL | SSCR1_PINTE \
57 | SSCR1_STRF | SSCR1_EFWR |SSCR1_RFT \
58 | SSCR1_TFT | SSCR1_SPH | SSCR1_SPO | SSCR1_LBM)
59
52#define DEFINE_SSP_REG(reg, off) \ 60#define DEFINE_SSP_REG(reg, off) \
53static inline u32 read_##reg(void *p) { return __raw_readl(p + (off)); } \ 61static inline u32 read_##reg(void *p) { return __raw_readl(p + (off)); } \
54static inline void write_##reg(u32 v, void *p) { __raw_writel(v, p + (off)); } 62static inline void write_##reg(u32 v, void *p) { __raw_writel(v, p + (off)); }
@@ -123,8 +131,8 @@ struct driver_data {
123 u8 n_bytes; 131 u8 n_bytes;
124 u32 dma_width; 132 u32 dma_width;
125 int cs_change; 133 int cs_change;
126 void (*write)(struct driver_data *drv_data); 134 int (*write)(struct driver_data *drv_data);
127 void (*read)(struct driver_data *drv_data); 135 int (*read)(struct driver_data *drv_data);
128 irqreturn_t (*transfer_handler)(struct driver_data *drv_data); 136 irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
129 void (*cs_control)(u32 command); 137 void (*cs_control)(u32 command);
130}; 138};
@@ -132,7 +140,6 @@ struct driver_data {
132struct chip_data { 140struct chip_data {
133 u32 cr0; 141 u32 cr0;
134 u32 cr1; 142 u32 cr1;
135 u32 to;
136 u32 psp; 143 u32 psp;
137 u32 timeout; 144 u32 timeout;
138 u8 n_bytes; 145 u8 n_bytes;
@@ -143,8 +150,8 @@ struct chip_data {
143 u8 enable_dma; 150 u8 enable_dma;
144 u8 bits_per_word; 151 u8 bits_per_word;
145 u32 speed_hz; 152 u32 speed_hz;
146 void (*write)(struct driver_data *drv_data); 153 int (*write)(struct driver_data *drv_data);
147 void (*read)(struct driver_data *drv_data); 154 int (*read)(struct driver_data *drv_data);
148 void (*cs_control)(u32 command); 155 void (*cs_control)(u32 command);
149}; 156};
150 157
@@ -166,114 +173,118 @@ static int flush(struct driver_data *drv_data)
166 return limit; 173 return limit;
167} 174}
168 175
169static void restore_state(struct driver_data *drv_data)
170{
171 void *reg = drv_data->ioaddr;
172
173 /* Clear status and disable clock */
174 write_SSSR(drv_data->clear_sr, reg);
175 write_SSCR0(drv_data->cur_chip->cr0 & ~SSCR0_SSE, reg);
176
177 /* Load the registers */
178 write_SSCR1(drv_data->cur_chip->cr1, reg);
179 write_SSCR0(drv_data->cur_chip->cr0, reg);
180 if (drv_data->ssp_type != PXA25x_SSP) {
181 write_SSTO(0, reg);
182 write_SSPSP(drv_data->cur_chip->psp, reg);
183 }
184}
185
186static void null_cs_control(u32 command) 176static void null_cs_control(u32 command)
187{ 177{
188} 178}
189 179
190static void null_writer(struct driver_data *drv_data) 180static int null_writer(struct driver_data *drv_data)
191{ 181{
192 void *reg = drv_data->ioaddr; 182 void *reg = drv_data->ioaddr;
193 u8 n_bytes = drv_data->n_bytes; 183 u8 n_bytes = drv_data->n_bytes;
194 184
195 while ((read_SSSR(reg) & SSSR_TNF) 185 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
196 && (drv_data->tx < drv_data->tx_end)) { 186 || (drv_data->tx == drv_data->tx_end))
197 write_SSDR(0, reg); 187 return 0;
198 drv_data->tx += n_bytes; 188
199 } 189 write_SSDR(0, reg);
190 drv_data->tx += n_bytes;
191
192 return 1;
200} 193}
201 194
202static void null_reader(struct driver_data *drv_data) 195static int null_reader(struct driver_data *drv_data)
203{ 196{
204 void *reg = drv_data->ioaddr; 197 void *reg = drv_data->ioaddr;
205 u8 n_bytes = drv_data->n_bytes; 198 u8 n_bytes = drv_data->n_bytes;
206 199
207 while ((read_SSSR(reg) & SSSR_RNE) 200 while ((read_SSSR(reg) & SSSR_RNE)
208 && (drv_data->rx < drv_data->rx_end)) { 201 && (drv_data->rx < drv_data->rx_end)) {
209 read_SSDR(reg); 202 read_SSDR(reg);
210 drv_data->rx += n_bytes; 203 drv_data->rx += n_bytes;
211 } 204 }
205
206 return drv_data->rx == drv_data->rx_end;
212} 207}
213 208
214static void u8_writer(struct driver_data *drv_data) 209static int u8_writer(struct driver_data *drv_data)
215{ 210{
216 void *reg = drv_data->ioaddr; 211 void *reg = drv_data->ioaddr;
217 212
218 while ((read_SSSR(reg) & SSSR_TNF) 213 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
219 && (drv_data->tx < drv_data->tx_end)) { 214 || (drv_data->tx == drv_data->tx_end))
220 write_SSDR(*(u8 *)(drv_data->tx), reg); 215 return 0;
221 ++drv_data->tx; 216
222 } 217 write_SSDR(*(u8 *)(drv_data->tx), reg);
218 ++drv_data->tx;
219
220 return 1;
223} 221}
224 222
225static void u8_reader(struct driver_data *drv_data) 223static int u8_reader(struct driver_data *drv_data)
226{ 224{
227 void *reg = drv_data->ioaddr; 225 void *reg = drv_data->ioaddr;
228 226
229 while ((read_SSSR(reg) & SSSR_RNE) 227 while ((read_SSSR(reg) & SSSR_RNE)
230 && (drv_data->rx < drv_data->rx_end)) { 228 && (drv_data->rx < drv_data->rx_end)) {
231 *(u8 *)(drv_data->rx) = read_SSDR(reg); 229 *(u8 *)(drv_data->rx) = read_SSDR(reg);
232 ++drv_data->rx; 230 ++drv_data->rx;
233 } 231 }
232
233 return drv_data->rx == drv_data->rx_end;
234} 234}
235 235
236static void u16_writer(struct driver_data *drv_data) 236static int u16_writer(struct driver_data *drv_data)
237{ 237{
238 void *reg = drv_data->ioaddr; 238 void *reg = drv_data->ioaddr;
239 239
240 while ((read_SSSR(reg) & SSSR_TNF) 240 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
241 && (drv_data->tx < drv_data->tx_end)) { 241 || (drv_data->tx == drv_data->tx_end))
242 write_SSDR(*(u16 *)(drv_data->tx), reg); 242 return 0;
243 drv_data->tx += 2; 243
244 } 244 write_SSDR(*(u16 *)(drv_data->tx), reg);
245 drv_data->tx += 2;
246
247 return 1;
245} 248}
246 249
247static void u16_reader(struct driver_data *drv_data) 250static int u16_reader(struct driver_data *drv_data)
248{ 251{
249 void *reg = drv_data->ioaddr; 252 void *reg = drv_data->ioaddr;
250 253
251 while ((read_SSSR(reg) & SSSR_RNE) 254 while ((read_SSSR(reg) & SSSR_RNE)
252 && (drv_data->rx < drv_data->rx_end)) { 255 && (drv_data->rx < drv_data->rx_end)) {
253 *(u16 *)(drv_data->rx) = read_SSDR(reg); 256 *(u16 *)(drv_data->rx) = read_SSDR(reg);
254 drv_data->rx += 2; 257 drv_data->rx += 2;
255 } 258 }
259
260 return drv_data->rx == drv_data->rx_end;
256} 261}
257static void u32_writer(struct driver_data *drv_data) 262
263static int u32_writer(struct driver_data *drv_data)
258{ 264{
259 void *reg = drv_data->ioaddr; 265 void *reg = drv_data->ioaddr;
260 266
261 while ((read_SSSR(reg) & SSSR_TNF) 267 if (((read_SSSR(reg) & 0x00000f00) == 0x00000f00)
262 && (drv_data->tx < drv_data->tx_end)) { 268 || (drv_data->tx == drv_data->tx_end))
263 write_SSDR(*(u32 *)(drv_data->tx), reg); 269 return 0;
264 drv_data->tx += 4; 270
265 } 271 write_SSDR(*(u32 *)(drv_data->tx), reg);
272 drv_data->tx += 4;
273
274 return 1;
266} 275}
267 276
268static void u32_reader(struct driver_data *drv_data) 277static int u32_reader(struct driver_data *drv_data)
269{ 278{
270 void *reg = drv_data->ioaddr; 279 void *reg = drv_data->ioaddr;
271 280
272 while ((read_SSSR(reg) & SSSR_RNE) 281 while ((read_SSSR(reg) & SSSR_RNE)
273 && (drv_data->rx < drv_data->rx_end)) { 282 && (drv_data->rx < drv_data->rx_end)) {
274 *(u32 *)(drv_data->rx) = read_SSDR(reg); 283 *(u32 *)(drv_data->rx) = read_SSDR(reg);
275 drv_data->rx += 4; 284 drv_data->rx += 4;
276 } 285 }
286
287 return drv_data->rx == drv_data->rx_end;
277} 288}
278 289
279static void *next_transfer(struct driver_data *drv_data) 290static void *next_transfer(struct driver_data *drv_data)
@@ -409,166 +420,134 @@ static int wait_dma_channel_stop(int channel)
409 return limit; 420 return limit;
410} 421}
411 422
412static void dma_handler(int channel, void *data) 423void dma_error_stop(struct driver_data *drv_data, const char *msg)
413{ 424{
414 struct driver_data *drv_data = data;
415 struct spi_message *msg = drv_data->cur_msg;
416 void *reg = drv_data->ioaddr; 425 void *reg = drv_data->ioaddr;
417 u32 irq_status = DCSR(channel) & DMA_INT_MASK;
418 u32 trailing_sssr = 0;
419 426
420 if (irq_status & DCSR_BUSERR) { 427 /* Stop and reset */
428 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
429 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
430 write_SSSR(drv_data->clear_sr, reg);
431 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
432 if (drv_data->ssp_type != PXA25x_SSP)
433 write_SSTO(0, reg);
434 flush(drv_data);
435 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
421 436
422 /* Disable interrupts, clear status and reset DMA */ 437 unmap_dma_buffers(drv_data);
423 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
424 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
425 if (drv_data->ssp_type != PXA25x_SSP)
426 write_SSTO(0, reg);
427 write_SSSR(drv_data->clear_sr, reg);
428 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
429 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
430 438
431 if (flush(drv_data) == 0) 439 dev_err(&drv_data->pdev->dev, "%s\n", msg);
432 dev_err(&drv_data->pdev->dev,
433 "dma_handler: flush fail\n");
434 440
435 unmap_dma_buffers(drv_data); 441 drv_data->cur_msg->state = ERROR_STATE;
442 tasklet_schedule(&drv_data->pump_transfers);
443}
444
445static void dma_transfer_complete(struct driver_data *drv_data)
446{
447 void *reg = drv_data->ioaddr;
448 struct spi_message *msg = drv_data->cur_msg;
449
450 /* Clear and disable interrupts on SSP and DMA channels*/
451 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
452 write_SSSR(drv_data->clear_sr, reg);
453 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
454 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
455
456 if (wait_dma_channel_stop(drv_data->rx_channel) == 0)
457 dev_err(&drv_data->pdev->dev,
458 "dma_handler: dma rx channel stop failed\n");
459
460 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
461 dev_err(&drv_data->pdev->dev,
462 "dma_transfer: ssp rx stall failed\n");
463
464 unmap_dma_buffers(drv_data);
465
466 /* update the buffer pointer for the amount completed in dma */
467 drv_data->rx += drv_data->len -
468 (DCMD(drv_data->rx_channel) & DCMD_LENGTH);
469
470 /* read trailing data from fifo, it does not matter how many
471 * bytes are in the fifo just read until buffer is full
472 * or fifo is empty, which ever occurs first */
473 drv_data->read(drv_data);
474
475 /* return count of what was actually read */
476 msg->actual_length += drv_data->len -
477 (drv_data->rx_end - drv_data->rx);
478
479 /* Release chip select if requested, transfer delays are
480 * handled in pump_transfers */
481 if (drv_data->cs_change)
482 drv_data->cs_control(PXA2XX_CS_DEASSERT);
483
484 /* Move to next transfer */
485 msg->state = next_transfer(drv_data);
486
487 /* Schedule transfer tasklet */
488 tasklet_schedule(&drv_data->pump_transfers);
489}
490
491static void dma_handler(int channel, void *data)
492{
493 struct driver_data *drv_data = data;
494 u32 irq_status = DCSR(channel) & DMA_INT_MASK;
495
496 if (irq_status & DCSR_BUSERR) {
436 497
437 if (channel == drv_data->tx_channel) 498 if (channel == drv_data->tx_channel)
438 dev_err(&drv_data->pdev->dev, 499 dma_error_stop(drv_data,
439 "dma_handler: bad bus address on " 500 "dma_handler: "
440 "tx channel %d, source %x target = %x\n", 501 "bad bus address on tx channel");
441 channel, DSADR(channel), DTADR(channel));
442 else 502 else
443 dev_err(&drv_data->pdev->dev, 503 dma_error_stop(drv_data,
444 "dma_handler: bad bus address on " 504 "dma_handler: "
445 "rx channel %d, source %x target = %x\n", 505 "bad bus address on rx channel");
446 channel, DSADR(channel), DTADR(channel)); 506 return;
447
448 msg->state = ERROR_STATE;
449 tasklet_schedule(&drv_data->pump_transfers);
450 } 507 }
451 508
452 /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */ 509 /* PXA255x_SSP has no timeout interrupt, wait for tailing bytes */
453 if ((drv_data->ssp_type == PXA25x_SSP) 510 if ((channel == drv_data->tx_channel)
454 && (channel == drv_data->tx_channel) 511 && (irq_status & DCSR_ENDINTR)
455 && (irq_status & DCSR_ENDINTR)) { 512 && (drv_data->ssp_type == PXA25x_SSP)) {
456 513
457 /* Wait for rx to stall */ 514 /* Wait for rx to stall */
458 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0) 515 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
459 dev_err(&drv_data->pdev->dev, 516 dev_err(&drv_data->pdev->dev,
460 "dma_handler: ssp rx stall failed\n"); 517 "dma_handler: ssp rx stall failed\n");
461 518
462 /* Clear and disable interrupts on SSP and DMA channels*/ 519 /* finish this transfer, start the next */
463 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg); 520 dma_transfer_complete(drv_data);
464 write_SSSR(drv_data->clear_sr, reg);
465 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
466 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
467 if (wait_dma_channel_stop(drv_data->rx_channel) == 0)
468 dev_err(&drv_data->pdev->dev,
469 "dma_handler: dma rx channel stop failed\n");
470
471 unmap_dma_buffers(drv_data);
472
473 /* Read trailing bytes */
474 /* Calculate number of trailing bytes, read them */
475 trailing_sssr = read_SSSR(reg);
476 if ((trailing_sssr & 0xf008) != 0xf000) {
477 drv_data->rx = drv_data->rx_end -
478 (((trailing_sssr >> 12) & 0x0f) + 1);
479 drv_data->read(drv_data);
480 }
481 msg->actual_length += drv_data->len;
482
483 /* Release chip select if requested, transfer delays are
484 * handled in pump_transfers */
485 if (drv_data->cs_change)
486 drv_data->cs_control(PXA2XX_CS_DEASSERT);
487
488 /* Move to next transfer */
489 msg->state = next_transfer(drv_data);
490
491 /* Schedule transfer tasklet */
492 tasklet_schedule(&drv_data->pump_transfers);
493 } 521 }
494} 522}
495 523
496static irqreturn_t dma_transfer(struct driver_data *drv_data) 524static irqreturn_t dma_transfer(struct driver_data *drv_data)
497{ 525{
498 u32 irq_status; 526 u32 irq_status;
499 u32 trailing_sssr = 0;
500 struct spi_message *msg = drv_data->cur_msg;
501 void *reg = drv_data->ioaddr; 527 void *reg = drv_data->ioaddr;
502 528
503 irq_status = read_SSSR(reg) & drv_data->mask_sr; 529 irq_status = read_SSSR(reg) & drv_data->mask_sr;
504 if (irq_status & SSSR_ROR) { 530 if (irq_status & SSSR_ROR) {
505 /* Clear and disable interrupts on SSP and DMA channels*/ 531 dma_error_stop(drv_data, "dma_transfer: fifo overrun");
506 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
507 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg);
508 if (drv_data->ssp_type != PXA25x_SSP)
509 write_SSTO(0, reg);
510 write_SSSR(drv_data->clear_sr, reg);
511 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
512 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
513 unmap_dma_buffers(drv_data);
514
515 if (flush(drv_data) == 0)
516 dev_err(&drv_data->pdev->dev,
517 "dma_transfer: flush fail\n");
518
519 dev_warn(&drv_data->pdev->dev, "dma_transfer: fifo overun\n");
520
521 drv_data->cur_msg->state = ERROR_STATE;
522 tasklet_schedule(&drv_data->pump_transfers);
523
524 return IRQ_HANDLED; 532 return IRQ_HANDLED;
525 } 533 }
526 534
527 /* Check for false positive timeout */ 535 /* Check for false positive timeout */
528 if ((irq_status & SSSR_TINT) && DCSR(drv_data->tx_channel) & DCSR_RUN) { 536 if ((irq_status & SSSR_TINT)
537 && (DCSR(drv_data->tx_channel) & DCSR_RUN)) {
529 write_SSSR(SSSR_TINT, reg); 538 write_SSSR(SSSR_TINT, reg);
530 return IRQ_HANDLED; 539 return IRQ_HANDLED;
531 } 540 }
532 541
533 if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) { 542 if (irq_status & SSSR_TINT || drv_data->rx == drv_data->rx_end) {
534 543
535 /* Clear and disable interrupts on SSP and DMA channels*/ 544 /* Clear and disable timeout interrupt, do the rest in
536 write_SSCR1(read_SSCR1(reg) & ~drv_data->dma_cr1, reg); 545 * dma_transfer_complete */
537 if (drv_data->ssp_type != PXA25x_SSP) 546 if (drv_data->ssp_type != PXA25x_SSP)
538 write_SSTO(0, reg); 547 write_SSTO(0, reg);
539 write_SSSR(drv_data->clear_sr, reg);
540 DCSR(drv_data->tx_channel) = RESET_DMA_CHANNEL;
541 DCSR(drv_data->rx_channel) = RESET_DMA_CHANNEL;
542 548
543 if (wait_dma_channel_stop(drv_data->rx_channel) == 0) 549 /* finish this transfer, start the next */
544 dev_err(&drv_data->pdev->dev, 550 dma_transfer_complete(drv_data);
545 "dma_transfer: dma rx channel stop failed\n");
546
547 if (wait_ssp_rx_stall(drv_data->ioaddr) == 0)
548 dev_err(&drv_data->pdev->dev,
549 "dma_transfer: ssp rx stall failed\n");
550
551 unmap_dma_buffers(drv_data);
552
553 /* Calculate number of trailing bytes, read them */
554 trailing_sssr = read_SSSR(reg);
555 if ((trailing_sssr & 0xf008) != 0xf000) {
556 drv_data->rx = drv_data->rx_end -
557 (((trailing_sssr >> 12) & 0x0f) + 1);
558 drv_data->read(drv_data);
559 }
560 msg->actual_length += drv_data->len;
561
562 /* Release chip select if requested, transfer delays are
563 * handled in pump_transfers */
564 if (drv_data->cs_change)
565 drv_data->cs_control(PXA2XX_CS_DEASSERT);
566
567 /* Move to next transfer */
568 msg->state = next_transfer(drv_data);
569
570 /* Schedule transfer tasklet */
571 tasklet_schedule(&drv_data->pump_transfers);
572 551
573 return IRQ_HANDLED; 552 return IRQ_HANDLED;
574 } 553 }
@@ -577,89 +556,103 @@ static irqreturn_t dma_transfer(struct driver_data *drv_data)
577 return IRQ_NONE; 556 return IRQ_NONE;
578} 557}
579 558
580static irqreturn_t interrupt_transfer(struct driver_data *drv_data) 559static void int_error_stop(struct driver_data *drv_data, const char* msg)
581{ 560{
582 struct spi_message *msg = drv_data->cur_msg;
583 void *reg = drv_data->ioaddr; 561 void *reg = drv_data->ioaddr;
584 unsigned long limit = loops_per_jiffy << 1;
585 u32 irq_status;
586 u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
587 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
588
589 while ((irq_status = read_SSSR(reg) & irq_mask)) {
590
591 if (irq_status & SSSR_ROR) {
592 562
593 /* Clear and disable interrupts */ 563 /* Stop and reset SSP */
594 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg); 564 write_SSSR(drv_data->clear_sr, reg);
595 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg); 565 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
596 if (drv_data->ssp_type != PXA25x_SSP) 566 if (drv_data->ssp_type != PXA25x_SSP)
597 write_SSTO(0, reg); 567 write_SSTO(0, reg);
598 write_SSSR(drv_data->clear_sr, reg); 568 flush(drv_data);
569 write_SSCR0(read_SSCR0(reg) & ~SSCR0_SSE, reg);
599 570
600 if (flush(drv_data) == 0) 571 dev_err(&drv_data->pdev->dev, "%s\n", msg);
601 dev_err(&drv_data->pdev->dev,
602 "interrupt_transfer: flush fail\n");
603 572
604 /* Stop the SSP */ 573 drv_data->cur_msg->state = ERROR_STATE;
574 tasklet_schedule(&drv_data->pump_transfers);
575}
605 576
606 dev_warn(&drv_data->pdev->dev, 577static void int_transfer_complete(struct driver_data *drv_data)
607 "interrupt_transfer: fifo overun\n"); 578{
579 void *reg = drv_data->ioaddr;
608 580
609 msg->state = ERROR_STATE; 581 /* Stop SSP */
610 tasklet_schedule(&drv_data->pump_transfers); 582 write_SSSR(drv_data->clear_sr, reg);
583 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg);
584 if (drv_data->ssp_type != PXA25x_SSP)
585 write_SSTO(0, reg);
611 586
612 return IRQ_HANDLED; 587 /* Update total byte transfered return count actual bytes read */
613 } 588 drv_data->cur_msg->actual_length += drv_data->len -
589 (drv_data->rx_end - drv_data->rx);
614 590
615 /* Look for false positive timeout */ 591 /* Release chip select if requested, transfer delays are
616 if ((irq_status & SSSR_TINT) 592 * handled in pump_transfers */
617 && (drv_data->rx < drv_data->rx_end)) 593 if (drv_data->cs_change)
618 write_SSSR(SSSR_TINT, reg); 594 drv_data->cs_control(PXA2XX_CS_DEASSERT);
619 595
620 /* Pump data */ 596 /* Move to next transfer */
621 drv_data->read(drv_data); 597 drv_data->cur_msg->state = next_transfer(drv_data);
622 drv_data->write(drv_data);
623 598
624 if (drv_data->tx == drv_data->tx_end) { 599 /* Schedule transfer tasklet */
625 /* Disable tx interrupt */ 600 tasklet_schedule(&drv_data->pump_transfers);
626 write_SSCR1(read_SSCR1(reg) & ~SSCR1_TIE, reg); 601}
627 irq_mask = drv_data->mask_sr & ~SSSR_TFS;
628 602
629 /* PXA25x_SSP has no timeout, read trailing bytes */ 603static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
630 if (drv_data->ssp_type == PXA25x_SSP) { 604{
631 while ((read_SSSR(reg) & SSSR_BSY) && limit--) 605 void *reg = drv_data->ioaddr;
632 drv_data->read(drv_data);
633 606
634 if (limit == 0) 607 u32 irq_mask = (read_SSCR1(reg) & SSCR1_TIE) ?
635 dev_err(&drv_data->pdev->dev, 608 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
636 "interrupt_transfer: "
637 "trailing byte read failed\n");
638 }
639 }
640 609
641 if ((irq_status & SSSR_TINT) 610 u32 irq_status = read_SSSR(reg) & irq_mask;
642 || (drv_data->rx == drv_data->rx_end)) {
643 611
644 /* Clear timeout */ 612 if (irq_status & SSSR_ROR) {
645 write_SSCR1(read_SSCR1(reg) & ~drv_data->int_cr1, reg); 613 int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
646 if (drv_data->ssp_type != PXA25x_SSP) 614 return IRQ_HANDLED;
647 write_SSTO(0, reg); 615 }
648 write_SSSR(drv_data->clear_sr, reg);
649 616
650 /* Update total byte transfered */ 617 if (irq_status & SSSR_TINT) {
651 msg->actual_length += drv_data->len; 618 write_SSSR(SSSR_TINT, reg);
619 if (drv_data->read(drv_data)) {
620 int_transfer_complete(drv_data);
621 return IRQ_HANDLED;
622 }
623 }
652 624
653 /* Release chip select if requested, transfer delays are 625 /* Drain rx fifo, Fill tx fifo and prevent overruns */
654 * handled in pump_transfers */ 626 do {
655 if (drv_data->cs_change) 627 if (drv_data->read(drv_data)) {
656 drv_data->cs_control(PXA2XX_CS_DEASSERT); 628 int_transfer_complete(drv_data);
629 return IRQ_HANDLED;
630 }
631 } while (drv_data->write(drv_data));
657 632
658 /* Move to next transfer */ 633 if (drv_data->read(drv_data)) {
659 msg->state = next_transfer(drv_data); 634 int_transfer_complete(drv_data);
635 return IRQ_HANDLED;
636 }
660 637
661 /* Schedule transfer tasklet */ 638 if (drv_data->tx == drv_data->tx_end) {
662 tasklet_schedule(&drv_data->pump_transfers); 639 write_SSCR1(read_SSCR1(reg) & ~SSCR1_TIE, reg);
640 /* PXA25x_SSP has no timeout, read trailing bytes */
641 if (drv_data->ssp_type == PXA25x_SSP) {
642 if (!wait_ssp_rx_stall(reg))
643 {
644 int_error_stop(drv_data, "interrupt_transfer: "
645 "rx stall failed");
646 return IRQ_HANDLED;
647 }
648 if (!drv_data->read(drv_data))
649 {
650 int_error_stop(drv_data,
651 "interrupt_transfer: "
652 "trailing byte read failed");
653 return IRQ_HANDLED;
654 }
655 int_transfer_complete(drv_data);
663 } 656 }
664 } 657 }
665 658
@@ -681,7 +674,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
681 write_SSSR(drv_data->clear_sr, reg); 674 write_SSSR(drv_data->clear_sr, reg);
682 675
683 dev_err(&drv_data->pdev->dev, "bad message state " 676 dev_err(&drv_data->pdev->dev, "bad message state "
684 "in interrupt handler"); 677 "in interrupt handler\n");
685 678
686 /* Never fail */ 679 /* Never fail */
687 return IRQ_HANDLED; 680 return IRQ_HANDLED;
@@ -690,6 +683,102 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
690 return drv_data->transfer_handler(drv_data); 683 return drv_data->transfer_handler(drv_data);
691} 684}
692 685
686int set_dma_burst_and_threshold(struct chip_data *chip, struct spi_device *spi,
687 u8 bits_per_word, u32 *burst_code,
688 u32 *threshold)
689{
690 struct pxa2xx_spi_chip *chip_info =
691 (struct pxa2xx_spi_chip *)spi->controller_data;
692 int bytes_per_word;
693 int burst_bytes;
694 int thresh_words;
695 int req_burst_size;
696 int retval = 0;
697
698 /* Set the threshold (in registers) to equal the same amount of data
699 * as represented by burst size (in bytes). The computation below
700 * is (burst_size rounded up to nearest 8 byte, word or long word)
701 * divided by (bytes/register); the tx threshold is the inverse of
702 * the rx, so that there will always be enough data in the rx fifo
703 * to satisfy a burst, and there will always be enough space in the
704 * tx fifo to accept a burst (a tx burst will overwrite the fifo if
705 * there is not enough space), there must always remain enough empty
706 * space in the rx fifo for any data loaded to the tx fifo.
707 * Whenever burst_size (in bytes) equals bits/word, the fifo threshold
708 * will be 8, or half the fifo;
709 * The threshold can only be set to 2, 4 or 8, but not 16, because
710 * to burst 16 to the tx fifo, the fifo would have to be empty;
711 * however, the minimum fifo trigger level is 1, and the tx will
712 * request service when the fifo is at this level, with only 15 spaces.
713 */
714
715 /* find bytes/word */
716 if (bits_per_word <= 8)
717 bytes_per_word = 1;
718 else if (bits_per_word <= 16)
719 bytes_per_word = 2;
720 else
721 bytes_per_word = 4;
722
723 /* use struct pxa2xx_spi_chip->dma_burst_size if available */
724 if (chip_info)
725 req_burst_size = chip_info->dma_burst_size;
726 else {
727 switch (chip->dma_burst_size) {
728 default:
729 /* if the default burst size is not set,
730 * do it now */
731 chip->dma_burst_size = DCMD_BURST8;
732 case DCMD_BURST8:
733 req_burst_size = 8;
734 break;
735 case DCMD_BURST16:
736 req_burst_size = 16;
737 break;
738 case DCMD_BURST32:
739 req_burst_size = 32;
740 break;
741 }
742 }
743 if (req_burst_size <= 8) {
744 *burst_code = DCMD_BURST8;
745 burst_bytes = 8;
746 } else if (req_burst_size <= 16) {
747 if (bytes_per_word == 1) {
748 /* don't burst more than 1/2 the fifo */
749 *burst_code = DCMD_BURST8;
750 burst_bytes = 8;
751 retval = 1;
752 } else {
753 *burst_code = DCMD_BURST16;
754 burst_bytes = 16;
755 }
756 } else {
757 if (bytes_per_word == 1) {
758 /* don't burst more than 1/2 the fifo */
759 *burst_code = DCMD_BURST8;
760 burst_bytes = 8;
761 retval = 1;
762 } else if (bytes_per_word == 2) {
763 /* don't burst more than 1/2 the fifo */
764 *burst_code = DCMD_BURST16;
765 burst_bytes = 16;
766 retval = 1;
767 } else {
768 *burst_code = DCMD_BURST32;
769 burst_bytes = 32;
770 }
771 }
772
773 thresh_words = burst_bytes / bytes_per_word;
774
775 /* thresh_words will be between 2 and 8 */
776 *threshold = (SSCR1_RxTresh(thresh_words) & SSCR1_RFT)
777 | (SSCR1_TxTresh(16-thresh_words) & SSCR1_TFT);
778
779 return retval;
780}
781
693static void pump_transfers(unsigned long data) 782static void pump_transfers(unsigned long data)
694{ 783{
695 struct driver_data *drv_data = (struct driver_data *)data; 784 struct driver_data *drv_data = (struct driver_data *)data;
@@ -702,6 +791,9 @@ static void pump_transfers(unsigned long data)
702 u8 bits = 0; 791 u8 bits = 0;
703 u32 speed = 0; 792 u32 speed = 0;
704 u32 cr0; 793 u32 cr0;
794 u32 cr1;
795 u32 dma_thresh = drv_data->cur_chip->dma_threshold;
796 u32 dma_burst = drv_data->cur_chip->dma_burst_size;
705 797
706 /* Get current state information */ 798 /* Get current state information */
707 message = drv_data->cur_msg; 799 message = drv_data->cur_msg;
@@ -731,6 +823,16 @@ static void pump_transfers(unsigned long data)
731 udelay(previous->delay_usecs); 823 udelay(previous->delay_usecs);
732 } 824 }
733 825
826 /* Check transfer length */
827 if (transfer->len > 8191)
828 {
829 dev_warn(&drv_data->pdev->dev, "pump_transfers: transfer "
830 "length greater than 8191\n");
831 message->status = -EINVAL;
832 giveback(drv_data);
833 return;
834 }
835
734 /* Setup the transfer state based on the type of transfer */ 836 /* Setup the transfer state based on the type of transfer */
735 if (flush(drv_data) == 0) { 837 if (flush(drv_data) == 0) {
736 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n"); 838 dev_err(&drv_data->pdev->dev, "pump_transfers: flush failed\n");
@@ -747,17 +849,15 @@ static void pump_transfers(unsigned long data)
747 drv_data->rx_end = drv_data->rx + transfer->len; 849 drv_data->rx_end = drv_data->rx + transfer->len;
748 drv_data->rx_dma = transfer->rx_dma; 850 drv_data->rx_dma = transfer->rx_dma;
749 drv_data->tx_dma = transfer->tx_dma; 851 drv_data->tx_dma = transfer->tx_dma;
750 drv_data->len = transfer->len; 852 drv_data->len = transfer->len & DCMD_LENGTH;
751 drv_data->write = drv_data->tx ? chip->write : null_writer; 853 drv_data->write = drv_data->tx ? chip->write : null_writer;
752 drv_data->read = drv_data->rx ? chip->read : null_reader; 854 drv_data->read = drv_data->rx ? chip->read : null_reader;
753 drv_data->cs_change = transfer->cs_change; 855 drv_data->cs_change = transfer->cs_change;
754 856
755 /* Change speed and bit per word on a per transfer */ 857 /* Change speed and bit per word on a per transfer */
858 cr0 = chip->cr0;
756 if (transfer->speed_hz || transfer->bits_per_word) { 859 if (transfer->speed_hz || transfer->bits_per_word) {
757 860
758 /* Disable clock */
759 write_SSCR0(chip->cr0 & ~SSCR0_SSE, reg);
760 cr0 = chip->cr0;
761 bits = chip->bits_per_word; 861 bits = chip->bits_per_word;
762 speed = chip->speed_hz; 862 speed = chip->speed_hz;
763 863
@@ -796,15 +896,24 @@ static void pump_transfers(unsigned long data)
796 drv_data->write = drv_data->write != null_writer ? 896 drv_data->write = drv_data->write != null_writer ?
797 u32_writer : null_writer; 897 u32_writer : null_writer;
798 } 898 }
899 /* if bits/word is changed in dma mode, then must check the
900 * thresholds and burst also */
901 if (chip->enable_dma) {
902 if (set_dma_burst_and_threshold(chip, message->spi,
903 bits, &dma_burst,
904 &dma_thresh))
905 if (printk_ratelimit())
906 dev_warn(&message->spi->dev,
907 "pump_transfer: "
908 "DMA burst size reduced to "
909 "match bits_per_word\n");
910 }
799 911
800 cr0 = clk_div 912 cr0 = clk_div
801 | SSCR0_Motorola 913 | SSCR0_Motorola
802 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits) 914 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
803 | SSCR0_SSE 915 | SSCR0_SSE
804 | (bits > 16 ? SSCR0_EDSS : 0); 916 | (bits > 16 ? SSCR0_EDSS : 0);
805
806 /* Start it back up */
807 write_SSCR0(cr0, reg);
808 } 917 }
809 918
810 message->state = RUNNING_STATE; 919 message->state = RUNNING_STATE;
@@ -823,13 +932,13 @@ static void pump_transfers(unsigned long data)
823 /* No target address increment */ 932 /* No target address increment */
824 DCMD(drv_data->rx_channel) = DCMD_FLOWSRC 933 DCMD(drv_data->rx_channel) = DCMD_FLOWSRC
825 | drv_data->dma_width 934 | drv_data->dma_width
826 | chip->dma_burst_size 935 | dma_burst
827 | drv_data->len; 936 | drv_data->len;
828 else 937 else
829 DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR 938 DCMD(drv_data->rx_channel) = DCMD_INCTRGADDR
830 | DCMD_FLOWSRC 939 | DCMD_FLOWSRC
831 | drv_data->dma_width 940 | drv_data->dma_width
832 | chip->dma_burst_size 941 | dma_burst
833 | drv_data->len; 942 | drv_data->len;
834 943
835 /* Setup tx DMA Channel */ 944 /* Setup tx DMA Channel */
@@ -840,13 +949,13 @@ static void pump_transfers(unsigned long data)
840 /* No source address increment */ 949 /* No source address increment */
841 DCMD(drv_data->tx_channel) = DCMD_FLOWTRG 950 DCMD(drv_data->tx_channel) = DCMD_FLOWTRG
842 | drv_data->dma_width 951 | drv_data->dma_width
843 | chip->dma_burst_size 952 | dma_burst
844 | drv_data->len; 953 | drv_data->len;
845 else 954 else
846 DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR 955 DCMD(drv_data->tx_channel) = DCMD_INCSRCADDR
847 | DCMD_FLOWTRG 956 | DCMD_FLOWTRG
848 | drv_data->dma_width 957 | drv_data->dma_width
849 | chip->dma_burst_size 958 | dma_burst
850 | drv_data->len; 959 | drv_data->len;
851 960
852 /* Enable dma end irqs on SSP to detect end of transfer */ 961 /* Enable dma end irqs on SSP to detect end of transfer */
@@ -856,16 +965,11 @@ static void pump_transfers(unsigned long data)
856 /* Fix me, need to handle cs polarity */ 965 /* Fix me, need to handle cs polarity */
857 drv_data->cs_control(PXA2XX_CS_ASSERT); 966 drv_data->cs_control(PXA2XX_CS_ASSERT);
858 967
859 /* Go baby, go */ 968 /* Clear status and start DMA engine */
969 cr1 = chip->cr1 | dma_thresh | drv_data->dma_cr1;
860 write_SSSR(drv_data->clear_sr, reg); 970 write_SSSR(drv_data->clear_sr, reg);
861 DCSR(drv_data->rx_channel) |= DCSR_RUN; 971 DCSR(drv_data->rx_channel) |= DCSR_RUN;
862 DCSR(drv_data->tx_channel) |= DCSR_RUN; 972 DCSR(drv_data->tx_channel) |= DCSR_RUN;
863 if (drv_data->ssp_type != PXA25x_SSP)
864 write_SSTO(chip->timeout, reg);
865 write_SSCR1(chip->cr1
866 | chip->dma_threshold
867 | drv_data->dma_cr1,
868 reg);
869 } else { 973 } else {
870 /* Ensure we have the correct interrupt handler */ 974 /* Ensure we have the correct interrupt handler */
871 drv_data->transfer_handler = interrupt_transfer; 975 drv_data->transfer_handler = interrupt_transfer;
@@ -873,14 +977,25 @@ static void pump_transfers(unsigned long data)
873 /* Fix me, need to handle cs polarity */ 977 /* Fix me, need to handle cs polarity */
874 drv_data->cs_control(PXA2XX_CS_ASSERT); 978 drv_data->cs_control(PXA2XX_CS_ASSERT);
875 979
876 /* Go baby, go */ 980 /* Clear status */
981 cr1 = chip->cr1 | chip->threshold | drv_data->int_cr1;
877 write_SSSR(drv_data->clear_sr, reg); 982 write_SSSR(drv_data->clear_sr, reg);
983 }
984
985 /* see if we need to reload the config registers */
986 if ((read_SSCR0(reg) != cr0)
987 || (read_SSCR1(reg) & SSCR1_CHANGE_MASK) !=
988 (cr1 & SSCR1_CHANGE_MASK)) {
989
990 write_SSCR0(cr0 & ~SSCR0_SSE, reg);
878 if (drv_data->ssp_type != PXA25x_SSP) 991 if (drv_data->ssp_type != PXA25x_SSP)
879 write_SSTO(chip->timeout, reg); 992 write_SSTO(chip->timeout, reg);
880 write_SSCR1(chip->cr1 993 write_SSCR1(cr1, reg);
881 | chip->threshold 994 write_SSCR0(cr0, reg);
882 | drv_data->int_cr1, 995 } else {
883 reg); 996 if (drv_data->ssp_type != PXA25x_SSP)
997 write_SSTO(chip->timeout, reg);
998 write_SSCR1(cr1, reg);
884 } 999 }
885} 1000}
886 1001
@@ -915,9 +1030,9 @@ static void pump_messages(struct work_struct *work)
915 struct spi_transfer, 1030 struct spi_transfer,
916 transfer_list); 1031 transfer_list);
917 1032
918 /* Setup the SSP using the per chip configuration */ 1033 /* prepare to setup the SSP, in pump_transfers, using the per
1034 * chip configuration */
919 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi); 1035 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
920 restore_state(drv_data);
921 1036
922 /* Mark as busy and launch transfers */ 1037 /* Mark as busy and launch transfers */
923 tasklet_schedule(&drv_data->pump_transfers); 1038 tasklet_schedule(&drv_data->pump_transfers);
@@ -963,63 +1078,77 @@ static int setup(struct spi_device *spi)
963 spi->bits_per_word = 8; 1078 spi->bits_per_word = 8;
964 1079
965 if (drv_data->ssp_type != PXA25x_SSP 1080 if (drv_data->ssp_type != PXA25x_SSP
966 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) 1081 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
1082 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1083 "b/w not 4-32 for type non-PXA25x_SSP\n",
1084 drv_data->ssp_type, spi->bits_per_word);
967 return -EINVAL; 1085 return -EINVAL;
968 else if (spi->bits_per_word < 4 || spi->bits_per_word > 16) 1086 }
1087 else if (drv_data->ssp_type == PXA25x_SSP
1088 && (spi->bits_per_word < 4
1089 || spi->bits_per_word > 16)) {
1090 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
1091 "b/w not 4-16 for type PXA25x_SSP\n",
1092 drv_data->ssp_type, spi->bits_per_word);
969 return -EINVAL; 1093 return -EINVAL;
1094 }
970 1095
971 /* Only alloc (or use chip_info) on first setup */ 1096 /* Only alloc on first setup */
972 chip = spi_get_ctldata(spi); 1097 chip = spi_get_ctldata(spi);
973 if (chip == NULL) { 1098 if (!chip) {
974 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); 1099 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
975 if (!chip) 1100 if (!chip) {
1101 dev_err(&spi->dev,
1102 "failed setup: can't allocate chip data\n");
976 return -ENOMEM; 1103 return -ENOMEM;
1104 }
977 1105
978 chip->cs_control = null_cs_control; 1106 chip->cs_control = null_cs_control;
979 chip->enable_dma = 0; 1107 chip->enable_dma = 0;
980 chip->timeout = SSP_TIMEOUT(1000); 1108 chip->timeout = 1000;
981 chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1); 1109 chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1);
982 chip->dma_burst_size = drv_data->master_info->enable_dma ? 1110 chip->dma_burst_size = drv_data->master_info->enable_dma ?
983 DCMD_BURST8 : 0; 1111 DCMD_BURST8 : 0;
984
985 chip_info = spi->controller_data;
986 } 1112 }
987 1113
1114 /* protocol drivers may change the chip settings, so...
1115 * if chip_info exists, use it */
1116 chip_info = spi->controller_data;
1117
988 /* chip_info isn't always needed */ 1118 /* chip_info isn't always needed */
1119 chip->cr1 = 0;
989 if (chip_info) { 1120 if (chip_info) {
990 if (chip_info->cs_control) 1121 if (chip_info->cs_control)
991 chip->cs_control = chip_info->cs_control; 1122 chip->cs_control = chip_info->cs_control;
992 1123
993 chip->timeout = SSP_TIMEOUT(chip_info->timeout_microsecs); 1124 chip->timeout = chip_info->timeout;
994 1125
995 chip->threshold = SSCR1_RxTresh(chip_info->rx_threshold) 1126 chip->threshold = (SSCR1_RxTresh(chip_info->rx_threshold) &
996 | SSCR1_TxTresh(chip_info->tx_threshold); 1127 SSCR1_RFT) |
1128 (SSCR1_TxTresh(chip_info->tx_threshold) &
1129 SSCR1_TFT);
997 1130
998 chip->enable_dma = chip_info->dma_burst_size != 0 1131 chip->enable_dma = chip_info->dma_burst_size != 0
999 && drv_data->master_info->enable_dma; 1132 && drv_data->master_info->enable_dma;
1000 chip->dma_threshold = 0; 1133 chip->dma_threshold = 0;
1001 1134
1002 if (chip->enable_dma) {
1003 if (chip_info->dma_burst_size <= 8) {
1004 chip->dma_threshold = SSCR1_RxTresh(8)
1005 | SSCR1_TxTresh(8);
1006 chip->dma_burst_size = DCMD_BURST8;
1007 } else if (chip_info->dma_burst_size <= 16) {
1008 chip->dma_threshold = SSCR1_RxTresh(16)
1009 | SSCR1_TxTresh(16);
1010 chip->dma_burst_size = DCMD_BURST16;
1011 } else {
1012 chip->dma_threshold = SSCR1_RxTresh(32)
1013 | SSCR1_TxTresh(32);
1014 chip->dma_burst_size = DCMD_BURST32;
1015 }
1016 }
1017
1018
1019 if (chip_info->enable_loopback) 1135 if (chip_info->enable_loopback)
1020 chip->cr1 = SSCR1_LBM; 1136 chip->cr1 = SSCR1_LBM;
1021 } 1137 }
1022 1138
1139 /* set dma burst and threshold outside of chip_info path so that if
1140 * chip_info goes away after setting chip->enable_dma, the
1141 * burst and threshold can still respond to changes in bits_per_word */
1142 if (chip->enable_dma) {
1143 /* set up legal burst and threshold for dma */
1144 if (set_dma_burst_and_threshold(chip, spi, spi->bits_per_word,
1145 &chip->dma_burst_size,
1146 &chip->dma_threshold)) {
1147 dev_warn(&spi->dev, "in setup: DMA burst size reduced "
1148 "to match bits_per_word\n");
1149 }
1150 }
1151
1023 if (drv_data->ioaddr == SSP1_VIRT) 1152 if (drv_data->ioaddr == SSP1_VIRT)
1024 clk_div = SSP1_SerClkDiv(spi->max_speed_hz); 1153 clk_div = SSP1_SerClkDiv(spi->max_speed_hz);
1025 else if (drv_data->ioaddr == SSP2_VIRT) 1154 else if (drv_data->ioaddr == SSP2_VIRT)
@@ -1027,7 +1156,11 @@ static int setup(struct spi_device *spi)
1027 else if (drv_data->ioaddr == SSP3_VIRT) 1156 else if (drv_data->ioaddr == SSP3_VIRT)
1028 clk_div = SSP3_SerClkDiv(spi->max_speed_hz); 1157 clk_div = SSP3_SerClkDiv(spi->max_speed_hz);
1029 else 1158 else
1159 {
1160 dev_err(&spi->dev, "failed setup: unknown IO address=0x%p\n",
1161 drv_data->ioaddr);
1030 return -ENODEV; 1162 return -ENODEV;
1163 }
1031 chip->speed_hz = spi->max_speed_hz; 1164 chip->speed_hz = spi->max_speed_hz;
1032 1165
1033 chip->cr0 = clk_div 1166 chip->cr0 = clk_div
@@ -1071,7 +1204,6 @@ static int setup(struct spi_device *spi)
1071 chip->write = u32_writer; 1204 chip->write = u32_writer;
1072 } else { 1205 } else {
1073 dev_err(&spi->dev, "invalid wordsize\n"); 1206 dev_err(&spi->dev, "invalid wordsize\n");
1074 kfree(chip);
1075 return -ENODEV; 1207 return -ENODEV;
1076 } 1208 }
1077 chip->bits_per_word = spi->bits_per_word; 1209 chip->bits_per_word = spi->bits_per_word;
@@ -1162,6 +1294,12 @@ static int destroy_queue(struct driver_data *drv_data)
1162 int status; 1294 int status;
1163 1295
1164 status = stop_queue(drv_data); 1296 status = stop_queue(drv_data);
1297 /* we are unloading the module or failing to load (only two calls
1298 * to this routine), and neither call can handle a return value.
1299 * However, destroy_workqueue calls flush_workqueue, and that will
1300 * block until all work is done. If the reason that stop_queue
1301 * timed out is that the work will never finish, then it does no
1302 * good to call destroy_workqueue, so return anyway. */
1165 if (status != 0) 1303 if (status != 0)
1166 return status; 1304 return status;
1167 1305
@@ -1360,7 +1498,16 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
1360 /* Remove the queue */ 1498 /* Remove the queue */
1361 status = destroy_queue(drv_data); 1499 status = destroy_queue(drv_data);
1362 if (status != 0) 1500 if (status != 0)
1363 return status; 1501 /* the kernel does not check the return status of this
1502 * this routine (mod->exit, within the kernel). Therefore
1503 * nothing is gained by returning from here, the module is
1504 * going away regardless, and we should not leave any more
1505 * resources allocated than necessary. We cannot free the
1506 * message memory in drv_data->queue, but we can release the
1507 * resources below. I think the kernel should honor -EBUSY
1508 * returns but... */
1509 dev_err(&pdev->dev, "pxa2xx_spi_remove: workqueue will not "
1510 "complete, message memory not freed\n");
1364 1511
1365 /* Disable the SSP at the peripheral and SOC level */ 1512 /* Disable the SSP at the peripheral and SOC level */
1366 write_SSCR0(0, drv_data->ioaddr); 1513 write_SSCR0(0, drv_data->ioaddr);
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index 792becdfe6f8..fc3197273663 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -1238,7 +1238,7 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
1238 return 0; 1238 return 0;
1239} 1239}
1240 1240
1241static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios) 1241static void rs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1242{ 1242{
1243 struct dec_serial *info = (struct dec_serial *)tty->driver_data; 1243 struct dec_serial *info = (struct dec_serial *)tty->driver_data;
1244 int was_stopped; 1244 int was_stopped;
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index 1b601b6cf2a2..df4cc1fb5f68 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -2747,7 +2747,7 @@ static void alaw2ulaw(unsigned char *buff, unsigned long len)
2747static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos) 2747static ssize_t ixj_read(struct file * file_p, char __user *buf, size_t length, loff_t * ppos)
2748{ 2748{
2749 unsigned long i = *ppos; 2749 unsigned long i = *ppos;
2750 IXJ * j = get_ixj(NUM(file_p->f_dentry->d_inode)); 2750 IXJ * j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2751 2751
2752 DECLARE_WAITQUEUE(wait, current); 2752 DECLARE_WAITQUEUE(wait, current);
2753 2753
@@ -2804,7 +2804,7 @@ static ssize_t ixj_enhanced_read(struct file * file_p, char __user *buf, size_t
2804{ 2804{
2805 int pre_retval; 2805 int pre_retval;
2806 ssize_t read_retval = 0; 2806 ssize_t read_retval = 0;
2807 IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode)); 2807 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2808 2808
2809 pre_retval = ixj_PreRead(j, 0L); 2809 pre_retval = ixj_PreRead(j, 0L);
2810 switch (pre_retval) { 2810 switch (pre_retval) {
@@ -2883,7 +2883,7 @@ static ssize_t ixj_enhanced_write(struct file * file_p, const char __user *buf,
2883 int pre_retval; 2883 int pre_retval;
2884 ssize_t write_retval = 0; 2884 ssize_t write_retval = 0;
2885 2885
2886 IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode)); 2886 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
2887 2887
2888 pre_retval = ixj_PreWrite(j, 0L); 2888 pre_retval = ixj_PreWrite(j, 0L);
2889 switch (pre_retval) { 2889 switch (pre_retval) {
@@ -4582,7 +4582,7 @@ static unsigned int ixj_poll(struct file *file_p, poll_table * wait)
4582{ 4582{
4583 unsigned int mask = 0; 4583 unsigned int mask = 0;
4584 4584
4585 IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode)); 4585 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
4586 4586
4587 poll_wait(file_p, &(j->poll_q), wait); 4587 poll_wait(file_p, &(j->poll_q), wait);
4588 if (j->read_buffer_ready > 0) 4588 if (j->read_buffer_ready > 0)
@@ -6657,7 +6657,7 @@ static int ixj_ioctl(struct inode *inode, struct file *file_p, unsigned int cmd,
6657 6657
6658static int ixj_fasync(int fd, struct file *file_p, int mode) 6658static int ixj_fasync(int fd, struct file *file_p, int mode)
6659{ 6659{
6660 IXJ *j = get_ixj(NUM(file_p->f_dentry->d_inode)); 6660 IXJ *j = get_ixj(NUM(file_p->f_path.dentry->d_inode));
6661 6661
6662 return fasync_helper(fd, file_p, mode, &j->async_queue); 6662 return fasync_helper(fd, file_p, mode, &j->async_queue);
6663} 6663}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 7f1fa956dcdb..98199628e394 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -677,10 +677,10 @@ static const __u8 acm_tty_size[] = {
677 5, 6, 7, 8 677 5, 6, 7, 8
678}; 678};
679 679
680static void acm_tty_set_termios(struct tty_struct *tty, struct termios *termios_old) 680static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old)
681{ 681{
682 struct acm *acm = tty->driver_data; 682 struct acm *acm = tty->driver_data;
683 struct termios *termios = tty->termios; 683 struct ktermios *termios = tty->termios;
684 struct usb_cdc_line_coding newline; 684 struct usb_cdc_line_coding newline;
685 int newctrl = acm->ctrlout; 685 int newctrl = acm->ctrlout;
686 686
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index b5d6a79af0be..11dad22da41c 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -379,7 +379,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
379{ 379{
380 loff_t retval = -EINVAL; 380 loff_t retval = -EINVAL;
381 381
382 mutex_lock(&file->f_dentry->d_inode->i_mutex); 382 mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
383 switch(orig) { 383 switch(orig) {
384 case 0: 384 case 0:
385 if (offset > 0) { 385 if (offset > 0) {
@@ -396,7 +396,7 @@ static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
396 default: 396 default:
397 break; 397 break;
398 } 398 }
399 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 399 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
400 return retval; 400 return retval;
401} 401}
402 402
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index c98316ce8384..a265e262a2ee 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -1909,10 +1909,10 @@ static int fsync_sub(struct lun *curlun)
1909 if (!filp->f_op->fsync) 1909 if (!filp->f_op->fsync)
1910 return -EINVAL; 1910 return -EINVAL;
1911 1911
1912 inode = filp->f_dentry->d_inode; 1912 inode = filp->f_path.dentry->d_inode;
1913 mutex_lock(&inode->i_mutex); 1913 mutex_lock(&inode->i_mutex);
1914 rc = filemap_fdatawrite(inode->i_mapping); 1914 rc = filemap_fdatawrite(inode->i_mapping);
1915 err = filp->f_op->fsync(filp, filp->f_dentry, 1); 1915 err = filp->f_op->fsync(filp, filp->f_path.dentry, 1);
1916 if (!rc) 1916 if (!rc)
1917 rc = err; 1917 rc = err;
1918 err = filemap_fdatawait(inode->i_mapping); 1918 err = filemap_fdatawait(inode->i_mapping);
@@ -1950,7 +1950,7 @@ static int do_synchronize_cache(struct fsg_dev *fsg)
1950static void invalidate_sub(struct lun *curlun) 1950static void invalidate_sub(struct lun *curlun)
1951{ 1951{
1952 struct file *filp = curlun->filp; 1952 struct file *filp = curlun->filp;
1953 struct inode *inode = filp->f_dentry->d_inode; 1953 struct inode *inode = filp->f_path.dentry->d_inode;
1954 unsigned long rc; 1954 unsigned long rc;
1955 1955
1956 rc = invalidate_inode_pages(inode->i_mapping); 1956 rc = invalidate_inode_pages(inode->i_mapping);
@@ -3526,8 +3526,8 @@ static int open_backing_file(struct lun *curlun, const char *filename)
3526 if (!(filp->f_mode & FMODE_WRITE)) 3526 if (!(filp->f_mode & FMODE_WRITE))
3527 ro = 1; 3527 ro = 1;
3528 3528
3529 if (filp->f_dentry) 3529 if (filp->f_path.dentry)
3530 inode = filp->f_dentry->d_inode; 3530 inode = filp->f_path.dentry->d_inode;
3531 if (inode && S_ISBLK(inode->i_mode)) { 3531 if (inode && S_ISBLK(inode->i_mode)) {
3532 if (bdev_read_only(inode->i_bdev)) 3532 if (bdev_read_only(inode->i_bdev))
3533 ro = 1; 3533 ro = 1;
@@ -3606,7 +3606,7 @@ static ssize_t show_file(struct device *dev, struct device_attribute *attr, char
3606 3606
3607 down_read(&fsg->filesem); 3607 down_read(&fsg->filesem);
3608 if (backing_file_is_open(curlun)) { // Get the complete pathname 3608 if (backing_file_is_open(curlun)) { // Get the complete pathname
3609 p = d_path(curlun->filp->f_dentry, curlun->filp->f_vfsmnt, 3609 p = d_path(curlun->filp->f_path.dentry, curlun->filp->f_path.mnt,
3610 buf, PAGE_SIZE - 1); 3610 buf, PAGE_SIZE - 1);
3611 if (IS_ERR(p)) 3611 if (IS_ERR(p))
3612 rc = PTR_ERR(p); 3612 rc = PTR_ERR(p);
@@ -4030,8 +4030,8 @@ static int __init fsg_bind(struct usb_gadget *gadget)
4030 if (backing_file_is_open(curlun)) { 4030 if (backing_file_is_open(curlun)) {
4031 p = NULL; 4031 p = NULL;
4032 if (pathbuf) { 4032 if (pathbuf) {
4033 p = d_path(curlun->filp->f_dentry, 4033 p = d_path(curlun->filp->f_path.dentry,
4034 curlun->filp->f_vfsmnt, 4034 curlun->filp->f_path.mnt,
4035 pathbuf, PATH_MAX); 4035 pathbuf, PATH_MAX);
4036 if (IS_ERR(p)) 4036 if (IS_ERR(p))
4037 p = NULL; 4037 p = NULL;
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 208e55a667ac..5516c59ed5ec 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -200,7 +200,7 @@ static void gs_unthrottle(struct tty_struct * tty);
200static void gs_break(struct tty_struct *tty, int break_state); 200static void gs_break(struct tty_struct *tty, int break_state);
201static int gs_ioctl(struct tty_struct *tty, struct file *file, 201static int gs_ioctl(struct tty_struct *tty, struct file *file,
202 unsigned int cmd, unsigned long arg); 202 unsigned int cmd, unsigned long arg);
203static void gs_set_termios(struct tty_struct *tty, struct termios *old); 203static void gs_set_termios(struct tty_struct *tty, struct ktermios *old);
204 204
205static int gs_send(struct gs_dev *dev); 205static int gs_send(struct gs_dev *dev);
206static int gs_send_packet(struct gs_dev *dev, char *packet, 206static int gs_send_packet(struct gs_dev *dev, char *packet,
@@ -1077,7 +1077,7 @@ static int gs_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd,
1077/* 1077/*
1078 * gs_set_termios 1078 * gs_set_termios
1079 */ 1079 */
1080static void gs_set_termios(struct tty_struct *tty, struct termios *old) 1080static void gs_set_termios(struct tty_struct *tty, struct ktermios *old)
1081{ 1081{
1082} 1082}
1083 1083
diff --git a/drivers/usb/input/Kconfig b/drivers/usb/input/Kconfig
index 661af7aa6236..8a62d4785755 100644
--- a/drivers/usb/input/Kconfig
+++ b/drivers/usb/input/Kconfig
@@ -6,9 +6,10 @@ comment "USB Input Devices"
6 6
7config USB_HID 7config USB_HID
8 tristate "USB Human Interface Device (full HID) support" 8 tristate "USB Human Interface Device (full HID) support"
9 depends on USB 9 default y
10 depends on USB && HID
10 ---help--- 11 ---help---
11 Say Y here if you want full HID support to connect keyboards, 12 Say Y here if you want full HID support to connect USB keyboards,
12 mice, joysticks, graphic tablets, or any other HID based devices 13 mice, joysticks, graphic tablets, or any other HID based devices
13 to your computer via USB. You also need to select HID Input layer 14 to your computer via USB. You also need to select HID Input layer
14 support (below) if you want to use keyboards, mice, joysticks and 15 support (below) if you want to use keyboards, mice, joysticks and
@@ -27,20 +28,10 @@ config USB_HID
27comment "Input core support is needed for USB HID input layer or HIDBP support" 28comment "Input core support is needed for USB HID input layer or HIDBP support"
28 depends on USB_HID && INPUT=n 29 depends on USB_HID && INPUT=n
29 30
30config USB_HIDINPUT 31config USB_HID_POWERBOOK
31 bool "HID input layer support"
32 default y
33 depends on INPUT && USB_HID
34 help
35 Say Y here if you want to use a USB keyboard, mouse or joystick,
36 or any other HID input device.
37
38 If unsure, say Y.
39
40config USB_HIDINPUT_POWERBOOK
41 bool "Enable support for iBook/PowerBook special keys" 32 bool "Enable support for iBook/PowerBook special keys"
42 default n 33 default n
43 depends on USB_HIDINPUT 34 depends on USB_HID
44 help 35 help
45 Say Y here if you want support for the special keys (Fn, Numlock) on 36 Say Y here if you want support for the special keys (Fn, Numlock) on
46 Apple iBooks and PowerBooks. 37 Apple iBooks and PowerBooks.
@@ -49,7 +40,7 @@ config USB_HIDINPUT_POWERBOOK
49 40
50config HID_FF 41config HID_FF
51 bool "Force feedback support (EXPERIMENTAL)" 42 bool "Force feedback support (EXPERIMENTAL)"
52 depends on USB_HIDINPUT && EXPERIMENTAL 43 depends on USB_HID && EXPERIMENTAL
53 help 44 help
54 Say Y here is you want force feedback support for a few HID devices. 45 Say Y here is you want force feedback support for a few HID devices.
55 See below for a list of supported devices. 46 See below for a list of supported devices.
diff --git a/drivers/usb/input/Makefile b/drivers/usb/input/Makefile
index d946d5213b30..1a24b5bfa05f 100644
--- a/drivers/usb/input/Makefile
+++ b/drivers/usb/input/Makefile
@@ -11,9 +11,6 @@ usbhid-objs := hid-core.o
11ifeq ($(CONFIG_USB_HIDDEV),y) 11ifeq ($(CONFIG_USB_HIDDEV),y)
12 usbhid-objs += hiddev.o 12 usbhid-objs += hiddev.o
13endif 13endif
14ifeq ($(CONFIG_USB_HIDINPUT),y)
15 usbhid-objs += hid-input.o
16endif
17ifeq ($(CONFIG_HID_PID),y) 14ifeq ($(CONFIG_HID_PID),y)
18 usbhid-objs += hid-pidff.o 15 usbhid-objs += hid-pidff.o
19endif 16endif
diff --git a/drivers/usb/input/appletouch.c b/drivers/usb/input/appletouch.c
index 4c213513484d..c77291d3d063 100644
--- a/drivers/usb/input/appletouch.c
+++ b/drivers/usb/input/appletouch.c
@@ -38,14 +38,29 @@
38#define APPLE_VENDOR_ID 0x05AC 38#define APPLE_VENDOR_ID 0x05AC
39 39
40/* These names come from Info.plist in AppleUSBTrackpad.kext */ 40/* These names come from Info.plist in AppleUSBTrackpad.kext */
41#define GEYSER_ANSI_PRODUCT_ID 0x0214 41#define FOUNTAIN_ANSI_PRODUCT_ID 0x020E
42#define GEYSER_ISO_PRODUCT_ID 0x0215 42#define FOUNTAIN_ISO_PRODUCT_ID 0x020F
43#define GEYSER_JIS_PRODUCT_ID 0x0216 43
44#define FOUNTAIN_TP_ONLY_PRODUCT_ID 0x030A
45
46#define GEYSER1_TP_ONLY_PRODUCT_ID 0x030B
47
48#define GEYSER_ANSI_PRODUCT_ID 0x0214
49#define GEYSER_ISO_PRODUCT_ID 0x0215
50#define GEYSER_JIS_PRODUCT_ID 0x0216
44 51
45/* MacBook devices */ 52/* MacBook devices */
46#define GEYSER3_ANSI_PRODUCT_ID 0x0217 53#define GEYSER3_ANSI_PRODUCT_ID 0x0217
47#define GEYSER3_ISO_PRODUCT_ID 0x0218 54#define GEYSER3_ISO_PRODUCT_ID 0x0218
48#define GEYSER3_JIS_PRODUCT_ID 0x0219 55#define GEYSER3_JIS_PRODUCT_ID 0x0219
56
57/*
58 * Geyser IV: same as Geyser III according to Info.plist in AppleUSBTrackpad.kext
59 * -> same IOClass (AppleUSBGrIIITrackpad), same acceleration tables
60 */
61#define GEYSER4_ANSI_PRODUCT_ID 0x021A
62#define GEYSER4_ISO_PRODUCT_ID 0x021B
63#define GEYSER4_JIS_PRODUCT_ID 0x021C
49 64
50#define ATP_DEVICE(prod) \ 65#define ATP_DEVICE(prod) \
51 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ 66 .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
@@ -58,20 +73,26 @@
58 73
59/* table of devices that work with this driver */ 74/* table of devices that work with this driver */
60static struct usb_device_id atp_table [] = { 75static struct usb_device_id atp_table [] = {
61 { ATP_DEVICE(0x020E) }, 76 { ATP_DEVICE(FOUNTAIN_ANSI_PRODUCT_ID) },
62 { ATP_DEVICE(0x020F) }, 77 { ATP_DEVICE(FOUNTAIN_ISO_PRODUCT_ID) },
63 { ATP_DEVICE(0x030A) }, 78 { ATP_DEVICE(FOUNTAIN_TP_ONLY_PRODUCT_ID) },
64 { ATP_DEVICE(0x030B) }, 79 { ATP_DEVICE(GEYSER1_TP_ONLY_PRODUCT_ID) },
65 80
66 /* PowerBooks Oct 2005 */ 81 /* PowerBooks Oct 2005 */
67 { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) }, 82 { ATP_DEVICE(GEYSER_ANSI_PRODUCT_ID) },
68 { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) }, 83 { ATP_DEVICE(GEYSER_ISO_PRODUCT_ID) },
69 { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) }, 84 { ATP_DEVICE(GEYSER_JIS_PRODUCT_ID) },
70 85
86 /* Core Duo MacBook & MacBook Pro */
71 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) }, 87 { ATP_DEVICE(GEYSER3_ANSI_PRODUCT_ID) },
72 { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) }, 88 { ATP_DEVICE(GEYSER3_ISO_PRODUCT_ID) },
73 { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) }, 89 { ATP_DEVICE(GEYSER3_JIS_PRODUCT_ID) },
74 90
91 /* Core2 Duo MacBook & MacBook Pro */
92 { ATP_DEVICE(GEYSER4_ANSI_PRODUCT_ID) },
93 { ATP_DEVICE(GEYSER4_ISO_PRODUCT_ID) },
94 { ATP_DEVICE(GEYSER4_JIS_PRODUCT_ID) },
95
75 /* Terminating entry */ 96 /* Terminating entry */
76 { } 97 { }
77}; 98};
@@ -108,7 +129,7 @@ MODULE_DEVICE_TABLE (usb, atp_table);
108 */ 129 */
109#define ATP_THRESHOLD 5 130#define ATP_THRESHOLD 5
110 131
111/* MacBook Pro (Geyser 3) initialization constants */ 132/* MacBook Pro (Geyser 3 & 4) initialization constants */
112#define ATP_GEYSER3_MODE_READ_REQUEST_ID 1 133#define ATP_GEYSER3_MODE_READ_REQUEST_ID 1
113#define ATP_GEYSER3_MODE_WRITE_REQUEST_ID 9 134#define ATP_GEYSER3_MODE_WRITE_REQUEST_ID 9
114#define ATP_GEYSER3_MODE_REQUEST_VALUE 0x300 135#define ATP_GEYSER3_MODE_REQUEST_VALUE 0x300
@@ -154,6 +175,13 @@ MODULE_AUTHOR("Johannes Berg, Stelian Pop, Frank Arnold, Michael Hanselmann");
154MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver"); 175MODULE_DESCRIPTION("Apple PowerBooks USB touchpad driver");
155MODULE_LICENSE("GPL"); 176MODULE_LICENSE("GPL");
156 177
178/*
179 * Make the threshold a module parameter
180 */
181static int threshold = ATP_THRESHOLD;
182module_param(threshold, int, 0644);
183MODULE_PARM_DESC(threshold, "Discards any change in data from a sensor (trackpad has hundreds of these sensors) less than this value");
184
157static int debug = 1; 185static int debug = 1;
158module_param(debug, int, 0644); 186module_param(debug, int, 0644);
159MODULE_PARM_DESC(debug, "Activate debugging output"); 187MODULE_PARM_DESC(debug, "Activate debugging output");
@@ -174,7 +202,10 @@ static inline int atp_is_geyser_3(struct atp *dev)
174 202
175 return (productId == GEYSER3_ANSI_PRODUCT_ID) || 203 return (productId == GEYSER3_ANSI_PRODUCT_ID) ||
176 (productId == GEYSER3_ISO_PRODUCT_ID) || 204 (productId == GEYSER3_ISO_PRODUCT_ID) ||
177 (productId == GEYSER3_JIS_PRODUCT_ID); 205 (productId == GEYSER3_JIS_PRODUCT_ID) ||
206 (productId == GEYSER4_ANSI_PRODUCT_ID) ||
207 (productId == GEYSER4_ISO_PRODUCT_ID) ||
208 (productId == GEYSER4_JIS_PRODUCT_ID);
178} 209}
179 210
180static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact, 211static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
@@ -183,16 +214,48 @@ static int atp_calculate_abs(int *xy_sensors, int nb_sensors, int fact,
183 int i; 214 int i;
184 /* values to calculate mean */ 215 /* values to calculate mean */
185 int pcum = 0, psum = 0; 216 int pcum = 0, psum = 0;
217 int is_increasing = 0;
186 218
187 *fingers = 0; 219 *fingers = 0;
188 220
189 for (i = 0; i < nb_sensors; i++) { 221 for (i = 0; i < nb_sensors; i++) {
190 if (xy_sensors[i] < ATP_THRESHOLD) 222 if (xy_sensors[i] < threshold) {
223 if (is_increasing)
224 is_increasing = 0;
225
191 continue; 226 continue;
192 if ((i - 1 < 0) || (xy_sensors[i - 1] < ATP_THRESHOLD)) 227 }
228
229 /*
230 * Makes the finger detection more versatile. For example,
231 * two fingers with no gap will be detected. Also, my
232 * tests show it less likely to have intermittent loss
233 * of multiple finger readings while moving around (scrolling).
234 *
235 * Changes the multiple finger detection to counting humps on
236 * sensors (transitions from nonincreasing to increasing)
237 * instead of counting transitions from low sensors (no
238 * finger reading) to high sensors (finger above
239 * sensor)
240 *
241 * - Jason Parekh <jasonparekh@gmail.com>
242 */
243 if (i < 1 || (!is_increasing && xy_sensors[i - 1] < xy_sensors[i])) {
193 (*fingers)++; 244 (*fingers)++;
194 pcum += xy_sensors[i] * i; 245 is_increasing = 1;
195 psum += xy_sensors[i]; 246 } else if (i > 0 && xy_sensors[i - 1] >= xy_sensors[i]) {
247 is_increasing = 0;
248 }
249
250 /*
251 * Subtracts threshold so a high sensor that just passes the threshold
252 * won't skew the calculated absolute coordinate. Fixes an issue
253 * where slowly moving the mouse would occassionaly jump a number of
254 * pixels (let me restate--slowly moving the mouse makes this issue
255 * most apparent).
256 */
257 pcum += (xy_sensors[i] - threshold) * i;
258 psum += (xy_sensors[i] - threshold);
196 } 259 }
197 260
198 if (psum > 0) { 261 if (psum > 0) {
diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index f1d0e1d69828..89fa6885709b 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -4,6 +4,7 @@
4 * Copyright (c) 1999 Andreas Gal 4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006 Jiri Kosina
7 */ 8 */
8 9
9/* 10/*
@@ -32,8 +33,9 @@
32 33
33#include <linux/usb.h> 34#include <linux/usb.h>
34 35
35#include "hid.h" 36#include <linux/hid.h>
36#include <linux/hiddev.h> 37#include <linux/hiddev.h>
38#include "usbhid.h"
37 39
38/* 40/*
39 * Version Information 41 * Version Information
@@ -54,886 +56,10 @@ static unsigned int hid_mousepoll_interval;
54module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644); 56module_param_named(mousepoll, hid_mousepoll_interval, uint, 0644);
55MODULE_PARM_DESC(mousepoll, "Polling interval of mice"); 57MODULE_PARM_DESC(mousepoll, "Polling interval of mice");
56 58
57/* 59static int usbhid_pb_fnmode = 1;
58 * Register a new report for a device. 60module_param_named(pb_fnmode, usbhid_pb_fnmode, int, 0644);
59 */ 61MODULE_PARM_DESC(pb_fnmode,
60 62 "Mode of fn key on PowerBooks (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
61static struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id)
62{
63 struct hid_report_enum *report_enum = device->report_enum + type;
64 struct hid_report *report;
65
66 if (report_enum->report_id_hash[id])
67 return report_enum->report_id_hash[id];
68
69 if (!(report = kzalloc(sizeof(struct hid_report), GFP_KERNEL)))
70 return NULL;
71
72 if (id != 0)
73 report_enum->numbered = 1;
74
75 report->id = id;
76 report->type = type;
77 report->size = 0;
78 report->device = device;
79 report_enum->report_id_hash[id] = report;
80
81 list_add_tail(&report->list, &report_enum->report_list);
82
83 return report;
84}
85
86/*
87 * Register a new field for this report.
88 */
89
90static struct hid_field *hid_register_field(struct hid_report *report, unsigned usages, unsigned values)
91{
92 struct hid_field *field;
93
94 if (report->maxfield == HID_MAX_FIELDS) {
95 dbg("too many fields in report");
96 return NULL;
97 }
98
99 if (!(field = kzalloc(sizeof(struct hid_field) + usages * sizeof(struct hid_usage)
100 + values * sizeof(unsigned), GFP_KERNEL))) return NULL;
101
102 field->index = report->maxfield++;
103 report->field[field->index] = field;
104 field->usage = (struct hid_usage *)(field + 1);
105 field->value = (unsigned *)(field->usage + usages);
106 field->report = report;
107
108 return field;
109}
110
111/*
112 * Open a collection. The type/usage is pushed on the stack.
113 */
114
115static int open_collection(struct hid_parser *parser, unsigned type)
116{
117 struct hid_collection *collection;
118 unsigned usage;
119
120 usage = parser->local.usage[0];
121
122 if (parser->collection_stack_ptr == HID_COLLECTION_STACK_SIZE) {
123 dbg("collection stack overflow");
124 return -1;
125 }
126
127 if (parser->device->maxcollection == parser->device->collection_size) {
128 collection = kmalloc(sizeof(struct hid_collection) *
129 parser->device->collection_size * 2, GFP_KERNEL);
130 if (collection == NULL) {
131 dbg("failed to reallocate collection array");
132 return -1;
133 }
134 memcpy(collection, parser->device->collection,
135 sizeof(struct hid_collection) *
136 parser->device->collection_size);
137 memset(collection + parser->device->collection_size, 0,
138 sizeof(struct hid_collection) *
139 parser->device->collection_size);
140 kfree(parser->device->collection);
141 parser->device->collection = collection;
142 parser->device->collection_size *= 2;
143 }
144
145 parser->collection_stack[parser->collection_stack_ptr++] =
146 parser->device->maxcollection;
147
148 collection = parser->device->collection +
149 parser->device->maxcollection++;
150 collection->type = type;
151 collection->usage = usage;
152 collection->level = parser->collection_stack_ptr - 1;
153
154 if (type == HID_COLLECTION_APPLICATION)
155 parser->device->maxapplication++;
156
157 return 0;
158}
159
160/*
161 * Close a collection.
162 */
163
164static int close_collection(struct hid_parser *parser)
165{
166 if (!parser->collection_stack_ptr) {
167 dbg("collection stack underflow");
168 return -1;
169 }
170 parser->collection_stack_ptr--;
171 return 0;
172}
173
174/*
175 * Climb up the stack, search for the specified collection type
176 * and return the usage.
177 */
178
179static unsigned hid_lookup_collection(struct hid_parser *parser, unsigned type)
180{
181 int n;
182 for (n = parser->collection_stack_ptr - 1; n >= 0; n--)
183 if (parser->device->collection[parser->collection_stack[n]].type == type)
184 return parser->device->collection[parser->collection_stack[n]].usage;
185 return 0; /* we know nothing about this usage type */
186}
187
188/*
189 * Add a usage to the temporary parser table.
190 */
191
192static int hid_add_usage(struct hid_parser *parser, unsigned usage)
193{
194 if (parser->local.usage_index >= HID_MAX_USAGES) {
195 dbg("usage index exceeded");
196 return -1;
197 }
198 parser->local.usage[parser->local.usage_index] = usage;
199 parser->local.collection_index[parser->local.usage_index] =
200 parser->collection_stack_ptr ?
201 parser->collection_stack[parser->collection_stack_ptr - 1] : 0;
202 parser->local.usage_index++;
203 return 0;
204}
205
206/*
207 * Register a new field for this report.
208 */
209
210static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsigned flags)
211{
212 struct hid_report *report;
213 struct hid_field *field;
214 int usages;
215 unsigned offset;
216 int i;
217
218 if (!(report = hid_register_report(parser->device, report_type, parser->global.report_id))) {
219 dbg("hid_register_report failed");
220 return -1;
221 }
222
223 if (parser->global.logical_maximum < parser->global.logical_minimum) {
224 dbg("logical range invalid %d %d", parser->global.logical_minimum, parser->global.logical_maximum);
225 return -1;
226 }
227
228 offset = report->size;
229 report->size += parser->global.report_size * parser->global.report_count;
230
231 if (!parser->local.usage_index) /* Ignore padding fields */
232 return 0;
233
234 usages = max_t(int, parser->local.usage_index, parser->global.report_count);
235
236 if ((field = hid_register_field(report, usages, parser->global.report_count)) == NULL)
237 return 0;
238
239 field->physical = hid_lookup_collection(parser, HID_COLLECTION_PHYSICAL);
240 field->logical = hid_lookup_collection(parser, HID_COLLECTION_LOGICAL);
241 field->application = hid_lookup_collection(parser, HID_COLLECTION_APPLICATION);
242
243 for (i = 0; i < usages; i++) {
244 int j = i;
245 /* Duplicate the last usage we parsed if we have excess values */
246 if (i >= parser->local.usage_index)
247 j = parser->local.usage_index - 1;
248 field->usage[i].hid = parser->local.usage[j];
249 field->usage[i].collection_index =
250 parser->local.collection_index[j];
251 }
252
253 field->maxusage = usages;
254 field->flags = flags;
255 field->report_offset = offset;
256 field->report_type = report_type;
257 field->report_size = parser->global.report_size;
258 field->report_count = parser->global.report_count;
259 field->logical_minimum = parser->global.logical_minimum;
260 field->logical_maximum = parser->global.logical_maximum;
261 field->physical_minimum = parser->global.physical_minimum;
262 field->physical_maximum = parser->global.physical_maximum;
263 field->unit_exponent = parser->global.unit_exponent;
264 field->unit = parser->global.unit;
265
266 return 0;
267}
268
269/*
270 * Read data value from item.
271 */
272
273static u32 item_udata(struct hid_item *item)
274{
275 switch (item->size) {
276 case 1: return item->data.u8;
277 case 2: return item->data.u16;
278 case 4: return item->data.u32;
279 }
280 return 0;
281}
282
283static s32 item_sdata(struct hid_item *item)
284{
285 switch (item->size) {
286 case 1: return item->data.s8;
287 case 2: return item->data.s16;
288 case 4: return item->data.s32;
289 }
290 return 0;
291}
292
293/*
294 * Process a global item.
295 */
296
297static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
298{
299 switch (item->tag) {
300
301 case HID_GLOBAL_ITEM_TAG_PUSH:
302
303 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
304 dbg("global enviroment stack overflow");
305 return -1;
306 }
307
308 memcpy(parser->global_stack + parser->global_stack_ptr++,
309 &parser->global, sizeof(struct hid_global));
310 return 0;
311
312 case HID_GLOBAL_ITEM_TAG_POP:
313
314 if (!parser->global_stack_ptr) {
315 dbg("global enviroment stack underflow");
316 return -1;
317 }
318
319 memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr,
320 sizeof(struct hid_global));
321 return 0;
322
323 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
324 parser->global.usage_page = item_udata(item);
325 return 0;
326
327 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
328 parser->global.logical_minimum = item_sdata(item);
329 return 0;
330
331 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
332 if (parser->global.logical_minimum < 0)
333 parser->global.logical_maximum = item_sdata(item);
334 else
335 parser->global.logical_maximum = item_udata(item);
336 return 0;
337
338 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
339 parser->global.physical_minimum = item_sdata(item);
340 return 0;
341
342 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
343 if (parser->global.physical_minimum < 0)
344 parser->global.physical_maximum = item_sdata(item);
345 else
346 parser->global.physical_maximum = item_udata(item);
347 return 0;
348
349 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
350 parser->global.unit_exponent = item_sdata(item);
351 return 0;
352
353 case HID_GLOBAL_ITEM_TAG_UNIT:
354 parser->global.unit = item_udata(item);
355 return 0;
356
357 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
358 if ((parser->global.report_size = item_udata(item)) > 32) {
359 dbg("invalid report_size %d", parser->global.report_size);
360 return -1;
361 }
362 return 0;
363
364 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
365 if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) {
366 dbg("invalid report_count %d", parser->global.report_count);
367 return -1;
368 }
369 return 0;
370
371 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
372 if ((parser->global.report_id = item_udata(item)) == 0) {
373 dbg("report_id 0 is invalid");
374 return -1;
375 }
376 return 0;
377
378 default:
379 dbg("unknown global tag 0x%x", item->tag);
380 return -1;
381 }
382}
383
384/*
385 * Process a local item.
386 */
387
388static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
389{
390 __u32 data;
391 unsigned n;
392
393 if (item->size == 0) {
394 dbg("item data expected for local item");
395 return -1;
396 }
397
398 data = item_udata(item);
399
400 switch (item->tag) {
401
402 case HID_LOCAL_ITEM_TAG_DELIMITER:
403
404 if (data) {
405 /*
406 * We treat items before the first delimiter
407 * as global to all usage sets (branch 0).
408 * In the moment we process only these global
409 * items and the first delimiter set.
410 */
411 if (parser->local.delimiter_depth != 0) {
412 dbg("nested delimiters");
413 return -1;
414 }
415 parser->local.delimiter_depth++;
416 parser->local.delimiter_branch++;
417 } else {
418 if (parser->local.delimiter_depth < 1) {
419 dbg("bogus close delimiter");
420 return -1;
421 }
422 parser->local.delimiter_depth--;
423 }
424 return 1;
425
426 case HID_LOCAL_ITEM_TAG_USAGE:
427
428 if (parser->local.delimiter_branch > 1) {
429 dbg("alternative usage ignored");
430 return 0;
431 }
432
433 if (item->size <= 2)
434 data = (parser->global.usage_page << 16) + data;
435
436 return hid_add_usage(parser, data);
437
438 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
439
440 if (parser->local.delimiter_branch > 1) {
441 dbg("alternative usage ignored");
442 return 0;
443 }
444
445 if (item->size <= 2)
446 data = (parser->global.usage_page << 16) + data;
447
448 parser->local.usage_minimum = data;
449 return 0;
450
451 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
452
453 if (parser->local.delimiter_branch > 1) {
454 dbg("alternative usage ignored");
455 return 0;
456 }
457
458 if (item->size <= 2)
459 data = (parser->global.usage_page << 16) + data;
460
461 for (n = parser->local.usage_minimum; n <= data; n++)
462 if (hid_add_usage(parser, n)) {
463 dbg("hid_add_usage failed\n");
464 return -1;
465 }
466 return 0;
467
468 default:
469
470 dbg("unknown local item tag 0x%x", item->tag);
471 return 0;
472 }
473 return 0;
474}
475
476/*
477 * Process a main item.
478 */
479
480static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
481{
482 __u32 data;
483 int ret;
484
485 data = item_udata(item);
486
487 switch (item->tag) {
488 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
489 ret = open_collection(parser, data & 0xff);
490 break;
491 case HID_MAIN_ITEM_TAG_END_COLLECTION:
492 ret = close_collection(parser);
493 break;
494 case HID_MAIN_ITEM_TAG_INPUT:
495 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
496 break;
497 case HID_MAIN_ITEM_TAG_OUTPUT:
498 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
499 break;
500 case HID_MAIN_ITEM_TAG_FEATURE:
501 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
502 break;
503 default:
504 dbg("unknown main item tag 0x%x", item->tag);
505 ret = 0;
506 }
507
508 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
509
510 return ret;
511}
512
513/*
514 * Process a reserved item.
515 */
516
517static int hid_parser_reserved(struct hid_parser *parser, struct hid_item *item)
518{
519 dbg("reserved item type, tag 0x%x", item->tag);
520 return 0;
521}
522
523/*
524 * Free a report and all registered fields. The field->usage and
525 * field->value table's are allocated behind the field, so we need
526 * only to free(field) itself.
527 */
528
529static void hid_free_report(struct hid_report *report)
530{
531 unsigned n;
532
533 for (n = 0; n < report->maxfield; n++)
534 kfree(report->field[n]);
535 kfree(report);
536}
537
538/*
539 * Free a device structure, all reports, and all fields.
540 */
541
542static void hid_free_device(struct hid_device *device)
543{
544 unsigned i,j;
545
546 for (i = 0; i < HID_REPORT_TYPES; i++) {
547 struct hid_report_enum *report_enum = device->report_enum + i;
548
549 for (j = 0; j < 256; j++) {
550 struct hid_report *report = report_enum->report_id_hash[j];
551 if (report)
552 hid_free_report(report);
553 }
554 }
555
556 kfree(device->rdesc);
557 kfree(device);
558}
559
560/*
561 * Fetch a report description item from the data stream. We support long
562 * items, though they are not used yet.
563 */
564
565static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
566{
567 u8 b;
568
569 if ((end - start) <= 0)
570 return NULL;
571
572 b = *start++;
573
574 item->type = (b >> 2) & 3;
575 item->tag = (b >> 4) & 15;
576
577 if (item->tag == HID_ITEM_TAG_LONG) {
578
579 item->format = HID_ITEM_FORMAT_LONG;
580
581 if ((end - start) < 2)
582 return NULL;
583
584 item->size = *start++;
585 item->tag = *start++;
586
587 if ((end - start) < item->size)
588 return NULL;
589
590 item->data.longdata = start;
591 start += item->size;
592 return start;
593 }
594
595 item->format = HID_ITEM_FORMAT_SHORT;
596 item->size = b & 3;
597
598 switch (item->size) {
599
600 case 0:
601 return start;
602
603 case 1:
604 if ((end - start) < 1)
605 return NULL;
606 item->data.u8 = *start++;
607 return start;
608
609 case 2:
610 if ((end - start) < 2)
611 return NULL;
612 item->data.u16 = le16_to_cpu(get_unaligned((__le16*)start));
613 start = (__u8 *)((__le16 *)start + 1);
614 return start;
615
616 case 3:
617 item->size++;
618 if ((end - start) < 4)
619 return NULL;
620 item->data.u32 = le32_to_cpu(get_unaligned((__le32*)start));
621 start = (__u8 *)((__le32 *)start + 1);
622 return start;
623 }
624
625 return NULL;
626}
627
628/*
629 * Parse a report description into a hid_device structure. Reports are
630 * enumerated, fields are attached to these reports.
631 */
632
633static struct hid_device *hid_parse_report(__u8 *start, unsigned size)
634{
635 struct hid_device *device;
636 struct hid_parser *parser;
637 struct hid_item item;
638 __u8 *end;
639 unsigned i;
640 static int (*dispatch_type[])(struct hid_parser *parser,
641 struct hid_item *item) = {
642 hid_parser_main,
643 hid_parser_global,
644 hid_parser_local,
645 hid_parser_reserved
646 };
647
648 if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL)))
649 return NULL;
650
651 if (!(device->collection = kzalloc(sizeof(struct hid_collection) *
652 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) {
653 kfree(device);
654 return NULL;
655 }
656 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
657
658 for (i = 0; i < HID_REPORT_TYPES; i++)
659 INIT_LIST_HEAD(&device->report_enum[i].report_list);
660
661 if (!(device->rdesc = (__u8 *)kmalloc(size, GFP_KERNEL))) {
662 kfree(device->collection);
663 kfree(device);
664 return NULL;
665 }
666 memcpy(device->rdesc, start, size);
667 device->rsize = size;
668
669 if (!(parser = kzalloc(sizeof(struct hid_parser), GFP_KERNEL))) {
670 kfree(device->rdesc);
671 kfree(device->collection);
672 kfree(device);
673 return NULL;
674 }
675 parser->device = device;
676
677 end = start + size;
678 while ((start = fetch_item(start, end, &item)) != NULL) {
679
680 if (item.format != HID_ITEM_FORMAT_SHORT) {
681 dbg("unexpected long global item");
682 kfree(device->collection);
683 hid_free_device(device);
684 kfree(parser);
685 return NULL;
686 }
687
688 if (dispatch_type[item.type](parser, &item)) {
689 dbg("item %u %u %u %u parsing failed\n",
690 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
691 kfree(device->collection);
692 hid_free_device(device);
693 kfree(parser);
694 return NULL;
695 }
696
697 if (start == end) {
698 if (parser->collection_stack_ptr) {
699 dbg("unbalanced collection at end of report description");
700 kfree(device->collection);
701 hid_free_device(device);
702 kfree(parser);
703 return NULL;
704 }
705 if (parser->local.delimiter_depth) {
706 dbg("unbalanced delimiter at end of report description");
707 kfree(device->collection);
708 hid_free_device(device);
709 kfree(parser);
710 return NULL;
711 }
712 kfree(parser);
713 return device;
714 }
715 }
716
717 dbg("item fetching failed at offset %d\n", (int)(end - start));
718 kfree(device->collection);
719 hid_free_device(device);
720 kfree(parser);
721 return NULL;
722}
723
724/*
725 * Convert a signed n-bit integer to signed 32-bit integer. Common
726 * cases are done through the compiler, the screwed things has to be
727 * done by hand.
728 */
729
730static s32 snto32(__u32 value, unsigned n)
731{
732 switch (n) {
733 case 8: return ((__s8)value);
734 case 16: return ((__s16)value);
735 case 32: return ((__s32)value);
736 }
737 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
738}
739
740/*
741 * Convert a signed 32-bit integer to a signed n-bit integer.
742 */
743
744static u32 s32ton(__s32 value, unsigned n)
745{
746 s32 a = value >> (n - 1);
747 if (a && a != -1)
748 return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1;
749 return value & ((1 << n) - 1);
750}
751
752/*
753 * Extract/implement a data field from/to a little endian report (bit array).
754 *
755 * Code sort-of follows HID spec:
756 * http://www.usb.org/developers/devclass_docs/HID1_11.pdf
757 *
758 * While the USB HID spec allows unlimited length bit fields in "report
759 * descriptors", most devices never use more than 16 bits.
760 * One model of UPS is claimed to report "LINEV" as a 32-bit field.
761 * Search linux-kernel and linux-usb-devel archives for "hid-core extract".
762 */
763
764static __inline__ __u32 extract(__u8 *report, unsigned offset, unsigned n)
765{
766 u64 x;
767
768 WARN_ON(n > 32);
769
770 report += offset >> 3; /* adjust byte index */
771 offset &= 7; /* now only need bit offset into one byte */
772 x = get_unaligned((u64 *) report);
773 x = le64_to_cpu(x);
774 x = (x >> offset) & ((1ULL << n) - 1); /* extract bit field */
775 return (u32) x;
776}
777
778/*
779 * "implement" : set bits in a little endian bit stream.
780 * Same concepts as "extract" (see comments above).
781 * The data mangled in the bit stream remains in little endian
782 * order the whole time. It make more sense to talk about
783 * endianness of register values by considering a register
784 * a "cached" copy of the little endiad bit stream.
785 */
786static __inline__ void implement(__u8 *report, unsigned offset, unsigned n, __u32 value)
787{
788 u64 x;
789 u64 m = (1ULL << n) - 1;
790
791 WARN_ON(n > 32);
792
793 WARN_ON(value > m);
794 value &= m;
795
796 report += offset >> 3;
797 offset &= 7;
798
799 x = get_unaligned((u64 *)report);
800 x &= cpu_to_le64(~(m << offset));
801 x |= cpu_to_le64(((u64) value) << offset);
802 put_unaligned(x, (u64 *) report);
803}
804
805/*
806 * Search an array for a value.
807 */
808
809static __inline__ int search(__s32 *array, __s32 value, unsigned n)
810{
811 while (n--) {
812 if (*array++ == value)
813 return 0;
814 }
815 return -1;
816}
817
818static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt)
819{
820 hid_dump_input(usage, value);
821 if (hid->claimed & HID_CLAIMED_INPUT)
822 hidinput_hid_event(hid, field, usage, value);
823 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt)
824 hiddev_hid_event(hid, field, usage, value);
825}
826
827/*
828 * Analyse a received field, and fetch the data from it. The field
829 * content is stored for next report processing (we do differential
830 * reporting to the layer).
831 */
832
833static void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt)
834{
835 unsigned n;
836 unsigned count = field->report_count;
837 unsigned offset = field->report_offset;
838 unsigned size = field->report_size;
839 __s32 min = field->logical_minimum;
840 __s32 max = field->logical_maximum;
841 __s32 *value;
842
843 if (!(value = kmalloc(sizeof(__s32) * count, GFP_ATOMIC)))
844 return;
845
846 for (n = 0; n < count; n++) {
847
848 value[n] = min < 0 ? snto32(extract(data, offset + n * size, size), size) :
849 extract(data, offset + n * size, size);
850
851 if (!(field->flags & HID_MAIN_ITEM_VARIABLE) /* Ignore report if ErrorRollOver */
852 && value[n] >= min && value[n] <= max
853 && field->usage[value[n] - min].hid == HID_UP_KEYBOARD + 1)
854 goto exit;
855 }
856
857 for (n = 0; n < count; n++) {
858
859 if (HID_MAIN_ITEM_VARIABLE & field->flags) {
860 hid_process_event(hid, field, &field->usage[n], value[n], interrupt);
861 continue;
862 }
863
864 if (field->value[n] >= min && field->value[n] <= max
865 && field->usage[field->value[n] - min].hid
866 && search(value, field->value[n], count))
867 hid_process_event(hid, field, &field->usage[field->value[n] - min], 0, interrupt);
868
869 if (value[n] >= min && value[n] <= max
870 && field->usage[value[n] - min].hid
871 && search(field->value, value[n], count))
872 hid_process_event(hid, field, &field->usage[value[n] - min], 1, interrupt);
873 }
874
875 memcpy(field->value, value, count * sizeof(__s32));
876exit:
877 kfree(value);
878}
879
880static int hid_input_report(int type, struct urb *urb, int interrupt)
881{
882 struct hid_device *hid = urb->context;
883 struct hid_report_enum *report_enum = hid->report_enum + type;
884 u8 *data = urb->transfer_buffer;
885 int len = urb->actual_length;
886 struct hid_report *report;
887 int n, size;
888
889 if (!len) {
890 dbg("empty report");
891 return -1;
892 }
893
894#ifdef DEBUG_DATA
895 printk(KERN_DEBUG __FILE__ ": report (size %u) (%snumbered)\n", len, report_enum->numbered ? "" : "un");
896#endif
897
898 n = 0; /* Normally report number is 0 */
899 if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */
900 n = *data++;
901 len--;
902 }
903
904#ifdef DEBUG_DATA
905 {
906 int i;
907 printk(KERN_DEBUG __FILE__ ": report %d (size %u) = ", n, len);
908 for (i = 0; i < len; i++)
909 printk(" %02x", data[i]);
910 printk("\n");
911 }
912#endif
913
914 if (!(report = report_enum->report_id_hash[n])) {
915 dbg("undefined report_id %d received", n);
916 return -1;
917 }
918
919 size = ((report->size - 1) >> 3) + 1;
920
921 if (len < size) {
922 dbg("report %d is too short, (%d < %d)", report->id, len, size);
923 memset(data + len, 0, size - len);
924 }
925
926 if (hid->claimed & HID_CLAIMED_HIDDEV)
927 hiddev_report_event(hid, report);
928
929 for (n = 0; n < report->maxfield; n++)
930 hid_input_field(hid, report->field[n], data, interrupt);
931
932 if (hid->claimed & HID_CLAIMED_INPUT)
933 hidinput_report_event(hid, report);
934
935 return 0;
936}
937 63
938/* 64/*
939 * Input submission and I/O error handler. 65 * Input submission and I/O error handler.
@@ -946,15 +72,16 @@ static int hid_start_in(struct hid_device *hid)
946{ 72{
947 unsigned long flags; 73 unsigned long flags;
948 int rc = 0; 74 int rc = 0;
75 struct usbhid_device *usbhid = hid->driver_data;
949 76
950 spin_lock_irqsave(&hid->inlock, flags); 77 spin_lock_irqsave(&usbhid->inlock, flags);
951 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &hid->iofl) && 78 if (hid->open > 0 && !test_bit(HID_SUSPENDED, &usbhid->iofl) &&
952 !test_and_set_bit(HID_IN_RUNNING, &hid->iofl)) { 79 !test_and_set_bit(HID_IN_RUNNING, &usbhid->iofl)) {
953 rc = usb_submit_urb(hid->urbin, GFP_ATOMIC); 80 rc = usb_submit_urb(usbhid->urbin, GFP_ATOMIC);
954 if (rc != 0) 81 if (rc != 0)
955 clear_bit(HID_IN_RUNNING, &hid->iofl); 82 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
956 } 83 }
957 spin_unlock_irqrestore(&hid->inlock, flags); 84 spin_unlock_irqrestore(&usbhid->inlock, flags);
958 return rc; 85 return rc;
959} 86}
960 87
@@ -962,8 +89,9 @@ static int hid_start_in(struct hid_device *hid)
962static void hid_retry_timeout(unsigned long _hid) 89static void hid_retry_timeout(unsigned long _hid)
963{ 90{
964 struct hid_device *hid = (struct hid_device *) _hid; 91 struct hid_device *hid = (struct hid_device *) _hid;
92 struct usbhid_device *usbhid = hid->driver_data;
965 93
966 dev_dbg(&hid->intf->dev, "retrying intr urb\n"); 94 dev_dbg(&usbhid->intf->dev, "retrying intr urb\n");
967 if (hid_start_in(hid)) 95 if (hid_start_in(hid))
968 hid_io_error(hid); 96 hid_io_error(hid);
969} 97}
@@ -971,38 +99,39 @@ static void hid_retry_timeout(unsigned long _hid)
971/* Workqueue routine to reset the device or clear a halt */ 99/* Workqueue routine to reset the device or clear a halt */
972static void hid_reset(struct work_struct *work) 100static void hid_reset(struct work_struct *work)
973{ 101{
974 struct hid_device *hid = 102 struct usbhid_device *usbhid =
975 container_of(work, struct hid_device, reset_work); 103 container_of(work, struct usbhid_device, reset_work);
104 struct hid_device *hid = usbhid->hid;
976 int rc_lock, rc = 0; 105 int rc_lock, rc = 0;
977 106
978 if (test_bit(HID_CLEAR_HALT, &hid->iofl)) { 107 if (test_bit(HID_CLEAR_HALT, &usbhid->iofl)) {
979 dev_dbg(&hid->intf->dev, "clear halt\n"); 108 dev_dbg(&usbhid->intf->dev, "clear halt\n");
980 rc = usb_clear_halt(hid->dev, hid->urbin->pipe); 109 rc = usb_clear_halt(to_usb_device(hid->dev), usbhid->urbin->pipe);
981 clear_bit(HID_CLEAR_HALT, &hid->iofl); 110 clear_bit(HID_CLEAR_HALT, &usbhid->iofl);
982 hid_start_in(hid); 111 hid_start_in(hid);
983 } 112 }
984 113
985 else if (test_bit(HID_RESET_PENDING, &hid->iofl)) { 114 else if (test_bit(HID_RESET_PENDING, &usbhid->iofl)) {
986 dev_dbg(&hid->intf->dev, "resetting device\n"); 115 dev_dbg(&usbhid->intf->dev, "resetting device\n");
987 rc = rc_lock = usb_lock_device_for_reset(hid->dev, hid->intf); 116 rc = rc_lock = usb_lock_device_for_reset(to_usb_device(hid->dev), usbhid->intf);
988 if (rc_lock >= 0) { 117 if (rc_lock >= 0) {
989 rc = usb_reset_composite_device(hid->dev, hid->intf); 118 rc = usb_reset_composite_device(to_usb_device(hid->dev), usbhid->intf);
990 if (rc_lock) 119 if (rc_lock)
991 usb_unlock_device(hid->dev); 120 usb_unlock_device(to_usb_device(hid->dev));
992 } 121 }
993 clear_bit(HID_RESET_PENDING, &hid->iofl); 122 clear_bit(HID_RESET_PENDING, &usbhid->iofl);
994 } 123 }
995 124
996 switch (rc) { 125 switch (rc) {
997 case 0: 126 case 0:
998 if (!test_bit(HID_IN_RUNNING, &hid->iofl)) 127 if (!test_bit(HID_IN_RUNNING, &usbhid->iofl))
999 hid_io_error(hid); 128 hid_io_error(hid);
1000 break; 129 break;
1001 default: 130 default:
1002 err("can't reset device, %s-%s/input%d, status %d", 131 err("can't reset device, %s-%s/input%d, status %d",
1003 hid->dev->bus->bus_name, 132 to_usb_device(hid->dev)->bus->bus_name,
1004 hid->dev->devpath, 133 to_usb_device(hid->dev)->devpath,
1005 hid->ifnum, rc); 134 usbhid->ifnum, rc);
1006 /* FALLTHROUGH */ 135 /* FALLTHROUGH */
1007 case -EHOSTUNREACH: 136 case -EHOSTUNREACH:
1008 case -ENODEV: 137 case -ENODEV:
@@ -1015,33 +144,34 @@ static void hid_reset(struct work_struct *work)
1015static void hid_io_error(struct hid_device *hid) 144static void hid_io_error(struct hid_device *hid)
1016{ 145{
1017 unsigned long flags; 146 unsigned long flags;
147 struct usbhid_device *usbhid = hid->driver_data;
1018 148
1019 spin_lock_irqsave(&hid->inlock, flags); 149 spin_lock_irqsave(&usbhid->inlock, flags);
1020 150
1021 /* Stop when disconnected */ 151 /* Stop when disconnected */
1022 if (usb_get_intfdata(hid->intf) == NULL) 152 if (usb_get_intfdata(usbhid->intf) == NULL)
1023 goto done; 153 goto done;
1024 154
1025 /* When an error occurs, retry at increasing intervals */ 155 /* When an error occurs, retry at increasing intervals */
1026 if (hid->retry_delay == 0) { 156 if (usbhid->retry_delay == 0) {
1027 hid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */ 157 usbhid->retry_delay = 13; /* Then 26, 52, 104, 104, ... */
1028 hid->stop_retry = jiffies + msecs_to_jiffies(1000); 158 usbhid->stop_retry = jiffies + msecs_to_jiffies(1000);
1029 } else if (hid->retry_delay < 100) 159 } else if (usbhid->retry_delay < 100)
1030 hid->retry_delay *= 2; 160 usbhid->retry_delay *= 2;
1031 161
1032 if (time_after(jiffies, hid->stop_retry)) { 162 if (time_after(jiffies, usbhid->stop_retry)) {
1033 163
1034 /* Retries failed, so do a port reset */ 164 /* Retries failed, so do a port reset */
1035 if (!test_and_set_bit(HID_RESET_PENDING, &hid->iofl)) { 165 if (!test_and_set_bit(HID_RESET_PENDING, &usbhid->iofl)) {
1036 schedule_work(&hid->reset_work); 166 schedule_work(&usbhid->reset_work);
1037 goto done; 167 goto done;
1038 } 168 }
1039 } 169 }
1040 170
1041 mod_timer(&hid->io_retry, 171 mod_timer(&usbhid->io_retry,
1042 jiffies + msecs_to_jiffies(hid->retry_delay)); 172 jiffies + msecs_to_jiffies(usbhid->retry_delay));
1043done: 173done:
1044 spin_unlock_irqrestore(&hid->inlock, flags); 174 spin_unlock_irqrestore(&usbhid->inlock, flags);
1045} 175}
1046 176
1047/* 177/*
@@ -1051,28 +181,31 @@ done:
1051static void hid_irq_in(struct urb *urb) 181static void hid_irq_in(struct urb *urb)
1052{ 182{
1053 struct hid_device *hid = urb->context; 183 struct hid_device *hid = urb->context;
184 struct usbhid_device *usbhid = hid->driver_data;
1054 int status; 185 int status;
1055 186
1056 switch (urb->status) { 187 switch (urb->status) {
1057 case 0: /* success */ 188 case 0: /* success */
1058 hid->retry_delay = 0; 189 usbhid->retry_delay = 0;
1059 hid_input_report(HID_INPUT_REPORT, urb, 1); 190 hid_input_report(urb->context, HID_INPUT_REPORT,
191 urb->transfer_buffer,
192 urb->actual_length, 1);
1060 break; 193 break;
1061 case -EPIPE: /* stall */ 194 case -EPIPE: /* stall */
1062 clear_bit(HID_IN_RUNNING, &hid->iofl); 195 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
1063 set_bit(HID_CLEAR_HALT, &hid->iofl); 196 set_bit(HID_CLEAR_HALT, &usbhid->iofl);
1064 schedule_work(&hid->reset_work); 197 schedule_work(&usbhid->reset_work);
1065 return; 198 return;
1066 case -ECONNRESET: /* unlink */ 199 case -ECONNRESET: /* unlink */
1067 case -ENOENT: 200 case -ENOENT:
1068 case -ESHUTDOWN: /* unplug */ 201 case -ESHUTDOWN: /* unplug */
1069 clear_bit(HID_IN_RUNNING, &hid->iofl); 202 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
1070 return; 203 return;
1071 case -EILSEQ: /* protocol error or unplug */ 204 case -EILSEQ: /* protocol error or unplug */
1072 case -EPROTO: /* protocol error or unplug */ 205 case -EPROTO: /* protocol error or unplug */
1073 case -ETIME: /* protocol error or unplug */ 206 case -ETIME: /* protocol error or unplug */
1074 case -ETIMEDOUT: /* Should never happen, but... */ 207 case -ETIMEDOUT: /* Should never happen, but... */
1075 clear_bit(HID_IN_RUNNING, &hid->iofl); 208 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
1076 hid_io_error(hid); 209 hid_io_error(hid);
1077 return; 210 return;
1078 default: /* error */ 211 default: /* error */
@@ -1081,79 +214,18 @@ static void hid_irq_in(struct urb *urb)
1081 214
1082 status = usb_submit_urb(urb, GFP_ATOMIC); 215 status = usb_submit_urb(urb, GFP_ATOMIC);
1083 if (status) { 216 if (status) {
1084 clear_bit(HID_IN_RUNNING, &hid->iofl); 217 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
1085 if (status != -EPERM) { 218 if (status != -EPERM) {
1086 err("can't resubmit intr, %s-%s/input%d, status %d", 219 err("can't resubmit intr, %s-%s/input%d, status %d",
1087 hid->dev->bus->bus_name, 220 to_usb_device(hid->dev)->bus->bus_name,
1088 hid->dev->devpath, 221 to_usb_device(hid->dev)->devpath,
1089 hid->ifnum, status); 222 usbhid->ifnum, status);
1090 hid_io_error(hid); 223 hid_io_error(hid);
1091 } 224 }
1092 } 225 }
1093} 226}
1094 227
1095/* 228/*
1096 * Output the field into the report.
1097 */
1098
1099static void hid_output_field(struct hid_field *field, __u8 *data)
1100{
1101 unsigned count = field->report_count;
1102 unsigned offset = field->report_offset;
1103 unsigned size = field->report_size;
1104 unsigned n;
1105
1106 for (n = 0; n < count; n++) {
1107 if (field->logical_minimum < 0) /* signed values */
1108 implement(data, offset + n * size, size, s32ton(field->value[n], size));
1109 else /* unsigned values */
1110 implement(data, offset + n * size, size, field->value[n]);
1111 }
1112}
1113
1114/*
1115 * Create a report.
1116 */
1117
1118static void hid_output_report(struct hid_report *report, __u8 *data)
1119{
1120 unsigned n;
1121
1122 if (report->id > 0)
1123 *data++ = report->id;
1124
1125 for (n = 0; n < report->maxfield; n++)
1126 hid_output_field(report->field[n], data);
1127}
1128
1129/*
1130 * Set a field value. The report this field belongs to has to be
1131 * created and transferred to the device, to set this value in the
1132 * device.
1133 */
1134
1135int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
1136{
1137 unsigned size = field->report_size;
1138
1139 hid_dump_input(field->usage + offset, value);
1140
1141 if (offset >= field->report_count) {
1142 dbg("offset (%d) exceeds report_count (%d)", offset, field->report_count);
1143 hid_dump_field(field, 8);
1144 return -1;
1145 }
1146 if (field->logical_minimum < 0) {
1147 if (value != snto32(s32ton(value, size), size)) {
1148 dbg("value %d is out of range", value);
1149 return -1;
1150 }
1151 }
1152 field->value[offset] = value;
1153 return 0;
1154}
1155
1156/*
1157 * Find a report field with a specified HID usage. 229 * Find a report field with a specified HID usage.
1158 */ 230 */
1159#if 0 231#if 0
@@ -1173,16 +245,17 @@ struct hid_field *hid_find_field_by_usage(struct hid_device *hid, __u32 wanted_u
1173static int hid_submit_out(struct hid_device *hid) 245static int hid_submit_out(struct hid_device *hid)
1174{ 246{
1175 struct hid_report *report; 247 struct hid_report *report;
248 struct usbhid_device *usbhid = hid->driver_data;
1176 249
1177 report = hid->out[hid->outtail]; 250 report = usbhid->out[usbhid->outtail];
1178 251
1179 hid_output_report(report, hid->outbuf); 252 hid_output_report(report, usbhid->outbuf);
1180 hid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); 253 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1181 hid->urbout->dev = hid->dev; 254 usbhid->urbout->dev = to_usb_device(hid->dev);
1182 255
1183 dbg("submitting out urb"); 256 dbg("submitting out urb");
1184 257
1185 if (usb_submit_urb(hid->urbout, GFP_ATOMIC)) { 258 if (usb_submit_urb(usbhid->urbout, GFP_ATOMIC)) {
1186 err("usb_submit_urb(out) failed"); 259 err("usb_submit_urb(out) failed");
1187 return -1; 260 return -1;
1188 } 261 }
@@ -1195,42 +268,43 @@ static int hid_submit_ctrl(struct hid_device *hid)
1195 struct hid_report *report; 268 struct hid_report *report;
1196 unsigned char dir; 269 unsigned char dir;
1197 int len; 270 int len;
271 struct usbhid_device *usbhid = hid->driver_data;
1198 272
1199 report = hid->ctrl[hid->ctrltail].report; 273 report = usbhid->ctrl[usbhid->ctrltail].report;
1200 dir = hid->ctrl[hid->ctrltail].dir; 274 dir = usbhid->ctrl[usbhid->ctrltail].dir;
1201 275
1202 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 276 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
1203 if (dir == USB_DIR_OUT) { 277 if (dir == USB_DIR_OUT) {
1204 hid_output_report(report, hid->ctrlbuf); 278 hid_output_report(report, usbhid->ctrlbuf);
1205 hid->urbctrl->pipe = usb_sndctrlpipe(hid->dev, 0); 279 usbhid->urbctrl->pipe = usb_sndctrlpipe(to_usb_device(hid->dev), 0);
1206 hid->urbctrl->transfer_buffer_length = len; 280 usbhid->urbctrl->transfer_buffer_length = len;
1207 } else { 281 } else {
1208 int maxpacket, padlen; 282 int maxpacket, padlen;
1209 283
1210 hid->urbctrl->pipe = usb_rcvctrlpipe(hid->dev, 0); 284 usbhid->urbctrl->pipe = usb_rcvctrlpipe(to_usb_device(hid->dev), 0);
1211 maxpacket = usb_maxpacket(hid->dev, hid->urbctrl->pipe, 0); 285 maxpacket = usb_maxpacket(to_usb_device(hid->dev), usbhid->urbctrl->pipe, 0);
1212 if (maxpacket > 0) { 286 if (maxpacket > 0) {
1213 padlen = (len + maxpacket - 1) / maxpacket; 287 padlen = (len + maxpacket - 1) / maxpacket;
1214 padlen *= maxpacket; 288 padlen *= maxpacket;
1215 if (padlen > hid->bufsize) 289 if (padlen > usbhid->bufsize)
1216 padlen = hid->bufsize; 290 padlen = usbhid->bufsize;
1217 } else 291 } else
1218 padlen = 0; 292 padlen = 0;
1219 hid->urbctrl->transfer_buffer_length = padlen; 293 usbhid->urbctrl->transfer_buffer_length = padlen;
1220 } 294 }
1221 hid->urbctrl->dev = hid->dev; 295 usbhid->urbctrl->dev = to_usb_device(hid->dev);
1222 296
1223 hid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir; 297 usbhid->cr->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE | dir;
1224 hid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT; 298 usbhid->cr->bRequest = (dir == USB_DIR_OUT) ? HID_REQ_SET_REPORT : HID_REQ_GET_REPORT;
1225 hid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id); 299 usbhid->cr->wValue = cpu_to_le16(((report->type + 1) << 8) | report->id);
1226 hid->cr->wIndex = cpu_to_le16(hid->ifnum); 300 usbhid->cr->wIndex = cpu_to_le16(usbhid->ifnum);
1227 hid->cr->wLength = cpu_to_le16(len); 301 usbhid->cr->wLength = cpu_to_le16(len);
1228 302
1229 dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u", 303 dbg("submitting ctrl urb: %s wValue=0x%04x wIndex=0x%04x wLength=%u",
1230 hid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report", 304 usbhid->cr->bRequest == HID_REQ_SET_REPORT ? "Set_Report" : "Get_Report",
1231 hid->cr->wValue, hid->cr->wIndex, hid->cr->wLength); 305 usbhid->cr->wValue, usbhid->cr->wIndex, usbhid->cr->wLength);
1232 306
1233 if (usb_submit_urb(hid->urbctrl, GFP_ATOMIC)) { 307 if (usb_submit_urb(usbhid->urbctrl, GFP_ATOMIC)) {
1234 err("usb_submit_urb(ctrl) failed"); 308 err("usb_submit_urb(ctrl) failed");
1235 return -1; 309 return -1;
1236 } 310 }
@@ -1245,6 +319,7 @@ static int hid_submit_ctrl(struct hid_device *hid)
1245static void hid_irq_out(struct urb *urb) 319static void hid_irq_out(struct urb *urb)
1246{ 320{
1247 struct hid_device *hid = urb->context; 321 struct hid_device *hid = urb->context;
322 struct usbhid_device *usbhid = hid->driver_data;
1248 unsigned long flags; 323 unsigned long flags;
1249 int unplug = 0; 324 int unplug = 0;
1250 325
@@ -1262,24 +337,24 @@ static void hid_irq_out(struct urb *urb)
1262 warn("output irq status %d received", urb->status); 337 warn("output irq status %d received", urb->status);
1263 } 338 }
1264 339
1265 spin_lock_irqsave(&hid->outlock, flags); 340 spin_lock_irqsave(&usbhid->outlock, flags);
1266 341
1267 if (unplug) 342 if (unplug)
1268 hid->outtail = hid->outhead; 343 usbhid->outtail = usbhid->outhead;
1269 else 344 else
1270 hid->outtail = (hid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1); 345 usbhid->outtail = (usbhid->outtail + 1) & (HID_OUTPUT_FIFO_SIZE - 1);
1271 346
1272 if (hid->outhead != hid->outtail) { 347 if (usbhid->outhead != usbhid->outtail) {
1273 if (hid_submit_out(hid)) { 348 if (hid_submit_out(hid)) {
1274 clear_bit(HID_OUT_RUNNING, &hid->iofl); 349 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
1275 wake_up(&hid->wait); 350 wake_up(&hid->wait);
1276 } 351 }
1277 spin_unlock_irqrestore(&hid->outlock, flags); 352 spin_unlock_irqrestore(&usbhid->outlock, flags);
1278 return; 353 return;
1279 } 354 }
1280 355
1281 clear_bit(HID_OUT_RUNNING, &hid->iofl); 356 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
1282 spin_unlock_irqrestore(&hid->outlock, flags); 357 spin_unlock_irqrestore(&usbhid->outlock, flags);
1283 wake_up(&hid->wait); 358 wake_up(&hid->wait);
1284} 359}
1285 360
@@ -1290,15 +365,17 @@ static void hid_irq_out(struct urb *urb)
1290static void hid_ctrl(struct urb *urb) 365static void hid_ctrl(struct urb *urb)
1291{ 366{
1292 struct hid_device *hid = urb->context; 367 struct hid_device *hid = urb->context;
368 struct usbhid_device *usbhid = hid->driver_data;
1293 unsigned long flags; 369 unsigned long flags;
1294 int unplug = 0; 370 int unplug = 0;
1295 371
1296 spin_lock_irqsave(&hid->ctrllock, flags); 372 spin_lock_irqsave(&usbhid->ctrllock, flags);
1297 373
1298 switch (urb->status) { 374 switch (urb->status) {
1299 case 0: /* success */ 375 case 0: /* success */
1300 if (hid->ctrl[hid->ctrltail].dir == USB_DIR_IN) 376 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
1301 hid_input_report(hid->ctrl[hid->ctrltail].report->type, urb, 0); 377 hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type,
378 urb->transfer_buffer, urb->actual_length, 0);
1302 break; 379 break;
1303 case -ESHUTDOWN: /* unplug */ 380 case -ESHUTDOWN: /* unplug */
1304 unplug = 1; 381 unplug = 1;
@@ -1313,76 +390,102 @@ static void hid_ctrl(struct urb *urb)
1313 } 390 }
1314 391
1315 if (unplug) 392 if (unplug)
1316 hid->ctrltail = hid->ctrlhead; 393 usbhid->ctrltail = usbhid->ctrlhead;
1317 else 394 else
1318 hid->ctrltail = (hid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1); 395 usbhid->ctrltail = (usbhid->ctrltail + 1) & (HID_CONTROL_FIFO_SIZE - 1);
1319 396
1320 if (hid->ctrlhead != hid->ctrltail) { 397 if (usbhid->ctrlhead != usbhid->ctrltail) {
1321 if (hid_submit_ctrl(hid)) { 398 if (hid_submit_ctrl(hid)) {
1322 clear_bit(HID_CTRL_RUNNING, &hid->iofl); 399 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
1323 wake_up(&hid->wait); 400 wake_up(&hid->wait);
1324 } 401 }
1325 spin_unlock_irqrestore(&hid->ctrllock, flags); 402 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
1326 return; 403 return;
1327 } 404 }
1328 405
1329 clear_bit(HID_CTRL_RUNNING, &hid->iofl); 406 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
1330 spin_unlock_irqrestore(&hid->ctrllock, flags); 407 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
1331 wake_up(&hid->wait); 408 wake_up(&hid->wait);
1332} 409}
1333 410
1334void hid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir) 411void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir)
1335{ 412{
1336 int head; 413 int head;
1337 unsigned long flags; 414 unsigned long flags;
415 struct usbhid_device *usbhid = hid->driver_data;
1338 416
1339 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) 417 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
1340 return; 418 return;
1341 419
1342 if (hid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) { 420 if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
1343 421
1344 spin_lock_irqsave(&hid->outlock, flags); 422 spin_lock_irqsave(&usbhid->outlock, flags);
1345 423
1346 if ((head = (hid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == hid->outtail) { 424 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
1347 spin_unlock_irqrestore(&hid->outlock, flags); 425 spin_unlock_irqrestore(&usbhid->outlock, flags);
1348 warn("output queue full"); 426 warn("output queue full");
1349 return; 427 return;
1350 } 428 }
1351 429
1352 hid->out[hid->outhead] = report; 430 usbhid->out[usbhid->outhead] = report;
1353 hid->outhead = head; 431 usbhid->outhead = head;
1354 432
1355 if (!test_and_set_bit(HID_OUT_RUNNING, &hid->iofl)) 433 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl))
1356 if (hid_submit_out(hid)) 434 if (hid_submit_out(hid))
1357 clear_bit(HID_OUT_RUNNING, &hid->iofl); 435 clear_bit(HID_OUT_RUNNING, &usbhid->iofl);
1358 436
1359 spin_unlock_irqrestore(&hid->outlock, flags); 437 spin_unlock_irqrestore(&usbhid->outlock, flags);
1360 return; 438 return;
1361 } 439 }
1362 440
1363 spin_lock_irqsave(&hid->ctrllock, flags); 441 spin_lock_irqsave(&usbhid->ctrllock, flags);
1364 442
1365 if ((head = (hid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == hid->ctrltail) { 443 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
1366 spin_unlock_irqrestore(&hid->ctrllock, flags); 444 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
1367 warn("control queue full"); 445 warn("control queue full");
1368 return; 446 return;
1369 } 447 }
1370 448
1371 hid->ctrl[hid->ctrlhead].report = report; 449 usbhid->ctrl[usbhid->ctrlhead].report = report;
1372 hid->ctrl[hid->ctrlhead].dir = dir; 450 usbhid->ctrl[usbhid->ctrlhead].dir = dir;
1373 hid->ctrlhead = head; 451 usbhid->ctrlhead = head;
1374 452
1375 if (!test_and_set_bit(HID_CTRL_RUNNING, &hid->iofl)) 453 if (!test_and_set_bit(HID_CTRL_RUNNING, &usbhid->iofl))
1376 if (hid_submit_ctrl(hid)) 454 if (hid_submit_ctrl(hid))
1377 clear_bit(HID_CTRL_RUNNING, &hid->iofl); 455 clear_bit(HID_CTRL_RUNNING, &usbhid->iofl);
456
457 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
458}
459
460static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
461{
462 struct hid_device *hid = dev->private;
463 struct hid_field *field;
464 int offset;
465
466 if (type == EV_FF)
467 return input_ff_event(dev, type, code, value);
468
469 if (type != EV_LED)
470 return -1;
471
472 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
473 warn("event field not found");
474 return -1;
475 }
476
477 hid_set_field(field, offset, value);
478 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
1378 479
1379 spin_unlock_irqrestore(&hid->ctrllock, flags); 480 return 0;
1380} 481}
1381 482
1382int hid_wait_io(struct hid_device *hid) 483int usbhid_wait_io(struct hid_device *hid)
1383{ 484{
1384 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &hid->iofl) && 485 struct usbhid_device *usbhid = hid->driver_data;
1385 !test_bit(HID_OUT_RUNNING, &hid->iofl)), 486
487 if (!wait_event_timeout(hid->wait, (!test_bit(HID_CTRL_RUNNING, &usbhid->iofl) &&
488 !test_bit(HID_OUT_RUNNING, &usbhid->iofl)),
1386 10*HZ)) { 489 10*HZ)) {
1387 dbg("timeout waiting for ctrl or out queue to clear"); 490 dbg("timeout waiting for ctrl or out queue to clear");
1388 return -1; 491 return -1;
@@ -1414,7 +517,7 @@ static int hid_get_class_descriptor(struct usb_device *dev, int ifnum,
1414 return result; 517 return result;
1415} 518}
1416 519
1417int hid_open(struct hid_device *hid) 520int usbhid_open(struct hid_device *hid)
1418{ 521{
1419 ++hid->open; 522 ++hid->open;
1420 if (hid_start_in(hid)) 523 if (hid_start_in(hid))
@@ -1422,10 +525,24 @@ int hid_open(struct hid_device *hid)
1422 return 0; 525 return 0;
1423} 526}
1424 527
1425void hid_close(struct hid_device *hid) 528void usbhid_close(struct hid_device *hid)
1426{ 529{
530 struct usbhid_device *usbhid = hid->driver_data;
531
1427 if (!--hid->open) 532 if (!--hid->open)
1428 usb_kill_urb(hid->urbin); 533 usb_kill_urb(usbhid->urbin);
534}
535
536static int hidinput_open(struct input_dev *dev)
537{
538 struct hid_device *hid = dev->private;
539 return usbhid_open(hid);
540}
541
542static void hidinput_close(struct input_dev *dev)
543{
544 struct hid_device *hid = dev->private;
545 usbhid_close(hid);
1429} 546}
1430 547
1431#define USB_VENDOR_ID_PANJIT 0x134c 548#define USB_VENDOR_ID_PANJIT 0x134c
@@ -1437,26 +554,27 @@ void hid_close(struct hid_device *hid)
1437 * Initialize all reports 554 * Initialize all reports
1438 */ 555 */
1439 556
1440void hid_init_reports(struct hid_device *hid) 557void usbhid_init_reports(struct hid_device *hid)
1441{ 558{
1442 struct hid_report *report; 559 struct hid_report *report;
560 struct usbhid_device *usbhid = hid->driver_data;
1443 int err, ret; 561 int err, ret;
1444 562
1445 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list) 563 list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
1446 hid_submit_report(hid, report, USB_DIR_IN); 564 usbhid_submit_report(hid, report, USB_DIR_IN);
1447 565
1448 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list) 566 list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
1449 hid_submit_report(hid, report, USB_DIR_IN); 567 usbhid_submit_report(hid, report, USB_DIR_IN);
1450 568
1451 err = 0; 569 err = 0;
1452 ret = hid_wait_io(hid); 570 ret = usbhid_wait_io(hid);
1453 while (ret) { 571 while (ret) {
1454 err |= ret; 572 err |= ret;
1455 if (test_bit(HID_CTRL_RUNNING, &hid->iofl)) 573 if (test_bit(HID_CTRL_RUNNING, &usbhid->iofl))
1456 usb_kill_urb(hid->urbctrl); 574 usb_kill_urb(usbhid->urbctrl);
1457 if (test_bit(HID_OUT_RUNNING, &hid->iofl)) 575 if (test_bit(HID_OUT_RUNNING, &usbhid->iofl))
1458 usb_kill_urb(hid->urbout); 576 usb_kill_urb(usbhid->urbout);
1459 ret = hid_wait_io(hid); 577 ret = usbhid_wait_io(hid);
1460 } 578 }
1461 579
1462 if (err) 580 if (err)
@@ -1670,6 +788,9 @@ void hid_init_reports(struct hid_device *hid)
1670#define USB_VENDOR_ID_AIRCABLE 0x16CA 788#define USB_VENDOR_ID_AIRCABLE 0x16CA
1671#define USB_DEVICE_ID_AIRCABLE1 0x1502 789#define USB_DEVICE_ID_AIRCABLE1 0x1502
1672 790
791#define USB_VENDOR_ID_LOGITECH 0x046d
792#define USB_DEVICE_ID_LOGITECH_USB_RECEIVER 0xc101
793
1673/* 794/*
1674 * Alphabetically sorted blacklist by quirk type. 795 * Alphabetically sorted blacklist by quirk type.
1675 */ 796 */
@@ -1841,7 +962,9 @@ static const struct hid_blacklist {
1841 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE }, 962 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
1842 963
1843 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 964 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
1844 965
966 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_USB_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS },
967
1845 { 0, 0 } 968 { 0, 0 }
1846}; 969};
1847 970
@@ -1864,13 +987,15 @@ static void hid_find_max_report(struct hid_device *hid, unsigned int type, int *
1864 987
1865static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) 988static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1866{ 989{
1867 if (!(hid->inbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->inbuf_dma))) 990 struct usbhid_device *usbhid = hid->driver_data;
991
992 if (!(usbhid->inbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->inbuf_dma)))
1868 return -1; 993 return -1;
1869 if (!(hid->outbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->outbuf_dma))) 994 if (!(usbhid->outbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->outbuf_dma)))
1870 return -1; 995 return -1;
1871 if (!(hid->cr = usb_buffer_alloc(dev, sizeof(*(hid->cr)), GFP_ATOMIC, &hid->cr_dma))) 996 if (!(usbhid->cr = usb_buffer_alloc(dev, sizeof(*(usbhid->cr)), GFP_ATOMIC, &usbhid->cr_dma)))
1872 return -1; 997 return -1;
1873 if (!(hid->ctrlbuf = usb_buffer_alloc(dev, hid->bufsize, GFP_ATOMIC, &hid->ctrlbuf_dma))) 998 if (!(usbhid->ctrlbuf = usb_buffer_alloc(dev, usbhid->bufsize, GFP_ATOMIC, &usbhid->ctrlbuf_dma)))
1874 return -1; 999 return -1;
1875 1000
1876 return 0; 1001 return 0;
@@ -1878,14 +1003,16 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid)
1878 1003
1879static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid) 1004static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
1880{ 1005{
1881 if (hid->inbuf) 1006 struct usbhid_device *usbhid = hid->driver_data;
1882 usb_buffer_free(dev, hid->bufsize, hid->inbuf, hid->inbuf_dma); 1007
1883 if (hid->outbuf) 1008 if (usbhid->inbuf)
1884 usb_buffer_free(dev, hid->bufsize, hid->outbuf, hid->outbuf_dma); 1009 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
1885 if (hid->cr) 1010 if (usbhid->outbuf)
1886 usb_buffer_free(dev, sizeof(*(hid->cr)), hid->cr, hid->cr_dma); 1011 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
1887 if (hid->ctrlbuf) 1012 if (usbhid->cr)
1888 usb_buffer_free(dev, hid->bufsize, hid->ctrlbuf, hid->ctrlbuf_dma); 1013 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
1014 if (usbhid->ctrlbuf)
1015 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
1889} 1016}
1890 1017
1891/* 1018/*
@@ -1911,6 +1038,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1911 unsigned quirks = 0, rsize = 0; 1038 unsigned quirks = 0, rsize = 0;
1912 char *rdesc; 1039 char *rdesc;
1913 int n, len, insize = 0; 1040 int n, len, insize = 0;
1041 struct usbhid_device *usbhid;
1914 1042
1915 /* Ignore all Wacom devices */ 1043 /* Ignore all Wacom devices */
1916 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM) 1044 if (le16_to_cpu(dev->descriptor.idVendor) == USB_VENDOR_ID_WACOM)
@@ -1980,13 +1108,19 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
1980 kfree(rdesc); 1108 kfree(rdesc);
1981 hid->quirks = quirks; 1109 hid->quirks = quirks;
1982 1110
1983 hid->bufsize = HID_MIN_BUFFER_SIZE; 1111 if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL)))
1984 hid_find_max_report(hid, HID_INPUT_REPORT, &hid->bufsize); 1112 goto fail;
1985 hid_find_max_report(hid, HID_OUTPUT_REPORT, &hid->bufsize); 1113
1986 hid_find_max_report(hid, HID_FEATURE_REPORT, &hid->bufsize); 1114 hid->driver_data = usbhid;
1115 usbhid->hid = hid;
1987 1116
1988 if (hid->bufsize > HID_MAX_BUFFER_SIZE) 1117 usbhid->bufsize = HID_MIN_BUFFER_SIZE;
1989 hid->bufsize = HID_MAX_BUFFER_SIZE; 1118 hid_find_max_report(hid, HID_INPUT_REPORT, &usbhid->bufsize);
1119 hid_find_max_report(hid, HID_OUTPUT_REPORT, &usbhid->bufsize);
1120 hid_find_max_report(hid, HID_FEATURE_REPORT, &usbhid->bufsize);
1121
1122 if (usbhid->bufsize > HID_MAX_BUFFER_SIZE)
1123 usbhid->bufsize = HID_MAX_BUFFER_SIZE;
1990 1124
1991 hid_find_max_report(hid, HID_INPUT_REPORT, &insize); 1125 hid_find_max_report(hid, HID_INPUT_REPORT, &insize);
1992 1126
@@ -2015,47 +1149,47 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
2015 interval = hid_mousepoll_interval; 1149 interval = hid_mousepoll_interval;
2016 1150
2017 if (usb_endpoint_dir_in(endpoint)) { 1151 if (usb_endpoint_dir_in(endpoint)) {
2018 if (hid->urbin) 1152 if (usbhid->urbin)
2019 continue; 1153 continue;
2020 if (!(hid->urbin = usb_alloc_urb(0, GFP_KERNEL))) 1154 if (!(usbhid->urbin = usb_alloc_urb(0, GFP_KERNEL)))
2021 goto fail; 1155 goto fail;
2022 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); 1156 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
2023 usb_fill_int_urb(hid->urbin, dev, pipe, hid->inbuf, insize, 1157 usb_fill_int_urb(usbhid->urbin, dev, pipe, usbhid->inbuf, insize,
2024 hid_irq_in, hid, interval); 1158 hid_irq_in, hid, interval);
2025 hid->urbin->transfer_dma = hid->inbuf_dma; 1159 usbhid->urbin->transfer_dma = usbhid->inbuf_dma;
2026 hid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1160 usbhid->urbin->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2027 } else { 1161 } else {
2028 if (hid->urbout) 1162 if (usbhid->urbout)
2029 continue; 1163 continue;
2030 if (!(hid->urbout = usb_alloc_urb(0, GFP_KERNEL))) 1164 if (!(usbhid->urbout = usb_alloc_urb(0, GFP_KERNEL)))
2031 goto fail; 1165 goto fail;
2032 pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress); 1166 pipe = usb_sndintpipe(dev, endpoint->bEndpointAddress);
2033 usb_fill_int_urb(hid->urbout, dev, pipe, hid->outbuf, 0, 1167 usb_fill_int_urb(usbhid->urbout, dev, pipe, usbhid->outbuf, 0,
2034 hid_irq_out, hid, interval); 1168 hid_irq_out, hid, interval);
2035 hid->urbout->transfer_dma = hid->outbuf_dma; 1169 usbhid->urbout->transfer_dma = usbhid->outbuf_dma;
2036 hid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1170 usbhid->urbout->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
2037 } 1171 }
2038 } 1172 }
2039 1173
2040 if (!hid->urbin) { 1174 if (!usbhid->urbin) {
2041 err("couldn't find an input interrupt endpoint"); 1175 err("couldn't find an input interrupt endpoint");
2042 goto fail; 1176 goto fail;
2043 } 1177 }
2044 1178
2045 init_waitqueue_head(&hid->wait); 1179 init_waitqueue_head(&hid->wait);
2046 1180
2047 INIT_WORK(&hid->reset_work, hid_reset); 1181 INIT_WORK(&usbhid->reset_work, hid_reset);
2048 setup_timer(&hid->io_retry, hid_retry_timeout, (unsigned long) hid); 1182 setup_timer(&usbhid->io_retry, hid_retry_timeout, (unsigned long) hid);
2049 1183
2050 spin_lock_init(&hid->inlock); 1184 spin_lock_init(&usbhid->inlock);
2051 spin_lock_init(&hid->outlock); 1185 spin_lock_init(&usbhid->outlock);
2052 spin_lock_init(&hid->ctrllock); 1186 spin_lock_init(&usbhid->ctrllock);
2053 1187
2054 hid->version = le16_to_cpu(hdesc->bcdHID); 1188 hid->version = le16_to_cpu(hdesc->bcdHID);
2055 hid->country = hdesc->bCountryCode; 1189 hid->country = hdesc->bCountryCode;
2056 hid->dev = dev; 1190 hid->dev = &dev->dev;
2057 hid->intf = intf; 1191 usbhid->intf = intf;
2058 hid->ifnum = interface->desc.bInterfaceNumber; 1192 usbhid->ifnum = interface->desc.bInterfaceNumber;
2059 1193
2060 hid->name[0] = 0; 1194 hid->name[0] = 0;
2061 1195
@@ -2073,6 +1207,10 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
2073 le16_to_cpu(dev->descriptor.idVendor), 1207 le16_to_cpu(dev->descriptor.idVendor),
2074 le16_to_cpu(dev->descriptor.idProduct)); 1208 le16_to_cpu(dev->descriptor.idProduct));
2075 1209
1210 hid->bus = BUS_USB;
1211 hid->vendor = dev->descriptor.idVendor;
1212 hid->product = dev->descriptor.idProduct;
1213
2076 usb_make_path(dev, hid->phys, sizeof(hid->phys)); 1214 usb_make_path(dev, hid->phys, sizeof(hid->phys));
2077 strlcat(hid->phys, "/input", sizeof(hid->phys)); 1215 strlcat(hid->phys, "/input", sizeof(hid->phys));
2078 len = strlen(hid->phys); 1216 len = strlen(hid->phys);
@@ -2083,22 +1221,32 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
2083 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0) 1221 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
2084 hid->uniq[0] = 0; 1222 hid->uniq[0] = 0;
2085 1223
2086 hid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); 1224 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
2087 if (!hid->urbctrl) 1225 if (!usbhid->urbctrl)
2088 goto fail; 1226 goto fail;
2089 1227
2090 usb_fill_control_urb(hid->urbctrl, dev, 0, (void *) hid->cr, 1228 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
2091 hid->ctrlbuf, 1, hid_ctrl, hid); 1229 usbhid->ctrlbuf, 1, hid_ctrl, hid);
2092 hid->urbctrl->setup_dma = hid->cr_dma; 1230 usbhid->urbctrl->setup_dma = usbhid->cr_dma;
2093 hid->urbctrl->transfer_dma = hid->ctrlbuf_dma; 1231 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
2094 hid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 1232 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
1233 hid->hidinput_input_event = usb_hidinput_input_event;
1234 hid->hidinput_open = hidinput_open;
1235 hid->hidinput_close = hidinput_close;
1236#ifdef CONFIG_USB_HIDDEV
1237 hid->hiddev_hid_event = hiddev_hid_event;
1238 hid->hiddev_report_event = hiddev_report_event;
1239#endif
1240#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
1241 hid->pb_fnmode = usbhid_pb_fnmode;
1242#endif
2095 1243
2096 return hid; 1244 return hid;
2097 1245
2098fail: 1246fail:
2099 usb_free_urb(hid->urbin); 1247 usb_free_urb(usbhid->urbin);
2100 usb_free_urb(hid->urbout); 1248 usb_free_urb(usbhid->urbout);
2101 usb_free_urb(hid->urbctrl); 1249 usb_free_urb(usbhid->urbctrl);
2102 hid_free_buffers(dev, hid); 1250 hid_free_buffers(dev, hid);
2103 hid_free_device(hid); 1251 hid_free_device(hid);
2104 1252
@@ -2108,18 +1256,21 @@ fail:
2108static void hid_disconnect(struct usb_interface *intf) 1256static void hid_disconnect(struct usb_interface *intf)
2109{ 1257{
2110 struct hid_device *hid = usb_get_intfdata (intf); 1258 struct hid_device *hid = usb_get_intfdata (intf);
1259 struct usbhid_device *usbhid;
2111 1260
2112 if (!hid) 1261 if (!hid)
2113 return; 1262 return;
2114 1263
2115 spin_lock_irq(&hid->inlock); /* Sync with error handler */ 1264 usbhid = hid->driver_data;
1265
1266 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
2116 usb_set_intfdata(intf, NULL); 1267 usb_set_intfdata(intf, NULL);
2117 spin_unlock_irq(&hid->inlock); 1268 spin_unlock_irq(&usbhid->inlock);
2118 usb_kill_urb(hid->urbin); 1269 usb_kill_urb(usbhid->urbin);
2119 usb_kill_urb(hid->urbout); 1270 usb_kill_urb(usbhid->urbout);
2120 usb_kill_urb(hid->urbctrl); 1271 usb_kill_urb(usbhid->urbctrl);
2121 1272
2122 del_timer_sync(&hid->io_retry); 1273 del_timer_sync(&usbhid->io_retry);
2123 flush_scheduled_work(); 1274 flush_scheduled_work();
2124 1275
2125 if (hid->claimed & HID_CLAIMED_INPUT) 1276 if (hid->claimed & HID_CLAIMED_INPUT)
@@ -2127,11 +1278,11 @@ static void hid_disconnect(struct usb_interface *intf)
2127 if (hid->claimed & HID_CLAIMED_HIDDEV) 1278 if (hid->claimed & HID_CLAIMED_HIDDEV)
2128 hiddev_disconnect(hid); 1279 hiddev_disconnect(hid);
2129 1280
2130 usb_free_urb(hid->urbin); 1281 usb_free_urb(usbhid->urbin);
2131 usb_free_urb(hid->urbctrl); 1282 usb_free_urb(usbhid->urbctrl);
2132 usb_free_urb(hid->urbout); 1283 usb_free_urb(usbhid->urbout);
2133 1284
2134 hid_free_buffers(hid->dev, hid); 1285 hid_free_buffers(to_usb_device(hid->dev), hid);
2135 hid_free_device(hid); 1286 hid_free_device(hid);
2136} 1287}
2137 1288
@@ -2148,7 +1299,7 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
2148 if (!(hid = usb_hid_configure(intf))) 1299 if (!(hid = usb_hid_configure(intf)))
2149 return -ENODEV; 1300 return -ENODEV;
2150 1301
2151 hid_init_reports(hid); 1302 usbhid_init_reports(hid);
2152 hid_dump_device(hid); 1303 hid_dump_device(hid);
2153 1304
2154 if (!hidinput_connect(hid)) 1305 if (!hidinput_connect(hid))
@@ -2164,6 +1315,13 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
2164 return -ENODEV; 1315 return -ENODEV;
2165 } 1316 }
2166 1317
1318 /* This only gets called when we are a single-input (most of the
1319 * time). IOW, not a HID_QUIRK_MULTI_INPUT. The hid_ff_init() is
1320 * only useful in this case, and not for multi-input quirks. */
1321 if ((hid->claimed & HID_CLAIMED_INPUT) &&
1322 !(hid->quirks & HID_QUIRK_MULTI_INPUT))
1323 hid_ff_init(hid);
1324
2167 printk(KERN_INFO); 1325 printk(KERN_INFO);
2168 1326
2169 if (hid->claimed & HID_CLAIMED_INPUT) 1327 if (hid->claimed & HID_CLAIMED_INPUT)
@@ -2194,12 +1352,13 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
2194static int hid_suspend(struct usb_interface *intf, pm_message_t message) 1352static int hid_suspend(struct usb_interface *intf, pm_message_t message)
2195{ 1353{
2196 struct hid_device *hid = usb_get_intfdata (intf); 1354 struct hid_device *hid = usb_get_intfdata (intf);
1355 struct usbhid_device *usbhid = hid->driver_data;
2197 1356
2198 spin_lock_irq(&hid->inlock); /* Sync with error handler */ 1357 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
2199 set_bit(HID_SUSPENDED, &hid->iofl); 1358 set_bit(HID_SUSPENDED, &usbhid->iofl);
2200 spin_unlock_irq(&hid->inlock); 1359 spin_unlock_irq(&usbhid->inlock);
2201 del_timer(&hid->io_retry); 1360 del_timer(&usbhid->io_retry);
2202 usb_kill_urb(hid->urbin); 1361 usb_kill_urb(usbhid->urbin);
2203 dev_dbg(&intf->dev, "suspend\n"); 1362 dev_dbg(&intf->dev, "suspend\n");
2204 return 0; 1363 return 0;
2205} 1364}
@@ -2207,10 +1366,11 @@ static int hid_suspend(struct usb_interface *intf, pm_message_t message)
2207static int hid_resume(struct usb_interface *intf) 1366static int hid_resume(struct usb_interface *intf)
2208{ 1367{
2209 struct hid_device *hid = usb_get_intfdata (intf); 1368 struct hid_device *hid = usb_get_intfdata (intf);
1369 struct usbhid_device *usbhid = hid->driver_data;
2210 int status; 1370 int status;
2211 1371
2212 clear_bit(HID_SUSPENDED, &hid->iofl); 1372 clear_bit(HID_SUSPENDED, &usbhid->iofl);
2213 hid->retry_delay = 0; 1373 usbhid->retry_delay = 0;
2214 status = hid_start_in(hid); 1374 status = hid_start_in(hid);
2215 dev_dbg(&intf->dev, "resume status %d\n", status); 1375 dev_dbg(&intf->dev, "resume status %d\n", status);
2216 return status; 1376 return status;
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index a8fc46c721c5..f8f660ee3fac 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -32,7 +32,7 @@
32#undef DEBUG 32#undef DEBUG
33#include <linux/usb.h> 33#include <linux/usb.h>
34 34
35#include "hid.h" 35#include <linux/hid.h>
36 36
37/* 37/*
38 * This table contains pointers to initializers. To add support for new 38 * This table contains pointers to initializers. To add support for new
@@ -70,8 +70,8 @@ static struct hid_ff_initializer inits[] = {
70int hid_ff_init(struct hid_device* hid) 70int hid_ff_init(struct hid_device* hid)
71{ 71{
72 struct hid_ff_initializer *init; 72 struct hid_ff_initializer *init;
73 int vendor = le16_to_cpu(hid->dev->descriptor.idVendor); 73 int vendor = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idVendor);
74 int product = le16_to_cpu(hid->dev->descriptor.idProduct); 74 int product = le16_to_cpu(to_usb_device(hid->dev)->descriptor.idProduct);
75 75
76 for (init = inits; init->idVendor; init++) 76 for (init = inits; init->idVendor; init++)
77 if (init->idVendor == vendor && init->idProduct == product) 77 if (init->idVendor == vendor && init->idProduct == product)
@@ -79,3 +79,5 @@ int hid_ff_init(struct hid_device* hid)
79 79
80 return init->init(hid); 80 return init->init(hid);
81} 81}
82EXPORT_SYMBOL_GPL(hid_ff_init);
83
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 93da222b6da8..e47466268565 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -29,7 +29,8 @@
29 29
30#include <linux/input.h> 30#include <linux/input.h>
31#include <linux/usb.h> 31#include <linux/usb.h>
32#include "hid.h" 32#include <linux/hid.h>
33#include "usbhid.h"
33 34
34struct device_type { 35struct device_type {
35 u16 idVendor; 36 u16 idVendor;
@@ -75,7 +76,7 @@ static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *ef
75 report->field[0]->value[2] = x; 76 report->field[0]->value[2] = x;
76 report->field[0]->value[3] = y; 77 report->field[0]->value[3] = y;
77 dbg("(x, y)=(%04x, %04x)", x, y); 78 dbg("(x, y)=(%04x, %04x)", x, y);
78 hid_submit_report(hid, report, USB_DIR_OUT); 79 usbhid_submit_report(hid, report, USB_DIR_OUT);
79 break; 80 break;
80 81
81 case FF_RUMBLE: 82 case FF_RUMBLE:
@@ -90,7 +91,7 @@ static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *ef
90 report->field[0]->value[2] = left; 91 report->field[0]->value[2] = left;
91 report->field[0]->value[3] = right; 92 report->field[0]->value[3] = right;
92 dbg("(left, right)=(%04x, %04x)", left, right); 93 dbg("(left, right)=(%04x, %04x)", left, right);
93 hid_submit_report(hid, report, USB_DIR_OUT); 94 usbhid_submit_report(hid, report, USB_DIR_OUT);
94 break; 95 break;
95 } 96 }
96 return 0; 97 return 0;
diff --git a/drivers/usb/input/hid-pidff.c b/drivers/usb/input/hid-pidff.c
index 5420c13eb8eb..cbd2d53fefff 100644
--- a/drivers/usb/input/hid-pidff.c
+++ b/drivers/usb/input/hid-pidff.c
@@ -28,7 +28,9 @@
28#include <linux/input.h> 28#include <linux/input.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30 30
31#include "hid.h" 31#include <linux/hid.h>
32
33#include "usbhid.h"
32 34
33#define PID_EFFECTS_MAX 64 35#define PID_EFFECTS_MAX 64
34 36
@@ -260,7 +262,7 @@ static void pidff_set_envelope_report(struct pidff_device *pidff,
260 debug("attack %u => %d", envelope->attack_level, 262 debug("attack %u => %d", envelope->attack_level,
261 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]); 263 pidff->set_envelope[PID_ATTACK_LEVEL].value[0]);
262 264
263 hid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE], 265 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_ENVELOPE],
264 USB_DIR_OUT); 266 USB_DIR_OUT);
265} 267}
266 268
@@ -287,7 +289,7 @@ static void pidff_set_constant_force_report(struct pidff_device *pidff,
287 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE], 289 pidff_set_signed(&pidff->set_constant[PID_MAGNITUDE],
288 effect->u.constant.level); 290 effect->u.constant.level);
289 291
290 hid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT], 292 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONSTANT],
291 USB_DIR_OUT); 293 USB_DIR_OUT);
292} 294}
293 295
@@ -322,7 +324,7 @@ static void pidff_set_effect_report(struct pidff_device *pidff,
322 pidff->effect_direction); 324 pidff->effect_direction);
323 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay; 325 pidff->set_effect[PID_START_DELAY].value[0] = effect->replay.delay;
324 326
325 hid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT], 327 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
326 USB_DIR_OUT); 328 USB_DIR_OUT);
327} 329}
328 330
@@ -354,7 +356,7 @@ static void pidff_set_periodic_report(struct pidff_device *pidff,
354 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase); 356 pidff_set(&pidff->set_periodic[PID_PHASE], effect->u.periodic.phase);
355 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period; 357 pidff->set_periodic[PID_PERIOD].value[0] = effect->u.periodic.period;
356 358
357 hid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC], 359 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_PERIODIC],
358 USB_DIR_OUT); 360 USB_DIR_OUT);
359 361
360} 362}
@@ -396,8 +398,8 @@ static void pidff_set_condition_report(struct pidff_device *pidff,
396 effect->u.condition[i].left_saturation); 398 effect->u.condition[i].left_saturation);
397 pidff_set(&pidff->set_condition[PID_DEAD_BAND], 399 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
398 effect->u.condition[i].deadband); 400 effect->u.condition[i].deadband);
399 hid_wait_io(pidff->hid); 401 usbhid_wait_io(pidff->hid);
400 hid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION], 402 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION],
401 USB_DIR_OUT); 403 USB_DIR_OUT);
402 } 404 }
403} 405}
@@ -438,7 +440,7 @@ static void pidff_set_ramp_force_report(struct pidff_device *pidff,
438 effect->u.ramp.start_level); 440 effect->u.ramp.start_level);
439 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END], 441 pidff_set_signed(&pidff->set_ramp[PID_RAMP_END],
440 effect->u.ramp.end_level); 442 effect->u.ramp.end_level);
441 hid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP], 443 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_RAMP],
442 USB_DIR_OUT); 444 USB_DIR_OUT);
443} 445}
444 446
@@ -463,19 +465,19 @@ static int pidff_request_effect_upload(struct pidff_device *pidff, int efnum)
463 int j; 465 int j;
464 466
465 pidff->create_new_effect_type->value[0] = efnum; 467 pidff->create_new_effect_type->value[0] = efnum;
466 hid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT], 468 usbhid_submit_report(pidff->hid, pidff->reports[PID_CREATE_NEW_EFFECT],
467 USB_DIR_OUT); 469 USB_DIR_OUT);
468 debug("create_new_effect sent, type: %d", efnum); 470 debug("create_new_effect sent, type: %d", efnum);
469 471
470 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0; 472 pidff->block_load[PID_EFFECT_BLOCK_INDEX].value[0] = 0;
471 pidff->block_load_status->value[0] = 0; 473 pidff->block_load_status->value[0] = 0;
472 hid_wait_io(pidff->hid); 474 usbhid_wait_io(pidff->hid);
473 475
474 for (j = 0; j < 60; j++) { 476 for (j = 0; j < 60; j++) {
475 debug("pid_block_load requested"); 477 debug("pid_block_load requested");
476 hid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD], 478 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_LOAD],
477 USB_DIR_IN); 479 USB_DIR_IN);
478 hid_wait_io(pidff->hid); 480 usbhid_wait_io(pidff->hid);
479 if (pidff->block_load_status->value[0] == 481 if (pidff->block_load_status->value[0] ==
480 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) { 482 pidff->status_id[PID_BLOCK_LOAD_SUCCESS]) {
481 debug("device reported free memory: %d bytes", 483 debug("device reported free memory: %d bytes",
@@ -511,8 +513,8 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
511 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n; 513 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
512 } 514 }
513 515
514 hid_wait_io(pidff->hid); 516 usbhid_wait_io(pidff->hid);
515 hid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION], 517 usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
516 USB_DIR_OUT); 518 USB_DIR_OUT);
517} 519}
518 520
@@ -534,7 +536,7 @@ static int pidff_playback(struct input_dev *dev, int effect_id, int value)
534static void pidff_erase_pid(struct pidff_device *pidff, int pid_id) 536static void pidff_erase_pid(struct pidff_device *pidff, int pid_id)
535{ 537{
536 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id; 538 pidff->block_free[PID_EFFECT_BLOCK_INDEX].value[0] = pid_id;
537 hid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE], 539 usbhid_submit_report(pidff->hid, pidff->reports[PID_BLOCK_FREE],
538 USB_DIR_OUT); 540 USB_DIR_OUT);
539} 541}
540 542
@@ -714,7 +716,7 @@ static void pidff_set_gain(struct input_dev *dev, u16 gain)
714 struct pidff_device *pidff = dev->ff->private; 716 struct pidff_device *pidff = dev->ff->private;
715 717
716 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain); 718 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], gain);
717 hid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN], 719 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
718 USB_DIR_OUT); 720 USB_DIR_OUT);
719} 721}
720 722
@@ -739,7 +741,7 @@ static void pidff_autocenter(struct pidff_device *pidff, u16 magnitude)
739 pidff_set(&pidff->set_effect[PID_GAIN], magnitude); 741 pidff_set(&pidff->set_effect[PID_GAIN], magnitude);
740 pidff->set_effect[PID_START_DELAY].value[0] = 0; 742 pidff->set_effect[PID_START_DELAY].value[0] = 0;
741 743
742 hid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT], 744 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_EFFECT],
743 USB_DIR_OUT); 745 USB_DIR_OUT);
744} 746}
745 747
@@ -1163,19 +1165,19 @@ static void pidff_reset(struct pidff_device *pidff)
1163 1165
1164 pidff->device_control->value[0] = pidff->control_id[PID_RESET]; 1166 pidff->device_control->value[0] = pidff->control_id[PID_RESET];
1165 /* We reset twice as sometimes hid_wait_io isn't waiting long enough */ 1167 /* We reset twice as sometimes hid_wait_io isn't waiting long enough */
1166 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); 1168 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1167 hid_wait_io(hid); 1169 usbhid_wait_io(hid);
1168 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); 1170 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1169 hid_wait_io(hid); 1171 usbhid_wait_io(hid);
1170 1172
1171 pidff->device_control->value[0] = 1173 pidff->device_control->value[0] =
1172 pidff->control_id[PID_ENABLE_ACTUATORS]; 1174 pidff->control_id[PID_ENABLE_ACTUATORS];
1173 hid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT); 1175 usbhid_submit_report(hid, pidff->reports[PID_DEVICE_CONTROL], USB_DIR_OUT);
1174 hid_wait_io(hid); 1176 usbhid_wait_io(hid);
1175 1177
1176 /* pool report is sometimes messed up, refetch it */ 1178 /* pool report is sometimes messed up, refetch it */
1177 hid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN); 1179 usbhid_submit_report(hid, pidff->reports[PID_POOL], USB_DIR_IN);
1178 hid_wait_io(hid); 1180 usbhid_wait_io(hid);
1179 1181
1180 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) { 1182 if (pidff->pool[PID_SIMULTANEOUS_MAX].value) {
1181 int sim_effects = pidff->pool[PID_SIMULTANEOUS_MAX].value[0]; 1183 int sim_effects = pidff->pool[PID_SIMULTANEOUS_MAX].value[0];
@@ -1187,9 +1189,9 @@ static void pidff_reset(struct pidff_device *pidff)
1187 break; 1189 break;
1188 } 1190 }
1189 debug("pid_pool requested again"); 1191 debug("pid_pool requested again");
1190 hid_submit_report(hid, pidff->reports[PID_POOL], 1192 usbhid_submit_report(hid, pidff->reports[PID_POOL],
1191 USB_DIR_IN); 1193 USB_DIR_IN);
1192 hid_wait_io(hid); 1194 usbhid_wait_io(hid);
1193 } 1195 }
1194 } 1196 }
1195} 1197}
@@ -1275,7 +1277,7 @@ int hid_pidff_init(struct hid_device *hid)
1275 1277
1276 if (test_bit(FF_GAIN, dev->ffbit)) { 1278 if (test_bit(FF_GAIN, dev->ffbit)) {
1277 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff); 1279 pidff_set(&pidff->device_gain[PID_DEVICE_GAIN_FIELD], 0xffff);
1278 hid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN], 1280 usbhid_submit_report(pidff->hid, pidff->reports[PID_DEVICE_GAIN],
1279 USB_DIR_OUT); 1281 USB_DIR_OUT);
1280 } 1282 }
1281 1283
diff --git a/drivers/usb/input/hid-tmff.c b/drivers/usb/input/hid-tmff.c
index 2d5be4c318ac..ab67331620d0 100644
--- a/drivers/usb/input/hid-tmff.c
+++ b/drivers/usb/input/hid-tmff.c
@@ -32,7 +32,8 @@
32#undef DEBUG 32#undef DEBUG
33#include <linux/usb.h> 33#include <linux/usb.h>
34 34
35#include "hid.h" 35#include <linux/hid.h>
36#include "usbhid.h"
36 37
37/* Usages for thrustmaster devices I know about */ 38/* Usages for thrustmaster devices I know about */
38#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb) 39#define THRUSTMASTER_USAGE_RUMBLE_LR (HID_UP_GENDESK | 0xbb)
@@ -70,7 +71,7 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef
70 tmff->rumble->value[0] = left; 71 tmff->rumble->value[0] = left;
71 tmff->rumble->value[1] = right; 72 tmff->rumble->value[1] = right;
72 dbg("(left,right)=(%08x, %08x)", left, right); 73 dbg("(left,right)=(%08x, %08x)", left, right);
73 hid_submit_report(hid, tmff->report, USB_DIR_OUT); 74 usbhid_submit_report(hid, tmff->report, USB_DIR_OUT);
74 75
75 return 0; 76 return 0;
76} 77}
diff --git a/drivers/usb/input/hid-zpff.c b/drivers/usb/input/hid-zpff.c
index d2ce3214572c..7bd8238ca212 100644
--- a/drivers/usb/input/hid-zpff.c
+++ b/drivers/usb/input/hid-zpff.c
@@ -27,7 +27,8 @@
27 27
28#include <linux/input.h> 28#include <linux/input.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include "hid.h" 30#include <linux/hid.h>
31#include "usbhid.h"
31 32
32struct zpff_device { 33struct zpff_device {
33 struct hid_report *report; 34 struct hid_report *report;
@@ -56,7 +57,7 @@ static int hid_zpff_play(struct input_dev *dev, void *data,
56 zpff->report->field[2]->value[0] = left; 57 zpff->report->field[2]->value[0] = left;
57 zpff->report->field[3]->value[0] = right; 58 zpff->report->field[3]->value[0] = right;
58 debug("running with 0x%02x 0x%02x", left, right); 59 debug("running with 0x%02x 0x%02x", left, right);
59 hid_submit_report(hid, zpff->report, USB_DIR_OUT); 60 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
60 61
61 return 0; 62 return 0;
62} 63}
@@ -101,7 +102,7 @@ int hid_zpff_init(struct hid_device *hid)
101 zpff->report->field[1]->value[0] = 0x02; 102 zpff->report->field[1]->value[0] = 0x02;
102 zpff->report->field[2]->value[0] = 0x00; 103 zpff->report->field[2]->value[0] = 0x00;
103 zpff->report->field[3]->value[0] = 0x00; 104 zpff->report->field[3]->value[0] = 0x00;
104 hid_submit_report(hid, zpff->report, USB_DIR_OUT); 105 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
105 106
106 printk(KERN_INFO "Force feedback for Zeroplus based devices by " 107 printk(KERN_INFO "Force feedback for Zeroplus based devices by "
107 "Anssi Hannula <anssi.hannula@gmail.com>\n"); 108 "Anssi Hannula <anssi.hannula@gmail.com>\n");
diff --git a/drivers/usb/input/hiddev.c b/drivers/usb/input/hiddev.c
index 7dc14d0cacc1..114d6c9f64b1 100644
--- a/drivers/usb/input/hiddev.c
+++ b/drivers/usb/input/hiddev.c
@@ -32,8 +32,9 @@
32#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
33#include <linux/input.h> 33#include <linux/input.h>
34#include <linux/usb.h> 34#include <linux/usb.h>
35#include "hid.h" 35#include <linux/hid.h>
36#include <linux/hiddev.h> 36#include <linux/hiddev.h>
37#include "usbhid.h"
37 38
38#ifdef CONFIG_USB_DYNAMIC_MINORS 39#ifdef CONFIG_USB_DYNAMIC_MINORS
39#define HIDDEV_MINOR_BASE 0 40#define HIDDEV_MINOR_BASE 0
@@ -196,7 +197,7 @@ void hiddev_hid_event(struct hid_device *hid, struct hid_field *field,
196 197
197 hiddev_send_event(hid, &uref); 198 hiddev_send_event(hid, &uref);
198} 199}
199 200EXPORT_SYMBOL_GPL(hiddev_hid_event);
200 201
201void hiddev_report_event(struct hid_device *hid, struct hid_report *report) 202void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
202{ 203{
@@ -213,6 +214,7 @@ void hiddev_report_event(struct hid_device *hid, struct hid_report *report)
213 214
214 hiddev_send_event(hid, &uref); 215 hiddev_send_event(hid, &uref);
215} 216}
217
216/* 218/*
217 * fasync file op 219 * fasync file op
218 */ 220 */
@@ -239,7 +241,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
239 241
240 if (!--list->hiddev->open) { 242 if (!--list->hiddev->open) {
241 if (list->hiddev->exist) 243 if (list->hiddev->exist)
242 hid_close(list->hiddev->hid); 244 usbhid_close(list->hiddev->hid);
243 else 245 else
244 kfree(list->hiddev); 246 kfree(list->hiddev);
245 } 247 }
@@ -270,7 +272,7 @@ static int hiddev_open(struct inode *inode, struct file *file)
270 272
271 if (!list->hiddev->open++) 273 if (!list->hiddev->open++)
272 if (list->hiddev->exist) 274 if (list->hiddev->exist)
273 hid_open(hiddev_table[i]->hid); 275 usbhid_open(hiddev_table[i]->hid);
274 276
275 return 0; 277 return 0;
276} 278}
@@ -382,7 +384,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
382 struct hiddev_list *list = file->private_data; 384 struct hiddev_list *list = file->private_data;
383 struct hiddev *hiddev = list->hiddev; 385 struct hiddev *hiddev = list->hiddev;
384 struct hid_device *hid = hiddev->hid; 386 struct hid_device *hid = hiddev->hid;
385 struct usb_device *dev = hid->dev; 387 struct usb_device *dev = to_usb_device(hid->dev);
386 struct hiddev_collection_info cinfo; 388 struct hiddev_collection_info cinfo;
387 struct hiddev_report_info rinfo; 389 struct hiddev_report_info rinfo;
388 struct hiddev_field_info finfo; 390 struct hiddev_field_info finfo;
@@ -391,6 +393,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
391 struct hiddev_devinfo dinfo; 393 struct hiddev_devinfo dinfo;
392 struct hid_report *report; 394 struct hid_report *report;
393 struct hid_field *field; 395 struct hid_field *field;
396 struct usbhid_device *usbhid = hid->driver_data;
394 void __user *user_arg = (void __user *)arg; 397 void __user *user_arg = (void __user *)arg;
395 int i; 398 int i;
396 399
@@ -420,7 +423,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
420 dinfo.bustype = BUS_USB; 423 dinfo.bustype = BUS_USB;
421 dinfo.busnum = dev->bus->busnum; 424 dinfo.busnum = dev->bus->busnum;
422 dinfo.devnum = dev->devnum; 425 dinfo.devnum = dev->devnum;
423 dinfo.ifnum = hid->ifnum; 426 dinfo.ifnum = usbhid->ifnum;
424 dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor); 427 dinfo.vendor = le16_to_cpu(dev->descriptor.idVendor);
425 dinfo.product = le16_to_cpu(dev->descriptor.idProduct); 428 dinfo.product = le16_to_cpu(dev->descriptor.idProduct);
426 dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice); 429 dinfo.version = le16_to_cpu(dev->descriptor.bcdDevice);
@@ -479,7 +482,7 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
479 } 482 }
480 483
481 case HIDIOCINITREPORT: 484 case HIDIOCINITREPORT:
482 hid_init_reports(hid); 485 usbhid_init_reports(hid);
483 486
484 return 0; 487 return 0;
485 488
@@ -493,8 +496,8 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
493 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 496 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
494 return -EINVAL; 497 return -EINVAL;
495 498
496 hid_submit_report(hid, report, USB_DIR_IN); 499 usbhid_submit_report(hid, report, USB_DIR_IN);
497 hid_wait_io(hid); 500 usbhid_wait_io(hid);
498 501
499 return 0; 502 return 0;
500 503
@@ -508,8 +511,8 @@ static int hiddev_ioctl(struct inode *inode, struct file *file, unsigned int cmd
508 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL) 511 if ((report = hiddev_lookup_report(hid, &rinfo)) == NULL)
509 return -EINVAL; 512 return -EINVAL;
510 513
511 hid_submit_report(hid, report, USB_DIR_OUT); 514 usbhid_submit_report(hid, report, USB_DIR_OUT);
512 hid_wait_io(hid); 515 usbhid_wait_io(hid);
513 516
514 return 0; 517 return 0;
515 518
@@ -745,6 +748,7 @@ static struct usb_class_driver hiddev_class = {
745int hiddev_connect(struct hid_device *hid) 748int hiddev_connect(struct hid_device *hid)
746{ 749{
747 struct hiddev *hiddev; 750 struct hiddev *hiddev;
751 struct usbhid_device *usbhid = hid->driver_data;
748 int i; 752 int i;
749 int retval; 753 int retval;
750 754
@@ -760,7 +764,7 @@ int hiddev_connect(struct hid_device *hid)
760 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) 764 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
761 return -1; 765 return -1;
762 766
763 retval = usb_register_dev(hid->intf, &hiddev_class); 767 retval = usb_register_dev(usbhid->intf, &hiddev_class);
764 if (retval) { 768 if (retval) {
765 err("Not able to get a minor for this device."); 769 err("Not able to get a minor for this device.");
766 kfree(hiddev); 770 kfree(hiddev);
@@ -772,10 +776,10 @@ int hiddev_connect(struct hid_device *hid)
772 hiddev->hid = hid; 776 hiddev->hid = hid;
773 hiddev->exist = 1; 777 hiddev->exist = 1;
774 778
775 hid->minor = hid->intf->minor; 779 hid->minor = usbhid->intf->minor;
776 hid->hiddev = hiddev; 780 hid->hiddev = hiddev;
777 781
778 hiddev_table[hid->intf->minor - HIDDEV_MINOR_BASE] = hiddev; 782 hiddev_table[usbhid->intf->minor - HIDDEV_MINOR_BASE] = hiddev;
779 783
780 return 0; 784 return 0;
781} 785}
@@ -788,14 +792,15 @@ static struct usb_class_driver hiddev_class;
788void hiddev_disconnect(struct hid_device *hid) 792void hiddev_disconnect(struct hid_device *hid)
789{ 793{
790 struct hiddev *hiddev = hid->hiddev; 794 struct hiddev *hiddev = hid->hiddev;
795 struct usbhid_device *usbhid = hid->driver_data;
791 796
792 hiddev->exist = 0; 797 hiddev->exist = 0;
793 798
794 hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL; 799 hiddev_table[hiddev->hid->minor - HIDDEV_MINOR_BASE] = NULL;
795 usb_deregister_dev(hiddev->hid->intf, &hiddev_class); 800 usb_deregister_dev(usbhid->intf, &hiddev_class);
796 801
797 if (hiddev->open) { 802 if (hiddev->open) {
798 hid_close(hiddev->hid); 803 usbhid_close(hiddev->hid);
799 wake_up_interruptible(&hiddev->wait); 804 wake_up_interruptible(&hiddev->wait);
800 } else { 805 } else {
801 kfree(hiddev); 806 kfree(hiddev);
diff --git a/drivers/usb/input/usbhid.h b/drivers/usb/input/usbhid.h
new file mode 100644
index 000000000000..830107e5251f
--- /dev/null
+++ b/drivers/usb/input/usbhid.h
@@ -0,0 +1,84 @@
1#ifndef __USBHID_H
2#define __USBHID_H
3
4/*
5 * Copyright (c) 1999 Andreas Gal
6 * Copyright (c) 2000-2001 Vojtech Pavlik
7 * Copyright (c) 2006 Jiri Kosina
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#include <linux/types.h>
28#include <linux/slab.h>
29#include <linux/list.h>
30#include <linux/timer.h>
31#include <linux/workqueue.h>
32#include <linux/input.h>
33
34/* API provided by hid-core.c for USB HID drivers */
35int usbhid_wait_io(struct hid_device* hid);
36void usbhid_close(struct hid_device *hid);
37int usbhid_open(struct hid_device *hid);
38void usbhid_init_reports(struct hid_device *hid);
39void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, unsigned char dir);
40
41/*
42 * USB-specific HID struct, to be pointed to
43 * from struct hid_device->driver_data
44 */
45
46struct usbhid_device {
47 struct hid_device *hid; /* pointer to corresponding HID dev */
48
49 struct usb_interface *intf; /* USB interface */
50 int ifnum; /* USB interface number */
51
52 unsigned int bufsize; /* URB buffer size */
53
54 struct urb *urbin; /* Input URB */
55 char *inbuf; /* Input buffer */
56 dma_addr_t inbuf_dma; /* Input buffer dma */
57 spinlock_t inlock; /* Input fifo spinlock */
58
59 struct urb *urbctrl; /* Control URB */
60 struct usb_ctrlrequest *cr; /* Control request struct */
61 dma_addr_t cr_dma; /* Control request struct dma */
62 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
63 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
64 char *ctrlbuf; /* Control buffer */
65 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
66 spinlock_t ctrllock; /* Control fifo spinlock */
67
68 struct urb *urbout; /* Output URB */
69 struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
70 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
71 char *outbuf; /* Output buffer */
72 dma_addr_t outbuf_dma; /* Output buffer dma */
73 spinlock_t outlock; /* Output fifo spinlock */
74
75 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
76 struct timer_list io_retry; /* Retry timer */
77 unsigned long stop_retry; /* Time to give up, in jiffies */
78 unsigned int retry_delay; /* Delay length in ms */
79 struct work_struct reset_work; /* Task context for resets */
80
81};
82
83#endif
84
diff --git a/drivers/usb/misc/sisusbvga/sisusb.c b/drivers/usb/misc/sisusbvga/sisusb.c
index b99ca9c79821..0398908b15d4 100644
--- a/drivers/usb/misc/sisusbvga/sisusb.c
+++ b/drivers/usb/misc/sisusbvga/sisusb.c
@@ -3168,7 +3168,7 @@ sisusb_compat_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
3168 case SISUSB_GET_CONFIG: 3168 case SISUSB_GET_CONFIG:
3169 case SISUSB_COMMAND: 3169 case SISUSB_COMMAND:
3170 lock_kernel(); 3170 lock_kernel();
3171 retval = sisusb_ioctl(f->f_dentry->d_inode, f, cmd, arg); 3171 retval = sisusb_ioctl(f->f_path.dentry->d_inode, f, cmd, arg);
3172 unlock_kernel(); 3172 unlock_kernel();
3173 return retval; 3173 return retval;
3174 3174
diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 863966c1c5ac..5261cd22ee6b 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -156,7 +156,7 @@ cleanup:
156} 156}
157 157
158static void ark3116_set_termios(struct usb_serial_port *port, 158static void ark3116_set_termios(struct usb_serial_port *port,
159 struct termios *old_termios) 159 struct ktermios *old_termios)
160{ 160{
161 struct usb_serial *serial = port->serial; 161 struct usb_serial *serial = port->serial;
162 struct ark3116_private *priv = usb_get_serial_port_data(port); 162 struct ark3116_private *priv = usb_get_serial_port_data(port);
@@ -326,7 +326,7 @@ static void ark3116_set_termios(struct usb_serial_port *port,
326 326
327static int ark3116_open(struct usb_serial_port *port, struct file *filp) 327static int ark3116_open(struct usb_serial_port *port, struct file *filp)
328{ 328{
329 struct termios tmp_termios; 329 struct ktermios tmp_termios;
330 struct usb_serial *serial = port->serial; 330 struct usb_serial *serial = port->serial;
331 char *buf; 331 char *buf;
332 int result = 0; 332 int result = 0;
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 8835bb58ca9b..38b4dae319ee 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -92,7 +92,7 @@ static void belkin_sa_shutdown (struct usb_serial *serial);
92static int belkin_sa_open (struct usb_serial_port *port, struct file *filp); 92static int belkin_sa_open (struct usb_serial_port *port, struct file *filp);
93static void belkin_sa_close (struct usb_serial_port *port, struct file *filp); 93static void belkin_sa_close (struct usb_serial_port *port, struct file *filp);
94static void belkin_sa_read_int_callback (struct urb *urb); 94static void belkin_sa_read_int_callback (struct urb *urb);
95static void belkin_sa_set_termios (struct usb_serial_port *port, struct termios * old); 95static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios * old);
96static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 96static int belkin_sa_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
97static void belkin_sa_break_ctl (struct usb_serial_port *port, int break_state ); 97static void belkin_sa_break_ctl (struct usb_serial_port *port, int break_state );
98static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file); 98static int belkin_sa_tiocmget (struct usb_serial_port *port, struct file *file);
@@ -333,7 +333,7 @@ exit:
333 __FUNCTION__, retval); 333 __FUNCTION__, retval);
334} 334}
335 335
336static void belkin_sa_set_termios (struct usb_serial_port *port, struct termios *old_termios) 336static void belkin_sa_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
337{ 337{
338 struct usb_serial *serial = port->serial; 338 struct usb_serial *serial = port->serial;
339 struct belkin_sa_private *priv = usb_get_serial_port_data(port); 339 struct belkin_sa_private *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 7167728d764c..9386e216d681 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -65,7 +65,7 @@ static int usb_console_setup(struct console *co, char *options)
65 struct usb_serial_port *port; 65 struct usb_serial_port *port;
66 int retval = 0; 66 int retval = 0;
67 struct tty_struct *tty; 67 struct tty_struct *tty;
68 struct termios *termios; 68 struct ktermios *termios;
69 69
70 dbg ("%s", __FUNCTION__); 70 dbg ("%s", __FUNCTION__);
71 71
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index f95d42c0d16a..2f9b7ac32663 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -41,7 +41,7 @@ static int cp2101_open(struct usb_serial_port*, struct file*);
41static void cp2101_cleanup(struct usb_serial_port*); 41static void cp2101_cleanup(struct usb_serial_port*);
42static void cp2101_close(struct usb_serial_port*, struct file*); 42static void cp2101_close(struct usb_serial_port*, struct file*);
43static void cp2101_get_termios(struct usb_serial_port*); 43static void cp2101_get_termios(struct usb_serial_port*);
44static void cp2101_set_termios(struct usb_serial_port*, struct termios*); 44static void cp2101_set_termios(struct usb_serial_port*, struct ktermios*);
45static int cp2101_tiocmget (struct usb_serial_port *, struct file *); 45static int cp2101_tiocmget (struct usb_serial_port *, struct file *);
46static int cp2101_tiocmset (struct usb_serial_port *, struct file *, 46static int cp2101_tiocmset (struct usb_serial_port *, struct file *,
47 unsigned int, unsigned int); 47 unsigned int, unsigned int);
@@ -506,7 +506,7 @@ static void cp2101_get_termios (struct usb_serial_port *port)
506} 506}
507 507
508static void cp2101_set_termios (struct usb_serial_port *port, 508static void cp2101_set_termios (struct usb_serial_port *port,
509 struct termios *old_termios) 509 struct ktermios *old_termios)
510{ 510{
511 unsigned int cflag, old_cflag=0; 511 unsigned int cflag, old_cflag=0;
512 int baud=0, bits; 512 int baud=0, bits;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 093f303b3189..a1fdb85b8c0a 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -143,7 +143,7 @@ struct cypress_private {
143 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */ 143 wait_queue_head_t delta_msr_wait; /* used for TIOCMIWAIT */
144 char prev_status, diff_status; /* used for TIOCMIWAIT */ 144 char prev_status, diff_status; /* used for TIOCMIWAIT */
145 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */ 145 /* we pass a pointer to this as the arguement sent to cypress_set_termios old_termios */
146 struct termios tmp_termios; /* stores the old termios settings */ 146 struct ktermios tmp_termios; /* stores the old termios settings */
147}; 147};
148 148
149/* write buffer structure */ 149/* write buffer structure */
@@ -165,7 +165,7 @@ static int cypress_write (struct usb_serial_port *port, const unsigned char *b
165static void cypress_send (struct usb_serial_port *port); 165static void cypress_send (struct usb_serial_port *port);
166static int cypress_write_room (struct usb_serial_port *port); 166static int cypress_write_room (struct usb_serial_port *port);
167static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 167static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
168static void cypress_set_termios (struct usb_serial_port *port, struct termios * old); 168static void cypress_set_termios (struct usb_serial_port *port, struct ktermios * old);
169static int cypress_tiocmget (struct usb_serial_port *port, struct file *file); 169static int cypress_tiocmget (struct usb_serial_port *port, struct file *file);
170static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 170static int cypress_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
171static int cypress_chars_in_buffer (struct usb_serial_port *port); 171static int cypress_chars_in_buffer (struct usb_serial_port *port);
@@ -949,13 +949,13 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
949 949
950 switch (cmd) { 950 switch (cmd) {
951 case TIOCGSERIAL: 951 case TIOCGSERIAL:
952 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct termios))) { 952 if (copy_to_user((void __user *)arg, port->tty->termios, sizeof(struct ktermios))) {
953 return -EFAULT; 953 return -EFAULT;
954 } 954 }
955 return (0); 955 return (0);
956 break; 956 break;
957 case TIOCSSERIAL: 957 case TIOCSSERIAL:
958 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct termios))) { 958 if (copy_from_user(port->tty->termios, (void __user *)arg, sizeof(struct ktermios))) {
959 return -EFAULT; 959 return -EFAULT;
960 } 960 }
961 /* here we need to call cypress_set_termios to invoke the new settings */ 961 /* here we need to call cypress_set_termios to invoke the new settings */
@@ -1019,7 +1019,7 @@ static int cypress_ioctl (struct usb_serial_port *port, struct file * file, unsi
1019 1019
1020 1020
1021static void cypress_set_termios (struct usb_serial_port *port, 1021static void cypress_set_termios (struct usb_serial_port *port,
1022 struct termios *old_termios) 1022 struct ktermios *old_termios)
1023{ 1023{
1024 struct cypress_private *priv = usb_get_serial_port_data(port); 1024 struct cypress_private *priv = usb_get_serial_port_data(port);
1025 struct tty_struct *tty; 1025 struct tty_struct *tty;
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 83d0e21145b0..9d9ea874639c 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -449,7 +449,7 @@ static int digi_transmit_idle( struct usb_serial_port *port,
449static void digi_rx_throttle (struct usb_serial_port *port); 449static void digi_rx_throttle (struct usb_serial_port *port);
450static void digi_rx_unthrottle (struct usb_serial_port *port); 450static void digi_rx_unthrottle (struct usb_serial_port *port);
451static void digi_set_termios( struct usb_serial_port *port, 451static void digi_set_termios( struct usb_serial_port *port,
452 struct termios *old_termios ); 452 struct ktermios *old_termios );
453static void digi_break_ctl( struct usb_serial_port *port, int break_state ); 453static void digi_break_ctl( struct usb_serial_port *port, int break_state );
454static int digi_ioctl( struct usb_serial_port *port, struct file *file, 454static int digi_ioctl( struct usb_serial_port *port, struct file *file,
455 unsigned int cmd, unsigned long arg ); 455 unsigned int cmd, unsigned long arg );
@@ -976,7 +976,7 @@ dbg( "digi_rx_unthrottle: TOP: port=%d", priv->dp_port_num );
976 976
977 977
978static void digi_set_termios( struct usb_serial_port *port, 978static void digi_set_termios( struct usb_serial_port *port,
979 struct termios *old_termios ) 979 struct ktermios *old_termios )
980{ 980{
981 981
982 struct digi_port *priv = usb_get_serial_port_data(port); 982 struct digi_port *priv = usb_get_serial_port_data(port);
@@ -1463,7 +1463,7 @@ static int digi_open( struct usb_serial_port *port, struct file *filp )
1463 int ret; 1463 int ret;
1464 unsigned char buf[32]; 1464 unsigned char buf[32];
1465 struct digi_port *priv = usb_get_serial_port_data(port); 1465 struct digi_port *priv = usb_get_serial_port_data(port);
1466 struct termios not_termios; 1466 struct ktermios not_termios;
1467 unsigned long flags = 0; 1467 unsigned long flags = 0;
1468 1468
1469 1469
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index 4ce10a831953..92beeb19795f 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -92,7 +92,7 @@ static int empeg_ioctl (struct usb_serial_port *port,
92 struct file * file, 92 struct file * file,
93 unsigned int cmd, 93 unsigned int cmd,
94 unsigned long arg); 94 unsigned long arg);
95static void empeg_set_termios (struct usb_serial_port *port, struct termios *old_termios); 95static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
96static void empeg_write_bulk_callback (struct urb *urb); 96static void empeg_write_bulk_callback (struct urb *urb);
97static void empeg_read_bulk_callback (struct urb *urb); 97static void empeg_read_bulk_callback (struct urb *urb);
98 98
@@ -442,7 +442,7 @@ static int empeg_ioctl (struct usb_serial_port *port, struct file * file, unsign
442} 442}
443 443
444 444
445static void empeg_set_termios (struct usb_serial_port *port, struct termios *old_termios) 445static void empeg_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
446{ 446{
447 447
448 dbg("%s - port %d", __FUNCTION__, port->number); 448 dbg("%s - port %d", __FUNCTION__, port->number);
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 72e4d48f51e9..41b0ad2d56ac 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -595,7 +595,7 @@ static int ftdi_chars_in_buffer (struct usb_serial_port *port);
595static void ftdi_write_bulk_callback (struct urb *urb); 595static void ftdi_write_bulk_callback (struct urb *urb);
596static void ftdi_read_bulk_callback (struct urb *urb); 596static void ftdi_read_bulk_callback (struct urb *urb);
597static void ftdi_process_read (struct work_struct *work); 597static void ftdi_process_read (struct work_struct *work);
598static void ftdi_set_termios (struct usb_serial_port *port, struct termios * old); 598static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios * old);
599static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file); 599static int ftdi_tiocmget (struct usb_serial_port *port, struct file *file);
600static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear); 600static int ftdi_tiocmset (struct usb_serial_port *port, struct file * file, unsigned int set, unsigned int clear);
601static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 601static int ftdi_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
@@ -1880,7 +1880,7 @@ static void ftdi_break_ctl( struct usb_serial_port *port, int break_state )
1880 * WARNING: set_termios calls this with old_termios in kernel space 1880 * WARNING: set_termios calls this with old_termios in kernel space
1881 */ 1881 */
1882 1882
1883static void ftdi_set_termios (struct usb_serial_port *port, struct termios *old_termios) 1883static void ftdi_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
1884{ /* ftdi_termios */ 1884{ /* ftdi_termios */
1885 struct usb_device *dev = port->serial->dev; 1885 struct usb_device *dev = port->serial->dev;
1886 unsigned int cflag = port->tty->termios->c_cflag; 1886 unsigned int cflag = port->tty->termios->c_cflag;
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index d06547a13f28..f623d58370a4 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -229,7 +229,7 @@ static int edge_write_room (struct usb_serial_port *port);
229static int edge_chars_in_buffer (struct usb_serial_port *port); 229static int edge_chars_in_buffer (struct usb_serial_port *port);
230static void edge_throttle (struct usb_serial_port *port); 230static void edge_throttle (struct usb_serial_port *port);
231static void edge_unthrottle (struct usb_serial_port *port); 231static void edge_unthrottle (struct usb_serial_port *port);
232static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios); 232static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
233static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 233static int edge_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg);
234static void edge_break (struct usb_serial_port *port, int break_state); 234static void edge_break (struct usb_serial_port *port, int break_state);
235static int edge_tiocmget (struct usb_serial_port *port, struct file *file); 235static int edge_tiocmget (struct usb_serial_port *port, struct file *file);
@@ -257,7 +257,7 @@ static void handle_new_lsr (struct edgeport_port *edge_port, __u8 lsrData, __u8
257static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param); 257static int send_iosp_ext_cmd (struct edgeport_port *edge_port, __u8 command, __u8 param);
258static int calc_baud_rate_divisor (int baud_rate, int *divisor); 258static int calc_baud_rate_divisor (int baud_rate, int *divisor);
259static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate); 259static int send_cmd_write_baud_rate (struct edgeport_port *edge_port, int baudRate);
260static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios); 260static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios);
261static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue); 261static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 regNum, __u8 regValue);
262static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength); 262static int write_cmd_usb (struct edgeport_port *edge_port, unsigned char *buffer, int writeLength);
263static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port); 263static void send_more_port_data (struct edgeport_serial *edge_serial, struct edgeport_port *edge_port);
@@ -1431,7 +1431,7 @@ static void edge_unthrottle (struct usb_serial_port *port)
1431 * SerialSetTermios 1431 * SerialSetTermios
1432 * this function is called by the tty driver when it wants to change the termios structure 1432 * this function is called by the tty driver when it wants to change the termios structure
1433 *****************************************************************************/ 1433 *****************************************************************************/
1434static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios) 1434static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
1435{ 1435{
1436 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1436 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1437 struct tty_struct *tty = port->tty; 1437 struct tty_struct *tty = port->tty;
@@ -2412,7 +2412,7 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2412#ifndef CMSPAR 2412#ifndef CMSPAR
2413#define CMSPAR 0 2413#define CMSPAR 0
2414#endif 2414#endif
2415static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios) 2415static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios)
2416{ 2416{
2417 struct tty_struct *tty; 2417 struct tty_struct *tty;
2418 int baud; 2418 int baud;
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index ee0c921e1520..2da2684e0809 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -238,7 +238,7 @@ static void edge_tty_recv(struct device *dev, struct tty_struct *tty, unsigned c
238static void stop_read(struct edgeport_port *edge_port); 238static void stop_read(struct edgeport_port *edge_port);
239static int restart_read(struct edgeport_port *edge_port); 239static int restart_read(struct edgeport_port *edge_port);
240 240
241static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios); 241static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
242static void edge_send(struct usb_serial_port *port); 242static void edge_send(struct usb_serial_port *port);
243 243
244/* circular buffer */ 244/* circular buffer */
@@ -2361,7 +2361,7 @@ static int restart_read(struct edgeport_port *edge_port)
2361 return status; 2361 return status;
2362} 2362}
2363 2363
2364static void change_port_settings (struct edgeport_port *edge_port, struct termios *old_termios) 2364static void change_port_settings (struct edgeport_port *edge_port, struct ktermios *old_termios)
2365{ 2365{
2366 struct ump_uart_config *config; 2366 struct ump_uart_config *config;
2367 struct tty_struct *tty; 2367 struct tty_struct *tty;
@@ -2512,7 +2512,7 @@ static void change_port_settings (struct edgeport_port *edge_port, struct termio
2512 return; 2512 return;
2513} 2513}
2514 2514
2515static void edge_set_termios (struct usb_serial_port *port, struct termios *old_termios) 2515static void edge_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
2516{ 2516{
2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2517 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
2518 struct tty_struct *tty = port->tty; 2518 struct tty_struct *tty = port->tty;
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 331bf81556fc..8fdf486e3465 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -107,7 +107,7 @@ static void ir_close (struct usb_serial_port *port, struct file *filep);
107static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count); 107static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count);
108static void ir_write_bulk_callback (struct urb *urb); 108static void ir_write_bulk_callback (struct urb *urb);
109static void ir_read_bulk_callback (struct urb *urb); 109static void ir_read_bulk_callback (struct urb *urb);
110static void ir_set_termios (struct usb_serial_port *port, struct termios *old_termios); 110static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
111 111
112static u8 ir_baud = 0; 112static u8 ir_baud = 0;
113static u8 ir_xbof = 0; 113static u8 ir_xbof = 0;
@@ -497,7 +497,7 @@ static void ir_read_bulk_callback (struct urb *urb)
497 return; 497 return;
498} 498}
499 499
500static void ir_set_termios (struct usb_serial_port *port, struct termios *old_termios) 500static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
501{ 501{
502 unsigned char *transfer_buffer; 502 unsigned char *transfer_buffer;
503 unsigned int cflag; 503 unsigned int cflag;
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 7639652cec42..9d2fdfd6865f 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -264,7 +264,7 @@ static void keyspan_break_ctl (struct usb_serial_port *port, int break_state)
264 264
265 265
266static void keyspan_set_termios (struct usb_serial_port *port, 266static void keyspan_set_termios (struct usb_serial_port *port,
267 struct termios *old_termios) 267 struct ktermios *old_termios)
268{ 268{
269 int baud_rate, device_port; 269 int baud_rate, device_port;
270 struct keyspan_port_private *p_priv; 270 struct keyspan_port_private *p_priv;
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index 7472ed6bf626..6413d73c139c 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -59,7 +59,7 @@ static int keyspan_ioctl (struct usb_serial_port *port,
59 unsigned int cmd, 59 unsigned int cmd,
60 unsigned long arg); 60 unsigned long arg);
61static void keyspan_set_termios (struct usb_serial_port *port, 61static void keyspan_set_termios (struct usb_serial_port *port,
62 struct termios *old); 62 struct ktermios *old);
63static void keyspan_break_ctl (struct usb_serial_port *port, 63static void keyspan_break_ctl (struct usb_serial_port *port,
64 int break_state); 64 int break_state);
65static int keyspan_tiocmget (struct usb_serial_port *port, 65static int keyspan_tiocmget (struct usb_serial_port *port,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index e09a0bfe6231..126b9703bbaf 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -365,7 +365,7 @@ static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state
365 365
366 366
367static void keyspan_pda_set_termios (struct usb_serial_port *port, 367static void keyspan_pda_set_termios (struct usb_serial_port *port,
368 struct termios *old_termios) 368 struct ktermios *old_termios)
369{ 369{
370 struct usb_serial *serial = port->serial; 370 struct usb_serial *serial = port->serial;
371 unsigned int cflag = port->tty->termios->c_cflag; 371 unsigned int cflag = port->tty->termios->c_cflag;
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index 17e205699c2b..73d755df4840 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -86,7 +86,7 @@ static int klsi_105_write_room (struct usb_serial_port *port);
86 86
87static void klsi_105_read_bulk_callback (struct urb *urb); 87static void klsi_105_read_bulk_callback (struct urb *urb);
88static void klsi_105_set_termios (struct usb_serial_port *port, 88static void klsi_105_set_termios (struct usb_serial_port *port,
89 struct termios * old); 89 struct ktermios *old);
90static int klsi_105_ioctl (struct usb_serial_port *port, 90static int klsi_105_ioctl (struct usb_serial_port *port,
91 struct file * file, 91 struct file * file,
92 unsigned int cmd, 92 unsigned int cmd,
@@ -164,7 +164,7 @@ struct klsi_105_port_settings {
164#define URB_TRANSFER_BUFFER_SIZE 64 164#define URB_TRANSFER_BUFFER_SIZE 64
165struct klsi_105_private { 165struct klsi_105_private {
166 struct klsi_105_port_settings cfg; 166 struct klsi_105_port_settings cfg;
167 struct termios termios; 167 struct ktermios termios;
168 unsigned long line_state; /* modem line settings */ 168 unsigned long line_state; /* modem line settings */
169 /* write pool */ 169 /* write pool */
170 struct urb * write_urb_pool[NUM_URBS]; 170 struct urb * write_urb_pool[NUM_URBS];
@@ -688,7 +688,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
688 688
689 689
690static void klsi_105_set_termios (struct usb_serial_port *port, 690static void klsi_105_set_termios (struct usb_serial_port *port,
691 struct termios *old_termios) 691 struct ktermios *old_termios)
692{ 692{
693 struct klsi_105_private *priv = usb_get_serial_port_data(port); 693 struct klsi_105_private *priv = usb_get_serial_port_data(port);
694 unsigned int iflag = port->tty->termios->c_iflag; 694 unsigned int iflag = port->tty->termios->c_iflag;
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 237289920f03..e284d6c0fd35 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -136,7 +136,7 @@ struct kobil_private {
136 int cur_pos; // index of the next char to send in buf 136 int cur_pos; // index of the next char to send in buf
137 __u16 device_type; 137 __u16 device_type;
138 int line_state; 138 int line_state;
139 struct termios internal_termios; 139 struct ktermios internal_termios;
140}; 140};
141 141
142 142
@@ -624,11 +624,11 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file *file,
624 624
625 switch (cmd) { 625 switch (cmd) {
626 case TCGETS: // 0x5401 626 case TCGETS: // 0x5401
627 if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct termios))) { 627 if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct ktermios))) {
628 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number); 628 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
629 return -EFAULT; 629 return -EFAULT;
630 } 630 }
631 if (kernel_termios_to_user_termios((struct termios __user *)arg, 631 if (kernel_termios_to_user_termios((struct ktermios __user *)arg,
632 &priv->internal_termios)) 632 &priv->internal_termios))
633 return -EFAULT; 633 return -EFAULT;
634 return 0; 634 return 0;
@@ -638,12 +638,12 @@ static int kobil_ioctl(struct usb_serial_port *port, struct file *file,
638 dbg("%s - port %d Error: port->tty->termios is NULL", __FUNCTION__, port->number); 638 dbg("%s - port %d Error: port->tty->termios is NULL", __FUNCTION__, port->number);
639 return -ENOTTY; 639 return -ENOTTY;
640 } 640 }
641 if (!access_ok(VERIFY_READ, user_arg, sizeof(struct termios))) { 641 if (!access_ok(VERIFY_READ, user_arg, sizeof(struct ktermios))) {
642 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number); 642 dbg("%s - port %d Error in access_ok", __FUNCTION__, port->number);
643 return -EFAULT; 643 return -EFAULT;
644 } 644 }
645 if (user_termios_to_kernel_termios(&priv->internal_termios, 645 if (user_termios_to_kernel_termios(&priv->internal_termios,
646 (struct termios __user *)arg)) 646 (struct ktermios __user *)arg))
647 return -EFAULT; 647 return -EFAULT;
648 648
649 settings = kzalloc(50, GFP_KERNEL); 649 settings = kzalloc(50, GFP_KERNEL);
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index a906e500a02b..38b1d17e06ef 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -98,7 +98,7 @@ static void mct_u232_close (struct usb_serial_port *port,
98 struct file *filp); 98 struct file *filp);
99static void mct_u232_read_int_callback (struct urb *urb); 99static void mct_u232_read_int_callback (struct urb *urb);
100static void mct_u232_set_termios (struct usb_serial_port *port, 100static void mct_u232_set_termios (struct usb_serial_port *port,
101 struct termios * old); 101 struct ktermios * old);
102static int mct_u232_ioctl (struct usb_serial_port *port, 102static int mct_u232_ioctl (struct usb_serial_port *port,
103 struct file * file, 103 struct file * file,
104 unsigned int cmd, 104 unsigned int cmd,
@@ -556,7 +556,7 @@ exit:
556} /* mct_u232_read_int_callback */ 556} /* mct_u232_read_int_callback */
557 557
558static void mct_u232_set_termios (struct usb_serial_port *port, 558static void mct_u232_set_termios (struct usb_serial_port *port,
559 struct termios *old_termios) 559 struct ktermios *old_termios)
560{ 560{
561 struct usb_serial *serial = port->serial; 561 struct usb_serial *serial = port->serial;
562 struct mct_u232_private *priv = usb_get_serial_port_data(port); 562 struct mct_u232_private *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 70f93b18292f..e55f4ed81d7b 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -1014,7 +1014,7 @@ static int send_cmd_write_baud_rate(struct moschip_port *mos7720_port,
1014 * the specified new settings. 1014 * the specified new settings.
1015 */ 1015 */
1016static void change_port_settings(struct moschip_port *mos7720_port, 1016static void change_port_settings(struct moschip_port *mos7720_port,
1017 struct termios *old_termios) 1017 struct ktermios *old_termios)
1018{ 1018{
1019 struct usb_serial_port *port; 1019 struct usb_serial_port *port;
1020 struct usb_serial *serial; 1020 struct usb_serial *serial;
@@ -1203,7 +1203,7 @@ static void change_port_settings(struct moschip_port *mos7720_port,
1203 * termios structure. 1203 * termios structure.
1204 */ 1204 */
1205static void mos7720_set_termios(struct usb_serial_port *port, 1205static void mos7720_set_termios(struct usb_serial_port *port,
1206 struct termios *old_termios) 1206 struct ktermios *old_termios)
1207{ 1207{
1208 int status; 1208 int status;
1209 unsigned int cflag; 1209 unsigned int cflag;
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 5432c6340086..8cc728a49e41 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1931,7 +1931,7 @@ static int mos7840_send_cmd_write_baud_rate(struct moschip_port *mos7840_port,
1931 *****************************************************************************/ 1931 *****************************************************************************/
1932 1932
1933static void mos7840_change_port_settings(struct moschip_port *mos7840_port, 1933static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
1934 struct termios *old_termios) 1934 struct ktermios *old_termios)
1935{ 1935{
1936 struct tty_struct *tty; 1936 struct tty_struct *tty;
1937 int baud; 1937 int baud;
@@ -2118,7 +2118,7 @@ static void mos7840_change_port_settings(struct moschip_port *mos7840_port,
2118 *****************************************************************************/ 2118 *****************************************************************************/
2119 2119
2120static void mos7840_set_termios(struct usb_serial_port *port, 2120static void mos7840_set_termios(struct usb_serial_port *port,
2121 struct termios *old_termios) 2121 struct ktermios *old_termios)
2122{ 2122{
2123 int status; 2123 int status;
2124 unsigned int cflag; 2124 unsigned int cflag;
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 130afbbd3fca..0ae4098718c3 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -59,7 +59,7 @@ static int option_chars_in_buffer(struct usb_serial_port *port);
59static int option_ioctl(struct usb_serial_port *port, struct file *file, 59static int option_ioctl(struct usb_serial_port *port, struct file *file,
60 unsigned int cmd, unsigned long arg); 60 unsigned int cmd, unsigned long arg);
61static void option_set_termios(struct usb_serial_port *port, 61static void option_set_termios(struct usb_serial_port *port,
62 struct termios *old); 62 struct ktermios *old);
63static void option_break_ctl(struct usb_serial_port *port, int break_state); 63static void option_break_ctl(struct usb_serial_port *port, int break_state);
64static int option_tiocmget(struct usb_serial_port *port, struct file *file); 64static int option_tiocmget(struct usb_serial_port *port, struct file *file);
65static int option_tiocmset(struct usb_serial_port *port, struct file *file, 65static int option_tiocmset(struct usb_serial_port *port, struct file *file,
@@ -230,7 +230,7 @@ static void option_break_ctl(struct usb_serial_port *port, int break_state)
230} 230}
231 231
232static void option_set_termios(struct usb_serial_port *port, 232static void option_set_termios(struct usb_serial_port *port,
233 struct termios *old_termios) 233 struct ktermios *old_termios)
234{ 234{
235 dbg("%s", __FUNCTION__); 235 dbg("%s", __FUNCTION__);
236 236
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index bc800c8787a8..d124d780e42e 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -455,7 +455,7 @@ static int pl2303_chars_in_buffer(struct usb_serial_port *port)
455} 455}
456 456
457static void pl2303_set_termios(struct usb_serial_port *port, 457static void pl2303_set_termios(struct usb_serial_port *port,
458 struct termios *old_termios) 458 struct ktermios *old_termios)
459{ 459{
460 struct usb_serial *serial = port->serial; 460 struct usb_serial *serial = port->serial;
461 struct pl2303_private *priv = usb_get_serial_port_data(port); 461 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -687,7 +687,7 @@ static void pl2303_close(struct usb_serial_port *port, struct file *filp)
687 687
688static int pl2303_open(struct usb_serial_port *port, struct file *filp) 688static int pl2303_open(struct usb_serial_port *port, struct file *filp)
689{ 689{
690 struct termios tmp_termios; 690 struct ktermios tmp_termios;
691 struct usb_serial *serial = port->serial; 691 struct usb_serial *serial = port->serial;
692 struct pl2303_private *priv = usb_get_serial_port_data(port); 692 struct pl2303_private *priv = usb_get_serial_port_data(port);
693 unsigned char *buf; 693 unsigned char *buf;
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 4b5097fa48d7..6d8e91e00ecf 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -145,7 +145,7 @@ static void sierra_break_ctl(struct usb_serial_port *port, int break_state)
145} 145}
146 146
147static void sierra_set_termios(struct usb_serial_port *port, 147static void sierra_set_termios(struct usb_serial_port *port,
148 struct termios *old_termios) 148 struct ktermios *old_termios)
149{ 149{
150 dbg("%s", __FUNCTION__); 150 dbg("%s", __FUNCTION__);
151 151
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index ae98d8cbdbb8..f42eb9ea6405 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -161,7 +161,7 @@ static void ti_throttle(struct usb_serial_port *port);
161static void ti_unthrottle(struct usb_serial_port *port); 161static void ti_unthrottle(struct usb_serial_port *port);
162static int ti_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg); 162static int ti_ioctl(struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg);
163static void ti_set_termios(struct usb_serial_port *port, 163static void ti_set_termios(struct usb_serial_port *port,
164 struct termios *old_termios); 164 struct ktermios *old_termios);
165static int ti_tiocmget(struct usb_serial_port *port, struct file *file); 165static int ti_tiocmget(struct usb_serial_port *port, struct file *file);
166static int ti_tiocmset(struct usb_serial_port *port, struct file *file, 166static int ti_tiocmset(struct usb_serial_port *port, struct file *file,
167 unsigned int set, unsigned int clear); 167 unsigned int set, unsigned int clear);
@@ -881,7 +881,7 @@ static int ti_ioctl(struct usb_serial_port *port, struct file *file,
881 881
882 882
883static void ti_set_termios(struct usb_serial_port *port, 883static void ti_set_termios(struct usb_serial_port *port,
884 struct termios *old_termios) 884 struct ktermios *old_termios)
885{ 885{
886 struct ti_port *tport = usb_get_serial_port_data(port); 886 struct ti_port *tport = usb_get_serial_port_data(port);
887 struct tty_struct *tty = port->tty; 887 struct tty_struct *tty = port->tty;
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 3d5072f14b8d..716f6806cc89 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -397,7 +397,7 @@ exit:
397 return retval; 397 return retval;
398} 398}
399 399
400static void serial_set_termios (struct tty_struct *tty, struct termios * old) 400static void serial_set_termios (struct tty_struct *tty, struct ktermios * old)
401{ 401{
402 struct usb_serial_port *port = tty->driver_data; 402 struct usb_serial_port *port = tty->driver_data;
403 403
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index eef5eaa5fa0b..b09f06096056 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -46,7 +46,7 @@ static int visor_probe (struct usb_serial *serial, const struct usb_device_id
46static int visor_calc_num_ports(struct usb_serial *serial); 46static int visor_calc_num_ports(struct usb_serial *serial);
47static void visor_shutdown (struct usb_serial *serial); 47static void visor_shutdown (struct usb_serial *serial);
48static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 48static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
49static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios); 49static void visor_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
50static void visor_write_bulk_callback (struct urb *urb); 50static void visor_write_bulk_callback (struct urb *urb);
51static void visor_read_bulk_callback (struct urb *urb); 51static void visor_read_bulk_callback (struct urb *urb);
52static void visor_read_int_callback (struct urb *urb); 52static void visor_read_int_callback (struct urb *urb);
@@ -916,7 +916,7 @@ static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsign
916 916
917 917
918/* This function is all nice and good, but we don't change anything based on it :) */ 918/* This function is all nice and good, but we don't change anything based on it :) */
919static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios) 919static void visor_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
920{ 920{
921 unsigned int cflag; 921 unsigned int cflag;
922 922
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 154c7d290597..dc45e58e2b8c 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -145,7 +145,7 @@ static void whiteheat_close (struct usb_serial_port *port, struct file *filp);
145static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count); 145static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count);
146static int whiteheat_write_room (struct usb_serial_port *port); 146static int whiteheat_write_room (struct usb_serial_port *port);
147static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 147static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
148static void whiteheat_set_termios (struct usb_serial_port *port, struct termios * old); 148static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios * old);
149static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file); 149static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file);
150static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear); 150static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
151static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state); 151static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state);
@@ -597,7 +597,7 @@ static void whiteheat_shutdown (struct usb_serial *serial)
597static int whiteheat_open (struct usb_serial_port *port, struct file *filp) 597static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
598{ 598{
599 int retval = 0; 599 int retval = 0;
600 struct termios old_term; 600 struct ktermios old_term;
601 601
602 dbg("%s - port %d", __FUNCTION__, port->number); 602 dbg("%s - port %d", __FUNCTION__, port->number);
603 603
@@ -870,7 +870,7 @@ static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, un
870} 870}
871 871
872 872
873static void whiteheat_set_termios (struct usb_serial_port *port, struct termios *old_termios) 873static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
874{ 874{
875 dbg("%s -port %d", __FUNCTION__, port->number); 875 dbg("%s -port %d", __FUNCTION__, port->number);
876 876
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 7a43020fa583..4e83f01e894e 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -541,6 +541,7 @@ config FB_TGA
541 select FB_CFB_FILLRECT 541 select FB_CFB_FILLRECT
542 select FB_CFB_COPYAREA 542 select FB_CFB_COPYAREA
543 select FB_CFB_IMAGEBLIT 543 select FB_CFB_IMAGEBLIT
544 select BITREVERSE
544 help 545 help
545 This is the frame buffer device driver for generic TGA graphic 546 This is the frame buffer device driver for generic TGA graphic
546 cards. Say Y if you have one of those. 547 cards. Say Y if you have one of those.
@@ -551,6 +552,7 @@ config FB_VESA
551 select FB_CFB_FILLRECT 552 select FB_CFB_FILLRECT
552 select FB_CFB_COPYAREA 553 select FB_CFB_COPYAREA
553 select FB_CFB_IMAGEBLIT 554 select FB_CFB_IMAGEBLIT
555 select VIDEO_SELECT
554 help 556 help
555 This is the frame buffer device driver for generic VESA 2.0 557 This is the frame buffer device driver for generic VESA 2.0
556 compliant graphic cards. The older VESA 1.2 cards are not supported. 558 compliant graphic cards. The older VESA 1.2 cards are not supported.
@@ -705,6 +707,7 @@ config FB_NVIDIA
705 select FB_CFB_FILLRECT 707 select FB_CFB_FILLRECT
706 select FB_CFB_COPYAREA 708 select FB_CFB_COPYAREA
707 select FB_CFB_IMAGEBLIT 709 select FB_CFB_IMAGEBLIT
710 select BITREVERSE
708 help 711 help
709 This driver supports graphics boards with the nVidia chips, TNT 712 This driver supports graphics boards with the nVidia chips, TNT
710 and newer. For very old chipsets, such as the RIVA128, then use 713 and newer. For very old chipsets, such as the RIVA128, then use
@@ -744,6 +747,7 @@ config FB_RIVA
744 select FB_CFB_FILLRECT 747 select FB_CFB_FILLRECT
745 select FB_CFB_COPYAREA 748 select FB_CFB_COPYAREA
746 select FB_CFB_IMAGEBLIT 749 select FB_CFB_IMAGEBLIT
750 select BITREVERSE
747 help 751 help
748 This driver supports graphics boards with the nVidia Riva/Geforce 752 This driver supports graphics boards with the nVidia Riva/Geforce
749 chips. 753 chips.
@@ -1611,6 +1615,16 @@ config FB_PNX4008_DUM_RGB
1611 ---help--- 1615 ---help---
1612 Say Y here to enable support for PNX4008 RGB Framebuffer 1616 Say Y here to enable support for PNX4008 RGB Framebuffer
1613 1617
1618config FB_IBM_GXT4500
1619 tristate "Framebuffer support for IBM GXT4500P adaptor"
1620 depends on PPC
1621 select FB_CFB_FILLRECT
1622 select FB_CFB_COPYAREA
1623 select FB_CFB_IMAGEBLIT
1624 ---help---
1625 Say Y here to enable support for the IBM GXT4500P display
1626 adaptor, found on some IBM System P (pSeries) machines.
1627
1614config FB_VIRTUAL 1628config FB_VIRTUAL
1615 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 1629 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1616 depends on FB 1630 depends on FB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index a6980e9a2481..309a26dd164a 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -99,6 +99,7 @@ obj-$(CONFIG_FB_IMX) += imxfb.o
99obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o 99obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
100obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/ 100obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/
101obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/ 101obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
102obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
102 103
103# Platform or fallback drivers go here 104# Platform or fallback drivers go here
104obj-$(CONFIG_FB_VESA) += vesafb.o 105obj-$(CONFIG_FB_VESA) += vesafb.o
diff --git a/drivers/video/S3triofb.c b/drivers/video/S3triofb.c
index 397005eb392d..b3717c8f1bc2 100644
--- a/drivers/video/S3triofb.c
+++ b/drivers/video/S3triofb.c
@@ -535,8 +535,11 @@ static void __init s3triofb_of_init(struct device_node *dp)
535#endif 535#endif
536 536
537 fb_info.flags = FBINFO_FLAG_DEFAULT; 537 fb_info.flags = FBINFO_FLAG_DEFAULT;
538 if (register_framebuffer(&fb_info) < 0) 538 if (register_framebuffer(&fb_info) < 0) {
539 return; 539 iounmap(fb_info.screen_base);
540 fb_info.screen_base = NULL;
541 return;
542 }
540 543
541 printk("fb%d: S3 Trio frame buffer device on %s\n", 544 printk("fb%d: S3 Trio frame buffer device on %s\n",
542 fb_info.node, dp->full_name); 545 fb_info.node, dp->full_name);
diff --git a/drivers/video/amifb.c b/drivers/video/amifb.c
index a4e3fca05891..88a47845c4f7 100644
--- a/drivers/video/amifb.c
+++ b/drivers/video/amifb.c
@@ -2407,10 +2407,10 @@ default_chipset:
2407 fb_info.fix.smem_len); 2407 fb_info.fix.smem_len);
2408 if (!videomemory) { 2408 if (!videomemory) {
2409 printk("amifb: WARNING! unable to map videomem cached writethrough\n"); 2409 printk("amifb: WARNING! unable to map videomem cached writethrough\n");
2410 videomemory = ZTWO_VADDR(fb_info.fix.smem_start); 2410 fb_info.screen_base = (char *)ZTWO_VADDR(fb_info.fix.smem_start);
2411 } 2411 } else
2412 fb_info.screen_base = (char *)videomemory;
2412 2413
2413 fb_info.screen_base = (char *)videomemory;
2414 memset(dummysprite, 0, DUMMYSPRITEMEMSIZE); 2414 memset(dummysprite, 0, DUMMYSPRITEMEMSIZE);
2415 2415
2416 /* 2416 /*
@@ -2453,6 +2453,8 @@ static void amifb_deinit(void)
2453{ 2453{
2454 fb_dealloc_cmap(&fb_info.cmap); 2454 fb_dealloc_cmap(&fb_info.cmap);
2455 chipfree(); 2455 chipfree();
2456 if (videomemory)
2457 iounmap((void*)videomemory);
2456 release_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120); 2458 release_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120);
2457 custom.dmacon = DMAF_ALL | DMAF_MASTER; 2459 custom.dmacon = DMAF_ALL | DMAF_MASTER;
2458} 2460}
diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
index ab34b96acc31..30a8369757e7 100644
--- a/drivers/video/arcfb.c
+++ b/drivers/video/arcfb.c
@@ -454,7 +454,7 @@ static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t cou
454 unsigned int xres; 454 unsigned int xres;
455 455
456 p = *ppos; 456 p = *ppos;
457 inode = file->f_dentry->d_inode; 457 inode = file->f_path.dentry->d_inode;
458 fbidx = iminor(inode); 458 fbidx = iminor(inode);
459 info = registered_fb[fbidx]; 459 info = registered_fb[fbidx];
460 460
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c
index 02c41a626fa2..602db660bc73 100644
--- a/drivers/video/atafb.c
+++ b/drivers/video/atafb.c
@@ -2804,8 +2804,19 @@ int __init atafb_init(void)
2804 atafb_set_disp(-1, &fb_info); 2804 atafb_set_disp(-1, &fb_info);
2805 do_install_cmap(0, &fb_info); 2805 do_install_cmap(0, &fb_info);
2806 2806
2807 if (register_framebuffer(&fb_info) < 0) 2807 if (register_framebuffer(&fb_info) < 0) {
2808#ifdef ATAFB_EXT
2809 if (external_addr) {
2810 iounmap(external_addr);
2811 external_addr = NULL;
2812 }
2813 if (external_vgaiobase) {
2814 iounmap((void*)external_vgaiobase);
2815 external_vgaiobase = 0;
2816 }
2817#endif
2808 return -EINVAL; 2818 return -EINVAL;
2819 }
2809 2820
2810 printk("Determined %dx%d, depth %d\n", 2821 printk("Determined %dx%d, depth %d\n",
2811 disp.var.xres, disp.var.yres, disp.var.bits_per_pixel); 2822 disp.var.xres, disp.var.yres, disp.var.bits_per_pixel);
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index 276a21530b95..3feddf89d100 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -1333,6 +1333,8 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
1333 if (vclk * 12 < c.ppll_min) 1333 if (vclk * 12 < c.ppll_min)
1334 vclk = c.ppll_min/12; 1334 vclk = c.ppll_min/12;
1335 1335
1336 pll->post_divider = -1;
1337
1336 /* now, find an acceptable divider */ 1338 /* now, find an acceptable divider */
1337 for (i = 0; i < sizeof(post_dividers); i++) { 1339 for (i = 0; i < sizeof(post_dividers); i++) {
1338 output_freq = post_dividers[i] * vclk; 1340 output_freq = post_dividers[i] * vclk;
@@ -1342,6 +1344,9 @@ static int aty128_var_to_pll(u32 period_in_ps, struct aty128_pll *pll,
1342 } 1344 }
1343 } 1345 }
1344 1346
1347 if (pll->post_divider < 0)
1348 return -EINVAL;
1349
1345 /* calculate feedback divider */ 1350 /* calculate feedback divider */
1346 n = c.ref_divider * output_freq; 1351 n = c.ref_divider * output_freq;
1347 d = c.ref_clk; 1352 d = c.ref_clk;
diff --git a/drivers/video/aty/atyfb.h b/drivers/video/aty/atyfb.h
index b04f49fb976a..f72faff33c0c 100644
--- a/drivers/video/aty/atyfb.h
+++ b/drivers/video/aty/atyfb.h
@@ -126,7 +126,6 @@ union aty_pll {
126 */ 126 */
127 127
128struct atyfb_par { 128struct atyfb_par {
129 struct aty_cmap_regs __iomem *aty_cmap_regs;
130 struct { u8 red, green, blue; } palette[256]; 129 struct { u8 red, green, blue; } palette[256];
131 const struct aty_dac_ops *dac_ops; 130 const struct aty_dac_ops *dac_ops;
132 const struct aty_pll_ops *pll_ops; 131 const struct aty_pll_ops *pll_ops;
@@ -186,6 +185,7 @@ struct atyfb_par {
186 int mtrr_aper; 185 int mtrr_aper;
187 int mtrr_reg; 186 int mtrr_reg;
188#endif 187#endif
188 u32 mem_cntl;
189}; 189};
190 190
191 /* 191 /*
@@ -227,7 +227,7 @@ static inline u32 aty_ld_le32(int regindex, const struct atyfb_par *par)
227 regindex -= 0x800; 227 regindex -= 0x800;
228 228
229#ifdef CONFIG_ATARI 229#ifdef CONFIG_ATARI
230 return in_le32((volatile u32 *)(par->ati_regbase + regindex)); 230 return in_le32(par->ati_regbase + regindex);
231#else 231#else
232 return readl(par->ati_regbase + regindex); 232 return readl(par->ati_regbase + regindex);
233#endif 233#endif
@@ -240,7 +240,7 @@ static inline void aty_st_le32(int regindex, u32 val, const struct atyfb_par *pa
240 regindex -= 0x800; 240 regindex -= 0x800;
241 241
242#ifdef CONFIG_ATARI 242#ifdef CONFIG_ATARI
243 out_le32((volatile u32 *)(par->ati_regbase + regindex), val); 243 out_le32(par->ati_regbase + regindex, val);
244#else 244#else
245 writel(val, par->ati_regbase + regindex); 245 writel(val, par->ati_regbase + regindex);
246#endif 246#endif
@@ -253,7 +253,7 @@ static inline void aty_st_le16(int regindex, u16 val,
253 if (regindex >= 0x400) 253 if (regindex >= 0x400)
254 regindex -= 0x800; 254 regindex -= 0x800;
255#ifdef CONFIG_ATARI 255#ifdef CONFIG_ATARI
256 out_le16((volatile u16 *)(par->ati_regbase + regindex), val); 256 out_le16(par->ati_regbase + regindex, val);
257#else 257#else
258 writel(val, par->ati_regbase + regindex); 258 writel(val, par->ati_regbase + regindex);
259#endif 259#endif
@@ -315,6 +315,7 @@ struct aty_pll_ops {
315 void (*set_pll) (const struct fb_info * info, const union aty_pll * pll); 315 void (*set_pll) (const struct fb_info * info, const union aty_pll * pll);
316 void (*get_pll) (const struct fb_info *info, union aty_pll * pll); 316 void (*get_pll) (const struct fb_info *info, union aty_pll * pll);
317 int (*init_pll) (const struct fb_info * info, union aty_pll * pll); 317 int (*init_pll) (const struct fb_info * info, union aty_pll * pll);
318 void (*resume_pll)(const struct fb_info *info, union aty_pll *pll);
318}; 319};
319 320
320extern const struct aty_pll_ops aty_pll_ati18818_1; /* ATI 18818 */ 321extern const struct aty_pll_ops aty_pll_ati18818_1; /* ATI 18818 */
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index e815b354c09d..176f9b85cdbe 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -203,14 +203,6 @@ static void ATIReduceRatio(int *Numerator, int *Denominator)
203 * The Hardware parameters for each card 203 * The Hardware parameters for each card
204 */ 204 */
205 205
206struct aty_cmap_regs {
207 u8 windex;
208 u8 lut;
209 u8 mask;
210 u8 rindex;
211 u8 cntl;
212};
213
214struct pci_mmap_map { 206struct pci_mmap_map {
215 unsigned long voff; 207 unsigned long voff;
216 unsigned long poff; 208 unsigned long poff;
@@ -249,7 +241,8 @@ static int atyfb_sync(struct fb_info *info);
249 * Internal routines 241 * Internal routines
250 */ 242 */
251 243
252static int aty_init(struct fb_info *info, const char *name); 244static int aty_init(struct fb_info *info);
245static void aty_resume_chip(struct fb_info *info);
253#ifdef CONFIG_ATARI 246#ifdef CONFIG_ATARI
254static int store_video_par(char *videopar, unsigned char m64_num); 247static int store_video_par(char *videopar, unsigned char m64_num);
255#endif 248#endif
@@ -1937,17 +1930,14 @@ static void atyfb_save_palette(struct atyfb_par *par, int enter)
1937 aty_st_8(DAC_CNTL, tmp, par); 1930 aty_st_8(DAC_CNTL, tmp, par);
1938 aty_st_8(DAC_MASK, 0xff, par); 1931 aty_st_8(DAC_MASK, 0xff, par);
1939 1932
1940 writeb(i, &par->aty_cmap_regs->rindex); 1933 aty_st_8(DAC_R_INDEX, i, par);
1941 atyfb_save.r[enter][i] = readb(&par->aty_cmap_regs->lut); 1934 atyfb_save.r[enter][i] = aty_ld_8(DAC_DATA, par);
1942 atyfb_save.g[enter][i] = readb(&par->aty_cmap_regs->lut); 1935 atyfb_save.g[enter][i] = aty_ld_8(DAC_DATA, par);
1943 atyfb_save.b[enter][i] = readb(&par->aty_cmap_regs->lut); 1936 atyfb_save.b[enter][i] = aty_ld_8(DAC_DATA, par);
1944 writeb(i, &par->aty_cmap_regs->windex); 1937 aty_st_8(DAC_W_INDEX, i, par);
1945 writeb(atyfb_save.r[1 - enter][i], 1938 aty_st_8(DAC_DATA, atyfb_save.r[1 - enter][i], par);
1946 &par->aty_cmap_regs->lut); 1939 aty_st_8(DAC_DATA, atyfb_save.g[1 - enter][i], par);
1947 writeb(atyfb_save.g[1 - enter][i], 1940 aty_st_8(DAC_DATA, atyfb_save.b[1 - enter][i], par);
1948 &par->aty_cmap_regs->lut);
1949 writeb(atyfb_save.b[1 - enter][i],
1950 &par->aty_cmap_regs->lut);
1951 } 1941 }
1952} 1942}
1953 1943
@@ -1982,6 +1972,7 @@ static void atyfb_palette(int enter)
1982 1972
1983#if defined(CONFIG_PM) && defined(CONFIG_PCI) 1973#if defined(CONFIG_PM) && defined(CONFIG_PCI)
1984 1974
1975#ifdef CONFIG_PPC_PMAC
1985/* Power management routines. Those are used for PowerBook sleep. 1976/* Power management routines. Those are used for PowerBook sleep.
1986 */ 1977 */
1987static int aty_power_mgmt(int sleep, struct atyfb_par *par) 1978static int aty_power_mgmt(int sleep, struct atyfb_par *par)
@@ -2038,21 +2029,13 @@ static int aty_power_mgmt(int sleep, struct atyfb_par *par)
2038 2029
2039 return timeout ? 0 : -EIO; 2030 return timeout ? 0 : -EIO;
2040} 2031}
2032#endif
2041 2033
2042static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) 2034static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2043{ 2035{
2044 struct fb_info *info = pci_get_drvdata(pdev); 2036 struct fb_info *info = pci_get_drvdata(pdev);
2045 struct atyfb_par *par = (struct atyfb_par *) info->par; 2037 struct atyfb_par *par = (struct atyfb_par *) info->par;
2046 2038
2047#ifndef CONFIG_PPC_PMAC
2048 /* HACK ALERT ! Once I find a proper way to say to each driver
2049 * individually what will happen with it's PCI slot, I'll change
2050 * that. On laptops, the AGP slot is just unclocked, so D2 is
2051 * expected, while on desktops, the card is powered off
2052 */
2053 return 0;
2054#endif /* CONFIG_PPC_PMAC */
2055
2056 if (state.event == pdev->dev.power.power_state.event) 2039 if (state.event == pdev->dev.power.power_state.event)
2057 return 0; 2040 return 0;
2058 2041
@@ -2070,6 +2053,7 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2070 par->asleep = 1; 2053 par->asleep = 1;
2071 par->lock_blank = 1; 2054 par->lock_blank = 1;
2072 2055
2056#ifdef CONFIG_PPC_PMAC
2073 /* Set chip to "suspend" mode */ 2057 /* Set chip to "suspend" mode */
2074 if (aty_power_mgmt(1, par)) { 2058 if (aty_power_mgmt(1, par)) {
2075 par->asleep = 0; 2059 par->asleep = 0;
@@ -2079,6 +2063,9 @@ static int atyfb_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2079 release_console_sem(); 2063 release_console_sem();
2080 return -EIO; 2064 return -EIO;
2081 } 2065 }
2066#else
2067 pci_set_power_state(pdev, pci_choose_state(pdev, state));
2068#endif
2082 2069
2083 release_console_sem(); 2070 release_console_sem();
2084 2071
@@ -2097,8 +2084,15 @@ static int atyfb_pci_resume(struct pci_dev *pdev)
2097 2084
2098 acquire_console_sem(); 2085 acquire_console_sem();
2099 2086
2087#ifdef CONFIG_PPC_PMAC
2100 if (pdev->dev.power.power_state.event == 2) 2088 if (pdev->dev.power.power_state.event == 2)
2101 aty_power_mgmt(0, par); 2089 aty_power_mgmt(0, par);
2090#else
2091 pci_set_power_state(pdev, PCI_D0);
2092#endif
2093
2094 aty_resume_chip(info);
2095
2102 par->asleep = 0; 2096 par->asleep = 0;
2103 2097
2104 /* Restore display */ 2098 /* Restore display */
@@ -2344,24 +2338,16 @@ static int __devinit atyfb_get_timings_from_lcd(struct atyfb_par *par,
2344} 2338}
2345#endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */ 2339#endif /* defined(__i386__) && defined(CONFIG_FB_ATY_GENERIC_LCD) */
2346 2340
2347static int __devinit aty_init(struct fb_info *info, const char *name) 2341static int __devinit aty_init(struct fb_info *info)
2348{ 2342{
2349 struct atyfb_par *par = (struct atyfb_par *) info->par; 2343 struct atyfb_par *par = (struct atyfb_par *) info->par;
2350 const char *ramname = NULL, *xtal; 2344 const char *ramname = NULL, *xtal;
2351 int gtb_memsize, has_var = 0; 2345 int gtb_memsize, has_var = 0;
2352 struct fb_var_screeninfo var; 2346 struct fb_var_screeninfo var;
2353 u8 pll_ref_div;
2354 u32 i;
2355#if defined(CONFIG_PPC)
2356 int sense;
2357#endif
2358 2347
2359 init_waitqueue_head(&par->vblank.wait); 2348 init_waitqueue_head(&par->vblank.wait);
2360 spin_lock_init(&par->int_lock); 2349 spin_lock_init(&par->int_lock);
2361 2350
2362 par->aty_cmap_regs =
2363 (struct aty_cmap_regs __iomem *) (par->ati_regbase + 0xc0);
2364
2365#ifdef CONFIG_PPC_PMAC 2351#ifdef CONFIG_PPC_PMAC
2366 /* The Apple iBook1 uses non-standard memory frequencies. We detect it 2352 /* The Apple iBook1 uses non-standard memory frequencies. We detect it
2367 * and set the frequency manually. */ 2353 * and set the frequency manually. */
@@ -2464,18 +2450,21 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2464 par->pll_limits.mclk = 63; 2450 par->pll_limits.mclk = 63;
2465 } 2451 }
2466 2452
2467 if (M64_HAS(GTB_DSP) 2453 if (M64_HAS(GTB_DSP)) {
2468 && (pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par))) { 2454 u8 pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
2469 int diff1, diff2; 2455
2470 diff1 = 510 * 14 / pll_ref_div - par->pll_limits.pll_max; 2456 if (pll_ref_div) {
2471 diff2 = 510 * 29 / pll_ref_div - par->pll_limits.pll_max; 2457 int diff1, diff2;
2472 if (diff1 < 0) 2458 diff1 = 510 * 14 / pll_ref_div - par->pll_limits.pll_max;
2473 diff1 = -diff1; 2459 diff2 = 510 * 29 / pll_ref_div - par->pll_limits.pll_max;
2474 if (diff2 < 0) 2460 if (diff1 < 0)
2475 diff2 = -diff2; 2461 diff1 = -diff1;
2476 if (diff2 < diff1) { 2462 if (diff2 < 0)
2477 par->ref_clk_per = 1000000000000ULL / 29498928; 2463 diff2 = -diff2;
2478 xtal = "29.498928"; 2464 if (diff2 < diff1) {
2465 par->ref_clk_per = 1000000000000ULL / 29498928;
2466 xtal = "29.498928";
2467 }
2479 } 2468 }
2480 } 2469 }
2481#endif /* CONFIG_FB_ATY_CT */ 2470#endif /* CONFIG_FB_ATY_CT */
@@ -2485,10 +2474,10 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2485 if(par->pll_ops->get_pll) 2474 if(par->pll_ops->get_pll)
2486 par->pll_ops->get_pll(info, &saved_pll); 2475 par->pll_ops->get_pll(info, &saved_pll);
2487 2476
2488 i = aty_ld_le32(MEM_CNTL, par); 2477 par->mem_cntl = aty_ld_le32(MEM_CNTL, par);
2489 gtb_memsize = M64_HAS(GTB_DSP); 2478 gtb_memsize = M64_HAS(GTB_DSP);
2490 if (gtb_memsize) 2479 if (gtb_memsize)
2491 switch (i & 0xF) { /* 0xF used instead of MEM_SIZE_ALIAS */ 2480 switch (par->mem_cntl & 0xF) { /* 0xF used instead of MEM_SIZE_ALIAS */
2492 case MEM_SIZE_512K: 2481 case MEM_SIZE_512K:
2493 info->fix.smem_len = 0x80000; 2482 info->fix.smem_len = 0x80000;
2494 break; 2483 break;
@@ -2510,7 +2499,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2510 default: 2499 default:
2511 info->fix.smem_len = 0x80000; 2500 info->fix.smem_len = 0x80000;
2512 } else 2501 } else
2513 switch (i & MEM_SIZE_ALIAS) { 2502 switch (par->mem_cntl & MEM_SIZE_ALIAS) {
2514 case MEM_SIZE_512K: 2503 case MEM_SIZE_512K:
2515 info->fix.smem_len = 0x80000; 2504 info->fix.smem_len = 0x80000;
2516 break; 2505 break;
@@ -2540,20 +2529,20 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2540 2529
2541 if (vram) { 2530 if (vram) {
2542 info->fix.smem_len = vram * 1024; 2531 info->fix.smem_len = vram * 1024;
2543 i = i & ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS); 2532 par->mem_cntl &= ~(gtb_memsize ? 0xF : MEM_SIZE_ALIAS);
2544 if (info->fix.smem_len <= 0x80000) 2533 if (info->fix.smem_len <= 0x80000)
2545 i |= MEM_SIZE_512K; 2534 par->mem_cntl |= MEM_SIZE_512K;
2546 else if (info->fix.smem_len <= 0x100000) 2535 else if (info->fix.smem_len <= 0x100000)
2547 i |= MEM_SIZE_1M; 2536 par->mem_cntl |= MEM_SIZE_1M;
2548 else if (info->fix.smem_len <= 0x200000) 2537 else if (info->fix.smem_len <= 0x200000)
2549 i |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M; 2538 par->mem_cntl |= gtb_memsize ? MEM_SIZE_2M_GTB : MEM_SIZE_2M;
2550 else if (info->fix.smem_len <= 0x400000) 2539 else if (info->fix.smem_len <= 0x400000)
2551 i |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M; 2540 par->mem_cntl |= gtb_memsize ? MEM_SIZE_4M_GTB : MEM_SIZE_4M;
2552 else if (info->fix.smem_len <= 0x600000) 2541 else if (info->fix.smem_len <= 0x600000)
2553 i |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M; 2542 par->mem_cntl |= gtb_memsize ? MEM_SIZE_6M_GTB : MEM_SIZE_6M;
2554 else 2543 else
2555 i |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M; 2544 par->mem_cntl |= gtb_memsize ? MEM_SIZE_8M_GTB : MEM_SIZE_8M;
2556 aty_st_le32(MEM_CNTL, i, par); 2545 aty_st_le32(MEM_CNTL, par->mem_cntl, par);
2557 } 2546 }
2558 2547
2559 /* 2548 /*
@@ -2599,11 +2588,12 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2599#endif 2588#endif
2600 if(par->pll_ops->init_pll) 2589 if(par->pll_ops->init_pll)
2601 par->pll_ops->init_pll(info, &par->pll); 2590 par->pll_ops->init_pll(info, &par->pll);
2591 if (par->pll_ops->resume_pll)
2592 par->pll_ops->resume_pll(info, &par->pll);
2602 2593
2603 /* 2594 /*
2604 * Last page of 8 MB (4 MB on ISA) aperture is MMIO 2595 * Last page of 8 MB (4 MB on ISA) aperture is MMIO,
2605 * FIXME: we should use the auxiliary aperture instead so we can access 2596 * unless the auxiliary register aperture is used.
2606 * the full 8 MB of video RAM on 8 MB boards
2607 */ 2597 */
2608 2598
2609 if (!par->aux_start && 2599 if (!par->aux_start &&
@@ -2669,6 +2659,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2669 has_var = 1; 2659 has_var = 1;
2670 } else { 2660 } else {
2671 if (default_vmode == VMODE_CHOOSE) { 2661 if (default_vmode == VMODE_CHOOSE) {
2662 int sense;
2672 if (M64_HAS(G3_PB_1024x768)) 2663 if (M64_HAS(G3_PB_1024x768))
2673 /* G3 PowerBook with 1024x768 LCD */ 2664 /* G3 PowerBook with 1024x768 LCD */
2674 default_vmode = VMODE_1024_768_60; 2665 default_vmode = VMODE_1024_768_60;
@@ -2749,7 +2740,7 @@ static int __devinit aty_init(struct fb_info *info, const char *name)
2749 fb_list = info; 2740 fb_list = info;
2750 2741
2751 PRINTKI("fb%d: %s frame buffer device on %s\n", 2742 PRINTKI("fb%d: %s frame buffer device on %s\n",
2752 info->node, info->fix.id, name); 2743 info->node, info->fix.id, par->bus_type == ISA ? "ISA" : "PCI");
2753 return 0; 2744 return 0;
2754 2745
2755aty_init_exit: 2746aty_init_exit:
@@ -2770,6 +2761,19 @@ aty_init_exit:
2770 return -1; 2761 return -1;
2771} 2762}
2772 2763
2764static void aty_resume_chip(struct fb_info *info)
2765{
2766 struct atyfb_par *par = info->par;
2767
2768 aty_st_le32(MEM_CNTL, par->mem_cntl, par);
2769
2770 if (par->pll_ops->resume_pll)
2771 par->pll_ops->resume_pll(info, &par->pll);
2772
2773 if (par->aux_start)
2774 aty_st_le32(BUS_CNTL, aty_ld_le32(BUS_CNTL, par) | BUS_APER_REG_DIS, par);
2775}
2776
2773#ifdef CONFIG_ATARI 2777#ifdef CONFIG_ATARI
2774static int __devinit store_video_par(char *video_str, unsigned char m64_num) 2778static int __devinit store_video_par(char *video_str, unsigned char m64_num)
2775{ 2779{
@@ -2826,9 +2830,9 @@ static int atyfb_blank(int blank, struct fb_info *info)
2826#endif 2830#endif
2827 2831
2828 gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par); 2832 gen_cntl = aty_ld_le32(CRTC_GEN_CNTL, par);
2833 gen_cntl &= ~0x400004c;
2829 switch (blank) { 2834 switch (blank) {
2830 case FB_BLANK_UNBLANK: 2835 case FB_BLANK_UNBLANK:
2831 gen_cntl &= ~0x400004c;
2832 break; 2836 break;
2833 case FB_BLANK_NORMAL: 2837 case FB_BLANK_NORMAL:
2834 gen_cntl |= 0x4000040; 2838 gen_cntl |= 0x4000040;
@@ -2863,17 +2867,10 @@ static int atyfb_blank(int blank, struct fb_info *info)
2863static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue, 2867static void aty_st_pal(u_int regno, u_int red, u_int green, u_int blue,
2864 const struct atyfb_par *par) 2868 const struct atyfb_par *par)
2865{ 2869{
2866#ifdef CONFIG_ATARI 2870 aty_st_8(DAC_W_INDEX, regno, par);
2867 out_8(&par->aty_cmap_regs->windex, regno); 2871 aty_st_8(DAC_DATA, red, par);
2868 out_8(&par->aty_cmap_regs->lut, red); 2872 aty_st_8(DAC_DATA, green, par);
2869 out_8(&par->aty_cmap_regs->lut, green); 2873 aty_st_8(DAC_DATA, blue, par);
2870 out_8(&par->aty_cmap_regs->lut, blue);
2871#else
2872 writeb(regno, &par->aty_cmap_regs->windex);
2873 writeb(red, &par->aty_cmap_regs->lut);
2874 writeb(green, &par->aty_cmap_regs->lut);
2875 writeb(blue, &par->aty_cmap_regs->lut);
2876#endif
2877} 2874}
2878 2875
2879 /* 2876 /*
@@ -3182,7 +3179,7 @@ static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
3182 3179
3183#ifdef __i386__ 3180#ifdef __i386__
3184#ifdef CONFIG_FB_ATY_GENERIC_LCD 3181#ifdef CONFIG_FB_ATY_GENERIC_LCD
3185static void aty_init_lcd(struct atyfb_par *par, u32 bios_base) 3182static void __devinit aty_init_lcd(struct atyfb_par *par, u32 bios_base)
3186{ 3183{
3187 u32 driv_inf_tab, sig; 3184 u32 driv_inf_tab, sig;
3188 u16 lcd_ofs; 3185 u16 lcd_ofs;
@@ -3527,6 +3524,10 @@ static int __devinit atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *i
3527atyfb_setup_generic_fail: 3524atyfb_setup_generic_fail:
3528 iounmap(par->ati_regbase); 3525 iounmap(par->ati_regbase);
3529 par->ati_regbase = NULL; 3526 par->ati_regbase = NULL;
3527 if (info->screen_base) {
3528 iounmap(info->screen_base);
3529 info->screen_base = NULL;
3530 }
3530 return ret; 3531 return ret;
3531} 3532}
3532 3533
@@ -3594,7 +3595,7 @@ static int __devinit atyfb_pci_probe(struct pci_dev *pdev, const struct pci_devi
3594 pci_set_drvdata(pdev, info); 3595 pci_set_drvdata(pdev, info);
3595 3596
3596 /* Init chip & register framebuffer */ 3597 /* Init chip & register framebuffer */
3597 if (aty_init(info, "PCI")) 3598 if (aty_init(info))
3598 goto err_release_io; 3599 goto err_release_io;
3599 3600
3600#ifdef __sparc__ 3601#ifdef __sparc__
@@ -3641,12 +3642,13 @@ err_release_mem:
3641 3642
3642#ifdef CONFIG_ATARI 3643#ifdef CONFIG_ATARI
3643 3644
3644static int __devinit atyfb_atari_probe(void) 3645static int __init atyfb_atari_probe(void)
3645{ 3646{
3646 struct atyfb_par *par; 3647 struct atyfb_par *par;
3647 struct fb_info *info; 3648 struct fb_info *info;
3648 int m64_num; 3649 int m64_num;
3649 u32 clock_r; 3650 u32 clock_r;
3651 int num_found = 0;
3650 3652
3651 for (m64_num = 0; m64_num < mach64_count; m64_num++) { 3653 for (m64_num = 0; m64_num < mach64_count; m64_num++) {
3652 if (!phys_vmembase[m64_num] || !phys_size[m64_num] || 3654 if (!phys_vmembase[m64_num] || !phys_size[m64_num] ||
@@ -3694,16 +3696,34 @@ static int __devinit atyfb_atari_probe(void)
3694 break; 3696 break;
3695 } 3697 }
3696 3698
3697 if (aty_init(info, "ISA bus")) { 3699 /* Fake pci_id for correct_chipset() */
3700 switch (aty_ld_le32(CONFIG_CHIP_ID, par) & CFG_CHIP_TYPE) {
3701 case 0x00d7:
3702 par->pci_id = PCI_CHIP_MACH64GX;
3703 break;
3704 case 0x0057:
3705 par->pci_id = PCI_CHIP_MACH64CX;
3706 break;
3707 default:
3708 break;
3709 }
3710
3711 if (correct_chipset(par) || aty_init(info)) {
3712 iounmap(info->screen_base);
3713 iounmap(par->ati_regbase);
3698 framebuffer_release(info); 3714 framebuffer_release(info);
3699 /* This is insufficient! kernel_map has added two large chunks!! */ 3715 } else {
3700 return -ENXIO; 3716 num_found++;
3701 } 3717 }
3702 } 3718 }
3719
3720 return num_found ? 0 : -ENXIO;
3703} 3721}
3704 3722
3705#endif /* CONFIG_ATARI */ 3723#endif /* CONFIG_ATARI */
3706 3724
3725#ifdef CONFIG_PCI
3726
3707static void __devexit atyfb_remove(struct fb_info *info) 3727static void __devexit atyfb_remove(struct fb_info *info)
3708{ 3728{
3709 struct atyfb_par *par = (struct atyfb_par *) info->par; 3729 struct atyfb_par *par = (struct atyfb_par *) info->par;
@@ -3751,7 +3771,6 @@ static void __devexit atyfb_remove(struct fb_info *info)
3751 framebuffer_release(info); 3771 framebuffer_release(info);
3752} 3772}
3753 3773
3754#ifdef CONFIG_PCI
3755 3774
3756static void __devexit atyfb_pci_remove(struct pci_dev *pdev) 3775static void __devexit atyfb_pci_remove(struct pci_dev *pdev)
3757{ 3776{
@@ -3786,7 +3805,7 @@ static struct pci_driver atyfb_driver = {
3786#endif /* CONFIG_PCI */ 3805#endif /* CONFIG_PCI */
3787 3806
3788#ifndef MODULE 3807#ifndef MODULE
3789static int __devinit atyfb_setup(char *options) 3808static int __init atyfb_setup(char *options)
3790{ 3809{
3791 char *this_opt; 3810 char *this_opt;
3792 3811
@@ -3858,7 +3877,7 @@ static int __devinit atyfb_setup(char *options)
3858} 3877}
3859#endif /* MODULE */ 3878#endif /* MODULE */
3860 3879
3861static int __devinit atyfb_init(void) 3880static int __init atyfb_init(void)
3862{ 3881{
3863 int err1 = 1, err2 = 1; 3882 int err1 = 1, err2 = 1;
3864#ifndef MODULE 3883#ifndef MODULE
diff --git a/drivers/video/aty/mach64_ct.c b/drivers/video/aty/mach64_ct.c
index 5080816be653..f3b487b8710b 100644
--- a/drivers/video/aty/mach64_ct.c
+++ b/drivers/video/aty/mach64_ct.c
@@ -370,8 +370,8 @@ void aty_set_pll_ct(const struct fb_info *info, const union aty_pll *pll)
370#endif 370#endif
371} 371}
372 372
373static void __init aty_get_pll_ct(const struct fb_info *info, 373static void __devinit aty_get_pll_ct(const struct fb_info *info,
374 union aty_pll *pll) 374 union aty_pll *pll)
375{ 375{
376 struct atyfb_par *par = (struct atyfb_par *) info->par; 376 struct atyfb_par *par = (struct atyfb_par *) info->par;
377 u8 tmp, clock; 377 u8 tmp, clock;
@@ -394,12 +394,12 @@ static void __init aty_get_pll_ct(const struct fb_info *info,
394 } 394 }
395} 395}
396 396
397static int __init aty_init_pll_ct(const struct fb_info *info, 397static int __devinit aty_init_pll_ct(const struct fb_info *info,
398 union aty_pll *pll) 398 union aty_pll *pll)
399{ 399{
400 struct atyfb_par *par = (struct atyfb_par *) info->par; 400 struct atyfb_par *par = (struct atyfb_par *) info->par;
401 u8 mpost_div, xpost_div, sclk_post_div_real, sclk_fb_div, spll_cntl2; 401 u8 mpost_div, xpost_div, sclk_post_div_real;
402 u32 q, i, memcntl, trp; 402 u32 q, memcntl, trp;
403 u32 dsp_config, dsp_on_off, vga_dsp_config, vga_dsp_on_off; 403 u32 dsp_config, dsp_on_off, vga_dsp_config, vga_dsp_on_off;
404#ifdef DEBUG 404#ifdef DEBUG
405 int pllmclk, pllsclk; 405 int pllmclk, pllsclk;
@@ -575,14 +575,30 @@ static int __init aty_init_pll_ct(const struct fb_info *info,
575 mpost_div += (q < 32*8); 575 mpost_div += (q < 32*8);
576 } 576 }
577 sclk_post_div_real = postdividers[mpost_div]; 577 sclk_post_div_real = postdividers[mpost_div];
578 sclk_fb_div = q * sclk_post_div_real / 8; 578 pll->ct.sclk_fb_div = q * sclk_post_div_real / 8;
579 spll_cntl2 = mpost_div << 4; 579 pll->ct.spll_cntl2 = mpost_div << 4;
580#ifdef DEBUG 580#ifdef DEBUG
581 pllsclk = (1000000 * 2 * sclk_fb_div) / 581 pllsclk = (1000000 * 2 * pll->ct.sclk_fb_div) /
582 (par->ref_clk_per * pll->ct.pll_ref_div); 582 (par->ref_clk_per * pll->ct.pll_ref_div);
583 printk("atyfb(%s): use sclk, pllsclk=%d MHz, sclk=mclk=%d MHz\n", 583 printk("atyfb(%s): use sclk, pllsclk=%d MHz, sclk=mclk=%d MHz\n",
584 __FUNCTION__, pllsclk, pllsclk / sclk_post_div_real); 584 __FUNCTION__, pllsclk, pllsclk / sclk_post_div_real);
585#endif 585#endif
586 }
587
588 /* Disable the extra precision pixel clock controls since we do not use them. */
589 pll->ct.ext_vpll_cntl = aty_ld_pll_ct(EXT_VPLL_CNTL, par);
590 pll->ct.ext_vpll_cntl &= ~(EXT_VPLL_EN | EXT_VPLL_VGA_EN | EXT_VPLL_INSYNC);
591
592 return 0;
593}
594
595static void aty_resume_pll_ct(const struct fb_info *info,
596 union aty_pll *pll)
597{
598 struct atyfb_par *par = info->par;
599
600 if (par->mclk_per != par->xclk_per) {
601 int i;
586 /* 602 /*
587 * This disables the sclk, crashes the computer as reported: 603 * This disables the sclk, crashes the computer as reported:
588 * aty_st_pll_ct(SPLL_CNTL2, 3, info); 604 * aty_st_pll_ct(SPLL_CNTL2, 3, info);
@@ -590,8 +606,8 @@ static int __init aty_init_pll_ct(const struct fb_info *info,
590 * So it seems the sclk must be enabled before it is used; 606 * So it seems the sclk must be enabled before it is used;
591 * so PLL_GEN_CNTL must be programmed *after* the sclk. 607 * so PLL_GEN_CNTL must be programmed *after* the sclk.
592 */ 608 */
593 aty_st_pll_ct(SCLK_FB_DIV, sclk_fb_div, par); 609 aty_st_pll_ct(SCLK_FB_DIV, pll->ct.sclk_fb_div, par);
594 aty_st_pll_ct(SPLL_CNTL2, spll_cntl2, par); 610 aty_st_pll_ct(SPLL_CNTL2, pll->ct.spll_cntl2, par);
595 /* 611 /*
596 * The sclk has been started. However, I believe the first clock 612 * The sclk has been started. However, I believe the first clock
597 * ticks it generates are not very stable. Hope this primitive loop 613 * ticks it generates are not very stable. Hope this primitive loop
@@ -605,11 +621,7 @@ static int __init aty_init_pll_ct(const struct fb_info *info,
605 aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par); 621 aty_st_pll_ct(PLL_GEN_CNTL, pll->ct.pll_gen_cntl, par);
606 aty_st_pll_ct(MCLK_FB_DIV, pll->ct.mclk_fb_div, par); 622 aty_st_pll_ct(MCLK_FB_DIV, pll->ct.mclk_fb_div, par);
607 aty_st_pll_ct(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, par); 623 aty_st_pll_ct(PLL_EXT_CNTL, pll->ct.pll_ext_cntl, par);
608 /* Disable the extra precision pixel clock controls since we do not use them. */ 624 aty_st_pll_ct(EXT_VPLL_CNTL, pll->ct.ext_vpll_cntl, par);
609 aty_st_pll_ct(EXT_VPLL_CNTL, aty_ld_pll_ct(EXT_VPLL_CNTL, par) &
610 ~(EXT_VPLL_EN | EXT_VPLL_VGA_EN | EXT_VPLL_INSYNC), par);
611
612 return 0;
613} 625}
614 626
615static int dummy(void) 627static int dummy(void)
@@ -626,5 +638,6 @@ const struct aty_pll_ops aty_pll_ct = {
626 .pll_to_var = aty_pll_to_var_ct, 638 .pll_to_var = aty_pll_to_var_ct,
627 .set_pll = aty_set_pll_ct, 639 .set_pll = aty_set_pll_ct,
628 .get_pll = aty_get_pll_ct, 640 .get_pll = aty_get_pll_ct,
629 .init_pll = aty_init_pll_ct 641 .init_pll = aty_init_pll_ct,
642 .resume_pll = aty_resume_pll_ct,
630}; 643};
diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c
index 869725a13c21..e7c5b219ad1b 100644
--- a/drivers/video/aty/radeon_i2c.c
+++ b/drivers/video/aty/radeon_i2c.c
@@ -120,19 +120,19 @@ void radeon_create_i2c_busses(struct radeonfb_info *rinfo)
120void radeon_delete_i2c_busses(struct radeonfb_info *rinfo) 120void radeon_delete_i2c_busses(struct radeonfb_info *rinfo)
121{ 121{
122 if (rinfo->i2c[0].rinfo) 122 if (rinfo->i2c[0].rinfo)
123 i2c_bit_del_bus(&rinfo->i2c[0].adapter); 123 i2c_del_adapter(&rinfo->i2c[0].adapter);
124 rinfo->i2c[0].rinfo = NULL; 124 rinfo->i2c[0].rinfo = NULL;
125 125
126 if (rinfo->i2c[1].rinfo) 126 if (rinfo->i2c[1].rinfo)
127 i2c_bit_del_bus(&rinfo->i2c[1].adapter); 127 i2c_del_adapter(&rinfo->i2c[1].adapter);
128 rinfo->i2c[1].rinfo = NULL; 128 rinfo->i2c[1].rinfo = NULL;
129 129
130 if (rinfo->i2c[2].rinfo) 130 if (rinfo->i2c[2].rinfo)
131 i2c_bit_del_bus(&rinfo->i2c[2].adapter); 131 i2c_del_adapter(&rinfo->i2c[2].adapter);
132 rinfo->i2c[2].rinfo = NULL; 132 rinfo->i2c[2].rinfo = NULL;
133 133
134 if (rinfo->i2c[3].rinfo) 134 if (rinfo->i2c[3].rinfo)
135 i2c_bit_del_bus(&rinfo->i2c[3].adapter); 135 i2c_del_adapter(&rinfo->i2c[3].adapter);
136 rinfo->i2c[3].rinfo = NULL; 136 rinfo->i2c[3].rinfo = NULL;
137} 137}
138 138
diff --git a/drivers/video/aty/radeon_monitor.c b/drivers/video/aty/radeon_monitor.c
index ea531a6f45d1..38c7dbf8c151 100644
--- a/drivers/video/aty/radeon_monitor.c
+++ b/drivers/video/aty/radeon_monitor.c
@@ -104,10 +104,9 @@ static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_
104 if (pedid == NULL) 104 if (pedid == NULL)
105 return mt; 105 return mt;
106 106
107 tmp = (u8 *)kmalloc(EDID_LENGTH, GFP_KERNEL); 107 tmp = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
108 if (!tmp) 108 if (!tmp)
109 return mt; 109 return mt;
110 memcpy(tmp, pedid, EDID_LENGTH);
111 *out_EDID = tmp; 110 *out_EDID = tmp;
112 return mt; 111 return mt;
113} 112}
diff --git a/drivers/video/au1100fb.h b/drivers/video/au1100fb.h
index 2855534dc235..164fe2f231ec 100644
--- a/drivers/video/au1100fb.h
+++ b/drivers/video/au1100fb.h
@@ -274,7 +274,7 @@ static struct au1100fb_panel known_lcd_panels[] =
274 .bpp = 16, 274 .bpp = 16,
275 .control_base = 0x0004886A | 275 .control_base = 0x0004886A |
276 LCD_CONTROL_DEFAULT_PO | LCD_CONTROL_DEFAULT_SBPPF | 276 LCD_CONTROL_DEFAULT_PO | LCD_CONTROL_DEFAULT_SBPPF |
277 LCD_CONTROL_BPP_16, 277 LCD_CONTROL_BPP_16 | LCD_CONTROL_SBB_4,
278 .clkcontrol_base = 0x00020000, 278 .clkcontrol_base = 0x00020000,
279 .horztiming = 0x005aff1f, 279 .horztiming = 0x005aff1f,
280 .verttiming = 0x16000e57, 280 .verttiming = 0x16000e57,
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 27597c576eff..db8c191b1201 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -14,6 +14,59 @@
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16 16
17
18#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
19 defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
20/* This callback gets called when something important happens inside a
21 * framebuffer driver. We're looking if that important event is blanking,
22 * and if it is, we're switching backlight power as well ...
23 */
24static int fb_notifier_callback(struct notifier_block *self,
25 unsigned long event, void *data)
26{
27 struct backlight_device *bd;
28 struct fb_event *evdata = data;
29
30 /* If we aren't interested in this event, skip it immediately ... */
31 if (event != FB_EVENT_BLANK)
32 return 0;
33
34 bd = container_of(self, struct backlight_device, fb_notif);
35 down(&bd->sem);
36 if (bd->props)
37 if (!bd->props->check_fb ||
38 bd->props->check_fb(evdata->info)) {
39 bd->props->fb_blank = *(int *)evdata->data;
40 if (likely(bd->props && bd->props->update_status))
41 bd->props->update_status(bd);
42 }
43 up(&bd->sem);
44 return 0;
45}
46
47static int backlight_register_fb(struct backlight_device *bd)
48{
49 memset(&bd->fb_notif, 0, sizeof(bd->fb_notif));
50 bd->fb_notif.notifier_call = fb_notifier_callback;
51
52 return fb_register_client(&bd->fb_notif);
53}
54
55static void backlight_unregister_fb(struct backlight_device *bd)
56{
57 fb_unregister_client(&bd->fb_notif);
58}
59#else
60static inline int backlight_register_fb(struct backlight_device *bd)
61{
62 return 0;
63}
64
65static inline void backlight_unregister_fb(struct backlight_device *bd)
66{
67}
68#endif /* CONFIG_FB */
69
17static ssize_t backlight_show_power(struct class_device *cdev, char *buf) 70static ssize_t backlight_show_power(struct class_device *cdev, char *buf)
18{ 71{
19 int rc = -ENXIO; 72 int rc = -ENXIO;
@@ -142,7 +195,7 @@ static struct class backlight_class = {
142 .store = _store, \ 195 .store = _store, \
143} 196}
144 197
145static struct class_device_attribute bl_class_device_attributes[] = { 198static const struct class_device_attribute bl_class_device_attributes[] = {
146 DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power), 199 DECLARE_ATTR(power, 0644, backlight_show_power, backlight_store_power),
147 DECLARE_ATTR(brightness, 0644, backlight_show_brightness, 200 DECLARE_ATTR(brightness, 0644, backlight_show_brightness,
148 backlight_store_brightness), 201 backlight_store_brightness),
@@ -151,33 +204,6 @@ static struct class_device_attribute bl_class_device_attributes[] = {
151 DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), 204 DECLARE_ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL),
152}; 205};
153 206
154/* This callback gets called when something important happens inside a
155 * framebuffer driver. We're looking if that important event is blanking,
156 * and if it is, we're switching backlight power as well ...
157 */
158static int fb_notifier_callback(struct notifier_block *self,
159 unsigned long event, void *data)
160{
161 struct backlight_device *bd;
162 struct fb_event *evdata =(struct fb_event *)data;
163
164 /* If we aren't interested in this event, skip it immediately ... */
165 if (event != FB_EVENT_BLANK)
166 return 0;
167
168 bd = container_of(self, struct backlight_device, fb_notif);
169 down(&bd->sem);
170 if (bd->props)
171 if (!bd->props->check_fb ||
172 bd->props->check_fb(evdata->info)) {
173 bd->props->fb_blank = *(int *)evdata->data;
174 if (likely(bd->props && bd->props->update_status))
175 bd->props->update_status(bd);
176 }
177 up(&bd->sem);
178 return 0;
179}
180
181/** 207/**
182 * backlight_device_register - create and register a new object of 208 * backlight_device_register - create and register a new object of
183 * backlight_device class. 209 * backlight_device class.
@@ -215,10 +241,7 @@ error: kfree(new_bd);
215 return ERR_PTR(rc); 241 return ERR_PTR(rc);
216 } 242 }
217 243
218 memset(&new_bd->fb_notif, 0, sizeof(new_bd->fb_notif)); 244 rc = backlight_register_fb(new_bd);
219 new_bd->fb_notif.notifier_call = fb_notifier_callback;
220
221 rc = fb_register_client(&new_bd->fb_notif);
222 if (unlikely(rc)) 245 if (unlikely(rc))
223 goto error; 246 goto error;
224 247
@@ -259,16 +282,10 @@ void backlight_device_unregister(struct backlight_device *bd)
259 &bl_class_device_attributes[i]); 282 &bl_class_device_attributes[i]);
260 283
261 down(&bd->sem); 284 down(&bd->sem);
262 if (likely(bd->props && bd->props->update_status)) {
263 bd->props->brightness = 0;
264 bd->props->power = 0;
265 bd->props->update_status(bd);
266 }
267
268 bd->props = NULL; 285 bd->props = NULL;
269 up(&bd->sem); 286 up(&bd->sem);
270 287
271 fb_unregister_client(&bd->fb_notif); 288 backlight_unregister_fb(bd);
272 289
273 class_device_unregister(&bd->class_dev); 290 class_device_unregister(&bd->class_dev);
274} 291}
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
index d07ecb53c68b..61587ca2cdbb 100644
--- a/drivers/video/backlight/corgi_bl.c
+++ b/drivers/video/backlight/corgi_bl.c
@@ -135,6 +135,10 @@ static int corgibl_probe(struct platform_device *pdev)
135 135
136static int corgibl_remove(struct platform_device *dev) 136static int corgibl_remove(struct platform_device *dev)
137{ 137{
138 corgibl_data.power = 0;
139 corgibl_data.brightness = 0;
140 corgibl_send_intensity(corgi_backlight_device);
141
138 backlight_device_unregister(corgi_backlight_device); 142 backlight_device_unregister(corgi_backlight_device);
139 143
140 printk("Corgi Backlight Driver Unloaded\n"); 144 printk("Corgi Backlight Driver Unloaded\n");
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index e3993213d10e..1c569fb543ae 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -117,6 +117,10 @@ static int __init hp680bl_probe(struct platform_device *dev)
117 117
118static int hp680bl_remove(struct platform_device *dev) 118static int hp680bl_remove(struct platform_device *dev)
119{ 119{
120 hp680bl_data.brightness = 0;
121 hp680bl_data.power = 0;
122 hp680bl_send_intensity(hp680_backlight_device);
123
120 backlight_device_unregister(hp680_backlight_device); 124 backlight_device_unregister(hp680_backlight_device);
121 125
122 return 0; 126 return 0;
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index bc8ab005a3fb..f6e041627edb 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -14,6 +14,53 @@
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/fb.h> 15#include <linux/fb.h>
16 16
17#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \
18 defined(CONFIG_LCD_CLASS_DEVICE_MODULE))
19/* This callback gets called when something important happens inside a
20 * framebuffer driver. We're looking if that important event is blanking,
21 * and if it is, we're switching lcd power as well ...
22 */
23static int fb_notifier_callback(struct notifier_block *self,
24 unsigned long event, void *data)
25{
26 struct lcd_device *ld;
27 struct fb_event *evdata = data;
28
29 /* If we aren't interested in this event, skip it immediately ... */
30 if (event != FB_EVENT_BLANK)
31 return 0;
32
33 ld = container_of(self, struct lcd_device, fb_notif);
34 down(&ld->sem);
35 if (ld->props)
36 if (!ld->props->check_fb || ld->props->check_fb(evdata->info))
37 ld->props->set_power(ld, *(int *)evdata->data);
38 up(&ld->sem);
39 return 0;
40}
41
42static int lcd_register_fb(struct lcd_device *ld)
43{
44 memset(&ld->fb_notif, 0, sizeof(&ld->fb_notif));
45 ld->fb_notif.notifier_call = fb_notifier_callback;
46 return fb_register_client(&ld->fb_notif);
47}
48
49static void lcd_unregister_fb(struct lcd_device *ld)
50{
51 fb_unregister_client(&ld->fb_notif);
52}
53#else
54static int lcd_register_fb(struct lcd_device *ld)
55{
56 return 0;
57}
58
59static inline void lcd_unregister_fb(struct lcd_device *ld)
60{
61}
62#endif /* CONFIG_FB */
63
17static ssize_t lcd_show_power(struct class_device *cdev, char *buf) 64static ssize_t lcd_show_power(struct class_device *cdev, char *buf)
18{ 65{
19 int rc; 66 int rc;
@@ -121,35 +168,12 @@ static struct class lcd_class = {
121 .store = _store, \ 168 .store = _store, \
122} 169}
123 170
124static struct class_device_attribute lcd_class_device_attributes[] = { 171static const struct class_device_attribute lcd_class_device_attributes[] = {
125 DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power), 172 DECLARE_ATTR(power, 0644, lcd_show_power, lcd_store_power),
126 DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast), 173 DECLARE_ATTR(contrast, 0644, lcd_show_contrast, lcd_store_contrast),
127 DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL), 174 DECLARE_ATTR(max_contrast, 0444, lcd_show_max_contrast, NULL),
128}; 175};
129 176
130/* This callback gets called when something important happens inside a
131 * framebuffer driver. We're looking if that important event is blanking,
132 * and if it is, we're switching lcd power as well ...
133 */
134static int fb_notifier_callback(struct notifier_block *self,
135 unsigned long event, void *data)
136{
137 struct lcd_device *ld;
138 struct fb_event *evdata =(struct fb_event *)data;
139
140 /* If we aren't interested in this event, skip it immediately ... */
141 if (event != FB_EVENT_BLANK)
142 return 0;
143
144 ld = container_of(self, struct lcd_device, fb_notif);
145 down(&ld->sem);
146 if (ld->props)
147 if (!ld->props->check_fb || ld->props->check_fb(evdata->info))
148 ld->props->set_power(ld, *(int *)evdata->data);
149 up(&ld->sem);
150 return 0;
151}
152
153/** 177/**
154 * lcd_device_register - register a new object of lcd_device class. 178 * lcd_device_register - register a new object of lcd_device class.
155 * @name: the name of the new object(must be the same as the name of the 179 * @name: the name of the new object(must be the same as the name of the
@@ -186,10 +210,8 @@ error: kfree(new_ld);
186 return ERR_PTR(rc); 210 return ERR_PTR(rc);
187 } 211 }
188 212
189 memset(&new_ld->fb_notif, 0, sizeof(new_ld->fb_notif)); 213 rc = lcd_register_fb(new_ld);
190 new_ld->fb_notif.notifier_call = fb_notifier_callback;
191 214
192 rc = fb_register_client(&new_ld->fb_notif);
193 if (unlikely(rc)) 215 if (unlikely(rc))
194 goto error; 216 goto error;
195 217
@@ -232,9 +254,7 @@ void lcd_device_unregister(struct lcd_device *ld)
232 down(&ld->sem); 254 down(&ld->sem);
233 ld->props = NULL; 255 ld->props = NULL;
234 up(&ld->sem); 256 up(&ld->sem);
235 257 lcd_unregister_fb(ld);
236 fb_unregister_client(&ld->fb_notif);
237
238 class_device_unregister(&ld->class_dev); 258 class_device_unregister(&ld->class_dev);
239} 259}
240EXPORT_SYMBOL(lcd_device_unregister); 260EXPORT_SYMBOL(lcd_device_unregister);
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index 628571c63bac..2d7905410b2a 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -200,6 +200,10 @@ static int locomolcd_remove(struct locomo_dev *dev)
200{ 200{
201 unsigned long flags; 201 unsigned long flags;
202 202
203 locomobl_data.brightness = 0;
204 locomobl_data.power = 0;
205 locomolcd_set_intensity(locomolcd_bl_device);
206
203 backlight_device_unregister(locomolcd_bl_device); 207 backlight_device_unregister(locomolcd_bl_device);
204 local_irq_save(flags); 208 local_irq_save(flags);
205 locomolcd_dev = NULL; 209 locomolcd_dev = NULL;
diff --git a/drivers/video/cfbimgblt.c b/drivers/video/cfbimgblt.c
index 51d35386a945..261004473c8e 100644
--- a/drivers/video/cfbimgblt.c
+++ b/drivers/video/cfbimgblt.c
@@ -42,7 +42,7 @@
42#define DPRINTK(fmt, args...) 42#define DPRINTK(fmt, args...)
43#endif 43#endif
44 44
45static u32 cfb_tab8[] = { 45static const u32 cfb_tab8[] = {
46#if defined(__BIG_ENDIAN) 46#if defined(__BIG_ENDIAN)
47 0x00000000,0x000000ff,0x0000ff00,0x0000ffff, 47 0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
48 0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff, 48 0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
@@ -58,7 +58,7 @@ static u32 cfb_tab8[] = {
58#endif 58#endif
59}; 59};
60 60
61static u32 cfb_tab16[] = { 61static const u32 cfb_tab16[] = {
62#if defined(__BIG_ENDIAN) 62#if defined(__BIG_ENDIAN)
63 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff 63 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
64#elif defined(__LITTLE_ENDIAN) 64#elif defined(__LITTLE_ENDIAN)
@@ -68,7 +68,7 @@ static u32 cfb_tab16[] = {
68#endif 68#endif
69}; 69};
70 70
71static u32 cfb_tab32[] = { 71static const u32 cfb_tab32[] = {
72 0x00000000, 0xffffffff 72 0x00000000, 0xffffffff
73}; 73};
74 74
@@ -218,7 +218,7 @@ static inline void fast_imageblit(const struct fb_image *image, struct fb_info *
218 u32 bit_mask, end_mask, eorx, shift; 218 u32 bit_mask, end_mask, eorx, shift;
219 const char *s = image->data, *src; 219 const char *s = image->data, *src;
220 u32 __iomem *dst; 220 u32 __iomem *dst;
221 u32 *tab = NULL; 221 const u32 *tab = NULL;
222 int i, j, k; 222 int i, j, k;
223 223
224 switch (bpp) { 224 switch (bpp) {
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index daf43f535a0b..2c4bc6205738 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -2442,7 +2442,10 @@ static int cirrusfb_pci_register (struct pci_dev *pdev,
2442 printk ("Cirrus Logic chipset on PCI bus\n"); 2442 printk ("Cirrus Logic chipset on PCI bus\n");
2443 pci_set_drvdata(pdev, info); 2443 pci_set_drvdata(pdev, info);
2444 2444
2445 return cirrusfb_register(cinfo); 2445 ret = cirrusfb_register(cinfo);
2446 if (ret)
2447 iounmap(cinfo->fbmem);
2448 return ret;
2446 2449
2447err_release_legacy: 2450err_release_legacy:
2448 if (release_io_ports) 2451 if (release_io_ports)
@@ -2574,7 +2577,15 @@ static int cirrusfb_zorro_register(struct zorro_dev *z,
2574 printk (KERN_INFO "Cirrus Logic chipset on Zorro bus\n"); 2577 printk (KERN_INFO "Cirrus Logic chipset on Zorro bus\n");
2575 zorro_set_drvdata(z, info); 2578 zorro_set_drvdata(z, info);
2576 2579
2577 return cirrusfb_register(cinfo); 2580 ret = cirrusfb_register(cinfo);
2581 if (ret) {
2582 if (btype == BT_PICASSO4) {
2583 iounmap(cinfo->fbmem);
2584 iounmap(cinfo->regbase - 0x600000);
2585 } else if (board_addr > 0x01000000)
2586 iounmap(cinfo->fbmem);
2587 }
2588 return ret;
2578 2589
2579err_unmap_regbase: 2590err_unmap_regbase:
2580 /* Parental advisory: explicit hack */ 2591 /* Parental advisory: explicit hack */
diff --git a/drivers/video/console/softcursor.c b/drivers/video/console/softcursor.c
index 7d07d8383569..f577bd80e020 100644
--- a/drivers/video/console/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -1,11 +1,13 @@
1/* 1/*
2 * linux/drivers/video/softcursor.c -- Generic software cursor for frame buffer devices 2 * linux/drivers/video/softcursor.c
3 *
4 * Generic software cursor for frame buffer devices
3 * 5 *
4 * Created 14 Nov 2002 by James Simmons 6 * Created 14 Nov 2002 by James Simmons
5 * 7 *
6 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General
7 * License. See the file COPYING in the main directory of this archive 9 * Public License. See the file COPYING in the main directory of this
8 * for more details. 10 * archive for more details.
9 */ 11 */
10 12
11#include <linux/module.h> 13#include <linux/module.h>
@@ -25,7 +27,7 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
25 unsigned int buf_align = info->pixmap.buf_align - 1; 27 unsigned int buf_align = info->pixmap.buf_align - 1;
26 unsigned int i, size, dsize, s_pitch, d_pitch; 28 unsigned int i, size, dsize, s_pitch, d_pitch;
27 struct fb_image *image; 29 struct fb_image *image;
28 u8 *dst; 30 u8 *src, *dst;
29 31
30 if (info->state != FBINFO_STATE_RUNNING) 32 if (info->state != FBINFO_STATE_RUNNING)
31 return 0; 33 return 0;
@@ -45,7 +47,8 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
45 } 47 }
46 } 48 }
47 49
48 image = (struct fb_image *) (ops->cursor_src + dsize); 50 src = ops->cursor_src + sizeof(struct fb_image);
51 image = (struct fb_image *)ops->cursor_src;
49 *image = cursor->image; 52 *image = cursor->image;
50 d_pitch = (s_pitch + scan_align) & ~scan_align; 53 d_pitch = (s_pitch + scan_align) & ~scan_align;
51 54
@@ -57,21 +60,18 @@ int soft_cursor(struct fb_info *info, struct fb_cursor *cursor)
57 switch (cursor->rop) { 60 switch (cursor->rop) {
58 case ROP_XOR: 61 case ROP_XOR:
59 for (i = 0; i < dsize; i++) 62 for (i = 0; i < dsize; i++)
60 ops->cursor_src[i] = image->data[i] ^ 63 src[i] = image->data[i] ^ cursor->mask[i];
61 cursor->mask[i];
62 break; 64 break;
63 case ROP_COPY: 65 case ROP_COPY:
64 default: 66 default:
65 for (i = 0; i < dsize; i++) 67 for (i = 0; i < dsize; i++)
66 ops->cursor_src[i] = image->data[i] & 68 src[i] = image->data[i] & cursor->mask[i];
67 cursor->mask[i];
68 break; 69 break;
69 } 70 }
70 } else 71 } else
71 memcpy(ops->cursor_src, image->data, dsize); 72 memcpy(src, image->data, dsize);
72 73
73 fb_pad_aligned_buffer(dst, d_pitch, ops->cursor_src, s_pitch, 74 fb_pad_aligned_buffer(dst, d_pitch, src, s_pitch, image->height);
74 image->height);
75 image->data = dst; 75 image->data = dst;
76 info->fbops->fb_imageblit(info, image); 76 info->fbops->fb_imageblit(info, image);
77 return 0; 77 return 0;
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 45586aaabd1e..57b21e533036 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -345,7 +345,7 @@ static void sticon_save_screen(struct vc_data *conp)
345{ 345{
346} 346}
347 347
348static struct consw sti_con = { 348static const struct consw sti_con = {
349 .owner = THIS_MODULE, 349 .owner = THIS_MODULE,
350 .con_startup = sticon_startup, 350 .con_startup = sticon_startup,
351 .con_init = sticon_init, 351 .con_init = sticon_init,
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 0a2c10a1abf8..4a9bde2c839b 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -93,27 +93,27 @@ static void vgacon_invert_region(struct vc_data *c, u16 * p, int count);
93static unsigned long vgacon_uni_pagedir[2]; 93static unsigned long vgacon_uni_pagedir[2];
94 94
95/* Description of the hardware situation */ 95/* Description of the hardware situation */
96static unsigned long vga_vram_base; /* Base of video memory */ 96static int vga_init_done __read_mostly;
97static unsigned long vga_vram_end; /* End of video memory */ 97static unsigned long vga_vram_base __read_mostly; /* Base of video memory */
98static int vga_vram_size; /* Size of video memory */ 98static unsigned long vga_vram_end __read_mostly; /* End of video memory */
99static u16 vga_video_port_reg; /* Video register select port */ 99static unsigned int vga_vram_size __read_mostly; /* Size of video memory */
100static u16 vga_video_port_val; /* Video register value port */ 100static u16 vga_video_port_reg __read_mostly; /* Video register select port */
101static unsigned int vga_video_num_columns; /* Number of text columns */ 101static u16 vga_video_port_val __read_mostly; /* Video register value port */
102static unsigned int vga_video_num_lines; /* Number of text lines */ 102static unsigned int vga_video_num_columns; /* Number of text columns */
103static int vga_can_do_color = 0; /* Do we support colors? */ 103static unsigned int vga_video_num_lines; /* Number of text lines */
104static unsigned int vga_default_font_height;/* Height of default screen font */ 104static int vga_can_do_color __read_mostly; /* Do we support colors? */
105static unsigned char vga_video_type; /* Card type */ 105static unsigned int vga_default_font_height __read_mostly; /* Height of default screen font */
106static unsigned char vga_hardscroll_enabled; 106static unsigned char vga_video_type __read_mostly; /* Card type */
107static unsigned char vga_hardscroll_user_enable = 1; 107static unsigned char vga_hardscroll_enabled __read_mostly;
108static unsigned char vga_hardscroll_user_enable __read_mostly = 1;
108static unsigned char vga_font_is_default = 1; 109static unsigned char vga_font_is_default = 1;
109static int vga_vesa_blanked; 110static int vga_vesa_blanked;
110static int vga_palette_blanked; 111static int vga_palette_blanked;
111static int vga_is_gfx; 112static int vga_is_gfx;
112static int vga_512_chars; 113static int vga_512_chars;
113static int vga_video_font_height; 114static int vga_video_font_height;
114static int vga_scan_lines; 115static int vga_scan_lines __read_mostly;
115static unsigned int vga_rolled_over = 0; 116static unsigned int vga_rolled_over;
116static int vga_init_done;
117 117
118static int __init no_scroll(char *str) 118static int __init no_scroll(char *str)
119{ 119{
diff --git a/drivers/video/cyberfb.c b/drivers/video/cyberfb.c
index c40e72dafb0e..0b8d5b121152 100644
--- a/drivers/video/cyberfb.c
+++ b/drivers/video/cyberfb.c
@@ -109,8 +109,6 @@ static void cv64_dump(void);
109#define wb_64(regs,reg,dat) (*(((volatile unsigned char *)regs) + reg) = dat) 109#define wb_64(regs,reg,dat) (*(((volatile unsigned char *)regs) + reg) = dat)
110#define rb_64(regs, reg) (*(((volatile unsigned char *)regs) + reg)) 110#define rb_64(regs, reg) (*(((volatile unsigned char *)regs) + reg))
111 111
112#define ww_64(regs,reg,dat) (*((volatile unsigned short *)(regs + reg) = dat)
113
114struct cyberfb_par { 112struct cyberfb_par {
115 struct fb_var_screeninfo var; 113 struct fb_var_screeninfo var;
116 __u32 type; 114 __u32 type;
@@ -1055,6 +1053,8 @@ int __init cyberfb_init(void)
1055 1053
1056 if (register_framebuffer(&fb_info) < 0) { 1054 if (register_framebuffer(&fb_info) < 0) {
1057 DPRINTK("EXIT - register_framebuffer failed\n"); 1055 DPRINTK("EXIT - register_framebuffer failed\n");
1056 if (CyberBase)
1057 iounmap(CyberBase);
1058 release_mem_region(CyberMem_phys, 0x400000); 1058 release_mem_region(CyberMem_phys, 0x400000);
1059 release_mem_region(CyberRegs_phys, 0x10000); 1059 release_mem_region(CyberRegs_phys, 0x10000);
1060 return -EINVAL; 1060 return -EINVAL;
diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index 737257d278f0..29e07c109887 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -405,7 +405,7 @@ static inline unsigned long copy_to_user16(void *to, const void *from,
405static ssize_t 405static ssize_t
406epson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos) 406epson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos)
407{ 407{
408 struct inode *inode = file->f_dentry->d_inode; 408 struct inode *inode = file->f_path.dentry->d_inode;
409 int fbidx = iminor(inode); 409 int fbidx = iminor(inode);
410 struct fb_info *info = registered_fb[fbidx]; 410 struct fb_info *info = registered_fb[fbidx];
411 unsigned long p = *ppos; 411 unsigned long p = *ppos;
@@ -437,7 +437,7 @@ static ssize_t
437epson1355fb_write(struct file *file, const char *buf, 437epson1355fb_write(struct file *file, const char *buf,
438 size_t count, loff_t * ppos) 438 size_t count, loff_t * ppos)
439{ 439{
440 struct inode *inode = file->f_dentry->d_inode; 440 struct inode *inode = file->f_path.dentry->d_inode;
441 int fbidx = iminor(inode); 441 int fbidx = iminor(inode);
442 struct fb_info *info = registered_fb[fbidx]; 442 struct fb_info *info = registered_fb[fbidx];
443 unsigned long p = *ppos; 443 unsigned long p = *ppos;
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index e8b135f3d80d..148108afdd51 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -18,63 +18,64 @@
18 18
19#include <asm/uaccess.h> 19#include <asm/uaccess.h>
20 20
21static u16 red2[] = { 21static u16 red2[] __read_mostly = {
22 0x0000, 0xaaaa 22 0x0000, 0xaaaa
23}; 23};
24static u16 green2[] = { 24static u16 green2[] __read_mostly = {
25 0x0000, 0xaaaa 25 0x0000, 0xaaaa
26}; 26};
27static u16 blue2[] = { 27static u16 blue2[] __read_mostly = {
28 0x0000, 0xaaaa 28 0x0000, 0xaaaa
29}; 29};
30 30
31static u16 red4[] = { 31static u16 red4[] __read_mostly = {
32 0x0000, 0xaaaa, 0x5555, 0xffff 32 0x0000, 0xaaaa, 0x5555, 0xffff
33}; 33};
34static u16 green4[] = { 34static u16 green4[] __read_mostly = {
35 0x0000, 0xaaaa, 0x5555, 0xffff 35 0x0000, 0xaaaa, 0x5555, 0xffff
36}; 36};
37static u16 blue4[] = { 37static u16 blue4[] __read_mostly = {
38 0x0000, 0xaaaa, 0x5555, 0xffff 38 0x0000, 0xaaaa, 0x5555, 0xffff
39}; 39};
40 40
41static u16 red8[] = { 41static u16 red8[] __read_mostly = {
42 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa 42 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa
43}; 43};
44static u16 green8[] = { 44static u16 green8[] __read_mostly = {
45 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa 45 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa
46}; 46};
47static u16 blue8[] = { 47static u16 blue8[] __read_mostly = {
48 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa 48 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa
49}; 49};
50 50
51static u16 red16[] = { 51static u16 red16[] __read_mostly = {
52 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 52 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
53 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff 53 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
54}; 54};
55static u16 green16[] = { 55static u16 green16[] __read_mostly = {
56 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa, 56 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
57 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff 57 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
58}; 58};
59static u16 blue16[] = { 59static u16 blue16[] __read_mostly = {
60 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 60 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
61 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff 61 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
62}; 62};
63 63
64static struct fb_cmap default_2_colors = { 64static const struct fb_cmap default_2_colors = {
65 0, 2, red2, green2, blue2, NULL 65 .len=2, .red=red2, .green=green2, .blue=blue2
66}; 66};
67static struct fb_cmap default_8_colors = { 67static const struct fb_cmap default_8_colors = {
68 0, 8, red8, green8, blue8, NULL 68 .len=8, .red=red8, .green=green8, .blue=blue8
69}; 69};
70static struct fb_cmap default_4_colors = { 70static const struct fb_cmap default_4_colors = {
71 0, 4, red4, green4, blue4, NULL 71 .len=4, .red=red4, .green=green4, .blue=blue4
72}; 72};
73static struct fb_cmap default_16_colors = { 73static const struct fb_cmap default_16_colors = {
74 0, 16, red16, green16, blue16, NULL 74 .len=16, .red=red16, .green=green16, .blue=blue16
75}; 75};
76 76
77 77
78
78/** 79/**
79 * fb_alloc_cmap - allocate a colormap 80 * fb_alloc_cmap - allocate a colormap
80 * @cmap: frame buffer colormap structure 81 * @cmap: frame buffer colormap structure
@@ -146,7 +147,7 @@ void fb_dealloc_cmap(struct fb_cmap *cmap)
146 * Copy contents of colormap from @from to @to. 147 * Copy contents of colormap from @from to @to.
147 */ 148 */
148 149
149int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to) 150int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)
150{ 151{
151 int tooff = 0, fromoff = 0; 152 int tooff = 0, fromoff = 0;
152 int size; 153 int size;
@@ -170,7 +171,7 @@ int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to)
170 return 0; 171 return 0;
171} 172}
172 173
173int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to) 174int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to)
174{ 175{
175 int tooff = 0, fromoff = 0; 176 int tooff = 0, fromoff = 0;
176 int size; 177 int size;
@@ -282,7 +283,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
282 * 283 *
283 */ 284 */
284 285
285struct fb_cmap *fb_default_cmap(int len) 286const struct fb_cmap *fb_default_cmap(int len)
286{ 287{
287 if (len <= 2) 288 if (len <= 2)
288 return &default_2_colors; 289 return &default_2_colors;
@@ -305,22 +306,22 @@ void fb_invert_cmaps(void)
305{ 306{
306 u_int i; 307 u_int i;
307 308
308 for (i = 0; i < 2; i++) { 309 for (i = 0; i < ARRAY_SIZE(red2); i++) {
309 red2[i] = ~red2[i]; 310 red2[i] = ~red2[i];
310 green2[i] = ~green2[i]; 311 green2[i] = ~green2[i];
311 blue2[i] = ~blue2[i]; 312 blue2[i] = ~blue2[i];
312 } 313 }
313 for (i = 0; i < 4; i++) { 314 for (i = 0; i < ARRAY_SIZE(red4); i++) {
314 red4[i] = ~red4[i]; 315 red4[i] = ~red4[i];
315 green4[i] = ~green4[i]; 316 green4[i] = ~green4[i];
316 blue4[i] = ~blue4[i]; 317 blue4[i] = ~blue4[i];
317 } 318 }
318 for (i = 0; i < 8; i++) { 319 for (i = 0; i < ARRAY_SIZE(red8); i++) {
319 red8[i] = ~red8[i]; 320 red8[i] = ~red8[i];
320 green8[i] = ~green8[i]; 321 green8[i] = ~green8[i];
321 blue8[i] = ~blue8[i]; 322 blue8[i] = ~blue8[i];
322 } 323 }
323 for (i = 0; i < 16; i++) { 324 for (i = 0; i < ARRAY_SIZE(red16); i++) {
324 red16[i] = ~red16[i]; 325 red16[i] = ~red16[i];
325 green16[i] = ~green16[i]; 326 green16[i] = ~green16[i];
326 blue16[i] = ~blue16[i]; 327 blue16[i] = ~blue16[i];
diff --git a/drivers/video/fbcvt.c b/drivers/video/fbcvt.c
index b5498999c4ec..0847c5e72cbd 100644
--- a/drivers/video/fbcvt.c
+++ b/drivers/video/fbcvt.c
@@ -57,7 +57,7 @@ struct fb_cvt_data {
57 u32 status; 57 u32 status;
58}; 58};
59 59
60static int fb_cvt_vbi_tab[] = { 60static const unsigned char fb_cvt_vbi_tab[] = {
61 4, /* 4:3 */ 61 4, /* 4:3 */
62 5, /* 16:9 */ 62 5, /* 16:9 */
63 6, /* 16:10 */ 63 6, /* 16:10 */
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index e973a87fbb01..3cfea315a48f 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -52,8 +52,8 @@
52 52
53#define FBPIXMAPSIZE (1024 * 8) 53#define FBPIXMAPSIZE (1024 * 8)
54 54
55struct fb_info *registered_fb[FB_MAX]; 55struct fb_info *registered_fb[FB_MAX] __read_mostly;
56int num_registered_fb; 56int num_registered_fb __read_mostly;
57 57
58/* 58/*
59 * Helpers 59 * Helpers
@@ -202,7 +202,7 @@ static void fb_set_logo_truepalette(struct fb_info *info,
202 const struct linux_logo *logo, 202 const struct linux_logo *logo,
203 u32 *palette) 203 u32 *palette)
204{ 204{
205 unsigned char mask[9] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff }; 205 static const unsigned char mask[] = { 0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff };
206 unsigned char redmask, greenmask, bluemask; 206 unsigned char redmask, greenmask, bluemask;
207 int redshift, greenshift, blueshift; 207 int redshift, greenshift, blueshift;
208 int i; 208 int i;
@@ -317,7 +317,7 @@ static struct logo_data {
317 int needs_truepalette; 317 int needs_truepalette;
318 int needs_cmapreset; 318 int needs_cmapreset;
319 const struct linux_logo *logo; 319 const struct linux_logo *logo;
320} fb_logo; 320} fb_logo __read_mostly;
321 321
322static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height) 322static void fb_rotate_logo_ud(const u8 *in, u8 *out, u32 width, u32 height)
323{ 323{
@@ -572,7 +572,7 @@ static ssize_t
572fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 572fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
573{ 573{
574 unsigned long p = *ppos; 574 unsigned long p = *ppos;
575 struct inode *inode = file->f_dentry->d_inode; 575 struct inode *inode = file->f_path.dentry->d_inode;
576 int fbidx = iminor(inode); 576 int fbidx = iminor(inode);
577 struct fb_info *info = registered_fb[fbidx]; 577 struct fb_info *info = registered_fb[fbidx];
578 u32 *buffer, *dst; 578 u32 *buffer, *dst;
@@ -647,7 +647,7 @@ static ssize_t
647fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 647fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
648{ 648{
649 unsigned long p = *ppos; 649 unsigned long p = *ppos;
650 struct inode *inode = file->f_dentry->d_inode; 650 struct inode *inode = file->f_path.dentry->d_inode;
651 int fbidx = iminor(inode); 651 int fbidx = iminor(inode);
652 struct fb_info *info = registered_fb[fbidx]; 652 struct fb_info *info = registered_fb[fbidx];
653 u32 *buffer, *src; 653 u32 *buffer, *src;
@@ -1081,7 +1081,7 @@ static int fb_get_fscreeninfo(struct inode *inode, struct file *file,
1081static long 1081static long
1082fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1082fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1083{ 1083{
1084 struct inode *inode = file->f_dentry->d_inode; 1084 struct inode *inode = file->f_path.dentry->d_inode;
1085 int fbidx = iminor(inode); 1085 int fbidx = iminor(inode);
1086 struct fb_info *info = registered_fb[fbidx]; 1086 struct fb_info *info = registered_fb[fbidx];
1087 struct fb_ops *fb = info->fbops; 1087 struct fb_ops *fb = info->fbops;
@@ -1121,7 +1121,7 @@ fb_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1121static int 1121static int
1122fb_mmap(struct file *file, struct vm_area_struct * vma) 1122fb_mmap(struct file *file, struct vm_area_struct * vma)
1123{ 1123{
1124 int fbidx = iminor(file->f_dentry->d_inode); 1124 int fbidx = iminor(file->f_path.dentry->d_inode);
1125 struct fb_info *info = registered_fb[fbidx]; 1125 struct fb_info *info = registered_fb[fbidx];
1126 struct fb_ops *fb = info->fbops; 1126 struct fb_ops *fb = info->fbops;
1127 unsigned long off; 1127 unsigned long off;
@@ -1253,7 +1253,7 @@ fb_release(struct inode *inode, struct file *file)
1253 return 0; 1253 return 0;
1254} 1254}
1255 1255
1256static struct file_operations fb_fops = { 1256static const struct file_operations fb_fops = {
1257 .owner = THIS_MODULE, 1257 .owner = THIS_MODULE,
1258 .read = fb_read, 1258 .read = fb_read,
1259 .write = fb_write, 1259 .write = fb_write,
@@ -1459,8 +1459,8 @@ int fb_new_modelist(struct fb_info *info)
1459 return err; 1459 return err;
1460} 1460}
1461 1461
1462static char *video_options[FB_MAX]; 1462static char *video_options[FB_MAX] __read_mostly;
1463static int ofonly; 1463static int ofonly __read_mostly;
1464 1464
1465extern const char *global_mode_option; 1465extern const char *global_mode_option;
1466 1466
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index de93139ccbb5..6b385c39b8b5 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -58,7 +58,7 @@ struct broken_edid {
58 u32 fix; 58 u32 fix;
59}; 59};
60 60
61static struct broken_edid brokendb[] = { 61static const struct broken_edid brokendb[] = {
62 /* DEC FR-PCXAV-YZ */ 62 /* DEC FR-PCXAV-YZ */
63 { 63 {
64 .manufacturer = "DEC", 64 .manufacturer = "DEC",
diff --git a/drivers/video/ffb.c b/drivers/video/ffb.c
index 2a0e8210d398..949141bd44d4 100644
--- a/drivers/video/ffb.c
+++ b/drivers/video/ffb.c
@@ -968,6 +968,8 @@ static int ffb_init_one(struct of_device *op)
968 968
969 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 969 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) {
970 printk(KERN_ERR "ffb: Could not allocate color map.\n"); 970 printk(KERN_ERR "ffb: Could not allocate color map.\n");
971 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc));
972 of_iounmap(all->par.dac, sizeof(struct ffb_dac));
971 kfree(all); 973 kfree(all);
972 return -ENOMEM; 974 return -ENOMEM;
973 } 975 }
@@ -978,6 +980,8 @@ static int ffb_init_one(struct of_device *op)
978 if (err < 0) { 980 if (err < 0) {
979 printk(KERN_ERR "ffb: Could not register framebuffer.\n"); 981 printk(KERN_ERR "ffb: Could not register framebuffer.\n");
980 fb_dealloc_cmap(&all->info.cmap); 982 fb_dealloc_cmap(&all->info.cmap);
983 of_iounmap(all->par.fbc, sizeof(struct ffb_fbc));
984 of_iounmap(all->par.dac, sizeof(struct ffb_dac));
981 kfree(all); 985 kfree(all);
982 return err; 986 return err;
983 } 987 }
diff --git a/drivers/video/fm2fb.c b/drivers/video/fm2fb.c
index 998374cfae6d..70ff55b14596 100644
--- a/drivers/video/fm2fb.c
+++ b/drivers/video/fm2fb.c
@@ -283,6 +283,7 @@ static int __devinit fm2fb_probe(struct zorro_dev *z,
283 283
284 if (register_framebuffer(info) < 0) { 284 if (register_framebuffer(info) < 0) {
285 fb_dealloc_cmap(&info->cmap); 285 fb_dealloc_cmap(&info->cmap);
286 iounmap(info->screen_base);
286 framebuffer_release(info); 287 framebuffer_release(info);
287 zorro_release_device(z); 288 zorro_release_device(z);
288 return -EINVAL; 289 return -EINVAL;
diff --git a/drivers/video/geode/Kconfig b/drivers/video/geode/Kconfig
index 4e173ef20a7d..a814b6c2605c 100644
--- a/drivers/video/geode/Kconfig
+++ b/drivers/video/geode/Kconfig
@@ -23,6 +23,26 @@ config FB_GEODE_GX
23 23
24 If unsure, say N. 24 If unsure, say N.
25 25
26config FB_GEODE_GX_SET_FBSIZE
27 bool "Manually specify the Geode GX framebuffer size"
28 depends on FB_GEODE_GX
29 default n
30 ---help---
31 If you want to manually specify the size of your GX framebuffer,
32 say Y here, otherwise say N to dynamically probe it.
33
34 Say N unless you know what you are doing.
35
36config FB_GEODE_GX_FBSIZE
37 hex "Size of the GX framebuffer, in bytes"
38 depends on FB_GEODE_GX_SET_FBSIZE
39 default "0x1600000"
40 ---help---
41 Specify the size of the GX framebuffer. Normally, you will
42 want this to be MB aligned. Common values are 0x80000 (8MB)
43 and 0x1600000 (16MB). Don't change this unless you know what
44 you are doing
45
26config FB_GEODE_GX1 46config FB_GEODE_GX1
27 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)" 47 tristate "AMD Geode GX1 framebuffer support (EXPERIMENTAL)"
28 depends on FB && FB_GEODE && EXPERIMENTAL 48 depends on FB && FB_GEODE && EXPERIMENTAL
diff --git a/drivers/video/geode/display_gx.c b/drivers/video/geode/display_gx.c
index 825c3405f5c2..0f16e4bffc6c 100644
--- a/drivers/video/geode/display_gx.c
+++ b/drivers/video/geode/display_gx.c
@@ -21,11 +21,27 @@
21#include "geodefb.h" 21#include "geodefb.h"
22#include "display_gx.h" 22#include "display_gx.h"
23 23
24int gx_frame_buffer_size(void) 24#ifdef CONFIG_FB_GEODE_GX_SET_FBSIZE
25unsigned int gx_frame_buffer_size(void)
25{ 26{
26 /* Assuming 16 MiB. */ 27 return CONFIG_FB_GEODE_GX_FBSIZE;
27 return 16*1024*1024;
28} 28}
29#else
30unsigned int gx_frame_buffer_size(void)
31{
32 unsigned int val;
33
34 /* FB size is reported by a virtual register */
35 /* Virtual register class = 0x02 */
36 /* VG_MEM_SIZE(512Kb units) = 0x00 */
37
38 outw(0xFC53, 0xAC1C);
39 outw(0x0200, 0xAC1C);
40
41 val = (unsigned int)(inw(0xAC1E)) & 0xFFl;
42 return (val << 19);
43}
44#endif
29 45
30int gx_line_delta(int xres, int bpp) 46int gx_line_delta(int xres, int bpp)
31{ 47{
@@ -81,6 +97,7 @@ static void gx_set_mode(struct fb_info *info)
81 writel(((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2, 97 writel(((info->var.xres * info->var.bits_per_pixel/8) >> 3) + 2,
82 par->dc_regs + DC_LINE_SIZE); 98 par->dc_regs + DC_LINE_SIZE);
83 99
100
84 /* Enable graphics and video data and unmask address lines. */ 101 /* Enable graphics and video data and unmask address lines. */
85 dcfg |= DC_DCFG_GDEN | DC_DCFG_VDEN | DC_DCFG_A20M | DC_DCFG_A18M; 102 dcfg |= DC_DCFG_GDEN | DC_DCFG_VDEN | DC_DCFG_A20M | DC_DCFG_A18M;
86 103
diff --git a/drivers/video/geode/display_gx.h b/drivers/video/geode/display_gx.h
index 86c623361305..0af33f329e88 100644
--- a/drivers/video/geode/display_gx.h
+++ b/drivers/video/geode/display_gx.h
@@ -11,11 +11,15 @@
11#ifndef __DISPLAY_GX_H__ 11#ifndef __DISPLAY_GX_H__
12#define __DISPLAY_GX_H__ 12#define __DISPLAY_GX_H__
13 13
14int gx_frame_buffer_size(void); 14unsigned int gx_frame_buffer_size(void);
15int gx_line_delta(int xres, int bpp); 15int gx_line_delta(int xres, int bpp);
16 16
17extern struct geode_dc_ops gx_dc_ops; 17extern struct geode_dc_ops gx_dc_ops;
18 18
19/* MSR that tells us if a TFT or CRT is attached */
20#define GLD_MSR_CONFIG 0xC0002001
21#define GLD_MSR_CONFIG_DM_FP 0x40
22
19/* Display controller registers */ 23/* Display controller registers */
20 24
21#define DC_UNLOCK 0x00 25#define DC_UNLOCK 0x00
@@ -93,4 +97,5 @@ extern struct geode_dc_ops gx_dc_ops;
93#define DC_PAL_ADDRESS 0x70 97#define DC_PAL_ADDRESS 0x70
94#define DC_PAL_DATA 0x74 98#define DC_PAL_DATA 0x74
95 99
100#define DC_GLIU0_MEM_OFFSET 0x84
96#endif /* !__DISPLAY_GX1_H__ */ 101#endif /* !__DISPLAY_GX1_H__ */
diff --git a/drivers/video/geode/gxfb_core.c b/drivers/video/geode/gxfb_core.c
index a454dcb8e215..cf841efa229a 100644
--- a/drivers/video/geode/gxfb_core.c
+++ b/drivers/video/geode/gxfb_core.c
@@ -35,10 +35,10 @@
35#include "display_gx.h" 35#include "display_gx.h"
36#include "video_gx.h" 36#include "video_gx.h"
37 37
38static char mode_option[32] = "640x480-16@60"; 38static char *mode_option;
39 39
40/* Modes relevant to the GX (taken from modedb.c) */ 40/* Modes relevant to the GX (taken from modedb.c) */
41static const struct fb_videomode __initdata gx_modedb[] = { 41static const struct fb_videomode gx_modedb[] __initdata = {
42 /* 640x480-60 VESA */ 42 /* 640x480-60 VESA */
43 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2, 43 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
44 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA }, 44 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
@@ -240,6 +240,12 @@ static int __init gxfb_map_video_memory(struct fb_info *info, struct pci_dev *de
240 if (!info->screen_base) 240 if (!info->screen_base)
241 return -ENOMEM; 241 return -ENOMEM;
242 242
243 /* Set the 16MB aligned base address of the graphics memory region
244 * in the display controller */
245
246 writel(info->fix.smem_start & 0xFF000000,
247 par->dc_regs + DC_GLIU0_MEM_OFFSET);
248
243 dev_info(&dev->dev, "%d Kibyte of video memory at 0x%lx\n", 249 dev_info(&dev->dev, "%d Kibyte of video memory at 0x%lx\n",
244 info->fix.smem_len / 1024, info->fix.smem_start); 250 info->fix.smem_len / 1024, info->fix.smem_start);
245 251
@@ -302,6 +308,7 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
302 struct geodefb_par *par; 308 struct geodefb_par *par;
303 struct fb_info *info; 309 struct fb_info *info;
304 int ret; 310 int ret;
311 unsigned long val;
305 312
306 info = gxfb_init_fbinfo(&pdev->dev); 313 info = gxfb_init_fbinfo(&pdev->dev);
307 if (!info) 314 if (!info)
@@ -317,6 +324,15 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
317 goto err; 324 goto err;
318 } 325 }
319 326
327 /* Figure out if this is a TFT or CRT part */
328
329 rdmsrl(GLD_MSR_CONFIG, val);
330
331 if ((val & GLD_MSR_CONFIG_DM_FP) == GLD_MSR_CONFIG_DM_FP)
332 par->enable_crt = 0;
333 else
334 par->enable_crt = 1;
335
320 ret = fb_find_mode(&info->var, info, mode_option, 336 ret = fb_find_mode(&info->var, info, mode_option,
321 gx_modedb, ARRAY_SIZE(gx_modedb), NULL, 16); 337 gx_modedb, ARRAY_SIZE(gx_modedb), NULL, 16);
322 if (ret == 0 || ret == 4) { 338 if (ret == 0 || ret == 4) {
@@ -325,7 +341,8 @@ static int __init gxfb_probe(struct pci_dev *pdev, const struct pci_device_id *i
325 goto err; 341 goto err;
326 } 342 }
327 343
328 /* Clear the frame buffer of garbage. */ 344
345 /* Clear the frame buffer of garbage. */
329 memset_io(info->screen_base, 0, info->fix.smem_len); 346 memset_io(info->screen_base, 0, info->fix.smem_len);
330 347
331 gxfb_check_var(&info->var, info); 348 gxfb_check_var(&info->var, info);
@@ -395,11 +412,35 @@ static struct pci_driver gxfb_driver = {
395 .remove = gxfb_remove, 412 .remove = gxfb_remove,
396}; 413};
397 414
415#ifndef MODULE
416static int __init gxfb_setup(char *options)
417{
418
419 char *opt;
420
421 if (!options || !*options)
422 return 0;
423
424 while ((opt = strsep(&options, ",")) != NULL) {
425 if (!*opt)
426 continue;
427
428 mode_option = opt;
429 }
430
431 return 0;
432}
433#endif
434
398static int __init gxfb_init(void) 435static int __init gxfb_init(void)
399{ 436{
400#ifndef MODULE 437#ifndef MODULE
401 if (fb_get_options("gxfb", NULL)) 438 char *option = NULL;
439
440 if (fb_get_options("gxfb", &option))
402 return -ENODEV; 441 return -ENODEV;
442
443 gxfb_setup(option);
403#endif 444#endif
404 return pci_register_driver(&gxfb_driver); 445 return pci_register_driver(&gxfb_driver);
405} 446}
@@ -412,8 +453,8 @@ static void __exit gxfb_cleanup(void)
412module_init(gxfb_init); 453module_init(gxfb_init);
413module_exit(gxfb_cleanup); 454module_exit(gxfb_cleanup);
414 455
415module_param_string(mode, mode_option, sizeof(mode_option), 0444); 456module_param(mode_option, charp, 0);
416MODULE_PARM_DESC(mode, "video mode (<x>x<y>[-<bpp>][@<refr>])"); 457MODULE_PARM_DESC(mode_option, "video mode (<x>x<y>[-<bpp>][@<refr>])");
417 458
418MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode GX"); 459MODULE_DESCRIPTION("Framebuffer driver for the AMD Geode GX");
419MODULE_LICENSE("GPL"); 460MODULE_LICENSE("GPL");
diff --git a/drivers/video/geode/video_gx.c b/drivers/video/geode/video_gx.c
index 2b2a7880ea75..7f3f18d06718 100644
--- a/drivers/video/geode/video_gx.c
+++ b/drivers/video/geode/video_gx.c
@@ -175,13 +175,88 @@ static void gx_set_dclk_frequency(struct fb_info *info)
175 } while (timeout-- && !(dotpll & MSR_GLCP_DOTPLL_LOCK)); 175 } while (timeout-- && !(dotpll & MSR_GLCP_DOTPLL_LOCK));
176} 176}
177 177
178static void
179gx_configure_tft(struct fb_info *info)
180{
181 struct geodefb_par *par = info->par;
182 unsigned long val;
183 unsigned long fp;
184
185 /* Set up the DF pad select MSR */
186
187 rdmsrl(GX_VP_MSR_PAD_SELECT, val);
188 val &= ~GX_VP_PAD_SELECT_MASK;
189 val |= GX_VP_PAD_SELECT_TFT;
190 wrmsrl(GX_VP_MSR_PAD_SELECT, val);
191
192 /* Turn off the panel */
193
194 fp = readl(par->vid_regs + GX_FP_PM);
195 fp &= ~GX_FP_PM_P;
196 writel(fp, par->vid_regs + GX_FP_PM);
197
198 /* Set timing 1 */
199
200 fp = readl(par->vid_regs + GX_FP_PT1);
201 fp &= GX_FP_PT1_VSIZE_MASK;
202 fp |= info->var.yres << GX_FP_PT1_VSIZE_SHIFT;
203 writel(fp, par->vid_regs + GX_FP_PT1);
204
205 /* Timing 2 */
206 /* Set bits that are always on for TFT */
207
208 fp = 0x0F100000;
209
210 /* Add sync polarity */
211
212 if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
213 fp |= GX_FP_PT2_VSP;
214
215 if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
216 fp |= GX_FP_PT2_HSP;
217
218 writel(fp, par->vid_regs + GX_FP_PT2);
219
220 /* Set the dither control */
221 writel(0x70, par->vid_regs + GX_FP_DFC);
222
223 /* Enable the FP data and power (in case the BIOS didn't) */
224
225 fp = readl(par->vid_regs + GX_DCFG);
226 fp |= GX_DCFG_FP_PWR_EN | GX_DCFG_FP_DATA_EN;
227 writel(fp, par->vid_regs + GX_DCFG);
228
229 /* Unblank the panel */
230
231 fp = readl(par->vid_regs + GX_FP_PM);
232 fp |= GX_FP_PM_P;
233 writel(fp, par->vid_regs + GX_FP_PM);
234}
235
178static void gx_configure_display(struct fb_info *info) 236static void gx_configure_display(struct fb_info *info)
179{ 237{
180 struct geodefb_par *par = info->par; 238 struct geodefb_par *par = info->par;
181 u32 dcfg, fp_pm; 239 u32 dcfg, misc;
240
241 /* Set up the MISC register */
242
243 misc = readl(par->vid_regs + GX_MISC);
244
245 /* Power up the DAC */
246 misc &= ~(GX_MISC_A_PWRDN | GX_MISC_DAC_PWRDN);
247
248 /* Disable gamma correction */
249 misc |= GX_MISC_GAM_EN;
250
251 writel(misc, par->vid_regs + GX_MISC);
182 252
253 /* Write the display configuration */
183 dcfg = readl(par->vid_regs + GX_DCFG); 254 dcfg = readl(par->vid_regs + GX_DCFG);
184 255
256 /* Disable hsync and vsync */
257 dcfg &= ~(GX_DCFG_VSYNC_EN | GX_DCFG_HSYNC_EN);
258 writel(dcfg, par->vid_regs + GX_DCFG);
259
185 /* Clear bits from existing mode. */ 260 /* Clear bits from existing mode. */
186 dcfg &= ~(GX_DCFG_CRT_SYNC_SKW_MASK 261 dcfg &= ~(GX_DCFG_CRT_SYNC_SKW_MASK
187 | GX_DCFG_CRT_HSYNC_POL | GX_DCFG_CRT_VSYNC_POL 262 | GX_DCFG_CRT_HSYNC_POL | GX_DCFG_CRT_VSYNC_POL
@@ -199,12 +274,19 @@ static void gx_configure_display(struct fb_info *info)
199 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) 274 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
200 dcfg |= GX_DCFG_CRT_VSYNC_POL; 275 dcfg |= GX_DCFG_CRT_VSYNC_POL;
201 276
277 /* Enable the display logic */
278 /* Set up the DACS to blank normally */
279
280 dcfg |= GX_DCFG_CRT_EN | GX_DCFG_DAC_BL_EN;
281
282 /* Enable the external DAC VREF? */
283
202 writel(dcfg, par->vid_regs + GX_DCFG); 284 writel(dcfg, par->vid_regs + GX_DCFG);
203 285
204 /* Power on flat panel. */ 286 /* Set up the flat panel (if it is enabled) */
205 fp_pm = readl(par->vid_regs + GX_FP_PM); 287
206 fp_pm |= GX_FP_PM_P; 288 if (par->enable_crt == 0)
207 writel(fp_pm, par->vid_regs + GX_FP_PM); 289 gx_configure_tft(info);
208} 290}
209 291
210static int gx_blank_display(struct fb_info *info, int blank_mode) 292static int gx_blank_display(struct fb_info *info, int blank_mode)
@@ -245,12 +327,15 @@ static int gx_blank_display(struct fb_info *info, int blank_mode)
245 writel(dcfg, par->vid_regs + GX_DCFG); 327 writel(dcfg, par->vid_regs + GX_DCFG);
246 328
247 /* Power on/off flat panel. */ 329 /* Power on/off flat panel. */
248 fp_pm = readl(par->vid_regs + GX_FP_PM); 330
249 if (blank_mode == FB_BLANK_POWERDOWN) 331 if (par->enable_crt == 0) {
250 fp_pm &= ~GX_FP_PM_P; 332 fp_pm = readl(par->vid_regs + GX_FP_PM);
251 else 333 if (blank_mode == FB_BLANK_POWERDOWN)
252 fp_pm |= GX_FP_PM_P; 334 fp_pm &= ~GX_FP_PM_P;
253 writel(fp_pm, par->vid_regs + GX_FP_PM); 335 else
336 fp_pm |= GX_FP_PM_P;
337 writel(fp_pm, par->vid_regs + GX_FP_PM);
338 }
254 339
255 return 0; 340 return 0;
256} 341}
diff --git a/drivers/video/geode/video_gx.h b/drivers/video/geode/video_gx.h
index 2d9211f3ed84..ce28d8f382dc 100644
--- a/drivers/video/geode/video_gx.h
+++ b/drivers/video/geode/video_gx.h
@@ -13,6 +13,11 @@
13 13
14extern struct geode_vid_ops gx_vid_ops; 14extern struct geode_vid_ops gx_vid_ops;
15 15
16/* GX Flatpanel control MSR */
17#define GX_VP_MSR_PAD_SELECT 0xC0002011
18#define GX_VP_PAD_SELECT_MASK 0x3FFFFFFF
19#define GX_VP_PAD_SELECT_TFT 0x1FFFFFFF
20
16/* Geode GX video processor registers */ 21/* Geode GX video processor registers */
17 22
18#define GX_DCFG 0x0008 23#define GX_DCFG 0x0008
@@ -20,6 +25,8 @@ extern struct geode_vid_ops gx_vid_ops;
20# define GX_DCFG_HSYNC_EN 0x00000002 25# define GX_DCFG_HSYNC_EN 0x00000002
21# define GX_DCFG_VSYNC_EN 0x00000004 26# define GX_DCFG_VSYNC_EN 0x00000004
22# define GX_DCFG_DAC_BL_EN 0x00000008 27# define GX_DCFG_DAC_BL_EN 0x00000008
28# define GX_DCFG_FP_PWR_EN 0x00000040
29# define GX_DCFG_FP_DATA_EN 0x00000080
23# define GX_DCFG_CRT_HSYNC_POL 0x00000100 30# define GX_DCFG_CRT_HSYNC_POL 0x00000100
24# define GX_DCFG_CRT_VSYNC_POL 0x00000200 31# define GX_DCFG_CRT_VSYNC_POL 0x00000200
25# define GX_DCFG_CRT_SYNC_SKW_MASK 0x0001C000 32# define GX_DCFG_CRT_SYNC_SKW_MASK 0x0001C000
@@ -28,10 +35,28 @@ extern struct geode_vid_ops gx_vid_ops;
28# define GX_DCFG_GV_GAM 0x00200000 35# define GX_DCFG_GV_GAM 0x00200000
29# define GX_DCFG_DAC_VREF 0x04000000 36# define GX_DCFG_DAC_VREF 0x04000000
30 37
38/* Geode GX MISC video configuration */
39
40#define GX_MISC 0x50
41#define GX_MISC_GAM_EN 0x00000001
42#define GX_MISC_DAC_PWRDN 0x00000400
43#define GX_MISC_A_PWRDN 0x00000800
44
31/* Geode GX flat panel display control registers */ 45/* Geode GX flat panel display control registers */
46
47#define GX_FP_PT1 0x0400
48#define GX_FP_PT1_VSIZE_MASK 0x7FF0000
49#define GX_FP_PT1_VSIZE_SHIFT 16
50
51#define GX_FP_PT2 0x408
52#define GX_FP_PT2_VSP (1 << 23)
53#define GX_FP_PT2_HSP (1 << 22)
54
32#define GX_FP_PM 0x410 55#define GX_FP_PM 0x410
33# define GX_FP_PM_P 0x01000000 56# define GX_FP_PM_P 0x01000000
34 57
58#define GX_FP_DFC 0x418
59
35/* Geode GX clock control MSRs */ 60/* Geode GX clock control MSRs */
36 61
37#define MSR_GLCP_SYS_RSTPLL 0x4c000014 62#define MSR_GLCP_SYS_RSTPLL 0x4c000014
diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
new file mode 100644
index 000000000000..3adf6ab0768f
--- /dev/null
+++ b/drivers/video/gxt4500.c
@@ -0,0 +1,741 @@
1/*
2 * Frame buffer device for IBM GXT4500P display adaptor
3 *
4 * Copyright (C) 2006 Paul Mackerras, IBM Corp. <paulus@samba.org>
5 */
6
7#include <linux/kernel.h>
8#include <linux/module.h>
9#include <linux/fb.h>
10#include <linux/console.h>
11#include <linux/pci.h>
12#include <linux/pci_ids.h>
13#include <linux/delay.h>
14
15#define PCI_DEVICE_ID_IBM_GXT4500P 0x21c
16
17/* GXT4500P registers */
18
19/* Registers in PCI config space */
20#define CFG_ENDIAN0 0x40
21
22/* Misc control/status registers */
23#define STATUS 0x1000
24#define CTRL_REG0 0x1004
25#define CR0_HALT_DMA 0x4
26#define CR0_RASTER_RESET 0x8
27#define CR0_GEOM_RESET 0x10
28#define CR0_MEM_CTRLER_RESET 0x20
29
30/* Framebuffer control registers */
31#define FB_AB_CTRL 0x1100
32#define FB_CD_CTRL 0x1104
33#define FB_WID_CTRL 0x1108
34#define FB_Z_CTRL 0x110c
35#define FB_VGA_CTRL 0x1110
36#define REFRESH_AB_CTRL 0x1114
37#define REFRESH_CD_CTRL 0x1118
38#define FB_OVL_CTRL 0x111c
39#define FB_CTRL_TYPE 0x80000000
40#define FB_CTRL_WIDTH_MASK 0x007f0000
41#define FB_CTRL_WIDTH_SHIFT 16
42#define FB_CTRL_START_SEG_MASK 0x00003fff
43
44#define REFRESH_START 0x1098
45#define REFRESH_SIZE 0x109c
46
47/* "Direct" framebuffer access registers */
48#define DFA_FB_A 0x11e0
49#define DFA_FB_B 0x11e4
50#define DFA_FB_C 0x11e8
51#define DFA_FB_D 0x11ec
52#define DFA_FB_ENABLE 0x80000000
53#define DFA_FB_BASE_MASK 0x03f00000
54#define DFA_FB_STRIDE_1k 0x00000000
55#define DFA_FB_STRIDE_2k 0x00000010
56#define DFA_FB_STRIDE_4k 0x00000020
57#define DFA_PIX_8BIT 0x00000000
58#define DFA_PIX_16BIT_565 0x00000001
59#define DFA_PIX_16BIT_1555 0x00000002
60#define DFA_PIX_24BIT 0x00000004
61#define DFA_PIX_32BIT 0x00000005
62
63/* maps DFA_PIX_* to pixel size in bytes */
64static const unsigned char pixsize[] = {
65 1, 2, 2, 2, 4, 4
66};
67
68/* Display timing generator registers */
69#define DTG_CONTROL 0x1900
70#define DTG_CTL_SCREEN_REFRESH 2
71#define DTG_CTL_ENABLE 1
72#define DTG_HORIZ_EXTENT 0x1904
73#define DTG_HORIZ_DISPLAY 0x1908
74#define DTG_HSYNC_START 0x190c
75#define DTG_HSYNC_END 0x1910
76#define DTG_HSYNC_END_COMP 0x1914
77#define DTG_VERT_EXTENT 0x1918
78#define DTG_VERT_DISPLAY 0x191c
79#define DTG_VSYNC_START 0x1920
80#define DTG_VSYNC_END 0x1924
81#define DTG_VERT_SHORT 0x1928
82
83/* PLL/RAMDAC registers */
84#define DISP_CTL 0x402c
85#define DISP_CTL_OFF 2
86#define SYNC_CTL 0x4034
87#define SYNC_CTL_SYNC_ON_RGB 1
88#define SYNC_CTL_SYNC_OFF 2
89#define SYNC_CTL_HSYNC_INV 8
90#define SYNC_CTL_VSYNC_INV 0x10
91#define SYNC_CTL_HSYNC_OFF 0x20
92#define SYNC_CTL_VSYNC_OFF 0x40
93
94#define PLL_M 0x4040
95#define PLL_N 0x4044
96#define PLL_POSTDIV 0x4048
97
98/* Hardware cursor */
99#define CURSOR_X 0x4078
100#define CURSOR_Y 0x407c
101#define CURSOR_HOTSPOT 0x4080
102#define CURSOR_MODE 0x4084
103#define CURSOR_MODE_OFF 0
104#define CURSOR_MODE_4BPP 1
105#define CURSOR_PIXMAP 0x5000
106#define CURSOR_CMAP 0x7400
107
108/* Window attribute table */
109#define WAT_FMT 0x4100
110#define WAT_FMT_24BIT 0
111#define WAT_FMT_16BIT_565 1
112#define WAT_FMT_16BIT_1555 2
113#define WAT_FMT_32BIT 3 /* 0 vs. 3 is a guess */
114#define WAT_FMT_8BIT_332 9
115#define WAT_FMT_8BIT 0xa
116#define WAT_FMT_NO_CMAP 4 /* ORd in to other values */
117#define WAT_CMAP_OFFSET 0x4104 /* 4-bit value gets << 6 */
118#define WAT_CTRL 0x4108
119#define WAT_CTRL_SEL_B 1 /* select B buffer if 1 */
120#define WAT_CTRL_NO_INC 2
121#define WAT_GAMMA_CTRL 0x410c
122#define WAT_GAMMA_DISABLE 1 /* disables gamma cmap */
123#define WAT_OVL_CTRL 0x430c /* controls overlay */
124
125/* Indexed by DFA_PIX_* values */
126static const unsigned char watfmt[] = {
127 WAT_FMT_8BIT, WAT_FMT_16BIT_565, WAT_FMT_16BIT_1555, 0,
128 WAT_FMT_24BIT, WAT_FMT_32BIT
129};
130
131/* Colormap array; 1k entries of 4 bytes each */
132#define CMAP 0x6000
133
134#define readreg(par, reg) readl((par)->regs + (reg))
135#define writereg(par, reg, val) writel((val), (par)->regs + (reg))
136
137struct gxt4500_par {
138 void __iomem *regs;
139
140 int pixfmt; /* pixel format, see DFA_PIX_* values */
141
142 /* PLL parameters */
143 int pll_m; /* ref clock divisor */
144 int pll_n; /* VCO divisor */
145 int pll_pd1; /* first post-divisor */
146 int pll_pd2; /* second post-divisor */
147
148 u32 pseudo_palette[16]; /* used in color blits */
149};
150
151/* mode requested by user */
152static char *mode_option;
153
154/* default mode: 1280x1024 @ 60 Hz, 8 bpp */
155static const struct fb_videomode defaultmode __devinitdata = {
156 .refresh = 60,
157 .xres = 1280,
158 .yres = 1024,
159 .pixclock = 9295,
160 .left_margin = 248,
161 .right_margin = 48,
162 .upper_margin = 38,
163 .lower_margin = 1,
164 .hsync_len = 112,
165 .vsync_len = 3,
166 .vmode = FB_VMODE_NONINTERLACED
167};
168
169/*
170 * The refclk and VCO dividers appear to use a linear feedback shift
171 * register, which gets reloaded when it reaches a terminal value, at
172 * which point the divider output is toggled. Thus one can obtain
173 * whatever divisor is required by putting the appropriate value into
174 * the reload register. For a divisor of N, one puts the value from
175 * the LFSR sequence that comes N-1 places before the terminal value
176 * into the reload register.
177 */
178
179static const unsigned char mdivtab[] = {
180/* 1 */ 0x3f, 0x00, 0x20, 0x10, 0x28, 0x14, 0x2a, 0x15, 0x0a,
181/* 10 */ 0x25, 0x32, 0x19, 0x0c, 0x26, 0x13, 0x09, 0x04, 0x22, 0x11,
182/* 20 */ 0x08, 0x24, 0x12, 0x29, 0x34, 0x1a, 0x2d, 0x36, 0x1b, 0x0d,
183/* 30 */ 0x06, 0x23, 0x31, 0x38, 0x1c, 0x2e, 0x17, 0x0b, 0x05, 0x02,
184/* 40 */ 0x21, 0x30, 0x18, 0x2c, 0x16, 0x2b, 0x35, 0x3a, 0x1d, 0x0e,
185/* 50 */ 0x27, 0x33, 0x39, 0x3c, 0x1e, 0x2f, 0x37, 0x3b, 0x3d, 0x3e,
186/* 60 */ 0x1f, 0x0f, 0x07, 0x03, 0x01,
187};
188
189static const unsigned char ndivtab[] = {
190/* 2 */ 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0x78, 0xbc, 0x5e,
191/* 10 */ 0x2f, 0x17, 0x0b, 0x85, 0xc2, 0xe1, 0x70, 0x38, 0x9c, 0x4e,
192/* 20 */ 0xa7, 0xd3, 0xe9, 0xf4, 0xfa, 0xfd, 0xfe, 0x7f, 0xbf, 0xdf,
193/* 30 */ 0xef, 0x77, 0x3b, 0x1d, 0x8e, 0xc7, 0xe3, 0x71, 0xb8, 0xdc,
194/* 40 */ 0x6e, 0xb7, 0x5b, 0x2d, 0x16, 0x8b, 0xc5, 0xe2, 0xf1, 0xf8,
195/* 50 */ 0xfc, 0x7e, 0x3f, 0x9f, 0xcf, 0x67, 0xb3, 0xd9, 0x6c, 0xb6,
196/* 60 */ 0xdb, 0x6d, 0x36, 0x9b, 0x4d, 0x26, 0x13, 0x89, 0xc4, 0x62,
197/* 70 */ 0xb1, 0xd8, 0xec, 0xf6, 0xfb, 0x7d, 0xbe, 0x5f, 0xaf, 0x57,
198/* 80 */ 0x2b, 0x95, 0x4a, 0x25, 0x92, 0x49, 0xa4, 0x52, 0x29, 0x94,
199/* 90 */ 0xca, 0x65, 0xb2, 0x59, 0x2c, 0x96, 0xcb, 0xe5, 0xf2, 0x79,
200/* 100 */ 0x3c, 0x1e, 0x0f, 0x07, 0x83, 0x41, 0x20, 0x90, 0x48, 0x24,
201/* 110 */ 0x12, 0x09, 0x84, 0x42, 0xa1, 0x50, 0x28, 0x14, 0x8a, 0x45,
202/* 120 */ 0xa2, 0xd1, 0xe8, 0x74, 0xba, 0xdd, 0xee, 0xf7, 0x7b, 0x3d,
203/* 130 */ 0x9e, 0x4f, 0x27, 0x93, 0xc9, 0xe4, 0x72, 0x39, 0x1c, 0x0e,
204/* 140 */ 0x87, 0xc3, 0x61, 0x30, 0x18, 0x8c, 0xc6, 0x63, 0x31, 0x98,
205/* 150 */ 0xcc, 0xe6, 0x73, 0xb9, 0x5c, 0x2e, 0x97, 0x4b, 0xa5, 0xd2,
206/* 160 */ 0x69, 0xb4, 0xda, 0xed, 0x76, 0xbb, 0x5d, 0xae, 0xd7, 0x6b,
207/* 170 */ 0xb5, 0x5a, 0xad, 0x56, 0xab, 0xd5, 0x6a, 0x35, 0x1a, 0x8d,
208/* 180 */ 0x46, 0x23, 0x11, 0x88, 0x44, 0x22, 0x91, 0xc8, 0x64, 0x32,
209/* 190 */ 0x19, 0x0c, 0x86, 0x43, 0x21, 0x10, 0x08, 0x04, 0x02, 0x81,
210/* 200 */ 0x40, 0xa0, 0xd0, 0x68, 0x34, 0x9a, 0xcd, 0x66, 0x33, 0x99,
211/* 210 */ 0x4c, 0xa6, 0x53, 0xa9, 0xd4, 0xea, 0x75, 0x3a, 0x9d, 0xce,
212/* 220 */ 0xe7, 0xf3, 0xf9, 0x7c, 0x3e, 0x1f, 0x8f, 0x47, 0xa3, 0x51,
213/* 230 */ 0xa8, 0x54, 0xaa, 0x55, 0x2a, 0x15, 0x0a, 0x05, 0x82, 0xc1,
214/* 240 */ 0x60, 0xb0, 0x58, 0xac, 0xd6, 0xeb, 0xf5, 0x7a, 0xbd, 0xde,
215/* 250 */ 0x6f, 0x37, 0x1b, 0x0d, 0x06, 0x03, 0x01,
216};
217
218#define REF_PERIOD_PS 9259 /* period of reference clock in ps */
219
220static int calc_pll(int period_ps, struct gxt4500_par *par)
221{
222 int m, n, pdiv1, pdiv2, postdiv;
223 int pll_period, best_error, t;
224
225 /* only deal with range 1MHz - 400MHz */
226 if (period_ps < 2500 || period_ps > 1000000)
227 return -1;
228
229 best_error = 1000000;
230 for (pdiv1 = 1; pdiv1 <= 8; ++pdiv1) {
231 for (pdiv2 = 1; pdiv2 <= pdiv1; ++pdiv2) {
232 postdiv = pdiv1 * pdiv2;
233 pll_period = (period_ps + postdiv - 1) / postdiv;
234 /* keep pll in range 500..1250 MHz */
235 if (pll_period < 800 || pll_period > 2000)
236 continue;
237 for (m = 3; m <= 40; ++m) {
238 n = REF_PERIOD_PS * m * postdiv / period_ps;
239 if (n < 5 || n > 256)
240 continue;
241 t = REF_PERIOD_PS * m * postdiv / n;
242 t -= period_ps;
243 if (t >= 0 && t < best_error) {
244 par->pll_m = m;
245 par->pll_n = n;
246 par->pll_pd1 = pdiv1;
247 par->pll_pd2 = pdiv2;
248 best_error = t;
249 }
250 }
251 }
252 }
253 if (best_error == 1000000)
254 return -1;
255 return 0;
256}
257
258static int calc_pixclock(struct gxt4500_par *par)
259{
260 return REF_PERIOD_PS * par->pll_m * par->pll_pd1 * par->pll_pd2
261 / par->pll_n;
262}
263
264static int gxt4500_var_to_par(struct fb_var_screeninfo *var,
265 struct gxt4500_par *par)
266{
267 if (var->xres + var->xoffset > var->xres_virtual ||
268 var->yres + var->yoffset > var->yres_virtual ||
269 var->xres_virtual > 4096)
270 return -EINVAL;
271 if ((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
272 return -EINVAL;
273
274 if (calc_pll(var->pixclock, par) < 0)
275 return -EINVAL;
276
277 switch (var->bits_per_pixel) {
278 case 32:
279 if (var->transp.length)
280 par->pixfmt = DFA_PIX_32BIT;
281 else
282 par->pixfmt = DFA_PIX_24BIT;
283 break;
284 case 24:
285 par->pixfmt = DFA_PIX_24BIT;
286 break;
287 case 16:
288 if (var->green.length == 5)
289 par->pixfmt = DFA_PIX_16BIT_1555;
290 else
291 par->pixfmt = DFA_PIX_16BIT_565;
292 break;
293 case 8:
294 par->pixfmt = DFA_PIX_8BIT;
295 break;
296 default:
297 return -EINVAL;
298 }
299
300 return 0;
301}
302
303static const struct fb_bitfield eightbits = {0, 8};
304static const struct fb_bitfield nobits = {0, 0};
305
306static void gxt4500_unpack_pixfmt(struct fb_var_screeninfo *var,
307 int pixfmt)
308{
309 var->bits_per_pixel = pixsize[pixfmt] * 8;
310 var->red = eightbits;
311 var->green = eightbits;
312 var->blue = eightbits;
313 var->transp = nobits;
314
315 switch (pixfmt) {
316 case DFA_PIX_16BIT_565:
317 var->red.length = 5;
318 var->green.length = 6;
319 var->blue.length = 5;
320 break;
321 case DFA_PIX_16BIT_1555:
322 var->red.length = 5;
323 var->green.length = 5;
324 var->blue.length = 5;
325 var->transp.length = 1;
326 break;
327 case DFA_PIX_32BIT:
328 var->transp.length = 8;
329 break;
330 }
331 if (pixfmt != DFA_PIX_8BIT) {
332 var->green.offset = var->red.length;
333 var->blue.offset = var->green.offset + var->green.length;
334 if (var->transp.length)
335 var->transp.offset =
336 var->blue.offset + var->blue.length;
337 }
338}
339
340static int gxt4500_check_var(struct fb_var_screeninfo *var,
341 struct fb_info *info)
342{
343 struct gxt4500_par par;
344 int err;
345
346 par = *(struct gxt4500_par *)info->par;
347 err = gxt4500_var_to_par(var, &par);
348 if (!err) {
349 var->pixclock = calc_pixclock(&par);
350 gxt4500_unpack_pixfmt(var, par.pixfmt);
351 }
352 return err;
353}
354
355static int gxt4500_set_par(struct fb_info *info)
356{
357 struct gxt4500_par *par = info->par;
358 struct fb_var_screeninfo *var = &info->var;
359 int err;
360 u32 ctrlreg;
361 unsigned int dfa_ctl, pixfmt, stride;
362 unsigned int wid_tiles, i;
363 unsigned int prefetch_pix, htot;
364 struct gxt4500_par save_par;
365
366 save_par = *par;
367 err = gxt4500_var_to_par(var, par);
368 if (err) {
369 *par = save_par;
370 return err;
371 }
372
373 /* turn off DTG for now */
374 ctrlreg = readreg(par, DTG_CONTROL);
375 ctrlreg &= ~(DTG_CTL_ENABLE | DTG_CTL_SCREEN_REFRESH);
376 writereg(par, DTG_CONTROL, ctrlreg);
377
378 /* set PLL registers */
379 writereg(par, PLL_M, mdivtab[par->pll_m - 1]);
380 writereg(par, PLL_N, ndivtab[par->pll_n - 2]);
381 writereg(par, PLL_POSTDIV,
382 ((8 - par->pll_pd1) << 3) | (8 - par->pll_pd2));
383 msleep(20);
384
385 /* turn off hardware cursor */
386 writereg(par, CURSOR_MODE, CURSOR_MODE_OFF);
387
388 /* reset raster engine */
389 writereg(par, CTRL_REG0, CR0_RASTER_RESET | (CR0_RASTER_RESET << 16));
390 udelay(10);
391 writereg(par, CTRL_REG0, CR0_RASTER_RESET << 16);
392
393 /* set display timing generator registers */
394 htot = var->xres + var->left_margin + var->right_margin +
395 var->hsync_len;
396 writereg(par, DTG_HORIZ_EXTENT, htot - 1);
397 writereg(par, DTG_HORIZ_DISPLAY, var->xres - 1);
398 writereg(par, DTG_HSYNC_START, var->xres + var->right_margin - 1);
399 writereg(par, DTG_HSYNC_END,
400 var->xres + var->right_margin + var->hsync_len - 1);
401 writereg(par, DTG_HSYNC_END_COMP,
402 var->xres + var->right_margin + var->hsync_len - 1);
403 writereg(par, DTG_VERT_EXTENT,
404 var->yres + var->upper_margin + var->lower_margin +
405 var->vsync_len - 1);
406 writereg(par, DTG_VERT_DISPLAY, var->yres - 1);
407 writereg(par, DTG_VSYNC_START, var->yres + var->lower_margin - 1);
408 writereg(par, DTG_VSYNC_END,
409 var->yres + var->lower_margin + var->vsync_len - 1);
410 prefetch_pix = 3300000 / var->pixclock;
411 if (prefetch_pix >= htot)
412 prefetch_pix = htot - 1;
413 writereg(par, DTG_VERT_SHORT, htot - prefetch_pix - 1);
414 ctrlreg |= DTG_CTL_ENABLE | DTG_CTL_SCREEN_REFRESH;
415 writereg(par, DTG_CONTROL, ctrlreg);
416
417 /* calculate stride in DFA aperture */
418 if (var->xres_virtual > 2048) {
419 stride = 4096;
420 dfa_ctl = DFA_FB_STRIDE_4k;
421 } else if (var->xres_virtual > 1024) {
422 stride = 2048;
423 dfa_ctl = DFA_FB_STRIDE_2k;
424 } else {
425 stride = 1024;
426 dfa_ctl = DFA_FB_STRIDE_1k;
427 }
428
429 /* Set up framebuffer definition */
430 wid_tiles = (var->xres_virtual + 63) >> 6;
431
432 /* XXX add proper FB allocation here someday */
433 writereg(par, FB_AB_CTRL, FB_CTRL_TYPE | (wid_tiles << 16) | 0);
434 writereg(par, REFRESH_AB_CTRL, FB_CTRL_TYPE | (wid_tiles << 16) | 0);
435 writereg(par, FB_CD_CTRL, FB_CTRL_TYPE | (wid_tiles << 16) | 0);
436 writereg(par, REFRESH_CD_CTRL, FB_CTRL_TYPE | (wid_tiles << 16) | 0);
437 writereg(par, REFRESH_START, (var->xoffset << 16) | var->yoffset);
438 writereg(par, REFRESH_SIZE, (var->xres << 16) | var->yres);
439
440 /* Set up framebuffer access by CPU */
441
442 pixfmt = par->pixfmt;
443 dfa_ctl |= DFA_FB_ENABLE | pixfmt;
444 writereg(par, DFA_FB_A, dfa_ctl);
445
446 /*
447 * Set up window attribute table.
448 * We set all WAT entries the same so it doesn't matter what the
449 * window ID (WID) plane contains.
450 */
451 for (i = 0; i < 32; ++i) {
452 writereg(par, WAT_FMT + (i << 4), watfmt[pixfmt]);
453 writereg(par, WAT_CMAP_OFFSET + (i << 4), 0);
454 writereg(par, WAT_CTRL + (i << 4), 0);
455 writereg(par, WAT_GAMMA_CTRL + (i << 4), WAT_GAMMA_DISABLE);
456 }
457
458 /* Set sync polarity etc. */
459 ctrlreg = readreg(par, SYNC_CTL) &
460 ~(SYNC_CTL_SYNC_ON_RGB | SYNC_CTL_HSYNC_INV |
461 SYNC_CTL_VSYNC_INV);
462 if (var->sync & FB_SYNC_ON_GREEN)
463 ctrlreg |= SYNC_CTL_SYNC_ON_RGB;
464 if (!(var->sync & FB_SYNC_HOR_HIGH_ACT))
465 ctrlreg |= SYNC_CTL_HSYNC_INV;
466 if (!(var->sync & FB_SYNC_VERT_HIGH_ACT))
467 ctrlreg |= SYNC_CTL_VSYNC_INV;
468 writereg(par, SYNC_CTL, ctrlreg);
469
470 info->fix.line_length = stride * pixsize[pixfmt];
471 info->fix.visual = (pixfmt == DFA_PIX_8BIT)? FB_VISUAL_PSEUDOCOLOR:
472 FB_VISUAL_DIRECTCOLOR;
473
474 return 0;
475}
476
477static int gxt4500_setcolreg(unsigned int reg, unsigned int red,
478 unsigned int green, unsigned int blue,
479 unsigned int transp, struct fb_info *info)
480{
481 u32 cmap_entry;
482 struct gxt4500_par *par = info->par;
483
484 if (reg > 1023)
485 return 1;
486 cmap_entry = ((transp & 0xff00) << 16) | ((blue & 0xff00) << 8) |
487 (green & 0xff00) | (red >> 8);
488 writereg(par, CMAP + reg * 4, cmap_entry);
489
490 if (reg < 16 && par->pixfmt != DFA_PIX_8BIT) {
491 u32 *pal = info->pseudo_palette;
492 u32 val = reg;
493 switch (par->pixfmt) {
494 case DFA_PIX_16BIT_565:
495 val |= (reg << 11) | (reg << 6);
496 break;
497 case DFA_PIX_16BIT_1555:
498 val |= (reg << 10) | (reg << 5);
499 break;
500 case DFA_PIX_32BIT:
501 val |= (reg << 24);
502 /* fall through */
503 case DFA_PIX_24BIT:
504 val |= (reg << 16) | (reg << 8);
505 break;
506 }
507 pal[reg] = val;
508 }
509
510 return 0;
511}
512
513static int gxt4500_pan_display(struct fb_var_screeninfo *var,
514 struct fb_info *info)
515{
516 struct gxt4500_par *par = info->par;
517
518 if (var->xoffset & 7)
519 return -EINVAL;
520 if (var->xoffset + var->xres > var->xres_virtual ||
521 var->yoffset + var->yres > var->yres_virtual)
522 return -EINVAL;
523
524 writereg(par, REFRESH_START, (var->xoffset << 16) | var->yoffset);
525 return 0;
526}
527
528static int gxt4500_blank(int blank, struct fb_info *info)
529{
530 struct gxt4500_par *par = info->par;
531 int ctrl, dctl;
532
533 ctrl = readreg(par, SYNC_CTL);
534 ctrl &= ~(SYNC_CTL_SYNC_OFF | SYNC_CTL_HSYNC_OFF | SYNC_CTL_VSYNC_OFF);
535 dctl = readreg(par, DISP_CTL);
536 dctl |= DISP_CTL_OFF;
537 switch (blank) {
538 case FB_BLANK_UNBLANK:
539 dctl &= ~DISP_CTL_OFF;
540 break;
541 case FB_BLANK_POWERDOWN:
542 ctrl |= SYNC_CTL_SYNC_OFF;
543 break;
544 case FB_BLANK_HSYNC_SUSPEND:
545 ctrl |= SYNC_CTL_HSYNC_OFF;
546 break;
547 case FB_BLANK_VSYNC_SUSPEND:
548 ctrl |= SYNC_CTL_VSYNC_OFF;
549 break;
550 default: ;
551 }
552 writereg(par, SYNC_CTL, ctrl);
553 writereg(par, DISP_CTL, dctl);
554
555 return 0;
556}
557
558static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
559 .id = "IBM GXT4500P",
560 .type = FB_TYPE_PACKED_PIXELS,
561 .visual = FB_VISUAL_PSEUDOCOLOR,
562 .xpanstep = 8,
563 .ypanstep = 1,
564 .mmio_len = 0x20000,
565};
566
567static struct fb_ops gxt4500_ops = {
568 .owner = THIS_MODULE,
569 .fb_check_var = gxt4500_check_var,
570 .fb_set_par = gxt4500_set_par,
571 .fb_setcolreg = gxt4500_setcolreg,
572 .fb_pan_display = gxt4500_pan_display,
573 .fb_blank = gxt4500_blank,
574 .fb_fillrect = cfb_fillrect,
575 .fb_copyarea = cfb_copyarea,
576 .fb_imageblit = cfb_imageblit,
577};
578
579/* PCI functions */
580static int __devinit gxt4500_probe(struct pci_dev *pdev,
581 const struct pci_device_id *ent)
582{
583 int err;
584 unsigned long reg_phys, fb_phys;
585 struct gxt4500_par *par;
586 struct fb_info *info;
587 struct fb_var_screeninfo var;
588
589 err = pci_enable_device(pdev);
590 if (err) {
591 dev_err(&pdev->dev, "gxt4500: cannot enable PCI device: %d\n",
592 err);
593 return err;
594 }
595
596 reg_phys = pci_resource_start(pdev, 0);
597 if (!request_mem_region(reg_phys, pci_resource_len(pdev, 0),
598 "gxt4500 regs")) {
599 dev_err(&pdev->dev, "gxt4500: cannot get registers\n");
600 goto err_nodev;
601 }
602
603 fb_phys = pci_resource_start(pdev, 1);
604 if (!request_mem_region(fb_phys, pci_resource_len(pdev, 1),
605 "gxt4500 FB")) {
606 dev_err(&pdev->dev, "gxt4500: cannot get framebuffer\n");
607 goto err_free_regs;
608 }
609
610 info = framebuffer_alloc(sizeof(struct gxt4500_par), &pdev->dev);
611 if (!info) {
612 dev_err(&pdev->dev, "gxt4500: cannot alloc FB info record");
613 goto err_free_fb;
614 }
615 par = info->par;
616 info->fix = gxt4500_fix;
617 info->pseudo_palette = par->pseudo_palette;
618
619 info->fix.mmio_start = reg_phys;
620 par->regs = ioremap(reg_phys, pci_resource_len(pdev, 0));
621 if (!par->regs) {
622 dev_err(&pdev->dev, "gxt4500: cannot map registers\n");
623 goto err_free_all;
624 }
625
626 info->fix.smem_start = fb_phys;
627 info->fix.smem_len = pci_resource_len(pdev, 1);
628 info->screen_base = ioremap(fb_phys, pci_resource_len(pdev, 1));
629 if (!info->screen_base) {
630 dev_err(&pdev->dev, "gxt4500: cannot map framebuffer\n");
631 goto err_unmap_regs;
632 }
633
634 pci_set_drvdata(pdev, info);
635
636 /* Set byte-swapping for DFA aperture for all pixel sizes */
637 pci_write_config_dword(pdev, CFG_ENDIAN0, 0x333300);
638
639 info->fbops = &gxt4500_ops;
640 info->flags = FBINFO_FLAG_DEFAULT;
641
642 err = fb_alloc_cmap(&info->cmap, 256, 0);
643 if (err) {
644 dev_err(&pdev->dev, "gxt4500: cannot allocate cmap\n");
645 goto err_unmap_all;
646 }
647
648 gxt4500_blank(FB_BLANK_UNBLANK, info);
649
650 if (!fb_find_mode(&var, info, mode_option, NULL, 0, &defaultmode, 8)) {
651 dev_err(&pdev->dev, "gxt4500: cannot find valid video mode\n");
652 goto err_free_cmap;
653 }
654 info->var = var;
655 if (gxt4500_set_par(info)) {
656 printk(KERN_ERR "gxt4500: cannot set video mode\n");
657 goto err_free_cmap;
658 }
659
660 if (register_framebuffer(info) < 0) {
661 dev_err(&pdev->dev, "gxt4500: cannot register framebuffer\n");
662 goto err_free_cmap;
663 }
664 printk(KERN_INFO "fb%d: %s frame buffer device\n",
665 info->node, info->fix.id);
666
667 return 0;
668
669 err_free_cmap:
670 fb_dealloc_cmap(&info->cmap);
671 err_unmap_all:
672 iounmap(info->screen_base);
673 err_unmap_regs:
674 iounmap(par->regs);
675 err_free_all:
676 framebuffer_release(info);
677 err_free_fb:
678 release_mem_region(fb_phys, pci_resource_len(pdev, 1));
679 err_free_regs:
680 release_mem_region(reg_phys, pci_resource_len(pdev, 0));
681 err_nodev:
682 return -ENODEV;
683}
684
685static void __devexit gxt4500_remove(struct pci_dev *pdev)
686{
687 struct fb_info *info = pci_get_drvdata(pdev);
688 struct gxt4500_par *par;
689
690 if (!info)
691 return;
692 par = info->par;
693 unregister_framebuffer(info);
694 fb_dealloc_cmap(&info->cmap);
695 iounmap(par->regs);
696 iounmap(info->screen_base);
697 release_mem_region(pci_resource_start(pdev, 0),
698 pci_resource_len(pdev, 0));
699 release_mem_region(pci_resource_start(pdev, 1),
700 pci_resource_len(pdev, 1));
701 framebuffer_release(info);
702}
703
704/* supported chipsets */
705static const struct pci_device_id gxt4500_pci_tbl[] = {
706 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_GXT4500P,
707 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
708 { 0 }
709};
710
711MODULE_DEVICE_TABLE(pci, gxt4500_pci_tbl);
712
713static struct pci_driver gxt4500_driver = {
714 .name = "gxt4500",
715 .id_table = gxt4500_pci_tbl,
716 .probe = gxt4500_probe,
717 .remove = __devexit_p(gxt4500_remove),
718};
719
720static int __devinit gxt4500_init(void)
721{
722#ifndef MODULE
723 if (fb_get_options("gxt4500", &mode_option))
724 return -ENODEV;
725#endif
726
727 return pci_register_driver(&gxt4500_driver);
728}
729module_init(gxt4500_init);
730
731static void __exit gxt4500_exit(void)
732{
733 pci_unregister_driver(&gxt4500_driver);
734}
735module_exit(gxt4500_exit);
736
737MODULE_AUTHOR("Paul Mackerras <paulus@samba.org>");
738MODULE_DESCRIPTION("FBDev driver for IBM GXT4500P");
739MODULE_LICENSE("GPL");
740module_param(mode_option, charp, 0);
741MODULE_PARM_DESC(mode_option, "Specify resolution as \"<xres>x<yres>[-<bpp>][@<refresh>]\"");
diff --git a/drivers/video/hpfb.c b/drivers/video/hpfb.c
index 91cf3b577d15..9ab9b839a0f5 100644
--- a/drivers/video/hpfb.c
+++ b/drivers/video/hpfb.c
@@ -295,6 +295,8 @@ static int __init hpfb_init_one(unsigned long phys_base, unsigned long virt_base
295 295
296 if (register_framebuffer(&fb_info) < 0) { 296 if (register_framebuffer(&fb_info) < 0) {
297 fb_dealloc_cmap(&fb_info.cmap); 297 fb_dealloc_cmap(&fb_info.cmap);
298 iounmap(fb_info.screen_base);
299 fb_info.screen_base = NULL;
298 return 1; 300 return 1;
299 } 301 }
300 302
diff --git a/drivers/video/i810/i810-i2c.c b/drivers/video/i810/i810-i2c.c
index b38d805db313..961f4d404467 100644
--- a/drivers/video/i810/i810-i2c.c
+++ b/drivers/video/i810/i810-i2c.c
@@ -137,15 +137,15 @@ void i810_create_i2c_busses(struct i810fb_par *par)
137void i810_delete_i2c_busses(struct i810fb_par *par) 137void i810_delete_i2c_busses(struct i810fb_par *par)
138{ 138{
139 if (par->chan[0].par) 139 if (par->chan[0].par)
140 i2c_bit_del_bus(&par->chan[0].adapter); 140 i2c_del_adapter(&par->chan[0].adapter);
141 par->chan[0].par = NULL; 141 par->chan[0].par = NULL;
142 142
143 if (par->chan[1].par) 143 if (par->chan[1].par)
144 i2c_bit_del_bus(&par->chan[1].adapter); 144 i2c_del_adapter(&par->chan[1].adapter);
145 par->chan[1].par = NULL; 145 par->chan[1].par = NULL;
146 146
147 if (par->chan[2].par) 147 if (par->chan[2].par)
148 i2c_bit_del_bus(&par->chan[2].adapter); 148 i2c_del_adapter(&par->chan[2].adapter);
149 par->chan[2].par = NULL; 149 par->chan[2].par = NULL;
150} 150}
151 151
@@ -162,9 +162,7 @@ int i810_probe_i2c_connector(struct fb_info *info, u8 **out_edid, int conn)
162 162
163 if (e != NULL) { 163 if (e != NULL) {
164 DPRINTK("i810-i2c: Getting EDID from BIOS\n"); 164 DPRINTK("i810-i2c: Getting EDID from BIOS\n");
165 edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 165 edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
166 if (edid)
167 memcpy(edid, e, EDID_LENGTH);
168 } 166 }
169 } 167 }
170 168
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index e6df492c22a5..655ae0fa99ca 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -384,19 +384,21 @@ int __init igafb_init(void)
384 if (!con_is_present()) 384 if (!con_is_present())
385 return -ENXIO; 385 return -ENXIO;
386 386
387 pdev = pci_find_device(PCI_VENDOR_ID_INTERG, 387 pdev = pci_get_device(PCI_VENDOR_ID_INTERG,
388 PCI_DEVICE_ID_INTERG_1682, 0); 388 PCI_DEVICE_ID_INTERG_1682, 0);
389 if (pdev == NULL) { 389 if (pdev == NULL) {
390 /* 390 /*
391 * XXX We tried to use cyber2000fb.c for IGS 2000. 391 * XXX We tried to use cyber2000fb.c for IGS 2000.
392 * But it does not initialize the chip in JavaStation-E, alas. 392 * But it does not initialize the chip in JavaStation-E, alas.
393 */ 393 */
394 pdev = pci_find_device(PCI_VENDOR_ID_INTERG, 0x2000, 0); 394 pdev = pci_get_device(PCI_VENDOR_ID_INTERG, 0x2000, 0);
395 if(pdev == NULL) { 395 if(pdev == NULL) {
396 return -ENXIO; 396 return -ENXIO;
397 } 397 }
398 iga2000 = 1; 398 iga2000 = 1;
399 } 399 }
400 /* We leak a reference here but as it cannot be unloaded this is
401 fine. If you write unload code remember to free it in unload */
400 402
401 size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16; 403 size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16;
402 404
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c
index 5686e2164e39..33bc41f50540 100644
--- a/drivers/video/intelfb/intelfb_i2c.c
+++ b/drivers/video/intelfb/intelfb_i2c.c
@@ -188,11 +188,11 @@ void intelfb_delete_i2c_busses(struct intelfb_info *dinfo)
188 188
189 for (i = 0; i < MAX_OUTPUTS; i++) { 189 for (i = 0; i < MAX_OUTPUTS; i++) {
190 if (dinfo->output[i].i2c_bus.dinfo) { 190 if (dinfo->output[i].i2c_bus.dinfo) {
191 i2c_bit_del_bus(&dinfo->output[i].i2c_bus.adapter); 191 i2c_del_adapter(&dinfo->output[i].i2c_bus.adapter);
192 dinfo->output[i].i2c_bus.dinfo = NULL; 192 dinfo->output[i].i2c_bus.dinfo = NULL;
193 } 193 }
194 if (dinfo->output[i].ddc_bus.dinfo) { 194 if (dinfo->output[i].ddc_bus.dinfo) {
195 i2c_bit_del_bus(&dinfo->output[i].ddc_bus.adapter); 195 i2c_del_adapter(&dinfo->output[i].ddc_bus.adapter);
196 dinfo->output[i].ddc_bus.dinfo = NULL; 196 dinfo->output[i].ddc_bus.dinfo = NULL;
197 } 197 }
198 } 198 }
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 6f9de04193d2..664fc5cf962a 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -1058,10 +1058,9 @@ intelfb_init_var(struct intelfb_info *dinfo)
1058 u8 *edid_d = NULL; 1058 u8 *edid_d = NULL;
1059 1059
1060 if (edid_s) { 1060 if (edid_s) {
1061 edid_d = kmalloc(EDID_LENGTH, GFP_KERNEL); 1061 edid_d = kmemdup(edid_s, EDID_LENGTH, GFP_KERNEL);
1062 1062
1063 if (edid_d) { 1063 if (edid_d) {
1064 memcpy(edid_d, edid_s, EDID_LENGTH);
1065 fb_edid_to_monspecs(edid_d, 1064 fb_edid_to_monspecs(edid_d,
1066 &dinfo->info->monspecs); 1065 &dinfo->info->monspecs);
1067 kfree(edid_d); 1066 kfree(edid_d);
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c
index 80a043807161..180d94c2b4d2 100644
--- a/drivers/video/macfb.c
+++ b/drivers/video/macfb.c
@@ -608,6 +608,22 @@ void __init macfb_setup(char *options)
608 } 608 }
609} 609}
610 610
611static void __init iounmap_macfb(void)
612{
613 if (valkyrie_cmap_regs)
614 iounmap(valkyrie_cmap_regs);
615 if (dafb_cmap_regs)
616 iounmap(dafb_cmap_regs);
617 if (v8_brazil_cmap_regs)
618 iounmap(v8_brazil_cmap_regs);
619 if (rbv_cmap_regs)
620 iounmap(rbv_cmap_regs);
621 if (civic_cmap_regs)
622 iounmap(civic_cmap_regs);
623 if (csc_cmap_regs)
624 iounmap(csc_cmap_regs);
625}
626
611static int __init macfb_init(void) 627static int __init macfb_init(void)
612{ 628{
613 int video_cmap_len, video_is_nubus = 0; 629 int video_cmap_len, video_is_nubus = 0;
@@ -962,6 +978,10 @@ static int __init macfb_init(void)
962 if (!err) 978 if (!err)
963 printk("fb%d: %s frame buffer device\n", 979 printk("fb%d: %s frame buffer device\n",
964 fb_info.node, fb_info.fix.id); 980 fb_info.node, fb_info.fix.id);
981 else {
982 iounmap(fb_info.screen_base);
983 iounmap_macfb();
984 }
965 return err; 985 return err;
966} 986}
967 987
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index 795c1a99a680..797b42305b0f 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -124,7 +124,7 @@ static int i2c_bus_reg(struct i2c_bit_adapter* b, struct matrox_fb_info* minfo,
124 124
125static void i2c_bit_bus_del(struct i2c_bit_adapter* b) { 125static void i2c_bit_bus_del(struct i2c_bit_adapter* b) {
126 if (b->initialized) { 126 if (b->initialized) {
127 i2c_bit_del_bus(&b->adapter); 127 i2c_del_adapter(&b->adapter);
128 b->initialized = 0; 128 b->initialized = 0;
129 } 129 }
130} 130}
diff --git a/drivers/video/mbx/mbxdebugfs.c b/drivers/video/mbx/mbxdebugfs.c
index 84aab3ad024e..472a3ca3d92d 100644
--- a/drivers/video/mbx/mbxdebugfs.c
+++ b/drivers/video/mbx/mbxdebugfs.c
@@ -10,6 +10,8 @@ struct mbxfb_debugfs_data {
10 struct dentry *clock; 10 struct dentry *clock;
11 struct dentry *display; 11 struct dentry *display;
12 struct dentry *gsctl; 12 struct dentry *gsctl;
13 struct dentry *sdram;
14 struct dentry *misc;
13}; 15};
14 16
15static int open_file_generic(struct inode *inode, struct file *file) 17static int open_file_generic(struct inode *inode, struct file *file)
@@ -29,11 +31,11 @@ static ssize_t sysconf_read_file(struct file *file, char __user *userbuf,
29{ 31{
30 char * s = big_buffer; 32 char * s = big_buffer;
31 33
32 s += sprintf(s, "SYSCFG = %08lx\n", SYSCFG); 34 s += sprintf(s, "SYSCFG = %08x\n", readl(SYSCFG));
33 s += sprintf(s, "PFBASE = %08lx\n", PFBASE); 35 s += sprintf(s, "PFBASE = %08x\n", readl(PFBASE));
34 s += sprintf(s, "PFCEIL = %08lx\n", PFCEIL); 36 s += sprintf(s, "PFCEIL = %08x\n", readl(PFCEIL));
35 s += sprintf(s, "POLLFLAG = %08lx\n", POLLFLAG); 37 s += sprintf(s, "POLLFLAG = %08x\n", readl(POLLFLAG));
36 s += sprintf(s, "SYSRST = %08lx\n", SYSRST); 38 s += sprintf(s, "SYSRST = %08x\n", readl(SYSRST));
37 39
38 return simple_read_from_buffer(userbuf, count, ppos, 40 return simple_read_from_buffer(userbuf, count, ppos,
39 big_buffer, s-big_buffer); 41 big_buffer, s-big_buffer);
@@ -45,24 +47,24 @@ static ssize_t gsctl_read_file(struct file *file, char __user *userbuf,
45{ 47{
46 char * s = big_buffer; 48 char * s = big_buffer;
47 49
48 s += sprintf(s, "GSCTRL = %08lx\n", GSCTRL); 50 s += sprintf(s, "GSCTRL = %08x\n", readl(GSCTRL));
49 s += sprintf(s, "VSCTRL = %08lx\n", VSCTRL); 51 s += sprintf(s, "VSCTRL = %08x\n", readl(VSCTRL));
50 s += sprintf(s, "GBBASE = %08lx\n", GBBASE); 52 s += sprintf(s, "GBBASE = %08x\n", readl(GBBASE));
51 s += sprintf(s, "VBBASE = %08lx\n", VBBASE); 53 s += sprintf(s, "VBBASE = %08x\n", readl(VBBASE));
52 s += sprintf(s, "GDRCTRL = %08lx\n", GDRCTRL); 54 s += sprintf(s, "GDRCTRL = %08x\n", readl(GDRCTRL));
53 s += sprintf(s, "VCMSK = %08lx\n", VCMSK); 55 s += sprintf(s, "VCMSK = %08x\n", readl(VCMSK));
54 s += sprintf(s, "GSCADR = %08lx\n", GSCADR); 56 s += sprintf(s, "GSCADR = %08x\n", readl(GSCADR));
55 s += sprintf(s, "VSCADR = %08lx\n", VSCADR); 57 s += sprintf(s, "VSCADR = %08x\n", readl(VSCADR));
56 s += sprintf(s, "VUBASE = %08lx\n", VUBASE); 58 s += sprintf(s, "VUBASE = %08x\n", readl(VUBASE));
57 s += sprintf(s, "VVBASE = %08lx\n", VVBASE); 59 s += sprintf(s, "VVBASE = %08x\n", readl(VVBASE));
58 s += sprintf(s, "GSADR = %08lx\n", GSADR); 60 s += sprintf(s, "GSADR = %08x\n", readl(GSADR));
59 s += sprintf(s, "VSADR = %08lx\n", VSADR); 61 s += sprintf(s, "VSADR = %08x\n", readl(VSADR));
60 s += sprintf(s, "HCCTRL = %08lx\n", HCCTRL); 62 s += sprintf(s, "HCCTRL = %08x\n", readl(HCCTRL));
61 s += sprintf(s, "HCSIZE = %08lx\n", HCSIZE); 63 s += sprintf(s, "HCSIZE = %08x\n", readl(HCSIZE));
62 s += sprintf(s, "HCPOS = %08lx\n", HCPOS); 64 s += sprintf(s, "HCPOS = %08x\n", readl(HCPOS));
63 s += sprintf(s, "HCBADR = %08lx\n", HCBADR); 65 s += sprintf(s, "HCBADR = %08x\n", readl(HCBADR));
64 s += sprintf(s, "HCCKMSK = %08lx\n", HCCKMSK); 66 s += sprintf(s, "HCCKMSK = %08x\n", readl(HCCKMSK));
65 s += sprintf(s, "GPLUT = %08lx\n", GPLUT); 67 s += sprintf(s, "GPLUT = %08x\n", readl(GPLUT));
66 68
67 return simple_read_from_buffer(userbuf, count, ppos, 69 return simple_read_from_buffer(userbuf, count, ppos,
68 big_buffer, s-big_buffer); 70 big_buffer, s-big_buffer);
@@ -73,36 +75,36 @@ static ssize_t display_read_file(struct file *file, char __user *userbuf,
73{ 75{
74 char * s = big_buffer; 76 char * s = big_buffer;
75 77
76 s += sprintf(s, "DSCTRL = %08lx\n", DSCTRL); 78 s += sprintf(s, "DSCTRL = %08x\n", readl(DSCTRL));
77 s += sprintf(s, "DHT01 = %08lx\n", DHT01); 79 s += sprintf(s, "DHT01 = %08x\n", readl(DHT01));
78 s += sprintf(s, "DHT02 = %08lx\n", DHT02); 80 s += sprintf(s, "DHT02 = %08x\n", readl(DHT02));
79 s += sprintf(s, "DHT03 = %08lx\n", DHT03); 81 s += sprintf(s, "DHT03 = %08x\n", readl(DHT03));
80 s += sprintf(s, "DVT01 = %08lx\n", DVT01); 82 s += sprintf(s, "DVT01 = %08x\n", readl(DVT01));
81 s += sprintf(s, "DVT02 = %08lx\n", DVT02); 83 s += sprintf(s, "DVT02 = %08x\n", readl(DVT02));
82 s += sprintf(s, "DVT03 = %08lx\n", DVT03); 84 s += sprintf(s, "DVT03 = %08x\n", readl(DVT03));
83 s += sprintf(s, "DBCOL = %08lx\n", DBCOL); 85 s += sprintf(s, "DBCOL = %08x\n", readl(DBCOL));
84 s += sprintf(s, "BGCOLOR = %08lx\n", BGCOLOR); 86 s += sprintf(s, "BGCOLOR = %08x\n", readl(BGCOLOR));
85 s += sprintf(s, "DINTRS = %08lx\n", DINTRS); 87 s += sprintf(s, "DINTRS = %08x\n", readl(DINTRS));
86 s += sprintf(s, "DINTRE = %08lx\n", DINTRE); 88 s += sprintf(s, "DINTRE = %08x\n", readl(DINTRE));
87 s += sprintf(s, "DINTRCNT = %08lx\n", DINTRCNT); 89 s += sprintf(s, "DINTRCNT = %08x\n", readl(DINTRCNT));
88 s += sprintf(s, "DSIG = %08lx\n", DSIG); 90 s += sprintf(s, "DSIG = %08x\n", readl(DSIG));
89 s += sprintf(s, "DMCTRL = %08lx\n", DMCTRL); 91 s += sprintf(s, "DMCTRL = %08x\n", readl(DMCTRL));
90 s += sprintf(s, "CLIPCTRL = %08lx\n", CLIPCTRL); 92 s += sprintf(s, "CLIPCTRL = %08x\n", readl(CLIPCTRL));
91 s += sprintf(s, "SPOCTRL = %08lx\n", SPOCTRL); 93 s += sprintf(s, "SPOCTRL = %08x\n", readl(SPOCTRL));
92 s += sprintf(s, "SVCTRL = %08lx\n", SVCTRL); 94 s += sprintf(s, "SVCTRL = %08x\n", readl(SVCTRL));
93 s += sprintf(s, "DLSTS = %08lx\n", DLSTS); 95 s += sprintf(s, "DLSTS = %08x\n", readl(DLSTS));
94 s += sprintf(s, "DLLCTRL = %08lx\n", DLLCTRL); 96 s += sprintf(s, "DLLCTRL = %08x\n", readl(DLLCTRL));
95 s += sprintf(s, "DVLNUM = %08lx\n", DVLNUM); 97 s += sprintf(s, "DVLNUM = %08x\n", readl(DVLNUM));
96 s += sprintf(s, "DUCTRL = %08lx\n", DUCTRL); 98 s += sprintf(s, "DUCTRL = %08x\n", readl(DUCTRL));
97 s += sprintf(s, "DVECTRL = %08lx\n", DVECTRL); 99 s += sprintf(s, "DVECTRL = %08x\n", readl(DVECTRL));
98 s += sprintf(s, "DHDET = %08lx\n", DHDET); 100 s += sprintf(s, "DHDET = %08x\n", readl(DHDET));
99 s += sprintf(s, "DVDET = %08lx\n", DVDET); 101 s += sprintf(s, "DVDET = %08x\n", readl(DVDET));
100 s += sprintf(s, "DODMSK = %08lx\n", DODMSK); 102 s += sprintf(s, "DODMSK = %08x\n", readl(DODMSK));
101 s += sprintf(s, "CSC01 = %08lx\n", CSC01); 103 s += sprintf(s, "CSC01 = %08x\n", readl(CSC01));
102 s += sprintf(s, "CSC02 = %08lx\n", CSC02); 104 s += sprintf(s, "CSC02 = %08x\n", readl(CSC02));
103 s += sprintf(s, "CSC03 = %08lx\n", CSC03); 105 s += sprintf(s, "CSC03 = %08x\n", readl(CSC03));
104 s += sprintf(s, "CSC04 = %08lx\n", CSC04); 106 s += sprintf(s, "CSC04 = %08x\n", readl(CSC04));
105 s += sprintf(s, "CSC05 = %08lx\n", CSC05); 107 s += sprintf(s, "CSC05 = %08x\n", readl(CSC05));
106 108
107 return simple_read_from_buffer(userbuf, count, ppos, 109 return simple_read_from_buffer(userbuf, count, ppos,
108 big_buffer, s-big_buffer); 110 big_buffer, s-big_buffer);
@@ -113,24 +115,61 @@ static ssize_t clock_read_file(struct file *file, char __user *userbuf,
113{ 115{
114 char * s = big_buffer; 116 char * s = big_buffer;
115 117
116 s += sprintf(s, "SYSCLKSRC = %08lx\n", SYSCLKSRC); 118 s += sprintf(s, "SYSCLKSRC = %08x\n", readl(SYSCLKSRC));
117 s += sprintf(s, "PIXCLKSRC = %08lx\n", PIXCLKSRC); 119 s += sprintf(s, "PIXCLKSRC = %08x\n", readl(PIXCLKSRC));
118 s += sprintf(s, "CLKSLEEP = %08lx\n", CLKSLEEP); 120 s += sprintf(s, "CLKSLEEP = %08x\n", readl(CLKSLEEP));
119 s += sprintf(s, "COREPLL = %08lx\n", COREPLL); 121 s += sprintf(s, "COREPLL = %08x\n", readl(COREPLL));
120 s += sprintf(s, "DISPPLL = %08lx\n", DISPPLL); 122 s += sprintf(s, "DISPPLL = %08x\n", readl(DISPPLL));
121 s += sprintf(s, "PLLSTAT = %08lx\n", PLLSTAT); 123 s += sprintf(s, "PLLSTAT = %08x\n", readl(PLLSTAT));
122 s += sprintf(s, "VOVRCLK = %08lx\n", VOVRCLK); 124 s += sprintf(s, "VOVRCLK = %08x\n", readl(VOVRCLK));
123 s += sprintf(s, "PIXCLK = %08lx\n", PIXCLK); 125 s += sprintf(s, "PIXCLK = %08x\n", readl(PIXCLK));
124 s += sprintf(s, "MEMCLK = %08lx\n", MEMCLK); 126 s += sprintf(s, "MEMCLK = %08x\n", readl(MEMCLK));
125 s += sprintf(s, "M24CLK = %08lx\n", M24CLK); 127 s += sprintf(s, "M24CLK = %08x\n", readl(M24CLK));
126 s += sprintf(s, "MBXCLK = %08lx\n", MBXCLK); 128 s += sprintf(s, "MBXCLK = %08x\n", readl(MBXCLK));
127 s += sprintf(s, "SDCLK = %08lx\n", SDCLK); 129 s += sprintf(s, "SDCLK = %08x\n", readl(SDCLK));
128 s += sprintf(s, "PIXCLKDIV = %08lx\n", PIXCLKDIV); 130 s += sprintf(s, "PIXCLKDIV = %08x\n", readl(PIXCLKDIV));
129 131
130 return simple_read_from_buffer(userbuf, count, ppos, 132 return simple_read_from_buffer(userbuf, count, ppos,
131 big_buffer, s-big_buffer); 133 big_buffer, s-big_buffer);
132} 134}
133 135
136static ssize_t sdram_read_file(struct file *file, char __user *userbuf,
137 size_t count, loff_t *ppos)
138{
139 char * s = big_buffer;
140
141 s += sprintf(s, "LMRST = %08x\n", readl(LMRST));
142 s += sprintf(s, "LMCFG = %08x\n", readl(LMCFG));
143 s += sprintf(s, "LMPWR = %08x\n", readl(LMPWR));
144 s += sprintf(s, "LMPWRSTAT = %08x\n", readl(LMPWRSTAT));
145 s += sprintf(s, "LMCEMR = %08x\n", readl(LMCEMR));
146 s += sprintf(s, "LMTYPE = %08x\n", readl(LMTYPE));
147 s += sprintf(s, "LMTIM = %08x\n", readl(LMTIM));
148 s += sprintf(s, "LMREFRESH = %08x\n", readl(LMREFRESH));
149 s += sprintf(s, "LMPROTMIN = %08x\n", readl(LMPROTMIN));
150 s += sprintf(s, "LMPROTMAX = %08x\n", readl(LMPROTMAX));
151 s += sprintf(s, "LMPROTCFG = %08x\n", readl(LMPROTCFG));
152 s += sprintf(s, "LMPROTERR = %08x\n", readl(LMPROTERR));
153
154 return simple_read_from_buffer(userbuf, count, ppos,
155 big_buffer, s-big_buffer);
156}
157
158static ssize_t misc_read_file(struct file *file, char __user *userbuf,
159 size_t count, loff_t *ppos)
160{
161 char * s = big_buffer;
162
163 s += sprintf(s, "LCD_CONFIG = %08x\n", readl(LCD_CONFIG));
164 s += sprintf(s, "ODFBPWR = %08x\n", readl(ODFBPWR));
165 s += sprintf(s, "ODFBSTAT = %08x\n", readl(ODFBSTAT));
166 s += sprintf(s, "ID = %08x\n", readl(ID));
167
168 return simple_read_from_buffer(userbuf, count, ppos,
169 big_buffer, s-big_buffer);
170}
171
172
134static struct file_operations sysconf_fops = { 173static struct file_operations sysconf_fops = {
135 .read = sysconf_read_file, 174 .read = sysconf_read_file,
136 .write = write_file_dummy, 175 .write = write_file_dummy,
@@ -155,6 +194,17 @@ static struct file_operations gsctl_fops = {
155 .open = open_file_generic, 194 .open = open_file_generic,
156}; 195};
157 196
197static struct file_operations sdram_fops = {
198 .read = sdram_read_file,
199 .write = write_file_dummy,
200 .open = open_file_generic,
201};
202
203static struct file_operations misc_fops = {
204 .read = misc_read_file,
205 .write = write_file_dummy,
206 .open = open_file_generic,
207};
158 208
159static void __devinit mbxfb_debugfs_init(struct fb_info *fbi) 209static void __devinit mbxfb_debugfs_init(struct fb_info *fbi)
160{ 210{
@@ -173,6 +223,10 @@ static void __devinit mbxfb_debugfs_init(struct fb_info *fbi)
173 fbi, &display_fops); 223 fbi, &display_fops);
174 dbg->gsctl = debugfs_create_file("gsctl", 0444, dbg->dir, 224 dbg->gsctl = debugfs_create_file("gsctl", 0444, dbg->dir,
175 fbi, &gsctl_fops); 225 fbi, &gsctl_fops);
226 dbg->sdram = debugfs_create_file("sdram", 0444, dbg->dir,
227 fbi, &sdram_fops);
228 dbg->misc = debugfs_create_file("misc", 0444, dbg->dir,
229 fbi, &misc_fops);
176} 230}
177 231
178static void __devexit mbxfb_debugfs_remove(struct fb_info *fbi) 232static void __devexit mbxfb_debugfs_remove(struct fb_info *fbi)
@@ -180,6 +234,8 @@ static void __devexit mbxfb_debugfs_remove(struct fb_info *fbi)
180 struct mbxfb_info *mfbi = fbi->par; 234 struct mbxfb_info *mfbi = fbi->par;
181 struct mbxfb_debugfs_data *dbg = mfbi->debugfs_data; 235 struct mbxfb_debugfs_data *dbg = mfbi->debugfs_data;
182 236
237 debugfs_remove(dbg->misc);
238 debugfs_remove(dbg->sdram);
183 debugfs_remove(dbg->gsctl); 239 debugfs_remove(dbg->gsctl);
184 debugfs_remove(dbg->display); 240 debugfs_remove(dbg->display);
185 debugfs_remove(dbg->clock); 241 debugfs_remove(dbg->clock);
diff --git a/drivers/video/mbx/mbxfb.c b/drivers/video/mbx/mbxfb.c
index a32d1af79e07..980d5f623902 100644
--- a/drivers/video/mbx/mbxfb.c
+++ b/drivers/video/mbx/mbxfb.c
@@ -1,8 +1,14 @@
1/* 1/*
2 * linux/drivers/video/mbx/mbxfb.c 2 * linux/drivers/video/mbx/mbxfb.c
3 * 3 *
4 * Copyright (C) 2006 8D Technologies inc
5 * Raphael Assenat <raph@8d.com>
6 * - Added video overlay support
7 * - Various improvements
8 *
4 * Copyright (C) 2006 Compulab, Ltd. 9 * Copyright (C) 2006 Compulab, Ltd.
5 * Mike Rapoport <mike@compulab.co.il> 10 * Mike Rapoport <mike@compulab.co.il>
11 * - Creation of driver
6 * 12 *
7 * Based on pxafb.c 13 * Based on pxafb.c
8 * 14 *
@@ -19,6 +25,7 @@
19#include <linux/init.h> 25#include <linux/init.h>
20#include <linux/module.h> 26#include <linux/module.h>
21#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/uaccess.h>
22 29
23#include <asm/io.h> 30#include <asm/io.h>
24 31
@@ -29,6 +36,14 @@
29 36
30static unsigned long virt_base_2700; 37static unsigned long virt_base_2700;
31 38
39#define write_reg(val, reg) do { writel((val), (reg)); } while(0)
40
41/* Without this delay, the graphics appears somehow scaled and
42 * there is a lot of jitter in scanlines. This delay is probably
43 * needed only after setting some specific register(s) somewhere,
44 * not all over the place... */
45#define write_reg_dly(val, reg) do { writel((val), reg); udelay(1000); } while(0)
46
32#define MIN_XRES 16 47#define MIN_XRES 16
33#define MIN_YRES 16 48#define MIN_YRES 16
34#define MAX_XRES 2048 49#define MAX_XRES 2048
@@ -257,19 +272,17 @@ static int mbxfb_set_par(struct fb_info *info)
257 gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT)); 272 gsctrl &= ~(FMsk(GSCTRL_GSWIDTH) | FMsk(GSCTRL_GSHEIGHT));
258 gsctrl |= Gsctrl_Width(info->var.xres) | 273 gsctrl |= Gsctrl_Width(info->var.xres) |
259 Gsctrl_Height(info->var.yres); 274 Gsctrl_Height(info->var.yres);
260 writel(gsctrl, GSCTRL); 275 write_reg_dly(gsctrl, GSCTRL);
261 udelay(1000);
262 276
263 gsadr &= ~(FMsk(GSADR_SRCSTRIDE)); 277 gsadr &= ~(FMsk(GSADR_SRCSTRIDE));
264 gsadr |= Gsadr_Srcstride(info->var.xres * info->var.bits_per_pixel / 278 gsadr |= Gsadr_Srcstride(info->var.xres * info->var.bits_per_pixel /
265 (8 * 16) - 1); 279 (8 * 16) - 1);
266 writel(gsadr, GSADR); 280 write_reg_dly(gsadr, GSADR);
267 udelay(1000);
268 281
269 /* setup timings */ 282 /* setup timings */
270 var->pixclock = mbxfb_get_pixclock(info->var.pixclock, &div); 283 var->pixclock = mbxfb_get_pixclock(info->var.pixclock, &div);
271 284
272 writel((Disp_Pll_M(div.m) | Disp_Pll_N(div.n) | 285 write_reg_dly((Disp_Pll_M(div.m) | Disp_Pll_N(div.n) |
273 Disp_Pll_P(div.p) | DISP_PLL_EN), DISPPLL); 286 Disp_Pll_P(div.p) | DISP_PLL_EN), DISPPLL);
274 287
275 hbps = var->hsync_len; 288 hbps = var->hsync_len;
@@ -282,18 +295,20 @@ static int mbxfb_set_par(struct fb_info *info)
282 vfps = vas + var->yres; 295 vfps = vas + var->yres;
283 vt = vfps + var->lower_margin; 296 vt = vfps + var->lower_margin;
284 297
285 writel((Dht01_Hbps(hbps) | Dht01_Ht(ht)), DHT01); 298 write_reg_dly((Dht01_Hbps(hbps) | Dht01_Ht(ht)), DHT01);
286 writel((Dht02_Hlbs(has) | Dht02_Has(has)), DHT02); 299 write_reg_dly((Dht02_Hlbs(has) | Dht02_Has(has)), DHT02);
287 writel((Dht03_Hfps(hfps) | Dht03_Hrbs(hfps)), DHT03); 300 write_reg_dly((Dht03_Hfps(hfps) | Dht03_Hrbs(hfps)), DHT03);
288 writel((Dhdet_Hdes(has) | Dhdet_Hdef(hfps)), DHDET); 301 write_reg_dly((Dhdet_Hdes(has) | Dhdet_Hdef(hfps)), DHDET);
289 302
290 writel((Dvt01_Vbps(vbps) | Dvt01_Vt(vt)), DVT01); 303 write_reg_dly((Dvt01_Vbps(vbps) | Dvt01_Vt(vt)), DVT01);
291 writel((Dvt02_Vtbs(vas) | Dvt02_Vas(vas)), DVT02); 304 write_reg_dly((Dvt02_Vtbs(vas) | Dvt02_Vas(vas)), DVT02);
292 writel((Dvt03_Vfps(vfps) | Dvt03_Vbbs(vfps)), DVT03); 305 write_reg_dly((Dvt03_Vfps(vfps) | Dvt03_Vbbs(vfps)), DVT03);
293 writel((Dvdet_Vdes(vas) | Dvdet_Vdef(vfps)), DVDET); 306 write_reg_dly((Dvdet_Vdes(vas) | Dvdet_Vdef(vfps)), DVDET);
294 writel((Dvectrl_Vevent(vfps) | Dvectrl_Vfetch(vbps)), DVECTRL); 307 write_reg_dly((Dvectrl_Vevent(vfps) | Dvectrl_Vfetch(vbps)), DVECTRL);
295 308
296 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL); 309 write_reg_dly((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
310
311 write_reg_dly(DINTRE_VEVENT0_EN, DINTRE);
297 312
298 return 0; 313 return 0;
299} 314}
@@ -305,23 +320,203 @@ static int mbxfb_blank(int blank, struct fb_info *info)
305 case FB_BLANK_VSYNC_SUSPEND: 320 case FB_BLANK_VSYNC_SUSPEND:
306 case FB_BLANK_HSYNC_SUSPEND: 321 case FB_BLANK_HSYNC_SUSPEND:
307 case FB_BLANK_NORMAL: 322 case FB_BLANK_NORMAL:
308 writel((readl(DSCTRL) & ~DSCTRL_SYNCGEN_EN), DSCTRL); 323 write_reg_dly((readl(DSCTRL) & ~DSCTRL_SYNCGEN_EN), DSCTRL);
309 udelay(1000); 324 write_reg_dly((readl(PIXCLK) & ~PIXCLK_EN), PIXCLK);
310 writel((readl(PIXCLK) & ~PIXCLK_EN), PIXCLK); 325 write_reg_dly((readl(VOVRCLK) & ~VOVRCLK_EN), VOVRCLK);
311 udelay(1000);
312 writel((readl(VOVRCLK) & ~VOVRCLK_EN), VOVRCLK);
313 udelay(1000);
314 break; 326 break;
315 case FB_BLANK_UNBLANK: 327 case FB_BLANK_UNBLANK:
316 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL); 328 write_reg_dly((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
317 udelay(1000); 329 write_reg_dly((readl(PIXCLK) | PIXCLK_EN), PIXCLK);
318 writel((readl(PIXCLK) | PIXCLK_EN), PIXCLK);
319 udelay(1000);
320 break; 330 break;
321 } 331 }
322 return 0; 332 return 0;
323} 333}
324 334
335static int mbxfb_setupOverlay(struct mbxfb_overlaySetup *set)
336{
337 u32 vsctrl, vbbase, vscadr, vsadr;
338 u32 sssize, spoctrl, svctrl, shctrl;
339 u32 vubase, vvbase;
340 u32 vovrclk;
341
342 if (set->scaled_width==0 || set->scaled_height==0)
343 return -EINVAL;
344
345 /* read registers which have reserved bits
346 * so we can write them back as-is. */
347 vovrclk = readl(VOVRCLK);
348 vsctrl = readl(VSCTRL);
349 vscadr = readl(VSCADR);
350 vubase = readl(VUBASE);
351 vvbase = readl(VVBASE);
352
353 spoctrl = readl(SPOCTRL);
354 sssize = readl(SSSIZE);
355
356
357 vbbase = Vbbase_Glalpha(set->alpha);
358
359 vsctrl &= ~( FMsk(VSCTRL_VSWIDTH) |
360 FMsk(VSCTRL_VSHEIGHT) |
361 FMsk(VSCTRL_VPIXFMT) |
362 VSCTRL_GAMMA_EN | VSCTRL_CSC_EN |
363 VSCTRL_COSITED );
364 vsctrl |= Vsctrl_Width(set->width) | Vsctrl_Height(set->height) |
365 VSCTRL_CSC_EN;
366
367 vscadr &= ~(VSCADR_STR_EN | VSCADR_COLKEY_EN | VSCADR_COLKEYSRC |
368 FMsk(VSCADR_BLEND_M) | FMsk(VSCADR_BLEND_POS) |
369 FMsk(VSCADR_VBASE_ADR) );
370 vubase &= ~(VUBASE_UVHALFSTR | FMsk(VUBASE_UBASE_ADR));
371 vvbase &= ~(FMsk(VVBASE_VBASE_ADR));
372
373 switch (set->fmt)
374 {
375 case MBXFB_FMT_YUV12:
376 vsctrl |= VSCTRL_VPIXFMT_YUV12;
377
378 set->Y_stride = ((set->width) + 0xf ) & ~0xf;
379
380 break;
381 case MBXFB_FMT_UY0VY1:
382 vsctrl |= VSCTRL_VPIXFMT_UY0VY1;
383 set->Y_stride = (set->width*2 + 0xf ) & ~0xf;
384 break;
385 case MBXFB_FMT_VY0UY1:
386 vsctrl |= VSCTRL_VPIXFMT_VY0UY1;
387 set->Y_stride = (set->width*2 + 0xf ) & ~0xf;
388 break;
389 case MBXFB_FMT_Y0UY1V:
390 vsctrl |= VSCTRL_VPIXFMT_Y0UY1V;
391 set->Y_stride = (set->width*2 + 0xf ) & ~0xf;
392 break;
393 case MBXFB_FMT_Y0VY1U:
394 vsctrl |= VSCTRL_VPIXFMT_Y0VY1U;
395 set->Y_stride = (set->width*2 + 0xf ) & ~0xf;
396 break;
397 default:
398 return -EINVAL;
399 }
400
401 /* VSCTRL has the bits which sets the Video Pixel Format.
402 * When passing from a packed to planar format,
403 * if we write VSCTRL first, VVBASE and VUBASE would
404 * be zero if we would not set them here. (And then,
405 * the chips hangs and only a reset seems to fix it).
406 *
407 * If course, the values calculated here have no meaning
408 * for packed formats.
409 */
410 set->UV_stride = ((set->width/2) + 0x7 ) & ~0x7;
411 set->U_offset = set->height * set->Y_stride;
412 set->V_offset = set->U_offset +
413 set->height * set->UV_stride;
414 vubase |= Vubase_Ubase_Adr(
415 (0x60000 + set->mem_offset + set->U_offset)>>3);
416 vvbase |= Vvbase_Vbase_Adr(
417 (0x60000 + set->mem_offset + set->V_offset)>>3);
418
419
420 vscadr |= VSCADR_BLEND_VID | VSCADR_BLEND_GLOB |
421 Vscadr_Vbase_Adr((0x60000 + set->mem_offset)>>4);
422
423 if (set->enable)
424 vscadr |= VSCADR_STR_EN;
425
426
427 vsadr = Vsadr_Srcstride((set->Y_stride)/16-1) |
428 Vsadr_Xstart(set->x) | Vsadr_Ystart(set->y);
429
430 sssize &= ~(FMsk(SSSIZE_SC_WIDTH) | FMsk(SSSIZE_SC_HEIGHT));
431 sssize = Sssize_Sc_Width(set->scaled_width-1) |
432 Sssize_Sc_Height(set->scaled_height-1);
433
434 spoctrl &= ~(SPOCTRL_H_SC_BP | SPOCTRL_V_SC_BP |
435 SPOCTRL_HV_SC_OR | SPOCTRL_VS_UR_C |
436 FMsk(SPOCTRL_VORDER) | FMsk(SPOCTRL_VPITCH));
437 spoctrl = Spoctrl_Vpitch((set->height<<11)/set->scaled_height)
438 | SPOCTRL_VORDER_2TAP;
439
440 /* Bypass horiz/vert scaler when same size */
441 if (set->scaled_width == set->width)
442 spoctrl |= SPOCTRL_H_SC_BP;
443 if (set->scaled_height == set->height)
444 spoctrl |= SPOCTRL_V_SC_BP;
445
446 svctrl = Svctrl_Initial1(1<<10) | Svctrl_Initial2(1<<10);
447
448 shctrl = Shctrl_Hinitial(4<<11)
449 | Shctrl_Hpitch((set->width<<11)/set->scaled_width);
450
451 /* Video plane registers */
452 write_reg(vsctrl, VSCTRL);
453 write_reg(vbbase, VBBASE);
454 write_reg(vscadr, VSCADR);
455 write_reg(vubase, VUBASE);
456 write_reg(vvbase, VVBASE);
457 write_reg(vsadr, VSADR);
458
459 /* Video scaler registers */
460 write_reg(sssize, SSSIZE);
461 write_reg(spoctrl, SPOCTRL);
462 write_reg(svctrl, SVCTRL);
463 write_reg(shctrl, SHCTRL);
464
465 /* RAPH: Using those coefficients, the scaled
466 * image is quite blurry. I dont know how
467 * to improve them ; The chip documentation
468 * was not helpful.. */
469 write_reg(0x21212121, VSCOEFF0);
470 write_reg(0x21212121, VSCOEFF1);
471 write_reg(0x21212121, VSCOEFF2);
472 write_reg(0x21212121, VSCOEFF3);
473 write_reg(0x21212121, VSCOEFF4);
474 write_reg(0x00000000, HSCOEFF0);
475 write_reg(0x00000000, HSCOEFF1);
476 write_reg(0x00000000, HSCOEFF2);
477 write_reg(0x03020201, HSCOEFF3);
478 write_reg(0x09070604, HSCOEFF4);
479 write_reg(0x0f0e0c0a, HSCOEFF5);
480 write_reg(0x15141211, HSCOEFF6);
481 write_reg(0x19181716, HSCOEFF7);
482 write_reg(0x00000019, HSCOEFF8);
483
484 /* Clock */
485 if (set->enable)
486 vovrclk |= 1;
487 else
488 vovrclk &= ~1;
489
490 write_reg(vovrclk, VOVRCLK);
491
492 return 0;
493}
494
495static int mbxfb_ioctl(struct fb_info *info, unsigned int cmd,
496 unsigned long arg)
497{
498 struct mbxfb_overlaySetup setup;
499 int res;
500
501 if (cmd == MBXFB_IOCX_OVERLAY)
502 {
503 if (copy_from_user(&setup, (void __user*)arg,
504 sizeof(struct mbxfb_overlaySetup)))
505 return -EFAULT;
506
507 res = mbxfb_setupOverlay(&setup);
508 if (res)
509 return res;
510
511 if (copy_to_user((void __user*)arg, &setup,
512 sizeof(struct mbxfb_overlaySetup)))
513 return -EFAULT;
514
515 return 0;
516 }
517 return -EINVAL;
518}
519
325static struct fb_ops mbxfb_ops = { 520static struct fb_ops mbxfb_ops = {
326 .owner = THIS_MODULE, 521 .owner = THIS_MODULE,
327 .fb_check_var = mbxfb_check_var, 522 .fb_check_var = mbxfb_check_var,
@@ -331,6 +526,7 @@ static struct fb_ops mbxfb_ops = {
331 .fb_copyarea = cfb_copyarea, 526 .fb_copyarea = cfb_copyarea,
332 .fb_imageblit = cfb_imageblit, 527 .fb_imageblit = cfb_imageblit,
333 .fb_blank = mbxfb_blank, 528 .fb_blank = mbxfb_blank,
529 .fb_ioctl = mbxfb_ioctl,
334}; 530};
335 531
336/* 532/*
@@ -339,36 +535,29 @@ static struct fb_ops mbxfb_ops = {
339*/ 535*/
340static void __devinit setup_memc(struct fb_info *fbi) 536static void __devinit setup_memc(struct fb_info *fbi)
341{ 537{
342 struct mbxfb_info *mfbi = fbi->par;
343 unsigned long tmp; 538 unsigned long tmp;
344 int i; 539 int i;
345 540
346 /* FIXME: use platfrom specific parameters */ 541 /* FIXME: use platfrom specific parameters */
347 /* setup SDRAM controller */ 542 /* setup SDRAM controller */
348 writel((LMCFG_LMC_DS | LMCFG_LMC_TS | LMCFG_LMD_TS | 543 write_reg_dly((LMCFG_LMC_DS | LMCFG_LMC_TS | LMCFG_LMD_TS |
349 LMCFG_LMA_TS), 544 LMCFG_LMA_TS),
350 LMCFG); 545 LMCFG);
351 udelay(1000);
352 546
353 writel(LMPWR_MC_PWR_ACT, LMPWR); 547 write_reg_dly(LMPWR_MC_PWR_ACT, LMPWR);
354 udelay(1000);
355 548
356 /* setup SDRAM timings */ 549 /* setup SDRAM timings */
357 writel((Lmtim_Tras(7) | Lmtim_Trp(3) | Lmtim_Trcd(3) | 550 write_reg_dly((Lmtim_Tras(7) | Lmtim_Trp(3) | Lmtim_Trcd(3) |
358 Lmtim_Trc(9) | Lmtim_Tdpl(2)), 551 Lmtim_Trc(9) | Lmtim_Tdpl(2)),
359 LMTIM); 552 LMTIM);
360 udelay(1000);
361 /* setup SDRAM refresh rate */ 553 /* setup SDRAM refresh rate */
362 writel(0xc2b, LMREFRESH); 554 write_reg_dly(0xc2b, LMREFRESH);
363 udelay(1000);
364 /* setup SDRAM type parameters */ 555 /* setup SDRAM type parameters */
365 writel((LMTYPE_CASLAT_3 | LMTYPE_BKSZ_2 | LMTYPE_ROWSZ_11 | 556 write_reg_dly((LMTYPE_CASLAT_3 | LMTYPE_BKSZ_2 | LMTYPE_ROWSZ_11 |
366 LMTYPE_COLSZ_8), 557 LMTYPE_COLSZ_8),
367 LMTYPE); 558 LMTYPE);
368 udelay(1000);
369 /* enable memory controller */ 559 /* enable memory controller */
370 writel(LMPWR_MC_PWR_ACT, LMPWR); 560 write_reg_dly(LMPWR_MC_PWR_ACT, LMPWR);
371 udelay(1000);
372 561
373 /* perform dummy reads */ 562 /* perform dummy reads */
374 for ( i = 0; i < 16; i++ ) { 563 for ( i = 0; i < 16; i++ ) {
@@ -379,34 +568,30 @@ static void __devinit setup_memc(struct fb_info *fbi)
379static void enable_clocks(struct fb_info *fbi) 568static void enable_clocks(struct fb_info *fbi)
380{ 569{
381 /* enable clocks */ 570 /* enable clocks */
382 writel(SYSCLKSRC_PLL_2, SYSCLKSRC); 571 write_reg_dly(SYSCLKSRC_PLL_2, SYSCLKSRC);
383 udelay(1000); 572 write_reg_dly(PIXCLKSRC_PLL_1, PIXCLKSRC);
384 writel(PIXCLKSRC_PLL_1, PIXCLKSRC); 573 write_reg_dly(0x00000000, CLKSLEEP);
385 udelay(1000); 574
386 writel(0x00000000, CLKSLEEP); 575 /* PLL output = (Frefclk * M) / (N * 2^P )
387 udelay(1000); 576 *
388 writel((Core_Pll_M(0x17) | Core_Pll_N(0x3) | Core_Pll_P(0x0) | 577 * M: 0x17, N: 0x3, P: 0x0 == 100 Mhz!
578 * M: 0xb, N: 0x1, P: 0x1 == 71 Mhz
579 * */
580 write_reg_dly((Core_Pll_M(0xb) | Core_Pll_N(0x1) | Core_Pll_P(0x1) |
389 CORE_PLL_EN), 581 CORE_PLL_EN),
390 COREPLL); 582 COREPLL);
391 udelay(1000); 583
392 writel((Disp_Pll_M(0x1b) | Disp_Pll_N(0x7) | Disp_Pll_P(0x1) | 584 write_reg_dly((Disp_Pll_M(0x1b) | Disp_Pll_N(0x7) | Disp_Pll_P(0x1) |
393 DISP_PLL_EN), 585 DISP_PLL_EN),
394 DISPPLL); 586 DISPPLL);
395 587
396 writel(0x00000000, VOVRCLK); 588 write_reg_dly(0x00000000, VOVRCLK);
397 udelay(1000); 589 write_reg_dly(PIXCLK_EN, PIXCLK);
398 writel(PIXCLK_EN, PIXCLK); 590 write_reg_dly(MEMCLK_EN, MEMCLK);
399 udelay(1000); 591 write_reg_dly(0x00000006, M24CLK);
400 writel(MEMCLK_EN, MEMCLK); 592 write_reg_dly(0x00000006, MBXCLK);
401 udelay(1000); 593 write_reg_dly(SDCLK_EN, SDCLK);
402 writel(0x00000006, M24CLK); 594 write_reg_dly(0x00000001, PIXCLKDIV);
403 udelay(1000);
404 writel(0x00000006, MBXCLK);
405 udelay(1000);
406 writel(SDCLK_EN, SDCLK);
407 udelay(1000);
408 writel(0x00000001, PIXCLKDIV);
409 udelay(1000);
410} 595}
411 596
412static void __devinit setup_graphics(struct fb_info *fbi) 597static void __devinit setup_graphics(struct fb_info *fbi)
@@ -430,16 +615,11 @@ static void __devinit setup_graphics(struct fb_info *fbi)
430 break; 615 break;
431 } 616 }
432 617
433 writel(gsctrl, GSCTRL); 618 write_reg_dly(gsctrl, GSCTRL);
434 udelay(1000); 619 write_reg_dly(0x00000000, GBBASE);
435 writel(0x00000000, GBBASE); 620 write_reg_dly(0x00ffffff, GDRCTRL);
436 udelay(1000); 621 write_reg_dly((GSCADR_STR_EN | Gscadr_Gbase_Adr(0x6000)), GSCADR);
437 writel(0x00ffffff, GDRCTRL); 622 write_reg_dly(0x00000000, GPLUT);
438 udelay(1000);
439 writel((GSCADR_STR_EN | Gscadr_Gbase_Adr(0x6000)), GSCADR);
440 udelay(1000);
441 writel(0x00000000, GPLUT);
442 udelay(1000);
443} 623}
444 624
445static void __devinit setup_display(struct fb_info *fbi) 625static void __devinit setup_display(struct fb_info *fbi)
@@ -451,17 +631,14 @@ static void __devinit setup_display(struct fb_info *fbi)
451 dsctrl |= DSCTRL_HS_POL; 631 dsctrl |= DSCTRL_HS_POL;
452 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT) 632 if (fbi->var.sync & FB_SYNC_VERT_HIGH_ACT)
453 dsctrl |= DSCTRL_VS_POL; 633 dsctrl |= DSCTRL_VS_POL;
454 writel(dsctrl, DSCTRL); 634 write_reg_dly(dsctrl, DSCTRL);
455 udelay(1000); 635 write_reg_dly(0xd0303010, DMCTRL);
456 writel(0xd0303010, DMCTRL); 636 write_reg_dly((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
457 udelay(1000);
458 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
459} 637}
460 638
461static void __devinit enable_controller(struct fb_info *fbi) 639static void __devinit enable_controller(struct fb_info *fbi)
462{ 640{
463 writel(SYSRST_RST, SYSRST); 641 write_reg_dly(SYSRST_RST, SYSRST);
464 udelay(1000);
465 642
466 643
467 enable_clocks(fbi); 644 enable_clocks(fbi);
@@ -478,12 +655,12 @@ static void __devinit enable_controller(struct fb_info *fbi)
478static int mbxfb_suspend(struct platform_device *dev, pm_message_t state) 655static int mbxfb_suspend(struct platform_device *dev, pm_message_t state)
479{ 656{
480 /* make frame buffer memory enter self-refresh mode */ 657 /* make frame buffer memory enter self-refresh mode */
481 writel(LMPWR_MC_PWR_SRM, LMPWR); 658 write_reg_dly(LMPWR_MC_PWR_SRM, LMPWR);
482 while (LMPWRSTAT != LMPWRSTAT_MC_PWR_SRM) 659 while (LMPWRSTAT != LMPWRSTAT_MC_PWR_SRM)
483 ; /* empty statement */ 660 ; /* empty statement */
484 661
485 /* reset the device, since it's initial state is 'mostly sleeping' */ 662 /* reset the device, since it's initial state is 'mostly sleeping' */
486 writel(SYSRST_RST, SYSRST); 663 write_reg_dly(SYSRST_RST, SYSRST);
487 return 0; 664 return 0;
488} 665}
489 666
@@ -495,7 +672,7 @@ static int mbxfb_resume(struct platform_device *dev)
495/* setup_graphics(fbi); */ 672/* setup_graphics(fbi); */
496/* setup_display(fbi); */ 673/* setup_display(fbi); */
497 674
498 writel((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL); 675 write_reg_dly((readl(DSCTRL) | DSCTRL_SYNCGEN_EN), DSCTRL);
499 return 0; 676 return 0;
500} 677}
501#else 678#else
@@ -520,6 +697,12 @@ static int __devinit mbxfb_probe(struct platform_device *dev)
520 697
521 dev_dbg(dev, "mbxfb_probe\n"); 698 dev_dbg(dev, "mbxfb_probe\n");
522 699
700 pdata = dev->dev.platform_data;
701 if (!pdata) {
702 dev_err(&dev->dev, "platform data is required\n");
703 return -EINVAL;
704 }
705
523 fbi = framebuffer_alloc(sizeof(struct mbxfb_info), &dev->dev); 706 fbi = framebuffer_alloc(sizeof(struct mbxfb_info), &dev->dev);
524 if (fbi == NULL) { 707 if (fbi == NULL) {
525 dev_err(&dev->dev, "framebuffer_alloc failed\n"); 708 dev_err(&dev->dev, "framebuffer_alloc failed\n");
@@ -528,7 +711,8 @@ static int __devinit mbxfb_probe(struct platform_device *dev)
528 711
529 mfbi = fbi->par; 712 mfbi = fbi->par;
530 fbi->pseudo_palette = mfbi->pseudo_palette; 713 fbi->pseudo_palette = mfbi->pseudo_palette;
531 pdata = dev->dev.platform_data; 714
715
532 if (pdata->probe) 716 if (pdata->probe)
533 mfbi->platform_probe = pdata->probe; 717 mfbi->platform_probe = pdata->probe;
534 if (pdata->remove) 718 if (pdata->remove)
@@ -578,16 +762,16 @@ static int __devinit mbxfb_probe(struct platform_device *dev)
578 goto err4; 762 goto err4;
579 } 763 }
580 764
581 /* FIXME: get from platform */
582 fbi->screen_base = (char __iomem *)(mfbi->fb_virt_addr + 0x60000); 765 fbi->screen_base = (char __iomem *)(mfbi->fb_virt_addr + 0x60000);
583 fbi->screen_size = 8 * 1024 * 1024; /* 8 Megs */ 766 fbi->screen_size = pdata->memsize;
584 fbi->fbops = &mbxfb_ops; 767 fbi->fbops = &mbxfb_ops;
585 768
586 fbi->var = mbxfb_default; 769 fbi->var = mbxfb_default;
587 fbi->fix = mbxfb_fix; 770 fbi->fix = mbxfb_fix;
588 fbi->fix.smem_start = mfbi->fb_phys_addr + 0x60000; 771 fbi->fix.smem_start = mfbi->fb_phys_addr + 0x60000;
589 fbi->fix.smem_len = 8 * 1024 * 1024; 772 fbi->fix.smem_len = pdata->memsize;
590 fbi->fix.line_length = 640 * 2; 773 fbi->fix.line_length = mbxfb_default.xres_virtual *
774 mbxfb_default.bits_per_pixel / 8;
591 775
592 ret = fb_alloc_cmap(&fbi->cmap, 256, 0); 776 ret = fb_alloc_cmap(&fbi->cmap, 256, 0);
593 if (ret < 0) { 777 if (ret < 0) {
@@ -636,8 +820,7 @@ static int __devexit mbxfb_remove(struct platform_device *dev)
636{ 820{
637 struct fb_info *fbi = platform_get_drvdata(dev); 821 struct fb_info *fbi = platform_get_drvdata(dev);
638 822
639 writel(SYSRST_RST, SYSRST); 823 write_reg_dly(SYSRST_RST, SYSRST);
640 udelay(1000);
641 824
642 mbxfb_debugfs_remove(fbi); 825 mbxfb_debugfs_remove(fbi);
643 826
diff --git a/drivers/video/mbx/reg_bits.h b/drivers/video/mbx/reg_bits.h
index c226a8e45312..9a24fb0c7d48 100644
--- a/drivers/video/mbx/reg_bits.h
+++ b/drivers/video/mbx/reg_bits.h
@@ -242,6 +242,67 @@
242#define GPLUT_LUTDATA Fld(24,0) 242#define GPLUT_LUTDATA Fld(24,0)
243#define Gplut_Lutdata(x) ((x) << FShft(GPLUT_LUTDATA)) 243#define Gplut_Lutdata(x) ((x) << FShft(GPLUT_LUTDATA))
244 244
245/* VSCTRL - Video Surface Control Register */
246#define VSCTRL_VPIXFMT Fld(4,27)
247#define VSCTRL_VPIXFMT_YUV12 ((0x9) << FShft(VSCTRL_VPIXFMT))
248#define VSCTRL_VPIXFMT_UY0VY1 ((0xc) << FShft(VSCTRL_VPIXFMT))
249#define VSCTRL_VPIXFMT_VY0UY1 ((0xd) << FShft(VSCTRL_VPIXFMT))
250#define VSCTRL_VPIXFMT_Y0UY1V ((0xe) << FShft(VSCTRL_VPIXFMT))
251#define VSCTRL_VPIXFMT_Y0VY1U ((0xf) << FShft(VSCTRL_VPIXFMT))
252#define VSCTRL_GAMMA_EN (1 << 26)
253#define VSCTRL_CSC_EN (1 << 25)
254#define VSCTRL_COSITED (1 << 22)
255#define VSCTRL_VSWIDTH Fld(11,11)
256#define Vsctrl_Width(Pixels) /* Video Width [1-2048] */ \
257 (((Pixels) - 1) << FShft(VSCTRL_VSWIDTH))
258#define VSCTRL_VSHEIGHT Fld(11,0)
259#define Vsctrl_Height(Pixels) /* Video Height [1-2048] */ \
260 (((Pixels) - 1) << FShft(VSCTRL_VSHEIGHT))
261
262/* VBBASE - Video Blending Base Register */
263#define VBBASE_GLALPHA Fld(8,24)
264#define Vbbase_Glalpha(x) ((x) << FShft(VBBASE_GLALPHA))
265
266#define VBBASE_COLKEY Fld(24,0)
267#define Vbbase_Colkey(x) ((x) << FShft(VBBASE_COLKEY))
268
269/* VCMSK - Video Color Key Mask Register */
270#define VCMSK_COLKEY_M Fld(24,0)
271#define Vcmsk_colkey_m(x) ((x) << FShft(VCMSK_COLKEY_M))
272
273/* VSCADR - Video Stream Control Rddress Register */
274#define VSCADR_STR_EN (1 << 31)
275#define VSCADR_COLKEY_EN (1 << 30)
276#define VSCADR_COLKEYSRC (1 << 29)
277#define VSCADR_BLEND_M Fld(2,27)
278#define VSCADR_BLEND_NONE ((0x0) << FShft(VSCADR_BLEND_M))
279#define VSCADR_BLEND_INV ((0x1) << FShft(VSCADR_BLEND_M))
280#define VSCADR_BLEND_GLOB ((0x2) << FShft(VSCADR_BLEND_M))
281#define VSCADR_BLEND_PIX ((0x3) << FShft(VSCADR_BLEND_M))
282#define VSCADR_BLEND_POS Fld(2,24)
283#define VSCADR_BLEND_GFX ((0x0) << FShft(VSCADR_BLEND_POS))
284#define VSCADR_BLEND_VID ((0x1) << FShft(VSCADR_BLEND_POS))
285#define VSCADR_BLEND_CUR ((0x2) << FShft(VSCADR_BLEND_POS))
286#define VSCADR_VBASE_ADR Fld(23,0)
287#define Vscadr_Vbase_Adr(x) ((x) << FShft(VSCADR_VBASE_ADR))
288
289/* VUBASE - Video U Base Register */
290#define VUBASE_UVHALFSTR (1 << 31)
291#define VUBASE_UBASE_ADR Fld(24,0)
292#define Vubase_Ubase_Adr(x) ((x) << FShft(VUBASE_UBASE_ADR))
293
294/* VVBASE - Video V Base Register */
295#define VVBASE_VBASE_ADR Fld(24,0)
296#define Vvbase_Vbase_Adr(x) ((x) << FShft(VVBASE_VBASE_ADR))
297
298/* VSADR - Video Stride Address Register */
299#define VSADR_SRCSTRIDE Fld(10,22)
300#define Vsadr_Srcstride(x) ((x) << FShft(VSADR_SRCSTRIDE))
301#define VSADR_XSTART Fld(11,11)
302#define Vsadr_Xstart(x) ((x) << FShft(VSADR_XSTART))
303#define VSADR_YSTART Fld(11,0)
304#define Vsadr_Ystart(x) ((x) << FShft(VSADR_YSTART))
305
245/* HCCTRL - Hardware Cursor Register fields */ 306/* HCCTRL - Hardware Cursor Register fields */
246#define HCCTRL_CUR_EN (1 << 31) 307#define HCCTRL_CUR_EN (1 << 31)
247#define HCCTRL_COLKEY_EN (1 << 29) 308#define HCCTRL_COLKEY_EN (1 << 29)
@@ -394,6 +455,30 @@
394#define DMCTRL_BURSTLEN Fld(6,0) 455#define DMCTRL_BURSTLEN Fld(6,0)
395#define Dmctrl_Burstlen(x) ((x) << FShft(DMCTRL_BURSTLEN)) 456#define Dmctrl_Burstlen(x) ((x) << FShft(DMCTRL_BURSTLEN))
396 457
458/* DINTRS - Display Interrupt Status Register */
459#define DINTRS_CUR_OR_S (1 << 18)
460#define DINTRS_STR2_OR_S (1 << 17)
461#define DINTRS_STR1_OR_S (1 << 16)
462#define DINTRS_CUR_UR_S (1 << 6)
463#define DINTRS_STR2_UR_S (1 << 5)
464#define DINTRS_STR1_UR_S (1 << 4)
465#define DINTRS_VEVENT1_S (1 << 3)
466#define DINTRS_VEVENT0_S (1 << 2)
467#define DINTRS_HBLNK1_S (1 << 1)
468#define DINTRS_HBLNK0_S (1 << 0)
469
470/* DINTRE - Display Interrupt Enable Register */
471#define DINTRE_CUR_OR_EN (1 << 18)
472#define DINTRE_STR2_OR_EN (1 << 17)
473#define DINTRE_STR1_OR_EN (1 << 16)
474#define DINTRE_CUR_UR_EN (1 << 6)
475#define DINTRE_STR2_UR_EN (1 << 5)
476#define DINTRE_STR1_UR_EN (1 << 4)
477#define DINTRE_VEVENT1_EN (1 << 3)
478#define DINTRE_VEVENT0_EN (1 << 2)
479#define DINTRE_HBLNK1_EN (1 << 1)
480#define DINTRE_HBLNK0_EN (1 << 0)
481
397 482
398/* DLSTS - display load status register */ 483/* DLSTS - display load status register */
399#define DLSTS_RLD_ADONE (1 << 23) 484#define DLSTS_RLD_ADONE (1 << 23)
@@ -403,16 +488,41 @@
403#define DLLCTRL_RLD_ADRLN Fld(8,24) 488#define DLLCTRL_RLD_ADRLN Fld(8,24)
404#define Dllctrl_Rld_Adrln(x) ((x) << FShft(DLLCTRL_RLD_ADRLN)) 489#define Dllctrl_Rld_Adrln(x) ((x) << FShft(DLLCTRL_RLD_ADRLN))
405 490
491/* CLIPCTRL - Clipping Control Register */
492#define CLIPCTRL_HSKIP Fld(11,16)
493#define Clipctrl_Hskip ((x) << FShft(CLIPCTRL_HSKIP))
494#define CLIPCTRL_VSKIP Fld(11,0)
495#define Clipctrl_Vskip ((x) << FShft(CLIPCTRL_VSKIP))
496
406/* SPOCTRL - Scale Pitch/Order Control Register */ 497/* SPOCTRL - Scale Pitch/Order Control Register */
407#define SPOCTRL_H_SC_BP (1 << 31) 498#define SPOCTRL_H_SC_BP (1 << 31)
408#define SPOCTRL_V_SC_BP (1 << 30) 499#define SPOCTRL_V_SC_BP (1 << 30)
409#define SPOCTRL_HV_SC_OR (1 << 29) 500#define SPOCTRL_HV_SC_OR (1 << 29)
410#define SPOCTRL_VS_UR_C (1 << 27) 501#define SPOCTRL_VS_UR_C (1 << 27)
411#define SPOCTRL_VORDER Fld(2,16) 502#define SPOCTRL_VORDER Fld(2,16)
412#define SPOCTRL_VORDER_1TAP ((0x0) << FShft(SPOCTRL_VORDER)) 503#define SPOCTRL_VORDER_1TAP ((0x0) << FShft(SPOCTRL_VORDER))
413#define SPOCTRL_VORDER_2TAP ((0x1) << FShft(SPOCTRL_VORDER)) 504#define SPOCTRL_VORDER_2TAP ((0x1) << FShft(SPOCTRL_VORDER))
414#define SPOCTRL_VORDER_4TAP ((0x3) << FShft(SPOCTRL_VORDER)) 505#define SPOCTRL_VORDER_4TAP ((0x3) << FShft(SPOCTRL_VORDER))
415#define SPOCTRL_VPITCH Fld(16,0) 506#define SPOCTRL_VPITCH Fld(16,0)
416#define Spoctrl_Vpitch(x) ((x) << FShft(SPOCTRL_VPITCH)) 507#define Spoctrl_Vpitch(x) ((x) << FShft(SPOCTRL_VPITCH))
417 508
509/* SVCTRL - Scale Vertical Control Register */
510#define SVCTRL_INITIAL1 Fld(16,16)
511#define Svctrl_Initial1(x) ((x) << FShft(SVCTRL_INITIAL1))
512#define SVCTRL_INITIAL2 Fld(16,0)
513#define Svctrl_Initial2(x) ((x) << FShft(SVCTRL_INITIAL2))
514
515/* SHCTRL - Scale Horizontal Control Register */
516#define SHCTRL_HINITIAL Fld(16,16)
517#define Shctrl_Hinitial(x) ((x) << FShft(SHCTRL_HINITIAL))
518#define SHCTRL_HDECIM (1 << 15)
519#define SHCTRL_HPITCH Fld(15,0)
520#define Shctrl_Hpitch(x) ((x) << FShft(SHCTRL_HPITCH))
521
522/* SSSIZE - Scale Surface Size Register */
523#define SSSIZE_SC_WIDTH Fld(11,16)
524#define Sssize_Sc_Width(x) ((x) << FShft(SSSIZE_SC_WIDTH))
525#define SSSIZE_SC_HEIGHT Fld(11,0)
526#define Sssize_Sc_Height(x) ((x) << FShft(SSSIZE_SC_HEIGHT))
527
418#endif /* __REG_BITS_2700G_ */ 528#endif /* __REG_BITS_2700G_ */
diff --git a/drivers/video/mbx/regs.h b/drivers/video/mbx/regs.h
index ad20be07666b..a7c63d865aad 100644
--- a/drivers/video/mbx/regs.h
+++ b/drivers/video/mbx/regs.h
@@ -127,7 +127,7 @@
127#define HSCOEFF0 __REG_2700G(0x000021b4) 127#define HSCOEFF0 __REG_2700G(0x000021b4)
128#define HSCOEFF1 __REG_2700G(0x000021b8) 128#define HSCOEFF1 __REG_2700G(0x000021b8)
129#define HSCOEFF2 __REG_2700G(0x000021bc) 129#define HSCOEFF2 __REG_2700G(0x000021bc)
130#define HSCOEFF3 __REG_2700G(0x000021b0) 130#define HSCOEFF3 __REG_2700G(0x000021c0)
131#define HSCOEFF4 __REG_2700G(0x000021c4) 131#define HSCOEFF4 __REG_2700G(0x000021c4)
132#define HSCOEFF5 __REG_2700G(0x000021c8) 132#define HSCOEFF5 __REG_2700G(0x000021c8)
133#define HSCOEFF6 __REG_2700G(0x000021cc) 133#define HSCOEFF6 __REG_2700G(0x000021cc)
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index d1267904c280..5df41f6f2b86 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -34,8 +34,6 @@ const char *global_mode_option;
34 * Standard video mode definitions (taken from XFree86) 34 * Standard video mode definitions (taken from XFree86)
35 */ 35 */
36 36
37#define DEFAULT_MODEDB_INDEX 0
38
39static const struct fb_videomode modedb[] = { 37static const struct fb_videomode modedb[] = {
40 { 38 {
41 /* 640x400 @ 70 Hz, 31.5 kHz hsync */ 39 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
@@ -505,8 +503,10 @@ int fb_find_mode(struct fb_var_screeninfo *var,
505 db = modedb; 503 db = modedb;
506 dbsize = ARRAY_SIZE(modedb); 504 dbsize = ARRAY_SIZE(modedb);
507 } 505 }
506
508 if (!default_mode) 507 if (!default_mode)
509 default_mode = &modedb[DEFAULT_MODEDB_INDEX]; 508 default_mode = &db[0];
509
510 if (!default_bpp) 510 if (!default_bpp)
511 default_bpp = 8; 511 default_bpp = 8;
512 512
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 59a6f5fa5ae6..deaf820cb38f 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -1932,7 +1932,7 @@ static int __devinit neo_init_hw(struct fb_info *info)
1932 printk(KERN_DEBUG "--- Neo extended register dump ---\n"); 1932 printk(KERN_DEBUG "--- Neo extended register dump ---\n");
1933 for (int w = 0; w < 0x85; w++) 1933 for (int w = 0; w < 0x85; w++)
1934 printk(KERN_DEBUG "CR %p: %p\n", (void *) w, 1934 printk(KERN_DEBUG "CR %p: %p\n", (void *) w,
1935 (void *) vga_rcrt(NULL, w); 1935 (void *) vga_rcrt(NULL, w));
1936 for (int w = 0; w < 0xC7; w++) 1936 for (int w = 0; w < 0xC7; w++)
1937 printk(KERN_DEBUG "GR %p: %p\n", (void *) w, 1937 printk(KERN_DEBUG "GR %p: %p\n", (void *) w,
1938 (void *) vga_rgfx(NULL, w)); 1938 (void *) vga_rgfx(NULL, w));
diff --git a/drivers/video/nvidia/nv_accel.c b/drivers/video/nvidia/nv_accel.c
index 4aefb8f41637..9efb8a3854e2 100644
--- a/drivers/video/nvidia/nv_accel.c
+++ b/drivers/video/nvidia/nv_accel.c
@@ -261,41 +261,6 @@ void NVResetGraphics(struct fb_info *info)
261 NVDmaKickoff(par); 261 NVDmaKickoff(par);
262} 262}
263 263
264u8 byte_rev[256] = {
265 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
266 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
267 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
268 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
269 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
270 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
271 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
272 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
273 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
274 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
275 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
276 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
277 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
278 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
279 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
280 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
281 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
282 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
283 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
284 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
285 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
286 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
287 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
288 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
289 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
290 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
291 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
292 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
293 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
294 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
295 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
296 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
297};
298
299int nvidiafb_sync(struct fb_info *info) 264int nvidiafb_sync(struct fb_info *info)
300{ 265{
301 struct nvidia_par *par = info->par; 266 struct nvidia_par *par = info->par;
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index 19eef3a09023..8454adf2d178 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -147,15 +147,15 @@ void nvidia_create_i2c_busses(struct nvidia_par *par)
147void nvidia_delete_i2c_busses(struct nvidia_par *par) 147void nvidia_delete_i2c_busses(struct nvidia_par *par)
148{ 148{
149 if (par->chan[0].par) 149 if (par->chan[0].par)
150 i2c_bit_del_bus(&par->chan[0].adapter); 150 i2c_del_adapter(&par->chan[0].adapter);
151 par->chan[0].par = NULL; 151 par->chan[0].par = NULL;
152 152
153 if (par->chan[1].par) 153 if (par->chan[1].par)
154 i2c_bit_del_bus(&par->chan[1].adapter); 154 i2c_del_adapter(&par->chan[1].adapter);
155 par->chan[1].par = NULL; 155 par->chan[1].par = NULL;
156 156
157 if (par->chan[2].par) 157 if (par->chan[2].par)
158 i2c_bit_del_bus(&par->chan[2].adapter); 158 i2c_del_adapter(&par->chan[2].adapter);
159 par->chan[2].par = NULL; 159 par->chan[2].par = NULL;
160 160
161} 161}
@@ -210,11 +210,8 @@ int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
210 /* try to get from firmware */ 210 /* try to get from firmware */
211 const u8 *e = fb_firmware_edid(info->device); 211 const u8 *e = fb_firmware_edid(info->device);
212 212
213 if (e != NULL) { 213 if (e != NULL)
214 edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 214 edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
215 if (edid)
216 memcpy(edid, e, EDID_LENGTH);
217 }
218 } 215 }
219 216
220 *out_edid = edid; 217 *out_edid = edid;
diff --git a/drivers/video/nvidia/nv_local.h b/drivers/video/nvidia/nv_local.h
index 4243d7fae972..e009d242ea10 100644
--- a/drivers/video/nvidia/nv_local.h
+++ b/drivers/video/nvidia/nv_local.h
@@ -96,13 +96,16 @@
96#define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2) 96#define READ_GET(par) (NV_RD32(&(par)->FIFO[0x0011], 0) >> 2)
97 97
98#ifdef __LITTLE_ENDIAN 98#ifdef __LITTLE_ENDIAN
99
100#include <linux/bitrev.h>
101
99#define reverse_order(l) \ 102#define reverse_order(l) \
100do { \ 103do { \
101 u8 *a = (u8 *)(l); \ 104 u8 *a = (u8 *)(l); \
102 *a = byte_rev[*a], a++; \ 105 a[0] = bitrev8(a[0]); \
103 *a = byte_rev[*a], a++; \ 106 a[1] = bitrev8(a[1]); \
104 *a = byte_rev[*a], a++; \ 107 a[2] = bitrev8(a[2]); \
105 *a = byte_rev[*a]; \ 108 a[3] = bitrev8(a[3]); \
106} while(0) 109} while(0)
107#else 110#else
108#define reverse_order(l) do { } while(0) 111#define reverse_order(l) do { } while(0)
diff --git a/drivers/video/nvidia/nv_of.c b/drivers/video/nvidia/nv_of.c
index d9af88c2b580..181875fe35c6 100644
--- a/drivers/video/nvidia/nv_of.c
+++ b/drivers/video/nvidia/nv_of.c
@@ -72,10 +72,9 @@ int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
72 } 72 }
73 } 73 }
74 if (pedid) { 74 if (pedid) {
75 *out_edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 75 *out_edid = kmemdup(pedid, EDID_LENGTH, GFP_KERNEL);
76 if (*out_edid == NULL) 76 if (*out_edid == NULL)
77 return -1; 77 return -1;
78 memcpy(*out_edid, pedid, EDID_LENGTH);
79 printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn); 78 printk(KERN_DEBUG "nvidiafb: Found OF EDID for head %d\n", conn);
80 return 0; 79 return 0;
81 } 80 }
diff --git a/drivers/video/nvidia/nv_proto.h b/drivers/video/nvidia/nv_proto.h
index 861271017655..43058d0cf5b7 100644
--- a/drivers/video/nvidia/nv_proto.h
+++ b/drivers/video/nvidia/nv_proto.h
@@ -62,7 +62,6 @@ extern void nvidiafb_fillrect(struct fb_info *info,
62extern void nvidiafb_imageblit(struct fb_info *info, 62extern void nvidiafb_imageblit(struct fb_info *info,
63 const struct fb_image *image); 63 const struct fb_image *image);
64extern int nvidiafb_sync(struct fb_info *info); 64extern int nvidiafb_sync(struct fb_info *info);
65extern u8 byte_rev[256];
66 65
67/* in nv_backlight.h */ 66/* in nv_backlight.h */
68#ifdef CONFIG_FB_NVIDIA_BACKLIGHT 67#ifdef CONFIG_FB_NVIDIA_BACKLIGHT
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 9a40bbecf76b..9576a55eaf16 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -402,6 +402,9 @@ static void __init offb_init_fb(const char *name, const char *full_name,
402 fb_alloc_cmap(&info->cmap, 256, 0); 402 fb_alloc_cmap(&info->cmap, 256, 0);
403 403
404 if (register_framebuffer(info) < 0) { 404 if (register_framebuffer(info) < 0) {
405 iounmap(par->cmap_adr);
406 par->cmap_adr = NULL;
407 iounmap(info->screen_base);
405 kfree(info); 408 kfree(info);
406 release_mem_region(res_start, res_size); 409 release_mem_region(res_start, res_size);
407 return; 410 return;
diff --git a/drivers/video/platinumfb.c b/drivers/video/platinumfb.c
index cb26c6df0583..233871655824 100644
--- a/drivers/video/platinumfb.c
+++ b/drivers/video/platinumfb.c
@@ -627,6 +627,9 @@ static int __devinit platinumfb_probe(struct of_device* odev,
627 627
628 rc = platinum_init_fb(info); 628 rc = platinum_init_fb(info);
629 if (rc != 0) { 629 if (rc != 0) {
630 iounmap(pinfo->frame_buffer);
631 iounmap(pinfo->platinum_regs);
632 iounmap(pinfo->cmap_regs);
630 dev_set_drvdata(&odev->dev, NULL); 633 dev_set_drvdata(&odev->dev, NULL);
631 framebuffer_release(info); 634 framebuffer_release(info);
632 } 635 }
diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c
index 73e2d7d16608..a06a064ad757 100644
--- a/drivers/video/pmagb-b-fb.c
+++ b/drivers/video/pmagb-b-fb.c
@@ -186,7 +186,7 @@ static void __init pmagbbfb_screen_setup(struct fb_info *info)
186static void __init pmagbbfb_osc_setup(struct fb_info *info) 186static void __init pmagbbfb_osc_setup(struct fb_info *info)
187{ 187{
188 static unsigned int pmagbbfb_freqs[] __initdata = { 188 static unsigned int pmagbbfb_freqs[] __initdata = {
189 130808, 119843, 104000, 92980, 74367, 72800, 189 130808, 119843, 104000, 92980, 74370, 72800,
190 69197, 66000, 65000, 50350, 36000, 32000, 25175 190 69197, 66000, 65000, 50350, 36000, 32000, 25175
191 }; 191 };
192 struct pmagbbfb_par *par = info->par; 192 struct pmagbbfb_par *par = info->par;
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index c7bc80921f16..a93618bc9d27 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -905,6 +905,15 @@ static int __init pvr2fb_dc_init(void)
905 905
906static void pvr2fb_dc_exit(void) 906static void pvr2fb_dc_exit(void)
907{ 907{
908 if (fb_info->screen_base) {
909 iounmap(fb_info->screen_base);
910 fb_info->screen_base = NULL;
911 }
912 if (currentpar->mmio_base) {
913 iounmap((void *)currentpar->mmio_base);
914 currentpar->mmio_base = 0;
915 }
916
908 free_irq(HW_EVENT_VSYNC, 0); 917 free_irq(HW_EVENT_VSYNC, 0);
909#ifdef CONFIG_SH_DMA 918#ifdef CONFIG_SH_DMA
910 free_dma(pvr2dma); 919 free_dma(pvr2dma);
@@ -946,6 +955,15 @@ static int __devinit pvr2fb_pci_probe(struct pci_dev *pdev,
946 955
947static void __devexit pvr2fb_pci_remove(struct pci_dev *pdev) 956static void __devexit pvr2fb_pci_remove(struct pci_dev *pdev)
948{ 957{
958 if (fb_info->screen_base) {
959 iounmap(fb_info->screen_base);
960 fb_info->screen_base = NULL;
961 }
962 if (currentpar->mmio_base) {
963 iounmap((void *)currentpar->mmio_base);
964 currentpar->mmio_base = 0;
965 }
966
949 pci_release_regions(pdev); 967 pci_release_regions(pdev);
950} 968}
951 969
diff --git a/drivers/video/retz3fb.c b/drivers/video/retz3fb.c
index cf41ff177644..bc7ffc84e185 100644
--- a/drivers/video/retz3fb.c
+++ b/drivers/video/retz3fb.c
@@ -1423,8 +1423,10 @@ int __init retz3fb_init(void)
1423 1423
1424 do_install_cmap(0, fb_info); 1424 do_install_cmap(0, fb_info);
1425 1425
1426 if (register_framebuffer(fb_info) < 0) 1426 if (register_framebuffer(fb_info) < 0) {
1427 iounmap(zinfo->base);
1427 return -EINVAL; 1428 return -EINVAL;
1429 }
1428 1430
1429 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of " 1431 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of "
1430 "video memory\n", fb_info->node, 1432 "video memory\n", fb_info->node,
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index a433cc78ef90..345e8b1c1af8 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -40,6 +40,7 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/pci.h> 41#include <linux/pci.h>
42#include <linux/backlight.h> 42#include <linux/backlight.h>
43#include <linux/bitrev.h>
43#ifdef CONFIG_MTRR 44#ifdef CONFIG_MTRR
44#include <asm/mtrr.h> 45#include <asm/mtrr.h>
45#endif 46#endif
@@ -521,48 +522,13 @@ static inline unsigned char MISCin(struct riva_par *par)
521 return (VGA_RD08(par->riva.PVIO, 0x3cc)); 522 return (VGA_RD08(par->riva.PVIO, 0x3cc));
522} 523}
523 524
524static u8 byte_rev[256] = {
525 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
526 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
527 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
528 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
529 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
530 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
531 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
532 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
533 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
534 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
535 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
536 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
537 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
538 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
539 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
540 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
541 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
542 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
543 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
544 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
545 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
546 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
547 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
548 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
549 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
550 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
551 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
552 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
553 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
554 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
555 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
556 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
557};
558
559static inline void reverse_order(u32 *l) 525static inline void reverse_order(u32 *l)
560{ 526{
561 u8 *a = (u8 *)l; 527 u8 *a = (u8 *)l;
562 *a = byte_rev[*a], a++; 528 a[0] = bitrev8(a[0]);
563 *a = byte_rev[*a], a++; 529 a[1] = bitrev8(a[1]);
564 *a = byte_rev[*a], a++; 530 a[2] = bitrev8(a[2]);
565 *a = byte_rev[*a]; 531 a[3] = bitrev8(a[3]);
566} 532}
567 533
568/* ------------------------------------------------------------------------- * 534/* ------------------------------------------------------------------------- *
@@ -774,11 +740,12 @@ static void riva_load_state(struct riva_par *par, struct riva_regs *regs)
774 * CALLED FROM: 740 * CALLED FROM:
775 * rivafb_set_par() 741 * rivafb_set_par()
776 */ 742 */
777static void riva_load_video_mode(struct fb_info *info) 743static int riva_load_video_mode(struct fb_info *info)
778{ 744{
779 int bpp, width, hDisplaySize, hDisplay, hStart, 745 int bpp, width, hDisplaySize, hDisplay, hStart,
780 hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock; 746 hEnd, hTotal, height, vDisplay, vStart, vEnd, vTotal, dotClock;
781 int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd; 747 int hBlankStart, hBlankEnd, vBlankStart, vBlankEnd;
748 int rc;
782 struct riva_par *par = info->par; 749 struct riva_par *par = info->par;
783 struct riva_regs newmode; 750 struct riva_regs newmode;
784 751
@@ -884,8 +851,10 @@ static void riva_load_video_mode(struct fb_info *info)
884 else 851 else
885 newmode.misc_output |= 0x80; 852 newmode.misc_output |= 0x80;
886 853
887 par->riva.CalcStateExt(&par->riva, &newmode.ext, bpp, width, 854 rc = CalcStateExt(&par->riva, &newmode.ext, bpp, width,
888 hDisplaySize, height, dotClock); 855 hDisplaySize, height, dotClock);
856 if (rc)
857 goto out;
889 858
890 newmode.ext.scale = NV_RD32(par->riva.PRAMDAC, 0x00000848) & 859 newmode.ext.scale = NV_RD32(par->riva.PRAMDAC, 0x00000848) &
891 0xfff000ff; 860 0xfff000ff;
@@ -917,8 +886,12 @@ static void riva_load_video_mode(struct fb_info *info)
917 par->current_state = newmode; 886 par->current_state = newmode;
918 riva_load_state(par, &par->current_state); 887 riva_load_state(par, &par->current_state);
919 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */ 888 par->riva.LockUnlock(&par->riva, 0); /* important for HW cursor */
889
890out:
920 rivafb_blank(FB_BLANK_UNBLANK, info); 891 rivafb_blank(FB_BLANK_UNBLANK, info);
921 NVTRACE_LEAVE(); 892 NVTRACE_LEAVE();
893
894 return rc;
922} 895}
923 896
924static void riva_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb) 897static void riva_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb)
@@ -1286,12 +1259,15 @@ static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1286static int rivafb_set_par(struct fb_info *info) 1259static int rivafb_set_par(struct fb_info *info)
1287{ 1260{
1288 struct riva_par *par = info->par; 1261 struct riva_par *par = info->par;
1262 int rc = 0;
1289 1263
1290 NVTRACE_ENTER(); 1264 NVTRACE_ENTER();
1291 /* vgaHWunlock() + riva unlock (0x7F) */ 1265 /* vgaHWunlock() + riva unlock (0x7F) */
1292 CRTCout(par, 0x11, 0xFF); 1266 CRTCout(par, 0x11, 0xFF);
1293 par->riva.LockUnlock(&par->riva, 0); 1267 par->riva.LockUnlock(&par->riva, 0);
1294 riva_load_video_mode(info); 1268 rc = riva_load_video_mode(info);
1269 if (rc)
1270 goto out;
1295 if(!(info->flags & FBINFO_HWACCEL_DISABLED)) 1271 if(!(info->flags & FBINFO_HWACCEL_DISABLED))
1296 riva_setup_accel(info); 1272 riva_setup_accel(info);
1297 1273
@@ -1304,8 +1280,10 @@ static int rivafb_set_par(struct fb_info *info)
1304 info->pixmap.scan_align = 1; 1280 info->pixmap.scan_align = 1;
1305 else 1281 else
1306 info->pixmap.scan_align = 4; 1282 info->pixmap.scan_align = 4;
1283
1284out:
1307 NVTRACE_LEAVE(); 1285 NVTRACE_LEAVE();
1308 return 0; 1286 return rc;
1309} 1287}
1310 1288
1311/** 1289/**
diff --git a/drivers/video/riva/riva_hw.c b/drivers/video/riva/riva_hw.c
index b6f8690b96c9..e0b8c521cc9c 100644
--- a/drivers/video/riva/riva_hw.c
+++ b/drivers/video/riva/riva_hw.c
@@ -1227,7 +1227,7 @@ static int CalcVClock
1227 * Calculate extended mode parameters (SVGA) and save in a 1227 * Calculate extended mode parameters (SVGA) and save in a
1228 * mode state structure. 1228 * mode state structure.
1229 */ 1229 */
1230static void CalcStateExt 1230int CalcStateExt
1231( 1231(
1232 RIVA_HW_INST *chip, 1232 RIVA_HW_INST *chip,
1233 RIVA_HW_STATE *state, 1233 RIVA_HW_STATE *state,
@@ -1249,7 +1249,8 @@ static void CalcStateExt
1249 * Extended RIVA registers. 1249 * Extended RIVA registers.
1250 */ 1250 */
1251 pixelDepth = (bpp + 1)/8; 1251 pixelDepth = (bpp + 1)/8;
1252 CalcVClock(dotClock, &VClk, &m, &n, &p, chip); 1252 if (!CalcVClock(dotClock, &VClk, &m, &n, &p, chip))
1253 return -EINVAL;
1253 1254
1254 switch (chip->Architecture) 1255 switch (chip->Architecture)
1255 { 1256 {
@@ -1327,6 +1328,8 @@ static void CalcStateExt
1327 state->pitch1 = 1328 state->pitch1 =
1328 state->pitch2 = 1329 state->pitch2 =
1329 state->pitch3 = pixelDepth * width; 1330 state->pitch3 = pixelDepth * width;
1331
1332 return 0;
1330} 1333}
1331/* 1334/*
1332 * Load fixed function state and pre-calculated/stored state. 1335 * Load fixed function state and pre-calculated/stored state.
@@ -2026,7 +2029,6 @@ static void nv3GetConfig
2026 */ 2029 */
2027 chip->Busy = nv3Busy; 2030 chip->Busy = nv3Busy;
2028 chip->ShowHideCursor = ShowHideCursor; 2031 chip->ShowHideCursor = ShowHideCursor;
2029 chip->CalcStateExt = CalcStateExt;
2030 chip->LoadStateExt = LoadStateExt; 2032 chip->LoadStateExt = LoadStateExt;
2031 chip->UnloadStateExt = UnloadStateExt; 2033 chip->UnloadStateExt = UnloadStateExt;
2032 chip->SetStartAddress = SetStartAddress3; 2034 chip->SetStartAddress = SetStartAddress3;
@@ -2084,7 +2086,6 @@ static void nv4GetConfig
2084 */ 2086 */
2085 chip->Busy = nv4Busy; 2087 chip->Busy = nv4Busy;
2086 chip->ShowHideCursor = ShowHideCursor; 2088 chip->ShowHideCursor = ShowHideCursor;
2087 chip->CalcStateExt = CalcStateExt;
2088 chip->LoadStateExt = LoadStateExt; 2089 chip->LoadStateExt = LoadStateExt;
2089 chip->UnloadStateExt = UnloadStateExt; 2090 chip->UnloadStateExt = UnloadStateExt;
2090 chip->SetStartAddress = SetStartAddress; 2091 chip->SetStartAddress = SetStartAddress;
@@ -2186,7 +2187,6 @@ static void nv10GetConfig
2186 */ 2187 */
2187 chip->Busy = nv10Busy; 2188 chip->Busy = nv10Busy;
2188 chip->ShowHideCursor = ShowHideCursor; 2189 chip->ShowHideCursor = ShowHideCursor;
2189 chip->CalcStateExt = CalcStateExt;
2190 chip->LoadStateExt = LoadStateExt; 2190 chip->LoadStateExt = LoadStateExt;
2191 chip->UnloadStateExt = UnloadStateExt; 2191 chip->UnloadStateExt = UnloadStateExt;
2192 chip->SetStartAddress = SetStartAddress; 2192 chip->SetStartAddress = SetStartAddress;
diff --git a/drivers/video/riva/riva_hw.h b/drivers/video/riva/riva_hw.h
index a1e71a626df2..c2769f73e0b2 100644
--- a/drivers/video/riva/riva_hw.h
+++ b/drivers/video/riva/riva_hw.h
@@ -463,7 +463,6 @@ typedef struct _riva_hw_inst
463 * Common chip functions. 463 * Common chip functions.
464 */ 464 */
465 int (*Busy)(struct _riva_hw_inst *); 465 int (*Busy)(struct _riva_hw_inst *);
466 void (*CalcStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *,int,int,int,int,int);
467 void (*LoadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *); 466 void (*LoadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
468 void (*UnloadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *); 467 void (*UnloadStateExt)(struct _riva_hw_inst *,struct _riva_hw_state *);
469 void (*SetStartAddress)(struct _riva_hw_inst *,U032); 468 void (*SetStartAddress)(struct _riva_hw_inst *,U032);
@@ -528,6 +527,22 @@ typedef struct _riva_hw_state
528 U032 pitch2; 527 U032 pitch2;
529 U032 pitch3; 528 U032 pitch3;
530} RIVA_HW_STATE; 529} RIVA_HW_STATE;
530
531/*
532 * function prototypes
533 */
534
535extern int CalcStateExt
536(
537 RIVA_HW_INST *chip,
538 RIVA_HW_STATE *state,
539 int bpp,
540 int width,
541 int hDisplaySize,
542 int height,
543 int dotClock
544);
545
531/* 546/*
532 * External routines. 547 * External routines.
533 */ 548 */
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index c15b259af644..01b85e3b0ae1 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -144,15 +144,15 @@ void riva_create_i2c_busses(struct riva_par *par)
144void riva_delete_i2c_busses(struct riva_par *par) 144void riva_delete_i2c_busses(struct riva_par *par)
145{ 145{
146 if (par->chan[0].par) 146 if (par->chan[0].par)
147 i2c_bit_del_bus(&par->chan[0].adapter); 147 i2c_del_adapter(&par->chan[0].adapter);
148 par->chan[0].par = NULL; 148 par->chan[0].par = NULL;
149 149
150 if (par->chan[1].par) 150 if (par->chan[1].par)
151 i2c_bit_del_bus(&par->chan[1].adapter); 151 i2c_del_adapter(&par->chan[1].adapter);
152 par->chan[1].par = NULL; 152 par->chan[1].par = NULL;
153 153
154 if (par->chan[2].par) 154 if (par->chan[2].par)
155 i2c_bit_del_bus(&par->chan[2].adapter); 155 i2c_del_adapter(&par->chan[2].adapter);
156 par->chan[2].par = NULL; 156 par->chan[2].par = NULL;
157} 157}
158 158
diff --git a/drivers/video/s3c2410fb.c b/drivers/video/s3c2410fb.c
index 59407343cc73..ccef56d0c157 100644
--- a/drivers/video/s3c2410fb.c
+++ b/drivers/video/s3c2410fb.c
@@ -131,7 +131,7 @@ static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi)
131 saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8; 131 saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8;
132 saddr2>>= 1; 132 saddr2>>= 1;
133 133
134 saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH(var->xres); 134 saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH((var->xres * var->bits_per_pixel / 16) & 0x3ff);
135 135
136 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1); 136 dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
137 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2); 137 dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
@@ -199,28 +199,86 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
199 var->bits_per_pixel = fbi->mach_info->bpp.min; 199 var->bits_per_pixel = fbi->mach_info->bpp.min;
200 200
201 /* set r/g/b positions */ 201 /* set r/g/b positions */
202 switch (var->bits_per_pixel) {
203 case 1:
204 case 2:
205 case 4:
206 var->red.offset = 0;
207 var->red.length = var->bits_per_pixel;
208 var->green = var->red;
209 var->blue = var->red;
210 var->transp.offset = 0;
211 var->transp.length = 0;
212 break;
213 case 8:
214 if ( fbi->mach_info->type != S3C2410_LCDCON1_TFT ) {
215 /* 8 bpp 332 */
216 var->red.length = 3;
217 var->red.offset = 5;
218 var->green.length = 3;
219 var->green.offset = 2;
220 var->blue.length = 2;
221 var->blue.offset = 0;
222 var->transp.length = 0;
223 } else {
224 var->red.offset = 0;
225 var->red.length = var->bits_per_pixel;
226 var->green = var->red;
227 var->blue = var->red;
228 var->transp.offset = 0;
229 var->transp.length = 0;
230 }
231 break;
232 case 12:
233 /* 12 bpp 444 */
234 var->red.length = 4;
235 var->red.offset = 8;
236 var->green.length = 4;
237 var->green.offset = 4;
238 var->blue.length = 4;
239 var->blue.offset = 0;
240 var->transp.length = 0;
241 break;
242
243 default:
244 case 16:
245 if (fbi->regs.lcdcon5 & S3C2410_LCDCON5_FRM565 ) {
246 /* 16 bpp, 565 format */
247 var->red.offset = 11;
248 var->green.offset = 5;
249 var->blue.offset = 0;
250 var->red.length = 5;
251 var->green.length = 6;
252 var->blue.length = 5;
253 var->transp.length = 0;
254 } else {
255 /* 16 bpp, 5551 format */
256 var->red.offset = 11;
257 var->green.offset = 6;
258 var->blue.offset = 1;
259 var->red.length = 5;
260 var->green.length = 5;
261 var->blue.length = 5;
262 var->transp.length = 0;
263 }
264 break;
265 case 24:
266 /* 24 bpp 888 */
267 var->red.length = 8;
268 var->red.offset = 16;
269 var->green.length = 8;
270 var->green.offset = 8;
271 var->blue.length = 8;
272 var->blue.offset = 0;
273 var->transp.length = 0;
274 break;
202 275
203 if (var->bits_per_pixel == 16) {
204 var->red.offset = 11;
205 var->green.offset = 5;
206 var->blue.offset = 0;
207 var->red.length = 5;
208 var->green.length = 6;
209 var->blue.length = 5;
210 var->transp.length = 0;
211 } else {
212 var->red.length = var->bits_per_pixel;
213 var->red.offset = 0;
214 var->green.length = var->bits_per_pixel;
215 var->green.offset = 0;
216 var->blue.length = var->bits_per_pixel;
217 var->blue.offset = 0;
218 var->transp.length = 0;
219 }
220 276
277 }
221 return 0; 278 return 0;
222} 279}
223 280
281
224/* s3c2410fb_activate_var 282/* s3c2410fb_activate_var
225 * 283 *
226 * activate (set) the controller from the given framebuffer 284 * activate (set) the controller from the given framebuffer
@@ -230,29 +288,61 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
230static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi, 288static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
231 struct fb_var_screeninfo *var) 289 struct fb_var_screeninfo *var)
232{ 290{
291 int hs;
292
233 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK; 293 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_MODEMASK;
294 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_TFT;
234 295
235 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres); 296 dprintk("%s: var->xres = %d\n", __FUNCTION__, var->xres);
236 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres); 297 dprintk("%s: var->yres = %d\n", __FUNCTION__, var->yres);
237 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel); 298 dprintk("%s: var->bpp = %d\n", __FUNCTION__, var->bits_per_pixel);
238 299
239 switch (var->bits_per_pixel) { 300 fbi->regs.lcdcon1 |= fbi->mach_info->type;
240 case 1: 301
241 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT1BPP; 302 if (fbi->mach_info->type == S3C2410_LCDCON1_TFT)
242 break; 303 switch (var->bits_per_pixel) {
243 case 2: 304 case 1:
244 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT2BPP; 305 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT1BPP;
245 break; 306 break;
246 case 4: 307 case 2:
247 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT4BPP; 308 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT2BPP;
248 break; 309 break;
249 case 8: 310 case 4:
250 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT8BPP; 311 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT4BPP;
251 break; 312 break;
252 case 16: 313 case 8:
253 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT16BPP; 314 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT8BPP;
254 break; 315 break;
255 } 316 case 16:
317 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_TFT16BPP;
318 break;
319
320 default:
321 /* invalid pixel depth */
322 dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel);
323 }
324 else
325 switch (var->bits_per_pixel) {
326 case 1:
327 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN1BPP;
328 break;
329 case 2:
330 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN2GREY;
331 break;
332 case 4:
333 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN4GREY;
334 break;
335 case 8:
336 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN8BPP;
337 break;
338 case 12:
339 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_STN12BPP;
340 break;
341
342 default:
343 /* invalid pixel depth */
344 dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel);
345 }
256 346
257 /* check to see if we need to update sync/borders */ 347 /* check to see if we need to update sync/borders */
258 348
@@ -283,15 +373,44 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
283 fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff); 373 fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff);
284 fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1); 374 fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1);
285 375
376 switch(fbi->mach_info->type) {
377 case S3C2410_LCDCON1_DSCAN4:
378 case S3C2410_LCDCON1_STN8:
379 hs = var->xres / 8;
380 break;
381 case S3C2410_LCDCON1_STN4:
382 hs = var->xres / 4;
383 break;
384 default:
385 case S3C2410_LCDCON1_TFT:
386 hs = var->xres;
387 break;
388
389 }
390
391 /* Special cases : STN color displays */
392 if ( ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN8BPP) \
393 || ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN12BPP) ) {
394 hs = hs * 3;
395 }
396
397
286 fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff); 398 fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff);
287 fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(var->xres - 1); 399 fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(hs - 1);
288 400
289 if (var->pixclock > 0) { 401 if (var->pixclock > 0) {
290 int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock); 402 int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock);
291 403
292 clkdiv = (clkdiv / 2) -1; 404 if (fbi->mach_info->type == S3C2410_LCDCON1_TFT) {
293 if (clkdiv < 0) 405 clkdiv = (clkdiv / 2) -1;
294 clkdiv = 0; 406 if (clkdiv < 0)
407 clkdiv = 0;
408 }
409 else {
410 clkdiv = (clkdiv / 2);
411 if (clkdiv < 2)
412 clkdiv = 2;
413 }
295 414
296 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff); 415 fbi->regs.lcdcon1 &= ~S3C2410_LCDCON1_CLKVAL(0x3ff);
297 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv); 416 fbi->regs.lcdcon1 |= S3C2410_LCDCON1_CLKVAL(clkdiv);
@@ -329,10 +448,18 @@ static int s3c2410fb_set_par(struct fb_info *info)
329 struct s3c2410fb_info *fbi = info->par; 448 struct s3c2410fb_info *fbi = info->par;
330 struct fb_var_screeninfo *var = &info->var; 449 struct fb_var_screeninfo *var = &info->var;
331 450
332 if (var->bits_per_pixel == 16) 451 switch (var->bits_per_pixel)
333 fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR; 452 {
334 else 453 case 16:
335 fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR; 454 fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR;
455 break;
456 case 1:
457 fbi->fb->fix.visual = FB_VISUAL_MONO01;
458 break;
459 default:
460 fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR;
461 break;
462 }
336 463
337 fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8; 464 fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8;
338 465
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 3f94223b7f0c..1411f3b6a009 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -208,7 +208,7 @@ void savagefb_delete_i2c_busses(struct fb_info *info)
208 struct savagefb_par *par = info->par; 208 struct savagefb_par *par = info->par;
209 209
210 if (par->chan.par) 210 if (par->chan.par)
211 i2c_bit_del_bus(&par->chan.adapter); 211 i2c_del_adapter(&par->chan.adapter);
212 212
213 par->chan.par = NULL; 213 par->chan.par = NULL;
214} 214}
@@ -227,11 +227,8 @@ int savagefb_probe_i2c_connector(struct fb_info *info, u8 **out_edid)
227 /* try to get from firmware */ 227 /* try to get from firmware */
228 const u8 *e = fb_firmware_edid(info->device); 228 const u8 *e = fb_firmware_edid(info->device);
229 229
230 if (e) { 230 if (e)
231 edid = kmalloc(EDID_LENGTH, GFP_KERNEL); 231 edid = kmemdup(e, EDID_LENGTH, GFP_KERNEL);
232 if (edid)
233 memcpy(edid, e, EDID_LENGTH);
234 }
235 } 232 }
236 233
237 *out_edid = edid; 234 *out_edid = edid;
diff --git a/drivers/video/sis/init301.c b/drivers/video/sis/init301.c
index f13faddc6181..47e1896cffeb 100644
--- a/drivers/video/sis/init301.c
+++ b/drivers/video/sis/init301.c
@@ -445,11 +445,8 @@ SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
445void 445void
446SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime) 446SiS_DDC2Delay(struct SiS_Private *SiS_Pr, unsigned int delaytime)
447{ 447{
448 unsigned int i, j; 448 while (delaytime-- > 0)
449 449 SiS_GetReg(SiS_Pr->SiS_P3c4, 0x05);
450 for(i = 0; i < delaytime; i++) {
451 j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
452 }
453} 450}
454 451
455#if defined(SIS300) || defined(SIS315H) 452#if defined(SIS300) || defined(SIS315H)
diff --git a/drivers/video/stifb.c b/drivers/video/stifb.c
index 3e16e2d9d55d..69f3b264a22e 100644
--- a/drivers/video/stifb.c
+++ b/drivers/video/stifb.c
@@ -1291,6 +1291,7 @@ out_err3:
1291out_err2: 1291out_err2:
1292 release_mem_region(fix->smem_start, fix->smem_len); 1292 release_mem_region(fix->smem_start, fix->smem_len);
1293out_err1: 1293out_err1:
1294 iounmap(info->screen_base);
1294 fb_dealloc_cmap(&info->cmap); 1295 fb_dealloc_cmap(&info->cmap);
1295out_err0: 1296out_err0:
1296 kfree(fb); 1297 kfree(fb);
@@ -1364,6 +1365,8 @@ stifb_cleanup(void)
1364 unregister_framebuffer(sti->info); 1365 unregister_framebuffer(sti->info);
1365 release_mem_region(info->fix.mmio_start, info->fix.mmio_len); 1366 release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
1366 release_mem_region(info->fix.smem_start, info->fix.smem_len); 1367 release_mem_region(info->fix.smem_start, info->fix.smem_len);
1368 if (info->screen_base)
1369 iounmap(info->screen_base);
1367 fb_dealloc_cmap(&info->cmap); 1370 fb_dealloc_cmap(&info->cmap);
1368 kfree(info); 1371 kfree(info);
1369 } 1372 }
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 94fde625a6c0..4b88fab83b74 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -23,6 +23,7 @@
23#include <linux/fb.h> 23#include <linux/fb.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/selection.h> 25#include <linux/selection.h>
26#include <linux/bitrev.h>
26#include <asm/io.h> 27#include <asm/io.h>
27#include <video/tgafb.h> 28#include <video/tgafb.h>
28 29
@@ -517,41 +518,6 @@ tgafb_blank(int blank, struct fb_info *info)
517static void 518static void
518tgafb_imageblit(struct fb_info *info, const struct fb_image *image) 519tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
519{ 520{
520 static unsigned char const bitrev[256] = {
521 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
522 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
523 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
524 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
525 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
526 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
527 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
528 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
529 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
530 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
531 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
532 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
533 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
534 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
535 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
536 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
537 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
538 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
539 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
540 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
541 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
542 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
543 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
544 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
545 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
546 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
547 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
548 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
549 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
550 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
551 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
552 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
553 };
554
555 struct tga_par *par = (struct tga_par *) info->par; 521 struct tga_par *par = (struct tga_par *) info->par;
556 u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask; 522 u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask;
557 unsigned long rincr, line_length, shift, pos, is8bpp; 523 unsigned long rincr, line_length, shift, pos, is8bpp;
@@ -649,7 +615,7 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
649 /* The image data is bit big endian; we need 615 /* The image data is bit big endian; we need
650 little endian. */ 616 little endian. */
651 for (j = 0; j < bwidth; ++j) 617 for (j = 0; j < bwidth; ++j)
652 mask |= bitrev[data[j]] << (j * 8); 618 mask |= bitrev8(data[j]) << (j * 8);
653 619
654 __raw_writel(mask << shift, fb_base + pos); 620 __raw_writel(mask << shift, fb_base + pos);
655 621
@@ -676,10 +642,10 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
676 for (i = 0; i < height; ++i) { 642 for (i = 0; i < height; ++i) {
677 for (j = 0; j < bwidth; j += 4) { 643 for (j = 0; j < bwidth; j += 4) {
678 u32 mask = 0; 644 u32 mask = 0;
679 mask |= bitrev[data[j+0]] << (0 * 8); 645 mask |= bitrev8(data[j+0]) << (0 * 8);
680 mask |= bitrev[data[j+1]] << (1 * 8); 646 mask |= bitrev8(data[j+1]) << (1 * 8);
681 mask |= bitrev[data[j+2]] << (2 * 8); 647 mask |= bitrev8(data[j+2]) << (2 * 8);
682 mask |= bitrev[data[j+3]] << (3 * 8); 648 mask |= bitrev8(data[j+3]) << (3 * 8);
683 __raw_writel(mask, fb_base + pos + j*bincr); 649 __raw_writel(mask, fb_base + pos + j*bincr);
684 } 650 }
685 pos += line_length; 651 pos += line_length;
@@ -699,7 +665,7 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
699 for (i = 0; i < height; ++i) { 665 for (i = 0; i < height; ++i) {
700 u32 mask = 0; 666 u32 mask = 0;
701 for (j = 0; j < bwidth; ++j) 667 for (j = 0; j < bwidth; ++j)
702 mask |= bitrev[data[j]] << (j * 8); 668 mask |= bitrev8(data[j]) << (j * 8);
703 __raw_writel(mask, fb_base + pos); 669 __raw_writel(mask, fb_base + pos);
704 pos += line_length; 670 pos += line_length;
705 data += rincr; 671 data += rincr;
@@ -726,8 +692,8 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
726 for (i = 0; i < height; ++i) { 692 for (i = 0; i < height; ++i) {
727 for (j = 0; j < bwidth; j += 2) { 693 for (j = 0; j < bwidth; j += 2) {
728 u32 mask = 0; 694 u32 mask = 0;
729 mask |= bitrev[data[j+0]] << (0 * 8); 695 mask |= bitrev8(data[j+0]) << (0 * 8);
730 mask |= bitrev[data[j+1]] << (1 * 8); 696 mask |= bitrev8(data[j+1]) << (1 * 8);
731 mask <<= shift; 697 mask <<= shift;
732 __raw_writel(mask, fb_base + pos + j*bincr); 698 __raw_writel(mask, fb_base + pos + j*bincr);
733 } 699 }
@@ -746,9 +712,9 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
746 bwidth = (width & 15) > 8; 712 bwidth = (width & 15) > 8;
747 713
748 for (i = 0; i < height; ++i) { 714 for (i = 0; i < height; ++i) {
749 u32 mask = bitrev[data[0]]; 715 u32 mask = bitrev8(data[0]);
750 if (bwidth) 716 if (bwidth)
751 mask |= bitrev[data[1]] << 8; 717 mask |= bitrev8(data[1]) << 8;
752 mask <<= shift; 718 mask <<= shift;
753 __raw_writel(mask, fb_base + pos); 719 __raw_writel(mask, fb_base + pos);
754 pos += line_length; 720 pos += line_length;
@@ -1473,6 +1439,8 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1473 return 0; 1439 return 0;
1474 1440
1475 err1: 1441 err1:
1442 if (mem_base)
1443 iounmap(mem_base);
1476 release_mem_region(bar0_start, bar0_len); 1444 release_mem_region(bar0_start, bar0_len);
1477 err0: 1445 err0:
1478 kfree(all); 1446 kfree(all);
diff --git a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
index 14175cdb9c9c..55e8aa450bfa 100644
--- a/drivers/video/tridentfb.c
+++ b/drivers/video/tridentfb.c
@@ -1130,7 +1130,8 @@ static int __devinit trident_pci_probe(struct pci_dev * dev, const struct pci_de
1130 1130
1131 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) { 1131 if (!request_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len, "tridentfb")) {
1132 debug("request_mem_region failed!\n"); 1132 debug("request_mem_region failed!\n");
1133 return -1; 1133 err = -1;
1134 goto out_unmap;
1134 } 1135 }
1135 1136
1136 fb_info.screen_base = ioremap_nocache(tridentfb_fix.smem_start, 1137 fb_info.screen_base = ioremap_nocache(tridentfb_fix.smem_start,
@@ -1139,7 +1140,8 @@ static int __devinit trident_pci_probe(struct pci_dev * dev, const struct pci_de
1139 if (!fb_info.screen_base) { 1140 if (!fb_info.screen_base) {
1140 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len); 1141 release_mem_region(tridentfb_fix.smem_start, tridentfb_fix.smem_len);
1141 debug("ioremap failed\n"); 1142 debug("ioremap failed\n");
1142 return -1; 1143 err = -1;
1144 goto out_unmap;
1143 } 1145 }
1144 1146
1145 output("%s board found\n", pci_name(dev)); 1147 output("%s board found\n", pci_name(dev));
@@ -1162,8 +1164,10 @@ static int __devinit trident_pci_probe(struct pci_dev * dev, const struct pci_de
1162#endif 1164#endif
1163 fb_info.pseudo_palette = pseudo_pal; 1165 fb_info.pseudo_palette = pseudo_pal;
1164 1166
1165 if (!fb_find_mode(&default_var,&fb_info,mode,NULL,0,NULL,bpp)) 1167 if (!fb_find_mode(&default_var,&fb_info,mode,NULL,0,NULL,bpp)) {
1166 return -EINVAL; 1168 err = -EINVAL;
1169 goto out_unmap;
1170 }
1167 fb_alloc_cmap(&fb_info.cmap,256,0); 1171 fb_alloc_cmap(&fb_info.cmap,256,0);
1168 if (defaultaccel && acc) 1172 if (defaultaccel && acc)
1169 default_var.accel_flags |= FB_ACCELF_TEXT; 1173 default_var.accel_flags |= FB_ACCELF_TEXT;
@@ -1174,12 +1178,20 @@ static int __devinit trident_pci_probe(struct pci_dev * dev, const struct pci_de
1174 fb_info.device = &dev->dev; 1178 fb_info.device = &dev->dev;
1175 if (register_framebuffer(&fb_info) < 0) { 1179 if (register_framebuffer(&fb_info) < 0) {
1176 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n"); 1180 printk(KERN_ERR "tridentfb: could not register Trident framebuffer\n");
1177 return -EINVAL; 1181 err = -EINVAL;
1182 goto out_unmap;
1178 } 1183 }
1179 output("fb%d: %s frame buffer device %dx%d-%dbpp\n", 1184 output("fb%d: %s frame buffer device %dx%d-%dbpp\n",
1180 fb_info.node, fb_info.fix.id,default_var.xres, 1185 fb_info.node, fb_info.fix.id,default_var.xres,
1181 default_var.yres,default_var.bits_per_pixel); 1186 default_var.yres,default_var.bits_per_pixel);
1182 return 0; 1187 return 0;
1188
1189out_unmap:
1190 if (default_par.io_virt)
1191 iounmap(default_par.io_virt);
1192 if (fb_info.screen_base)
1193 iounmap(fb_info.screen_base);
1194 return err;
1183} 1195}
1184 1196
1185static void __devexit trident_pci_remove(struct pci_dev * dev) 1197static void __devexit trident_pci_remove(struct pci_dev * dev)
diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
index 2196448396ec..e16322d157d0 100644
--- a/drivers/video/vesafb.c
+++ b/drivers/video/vesafb.c
@@ -47,17 +47,16 @@ static struct fb_fix_screeninfo vesafb_fix __initdata = {
47 .accel = FB_ACCEL_NONE, 47 .accel = FB_ACCEL_NONE,
48}; 48};
49 49
50static int inverse = 0; 50static int inverse __read_mostly;
51static int mtrr = 0; /* disable mtrr */ 51static int mtrr __read_mostly; /* disable mtrr */
52static int vram_remap __initdata = 0; /* Set amount of memory to be used */ 52static int vram_remap __initdata; /* Set amount of memory to be used */
53static int vram_total __initdata = 0; /* Set total amount of memory */ 53static int vram_total __initdata; /* Set total amount of memory */
54static int pmi_setpal = 1; /* pmi for palette changes ??? */ 54static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55static int ypan = 0; /* 0..nothing, 1..ypan, 2..ywrap */ 55static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
56static unsigned short *pmi_base = NULL; 56static void (*pmi_start)(void) __read_mostly;
57static void (*pmi_start)(void); 57static void (*pmi_pal) (void) __read_mostly;
58static void (*pmi_pal)(void); 58static int depth __read_mostly;
59static int depth; 59static int vga_compat __read_mostly;
60static int vga_compat;
61/* --------------------------------------------------------------------- */ 60/* --------------------------------------------------------------------- */
62 61
63static int vesafb_pan_display(struct fb_var_screeninfo *var, 62static int vesafb_pan_display(struct fb_var_screeninfo *var,
@@ -312,6 +311,7 @@ static int __init vesafb_probe(struct platform_device *dev)
312 ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */ 311 ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */
313 312
314 if (ypan || pmi_setpal) { 313 if (ypan || pmi_setpal) {
314 unsigned short *pmi_base;
315 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); 315 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
316 pmi_start = (void*)((char*)pmi_base + pmi_base[1]); 316 pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
317 pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); 317 pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
@@ -456,6 +456,8 @@ static int __init vesafb_probe(struct platform_device *dev)
456 info->node, info->fix.id); 456 info->node, info->fix.id);
457 return 0; 457 return 0;
458err: 458err:
459 if (info->screen_base)
460 iounmap(info->screen_base);
459 framebuffer_release(info); 461 framebuffer_release(info);
460 release_mem_region(vesafb_fix.smem_start, size_total); 462 release_mem_region(vesafb_fix.smem_start, size_total);
461 return err; 463 return err;
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index 43d5a6d9c4a6..6aff63d5b295 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -264,7 +264,7 @@ static void vga16fb_clock_chip(struct vga16fb_par *par,
264 const struct fb_info *info, 264 const struct fb_info *info,
265 int mul, int div) 265 int mul, int div)
266{ 266{
267 static struct { 267 static const struct {
268 u32 pixclock; 268 u32 pixclock;
269 u8 misc; 269 u8 misc;
270 u8 seq_clock_mode; 270 u8 seq_clock_mode;
@@ -652,7 +652,7 @@ static int vga16fb_set_par(struct fb_info *info)
652 652
653static void ega16_setpalette(int regno, unsigned red, unsigned green, unsigned blue) 653static void ega16_setpalette(int regno, unsigned red, unsigned green, unsigned blue)
654{ 654{
655 static unsigned char map[] = { 000, 001, 010, 011 }; 655 static const unsigned char map[] = { 000, 001, 010, 011 };
656 int val; 656 int val;
657 657
658 if (regno >= 16) 658 if (regno >= 16)
@@ -1139,23 +1139,19 @@ static void vga16fb_copyarea(struct fb_info *info, const struct fb_copyarea *are
1139 } 1139 }
1140} 1140}
1141 1141
1142#ifdef __LITTLE_ENDIAN 1142#define TRANS_MASK_LOW {0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF}
1143static unsigned int transl_l[] = 1143#define TRANS_MASK_HIGH {0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00, \
1144{0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF}; 1144 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00}
1145static unsigned int transl_h[] = 1145
1146{0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00, 1146#if defined(__LITTLE_ENDIAN)
1147 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00}; 1147static const u16 transl_l[] = TRANS_MASK_LOW;
1148#else 1148static const u16 transl_h[] = TRANS_MASK_HIGH;
1149#ifdef __BIG_ENDIAN 1149#elif defined(__BIG_ENDIAN)
1150static unsigned int transl_h[] = 1150static const u16 transl_l[] = TRANS_MASK_HIGH;
1151{0x0,0x8,0x4,0xC,0x2,0xA,0x6,0xE,0x1,0x9,0x5,0xD,0x3,0xB,0x7,0xF}; 1151static const u16 transl_h[] = TRANS_MASK_LOW;
1152static unsigned int transl_l[] =
1153{0x000, 0x800, 0x400, 0xC00, 0x200, 0xA00, 0x600, 0xE00,
1154 0x100, 0x900, 0x500, 0xD00, 0x300, 0xB00, 0x700, 0xF00};
1155#else 1152#else
1156#error "Only __BIG_ENDIAN and __LITTLE_ENDIAN are supported in vga-planes" 1153#error "Only __BIG_ENDIAN and __LITTLE_ENDIAN are supported in vga-planes"
1157#endif 1154#endif
1158#endif
1159 1155
1160static void vga_8planes_imageblit(struct fb_info *info, const struct fb_image *image) 1156static void vga_8planes_imageblit(struct fb_info *info, const struct fb_image *image)
1161{ 1157{
diff --git a/drivers/video/virgefb.c b/drivers/video/virgefb.c
index 64378959dd7b..b9fb6fb3600d 100644
--- a/drivers/video/virgefb.c
+++ b/drivers/video/virgefb.c
@@ -1799,7 +1799,7 @@ int __init virgefb_init(void)
1799 #warning release resources 1799 #warning release resources
1800 printk(KERN_ERR "virgefb.c: register_framebuffer failed\n"); 1800 printk(KERN_ERR "virgefb.c: register_framebuffer failed\n");
1801 DPRINTK("EXIT\n"); 1801 DPRINTK("EXIT\n");
1802 return -EINVAL; 1802 goto out_unmap;
1803 } 1803 }
1804 1804
1805 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of video memory\n", 1805 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of video memory\n",
@@ -1809,6 +1809,21 @@ int __init virgefb_init(void)
1809 1809
1810 DPRINTK("EXIT\n"); 1810 DPRINTK("EXIT\n");
1811 return 0; 1811 return 0;
1812
1813out_unmap:
1814 if (board_addr >= 0x01000000) {
1815 if (v_ram)
1816 iounmap((void*)v_ram);
1817 if (vgaio_regs)
1818 iounmap(vgaio_regs);
1819 if (mmio_regs)
1820 iounmap(mmio_regs);
1821 if (vcode_switch_base)
1822 iounmap((void*)vcode_switch_base);
1823 v_ram = vcode_switch_base = 0;
1824 vgaio_regs = mmio_regs = NULL;
1825 }
1826 return -EINVAL;
1812} 1827}
1813 1828
1814 1829
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index 7aa2d3de6d37..60b05bc15642 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -47,7 +47,7 @@ proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
47static ssize_t 47static ssize_t
48proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 48proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
49{ 49{
50 struct inode *ino = file->f_dentry->d_inode; 50 struct inode *ino = file->f_path.dentry->d_inode;
51 struct proc_dir_entry *dp = PDE(ino); 51 struct proc_dir_entry *dp = PDE(ino);
52 struct zorro_dev *z = dp->data; 52 struct zorro_dev *z = dp->data;
53 struct ConfigDev cd; 53 struct ConfigDev cd;
diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
index 9dfd259a70b4..cc24abf232d5 100644
--- a/fs/9p/vfs_addr.c
+++ b/fs/9p/vfs_addr.c
@@ -54,7 +54,7 @@ static int v9fs_vfs_readpage(struct file *filp, struct page *page)
54 int retval = -EIO; 54 int retval = -EIO;
55 loff_t offset = page_offset(page); 55 loff_t offset = page_offset(page);
56 int count = PAGE_CACHE_SIZE; 56 int count = PAGE_CACHE_SIZE;
57 struct inode *inode = filp->f_dentry->d_inode; 57 struct inode *inode = filp->f_path.dentry->d_inode;
58 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); 58 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
59 int rsize = v9ses->maxdata - V9FS_IOHDRSZ; 59 int rsize = v9ses->maxdata - V9FS_IOHDRSZ;
60 struct v9fs_fid *v9f = filp->private_data; 60 struct v9fs_fid *v9f = filp->private_data;
diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index 905c882f4e2f..3129688143ea 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -71,7 +71,7 @@ static inline int dt_type(struct v9fs_stat *mistat)
71static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir) 71static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
72{ 72{
73 struct v9fs_fcall *fcall = NULL; 73 struct v9fs_fcall *fcall = NULL;
74 struct inode *inode = filp->f_dentry->d_inode; 74 struct inode *inode = filp->f_path.dentry->d_inode;
75 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); 75 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
76 struct v9fs_fid *file = filp->private_data; 76 struct v9fs_fid *file = filp->private_data;
77 unsigned int i, n, s; 77 unsigned int i, n, s;
@@ -80,7 +80,7 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
80 struct v9fs_stat stat; 80 struct v9fs_stat stat;
81 int over = 0; 81 int over = 0;
82 82
83 dprintk(DEBUG_VFS, "name %s\n", filp->f_dentry->d_name.name); 83 dprintk(DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
84 84
85 fid = file->fid; 85 fid = file->fid;
86 86
diff --git a/fs/9p/vfs_file.c b/fs/9p/vfs_file.c
index 79e6f9cd7340..e86a07151280 100644
--- a/fs/9p/vfs_file.c
+++ b/fs/9p/vfs_file.c
@@ -60,7 +60,7 @@ int v9fs_file_open(struct inode *inode, struct file *file)
60 60
61 dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file); 61 dprintk(DEBUG_VFS, "inode: %p file: %p \n", inode, file);
62 62
63 vfid = v9fs_fid_lookup(file->f_dentry); 63 vfid = v9fs_fid_lookup(file->f_path.dentry);
64 if (!vfid) { 64 if (!vfid) {
65 dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n"); 65 dprintk(DEBUG_ERROR, "Couldn't resolve fid from dentry\n");
66 return -EBADF; 66 return -EBADF;
@@ -133,7 +133,7 @@ free_fcall:
133static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl) 133static int v9fs_file_lock(struct file *filp, int cmd, struct file_lock *fl)
134{ 134{
135 int res = 0; 135 int res = 0;
136 struct inode *inode = filp->f_dentry->d_inode; 136 struct inode *inode = filp->f_path.dentry->d_inode;
137 137
138 dprintk(DEBUG_VFS, "filp: %p lock: %p\n", filp, fl); 138 dprintk(DEBUG_VFS, "filp: %p lock: %p\n", filp, fl);
139 139
@@ -161,7 +161,7 @@ static ssize_t
161v9fs_file_read(struct file *filp, char __user * data, size_t count, 161v9fs_file_read(struct file *filp, char __user * data, size_t count,
162 loff_t * offset) 162 loff_t * offset)
163{ 163{
164 struct inode *inode = filp->f_dentry->d_inode; 164 struct inode *inode = filp->f_path.dentry->d_inode;
165 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); 165 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
166 struct v9fs_fid *v9f = filp->private_data; 166 struct v9fs_fid *v9f = filp->private_data;
167 struct v9fs_fcall *fcall = NULL; 167 struct v9fs_fcall *fcall = NULL;
@@ -225,7 +225,7 @@ static ssize_t
225v9fs_file_write(struct file *filp, const char __user * data, 225v9fs_file_write(struct file *filp, const char __user * data,
226 size_t count, loff_t * offset) 226 size_t count, loff_t * offset)
227{ 227{
228 struct inode *inode = filp->f_dentry->d_inode; 228 struct inode *inode = filp->f_path.dentry->d_inode;
229 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode); 229 struct v9fs_session_info *v9ses = v9fs_inode2v9ses(inode);
230 struct v9fs_fid *v9fid = filp->private_data; 230 struct v9fs_fid *v9fid = filp->private_data;
231 struct v9fs_fcall *fcall; 231 struct v9fs_fcall *fcall;
diff --git a/fs/Makefile b/fs/Makefile
index 9a5ce9323bfd..b9ffa63f77fc 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -10,7 +10,8 @@ obj-y := open.o read_write.o file_table.o super.o \
10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \ 10 ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \ 11 attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
12 seq_file.o xattr.o libfs.o fs-writeback.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o \
13 pnode.o drop_caches.o splice.o sync.o utimes.o 13 pnode.o drop_caches.o splice.o sync.o utimes.o \
14 stack.o
14 15
15ifeq ($(CONFIG_BLOCK),y) 16ifeq ($(CONFIG_BLOCK),y)
16obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o 17obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index d3c7905b2ddc..2b8903893d3f 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -28,7 +28,7 @@ static DEFINE_RWLOCK(adfs_dir_lock);
28static int 28static int
29adfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 29adfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
30{ 30{
31 struct inode *inode = filp->f_dentry->d_inode; 31 struct inode *inode = filp->f_path.dentry->d_inode;
32 struct super_block *sb = inode->i_sb; 32 struct super_block *sb = inode->i_sb;
33 struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir; 33 struct adfs_dir_ops *ops = ADFS_SB(sb)->s_dir;
34 struct object_info obj; 34 struct object_info obj;
diff --git a/fs/affs/dir.c b/fs/affs/dir.c
index 5d9649fa1814..cad3ee340063 100644
--- a/fs/affs/dir.c
+++ b/fs/affs/dir.c
@@ -41,7 +41,7 @@ struct inode_operations affs_dir_inode_operations = {
41static int 41static int
42affs_readdir(struct file *filp, void *dirent, filldir_t filldir) 42affs_readdir(struct file *filp, void *dirent, filldir_t filldir)
43{ 43{
44 struct inode *inode = filp->f_dentry->d_inode; 44 struct inode *inode = filp->f_path.dentry->d_inode;
45 struct super_block *sb = inode->i_sb; 45 struct super_block *sb = inode->i_sb;
46 struct buffer_head *dir_bh; 46 struct buffer_head *dir_bh;
47 struct buffer_head *fh_bh; 47 struct buffer_head *fh_bh;
@@ -71,7 +71,7 @@ affs_readdir(struct file *filp, void *dirent, filldir_t filldir)
71 stored++; 71 stored++;
72 } 72 }
73 if (f_pos == 1) { 73 if (f_pos == 1) {
74 if (filldir(dirent, "..", 2, f_pos, parent_ino(filp->f_dentry), DT_DIR) < 0) 74 if (filldir(dirent, "..", 2, f_pos, parent_ino(filp->f_path.dentry), DT_DIR) < 0)
75 return stored; 75 return stored;
76 filp->f_pos = f_pos = 2; 76 filp->f_pos = f_pos = 2;
77 stored++; 77 stored++;
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index a6ec75c56fcf..4acd04134055 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -392,10 +392,10 @@ static int afs_dir_readdir(struct file *file, void *cookie, filldir_t filldir)
392 unsigned fpos; 392 unsigned fpos;
393 int ret; 393 int ret;
394 394
395 _enter("{%Ld,{%lu}}", file->f_pos, file->f_dentry->d_inode->i_ino); 395 _enter("{%Ld,{%lu}}", file->f_pos, file->f_path.dentry->d_inode->i_ino);
396 396
397 fpos = file->f_pos; 397 fpos = file->f_pos;
398 ret = afs_dir_iterate(file->f_dentry->d_inode, &fpos, cookie, filldir); 398 ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos, cookie, filldir);
399 file->f_pos = fpos; 399 file->f_pos = fpos;
400 400
401 _leave(" = %d", ret); 401 _leave(" = %d", ret);
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index 99785a79d043..8f74e8450826 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -18,7 +18,7 @@
18#include <linux/pagemap.h> 18#include <linux/pagemap.h>
19#include <linux/mount.h> 19#include <linux/mount.h>
20#include <linux/namei.h> 20#include <linux/namei.h>
21#include <linux/namespace.h> 21#include <linux/mnt_namespace.h>
22#include "super.h" 22#include "super.h"
23#include "cell.h" 23#include "cell.h"
24#include "volume.h" 24#include "volume.h"
@@ -136,11 +136,11 @@ static int afs_mntpt_open(struct inode *inode, struct file *file)
136{ 136{
137 kenter("%p,%p{%p{%s},%s}", 137 kenter("%p,%p{%p{%s},%s}",
138 inode, file, 138 inode, file,
139 file->f_dentry->d_parent, 139 file->f_path.dentry->d_parent,
140 file->f_dentry->d_parent ? 140 file->f_path.dentry->d_parent ?
141 file->f_dentry->d_parent->d_name.name : 141 file->f_path.dentry->d_parent->d_name.name :
142 (const unsigned char *) "", 142 (const unsigned char *) "",
143 file->f_dentry->d_name.name); 143 file->f_path.dentry->d_name.name);
144 144
145 return -EREMOTE; 145 return -EREMOTE;
146} /* end afs_mntpt_open() */ 146} /* end afs_mntpt_open() */
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 368a1c33a3c8..e698c51d2b02 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -45,7 +45,7 @@ static int autofs_root_readdir(struct file *filp, void *dirent, filldir_t filldi
45 struct autofs_dir_ent *ent = NULL; 45 struct autofs_dir_ent *ent = NULL;
46 struct autofs_dirhash *dirhash; 46 struct autofs_dirhash *dirhash;
47 struct autofs_sb_info *sbi; 47 struct autofs_sb_info *sbi;
48 struct inode * inode = filp->f_dentry->d_inode; 48 struct inode * inode = filp->f_path.dentry->d_inode;
49 off_t onr, nr; 49 off_t onr, nr;
50 50
51 lock_kernel(); 51 lock_kernel();
@@ -557,7 +557,7 @@ static int autofs_root_ioctl(struct inode *inode, struct file *filp,
557 case AUTOFS_IOC_SETTIMEOUT: 557 case AUTOFS_IOC_SETTIMEOUT:
558 return autofs_get_set_timeout(sbi, argp); 558 return autofs_get_set_timeout(sbi, argp);
559 case AUTOFS_IOC_EXPIRE: 559 case AUTOFS_IOC_EXPIRE:
560 return autofs_expire_run(inode->i_sb, sbi, filp->f_vfsmnt, 560 return autofs_expire_run(inode->i_sb, sbi, filp->f_path.mnt,
561 argp); 561 argp);
562 default: 562 default:
563 return -ENOSYS; 563 return -ENOSYS;
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index b13f32c8aeee..216b1a364ccb 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -150,7 +150,8 @@ static inline int autofs4_ispending(struct dentry *dentry)
150 150
151static inline void autofs4_copy_atime(struct file *src, struct file *dst) 151static inline void autofs4_copy_atime(struct file *src, struct file *dst)
152{ 152{
153 dst->f_dentry->d_inode->i_atime = src->f_dentry->d_inode->i_atime; 153 dst->f_path.dentry->d_inode->i_atime =
154 src->f_path.dentry->d_inode->i_atime;
154 return; 155 return;
155} 156}
156 157
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index c1493524da4d..8d05b9f7578d 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -74,7 +74,7 @@ struct inode_operations autofs4_dir_inode_operations = {
74static int autofs4_root_readdir(struct file *file, void *dirent, 74static int autofs4_root_readdir(struct file *file, void *dirent,
75 filldir_t filldir) 75 filldir_t filldir)
76{ 76{
77 struct autofs_sb_info *sbi = autofs4_sbi(file->f_dentry->d_sb); 77 struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb);
78 int oz_mode = autofs4_oz_mode(sbi); 78 int oz_mode = autofs4_oz_mode(sbi);
79 79
80 DPRINTK("called, filp->f_pos = %lld", file->f_pos); 80 DPRINTK("called, filp->f_pos = %lld", file->f_pos);
@@ -95,8 +95,8 @@ static int autofs4_root_readdir(struct file *file, void *dirent,
95 95
96static int autofs4_dir_open(struct inode *inode, struct file *file) 96static int autofs4_dir_open(struct inode *inode, struct file *file)
97{ 97{
98 struct dentry *dentry = file->f_dentry; 98 struct dentry *dentry = file->f_path.dentry;
99 struct vfsmount *mnt = file->f_vfsmnt; 99 struct vfsmount *mnt = file->f_path.mnt;
100 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 100 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
101 struct dentry *cursor; 101 struct dentry *cursor;
102 int status; 102 int status;
@@ -172,7 +172,7 @@ out:
172 172
173static int autofs4_dir_close(struct inode *inode, struct file *file) 173static int autofs4_dir_close(struct inode *inode, struct file *file)
174{ 174{
175 struct dentry *dentry = file->f_dentry; 175 struct dentry *dentry = file->f_path.dentry;
176 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 176 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
177 struct dentry *cursor = file->private_data; 177 struct dentry *cursor = file->private_data;
178 int status = 0; 178 int status = 0;
@@ -204,7 +204,7 @@ out:
204 204
205static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) 205static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir)
206{ 206{
207 struct dentry *dentry = file->f_dentry; 207 struct dentry *dentry = file->f_path.dentry;
208 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); 208 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
209 struct dentry *cursor = file->private_data; 209 struct dentry *cursor = file->private_data;
210 int status; 210 int status;
@@ -858,14 +858,14 @@ static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
858 return autofs4_ask_reghost(sbi, p); 858 return autofs4_ask_reghost(sbi, p);
859 859
860 case AUTOFS_IOC_ASKUMOUNT: 860 case AUTOFS_IOC_ASKUMOUNT:
861 return autofs4_ask_umount(filp->f_vfsmnt, p); 861 return autofs4_ask_umount(filp->f_path.mnt, p);
862 862
863 /* return a single thing to expire */ 863 /* return a single thing to expire */
864 case AUTOFS_IOC_EXPIRE: 864 case AUTOFS_IOC_EXPIRE:
865 return autofs4_expire_run(inode->i_sb,filp->f_vfsmnt,sbi, p); 865 return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p);
866 /* same as above, but can send multiple expires through pipe */ 866 /* same as above, but can send multiple expires through pipe */
867 case AUTOFS_IOC_EXPIRE_MULTI: 867 case AUTOFS_IOC_EXPIRE_MULTI:
868 return autofs4_expire_multi(inode->i_sb,filp->f_vfsmnt,sbi, p); 868 return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p);
869 869
870 default: 870 default:
871 return -ENOSYS; 871 return -ENOSYS;
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index bce402eee554..481e59b9d91c 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -212,7 +212,7 @@ befs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
212static int 212static int
213befs_readdir(struct file *filp, void *dirent, filldir_t filldir) 213befs_readdir(struct file *filp, void *dirent, filldir_t filldir)
214{ 214{
215 struct inode *inode = filp->f_dentry->d_inode; 215 struct inode *inode = filp->f_path.dentry->d_inode;
216 struct super_block *sb = inode->i_sb; 216 struct super_block *sb = inode->i_sb;
217 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds; 217 befs_data_stream *ds = &BEFS_I(inode)->i_data.ds;
218 befs_off_t value; 218 befs_off_t value;
@@ -222,7 +222,7 @@ befs_readdir(struct file *filp, void *dirent, filldir_t filldir)
222 char keybuf[BEFS_NAME_LEN + 1]; 222 char keybuf[BEFS_NAME_LEN + 1];
223 char *nlsname; 223 char *nlsname;
224 int nlsnamelen; 224 int nlsnamelen;
225 const char *dirname = filp->f_dentry->d_name.name; 225 const char *dirname = filp->f_path.dentry->d_name.name;
226 226
227 befs_debug(sb, "---> befs_readdir() " 227 befs_debug(sb, "---> befs_readdir() "
228 "name %s, inode %ld, filp->f_pos %Ld", 228 "name %s, inode %ld, filp->f_pos %Ld",
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c
index a650f1d0b85e..2a746e688df5 100644
--- a/fs/bfs/dir.c
+++ b/fs/bfs/dir.c
@@ -27,7 +27,7 @@ static struct buffer_head * bfs_find_entry(struct inode * dir,
27 27
28static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) 28static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir)
29{ 29{
30 struct inode * dir = f->f_dentry->d_inode; 30 struct inode * dir = f->f_path.dentry->d_inode;
31 struct buffer_head * bh; 31 struct buffer_head * bh;
32 struct bfs_dirent * de; 32 struct bfs_dirent * de;
33 unsigned int offset; 33 unsigned int offset;
diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
index 517e111bb7ef..813a887cd2b3 100644
--- a/fs/binfmt_aout.c
+++ b/fs/binfmt_aout.c
@@ -274,7 +274,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
274 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC && 274 if ((N_MAGIC(ex) != ZMAGIC && N_MAGIC(ex) != OMAGIC &&
275 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) || 275 N_MAGIC(ex) != QMAGIC && N_MAGIC(ex) != NMAGIC) ||
276 N_TRSIZE(ex) || N_DRSIZE(ex) || 276 N_TRSIZE(ex) || N_DRSIZE(ex) ||
277 i_size_read(bprm->file->f_dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) { 277 i_size_read(bprm->file->f_path.dentry->d_inode) < ex.a_text+ex.a_data+N_SYMSIZE(ex)+N_TXTOFF(ex)) {
278 return -ENOEXEC; 278 return -ENOEXEC;
279 } 279 }
280 280
@@ -389,7 +389,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
389 { 389 {
390 printk(KERN_WARNING 390 printk(KERN_WARNING
391 "fd_offset is not page aligned. Please convert program: %s\n", 391 "fd_offset is not page aligned. Please convert program: %s\n",
392 bprm->file->f_dentry->d_name.name); 392 bprm->file->f_path.dentry->d_name.name);
393 error_time = jiffies; 393 error_time = jiffies;
394 } 394 }
395 395
@@ -469,7 +469,7 @@ static int load_aout_library(struct file *file)
469 int retval; 469 int retval;
470 struct exec ex; 470 struct exec ex;
471 471
472 inode = file->f_dentry->d_inode; 472 inode = file->f_path.dentry->d_inode;
473 473
474 retval = -ENOEXEC; 474 retval = -ENOEXEC;
475 error = kernel_read(file, 0, (char *) &ex, sizeof(ex)); 475 error = kernel_read(file, 0, (char *) &ex, sizeof(ex));
@@ -506,7 +506,7 @@ static int load_aout_library(struct file *file)
506 { 506 {
507 printk(KERN_WARNING 507 printk(KERN_WARNING
508 "N_TXTOFF is not page aligned. Please convert library: %s\n", 508 "N_TXTOFF is not page aligned. Please convert library: %s\n",
509 file->f_dentry->d_name.name); 509 file->f_path.dentry->d_name.name);
510 error_time = jiffies; 510 error_time = jiffies;
511 } 511 }
512 down_write(&current->mm->mmap_sem); 512 down_write(&current->mm->mmap_sem);
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index be5869d34999..d3adfd353ff9 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1190,7 +1190,7 @@ static int maydump(struct vm_area_struct *vma)
1190 1190
1191 /* Dump shared memory only if mapped from an anonymous file. */ 1191 /* Dump shared memory only if mapped from an anonymous file. */
1192 if (vma->vm_flags & VM_SHARED) 1192 if (vma->vm_flags & VM_SHARED)
1193 return vma->vm_file->f_dentry->d_inode->i_nlink == 0; 1193 return vma->vm_file->f_path.dentry->d_inode->i_nlink == 0;
1194 1194
1195 /* If it hasn't been written to, don't write it out */ 1195 /* If it hasn't been written to, don't write it out */
1196 if (!vma->anon_vma) 1196 if (!vma->anon_vma)
@@ -1317,7 +1317,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
1317 prstatus->pr_pid = p->pid; 1317 prstatus->pr_pid = p->pid;
1318 prstatus->pr_ppid = p->parent->pid; 1318 prstatus->pr_ppid = p->parent->pid;
1319 prstatus->pr_pgrp = process_group(p); 1319 prstatus->pr_pgrp = process_group(p);
1320 prstatus->pr_sid = p->signal->session; 1320 prstatus->pr_sid = process_session(p);
1321 if (thread_group_leader(p)) { 1321 if (thread_group_leader(p)) {
1322 /* 1322 /*
1323 * This is the record for the group leader. Add in the 1323 * This is the record for the group leader. Add in the
@@ -1363,7 +1363,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
1363 psinfo->pr_pid = p->pid; 1363 psinfo->pr_pid = p->pid;
1364 psinfo->pr_ppid = p->parent->pid; 1364 psinfo->pr_ppid = p->parent->pid;
1365 psinfo->pr_pgrp = process_group(p); 1365 psinfo->pr_pgrp = process_group(p);
1366 psinfo->pr_sid = p->signal->session; 1366 psinfo->pr_sid = process_session(p);
1367 1367
1368 i = p->state ? ffz(~p->state) + 1 : 0; 1368 i = p->state ? ffz(~p->state) + 1 : 0;
1369 psinfo->pr_state = i; 1369 psinfo->pr_state = i;
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index ed9a61c6beb3..76f06f6bc2f6 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -855,7 +855,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
855 855
856dynamic_error: 856dynamic_error:
857 printk("ELF FDPIC %s with invalid DYNAMIC section (inode=%lu)\n", 857 printk("ELF FDPIC %s with invalid DYNAMIC section (inode=%lu)\n",
858 what, file->f_dentry->d_inode->i_ino); 858 what, file->f_path.dentry->d_inode->i_ino);
859 return -ELIBBAD; 859 return -ELIBBAD;
860} 860}
861 861
@@ -1186,7 +1186,7 @@ static int maydump(struct vm_area_struct *vma)
1186 1186
1187 /* Dump shared memory only if mapped from an anonymous file. */ 1187 /* Dump shared memory only if mapped from an anonymous file. */
1188 if (vma->vm_flags & VM_SHARED) { 1188 if (vma->vm_flags & VM_SHARED) {
1189 if (vma->vm_file->f_dentry->d_inode->i_nlink == 0) { 1189 if (vma->vm_file->f_path.dentry->d_inode->i_nlink == 0) {
1190 kdcore("%08lx: %08lx: no (share)", vma->vm_start, vma->vm_flags); 1190 kdcore("%08lx: %08lx: no (share)", vma->vm_start, vma->vm_flags);
1191 return 1; 1191 return 1;
1192 } 1192 }
@@ -1322,7 +1322,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
1322 prstatus->pr_pid = p->pid; 1322 prstatus->pr_pid = p->pid;
1323 prstatus->pr_ppid = p->parent->pid; 1323 prstatus->pr_ppid = p->parent->pid;
1324 prstatus->pr_pgrp = process_group(p); 1324 prstatus->pr_pgrp = process_group(p);
1325 prstatus->pr_sid = p->signal->session; 1325 prstatus->pr_sid = process_session(p);
1326 if (thread_group_leader(p)) { 1326 if (thread_group_leader(p)) {
1327 /* 1327 /*
1328 * This is the record for the group leader. Add in the 1328 * This is the record for the group leader. Add in the
@@ -1371,7 +1371,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
1371 psinfo->pr_pid = p->pid; 1371 psinfo->pr_pid = p->pid;
1372 psinfo->pr_ppid = p->parent->pid; 1372 psinfo->pr_ppid = p->parent->pid;
1373 psinfo->pr_pgrp = process_group(p); 1373 psinfo->pr_pgrp = process_group(p);
1374 psinfo->pr_sid = p->signal->session; 1374 psinfo->pr_sid = process_session(p);
1375 1375
1376 i = p->state ? ffz(~p->state) + 1 : 0; 1376 i = p->state ? ffz(~p->state) + 1 : 0;
1377 psinfo->pr_state = i; 1377 psinfo->pr_state = i;
diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
index a62fd4018a20..ae8595d49856 100644
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -429,7 +429,7 @@ static int load_flat_file(struct linux_binprm * bprm,
429 int ret; 429 int ret;
430 430
431 hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ 431 hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */
432 inode = bprm->file->f_dentry->d_inode; 432 inode = bprm->file->f_path.dentry->d_inode;
433 433
434 text_len = ntohl(hdr->data_start); 434 text_len = ntohl(hdr->data_start);
435 data_len = ntohl(hdr->data_end) - ntohl(hdr->data_start); 435 data_len = ntohl(hdr->data_end) - ntohl(hdr->data_start);
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 1713c48fef54..00687ea62738 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -542,7 +542,7 @@ static void kill_node(Node *e)
542static ssize_t 542static ssize_t
543bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos) 543bm_entry_read(struct file * file, char __user * buf, size_t nbytes, loff_t *ppos)
544{ 544{
545 Node *e = file->f_dentry->d_inode->i_private; 545 Node *e = file->f_path.dentry->d_inode->i_private;
546 loff_t pos = *ppos; 546 loff_t pos = *ppos;
547 ssize_t res; 547 ssize_t res;
548 char *page; 548 char *page;
@@ -576,7 +576,7 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
576 size_t count, loff_t *ppos) 576 size_t count, loff_t *ppos)
577{ 577{
578 struct dentry *root; 578 struct dentry *root;
579 Node *e = file->f_dentry->d_inode->i_private; 579 Node *e = file->f_path.dentry->d_inode->i_private;
580 int res = parse_command(buffer, count); 580 int res = parse_command(buffer, count);
581 581
582 switch (res) { 582 switch (res) {
@@ -584,7 +584,7 @@ static ssize_t bm_entry_write(struct file *file, const char __user *buffer,
584 break; 584 break;
585 case 2: set_bit(Enabled, &e->flags); 585 case 2: set_bit(Enabled, &e->flags);
586 break; 586 break;
587 case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root); 587 case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
588 mutex_lock(&root->d_inode->i_mutex); 588 mutex_lock(&root->d_inode->i_mutex);
589 589
590 kill_node(e); 590 kill_node(e);
@@ -610,7 +610,7 @@ static ssize_t bm_register_write(struct file *file, const char __user *buffer,
610 Node *e; 610 Node *e;
611 struct inode *inode; 611 struct inode *inode;
612 struct dentry *root, *dentry; 612 struct dentry *root, *dentry;
613 struct super_block *sb = file->f_vfsmnt->mnt_sb; 613 struct super_block *sb = file->f_path.mnt->mnt_sb;
614 int err = 0; 614 int err = 0;
615 615
616 e = create_entry(buffer, count); 616 e = create_entry(buffer, count);
@@ -699,7 +699,7 @@ static ssize_t bm_status_write(struct file * file, const char __user * buffer,
699 switch (res) { 699 switch (res) {
700 case 1: enabled = 0; break; 700 case 1: enabled = 0; break;
701 case 2: enabled = 1; break; 701 case 2: enabled = 1; break;
702 case 3: root = dget(file->f_vfsmnt->mnt_sb->s_root); 702 case 3: root = dget(file->f_path.mnt->mnt_sb->s_root);
703 mutex_lock(&root->d_inode->i_mutex); 703 mutex_lock(&root->d_inode->i_mutex);
704 704
705 while (!list_empty(&entries)) 705 while (!list_empty(&entries))
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 13816b4d76f6..197f93921847 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -190,7 +190,7 @@ static int blkdev_commit_write(struct file *file, struct page *page, unsigned fr
190 190
191/* 191/*
192 * private llseek: 192 * private llseek:
193 * for a block special file file->f_dentry->d_inode->i_size is zero 193 * for a block special file file->f_path.dentry->d_inode->i_size is zero
194 * so we compute the size by hand (just as in block_read/write above) 194 * so we compute the size by hand (just as in block_read/write above)
195 */ 195 */
196static loff_t block_llseek(struct file *file, loff_t offset, int origin) 196static loff_t block_llseek(struct file *file, loff_t offset, int origin)
@@ -762,7 +762,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
762 if (!bo) 762 if (!bo)
763 return -ENOMEM; 763 return -ENOMEM;
764 764
765 mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_PARTITION); 765 mutex_lock(&bdev->bd_mutex);
766 res = bd_claim(bdev, holder); 766 res = bd_claim(bdev, holder);
767 if (res == 0) { 767 if (res == 0) {
768 found = find_bd_holder(bdev, bo); 768 found = find_bd_holder(bdev, bo);
@@ -796,7 +796,7 @@ static void bd_release_from_kobject(struct block_device *bdev,
796 if (!kobj) 796 if (!kobj)
797 return; 797 return;
798 798
799 mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_PARTITION); 799 mutex_lock(&bdev->bd_mutex);
800 bd_release(bdev); 800 bd_release(bdev);
801 if ((bo = del_bd_holder(bdev, kobj))) 801 if ((bo = del_bd_holder(bdev, kobj)))
802 free_bd_holder(bo); 802 free_bd_holder(bo);
@@ -854,22 +854,6 @@ struct block_device *open_by_devnum(dev_t dev, unsigned mode)
854 854
855EXPORT_SYMBOL(open_by_devnum); 855EXPORT_SYMBOL(open_by_devnum);
856 856
857static int
858blkdev_get_partition(struct block_device *bdev, mode_t mode, unsigned flags);
859
860struct block_device *open_partition_by_devnum(dev_t dev, unsigned mode)
861{
862 struct block_device *bdev = bdget(dev);
863 int err = -ENOMEM;
864 int flags = mode & FMODE_WRITE ? O_RDWR : O_RDONLY;
865 if (bdev)
866 err = blkdev_get_partition(bdev, mode, flags);
867 return err ? ERR_PTR(err) : bdev;
868}
869
870EXPORT_SYMBOL(open_partition_by_devnum);
871
872
873/* 857/*
874 * This routine checks whether a removable media has been changed, 858 * This routine checks whether a removable media has been changed,
875 * and invalidates all buffer-cache-entries in that case. This 859 * and invalidates all buffer-cache-entries in that case. This
@@ -916,66 +900,11 @@ void bd_set_size(struct block_device *bdev, loff_t size)
916} 900}
917EXPORT_SYMBOL(bd_set_size); 901EXPORT_SYMBOL(bd_set_size);
918 902
919static int __blkdev_put(struct block_device *bdev, unsigned int subclass) 903static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags,
920{ 904 int for_part);
921 int ret = 0; 905static int __blkdev_put(struct block_device *bdev, int for_part);
922 struct inode *bd_inode = bdev->bd_inode;
923 struct gendisk *disk = bdev->bd_disk;
924
925 mutex_lock_nested(&bdev->bd_mutex, subclass);
926 lock_kernel();
927 if (!--bdev->bd_openers) {
928 sync_blockdev(bdev);
929 kill_bdev(bdev);
930 }
931 if (bdev->bd_contains == bdev) {
932 if (disk->fops->release)
933 ret = disk->fops->release(bd_inode, NULL);
934 } else {
935 mutex_lock_nested(&bdev->bd_contains->bd_mutex,
936 subclass + 1);
937 bdev->bd_contains->bd_part_count--;
938 mutex_unlock(&bdev->bd_contains->bd_mutex);
939 }
940 if (!bdev->bd_openers) {
941 struct module *owner = disk->fops->owner;
942
943 put_disk(disk);
944 module_put(owner);
945
946 if (bdev->bd_contains != bdev) {
947 kobject_put(&bdev->bd_part->kobj);
948 bdev->bd_part = NULL;
949 }
950 bdev->bd_disk = NULL;
951 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
952 if (bdev != bdev->bd_contains)
953 __blkdev_put(bdev->bd_contains, subclass + 1);
954 bdev->bd_contains = NULL;
955 }
956 unlock_kernel();
957 mutex_unlock(&bdev->bd_mutex);
958 bdput(bdev);
959 return ret;
960}
961
962int blkdev_put(struct block_device *bdev)
963{
964 return __blkdev_put(bdev, BD_MUTEX_NORMAL);
965}
966EXPORT_SYMBOL(blkdev_put);
967
968int blkdev_put_partition(struct block_device *bdev)
969{
970 return __blkdev_put(bdev, BD_MUTEX_PARTITION);
971}
972EXPORT_SYMBOL(blkdev_put_partition);
973 906
974static int 907static int do_open(struct block_device *bdev, struct file *file, int for_part)
975blkdev_get_whole(struct block_device *bdev, mode_t mode, unsigned flags);
976
977static int
978do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
979{ 908{
980 struct module *owner = NULL; 909 struct module *owner = NULL;
981 struct gendisk *disk; 910 struct gendisk *disk;
@@ -992,8 +921,7 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
992 } 921 }
993 owner = disk->fops->owner; 922 owner = disk->fops->owner;
994 923
995 mutex_lock_nested(&bdev->bd_mutex, subclass); 924 mutex_lock_nested(&bdev->bd_mutex, for_part);
996
997 if (!bdev->bd_openers) { 925 if (!bdev->bd_openers) {
998 bdev->bd_disk = disk; 926 bdev->bd_disk = disk;
999 bdev->bd_contains = bdev; 927 bdev->bd_contains = bdev;
@@ -1020,25 +948,21 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
1020 ret = -ENOMEM; 948 ret = -ENOMEM;
1021 if (!whole) 949 if (!whole)
1022 goto out_first; 950 goto out_first;
1023 ret = blkdev_get_whole(whole, file->f_mode, file->f_flags); 951 BUG_ON(for_part);
952 ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1);
1024 if (ret) 953 if (ret)
1025 goto out_first; 954 goto out_first;
1026 bdev->bd_contains = whole; 955 bdev->bd_contains = whole;
1027 mutex_lock_nested(&whole->bd_mutex, BD_MUTEX_WHOLE);
1028 whole->bd_part_count++;
1029 p = disk->part[part - 1]; 956 p = disk->part[part - 1];
1030 bdev->bd_inode->i_data.backing_dev_info = 957 bdev->bd_inode->i_data.backing_dev_info =
1031 whole->bd_inode->i_data.backing_dev_info; 958 whole->bd_inode->i_data.backing_dev_info;
1032 if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) { 959 if (!(disk->flags & GENHD_FL_UP) || !p || !p->nr_sects) {
1033 whole->bd_part_count--;
1034 mutex_unlock(&whole->bd_mutex);
1035 ret = -ENXIO; 960 ret = -ENXIO;
1036 goto out_first; 961 goto out_first;
1037 } 962 }
1038 kobject_get(&p->kobj); 963 kobject_get(&p->kobj);
1039 bdev->bd_part = p; 964 bdev->bd_part = p;
1040 bd_set_size(bdev, (loff_t) p->nr_sects << 9); 965 bd_set_size(bdev, (loff_t) p->nr_sects << 9);
1041 mutex_unlock(&whole->bd_mutex);
1042 } 966 }
1043 } else { 967 } else {
1044 put_disk(disk); 968 put_disk(disk);
@@ -1051,14 +975,11 @@ do_open(struct block_device *bdev, struct file *file, unsigned int subclass)
1051 } 975 }
1052 if (bdev->bd_invalidated) 976 if (bdev->bd_invalidated)
1053 rescan_partitions(bdev->bd_disk, bdev); 977 rescan_partitions(bdev->bd_disk, bdev);
1054 } else {
1055 mutex_lock_nested(&bdev->bd_contains->bd_mutex,
1056 BD_MUTEX_WHOLE);
1057 bdev->bd_contains->bd_part_count++;
1058 mutex_unlock(&bdev->bd_contains->bd_mutex);
1059 } 978 }
1060 } 979 }
1061 bdev->bd_openers++; 980 bdev->bd_openers++;
981 if (for_part)
982 bdev->bd_part_count++;
1062 mutex_unlock(&bdev->bd_mutex); 983 mutex_unlock(&bdev->bd_mutex);
1063 unlock_kernel(); 984 unlock_kernel();
1064 return 0; 985 return 0;
@@ -1067,7 +988,7 @@ out_first:
1067 bdev->bd_disk = NULL; 988 bdev->bd_disk = NULL;
1068 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; 989 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1069 if (bdev != bdev->bd_contains) 990 if (bdev != bdev->bd_contains)
1070 __blkdev_put(bdev->bd_contains, BD_MUTEX_WHOLE); 991 __blkdev_put(bdev->bd_contains, 1);
1071 bdev->bd_contains = NULL; 992 bdev->bd_contains = NULL;
1072 put_disk(disk); 993 put_disk(disk);
1073 module_put(owner); 994 module_put(owner);
@@ -1079,7 +1000,8 @@ out:
1079 return ret; 1000 return ret;
1080} 1001}
1081 1002
1082int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags) 1003static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags,
1004 int for_part)
1083{ 1005{
1084 /* 1006 /*
1085 * This crockload is due to bad choice of ->open() type. 1007 * This crockload is due to bad choice of ->open() type.
@@ -1091,51 +1013,17 @@ int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags)
1091 struct dentry fake_dentry = {}; 1013 struct dentry fake_dentry = {};
1092 fake_file.f_mode = mode; 1014 fake_file.f_mode = mode;
1093 fake_file.f_flags = flags; 1015 fake_file.f_flags = flags;
1094 fake_file.f_dentry = &fake_dentry; 1016 fake_file.f_path.dentry = &fake_dentry;
1095 fake_dentry.d_inode = bdev->bd_inode; 1017 fake_dentry.d_inode = bdev->bd_inode;
1096 1018
1097 return do_open(bdev, &fake_file, BD_MUTEX_NORMAL); 1019 return do_open(bdev, &fake_file, for_part);
1098} 1020}
1099 1021
1100EXPORT_SYMBOL(blkdev_get); 1022int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags)
1101
1102static int
1103blkdev_get_whole(struct block_device *bdev, mode_t mode, unsigned flags)
1104{
1105 /*
1106 * This crockload is due to bad choice of ->open() type.
1107 * It will go away.
1108 * For now, block device ->open() routine must _not_
1109 * examine anything in 'inode' argument except ->i_rdev.
1110 */
1111 struct file fake_file = {};
1112 struct dentry fake_dentry = {};
1113 fake_file.f_mode = mode;
1114 fake_file.f_flags = flags;
1115 fake_file.f_dentry = &fake_dentry;
1116 fake_dentry.d_inode = bdev->bd_inode;
1117
1118 return do_open(bdev, &fake_file, BD_MUTEX_WHOLE);
1119}
1120
1121static int
1122blkdev_get_partition(struct block_device *bdev, mode_t mode, unsigned flags)
1123{ 1023{
1124 /* 1024 return __blkdev_get(bdev, mode, flags, 0);
1125 * This crockload is due to bad choice of ->open() type.
1126 * It will go away.
1127 * For now, block device ->open() routine must _not_
1128 * examine anything in 'inode' argument except ->i_rdev.
1129 */
1130 struct file fake_file = {};
1131 struct dentry fake_dentry = {};
1132 fake_file.f_mode = mode;
1133 fake_file.f_flags = flags;
1134 fake_file.f_dentry = &fake_dentry;
1135 fake_dentry.d_inode = bdev->bd_inode;
1136
1137 return do_open(bdev, &fake_file, BD_MUTEX_PARTITION);
1138} 1025}
1026EXPORT_SYMBOL(blkdev_get);
1139 1027
1140static int blkdev_open(struct inode * inode, struct file * filp) 1028static int blkdev_open(struct inode * inode, struct file * filp)
1141{ 1029{
@@ -1154,7 +1042,7 @@ static int blkdev_open(struct inode * inode, struct file * filp)
1154 if (bdev == NULL) 1042 if (bdev == NULL)
1155 return -ENOMEM; 1043 return -ENOMEM;
1156 1044
1157 res = do_open(bdev, filp, BD_MUTEX_NORMAL); 1045 res = do_open(bdev, filp, 0);
1158 if (res) 1046 if (res)
1159 return res; 1047 return res;
1160 1048
@@ -1168,6 +1056,56 @@ static int blkdev_open(struct inode * inode, struct file * filp)
1168 return res; 1056 return res;
1169} 1057}
1170 1058
1059static int __blkdev_put(struct block_device *bdev, int for_part)
1060{
1061 int ret = 0;
1062 struct inode *bd_inode = bdev->bd_inode;
1063 struct gendisk *disk = bdev->bd_disk;
1064 struct block_device *victim = NULL;
1065
1066 mutex_lock_nested(&bdev->bd_mutex, for_part);
1067 lock_kernel();
1068 if (for_part)
1069 bdev->bd_part_count--;
1070
1071 if (!--bdev->bd_openers) {
1072 sync_blockdev(bdev);
1073 kill_bdev(bdev);
1074 }
1075 if (bdev->bd_contains == bdev) {
1076 if (disk->fops->release)
1077 ret = disk->fops->release(bd_inode, NULL);
1078 }
1079 if (!bdev->bd_openers) {
1080 struct module *owner = disk->fops->owner;
1081
1082 put_disk(disk);
1083 module_put(owner);
1084
1085 if (bdev->bd_contains != bdev) {
1086 kobject_put(&bdev->bd_part->kobj);
1087 bdev->bd_part = NULL;
1088 }
1089 bdev->bd_disk = NULL;
1090 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1091 if (bdev != bdev->bd_contains)
1092 victim = bdev->bd_contains;
1093 bdev->bd_contains = NULL;
1094 }
1095 unlock_kernel();
1096 mutex_unlock(&bdev->bd_mutex);
1097 bdput(bdev);
1098 if (victim)
1099 __blkdev_put(victim, 1);
1100 return ret;
1101}
1102
1103int blkdev_put(struct block_device *bdev)
1104{
1105 return __blkdev_put(bdev, 0);
1106}
1107EXPORT_SYMBOL(blkdev_put);
1108
1171static int blkdev_close(struct inode * inode, struct file * filp) 1109static int blkdev_close(struct inode * inode, struct file * filp)
1172{ 1110{
1173 struct block_device *bdev = I_BDEV(filp->f_mapping->host); 1111 struct block_device *bdev = I_BDEV(filp->f_mapping->host);
diff --git a/fs/buffer.c b/fs/buffer.c
index 517860f2d75b..d1f1b54d3108 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -35,6 +35,7 @@
35#include <linux/hash.h> 35#include <linux/hash.h>
36#include <linux/suspend.h> 36#include <linux/suspend.h>
37#include <linux/buffer_head.h> 37#include <linux/buffer_head.h>
38#include <linux/task_io_accounting_ops.h>
38#include <linux/bio.h> 39#include <linux/bio.h>
39#include <linux/notifier.h> 40#include <linux/notifier.h>
40#include <linux/cpu.h> 41#include <linux/cpu.h>
@@ -724,20 +725,21 @@ int __set_page_dirty_buffers(struct page *page)
724 } 725 }
725 spin_unlock(&mapping->private_lock); 726 spin_unlock(&mapping->private_lock);
726 727
727 if (!TestSetPageDirty(page)) { 728 if (TestSetPageDirty(page))
728 write_lock_irq(&mapping->tree_lock); 729 return 0;
729 if (page->mapping) { /* Race with truncate? */ 730
730 if (mapping_cap_account_dirty(mapping)) 731 write_lock_irq(&mapping->tree_lock);
731 __inc_zone_page_state(page, NR_FILE_DIRTY); 732 if (page->mapping) { /* Race with truncate? */
732 radix_tree_tag_set(&mapping->page_tree, 733 if (mapping_cap_account_dirty(mapping)) {
733 page_index(page), 734 __inc_zone_page_state(page, NR_FILE_DIRTY);
734 PAGECACHE_TAG_DIRTY); 735 task_io_account_write(PAGE_CACHE_SIZE);
735 } 736 }
736 write_unlock_irq(&mapping->tree_lock); 737 radix_tree_tag_set(&mapping->page_tree,
737 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); 738 page_index(page), PAGECACHE_TAG_DIRTY);
738 return 1;
739 } 739 }
740 return 0; 740 write_unlock_irq(&mapping->tree_lock);
741 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
742 return 1;
741} 743}
742EXPORT_SYMBOL(__set_page_dirty_buffers); 744EXPORT_SYMBOL(__set_page_dirty_buffers);
743 745
@@ -2851,8 +2853,13 @@ int try_to_free_buffers(struct page *page)
2851 * could encounter a non-uptodate page, which is unresolvable. 2853 * could encounter a non-uptodate page, which is unresolvable.
2852 * This only applies in the rare case where try_to_free_buffers 2854 * This only applies in the rare case where try_to_free_buffers
2853 * succeeds but the page is not freed. 2855 * succeeds but the page is not freed.
2856 *
2857 * Also, during truncate, discard_buffer will have marked all
2858 * the page's buffers clean. We discover that here and clean
2859 * the page also.
2854 */ 2860 */
2855 clear_page_dirty(page); 2861 if (test_clear_page_dirty(page))
2862 task_io_account_cancelled_write(PAGE_CACHE_SIZE);
2856 } 2863 }
2857out: 2864out:
2858 if (buffers_to_free) { 2865 if (buffers_to_free) {
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES
index 0b3c37ef52e0..3539d6ef9611 100644
--- a/fs/cifs/CHANGES
+++ b/fs/cifs/CHANGES
@@ -5,7 +5,8 @@ Allow null user to be specified on mount ("username="). Do not return
5EINVAL on readdir when filldir fails due to overwritten blocksize 5EINVAL on readdir when filldir fails due to overwritten blocksize
6(fixes FC problem). Return error in rename 2nd attempt retry (ie report 6(fixes FC problem). Return error in rename 2nd attempt retry (ie report
7if rename by handle also fails, after rename by path fails, we were 7if rename by handle also fails, after rename by path fails, we were
8not reporting whether the retry worked or not). 8not reporting whether the retry worked or not). Fix NTLMv2 to
9work to Windows servers (mount with option "sec=ntlmv2").
9 10
10Version 1.45 11Version 1.45
11------------ 12------------
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 4bc250b2d9fc..fdeda519eace 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -372,8 +372,10 @@ void setup_ntlmv2_rsp(struct cifsSesInfo * ses, char * resp_buf,
372 buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); 372 buf->time = cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME));
373 get_random_bytes(&buf->client_chal, sizeof(buf->client_chal)); 373 get_random_bytes(&buf->client_chal, sizeof(buf->client_chal));
374 buf->reserved2 = 0; 374 buf->reserved2 = 0;
375 buf->names[0].type = 0; 375 buf->names[0].type = cpu_to_le16(NTLMSSP_DOMAIN_TYPE);
376 buf->names[0].length = 0; 376 buf->names[0].length = 0;
377 buf->names[1].type = 0;
378 buf->names[1].length = 0;
377 379
378 /* calculate buf->ntlmv2_hash */ 380 /* calculate buf->ntlmv2_hash */
379 rc = calc_ntlmv2_hash(ses, nls_cp); 381 rc = calc_ntlmv2_hash(ses, nls_cp);
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 71bc87a37fc1..10c90294cd18 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -498,7 +498,7 @@ cifs_get_sb(struct file_system_type *fs_type,
498static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 498static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
499 unsigned long nr_segs, loff_t pos) 499 unsigned long nr_segs, loff_t pos)
500{ 500{
501 struct inode *inode = iocb->ki_filp->f_dentry->d_inode; 501 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
502 ssize_t written; 502 ssize_t written;
503 503
504 written = generic_file_aio_write(iocb, iov, nr_segs, pos); 504 written = generic_file_aio_write(iocb, iov, nr_segs, pos);
@@ -511,7 +511,7 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
511{ 511{
512 /* origin == SEEK_END => we must revalidate the cached file length */ 512 /* origin == SEEK_END => we must revalidate the cached file length */
513 if (origin == SEEK_END) { 513 if (origin == SEEK_END) {
514 int retval = cifs_revalidate(file->f_dentry); 514 int retval = cifs_revalidate(file->f_path.dentry);
515 if (retval < 0) 515 if (retval < 0)
516 return (loff_t)retval; 516 return (loff_t)retval;
517 } 517 }
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index 6df9dadba647..068ef51edbf7 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -580,6 +580,12 @@ typedef union smb_com_session_setup_andx {
580 580
581/* format of NLTMv2 Response ie "case sensitive password" hash when NTLMv2 */ 581/* format of NLTMv2 Response ie "case sensitive password" hash when NTLMv2 */
582 582
583#define NTLMSSP_SERVER_TYPE 1
584#define NTLMSSP_DOMAIN_TYPE 2
585#define NTLMSSP_FQ_DOMAIN_TYPE 3
586#define NTLMSSP_DNS_DOMAIN_TYPE 4
587#define NTLMSSP_DNS_PARENT_TYPE 5
588
583struct ntlmssp2_name { 589struct ntlmssp2_name {
584 __le16 type; 590 __le16 type;
585 __le16 length; 591 __le16 length;
@@ -593,7 +599,7 @@ struct ntlmv2_resp {
593 __le64 time; 599 __le64 time;
594 __u64 client_chal; /* random */ 600 __u64 client_chal; /* random */
595 __u32 reserved2; 601 __u32 reserved2;
596 struct ntlmssp2_name names[1]; 602 struct ntlmssp2_name names[2];
597 /* array of name entries could follow ending in minimum 4 byte struct */ 603 /* array of name entries could follow ending in minimum 4 byte struct */
598} __attribute__((packed)); 604} __attribute__((packed));
599 605
diff --git a/fs/cifs/fcntl.c b/fs/cifs/fcntl.c
index d91a3d44e9e3..da12b482ebe5 100644
--- a/fs/cifs/fcntl.c
+++ b/fs/cifs/fcntl.c
@@ -83,10 +83,10 @@ int cifs_dir_notify(struct file * file, unsigned long arg)
83 return 0; 83 return 0;
84 84
85 xid = GetXid(); 85 xid = GetXid();
86 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 86 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
87 pTcon = cifs_sb->tcon; 87 pTcon = cifs_sb->tcon;
88 88
89 full_path = build_path_from_dentry(file->f_dentry); 89 full_path = build_path_from_dentry(file->f_path.dentry);
90 90
91 if(full_path == NULL) { 91 if(full_path == NULL) {
92 rc = -ENOMEM; 92 rc = -ENOMEM;
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 2436ed8fc840..0f05cab5d24a 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -29,6 +29,7 @@
29#include <linux/pagevec.h> 29#include <linux/pagevec.h>
30#include <linux/smp_lock.h> 30#include <linux/smp_lock.h>
31#include <linux/writeback.h> 31#include <linux/writeback.h>
32#include <linux/task_io_accounting_ops.h>
32#include <linux/delay.h> 33#include <linux/delay.h>
33#include <asm/div64.h> 34#include <asm/div64.h>
34#include "cifsfs.h" 35#include "cifsfs.h"
@@ -122,34 +123,34 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
122 /* if not oplocked, invalidate inode pages if mtime or file 123 /* if not oplocked, invalidate inode pages if mtime or file
123 size changed */ 124 size changed */
124 temp = cifs_NTtimeToUnix(le64_to_cpu(buf->LastWriteTime)); 125 temp = cifs_NTtimeToUnix(le64_to_cpu(buf->LastWriteTime));
125 if (timespec_equal(&file->f_dentry->d_inode->i_mtime, &temp) && 126 if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
126 (file->f_dentry->d_inode->i_size == 127 (file->f_path.dentry->d_inode->i_size ==
127 (loff_t)le64_to_cpu(buf->EndOfFile))) { 128 (loff_t)le64_to_cpu(buf->EndOfFile))) {
128 cFYI(1, ("inode unchanged on server")); 129 cFYI(1, ("inode unchanged on server"));
129 } else { 130 } else {
130 if (file->f_dentry->d_inode->i_mapping) { 131 if (file->f_path.dentry->d_inode->i_mapping) {
131 /* BB no need to lock inode until after invalidate 132 /* BB no need to lock inode until after invalidate
132 since namei code should already have it locked? */ 133 since namei code should already have it locked? */
133 filemap_write_and_wait(file->f_dentry->d_inode->i_mapping); 134 filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping);
134 } 135 }
135 cFYI(1, ("invalidating remote inode since open detected it " 136 cFYI(1, ("invalidating remote inode since open detected it "
136 "changed")); 137 "changed"));
137 invalidate_remote_inode(file->f_dentry->d_inode); 138 invalidate_remote_inode(file->f_path.dentry->d_inode);
138 } 139 }
139 140
140client_can_cache: 141client_can_cache:
141 if (pTcon->ses->capabilities & CAP_UNIX) 142 if (pTcon->ses->capabilities & CAP_UNIX)
142 rc = cifs_get_inode_info_unix(&file->f_dentry->d_inode, 143 rc = cifs_get_inode_info_unix(&file->f_path.dentry->d_inode,
143 full_path, inode->i_sb, xid); 144 full_path, inode->i_sb, xid);
144 else 145 else
145 rc = cifs_get_inode_info(&file->f_dentry->d_inode, 146 rc = cifs_get_inode_info(&file->f_path.dentry->d_inode,
146 full_path, buf, inode->i_sb, xid); 147 full_path, buf, inode->i_sb, xid);
147 148
148 if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) { 149 if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) {
149 pCifsInode->clientCanCacheAll = TRUE; 150 pCifsInode->clientCanCacheAll = TRUE;
150 pCifsInode->clientCanCacheRead = TRUE; 151 pCifsInode->clientCanCacheRead = TRUE;
151 cFYI(1, ("Exclusive Oplock granted on inode %p", 152 cFYI(1, ("Exclusive Oplock granted on inode %p",
152 file->f_dentry->d_inode)); 153 file->f_path.dentry->d_inode));
153 } else if ((*oplock & 0xF) == OPLOCK_READ) 154 } else if ((*oplock & 0xF) == OPLOCK_READ)
154 pCifsInode->clientCanCacheRead = TRUE; 155 pCifsInode->clientCanCacheRead = TRUE;
155 156
@@ -178,7 +179,7 @@ int cifs_open(struct inode *inode, struct file *file)
178 179
179 if (file->f_flags & O_CREAT) { 180 if (file->f_flags & O_CREAT) {
180 /* search inode for this file and fill in file->private_data */ 181 /* search inode for this file and fill in file->private_data */
181 pCifsInode = CIFS_I(file->f_dentry->d_inode); 182 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
182 read_lock(&GlobalSMBSeslock); 183 read_lock(&GlobalSMBSeslock);
183 list_for_each(tmp, &pCifsInode->openFileList) { 184 list_for_each(tmp, &pCifsInode->openFileList) {
184 pCifsFile = list_entry(tmp, struct cifsFileInfo, 185 pCifsFile = list_entry(tmp, struct cifsFileInfo,
@@ -206,7 +207,7 @@ int cifs_open(struct inode *inode, struct file *file)
206 } 207 }
207 } 208 }
208 209
209 full_path = build_path_from_dentry(file->f_dentry); 210 full_path = build_path_from_dentry(file->f_path.dentry);
210 if (full_path == NULL) { 211 if (full_path == NULL) {
211 FreeXid(xid); 212 FreeXid(xid);
212 return -ENOMEM; 213 return -ENOMEM;
@@ -291,7 +292,7 @@ int cifs_open(struct inode *inode, struct file *file)
291 write_lock(&GlobalSMBSeslock); 292 write_lock(&GlobalSMBSeslock);
292 list_add(&pCifsFile->tlist, &pTcon->openFileList); 293 list_add(&pCifsFile->tlist, &pTcon->openFileList);
293 294
294 pCifsInode = CIFS_I(file->f_dentry->d_inode); 295 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
295 if (pCifsInode) { 296 if (pCifsInode) {
296 rc = cifs_open_inode_helper(inode, file, pCifsInode, 297 rc = cifs_open_inode_helper(inode, file, pCifsInode,
297 pCifsFile, pTcon, 298 pCifsFile, pTcon,
@@ -366,7 +367,7 @@ static int cifs_reopen_file(struct inode *inode, struct file *file,
366 return 0; 367 return 0;
367 } 368 }
368 369
369 if (file->f_dentry == NULL) { 370 if (file->f_path.dentry == NULL) {
370 up(&pCifsFile->fh_sem); 371 up(&pCifsFile->fh_sem);
371 cFYI(1, ("failed file reopen, no valid name if dentry freed")); 372 cFYI(1, ("failed file reopen, no valid name if dentry freed"));
372 FreeXid(xid); 373 FreeXid(xid);
@@ -378,7 +379,7 @@ static int cifs_reopen_file(struct inode *inode, struct file *file,
378 those that already have the rename sem can end up causing writepage 379 those that already have the rename sem can end up causing writepage
379 to get called and if the server was down that means we end up here, 380 to get called and if the server was down that means we end up here,
380 and we can never tell if the caller already has the rename_sem */ 381 and we can never tell if the caller already has the rename_sem */
381 full_path = build_path_from_dentry(file->f_dentry); 382 full_path = build_path_from_dentry(file->f_path.dentry);
382 if (full_path == NULL) { 383 if (full_path == NULL) {
383 up(&pCifsFile->fh_sem); 384 up(&pCifsFile->fh_sem);
384 FreeXid(xid); 385 FreeXid(xid);
@@ -444,7 +445,7 @@ static int cifs_reopen_file(struct inode *inode, struct file *file,
444 pCifsInode->clientCanCacheAll = TRUE; 445 pCifsInode->clientCanCacheAll = TRUE;
445 pCifsInode->clientCanCacheRead = TRUE; 446 pCifsInode->clientCanCacheRead = TRUE;
446 cFYI(1, ("Exclusive Oplock granted on inode %p", 447 cFYI(1, ("Exclusive Oplock granted on inode %p",
447 file->f_dentry->d_inode)); 448 file->f_path.dentry->d_inode));
448 } else if ((oplock & 0xF) == OPLOCK_READ) { 449 } else if ((oplock & 0xF) == OPLOCK_READ) {
449 pCifsInode->clientCanCacheRead = TRUE; 450 pCifsInode->clientCanCacheRead = TRUE;
450 pCifsInode->clientCanCacheAll = FALSE; 451 pCifsInode->clientCanCacheAll = FALSE;
@@ -551,7 +552,7 @@ int cifs_closedir(struct inode *inode, struct file *file)
551 552
552 if (pCFileStruct) { 553 if (pCFileStruct) {
553 struct cifsTconInfo *pTcon; 554 struct cifsTconInfo *pTcon;
554 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_dentry->d_sb); 555 struct cifs_sb_info *cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
555 556
556 pTcon = cifs_sb->tcon; 557 pTcon = cifs_sb->tcon;
557 558
@@ -664,7 +665,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
664 } else 665 } else
665 cFYI(1, ("Unknown type of lock")); 666 cFYI(1, ("Unknown type of lock"));
666 667
667 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 668 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
668 pTcon = cifs_sb->tcon; 669 pTcon = cifs_sb->tcon;
669 670
670 if (file->private_data == NULL) { 671 if (file->private_data == NULL) {
@@ -791,10 +792,10 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
791 int xid, long_op; 792 int xid, long_op;
792 struct cifsFileInfo *open_file; 793 struct cifsFileInfo *open_file;
793 794
794 if (file->f_dentry == NULL) 795 if (file->f_path.dentry == NULL)
795 return -EBADF; 796 return -EBADF;
796 797
797 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 798 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
798 if (cifs_sb == NULL) 799 if (cifs_sb == NULL)
799 return -EBADF; 800 return -EBADF;
800 801
@@ -802,7 +803,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
802 803
803 /* cFYI(1, 804 /* cFYI(1,
804 (" write %d bytes to offset %lld of %s", write_size, 805 (" write %d bytes to offset %lld of %s", write_size,
805 *poffset, file->f_dentry->d_name.name)); */ 806 *poffset, file->f_path.dentry->d_name.name)); */
806 807
807 if (file->private_data == NULL) 808 if (file->private_data == NULL)
808 return -EBADF; 809 return -EBADF;
@@ -810,12 +811,12 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
810 open_file = (struct cifsFileInfo *) file->private_data; 811 open_file = (struct cifsFileInfo *) file->private_data;
811 812
812 xid = GetXid(); 813 xid = GetXid();
813 if (file->f_dentry->d_inode == NULL) { 814 if (file->f_path.dentry->d_inode == NULL) {
814 FreeXid(xid); 815 FreeXid(xid);
815 return -EBADF; 816 return -EBADF;
816 } 817 }
817 818
818 if (*poffset > file->f_dentry->d_inode->i_size) 819 if (*poffset > file->f_path.dentry->d_inode->i_size)
819 long_op = 2; /* writes past end of file can take a long time */ 820 long_op = 2; /* writes past end of file can take a long time */
820 else 821 else
821 long_op = 1; 822 long_op = 1;
@@ -840,8 +841,8 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
840 return -EBADF; 841 return -EBADF;
841 } 842 }
842 if (open_file->invalidHandle) { 843 if (open_file->invalidHandle) {
843 if ((file->f_dentry == NULL) || 844 if ((file->f_path.dentry == NULL) ||
844 (file->f_dentry->d_inode == NULL)) { 845 (file->f_path.dentry->d_inode == NULL)) {
845 FreeXid(xid); 846 FreeXid(xid);
846 return total_written; 847 return total_written;
847 } 848 }
@@ -849,7 +850,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
849 filemap_fdatawait from here so tell 850 filemap_fdatawait from here so tell
850 reopen_file not to flush data to server 851 reopen_file not to flush data to server
851 now */ 852 now */
852 rc = cifs_reopen_file(file->f_dentry->d_inode, 853 rc = cifs_reopen_file(file->f_path.dentry->d_inode,
853 file, FALSE); 854 file, FALSE);
854 if (rc != 0) 855 if (rc != 0)
855 break; 856 break;
@@ -878,17 +879,17 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
878 cifs_stats_bytes_written(pTcon, total_written); 879 cifs_stats_bytes_written(pTcon, total_written);
879 880
880 /* since the write may have blocked check these pointers again */ 881 /* since the write may have blocked check these pointers again */
881 if (file->f_dentry) { 882 if (file->f_path.dentry) {
882 if (file->f_dentry->d_inode) { 883 if (file->f_path.dentry->d_inode) {
883 struct inode *inode = file->f_dentry->d_inode; 884 struct inode *inode = file->f_path.dentry->d_inode;
884 inode->i_ctime = inode->i_mtime = 885 inode->i_ctime = inode->i_mtime =
885 current_fs_time(inode->i_sb); 886 current_fs_time(inode->i_sb);
886 if (total_written > 0) { 887 if (total_written > 0) {
887 if (*poffset > file->f_dentry->d_inode->i_size) 888 if (*poffset > file->f_path.dentry->d_inode->i_size)
888 i_size_write(file->f_dentry->d_inode, 889 i_size_write(file->f_path.dentry->d_inode,
889 *poffset); 890 *poffset);
890 } 891 }
891 mark_inode_dirty_sync(file->f_dentry->d_inode); 892 mark_inode_dirty_sync(file->f_path.dentry->d_inode);
892 } 893 }
893 } 894 }
894 FreeXid(xid); 895 FreeXid(xid);
@@ -906,17 +907,17 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
906 int xid, long_op; 907 int xid, long_op;
907 struct cifsFileInfo *open_file; 908 struct cifsFileInfo *open_file;
908 909
909 if (file->f_dentry == NULL) 910 if (file->f_path.dentry == NULL)
910 return -EBADF; 911 return -EBADF;
911 912
912 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 913 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
913 if (cifs_sb == NULL) 914 if (cifs_sb == NULL)
914 return -EBADF; 915 return -EBADF;
915 916
916 pTcon = cifs_sb->tcon; 917 pTcon = cifs_sb->tcon;
917 918
918 cFYI(1,("write %zd bytes to offset %lld of %s", write_size, 919 cFYI(1,("write %zd bytes to offset %lld of %s", write_size,
919 *poffset, file->f_dentry->d_name.name)); 920 *poffset, file->f_path.dentry->d_name.name));
920 921
921 if (file->private_data == NULL) 922 if (file->private_data == NULL)
922 return -EBADF; 923 return -EBADF;
@@ -924,12 +925,12 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
924 open_file = (struct cifsFileInfo *)file->private_data; 925 open_file = (struct cifsFileInfo *)file->private_data;
925 926
926 xid = GetXid(); 927 xid = GetXid();
927 if (file->f_dentry->d_inode == NULL) { 928 if (file->f_path.dentry->d_inode == NULL) {
928 FreeXid(xid); 929 FreeXid(xid);
929 return -EBADF; 930 return -EBADF;
930 } 931 }
931 932
932 if (*poffset > file->f_dentry->d_inode->i_size) 933 if (*poffset > file->f_path.dentry->d_inode->i_size)
933 long_op = 2; /* writes past end of file can take a long time */ 934 long_op = 2; /* writes past end of file can take a long time */
934 else 935 else
935 long_op = 1; 936 long_op = 1;
@@ -955,8 +956,8 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
955 return -EBADF; 956 return -EBADF;
956 } 957 }
957 if (open_file->invalidHandle) { 958 if (open_file->invalidHandle) {
958 if ((file->f_dentry == NULL) || 959 if ((file->f_path.dentry == NULL) ||
959 (file->f_dentry->d_inode == NULL)) { 960 (file->f_path.dentry->d_inode == NULL)) {
960 FreeXid(xid); 961 FreeXid(xid);
961 return total_written; 962 return total_written;
962 } 963 }
@@ -964,7 +965,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
964 filemap_fdatawait from here so tell 965 filemap_fdatawait from here so tell
965 reopen_file not to flush data to 966 reopen_file not to flush data to
966 server now */ 967 server now */
967 rc = cifs_reopen_file(file->f_dentry->d_inode, 968 rc = cifs_reopen_file(file->f_path.dentry->d_inode,
968 file, FALSE); 969 file, FALSE);
969 if (rc != 0) 970 if (rc != 0)
970 break; 971 break;
@@ -1011,16 +1012,16 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
1011 cifs_stats_bytes_written(pTcon, total_written); 1012 cifs_stats_bytes_written(pTcon, total_written);
1012 1013
1013 /* since the write may have blocked check these pointers again */ 1014 /* since the write may have blocked check these pointers again */
1014 if (file->f_dentry) { 1015 if (file->f_path.dentry) {
1015 if (file->f_dentry->d_inode) { 1016 if (file->f_path.dentry->d_inode) {
1016 file->f_dentry->d_inode->i_ctime = 1017 file->f_path.dentry->d_inode->i_ctime =
1017 file->f_dentry->d_inode->i_mtime = CURRENT_TIME; 1018 file->f_path.dentry->d_inode->i_mtime = CURRENT_TIME;
1018 if (total_written > 0) { 1019 if (total_written > 0) {
1019 if (*poffset > file->f_dentry->d_inode->i_size) 1020 if (*poffset > file->f_path.dentry->d_inode->i_size)
1020 i_size_write(file->f_dentry->d_inode, 1021 i_size_write(file->f_path.dentry->d_inode,
1021 *poffset); 1022 *poffset);
1022 } 1023 }
1023 mark_inode_dirty_sync(file->f_dentry->d_inode); 1024 mark_inode_dirty_sync(file->f_path.dentry->d_inode);
1024 } 1025 }
1025 } 1026 }
1026 FreeXid(xid); 1027 FreeXid(xid);
@@ -1384,7 +1385,7 @@ static int cifs_commit_write(struct file *file, struct page *page,
1384 if ((open_file->invalidHandle) && 1385 if ((open_file->invalidHandle) &&
1385 (!open_file->closePend)) { 1386 (!open_file->closePend)) {
1386 rc = cifs_reopen_file( 1387 rc = cifs_reopen_file(
1387 file->f_dentry->d_inode, file); 1388 file->f_path.dentry->d_inode, file);
1388 if (rc != 0) 1389 if (rc != 0)
1389 break; 1390 break;
1390 } 1391 }
@@ -1434,7 +1435,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
1434{ 1435{
1435 int xid; 1436 int xid;
1436 int rc = 0; 1437 int rc = 0;
1437 struct inode *inode = file->f_dentry->d_inode; 1438 struct inode *inode = file->f_path.dentry->d_inode;
1438 1439
1439 xid = GetXid(); 1440 xid = GetXid();
1440 1441
@@ -1482,7 +1483,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
1482 */ 1483 */
1483int cifs_flush(struct file *file, fl_owner_t id) 1484int cifs_flush(struct file *file, fl_owner_t id)
1484{ 1485{
1485 struct inode * inode = file->f_dentry->d_inode; 1486 struct inode * inode = file->f_path.dentry->d_inode;
1486 int rc = 0; 1487 int rc = 0;
1487 1488
1488 /* Rather than do the steps manually: 1489 /* Rather than do the steps manually:
@@ -1519,7 +1520,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
1519 struct smb_com_read_rsp *pSMBr; 1520 struct smb_com_read_rsp *pSMBr;
1520 1521
1521 xid = GetXid(); 1522 xid = GetXid();
1522 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 1523 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1523 pTcon = cifs_sb->tcon; 1524 pTcon = cifs_sb->tcon;
1524 1525
1525 if (file->private_data == NULL) { 1526 if (file->private_data == NULL) {
@@ -1542,7 +1543,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
1542 int buf_type = CIFS_NO_BUFFER; 1543 int buf_type = CIFS_NO_BUFFER;
1543 if ((open_file->invalidHandle) && 1544 if ((open_file->invalidHandle) &&
1544 (!open_file->closePend)) { 1545 (!open_file->closePend)) {
1545 rc = cifs_reopen_file(file->f_dentry->d_inode, 1546 rc = cifs_reopen_file(file->f_path.dentry->d_inode,
1546 file, TRUE); 1547 file, TRUE);
1547 if (rc != 0) 1548 if (rc != 0)
1548 break; 1549 break;
@@ -1601,7 +1602,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1601 int buf_type = CIFS_NO_BUFFER; 1602 int buf_type = CIFS_NO_BUFFER;
1602 1603
1603 xid = GetXid(); 1604 xid = GetXid();
1604 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 1605 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1605 pTcon = cifs_sb->tcon; 1606 pTcon = cifs_sb->tcon;
1606 1607
1607 if (file->private_data == NULL) { 1608 if (file->private_data == NULL) {
@@ -1629,7 +1630,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1629 while (rc == -EAGAIN) { 1630 while (rc == -EAGAIN) {
1630 if ((open_file->invalidHandle) && 1631 if ((open_file->invalidHandle) &&
1631 (!open_file->closePend)) { 1632 (!open_file->closePend)) {
1632 rc = cifs_reopen_file(file->f_dentry->d_inode, 1633 rc = cifs_reopen_file(file->f_path.dentry->d_inode,
1633 file, TRUE); 1634 file, TRUE);
1634 if (rc != 0) 1635 if (rc != 0)
1635 break; 1636 break;
@@ -1658,7 +1659,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
1658 1659
1659int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) 1660int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
1660{ 1661{
1661 struct dentry *dentry = file->f_dentry; 1662 struct dentry *dentry = file->f_path.dentry;
1662 int rc, xid; 1663 int rc, xid;
1663 1664
1664 xid = GetXid(); 1665 xid = GetXid();
@@ -1744,7 +1745,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
1744 return -EBADF; 1745 return -EBADF;
1745 } 1746 }
1746 open_file = (struct cifsFileInfo *)file->private_data; 1747 open_file = (struct cifsFileInfo *)file->private_data;
1747 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 1748 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
1748 pTcon = cifs_sb->tcon; 1749 pTcon = cifs_sb->tcon;
1749 1750
1750 pagevec_init(&lru_pvec, 0); 1751 pagevec_init(&lru_pvec, 0);
@@ -1786,7 +1787,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
1786 while (rc == -EAGAIN) { 1787 while (rc == -EAGAIN) {
1787 if ((open_file->invalidHandle) && 1788 if ((open_file->invalidHandle) &&
1788 (!open_file->closePend)) { 1789 (!open_file->closePend)) {
1789 rc = cifs_reopen_file(file->f_dentry->d_inode, 1790 rc = cifs_reopen_file(file->f_path.dentry->d_inode,
1790 file, TRUE); 1791 file, TRUE);
1791 if (rc != 0) 1792 if (rc != 0)
1792 break; 1793 break;
@@ -1812,6 +1813,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
1812 cFYI(1, ("Read error in readpages: %d", rc)); 1813 cFYI(1, ("Read error in readpages: %d", rc));
1813 break; 1814 break;
1814 } else if (bytes_read > 0) { 1815 } else if (bytes_read > 0) {
1816 task_io_account_read(bytes_read);
1815 pSMBr = (struct smb_com_read_rsp *)smb_read_data; 1817 pSMBr = (struct smb_com_read_rsp *)smb_read_data;
1816 cifs_copy_cache_pages(mapping, page_list, bytes_read, 1818 cifs_copy_cache_pages(mapping, page_list, bytes_read,
1817 smb_read_data + 4 /* RFC1001 hdr */ + 1819 smb_read_data + 4 /* RFC1001 hdr */ +
@@ -1880,8 +1882,8 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
1880 else 1882 else
1881 cFYI(1, ("Bytes read %d",rc)); 1883 cFYI(1, ("Bytes read %d",rc));
1882 1884
1883 file->f_dentry->d_inode->i_atime = 1885 file->f_path.dentry->d_inode->i_atime =
1884 current_fs_time(file->f_dentry->d_inode->i_sb); 1886 current_fs_time(file->f_path.dentry->d_inode->i_sb);
1885 1887
1886 if (PAGE_CACHE_SIZE > rc) 1888 if (PAGE_CACHE_SIZE > rc)
1887 memset(read_data + rc, 0, PAGE_CACHE_SIZE - rc); 1889 memset(read_data + rc, 0, PAGE_CACHE_SIZE - rc);
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index ed18c3965f7b..99dfb5337e31 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -68,30 +68,30 @@ static int construct_dentry(struct qstr *qstring, struct file *file,
68 int rc = 0; 68 int rc = 0;
69 69
70 cFYI(1, ("For %s", qstring->name)); 70 cFYI(1, ("For %s", qstring->name));
71 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 71 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
72 pTcon = cifs_sb->tcon; 72 pTcon = cifs_sb->tcon;
73 73
74 qstring->hash = full_name_hash(qstring->name, qstring->len); 74 qstring->hash = full_name_hash(qstring->name, qstring->len);
75 tmp_dentry = d_lookup(file->f_dentry, qstring); 75 tmp_dentry = d_lookup(file->f_path.dentry, qstring);
76 if (tmp_dentry) { 76 if (tmp_dentry) {
77 cFYI(0, ("existing dentry with inode 0x%p", tmp_dentry->d_inode)); 77 cFYI(0, ("existing dentry with inode 0x%p", tmp_dentry->d_inode));
78 *ptmp_inode = tmp_dentry->d_inode; 78 *ptmp_inode = tmp_dentry->d_inode;
79/* BB overwrite old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len??*/ 79/* BB overwrite old name? i.e. tmp_dentry->d_name and tmp_dentry->d_name.len??*/
80 if(*ptmp_inode == NULL) { 80 if(*ptmp_inode == NULL) {
81 *ptmp_inode = new_inode(file->f_dentry->d_sb); 81 *ptmp_inode = new_inode(file->f_path.dentry->d_sb);
82 if(*ptmp_inode == NULL) 82 if(*ptmp_inode == NULL)
83 return rc; 83 return rc;
84 rc = 1; 84 rc = 1;
85 } 85 }
86 } else { 86 } else {
87 tmp_dentry = d_alloc(file->f_dentry, qstring); 87 tmp_dentry = d_alloc(file->f_path.dentry, qstring);
88 if(tmp_dentry == NULL) { 88 if(tmp_dentry == NULL) {
89 cERROR(1,("Failed allocating dentry")); 89 cERROR(1,("Failed allocating dentry"));
90 *ptmp_inode = NULL; 90 *ptmp_inode = NULL;
91 return rc; 91 return rc;
92 } 92 }
93 93
94 *ptmp_inode = new_inode(file->f_dentry->d_sb); 94 *ptmp_inode = new_inode(file->f_path.dentry->d_sb);
95 if (pTcon->nocase) 95 if (pTcon->nocase)
96 tmp_dentry->d_op = &cifs_ci_dentry_ops; 96 tmp_dentry->d_op = &cifs_ci_dentry_ops;
97 else 97 else
@@ -432,10 +432,10 @@ static int initiate_cifs_search(const int xid, struct file *file)
432 cifsFile->invalidHandle = TRUE; 432 cifsFile->invalidHandle = TRUE;
433 cifsFile->srch_inf.endOfSearch = FALSE; 433 cifsFile->srch_inf.endOfSearch = FALSE;
434 434
435 if(file->f_dentry == NULL) 435 if(file->f_path.dentry == NULL)
436 return -ENOENT; 436 return -ENOENT;
437 437
438 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 438 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
439 if(cifs_sb == NULL) 439 if(cifs_sb == NULL)
440 return -EINVAL; 440 return -EINVAL;
441 441
@@ -443,7 +443,7 @@ static int initiate_cifs_search(const int xid, struct file *file)
443 if(pTcon == NULL) 443 if(pTcon == NULL)
444 return -EINVAL; 444 return -EINVAL;
445 445
446 full_path = build_path_from_dentry(file->f_dentry); 446 full_path = build_path_from_dentry(file->f_path.dentry);
447 447
448 if(full_path == NULL) { 448 if(full_path == NULL) {
449 return -ENOMEM; 449 return -ENOMEM;
@@ -609,10 +609,10 @@ static int is_dir_changed(struct file * file)
609 struct inode * inode; 609 struct inode * inode;
610 struct cifsInodeInfo *cifsInfo; 610 struct cifsInodeInfo *cifsInfo;
611 611
612 if(file->f_dentry == NULL) 612 if(file->f_path.dentry == NULL)
613 return 0; 613 return 0;
614 614
615 inode = file->f_dentry->d_inode; 615 inode = file->f_path.dentry->d_inode;
616 616
617 if(inode == NULL) 617 if(inode == NULL)
618 return 0; 618 return 0;
@@ -839,7 +839,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
839 if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL)) 839 if((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
840 return -ENOENT; 840 return -ENOENT;
841 841
842 if(file->f_dentry == NULL) 842 if(file->f_path.dentry == NULL)
843 return -ENOENT; 843 return -ENOENT;
844 844
845 rc = cifs_entry_is_dot(pfindEntry,pCifsF); 845 rc = cifs_entry_is_dot(pfindEntry,pCifsF);
@@ -847,7 +847,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
847 if(rc != 0) 847 if(rc != 0)
848 return 0; 848 return 0;
849 849
850 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 850 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
851 851
852 qstring.name = scratch_buf; 852 qstring.name = scratch_buf;
853 rc = cifs_get_name_from_search_buf(&qstring,pfindEntry, 853 rc = cifs_get_name_from_search_buf(&qstring,pfindEntry,
@@ -985,12 +985,12 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
985 985
986 xid = GetXid(); 986 xid = GetXid();
987 987
988 if(file->f_dentry == NULL) { 988 if(file->f_path.dentry == NULL) {
989 FreeXid(xid); 989 FreeXid(xid);
990 return -EIO; 990 return -EIO;
991 } 991 }
992 992
993 cifs_sb = CIFS_SB(file->f_dentry->d_sb); 993 cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
994 pTcon = cifs_sb->tcon; 994 pTcon = cifs_sb->tcon;
995 if(pTcon == NULL) 995 if(pTcon == NULL)
996 return -EINVAL; 996 return -EINVAL;
@@ -998,7 +998,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
998 switch ((int) file->f_pos) { 998 switch ((int) file->f_pos) {
999 case 0: 999 case 0:
1000 if (filldir(direntry, ".", 1, file->f_pos, 1000 if (filldir(direntry, ".", 1, file->f_pos,
1001 file->f_dentry->d_inode->i_ino, DT_DIR) < 0) { 1001 file->f_path.dentry->d_inode->i_ino, DT_DIR) < 0) {
1002 cERROR(1, ("Filldir for current dir failed")); 1002 cERROR(1, ("Filldir for current dir failed"));
1003 rc = -ENOMEM; 1003 rc = -ENOMEM;
1004 break; 1004 break;
@@ -1006,7 +1006,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
1006 file->f_pos++; 1006 file->f_pos++;
1007 case 1: 1007 case 1:
1008 if (filldir(direntry, "..", 2, file->f_pos, 1008 if (filldir(direntry, "..", 2, file->f_pos,
1009 file->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) { 1009 file->f_path.dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
1010 cERROR(1, ("Filldir for parent dir failed")); 1010 cERROR(1, ("Filldir for parent dir failed"));
1011 rc = -ENOMEM; 1011 rc = -ENOMEM;
1012 break; 1012 break;
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 0102b28a15fb..0c6f7f3b3dd7 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -441,7 +441,7 @@ static int coda_rename(struct inode *old_dir, struct dentry *old_dentry,
441/* file operations for directories */ 441/* file operations for directories */
442int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir) 442int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir)
443{ 443{
444 struct dentry *coda_dentry = coda_file->f_dentry; 444 struct dentry *coda_dentry = coda_file->f_path.dentry;
445 struct coda_file_info *cfi; 445 struct coda_file_info *cfi;
446 struct file *host_file; 446 struct file *host_file;
447 struct inode *host_inode; 447 struct inode *host_inode;
@@ -453,7 +453,7 @@ int coda_readdir(struct file *coda_file, void *dirent, filldir_t filldir)
453 453
454 coda_vfs_stat.readdir++; 454 coda_vfs_stat.readdir++;
455 455
456 host_inode = host_file->f_dentry->d_inode; 456 host_inode = host_file->f_path.dentry->d_inode;
457 mutex_lock(&host_inode->i_mutex); 457 mutex_lock(&host_inode->i_mutex);
458 host_file->f_pos = coda_file->f_pos; 458 host_file->f_pos = coda_file->f_pos;
459 459
@@ -544,14 +544,14 @@ static int coda_venus_readdir(struct file *filp, filldir_t filldir,
544 /* catch truncated reads */ 544 /* catch truncated reads */
545 if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) { 545 if (ret < vdir_size || ret < vdir_size + vdir->d_namlen) {
546 printk("coda_venus_readdir: short read: %ld\n", 546 printk("coda_venus_readdir: short read: %ld\n",
547 filp->f_dentry->d_inode->i_ino); 547 filp->f_path.dentry->d_inode->i_ino);
548 ret = -EBADF; 548 ret = -EBADF;
549 break; 549 break;
550 } 550 }
551 /* validate whether the directory file actually makes sense */ 551 /* validate whether the directory file actually makes sense */
552 if (vdir->d_reclen < vdir_size + vdir->d_namlen) { 552 if (vdir->d_reclen < vdir_size + vdir->d_namlen) {
553 printk("coda_venus_readdir: Invalid dir: %ld\n", 553 printk("coda_venus_readdir: Invalid dir: %ld\n",
554 filp->f_dentry->d_inode->i_ino); 554 filp->f_path.dentry->d_inode->i_ino);
555 ret = -EBADF; 555 ret = -EBADF;
556 break; 556 break;
557 } 557 }
diff --git a/fs/coda/file.c b/fs/coda/file.c
index dbfbcfa5b3c0..5ef2b609ec7d 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -66,7 +66,7 @@ coda_file_sendfile(struct file *coda_file, loff_t *ppos, size_t count,
66static ssize_t 66static ssize_t
67coda_file_write(struct file *coda_file, const char __user *buf, size_t count, loff_t *ppos) 67coda_file_write(struct file *coda_file, const char __user *buf, size_t count, loff_t *ppos)
68{ 68{
69 struct inode *host_inode, *coda_inode = coda_file->f_dentry->d_inode; 69 struct inode *host_inode, *coda_inode = coda_file->f_path.dentry->d_inode;
70 struct coda_file_info *cfi; 70 struct coda_file_info *cfi;
71 struct file *host_file; 71 struct file *host_file;
72 ssize_t ret; 72 ssize_t ret;
@@ -78,7 +78,7 @@ coda_file_write(struct file *coda_file, const char __user *buf, size_t count, lo
78 if (!host_file->f_op || !host_file->f_op->write) 78 if (!host_file->f_op || !host_file->f_op->write)
79 return -EINVAL; 79 return -EINVAL;
80 80
81 host_inode = host_file->f_dentry->d_inode; 81 host_inode = host_file->f_path.dentry->d_inode;
82 mutex_lock(&coda_inode->i_mutex); 82 mutex_lock(&coda_inode->i_mutex);
83 83
84 ret = host_file->f_op->write(host_file, buf, count, ppos); 84 ret = host_file->f_op->write(host_file, buf, count, ppos);
@@ -106,8 +106,8 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
106 if (!host_file->f_op || !host_file->f_op->mmap) 106 if (!host_file->f_op || !host_file->f_op->mmap)
107 return -ENODEV; 107 return -ENODEV;
108 108
109 coda_inode = coda_file->f_dentry->d_inode; 109 coda_inode = coda_file->f_path.dentry->d_inode;
110 host_inode = host_file->f_dentry->d_inode; 110 host_inode = host_file->f_path.dentry->d_inode;
111 coda_file->f_mapping = host_file->f_mapping; 111 coda_file->f_mapping = host_file->f_mapping;
112 if (coda_inode->i_mapping == &coda_inode->i_data) 112 if (coda_inode->i_mapping == &coda_inode->i_data)
113 coda_inode->i_mapping = host_inode->i_mapping; 113 coda_inode->i_mapping = host_inode->i_mapping;
@@ -190,7 +190,7 @@ int coda_flush(struct file *coda_file, fl_owner_t id)
190 cfi = CODA_FTOC(coda_file); 190 cfi = CODA_FTOC(coda_file);
191 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 191 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
192 192
193 coda_inode = coda_file->f_dentry->d_inode; 193 coda_inode = coda_file->f_path.dentry->d_inode;
194 194
195 err = venus_store(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags, 195 err = venus_store(coda_inode->i_sb, coda_i2f(coda_inode), coda_flags,
196 coda_file->f_uid); 196 coda_file->f_uid);
@@ -233,7 +233,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
233 err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode), 233 err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
234 coda_flags, coda_file->f_uid); 234 coda_flags, coda_file->f_uid);
235 235
236 host_inode = cfi->cfi_container->f_dentry->d_inode; 236 host_inode = cfi->cfi_container->f_path.dentry->d_inode;
237 cii = ITOC(coda_inode); 237 cii = ITOC(coda_inode);
238 238
239 /* did we mmap this file? */ 239 /* did we mmap this file? */
@@ -270,7 +270,7 @@ int coda_fsync(struct file *coda_file, struct dentry *coda_dentry, int datasync)
270 coda_vfs_stat.fsync++; 270 coda_vfs_stat.fsync++;
271 271
272 if (host_file->f_op && host_file->f_op->fsync) { 272 if (host_file->f_op && host_file->f_op->fsync) {
273 host_dentry = host_file->f_dentry; 273 host_dentry = host_file->f_path.dentry;
274 host_inode = host_dentry->d_inode; 274 host_inode = host_dentry->d_inode;
275 mutex_lock(&host_inode->i_mutex); 275 mutex_lock(&host_inode->i_mutex);
276 err = host_file->f_op->fsync(host_file, host_dentry, datasync); 276 err = host_file->f_op->fsync(host_file, host_dentry, datasync);
diff --git a/fs/coda/inode.c b/fs/coda/inode.c
index b64659fa82d0..01395defed85 100644
--- a/fs/coda/inode.c
+++ b/fs/coda/inode.c
@@ -119,7 +119,7 @@ static int get_device_index(struct coda_mount_data *data)
119 file = fget(data->fd); 119 file = fget(data->fd);
120 inode = NULL; 120 inode = NULL;
121 if(file) 121 if(file)
122 inode = file->f_dentry->d_inode; 122 inode = file->f_path.dentry->d_inode;
123 123
124 if(!inode || !S_ISCHR(inode->i_mode) || 124 if(!inode || !S_ISCHR(inode->i_mode) ||
125 imajor(inode) != CODA_PSDEV_MAJOR) { 125 imajor(inode) != CODA_PSDEV_MAJOR) {
diff --git a/fs/compat.c b/fs/compat.c
index a7e3f162fb15..0ec70e3cee0a 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -232,7 +232,7 @@ asmlinkage long compat_sys_fstatfs(unsigned int fd, struct compat_statfs __user
232 file = fget(fd); 232 file = fget(fd);
233 if (!file) 233 if (!file)
234 goto out; 234 goto out;
235 error = vfs_statfs(file->f_dentry, &tmp); 235 error = vfs_statfs(file->f_path.dentry, &tmp);
236 if (!error) 236 if (!error)
237 error = put_compat_statfs(buf, &tmp); 237 error = put_compat_statfs(buf, &tmp);
238 fput(file); 238 fput(file);
@@ -303,7 +303,7 @@ asmlinkage long compat_sys_fstatfs64(unsigned int fd, compat_size_t sz, struct c
303 file = fget(fd); 303 file = fget(fd);
304 if (!file) 304 if (!file)
305 goto out; 305 goto out;
306 error = vfs_statfs(file->f_dentry, &tmp); 306 error = vfs_statfs(file->f_path.dentry, &tmp);
307 if (!error) 307 if (!error)
308 error = put_compat_statfs64(buf, &tmp); 308 error = put_compat_statfs64(buf, &tmp);
309 fput(file); 309 fput(file);
@@ -365,7 +365,7 @@ static void compat_ioctl_error(struct file *filp, unsigned int fd,
365 /* find the name of the device. */ 365 /* find the name of the device. */
366 path = (char *)__get_free_page(GFP_KERNEL); 366 path = (char *)__get_free_page(GFP_KERNEL);
367 if (path) { 367 if (path) {
368 fn = d_path(filp->f_dentry, filp->f_vfsmnt, path, PAGE_SIZE); 368 fn = d_path(filp->f_path.dentry, filp->f_path.mnt, path, PAGE_SIZE);
369 if (IS_ERR(fn)) 369 if (IS_ERR(fn))
370 fn = "?"; 370 fn = "?";
371 } 371 }
@@ -416,7 +416,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
416 case FIBMAP: 416 case FIBMAP:
417 case FIGETBSZ: 417 case FIGETBSZ:
418 case FIONREAD: 418 case FIONREAD:
419 if (S_ISREG(filp->f_dentry->d_inode->i_mode)) 419 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
420 break; 420 break;
421 /*FALL THROUGH*/ 421 /*FALL THROUGH*/
422 422
@@ -438,7 +438,7 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
438 goto found_handler; 438 goto found_handler;
439 } 439 }
440 440
441 if (S_ISSOCK(filp->f_dentry->d_inode->i_mode) && 441 if (S_ISSOCK(filp->f_path.dentry->d_inode->i_mode) &&
442 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) { 442 cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
443 error = siocdevprivate_ioctl(fd, cmd, arg); 443 error = siocdevprivate_ioctl(fd, cmd, arg);
444 } else { 444 } else {
@@ -1259,7 +1259,7 @@ out:
1259 if (iov != iovstack) 1259 if (iov != iovstack)
1260 kfree(iov); 1260 kfree(iov);
1261 if ((ret + (type == READ)) > 0) { 1261 if ((ret + (type == READ)) > 0) {
1262 struct dentry *dentry = file->f_dentry; 1262 struct dentry *dentry = file->f_path.dentry;
1263 if (type == READ) 1263 if (type == READ)
1264 fsnotify_access(dentry); 1264 fsnotify_access(dentry);
1265 else 1265 else
@@ -1679,19 +1679,19 @@ int compat_core_sys_select(int n, compat_ulong_t __user *inp,
1679{ 1679{
1680 fd_set_bits fds; 1680 fd_set_bits fds;
1681 char *bits; 1681 char *bits;
1682 int size, max_fdset, ret = -EINVAL; 1682 int size, max_fds, ret = -EINVAL;
1683 struct fdtable *fdt; 1683 struct fdtable *fdt;
1684 1684
1685 if (n < 0) 1685 if (n < 0)
1686 goto out_nofds; 1686 goto out_nofds;
1687 1687
1688 /* max_fdset can increase, so grab it once to avoid race */ 1688 /* max_fds can increase, so grab it once to avoid race */
1689 rcu_read_lock(); 1689 rcu_read_lock();
1690 fdt = files_fdtable(current->files); 1690 fdt = files_fdtable(current->files);
1691 max_fdset = fdt->max_fdset; 1691 max_fds = fdt->max_fds;
1692 rcu_read_unlock(); 1692 rcu_read_unlock();
1693 if (n > max_fdset) 1693 if (n > max_fds)
1694 n = max_fdset; 1694 n = max_fds;
1695 1695
1696 /* 1696 /*
1697 * We need 6 bitmaps (in/out/ex for both incoming and outgoing), 1697 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index bcc3caf5d820..c81c958b3e1d 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -1177,7 +1177,7 @@ static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long ar
1177static int vt_check(struct file *file) 1177static int vt_check(struct file *file)
1178{ 1178{
1179 struct tty_struct *tty; 1179 struct tty_struct *tty;
1180 struct inode *inode = file->f_dentry->d_inode; 1180 struct inode *inode = file->f_path.dentry->d_inode;
1181 1181
1182 if (file->f_op->ioctl != tty_ioctl) 1182 if (file->f_op->ioctl != tty_ioctl)
1183 return -EINVAL; 1183 return -EINVAL;
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index c398861f78a5..1814ba446809 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -980,7 +980,7 @@ int configfs_rename_dir(struct config_item * item, const char *new_name)
980 980
981static int configfs_dir_open(struct inode *inode, struct file *file) 981static int configfs_dir_open(struct inode *inode, struct file *file)
982{ 982{
983 struct dentry * dentry = file->f_dentry; 983 struct dentry * dentry = file->f_path.dentry;
984 struct configfs_dirent * parent_sd = dentry->d_fsdata; 984 struct configfs_dirent * parent_sd = dentry->d_fsdata;
985 985
986 mutex_lock(&dentry->d_inode->i_mutex); 986 mutex_lock(&dentry->d_inode->i_mutex);
@@ -993,7 +993,7 @@ static int configfs_dir_open(struct inode *inode, struct file *file)
993 993
994static int configfs_dir_close(struct inode *inode, struct file *file) 994static int configfs_dir_close(struct inode *inode, struct file *file)
995{ 995{
996 struct dentry * dentry = file->f_dentry; 996 struct dentry * dentry = file->f_path.dentry;
997 struct configfs_dirent * cursor = file->private_data; 997 struct configfs_dirent * cursor = file->private_data;
998 998
999 mutex_lock(&dentry->d_inode->i_mutex); 999 mutex_lock(&dentry->d_inode->i_mutex);
@@ -1013,7 +1013,7 @@ static inline unsigned char dt_type(struct configfs_dirent *sd)
1013 1013
1014static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir) 1014static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
1015{ 1015{
1016 struct dentry *dentry = filp->f_dentry; 1016 struct dentry *dentry = filp->f_path.dentry;
1017 struct configfs_dirent * parent_sd = dentry->d_fsdata; 1017 struct configfs_dirent * parent_sd = dentry->d_fsdata;
1018 struct configfs_dirent *cursor = filp->private_data; 1018 struct configfs_dirent *cursor = filp->private_data;
1019 struct list_head *p, *q = &cursor->s_sibling; 1019 struct list_head *p, *q = &cursor->s_sibling;
@@ -1070,7 +1070,7 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
1070 1070
1071static loff_t configfs_dir_lseek(struct file * file, loff_t offset, int origin) 1071static loff_t configfs_dir_lseek(struct file * file, loff_t offset, int origin)
1072{ 1072{
1073 struct dentry * dentry = file->f_dentry; 1073 struct dentry * dentry = file->f_path.dentry;
1074 1074
1075 mutex_lock(&dentry->d_inode->i_mutex); 1075 mutex_lock(&dentry->d_inode->i_mutex);
1076 switch (origin) { 1076 switch (origin) {
@@ -1080,7 +1080,7 @@ static loff_t configfs_dir_lseek(struct file * file, loff_t offset, int origin)
1080 if (offset >= 0) 1080 if (offset >= 0)
1081 break; 1081 break;
1082 default: 1082 default:
1083 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 1083 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
1084 return -EINVAL; 1084 return -EINVAL;
1085 } 1085 }
1086 if (offset != file->f_pos) { 1086 if (offset != file->f_pos) {
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index cf33fac68c84..2a7cb086e80c 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -134,7 +134,7 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp
134 134
135 down(&buffer->sem); 135 down(&buffer->sem);
136 if (buffer->needs_read_fill) { 136 if (buffer->needs_read_fill) {
137 if ((retval = fill_read_buffer(file->f_dentry,buffer))) 137 if ((retval = fill_read_buffer(file->f_path.dentry,buffer)))
138 goto out; 138 goto out;
139 } 139 }
140 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 140 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
@@ -222,7 +222,7 @@ configfs_write_file(struct file *file, const char __user *buf, size_t count, lof
222 down(&buffer->sem); 222 down(&buffer->sem);
223 len = fill_write_buffer(buffer, buf, count); 223 len = fill_write_buffer(buffer, buf, count);
224 if (len > 0) 224 if (len > 0)
225 len = flush_write_buffer(file->f_dentry, buffer, count); 225 len = flush_write_buffer(file->f_path.dentry, buffer, count);
226 if (len > 0) 226 if (len > 0)
227 *ppos += len; 227 *ppos += len;
228 up(&buffer->sem); 228 up(&buffer->sem);
@@ -231,8 +231,8 @@ configfs_write_file(struct file *file, const char __user *buf, size_t count, lof
231 231
232static int check_perm(struct inode * inode, struct file * file) 232static int check_perm(struct inode * inode, struct file * file)
233{ 233{
234 struct config_item *item = configfs_get_config_item(file->f_dentry->d_parent); 234 struct config_item *item = configfs_get_config_item(file->f_path.dentry->d_parent);
235 struct configfs_attribute * attr = to_attr(file->f_dentry); 235 struct configfs_attribute * attr = to_attr(file->f_path.dentry);
236 struct configfs_buffer * buffer; 236 struct configfs_buffer * buffer;
237 struct configfs_item_operations * ops = NULL; 237 struct configfs_item_operations * ops = NULL;
238 int error = 0; 238 int error = 0;
@@ -305,8 +305,8 @@ static int configfs_open_file(struct inode * inode, struct file * filp)
305 305
306static int configfs_release(struct inode * inode, struct file * filp) 306static int configfs_release(struct inode * inode, struct file * filp)
307{ 307{
308 struct config_item * item = to_item(filp->f_dentry->d_parent); 308 struct config_item * item = to_item(filp->f_path.dentry->d_parent);
309 struct configfs_attribute * attr = to_attr(filp->f_dentry); 309 struct configfs_attribute * attr = to_attr(filp->f_path.dentry);
310 struct module * owner = attr->ca_owner; 310 struct module * owner = attr->ca_owner;
311 struct configfs_buffer * buffer = filp->private_data; 311 struct configfs_buffer * buffer = filp->private_data;
312 312
diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c
index 0509cedd415c..6db03fb089dc 100644
--- a/fs/cramfs/inode.c
+++ b/fs/cramfs/inode.c
@@ -338,7 +338,7 @@ static int cramfs_statfs(struct dentry *dentry, struct kstatfs *buf)
338 */ 338 */
339static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 339static int cramfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
340{ 340{
341 struct inode *inode = filp->f_dentry->d_inode; 341 struct inode *inode = filp->f_path.dentry->d_inode;
342 struct super_block *sb = inode->i_sb; 342 struct super_block *sb = inode->i_sb;
343 char *buf; 343 char *buf;
344 unsigned int offset; 344 unsigned int offset;
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 5981e17f46f0..d9d0833444f5 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/highmem.h> 28#include <linux/highmem.h>
29#include <linux/pagemap.h> 29#include <linux/pagemap.h>
30#include <linux/task_io_accounting_ops.h>
30#include <linux/bio.h> 31#include <linux/bio.h>
31#include <linux/wait.h> 32#include <linux/wait.h>
32#include <linux/err.h> 33#include <linux/err.h>
@@ -121,8 +122,7 @@ struct dio {
121 122
122 /* BIO completion state */ 123 /* BIO completion state */
123 spinlock_t bio_lock; /* protects BIO fields below */ 124 spinlock_t bio_lock; /* protects BIO fields below */
124 int bio_count; /* nr bios to be completed */ 125 unsigned long refcount; /* direct_io_worker() and bios */
125 int bios_in_flight; /* nr bios in flight */
126 struct bio *bio_list; /* singly linked via bi_private */ 126 struct bio *bio_list; /* singly linked via bi_private */
127 struct task_struct *waiter; /* waiting task (NULL if none) */ 127 struct task_struct *waiter; /* waiting task (NULL if none) */
128 128
@@ -209,76 +209,55 @@ static struct page *dio_get_page(struct dio *dio)
209 return dio->pages[dio->head++]; 209 return dio->pages[dio->head++];
210} 210}
211 211
212/* 212/**
213 * Called when all DIO BIO I/O has been completed - let the filesystem 213 * dio_complete() - called when all DIO BIO I/O has been completed
214 * know, if it registered an interest earlier via get_block. Pass the 214 * @offset: the byte offset in the file of the completed operation
215 * private field of the map buffer_head so that filesystems can use it 215 *
216 * to hold additional state between get_block calls and dio_complete. 216 * This releases locks as dictated by the locking type, lets interested parties
217 */ 217 * know that a DIO operation has completed, and calculates the resulting return
218static void dio_complete(struct dio *dio, loff_t offset, ssize_t bytes) 218 * code for the operation.
219{ 219 *
220 if (dio->end_io && dio->result) 220 * It lets the filesystem know if it registered an interest earlier via
221 dio->end_io(dio->iocb, offset, bytes, dio->map_bh.b_private); 221 * get_block. Pass the private field of the map buffer_head so that
222 if (dio->lock_type == DIO_LOCKING) 222 * filesystems can use it to hold additional state between get_block calls and
223 /* lockdep: non-owner release */ 223 * dio_complete.
224 up_read_non_owner(&dio->inode->i_alloc_sem);
225}
226
227/*
228 * Called when a BIO has been processed. If the count goes to zero then IO is
229 * complete and we can signal this to the AIO layer.
230 */ 224 */
231static void finished_one_bio(struct dio *dio) 225static int dio_complete(struct dio *dio, loff_t offset, int ret)
232{ 226{
233 unsigned long flags; 227 ssize_t transferred = 0;
234 228
235 spin_lock_irqsave(&dio->bio_lock, flags); 229 /*
236 if (dio->bio_count == 1) { 230 * AIO submission can race with bio completion to get here while
237 if (dio->is_async) { 231 * expecting to have the last io completed by bio completion.
238 ssize_t transferred; 232 * In that case -EIOCBQUEUED is in fact not an error we want
239 loff_t offset; 233 * to preserve through this call.
240 234 */
241 /* 235 if (ret == -EIOCBQUEUED)
242 * Last reference to the dio is going away. 236 ret = 0;
243 * Drop spinlock and complete the DIO.
244 */
245 spin_unlock_irqrestore(&dio->bio_lock, flags);
246 237
247 /* Check for short read case */ 238 if (dio->result) {
248 transferred = dio->result; 239 transferred = dio->result;
249 offset = dio->iocb->ki_pos;
250 240
251 if ((dio->rw == READ) && 241 /* Check for short read case */
252 ((offset + transferred) > dio->i_size)) 242 if ((dio->rw == READ) && ((offset + transferred) > dio->i_size))
253 transferred = dio->i_size - offset; 243 transferred = dio->i_size - offset;
244 }
254 245
255 /* check for error in completion path */ 246 if (dio->end_io && dio->result)
256 if (dio->io_error) 247 dio->end_io(dio->iocb, offset, transferred,
257 transferred = dio->io_error; 248 dio->map_bh.b_private);
249 if (dio->lock_type == DIO_LOCKING)
250 /* lockdep: non-owner release */
251 up_read_non_owner(&dio->inode->i_alloc_sem);
258 252
259 dio_complete(dio, offset, transferred); 253 if (ret == 0)
254 ret = dio->page_errors;
255 if (ret == 0)
256 ret = dio->io_error;
257 if (ret == 0)
258 ret = transferred;
260 259
261 /* Complete AIO later if falling back to buffered i/o */ 260 return ret;
262 if (dio->result == dio->size ||
263 ((dio->rw == READ) && dio->result)) {
264 aio_complete(dio->iocb, transferred, 0);
265 kfree(dio);
266 return;
267 } else {
268 /*
269 * Falling back to buffered
270 */
271 spin_lock_irqsave(&dio->bio_lock, flags);
272 dio->bio_count--;
273 if (dio->waiter)
274 wake_up_process(dio->waiter);
275 spin_unlock_irqrestore(&dio->bio_lock, flags);
276 return;
277 }
278 }
279 }
280 dio->bio_count--;
281 spin_unlock_irqrestore(&dio->bio_lock, flags);
282} 261}
283 262
284static int dio_bio_complete(struct dio *dio, struct bio *bio); 263static int dio_bio_complete(struct dio *dio, struct bio *bio);
@@ -288,12 +267,27 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio);
288static int dio_bio_end_aio(struct bio *bio, unsigned int bytes_done, int error) 267static int dio_bio_end_aio(struct bio *bio, unsigned int bytes_done, int error)
289{ 268{
290 struct dio *dio = bio->bi_private; 269 struct dio *dio = bio->bi_private;
270 unsigned long remaining;
271 unsigned long flags;
291 272
292 if (bio->bi_size) 273 if (bio->bi_size)
293 return 1; 274 return 1;
294 275
295 /* cleanup the bio */ 276 /* cleanup the bio */
296 dio_bio_complete(dio, bio); 277 dio_bio_complete(dio, bio);
278
279 spin_lock_irqsave(&dio->bio_lock, flags);
280 remaining = --dio->refcount;
281 if (remaining == 1 && dio->waiter)
282 wake_up_process(dio->waiter);
283 spin_unlock_irqrestore(&dio->bio_lock, flags);
284
285 if (remaining == 0) {
286 int ret = dio_complete(dio, dio->iocb->ki_pos, 0);
287 aio_complete(dio->iocb, ret, 0);
288 kfree(dio);
289 }
290
297 return 0; 291 return 0;
298} 292}
299 293
@@ -315,8 +309,7 @@ static int dio_bio_end_io(struct bio *bio, unsigned int bytes_done, int error)
315 spin_lock_irqsave(&dio->bio_lock, flags); 309 spin_lock_irqsave(&dio->bio_lock, flags);
316 bio->bi_private = dio->bio_list; 310 bio->bi_private = dio->bio_list;
317 dio->bio_list = bio; 311 dio->bio_list = bio;
318 dio->bios_in_flight--; 312 if (--dio->refcount == 1 && dio->waiter)
319 if (dio->waiter && dio->bios_in_flight == 0)
320 wake_up_process(dio->waiter); 313 wake_up_process(dio->waiter);
321 spin_unlock_irqrestore(&dio->bio_lock, flags); 314 spin_unlock_irqrestore(&dio->bio_lock, flags);
322 return 0; 315 return 0;
@@ -347,6 +340,8 @@ dio_bio_alloc(struct dio *dio, struct block_device *bdev,
347 * In the AIO read case we speculatively dirty the pages before starting IO. 340 * In the AIO read case we speculatively dirty the pages before starting IO.
348 * During IO completion, any of these pages which happen to have been written 341 * During IO completion, any of these pages which happen to have been written
349 * back will be redirtied by bio_check_pages_dirty(). 342 * back will be redirtied by bio_check_pages_dirty().
343 *
344 * bios hold a dio reference between submit_bio and ->end_io.
350 */ 345 */
351static void dio_bio_submit(struct dio *dio) 346static void dio_bio_submit(struct dio *dio)
352{ 347{
@@ -354,12 +349,14 @@ static void dio_bio_submit(struct dio *dio)
354 unsigned long flags; 349 unsigned long flags;
355 350
356 bio->bi_private = dio; 351 bio->bi_private = dio;
352
357 spin_lock_irqsave(&dio->bio_lock, flags); 353 spin_lock_irqsave(&dio->bio_lock, flags);
358 dio->bio_count++; 354 dio->refcount++;
359 dio->bios_in_flight++;
360 spin_unlock_irqrestore(&dio->bio_lock, flags); 355 spin_unlock_irqrestore(&dio->bio_lock, flags);
356
361 if (dio->is_async && dio->rw == READ) 357 if (dio->is_async && dio->rw == READ)
362 bio_set_pages_dirty(bio); 358 bio_set_pages_dirty(bio);
359
363 submit_bio(dio->rw, bio); 360 submit_bio(dio->rw, bio);
364 361
365 dio->bio = NULL; 362 dio->bio = NULL;
@@ -376,28 +373,37 @@ static void dio_cleanup(struct dio *dio)
376} 373}
377 374
378/* 375/*
379 * Wait for the next BIO to complete. Remove it and return it. 376 * Wait for the next BIO to complete. Remove it and return it. NULL is
377 * returned once all BIOs have been completed. This must only be called once
378 * all bios have been issued so that dio->refcount can only decrease. This
379 * requires that that the caller hold a reference on the dio.
380 */ 380 */
381static struct bio *dio_await_one(struct dio *dio) 381static struct bio *dio_await_one(struct dio *dio)
382{ 382{
383 unsigned long flags; 383 unsigned long flags;
384 struct bio *bio; 384 struct bio *bio = NULL;
385 385
386 spin_lock_irqsave(&dio->bio_lock, flags); 386 spin_lock_irqsave(&dio->bio_lock, flags);
387 while (dio->bio_list == NULL) { 387
388 set_current_state(TASK_UNINTERRUPTIBLE); 388 /*
389 if (dio->bio_list == NULL) { 389 * Wait as long as the list is empty and there are bios in flight. bio
390 dio->waiter = current; 390 * completion drops the count, maybe adds to the list, and wakes while
391 spin_unlock_irqrestore(&dio->bio_lock, flags); 391 * holding the bio_lock so we don't need set_current_state()'s barrier
392 blk_run_address_space(dio->inode->i_mapping); 392 * and can call it after testing our condition.
393 io_schedule(); 393 */
394 spin_lock_irqsave(&dio->bio_lock, flags); 394 while (dio->refcount > 1 && dio->bio_list == NULL) {
395 dio->waiter = NULL; 395 __set_current_state(TASK_UNINTERRUPTIBLE);
396 } 396 dio->waiter = current;
397 set_current_state(TASK_RUNNING); 397 spin_unlock_irqrestore(&dio->bio_lock, flags);
398 io_schedule();
399 /* wake up sets us TASK_RUNNING */
400 spin_lock_irqsave(&dio->bio_lock, flags);
401 dio->waiter = NULL;
402 }
403 if (dio->bio_list) {
404 bio = dio->bio_list;
405 dio->bio_list = bio->bi_private;
398 } 406 }
399 bio = dio->bio_list;
400 dio->bio_list = bio->bi_private;
401 spin_unlock_irqrestore(&dio->bio_lock, flags); 407 spin_unlock_irqrestore(&dio->bio_lock, flags);
402 return bio; 408 return bio;
403} 409}
@@ -426,34 +432,24 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
426 } 432 }
427 bio_put(bio); 433 bio_put(bio);
428 } 434 }
429 finished_one_bio(dio);
430 return uptodate ? 0 : -EIO; 435 return uptodate ? 0 : -EIO;
431} 436}
432 437
433/* 438/*
434 * Wait on and process all in-flight BIOs. 439 * Wait on and process all in-flight BIOs. This must only be called once
440 * all bios have been issued so that the refcount can only decrease.
441 * This just waits for all bios to make it through dio_bio_complete. IO
442 * errors are propogated through dio->io_error and should be propogated via
443 * dio_complete().
435 */ 444 */
436static int dio_await_completion(struct dio *dio) 445static void dio_await_completion(struct dio *dio)
437{ 446{
438 int ret = 0; 447 struct bio *bio;
439 448 do {
440 if (dio->bio) 449 bio = dio_await_one(dio);
441 dio_bio_submit(dio); 450 if (bio)
442 451 dio_bio_complete(dio, bio);
443 /* 452 } while (bio);
444 * The bio_lock is not held for the read of bio_count.
445 * This is ok since it is the dio_bio_complete() that changes
446 * bio_count.
447 */
448 while (dio->bio_count) {
449 struct bio *bio = dio_await_one(dio);
450 int ret2;
451
452 ret2 = dio_bio_complete(dio, bio);
453 if (ret == 0)
454 ret = ret2;
455 }
456 return ret;
457} 453}
458 454
459/* 455/*
@@ -675,6 +671,13 @@ submit_page_section(struct dio *dio, struct page *page,
675{ 671{
676 int ret = 0; 672 int ret = 0;
677 673
674 if (dio->rw & WRITE) {
675 /*
676 * Read accounting is performed in submit_bio()
677 */
678 task_io_account_write(len);
679 }
680
678 /* 681 /*
679 * Can we just grow the current page's presence in the dio? 682 * Can we just grow the current page's presence in the dio?
680 */ 683 */
@@ -953,6 +956,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
953 struct dio *dio) 956 struct dio *dio)
954{ 957{
955 unsigned long user_addr; 958 unsigned long user_addr;
959 unsigned long flags;
956 int seg; 960 int seg;
957 ssize_t ret = 0; 961 ssize_t ret = 0;
958 ssize_t ret2; 962 ssize_t ret2;
@@ -983,17 +987,8 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
983 dio->iocb = iocb; 987 dio->iocb = iocb;
984 dio->i_size = i_size_read(inode); 988 dio->i_size = i_size_read(inode);
985 989
986 /*
987 * BIO completion state.
988 *
989 * ->bio_count starts out at one, and we decrement it to zero after all
990 * BIOs are submitted. This to avoid the situation where a really fast
991 * (or synchronous) device could take the count to zero while we're
992 * still submitting BIOs.
993 */
994 dio->bio_count = 1;
995 dio->bios_in_flight = 0;
996 spin_lock_init(&dio->bio_lock); 990 spin_lock_init(&dio->bio_lock);
991 dio->refcount = 1;
997 dio->bio_list = NULL; 992 dio->bio_list = NULL;
998 dio->waiter = NULL; 993 dio->waiter = NULL;
999 994
@@ -1069,6 +1064,9 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
1069 if (dio->bio) 1064 if (dio->bio)
1070 dio_bio_submit(dio); 1065 dio_bio_submit(dio);
1071 1066
1067 /* All IO is now issued, send it on its way */
1068 blk_run_address_space(inode->i_mapping);
1069
1072 /* 1070 /*
1073 * It is possible that, we return short IO due to end of file. 1071 * It is possible that, we return short IO due to end of file.
1074 * In that case, we need to release all the pages we got hold on. 1072 * In that case, we need to release all the pages we got hold on.
@@ -1084,74 +1082,41 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
1084 mutex_unlock(&dio->inode->i_mutex); 1082 mutex_unlock(&dio->inode->i_mutex);
1085 1083
1086 /* 1084 /*
1087 * OK, all BIOs are submitted, so we can decrement bio_count to truly 1085 * The only time we want to leave bios in flight is when a successful
1088 * reflect the number of to-be-processed BIOs. 1086 * partial aio read or full aio write have been setup. In that case
1087 * bio completion will call aio_complete. The only time it's safe to
1088 * call aio_complete is when we return -EIOCBQUEUED, so we key on that.
1089 * This had *better* be the only place that raises -EIOCBQUEUED.
1089 */ 1090 */
1090 if (dio->is_async) { 1091 BUG_ON(ret == -EIOCBQUEUED);
1091 int should_wait = 0; 1092 if (dio->is_async && ret == 0 && dio->result &&
1093 ((rw & READ) || (dio->result == dio->size)))
1094 ret = -EIOCBQUEUED;
1092 1095
1093 if (dio->result < dio->size && (rw & WRITE)) { 1096 if (ret != -EIOCBQUEUED)
1094 dio->waiter = current; 1097 dio_await_completion(dio);
1095 should_wait = 1;
1096 }
1097 if (ret == 0)
1098 ret = dio->result;
1099 finished_one_bio(dio); /* This can free the dio */
1100 blk_run_address_space(inode->i_mapping);
1101 if (should_wait) {
1102 unsigned long flags;
1103 /*
1104 * Wait for already issued I/O to drain out and
1105 * release its references to user-space pages
1106 * before returning to fallback on buffered I/O
1107 */
1108
1109 spin_lock_irqsave(&dio->bio_lock, flags);
1110 set_current_state(TASK_UNINTERRUPTIBLE);
1111 while (dio->bio_count) {
1112 spin_unlock_irqrestore(&dio->bio_lock, flags);
1113 io_schedule();
1114 spin_lock_irqsave(&dio->bio_lock, flags);
1115 set_current_state(TASK_UNINTERRUPTIBLE);
1116 }
1117 spin_unlock_irqrestore(&dio->bio_lock, flags);
1118 set_current_state(TASK_RUNNING);
1119 kfree(dio);
1120 }
1121 } else {
1122 ssize_t transferred = 0;
1123
1124 finished_one_bio(dio);
1125 ret2 = dio_await_completion(dio);
1126 if (ret == 0)
1127 ret = ret2;
1128 if (ret == 0)
1129 ret = dio->page_errors;
1130 if (dio->result) {
1131 loff_t i_size = i_size_read(inode);
1132
1133 transferred = dio->result;
1134 /*
1135 * Adjust the return value if the read crossed a
1136 * non-block-aligned EOF.
1137 */
1138 if (rw == READ && (offset + transferred > i_size))
1139 transferred = i_size - offset;
1140 }
1141 dio_complete(dio, offset, transferred);
1142 if (ret == 0)
1143 ret = transferred;
1144 1098
1145 /* We could have also come here on an AIO file extend */ 1099 /*
1146 if (!is_sync_kiocb(iocb) && (rw & WRITE) && 1100 * Sync will always be dropping the final ref and completing the
1147 ret >= 0 && dio->result == dio->size) 1101 * operation. AIO can if it was a broken operation described above or
1148 /* 1102 * in fact if all the bios race to complete before we get here. In
1149 * For AIO writes where we have completed the 1103 * that case dio_complete() translates the EIOCBQUEUED into the proper
1150 * i/o, we have to mark the the aio complete. 1104 * return code that the caller will hand to aio_complete().
1151 */ 1105 *
1152 aio_complete(iocb, ret, 0); 1106 * This is managed by the bio_lock instead of being an atomic_t so that
1107 * completion paths can drop their ref and use the remaining count to
1108 * decide to wake the submission path atomically.
1109 */
1110 spin_lock_irqsave(&dio->bio_lock, flags);
1111 ret2 = --dio->refcount;
1112 spin_unlock_irqrestore(&dio->bio_lock, flags);
1113 BUG_ON(!dio->is_async && ret2 != 0);
1114 if (ret2 == 0) {
1115 ret = dio_complete(dio, offset, ret);
1153 kfree(dio); 1116 kfree(dio);
1154 } 1117 } else
1118 BUG_ON(ret != -EIOCBQUEUED);
1119
1155 return ret; 1120 return ret;
1156} 1121}
1157 1122
diff --git a/fs/dnotify.c b/fs/dnotify.c
index 1f26a2b9eee1..936409fcd939 100644
--- a/fs/dnotify.c
+++ b/fs/dnotify.c
@@ -42,7 +42,7 @@ void dnotify_flush(struct file *filp, fl_owner_t id)
42 struct dnotify_struct **prev; 42 struct dnotify_struct **prev;
43 struct inode *inode; 43 struct inode *inode;
44 44
45 inode = filp->f_dentry->d_inode; 45 inode = filp->f_path.dentry->d_inode;
46 if (!S_ISDIR(inode->i_mode)) 46 if (!S_ISDIR(inode->i_mode))
47 return; 47 return;
48 spin_lock(&inode->i_lock); 48 spin_lock(&inode->i_lock);
@@ -74,7 +74,7 @@ int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)
74 } 74 }
75 if (!dir_notify_enable) 75 if (!dir_notify_enable)
76 return -EINVAL; 76 return -EINVAL;
77 inode = filp->f_dentry->d_inode; 77 inode = filp->f_path.dentry->d_inode;
78 if (!S_ISDIR(inode->i_mode)) 78 if (!S_ISDIR(inode->i_mode))
79 return -ENOTDIR; 79 return -ENOTDIR;
80 dn = kmem_cache_alloc(dn_cache, GFP_KERNEL); 80 dn = kmem_cache_alloc(dn_cache, GFP_KERNEL);
diff --git a/fs/dquot.c b/fs/dquot.c
index f9cd5e23ebdf..0952cc474d9a 100644
--- a/fs/dquot.c
+++ b/fs/dquot.c
@@ -694,9 +694,9 @@ restart:
694 file_list_lock(); 694 file_list_lock();
695 list_for_each(p, &sb->s_files) { 695 list_for_each(p, &sb->s_files) {
696 struct file *filp = list_entry(p, struct file, f_u.fu_list); 696 struct file *filp = list_entry(p, struct file, f_u.fu_list);
697 struct inode *inode = filp->f_dentry->d_inode; 697 struct inode *inode = filp->f_path.dentry->d_inode;
698 if (filp->f_mode & FMODE_WRITE && dqinit_needed(inode, type)) { 698 if (filp->f_mode & FMODE_WRITE && dqinit_needed(inode, type)) {
699 struct dentry *dentry = dget(filp->f_dentry); 699 struct dentry *dentry = dget(filp->f_path.dentry);
700 file_list_unlock(); 700 file_list_unlock();
701 sb->dq_op->initialize(inode, type); 701 sb->dq_op->initialize(inode, type);
702 dput(dentry); 702 dput(dentry);
@@ -828,6 +828,7 @@ static inline int need_print_warning(struct dquot *dquot)
828static void print_warning(struct dquot *dquot, const char warntype) 828static void print_warning(struct dquot *dquot, const char warntype)
829{ 829{
830 char *msg = NULL; 830 char *msg = NULL;
831 struct tty_struct *tty;
831 int flag = (warntype == BHARDWARN || warntype == BSOFTLONGWARN) ? DQ_BLKS_B : 832 int flag = (warntype == BHARDWARN || warntype == BSOFTLONGWARN) ? DQ_BLKS_B :
832 ((warntype == IHARDWARN || warntype == ISOFTLONGWARN) ? DQ_INODES_B : 0); 833 ((warntype == IHARDWARN || warntype == ISOFTLONGWARN) ? DQ_INODES_B : 0);
833 834
@@ -835,14 +836,15 @@ static void print_warning(struct dquot *dquot, const char warntype)
835 return; 836 return;
836 837
837 mutex_lock(&tty_mutex); 838 mutex_lock(&tty_mutex);
838 if (!current->signal->tty) 839 tty = get_current_tty();
840 if (!tty)
839 goto out_lock; 841 goto out_lock;
840 tty_write_message(current->signal->tty, dquot->dq_sb->s_id); 842 tty_write_message(tty, dquot->dq_sb->s_id);
841 if (warntype == ISOFTWARN || warntype == BSOFTWARN) 843 if (warntype == ISOFTWARN || warntype == BSOFTWARN)
842 tty_write_message(current->signal->tty, ": warning, "); 844 tty_write_message(tty, ": warning, ");
843 else 845 else
844 tty_write_message(current->signal->tty, ": write failed, "); 846 tty_write_message(tty, ": write failed, ");
845 tty_write_message(current->signal->tty, quotatypes[dquot->dq_type]); 847 tty_write_message(tty, quotatypes[dquot->dq_type]);
846 switch (warntype) { 848 switch (warntype) {
847 case IHARDWARN: 849 case IHARDWARN:
848 msg = " file limit reached.\r\n"; 850 msg = " file limit reached.\r\n";
@@ -863,7 +865,7 @@ static void print_warning(struct dquot *dquot, const char warntype)
863 msg = " block quota exceeded.\r\n"; 865 msg = " block quota exceeded.\r\n";
864 break; 866 break;
865 } 867 }
866 tty_write_message(current->signal->tty, msg); 868 tty_write_message(tty, msg);
867out_lock: 869out_lock:
868 mutex_unlock(&tty_mutex); 870 mutex_unlock(&tty_mutex);
869} 871}
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c
index 52d1e36dc746..329efcd3d8c9 100644
--- a/fs/ecryptfs/dentry.c
+++ b/fs/ecryptfs/dentry.c
@@ -25,6 +25,7 @@
25#include <linux/dcache.h> 25#include <linux/dcache.h>
26#include <linux/namei.h> 26#include <linux/namei.h>
27#include <linux/mount.h> 27#include <linux/mount.h>
28#include <linux/fs_stack.h>
28#include "ecryptfs_kernel.h" 29#include "ecryptfs_kernel.h"
29 30
30/** 31/**
@@ -61,7 +62,7 @@ static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
61 struct inode *lower_inode = 62 struct inode *lower_inode =
62 ecryptfs_inode_to_lower(dentry->d_inode); 63 ecryptfs_inode_to_lower(dentry->d_inode);
63 64
64 ecryptfs_copy_attr_all(dentry->d_inode, lower_inode); 65 fsstack_copy_attr_all(dentry->d_inode, lower_inode, NULL);
65 } 66 }
66out: 67out:
67 return rc; 68 return rc;
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index f992533d1692..afb64bdbe6ad 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -28,6 +28,8 @@
28 28
29#include <keys/user-type.h> 29#include <keys/user-type.h>
30#include <linux/fs.h> 30#include <linux/fs.h>
31#include <linux/fs_stack.h>
32#include <linux/namei.h>
31#include <linux/scatterlist.h> 33#include <linux/scatterlist.h>
32 34
33/* Version verification for shared data structures w/ userspace */ 35/* Version verification for shared data structures w/ userspace */
@@ -227,8 +229,7 @@ struct ecryptfs_inode_info {
227/* dentry private data. Each dentry must keep track of a lower 229/* dentry private data. Each dentry must keep track of a lower
228 * vfsmount too. */ 230 * vfsmount too. */
229struct ecryptfs_dentry_info { 231struct ecryptfs_dentry_info {
230 struct dentry *wdi_dentry; 232 struct path lower_path;
231 struct vfsmount *lower_mnt;
232 struct ecryptfs_crypt_stat *crypt_stat; 233 struct ecryptfs_crypt_stat *crypt_stat;
233}; 234};
234 235
@@ -355,26 +356,26 @@ ecryptfs_set_dentry_private(struct dentry *dentry,
355static inline struct dentry * 356static inline struct dentry *
356ecryptfs_dentry_to_lower(struct dentry *dentry) 357ecryptfs_dentry_to_lower(struct dentry *dentry)
357{ 358{
358 return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->wdi_dentry; 359 return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
359} 360}
360 361
361static inline void 362static inline void
362ecryptfs_set_dentry_lower(struct dentry *dentry, struct dentry *lower_dentry) 363ecryptfs_set_dentry_lower(struct dentry *dentry, struct dentry *lower_dentry)
363{ 364{
364 ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->wdi_dentry = 365 ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry =
365 lower_dentry; 366 lower_dentry;
366} 367}
367 368
368static inline struct vfsmount * 369static inline struct vfsmount *
369ecryptfs_dentry_to_lower_mnt(struct dentry *dentry) 370ecryptfs_dentry_to_lower_mnt(struct dentry *dentry)
370{ 371{
371 return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_mnt; 372 return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
372} 373}
373 374
374static inline void 375static inline void
375ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt) 376ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt)
376{ 377{
377 ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_mnt = 378 ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt =
378 lower_mnt; 379 lower_mnt;
379} 380}
380 381
@@ -413,9 +414,6 @@ int ecryptfs_encode_filename(struct ecryptfs_crypt_stat *crypt_stat,
413 const char *name, int length, 414 const char *name, int length,
414 char **encoded_name); 415 char **encoded_name);
415struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry); 416struct dentry *ecryptfs_lower_dentry(struct dentry *this_dentry);
416void ecryptfs_copy_attr_atime(struct inode *dest, const struct inode *src);
417void ecryptfs_copy_attr_all(struct inode *dest, const struct inode *src);
418void ecryptfs_copy_inode_size(struct inode *dst, const struct inode *src);
419void ecryptfs_dump_hex(char *data, int bytes); 417void ecryptfs_dump_hex(char *data, int bytes);
420int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg, 418int virt_to_scatterlist(const void *addr, int size, struct scatterlist *sg,
421 int sg_size); 419 int sg_size);
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 42099e779a56..c5a2e5298f15 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -30,6 +30,7 @@
30#include <linux/security.h> 30#include <linux/security.h>
31#include <linux/smp_lock.h> 31#include <linux/smp_lock.h>
32#include <linux/compat.h> 32#include <linux/compat.h>
33#include <linux/fs_stack.h>
33#include "ecryptfs_kernel.h" 34#include "ecryptfs_kernel.h"
34 35
35/** 36/**
@@ -75,7 +76,7 @@ static loff_t ecryptfs_llseek(struct file *file, loff_t offset, int origin)
75 } 76 }
76 ecryptfs_printk(KERN_DEBUG, "new_end_pos = [0x%.16x]\n", new_end_pos); 77 ecryptfs_printk(KERN_DEBUG, "new_end_pos = [0x%.16x]\n", new_end_pos);
77 if (expanding_file) { 78 if (expanding_file) {
78 rc = ecryptfs_truncate(file->f_dentry, new_end_pos); 79 rc = ecryptfs_truncate(file->f_path.dentry, new_end_pos);
79 if (rc) { 80 if (rc) {
80 rv = rc; 81 rv = rc;
81 ecryptfs_printk(KERN_ERR, "Error on attempt to " 82 ecryptfs_printk(KERN_ERR, "Error on attempt to "
@@ -116,8 +117,8 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
116 if (-EIOCBQUEUED == rc) 117 if (-EIOCBQUEUED == rc)
117 rc = wait_on_sync_kiocb(iocb); 118 rc = wait_on_sync_kiocb(iocb);
118 if (rc >= 0) { 119 if (rc >= 0) {
119 lower_dentry = ecryptfs_dentry_to_lower(file->f_dentry); 120 lower_dentry = ecryptfs_dentry_to_lower(file->f_path.dentry);
120 lower_vfsmount = ecryptfs_dentry_to_lower_mnt(file->f_dentry); 121 lower_vfsmount = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry);
121 touch_atime(lower_vfsmount, lower_dentry); 122 touch_atime(lower_vfsmount, lower_dentry);
122 } 123 }
123 return rc; 124 return rc;
@@ -176,10 +177,10 @@ static int ecryptfs_readdir(struct file *file, void *dirent, filldir_t filldir)
176 177
177 lower_file = ecryptfs_file_to_lower(file); 178 lower_file = ecryptfs_file_to_lower(file);
178 lower_file->f_pos = file->f_pos; 179 lower_file->f_pos = file->f_pos;
179 inode = file->f_dentry->d_inode; 180 inode = file->f_path.dentry->d_inode;
180 memset(&buf, 0, sizeof(buf)); 181 memset(&buf, 0, sizeof(buf));
181 buf.dirent = dirent; 182 buf.dirent = dirent;
182 buf.dentry = file->f_dentry; 183 buf.dentry = file->f_path.dentry;
183 buf.filldir = filldir; 184 buf.filldir = filldir;
184retry: 185retry:
185 buf.filldir_called = 0; 186 buf.filldir_called = 0;
@@ -192,7 +193,7 @@ retry:
192 goto retry; 193 goto retry;
193 file->f_pos = lower_file->f_pos; 194 file->f_pos = lower_file->f_pos;
194 if (rc >= 0) 195 if (rc >= 0)
195 ecryptfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode); 196 fsstack_copy_attr_atime(inode, lower_file->f_path.dentry->d_inode);
196 return rc; 197 return rc;
197} 198}
198 199
@@ -239,7 +240,7 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
239 int rc = 0; 240 int rc = 0;
240 struct ecryptfs_crypt_stat *crypt_stat = NULL; 241 struct ecryptfs_crypt_stat *crypt_stat = NULL;
241 struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 242 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
242 struct dentry *ecryptfs_dentry = file->f_dentry; 243 struct dentry *ecryptfs_dentry = file->f_path.dentry;
243 /* Private value of ecryptfs_dentry allocated in 244 /* Private value of ecryptfs_dentry allocated in
244 * ecryptfs_lookup() */ 245 * ecryptfs_lookup() */
245 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); 246 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 8a1945a84c36..11f5e5076aef 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -30,6 +30,7 @@
30#include <linux/namei.h> 30#include <linux/namei.h>
31#include <linux/mount.h> 31#include <linux/mount.h>
32#include <linux/crypto.h> 32#include <linux/crypto.h>
33#include <linux/fs_stack.h>
33#include "ecryptfs_kernel.h" 34#include "ecryptfs_kernel.h"
34 35
35static struct dentry *lock_parent(struct dentry *dentry) 36static struct dentry *lock_parent(struct dentry *dentry)
@@ -53,48 +54,6 @@ static void unlock_dir(struct dentry *dir)
53 dput(dir); 54 dput(dir);
54} 55}
55 56
56void ecryptfs_copy_inode_size(struct inode *dst, const struct inode *src)
57{
58 i_size_write(dst, i_size_read((struct inode *)src));
59 dst->i_blocks = src->i_blocks;
60}
61
62void ecryptfs_copy_attr_atime(struct inode *dest, const struct inode *src)
63{
64 dest->i_atime = src->i_atime;
65}
66
67static void ecryptfs_copy_attr_times(struct inode *dest,
68 const struct inode *src)
69{
70 dest->i_atime = src->i_atime;
71 dest->i_mtime = src->i_mtime;
72 dest->i_ctime = src->i_ctime;
73}
74
75static void ecryptfs_copy_attr_timesizes(struct inode *dest,
76 const struct inode *src)
77{
78 dest->i_atime = src->i_atime;
79 dest->i_mtime = src->i_mtime;
80 dest->i_ctime = src->i_ctime;
81 ecryptfs_copy_inode_size(dest, src);
82}
83
84void ecryptfs_copy_attr_all(struct inode *dest, const struct inode *src)
85{
86 dest->i_mode = src->i_mode;
87 dest->i_nlink = src->i_nlink;
88 dest->i_uid = src->i_uid;
89 dest->i_gid = src->i_gid;
90 dest->i_rdev = src->i_rdev;
91 dest->i_atime = src->i_atime;
92 dest->i_mtime = src->i_mtime;
93 dest->i_ctime = src->i_ctime;
94 dest->i_blkbits = src->i_blkbits;
95 dest->i_flags = src->i_flags;
96}
97
98/** 57/**
99 * ecryptfs_create_underlying_file 58 * ecryptfs_create_underlying_file
100 * @lower_dir_inode: inode of the parent in the lower fs of the new file 59 * @lower_dir_inode: inode of the parent in the lower fs of the new file
@@ -171,8 +130,8 @@ ecryptfs_do_create(struct inode *directory_inode,
171 ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n"); 130 ecryptfs_printk(KERN_ERR, "Failure in ecryptfs_interpose\n");
172 goto out_lock; 131 goto out_lock;
173 } 132 }
174 ecryptfs_copy_attr_timesizes(directory_inode, 133 fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode);
175 lower_dir_dentry->d_inode); 134 fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode);
176out_lock: 135out_lock:
177 unlock_dir(lower_dir_dentry); 136 unlock_dir(lower_dir_dentry);
178out: 137out:
@@ -196,7 +155,7 @@ static int grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file,
196 struct ecryptfs_file_info tmp_file_info; 155 struct ecryptfs_file_info tmp_file_info;
197 156
198 memset(&fake_file, 0, sizeof(fake_file)); 157 memset(&fake_file, 0, sizeof(fake_file));
199 fake_file.f_dentry = ecryptfs_dentry; 158 fake_file.f_path.dentry = ecryptfs_dentry;
200 memset(&tmp_file_info, 0, sizeof(tmp_file_info)); 159 memset(&tmp_file_info, 0, sizeof(tmp_file_info));
201 ecryptfs_set_file_private(&fake_file, &tmp_file_info); 160 ecryptfs_set_file_private(&fake_file, &tmp_file_info);
202 ecryptfs_set_file_lower(&fake_file, lower_file); 161 ecryptfs_set_file_lower(&fake_file, lower_file);
@@ -365,7 +324,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
365 "d_name.name = [%s]\n", lower_dentry, 324 "d_name.name = [%s]\n", lower_dentry,
366 lower_dentry->d_name.name); 325 lower_dentry->d_name.name);
367 lower_inode = lower_dentry->d_inode; 326 lower_inode = lower_dentry->d_inode;
368 ecryptfs_copy_attr_atime(dir, lower_dir_dentry->d_inode); 327 fsstack_copy_attr_atime(dir, lower_dir_dentry->d_inode);
369 BUG_ON(!atomic_read(&lower_dentry->d_count)); 328 BUG_ON(!atomic_read(&lower_dentry->d_count));
370 ecryptfs_set_dentry_private(dentry, 329 ecryptfs_set_dentry_private(dentry,
371 kmem_cache_alloc(ecryptfs_dentry_info_cache, 330 kmem_cache_alloc(ecryptfs_dentry_info_cache,
@@ -462,7 +421,8 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
462 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0); 421 rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb, 0);
463 if (rc) 422 if (rc)
464 goto out_lock; 423 goto out_lock;
465 ecryptfs_copy_attr_timesizes(dir, lower_new_dentry->d_inode); 424 fsstack_copy_attr_times(dir, lower_new_dentry->d_inode);
425 fsstack_copy_inode_size(dir, lower_new_dentry->d_inode);
466 old_dentry->d_inode->i_nlink = 426 old_dentry->d_inode->i_nlink =
467 ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink; 427 ecryptfs_inode_to_lower(old_dentry->d_inode)->i_nlink;
468 i_size_write(new_dentry->d_inode, file_size_save); 428 i_size_write(new_dentry->d_inode, file_size_save);
@@ -488,7 +448,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
488 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); 448 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
489 goto out_unlock; 449 goto out_unlock;
490 } 450 }
491 ecryptfs_copy_attr_times(dir, lower_dir_inode); 451 fsstack_copy_attr_times(dir, lower_dir_inode);
492 dentry->d_inode->i_nlink = 452 dentry->d_inode->i_nlink =
493 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink; 453 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink;
494 dentry->d_inode->i_ctime = dir->i_ctime; 454 dentry->d_inode->i_ctime = dir->i_ctime;
@@ -527,7 +487,8 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
527 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 487 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
528 if (rc) 488 if (rc)
529 goto out_lock; 489 goto out_lock;
530 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 490 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
491 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
531out_lock: 492out_lock:
532 unlock_dir(lower_dir_dentry); 493 unlock_dir(lower_dir_dentry);
533 dput(lower_dentry); 494 dput(lower_dentry);
@@ -550,7 +511,8 @@ static int ecryptfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
550 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 511 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
551 if (rc) 512 if (rc)
552 goto out; 513 goto out;
553 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 514 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
515 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
554 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; 516 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
555out: 517out:
556 unlock_dir(lower_dir_dentry); 518 unlock_dir(lower_dir_dentry);
@@ -573,7 +535,7 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
573 dput(lower_dentry); 535 dput(lower_dentry);
574 if (!rc) 536 if (!rc)
575 d_delete(lower_dentry); 537 d_delete(lower_dentry);
576 ecryptfs_copy_attr_times(dir, lower_dir_dentry->d_inode); 538 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
577 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; 539 dir->i_nlink = lower_dir_dentry->d_inode->i_nlink;
578 unlock_dir(lower_dir_dentry); 540 unlock_dir(lower_dir_dentry);
579 if (!rc) 541 if (!rc)
@@ -597,7 +559,8 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
597 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); 559 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
598 if (rc) 560 if (rc)
599 goto out; 561 goto out;
600 ecryptfs_copy_attr_timesizes(dir, lower_dir_dentry->d_inode); 562 fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);
563 fsstack_copy_inode_size(dir, lower_dir_dentry->d_inode);
601out: 564out:
602 unlock_dir(lower_dir_dentry); 565 unlock_dir(lower_dir_dentry);
603 if (!dentry->d_inode) 566 if (!dentry->d_inode)
@@ -626,9 +589,9 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
626 lower_new_dir_dentry->d_inode, lower_new_dentry); 589 lower_new_dir_dentry->d_inode, lower_new_dentry);
627 if (rc) 590 if (rc)
628 goto out_lock; 591 goto out_lock;
629 ecryptfs_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode); 592 fsstack_copy_attr_all(new_dir, lower_new_dir_dentry->d_inode, NULL);
630 if (new_dir != old_dir) 593 if (new_dir != old_dir)
631 ecryptfs_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); 594 fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode, NULL);
632out_lock: 595out_lock:
633 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); 596 unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry);
634 dput(lower_new_dentry->d_parent); 597 dput(lower_new_dentry->d_parent);
@@ -684,8 +647,8 @@ ecryptfs_readlink(struct dentry *dentry, char __user * buf, int bufsiz)
684 rc = -EFAULT; 647 rc = -EFAULT;
685 } 648 }
686 kfree(decoded_name); 649 kfree(decoded_name);
687 ecryptfs_copy_attr_atime(dentry->d_inode, 650 fsstack_copy_attr_atime(dentry->d_inode,
688 lower_dentry->d_inode); 651 lower_dentry->d_inode);
689 } 652 }
690out_free_lower_buf: 653out_free_lower_buf:
691 kfree(lower_buf); 654 kfree(lower_buf);
@@ -791,7 +754,7 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
791 * the file in the underlying filesystem so that the 754 * the file in the underlying filesystem so that the
792 * truncation has an effect there as well. */ 755 * truncation has an effect there as well. */
793 memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file)); 756 memset(&fake_ecryptfs_file, 0, sizeof(fake_ecryptfs_file));
794 fake_ecryptfs_file.f_dentry = dentry; 757 fake_ecryptfs_file.f_path.dentry = dentry;
795 /* Released at out_free: label */ 758 /* Released at out_free: label */
796 ecryptfs_set_file_private(&fake_ecryptfs_file, 759 ecryptfs_set_file_private(&fake_ecryptfs_file,
797 kmem_cache_alloc(ecryptfs_file_info_cache, 760 kmem_cache_alloc(ecryptfs_file_info_cache,
@@ -915,7 +878,7 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
915 } 878 }
916 rc = notify_change(lower_dentry, ia); 879 rc = notify_change(lower_dentry, ia);
917out: 880out:
918 ecryptfs_copy_attr_all(inode, lower_inode); 881 fsstack_copy_attr_all(inode, lower_inode, NULL);
919 return rc; 882 return rc;
920} 883}
921 884
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index 3ede12b25933..d0541ae8faba 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -35,6 +35,7 @@
35#include <linux/pagemap.h> 35#include <linux/pagemap.h>
36#include <linux/key.h> 36#include <linux/key.h>
37#include <linux/parser.h> 37#include <linux/parser.h>
38#include <linux/fs_stack.h>
38#include "ecryptfs_kernel.h" 39#include "ecryptfs_kernel.h"
39 40
40/** 41/**
@@ -112,10 +113,10 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
112 d_add(dentry, inode); 113 d_add(dentry, inode);
113 else 114 else
114 d_instantiate(dentry, inode); 115 d_instantiate(dentry, inode);
115 ecryptfs_copy_attr_all(inode, lower_inode); 116 fsstack_copy_attr_all(inode, lower_inode, NULL);
116 /* This size will be overwritten for real files w/ headers and 117 /* This size will be overwritten for real files w/ headers and
117 * other metadata */ 118 * other metadata */
118 ecryptfs_copy_inode_size(inode, lower_inode); 119 fsstack_copy_inode_size(inode, lower_inode);
119out: 120out:
120 return rc; 121 return rc;
121} 122}
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 924dd90a4cf5..06843d24f239 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -51,7 +51,7 @@ static struct page *ecryptfs_get1page(struct file *file, int index)
51 struct inode *inode; 51 struct inode *inode;
52 struct address_space *mapping; 52 struct address_space *mapping;
53 53
54 dentry = file->f_dentry; 54 dentry = file->f_path.dentry;
55 inode = dentry->d_inode; 55 inode = dentry->d_inode;
56 mapping = inode->i_mapping; 56 mapping = inode->i_mapping;
57 page = read_cache_page(mapping, index, 57 page = read_cache_page(mapping, index,
@@ -84,7 +84,7 @@ int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros);
84int ecryptfs_fill_zeros(struct file *file, loff_t new_length) 84int ecryptfs_fill_zeros(struct file *file, loff_t new_length)
85{ 85{
86 int rc = 0; 86 int rc = 0;
87 struct dentry *dentry = file->f_dentry; 87 struct dentry *dentry = file->f_path.dentry;
88 struct inode *inode = dentry->d_inode; 88 struct inode *inode = dentry->d_inode;
89 pgoff_t old_end_page_index = 0; 89 pgoff_t old_end_page_index = 0;
90 pgoff_t index = old_end_page_index; 90 pgoff_t index = old_end_page_index;
@@ -218,7 +218,7 @@ int ecryptfs_do_readpage(struct file *file, struct page *page,
218 char *lower_page_data; 218 char *lower_page_data;
219 const struct address_space_operations *lower_a_ops; 219 const struct address_space_operations *lower_a_ops;
220 220
221 dentry = file->f_dentry; 221 dentry = file->f_path.dentry;
222 lower_file = ecryptfs_file_to_lower(file); 222 lower_file = ecryptfs_file_to_lower(file);
223 lower_dentry = ecryptfs_dentry_to_lower(dentry); 223 lower_dentry = ecryptfs_dentry_to_lower(dentry);
224 inode = dentry->d_inode; 224 inode = dentry->d_inode;
@@ -275,9 +275,9 @@ static int ecryptfs_readpage(struct file *file, struct page *page)
275 int rc = 0; 275 int rc = 0;
276 struct ecryptfs_crypt_stat *crypt_stat; 276 struct ecryptfs_crypt_stat *crypt_stat;
277 277
278 BUG_ON(!(file && file->f_dentry && file->f_dentry->d_inode)); 278 BUG_ON(!(file && file->f_path.dentry && file->f_path.dentry->d_inode));
279 crypt_stat = 279 crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
280 &ecryptfs_inode_to_private(file->f_dentry->d_inode)->crypt_stat; 280 ->crypt_stat;
281 if (!crypt_stat 281 if (!crypt_stat
282 || !ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED) 282 || !ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED)
283 || ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) { 283 || ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) {
@@ -638,8 +638,8 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
638 lower_inode = ecryptfs_inode_to_lower(inode); 638 lower_inode = ecryptfs_inode_to_lower(inode);
639 lower_file = ecryptfs_file_to_lower(file); 639 lower_file = ecryptfs_file_to_lower(file);
640 mutex_lock(&lower_inode->i_mutex); 640 mutex_lock(&lower_inode->i_mutex);
641 crypt_stat = 641 crypt_stat = &ecryptfs_inode_to_private(file->f_path.dentry->d_inode)
642 &ecryptfs_inode_to_private(file->f_dentry->d_inode)->crypt_stat; 642 ->crypt_stat;
643 if (ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) { 643 if (ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE)) {
644 ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in " 644 ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in "
645 "crypt_stat at memory location [%p]\n", crypt_stat); 645 "crypt_stat at memory location [%p]\n", crypt_stat);
diff --git a/fs/efs/dir.c b/fs/efs/dir.c
index 17f5b2d3c16a..b46c488eefc8 100644
--- a/fs/efs/dir.c
+++ b/fs/efs/dir.c
@@ -20,7 +20,7 @@ struct inode_operations efs_dir_inode_operations = {
20}; 20};
21 21
22static int efs_readdir(struct file *filp, void *dirent, filldir_t filldir) { 22static int efs_readdir(struct file *filp, void *dirent, filldir_t filldir) {
23 struct inode *inode = filp->f_dentry->d_inode; 23 struct inode *inode = filp->f_path.dentry->d_inode;
24 struct buffer_head *bh; 24 struct buffer_head *bh;
25 25
26 struct efs_dir *dirblock; 26 struct efs_dir *dirblock;
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 88a6f8d0b88e..3ae644e7e860 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -795,8 +795,8 @@ static int ep_getfd(int *efd, struct inode **einode, struct file **efile,
795 goto eexit_4; 795 goto eexit_4;
796 dentry->d_op = &eventpollfs_dentry_operations; 796 dentry->d_op = &eventpollfs_dentry_operations;
797 d_add(dentry, inode); 797 d_add(dentry, inode);
798 file->f_vfsmnt = mntget(eventpoll_mnt); 798 file->f_path.mnt = mntget(eventpoll_mnt);
799 file->f_dentry = dentry; 799 file->f_path.dentry = dentry;
800 file->f_mapping = inode->i_mapping; 800 file->f_mapping = inode->i_mapping;
801 801
802 file->f_pos = 0; 802 file->f_pos = 0;
diff --git a/fs/exec.c b/fs/exec.c
index add0e03c3ea9..11fe93f7363c 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -38,6 +38,7 @@
38#include <linux/binfmts.h> 38#include <linux/binfmts.h>
39#include <linux/swap.h> 39#include <linux/swap.h>
40#include <linux/utsname.h> 40#include <linux/utsname.h>
41#include <linux/pid_namespace.h>
41#include <linux/module.h> 42#include <linux/module.h>
42#include <linux/namei.h> 43#include <linux/namei.h>
43#include <linux/proc_fs.h> 44#include <linux/proc_fs.h>
@@ -620,8 +621,8 @@ static int de_thread(struct task_struct *tsk)
620 * Reparenting needs write_lock on tasklist_lock, 621 * Reparenting needs write_lock on tasklist_lock,
621 * so it is safe to do it under read_lock. 622 * so it is safe to do it under read_lock.
622 */ 623 */
623 if (unlikely(tsk->group_leader == child_reaper)) 624 if (unlikely(tsk->group_leader == child_reaper(tsk)))
624 child_reaper = tsk; 625 tsk->nsproxy->pid_ns->child_reaper = tsk;
625 626
626 zap_other_threads(tsk); 627 zap_other_threads(tsk);
627 read_unlock(&tasklist_lock); 628 read_unlock(&tasklist_lock);
@@ -782,7 +783,7 @@ static void flush_old_files(struct files_struct * files)
782 j++; 783 j++;
783 i = j * __NFDBITS; 784 i = j * __NFDBITS;
784 fdt = files_fdtable(files); 785 fdt = files_fdtable(files);
785 if (i >= fdt->max_fds || i >= fdt->max_fdset) 786 if (i >= fdt->max_fds)
786 break; 787 break;
787 set = fdt->close_on_exec->fds_bits[j]; 788 set = fdt->close_on_exec->fds_bits[j];
788 if (!set) 789 if (!set)
@@ -912,7 +913,7 @@ EXPORT_SYMBOL(flush_old_exec);
912int prepare_binprm(struct linux_binprm *bprm) 913int prepare_binprm(struct linux_binprm *bprm)
913{ 914{
914 int mode; 915 int mode;
915 struct inode * inode = bprm->file->f_dentry->d_inode; 916 struct inode * inode = bprm->file->f_path.dentry->d_inode;
916 int retval; 917 int retval;
917 918
918 mode = inode->i_mode; 919 mode = inode->i_mode;
@@ -922,7 +923,7 @@ int prepare_binprm(struct linux_binprm *bprm)
922 bprm->e_uid = current->euid; 923 bprm->e_uid = current->euid;
923 bprm->e_gid = current->egid; 924 bprm->e_gid = current->egid;
924 925
925 if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) { 926 if(!(bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)) {
926 /* Set-uid? */ 927 /* Set-uid? */
927 if (mode & S_ISUID) { 928 if (mode & S_ISUID) {
928 current->personality &= ~PER_CLEAR_ON_SETID; 929 current->personality &= ~PER_CLEAR_ON_SETID;
@@ -1519,10 +1520,10 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1519 0600); 1520 0600);
1520 if (IS_ERR(file)) 1521 if (IS_ERR(file))
1521 goto fail_unlock; 1522 goto fail_unlock;
1522 inode = file->f_dentry->d_inode; 1523 inode = file->f_path.dentry->d_inode;
1523 if (inode->i_nlink > 1) 1524 if (inode->i_nlink > 1)
1524 goto close_fail; /* multiple links - don't dump */ 1525 goto close_fail; /* multiple links - don't dump */
1525 if (!ispipe && d_unhashed(file->f_dentry)) 1526 if (!ispipe && d_unhashed(file->f_path.dentry))
1526 goto close_fail; 1527 goto close_fail;
1527 1528
1528 /* AK: actually i see no reason to not allow this for named pipes etc., 1529 /* AK: actually i see no reason to not allow this for named pipes etc.,
@@ -1533,7 +1534,7 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
1533 goto close_fail; 1534 goto close_fail;
1534 if (!file->f_op->write) 1535 if (!file->f_op->write)
1535 goto close_fail; 1536 goto close_fail;
1536 if (!ispipe && do_truncate(file->f_dentry, 0, 0, file) != 0) 1537 if (!ispipe && do_truncate(file->f_path.dentry, 0, 0, file) != 0)
1537 goto close_fail; 1538 goto close_fail;
1538 1539
1539 retval = binfmt->core_dump(signr, regs, file); 1540 retval = binfmt->core_dump(signr, regs, file);
diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index 3e7a84a1e509..0b02ba9642d2 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -248,7 +248,7 @@ static int
248ext2_readdir (struct file * filp, void * dirent, filldir_t filldir) 248ext2_readdir (struct file * filp, void * dirent, filldir_t filldir)
249{ 249{
250 loff_t pos = filp->f_pos; 250 loff_t pos = filp->f_pos;
251 struct inode *inode = filp->f_dentry->d_inode; 251 struct inode *inode = filp->f_path.dentry->d_inode;
252 struct super_block *sb = inode->i_sb; 252 struct super_block *sb = inode->i_sb;
253 unsigned int offset = pos & ~PAGE_CACHE_MASK; 253 unsigned int offset = pos & ~PAGE_CACHE_MASK;
254 unsigned long n = pos >> PAGE_CACHE_SHIFT; 254 unsigned long n = pos >> PAGE_CACHE_SHIFT;
diff --git a/fs/ext2/ioctl.c b/fs/ext2/ioctl.c
index e3cf8c81507f..4b099d310712 100644
--- a/fs/ext2/ioctl.c
+++ b/fs/ext2/ioctl.c
@@ -90,7 +90,7 @@ int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
90#ifdef CONFIG_COMPAT 90#ifdef CONFIG_COMPAT
91long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 91long ext2_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
92{ 92{
93 struct inode *inode = file->f_dentry->d_inode; 93 struct inode *inode = file->f_path.dentry->d_inode;
94 int ret; 94 int ret;
95 95
96 /* These are just misnamed, they actually get/put from/to user an int */ 96 /* These are just misnamed, they actually get/put from/to user an int */
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 255cef5f7420..6347c2dbdd81 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -597,8 +597,6 @@ static int ext2_check_descriptors (struct super_block * sb)
597 return 1; 597 return 1;
598} 598}
599 599
600#define log2(n) ffz(~(n))
601
602/* 600/*
603 * Maximal file size. There is a direct, and {,double-,triple-}indirect 601 * Maximal file size. There is a direct, and {,double-,triple-}indirect
604 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. 602 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
@@ -834,9 +832,9 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
834 sbi->s_sbh = bh; 832 sbi->s_sbh = bh;
835 sbi->s_mount_state = le16_to_cpu(es->s_state); 833 sbi->s_mount_state = le16_to_cpu(es->s_state);
836 sbi->s_addr_per_block_bits = 834 sbi->s_addr_per_block_bits =
837 log2 (EXT2_ADDR_PER_BLOCK(sb)); 835 ilog2 (EXT2_ADDR_PER_BLOCK(sb));
838 sbi->s_desc_per_block_bits = 836 sbi->s_desc_per_block_bits =
839 log2 (EXT2_DESC_PER_BLOCK(sb)); 837 ilog2 (EXT2_DESC_PER_BLOCK(sb));
840 838
841 if (sb->s_magic != EXT2_SUPER_MAGIC) 839 if (sb->s_magic != EXT2_SUPER_MAGIC)
842 goto cantfind_ext2; 840 goto cantfind_ext2;
diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
index 5a9313ecd4ef..665adee99b31 100644
--- a/fs/ext3/dir.c
+++ b/fs/ext3/dir.c
@@ -103,7 +103,7 @@ static int ext3_readdir(struct file * filp,
103 struct ext3_dir_entry_2 *de; 103 struct ext3_dir_entry_2 *de;
104 struct super_block *sb; 104 struct super_block *sb;
105 int err; 105 int err;
106 struct inode *inode = filp->f_dentry->d_inode; 106 struct inode *inode = filp->f_path.dentry->d_inode;
107 int ret = 0; 107 int ret = 0;
108 108
109 sb = inode->i_sb; 109 sb = inode->i_sb;
@@ -122,7 +122,7 @@ static int ext3_readdir(struct file * filp,
122 * We don't set the inode dirty flag since it's not 122 * We don't set the inode dirty flag since it's not
123 * critical that it get flushed back to the disk. 123 * critical that it get flushed back to the disk.
124 */ 124 */
125 EXT3_I(filp->f_dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL; 125 EXT3_I(filp->f_path.dentry->d_inode)->i_flags &= ~EXT3_INDEX_FL;
126 } 126 }
127#endif 127#endif
128 stored = 0; 128 stored = 0;
@@ -402,7 +402,7 @@ static int call_filldir(struct file * filp, void * dirent,
402{ 402{
403 struct dir_private_info *info = filp->private_data; 403 struct dir_private_info *info = filp->private_data;
404 loff_t curr_pos; 404 loff_t curr_pos;
405 struct inode *inode = filp->f_dentry->d_inode; 405 struct inode *inode = filp->f_path.dentry->d_inode;
406 struct super_block * sb; 406 struct super_block * sb;
407 int error; 407 int error;
408 408
@@ -432,7 +432,7 @@ static int ext3_dx_readdir(struct file * filp,
432 void * dirent, filldir_t filldir) 432 void * dirent, filldir_t filldir)
433{ 433{
434 struct dir_private_info *info = filp->private_data; 434 struct dir_private_info *info = filp->private_data;
435 struct inode *inode = filp->f_dentry->d_inode; 435 struct inode *inode = filp->f_path.dentry->d_inode;
436 struct fname *fname; 436 struct fname *fname;
437 int ret; 437 int ret;
438 438
diff --git a/fs/ext3/file.c b/fs/ext3/file.c
index e96c388047e0..881f6365c41a 100644
--- a/fs/ext3/file.c
+++ b/fs/ext3/file.c
@@ -52,7 +52,7 @@ ext3_file_write(struct kiocb *iocb, const struct iovec *iov,
52 unsigned long nr_segs, loff_t pos) 52 unsigned long nr_segs, loff_t pos)
53{ 53{
54 struct file *file = iocb->ki_filp; 54 struct file *file = iocb->ki_filp;
55 struct inode *inode = file->f_dentry->d_inode; 55 struct inode *inode = file->f_path.dentry->d_inode;
56 ssize_t ret; 56 ssize_t ret;
57 int err; 57 int err;
58 58
diff --git a/fs/ext3/ioctl.c b/fs/ext3/ioctl.c
index 12daa6869572..9b8090d94e6c 100644
--- a/fs/ext3/ioctl.c
+++ b/fs/ext3/ioctl.c
@@ -257,7 +257,7 @@ flags_err:
257#ifdef CONFIG_COMPAT 257#ifdef CONFIG_COMPAT
258long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 258long ext3_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
259{ 259{
260 struct inode *inode = file->f_dentry->d_inode; 260 struct inode *inode = file->f_path.dentry->d_inode;
261 int ret; 261 int ret;
262 262
263 /* These are just misnamed, they actually get/put from/to user an int */ 263 /* These are just misnamed, they actually get/put from/to user an int */
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 60d2f9dbdb00..4df39c4315e1 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -602,7 +602,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
602 602
603 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash, 603 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
604 start_minor_hash)); 604 start_minor_hash));
605 dir = dir_file->f_dentry->d_inode; 605 dir = dir_file->f_path.dentry->d_inode;
606 if (!(EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) { 606 if (!(EXT3_I(dir)->i_flags & EXT3_INDEX_FL)) {
607 hinfo.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version; 607 hinfo.hash_version = EXT3_SB(dir->i_sb)->s_def_hash_version;
608 hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed; 608 hinfo.seed = EXT3_SB(dir->i_sb)->s_hash_seed;
@@ -613,7 +613,7 @@ int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
613 } 613 }
614 hinfo.hash = start_hash; 614 hinfo.hash = start_hash;
615 hinfo.minor_hash = 0; 615 hinfo.minor_hash = 0;
616 frame = dx_probe(NULL, dir_file->f_dentry->d_inode, &hinfo, frames, &err); 616 frame = dx_probe(NULL, dir_file->f_path.dentry->d_inode, &hinfo, frames, &err);
617 if (!frame) 617 if (!frame)
618 return err; 618 return err;
619 619
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 580b8a6ca979..b34886734a44 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -1347,8 +1347,6 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1347 sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1347 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1348} 1348}
1349 1349
1350#define log2(n) ffz(~(n))
1351
1352/* 1350/*
1353 * Maximal file size. There is a direct, and {,double-,triple-}indirect 1351 * Maximal file size. There is a direct, and {,double-,triple-}indirect
1354 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks. 1352 * block limit, and also a limit of (2^32 - 1) 512-byte sectors in i_blocks.
@@ -1597,8 +1595,8 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1597 sbi->s_desc_per_block = blocksize / sizeof(struct ext3_group_desc); 1595 sbi->s_desc_per_block = blocksize / sizeof(struct ext3_group_desc);
1598 sbi->s_sbh = bh; 1596 sbi->s_sbh = bh;
1599 sbi->s_mount_state = le16_to_cpu(es->s_state); 1597 sbi->s_mount_state = le16_to_cpu(es->s_state);
1600 sbi->s_addr_per_block_bits = log2(EXT3_ADDR_PER_BLOCK(sb)); 1598 sbi->s_addr_per_block_bits = ilog2(EXT3_ADDR_PER_BLOCK(sb));
1601 sbi->s_desc_per_block_bits = log2(EXT3_DESC_PER_BLOCK(sb)); 1599 sbi->s_desc_per_block_bits = ilog2(EXT3_DESC_PER_BLOCK(sb));
1602 for (i=0; i < 4; i++) 1600 for (i=0; i < 4; i++)
1603 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 1601 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
1604 sbi->s_def_hash_version = es->s_def_hash_version; 1602 sbi->s_def_hash_version = es->s_def_hash_version;
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index f2ed3e7fb9f5..da80368b66f0 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -103,7 +103,7 @@ static int ext4_readdir(struct file * filp,
103 struct ext4_dir_entry_2 *de; 103 struct ext4_dir_entry_2 *de;
104 struct super_block *sb; 104 struct super_block *sb;
105 int err; 105 int err;
106 struct inode *inode = filp->f_dentry->d_inode; 106 struct inode *inode = filp->f_path.dentry->d_inode;
107 int ret = 0; 107 int ret = 0;
108 108
109 sb = inode->i_sb; 109 sb = inode->i_sb;
@@ -122,7 +122,7 @@ static int ext4_readdir(struct file * filp,
122 * We don't set the inode dirty flag since it's not 122 * We don't set the inode dirty flag since it's not
123 * critical that it get flushed back to the disk. 123 * critical that it get flushed back to the disk.
124 */ 124 */
125 EXT4_I(filp->f_dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL; 125 EXT4_I(filp->f_path.dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL;
126 } 126 }
127#endif 127#endif
128 stored = 0; 128 stored = 0;
@@ -402,7 +402,7 @@ static int call_filldir(struct file * filp, void * dirent,
402{ 402{
403 struct dir_private_info *info = filp->private_data; 403 struct dir_private_info *info = filp->private_data;
404 loff_t curr_pos; 404 loff_t curr_pos;
405 struct inode *inode = filp->f_dentry->d_inode; 405 struct inode *inode = filp->f_path.dentry->d_inode;
406 struct super_block * sb; 406 struct super_block * sb;
407 int error; 407 int error;
408 408
@@ -432,7 +432,7 @@ static int ext4_dx_readdir(struct file * filp,
432 void * dirent, filldir_t filldir) 432 void * dirent, filldir_t filldir)
433{ 433{
434 struct dir_private_info *info = filp->private_data; 434 struct dir_private_info *info = filp->private_data;
435 struct inode *inode = filp->f_dentry->d_inode; 435 struct inode *inode = filp->f_path.dentry->d_inode;
436 struct fname *fname; 436 struct fname *fname;
437 int ret; 437 int ret;
438 438
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 0b622c0624b7..3bbc24b58785 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -52,7 +52,7 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
52 unsigned long nr_segs, loff_t pos) 52 unsigned long nr_segs, loff_t pos)
53{ 53{
54 struct file *file = iocb->ki_filp; 54 struct file *file = iocb->ki_filp;
55 struct inode *inode = file->f_dentry->d_inode; 55 struct inode *inode = file->f_path.dentry->d_inode;
56 ssize_t ret; 56 ssize_t ret;
57 int err; 57 int err;
58 58
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 1d85d4ec9598..a127cc03c9fa 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1232,7 +1232,7 @@ retry:
1232 from, to, NULL, do_journal_get_write_access); 1232 from, to, NULL, do_journal_get_write_access);
1233 if (ret) 1233 if (ret)
1234 /* fatal error, just put the handle and return */ 1234 /* fatal error, just put the handle and return */
1235 journal_stop(handle); 1235 ext4_journal_stop(handle);
1236 } 1236 }
1237 return ret; 1237 return ret;
1238 1238
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 22a737c306c7..500567dd53b6 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -256,7 +256,7 @@ flags_err:
256#ifdef CONFIG_COMPAT 256#ifdef CONFIG_COMPAT
257long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 257long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
258{ 258{
259 struct inode *inode = file->f_dentry->d_inode; 259 struct inode *inode = file->f_path.dentry->d_inode;
260 int ret; 260 int ret;
261 261
262 /* These are just misnamed, they actually get/put from/to user an int */ 262 /* These are just misnamed, they actually get/put from/to user an int */
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 859990eac504..e5a74a5ac261 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -602,7 +602,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
602 602
603 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash, 603 dxtrace(printk("In htree_fill_tree, start hash: %x:%x\n", start_hash,
604 start_minor_hash)); 604 start_minor_hash));
605 dir = dir_file->f_dentry->d_inode; 605 dir = dir_file->f_path.dentry->d_inode;
606 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) { 606 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
607 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version; 607 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
608 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed; 608 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
@@ -613,7 +613,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
613 } 613 }
614 hinfo.hash = start_hash; 614 hinfo.hash = start_hash;
615 hinfo.minor_hash = 0; 615 hinfo.minor_hash = 0;
616 frame = dx_probe(NULL, dir_file->f_dentry->d_inode, &hinfo, frames, &err); 616 frame = dx_probe(NULL, dir_file->f_path.dentry->d_inode, &hinfo, frames, &err);
617 if (!frame) 617 if (!frame)
618 return err; 618 return err;
619 619
diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 69c439f44387..c16af246d245 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -579,7 +579,7 @@ parse_record:
579 if (!memcmp(de->name, MSDOS_DOT, MSDOS_NAME)) 579 if (!memcmp(de->name, MSDOS_DOT, MSDOS_NAME))
580 inum = inode->i_ino; 580 inum = inode->i_ino;
581 else if (!memcmp(de->name, MSDOS_DOTDOT, MSDOS_NAME)) { 581 else if (!memcmp(de->name, MSDOS_DOTDOT, MSDOS_NAME)) {
582 inum = parent_ino(filp->f_dentry); 582 inum = parent_ino(filp->f_path.dentry);
583 } else { 583 } else {
584 loff_t i_pos = fat_make_i_pos(sb, bh, de); 584 loff_t i_pos = fat_make_i_pos(sb, bh, de);
585 struct inode *tmp = fat_iget(sb, i_pos); 585 struct inode *tmp = fat_iget(sb, i_pos);
@@ -643,7 +643,7 @@ out:
643 643
644static int fat_readdir(struct file *filp, void *dirent, filldir_t filldir) 644static int fat_readdir(struct file *filp, void *dirent, filldir_t filldir)
645{ 645{
646 struct inode *inode = filp->f_dentry->d_inode; 646 struct inode *inode = filp->f_path.dentry->d_inode;
647 return __fat_readdir(inode, filp, dirent, filldir, 0, 0); 647 return __fat_readdir(inode, filp, dirent, filldir, 0, 0);
648} 648}
649 649
@@ -782,7 +782,7 @@ static long fat_compat_dir_ioctl(struct file *file, unsigned cmd,
782 782
783 set_fs(KERNEL_DS); 783 set_fs(KERNEL_DS);
784 lock_kernel(); 784 lock_kernel();
785 ret = fat_dir_ioctl(file->f_dentry->d_inode, file, 785 ret = fat_dir_ioctl(file->f_path.dentry->d_inode, file,
786 cmd, (unsigned long) &d); 786 cmd, (unsigned long) &d);
787 unlock_kernel(); 787 unlock_kernel();
788 set_fs(oldfs); 788 set_fs(oldfs);
diff --git a/fs/fat/file.c b/fs/fat/file.c
index 0aa813d944a6..c1237b70c1fe 100644
--- a/fs/fat/file.c
+++ b/fs/fat/file.c
@@ -92,7 +92,7 @@ int fat_generic_ioctl(struct inode *inode, struct file *filp,
92 } 92 }
93 93
94 /* This MUST be done before doing anything irreversible... */ 94 /* This MUST be done before doing anything irreversible... */
95 err = notify_change(filp->f_dentry, &ia); 95 err = notify_change(filp->f_path.dentry, &ia);
96 if (err) 96 if (err)
97 goto up; 97 goto up;
98 98
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 4740d35e52cd..8e382a5d51bd 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -77,10 +77,9 @@ repeat:
77 start = files->next_fd; 77 start = files->next_fd;
78 78
79 newfd = start; 79 newfd = start;
80 if (start < fdt->max_fdset) { 80 if (start < fdt->max_fds)
81 newfd = find_next_zero_bit(fdt->open_fds->fds_bits, 81 newfd = find_next_zero_bit(fdt->open_fds->fds_bits,
82 fdt->max_fdset, start); 82 fdt->max_fds, start);
83 }
84 83
85 error = -EMFILE; 84 error = -EMFILE;
86 if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur) 85 if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
@@ -204,7 +203,7 @@ asmlinkage long sys_dup(unsigned int fildes)
204 203
205static int setfl(int fd, struct file * filp, unsigned long arg) 204static int setfl(int fd, struct file * filp, unsigned long arg)
206{ 205{
207 struct inode * inode = filp->f_dentry->d_inode; 206 struct inode * inode = filp->f_path.dentry->d_inode;
208 int error = 0; 207 int error = 0;
209 208
210 /* 209 /*
diff --git a/fs/file.c b/fs/file.c
index 51aef675470f..857fa49e984c 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -32,46 +32,28 @@ struct fdtable_defer {
32 */ 32 */
33static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list); 33static DEFINE_PER_CPU(struct fdtable_defer, fdtable_defer_list);
34 34
35 35static inline void * alloc_fdmem(unsigned int size)
36/*
37 * Allocate an fd array, using kmalloc or vmalloc.
38 * Note: the array isn't cleared at allocation time.
39 */
40struct file ** alloc_fd_array(int num)
41{ 36{
42 struct file **new_fds;
43 int size = num * sizeof(struct file *);
44
45 if (size <= PAGE_SIZE) 37 if (size <= PAGE_SIZE)
46 new_fds = (struct file **) kmalloc(size, GFP_KERNEL); 38 return kmalloc(size, GFP_KERNEL);
47 else 39 else
48 new_fds = (struct file **) vmalloc(size); 40 return vmalloc(size);
49 return new_fds;
50} 41}
51 42
52void free_fd_array(struct file **array, int num) 43static inline void free_fdarr(struct fdtable *fdt)
53{ 44{
54 int size = num * sizeof(struct file *); 45 if (fdt->max_fds <= (PAGE_SIZE / sizeof(struct file *)))
55 46 kfree(fdt->fd);
56 if (!array) {
57 printk (KERN_ERR "free_fd_array: array = 0 (num = %d)\n", num);
58 return;
59 }
60
61 if (num <= NR_OPEN_DEFAULT) /* Don't free the embedded fd array! */
62 return;
63 else if (size <= PAGE_SIZE)
64 kfree(array);
65 else 47 else
66 vfree(array); 48 vfree(fdt->fd);
67} 49}
68 50
69static void __free_fdtable(struct fdtable *fdt) 51static inline void free_fdset(struct fdtable *fdt)
70{ 52{
71 free_fdset(fdt->open_fds, fdt->max_fdset); 53 if (fdt->max_fds <= (PAGE_SIZE * BITS_PER_BYTE / 2))
72 free_fdset(fdt->close_on_exec, fdt->max_fdset); 54 kfree(fdt->open_fds);
73 free_fd_array(fdt->fd, fdt->max_fds); 55 else
74 kfree(fdt); 56 vfree(fdt->open_fds);
75} 57}
76 58
77static void free_fdtable_work(struct work_struct *work) 59static void free_fdtable_work(struct work_struct *work)
@@ -86,41 +68,32 @@ static void free_fdtable_work(struct work_struct *work)
86 spin_unlock_bh(&f->lock); 68 spin_unlock_bh(&f->lock);
87 while(fdt) { 69 while(fdt) {
88 struct fdtable *next = fdt->next; 70 struct fdtable *next = fdt->next;
89 __free_fdtable(fdt); 71 vfree(fdt->fd);
72 free_fdset(fdt);
73 kfree(fdt);
90 fdt = next; 74 fdt = next;
91 } 75 }
92} 76}
93 77
94static void free_fdtable_rcu(struct rcu_head *rcu) 78void free_fdtable_rcu(struct rcu_head *rcu)
95{ 79{
96 struct fdtable *fdt = container_of(rcu, struct fdtable, rcu); 80 struct fdtable *fdt = container_of(rcu, struct fdtable, rcu);
97 int fdset_size, fdarray_size;
98 struct fdtable_defer *fddef; 81 struct fdtable_defer *fddef;
99 82
100 BUG_ON(!fdt); 83 BUG_ON(!fdt);
101 fdset_size = fdt->max_fdset / 8;
102 fdarray_size = fdt->max_fds * sizeof(struct file *);
103 84
104 if (fdt->free_files) { 85 if (fdt->max_fds <= NR_OPEN_DEFAULT) {
105 /* 86 /*
106 * The this fdtable was embedded in the files structure 87 * This fdtable is embedded in the files structure and that
107 * and the files structure itself was getting destroyed. 88 * structure itself is getting destroyed.
108 * It is now safe to free the files structure.
109 */ 89 */
110 kmem_cache_free(files_cachep, fdt->free_files); 90 kmem_cache_free(files_cachep,
91 container_of(fdt, struct files_struct, fdtab));
111 return; 92 return;
112 } 93 }
113 if (fdt->max_fdset <= EMBEDDED_FD_SET_SIZE && 94 if (fdt->max_fds <= (PAGE_SIZE / sizeof(struct file *))) {
114 fdt->max_fds <= NR_OPEN_DEFAULT) {
115 /*
116 * The fdtable was embedded
117 */
118 return;
119 }
120 if (fdset_size <= PAGE_SIZE && fdarray_size <= PAGE_SIZE) {
121 kfree(fdt->open_fds);
122 kfree(fdt->close_on_exec);
123 kfree(fdt->fd); 95 kfree(fdt->fd);
96 kfree(fdt->open_fds);
124 kfree(fdt); 97 kfree(fdt);
125 } else { 98 } else {
126 fddef = &get_cpu_var(fdtable_defer_list); 99 fddef = &get_cpu_var(fdtable_defer_list);
@@ -134,136 +107,74 @@ static void free_fdtable_rcu(struct rcu_head *rcu)
134 } 107 }
135} 108}
136 109
137void free_fdtable(struct fdtable *fdt)
138{
139 if (fdt->free_files ||
140 fdt->max_fdset > EMBEDDED_FD_SET_SIZE ||
141 fdt->max_fds > NR_OPEN_DEFAULT)
142 call_rcu(&fdt->rcu, free_fdtable_rcu);
143}
144
145/* 110/*
146 * Expand the fdset in the files_struct. Called with the files spinlock 111 * Expand the fdset in the files_struct. Called with the files spinlock
147 * held for write. 112 * held for write.
148 */ 113 */
149static void copy_fdtable(struct fdtable *nfdt, struct fdtable *fdt) 114static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt)
150{ 115{
151 int i; 116 unsigned int cpy, set;
152 int count;
153
154 BUG_ON(nfdt->max_fdset < fdt->max_fdset);
155 BUG_ON(nfdt->max_fds < fdt->max_fds);
156 /* Copy the existing tables and install the new pointers */
157
158 i = fdt->max_fdset / (sizeof(unsigned long) * 8);
159 count = (nfdt->max_fdset - fdt->max_fdset) / 8;
160 117
161 /* 118 BUG_ON(nfdt->max_fds < ofdt->max_fds);
162 * Don't copy the entire array if the current fdset is 119 if (ofdt->max_fds == 0)
163 * not yet initialised. 120 return;
164 */
165 if (i) {
166 memcpy (nfdt->open_fds, fdt->open_fds,
167 fdt->max_fdset/8);
168 memcpy (nfdt->close_on_exec, fdt->close_on_exec,
169 fdt->max_fdset/8);
170 memset (&nfdt->open_fds->fds_bits[i], 0, count);
171 memset (&nfdt->close_on_exec->fds_bits[i], 0, count);
172 }
173
174 /* Don't copy/clear the array if we are creating a new
175 fd array for fork() */
176 if (fdt->max_fds) {
177 memcpy(nfdt->fd, fdt->fd,
178 fdt->max_fds * sizeof(struct file *));
179 /* clear the remainder of the array */
180 memset(&nfdt->fd[fdt->max_fds], 0,
181 (nfdt->max_fds - fdt->max_fds) *
182 sizeof(struct file *));
183 }
184}
185
186/*
187 * Allocate an fdset array, using kmalloc or vmalloc.
188 * Note: the array isn't cleared at allocation time.
189 */
190fd_set * alloc_fdset(int num)
191{
192 fd_set *new_fdset;
193 int size = num / 8;
194 121
195 if (size <= PAGE_SIZE) 122 cpy = ofdt->max_fds * sizeof(struct file *);
196 new_fdset = (fd_set *) kmalloc(size, GFP_KERNEL); 123 set = (nfdt->max_fds - ofdt->max_fds) * sizeof(struct file *);
197 else 124 memcpy(nfdt->fd, ofdt->fd, cpy);
198 new_fdset = (fd_set *) vmalloc(size); 125 memset((char *)(nfdt->fd) + cpy, 0, set);
199 return new_fdset; 126
127 cpy = ofdt->max_fds / BITS_PER_BYTE;
128 set = (nfdt->max_fds - ofdt->max_fds) / BITS_PER_BYTE;
129 memcpy(nfdt->open_fds, ofdt->open_fds, cpy);
130 memset((char *)(nfdt->open_fds) + cpy, 0, set);
131 memcpy(nfdt->close_on_exec, ofdt->close_on_exec, cpy);
132 memset((char *)(nfdt->close_on_exec) + cpy, 0, set);
200} 133}
201 134
202void free_fdset(fd_set *array, int num) 135static struct fdtable * alloc_fdtable(unsigned int nr)
203{ 136{
204 if (num <= EMBEDDED_FD_SET_SIZE) /* Don't free an embedded fdset */ 137 struct fdtable *fdt;
205 return; 138 char *data;
206 else if (num <= 8 * PAGE_SIZE)
207 kfree(array);
208 else
209 vfree(array);
210}
211 139
212static struct fdtable *alloc_fdtable(int nr) 140 /*
213{ 141 * Figure out how many fds we actually want to support in this fdtable.
214 struct fdtable *fdt = NULL; 142 * Allocation steps are keyed to the size of the fdarray, since it
215 int nfds = 0; 143 * grows far faster than any of the other dynamic data. We try to fit
216 fd_set *new_openset = NULL, *new_execset = NULL; 144 * the fdarray into comfortable page-tuned chunks: starting at 1024B
217 struct file **new_fds; 145 * and growing in powers of two from there on.
146 */
147 nr /= (1024 / sizeof(struct file *));
148 nr = roundup_pow_of_two(nr + 1);
149 nr *= (1024 / sizeof(struct file *));
150 if (nr > NR_OPEN)
151 nr = NR_OPEN;
218 152
219 fdt = kzalloc(sizeof(*fdt), GFP_KERNEL); 153 fdt = kmalloc(sizeof(struct fdtable), GFP_KERNEL);
220 if (!fdt) 154 if (!fdt)
221 goto out; 155 goto out;
222 156 fdt->max_fds = nr;
223 nfds = max_t(int, 8 * L1_CACHE_BYTES, roundup_pow_of_two(nr + 1)); 157 data = alloc_fdmem(nr * sizeof(struct file *));
224 if (nfds > NR_OPEN) 158 if (!data)
225 nfds = NR_OPEN; 159 goto out_fdt;
160 fdt->fd = (struct file **)data;
161 data = alloc_fdmem(max_t(unsigned int,
162 2 * nr / BITS_PER_BYTE, L1_CACHE_BYTES));
163 if (!data)
164 goto out_arr;
165 fdt->open_fds = (fd_set *)data;
166 data += nr / BITS_PER_BYTE;
167 fdt->close_on_exec = (fd_set *)data;
168 INIT_RCU_HEAD(&fdt->rcu);
169 fdt->next = NULL;
226 170
227 new_openset = alloc_fdset(nfds);
228 new_execset = alloc_fdset(nfds);
229 if (!new_openset || !new_execset)
230 goto out;
231 fdt->open_fds = new_openset;
232 fdt->close_on_exec = new_execset;
233 fdt->max_fdset = nfds;
234
235 nfds = NR_OPEN_DEFAULT;
236 /*
237 * Expand to the max in easy steps, and keep expanding it until
238 * we have enough for the requested fd array size.
239 */
240 do {
241#if NR_OPEN_DEFAULT < 256
242 if (nfds < 256)
243 nfds = 256;
244 else
245#endif
246 if (nfds < (PAGE_SIZE / sizeof(struct file *)))
247 nfds = PAGE_SIZE / sizeof(struct file *);
248 else {
249 nfds = nfds * 2;
250 if (nfds > NR_OPEN)
251 nfds = NR_OPEN;
252 }
253 } while (nfds <= nr);
254 new_fds = alloc_fd_array(nfds);
255 if (!new_fds)
256 goto out2;
257 fdt->fd = new_fds;
258 fdt->max_fds = nfds;
259 fdt->free_files = NULL;
260 return fdt; 171 return fdt;
261out2: 172
262 nfds = fdt->max_fdset; 173out_arr:
263out: 174 free_fdarr(fdt);
264 free_fdset(new_openset, nfds); 175out_fdt:
265 free_fdset(new_execset, nfds);
266 kfree(fdt); 176 kfree(fdt);
177out:
267 return NULL; 178 return NULL;
268} 179}
269 180
@@ -290,14 +201,17 @@ static int expand_fdtable(struct files_struct *files, int nr)
290 * we dropped the lock 201 * we dropped the lock
291 */ 202 */
292 cur_fdt = files_fdtable(files); 203 cur_fdt = files_fdtable(files);
293 if (nr >= cur_fdt->max_fds || nr >= cur_fdt->max_fdset) { 204 if (nr >= cur_fdt->max_fds) {
294 /* Continue as planned */ 205 /* Continue as planned */
295 copy_fdtable(new_fdt, cur_fdt); 206 copy_fdtable(new_fdt, cur_fdt);
296 rcu_assign_pointer(files->fdt, new_fdt); 207 rcu_assign_pointer(files->fdt, new_fdt);
297 free_fdtable(cur_fdt); 208 if (cur_fdt->max_fds > NR_OPEN_DEFAULT)
209 call_rcu(&cur_fdt->rcu, free_fdtable_rcu);
298 } else { 210 } else {
299 /* Somebody else expanded, so undo our attempt */ 211 /* Somebody else expanded, so undo our attempt */
300 __free_fdtable(new_fdt); 212 free_fdarr(new_fdt);
213 free_fdset(new_fdt);
214 kfree(new_fdt);
301 } 215 }
302 return 1; 216 return 1;
303} 217}
@@ -316,11 +230,10 @@ int expand_files(struct files_struct *files, int nr)
316 230
317 fdt = files_fdtable(files); 231 fdt = files_fdtable(files);
318 /* Do we need to expand? */ 232 /* Do we need to expand? */
319 if (nr < fdt->max_fdset && nr < fdt->max_fds) 233 if (nr < fdt->max_fds)
320 return 0; 234 return 0;
321 /* Can we expand? */ 235 /* Can we expand? */
322 if (fdt->max_fdset >= NR_OPEN || fdt->max_fds >= NR_OPEN || 236 if (nr >= NR_OPEN)
323 nr >= NR_OPEN)
324 return -EMFILE; 237 return -EMFILE;
325 238
326 /* All good, so we try */ 239 /* All good, so we try */
diff --git a/fs/file_table.c b/fs/file_table.c
index 24f25a057d9c..4c17a18d8c10 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -152,8 +152,8 @@ EXPORT_SYMBOL(fput);
152 */ 152 */
153void fastcall __fput(struct file *file) 153void fastcall __fput(struct file *file)
154{ 154{
155 struct dentry *dentry = file->f_dentry; 155 struct dentry *dentry = file->f_path.dentry;
156 struct vfsmount *mnt = file->f_vfsmnt; 156 struct vfsmount *mnt = file->f_path.mnt;
157 struct inode *inode = dentry->d_inode; 157 struct inode *inode = dentry->d_inode;
158 158
159 might_sleep(); 159 might_sleep();
@@ -176,8 +176,8 @@ void fastcall __fput(struct file *file)
176 put_write_access(inode); 176 put_write_access(inode);
177 put_pid(file->f_owner.pid); 177 put_pid(file->f_owner.pid);
178 file_kill(file); 178 file_kill(file);
179 file->f_dentry = NULL; 179 file->f_path.dentry = NULL;
180 file->f_vfsmnt = NULL; 180 file->f_path.mnt = NULL;
181 file_free(file); 181 file_free(file);
182 dput(dentry); 182 dput(dentry);
183 mntput(mnt); 183 mntput(mnt);
@@ -271,7 +271,7 @@ int fs_may_remount_ro(struct super_block *sb)
271 file_list_lock(); 271 file_list_lock();
272 list_for_each(p, &sb->s_files) { 272 list_for_each(p, &sb->s_files) {
273 struct file *file = list_entry(p, struct file, f_u.fu_list); 273 struct file *file = list_entry(p, struct file, f_u.fu_list);
274 struct inode *inode = file->f_dentry->d_inode; 274 struct inode *inode = file->f_path.dentry->d_inode;
275 275
276 /* File with pending delete? */ 276 /* File with pending delete? */
277 if (inode->i_nlink == 0) 277 if (inode->i_nlink == 0)
diff --git a/fs/freevxfs/vxfs_lookup.c b/fs/freevxfs/vxfs_lookup.c
index 43886fa00a2a..3995d7fbedab 100644
--- a/fs/freevxfs/vxfs_lookup.c
+++ b/fs/freevxfs/vxfs_lookup.c
@@ -240,7 +240,7 @@ vxfs_lookup(struct inode *dip, struct dentry *dp, struct nameidata *nd)
240static int 240static int
241vxfs_readdir(struct file *fp, void *retp, filldir_t filler) 241vxfs_readdir(struct file *fp, void *retp, filldir_t filler)
242{ 242{
243 struct inode *ip = fp->f_dentry->d_inode; 243 struct inode *ip = fp->f_path.dentry->d_inode;
244 struct super_block *sbp = ip->i_sb; 244 struct super_block *sbp = ip->i_sb;
245 u_long bsize = sbp->s_blocksize; 245 u_long bsize = sbp->s_blocksize;
246 u_long page, npages, block, pblocks, nblocks, offset; 246 u_long page, npages, block, pblocks, nblocks, offset;
diff --git a/fs/fuse/control.c b/fs/fuse/control.c
index 16b39c053d47..8c58bd453993 100644
--- a/fs/fuse/control.c
+++ b/fs/fuse/control.c
@@ -23,7 +23,7 @@ static struct fuse_conn *fuse_ctl_file_conn_get(struct file *file)
23{ 23{
24 struct fuse_conn *fc; 24 struct fuse_conn *fc;
25 mutex_lock(&fuse_mutex); 25 mutex_lock(&fuse_mutex);
26 fc = file->f_dentry->d_inode->i_private; 26 fc = file->f_path.dentry->d_inode->i_private;
27 if (fc) 27 if (fc)
28 fc = fuse_conn_get(fc); 28 fc = fuse_conn_get(fc);
29 mutex_unlock(&fuse_mutex); 29 mutex_unlock(&fuse_mutex);
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 1cabdb229adb..40080477ceb4 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -856,7 +856,7 @@ static int fuse_readdir(struct file *file, void *dstbuf, filldir_t filldir)
856 int err; 856 int err;
857 size_t nbytes; 857 size_t nbytes;
858 struct page *page; 858 struct page *page;
859 struct inode *inode = file->f_dentry->d_inode; 859 struct inode *inode = file->f_path.dentry->d_inode;
860 struct fuse_conn *fc = get_fuse_conn(inode); 860 struct fuse_conn *fc = get_fuse_conn(inode);
861 struct fuse_req *req; 861 struct fuse_req *req;
862 862
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 128f79c40803..1387749201b3 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -141,8 +141,8 @@ int fuse_release_common(struct inode *inode, struct file *file, int isdir)
141 isdir ? FUSE_RELEASEDIR : FUSE_RELEASE); 141 isdir ? FUSE_RELEASEDIR : FUSE_RELEASE);
142 142
143 /* Hold vfsmount and dentry until release is finished */ 143 /* Hold vfsmount and dentry until release is finished */
144 req->vfsmount = mntget(file->f_vfsmnt); 144 req->vfsmount = mntget(file->f_path.mnt);
145 req->dentry = dget(file->f_dentry); 145 req->dentry = dget(file->f_path.dentry);
146 request_send_background(fc, req); 146 request_send_background(fc, req);
147 } 147 }
148 148
@@ -184,7 +184,7 @@ static u64 fuse_lock_owner_id(struct fuse_conn *fc, fl_owner_t id)
184 184
185static int fuse_flush(struct file *file, fl_owner_t id) 185static int fuse_flush(struct file *file, fl_owner_t id)
186{ 186{
187 struct inode *inode = file->f_dentry->d_inode; 187 struct inode *inode = file->f_path.dentry->d_inode;
188 struct fuse_conn *fc = get_fuse_conn(inode); 188 struct fuse_conn *fc = get_fuse_conn(inode);
189 struct fuse_file *ff = file->private_data; 189 struct fuse_file *ff = file->private_data;
190 struct fuse_req *req; 190 struct fuse_req *req;
@@ -533,7 +533,7 @@ static int fuse_get_user_pages(struct fuse_req *req, const char __user *buf,
533static ssize_t fuse_direct_io(struct file *file, const char __user *buf, 533static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
534 size_t count, loff_t *ppos, int write) 534 size_t count, loff_t *ppos, int write)
535{ 535{
536 struct inode *inode = file->f_dentry->d_inode; 536 struct inode *inode = file->f_path.dentry->d_inode;
537 struct fuse_conn *fc = get_fuse_conn(inode); 537 struct fuse_conn *fc = get_fuse_conn(inode);
538 size_t nmax = write ? fc->max_write : fc->max_read; 538 size_t nmax = write ? fc->max_write : fc->max_read;
539 loff_t pos = *ppos; 539 loff_t pos = *ppos;
@@ -607,7 +607,7 @@ static ssize_t fuse_direct_read(struct file *file, char __user *buf,
607static ssize_t fuse_direct_write(struct file *file, const char __user *buf, 607static ssize_t fuse_direct_write(struct file *file, const char __user *buf,
608 size_t count, loff_t *ppos) 608 size_t count, loff_t *ppos)
609{ 609{
610 struct inode *inode = file->f_dentry->d_inode; 610 struct inode *inode = file->f_path.dentry->d_inode;
611 ssize_t res; 611 ssize_t res;
612 /* Don't allow parallel writes to the same file */ 612 /* Don't allow parallel writes to the same file */
613 mutex_lock(&inode->i_mutex); 613 mutex_lock(&inode->i_mutex);
@@ -662,7 +662,7 @@ static int convert_fuse_file_lock(const struct fuse_file_lock *ffl,
662static void fuse_lk_fill(struct fuse_req *req, struct file *file, 662static void fuse_lk_fill(struct fuse_req *req, struct file *file,
663 const struct file_lock *fl, int opcode, pid_t pid) 663 const struct file_lock *fl, int opcode, pid_t pid)
664{ 664{
665 struct inode *inode = file->f_dentry->d_inode; 665 struct inode *inode = file->f_path.dentry->d_inode;
666 struct fuse_conn *fc = get_fuse_conn(inode); 666 struct fuse_conn *fc = get_fuse_conn(inode);
667 struct fuse_file *ff = file->private_data; 667 struct fuse_file *ff = file->private_data;
668 struct fuse_lk_in *arg = &req->misc.lk_in; 668 struct fuse_lk_in *arg = &req->misc.lk_in;
@@ -682,7 +682,7 @@ static void fuse_lk_fill(struct fuse_req *req, struct file *file,
682 682
683static int fuse_getlk(struct file *file, struct file_lock *fl) 683static int fuse_getlk(struct file *file, struct file_lock *fl)
684{ 684{
685 struct inode *inode = file->f_dentry->d_inode; 685 struct inode *inode = file->f_path.dentry->d_inode;
686 struct fuse_conn *fc = get_fuse_conn(inode); 686 struct fuse_conn *fc = get_fuse_conn(inode);
687 struct fuse_req *req; 687 struct fuse_req *req;
688 struct fuse_lk_out outarg; 688 struct fuse_lk_out outarg;
@@ -707,7 +707,7 @@ static int fuse_getlk(struct file *file, struct file_lock *fl)
707 707
708static int fuse_setlk(struct file *file, struct file_lock *fl) 708static int fuse_setlk(struct file *file, struct file_lock *fl)
709{ 709{
710 struct inode *inode = file->f_dentry->d_inode; 710 struct inode *inode = file->f_path.dentry->d_inode;
711 struct fuse_conn *fc = get_fuse_conn(inode); 711 struct fuse_conn *fc = get_fuse_conn(inode);
712 struct fuse_req *req; 712 struct fuse_req *req;
713 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK; 713 int opcode = (fl->fl_flags & FL_SLEEP) ? FUSE_SETLKW : FUSE_SETLK;
@@ -734,7 +734,7 @@ static int fuse_setlk(struct file *file, struct file_lock *fl)
734 734
735static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl) 735static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
736{ 736{
737 struct inode *inode = file->f_dentry->d_inode; 737 struct inode *inode = file->f_path.dentry->d_inode;
738 struct fuse_conn *fc = get_fuse_conn(inode); 738 struct fuse_conn *fc = get_fuse_conn(inode);
739 int err; 739 int err;
740 740
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index b3f1e0349ae0..faa07e4b97d0 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -247,7 +247,7 @@ static const u32 gfs2_to_fsflags[32] = {
247 247
248static int gfs2_get_flags(struct file *filp, u32 __user *ptr) 248static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
249{ 249{
250 struct inode *inode = filp->f_dentry->d_inode; 250 struct inode *inode = filp->f_path.dentry->d_inode;
251 struct gfs2_inode *ip = GFS2_I(inode); 251 struct gfs2_inode *ip = GFS2_I(inode);
252 struct gfs2_holder gh; 252 struct gfs2_holder gh;
253 int error; 253 int error;
@@ -305,7 +305,7 @@ void gfs2_set_inode_flags(struct inode *inode)
305 */ 305 */
306static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) 306static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
307{ 307{
308 struct inode *inode = filp->f_dentry->d_inode; 308 struct inode *inode = filp->f_path.dentry->d_inode;
309 struct gfs2_inode *ip = GFS2_I(inode); 309 struct gfs2_inode *ip = GFS2_I(inode);
310 struct gfs2_sbd *sdp = GFS2_SB(inode); 310 struct gfs2_sbd *sdp = GFS2_SB(inode);
311 struct buffer_head *bh; 311 struct buffer_head *bh;
@@ -588,7 +588,7 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl)
588{ 588{
589 struct gfs2_file *fp = file->private_data; 589 struct gfs2_file *fp = file->private_data;
590 struct gfs2_holder *fl_gh = &fp->f_fl_gh; 590 struct gfs2_holder *fl_gh = &fp->f_fl_gh;
591 struct gfs2_inode *ip = GFS2_I(file->f_dentry->d_inode); 591 struct gfs2_inode *ip = GFS2_I(file->f_path.dentry->d_inode);
592 struct gfs2_glock *gl; 592 struct gfs2_glock *gl;
593 unsigned int state; 593 unsigned int state;
594 int flags; 594 int flags;
diff --git a/fs/hfs/dir.c b/fs/hfs/dir.c
index 37d681b4f216..e2e0358da335 100644
--- a/fs/hfs/dir.c
+++ b/fs/hfs/dir.c
@@ -53,7 +53,7 @@ done:
53 */ 53 */
54static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 54static int hfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
55{ 55{
56 struct inode *inode = filp->f_dentry->d_inode; 56 struct inode *inode = filp->f_path.dentry->d_inode;
57 struct super_block *sb = inode->i_sb; 57 struct super_block *sb = inode->i_sb;
58 int len, err; 58 int len, err;
59 char strbuf[HFS_MAX_NAMELEN]; 59 char strbuf[HFS_MAX_NAMELEN];
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index 02f5573e0349..5cb7f8fee8d6 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -102,7 +102,7 @@ static ssize_t hfs_direct_IO(int rw, struct kiocb *iocb,
102 const struct iovec *iov, loff_t offset, unsigned long nr_segs) 102 const struct iovec *iov, loff_t offset, unsigned long nr_segs)
103{ 103{
104 struct file *file = iocb->ki_filp; 104 struct file *file = iocb->ki_filp;
105 struct inode *inode = file->f_dentry->d_inode->i_mapping->host; 105 struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
106 106
107 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, 107 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
108 offset, nr_segs, hfs_get_block, NULL); 108 offset, nr_segs, hfs_get_block, NULL);
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 7e309751645f..e886ac8460d3 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -111,7 +111,7 @@ fail:
111 111
112static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir) 112static int hfsplus_readdir(struct file *filp, void *dirent, filldir_t filldir)
113{ 113{
114 struct inode *inode = filp->f_dentry->d_inode; 114 struct inode *inode = filp->f_path.dentry->d_inode;
115 struct super_block *sb = inode->i_sb; 115 struct super_block *sb = inode->i_sb;
116 int len, err; 116 int len, err;
117 char strbuf[HFSPLUS_MAX_STRLEN + 1]; 117 char strbuf[HFSPLUS_MAX_STRLEN + 1];
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 9e3675249633..75e8c4d8aac3 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -97,7 +97,7 @@ static ssize_t hfsplus_direct_IO(int rw, struct kiocb *iocb,
97 const struct iovec *iov, loff_t offset, unsigned long nr_segs) 97 const struct iovec *iov, loff_t offset, unsigned long nr_segs)
98{ 98{
99 struct file *file = iocb->ki_filp; 99 struct file *file = iocb->ki_filp;
100 struct inode *inode = file->f_dentry->d_inode->i_mapping->host; 100 struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
101 101
102 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov, 102 return blockdev_direct_IO(rw, iocb, inode, inode->i_sb->s_bdev, iov,
103 offset, nr_segs, hfsplus_get_block, NULL); 103 offset, nr_segs, hfsplus_get_block, NULL);
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index b6bd33ca3731..1e6fc3799876 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -35,7 +35,7 @@ static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
35 return(list_entry(inode, struct hostfs_inode_info, vfs_inode)); 35 return(list_entry(inode, struct hostfs_inode_info, vfs_inode));
36} 36}
37 37
38#define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_dentry->d_inode) 38#define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode)
39 39
40int hostfs_d_delete(struct dentry *dentry) 40int hostfs_d_delete(struct dentry *dentry)
41{ 41{
@@ -325,7 +325,7 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
325 unsigned long long next, ino; 325 unsigned long long next, ino;
326 int error, len; 326 int error, len;
327 327
328 name = dentry_name(file->f_dentry, 0); 328 name = dentry_name(file->f_path.dentry, 0);
329 if(name == NULL) return(-ENOMEM); 329 if(name == NULL) return(-ENOMEM);
330 dir = open_dir(name, &error); 330 dir = open_dir(name, &error);
331 kfree(name); 331 kfree(name);
@@ -366,7 +366,7 @@ int hostfs_file_open(struct inode *ino, struct file *file)
366 if(w) 366 if(w)
367 r = 1; 367 r = 1;
368 368
369 name = dentry_name(file->f_dentry, 0); 369 name = dentry_name(file->f_path.dentry, 0);
370 if(name == NULL) 370 if(name == NULL)
371 return(-ENOMEM); 371 return(-ENOMEM);
372 372
diff --git a/fs/hpfs/dir.c b/fs/hpfs/dir.c
index 594f9c428fc2..6916c41d7017 100644
--- a/fs/hpfs/dir.c
+++ b/fs/hpfs/dir.c
@@ -24,7 +24,7 @@ static loff_t hpfs_dir_lseek(struct file *filp, loff_t off, int whence)
24 loff_t new_off = off + (whence == 1 ? filp->f_pos : 0); 24 loff_t new_off = off + (whence == 1 ? filp->f_pos : 0);
25 loff_t pos; 25 loff_t pos;
26 struct quad_buffer_head qbh; 26 struct quad_buffer_head qbh;
27 struct inode *i = filp->f_dentry->d_inode; 27 struct inode *i = filp->f_path.dentry->d_inode;
28 struct hpfs_inode_info *hpfs_inode = hpfs_i(i); 28 struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
29 struct super_block *s = i->i_sb; 29 struct super_block *s = i->i_sb;
30 30
@@ -52,7 +52,7 @@ fail:
52 52
53static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 53static int hpfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
54{ 54{
55 struct inode *inode = filp->f_dentry->d_inode; 55 struct inode *inode = filp->f_path.dentry->d_inode;
56 struct hpfs_inode_info *hpfs_inode = hpfs_i(inode); 56 struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
57 struct quad_buffer_head qbh; 57 struct quad_buffer_head qbh;
58 struct hpfs_dirent *de; 58 struct hpfs_dirent *de;
diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c
index 8b94d24855f0..fb4c8915010a 100644
--- a/fs/hpfs/file.c
+++ b/fs/hpfs/file.c
@@ -115,7 +115,7 @@ static ssize_t hpfs_file_write(struct file *file, const char __user *buf,
115 115
116 retval = do_sync_write(file, buf, count, ppos); 116 retval = do_sync_write(file, buf, count, ppos);
117 if (retval > 0) 117 if (retval > 0)
118 hpfs_i(file->f_dentry->d_inode)->i_dirty = 1; 118 hpfs_i(file->f_path.dentry->d_inode)->i_dirty = 1;
119 return retval; 119 return retval;
120} 120}
121 121
diff --git a/fs/hppfs/hppfs_kern.c b/fs/hppfs/hppfs_kern.c
index 642675fc394a..afd340a45da4 100644
--- a/fs/hppfs/hppfs_kern.c
+++ b/fs/hppfs/hppfs_kern.c
@@ -221,7 +221,7 @@ static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
221 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); 221 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
222 ssize_t n; 222 ssize_t n;
223 223
224 read = file->f_dentry->d_inode->i_fop->read; 224 read = file->f_path.dentry->d_inode->i_fop->read;
225 225
226 if(!is_user) 226 if(!is_user)
227 set_fs(KERNEL_DS); 227 set_fs(KERNEL_DS);
@@ -320,7 +320,7 @@ static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len
320 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); 320 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
321 int err; 321 int err;
322 322
323 write = proc_file->f_dentry->d_inode->i_fop->write; 323 write = proc_file->f_path.dentry->d_inode->i_fop->write;
324 324
325 proc_file->f_pos = file->f_pos; 325 proc_file->f_pos = file->f_pos;
326 err = (*write)(proc_file, buf, len, &proc_file->f_pos); 326 err = (*write)(proc_file, buf, len, &proc_file->f_pos);
@@ -464,7 +464,7 @@ static int hppfs_open(struct inode *inode, struct file *file)
464 if(data == NULL) 464 if(data == NULL)
465 goto out; 465 goto out;
466 466
467 host_file = dentry_name(file->f_dentry, strlen("/rw")); 467 host_file = dentry_name(file->f_path.dentry, strlen("/rw"));
468 if(host_file == NULL) 468 if(host_file == NULL)
469 goto out_free2; 469 goto out_free2;
470 470
@@ -547,7 +547,7 @@ static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
547 loff_t (*llseek)(struct file *, loff_t, int); 547 loff_t (*llseek)(struct file *, loff_t, int);
548 loff_t ret; 548 loff_t ret;
549 549
550 llseek = proc_file->f_dentry->d_inode->i_fop->llseek; 550 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek;
551 if(llseek != NULL){ 551 if(llseek != NULL){
552 ret = (*llseek)(proc_file, off, where); 552 ret = (*llseek)(proc_file, off, where);
553 if(ret < 0) 553 if(ret < 0)
@@ -591,10 +591,10 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
591 struct hppfs_dirent dirent = ((struct hppfs_dirent) 591 struct hppfs_dirent dirent = ((struct hppfs_dirent)
592 { .vfs_dirent = ent, 592 { .vfs_dirent = ent,
593 .filldir = filldir, 593 .filldir = filldir,
594 .dentry = file->f_dentry } ); 594 .dentry = file->f_path.dentry } );
595 int err; 595 int err;
596 596
597 readdir = proc_file->f_dentry->d_inode->i_fop->readdir; 597 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir;
598 598
599 proc_file->f_pos = file->f_pos; 599 proc_file->f_pos = file->f_pos;
600 err = (*readdir)(proc_file, &dirent, hppfs_filldir); 600 err = (*readdir)(proc_file, &dirent, hppfs_filldir);
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 0706f5aac6a2..ed2c22340ad7 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -58,7 +58,7 @@ static void huge_pagevec_release(struct pagevec *pvec)
58 58
59static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma) 59static int hugetlbfs_file_mmap(struct file *file, struct vm_area_struct *vma)
60{ 60{
61 struct inode *inode = file->f_dentry->d_inode; 61 struct inode *inode = file->f_path.dentry->d_inode;
62 loff_t len, vma_len; 62 loff_t len, vma_len;
63 int ret; 63 int ret;
64 64
@@ -774,8 +774,8 @@ struct file *hugetlb_zero_setup(size_t size)
774 d_instantiate(dentry, inode); 774 d_instantiate(dentry, inode);
775 inode->i_size = size; 775 inode->i_size = size;
776 inode->i_nlink = 0; 776 inode->i_nlink = 0;
777 file->f_vfsmnt = mntget(hugetlbfs_vfsmount); 777 file->f_path.mnt = mntget(hugetlbfs_vfsmount);
778 file->f_dentry = dentry; 778 file->f_path.dentry = dentry;
779 file->f_mapping = inode->i_mapping; 779 file->f_mapping = inode->i_mapping;
780 file->f_op = &hugetlbfs_file_operations; 780 file->f_op = &hugetlbfs_file_operations;
781 file->f_mode = FMODE_WRITE | FMODE_READ; 781 file->f_mode = FMODE_WRITE | FMODE_READ;
diff --git a/fs/inode.c b/fs/inode.c
index 9ecccab7326d..d00de182ecb9 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1200,7 +1200,7 @@ EXPORT_SYMBOL(touch_atime);
1200 1200
1201void file_update_time(struct file *file) 1201void file_update_time(struct file *file)
1202{ 1202{
1203 struct inode *inode = file->f_dentry->d_inode; 1203 struct inode *inode = file->f_path.dentry->d_inode;
1204 struct timespec now; 1204 struct timespec now;
1205 int sync_it = 0; 1205 int sync_it = 0;
1206 1206
diff --git a/fs/inotify_user.c b/fs/inotify_user.c
index e1956e6f116c..55f6da55b7c0 100644
--- a/fs/inotify_user.c
+++ b/fs/inotify_user.c
@@ -570,9 +570,9 @@ asmlinkage long sys_inotify_init(void)
570 dev->ih = ih; 570 dev->ih = ih;
571 571
572 filp->f_op = &inotify_fops; 572 filp->f_op = &inotify_fops;
573 filp->f_vfsmnt = mntget(inotify_mnt); 573 filp->f_path.mnt = mntget(inotify_mnt);
574 filp->f_dentry = dget(inotify_mnt->mnt_root); 574 filp->f_path.dentry = dget(inotify_mnt->mnt_root);
575 filp->f_mapping = filp->f_dentry->d_inode->i_mapping; 575 filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
576 filp->f_mode = FMODE_READ; 576 filp->f_mode = FMODE_READ;
577 filp->f_flags = O_RDONLY; 577 filp->f_flags = O_RDONLY;
578 filp->private_data = dev; 578 filp->private_data = dev;
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 4b7660b09ac0..ff61772ceedd 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -31,7 +31,7 @@ static long do_ioctl(struct file *filp, unsigned int cmd,
31 goto out; 31 goto out;
32 } else if (filp->f_op->ioctl) { 32 } else if (filp->f_op->ioctl) {
33 lock_kernel(); 33 lock_kernel();
34 error = filp->f_op->ioctl(filp->f_dentry->d_inode, 34 error = filp->f_op->ioctl(filp->f_path.dentry->d_inode,
35 filp, cmd, arg); 35 filp, cmd, arg);
36 unlock_kernel(); 36 unlock_kernel();
37 } 37 }
@@ -45,7 +45,7 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
45{ 45{
46 int error; 46 int error;
47 int block; 47 int block;
48 struct inode * inode = filp->f_dentry->d_inode; 48 struct inode * inode = filp->f_path.dentry->d_inode;
49 int __user *p = (int __user *)arg; 49 int __user *p = (int __user *)arg;
50 50
51 switch (cmd) { 51 switch (cmd) {
@@ -137,17 +137,17 @@ int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned lon
137 break; 137 break;
138 138
139 case FIOQSIZE: 139 case FIOQSIZE:
140 if (S_ISDIR(filp->f_dentry->d_inode->i_mode) || 140 if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
141 S_ISREG(filp->f_dentry->d_inode->i_mode) || 141 S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
142 S_ISLNK(filp->f_dentry->d_inode->i_mode)) { 142 S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
143 loff_t res = inode_get_bytes(filp->f_dentry->d_inode); 143 loff_t res = inode_get_bytes(filp->f_path.dentry->d_inode);
144 error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0; 144 error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0;
145 } 145 }
146 else 146 else
147 error = -ENOTTY; 147 error = -ENOTTY;
148 break; 148 break;
149 default: 149 default:
150 if (S_ISREG(filp->f_dentry->d_inode->i_mode)) 150 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
151 error = file_ioctl(filp, cmd, arg); 151 error = file_ioctl(filp, cmd, arg);
152 else 152 else
153 error = do_ioctl(filp, cmd, arg); 153 error = do_ioctl(filp, cmd, arg);
diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
index 731816332b12..6bbbdb53581d 100644
--- a/fs/isofs/compress.c
+++ b/fs/isofs/compress.c
@@ -42,7 +42,7 @@ static struct semaphore zisofs_zlib_semaphore;
42 */ 42 */
43static int zisofs_readpage(struct file *file, struct page *page) 43static int zisofs_readpage(struct file *file, struct page *page)
44{ 44{
45 struct inode *inode = file->f_dentry->d_inode; 45 struct inode *inode = file->f_path.dentry->d_inode;
46 struct address_space *mapping = inode->i_mapping; 46 struct address_space *mapping = inode->i_mapping;
47 unsigned int maxpage, xpage, fpage, blockindex; 47 unsigned int maxpage, xpage, fpage, blockindex;
48 unsigned long offset; 48 unsigned long offset;
diff --git a/fs/isofs/dir.c b/fs/isofs/dir.c
index 27e276987fd2..4af2548f97a9 100644
--- a/fs/isofs/dir.c
+++ b/fs/isofs/dir.c
@@ -183,7 +183,7 @@ static int do_isofs_readdir(struct inode *inode, struct file *filp,
183 183
184 /* Handle the case of the '..' directory */ 184 /* Handle the case of the '..' directory */
185 if (de->name_len[0] == 1 && de->name[0] == 1) { 185 if (de->name_len[0] == 1 && de->name[0] == 1) {
186 inode_number = parent_ino(filp->f_dentry); 186 inode_number = parent_ino(filp->f_path.dentry);
187 if (filldir(dirent, "..", 2, filp->f_pos, inode_number, DT_DIR) < 0) 187 if (filldir(dirent, "..", 2, filp->f_pos, inode_number, DT_DIR) < 0)
188 break; 188 break;
189 filp->f_pos += de_len; 189 filp->f_pos += de_len;
@@ -255,8 +255,7 @@ static int isofs_readdir(struct file *filp,
255 int result; 255 int result;
256 char * tmpname; 256 char * tmpname;
257 struct iso_directory_record * tmpde; 257 struct iso_directory_record * tmpde;
258 struct inode *inode = filp->f_dentry->d_inode; 258 struct inode *inode = filp->f_path.dentry->d_inode;
259
260 259
261 tmpname = (char *)__get_free_page(GFP_KERNEL); 260 tmpname = (char *)__get_free_page(GFP_KERNEL);
262 if (tmpname == NULL) 261 if (tmpname == NULL)
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index d38e0d575e48..cceaf57e3778 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -55,7 +55,7 @@ get_transaction(journal_t *journal, transaction_t *transaction)
55 spin_lock_init(&transaction->t_handle_lock); 55 spin_lock_init(&transaction->t_handle_lock);
56 56
57 /* Set up the commit timer for the new transaction. */ 57 /* Set up the commit timer for the new transaction. */
58 journal->j_commit_timer.expires = transaction->t_expires; 58 journal->j_commit_timer.expires = round_jiffies(transaction->t_expires);
59 add_timer(&journal->j_commit_timer); 59 add_timer(&journal->j_commit_timer);
60 60
61 J_ASSERT(journal->j_running_transaction == NULL); 61 J_ASSERT(journal->j_running_transaction == NULL);
diff --git a/fs/jffs/inode-v23.c b/fs/jffs/inode-v23.c
index 9f15bce92022..7b40c69f44eb 100644
--- a/fs/jffs/inode-v23.c
+++ b/fs/jffs/inode-v23.c
@@ -566,7 +566,7 @@ static int
566jffs_readdir(struct file *filp, void *dirent, filldir_t filldir) 566jffs_readdir(struct file *filp, void *dirent, filldir_t filldir)
567{ 567{
568 struct jffs_file *f; 568 struct jffs_file *f;
569 struct dentry *dentry = filp->f_dentry; 569 struct dentry *dentry = filp->f_path.dentry;
570 struct inode *inode = dentry->d_inode; 570 struct inode *inode = dentry->d_inode;
571 struct jffs_control *c = (struct jffs_control *)inode->i_sb->s_fs_info; 571 struct jffs_control *c = (struct jffs_control *)inode->i_sb->s_fs_info;
572 int j; 572 int j;
@@ -1372,7 +1372,7 @@ jffs_file_write(struct file *filp, const char *buf, size_t count,
1372 struct jffs_control *c; 1372 struct jffs_control *c;
1373 struct jffs_file *f; 1373 struct jffs_file *f;
1374 struct jffs_node *node; 1374 struct jffs_node *node;
1375 struct dentry *dentry = filp->f_dentry; 1375 struct dentry *dentry = filp->f_path.dentry;
1376 struct inode *inode = dentry->d_inode; 1376 struct inode *inode = dentry->d_inode;
1377 int recoverable = 0; 1377 int recoverable = 0;
1378 size_t written = 0; 1378 size_t written = 0;
@@ -1380,7 +1380,7 @@ jffs_file_write(struct file *filp, const char *buf, size_t count,
1380 loff_t pos = *ppos; 1380 loff_t pos = *ppos;
1381 int err; 1381 int err;
1382 1382
1383 inode = filp->f_dentry->d_inode; 1383 inode = filp->f_path.dentry->d_inode;
1384 1384
1385 D2(printk("***jffs_file_write(): inode: 0x%p (ino: %lu), " 1385 D2(printk("***jffs_file_write(): inode: 0x%p (ino: %lu), "
1386 "filp: 0x%p, buf: 0x%p, count: %d\n", 1386 "filp: 0x%p, buf: 0x%p, count: %d\n",
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index 9def6adf4a5d..da6034d50718 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -123,11 +123,11 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
123{ 123{
124 struct jffs2_inode_info *f; 124 struct jffs2_inode_info *f;
125 struct jffs2_sb_info *c; 125 struct jffs2_sb_info *c;
126 struct inode *inode = filp->f_dentry->d_inode; 126 struct inode *inode = filp->f_path.dentry->d_inode;
127 struct jffs2_full_dirent *fd; 127 struct jffs2_full_dirent *fd;
128 unsigned long offset, curofs; 128 unsigned long offset, curofs;
129 129
130 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_dentry->d_inode->i_ino)); 130 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_path.dentry->d_inode->i_ino));
131 131
132 f = JFFS2_INODE_INFO(inode); 132 f = JFFS2_INODE_INFO(inode);
133 c = JFFS2_SB_INFO(inode->i_sb); 133 c = JFFS2_SB_INFO(inode->i_sb);
@@ -141,7 +141,7 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
141 offset++; 141 offset++;
142 } 142 }
143 if (offset == 1) { 143 if (offset == 1) {
144 unsigned long pino = parent_ino(filp->f_dentry); 144 unsigned long pino = parent_ino(filp->f_path.dentry);
145 D1(printk(KERN_DEBUG "Dirent 1: \"..\", ino #%lu\n", pino)); 145 D1(printk(KERN_DEBUG "Dirent 1: \"..\", ino #%lu\n", pino));
146 if (filldir(dirent, "..", 2, 1, pino, DT_DIR) < 0) 146 if (filldir(dirent, "..", 2, 1, pino, DT_DIR) < 0)
147 goto out; 147 goto out;
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index ecb2216d881c..47bc0b5d1324 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -3009,7 +3009,7 @@ static inline struct jfs_dirent *next_jfs_dirent(struct jfs_dirent *dirent)
3009 */ 3009 */
3010int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 3010int jfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
3011{ 3011{
3012 struct inode *ip = filp->f_dentry->d_inode; 3012 struct inode *ip = filp->f_path.dentry->d_inode;
3013 struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab; 3013 struct nls_table *codepage = JFS_SBI(ip->i_sb)->nls_tab;
3014 int rc = 0; 3014 int rc = 0;
3015 loff_t dtpos; /* legacy OS/2 style position */ 3015 loff_t dtpos; /* legacy OS/2 style position */
diff --git a/fs/jfs/jfs_filsys.h b/fs/jfs/jfs_filsys.h
index eb550b339bb8..38f70ac03bec 100644
--- a/fs/jfs/jfs_filsys.h
+++ b/fs/jfs/jfs_filsys.h
@@ -29,31 +29,21 @@
29/* 29/*
30 * file system option (superblock flag) 30 * file system option (superblock flag)
31 */ 31 */
32/* mount time flag to disable journaling to disk */ 32
33#define JFS_NOINTEGRITY 0x00000010 33/* directory option */
34#define JFS_UNICODE 0x00000001 /* unicode name */
34 35
35/* mount time flags for error handling */ 36/* mount time flags for error handling */
36#define JFS_ERR_REMOUNT_RO 0x00000002 /* remount read-only */ 37#define JFS_ERR_REMOUNT_RO 0x00000002 /* remount read-only */
37#define JFS_ERR_CONTINUE 0x00000004 /* continue */ 38#define JFS_ERR_CONTINUE 0x00000004 /* continue */
38#define JFS_ERR_PANIC 0x00000008 /* panic */ 39#define JFS_ERR_PANIC 0x00000008 /* panic */
39 40
41/* Quota support */
40#define JFS_USRQUOTA 0x00000010 42#define JFS_USRQUOTA 0x00000010
41#define JFS_GRPQUOTA 0x00000020 43#define JFS_GRPQUOTA 0x00000020
42 44
43/* platform option (conditional compilation) */ 45/* mount time flag to disable journaling to disk */
44#define JFS_AIX 0x80000000 /* AIX support */ 46#define JFS_NOINTEGRITY 0x00000040
45/* POSIX name/directory support */
46
47#define JFS_OS2 0x40000000 /* OS/2 support */
48/* case-insensitive name/directory support */
49
50#define JFS_DFS 0x20000000 /* DCE DFS LFS support */
51
52#define JFS_LINUX 0x10000000 /* Linux support */
53/* case-sensitive name/directory support */
54
55/* directory option */
56#define JFS_UNICODE 0x00000001 /* unicode name */
57 47
58/* commit option */ 48/* commit option */
59#define JFS_COMMIT 0x00000f00 /* commit option mask */ 49#define JFS_COMMIT 0x00000f00 /* commit option mask */
@@ -61,6 +51,7 @@
61#define JFS_LAZYCOMMIT 0x00000200 /* lazy commit */ 51#define JFS_LAZYCOMMIT 0x00000200 /* lazy commit */
62#define JFS_TMPFS 0x00000400 /* temporary file system - 52#define JFS_TMPFS 0x00000400 /* temporary file system -
63 * do not log/commit: 53 * do not log/commit:
54 * Never implemented
64 */ 55 */
65 56
66/* log logical volume option */ 57/* log logical volume option */
@@ -74,16 +65,25 @@
74#define JFS_SPARSE 0x00020000 /* sparse regular file */ 65#define JFS_SPARSE 0x00020000 /* sparse regular file */
75 66
76/* DASD Limits F226941 */ 67/* DASD Limits F226941 */
77#define JFS_DASD_ENABLED 0x00040000 /* DASD limits enabled */ 68#define JFS_DASD_ENABLED 0x00040000 /* DASD limits enabled */
78#define JFS_DASD_PRIME 0x00080000 /* Prime DASD usage on boot */ 69#define JFS_DASD_PRIME 0x00080000 /* Prime DASD usage on boot */
79 70
80/* big endian flag */ 71/* big endian flag */
81#define JFS_SWAP_BYTES 0x00100000 /* running on big endian computer */ 72#define JFS_SWAP_BYTES 0x00100000 /* running on big endian computer */
82 73
83/* Directory index */ 74/* Directory index */
84#define JFS_DIR_INDEX 0x00200000 /* Persistent index for */ 75#define JFS_DIR_INDEX 0x00200000 /* Persistent index for */
85 /* directory entries */
86 76
77/* platform options */
78#define JFS_LINUX 0x10000000 /* Linux support */
79#define JFS_DFS 0x20000000 /* DCE DFS LFS support */
80/* Never implemented */
81
82#define JFS_OS2 0x40000000 /* OS/2 support */
83/* case-insensitive name/directory support */
84
85#define JFS_AIX 0x80000000 /* AIX support */
86/* POSIX name/directory support - Never implemented*/
87 87
88/* 88/*
89 * buffer cache configuration 89 * buffer cache configuration
diff --git a/fs/libfs.c b/fs/libfs.c
index bd08e0e64a8c..503898d5c4a7 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -63,7 +63,7 @@ int dcache_dir_open(struct inode *inode, struct file *file)
63{ 63{
64 static struct qstr cursor_name = {.len = 1, .name = "."}; 64 static struct qstr cursor_name = {.len = 1, .name = "."};
65 65
66 file->private_data = d_alloc(file->f_dentry, &cursor_name); 66 file->private_data = d_alloc(file->f_path.dentry, &cursor_name);
67 67
68 return file->private_data ? 0 : -ENOMEM; 68 return file->private_data ? 0 : -ENOMEM;
69} 69}
@@ -76,7 +76,7 @@ int dcache_dir_close(struct inode *inode, struct file *file)
76 76
77loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin) 77loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
78{ 78{
79 mutex_lock(&file->f_dentry->d_inode->i_mutex); 79 mutex_lock(&file->f_path.dentry->d_inode->i_mutex);
80 switch (origin) { 80 switch (origin) {
81 case 1: 81 case 1:
82 offset += file->f_pos; 82 offset += file->f_pos;
@@ -84,7 +84,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
84 if (offset >= 0) 84 if (offset >= 0)
85 break; 85 break;
86 default: 86 default:
87 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 87 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
88 return -EINVAL; 88 return -EINVAL;
89 } 89 }
90 if (offset != file->f_pos) { 90 if (offset != file->f_pos) {
@@ -96,8 +96,8 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
96 96
97 spin_lock(&dcache_lock); 97 spin_lock(&dcache_lock);
98 list_del(&cursor->d_u.d_child); 98 list_del(&cursor->d_u.d_child);
99 p = file->f_dentry->d_subdirs.next; 99 p = file->f_path.dentry->d_subdirs.next;
100 while (n && p != &file->f_dentry->d_subdirs) { 100 while (n && p != &file->f_path.dentry->d_subdirs) {
101 struct dentry *next; 101 struct dentry *next;
102 next = list_entry(p, struct dentry, d_u.d_child); 102 next = list_entry(p, struct dentry, d_u.d_child);
103 if (!d_unhashed(next) && next->d_inode) 103 if (!d_unhashed(next) && next->d_inode)
@@ -108,7 +108,7 @@ loff_t dcache_dir_lseek(struct file *file, loff_t offset, int origin)
108 spin_unlock(&dcache_lock); 108 spin_unlock(&dcache_lock);
109 } 109 }
110 } 110 }
111 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 111 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
112 return offset; 112 return offset;
113} 113}
114 114
@@ -126,7 +126,7 @@ static inline unsigned char dt_type(struct inode *inode)
126 126
127int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir) 127int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
128{ 128{
129 struct dentry *dentry = filp->f_dentry; 129 struct dentry *dentry = filp->f_path.dentry;
130 struct dentry *cursor = filp->private_data; 130 struct dentry *cursor = filp->private_data;
131 struct list_head *p, *q = &cursor->d_u.d_child; 131 struct list_head *p, *q = &cursor->d_u.d_child;
132 ino_t ino; 132 ino_t ino;
diff --git a/fs/lockd/clntlock.c b/fs/lockd/clntlock.c
index b85a0ad2cfb6..92681c9e9b20 100644
--- a/fs/lockd/clntlock.c
+++ b/fs/lockd/clntlock.c
@@ -126,7 +126,7 @@ __be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock
126 continue; 126 continue;
127 if (!nlm_cmp_addr(&block->b_host->h_addr, addr)) 127 if (!nlm_cmp_addr(&block->b_host->h_addr, addr))
128 continue; 128 continue;
129 if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_dentry->d_inode) ,fh) != 0) 129 if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
130 continue; 130 continue;
131 /* Alright, we found a lock. Set the return status 131 /* Alright, we found a lock. Set the return status
132 * and wake up the caller 132 * and wake up the caller
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index 497c3cd59d52..80a1a6dccc8f 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -129,7 +129,7 @@ static void nlmclnt_setlockargs(struct nlm_rqst *req, struct file_lock *fl)
129 129
130 nlmclnt_next_cookie(&argp->cookie); 130 nlmclnt_next_cookie(&argp->cookie);
131 argp->state = nsm_local_state; 131 argp->state = nsm_local_state;
132 memcpy(&lock->fh, NFS_FH(fl->fl_file->f_dentry->d_inode), sizeof(struct nfs_fh)); 132 memcpy(&lock->fh, NFS_FH(fl->fl_file->f_path.dentry->d_inode), sizeof(struct nfs_fh));
133 lock->caller = utsname()->nodename; 133 lock->caller = utsname()->nodename;
134 lock->oh.data = req->a_owner; 134 lock->oh.data = req->a_owner;
135 lock->oh.len = snprintf(req->a_owner, sizeof(req->a_owner), "%u@%s", 135 lock->oh.len = snprintf(req->a_owner, sizeof(req->a_owner), "%u@%s",
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index 7e219b938552..5c054b20fd5e 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -343,8 +343,8 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
343 __be32 ret; 343 __be32 ret;
344 344
345 dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n", 345 dprintk("lockd: nlmsvc_lock(%s/%ld, ty=%d, pi=%d, %Ld-%Ld, bl=%d)\n",
346 file->f_file->f_dentry->d_inode->i_sb->s_id, 346 file->f_file->f_path.dentry->d_inode->i_sb->s_id,
347 file->f_file->f_dentry->d_inode->i_ino, 347 file->f_file->f_path.dentry->d_inode->i_ino,
348 lock->fl.fl_type, lock->fl.fl_pid, 348 lock->fl.fl_type, lock->fl.fl_pid,
349 (long long)lock->fl.fl_start, 349 (long long)lock->fl.fl_start,
350 (long long)lock->fl.fl_end, 350 (long long)lock->fl.fl_end,
@@ -420,8 +420,8 @@ nlmsvc_testlock(struct nlm_file *file, struct nlm_lock *lock,
420 struct nlm_lock *conflock) 420 struct nlm_lock *conflock)
421{ 421{
422 dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n", 422 dprintk("lockd: nlmsvc_testlock(%s/%ld, ty=%d, %Ld-%Ld)\n",
423 file->f_file->f_dentry->d_inode->i_sb->s_id, 423 file->f_file->f_path.dentry->d_inode->i_sb->s_id,
424 file->f_file->f_dentry->d_inode->i_ino, 424 file->f_file->f_path.dentry->d_inode->i_ino,
425 lock->fl.fl_type, 425 lock->fl.fl_type,
426 (long long)lock->fl.fl_start, 426 (long long)lock->fl.fl_start,
427 (long long)lock->fl.fl_end); 427 (long long)lock->fl.fl_end);
@@ -454,8 +454,8 @@ nlmsvc_unlock(struct nlm_file *file, struct nlm_lock *lock)
454 int error; 454 int error;
455 455
456 dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n", 456 dprintk("lockd: nlmsvc_unlock(%s/%ld, pi=%d, %Ld-%Ld)\n",
457 file->f_file->f_dentry->d_inode->i_sb->s_id, 457 file->f_file->f_path.dentry->d_inode->i_sb->s_id,
458 file->f_file->f_dentry->d_inode->i_ino, 458 file->f_file->f_path.dentry->d_inode->i_ino,
459 lock->fl.fl_pid, 459 lock->fl.fl_pid,
460 (long long)lock->fl.fl_start, 460 (long long)lock->fl.fl_start,
461 (long long)lock->fl.fl_end); 461 (long long)lock->fl.fl_end);
@@ -483,8 +483,8 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
483 int status = 0; 483 int status = 0;
484 484
485 dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n", 485 dprintk("lockd: nlmsvc_cancel(%s/%ld, pi=%d, %Ld-%Ld)\n",
486 file->f_file->f_dentry->d_inode->i_sb->s_id, 486 file->f_file->f_path.dentry->d_inode->i_sb->s_id,
487 file->f_file->f_dentry->d_inode->i_ino, 487 file->f_file->f_path.dentry->d_inode->i_ino,
488 lock->fl.fl_pid, 488 lock->fl.fl_pid,
489 (long long)lock->fl.fl_start, 489 (long long)lock->fl.fl_start,
490 (long long)lock->fl.fl_end); 490 (long long)lock->fl.fl_end);
diff --git a/fs/lockd/svcsubs.c b/fs/lockd/svcsubs.c
index e83024e16042..c0df00c74ce3 100644
--- a/fs/lockd/svcsubs.c
+++ b/fs/lockd/svcsubs.c
@@ -43,7 +43,7 @@ static inline void nlm_debug_print_fh(char *msg, struct nfs_fh *f)
43 43
44static inline void nlm_debug_print_file(char *msg, struct nlm_file *file) 44static inline void nlm_debug_print_file(char *msg, struct nlm_file *file)
45{ 45{
46 struct inode *inode = file->f_file->f_dentry->d_inode; 46 struct inode *inode = file->f_file->f_path.dentry->d_inode;
47 47
48 dprintk("lockd: %s %s/%ld\n", 48 dprintk("lockd: %s %s/%ld\n",
49 msg, inode->i_sb->s_id, inode->i_ino); 49 msg, inode->i_sb->s_id, inode->i_ino);
diff --git a/fs/locks.c b/fs/locks.c
index 1cb0c57fedbd..52a81005dab4 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -321,7 +321,7 @@ static int flock_to_posix_lock(struct file *filp, struct file_lock *fl,
321 start = filp->f_pos; 321 start = filp->f_pos;
322 break; 322 break;
323 case SEEK_END: 323 case SEEK_END:
324 start = i_size_read(filp->f_dentry->d_inode); 324 start = i_size_read(filp->f_path.dentry->d_inode);
325 break; 325 break;
326 default: 326 default:
327 return -EINVAL; 327 return -EINVAL;
@@ -371,7 +371,7 @@ static int flock64_to_posix_lock(struct file *filp, struct file_lock *fl,
371 start = filp->f_pos; 371 start = filp->f_pos;
372 break; 372 break;
373 case SEEK_END: 373 case SEEK_END:
374 start = i_size_read(filp->f_dentry->d_inode); 374 start = i_size_read(filp->f_path.dentry->d_inode);
375 break; 375 break;
376 default: 376 default:
377 return -EINVAL; 377 return -EINVAL;
@@ -672,7 +672,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl,
672 struct file_lock *cfl; 672 struct file_lock *cfl;
673 673
674 lock_kernel(); 674 lock_kernel();
675 for (cfl = filp->f_dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) { 675 for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
676 if (!IS_POSIX(cfl)) 676 if (!IS_POSIX(cfl))
677 continue; 677 continue;
678 if (posix_locks_conflict(cfl, fl)) 678 if (posix_locks_conflict(cfl, fl))
@@ -734,7 +734,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
734{ 734{
735 struct file_lock *new_fl = NULL; 735 struct file_lock *new_fl = NULL;
736 struct file_lock **before; 736 struct file_lock **before;
737 struct inode * inode = filp->f_dentry->d_inode; 737 struct inode * inode = filp->f_path.dentry->d_inode;
738 int error = 0; 738 int error = 0;
739 int found = 0; 739 int found = 0;
740 740
@@ -1018,7 +1018,7 @@ static int __posix_lock_file_conf(struct inode *inode, struct file_lock *request
1018 */ 1018 */
1019int posix_lock_file(struct file *filp, struct file_lock *fl) 1019int posix_lock_file(struct file *filp, struct file_lock *fl)
1020{ 1020{
1021 return __posix_lock_file_conf(filp->f_dentry->d_inode, fl, NULL); 1021 return __posix_lock_file_conf(filp->f_path.dentry->d_inode, fl, NULL);
1022} 1022}
1023EXPORT_SYMBOL(posix_lock_file); 1023EXPORT_SYMBOL(posix_lock_file);
1024 1024
@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(posix_lock_file);
1033int posix_lock_file_conf(struct file *filp, struct file_lock *fl, 1033int posix_lock_file_conf(struct file *filp, struct file_lock *fl,
1034 struct file_lock *conflock) 1034 struct file_lock *conflock)
1035{ 1035{
1036 return __posix_lock_file_conf(filp->f_dentry->d_inode, fl, conflock); 1036 return __posix_lock_file_conf(filp->f_path.dentry->d_inode, fl, conflock);
1037} 1037}
1038EXPORT_SYMBOL(posix_lock_file_conf); 1038EXPORT_SYMBOL(posix_lock_file_conf);
1039 1039
@@ -1333,8 +1333,8 @@ int fcntl_getlease(struct file *filp)
1333 int type = F_UNLCK; 1333 int type = F_UNLCK;
1334 1334
1335 lock_kernel(); 1335 lock_kernel();
1336 time_out_leases(filp->f_dentry->d_inode); 1336 time_out_leases(filp->f_path.dentry->d_inode);
1337 for (fl = filp->f_dentry->d_inode->i_flock; fl && IS_LEASE(fl); 1337 for (fl = filp->f_path.dentry->d_inode->i_flock; fl && IS_LEASE(fl);
1338 fl = fl->fl_next) { 1338 fl = fl->fl_next) {
1339 if (fl->fl_file == filp) { 1339 if (fl->fl_file == filp) {
1340 type = fl->fl_type & ~F_INPROGRESS; 1340 type = fl->fl_type & ~F_INPROGRESS;
@@ -1359,7 +1359,7 @@ int fcntl_getlease(struct file *filp)
1359static int __setlease(struct file *filp, long arg, struct file_lock **flp) 1359static int __setlease(struct file *filp, long arg, struct file_lock **flp)
1360{ 1360{
1361 struct file_lock *fl, **before, **my_before = NULL, *lease; 1361 struct file_lock *fl, **before, **my_before = NULL, *lease;
1362 struct dentry *dentry = filp->f_dentry; 1362 struct dentry *dentry = filp->f_path.dentry;
1363 struct inode *inode = dentry->d_inode; 1363 struct inode *inode = dentry->d_inode;
1364 int error, rdlease_count = 0, wrlease_count = 0; 1364 int error, rdlease_count = 0, wrlease_count = 0;
1365 1365
@@ -1448,7 +1448,7 @@ out:
1448 1448
1449int setlease(struct file *filp, long arg, struct file_lock **lease) 1449int setlease(struct file *filp, long arg, struct file_lock **lease)
1450{ 1450{
1451 struct dentry *dentry = filp->f_dentry; 1451 struct dentry *dentry = filp->f_path.dentry;
1452 struct inode *inode = dentry->d_inode; 1452 struct inode *inode = dentry->d_inode;
1453 int error; 1453 int error;
1454 1454
@@ -1482,7 +1482,7 @@ EXPORT_SYMBOL(setlease);
1482int fcntl_setlease(unsigned int fd, struct file *filp, long arg) 1482int fcntl_setlease(unsigned int fd, struct file *filp, long arg)
1483{ 1483{
1484 struct file_lock fl, *flp = &fl; 1484 struct file_lock fl, *flp = &fl;
1485 struct dentry *dentry = filp->f_dentry; 1485 struct dentry *dentry = filp->f_path.dentry;
1486 struct inode *inode = dentry->d_inode; 1486 struct inode *inode = dentry->d_inode;
1487 int error; 1487 int error;
1488 1488
@@ -1692,7 +1692,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
1692 if (copy_from_user(&flock, l, sizeof(flock))) 1692 if (copy_from_user(&flock, l, sizeof(flock)))
1693 goto out; 1693 goto out;
1694 1694
1695 inode = filp->f_dentry->d_inode; 1695 inode = filp->f_path.dentry->d_inode;
1696 1696
1697 /* Don't allow mandatory locks on files that may be memory mapped 1697 /* Don't allow mandatory locks on files that may be memory mapped
1698 * and shared. 1698 * and shared.
@@ -1835,7 +1835,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
1835 if (copy_from_user(&flock, l, sizeof(flock))) 1835 if (copy_from_user(&flock, l, sizeof(flock)))
1836 goto out; 1836 goto out;
1837 1837
1838 inode = filp->f_dentry->d_inode; 1838 inode = filp->f_path.dentry->d_inode;
1839 1839
1840 /* Don't allow mandatory locks on files that may be memory mapped 1840 /* Don't allow mandatory locks on files that may be memory mapped
1841 * and shared. 1841 * and shared.
@@ -1922,7 +1922,7 @@ void locks_remove_posix(struct file *filp, fl_owner_t owner)
1922 * posix_lock_file(). Another process could be setting a lock on this 1922 * posix_lock_file(). Another process could be setting a lock on this
1923 * file at the same time, but we wouldn't remove that lock anyway. 1923 * file at the same time, but we wouldn't remove that lock anyway.
1924 */ 1924 */
1925 if (!filp->f_dentry->d_inode->i_flock) 1925 if (!filp->f_path.dentry->d_inode->i_flock)
1926 return; 1926 return;
1927 1927
1928 lock.fl_type = F_UNLCK; 1928 lock.fl_type = F_UNLCK;
@@ -1951,7 +1951,7 @@ EXPORT_SYMBOL(locks_remove_posix);
1951 */ 1951 */
1952void locks_remove_flock(struct file *filp) 1952void locks_remove_flock(struct file *filp)
1953{ 1953{
1954 struct inode * inode = filp->f_dentry->d_inode; 1954 struct inode * inode = filp->f_path.dentry->d_inode;
1955 struct file_lock *fl; 1955 struct file_lock *fl;
1956 struct file_lock **before; 1956 struct file_lock **before;
1957 1957
@@ -2020,7 +2020,7 @@ static void lock_get_status(char* out, struct file_lock *fl, int id, char *pfx)
2020 struct inode *inode = NULL; 2020 struct inode *inode = NULL;
2021 2021
2022 if (fl->fl_file != NULL) 2022 if (fl->fl_file != NULL)
2023 inode = fl->fl_file->f_dentry->d_inode; 2023 inode = fl->fl_file->f_path.dentry->d_inode;
2024 2024
2025 out += sprintf(out, "%d:%s ", id, pfx); 2025 out += sprintf(out, "%d:%s ", id, pfx);
2026 if (IS_POSIX(fl)) { 2026 if (IS_POSIX(fl)) {
diff --git a/fs/minix/dir.c b/fs/minix/dir.c
index 2b0a389d1987..ab782c4086f5 100644
--- a/fs/minix/dir.c
+++ b/fs/minix/dir.c
@@ -82,7 +82,7 @@ static inline void *minix_next_entry(void *de, struct minix_sb_info *sbi)
82static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir) 82static int minix_readdir(struct file * filp, void * dirent, filldir_t filldir)
83{ 83{
84 unsigned long pos = filp->f_pos; 84 unsigned long pos = filp->f_pos;
85 struct inode *inode = filp->f_dentry->d_inode; 85 struct inode *inode = filp->f_path.dentry->d_inode;
86 struct super_block *sb = inode->i_sb; 86 struct super_block *sb = inode->i_sb;
87 unsigned offset = pos & ~PAGE_CACHE_MASK; 87 unsigned offset = pos & ~PAGE_CACHE_MASK;
88 unsigned long n = pos >> PAGE_CACHE_SHIFT; 88 unsigned long n = pos >> PAGE_CACHE_SHIFT;
diff --git a/fs/namei.c b/fs/namei.c
index db1bca26d88c..e4f108f08230 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -297,7 +297,7 @@ int vfs_permission(struct nameidata *nd, int mask)
297 */ 297 */
298int file_permission(struct file *file, int mask) 298int file_permission(struct file *file, int mask)
299{ 299{
300 return permission(file->f_dentry->d_inode, mask, NULL); 300 return permission(file->f_path.dentry->d_inode, mask, NULL);
301} 301}
302 302
303/* 303/*
@@ -333,7 +333,7 @@ int get_write_access(struct inode * inode)
333 333
334int deny_write_access(struct file * file) 334int deny_write_access(struct file * file)
335{ 335{
336 struct inode *inode = file->f_dentry->d_inode; 336 struct inode *inode = file->f_path.dentry->d_inode;
337 337
338 spin_lock(&inode->i_lock); 338 spin_lock(&inode->i_lock);
339 if (atomic_read(&inode->i_writecount) > 0) { 339 if (atomic_read(&inode->i_writecount) > 0) {
@@ -368,7 +368,7 @@ void path_release_on_umount(struct nameidata *nd)
368 */ 368 */
369void release_open_intent(struct nameidata *nd) 369void release_open_intent(struct nameidata *nd)
370{ 370{
371 if (nd->intent.open.file->f_dentry == NULL) 371 if (nd->intent.open.file->f_path.dentry == NULL)
372 put_filp(nd->intent.open.file); 372 put_filp(nd->intent.open.file);
373 else 373 else
374 fput(nd->intent.open.file); 374 fput(nd->intent.open.file);
@@ -572,11 +572,6 @@ fail:
572 return PTR_ERR(link); 572 return PTR_ERR(link);
573} 573}
574 574
575struct path {
576 struct vfsmount *mnt;
577 struct dentry *dentry;
578};
579
580static inline void dput_path(struct path *path, struct nameidata *nd) 575static inline void dput_path(struct path *path, struct nameidata *nd)
581{ 576{
582 dput(path->dentry); 577 dput(path->dentry);
@@ -1143,7 +1138,7 @@ static int fastcall do_path_lookup(int dfd, const char *name,
1143 if (!file) 1138 if (!file)
1144 goto out_fail; 1139 goto out_fail;
1145 1140
1146 dentry = file->f_dentry; 1141 dentry = file->f_path.dentry;
1147 1142
1148 retval = -ENOTDIR; 1143 retval = -ENOTDIR;
1149 if (!S_ISDIR(dentry->d_inode->i_mode)) 1144 if (!S_ISDIR(dentry->d_inode->i_mode))
@@ -1153,7 +1148,7 @@ static int fastcall do_path_lookup(int dfd, const char *name,
1153 if (retval) 1148 if (retval)
1154 goto fput_fail; 1149 goto fput_fail;
1155 1150
1156 nd->mnt = mntget(file->f_vfsmnt); 1151 nd->mnt = mntget(file->f_path.mnt);
1157 nd->dentry = dget(dentry); 1152 nd->dentry = dget(dentry);
1158 1153
1159 fput_light(file, fput_needed); 1154 fput_light(file, fput_needed);
diff --git a/fs/namespace.c b/fs/namespace.c
index b00ac84ebbdd..fde8553faa76 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -20,7 +20,7 @@
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/sysfs.h> 21#include <linux/sysfs.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/namespace.h> 23#include <linux/mnt_namespace.h>
24#include <linux/namei.h> 24#include <linux/namei.h>
25#include <linux/security.h> 25#include <linux/security.h>
26#include <linux/mount.h> 26#include <linux/mount.h>
@@ -133,10 +133,10 @@ struct vfsmount *lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
133 133
134static inline int check_mnt(struct vfsmount *mnt) 134static inline int check_mnt(struct vfsmount *mnt)
135{ 135{
136 return mnt->mnt_namespace == current->nsproxy->namespace; 136 return mnt->mnt_ns == current->nsproxy->mnt_ns;
137} 137}
138 138
139static void touch_namespace(struct namespace *ns) 139static void touch_mnt_namespace(struct mnt_namespace *ns)
140{ 140{
141 if (ns) { 141 if (ns) {
142 ns->event = ++event; 142 ns->event = ++event;
@@ -144,7 +144,7 @@ static void touch_namespace(struct namespace *ns)
144 } 144 }
145} 145}
146 146
147static void __touch_namespace(struct namespace *ns) 147static void __touch_mnt_namespace(struct mnt_namespace *ns)
148{ 148{
149 if (ns && ns->event != event) { 149 if (ns && ns->event != event) {
150 ns->event = event; 150 ns->event = event;
@@ -187,19 +187,19 @@ static void commit_tree(struct vfsmount *mnt)
187 struct vfsmount *parent = mnt->mnt_parent; 187 struct vfsmount *parent = mnt->mnt_parent;
188 struct vfsmount *m; 188 struct vfsmount *m;
189 LIST_HEAD(head); 189 LIST_HEAD(head);
190 struct namespace *n = parent->mnt_namespace; 190 struct mnt_namespace *n = parent->mnt_ns;
191 191
192 BUG_ON(parent == mnt); 192 BUG_ON(parent == mnt);
193 193
194 list_add_tail(&head, &mnt->mnt_list); 194 list_add_tail(&head, &mnt->mnt_list);
195 list_for_each_entry(m, &head, mnt_list) 195 list_for_each_entry(m, &head, mnt_list)
196 m->mnt_namespace = n; 196 m->mnt_ns = n;
197 list_splice(&head, n->list.prev); 197 list_splice(&head, n->list.prev);
198 198
199 list_add_tail(&mnt->mnt_hash, mount_hashtable + 199 list_add_tail(&mnt->mnt_hash, mount_hashtable +
200 hash(parent, mnt->mnt_mountpoint)); 200 hash(parent, mnt->mnt_mountpoint));
201 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts); 201 list_add_tail(&mnt->mnt_child, &parent->mnt_mounts);
202 touch_namespace(n); 202 touch_mnt_namespace(n);
203} 203}
204 204
205static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root) 205static struct vfsmount *next_mnt(struct vfsmount *p, struct vfsmount *root)
@@ -320,7 +320,7 @@ EXPORT_SYMBOL(mnt_unpin);
320/* iterator */ 320/* iterator */
321static void *m_start(struct seq_file *m, loff_t *pos) 321static void *m_start(struct seq_file *m, loff_t *pos)
322{ 322{
323 struct namespace *n = m->private; 323 struct mnt_namespace *n = m->private;
324 struct list_head *p; 324 struct list_head *p;
325 loff_t l = *pos; 325 loff_t l = *pos;
326 326
@@ -333,7 +333,7 @@ static void *m_start(struct seq_file *m, loff_t *pos)
333 333
334static void *m_next(struct seq_file *m, void *v, loff_t *pos) 334static void *m_next(struct seq_file *m, void *v, loff_t *pos)
335{ 335{
336 struct namespace *n = m->private; 336 struct mnt_namespace *n = m->private;
337 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next; 337 struct list_head *p = ((struct vfsmount *)v)->mnt_list.next;
338 (*pos)++; 338 (*pos)++;
339 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list); 339 return p == &n->list ? NULL : list_entry(p, struct vfsmount, mnt_list);
@@ -526,8 +526,8 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
526 list_for_each_entry(p, kill, mnt_hash) { 526 list_for_each_entry(p, kill, mnt_hash) {
527 list_del_init(&p->mnt_expire); 527 list_del_init(&p->mnt_expire);
528 list_del_init(&p->mnt_list); 528 list_del_init(&p->mnt_list);
529 __touch_namespace(p->mnt_namespace); 529 __touch_mnt_namespace(p->mnt_ns);
530 p->mnt_namespace = NULL; 530 p->mnt_ns = NULL;
531 list_del_init(&p->mnt_child); 531 list_del_init(&p->mnt_child);
532 if (p->mnt_parent != p) 532 if (p->mnt_parent != p)
533 p->mnt_mountpoint->d_mounted--; 533 p->mnt_mountpoint->d_mounted--;
@@ -830,7 +830,7 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
830 if (parent_nd) { 830 if (parent_nd) {
831 detach_mnt(source_mnt, parent_nd); 831 detach_mnt(source_mnt, parent_nd);
832 attach_mnt(source_mnt, nd); 832 attach_mnt(source_mnt, nd);
833 touch_namespace(current->nsproxy->namespace); 833 touch_mnt_namespace(current->nsproxy->mnt_ns);
834 } else { 834 } else {
835 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); 835 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
836 commit_tree(source_mnt); 836 commit_tree(source_mnt);
@@ -1145,9 +1145,9 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1145 */ 1145 */
1146 if (!propagate_mount_busy(mnt, 2)) { 1146 if (!propagate_mount_busy(mnt, 2)) {
1147 /* delete from the namespace */ 1147 /* delete from the namespace */
1148 touch_namespace(mnt->mnt_namespace); 1148 touch_mnt_namespace(mnt->mnt_ns);
1149 list_del_init(&mnt->mnt_list); 1149 list_del_init(&mnt->mnt_list);
1150 mnt->mnt_namespace = NULL; 1150 mnt->mnt_ns = NULL;
1151 umount_tree(mnt, 1, umounts); 1151 umount_tree(mnt, 1, umounts);
1152 spin_unlock(&vfsmount_lock); 1152 spin_unlock(&vfsmount_lock);
1153 } else { 1153 } else {
@@ -1168,7 +1168,7 @@ static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1168 */ 1168 */
1169static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts) 1169static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
1170{ 1170{
1171 struct namespace *namespace; 1171 struct mnt_namespace *ns;
1172 struct vfsmount *mnt; 1172 struct vfsmount *mnt;
1173 1173
1174 while (!list_empty(graveyard)) { 1174 while (!list_empty(graveyard)) {
@@ -1178,10 +1178,10 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1178 1178
1179 /* don't do anything if the namespace is dead - all the 1179 /* don't do anything if the namespace is dead - all the
1180 * vfsmounts from it are going away anyway */ 1180 * vfsmounts from it are going away anyway */
1181 namespace = mnt->mnt_namespace; 1181 ns = mnt->mnt_ns;
1182 if (!namespace || !namespace->root) 1182 if (!ns || !ns->root)
1183 continue; 1183 continue;
1184 get_namespace(namespace); 1184 get_mnt_ns(ns);
1185 1185
1186 spin_unlock(&vfsmount_lock); 1186 spin_unlock(&vfsmount_lock);
1187 down_write(&namespace_sem); 1187 down_write(&namespace_sem);
@@ -1189,7 +1189,7 @@ static void expire_mount_list(struct list_head *graveyard, struct list_head *mou
1189 up_write(&namespace_sem); 1189 up_write(&namespace_sem);
1190 release_mounts(&umounts); 1190 release_mounts(&umounts);
1191 mntput(mnt); 1191 mntput(mnt);
1192 put_namespace(namespace); 1192 put_mnt_ns(ns);
1193 spin_lock(&vfsmount_lock); 1193 spin_lock(&vfsmount_lock);
1194 } 1194 }
1195} 1195}
@@ -1439,14 +1439,15 @@ dput_out:
1439 * Allocate a new namespace structure and populate it with contents 1439 * Allocate a new namespace structure and populate it with contents
1440 * copied from the namespace of the passed in task structure. 1440 * copied from the namespace of the passed in task structure.
1441 */ 1441 */
1442struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs) 1442struct mnt_namespace *dup_mnt_ns(struct task_struct *tsk,
1443 struct fs_struct *fs)
1443{ 1444{
1444 struct namespace *namespace = tsk->nsproxy->namespace; 1445 struct mnt_namespace *mnt_ns = tsk->nsproxy->mnt_ns;
1445 struct namespace *new_ns; 1446 struct mnt_namespace *new_ns;
1446 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL; 1447 struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
1447 struct vfsmount *p, *q; 1448 struct vfsmount *p, *q;
1448 1449
1449 new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL); 1450 new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL);
1450 if (!new_ns) 1451 if (!new_ns)
1451 return NULL; 1452 return NULL;
1452 1453
@@ -1457,7 +1458,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1457 1458
1458 down_write(&namespace_sem); 1459 down_write(&namespace_sem);
1459 /* First pass: copy the tree topology */ 1460 /* First pass: copy the tree topology */
1460 new_ns->root = copy_tree(namespace->root, namespace->root->mnt_root, 1461 new_ns->root = copy_tree(mnt_ns->root, mnt_ns->root->mnt_root,
1461 CL_COPY_ALL | CL_EXPIRE); 1462 CL_COPY_ALL | CL_EXPIRE);
1462 if (!new_ns->root) { 1463 if (!new_ns->root) {
1463 up_write(&namespace_sem); 1464 up_write(&namespace_sem);
@@ -1473,10 +1474,10 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1473 * as belonging to new namespace. We have already acquired a private 1474 * as belonging to new namespace. We have already acquired a private
1474 * fs_struct, so tsk->fs->lock is not needed. 1475 * fs_struct, so tsk->fs->lock is not needed.
1475 */ 1476 */
1476 p = namespace->root; 1477 p = mnt_ns->root;
1477 q = new_ns->root; 1478 q = new_ns->root;
1478 while (p) { 1479 while (p) {
1479 q->mnt_namespace = new_ns; 1480 q->mnt_ns = new_ns;
1480 if (fs) { 1481 if (fs) {
1481 if (p == fs->rootmnt) { 1482 if (p == fs->rootmnt) {
1482 rootmnt = p; 1483 rootmnt = p;
@@ -1491,7 +1492,7 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1491 fs->altrootmnt = mntget(q); 1492 fs->altrootmnt = mntget(q);
1492 } 1493 }
1493 } 1494 }
1494 p = next_mnt(p, namespace->root); 1495 p = next_mnt(p, mnt_ns->root);
1495 q = next_mnt(q, new_ns->root); 1496 q = next_mnt(q, new_ns->root);
1496 } 1497 }
1497 up_write(&namespace_sem); 1498 up_write(&namespace_sem);
@@ -1506,16 +1507,16 @@ struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
1506 return new_ns; 1507 return new_ns;
1507} 1508}
1508 1509
1509int copy_namespace(int flags, struct task_struct *tsk) 1510int copy_mnt_ns(int flags, struct task_struct *tsk)
1510{ 1511{
1511 struct namespace *namespace = tsk->nsproxy->namespace; 1512 struct mnt_namespace *ns = tsk->nsproxy->mnt_ns;
1512 struct namespace *new_ns; 1513 struct mnt_namespace *new_ns;
1513 int err = 0; 1514 int err = 0;
1514 1515
1515 if (!namespace) 1516 if (!ns)
1516 return 0; 1517 return 0;
1517 1518
1518 get_namespace(namespace); 1519 get_mnt_ns(ns);
1519 1520
1520 if (!(flags & CLONE_NEWNS)) 1521 if (!(flags & CLONE_NEWNS))
1521 return 0; 1522 return 0;
@@ -1525,16 +1526,16 @@ int copy_namespace(int flags, struct task_struct *tsk)
1525 goto out; 1526 goto out;
1526 } 1527 }
1527 1528
1528 new_ns = dup_namespace(tsk, tsk->fs); 1529 new_ns = dup_mnt_ns(tsk, tsk->fs);
1529 if (!new_ns) { 1530 if (!new_ns) {
1530 err = -ENOMEM; 1531 err = -ENOMEM;
1531 goto out; 1532 goto out;
1532 } 1533 }
1533 1534
1534 tsk->nsproxy->namespace = new_ns; 1535 tsk->nsproxy->mnt_ns = new_ns;
1535 1536
1536out: 1537out:
1537 put_namespace(namespace); 1538 put_mnt_ns(ns);
1538 return err; 1539 return err;
1539} 1540}
1540 1541
@@ -1754,7 +1755,7 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1754 detach_mnt(user_nd.mnt, &root_parent); 1755 detach_mnt(user_nd.mnt, &root_parent);
1755 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */ 1756 attach_mnt(user_nd.mnt, &old_nd); /* mount old root on put_old */
1756 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */ 1757 attach_mnt(new_nd.mnt, &root_parent); /* mount new_root on / */
1757 touch_namespace(current->nsproxy->namespace); 1758 touch_mnt_namespace(current->nsproxy->mnt_ns);
1758 spin_unlock(&vfsmount_lock); 1759 spin_unlock(&vfsmount_lock);
1759 chroot_fs_refs(&user_nd, &new_nd); 1760 chroot_fs_refs(&user_nd, &new_nd);
1760 security_sb_post_pivotroot(&user_nd, &new_nd); 1761 security_sb_post_pivotroot(&user_nd, &new_nd);
@@ -1779,27 +1780,27 @@ out3:
1779static void __init init_mount_tree(void) 1780static void __init init_mount_tree(void)
1780{ 1781{
1781 struct vfsmount *mnt; 1782 struct vfsmount *mnt;
1782 struct namespace *namespace; 1783 struct mnt_namespace *ns;
1783 1784
1784 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL); 1785 mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
1785 if (IS_ERR(mnt)) 1786 if (IS_ERR(mnt))
1786 panic("Can't create rootfs"); 1787 panic("Can't create rootfs");
1787 namespace = kmalloc(sizeof(*namespace), GFP_KERNEL); 1788 ns = kmalloc(sizeof(*ns), GFP_KERNEL);
1788 if (!namespace) 1789 if (!ns)
1789 panic("Can't allocate initial namespace"); 1790 panic("Can't allocate initial namespace");
1790 atomic_set(&namespace->count, 1); 1791 atomic_set(&ns->count, 1);
1791 INIT_LIST_HEAD(&namespace->list); 1792 INIT_LIST_HEAD(&ns->list);
1792 init_waitqueue_head(&namespace->poll); 1793 init_waitqueue_head(&ns->poll);
1793 namespace->event = 0; 1794 ns->event = 0;
1794 list_add(&mnt->mnt_list, &namespace->list); 1795 list_add(&mnt->mnt_list, &ns->list);
1795 namespace->root = mnt; 1796 ns->root = mnt;
1796 mnt->mnt_namespace = namespace; 1797 mnt->mnt_ns = ns;
1797 1798
1798 init_task.nsproxy->namespace = namespace; 1799 init_task.nsproxy->mnt_ns = ns;
1799 get_namespace(namespace); 1800 get_mnt_ns(ns);
1800 1801
1801 set_fs_pwd(current->fs, namespace->root, namespace->root->mnt_root); 1802 set_fs_pwd(current->fs, ns->root, ns->root->mnt_root);
1802 set_fs_root(current->fs, namespace->root, namespace->root->mnt_root); 1803 set_fs_root(current->fs, ns->root, ns->root->mnt_root);
1803} 1804}
1804 1805
1805void __init mnt_init(unsigned long mempages) 1806void __init mnt_init(unsigned long mempages)
@@ -1860,11 +1861,11 @@ void __init mnt_init(unsigned long mempages)
1860 init_mount_tree(); 1861 init_mount_tree();
1861} 1862}
1862 1863
1863void __put_namespace(struct namespace *namespace) 1864void __put_mnt_ns(struct mnt_namespace *ns)
1864{ 1865{
1865 struct vfsmount *root = namespace->root; 1866 struct vfsmount *root = ns->root;
1866 LIST_HEAD(umount_list); 1867 LIST_HEAD(umount_list);
1867 namespace->root = NULL; 1868 ns->root = NULL;
1868 spin_unlock(&vfsmount_lock); 1869 spin_unlock(&vfsmount_lock);
1869 down_write(&namespace_sem); 1870 down_write(&namespace_sem);
1870 spin_lock(&vfsmount_lock); 1871 spin_lock(&vfsmount_lock);
@@ -1872,5 +1873,5 @@ void __put_namespace(struct namespace *namespace)
1872 spin_unlock(&vfsmount_lock); 1873 spin_unlock(&vfsmount_lock);
1873 up_write(&namespace_sem); 1874 up_write(&namespace_sem);
1874 release_mounts(&umount_list); 1875 release_mounts(&umount_list);
1875 kfree(namespace); 1876 kfree(ns);
1876} 1877}
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index 458b3b785194..73747772c3bb 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -402,7 +402,7 @@ static time_t ncp_obtain_mtime(struct dentry *dentry)
402 402
403static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir) 403static int ncp_readdir(struct file *filp, void *dirent, filldir_t filldir)
404{ 404{
405 struct dentry *dentry = filp->f_dentry; 405 struct dentry *dentry = filp->f_path.dentry;
406 struct inode *inode = dentry->d_inode; 406 struct inode *inode = dentry->d_inode;
407 struct page *page = NULL; 407 struct page *page = NULL;
408 struct ncp_server *server = NCP_SERVER(inode); 408 struct ncp_server *server = NCP_SERVER(inode);
@@ -554,7 +554,7 @@ static int
554ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir, 554ncp_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
555 struct ncp_cache_control *ctrl, struct ncp_entry_info *entry) 555 struct ncp_cache_control *ctrl, struct ncp_entry_info *entry)
556{ 556{
557 struct dentry *newdent, *dentry = filp->f_dentry; 557 struct dentry *newdent, *dentry = filp->f_path.dentry;
558 struct inode *newino, *inode = dentry->d_inode; 558 struct inode *newino, *inode = dentry->d_inode;
559 struct ncp_cache_control ctl = *ctrl; 559 struct ncp_cache_control ctl = *ctrl;
560 struct qstr qname; 560 struct qstr qname;
@@ -649,7 +649,7 @@ static void
649ncp_read_volume_list(struct file *filp, void *dirent, filldir_t filldir, 649ncp_read_volume_list(struct file *filp, void *dirent, filldir_t filldir,
650 struct ncp_cache_control *ctl) 650 struct ncp_cache_control *ctl)
651{ 651{
652 struct dentry *dentry = filp->f_dentry; 652 struct dentry *dentry = filp->f_path.dentry;
653 struct inode *inode = dentry->d_inode; 653 struct inode *inode = dentry->d_inode;
654 struct ncp_server *server = NCP_SERVER(inode); 654 struct ncp_server *server = NCP_SERVER(inode);
655 struct ncp_volume_info info; 655 struct ncp_volume_info info;
@@ -685,7 +685,7 @@ static void
685ncp_do_readdir(struct file *filp, void *dirent, filldir_t filldir, 685ncp_do_readdir(struct file *filp, void *dirent, filldir_t filldir,
686 struct ncp_cache_control *ctl) 686 struct ncp_cache_control *ctl)
687{ 687{
688 struct dentry *dentry = filp->f_dentry; 688 struct dentry *dentry = filp->f_path.dentry;
689 struct inode *dir = dentry->d_inode; 689 struct inode *dir = dentry->d_inode;
690 struct ncp_server *server = NCP_SERVER(dir); 690 struct ncp_server *server = NCP_SERVER(dir);
691 struct nw_search_sequence seq; 691 struct nw_search_sequence seq;
diff --git a/fs/ncpfs/file.c b/fs/ncpfs/file.c
index df37524b85db..b91fea03b1c3 100644
--- a/fs/ncpfs/file.c
+++ b/fs/ncpfs/file.c
@@ -101,7 +101,7 @@ out:
101static ssize_t 101static ssize_t
102ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 102ncp_file_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
103{ 103{
104 struct dentry *dentry = file->f_dentry; 104 struct dentry *dentry = file->f_path.dentry;
105 struct inode *inode = dentry->d_inode; 105 struct inode *inode = dentry->d_inode;
106 size_t already_read = 0; 106 size_t already_read = 0;
107 off_t pos; 107 off_t pos;
@@ -182,7 +182,7 @@ outrel:
182static ssize_t 182static ssize_t
183ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 183ncp_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
184{ 184{
185 struct dentry *dentry = file->f_dentry; 185 struct dentry *dentry = file->f_path.dentry;
186 struct inode *inode = dentry->d_inode; 186 struct inode *inode = dentry->d_inode;
187 size_t already_written = 0; 187 size_t already_written = 0;
188 off_t pos; 188 off_t pos;
diff --git a/fs/ncpfs/inode.c b/fs/ncpfs/inode.c
index fae53243bb92..47462ac94474 100644
--- a/fs/ncpfs/inode.c
+++ b/fs/ncpfs/inode.c
@@ -471,7 +471,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
471 if (!ncp_filp) 471 if (!ncp_filp)
472 goto out; 472 goto out;
473 error = -ENOTSOCK; 473 error = -ENOTSOCK;
474 sock_inode = ncp_filp->f_dentry->d_inode; 474 sock_inode = ncp_filp->f_path.dentry->d_inode;
475 if (!S_ISSOCK(sock_inode->i_mode)) 475 if (!S_ISSOCK(sock_inode->i_mode))
476 goto out_fput; 476 goto out_fput;
477 sock = SOCKET_I(sock_inode); 477 sock = SOCKET_I(sock_inode);
@@ -504,7 +504,7 @@ static int ncp_fill_super(struct super_block *sb, void *raw_data, int silent)
504 if (!server->info_filp) 504 if (!server->info_filp)
505 goto out_fput; 505 goto out_fput;
506 error = -ENOTSOCK; 506 error = -ENOTSOCK;
507 sock_inode = server->info_filp->f_dentry->d_inode; 507 sock_inode = server->info_filp->f_path.dentry->d_inode;
508 if (!S_ISSOCK(sock_inode->i_mode)) 508 if (!S_ISSOCK(sock_inode->i_mode))
509 goto out_fput2; 509 goto out_fput2;
510 info_sock = SOCKET_I(sock_inode); 510 info_sock = SOCKET_I(sock_inode);
diff --git a/fs/ncpfs/ioctl.c b/fs/ncpfs/ioctl.c
index 589d1eac55c1..8843a83d4ef0 100644
--- a/fs/ncpfs/ioctl.c
+++ b/fs/ncpfs/ioctl.c
@@ -35,7 +35,7 @@ static int
35ncp_get_fs_info(struct ncp_server * server, struct file *file, 35ncp_get_fs_info(struct ncp_server * server, struct file *file,
36 struct ncp_fs_info __user *arg) 36 struct ncp_fs_info __user *arg)
37{ 37{
38 struct inode *inode = file->f_dentry->d_inode; 38 struct inode *inode = file->f_path.dentry->d_inode;
39 struct ncp_fs_info info; 39 struct ncp_fs_info info;
40 40
41 if ((file_permission(file, MAY_WRITE) != 0) 41 if ((file_permission(file, MAY_WRITE) != 0)
@@ -65,7 +65,7 @@ static int
65ncp_get_fs_info_v2(struct ncp_server * server, struct file *file, 65ncp_get_fs_info_v2(struct ncp_server * server, struct file *file,
66 struct ncp_fs_info_v2 __user * arg) 66 struct ncp_fs_info_v2 __user * arg)
67{ 67{
68 struct inode *inode = file->f_dentry->d_inode; 68 struct inode *inode = file->f_path.dentry->d_inode;
69 struct ncp_fs_info_v2 info2; 69 struct ncp_fs_info_v2 info2;
70 70
71 if ((file_permission(file, MAY_WRITE) != 0) 71 if ((file_permission(file, MAY_WRITE) != 0)
@@ -136,7 +136,7 @@ static int
136ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file, 136ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file,
137 struct compat_ncp_fs_info_v2 __user * arg) 137 struct compat_ncp_fs_info_v2 __user * arg)
138{ 138{
139 struct inode *inode = file->f_dentry->d_inode; 139 struct inode *inode = file->f_path.dentry->d_inode;
140 struct compat_ncp_fs_info_v2 info2; 140 struct compat_ncp_fs_info_v2 info2;
141 141
142 if ((file_permission(file, MAY_WRITE) != 0) 142 if ((file_permission(file, MAY_WRITE) != 0)
@@ -824,7 +824,7 @@ outrel:
824#ifdef CONFIG_COMPAT 824#ifdef CONFIG_COMPAT
825long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 825long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
826{ 826{
827 struct inode *inode = file->f_dentry->d_inode; 827 struct inode *inode = file->f_path.dentry->d_inode;
828 int ret; 828 int ret;
829 829
830 lock_kernel(); 830 lock_kernel();
diff --git a/fs/ncpfs/mmap.c b/fs/ncpfs/mmap.c
index e7d5a3097fe6..70a69115500f 100644
--- a/fs/ncpfs/mmap.c
+++ b/fs/ncpfs/mmap.c
@@ -29,7 +29,7 @@ static struct page* ncp_file_mmap_nopage(struct vm_area_struct *area,
29 unsigned long address, int *type) 29 unsigned long address, int *type)
30{ 30{
31 struct file *file = area->vm_file; 31 struct file *file = area->vm_file;
32 struct dentry *dentry = file->f_dentry; 32 struct dentry *dentry = file->f_path.dentry;
33 struct inode *inode = dentry->d_inode; 33 struct inode *inode = dentry->d_inode;
34 struct page* page; 34 struct page* page;
35 char *pg_addr; 35 char *pg_addr;
@@ -106,7 +106,7 @@ static struct vm_operations_struct ncp_file_mmap =
106/* This is used for a general mmap of a ncp file */ 106/* This is used for a general mmap of a ncp file */
107int ncp_mmap(struct file *file, struct vm_area_struct *vma) 107int ncp_mmap(struct file *file, struct vm_area_struct *vma)
108{ 108{
109 struct inode *inode = file->f_dentry->d_inode; 109 struct inode *inode = file->f_path.dentry->d_inode;
110 110
111 DPRINTK("ncp_mmap: called\n"); 111 DPRINTK("ncp_mmap: called\n");
112 112
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index b34cd16f472f..dee3d6c0f194 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -172,7 +172,7 @@ static
172int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page) 172int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
173{ 173{
174 struct file *file = desc->file; 174 struct file *file = desc->file;
175 struct inode *inode = file->f_dentry->d_inode; 175 struct inode *inode = file->f_path.dentry->d_inode;
176 struct rpc_cred *cred = nfs_file_cred(file); 176 struct rpc_cred *cred = nfs_file_cred(file);
177 unsigned long timestamp; 177 unsigned long timestamp;
178 int error; 178 int error;
@@ -183,7 +183,7 @@ int nfs_readdir_filler(nfs_readdir_descriptor_t *desc, struct page *page)
183 183
184 again: 184 again:
185 timestamp = jiffies; 185 timestamp = jiffies;
186 error = NFS_PROTO(inode)->readdir(file->f_dentry, cred, desc->entry->cookie, page, 186 error = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, desc->entry->cookie, page,
187 NFS_SERVER(inode)->dtsize, desc->plus); 187 NFS_SERVER(inode)->dtsize, desc->plus);
188 if (error < 0) { 188 if (error < 0) {
189 /* We requested READDIRPLUS, but the server doesn't grok it */ 189 /* We requested READDIRPLUS, but the server doesn't grok it */
@@ -308,7 +308,7 @@ int find_dirent_index(nfs_readdir_descriptor_t *desc)
308static inline 308static inline
309int find_dirent_page(nfs_readdir_descriptor_t *desc) 309int find_dirent_page(nfs_readdir_descriptor_t *desc)
310{ 310{
311 struct inode *inode = desc->file->f_dentry->d_inode; 311 struct inode *inode = desc->file->f_path.dentry->d_inode;
312 struct page *page; 312 struct page *page;
313 int status; 313 int status;
314 314
@@ -464,7 +464,7 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
464 filldir_t filldir) 464 filldir_t filldir)
465{ 465{
466 struct file *file = desc->file; 466 struct file *file = desc->file;
467 struct inode *inode = file->f_dentry->d_inode; 467 struct inode *inode = file->f_path.dentry->d_inode;
468 struct rpc_cred *cred = nfs_file_cred(file); 468 struct rpc_cred *cred = nfs_file_cred(file);
469 struct page *page = NULL; 469 struct page *page = NULL;
470 int status; 470 int status;
@@ -477,7 +477,7 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
477 status = -ENOMEM; 477 status = -ENOMEM;
478 goto out; 478 goto out;
479 } 479 }
480 desc->error = NFS_PROTO(inode)->readdir(file->f_dentry, cred, *desc->dir_cookie, 480 desc->error = NFS_PROTO(inode)->readdir(file->f_path.dentry, cred, *desc->dir_cookie,
481 page, 481 page,
482 NFS_SERVER(inode)->dtsize, 482 NFS_SERVER(inode)->dtsize,
483 desc->plus); 483 desc->plus);
@@ -516,7 +516,7 @@ int uncached_readdir(nfs_readdir_descriptor_t *desc, void *dirent,
516 */ 516 */
517static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 517static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
518{ 518{
519 struct dentry *dentry = filp->f_dentry; 519 struct dentry *dentry = filp->f_path.dentry;
520 struct inode *inode = dentry->d_inode; 520 struct inode *inode = dentry->d_inode;
521 nfs_readdir_descriptor_t my_desc, 521 nfs_readdir_descriptor_t my_desc,
522 *desc = &my_desc; 522 *desc = &my_desc;
@@ -599,7 +599,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
599 599
600loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin) 600loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
601{ 601{
602 mutex_lock(&filp->f_dentry->d_inode->i_mutex); 602 mutex_lock(&filp->f_path.dentry->d_inode->i_mutex);
603 switch (origin) { 603 switch (origin) {
604 case 1: 604 case 1:
605 offset += filp->f_pos; 605 offset += filp->f_pos;
@@ -615,7 +615,7 @@ loff_t nfs_llseek_dir(struct file *filp, loff_t offset, int origin)
615 ((struct nfs_open_context *)filp->private_data)->dir_cookie = 0; 615 ((struct nfs_open_context *)filp->private_data)->dir_cookie = 0;
616 } 616 }
617out: 617out:
618 mutex_unlock(&filp->f_dentry->d_inode->i_mutex); 618 mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex);
619 return offset; 619 return offset;
620} 620}
621 621
@@ -1102,7 +1102,7 @@ no_open:
1102 1102
1103static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc) 1103static struct dentry *nfs_readdir_lookup(nfs_readdir_descriptor_t *desc)
1104{ 1104{
1105 struct dentry *parent = desc->file->f_dentry; 1105 struct dentry *parent = desc->file->f_path.dentry;
1106 struct inode *dir = parent->d_inode; 1106 struct inode *dir = parent->d_inode;
1107 struct nfs_entry *entry = desc->entry; 1107 struct nfs_entry *entry = desc->entry;
1108 struct dentry *dentry, *alias; 1108 struct dentry *dentry, *alias;
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index f9d678f4ae06..bd21d7fde650 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -116,7 +116,7 @@ static inline int put_dreq(struct nfs_direct_req *dreq)
116ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs) 116ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_t pos, unsigned long nr_segs)
117{ 117{
118 dprintk("NFS: nfs_direct_IO (%s) off/no(%Ld/%lu) EINVAL\n", 118 dprintk("NFS: nfs_direct_IO (%s) off/no(%Ld/%lu) EINVAL\n",
119 iocb->ki_filp->f_dentry->d_name.name, 119 iocb->ki_filp->f_path.dentry->d_name.name,
120 (long long) pos, nr_segs); 120 (long long) pos, nr_segs);
121 121
122 return -EINVAL; 122 return -EINVAL;
@@ -734,8 +734,8 @@ ssize_t nfs_file_direct_read(struct kiocb *iocb, const struct iovec *iov,
734 size_t count = iov[0].iov_len; 734 size_t count = iov[0].iov_len;
735 735
736 dprintk("nfs: direct read(%s/%s, %lu@%Ld)\n", 736 dprintk("nfs: direct read(%s/%s, %lu@%Ld)\n",
737 file->f_dentry->d_parent->d_name.name, 737 file->f_path.dentry->d_parent->d_name.name,
738 file->f_dentry->d_name.name, 738 file->f_path.dentry->d_name.name,
739 (unsigned long) count, (long long) pos); 739 (unsigned long) count, (long long) pos);
740 740
741 if (nr_segs != 1) 741 if (nr_segs != 1)
@@ -798,8 +798,8 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
798 size_t count = iov[0].iov_len; 798 size_t count = iov[0].iov_len;
799 799
800 dfprintk(VFS, "nfs: direct write(%s/%s, %lu@%Ld)\n", 800 dfprintk(VFS, "nfs: direct write(%s/%s, %lu@%Ld)\n",
801 file->f_dentry->d_parent->d_name.name, 801 file->f_path.dentry->d_parent->d_name.name,
802 file->f_dentry->d_name.name, 802 file->f_path.dentry->d_name.name,
803 (unsigned long) count, (long long) pos); 803 (unsigned long) count, (long long) pos);
804 804
805 if (nr_segs != 1) 805 if (nr_segs != 1)
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 8e28bffc35a0..0dd6be346aa7 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -176,7 +176,7 @@ static int
176nfs_file_flush(struct file *file, fl_owner_t id) 176nfs_file_flush(struct file *file, fl_owner_t id)
177{ 177{
178 struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data; 178 struct nfs_open_context *ctx = (struct nfs_open_context *)file->private_data;
179 struct inode *inode = file->f_dentry->d_inode; 179 struct inode *inode = file->f_path.dentry->d_inode;
180 int status; 180 int status;
181 181
182 dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino); 182 dfprintk(VFS, "nfs: flush(%s/%ld)\n", inode->i_sb->s_id, inode->i_ino);
@@ -201,7 +201,7 @@ static ssize_t
201nfs_file_read(struct kiocb *iocb, const struct iovec *iov, 201nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
202 unsigned long nr_segs, loff_t pos) 202 unsigned long nr_segs, loff_t pos)
203{ 203{
204 struct dentry * dentry = iocb->ki_filp->f_dentry; 204 struct dentry * dentry = iocb->ki_filp->f_path.dentry;
205 struct inode * inode = dentry->d_inode; 205 struct inode * inode = dentry->d_inode;
206 ssize_t result; 206 ssize_t result;
207 size_t count = iov_length(iov, nr_segs); 207 size_t count = iov_length(iov, nr_segs);
@@ -226,7 +226,7 @@ static ssize_t
226nfs_file_sendfile(struct file *filp, loff_t *ppos, size_t count, 226nfs_file_sendfile(struct file *filp, loff_t *ppos, size_t count,
227 read_actor_t actor, void *target) 227 read_actor_t actor, void *target)
228{ 228{
229 struct dentry *dentry = filp->f_dentry; 229 struct dentry *dentry = filp->f_path.dentry;
230 struct inode *inode = dentry->d_inode; 230 struct inode *inode = dentry->d_inode;
231 ssize_t res; 231 ssize_t res;
232 232
@@ -243,7 +243,7 @@ nfs_file_sendfile(struct file *filp, loff_t *ppos, size_t count,
243static int 243static int
244nfs_file_mmap(struct file * file, struct vm_area_struct * vma) 244nfs_file_mmap(struct file * file, struct vm_area_struct * vma)
245{ 245{
246 struct dentry *dentry = file->f_dentry; 246 struct dentry *dentry = file->f_path.dentry;
247 struct inode *inode = dentry->d_inode; 247 struct inode *inode = dentry->d_inode;
248 int status; 248 int status;
249 249
@@ -343,7 +343,7 @@ const struct address_space_operations nfs_file_aops = {
343static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov, 343static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
344 unsigned long nr_segs, loff_t pos) 344 unsigned long nr_segs, loff_t pos)
345{ 345{
346 struct dentry * dentry = iocb->ki_filp->f_dentry; 346 struct dentry * dentry = iocb->ki_filp->f_path.dentry;
347 struct inode * inode = dentry->d_inode; 347 struct inode * inode = dentry->d_inode;
348 ssize_t result; 348 ssize_t result;
349 size_t count = iov_length(iov, nr_segs); 349 size_t count = iov_length(iov, nr_segs);
@@ -535,8 +535,8 @@ static int nfs_lock(struct file *filp, int cmd, struct file_lock *fl)
535static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl) 535static int nfs_flock(struct file *filp, int cmd, struct file_lock *fl)
536{ 536{
537 dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n", 537 dprintk("NFS: nfs_flock(f=%s/%ld, t=%x, fl=%x)\n",
538 filp->f_dentry->d_inode->i_sb->s_id, 538 filp->f_path.dentry->d_inode->i_sb->s_id,
539 filp->f_dentry->d_inode->i_ino, 539 filp->f_path.dentry->d_inode->i_ino,
540 fl->fl_type, fl->fl_flags); 540 fl->fl_type, fl->fl_flags);
541 541
542 /* 542 /*
diff --git a/fs/nfs/getroot.c b/fs/nfs/getroot.c
index 20c6f39ea38a..8391bd7a83ce 100644
--- a/fs/nfs/getroot.c
+++ b/fs/nfs/getroot.c
@@ -31,7 +31,7 @@
31#include <linux/nfs_idmap.h> 31#include <linux/nfs_idmap.h>
32#include <linux/vfs.h> 32#include <linux/vfs.h>
33#include <linux/namei.h> 33#include <linux/namei.h>
34#include <linux/namespace.h> 34#include <linux/mnt_namespace.h>
35#include <linux/security.h> 35#include <linux/security.h>
36 36
37#include <asm/system.h> 37#include <asm/system.h>
diff --git a/fs/nfs/idmap.c b/fs/nfs/idmap.c
index 82ad7110a1c0..9d4a6b2d1996 100644
--- a/fs/nfs/idmap.c
+++ b/fs/nfs/idmap.c
@@ -377,7 +377,7 @@ idmap_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
377static ssize_t 377static ssize_t
378idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen) 378idmap_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
379{ 379{
380 struct rpc_inode *rpci = RPC_I(filp->f_dentry->d_inode); 380 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode);
381 struct idmap *idmap = (struct idmap *)rpci->private; 381 struct idmap *idmap = (struct idmap *)rpci->private;
382 struct idmap_msg im_in, *im = &idmap->idmap_im; 382 struct idmap_msg im_in, *im = &idmap->idmap_im;
383 struct idmap_hashtable *h; 383 struct idmap_hashtable *h;
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 36680d1061b0..63e470279309 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -496,7 +496,7 @@ void put_nfs_open_context(struct nfs_open_context *ctx)
496 */ 496 */
497static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx) 497static void nfs_file_set_open_context(struct file *filp, struct nfs_open_context *ctx)
498{ 498{
499 struct inode *inode = filp->f_dentry->d_inode; 499 struct inode *inode = filp->f_path.dentry->d_inode;
500 struct nfs_inode *nfsi = NFS_I(inode); 500 struct nfs_inode *nfsi = NFS_I(inode);
501 501
502 filp->private_data = get_nfs_open_context(ctx); 502 filp->private_data = get_nfs_open_context(ctx);
@@ -528,7 +528,7 @@ struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_c
528 528
529static void nfs_file_clear_open_context(struct file *filp) 529static void nfs_file_clear_open_context(struct file *filp)
530{ 530{
531 struct inode *inode = filp->f_dentry->d_inode; 531 struct inode *inode = filp->f_path.dentry->d_inode;
532 struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data; 532 struct nfs_open_context *ctx = (struct nfs_open_context *)filp->private_data;
533 533
534 if (ctx) { 534 if (ctx) {
@@ -551,7 +551,7 @@ int nfs_open(struct inode *inode, struct file *filp)
551 cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0); 551 cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0);
552 if (IS_ERR(cred)) 552 if (IS_ERR(cred))
553 return PTR_ERR(cred); 553 return PTR_ERR(cred);
554 ctx = alloc_nfs_open_context(filp->f_vfsmnt, filp->f_dentry, cred); 554 ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred);
555 put_rpccred(cred); 555 put_rpccred(cred);
556 if (ctx == NULL) 556 if (ctx == NULL)
557 return -ENOMEM; 557 return -ENOMEM;
diff --git a/fs/nfs/nfs3proc.c b/fs/nfs/nfs3proc.c
index 510ae524f3fd..acd8fe9762d3 100644
--- a/fs/nfs/nfs3proc.c
+++ b/fs/nfs/nfs3proc.c
@@ -841,7 +841,7 @@ static void nfs3_proc_commit_setup(struct nfs_write_data *data, int how)
841static int 841static int
842nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl) 842nfs3_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
843{ 843{
844 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl); 844 return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
845} 845}
846 846
847const struct nfs_rpc_ops nfs_v3_clientops = { 847const struct nfs_rpc_ops nfs_v3_clientops = {
diff --git a/fs/nfs/proc.c b/fs/nfs/proc.c
index 10f5e80ca157..560536ad74a4 100644
--- a/fs/nfs/proc.c
+++ b/fs/nfs/proc.c
@@ -651,7 +651,7 @@ nfs_proc_commit_setup(struct nfs_write_data *data, int how)
651static int 651static int
652nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl) 652nfs_proc_lock(struct file *filp, int cmd, struct file_lock *fl)
653{ 653{
654 return nlmclnt_proc(filp->f_dentry->d_inode, cmd, fl); 654 return nlmclnt_proc(filp->f_path.dentry->d_inode, cmd, fl);
655} 655}
656 656
657 657
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 594eb16879ef..345492e78643 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -754,8 +754,8 @@ int nfs_updatepage(struct file *file, struct page *page,
754 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE); 754 nfs_inc_stats(inode, NFSIOS_VFSUPDATEPAGE);
755 755
756 dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n", 756 dprintk("NFS: nfs_updatepage(%s/%s %d@%Ld)\n",
757 file->f_dentry->d_parent->d_name.name, 757 file->f_path.dentry->d_parent->d_name.name,
758 file->f_dentry->d_name.name, count, 758 file->f_path.dentry->d_name.name, count,
759 (long long)(page_offset(page) +offset)); 759 (long long)(page_offset(page) +offset));
760 760
761 /* If we're not using byte range locks, and we know the page 761 /* If we're not using byte range locks, and we know the page
diff --git a/fs/nfsd/nfs2acl.c b/fs/nfsd/nfs2acl.c
index e3eca0816986..edde5dc5f796 100644
--- a/fs/nfsd/nfs2acl.c
+++ b/fs/nfsd/nfs2acl.c
@@ -222,12 +222,10 @@ static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
222{ 222{
223 struct dentry *dentry = resp->fh.fh_dentry; 223 struct dentry *dentry = resp->fh.fh_dentry;
224 struct inode *inode = dentry->d_inode; 224 struct inode *inode = dentry->d_inode;
225 int w = nfsacl_size(
226 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
227 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
228 struct kvec *head = rqstp->rq_res.head; 225 struct kvec *head = rqstp->rq_res.head;
229 unsigned int base; 226 unsigned int base;
230 int n; 227 int n;
228 int w;
231 229
232 if (dentry == NULL || dentry->d_inode == NULL) 230 if (dentry == NULL || dentry->d_inode == NULL)
233 return 0; 231 return 0;
@@ -239,7 +237,9 @@ static int nfsaclsvc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
239 return 0; 237 return 0;
240 base = (char *)p - (char *)head->iov_base; 238 base = (char *)p - (char *)head->iov_base;
241 239
242 rqstp->rq_res.page_len = w; 240 rqstp->rq_res.page_len = w = nfsacl_size(
241 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
242 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
243 while (w > 0) { 243 while (w > 0) {
244 if (!rqstp->rq_respages[rqstp->rq_resused++]) 244 if (!rqstp->rq_respages[rqstp->rq_resused++])
245 return 0; 245 return 0;
diff --git a/fs/nfsd/nfs3acl.c b/fs/nfsd/nfs3acl.c
index fcad2895ddb0..3e3f2de82c36 100644
--- a/fs/nfsd/nfs3acl.c
+++ b/fs/nfsd/nfs3acl.c
@@ -171,19 +171,19 @@ static int nfs3svc_encode_getaclres(struct svc_rqst *rqstp, __be32 *p,
171 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh); 171 p = nfs3svc_encode_post_op_attr(rqstp, p, &resp->fh);
172 if (resp->status == 0 && dentry && dentry->d_inode) { 172 if (resp->status == 0 && dentry && dentry->d_inode) {
173 struct inode *inode = dentry->d_inode; 173 struct inode *inode = dentry->d_inode;
174 int w = nfsacl_size(
175 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
176 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
177 struct kvec *head = rqstp->rq_res.head; 174 struct kvec *head = rqstp->rq_res.head;
178 unsigned int base; 175 unsigned int base;
179 int n; 176 int n;
177 int w;
180 178
181 *p++ = htonl(resp->mask); 179 *p++ = htonl(resp->mask);
182 if (!xdr_ressize_check(rqstp, p)) 180 if (!xdr_ressize_check(rqstp, p))
183 return 0; 181 return 0;
184 base = (char *)p - (char *)head->iov_base; 182 base = (char *)p - (char *)head->iov_base;
185 183
186 rqstp->rq_res.page_len = w; 184 rqstp->rq_res.page_len = w = nfsacl_size(
185 (resp->mask & NFS_ACL) ? resp->acl_access : NULL,
186 (resp->mask & NFS_DFACL) ? resp->acl_default : NULL);
187 while (w > 0) { 187 while (w > 0) {
188 if (!rqstp->rq_respages[rqstp->rq_resused++]) 188 if (!rqstp->rq_respages[rqstp->rq_resused++])
189 return 0; 189 return 0;
diff --git a/fs/nfsd/nfs4recover.c b/fs/nfsd/nfs4recover.c
index 81b8565d3837..c7774e3a9469 100644
--- a/fs/nfsd/nfs4recover.c
+++ b/fs/nfsd/nfs4recover.c
@@ -259,7 +259,7 @@ nfsd4_remove_clid_file(struct dentry *dir, struct dentry *dentry)
259 printk("nfsd4: non-file found in client recovery directory\n"); 259 printk("nfsd4: non-file found in client recovery directory\n");
260 return -EINVAL; 260 return -EINVAL;
261 } 261 }
262 mutex_lock(&dir->d_inode->i_mutex); 262 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_PARENT);
263 status = vfs_unlink(dir->d_inode, dentry); 263 status = vfs_unlink(dir->d_inode, dentry);
264 mutex_unlock(&dir->d_inode->i_mutex); 264 mutex_unlock(&dir->d_inode->i_mutex);
265 return status; 265 return status;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 640c92b2a9f7..b7179bd45a1e 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1310,7 +1310,7 @@ static inline void
1310nfs4_file_downgrade(struct file *filp, unsigned int share_access) 1310nfs4_file_downgrade(struct file *filp, unsigned int share_access)
1311{ 1311{
1312 if (share_access & NFS4_SHARE_ACCESS_WRITE) { 1312 if (share_access & NFS4_SHARE_ACCESS_WRITE) {
1313 put_write_access(filp->f_dentry->d_inode); 1313 put_write_access(filp->f_path.dentry->d_inode);
1314 filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE; 1314 filp->f_mode = (filp->f_mode | FMODE_READ) & ~FMODE_WRITE;
1315 } 1315 }
1316} 1316}
@@ -1623,7 +1623,7 @@ static __be32
1623nfs4_upgrade_open(struct svc_rqst *rqstp, struct svc_fh *cur_fh, struct nfs4_stateid *stp, struct nfsd4_open *open) 1623nfs4_upgrade_open(struct svc_rqst *rqstp, struct svc_fh *cur_fh, struct nfs4_stateid *stp, struct nfsd4_open *open)
1624{ 1624{
1625 struct file *filp = stp->st_vfs_file; 1625 struct file *filp = stp->st_vfs_file;
1626 struct inode *inode = filp->f_dentry->d_inode; 1626 struct inode *inode = filp->f_path.dentry->d_inode;
1627 unsigned int share_access, new_writer; 1627 unsigned int share_access, new_writer;
1628 __be32 status; 1628 __be32 status;
1629 1629
@@ -1965,7 +1965,7 @@ search_close_lru(u32 st_id, int flags)
1965static inline int 1965static inline int
1966nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp) 1966nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
1967{ 1967{
1968 return fhp->fh_dentry->d_inode != stp->st_vfs_file->f_dentry->d_inode; 1968 return fhp->fh_dentry->d_inode != stp->st_vfs_file->f_path.dentry->d_inode;
1969} 1969}
1970 1970
1971static int 1971static int
@@ -2862,7 +2862,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lock
2862 * only the dentry:inode set. 2862 * only the dentry:inode set.
2863 */ 2863 */
2864 memset(&file, 0, sizeof (struct file)); 2864 memset(&file, 0, sizeof (struct file));
2865 file.f_dentry = current_fh->fh_dentry; 2865 file.f_path.dentry = current_fh->fh_dentry;
2866 2866
2867 status = nfs_ok; 2867 status = nfs_ok;
2868 if (posix_test_lock(&file, &file_lock, &conflock)) { 2868 if (posix_test_lock(&file, &file_lock, &conflock)) {
@@ -2952,7 +2952,7 @@ static int
2952check_for_locks(struct file *filp, struct nfs4_stateowner *lowner) 2952check_for_locks(struct file *filp, struct nfs4_stateowner *lowner)
2953{ 2953{
2954 struct file_lock **flpp; 2954 struct file_lock **flpp;
2955 struct inode *inode = filp->f_dentry->d_inode; 2955 struct inode *inode = filp->f_path.dentry->d_inode;
2956 int status = 0; 2956 int status = 0;
2957 2957
2958 lock_kernel(); 2958 lock_kernel();
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index 6100bbe27432..f90d70475854 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -66,14 +66,13 @@ nfsd_cache_init(void)
66 printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n", 66 printk (KERN_ERR "nfsd: cannot allocate all %d cache entries, only got %d\n",
67 CACHESIZE, CACHESIZE-i); 67 CACHESIZE, CACHESIZE-i);
68 68
69 hash_list = kmalloc (HASHSIZE * sizeof(struct hlist_head), GFP_KERNEL); 69 hash_list = kcalloc (HASHSIZE, sizeof(struct hlist_head), GFP_KERNEL);
70 if (!hash_list) { 70 if (!hash_list) {
71 nfsd_cache_shutdown(); 71 nfsd_cache_shutdown();
72 printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n", 72 printk (KERN_ERR "nfsd: cannot allocate %Zd bytes for hash list\n",
73 HASHSIZE * sizeof(struct hlist_head)); 73 HASHSIZE * sizeof(struct hlist_head));
74 return; 74 return;
75 } 75 }
76 memset(hash_list, 0, HASHSIZE * sizeof(struct hlist_head));
77 76
78 cache_disabled = 0; 77 cache_disabled = 0;
79} 78}
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 39aed901514b..eedf2e3990a9 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -111,7 +111,7 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
111 111
112static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 112static ssize_t nfsctl_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
113{ 113{
114 ino_t ino = file->f_dentry->d_inode->i_ino; 114 ino_t ino = file->f_path.dentry->d_inode->i_ino;
115 char *data; 115 char *data;
116 ssize_t rv; 116 ssize_t rv;
117 117
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index bb4d926e4487..4883d7586229 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -736,10 +736,10 @@ static int
736nfsd_sync(struct file *filp) 736nfsd_sync(struct file *filp)
737{ 737{
738 int err; 738 int err;
739 struct inode *inode = filp->f_dentry->d_inode; 739 struct inode *inode = filp->f_path.dentry->d_inode;
740 dprintk("nfsd: sync file %s\n", filp->f_dentry->d_name.name); 740 dprintk("nfsd: sync file %s\n", filp->f_path.dentry->d_name.name);
741 mutex_lock(&inode->i_mutex); 741 mutex_lock(&inode->i_mutex);
742 err=nfsd_dosync(filp, filp->f_dentry, filp->f_op); 742 err=nfsd_dosync(filp, filp->f_path.dentry, filp->f_op);
743 mutex_unlock(&inode->i_mutex); 743 mutex_unlock(&inode->i_mutex);
744 744
745 return err; 745 return err;
@@ -845,7 +845,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
845 int host_err; 845 int host_err;
846 846
847 err = nfserr_perm; 847 err = nfserr_perm;
848 inode = file->f_dentry->d_inode; 848 inode = file->f_path.dentry->d_inode;
849#ifdef MSNFS 849#ifdef MSNFS
850 if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) && 850 if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
851 (!lock_may_read(inode, offset, *count))) 851 (!lock_may_read(inode, offset, *count)))
@@ -883,7 +883,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
883 nfsdstats.io_read += host_err; 883 nfsdstats.io_read += host_err;
884 *count = host_err; 884 *count = host_err;
885 err = 0; 885 err = 0;
886 fsnotify_access(file->f_dentry); 886 fsnotify_access(file->f_path.dentry);
887 } else 887 } else
888 err = nfserrno(host_err); 888 err = nfserrno(host_err);
889out: 889out:
@@ -917,11 +917,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
917 err = nfserr_perm; 917 err = nfserr_perm;
918 918
919 if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) && 919 if ((fhp->fh_export->ex_flags & NFSEXP_MSNFS) &&
920 (!lock_may_write(file->f_dentry->d_inode, offset, cnt))) 920 (!lock_may_write(file->f_path.dentry->d_inode, offset, cnt)))
921 goto out; 921 goto out;
922#endif 922#endif
923 923
924 dentry = file->f_dentry; 924 dentry = file->f_path.dentry;
925 inode = dentry->d_inode; 925 inode = dentry->d_inode;
926 exp = fhp->fh_export; 926 exp = fhp->fh_export;
927 927
@@ -950,7 +950,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
950 set_fs(oldfs); 950 set_fs(oldfs);
951 if (host_err >= 0) { 951 if (host_err >= 0) {
952 nfsdstats.io_write += cnt; 952 nfsdstats.io_write += cnt;
953 fsnotify_modify(file->f_dentry); 953 fsnotify_modify(file->f_path.dentry);
954 } 954 }
955 955
956 /* clear setuid/setgid flag after write */ 956 /* clear setuid/setgid flag after write */
@@ -1885,28 +1885,27 @@ nfsd_racache_init(int cache_size)
1885 return 0; 1885 return 0;
1886 if (cache_size < 2*RAPARM_HASH_SIZE) 1886 if (cache_size < 2*RAPARM_HASH_SIZE)
1887 cache_size = 2*RAPARM_HASH_SIZE; 1887 cache_size = 2*RAPARM_HASH_SIZE;
1888 raparml = kmalloc(sizeof(struct raparms) * cache_size, GFP_KERNEL); 1888 raparml = kcalloc(cache_size, sizeof(struct raparms), GFP_KERNEL);
1889 1889
1890 if (raparml != NULL) { 1890 if (!raparml) {
1891 dprintk("nfsd: allocating %d readahead buffers.\n",
1892 cache_size);
1893 for (i = 0 ; i < RAPARM_HASH_SIZE ; i++) {
1894 raparm_hash[i].pb_head = NULL;
1895 spin_lock_init(&raparm_hash[i].pb_lock);
1896 }
1897 nperbucket = cache_size >> RAPARM_HASH_BITS;
1898 memset(raparml, 0, sizeof(struct raparms) * cache_size);
1899 for (i = 0; i < cache_size - 1; i++) {
1900 if (i % nperbucket == 0)
1901 raparm_hash[j++].pb_head = raparml + i;
1902 if (i % nperbucket < nperbucket-1)
1903 raparml[i].p_next = raparml + i + 1;
1904 }
1905 } else {
1906 printk(KERN_WARNING 1891 printk(KERN_WARNING
1907 "nfsd: Could not allocate memory read-ahead cache.\n"); 1892 "nfsd: Could not allocate memory read-ahead cache.\n");
1908 return -ENOMEM; 1893 return -ENOMEM;
1909 } 1894 }
1895
1896 dprintk("nfsd: allocating %d readahead buffers.\n", cache_size);
1897 for (i = 0 ; i < RAPARM_HASH_SIZE ; i++) {
1898 raparm_hash[i].pb_head = NULL;
1899 spin_lock_init(&raparm_hash[i].pb_lock);
1900 }
1901 nperbucket = cache_size >> RAPARM_HASH_BITS;
1902 for (i = 0; i < cache_size - 1; i++) {
1903 if (i % nperbucket == 0)
1904 raparm_hash[j++].pb_head = raparml + i;
1905 if (i % nperbucket < nperbucket-1)
1906 raparml[i].p_next = raparml + i + 1;
1907 }
1908
1910 nfsdstats.ra_size = cache_size; 1909 nfsdstats.ra_size = cache_size;
1911 return 0; 1910 return 0;
1912} 1911}
diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
index 85c36b8ca452..8296c29ae3b8 100644
--- a/fs/ntfs/dir.c
+++ b/fs/ntfs/dir.c
@@ -1101,7 +1101,7 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
1101{ 1101{
1102 s64 ia_pos, ia_start, prev_ia_pos, bmp_pos; 1102 s64 ia_pos, ia_start, prev_ia_pos, bmp_pos;
1103 loff_t fpos, i_size; 1103 loff_t fpos, i_size;
1104 struct inode *bmp_vi, *vdir = filp->f_dentry->d_inode; 1104 struct inode *bmp_vi, *vdir = filp->f_path.dentry->d_inode;
1105 struct super_block *sb = vdir->i_sb; 1105 struct super_block *sb = vdir->i_sb;
1106 ntfs_inode *ndir = NTFS_I(vdir); 1106 ntfs_inode *ndir = NTFS_I(vdir);
1107 ntfs_volume *vol = NTFS_SB(sb); 1107 ntfs_volume *vol = NTFS_SB(sb);
@@ -1136,9 +1136,9 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
1136 if (fpos == 1) { 1136 if (fpos == 1) {
1137 ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, " 1137 ntfs_debug("Calling filldir for .. with len 2, fpos 0x1, "
1138 "inode 0x%lx, DT_DIR.", 1138 "inode 0x%lx, DT_DIR.",
1139 (unsigned long)parent_ino(filp->f_dentry)); 1139 (unsigned long)parent_ino(filp->f_path.dentry));
1140 rc = filldir(dirent, "..", 2, fpos, 1140 rc = filldir(dirent, "..", 2, fpos,
1141 parent_ino(filp->f_dentry), DT_DIR); 1141 parent_ino(filp->f_path.dentry), DT_DIR);
1142 if (rc) 1142 if (rc)
1143 goto done; 1143 goto done;
1144 fpos++; 1144 fpos++;
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index ae2fe0016d2c..076c9420c257 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -2162,7 +2162,7 @@ static ssize_t ntfs_file_aio_write_nolock(struct kiocb *iocb,
2162 goto out; 2162 goto out;
2163 if (!count) 2163 if (!count)
2164 goto out; 2164 goto out;
2165 err = remove_suid(file->f_dentry); 2165 err = remove_suid(file->f_path.dentry);
2166 if (err) 2166 if (err)
2167 goto out; 2167 goto out;
2168 file_update_time(file); 2168 file_update_time(file);
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index 2f7268e81520..ef6cd30108a9 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -595,7 +595,7 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
595 ssize_t bytes, 595 ssize_t bytes,
596 void *private) 596 void *private)
597{ 597{
598 struct inode *inode = iocb->ki_filp->f_dentry->d_inode; 598 struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
599 599
600 /* this io's submitter should not have unlocked this before we could */ 600 /* this io's submitter should not have unlocked this before we could */
601 BUG_ON(!ocfs2_iocb_is_rw_locked(iocb)); 601 BUG_ON(!ocfs2_iocb_is_rw_locked(iocb));
@@ -611,7 +611,7 @@ static ssize_t ocfs2_direct_IO(int rw,
611 unsigned long nr_segs) 611 unsigned long nr_segs)
612{ 612{
613 struct file *file = iocb->ki_filp; 613 struct file *file = iocb->ki_filp;
614 struct inode *inode = file->f_dentry->d_inode->i_mapping->host; 614 struct inode *inode = file->f_path.dentry->d_inode->i_mapping->host;
615 int ret; 615 int ret;
616 616
617 mlog_entry_void(); 617 mlog_entry_void();
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c
index d11753c50bc1..357f1d551771 100644
--- a/fs/ocfs2/cluster/nodemanager.c
+++ b/fs/ocfs2/cluster/nodemanager.c
@@ -35,7 +35,7 @@
35/* for now we operate under the assertion that there can be only one 35/* for now we operate under the assertion that there can be only one
36 * cluster active at a time. Changing this will require trickling 36 * cluster active at a time. Changing this will require trickling
37 * cluster references throughout where nodes are looked up */ 37 * cluster references throughout where nodes are looked up */
38static struct o2nm_cluster *o2nm_single_cluster = NULL; 38struct o2nm_cluster *o2nm_single_cluster = NULL;
39 39
40#define OCFS2_MAX_HB_CTL_PATH 256 40#define OCFS2_MAX_HB_CTL_PATH 256
41static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl"; 41static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl";
@@ -97,17 +97,6 @@ const char *o2nm_get_hb_ctl_path(void)
97} 97}
98EXPORT_SYMBOL_GPL(o2nm_get_hb_ctl_path); 98EXPORT_SYMBOL_GPL(o2nm_get_hb_ctl_path);
99 99
100struct o2nm_cluster {
101 struct config_group cl_group;
102 unsigned cl_has_local:1;
103 u8 cl_local_node;
104 rwlock_t cl_nodes_lock;
105 struct o2nm_node *cl_nodes[O2NM_MAX_NODES];
106 struct rb_root cl_node_ip_tree;
107 /* this bitmap is part of a hack for disk bitmap.. will go eventually. - zab */
108 unsigned long cl_nodes_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
109};
110
111struct o2nm_node *o2nm_get_node_by_num(u8 node_num) 100struct o2nm_node *o2nm_get_node_by_num(u8 node_num)
112{ 101{
113 struct o2nm_node *node = NULL; 102 struct o2nm_node *node = NULL;
@@ -543,6 +532,179 @@ static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
543} 532}
544#endif 533#endif
545 534
535struct o2nm_cluster_attribute {
536 struct configfs_attribute attr;
537 ssize_t (*show)(struct o2nm_cluster *, char *);
538 ssize_t (*store)(struct o2nm_cluster *, const char *, size_t);
539};
540
541static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
542 unsigned int *val)
543{
544 unsigned long tmp;
545 char *p = (char *)page;
546
547 tmp = simple_strtoul(p, &p, 0);
548 if (!p || (*p && (*p != '\n')))
549 return -EINVAL;
550
551 if (tmp == 0)
552 return -EINVAL;
553 if (tmp >= (u32)-1)
554 return -ERANGE;
555
556 *val = tmp;
557
558 return count;
559}
560
561static ssize_t o2nm_cluster_attr_idle_timeout_ms_read(
562 struct o2nm_cluster *cluster, char *page)
563{
564 return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms);
565}
566
567static ssize_t o2nm_cluster_attr_idle_timeout_ms_write(
568 struct o2nm_cluster *cluster, const char *page, size_t count)
569{
570 ssize_t ret;
571 unsigned int val;
572
573 ret = o2nm_cluster_attr_write(page, count, &val);
574
575 if (ret > 0) {
576 if (cluster->cl_idle_timeout_ms != val
577 && o2net_num_connected_peers()) {
578 mlog(ML_NOTICE,
579 "o2net: cannot change idle timeout after "
580 "the first peer has agreed to it."
581 " %d connected peers\n",
582 o2net_num_connected_peers());
583 ret = -EINVAL;
584 } else if (val <= cluster->cl_keepalive_delay_ms) {
585 mlog(ML_NOTICE, "o2net: idle timeout must be larger "
586 "than keepalive delay\n");
587 ret = -EINVAL;
588 } else {
589 cluster->cl_idle_timeout_ms = val;
590 }
591 }
592
593 return ret;
594}
595
596static ssize_t o2nm_cluster_attr_keepalive_delay_ms_read(
597 struct o2nm_cluster *cluster, char *page)
598{
599 return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms);
600}
601
602static ssize_t o2nm_cluster_attr_keepalive_delay_ms_write(
603 struct o2nm_cluster *cluster, const char *page, size_t count)
604{
605 ssize_t ret;
606 unsigned int val;
607
608 ret = o2nm_cluster_attr_write(page, count, &val);
609
610 if (ret > 0) {
611 if (cluster->cl_keepalive_delay_ms != val
612 && o2net_num_connected_peers()) {
613 mlog(ML_NOTICE,
614 "o2net: cannot change keepalive delay after"
615 " the first peer has agreed to it."
616 " %d connected peers\n",
617 o2net_num_connected_peers());
618 ret = -EINVAL;
619 } else if (val >= cluster->cl_idle_timeout_ms) {
620 mlog(ML_NOTICE, "o2net: keepalive delay must be "
621 "smaller than idle timeout\n");
622 ret = -EINVAL;
623 } else {
624 cluster->cl_keepalive_delay_ms = val;
625 }
626 }
627
628 return ret;
629}
630
631static ssize_t o2nm_cluster_attr_reconnect_delay_ms_read(
632 struct o2nm_cluster *cluster, char *page)
633{
634 return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms);
635}
636
637static ssize_t o2nm_cluster_attr_reconnect_delay_ms_write(
638 struct o2nm_cluster *cluster, const char *page, size_t count)
639{
640 return o2nm_cluster_attr_write(page, count,
641 &cluster->cl_reconnect_delay_ms);
642}
643static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = {
644 .attr = { .ca_owner = THIS_MODULE,
645 .ca_name = "idle_timeout_ms",
646 .ca_mode = S_IRUGO | S_IWUSR },
647 .show = o2nm_cluster_attr_idle_timeout_ms_read,
648 .store = o2nm_cluster_attr_idle_timeout_ms_write,
649};
650
651static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms = {
652 .attr = { .ca_owner = THIS_MODULE,
653 .ca_name = "keepalive_delay_ms",
654 .ca_mode = S_IRUGO | S_IWUSR },
655 .show = o2nm_cluster_attr_keepalive_delay_ms_read,
656 .store = o2nm_cluster_attr_keepalive_delay_ms_write,
657};
658
659static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms = {
660 .attr = { .ca_owner = THIS_MODULE,
661 .ca_name = "reconnect_delay_ms",
662 .ca_mode = S_IRUGO | S_IWUSR },
663 .show = o2nm_cluster_attr_reconnect_delay_ms_read,
664 .store = o2nm_cluster_attr_reconnect_delay_ms_write,
665};
666
667static struct configfs_attribute *o2nm_cluster_attrs[] = {
668 &o2nm_cluster_attr_idle_timeout_ms.attr,
669 &o2nm_cluster_attr_keepalive_delay_ms.attr,
670 &o2nm_cluster_attr_reconnect_delay_ms.attr,
671 NULL,
672};
673static ssize_t o2nm_cluster_show(struct config_item *item,
674 struct configfs_attribute *attr,
675 char *page)
676{
677 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
678 struct o2nm_cluster_attribute *o2nm_cluster_attr =
679 container_of(attr, struct o2nm_cluster_attribute, attr);
680 ssize_t ret = 0;
681
682 if (o2nm_cluster_attr->show)
683 ret = o2nm_cluster_attr->show(cluster, page);
684 return ret;
685}
686
687static ssize_t o2nm_cluster_store(struct config_item *item,
688 struct configfs_attribute *attr,
689 const char *page, size_t count)
690{
691 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
692 struct o2nm_cluster_attribute *o2nm_cluster_attr =
693 container_of(attr, struct o2nm_cluster_attribute, attr);
694 ssize_t ret;
695
696 if (o2nm_cluster_attr->store == NULL) {
697 ret = -EINVAL;
698 goto out;
699 }
700
701 ret = o2nm_cluster_attr->store(cluster, page, count);
702 if (ret < count)
703 goto out;
704out:
705 return ret;
706}
707
546static struct config_item *o2nm_node_group_make_item(struct config_group *group, 708static struct config_item *o2nm_node_group_make_item(struct config_group *group,
547 const char *name) 709 const char *name)
548{ 710{
@@ -624,10 +786,13 @@ static void o2nm_cluster_release(struct config_item *item)
624 786
625static struct configfs_item_operations o2nm_cluster_item_ops = { 787static struct configfs_item_operations o2nm_cluster_item_ops = {
626 .release = o2nm_cluster_release, 788 .release = o2nm_cluster_release,
789 .show_attribute = o2nm_cluster_show,
790 .store_attribute = o2nm_cluster_store,
627}; 791};
628 792
629static struct config_item_type o2nm_cluster_type = { 793static struct config_item_type o2nm_cluster_type = {
630 .ct_item_ops = &o2nm_cluster_item_ops, 794 .ct_item_ops = &o2nm_cluster_item_ops,
795 .ct_attrs = o2nm_cluster_attrs,
631 .ct_owner = THIS_MODULE, 796 .ct_owner = THIS_MODULE,
632}; 797};
633 798
@@ -678,6 +843,9 @@ static struct config_group *o2nm_cluster_group_make_group(struct config_group *g
678 cluster->cl_group.default_groups[2] = NULL; 843 cluster->cl_group.default_groups[2] = NULL;
679 rwlock_init(&cluster->cl_nodes_lock); 844 rwlock_init(&cluster->cl_nodes_lock);
680 cluster->cl_node_ip_tree = RB_ROOT; 845 cluster->cl_node_ip_tree = RB_ROOT;
846 cluster->cl_reconnect_delay_ms = O2NET_RECONNECT_DELAY_MS_DEFAULT;
847 cluster->cl_idle_timeout_ms = O2NET_IDLE_TIMEOUT_MS_DEFAULT;
848 cluster->cl_keepalive_delay_ms = O2NET_KEEPALIVE_DELAY_MS_DEFAULT;
681 849
682 ret = &cluster->cl_group; 850 ret = &cluster->cl_group;
683 o2nm_single_cluster = cluster; 851 o2nm_single_cluster = cluster;
diff --git a/fs/ocfs2/cluster/nodemanager.h b/fs/ocfs2/cluster/nodemanager.h
index fce8033c310f..8fb23cacc2f5 100644
--- a/fs/ocfs2/cluster/nodemanager.h
+++ b/fs/ocfs2/cluster/nodemanager.h
@@ -53,6 +53,23 @@ struct o2nm_node {
53 unsigned long nd_set_attributes; 53 unsigned long nd_set_attributes;
54}; 54};
55 55
56struct o2nm_cluster {
57 struct config_group cl_group;
58 unsigned cl_has_local:1;
59 u8 cl_local_node;
60 rwlock_t cl_nodes_lock;
61 struct o2nm_node *cl_nodes[O2NM_MAX_NODES];
62 struct rb_root cl_node_ip_tree;
63 unsigned int cl_idle_timeout_ms;
64 unsigned int cl_keepalive_delay_ms;
65 unsigned int cl_reconnect_delay_ms;
66
67 /* this bitmap is part of a hack for disk bitmap.. will go eventually. - zab */
68 unsigned long cl_nodes_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
69};
70
71extern struct o2nm_cluster *o2nm_single_cluster;
72
56u8 o2nm_this_node(void); 73u8 o2nm_this_node(void);
57 74
58int o2nm_configured_node_map(unsigned long *map, unsigned bytes); 75int o2nm_configured_node_map(unsigned long *map, unsigned bytes);
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index 9b3209dc0b16..457753df1ae7 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -147,6 +147,28 @@ static void o2net_listen_data_ready(struct sock *sk, int bytes);
147static void o2net_sc_send_keep_req(struct work_struct *work); 147static void o2net_sc_send_keep_req(struct work_struct *work);
148static void o2net_idle_timer(unsigned long data); 148static void o2net_idle_timer(unsigned long data);
149static void o2net_sc_postpone_idle(struct o2net_sock_container *sc); 149static void o2net_sc_postpone_idle(struct o2net_sock_container *sc);
150static void o2net_sc_reset_idle_timer(struct o2net_sock_container *sc);
151
152/*
153 * FIXME: These should use to_o2nm_cluster_from_node(), but we end up
154 * losing our parent link to the cluster during shutdown. This can be
155 * solved by adding a pre-removal callback to configfs, or passing
156 * around the cluster with the node. -jeffm
157 */
158static inline int o2net_reconnect_delay(struct o2nm_node *node)
159{
160 return o2nm_single_cluster->cl_reconnect_delay_ms;
161}
162
163static inline int o2net_keepalive_delay(struct o2nm_node *node)
164{
165 return o2nm_single_cluster->cl_keepalive_delay_ms;
166}
167
168static inline int o2net_idle_timeout(struct o2nm_node *node)
169{
170 return o2nm_single_cluster->cl_idle_timeout_ms;
171}
150 172
151static inline int o2net_sys_err_to_errno(enum o2net_system_error err) 173static inline int o2net_sys_err_to_errno(enum o2net_system_error err)
152{ 174{
@@ -271,6 +293,8 @@ static void sc_kref_release(struct kref *kref)
271{ 293{
272 struct o2net_sock_container *sc = container_of(kref, 294 struct o2net_sock_container *sc = container_of(kref,
273 struct o2net_sock_container, sc_kref); 295 struct o2net_sock_container, sc_kref);
296 BUG_ON(timer_pending(&sc->sc_idle_timeout));
297
274 sclog(sc, "releasing\n"); 298 sclog(sc, "releasing\n");
275 299
276 if (sc->sc_sock) { 300 if (sc->sc_sock) {
@@ -356,6 +380,13 @@ static void o2net_sc_cancel_delayed_work(struct o2net_sock_container *sc,
356 sc_put(sc); 380 sc_put(sc);
357} 381}
358 382
383static atomic_t o2net_connected_peers = ATOMIC_INIT(0);
384
385int o2net_num_connected_peers(void)
386{
387 return atomic_read(&o2net_connected_peers);
388}
389
359static void o2net_set_nn_state(struct o2net_node *nn, 390static void o2net_set_nn_state(struct o2net_node *nn,
360 struct o2net_sock_container *sc, 391 struct o2net_sock_container *sc,
361 unsigned valid, int err) 392 unsigned valid, int err)
@@ -366,6 +397,11 @@ static void o2net_set_nn_state(struct o2net_node *nn,
366 397
367 assert_spin_locked(&nn->nn_lock); 398 assert_spin_locked(&nn->nn_lock);
368 399
400 if (old_sc && !sc)
401 atomic_dec(&o2net_connected_peers);
402 else if (!old_sc && sc)
403 atomic_inc(&o2net_connected_peers);
404
369 /* the node num comparison and single connect/accept path should stop 405 /* the node num comparison and single connect/accept path should stop
370 * an non-null sc from being overwritten with another */ 406 * an non-null sc from being overwritten with another */
371 BUG_ON(sc && nn->nn_sc && nn->nn_sc != sc); 407 BUG_ON(sc && nn->nn_sc && nn->nn_sc != sc);
@@ -424,9 +460,9 @@ static void o2net_set_nn_state(struct o2net_node *nn,
424 /* delay if we're withing a RECONNECT_DELAY of the 460 /* delay if we're withing a RECONNECT_DELAY of the
425 * last attempt */ 461 * last attempt */
426 delay = (nn->nn_last_connect_attempt + 462 delay = (nn->nn_last_connect_attempt +
427 msecs_to_jiffies(O2NET_RECONNECT_DELAY_MS)) 463 msecs_to_jiffies(o2net_reconnect_delay(sc->sc_node)))
428 - jiffies; 464 - jiffies;
429 if (delay > msecs_to_jiffies(O2NET_RECONNECT_DELAY_MS)) 465 if (delay > msecs_to_jiffies(o2net_reconnect_delay(sc->sc_node)))
430 delay = 0; 466 delay = 0;
431 mlog(ML_CONN, "queueing conn attempt in %lu jiffies\n", delay); 467 mlog(ML_CONN, "queueing conn attempt in %lu jiffies\n", delay);
432 queue_delayed_work(o2net_wq, &nn->nn_connect_work, delay); 468 queue_delayed_work(o2net_wq, &nn->nn_connect_work, delay);
@@ -1099,13 +1135,51 @@ static int o2net_check_handshake(struct o2net_sock_container *sc)
1099 return -1; 1135 return -1;
1100 } 1136 }
1101 1137
1138 /*
1139 * Ensure timeouts are consistent with other nodes, otherwise
1140 * we can end up with one node thinking that the other must be down,
1141 * but isn't. This can ultimately cause corruption.
1142 */
1143 if (be32_to_cpu(hand->o2net_idle_timeout_ms) !=
1144 o2net_idle_timeout(sc->sc_node)) {
1145 mlog(ML_NOTICE, SC_NODEF_FMT " uses a network idle timeout of "
1146 "%u ms, but we use %u ms locally. disconnecting\n",
1147 SC_NODEF_ARGS(sc),
1148 be32_to_cpu(hand->o2net_idle_timeout_ms),
1149 o2net_idle_timeout(sc->sc_node));
1150 o2net_ensure_shutdown(nn, sc, -ENOTCONN);
1151 return -1;
1152 }
1153
1154 if (be32_to_cpu(hand->o2net_keepalive_delay_ms) !=
1155 o2net_keepalive_delay(sc->sc_node)) {
1156 mlog(ML_NOTICE, SC_NODEF_FMT " uses a keepalive delay of "
1157 "%u ms, but we use %u ms locally. disconnecting\n",
1158 SC_NODEF_ARGS(sc),
1159 be32_to_cpu(hand->o2net_keepalive_delay_ms),
1160 o2net_keepalive_delay(sc->sc_node));
1161 o2net_ensure_shutdown(nn, sc, -ENOTCONN);
1162 return -1;
1163 }
1164
1165 if (be32_to_cpu(hand->o2hb_heartbeat_timeout_ms) !=
1166 O2HB_MAX_WRITE_TIMEOUT_MS) {
1167 mlog(ML_NOTICE, SC_NODEF_FMT " uses a heartbeat timeout of "
1168 "%u ms, but we use %u ms locally. disconnecting\n",
1169 SC_NODEF_ARGS(sc),
1170 be32_to_cpu(hand->o2hb_heartbeat_timeout_ms),
1171 O2HB_MAX_WRITE_TIMEOUT_MS);
1172 o2net_ensure_shutdown(nn, sc, -ENOTCONN);
1173 return -1;
1174 }
1175
1102 sc->sc_handshake_ok = 1; 1176 sc->sc_handshake_ok = 1;
1103 1177
1104 spin_lock(&nn->nn_lock); 1178 spin_lock(&nn->nn_lock);
1105 /* set valid and queue the idle timers only if it hasn't been 1179 /* set valid and queue the idle timers only if it hasn't been
1106 * shut down already */ 1180 * shut down already */
1107 if (nn->nn_sc == sc) { 1181 if (nn->nn_sc == sc) {
1108 o2net_sc_postpone_idle(sc); 1182 o2net_sc_reset_idle_timer(sc);
1109 o2net_set_nn_state(nn, sc, 1, 0); 1183 o2net_set_nn_state(nn, sc, 1, 0);
1110 } 1184 }
1111 spin_unlock(&nn->nn_lock); 1185 spin_unlock(&nn->nn_lock);
@@ -1131,6 +1205,23 @@ static int o2net_advance_rx(struct o2net_sock_container *sc)
1131 sclog(sc, "receiving\n"); 1205 sclog(sc, "receiving\n");
1132 do_gettimeofday(&sc->sc_tv_advance_start); 1206 do_gettimeofday(&sc->sc_tv_advance_start);
1133 1207
1208 if (unlikely(sc->sc_handshake_ok == 0)) {
1209 if(sc->sc_page_off < sizeof(struct o2net_handshake)) {
1210 data = page_address(sc->sc_page) + sc->sc_page_off;
1211 datalen = sizeof(struct o2net_handshake) - sc->sc_page_off;
1212 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen);
1213 if (ret > 0)
1214 sc->sc_page_off += ret;
1215 }
1216
1217 if (sc->sc_page_off == sizeof(struct o2net_handshake)) {
1218 o2net_check_handshake(sc);
1219 if (unlikely(sc->sc_handshake_ok == 0))
1220 ret = -EPROTO;
1221 }
1222 goto out;
1223 }
1224
1134 /* do we need more header? */ 1225 /* do we need more header? */
1135 if (sc->sc_page_off < sizeof(struct o2net_msg)) { 1226 if (sc->sc_page_off < sizeof(struct o2net_msg)) {
1136 data = page_address(sc->sc_page) + sc->sc_page_off; 1227 data = page_address(sc->sc_page) + sc->sc_page_off;
@@ -1138,15 +1229,6 @@ static int o2net_advance_rx(struct o2net_sock_container *sc)
1138 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen); 1229 ret = o2net_recv_tcp_msg(sc->sc_sock, data, datalen);
1139 if (ret > 0) { 1230 if (ret > 0) {
1140 sc->sc_page_off += ret; 1231 sc->sc_page_off += ret;
1141
1142 /* this working relies on the handshake being
1143 * smaller than the normal message header */
1144 if (sc->sc_page_off >= sizeof(struct o2net_handshake)&&
1145 !sc->sc_handshake_ok && o2net_check_handshake(sc)) {
1146 ret = -EPROTO;
1147 goto out;
1148 }
1149
1150 /* only swab incoming here.. we can 1232 /* only swab incoming here.. we can
1151 * only get here once as we cross from 1233 * only get here once as we cross from
1152 * being under to over */ 1234 * being under to over */
@@ -1248,6 +1330,18 @@ static int o2net_set_nodelay(struct socket *sock)
1248 return ret; 1330 return ret;
1249} 1331}
1250 1332
1333static void o2net_initialize_handshake(void)
1334{
1335 o2net_hand->o2hb_heartbeat_timeout_ms = cpu_to_be32(
1336 O2HB_MAX_WRITE_TIMEOUT_MS);
1337 o2net_hand->o2net_idle_timeout_ms = cpu_to_be32(
1338 o2net_idle_timeout(NULL));
1339 o2net_hand->o2net_keepalive_delay_ms = cpu_to_be32(
1340 o2net_keepalive_delay(NULL));
1341 o2net_hand->o2net_reconnect_delay_ms = cpu_to_be32(
1342 o2net_reconnect_delay(NULL));
1343}
1344
1251/* ------------------------------------------------------------ */ 1345/* ------------------------------------------------------------ */
1252 1346
1253/* called when a connect completes and after a sock is accepted. the 1347/* called when a connect completes and after a sock is accepted. the
@@ -1262,6 +1356,7 @@ static void o2net_sc_connect_completed(struct work_struct *work)
1262 (unsigned long long)O2NET_PROTOCOL_VERSION, 1356 (unsigned long long)O2NET_PROTOCOL_VERSION,
1263 (unsigned long long)be64_to_cpu(o2net_hand->connector_id)); 1357 (unsigned long long)be64_to_cpu(o2net_hand->connector_id));
1264 1358
1359 o2net_initialize_handshake();
1265 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); 1360 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand));
1266 sc_put(sc); 1361 sc_put(sc);
1267} 1362}
@@ -1287,8 +1382,10 @@ static void o2net_idle_timer(unsigned long data)
1287 1382
1288 do_gettimeofday(&now); 1383 do_gettimeofday(&now);
1289 1384
1290 printk(KERN_INFO "o2net: connection to " SC_NODEF_FMT " has been idle for 10 " 1385 printk(KERN_INFO "o2net: connection to " SC_NODEF_FMT " has been idle for %u.%u "
1291 "seconds, shutting it down.\n", SC_NODEF_ARGS(sc)); 1386 "seconds, shutting it down.\n", SC_NODEF_ARGS(sc),
1387 o2net_idle_timeout(sc->sc_node) / 1000,
1388 o2net_idle_timeout(sc->sc_node) % 1000);
1292 mlog(ML_NOTICE, "here are some times that might help debug the " 1389 mlog(ML_NOTICE, "here are some times that might help debug the "
1293 "situation: (tmr %ld.%ld now %ld.%ld dr %ld.%ld adv " 1390 "situation: (tmr %ld.%ld now %ld.%ld dr %ld.%ld adv "
1294 "%ld.%ld:%ld.%ld func (%08x:%u) %ld.%ld:%ld.%ld)\n", 1391 "%ld.%ld:%ld.%ld func (%08x:%u) %ld.%ld:%ld.%ld)\n",
@@ -1306,14 +1403,21 @@ static void o2net_idle_timer(unsigned long data)
1306 o2net_sc_queue_work(sc, &sc->sc_shutdown_work); 1403 o2net_sc_queue_work(sc, &sc->sc_shutdown_work);
1307} 1404}
1308 1405
1309static void o2net_sc_postpone_idle(struct o2net_sock_container *sc) 1406static void o2net_sc_reset_idle_timer(struct o2net_sock_container *sc)
1310{ 1407{
1311 o2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work); 1408 o2net_sc_cancel_delayed_work(sc, &sc->sc_keepalive_work);
1312 o2net_sc_queue_delayed_work(sc, &sc->sc_keepalive_work, 1409 o2net_sc_queue_delayed_work(sc, &sc->sc_keepalive_work,
1313 O2NET_KEEPALIVE_DELAY_SECS * HZ); 1410 msecs_to_jiffies(o2net_keepalive_delay(sc->sc_node)));
1314 do_gettimeofday(&sc->sc_tv_timer); 1411 do_gettimeofday(&sc->sc_tv_timer);
1315 mod_timer(&sc->sc_idle_timeout, 1412 mod_timer(&sc->sc_idle_timeout,
1316 jiffies + (O2NET_IDLE_TIMEOUT_SECS * HZ)); 1413 jiffies + msecs_to_jiffies(o2net_idle_timeout(sc->sc_node)));
1414}
1415
1416static void o2net_sc_postpone_idle(struct o2net_sock_container *sc)
1417{
1418 /* Only push out an existing timer */
1419 if (timer_pending(&sc->sc_idle_timeout))
1420 o2net_sc_reset_idle_timer(sc);
1317} 1421}
1318 1422
1319/* this work func is kicked whenever a path sets the nn state which doesn't 1423/* this work func is kicked whenever a path sets the nn state which doesn't
@@ -1435,9 +1539,12 @@ static void o2net_connect_expired(struct work_struct *work)
1435 1539
1436 spin_lock(&nn->nn_lock); 1540 spin_lock(&nn->nn_lock);
1437 if (!nn->nn_sc_valid) { 1541 if (!nn->nn_sc_valid) {
1542 struct o2nm_node *node = nn->nn_sc->sc_node;
1438 mlog(ML_ERROR, "no connection established with node %u after " 1543 mlog(ML_ERROR, "no connection established with node %u after "
1439 "%u seconds, giving up and returning errors.\n", 1544 "%u.%u seconds, giving up and returning errors.\n",
1440 o2net_num_from_nn(nn), O2NET_IDLE_TIMEOUT_SECS); 1545 o2net_num_from_nn(nn),
1546 o2net_idle_timeout(node) / 1000,
1547 o2net_idle_timeout(node) % 1000);
1441 1548
1442 o2net_set_nn_state(nn, NULL, 0, -ENOTCONN); 1549 o2net_set_nn_state(nn, NULL, 0, -ENOTCONN);
1443 } 1550 }
@@ -1478,6 +1585,8 @@ static void o2net_hb_node_down_cb(struct o2nm_node *node, int node_num,
1478 1585
1479 if (node_num != o2nm_this_node()) 1586 if (node_num != o2nm_this_node())
1480 o2net_disconnect_node(node); 1587 o2net_disconnect_node(node);
1588
1589 BUG_ON(atomic_read(&o2net_connected_peers) < 0);
1481} 1590}
1482 1591
1483static void o2net_hb_node_up_cb(struct o2nm_node *node, int node_num, 1592static void o2net_hb_node_up_cb(struct o2nm_node *node, int node_num,
@@ -1489,14 +1598,14 @@ static void o2net_hb_node_up_cb(struct o2nm_node *node, int node_num,
1489 1598
1490 /* ensure an immediate connect attempt */ 1599 /* ensure an immediate connect attempt */
1491 nn->nn_last_connect_attempt = jiffies - 1600 nn->nn_last_connect_attempt = jiffies -
1492 (msecs_to_jiffies(O2NET_RECONNECT_DELAY_MS) + 1); 1601 (msecs_to_jiffies(o2net_reconnect_delay(node)) + 1);
1493 1602
1494 if (node_num != o2nm_this_node()) { 1603 if (node_num != o2nm_this_node()) {
1495 /* heartbeat doesn't work unless a local node number is 1604 /* heartbeat doesn't work unless a local node number is
1496 * configured and doing so brings up the o2net_wq, so we can 1605 * configured and doing so brings up the o2net_wq, so we can
1497 * use it.. */ 1606 * use it.. */
1498 queue_delayed_work(o2net_wq, &nn->nn_connect_expired, 1607 queue_delayed_work(o2net_wq, &nn->nn_connect_expired,
1499 O2NET_IDLE_TIMEOUT_SECS * HZ); 1608 msecs_to_jiffies(o2net_idle_timeout(node)));
1500 1609
1501 /* believe it or not, accept and node hearbeating testing 1610 /* believe it or not, accept and node hearbeating testing
1502 * can succeed for this node before we got here.. so 1611 * can succeed for this node before we got here.. so
@@ -1641,6 +1750,7 @@ static int o2net_accept_one(struct socket *sock)
1641 o2net_register_callbacks(sc->sc_sock->sk, sc); 1750 o2net_register_callbacks(sc->sc_sock->sk, sc);
1642 o2net_sc_queue_work(sc, &sc->sc_rx_work); 1751 o2net_sc_queue_work(sc, &sc->sc_rx_work);
1643 1752
1753 o2net_initialize_handshake();
1644 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand)); 1754 o2net_sendpage(sc, o2net_hand, sizeof(*o2net_hand));
1645 1755
1646out: 1756out:
diff --git a/fs/ocfs2/cluster/tcp.h b/fs/ocfs2/cluster/tcp.h
index 616ff2b8434a..21a4e43df836 100644
--- a/fs/ocfs2/cluster/tcp.h
+++ b/fs/ocfs2/cluster/tcp.h
@@ -54,6 +54,13 @@ typedef int (o2net_msg_handler_func)(struct o2net_msg *msg, u32 len, void *data)
54 54
55#define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg)) 55#define O2NET_MAX_PAYLOAD_BYTES (4096 - sizeof(struct o2net_msg))
56 56
57/* same as hb delay, we're waiting for another node to recognize our hb */
58#define O2NET_RECONNECT_DELAY_MS_DEFAULT 2000
59
60#define O2NET_KEEPALIVE_DELAY_MS_DEFAULT 5000
61#define O2NET_IDLE_TIMEOUT_MS_DEFAULT 10000
62
63
57/* TODO: figure this out.... */ 64/* TODO: figure this out.... */
58static inline int o2net_link_down(int err, struct socket *sock) 65static inline int o2net_link_down(int err, struct socket *sock)
59{ 66{
@@ -101,6 +108,7 @@ void o2net_unregister_hb_callbacks(void);
101int o2net_start_listening(struct o2nm_node *node); 108int o2net_start_listening(struct o2nm_node *node);
102void o2net_stop_listening(struct o2nm_node *node); 109void o2net_stop_listening(struct o2nm_node *node);
103void o2net_disconnect_node(struct o2nm_node *node); 110void o2net_disconnect_node(struct o2nm_node *node);
111int o2net_num_connected_peers(void);
104 112
105int o2net_init(void); 113int o2net_init(void);
106void o2net_exit(void); 114void o2net_exit(void);
diff --git a/fs/ocfs2/cluster/tcp_internal.h b/fs/ocfs2/cluster/tcp_internal.h
index daebbd3a2c8c..b700dc9624d1 100644
--- a/fs/ocfs2/cluster/tcp_internal.h
+++ b/fs/ocfs2/cluster/tcp_internal.h
@@ -27,23 +27,20 @@
27#define O2NET_MSG_KEEP_REQ_MAGIC ((u16)0xfa57) 27#define O2NET_MSG_KEEP_REQ_MAGIC ((u16)0xfa57)
28#define O2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58) 28#define O2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58)
29 29
30/* same as hb delay, we're waiting for another node to recognize our hb */
31#define O2NET_RECONNECT_DELAY_MS O2HB_REGION_TIMEOUT_MS
32
33/* we're delaying our quorum decision so that heartbeat will have timed 30/* we're delaying our quorum decision so that heartbeat will have timed
34 * out truly dead nodes by the time we come around to making decisions 31 * out truly dead nodes by the time we come around to making decisions
35 * on their number */ 32 * on their number */
36#define O2NET_QUORUM_DELAY_MS ((o2hb_dead_threshold + 2) * O2HB_REGION_TIMEOUT_MS) 33#define O2NET_QUORUM_DELAY_MS ((o2hb_dead_threshold + 2) * O2HB_REGION_TIMEOUT_MS)
37 34
38#define O2NET_KEEPALIVE_DELAY_SECS 5
39#define O2NET_IDLE_TIMEOUT_SECS 10
40
41/* 35/*
42 * This version number represents quite a lot, unfortunately. It not 36 * This version number represents quite a lot, unfortunately. It not
43 * only represents the raw network message protocol on the wire but also 37 * only represents the raw network message protocol on the wire but also
44 * locking semantics of the file system using the protocol. It should 38 * locking semantics of the file system using the protocol. It should
45 * be somewhere else, I'm sure, but right now it isn't. 39 * be somewhere else, I'm sure, but right now it isn't.
46 * 40 *
41 * New in version 5:
42 * - Network timeout checking protocol
43 *
47 * New in version 4: 44 * New in version 4:
48 * - Remove i_generation from lock names for better stat performance. 45 * - Remove i_generation from lock names for better stat performance.
49 * 46 *
@@ -54,10 +51,14 @@
54 * - full 64 bit i_size in the metadata lock lvbs 51 * - full 64 bit i_size in the metadata lock lvbs
55 * - introduction of "rw" lock and pushing meta/data locking down 52 * - introduction of "rw" lock and pushing meta/data locking down
56 */ 53 */
57#define O2NET_PROTOCOL_VERSION 4ULL 54#define O2NET_PROTOCOL_VERSION 5ULL
58struct o2net_handshake { 55struct o2net_handshake {
59 __be64 protocol_version; 56 __be64 protocol_version;
60 __be64 connector_id; 57 __be64 connector_id;
58 __be32 o2hb_heartbeat_timeout_ms;
59 __be32 o2net_idle_timeout_ms;
60 __be32 o2net_keepalive_delay_ms;
61 __be32 o2net_reconnect_delay_ms;
61}; 62};
62 63
63struct o2net_node { 64struct o2net_node {
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index baad2aa27c14..66821e178167 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -79,7 +79,7 @@ int ocfs2_readdir(struct file * filp, void * dirent, filldir_t filldir)
79 struct buffer_head * bh, * tmp; 79 struct buffer_head * bh, * tmp;
80 struct ocfs2_dir_entry * de; 80 struct ocfs2_dir_entry * de;
81 int err; 81 int err;
82 struct inode *inode = filp->f_dentry->d_inode; 82 struct inode *inode = filp->f_path.dentry->d_inode;
83 struct super_block * sb = inode->i_sb; 83 struct super_block * sb = inode->i_sb;
84 unsigned int ra_sectors = 16; 84 unsigned int ra_sectors = 16;
85 int lock_level = 0; 85 int lock_level = 0;
diff --git a/fs/ocfs2/dlm/dlmfs.c b/fs/ocfs2/dlm/dlmfs.c
index 941acf14e61f..b7f0ba97a1a2 100644
--- a/fs/ocfs2/dlm/dlmfs.c
+++ b/fs/ocfs2/dlm/dlmfs.c
@@ -176,7 +176,7 @@ static ssize_t dlmfs_file_read(struct file *filp,
176 int bytes_left; 176 int bytes_left;
177 ssize_t readlen; 177 ssize_t readlen;
178 char *lvb_buf; 178 char *lvb_buf;
179 struct inode *inode = filp->f_dentry->d_inode; 179 struct inode *inode = filp->f_path.dentry->d_inode;
180 180
181 mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", 181 mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
182 inode->i_ino, count, *ppos); 182 inode->i_ino, count, *ppos);
@@ -220,7 +220,7 @@ static ssize_t dlmfs_file_write(struct file *filp,
220 int bytes_left; 220 int bytes_left;
221 ssize_t writelen; 221 ssize_t writelen;
222 char *lvb_buf; 222 char *lvb_buf;
223 struct inode *inode = filp->f_dentry->d_inode; 223 struct inode *inode = filp->f_path.dentry->d_inode;
224 224
225 mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", 225 mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
226 inode->i_ino, count, *ppos); 226 inode->i_ino, count, *ppos);
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 69fba16efbd1..e6220137bf69 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -770,7 +770,7 @@ static int ocfs2_lock_create(struct ocfs2_super *osb,
770 int dlm_flags) 770 int dlm_flags)
771{ 771{
772 int ret = 0; 772 int ret = 0;
773 enum dlm_status status; 773 enum dlm_status status = DLM_NORMAL;
774 unsigned long flags; 774 unsigned long flags;
775 775
776 mlog_entry_void(); 776 mlog_entry_void();
@@ -1138,6 +1138,7 @@ int ocfs2_rw_lock(struct inode *inode, int write)
1138{ 1138{
1139 int status, level; 1139 int status, level;
1140 struct ocfs2_lock_res *lockres; 1140 struct ocfs2_lock_res *lockres;
1141 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1141 1142
1142 BUG_ON(!inode); 1143 BUG_ON(!inode);
1143 1144
@@ -1147,6 +1148,9 @@ int ocfs2_rw_lock(struct inode *inode, int write)
1147 (unsigned long long)OCFS2_I(inode)->ip_blkno, 1148 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1148 write ? "EXMODE" : "PRMODE"); 1149 write ? "EXMODE" : "PRMODE");
1149 1150
1151 if (ocfs2_mount_local(osb))
1152 return 0;
1153
1150 lockres = &OCFS2_I(inode)->ip_rw_lockres; 1154 lockres = &OCFS2_I(inode)->ip_rw_lockres;
1151 1155
1152 level = write ? LKM_EXMODE : LKM_PRMODE; 1156 level = write ? LKM_EXMODE : LKM_PRMODE;
@@ -1164,6 +1168,7 @@ void ocfs2_rw_unlock(struct inode *inode, int write)
1164{ 1168{
1165 int level = write ? LKM_EXMODE : LKM_PRMODE; 1169 int level = write ? LKM_EXMODE : LKM_PRMODE;
1166 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres; 1170 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
1171 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1167 1172
1168 mlog_entry_void(); 1173 mlog_entry_void();
1169 1174
@@ -1171,7 +1176,8 @@ void ocfs2_rw_unlock(struct inode *inode, int write)
1171 (unsigned long long)OCFS2_I(inode)->ip_blkno, 1176 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1172 write ? "EXMODE" : "PRMODE"); 1177 write ? "EXMODE" : "PRMODE");
1173 1178
1174 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); 1179 if (!ocfs2_mount_local(osb))
1180 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1175 1181
1176 mlog_exit_void(); 1182 mlog_exit_void();
1177} 1183}
@@ -1182,6 +1188,7 @@ int ocfs2_data_lock_full(struct inode *inode,
1182{ 1188{
1183 int status = 0, level; 1189 int status = 0, level;
1184 struct ocfs2_lock_res *lockres; 1190 struct ocfs2_lock_res *lockres;
1191 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1185 1192
1186 BUG_ON(!inode); 1193 BUG_ON(!inode);
1187 1194
@@ -1201,6 +1208,9 @@ int ocfs2_data_lock_full(struct inode *inode,
1201 goto out; 1208 goto out;
1202 } 1209 }
1203 1210
1211 if (ocfs2_mount_local(osb))
1212 goto out;
1213
1204 lockres = &OCFS2_I(inode)->ip_data_lockres; 1214 lockres = &OCFS2_I(inode)->ip_data_lockres;
1205 1215
1206 level = write ? LKM_EXMODE : LKM_PRMODE; 1216 level = write ? LKM_EXMODE : LKM_PRMODE;
@@ -1269,6 +1279,7 @@ void ocfs2_data_unlock(struct inode *inode,
1269{ 1279{
1270 int level = write ? LKM_EXMODE : LKM_PRMODE; 1280 int level = write ? LKM_EXMODE : LKM_PRMODE;
1271 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres; 1281 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1282 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1272 1283
1273 mlog_entry_void(); 1284 mlog_entry_void();
1274 1285
@@ -1276,7 +1287,8 @@ void ocfs2_data_unlock(struct inode *inode,
1276 (unsigned long long)OCFS2_I(inode)->ip_blkno, 1287 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1277 write ? "EXMODE" : "PRMODE"); 1288 write ? "EXMODE" : "PRMODE");
1278 1289
1279 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) 1290 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1291 !ocfs2_mount_local(osb))
1280 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); 1292 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1281 1293
1282 mlog_exit_void(); 1294 mlog_exit_void();
@@ -1467,8 +1479,9 @@ static int ocfs2_meta_lock_update(struct inode *inode,
1467{ 1479{
1468 int status = 0; 1480 int status = 0;
1469 struct ocfs2_inode_info *oi = OCFS2_I(inode); 1481 struct ocfs2_inode_info *oi = OCFS2_I(inode);
1470 struct ocfs2_lock_res *lockres; 1482 struct ocfs2_lock_res *lockres = NULL;
1471 struct ocfs2_dinode *fe; 1483 struct ocfs2_dinode *fe;
1484 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1472 1485
1473 mlog_entry_void(); 1486 mlog_entry_void();
1474 1487
@@ -1483,10 +1496,12 @@ static int ocfs2_meta_lock_update(struct inode *inode,
1483 } 1496 }
1484 spin_unlock(&oi->ip_lock); 1497 spin_unlock(&oi->ip_lock);
1485 1498
1486 lockres = &oi->ip_meta_lockres; 1499 if (!ocfs2_mount_local(osb)) {
1500 lockres = &oi->ip_meta_lockres;
1487 1501
1488 if (!ocfs2_should_refresh_lock_res(lockres)) 1502 if (!ocfs2_should_refresh_lock_res(lockres))
1489 goto bail; 1503 goto bail;
1504 }
1490 1505
1491 /* This will discard any caching information we might have had 1506 /* This will discard any caching information we might have had
1492 * for the inode metadata. */ 1507 * for the inode metadata. */
@@ -1496,7 +1511,7 @@ static int ocfs2_meta_lock_update(struct inode *inode,
1496 * map (directories, bitmap files, etc) */ 1511 * map (directories, bitmap files, etc) */
1497 ocfs2_extent_map_trunc(inode, 0); 1512 ocfs2_extent_map_trunc(inode, 0);
1498 1513
1499 if (ocfs2_meta_lvb_is_trustable(inode, lockres)) { 1514 if (lockres && ocfs2_meta_lvb_is_trustable(inode, lockres)) {
1500 mlog(0, "Trusting LVB on inode %llu\n", 1515 mlog(0, "Trusting LVB on inode %llu\n",
1501 (unsigned long long)oi->ip_blkno); 1516 (unsigned long long)oi->ip_blkno);
1502 ocfs2_refresh_inode_from_lvb(inode); 1517 ocfs2_refresh_inode_from_lvb(inode);
@@ -1543,7 +1558,8 @@ static int ocfs2_meta_lock_update(struct inode *inode,
1543 1558
1544 status = 0; 1559 status = 0;
1545bail_refresh: 1560bail_refresh:
1546 ocfs2_complete_lock_res_refresh(lockres, status); 1561 if (lockres)
1562 ocfs2_complete_lock_res_refresh(lockres, status);
1547bail: 1563bail:
1548 mlog_exit(status); 1564 mlog_exit(status);
1549 return status; 1565 return status;
@@ -1585,7 +1601,7 @@ int ocfs2_meta_lock_full(struct inode *inode,
1585 int arg_flags) 1601 int arg_flags)
1586{ 1602{
1587 int status, level, dlm_flags, acquired; 1603 int status, level, dlm_flags, acquired;
1588 struct ocfs2_lock_res *lockres; 1604 struct ocfs2_lock_res *lockres = NULL;
1589 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 1605 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1590 struct buffer_head *local_bh = NULL; 1606 struct buffer_head *local_bh = NULL;
1591 1607
@@ -1607,6 +1623,9 @@ int ocfs2_meta_lock_full(struct inode *inode,
1607 goto bail; 1623 goto bail;
1608 } 1624 }
1609 1625
1626 if (ocfs2_mount_local(osb))
1627 goto local;
1628
1610 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY)) 1629 if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
1611 wait_event(osb->recovery_event, 1630 wait_event(osb->recovery_event,
1612 ocfs2_node_map_is_empty(osb, &osb->recovery_map)); 1631 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
@@ -1636,6 +1655,7 @@ int ocfs2_meta_lock_full(struct inode *inode,
1636 wait_event(osb->recovery_event, 1655 wait_event(osb->recovery_event,
1637 ocfs2_node_map_is_empty(osb, &osb->recovery_map)); 1656 ocfs2_node_map_is_empty(osb, &osb->recovery_map));
1638 1657
1658local:
1639 /* 1659 /*
1640 * We only see this flag if we're being called from 1660 * We only see this flag if we're being called from
1641 * ocfs2_read_locked_inode(). It means we're locking an inode 1661 * ocfs2_read_locked_inode(). It means we're locking an inode
@@ -1644,7 +1664,8 @@ int ocfs2_meta_lock_full(struct inode *inode,
1644 */ 1664 */
1645 if (inode->i_state & I_NEW) { 1665 if (inode->i_state & I_NEW) {
1646 status = 0; 1666 status = 0;
1647 ocfs2_complete_lock_res_refresh(lockres, 0); 1667 if (lockres)
1668 ocfs2_complete_lock_res_refresh(lockres, 0);
1648 goto bail; 1669 goto bail;
1649 } 1670 }
1650 1671
@@ -1767,6 +1788,7 @@ void ocfs2_meta_unlock(struct inode *inode,
1767{ 1788{
1768 int level = ex ? LKM_EXMODE : LKM_PRMODE; 1789 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1769 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres; 1790 struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1791 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
1770 1792
1771 mlog_entry_void(); 1793 mlog_entry_void();
1772 1794
@@ -1774,7 +1796,8 @@ void ocfs2_meta_unlock(struct inode *inode,
1774 (unsigned long long)OCFS2_I(inode)->ip_blkno, 1796 (unsigned long long)OCFS2_I(inode)->ip_blkno,
1775 ex ? "EXMODE" : "PRMODE"); 1797 ex ? "EXMODE" : "PRMODE");
1776 1798
1777 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb))) 1799 if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1800 !ocfs2_mount_local(osb))
1778 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level); 1801 ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1779 1802
1780 mlog_exit_void(); 1803 mlog_exit_void();
@@ -1783,7 +1806,7 @@ void ocfs2_meta_unlock(struct inode *inode,
1783int ocfs2_super_lock(struct ocfs2_super *osb, 1806int ocfs2_super_lock(struct ocfs2_super *osb,
1784 int ex) 1807 int ex)
1785{ 1808{
1786 int status; 1809 int status = 0;
1787 int level = ex ? LKM_EXMODE : LKM_PRMODE; 1810 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1788 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; 1811 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1789 struct buffer_head *bh; 1812 struct buffer_head *bh;
@@ -1794,6 +1817,9 @@ int ocfs2_super_lock(struct ocfs2_super *osb,
1794 if (ocfs2_is_hard_readonly(osb)) 1817 if (ocfs2_is_hard_readonly(osb))
1795 return -EROFS; 1818 return -EROFS;
1796 1819
1820 if (ocfs2_mount_local(osb))
1821 goto bail;
1822
1797 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0); 1823 status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
1798 if (status < 0) { 1824 if (status < 0) {
1799 mlog_errno(status); 1825 mlog_errno(status);
@@ -1832,7 +1858,8 @@ void ocfs2_super_unlock(struct ocfs2_super *osb,
1832 int level = ex ? LKM_EXMODE : LKM_PRMODE; 1858 int level = ex ? LKM_EXMODE : LKM_PRMODE;
1833 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres; 1859 struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
1834 1860
1835 ocfs2_cluster_unlock(osb, lockres, level); 1861 if (!ocfs2_mount_local(osb))
1862 ocfs2_cluster_unlock(osb, lockres, level);
1836} 1863}
1837 1864
1838int ocfs2_rename_lock(struct ocfs2_super *osb) 1865int ocfs2_rename_lock(struct ocfs2_super *osb)
@@ -1843,6 +1870,9 @@ int ocfs2_rename_lock(struct ocfs2_super *osb)
1843 if (ocfs2_is_hard_readonly(osb)) 1870 if (ocfs2_is_hard_readonly(osb))
1844 return -EROFS; 1871 return -EROFS;
1845 1872
1873 if (ocfs2_mount_local(osb))
1874 return 0;
1875
1846 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0); 1876 status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
1847 if (status < 0) 1877 if (status < 0)
1848 mlog_errno(status); 1878 mlog_errno(status);
@@ -1854,7 +1884,8 @@ void ocfs2_rename_unlock(struct ocfs2_super *osb)
1854{ 1884{
1855 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres; 1885 struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
1856 1886
1857 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE); 1887 if (!ocfs2_mount_local(osb))
1888 ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
1858} 1889}
1859 1890
1860int ocfs2_dentry_lock(struct dentry *dentry, int ex) 1891int ocfs2_dentry_lock(struct dentry *dentry, int ex)
@@ -1869,6 +1900,9 @@ int ocfs2_dentry_lock(struct dentry *dentry, int ex)
1869 if (ocfs2_is_hard_readonly(osb)) 1900 if (ocfs2_is_hard_readonly(osb))
1870 return -EROFS; 1901 return -EROFS;
1871 1902
1903 if (ocfs2_mount_local(osb))
1904 return 0;
1905
1872 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0); 1906 ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
1873 if (ret < 0) 1907 if (ret < 0)
1874 mlog_errno(ret); 1908 mlog_errno(ret);
@@ -1882,7 +1916,8 @@ void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
1882 struct ocfs2_dentry_lock *dl = dentry->d_fsdata; 1916 struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
1883 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 1917 struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
1884 1918
1885 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level); 1919 if (!ocfs2_mount_local(osb))
1920 ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
1886} 1921}
1887 1922
1888/* Reference counting of the dlm debug structure. We want this because 1923/* Reference counting of the dlm debug structure. We want this because
@@ -2145,12 +2180,15 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
2145 2180
2146int ocfs2_dlm_init(struct ocfs2_super *osb) 2181int ocfs2_dlm_init(struct ocfs2_super *osb)
2147{ 2182{
2148 int status; 2183 int status = 0;
2149 u32 dlm_key; 2184 u32 dlm_key;
2150 struct dlm_ctxt *dlm; 2185 struct dlm_ctxt *dlm = NULL;
2151 2186
2152 mlog_entry_void(); 2187 mlog_entry_void();
2153 2188
2189 if (ocfs2_mount_local(osb))
2190 goto local;
2191
2154 status = ocfs2_dlm_init_debug(osb); 2192 status = ocfs2_dlm_init_debug(osb);
2155 if (status < 0) { 2193 if (status < 0) {
2156 mlog_errno(status); 2194 mlog_errno(status);
@@ -2178,11 +2216,12 @@ int ocfs2_dlm_init(struct ocfs2_super *osb)
2178 goto bail; 2216 goto bail;
2179 } 2217 }
2180 2218
2219 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2220
2221local:
2181 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb); 2222 ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
2182 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb); 2223 ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
2183 2224
2184 dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2185
2186 osb->dlm = dlm; 2225 osb->dlm = dlm;
2187 2226
2188 status = 0; 2227 status = 0;
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 8786b3c490aa..e9a82ad95c1e 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -68,7 +68,7 @@ static int ocfs2_file_open(struct inode *inode, struct file *file)
68 struct ocfs2_inode_info *oi = OCFS2_I(inode); 68 struct ocfs2_inode_info *oi = OCFS2_I(inode);
69 69
70 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file, 70 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
71 file->f_dentry->d_name.len, file->f_dentry->d_name.name); 71 file->f_path.dentry->d_name.len, file->f_path.dentry->d_name.name);
72 72
73 spin_lock(&oi->ip_lock); 73 spin_lock(&oi->ip_lock);
74 74
@@ -98,8 +98,8 @@ static int ocfs2_file_release(struct inode *inode, struct file *file)
98 struct ocfs2_inode_info *oi = OCFS2_I(inode); 98 struct ocfs2_inode_info *oi = OCFS2_I(inode);
99 99
100 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file, 100 mlog_entry("(0x%p, 0x%p, '%.*s')\n", inode, file,
101 file->f_dentry->d_name.len, 101 file->f_path.dentry->d_name.len,
102 file->f_dentry->d_name.name); 102 file->f_path.dentry->d_name.name);
103 103
104 spin_lock(&oi->ip_lock); 104 spin_lock(&oi->ip_lock);
105 if (!--oi->ip_open_count) 105 if (!--oi->ip_open_count)
@@ -1131,13 +1131,13 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1131{ 1131{
1132 int ret, rw_level, have_alloc_sem = 0; 1132 int ret, rw_level, have_alloc_sem = 0;
1133 struct file *filp = iocb->ki_filp; 1133 struct file *filp = iocb->ki_filp;
1134 struct inode *inode = filp->f_dentry->d_inode; 1134 struct inode *inode = filp->f_path.dentry->d_inode;
1135 int appending = filp->f_flags & O_APPEND ? 1 : 0; 1135 int appending = filp->f_flags & O_APPEND ? 1 : 0;
1136 1136
1137 mlog_entry("(0x%p, %u, '%.*s')\n", filp, 1137 mlog_entry("(0x%p, %u, '%.*s')\n", filp,
1138 (unsigned int)nr_segs, 1138 (unsigned int)nr_segs,
1139 filp->f_dentry->d_name.len, 1139 filp->f_path.dentry->d_name.len,
1140 filp->f_dentry->d_name.name); 1140 filp->f_path.dentry->d_name.name);
1141 1141
1142 /* happy write of zero bytes */ 1142 /* happy write of zero bytes */
1143 if (iocb->ki_left == 0) 1143 if (iocb->ki_left == 0)
@@ -1159,7 +1159,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
1159 goto out; 1159 goto out;
1160 } 1160 }
1161 1161
1162 ret = ocfs2_prepare_inode_for_write(filp->f_dentry, &iocb->ki_pos, 1162 ret = ocfs2_prepare_inode_for_write(filp->f_path.dentry, &iocb->ki_pos,
1163 iocb->ki_left, appending); 1163 iocb->ki_left, appending);
1164 if (ret < 0) { 1164 if (ret < 0) {
1165 mlog_errno(ret); 1165 mlog_errno(ret);
@@ -1207,12 +1207,12 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
1207 unsigned int flags) 1207 unsigned int flags)
1208{ 1208{
1209 int ret; 1209 int ret;
1210 struct inode *inode = out->f_dentry->d_inode; 1210 struct inode *inode = out->f_path.dentry->d_inode;
1211 1211
1212 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe, 1212 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", out, pipe,
1213 (unsigned int)len, 1213 (unsigned int)len,
1214 out->f_dentry->d_name.len, 1214 out->f_path.dentry->d_name.len,
1215 out->f_dentry->d_name.name); 1215 out->f_path.dentry->d_name.name);
1216 1216
1217 inode_double_lock(inode, pipe->inode); 1217 inode_double_lock(inode, pipe->inode);
1218 1218
@@ -1222,7 +1222,7 @@ static ssize_t ocfs2_file_splice_write(struct pipe_inode_info *pipe,
1222 goto out; 1222 goto out;
1223 } 1223 }
1224 1224
1225 ret = ocfs2_prepare_inode_for_write(out->f_dentry, ppos, len, 0); 1225 ret = ocfs2_prepare_inode_for_write(out->f_path.dentry, ppos, len, 0);
1226 if (ret < 0) { 1226 if (ret < 0) {
1227 mlog_errno(ret); 1227 mlog_errno(ret);
1228 goto out_unlock; 1228 goto out_unlock;
@@ -1247,12 +1247,12 @@ static ssize_t ocfs2_file_splice_read(struct file *in,
1247 unsigned int flags) 1247 unsigned int flags)
1248{ 1248{
1249 int ret = 0; 1249 int ret = 0;
1250 struct inode *inode = in->f_dentry->d_inode; 1250 struct inode *inode = in->f_path.dentry->d_inode;
1251 1251
1252 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", in, pipe, 1252 mlog_entry("(0x%p, 0x%p, %u, '%.*s')\n", in, pipe,
1253 (unsigned int)len, 1253 (unsigned int)len,
1254 in->f_dentry->d_name.len, 1254 in->f_path.dentry->d_name.len,
1255 in->f_dentry->d_name.name); 1255 in->f_path.dentry->d_name.name);
1256 1256
1257 /* 1257 /*
1258 * See the comment in ocfs2_file_aio_read() 1258 * See the comment in ocfs2_file_aio_read()
@@ -1278,12 +1278,12 @@ static ssize_t ocfs2_file_aio_read(struct kiocb *iocb,
1278{ 1278{
1279 int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0; 1279 int ret = 0, rw_level = -1, have_alloc_sem = 0, lock_level = 0;
1280 struct file *filp = iocb->ki_filp; 1280 struct file *filp = iocb->ki_filp;
1281 struct inode *inode = filp->f_dentry->d_inode; 1281 struct inode *inode = filp->f_path.dentry->d_inode;
1282 1282
1283 mlog_entry("(0x%p, %u, '%.*s')\n", filp, 1283 mlog_entry("(0x%p, %u, '%.*s')\n", filp,
1284 (unsigned int)nr_segs, 1284 (unsigned int)nr_segs,
1285 filp->f_dentry->d_name.len, 1285 filp->f_path.dentry->d_name.len,
1286 filp->f_dentry->d_name.name); 1286 filp->f_path.dentry->d_name.name);
1287 1287
1288 if (!inode) { 1288 if (!inode) {
1289 ret = -EINVAL; 1289 ret = -EINVAL;
diff --git a/fs/ocfs2/heartbeat.c b/fs/ocfs2/heartbeat.c
index cbfd45a97a63..8fc52d6d0ce7 100644
--- a/fs/ocfs2/heartbeat.c
+++ b/fs/ocfs2/heartbeat.c
@@ -154,6 +154,9 @@ int ocfs2_register_hb_callbacks(struct ocfs2_super *osb)
154{ 154{
155 int status; 155 int status;
156 156
157 if (ocfs2_mount_local(osb))
158 return 0;
159
157 status = o2hb_register_callback(&osb->osb_hb_down); 160 status = o2hb_register_callback(&osb->osb_hb_down);
158 if (status < 0) { 161 if (status < 0) {
159 mlog_errno(status); 162 mlog_errno(status);
@@ -172,6 +175,9 @@ void ocfs2_clear_hb_callbacks(struct ocfs2_super *osb)
172{ 175{
173 int status; 176 int status;
174 177
178 if (ocfs2_mount_local(osb))
179 return;
180
175 status = o2hb_unregister_callback(&osb->osb_hb_down); 181 status = o2hb_unregister_callback(&osb->osb_hb_down);
176 if (status < 0) 182 if (status < 0)
177 mlog_errno(status); 183 mlog_errno(status);
@@ -186,6 +192,9 @@ void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
186 int ret; 192 int ret;
187 char *argv[5], *envp[3]; 193 char *argv[5], *envp[3];
188 194
195 if (ocfs2_mount_local(osb))
196 return;
197
189 if (!osb->uuid_str) { 198 if (!osb->uuid_str) {
190 /* This can happen if we don't get far enough in mount... */ 199 /* This can happen if we don't get far enough in mount... */
191 mlog(0, "No UUID with which to stop heartbeat!\n\n"); 200 mlog(0, "No UUID with which to stop heartbeat!\n\n");
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 42e361f3054f..e4d91493d7d7 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -423,7 +423,8 @@ static int ocfs2_read_locked_inode(struct inode *inode,
423 * cluster lock before trusting anything anyway. 423 * cluster lock before trusting anything anyway.
424 */ 424 */
425 can_lock = !(args->fi_flags & OCFS2_FI_FLAG_SYSFILE) 425 can_lock = !(args->fi_flags & OCFS2_FI_FLAG_SYSFILE)
426 && !(args->fi_flags & OCFS2_FI_FLAG_NOLOCK); 426 && !(args->fi_flags & OCFS2_FI_FLAG_NOLOCK)
427 && !ocfs2_mount_local(osb);
427 428
428 /* 429 /*
429 * To maintain backwards compatibility with older versions of 430 * To maintain backwards compatibility with older versions of
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 1d7f4ab1e5ed..825cb0ae1b4c 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -144,8 +144,10 @@ handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)
144 ocfs2_abort(osb->sb, "Detected aborted journal"); 144 ocfs2_abort(osb->sb, "Detected aborted journal");
145 handle = ERR_PTR(-EROFS); 145 handle = ERR_PTR(-EROFS);
146 } 146 }
147 } else 147 } else {
148 atomic_inc(&(osb->journal->j_num_trans)); 148 if (!ocfs2_mount_local(osb))
149 atomic_inc(&(osb->journal->j_num_trans));
150 }
149 151
150 return handle; 152 return handle;
151} 153}
@@ -507,9 +509,23 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)
507 509
508 BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0); 510 BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0);
509 511
510 status = ocfs2_journal_toggle_dirty(osb, 0); 512 if (ocfs2_mount_local(osb)) {
511 if (status < 0) 513 journal_lock_updates(journal->j_journal);
512 mlog_errno(status); 514 status = journal_flush(journal->j_journal);
515 journal_unlock_updates(journal->j_journal);
516 if (status < 0)
517 mlog_errno(status);
518 }
519
520 if (status == 0) {
521 /*
522 * Do not toggle if flush was unsuccessful otherwise
523 * will leave dirty metadata in a "clean" journal
524 */
525 status = ocfs2_journal_toggle_dirty(osb, 0);
526 if (status < 0)
527 mlog_errno(status);
528 }
513 529
514 /* Shutdown the kernel journal system */ 530 /* Shutdown the kernel journal system */
515 journal_destroy(journal->j_journal); 531 journal_destroy(journal->j_journal);
@@ -549,7 +565,7 @@ static void ocfs2_clear_journal_error(struct super_block *sb,
549 } 565 }
550} 566}
551 567
552int ocfs2_journal_load(struct ocfs2_journal *journal) 568int ocfs2_journal_load(struct ocfs2_journal *journal, int local)
553{ 569{
554 int status = 0; 570 int status = 0;
555 struct ocfs2_super *osb; 571 struct ocfs2_super *osb;
@@ -576,14 +592,18 @@ int ocfs2_journal_load(struct ocfs2_journal *journal)
576 } 592 }
577 593
578 /* Launch the commit thread */ 594 /* Launch the commit thread */
579 osb->commit_task = kthread_run(ocfs2_commit_thread, osb, "ocfs2cmt"); 595 if (!local) {
580 if (IS_ERR(osb->commit_task)) { 596 osb->commit_task = kthread_run(ocfs2_commit_thread, osb,
581 status = PTR_ERR(osb->commit_task); 597 "ocfs2cmt");
598 if (IS_ERR(osb->commit_task)) {
599 status = PTR_ERR(osb->commit_task);
600 osb->commit_task = NULL;
601 mlog(ML_ERROR, "unable to launch ocfs2commit thread, "
602 "error=%d", status);
603 goto done;
604 }
605 } else
582 osb->commit_task = NULL; 606 osb->commit_task = NULL;
583 mlog(ML_ERROR, "unable to launch ocfs2commit thread, error=%d",
584 status);
585 goto done;
586 }
587 607
588done: 608done:
589 mlog_exit(status); 609 mlog_exit(status);
diff --git a/fs/ocfs2/journal.h b/fs/ocfs2/journal.h
index 899112ad8136..e1216364d191 100644
--- a/fs/ocfs2/journal.h
+++ b/fs/ocfs2/journal.h
@@ -157,7 +157,7 @@ int ocfs2_journal_init(struct ocfs2_journal *journal,
157void ocfs2_journal_shutdown(struct ocfs2_super *osb); 157void ocfs2_journal_shutdown(struct ocfs2_super *osb);
158int ocfs2_journal_wipe(struct ocfs2_journal *journal, 158int ocfs2_journal_wipe(struct ocfs2_journal *journal,
159 int full); 159 int full);
160int ocfs2_journal_load(struct ocfs2_journal *journal); 160int ocfs2_journal_load(struct ocfs2_journal *journal, int local);
161int ocfs2_check_journals_nolocks(struct ocfs2_super *osb); 161int ocfs2_check_journals_nolocks(struct ocfs2_super *osb);
162void ocfs2_recovery_thread(struct ocfs2_super *osb, 162void ocfs2_recovery_thread(struct ocfs2_super *osb,
163 int node_num); 163 int node_num);
@@ -174,6 +174,9 @@ static inline void ocfs2_checkpoint_inode(struct inode *inode)
174{ 174{
175 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 175 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
176 176
177 if (ocfs2_mount_local(osb))
178 return;
179
177 if (!ocfs2_inode_fully_checkpointed(inode)) { 180 if (!ocfs2_inode_fully_checkpointed(inode)) {
178 /* WARNING: This only kicks off a single 181 /* WARNING: This only kicks off a single
179 * checkpoint. If someone races you and adds more 182 * checkpoint. If someone races you and adds more
diff --git a/fs/ocfs2/mmap.c b/fs/ocfs2/mmap.c
index 69f85ae392dc..51b020447683 100644
--- a/fs/ocfs2/mmap.c
+++ b/fs/ocfs2/mmap.c
@@ -83,10 +83,12 @@ static struct vm_operations_struct ocfs2_file_vm_ops = {
83int ocfs2_mmap(struct file *file, struct vm_area_struct *vma) 83int ocfs2_mmap(struct file *file, struct vm_area_struct *vma)
84{ 84{
85 int ret = 0, lock_level = 0; 85 int ret = 0, lock_level = 0;
86 struct ocfs2_super *osb = OCFS2_SB(file->f_dentry->d_inode->i_sb);
86 87
87 /* We don't want to support shared writable mappings yet. */ 88 /* We don't want to support shared writable mappings yet. */
88 if (((vma->vm_flags & VM_SHARED) || (vma->vm_flags & VM_MAYSHARE)) 89 if (!ocfs2_mount_local(osb) &&
89 && ((vma->vm_flags & VM_WRITE) || (vma->vm_flags & VM_MAYWRITE))) { 90 ((vma->vm_flags & VM_SHARED) || (vma->vm_flags & VM_MAYSHARE)) &&
91 ((vma->vm_flags & VM_WRITE) || (vma->vm_flags & VM_MAYWRITE))) {
90 mlog(0, "disallow shared writable mmaps %lx\n", vma->vm_flags); 92 mlog(0, "disallow shared writable mmaps %lx\n", vma->vm_flags);
91 /* This is -EINVAL because generic_file_readonly_mmap 93 /* This is -EINVAL because generic_file_readonly_mmap
92 * returns it in a similar situation. */ 94 * returns it in a similar situation. */
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 21db45ddf144..9637039c2633 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -587,9 +587,11 @@ static int ocfs2_mknod_locked(struct ocfs2_super *osb,
587 } 587 }
588 588
589 ocfs2_inode_set_new(osb, inode); 589 ocfs2_inode_set_new(osb, inode);
590 status = ocfs2_create_new_inode_locks(inode); 590 if (!ocfs2_mount_local(osb)) {
591 if (status < 0) 591 status = ocfs2_create_new_inode_locks(inode);
592 mlog_errno(status); 592 if (status < 0)
593 mlog_errno(status);
594 }
593 595
594 status = 0; /* error in ocfs2_create_new_inode_locks is not 596 status = 0; /* error in ocfs2_create_new_inode_locks is not
595 * critical */ 597 * critical */
diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
index b767fd7da6eb..db8e77cd35d3 100644
--- a/fs/ocfs2/ocfs2.h
+++ b/fs/ocfs2/ocfs2.h
@@ -349,6 +349,11 @@ static inline int ocfs2_is_soft_readonly(struct ocfs2_super *osb)
349 return ret; 349 return ret;
350} 350}
351 351
352static inline int ocfs2_mount_local(struct ocfs2_super *osb)
353{
354 return (osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT);
355}
356
352#define OCFS2_IS_VALID_DINODE(ptr) \ 357#define OCFS2_IS_VALID_DINODE(ptr) \
353 (!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE)) 358 (!strcmp((ptr)->i_signature, OCFS2_INODE_SIGNATURE))
354 359
diff --git a/fs/ocfs2/ocfs2_fs.h b/fs/ocfs2/ocfs2_fs.h
index 3330a5dc6be2..b5c68567077e 100644
--- a/fs/ocfs2/ocfs2_fs.h
+++ b/fs/ocfs2/ocfs2_fs.h
@@ -86,7 +86,7 @@
86 OCFS2_SB(sb)->s_feature_incompat &= ~(mask) 86 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
87 87
88#define OCFS2_FEATURE_COMPAT_SUPP 0 88#define OCFS2_FEATURE_COMPAT_SUPP 0
89#define OCFS2_FEATURE_INCOMPAT_SUPP 0 89#define OCFS2_FEATURE_INCOMPAT_SUPP OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT
90#define OCFS2_FEATURE_RO_COMPAT_SUPP 0 90#define OCFS2_FEATURE_RO_COMPAT_SUPP 0
91 91
92/* 92/*
@@ -96,6 +96,18 @@
96 */ 96 */
97#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 97#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
98 98
99/*
100 * tunefs sets this incompat flag before starting the resize and clears it
101 * at the end. This flag protects users from inadvertently mounting the fs
102 * after an aborted run without fsck-ing.
103 */
104#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
105
106/* Used to denote a non-clustered volume */
107#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
108
109/* Support for sparse allocation in b-trees */
110#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
99 111
100/* 112/*
101 * Flags on ocfs2_dinode.i_flags 113 * Flags on ocfs2_dinode.i_flags
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 4bf39540e652..a6d2f8cc165b 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -508,6 +508,27 @@ bail:
508 return status; 508 return status;
509} 509}
510 510
511static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
512{
513 if (ocfs2_mount_local(osb)) {
514 if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
515 mlog(ML_ERROR, "Cannot heartbeat on a locally "
516 "mounted device.\n");
517 return -EINVAL;
518 }
519 }
520
521 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
522 if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb)) {
523 mlog(ML_ERROR, "Heartbeat has to be started to mount "
524 "a read-write clustered device.\n");
525 return -EINVAL;
526 }
527 }
528
529 return 0;
530}
531
511static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) 532static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
512{ 533{
513 struct dentry *root; 534 struct dentry *root;
@@ -516,16 +537,24 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
516 struct inode *inode = NULL; 537 struct inode *inode = NULL;
517 struct ocfs2_super *osb = NULL; 538 struct ocfs2_super *osb = NULL;
518 struct buffer_head *bh = NULL; 539 struct buffer_head *bh = NULL;
540 char nodestr[8];
519 541
520 mlog_entry("%p, %p, %i", sb, data, silent); 542 mlog_entry("%p, %p, %i", sb, data, silent);
521 543
522 /* for now we only have one cluster/node, make sure we see it 544 if (!ocfs2_parse_options(sb, data, &parsed_opt, 0)) {
523 * in the heartbeat universe */
524 if (!o2hb_check_local_node_heartbeating()) {
525 status = -EINVAL; 545 status = -EINVAL;
526 goto read_super_error; 546 goto read_super_error;
527 } 547 }
528 548
549 /* for now we only have one cluster/node, make sure we see it
550 * in the heartbeat universe */
551 if (parsed_opt & OCFS2_MOUNT_HB_LOCAL) {
552 if (!o2hb_check_local_node_heartbeating()) {
553 status = -EINVAL;
554 goto read_super_error;
555 }
556 }
557
529 /* probe for superblock */ 558 /* probe for superblock */
530 status = ocfs2_sb_probe(sb, &bh, &sector_size); 559 status = ocfs2_sb_probe(sb, &bh, &sector_size);
531 if (status < 0) { 560 if (status < 0) {
@@ -541,11 +570,6 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
541 } 570 }
542 brelse(bh); 571 brelse(bh);
543 bh = NULL; 572 bh = NULL;
544
545 if (!ocfs2_parse_options(sb, data, &parsed_opt, 0)) {
546 status = -EINVAL;
547 goto read_super_error;
548 }
549 osb->s_mount_opt = parsed_opt; 573 osb->s_mount_opt = parsed_opt;
550 574
551 sb->s_magic = OCFS2_SUPER_MAGIC; 575 sb->s_magic = OCFS2_SUPER_MAGIC;
@@ -588,21 +612,16 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
588 } 612 }
589 613
590 if (!ocfs2_is_hard_readonly(osb)) { 614 if (!ocfs2_is_hard_readonly(osb)) {
591 /* If this isn't a hard readonly mount, then we need
592 * to make sure that heartbeat is in a valid state,
593 * and that we mark ourselves soft readonly is -oro
594 * was specified. */
595 if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
596 mlog(ML_ERROR, "No heartbeat for device (%s)\n",
597 sb->s_id);
598 status = -EINVAL;
599 goto read_super_error;
600 }
601
602 if (sb->s_flags & MS_RDONLY) 615 if (sb->s_flags & MS_RDONLY)
603 ocfs2_set_ro_flag(osb, 0); 616 ocfs2_set_ro_flag(osb, 0);
604 } 617 }
605 618
619 status = ocfs2_verify_heartbeat(osb);
620 if (status < 0) {
621 mlog_errno(status);
622 goto read_super_error;
623 }
624
606 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str, 625 osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
607 ocfs2_debugfs_root); 626 ocfs2_debugfs_root);
608 if (!osb->osb_debug_root) { 627 if (!osb->osb_debug_root) {
@@ -635,9 +654,14 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
635 654
636 ocfs2_complete_mount_recovery(osb); 655 ocfs2_complete_mount_recovery(osb);
637 656
638 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %d, slot %d) " 657 if (ocfs2_mount_local(osb))
658 snprintf(nodestr, sizeof(nodestr), "local");
659 else
660 snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
661
662 printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
639 "with %s data mode.\n", 663 "with %s data mode.\n",
640 osb->dev_str, osb->node_num, osb->slot_num, 664 osb->dev_str, nodestr, osb->slot_num,
641 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" : 665 osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
642 "ordered"); 666 "ordered");
643 667
@@ -999,7 +1023,11 @@ static int ocfs2_fill_local_node_info(struct ocfs2_super *osb)
999 1023
1000 /* XXX hold a ref on the node while mounte? easy enough, if 1024 /* XXX hold a ref on the node while mounte? easy enough, if
1001 * desirable. */ 1025 * desirable. */
1002 osb->node_num = o2nm_this_node(); 1026 if (ocfs2_mount_local(osb))
1027 osb->node_num = 0;
1028 else
1029 osb->node_num = o2nm_this_node();
1030
1003 if (osb->node_num == O2NM_MAX_NODES) { 1031 if (osb->node_num == O2NM_MAX_NODES) {
1004 mlog(ML_ERROR, "could not find this host's node number\n"); 1032 mlog(ML_ERROR, "could not find this host's node number\n");
1005 status = -ENOENT; 1033 status = -ENOENT;
@@ -1084,6 +1112,9 @@ static int ocfs2_mount_volume(struct super_block *sb)
1084 goto leave; 1112 goto leave;
1085 } 1113 }
1086 1114
1115 if (ocfs2_mount_local(osb))
1116 goto leave;
1117
1087 /* This should be sent *after* we recovered our journal as it 1118 /* This should be sent *after* we recovered our journal as it
1088 * will cause other nodes to unmark us as needing 1119 * will cause other nodes to unmark us as needing
1089 * recovery. However, we need to send it *before* dropping the 1120 * recovery. However, we need to send it *before* dropping the
@@ -1114,6 +1145,7 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1114{ 1145{
1115 int tmp; 1146 int tmp;
1116 struct ocfs2_super *osb = NULL; 1147 struct ocfs2_super *osb = NULL;
1148 char nodestr[8];
1117 1149
1118 mlog_entry("(0x%p)\n", sb); 1150 mlog_entry("(0x%p)\n", sb);
1119 1151
@@ -1177,8 +1209,13 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
1177 1209
1178 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED); 1210 atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
1179 1211
1180 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %d)\n", 1212 if (ocfs2_mount_local(osb))
1181 osb->dev_str, osb->node_num); 1213 snprintf(nodestr, sizeof(nodestr), "local");
1214 else
1215 snprintf(nodestr, sizeof(nodestr), "%d", osb->node_num);
1216
1217 printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
1218 osb->dev_str, nodestr);
1182 1219
1183 ocfs2_delete_osb(osb); 1220 ocfs2_delete_osb(osb);
1184 kfree(osb); 1221 kfree(osb);
@@ -1536,6 +1573,7 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
1536{ 1573{
1537 int status = 0; 1574 int status = 0;
1538 int dirty; 1575 int dirty;
1576 int local;
1539 struct ocfs2_dinode *local_alloc = NULL; /* only used if we 1577 struct ocfs2_dinode *local_alloc = NULL; /* only used if we
1540 * recover 1578 * recover
1541 * ourselves. */ 1579 * ourselves. */
@@ -1563,8 +1601,10 @@ static int ocfs2_check_volume(struct ocfs2_super *osb)
1563 "recovering volume.\n"); 1601 "recovering volume.\n");
1564 } 1602 }
1565 1603
1604 local = ocfs2_mount_local(osb);
1605
1566 /* will play back anything left in the journal. */ 1606 /* will play back anything left in the journal. */
1567 ocfs2_journal_load(osb->journal); 1607 ocfs2_journal_load(osb->journal, local);
1568 1608
1569 if (dirty) { 1609 if (dirty) {
1570 /* recover my local alloc if we didn't unmount cleanly. */ 1610 /* recover my local alloc if we didn't unmount cleanly. */
diff --git a/fs/ocfs2/vote.c b/fs/ocfs2/vote.c
index 5b4dca79990b..0315a8b61ed6 100644
--- a/fs/ocfs2/vote.c
+++ b/fs/ocfs2/vote.c
@@ -1000,6 +1000,9 @@ int ocfs2_register_net_handlers(struct ocfs2_super *osb)
1000{ 1000{
1001 int status = 0; 1001 int status = 0;
1002 1002
1003 if (ocfs2_mount_local(osb))
1004 return 0;
1005
1003 status = o2net_register_handler(OCFS2_MESSAGE_TYPE_RESPONSE, 1006 status = o2net_register_handler(OCFS2_MESSAGE_TYPE_RESPONSE,
1004 osb->net_key, 1007 osb->net_key,
1005 sizeof(struct ocfs2_response_msg), 1008 sizeof(struct ocfs2_response_msg),
diff --git a/fs/open.c b/fs/open.c
index 89e0c237a636..c989fb4cf7b9 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -165,7 +165,7 @@ asmlinkage long sys_fstatfs(unsigned int fd, struct statfs __user * buf)
165 file = fget(fd); 165 file = fget(fd);
166 if (!file) 166 if (!file)
167 goto out; 167 goto out;
168 error = vfs_statfs_native(file->f_dentry, &tmp); 168 error = vfs_statfs_native(file->f_path.dentry, &tmp);
169 if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) 169 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
170 error = -EFAULT; 170 error = -EFAULT;
171 fput(file); 171 fput(file);
@@ -186,7 +186,7 @@ asmlinkage long sys_fstatfs64(unsigned int fd, size_t sz, struct statfs64 __user
186 file = fget(fd); 186 file = fget(fd);
187 if (!file) 187 if (!file)
188 goto out; 188 goto out;
189 error = vfs_statfs64(file->f_dentry, &tmp); 189 error = vfs_statfs64(file->f_path.dentry, &tmp);
190 if (!error && copy_to_user(buf, &tmp, sizeof(tmp))) 190 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
191 error = -EFAULT; 191 error = -EFAULT;
192 fput(file); 192 fput(file);
@@ -302,7 +302,7 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
302 if (file->f_flags & O_LARGEFILE) 302 if (file->f_flags & O_LARGEFILE)
303 small = 0; 303 small = 0;
304 304
305 dentry = file->f_dentry; 305 dentry = file->f_path.dentry;
306 inode = dentry->d_inode; 306 inode = dentry->d_inode;
307 error = -EINVAL; 307 error = -EINVAL;
308 if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE)) 308 if (!S_ISREG(inode->i_mode) || !(file->f_mode & FMODE_WRITE))
@@ -448,8 +448,8 @@ asmlinkage long sys_fchdir(unsigned int fd)
448 if (!file) 448 if (!file)
449 goto out; 449 goto out;
450 450
451 dentry = file->f_dentry; 451 dentry = file->f_path.dentry;
452 mnt = file->f_vfsmnt; 452 mnt = file->f_path.mnt;
453 inode = dentry->d_inode; 453 inode = dentry->d_inode;
454 454
455 error = -ENOTDIR; 455 error = -ENOTDIR;
@@ -503,7 +503,7 @@ asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
503 if (!file) 503 if (!file)
504 goto out; 504 goto out;
505 505
506 dentry = file->f_dentry; 506 dentry = file->f_path.dentry;
507 inode = dentry->d_inode; 507 inode = dentry->d_inode;
508 508
509 audit_inode(NULL, inode); 509 audit_inode(NULL, inode);
@@ -662,7 +662,7 @@ asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group)
662 if (!file) 662 if (!file)
663 goto out; 663 goto out;
664 664
665 dentry = file->f_dentry; 665 dentry = file->f_path.dentry;
666 audit_inode(NULL, dentry->d_inode); 666 audit_inode(NULL, dentry->d_inode);
667 error = chown_common(dentry, user, group); 667 error = chown_common(dentry, user, group);
668 fput(file); 668 fput(file);
@@ -688,8 +688,8 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
688 } 688 }
689 689
690 f->f_mapping = inode->i_mapping; 690 f->f_mapping = inode->i_mapping;
691 f->f_dentry = dentry; 691 f->f_path.dentry = dentry;
692 f->f_vfsmnt = mnt; 692 f->f_path.mnt = mnt;
693 f->f_pos = 0; 693 f->f_pos = 0;
694 f->f_op = fops_get(inode->i_fop); 694 f->f_op = fops_get(inode->i_fop);
695 file_move(f, &inode->i_sb->s_files); 695 file_move(f, &inode->i_sb->s_files);
@@ -723,8 +723,8 @@ cleanup_all:
723 if (f->f_mode & FMODE_WRITE) 723 if (f->f_mode & FMODE_WRITE)
724 put_write_access(inode); 724 put_write_access(inode);
725 file_kill(f); 725 file_kill(f);
726 f->f_dentry = NULL; 726 f->f_path.dentry = NULL;
727 f->f_vfsmnt = NULL; 727 f->f_path.mnt = NULL;
728cleanup_file: 728cleanup_file:
729 put_filp(f); 729 put_filp(f);
730 dput(dentry); 730 dput(dentry);
@@ -822,7 +822,7 @@ struct file *nameidata_to_filp(struct nameidata *nd, int flags)
822 /* Pick up the filp from the open intent */ 822 /* Pick up the filp from the open intent */
823 filp = nd->intent.open.file; 823 filp = nd->intent.open.file;
824 /* Has the filesystem initialised the file for us? */ 824 /* Has the filesystem initialised the file for us? */
825 if (filp->f_dentry == NULL) 825 if (filp->f_path.dentry == NULL)
826 filp = __dentry_open(nd->dentry, nd->mnt, flags, filp, NULL); 826 filp = __dentry_open(nd->dentry, nd->mnt, flags, filp, NULL);
827 else 827 else
828 path_release(nd); 828 path_release(nd);
@@ -864,8 +864,7 @@ int get_unused_fd(void)
864 864
865repeat: 865repeat:
866 fdt = files_fdtable(files); 866 fdt = files_fdtable(files);
867 fd = find_next_zero_bit(fdt->open_fds->fds_bits, 867 fd = find_next_zero_bit(fdt->open_fds->fds_bits, fdt->max_fds,
868 fdt->max_fdset,
869 files->next_fd); 868 files->next_fd);
870 869
871 /* 870 /*
@@ -965,7 +964,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, int mode)
965 put_unused_fd(fd); 964 put_unused_fd(fd);
966 fd = PTR_ERR(f); 965 fd = PTR_ERR(f);
967 } else { 966 } else {
968 fsnotify_open(f->f_dentry); 967 fsnotify_open(f->f_path.dentry);
969 fd_install(fd, f); 968 fd_install(fd, f);
970 } 969 }
971 } 970 }
@@ -1087,6 +1086,7 @@ EXPORT_SYMBOL(sys_close);
1087asmlinkage long sys_vhangup(void) 1086asmlinkage long sys_vhangup(void)
1088{ 1087{
1089 if (capable(CAP_SYS_TTY_CONFIG)) { 1088 if (capable(CAP_SYS_TTY_CONFIG)) {
1089 /* XXX: this needs locking */
1090 tty_vhangup(current->signal->tty); 1090 tty_vhangup(current->signal->tty);
1091 return 0; 1091 return 0;
1092 } 1092 }
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index 26f44e0074ec..99c0bc37ba09 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -262,7 +262,7 @@ found:
262 262
263static int openpromfs_readdir(struct file * filp, void * dirent, filldir_t filldir) 263static int openpromfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
264{ 264{
265 struct inode *inode = filp->f_dentry->d_inode; 265 struct inode *inode = filp->f_path.dentry->d_inode;
266 struct op_inode_info *oi = OP_I(inode); 266 struct op_inode_info *oi = OP_I(inode);
267 struct device_node *dp = oi->u.node; 267 struct device_node *dp = oi->u.node;
268 struct device_node *child; 268 struct device_node *child;
diff --git a/fs/partitions/Kconfig b/fs/partitions/Kconfig
index e478f1941831..74552c60b671 100644
--- a/fs/partitions/Kconfig
+++ b/fs/partitions/Kconfig
@@ -194,7 +194,7 @@ config LDM_DEBUG
194 194
195config SGI_PARTITION 195config SGI_PARTITION
196 bool "SGI partition support" if PARTITION_ADVANCED 196 bool "SGI partition support" if PARTITION_ADVANCED
197 default y if (SGI_IP22 || SGI_IP27 || ((MACH_JAZZ || SNI_RM200_PCI) && !CPU_LITTLE_ENDIAN)) 197 default y if (SGI_IP22 || SGI_IP27 || ((MACH_JAZZ || SNI_RM) && !CPU_LITTLE_ENDIAN))
198 help 198 help
199 Say Y here if you would like to be able to read the hard disk 199 Say Y here if you would like to be able to read the hard disk
200 partition table format used by SGI machines. 200 partition table format used by SGI machines.
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 1901137f4eca..3d73d94d93a7 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -276,12 +276,39 @@ static struct part_attribute part_attr_stat = {
276 .show = part_stat_read 276 .show = part_stat_read
277}; 277};
278 278
279#ifdef CONFIG_FAIL_MAKE_REQUEST
280
281static ssize_t part_fail_store(struct hd_struct * p,
282 const char *buf, size_t count)
283{
284 int i;
285
286 if (count > 0 && sscanf(buf, "%d", &i) > 0)
287 p->make_it_fail = (i == 0) ? 0 : 1;
288
289 return count;
290}
291static ssize_t part_fail_read(struct hd_struct * p, char *page)
292{
293 return sprintf(page, "%d\n", p->make_it_fail);
294}
295static struct part_attribute part_attr_fail = {
296 .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
297 .store = part_fail_store,
298 .show = part_fail_read
299};
300
301#endif
302
279static struct attribute * default_attrs[] = { 303static struct attribute * default_attrs[] = {
280 &part_attr_uevent.attr, 304 &part_attr_uevent.attr,
281 &part_attr_dev.attr, 305 &part_attr_dev.attr,
282 &part_attr_start.attr, 306 &part_attr_start.attr,
283 &part_attr_size.attr, 307 &part_attr_size.attr,
284 &part_attr_stat.attr, 308 &part_attr_stat.attr,
309#ifdef CONFIG_FAIL_MAKE_REQUEST
310 &part_attr_fail.attr,
311#endif
285 NULL, 312 NULL,
286}; 313};
287 314
diff --git a/fs/pipe.c b/fs/pipe.c
index ae36b89b1a37..f8b6bdcb879a 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -222,7 +222,7 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
222 unsigned long nr_segs, loff_t pos) 222 unsigned long nr_segs, loff_t pos)
223{ 223{
224 struct file *filp = iocb->ki_filp; 224 struct file *filp = iocb->ki_filp;
225 struct inode *inode = filp->f_dentry->d_inode; 225 struct inode *inode = filp->f_path.dentry->d_inode;
226 struct pipe_inode_info *pipe; 226 struct pipe_inode_info *pipe;
227 int do_wakeup; 227 int do_wakeup;
228 ssize_t ret; 228 ssize_t ret;
@@ -335,7 +335,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
335 unsigned long nr_segs, loff_t ppos) 335 unsigned long nr_segs, loff_t ppos)
336{ 336{
337 struct file *filp = iocb->ki_filp; 337 struct file *filp = iocb->ki_filp;
338 struct inode *inode = filp->f_dentry->d_inode; 338 struct inode *inode = filp->f_path.dentry->d_inode;
339 struct pipe_inode_info *pipe; 339 struct pipe_inode_info *pipe;
340 ssize_t ret; 340 ssize_t ret;
341 int do_wakeup; 341 int do_wakeup;
@@ -520,7 +520,7 @@ static int
520pipe_ioctl(struct inode *pino, struct file *filp, 520pipe_ioctl(struct inode *pino, struct file *filp,
521 unsigned int cmd, unsigned long arg) 521 unsigned int cmd, unsigned long arg)
522{ 522{
523 struct inode *inode = filp->f_dentry->d_inode; 523 struct inode *inode = filp->f_path.dentry->d_inode;
524 struct pipe_inode_info *pipe; 524 struct pipe_inode_info *pipe;
525 int count, buf, nrbufs; 525 int count, buf, nrbufs;
526 526
@@ -548,7 +548,7 @@ static unsigned int
548pipe_poll(struct file *filp, poll_table *wait) 548pipe_poll(struct file *filp, poll_table *wait)
549{ 549{
550 unsigned int mask; 550 unsigned int mask;
551 struct inode *inode = filp->f_dentry->d_inode; 551 struct inode *inode = filp->f_path.dentry->d_inode;
552 struct pipe_inode_info *pipe = inode->i_pipe; 552 struct pipe_inode_info *pipe = inode->i_pipe;
553 int nrbufs; 553 int nrbufs;
554 554
@@ -601,7 +601,7 @@ pipe_release(struct inode *inode, int decr, int decw)
601static int 601static int
602pipe_read_fasync(int fd, struct file *filp, int on) 602pipe_read_fasync(int fd, struct file *filp, int on)
603{ 603{
604 struct inode *inode = filp->f_dentry->d_inode; 604 struct inode *inode = filp->f_path.dentry->d_inode;
605 int retval; 605 int retval;
606 606
607 mutex_lock(&inode->i_mutex); 607 mutex_lock(&inode->i_mutex);
@@ -618,7 +618,7 @@ pipe_read_fasync(int fd, struct file *filp, int on)
618static int 618static int
619pipe_write_fasync(int fd, struct file *filp, int on) 619pipe_write_fasync(int fd, struct file *filp, int on)
620{ 620{
621 struct inode *inode = filp->f_dentry->d_inode; 621 struct inode *inode = filp->f_path.dentry->d_inode;
622 int retval; 622 int retval;
623 623
624 mutex_lock(&inode->i_mutex); 624 mutex_lock(&inode->i_mutex);
@@ -635,7 +635,7 @@ pipe_write_fasync(int fd, struct file *filp, int on)
635static int 635static int
636pipe_rdwr_fasync(int fd, struct file *filp, int on) 636pipe_rdwr_fasync(int fd, struct file *filp, int on)
637{ 637{
638 struct inode *inode = filp->f_dentry->d_inode; 638 struct inode *inode = filp->f_path.dentry->d_inode;
639 struct pipe_inode_info *pipe = inode->i_pipe; 639 struct pipe_inode_info *pipe = inode->i_pipe;
640 int retval; 640 int retval;
641 641
@@ -914,8 +914,8 @@ struct file *create_write_pipe(void)
914 */ 914 */
915 dentry->d_flags &= ~DCACHE_UNHASHED; 915 dentry->d_flags &= ~DCACHE_UNHASHED;
916 d_instantiate(dentry, inode); 916 d_instantiate(dentry, inode);
917 f->f_vfsmnt = mntget(pipe_mnt); 917 f->f_path.mnt = mntget(pipe_mnt);
918 f->f_dentry = dentry; 918 f->f_path.dentry = dentry;
919 f->f_mapping = inode->i_mapping; 919 f->f_mapping = inode->i_mapping;
920 920
921 f->f_flags = O_WRONLY; 921 f->f_flags = O_WRONLY;
@@ -935,8 +935,8 @@ struct file *create_write_pipe(void)
935 935
936void free_write_pipe(struct file *f) 936void free_write_pipe(struct file *f)
937{ 937{
938 mntput(f->f_vfsmnt); 938 mntput(f->f_path.mnt);
939 dput(f->f_dentry); 939 dput(f->f_path.dentry);
940 put_filp(f); 940 put_filp(f);
941} 941}
942 942
@@ -947,9 +947,9 @@ struct file *create_read_pipe(struct file *wrf)
947 return ERR_PTR(-ENFILE); 947 return ERR_PTR(-ENFILE);
948 948
949 /* Grab pipe from the writer */ 949 /* Grab pipe from the writer */
950 f->f_vfsmnt = mntget(wrf->f_vfsmnt); 950 f->f_path.mnt = mntget(wrf->f_path.mnt);
951 f->f_dentry = dget(wrf->f_dentry); 951 f->f_path.dentry = dget(wrf->f_path.dentry);
952 f->f_mapping = wrf->f_dentry->d_inode->i_mapping; 952 f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping;
953 953
954 f->f_pos = 0; 954 f->f_pos = 0;
955 f->f_flags = O_RDONLY; 955 f->f_flags = O_RDONLY;
diff --git a/fs/pnode.c b/fs/pnode.c
index da42ee61c1df..56aacead8362 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -6,7 +6,7 @@
6 * Author : Ram Pai (linuxram@us.ibm.com) 6 * Author : Ram Pai (linuxram@us.ibm.com)
7 * 7 *
8 */ 8 */
9#include <linux/namespace.h> 9#include <linux/mnt_namespace.h>
10#include <linux/mount.h> 10#include <linux/mount.h>
11#include <linux/fs.h> 11#include <linux/fs.h>
12#include "pnode.h" 12#include "pnode.h"
diff --git a/fs/pnode.h b/fs/pnode.h
index 020e1bb60fdb..d45bd8ec36bf 100644
--- a/fs/pnode.h
+++ b/fs/pnode.h
@@ -13,7 +13,7 @@
13 13
14#define IS_MNT_SHARED(mnt) (mnt->mnt_flags & MNT_SHARED) 14#define IS_MNT_SHARED(mnt) (mnt->mnt_flags & MNT_SHARED)
15#define IS_MNT_SLAVE(mnt) (mnt->mnt_master) 15#define IS_MNT_SLAVE(mnt) (mnt->mnt_master)
16#define IS_MNT_NEW(mnt) (!mnt->mnt_namespace) 16#define IS_MNT_NEW(mnt) (!mnt->mnt_ns)
17#define CLEAR_MNT_SHARED(mnt) (mnt->mnt_flags &= ~MNT_SHARED) 17#define CLEAR_MNT_SHARED(mnt) (mnt->mnt_flags &= ~MNT_SHARED)
18#define IS_MNT_UNBINDABLE(mnt) (mnt->mnt_flags & MNT_UNBINDABLE) 18#define IS_MNT_UNBINDABLE(mnt) (mnt->mnt_flags & MNT_UNBINDABLE)
19 19
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 25e917fb4739..70e4fab117b1 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -346,20 +346,13 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
346 sigemptyset(&sigcatch); 346 sigemptyset(&sigcatch);
347 cutime = cstime = utime = stime = cputime_zero; 347 cutime = cstime = utime = stime = cputime_zero;
348 348
349 mutex_lock(&tty_mutex);
350 rcu_read_lock(); 349 rcu_read_lock();
351 if (lock_task_sighand(task, &flags)) { 350 if (lock_task_sighand(task, &flags)) {
352 struct signal_struct *sig = task->signal; 351 struct signal_struct *sig = task->signal;
353 struct tty_struct *tty = sig->tty; 352
354 353 if (sig->tty) {
355 if (tty) { 354 tty_pgrp = sig->tty->pgrp;
356 /* 355 tty_nr = new_encode_dev(tty_devnum(sig->tty));
357 * sig->tty is not stable, but tty_mutex
358 * protects us from release_dev(tty)
359 */
360 barrier();
361 tty_pgrp = tty->pgrp;
362 tty_nr = new_encode_dev(tty_devnum(tty));
363 } 356 }
364 357
365 num_threads = atomic_read(&sig->count); 358 num_threads = atomic_read(&sig->count);
@@ -388,14 +381,13 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
388 stime = cputime_add(stime, sig->stime); 381 stime = cputime_add(stime, sig->stime);
389 } 382 }
390 383
391 sid = sig->session; 384 sid = signal_session(sig);
392 pgid = process_group(task); 385 pgid = process_group(task);
393 ppid = rcu_dereference(task->real_parent)->tgid; 386 ppid = rcu_dereference(task->real_parent)->tgid;
394 387
395 unlock_task_sighand(task, &flags); 388 unlock_task_sighand(task, &flags);
396 } 389 }
397 rcu_read_unlock(); 390 rcu_read_unlock();
398 mutex_unlock(&tty_mutex);
399 391
400 if (!whole || num_threads<2) 392 if (!whole || num_threads<2)
401 wchan = get_wchan(task); 393 wchan = get_wchan(task);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b859fc749c07..77a57b5799c4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -59,7 +59,7 @@
59#include <linux/string.h> 59#include <linux/string.h>
60#include <linux/seq_file.h> 60#include <linux/seq_file.h>
61#include <linux/namei.h> 61#include <linux/namei.h>
62#include <linux/namespace.h> 62#include <linux/mnt_namespace.h>
63#include <linux/mm.h> 63#include <linux/mm.h>
64#include <linux/smp_lock.h> 64#include <linux/smp_lock.h>
65#include <linux/rcupdate.h> 65#include <linux/rcupdate.h>
@@ -365,33 +365,33 @@ struct proc_mounts {
365static int mounts_open(struct inode *inode, struct file *file) 365static int mounts_open(struct inode *inode, struct file *file)
366{ 366{
367 struct task_struct *task = get_proc_task(inode); 367 struct task_struct *task = get_proc_task(inode);
368 struct namespace *namespace = NULL; 368 struct mnt_namespace *ns = NULL;
369 struct proc_mounts *p; 369 struct proc_mounts *p;
370 int ret = -EINVAL; 370 int ret = -EINVAL;
371 371
372 if (task) { 372 if (task) {
373 task_lock(task); 373 task_lock(task);
374 namespace = task->nsproxy->namespace; 374 ns = task->nsproxy->mnt_ns;
375 if (namespace) 375 if (ns)
376 get_namespace(namespace); 376 get_mnt_ns(ns);
377 task_unlock(task); 377 task_unlock(task);
378 put_task_struct(task); 378 put_task_struct(task);
379 } 379 }
380 380
381 if (namespace) { 381 if (ns) {
382 ret = -ENOMEM; 382 ret = -ENOMEM;
383 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); 383 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
384 if (p) { 384 if (p) {
385 file->private_data = &p->m; 385 file->private_data = &p->m;
386 ret = seq_open(file, &mounts_op); 386 ret = seq_open(file, &mounts_op);
387 if (!ret) { 387 if (!ret) {
388 p->m.private = namespace; 388 p->m.private = ns;
389 p->event = namespace->event; 389 p->event = ns->event;
390 return 0; 390 return 0;
391 } 391 }
392 kfree(p); 392 kfree(p);
393 } 393 }
394 put_namespace(namespace); 394 put_mnt_ns(ns);
395 } 395 }
396 return ret; 396 return ret;
397} 397}
@@ -399,15 +399,15 @@ static int mounts_open(struct inode *inode, struct file *file)
399static int mounts_release(struct inode *inode, struct file *file) 399static int mounts_release(struct inode *inode, struct file *file)
400{ 400{
401 struct seq_file *m = file->private_data; 401 struct seq_file *m = file->private_data;
402 struct namespace *namespace = m->private; 402 struct mnt_namespace *ns = m->private;
403 put_namespace(namespace); 403 put_mnt_ns(ns);
404 return seq_release(inode, file); 404 return seq_release(inode, file);
405} 405}
406 406
407static unsigned mounts_poll(struct file *file, poll_table *wait) 407static unsigned mounts_poll(struct file *file, poll_table *wait)
408{ 408{
409 struct proc_mounts *p = file->private_data; 409 struct proc_mounts *p = file->private_data;
410 struct namespace *ns = p->m.private; 410 struct mnt_namespace *ns = p->m.private;
411 unsigned res = 0; 411 unsigned res = 0;
412 412
413 poll_wait(file, &ns->poll, wait); 413 poll_wait(file, &ns->poll, wait);
@@ -437,21 +437,21 @@ static int mountstats_open(struct inode *inode, struct file *file)
437 437
438 if (!ret) { 438 if (!ret) {
439 struct seq_file *m = file->private_data; 439 struct seq_file *m = file->private_data;
440 struct namespace *namespace = NULL; 440 struct mnt_namespace *mnt_ns = NULL;
441 struct task_struct *task = get_proc_task(inode); 441 struct task_struct *task = get_proc_task(inode);
442 442
443 if (task) { 443 if (task) {
444 task_lock(task); 444 task_lock(task);
445 if (task->nsproxy) 445 if (task->nsproxy)
446 namespace = task->nsproxy->namespace; 446 mnt_ns = task->nsproxy->mnt_ns;
447 if (namespace) 447 if (mnt_ns)
448 get_namespace(namespace); 448 get_mnt_ns(mnt_ns);
449 task_unlock(task); 449 task_unlock(task);
450 put_task_struct(task); 450 put_task_struct(task);
451 } 451 }
452 452
453 if (namespace) 453 if (mnt_ns)
454 m->private = namespace; 454 m->private = mnt_ns;
455 else { 455 else {
456 seq_release(inode, file); 456 seq_release(inode, file);
457 ret = -EINVAL; 457 ret = -EINVAL;
@@ -472,7 +472,7 @@ static struct file_operations proc_mountstats_operations = {
472static ssize_t proc_info_read(struct file * file, char __user * buf, 472static ssize_t proc_info_read(struct file * file, char __user * buf,
473 size_t count, loff_t *ppos) 473 size_t count, loff_t *ppos)
474{ 474{
475 struct inode * inode = file->f_dentry->d_inode; 475 struct inode * inode = file->f_path.dentry->d_inode;
476 unsigned long page; 476 unsigned long page;
477 ssize_t length; 477 ssize_t length;
478 struct task_struct *task = get_proc_task(inode); 478 struct task_struct *task = get_proc_task(inode);
@@ -512,7 +512,7 @@ static int mem_open(struct inode* inode, struct file* file)
512static ssize_t mem_read(struct file * file, char __user * buf, 512static ssize_t mem_read(struct file * file, char __user * buf,
513 size_t count, loff_t *ppos) 513 size_t count, loff_t *ppos)
514{ 514{
515 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 515 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
516 char *page; 516 char *page;
517 unsigned long src = *ppos; 517 unsigned long src = *ppos;
518 int ret = -ESRCH; 518 int ret = -ESRCH;
@@ -584,7 +584,7 @@ static ssize_t mem_write(struct file * file, const char * buf,
584{ 584{
585 int copied; 585 int copied;
586 char *page; 586 char *page;
587 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 587 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
588 unsigned long dst = *ppos; 588 unsigned long dst = *ppos;
589 589
590 copied = -ESRCH; 590 copied = -ESRCH;
@@ -654,7 +654,7 @@ static struct file_operations proc_mem_operations = {
654static ssize_t oom_adjust_read(struct file *file, char __user *buf, 654static ssize_t oom_adjust_read(struct file *file, char __user *buf,
655 size_t count, loff_t *ppos) 655 size_t count, loff_t *ppos)
656{ 656{
657 struct task_struct *task = get_proc_task(file->f_dentry->d_inode); 657 struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
658 char buffer[PROC_NUMBUF]; 658 char buffer[PROC_NUMBUF];
659 size_t len; 659 size_t len;
660 int oom_adjust; 660 int oom_adjust;
@@ -694,7 +694,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
694 return -EINVAL; 694 return -EINVAL;
695 if (*end == '\n') 695 if (*end == '\n')
696 end++; 696 end++;
697 task = get_proc_task(file->f_dentry->d_inode); 697 task = get_proc_task(file->f_path.dentry->d_inode);
698 if (!task) 698 if (!task)
699 return -ESRCH; 699 return -ESRCH;
700 if (oom_adjust < task->oomkilladj && !capable(CAP_SYS_RESOURCE)) { 700 if (oom_adjust < task->oomkilladj && !capable(CAP_SYS_RESOURCE)) {
@@ -718,7 +718,7 @@ static struct file_operations proc_oom_adjust_operations = {
718static ssize_t proc_loginuid_read(struct file * file, char __user * buf, 718static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
719 size_t count, loff_t *ppos) 719 size_t count, loff_t *ppos)
720{ 720{
721 struct inode * inode = file->f_dentry->d_inode; 721 struct inode * inode = file->f_path.dentry->d_inode;
722 struct task_struct *task = get_proc_task(inode); 722 struct task_struct *task = get_proc_task(inode);
723 ssize_t length; 723 ssize_t length;
724 char tmpbuf[TMPBUFLEN]; 724 char tmpbuf[TMPBUFLEN];
@@ -734,7 +734,7 @@ static ssize_t proc_loginuid_read(struct file * file, char __user * buf,
734static ssize_t proc_loginuid_write(struct file * file, const char __user * buf, 734static ssize_t proc_loginuid_write(struct file * file, const char __user * buf,
735 size_t count, loff_t *ppos) 735 size_t count, loff_t *ppos)
736{ 736{
737 struct inode * inode = file->f_dentry->d_inode; 737 struct inode * inode = file->f_path.dentry->d_inode;
738 char *page, *tmp; 738 char *page, *tmp;
739 ssize_t length; 739 ssize_t length;
740 uid_t loginuid; 740 uid_t loginuid;
@@ -853,6 +853,65 @@ static struct file_operations proc_seccomp_operations = {
853}; 853};
854#endif /* CONFIG_SECCOMP */ 854#endif /* CONFIG_SECCOMP */
855 855
856#ifdef CONFIG_FAULT_INJECTION
857static ssize_t proc_fault_inject_read(struct file * file, char __user * buf,
858 size_t count, loff_t *ppos)
859{
860 struct task_struct *task = get_proc_task(file->f_dentry->d_inode);
861 char buffer[PROC_NUMBUF];
862 size_t len;
863 int make_it_fail;
864 loff_t __ppos = *ppos;
865
866 if (!task)
867 return -ESRCH;
868 make_it_fail = task->make_it_fail;
869 put_task_struct(task);
870
871 len = snprintf(buffer, sizeof(buffer), "%i\n", make_it_fail);
872 if (__ppos >= len)
873 return 0;
874 if (count > len-__ppos)
875 count = len-__ppos;
876 if (copy_to_user(buf, buffer + __ppos, count))
877 return -EFAULT;
878 *ppos = __ppos + count;
879 return count;
880}
881
882static ssize_t proc_fault_inject_write(struct file * file,
883 const char __user * buf, size_t count, loff_t *ppos)
884{
885 struct task_struct *task;
886 char buffer[PROC_NUMBUF], *end;
887 int make_it_fail;
888
889 if (!capable(CAP_SYS_RESOURCE))
890 return -EPERM;
891 memset(buffer, 0, sizeof(buffer));
892 if (count > sizeof(buffer) - 1)
893 count = sizeof(buffer) - 1;
894 if (copy_from_user(buffer, buf, count))
895 return -EFAULT;
896 make_it_fail = simple_strtol(buffer, &end, 0);
897 if (*end == '\n')
898 end++;
899 task = get_proc_task(file->f_dentry->d_inode);
900 if (!task)
901 return -ESRCH;
902 task->make_it_fail = make_it_fail;
903 put_task_struct(task);
904 if (end - buffer == 0)
905 return -EIO;
906 return end - buffer;
907}
908
909static struct file_operations proc_fault_inject_operations = {
910 .read = proc_fault_inject_read,
911 .write = proc_fault_inject_write,
912};
913#endif
914
856static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd) 915static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
857{ 916{
858 struct inode *inode = dentry->d_inode; 917 struct inode *inode = dentry->d_inode;
@@ -1078,7 +1137,7 @@ static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
1078 char *name, int len, 1137 char *name, int len,
1079 instantiate_t instantiate, struct task_struct *task, void *ptr) 1138 instantiate_t instantiate, struct task_struct *task, void *ptr)
1080{ 1139{
1081 struct dentry *child, *dir = filp->f_dentry; 1140 struct dentry *child, *dir = filp->f_path.dentry;
1082 struct inode *inode; 1141 struct inode *inode;
1083 struct qstr qname; 1142 struct qstr qname;
1084 ino_t ino = 0; 1143 ino_t ino = 0;
@@ -1157,8 +1216,8 @@ static int proc_fd_link(struct inode *inode, struct dentry **dentry, struct vfsm
1157 spin_lock(&files->file_lock); 1216 spin_lock(&files->file_lock);
1158 file = fcheck_files(files, fd); 1217 file = fcheck_files(files, fd);
1159 if (file) { 1218 if (file) {
1160 *mnt = mntget(file->f_vfsmnt); 1219 *mnt = mntget(file->f_path.mnt);
1161 *dentry = dget(file->f_dentry); 1220 *dentry = dget(file->f_path.dentry);
1162 spin_unlock(&files->file_lock); 1221 spin_unlock(&files->file_lock);
1163 put_files_struct(files); 1222 put_files_struct(files);
1164 return 0; 1223 return 0;
@@ -1293,7 +1352,7 @@ static int proc_fd_fill_cache(struct file *filp, void *dirent, filldir_t filldir
1293 1352
1294static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir) 1353static int proc_readfd(struct file * filp, void * dirent, filldir_t filldir)
1295{ 1354{
1296 struct dentry *dentry = filp->f_dentry; 1355 struct dentry *dentry = filp->f_path.dentry;
1297 struct inode *inode = dentry->d_inode; 1356 struct inode *inode = dentry->d_inode;
1298 struct task_struct *p = get_proc_task(inode); 1357 struct task_struct *p = get_proc_task(inode);
1299 unsigned int fd, tid, ino; 1358 unsigned int fd, tid, ino;
@@ -1440,7 +1499,7 @@ static int proc_pident_readdir(struct file *filp,
1440{ 1499{
1441 int i; 1500 int i;
1442 int pid; 1501 int pid;
1443 struct dentry *dentry = filp->f_dentry; 1502 struct dentry *dentry = filp->f_path.dentry;
1444 struct inode *inode = dentry->d_inode; 1503 struct inode *inode = dentry->d_inode;
1445 struct task_struct *task = get_proc_task(inode); 1504 struct task_struct *task = get_proc_task(inode);
1446 struct pid_entry *p, *last; 1505 struct pid_entry *p, *last;
@@ -1496,7 +1555,7 @@ out_no_task:
1496static ssize_t proc_pid_attr_read(struct file * file, char __user * buf, 1555static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
1497 size_t count, loff_t *ppos) 1556 size_t count, loff_t *ppos)
1498{ 1557{
1499 struct inode * inode = file->f_dentry->d_inode; 1558 struct inode * inode = file->f_path.dentry->d_inode;
1500 unsigned long page; 1559 unsigned long page;
1501 ssize_t length; 1560 ssize_t length;
1502 struct task_struct *task = get_proc_task(inode); 1561 struct task_struct *task = get_proc_task(inode);
@@ -1512,7 +1571,7 @@ static ssize_t proc_pid_attr_read(struct file * file, char __user * buf,
1512 goto out; 1571 goto out;
1513 1572
1514 length = security_getprocattr(task, 1573 length = security_getprocattr(task,
1515 (char*)file->f_dentry->d_name.name, 1574 (char*)file->f_path.dentry->d_name.name,
1516 (void*)page, count); 1575 (void*)page, count);
1517 if (length >= 0) 1576 if (length >= 0)
1518 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length); 1577 length = simple_read_from_buffer(buf, count, ppos, (char *)page, length);
@@ -1526,7 +1585,7 @@ out_no_task:
1526static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, 1585static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
1527 size_t count, loff_t *ppos) 1586 size_t count, loff_t *ppos)
1528{ 1587{
1529 struct inode * inode = file->f_dentry->d_inode; 1588 struct inode * inode = file->f_path.dentry->d_inode;
1530 char *page; 1589 char *page;
1531 ssize_t length; 1590 ssize_t length;
1532 struct task_struct *task = get_proc_task(inode); 1591 struct task_struct *task = get_proc_task(inode);
@@ -1552,7 +1611,7 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
1552 goto out_free; 1611 goto out_free;
1553 1612
1554 length = security_setprocattr(task, 1613 length = security_setprocattr(task,
1555 (char*)file->f_dentry->d_name.name, 1614 (char*)file->f_path.dentry->d_name.name,
1556 (void*)page, count); 1615 (void*)page, count);
1557out_free: 1616out_free:
1558 free_page((unsigned long) page); 1617 free_page((unsigned long) page);
@@ -1745,6 +1804,27 @@ static int proc_base_fill_cache(struct file *filp, void *dirent, filldir_t filld
1745 proc_base_instantiate, task, p); 1804 proc_base_instantiate, task, p);
1746} 1805}
1747 1806
1807#ifdef CONFIG_TASK_IO_ACCOUNTING
1808static int proc_pid_io_accounting(struct task_struct *task, char *buffer)
1809{
1810 return sprintf(buffer,
1811 "rchar: %llu\n"
1812 "wchar: %llu\n"
1813 "syscr: %llu\n"
1814 "syscw: %llu\n"
1815 "read_bytes: %llu\n"
1816 "write_bytes: %llu\n"
1817 "cancelled_write_bytes: %llu\n",
1818 (unsigned long long)task->rchar,
1819 (unsigned long long)task->wchar,
1820 (unsigned long long)task->syscr,
1821 (unsigned long long)task->syscw,
1822 (unsigned long long)task->ioac.read_bytes,
1823 (unsigned long long)task->ioac.write_bytes,
1824 (unsigned long long)task->ioac.cancelled_write_bytes);
1825}
1826#endif
1827
1748/* 1828/*
1749 * Thread groups 1829 * Thread groups
1750 */ 1830 */
@@ -1793,6 +1873,12 @@ static struct pid_entry tgid_base_stuff[] = {
1793#ifdef CONFIG_AUDITSYSCALL 1873#ifdef CONFIG_AUDITSYSCALL
1794 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 1874 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
1795#endif 1875#endif
1876#ifdef CONFIG_FAULT_INJECTION
1877 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
1878#endif
1879#ifdef CONFIG_TASK_IO_ACCOUNTING
1880 INF("io", S_IRUGO, pid_io_accounting),
1881#endif
1796}; 1882};
1797 1883
1798static int proc_tgid_base_readdir(struct file * filp, 1884static int proc_tgid_base_readdir(struct file * filp,
@@ -1994,7 +2080,7 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
1994int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) 2080int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
1995{ 2081{
1996 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; 2082 unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
1997 struct task_struct *reaper = get_proc_task(filp->f_dentry->d_inode); 2083 struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
1998 struct task_struct *task; 2084 struct task_struct *task;
1999 int tgid; 2085 int tgid;
2000 2086
@@ -2068,6 +2154,9 @@ static struct pid_entry tid_base_stuff[] = {
2068#ifdef CONFIG_AUDITSYSCALL 2154#ifdef CONFIG_AUDITSYSCALL
2069 REG("loginuid", S_IWUSR|S_IRUGO, loginuid), 2155 REG("loginuid", S_IWUSR|S_IRUGO, loginuid),
2070#endif 2156#endif
2157#ifdef CONFIG_FAULT_INJECTION
2158 REG("make-it-fail", S_IRUGO|S_IWUSR, fault_inject),
2159#endif
2071}; 2160};
2072 2161
2073static int proc_tid_base_readdir(struct file * filp, 2162static int proc_tid_base_readdir(struct file * filp,
@@ -2235,7 +2324,7 @@ static int proc_task_fill_cache(struct file *filp, void *dirent, filldir_t filld
2235/* for the /proc/TGID/task/ directories */ 2324/* for the /proc/TGID/task/ directories */
2236static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir) 2325static int proc_task_readdir(struct file * filp, void * dirent, filldir_t filldir)
2237{ 2326{
2238 struct dentry *dentry = filp->f_dentry; 2327 struct dentry *dentry = filp->f_path.dentry;
2239 struct inode *inode = dentry->d_inode; 2328 struct inode *inode = dentry->d_inode;
2240 struct task_struct *leader = get_proc_task(inode); 2329 struct task_struct *leader = get_proc_task(inode);
2241 struct task_struct *task; 2330 struct task_struct *task;
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index 4ba03009cf72..853cb877d5f3 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -52,7 +52,7 @@ static ssize_t
52proc_file_read(struct file *file, char __user *buf, size_t nbytes, 52proc_file_read(struct file *file, char __user *buf, size_t nbytes,
53 loff_t *ppos) 53 loff_t *ppos)
54{ 54{
55 struct inode * inode = file->f_dentry->d_inode; 55 struct inode * inode = file->f_path.dentry->d_inode;
56 char *page; 56 char *page;
57 ssize_t retval=0; 57 ssize_t retval=0;
58 int eof=0; 58 int eof=0;
@@ -203,7 +203,7 @@ static ssize_t
203proc_file_write(struct file *file, const char __user *buffer, 203proc_file_write(struct file *file, const char __user *buffer,
204 size_t count, loff_t *ppos) 204 size_t count, loff_t *ppos)
205{ 205{
206 struct inode *inode = file->f_dentry->d_inode; 206 struct inode *inode = file->f_path.dentry->d_inode;
207 struct proc_dir_entry * dp; 207 struct proc_dir_entry * dp;
208 208
209 dp = PDE(inode); 209 dp = PDE(inode);
@@ -432,7 +432,7 @@ int proc_readdir(struct file * filp,
432 struct proc_dir_entry * de; 432 struct proc_dir_entry * de;
433 unsigned int ino; 433 unsigned int ino;
434 int i; 434 int i;
435 struct inode *inode = filp->f_dentry->d_inode; 435 struct inode *inode = filp->f_path.dentry->d_inode;
436 int ret = 0; 436 int ret = 0;
437 437
438 lock_kernel(); 438 lock_kernel();
@@ -453,7 +453,7 @@ int proc_readdir(struct file * filp,
453 /* fall through */ 453 /* fall through */
454 case 1: 454 case 1:
455 if (filldir(dirent, "..", 2, i, 455 if (filldir(dirent, "..", 2, i,
456 parent_ino(filp->f_dentry), 456 parent_ino(filp->f_path.dentry),
457 DT_DIR) < 0) 457 DT_DIR) < 0)
458 goto out; 458 goto out;
459 i++; 459 i++;
@@ -558,7 +558,7 @@ static void proc_kill_inodes(struct proc_dir_entry *de)
558 file_list_lock(); 558 file_list_lock();
559 list_for_each(p, &sb->s_files) { 559 list_for_each(p, &sb->s_files) {
560 struct file * filp = list_entry(p, struct file, f_u.fu_list); 560 struct file * filp = list_entry(p, struct file, f_u.fu_list);
561 struct dentry * dentry = filp->f_dentry; 561 struct dentry * dentry = filp->f_path.dentry;
562 struct inode * inode; 562 struct inode * inode;
563 const struct file_operations *fops; 563 const struct file_operations *fops;
564 564
diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
index d7dbdf9e0f49..5ec67257e5f9 100644
--- a/fs/proc/nommu.c
+++ b/fs/proc/nommu.c
@@ -46,7 +46,7 @@ int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46 file = vma->vm_file; 46 file = vma->vm_file;
47 47
48 if (file) { 48 if (file) {
49 struct inode *inode = vma->vm_file->f_dentry->d_inode; 49 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
50 dev = inode->i_sb->s_dev; 50 dev = inode->i_sb->s_dev;
51 ino = inode->i_ino; 51 ino = inode->i_ino;
52 } 52 }
@@ -67,7 +67,7 @@ int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
67 if (len < 1) 67 if (len < 1)
68 len = 1; 68 len = 1;
69 seq_printf(m, "%*c", len, ' '); 69 seq_printf(m, "%*c", len, ' ');
70 seq_path(m, file->f_vfsmnt, file->f_dentry, ""); 70 seq_path(m, file->f_path.mnt, file->f_path.dentry, "");
71 } 71 }
72 72
73 seq_putc(m, '\n'); 73 seq_putc(m, '\n');
diff --git a/fs/proc/proc_misc.c b/fs/proc/proc_misc.c
index 51815cece6f3..92ea7743fe8f 100644
--- a/fs/proc/proc_misc.c
+++ b/fs/proc/proc_misc.c
@@ -39,13 +39,15 @@
39#include <linux/seq_file.h> 39#include <linux/seq_file.h>
40#include <linux/times.h> 40#include <linux/times.h>
41#include <linux/profile.h> 41#include <linux/profile.h>
42#include <linux/utsname.h>
42#include <linux/blkdev.h> 43#include <linux/blkdev.h>
43#include <linux/hugetlb.h> 44#include <linux/hugetlb.h>
44#include <linux/jiffies.h> 45#include <linux/jiffies.h>
45#include <linux/sysrq.h> 46#include <linux/sysrq.h>
46#include <linux/vmalloc.h> 47#include <linux/vmalloc.h>
47#include <linux/crash_dump.h> 48#include <linux/crash_dump.h>
48#include <linux/pspace.h> 49#include <linux/pid_namespace.h>
50#include <linux/compile.h>
49#include <asm/uaccess.h> 51#include <asm/uaccess.h>
50#include <asm/pgtable.h> 52#include <asm/pgtable.h>
51#include <asm/io.h> 53#include <asm/io.h>
@@ -92,7 +94,7 @@ static int loadavg_read_proc(char *page, char **start, off_t off,
92 LOAD_INT(a), LOAD_FRAC(a), 94 LOAD_INT(a), LOAD_FRAC(a),
93 LOAD_INT(b), LOAD_FRAC(b), 95 LOAD_INT(b), LOAD_FRAC(b),
94 LOAD_INT(c), LOAD_FRAC(c), 96 LOAD_INT(c), LOAD_FRAC(c),
95 nr_running(), nr_threads, init_pspace.last_pid); 97 nr_running(), nr_threads, current->nsproxy->pid_ns->last_pid);
96 return proc_calc_metrics(page, start, off, count, eof, len); 98 return proc_calc_metrics(page, start, off, count, eof, len);
97} 99}
98 100
@@ -252,8 +254,15 @@ static int version_read_proc(char *page, char **start, off_t off,
252{ 254{
253 int len; 255 int len;
254 256
255 strcpy(page, linux_banner); 257 /* FIXED STRING! Don't touch! */
256 len = strlen(page); 258 len = snprintf(page, PAGE_SIZE,
259 "%s version %s"
260 " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ")"
261 " (" LINUX_COMPILER ")"
262 " %s\n",
263 utsname()->sysname,
264 utsname()->release,
265 utsname()->version);
257 return proc_calc_metrics(page, start, off, count, eof, len); 266 return proc_calc_metrics(page, start, off, count, eof, len);
258} 267}
259 268
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 6b769afac55a..55ade0d15621 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -94,8 +94,8 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
94 } 94 }
95 95
96 if (vma) { 96 if (vma) {
97 *mnt = mntget(vma->vm_file->f_vfsmnt); 97 *mnt = mntget(vma->vm_file->f_path.mnt);
98 *dentry = dget(vma->vm_file->f_dentry); 98 *dentry = dget(vma->vm_file->f_path.dentry);
99 result = 0; 99 result = 0;
100 } 100 }
101 101
@@ -135,7 +135,7 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
135 int len; 135 int len;
136 136
137 if (file) { 137 if (file) {
138 struct inode *inode = vma->vm_file->f_dentry->d_inode; 138 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
139 dev = inode->i_sb->s_dev; 139 dev = inode->i_sb->s_dev;
140 ino = inode->i_ino; 140 ino = inode->i_ino;
141 } 141 }
@@ -156,7 +156,7 @@ static int show_map_internal(struct seq_file *m, void *v, struct mem_size_stats
156 */ 156 */
157 if (file) { 157 if (file) {
158 pad_len_spaces(m, len); 158 pad_len_spaces(m, len);
159 seq_path(m, file->f_vfsmnt, file->f_dentry, "\n"); 159 seq_path(m, file->f_path.mnt, file->f_path.dentry, "\n");
160 } else { 160 } else {
161 const char *name = arch_vma_name(vma); 161 const char *name = arch_vma_name(vma);
162 if (!name) { 162 if (!name) {
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 091aa8e48e02..fcc5caf93f55 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -126,8 +126,8 @@ int proc_exe_link(struct inode *inode, struct dentry **dentry, struct vfsmount *
126 } 126 }
127 127
128 if (vma) { 128 if (vma) {
129 *mnt = mntget(vma->vm_file->f_vfsmnt); 129 *mnt = mntget(vma->vm_file->f_path.mnt);
130 *dentry = dget(vma->vm_file->f_dentry); 130 *dentry = dget(vma->vm_file->f_path.dentry);
131 result = 0; 131 result = 0;
132 } 132 }
133 133
diff --git a/fs/qnx4/dir.c b/fs/qnx4/dir.c
index 0d7103fa0df5..c94db1db7a71 100644
--- a/fs/qnx4/dir.c
+++ b/fs/qnx4/dir.c
@@ -22,7 +22,7 @@
22 22
23static int qnx4_readdir(struct file *filp, void *dirent, filldir_t filldir) 23static int qnx4_readdir(struct file *filp, void *dirent, filldir_t filldir)
24{ 24{
25 struct inode *inode = filp->f_dentry->d_inode; 25 struct inode *inode = filp->f_path.dentry->d_inode;
26 unsigned int offset; 26 unsigned int offset;
27 struct buffer_head *bh; 27 struct buffer_head *bh;
28 struct qnx4_inode_entry *de; 28 struct qnx4_inode_entry *de;
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index bfe5dbf1002e..61cbe1ef06b9 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -232,7 +232,7 @@ unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
232 unsigned long pgoff, unsigned long flags) 232 unsigned long pgoff, unsigned long flags)
233{ 233{
234 unsigned long maxpages, lpages, nr, loop, ret; 234 unsigned long maxpages, lpages, nr, loop, ret;
235 struct inode *inode = file->f_dentry->d_inode; 235 struct inode *inode = file->f_path.dentry->d_inode;
236 struct page **pages = NULL, **ptr, *page; 236 struct page **pages = NULL, **ptr, *page;
237 loff_t isize; 237 loff_t isize;
238 238
diff --git a/fs/read_write.c b/fs/read_write.c
index f792000a28e6..1d3dda4fa70c 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -64,13 +64,13 @@ loff_t remote_llseek(struct file *file, loff_t offset, int origin)
64 lock_kernel(); 64 lock_kernel();
65 switch (origin) { 65 switch (origin) {
66 case 2: 66 case 2:
67 offset += i_size_read(file->f_dentry->d_inode); 67 offset += i_size_read(file->f_path.dentry->d_inode);
68 break; 68 break;
69 case 1: 69 case 1:
70 offset += file->f_pos; 70 offset += file->f_pos;
71 } 71 }
72 retval = -EINVAL; 72 retval = -EINVAL;
73 if (offset>=0 && offset<=file->f_dentry->d_inode->i_sb->s_maxbytes) { 73 if (offset>=0 && offset<=file->f_path.dentry->d_inode->i_sb->s_maxbytes) {
74 if (offset != file->f_pos) { 74 if (offset != file->f_pos) {
75 file->f_pos = offset; 75 file->f_pos = offset;
76 file->f_version = 0; 76 file->f_version = 0;
@@ -95,7 +95,7 @@ loff_t default_llseek(struct file *file, loff_t offset, int origin)
95 lock_kernel(); 95 lock_kernel();
96 switch (origin) { 96 switch (origin) {
97 case 2: 97 case 2:
98 offset += i_size_read(file->f_dentry->d_inode); 98 offset += i_size_read(file->f_path.dentry->d_inode);
99 break; 99 break;
100 case 1: 100 case 1:
101 offset += file->f_pos; 101 offset += file->f_pos;
@@ -203,7 +203,7 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
203 if (unlikely((pos < 0) || (loff_t) (pos + count) < 0)) 203 if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
204 goto Einval; 204 goto Einval;
205 205
206 inode = file->f_dentry->d_inode; 206 inode = file->f_path.dentry->d_inode;
207 if (unlikely(inode->i_flock && MANDATORY_LOCK(inode))) { 207 if (unlikely(inode->i_flock && MANDATORY_LOCK(inode))) {
208 int retval = locks_mandatory_area( 208 int retval = locks_mandatory_area(
209 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, 209 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
@@ -273,7 +273,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
273 else 273 else
274 ret = do_sync_read(file, buf, count, pos); 274 ret = do_sync_read(file, buf, count, pos);
275 if (ret > 0) { 275 if (ret > 0) {
276 fsnotify_access(file->f_dentry); 276 fsnotify_access(file->f_path.dentry);
277 current->rchar += ret; 277 current->rchar += ret;
278 } 278 }
279 current->syscr++; 279 current->syscr++;
@@ -331,7 +331,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
331 else 331 else
332 ret = do_sync_write(file, buf, count, pos); 332 ret = do_sync_write(file, buf, count, pos);
333 if (ret > 0) { 333 if (ret > 0) {
334 fsnotify_modify(file->f_dentry); 334 fsnotify_modify(file->f_path.dentry);
335 current->wchar += ret; 335 current->wchar += ret;
336 } 336 }
337 current->syscw++; 337 current->syscw++;
@@ -628,9 +628,9 @@ out:
628 kfree(iov); 628 kfree(iov);
629 if ((ret + (type == READ)) > 0) { 629 if ((ret + (type == READ)) > 0) {
630 if (type == READ) 630 if (type == READ)
631 fsnotify_access(file->f_dentry); 631 fsnotify_access(file->f_path.dentry);
632 else 632 else
633 fsnotify_modify(file->f_dentry); 633 fsnotify_modify(file->f_path.dentry);
634 } 634 }
635 return ret; 635 return ret;
636} 636}
@@ -722,7 +722,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
722 if (!(in_file->f_mode & FMODE_READ)) 722 if (!(in_file->f_mode & FMODE_READ))
723 goto fput_in; 723 goto fput_in;
724 retval = -EINVAL; 724 retval = -EINVAL;
725 in_inode = in_file->f_dentry->d_inode; 725 in_inode = in_file->f_path.dentry->d_inode;
726 if (!in_inode) 726 if (!in_inode)
727 goto fput_in; 727 goto fput_in;
728 if (!in_file->f_op || !in_file->f_op->sendfile) 728 if (!in_file->f_op || !in_file->f_op->sendfile)
@@ -754,7 +754,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
754 retval = -EINVAL; 754 retval = -EINVAL;
755 if (!out_file->f_op || !out_file->f_op->sendpage) 755 if (!out_file->f_op || !out_file->f_op->sendpage)
756 goto fput_out; 756 goto fput_out;
757 out_inode = out_file->f_dentry->d_inode; 757 out_inode = out_file->f_path.dentry->d_inode;
758 retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count); 758 retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);
759 if (retval < 0) 759 if (retval < 0)
760 goto fput_out; 760 goto fput_out;
diff --git a/fs/readdir.c b/fs/readdir.c
index bff3ee58e2f8..f39f5b313252 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -21,7 +21,7 @@
21 21
22int vfs_readdir(struct file *file, filldir_t filler, void *buf) 22int vfs_readdir(struct file *file, filldir_t filler, void *buf)
23{ 23{
24 struct inode *inode = file->f_dentry->d_inode; 24 struct inode *inode = file->f_path.dentry->d_inode;
25 int res = -ENOTDIR; 25 int res = -ENOTDIR;
26 if (!file->f_op || !file->f_op->readdir) 26 if (!file->f_op || !file->f_op->readdir)
27 goto out; 27 goto out;
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index e3d466a228d4..b286ccb08587 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -708,7 +708,7 @@ static void oid_groups(reiserfs_blocknr_hint_t * hint)
708 */ 708 */
709static int get_left_neighbor(reiserfs_blocknr_hint_t * hint) 709static int get_left_neighbor(reiserfs_blocknr_hint_t * hint)
710{ 710{
711 struct path *path; 711 struct treepath *path;
712 struct buffer_head *bh; 712 struct buffer_head *bh;
713 struct item_head *ih; 713 struct item_head *ih;
714 int pos_in_item; 714 int pos_in_item;
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index 657050ad7430..96a2f8889da3 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -45,7 +45,7 @@ static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
45// 45//
46static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 46static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
47{ 47{
48 struct inode *inode = filp->f_dentry->d_inode; 48 struct inode *inode = filp->f_path.dentry->d_inode;
49 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 49 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
50 INITIALIZE_PATH(path_to_entry); 50 INITIALIZE_PATH(path_to_entry);
51 struct buffer_head *bh; 51 struct buffer_head *bh;
@@ -135,7 +135,7 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
135 /* Ignore the .reiserfs_priv entry */ 135 /* Ignore the .reiserfs_priv entry */
136 if (reiserfs_xattrs(inode->i_sb) && 136 if (reiserfs_xattrs(inode->i_sb) &&
137 !old_format_only(inode->i_sb) && 137 !old_format_only(inode->i_sb) &&
138 filp->f_dentry == inode->i_sb->s_root && 138 filp->f_path.dentry == inode->i_sb->s_root &&
139 REISERFS_SB(inode->i_sb)->priv_root && 139 REISERFS_SB(inode->i_sb)->priv_root &&
140 REISERFS_SB(inode->i_sb)->priv_root->d_inode 140 REISERFS_SB(inode->i_sb)->priv_root->d_inode
141 && deh_objectid(deh) == 141 && deh_objectid(deh) ==
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index 373d862c3f87..99b6f329ba23 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -1288,7 +1288,7 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1288 loff_t pos; // Current position in the file. 1288 loff_t pos; // Current position in the file.
1289 ssize_t res; // return value of various functions that we call. 1289 ssize_t res; // return value of various functions that we call.
1290 int err = 0; 1290 int err = 0;
1291 struct inode *inode = file->f_dentry->d_inode; // Inode of the file that we are writing to. 1291 struct inode *inode = file->f_path.dentry->d_inode; // Inode of the file that we are writing to.
1292 /* To simplify coding at this time, we store 1292 /* To simplify coding at this time, we store
1293 locked pages in array for now */ 1293 locked pages in array for now */
1294 struct page *prepared_pages[REISERFS_WRITE_PAGES_AT_A_TIME]; 1294 struct page *prepared_pages[REISERFS_WRITE_PAGES_AT_A_TIME];
@@ -1335,7 +1335,7 @@ static ssize_t reiserfs_file_write(struct file *file, /* the file we are going t
1335 if (count == 0) 1335 if (count == 0)
1336 goto out; 1336 goto out;
1337 1337
1338 res = remove_suid(file->f_dentry); 1338 res = remove_suid(file->f_path.dentry);
1339 if (res) 1339 if (res)
1340 goto out; 1340 goto out;
1341 1341
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index 6d0e554daa9d..0ee35c6c9b72 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -957,7 +957,7 @@ static int get_far_parent(struct tree_balance *p_s_tb,
957{ 957{
958 struct buffer_head *p_s_parent; 958 struct buffer_head *p_s_parent;
959 INITIALIZE_PATH(s_path_to_neighbor_father); 959 INITIALIZE_PATH(s_path_to_neighbor_father);
960 struct path *p_s_path = p_s_tb->tb_path; 960 struct treepath *p_s_path = p_s_tb->tb_path;
961 struct cpu_key s_lr_father_key; 961 struct cpu_key s_lr_father_key;
962 int n_counter, 962 int n_counter,
963 n_position = INT_MAX, 963 n_position = INT_MAX,
@@ -1074,7 +1074,7 @@ static int get_far_parent(struct tree_balance *p_s_tb,
1074 */ 1074 */
1075static int get_parents(struct tree_balance *p_s_tb, int n_h) 1075static int get_parents(struct tree_balance *p_s_tb, int n_h)
1076{ 1076{
1077 struct path *p_s_path = p_s_tb->tb_path; 1077 struct treepath *p_s_path = p_s_tb->tb_path;
1078 int n_position, 1078 int n_position,
1079 n_ret_value, 1079 n_ret_value,
1080 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1080 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
@@ -1885,7 +1885,7 @@ static int check_balance(int mode,
1885static int get_direct_parent(struct tree_balance *p_s_tb, int n_h) 1885static int get_direct_parent(struct tree_balance *p_s_tb, int n_h)
1886{ 1886{
1887 struct buffer_head *p_s_bh; 1887 struct buffer_head *p_s_bh;
1888 struct path *p_s_path = p_s_tb->tb_path; 1888 struct treepath *p_s_path = p_s_tb->tb_path;
1889 int n_position, 1889 int n_position,
1890 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1890 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h);
1891 1891
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 254239e6f9e3..f3d1c4a77979 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -207,7 +207,7 @@ static int file_capable(struct inode *inode, long block)
207} 207}
208 208
209/*static*/ int restart_transaction(struct reiserfs_transaction_handle *th, 209/*static*/ int restart_transaction(struct reiserfs_transaction_handle *th,
210 struct inode *inode, struct path *path) 210 struct inode *inode, struct treepath *path)
211{ 211{
212 struct super_block *s = th->t_super; 212 struct super_block *s = th->t_super;
213 int len = th->t_blocks_allocated; 213 int len = th->t_blocks_allocated;
@@ -570,7 +570,7 @@ static inline int _allocate_block(struct reiserfs_transaction_handle *th,
570 long block, 570 long block,
571 struct inode *inode, 571 struct inode *inode,
572 b_blocknr_t * allocated_block_nr, 572 b_blocknr_t * allocated_block_nr,
573 struct path *path, int flags) 573 struct treepath *path, int flags)
574{ 574{
575 BUG_ON(!th->t_trans_id); 575 BUG_ON(!th->t_trans_id);
576 576
@@ -1107,7 +1107,7 @@ static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size)
1107// 1107//
1108 1108
1109// called by read_locked_inode 1109// called by read_locked_inode
1110static void init_inode(struct inode *inode, struct path *path) 1110static void init_inode(struct inode *inode, struct treepath *path)
1111{ 1111{
1112 struct buffer_head *bh; 1112 struct buffer_head *bh;
1113 struct item_head *ih; 1113 struct item_head *ih;
@@ -1284,7 +1284,7 @@ static void inode2sd_v1(void *sd, struct inode *inode, loff_t size)
1284/* NOTE, you must prepare the buffer head before sending it here, 1284/* NOTE, you must prepare the buffer head before sending it here,
1285** and then log it after the call 1285** and then log it after the call
1286*/ 1286*/
1287static void update_stat_data(struct path *path, struct inode *inode, 1287static void update_stat_data(struct treepath *path, struct inode *inode,
1288 loff_t size) 1288 loff_t size)
1289{ 1289{
1290 struct buffer_head *bh; 1290 struct buffer_head *bh;
@@ -1653,7 +1653,7 @@ int reiserfs_write_inode(struct inode *inode, int do_sync)
1653 containing "." and ".." entries */ 1653 containing "." and ".." entries */
1654static int reiserfs_new_directory(struct reiserfs_transaction_handle *th, 1654static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
1655 struct inode *inode, 1655 struct inode *inode,
1656 struct item_head *ih, struct path *path, 1656 struct item_head *ih, struct treepath *path,
1657 struct inode *dir) 1657 struct inode *dir)
1658{ 1658{
1659 struct super_block *sb = th->t_super; 1659 struct super_block *sb = th->t_super;
@@ -1712,7 +1712,7 @@ static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
1712 containing the body of symlink */ 1712 containing the body of symlink */
1713static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct inode *inode, /* Inode of symlink */ 1713static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct inode *inode, /* Inode of symlink */
1714 struct item_head *ih, 1714 struct item_head *ih,
1715 struct path *path, const char *symname, 1715 struct treepath *path, const char *symname,
1716 int item_len) 1716 int item_len)
1717{ 1717{
1718 struct super_block *sb = th->t_super; 1718 struct super_block *sb = th->t_super;
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 9c57578cb831..b484d2913c0d 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -99,7 +99,7 @@ int reiserfs_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
99long reiserfs_compat_ioctl(struct file *file, unsigned int cmd, 99long reiserfs_compat_ioctl(struct file *file, unsigned int cmd,
100 unsigned long arg) 100 unsigned long arg)
101{ 101{
102 struct inode *inode = file->f_dentry->d_inode; 102 struct inode *inode = file->f_path.dentry->d_inode;
103 int ret; 103 int ret;
104 104
105 /* These are just misnamed, they actually get/put from/to user an int */ 105 /* These are just misnamed, they actually get/put from/to user an int */
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index abde1edc2235..23f5cd5bbf56 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -54,7 +54,7 @@ static int bin_search_in_dir_item(struct reiserfs_dir_entry *de, loff_t off)
54 54
55// comment? maybe something like set de to point to what the path points to? 55// comment? maybe something like set de to point to what the path points to?
56static inline void set_de_item_location(struct reiserfs_dir_entry *de, 56static inline void set_de_item_location(struct reiserfs_dir_entry *de,
57 struct path *path) 57 struct treepath *path)
58{ 58{
59 de->de_bh = get_last_bh(path); 59 de->de_bh = get_last_bh(path);
60 de->de_ih = get_ih(path); 60 de->de_ih = get_ih(path);
@@ -113,7 +113,7 @@ entry position in the item
113 113
114/* The function is NOT SCHEDULE-SAFE! */ 114/* The function is NOT SCHEDULE-SAFE! */
115int search_by_entry_key(struct super_block *sb, const struct cpu_key *key, 115int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
116 struct path *path, struct reiserfs_dir_entry *de) 116 struct treepath *path, struct reiserfs_dir_entry *de)
117{ 117{
118 int retval; 118 int retval;
119 119
@@ -282,7 +282,7 @@ static int linear_search_in_dir_item(struct cpu_key *key,
282// may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND 282// may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
283// FIXME: should add something like IOERROR 283// FIXME: should add something like IOERROR
284static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen, 284static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
285 struct path *path_to_entry, 285 struct treepath *path_to_entry,
286 struct reiserfs_dir_entry *de) 286 struct reiserfs_dir_entry *de)
287{ 287{
288 struct cpu_key key_to_search; 288 struct cpu_key key_to_search;
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index c533ec1bcaec..ecc9943202fc 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -295,7 +295,7 @@ static int show_oidmap(struct seq_file *m, struct super_block *sb)
295 } 295 }
296#if defined( REISERFS_USE_OIDMAPF ) 296#if defined( REISERFS_USE_OIDMAPF )
297 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) { 297 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
298 loff_t size = sb_info->oidmap.mapf->f_dentry->d_inode->i_size; 298 loff_t size = sb_info->oidmap.mapf->f_path.dentry->d_inode->i_size;
299 total_used += size / sizeof(reiserfs_oidinterval_d_t); 299 total_used += size / sizeof(reiserfs_oidinterval_d_t);
300 } 300 }
301#endif 301#endif
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 5240abe1a709..47e7027ea39f 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -244,7 +244,7 @@ static const struct reiserfs_key MAX_KEY = {
244 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 244 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
245 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 245 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
246 case we return a special key, either MIN_KEY or MAX_KEY. */ 246 case we return a special key, either MIN_KEY or MAX_KEY. */
247static inline const struct reiserfs_key *get_lkey(const struct path 247static inline const struct reiserfs_key *get_lkey(const struct treepath
248 *p_s_chk_path, 248 *p_s_chk_path,
249 const struct super_block 249 const struct super_block
250 *p_s_sb) 250 *p_s_sb)
@@ -290,7 +290,7 @@ static inline const struct reiserfs_key *get_lkey(const struct path
290} 290}
291 291
292/* Get delimiting key of the buffer at the path and its right neighbor. */ 292/* Get delimiting key of the buffer at the path and its right neighbor. */
293inline const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path, 293inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path,
294 const struct super_block *p_s_sb) 294 const struct super_block *p_s_sb)
295{ 295{
296 int n_position, n_path_offset = p_s_chk_path->path_length; 296 int n_position, n_path_offset = p_s_chk_path->path_length;
@@ -337,7 +337,7 @@ inline const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path,
337 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the 337 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
338 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in 338 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
339 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ 339 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
340static inline int key_in_buffer(struct path *p_s_chk_path, /* Path which should be checked. */ 340static inline int key_in_buffer(struct treepath *p_s_chk_path, /* Path which should be checked. */
341 const struct cpu_key *p_s_key, /* Key which should be checked. */ 341 const struct cpu_key *p_s_key, /* Key which should be checked. */
342 struct super_block *p_s_sb /* Super block pointer. */ 342 struct super_block *p_s_sb /* Super block pointer. */
343 ) 343 )
@@ -374,7 +374,7 @@ inline void decrement_bcount(struct buffer_head *p_s_bh)
374} 374}
375 375
376/* Decrement b_count field of the all buffers in the path. */ 376/* Decrement b_count field of the all buffers in the path. */
377void decrement_counters_in_path(struct path *p_s_search_path) 377void decrement_counters_in_path(struct treepath *p_s_search_path)
378{ 378{
379 int n_path_offset = p_s_search_path->path_length; 379 int n_path_offset = p_s_search_path->path_length;
380 380
@@ -391,7 +391,7 @@ void decrement_counters_in_path(struct path *p_s_search_path)
391 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 391 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
392} 392}
393 393
394int reiserfs_check_path(struct path *p) 394int reiserfs_check_path(struct treepath *p)
395{ 395{
396 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, 396 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
397 "path not properly relsed"); 397 "path not properly relsed");
@@ -403,7 +403,7 @@ int reiserfs_check_path(struct path *p)
403** 403**
404** only called from fix_nodes() 404** only called from fix_nodes()
405*/ 405*/
406void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path) 406void pathrelse_and_restore(struct super_block *s, struct treepath *p_s_search_path)
407{ 407{
408 int n_path_offset = p_s_search_path->path_length; 408 int n_path_offset = p_s_search_path->path_length;
409 409
@@ -421,7 +421,7 @@ void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path)
421} 421}
422 422
423/* Release all buffers in the path. */ 423/* Release all buffers in the path. */
424void pathrelse(struct path *p_s_search_path) 424void pathrelse(struct treepath *p_s_search_path)
425{ 425{
426 int n_path_offset = p_s_search_path->path_length; 426 int n_path_offset = p_s_search_path->path_length;
427 427
@@ -602,7 +602,7 @@ static void search_by_key_reada(struct super_block *s,
602 correctness of the bottom of the path */ 602 correctness of the bottom of the path */
603/* The function is NOT SCHEDULE-SAFE! */ 603/* The function is NOT SCHEDULE-SAFE! */
604int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */ 604int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */
605 struct path *p_s_search_path, /* This structure was 605 struct treepath *p_s_search_path,/* This structure was
606 allocated and initialized 606 allocated and initialized
607 by the calling 607 by the calling
608 function. It is filled up 608 function. It is filled up
@@ -813,7 +813,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
813/* The function is NOT SCHEDULE-SAFE! */ 813/* The function is NOT SCHEDULE-SAFE! */
814int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */ 814int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */
815 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ 815 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */
816 struct path *p_s_search_path /* Filled up by this function. */ 816 struct treepath *p_s_search_path /* Filled up by this function. */
817 ) 817 )
818{ 818{
819 struct item_head *p_le_ih; /* pointer to on-disk structure */ 819 struct item_head *p_le_ih; /* pointer to on-disk structure */
@@ -884,7 +884,7 @@ int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the sup
884} 884}
885 885
886/* Compare given item and item pointed to by the path. */ 886/* Compare given item and item pointed to by the path. */
887int comp_items(const struct item_head *stored_ih, const struct path *p_s_path) 887int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_path)
888{ 888{
889 struct buffer_head *p_s_bh; 889 struct buffer_head *p_s_bh;
890 struct item_head *ih; 890 struct item_head *ih;
@@ -911,7 +911,7 @@ int comp_items(const struct item_head *stored_ih, const struct path *p_s_path)
911#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh))) 911#define block_in_use(bh) (buffer_locked(bh) || (held_by_others(bh)))
912 912
913// prepare for delete or cut of direct item 913// prepare for delete or cut of direct item
914static inline int prepare_for_direct_item(struct path *path, 914static inline int prepare_for_direct_item(struct treepath *path,
915 struct item_head *le_ih, 915 struct item_head *le_ih,
916 struct inode *inode, 916 struct inode *inode,
917 loff_t new_file_length, int *cut_size) 917 loff_t new_file_length, int *cut_size)
@@ -952,7 +952,7 @@ static inline int prepare_for_direct_item(struct path *path,
952 return M_CUT; /* Cut from this item. */ 952 return M_CUT; /* Cut from this item. */
953} 953}
954 954
955static inline int prepare_for_direntry_item(struct path *path, 955static inline int prepare_for_direntry_item(struct treepath *path,
956 struct item_head *le_ih, 956 struct item_head *le_ih,
957 struct inode *inode, 957 struct inode *inode,
958 loff_t new_file_length, 958 loff_t new_file_length,
@@ -987,7 +987,7 @@ static inline int prepare_for_direntry_item(struct path *path,
987 In case of file truncate calculate whether this item must be deleted/truncated or last 987 In case of file truncate calculate whether this item must be deleted/truncated or last
988 unformatted node of this item will be converted to a direct item. 988 unformatted node of this item will be converted to a direct item.
989 This function returns a determination of what balance mode the calling function should employ. */ 989 This function returns a determination of what balance mode the calling function should employ. */
990static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct path *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed 990static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed
991 from end of the file. */ 991 from end of the file. */
992 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ 992 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */
993 ) 993 )
@@ -1125,7 +1125,7 @@ static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode)
1125static void init_tb_struct(struct reiserfs_transaction_handle *th, 1125static void init_tb_struct(struct reiserfs_transaction_handle *th,
1126 struct tree_balance *p_s_tb, 1126 struct tree_balance *p_s_tb,
1127 struct super_block *p_s_sb, 1127 struct super_block *p_s_sb,
1128 struct path *p_s_path, int n_size) 1128 struct treepath *p_s_path, int n_size)
1129{ 1129{
1130 1130
1131 BUG_ON(!th->t_trans_id); 1131 BUG_ON(!th->t_trans_id);
@@ -1176,7 +1176,7 @@ char head2type(struct item_head *ih)
1176#endif 1176#endif
1177 1177
1178/* Delete object item. */ 1178/* Delete object item. */
1179int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the deleted item. */ 1179int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the deleted item. */
1180 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */ 1180 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */
1181 struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */ 1181 struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */
1182 struct buffer_head *p_s_un_bh) 1182 struct buffer_head *p_s_un_bh)
@@ -1468,7 +1468,7 @@ static void unmap_buffers(struct page *page, loff_t pos)
1468static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, 1468static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1469 struct inode *p_s_inode, 1469 struct inode *p_s_inode,
1470 struct page *page, 1470 struct page *page,
1471 struct path *p_s_path, 1471 struct treepath *p_s_path,
1472 const struct cpu_key *p_s_item_key, 1472 const struct cpu_key *p_s_item_key,
1473 loff_t n_new_file_size, char *p_c_mode) 1473 loff_t n_new_file_size, char *p_c_mode)
1474{ 1474{
@@ -1503,7 +1503,7 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1503 pointer being converted. Therefore we have to delete inserted 1503 pointer being converted. Therefore we have to delete inserted
1504 direct item(s) */ 1504 direct item(s) */
1505static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th, 1505static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1506 struct inode *inode, struct path *path) 1506 struct inode *inode, struct treepath *path)
1507{ 1507{
1508 struct cpu_key tail_key; 1508 struct cpu_key tail_key;
1509 int tail_len; 1509 int tail_len;
@@ -1545,7 +1545,7 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1545 1545
1546/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ 1546/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */
1547int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, 1547int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1548 struct path *p_s_path, 1548 struct treepath *p_s_path,
1549 struct cpu_key *p_s_item_key, 1549 struct cpu_key *p_s_item_key,
1550 struct inode *p_s_inode, 1550 struct inode *p_s_inode,
1551 struct page *page, loff_t n_new_file_size) 1551 struct page *page, loff_t n_new_file_size)
@@ -1920,7 +1920,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p
1920 1920
1921#ifdef CONFIG_REISERFS_CHECK 1921#ifdef CONFIG_REISERFS_CHECK
1922// this makes sure, that we __append__, not overwrite or add holes 1922// this makes sure, that we __append__, not overwrite or add holes
1923static void check_research_for_paste(struct path *path, 1923static void check_research_for_paste(struct treepath *path,
1924 const struct cpu_key *p_s_key) 1924 const struct cpu_key *p_s_key)
1925{ 1925{
1926 struct item_head *found_ih = get_ih(path); 1926 struct item_head *found_ih = get_ih(path);
@@ -1954,7 +1954,7 @@ static void check_research_for_paste(struct path *path,
1954#endif /* config reiserfs check */ 1954#endif /* config reiserfs check */
1955 1955
1956/* Paste bytes to the existing item. Returns bytes number pasted into the item. */ 1956/* Paste bytes to the existing item. Returns bytes number pasted into the item. */
1957int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct path *p_s_search_path, /* Path to the pasted item. */ 1957int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_search_path, /* Path to the pasted item. */
1958 const struct cpu_key *p_s_key, /* Key to search for the needed item. */ 1958 const struct cpu_key *p_s_key, /* Key to search for the needed item. */
1959 struct inode *inode, /* Inode item belongs to */ 1959 struct inode *inode, /* Inode item belongs to */
1960 const char *p_c_body, /* Pointer to the bytes to paste. */ 1960 const char *p_c_body, /* Pointer to the bytes to paste. */
@@ -2036,7 +2036,7 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct path
2036} 2036}
2037 2037
2038/* Insert new item into the buffer at the path. */ 2038/* Insert new item into the buffer at the path. */
2039int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct path *p_s_path, /* Path to the inserteded item. */ 2039int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the inserteded item. */
2040 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */ 2040 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */
2041 struct inode *inode, const char *p_c_body) 2041 struct inode *inode, const char *p_c_body)
2042{ /* Pointer to the bytes to insert. */ 2042{ /* Pointer to the bytes to insert. */
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index 7fb5fb036f90..58ad4551a7c1 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -23,7 +23,7 @@
23#include <linux/blkdev.h> 23#include <linux/blkdev.h>
24#include <linux/buffer_head.h> 24#include <linux/buffer_head.h>
25#include <linux/vfs.h> 25#include <linux/vfs.h>
26#include <linux/namespace.h> 26#include <linux/mnt_namespace.h>
27#include <linux/mount.h> 27#include <linux/mount.h>
28#include <linux/namei.h> 28#include <linux/namei.h>
29#include <linux/quotaops.h> 29#include <linux/quotaops.h>
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index 36f108fc1cf5..f8121a1147e8 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -15,7 +15,7 @@
15/* path points to first direct item of the file regarless of how many of 15/* path points to first direct item of the file regarless of how many of
16 them are there */ 16 them are there */
17int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode, 17int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
18 struct path *path, struct buffer_head *unbh, 18 struct treepath *path, struct buffer_head *unbh,
19 loff_t tail_offset) 19 loff_t tail_offset)
20{ 20{
21 struct super_block *sb = inode->i_sb; 21 struct super_block *sb = inode->i_sb;
@@ -171,7 +171,7 @@ void reiserfs_unmap_buffer(struct buffer_head *bh)
171 what we expect from it (number of cut bytes). But when tail remains 171 what we expect from it (number of cut bytes). But when tail remains
172 in the unformatted node, we set mode to SKIP_BALANCING and unlock 172 in the unformatted node, we set mode to SKIP_BALANCING and unlock
173 inode */ 173 inode */
174int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, struct page *page, struct path *p_s_path, /* path to the indirect item. */ 174int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, struct page *page, struct treepath *p_s_path, /* path to the indirect item. */
175 const struct cpu_key *p_s_item_key, /* Key to look for unformatted node pointer to be cut. */ 175 const struct cpu_key *p_s_item_key, /* Key to look for unformatted node pointer to be cut. */
176 loff_t n_new_file_size, /* New file size. */ 176 loff_t n_new_file_size, /* New file size. */
177 char *p_c_mode) 177 char *p_c_mode)
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 1e4d68590178..f01389fd162e 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -274,7 +274,7 @@ static struct file *open_xa_file(const struct inode *inode, const char *name,
274 */ 274 */
275static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir) 275static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
276{ 276{
277 struct inode *inode = filp->f_dentry->d_inode; 277 struct inode *inode = filp->f_path.dentry->d_inode;
278 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 278 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
279 INITIALIZE_PATH(path_to_entry); 279 INITIALIZE_PATH(path_to_entry);
280 struct buffer_head *bh; 280 struct buffer_head *bh;
@@ -420,7 +420,7 @@ static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
420static 420static
421int xattr_readdir(struct file *file, filldir_t filler, void *buf) 421int xattr_readdir(struct file *file, filldir_t filler, void *buf)
422{ 422{
423 struct inode *inode = file->f_dentry->d_inode; 423 struct inode *inode = file->f_path.dentry->d_inode;
424 int res = -ENOTDIR; 424 int res = -ENOTDIR;
425 if (!file->f_op || !file->f_op->readdir) 425 if (!file->f_op || !file->f_op->readdir)
426 goto out; 426 goto out;
@@ -508,7 +508,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
508 goto out; 508 goto out;
509 } 509 }
510 510
511 xinode = fp->f_dentry->d_inode; 511 xinode = fp->f_path.dentry->d_inode;
512 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 512 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
513 513
514 /* we need to copy it off.. */ 514 /* we need to copy it off.. */
@@ -527,7 +527,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
527 newattrs.ia_size = buffer_size; 527 newattrs.ia_size = buffer_size;
528 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 528 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
529 mutex_lock(&xinode->i_mutex); 529 mutex_lock(&xinode->i_mutex);
530 err = notify_change(fp->f_dentry, &newattrs); 530 err = notify_change(fp->f_path.dentry, &newattrs);
531 if (err) 531 if (err)
532 goto out_filp; 532 goto out_filp;
533 533
@@ -626,7 +626,7 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
626 goto out; 626 goto out;
627 } 627 }
628 628
629 xinode = fp->f_dentry->d_inode; 629 xinode = fp->f_path.dentry->d_inode;
630 isize = xinode->i_size; 630 isize = xinode->i_size;
631 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 631 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
632 632
diff --git a/fs/romfs/inode.c b/fs/romfs/inode.c
index c5af088d4a4c..d3e243a6f609 100644
--- a/fs/romfs/inode.c
+++ b/fs/romfs/inode.c
@@ -276,7 +276,7 @@ static unsigned char romfs_dtype_table[] = {
276static int 276static int
277romfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 277romfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
278{ 278{
279 struct inode *i = filp->f_dentry->d_inode; 279 struct inode *i = filp->f_path.dentry->d_inode;
280 struct romfs_inode ri; 280 struct romfs_inode ri;
281 unsigned long offset, maxoff; 281 unsigned long offset, maxoff;
282 int j, ino, nextfh; 282 int j, ino, nextfh;
diff --git a/fs/select.c b/fs/select.c
index dcbc1112b7ec..fe0893afd931 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -311,7 +311,7 @@ static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
311{ 311{
312 fd_set_bits fds; 312 fd_set_bits fds;
313 void *bits; 313 void *bits;
314 int ret, max_fdset; 314 int ret, max_fds;
315 unsigned int size; 315 unsigned int size;
316 struct fdtable *fdt; 316 struct fdtable *fdt;
317 /* Allocate small arguments on the stack to save memory and be faster */ 317 /* Allocate small arguments on the stack to save memory and be faster */
@@ -321,13 +321,13 @@ static int core_sys_select(int n, fd_set __user *inp, fd_set __user *outp,
321 if (n < 0) 321 if (n < 0)
322 goto out_nofds; 322 goto out_nofds;
323 323
324 /* max_fdset can increase, so grab it once to avoid race */ 324 /* max_fds can increase, so grab it once to avoid race */
325 rcu_read_lock(); 325 rcu_read_lock();
326 fdt = files_fdtable(current->files); 326 fdt = files_fdtable(current->files);
327 max_fdset = fdt->max_fdset; 327 max_fds = fdt->max_fds;
328 rcu_read_unlock(); 328 rcu_read_unlock();
329 if (n > max_fdset) 329 if (n > max_fds)
330 n = max_fdset; 330 n = max_fds;
331 331
332 /* 332 /*
333 * We need 6 bitmaps (in/out/ex for both incoming and outgoing), 333 * We need 6 bitmaps (in/out/ex for both incoming and outgoing),
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 10690aa401c7..0ac22af7afe5 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -269,7 +269,7 @@ EXPORT_SYMBOL(seq_lseek);
269/** 269/**
270 * seq_release - free the structures associated with sequential file. 270 * seq_release - free the structures associated with sequential file.
271 * @file: file in question 271 * @file: file in question
272 * @inode: file->f_dentry->d_inode 272 * @inode: file->f_path.dentry->d_inode
273 * 273 *
274 * Frees the structures associated with sequential file; can be used 274 * Frees the structures associated with sequential file; can be used
275 * as ->f_op->release() if you don't have private data to destroy. 275 * as ->f_op->release() if you don't have private data to destroy.
diff --git a/fs/smbfs/cache.c b/fs/smbfs/cache.c
index 74b86d9725a6..8182f0542a21 100644
--- a/fs/smbfs/cache.c
+++ b/fs/smbfs/cache.c
@@ -125,7 +125,7 @@ smb_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
125 struct smb_cache_control *ctrl, struct qstr *qname, 125 struct smb_cache_control *ctrl, struct qstr *qname,
126 struct smb_fattr *entry) 126 struct smb_fattr *entry)
127{ 127{
128 struct dentry *newdent, *dentry = filp->f_dentry; 128 struct dentry *newdent, *dentry = filp->f_path.dentry;
129 struct inode *newino, *inode = dentry->d_inode; 129 struct inode *newino, *inode = dentry->d_inode;
130 struct smb_cache_control ctl = *ctrl; 130 struct smb_cache_control ctl = *ctrl;
131 int valid = 0; 131 int valid = 0;
diff --git a/fs/smbfs/dir.c b/fs/smbfs/dir.c
index 70d9c5a37f5a..b1e58d1ac9ca 100644
--- a/fs/smbfs/dir.c
+++ b/fs/smbfs/dir.c
@@ -78,7 +78,7 @@ struct inode_operations smb_dir_inode_operations_unix =
78static int 78static int
79smb_readdir(struct file *filp, void *dirent, filldir_t filldir) 79smb_readdir(struct file *filp, void *dirent, filldir_t filldir)
80{ 80{
81 struct dentry *dentry = filp->f_dentry; 81 struct dentry *dentry = filp->f_path.dentry;
82 struct inode *dir = dentry->d_inode; 82 struct inode *dir = dentry->d_inode;
83 struct smb_sb_info *server = server_from_dentry(dentry); 83 struct smb_sb_info *server = server_from_dentry(dentry);
84 union smb_dir_cache *cache = NULL; 84 union smb_dir_cache *cache = NULL;
@@ -238,12 +238,12 @@ out:
238static int 238static int
239smb_dir_open(struct inode *dir, struct file *file) 239smb_dir_open(struct inode *dir, struct file *file)
240{ 240{
241 struct dentry *dentry = file->f_dentry; 241 struct dentry *dentry = file->f_path.dentry;
242 struct smb_sb_info *server; 242 struct smb_sb_info *server;
243 int error = 0; 243 int error = 0;
244 244
245 VERBOSE("(%s/%s)\n", dentry->d_parent->d_name.name, 245 VERBOSE("(%s/%s)\n", dentry->d_parent->d_name.name,
246 file->f_dentry->d_name.name); 246 file->f_path.dentry->d_name.name);
247 247
248 /* 248 /*
249 * Directory timestamps in the core protocol aren't updated 249 * Directory timestamps in the core protocol aren't updated
diff --git a/fs/smbfs/file.c b/fs/smbfs/file.c
index 50784d13c87b..e50533a79517 100644
--- a/fs/smbfs/file.c
+++ b/fs/smbfs/file.c
@@ -102,7 +102,7 @@ static int
102smb_readpage(struct file *file, struct page *page) 102smb_readpage(struct file *file, struct page *page)
103{ 103{
104 int error; 104 int error;
105 struct dentry *dentry = file->f_dentry; 105 struct dentry *dentry = file->f_path.dentry;
106 106
107 page_cache_get(page); 107 page_cache_get(page);
108 error = smb_readpage_sync(dentry, page); 108 error = smb_readpage_sync(dentry, page);
@@ -205,7 +205,7 @@ static int
205smb_updatepage(struct file *file, struct page *page, unsigned long offset, 205smb_updatepage(struct file *file, struct page *page, unsigned long offset,
206 unsigned int count) 206 unsigned int count)
207{ 207{
208 struct dentry *dentry = file->f_dentry; 208 struct dentry *dentry = file->f_path.dentry;
209 209
210 DEBUG1("(%s/%s %d@%lld)\n", DENTRY_PATH(dentry), count, 210 DEBUG1("(%s/%s %d@%lld)\n", DENTRY_PATH(dentry), count,
211 ((unsigned long long)page->index << PAGE_CACHE_SHIFT) + offset); 211 ((unsigned long long)page->index << PAGE_CACHE_SHIFT) + offset);
@@ -218,7 +218,7 @@ smb_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
218 unsigned long nr_segs, loff_t pos) 218 unsigned long nr_segs, loff_t pos)
219{ 219{
220 struct file * file = iocb->ki_filp; 220 struct file * file = iocb->ki_filp;
221 struct dentry * dentry = file->f_dentry; 221 struct dentry * dentry = file->f_path.dentry;
222 ssize_t status; 222 ssize_t status;
223 223
224 VERBOSE("file %s/%s, count=%lu@%lu\n", DENTRY_PATH(dentry), 224 VERBOSE("file %s/%s, count=%lu@%lu\n", DENTRY_PATH(dentry),
@@ -243,7 +243,7 @@ out:
243static int 243static int
244smb_file_mmap(struct file * file, struct vm_area_struct * vma) 244smb_file_mmap(struct file * file, struct vm_area_struct * vma)
245{ 245{
246 struct dentry * dentry = file->f_dentry; 246 struct dentry * dentry = file->f_path.dentry;
247 int status; 247 int status;
248 248
249 VERBOSE("file %s/%s, address %lu - %lu\n", 249 VERBOSE("file %s/%s, address %lu - %lu\n",
@@ -264,7 +264,7 @@ static ssize_t
264smb_file_sendfile(struct file *file, loff_t *ppos, 264smb_file_sendfile(struct file *file, loff_t *ppos,
265 size_t count, read_actor_t actor, void *target) 265 size_t count, read_actor_t actor, void *target)
266{ 266{
267 struct dentry *dentry = file->f_dentry; 267 struct dentry *dentry = file->f_path.dentry;
268 ssize_t status; 268 ssize_t status;
269 269
270 VERBOSE("file %s/%s, pos=%Ld, count=%d\n", 270 VERBOSE("file %s/%s, pos=%Ld, count=%d\n",
@@ -323,7 +323,7 @@ smb_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
323 unsigned long nr_segs, loff_t pos) 323 unsigned long nr_segs, loff_t pos)
324{ 324{
325 struct file * file = iocb->ki_filp; 325 struct file * file = iocb->ki_filp;
326 struct dentry * dentry = file->f_dentry; 326 struct dentry * dentry = file->f_path.dentry;
327 ssize_t result; 327 ssize_t result;
328 328
329 VERBOSE("file %s/%s, count=%lu@%lu\n", 329 VERBOSE("file %s/%s, count=%lu@%lu\n",
@@ -355,7 +355,7 @@ static int
355smb_file_open(struct inode *inode, struct file * file) 355smb_file_open(struct inode *inode, struct file * file)
356{ 356{
357 int result; 357 int result;
358 struct dentry *dentry = file->f_dentry; 358 struct dentry *dentry = file->f_path.dentry;
359 int smb_mode = (file->f_mode & O_ACCMODE) - 1; 359 int smb_mode = (file->f_mode & O_ACCMODE) - 1;
360 360
361 lock_kernel(); 361 lock_kernel();
diff --git a/fs/smbfs/proc.c b/fs/smbfs/proc.c
index 40e174db9872..a5ced9e0c6c4 100644
--- a/fs/smbfs/proc.c
+++ b/fs/smbfs/proc.c
@@ -873,7 +873,7 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
873 filp = fget(opt->fd); 873 filp = fget(opt->fd);
874 if (!filp) 874 if (!filp)
875 goto out; 875 goto out;
876 if (!smb_valid_socket(filp->f_dentry->d_inode)) 876 if (!smb_valid_socket(filp->f_path.dentry->d_inode))
877 goto out_putf; 877 goto out_putf;
878 878
879 server->sock_file = filp; 879 server->sock_file = filp;
@@ -898,7 +898,7 @@ smb_newconn(struct smb_sb_info *server, struct smb_conn_opt *opt)
898 /* 898 /*
899 * Store the server in sock user_data (Only used by sunrpc) 899 * Store the server in sock user_data (Only used by sunrpc)
900 */ 900 */
901 sk = SOCKET_I(filp->f_dentry->d_inode)->sk; 901 sk = SOCKET_I(filp->f_path.dentry->d_inode)->sk;
902 sk->sk_user_data = server; 902 sk->sk_user_data = server;
903 903
904 /* chain into the data_ready callback */ 904 /* chain into the data_ready callback */
@@ -1939,7 +1939,7 @@ static int
1939smb_proc_readdir_short(struct file *filp, void *dirent, filldir_t filldir, 1939smb_proc_readdir_short(struct file *filp, void *dirent, filldir_t filldir,
1940 struct smb_cache_control *ctl) 1940 struct smb_cache_control *ctl)
1941{ 1941{
1942 struct dentry *dir = filp->f_dentry; 1942 struct dentry *dir = filp->f_path.dentry;
1943 struct smb_sb_info *server = server_from_dentry(dir); 1943 struct smb_sb_info *server = server_from_dentry(dir);
1944 struct qstr qname; 1944 struct qstr qname;
1945 struct smb_fattr fattr; 1945 struct smb_fattr fattr;
@@ -2291,7 +2291,7 @@ static int
2291smb_proc_readdir_long(struct file *filp, void *dirent, filldir_t filldir, 2291smb_proc_readdir_long(struct file *filp, void *dirent, filldir_t filldir,
2292 struct smb_cache_control *ctl) 2292 struct smb_cache_control *ctl)
2293{ 2293{
2294 struct dentry *dir = filp->f_dentry; 2294 struct dentry *dir = filp->f_path.dentry;
2295 struct smb_sb_info *server = server_from_dentry(dir); 2295 struct smb_sb_info *server = server_from_dentry(dir);
2296 struct qstr qname; 2296 struct qstr qname;
2297 struct smb_fattr fattr; 2297 struct smb_fattr fattr;
@@ -2859,7 +2859,7 @@ static int
2859smb_proc_readdir_null(struct file *filp, void *dirent, filldir_t filldir, 2859smb_proc_readdir_null(struct file *filp, void *dirent, filldir_t filldir,
2860 struct smb_cache_control *ctl) 2860 struct smb_cache_control *ctl)
2861{ 2861{
2862 struct smb_sb_info *server = server_from_dentry(filp->f_dentry); 2862 struct smb_sb_info *server = server_from_dentry(filp->f_path.dentry);
2863 2863
2864 if (smb_proc_ops_wait(server) < 0) 2864 if (smb_proc_ops_wait(server) < 0)
2865 return -EIO; 2865 return -EIO;
diff --git a/fs/smbfs/sock.c b/fs/smbfs/sock.c
index 6815b1b12b68..92ea6b2367d7 100644
--- a/fs/smbfs/sock.c
+++ b/fs/smbfs/sock.c
@@ -82,10 +82,10 @@ server_sock(struct smb_sb_info *server)
82 if (server && (file = server->sock_file)) 82 if (server && (file = server->sock_file))
83 { 83 {
84#ifdef SMBFS_PARANOIA 84#ifdef SMBFS_PARANOIA
85 if (!smb_valid_socket(file->f_dentry->d_inode)) 85 if (!smb_valid_socket(file->f_path.dentry->d_inode))
86 PARANOIA("bad socket!\n"); 86 PARANOIA("bad socket!\n");
87#endif 87#endif
88 return SOCKET_I(file->f_dentry->d_inode); 88 return SOCKET_I(file->f_path.dentry->d_inode);
89 } 89 }
90 return NULL; 90 return NULL;
91} 91}
diff --git a/fs/splice.c b/fs/splice.c
index da74583a00ee..bbd0aeb3f68e 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -844,7 +844,7 @@ generic_file_splice_write_nolock(struct pipe_inode_info *pipe, struct file *out,
844 ssize_t ret; 844 ssize_t ret;
845 int err; 845 int err;
846 846
847 err = remove_suid(out->f_dentry); 847 err = remove_suid(out->f_path.dentry);
848 if (unlikely(err)) 848 if (unlikely(err))
849 return err; 849 return err;
850 850
@@ -890,10 +890,10 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
890 ssize_t ret; 890 ssize_t ret;
891 int err; 891 int err;
892 892
893 err = should_remove_suid(out->f_dentry); 893 err = should_remove_suid(out->f_path.dentry);
894 if (unlikely(err)) { 894 if (unlikely(err)) {
895 mutex_lock(&inode->i_mutex); 895 mutex_lock(&inode->i_mutex);
896 err = __remove_suid(out->f_dentry, err); 896 err = __remove_suid(out->f_path.dentry, err);
897 mutex_unlock(&inode->i_mutex); 897 mutex_unlock(&inode->i_mutex);
898 if (err) 898 if (err)
899 return err; 899 return err;
@@ -1008,7 +1008,7 @@ long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1008 * randomly drop data for eg socket -> socket splicing. Use the 1008 * randomly drop data for eg socket -> socket splicing. Use the
1009 * piped splicing for that! 1009 * piped splicing for that!
1010 */ 1010 */
1011 i_mode = in->f_dentry->d_inode->i_mode; 1011 i_mode = in->f_path.dentry->d_inode->i_mode;
1012 if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode))) 1012 if (unlikely(!S_ISREG(i_mode) && !S_ISBLK(i_mode)))
1013 return -EINVAL; 1013 return -EINVAL;
1014 1014
@@ -1132,7 +1132,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1132 loff_t offset, *off; 1132 loff_t offset, *off;
1133 long ret; 1133 long ret;
1134 1134
1135 pipe = pipe_info(in->f_dentry->d_inode); 1135 pipe = pipe_info(in->f_path.dentry->d_inode);
1136 if (pipe) { 1136 if (pipe) {
1137 if (off_in) 1137 if (off_in)
1138 return -ESPIPE; 1138 return -ESPIPE;
@@ -1153,7 +1153,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1153 return ret; 1153 return ret;
1154 } 1154 }
1155 1155
1156 pipe = pipe_info(out->f_dentry->d_inode); 1156 pipe = pipe_info(out->f_path.dentry->d_inode);
1157 if (pipe) { 1157 if (pipe) {
1158 if (off_out) 1158 if (off_out)
1159 return -ESPIPE; 1159 return -ESPIPE;
@@ -1321,7 +1321,7 @@ static long do_vmsplice(struct file *file, const struct iovec __user *iov,
1321 .ops = &user_page_pipe_buf_ops, 1321 .ops = &user_page_pipe_buf_ops,
1322 }; 1322 };
1323 1323
1324 pipe = pipe_info(file->f_dentry->d_inode); 1324 pipe = pipe_info(file->f_path.dentry->d_inode);
1325 if (!pipe) 1325 if (!pipe)
1326 return -EBADF; 1326 return -EBADF;
1327 if (unlikely(nr_segs > UIO_MAXIOV)) 1327 if (unlikely(nr_segs > UIO_MAXIOV))
@@ -1549,8 +1549,8 @@ static int link_pipe(struct pipe_inode_info *ipipe,
1549static long do_tee(struct file *in, struct file *out, size_t len, 1549static long do_tee(struct file *in, struct file *out, size_t len,
1550 unsigned int flags) 1550 unsigned int flags)
1551{ 1551{
1552 struct pipe_inode_info *ipipe = pipe_info(in->f_dentry->d_inode); 1552 struct pipe_inode_info *ipipe = pipe_info(in->f_path.dentry->d_inode);
1553 struct pipe_inode_info *opipe = pipe_info(out->f_dentry->d_inode); 1553 struct pipe_inode_info *opipe = pipe_info(out->f_path.dentry->d_inode);
1554 int ret = -EINVAL; 1554 int ret = -EINVAL;
1555 1555
1556 /* 1556 /*
diff --git a/fs/stack.c b/fs/stack.c
new file mode 100644
index 000000000000..5ddbc34535f9
--- /dev/null
+++ b/fs/stack.c
@@ -0,0 +1,40 @@
1#include <linux/module.h>
2#include <linux/fs.h>
3#include <linux/fs_stack.h>
4
5/* does _NOT_ require i_mutex to be held.
6 *
7 * This function cannot be inlined since i_size_{read,write} is rather
8 * heavy-weight on 32-bit systems
9 */
10void fsstack_copy_inode_size(struct inode *dst, const struct inode *src)
11{
12 i_size_write(dst, i_size_read((struct inode *)src));
13 dst->i_blocks = src->i_blocks;
14}
15EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
16
17/* copy all attributes; get_nlinks is optional way to override the i_nlink
18 * copying
19 */
20void fsstack_copy_attr_all(struct inode *dest, const struct inode *src,
21 int (*get_nlinks)(struct inode *))
22{
23 if (!get_nlinks)
24 dest->i_nlink = src->i_nlink;
25 else
26 dest->i_nlink = (*get_nlinks)(dest);
27
28 dest->i_mode = src->i_mode;
29 dest->i_uid = src->i_uid;
30 dest->i_gid = src->i_gid;
31 dest->i_rdev = src->i_rdev;
32 dest->i_atime = src->i_atime;
33 dest->i_mtime = src->i_mtime;
34 dest->i_ctime = src->i_ctime;
35 dest->i_blkbits = src->i_blkbits;
36 dest->i_flags = src->i_flags;
37
38 fsstack_copy_inode_size(dest, src);
39}
40EXPORT_SYMBOL_GPL(fsstack_copy_attr_all);
diff --git a/fs/stat.c b/fs/stat.c
index a0ebfc7f8a64..38a8cb2a28de 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -102,7 +102,7 @@ int vfs_fstat(unsigned int fd, struct kstat *stat)
102 int error = -EBADF; 102 int error = -EBADF;
103 103
104 if (f) { 104 if (f) {
105 error = vfs_getattr(f->f_vfsmnt, f->f_dentry, stat); 105 error = vfs_getattr(f->f_path.mnt, f->f_path.dentry, stat);
106 fput(f); 106 fput(f);
107 } 107 }
108 return error; 108 return error;
diff --git a/fs/super.c b/fs/super.c
index 84c320f6ad7e..f961e0307997 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -570,7 +570,7 @@ static void mark_files_ro(struct super_block *sb)
570 570
571 file_list_lock(); 571 file_list_lock();
572 list_for_each_entry(f, &sb->s_files, f_u.fu_list) { 572 list_for_each_entry(f, &sb->s_files, f_u.fu_list) {
573 if (S_ISREG(f->f_dentry->d_inode->i_mode) && file_count(f)) 573 if (S_ISREG(f->f_path.dentry->d_inode->i_mode) && file_count(f))
574 f->f_mode &= ~FMODE_WRITE; 574 f->f_mode &= ~FMODE_WRITE;
575 } 575 }
576 file_list_unlock(); 576 file_list_unlock();
diff --git a/fs/sync.c b/fs/sync.c
index 865f32be386e..d0feff61e6aa 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -94,7 +94,7 @@ long do_fsync(struct file *file, int datasync)
94 * livelocks in fsync_buffers_list(). 94 * livelocks in fsync_buffers_list().
95 */ 95 */
96 mutex_lock(&mapping->host->i_mutex); 96 mutex_lock(&mapping->host->i_mutex);
97 err = file->f_op->fsync(file, file->f_dentry, datasync); 97 err = file->f_op->fsync(file, file->f_path.dentry, datasync);
98 if (!ret) 98 if (!ret)
99 ret = err; 99 ret = err;
100 mutex_unlock(&mapping->host->i_mutex); 100 mutex_unlock(&mapping->host->i_mutex);
@@ -223,7 +223,7 @@ asmlinkage long sys_sync_file_range(int fd, loff_t offset, loff_t nbytes,
223 if (!file) 223 if (!file)
224 goto out; 224 goto out;
225 225
226 i_mode = file->f_dentry->d_inode->i_mode; 226 i_mode = file->f_path.dentry->d_inode->i_mode;
227 ret = -ESPIPE; 227 ret = -ESPIPE;
228 if (!S_ISREG(i_mode) && !S_ISBLK(i_mode) && !S_ISDIR(i_mode) && 228 if (!S_ISREG(i_mode) && !S_ISBLK(i_mode) && !S_ISDIR(i_mode) &&
229 !S_ISLNK(i_mode)) 229 !S_ISLNK(i_mode))
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 98022e41cda1..e8f540d38d48 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -35,7 +35,7 @@ static ssize_t
35read(struct file * file, char __user * userbuf, size_t count, loff_t * off) 35read(struct file * file, char __user * userbuf, size_t count, loff_t * off)
36{ 36{
37 char *buffer = file->private_data; 37 char *buffer = file->private_data;
38 struct dentry *dentry = file->f_dentry; 38 struct dentry *dentry = file->f_path.dentry;
39 int size = dentry->d_inode->i_size; 39 int size = dentry->d_inode->i_size;
40 loff_t offs = *off; 40 loff_t offs = *off;
41 int ret; 41 int ret;
@@ -81,7 +81,7 @@ static ssize_t write(struct file * file, const char __user * userbuf,
81 size_t count, loff_t * off) 81 size_t count, loff_t * off)
82{ 82{
83 char *buffer = file->private_data; 83 char *buffer = file->private_data;
84 struct dentry *dentry = file->f_dentry; 84 struct dentry *dentry = file->f_path.dentry;
85 int size = dentry->d_inode->i_size; 85 int size = dentry->d_inode->i_size;
86 loff_t offs = *off; 86 loff_t offs = *off;
87 87
@@ -105,7 +105,7 @@ static ssize_t write(struct file * file, const char __user * userbuf,
105 105
106static int mmap(struct file *file, struct vm_area_struct *vma) 106static int mmap(struct file *file, struct vm_area_struct *vma)
107{ 107{
108 struct dentry *dentry = file->f_dentry; 108 struct dentry *dentry = file->f_path.dentry;
109 struct bin_attribute *attr = to_bin_attr(dentry); 109 struct bin_attribute *attr = to_bin_attr(dentry);
110 struct kobject *kobj = to_kobj(dentry->d_parent); 110 struct kobject *kobj = to_kobj(dentry->d_parent);
111 111
@@ -117,8 +117,8 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
117 117
118static int open(struct inode * inode, struct file * file) 118static int open(struct inode * inode, struct file * file)
119{ 119{
120 struct kobject *kobj = sysfs_get_kobject(file->f_dentry->d_parent); 120 struct kobject *kobj = sysfs_get_kobject(file->f_path.dentry->d_parent);
121 struct bin_attribute * attr = to_bin_attr(file->f_dentry); 121 struct bin_attribute * attr = to_bin_attr(file->f_path.dentry);
122 int error = -EINVAL; 122 int error = -EINVAL;
123 123
124 if (!kobj || !attr) 124 if (!kobj || !attr)
@@ -153,8 +153,8 @@ static int open(struct inode * inode, struct file * file)
153 153
154static int release(struct inode * inode, struct file * file) 154static int release(struct inode * inode, struct file * file)
155{ 155{
156 struct kobject * kobj = to_kobj(file->f_dentry->d_parent); 156 struct kobject * kobj = to_kobj(file->f_path.dentry->d_parent);
157 struct bin_attribute * attr = to_bin_attr(file->f_dentry); 157 struct bin_attribute * attr = to_bin_attr(file->f_path.dentry);
158 u8 * buffer = file->private_data; 158 u8 * buffer = file->private_data;
159 159
160 if (kobj) 160 if (kobj)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index a5782e8c7f07..511edef8b321 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -419,7 +419,7 @@ out:
419 419
420static int sysfs_dir_open(struct inode *inode, struct file *file) 420static int sysfs_dir_open(struct inode *inode, struct file *file)
421{ 421{
422 struct dentry * dentry = file->f_dentry; 422 struct dentry * dentry = file->f_path.dentry;
423 struct sysfs_dirent * parent_sd = dentry->d_fsdata; 423 struct sysfs_dirent * parent_sd = dentry->d_fsdata;
424 424
425 mutex_lock(&dentry->d_inode->i_mutex); 425 mutex_lock(&dentry->d_inode->i_mutex);
@@ -432,7 +432,7 @@ static int sysfs_dir_open(struct inode *inode, struct file *file)
432 432
433static int sysfs_dir_close(struct inode *inode, struct file *file) 433static int sysfs_dir_close(struct inode *inode, struct file *file)
434{ 434{
435 struct dentry * dentry = file->f_dentry; 435 struct dentry * dentry = file->f_path.dentry;
436 struct sysfs_dirent * cursor = file->private_data; 436 struct sysfs_dirent * cursor = file->private_data;
437 437
438 mutex_lock(&dentry->d_inode->i_mutex); 438 mutex_lock(&dentry->d_inode->i_mutex);
@@ -452,7 +452,7 @@ static inline unsigned char dt_type(struct sysfs_dirent *sd)
452 452
453static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) 453static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
454{ 454{
455 struct dentry *dentry = filp->f_dentry; 455 struct dentry *dentry = filp->f_path.dentry;
456 struct sysfs_dirent * parent_sd = dentry->d_fsdata; 456 struct sysfs_dirent * parent_sd = dentry->d_fsdata;
457 struct sysfs_dirent *cursor = filp->private_data; 457 struct sysfs_dirent *cursor = filp->private_data;
458 struct list_head *p, *q = &cursor->s_sibling; 458 struct list_head *p, *q = &cursor->s_sibling;
@@ -509,7 +509,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
509 509
510static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin) 510static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
511{ 511{
512 struct dentry * dentry = file->f_dentry; 512 struct dentry * dentry = file->f_path.dentry;
513 513
514 mutex_lock(&dentry->d_inode->i_mutex); 514 mutex_lock(&dentry->d_inode->i_mutex);
515 switch (origin) { 515 switch (origin) {
@@ -519,7 +519,7 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
519 if (offset >= 0) 519 if (offset >= 0)
520 break; 520 break;
521 default: 521 default:
522 mutex_unlock(&file->f_dentry->d_inode->i_mutex); 522 mutex_unlock(&file->f_path.dentry->d_inode->i_mutex);
523 return -EINVAL; 523 return -EINVAL;
524 } 524 }
525 if (offset != file->f_pos) { 525 if (offset != file->f_pos) {
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 95c165101c98..9cfe53e1e00d 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -154,7 +154,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
154 154
155 down(&buffer->sem); 155 down(&buffer->sem);
156 if (buffer->needs_read_fill) { 156 if (buffer->needs_read_fill) {
157 if ((retval = fill_read_buffer(file->f_dentry,buffer))) 157 if ((retval = fill_read_buffer(file->f_path.dentry,buffer)))
158 goto out; 158 goto out;
159 } 159 }
160 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 160 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
@@ -245,7 +245,7 @@ sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t
245 down(&buffer->sem); 245 down(&buffer->sem);
246 len = fill_write_buffer(buffer, buf, count); 246 len = fill_write_buffer(buffer, buf, count);
247 if (len > 0) 247 if (len > 0)
248 len = flush_write_buffer(file->f_dentry, buffer, len); 248 len = flush_write_buffer(file->f_path.dentry, buffer, len);
249 if (len > 0) 249 if (len > 0)
250 *ppos += len; 250 *ppos += len;
251 up(&buffer->sem); 251 up(&buffer->sem);
@@ -254,8 +254,8 @@ sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t
254 254
255static int check_perm(struct inode * inode, struct file * file) 255static int check_perm(struct inode * inode, struct file * file)
256{ 256{
257 struct kobject *kobj = sysfs_get_kobject(file->f_dentry->d_parent); 257 struct kobject *kobj = sysfs_get_kobject(file->f_path.dentry->d_parent);
258 struct attribute * attr = to_attr(file->f_dentry); 258 struct attribute * attr = to_attr(file->f_path.dentry);
259 struct sysfs_buffer * buffer; 259 struct sysfs_buffer * buffer;
260 struct sysfs_ops * ops = NULL; 260 struct sysfs_ops * ops = NULL;
261 int error = 0; 261 int error = 0;
@@ -337,8 +337,8 @@ static int sysfs_open_file(struct inode * inode, struct file * filp)
337 337
338static int sysfs_release(struct inode * inode, struct file * filp) 338static int sysfs_release(struct inode * inode, struct file * filp)
339{ 339{
340 struct kobject * kobj = to_kobj(filp->f_dentry->d_parent); 340 struct kobject * kobj = to_kobj(filp->f_path.dentry->d_parent);
341 struct attribute * attr = to_attr(filp->f_dentry); 341 struct attribute * attr = to_attr(filp->f_path.dentry);
342 struct module * owner = attr->owner; 342 struct module * owner = attr->owner;
343 struct sysfs_buffer * buffer = filp->private_data; 343 struct sysfs_buffer * buffer = filp->private_data;
344 344
@@ -372,8 +372,8 @@ static int sysfs_release(struct inode * inode, struct file * filp)
372static unsigned int sysfs_poll(struct file *filp, poll_table *wait) 372static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
373{ 373{
374 struct sysfs_buffer * buffer = filp->private_data; 374 struct sysfs_buffer * buffer = filp->private_data;
375 struct kobject * kobj = to_kobj(filp->f_dentry->d_parent); 375 struct kobject * kobj = to_kobj(filp->f_path.dentry->d_parent);
376 struct sysfs_dirent * sd = filp->f_dentry->d_fsdata; 376 struct sysfs_dirent * sd = filp->f_path.dentry->d_fsdata;
377 int res = 0; 377 int res = 0;
378 378
379 poll_wait(filp, &kobj->poll, wait); 379 poll_wait(filp, &kobj->poll, wait);
diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c
index f2bef962d309..ebf7007fa161 100644
--- a/fs/sysv/dir.c
+++ b/fs/sysv/dir.c
@@ -70,7 +70,7 @@ fail:
70static int sysv_readdir(struct file * filp, void * dirent, filldir_t filldir) 70static int sysv_readdir(struct file * filp, void * dirent, filldir_t filldir)
71{ 71{
72 unsigned long pos = filp->f_pos; 72 unsigned long pos = filp->f_pos;
73 struct inode *inode = filp->f_dentry->d_inode; 73 struct inode *inode = filp->f_path.dentry->d_inode;
74 struct super_block *sb = inode->i_sb; 74 struct super_block *sb = inode->i_sb;
75 unsigned offset = pos & ~PAGE_CACHE_MASK; 75 unsigned offset = pos & ~PAGE_CACHE_MASK;
76 unsigned long n = pos >> PAGE_CACHE_SHIFT; 76 unsigned long n = pos >> PAGE_CACHE_SHIFT;
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index 8c28efa3b8ff..2391c9150c49 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -77,7 +77,7 @@ const struct file_operations udf_dir_operations = {
77 77
78int udf_readdir(struct file *filp, void *dirent, filldir_t filldir) 78int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
79{ 79{
80 struct inode *dir = filp->f_dentry->d_inode; 80 struct inode *dir = filp->f_path.dentry->d_inode;
81 int result; 81 int result;
82 82
83 lock_kernel(); 83 lock_kernel();
@@ -225,7 +225,7 @@ do_udf_readdir(struct inode * dir, struct file *filp, filldir_t filldir, void *d
225 225
226 if ( cfi.fileCharacteristics & FID_FILE_CHAR_PARENT ) 226 if ( cfi.fileCharacteristics & FID_FILE_CHAR_PARENT )
227 { 227 {
228 iblock = parent_ino(filp->f_dentry); 228 iblock = parent_ino(filp->f_path.dentry);
229 flen = 2; 229 flen = 2;
230 memcpy(fname, "..", flen); 230 memcpy(fname, "..", flen);
231 dt_type = DT_DIR; 231 dt_type = DT_DIR;
diff --git a/fs/udf/file.c b/fs/udf/file.c
index 7aedd552cba1..d81f2db7b0e3 100644
--- a/fs/udf/file.c
+++ b/fs/udf/file.c
@@ -108,7 +108,7 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
108{ 108{
109 ssize_t retval; 109 ssize_t retval;
110 struct file *file = iocb->ki_filp; 110 struct file *file = iocb->ki_filp;
111 struct inode *inode = file->f_dentry->d_inode; 111 struct inode *inode = file->f_path.dentry->d_inode;
112 int err, pos; 112 int err, pos;
113 size_t count = iocb->ki_left; 113 size_t count = iocb->ki_left;
114 114
diff --git a/fs/ufs/dir.c b/fs/ufs/dir.c
index 7f0a0aa63584..433b6f68403a 100644
--- a/fs/ufs/dir.c
+++ b/fs/ufs/dir.c
@@ -426,7 +426,7 @@ static int
426ufs_readdir(struct file *filp, void *dirent, filldir_t filldir) 426ufs_readdir(struct file *filp, void *dirent, filldir_t filldir)
427{ 427{
428 loff_t pos = filp->f_pos; 428 loff_t pos = filp->f_pos;
429 struct inode *inode = filp->f_dentry->d_inode; 429 struct inode *inode = filp->f_path.dentry->d_inode;
430 struct super_block *sb = inode->i_sb; 430 struct super_block *sb = inode->i_sb;
431 unsigned int offset = pos & ~PAGE_CACHE_MASK; 431 unsigned int offset = pos & ~PAGE_CACHE_MASK;
432 unsigned long n = pos >> PAGE_CACHE_SHIFT; 432 unsigned long n = pos >> PAGE_CACHE_SHIFT;
diff --git a/fs/xattr.c b/fs/xattr.c
index 0901bdc2ce24..38646132ab0e 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -268,7 +268,7 @@ sys_fsetxattr(int fd, char __user *name, void __user *value,
268 f = fget(fd); 268 f = fget(fd);
269 if (!f) 269 if (!f)
270 return error; 270 return error;
271 dentry = f->f_dentry; 271 dentry = f->f_path.dentry;
272 audit_inode(NULL, dentry->d_inode); 272 audit_inode(NULL, dentry->d_inode);
273 error = setxattr(dentry, name, value, size, flags); 273 error = setxattr(dentry, name, value, size, flags);
274 fput(f); 274 fput(f);
@@ -351,7 +351,7 @@ sys_fgetxattr(int fd, char __user *name, void __user *value, size_t size)
351 f = fget(fd); 351 f = fget(fd);
352 if (!f) 352 if (!f)
353 return error; 353 return error;
354 error = getxattr(f->f_dentry, name, value, size); 354 error = getxattr(f->f_path.dentry, name, value, size);
355 fput(f); 355 fput(f);
356 return error; 356 return error;
357} 357}
@@ -423,7 +423,7 @@ sys_flistxattr(int fd, char __user *list, size_t size)
423 f = fget(fd); 423 f = fget(fd);
424 if (!f) 424 if (!f)
425 return error; 425 return error;
426 error = listxattr(f->f_dentry, list, size); 426 error = listxattr(f->f_path.dentry, list, size);
427 fput(f); 427 fput(f);
428 return error; 428 return error;
429} 429}
@@ -484,7 +484,7 @@ sys_fremovexattr(int fd, char __user *name)
484 f = fget(fd); 484 f = fget(fd);
485 if (!f) 485 if (!f)
486 return error; 486 return error;
487 dentry = f->f_dentry; 487 dentry = f->f_path.dentry;
488 audit_inode(NULL, dentry->d_inode); 488 audit_inode(NULL, dentry->d_inode);
489 error = removexattr(dentry, name); 489 error = removexattr(dentry, name);
490 fput(f); 490 fput(f);
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index 8e6b56fc1cad..b56eb754e2d2 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -1406,7 +1406,7 @@ xfs_vm_direct_IO(
1406 xfs_end_io_direct); 1406 xfs_end_io_direct);
1407 } 1407 }
1408 1408
1409 if (unlikely(ret <= 0 && iocb->private)) 1409 if (unlikely(ret != -EIOCBQUEUED && iocb->private))
1410 xfs_destroy_ioend(iocb->private); 1410 xfs_destroy_ioend(iocb->private);
1411 return ret; 1411 return ret;
1412} 1412}
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index d93d8dd1958d..d26f5cd2ba70 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -55,7 +55,7 @@ __xfs_file_read(
55 loff_t pos) 55 loff_t pos)
56{ 56{
57 struct file *file = iocb->ki_filp; 57 struct file *file = iocb->ki_filp;
58 bhv_vnode_t *vp = vn_from_inode(file->f_dentry->d_inode); 58 bhv_vnode_t *vp = vn_from_inode(file->f_path.dentry->d_inode);
59 59
60 BUG_ON(iocb->ki_pos != pos); 60 BUG_ON(iocb->ki_pos != pos);
61 if (unlikely(file->f_flags & O_DIRECT)) 61 if (unlikely(file->f_flags & O_DIRECT))
@@ -131,7 +131,7 @@ xfs_file_sendfile(
131 read_actor_t actor, 131 read_actor_t actor,
132 void *target) 132 void *target)
133{ 133{
134 return bhv_vop_sendfile(vn_from_inode(filp->f_dentry->d_inode), 134 return bhv_vop_sendfile(vn_from_inode(filp->f_path.dentry->d_inode),
135 filp, pos, 0, count, actor, target, NULL); 135 filp, pos, 0, count, actor, target, NULL);
136} 136}
137 137
@@ -143,7 +143,7 @@ xfs_file_sendfile_invis(
143 read_actor_t actor, 143 read_actor_t actor,
144 void *target) 144 void *target)
145{ 145{
146 return bhv_vop_sendfile(vn_from_inode(filp->f_dentry->d_inode), 146 return bhv_vop_sendfile(vn_from_inode(filp->f_path.dentry->d_inode),
147 filp, pos, IO_INVIS, count, actor, target, NULL); 147 filp, pos, IO_INVIS, count, actor, target, NULL);
148} 148}
149 149
@@ -155,7 +155,7 @@ xfs_file_splice_read(
155 size_t len, 155 size_t len,
156 unsigned int flags) 156 unsigned int flags)
157{ 157{
158 return bhv_vop_splice_read(vn_from_inode(infilp->f_dentry->d_inode), 158 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
159 infilp, ppos, pipe, len, flags, 0, NULL); 159 infilp, ppos, pipe, len, flags, 0, NULL);
160} 160}
161 161
@@ -167,7 +167,7 @@ xfs_file_splice_read_invis(
167 size_t len, 167 size_t len,
168 unsigned int flags) 168 unsigned int flags)
169{ 169{
170 return bhv_vop_splice_read(vn_from_inode(infilp->f_dentry->d_inode), 170 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
171 infilp, ppos, pipe, len, flags, IO_INVIS, 171 infilp, ppos, pipe, len, flags, IO_INVIS,
172 NULL); 172 NULL);
173} 173}
@@ -180,7 +180,7 @@ xfs_file_splice_write(
180 size_t len, 180 size_t len,
181 unsigned int flags) 181 unsigned int flags)
182{ 182{
183 return bhv_vop_splice_write(vn_from_inode(outfilp->f_dentry->d_inode), 183 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
184 pipe, outfilp, ppos, len, flags, 0, NULL); 184 pipe, outfilp, ppos, len, flags, 0, NULL);
185} 185}
186 186
@@ -192,7 +192,7 @@ xfs_file_splice_write_invis(
192 size_t len, 192 size_t len,
193 unsigned int flags) 193 unsigned int flags)
194{ 194{
195 return bhv_vop_splice_write(vn_from_inode(outfilp->f_dentry->d_inode), 195 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
196 pipe, outfilp, ppos, len, flags, IO_INVIS, 196 pipe, outfilp, ppos, len, flags, IO_INVIS,
197 NULL); 197 NULL);
198} 198}
@@ -212,7 +212,7 @@ xfs_file_close(
212 struct file *filp, 212 struct file *filp,
213 fl_owner_t id) 213 fl_owner_t id)
214{ 214{
215 return -bhv_vop_close(vn_from_inode(filp->f_dentry->d_inode), 0, 215 return -bhv_vop_close(vn_from_inode(filp->f_path.dentry->d_inode), 0,
216 file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL); 216 file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL);
217} 217}
218 218
@@ -251,7 +251,7 @@ xfs_vm_nopage(
251 unsigned long address, 251 unsigned long address,
252 int *type) 252 int *type)
253{ 253{
254 struct inode *inode = area->vm_file->f_dentry->d_inode; 254 struct inode *inode = area->vm_file->f_path.dentry->d_inode;
255 bhv_vnode_t *vp = vn_from_inode(inode); 255 bhv_vnode_t *vp = vn_from_inode(inode);
256 256
257 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); 257 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
@@ -268,7 +268,7 @@ xfs_file_readdir(
268 filldir_t filldir) 268 filldir_t filldir)
269{ 269{
270 int error = 0; 270 int error = 0;
271 bhv_vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode); 271 bhv_vnode_t *vp = vn_from_inode(filp->f_path.dentry->d_inode);
272 uio_t uio; 272 uio_t uio;
273 iovec_t iov; 273 iovec_t iov;
274 int eof = 0; 274 int eof = 0;
@@ -345,7 +345,7 @@ xfs_file_mmap(
345 vma->vm_ops = &xfs_file_vm_ops; 345 vma->vm_ops = &xfs_file_vm_ops;
346 346
347#ifdef CONFIG_XFS_DMAPI 347#ifdef CONFIG_XFS_DMAPI
348 if (vn_from_inode(filp->f_dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI) 348 if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
349 vma->vm_ops = &xfs_dmapi_file_vm_ops; 349 vma->vm_ops = &xfs_dmapi_file_vm_ops;
350#endif /* CONFIG_XFS_DMAPI */ 350#endif /* CONFIG_XFS_DMAPI */
351 351
@@ -360,7 +360,7 @@ xfs_file_ioctl(
360 unsigned long p) 360 unsigned long p)
361{ 361{
362 int error; 362 int error;
363 struct inode *inode = filp->f_dentry->d_inode; 363 struct inode *inode = filp->f_path.dentry->d_inode;
364 bhv_vnode_t *vp = vn_from_inode(inode); 364 bhv_vnode_t *vp = vn_from_inode(inode);
365 365
366 error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p); 366 error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p);
@@ -382,7 +382,7 @@ xfs_file_ioctl_invis(
382 unsigned long p) 382 unsigned long p)
383{ 383{
384 int error; 384 int error;
385 struct inode *inode = filp->f_dentry->d_inode; 385 struct inode *inode = filp->f_path.dentry->d_inode;
386 bhv_vnode_t *vp = vn_from_inode(inode); 386 bhv_vnode_t *vp = vn_from_inode(inode);
387 387
388 error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p); 388 error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p);
@@ -404,7 +404,7 @@ xfs_vm_mprotect(
404 struct vm_area_struct *vma, 404 struct vm_area_struct *vma,
405 unsigned int newflags) 405 unsigned int newflags)
406{ 406{
407 bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_dentry->d_inode); 407 bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_path.dentry->d_inode);
408 int error = 0; 408 int error = 0;
409 409
410 if (vp->v_vfsp->vfs_flag & VFS_DMI) { 410 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index 74d094829a4d..f011c9cd0d62 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -107,9 +107,9 @@ xfs_find_handle(
107 if (!file) 107 if (!file)
108 return -EBADF; 108 return -EBADF;
109 109
110 ASSERT(file->f_dentry); 110 ASSERT(file->f_path.dentry);
111 ASSERT(file->f_dentry->d_inode); 111 ASSERT(file->f_path.dentry->d_inode);
112 inode = igrab(file->f_dentry->d_inode); 112 inode = igrab(file->f_path.dentry->d_inode);
113 fput(file); 113 fput(file);
114 break; 114 break;
115 } 115 }
@@ -333,10 +333,10 @@ xfs_open_by_handle(
333 } 333 }
334 334
335 /* Ensure umount returns EBUSY on umounts while this file is open. */ 335 /* Ensure umount returns EBUSY on umounts while this file is open. */
336 mntget(parfilp->f_vfsmnt); 336 mntget(parfilp->f_path.mnt);
337 337
338 /* Create file pointer. */ 338 /* Create file pointer. */
339 filp = dentry_open(dentry, parfilp->f_vfsmnt, hreq.oflags); 339 filp = dentry_open(dentry, parfilp->f_path.mnt, hreq.oflags);
340 if (IS_ERR(filp)) { 340 if (IS_ERR(filp)) {
341 put_unused_fd(new_fd); 341 put_unused_fd(new_fd);
342 return -XFS_ERROR(-PTR_ERR(filp)); 342 return -XFS_ERROR(-PTR_ERR(filp));
diff --git a/fs/xfs/linux-2.6/xfs_ioctl32.c b/fs/xfs/linux-2.6/xfs_ioctl32.c
index 270db0f3861d..b83cebc165f1 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl32.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl32.c
@@ -112,7 +112,7 @@ xfs_compat_ioctl(
112 unsigned cmd, 112 unsigned cmd,
113 unsigned long arg) 113 unsigned long arg)
114{ 114{
115 struct inode *inode = file->f_dentry->d_inode; 115 struct inode *inode = file->f_path.dentry->d_inode;
116 bhv_vnode_t *vp = vn_from_inode(inode); 116 bhv_vnode_t *vp = vn_from_inode(inode);
117 int error; 117 int error;
118 118
diff --git a/fs/xfs/linux-2.6/xfs_lrw.c b/fs/xfs/linux-2.6/xfs_lrw.c
index fa842f1c9fa2..65e79b471d49 100644
--- a/fs/xfs/linux-2.6/xfs_lrw.c
+++ b/fs/xfs/linux-2.6/xfs_lrw.c
@@ -805,7 +805,7 @@ start:
805 !capable(CAP_FSETID)) { 805 !capable(CAP_FSETID)) {
806 error = xfs_write_clear_setuid(xip); 806 error = xfs_write_clear_setuid(xip);
807 if (likely(!error)) 807 if (likely(!error))
808 error = -remove_suid(file->f_dentry); 808 error = -remove_suid(file->f_path.dentry);
809 if (unlikely(error)) { 809 if (unlikely(error)) {
810 xfs_iunlock(xip, iolock); 810 xfs_iunlock(xip, iolock);
811 goto out_unlock_mutex; 811 goto out_unlock_mutex;
diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 80562b60fb95..50d0faea371d 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -71,7 +71,7 @@ xfs_swapext(
71 71
72 /* Pull information for the target fd */ 72 /* Pull information for the target fd */
73 if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) || 73 if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) ||
74 ((vp = vn_from_inode(fp->f_dentry->d_inode)) == NULL)) { 74 ((vp = vn_from_inode(fp->f_path.dentry->d_inode)) == NULL)) {
75 error = XFS_ERROR(EINVAL); 75 error = XFS_ERROR(EINVAL);
76 goto error0; 76 goto error0;
77 } 77 }
@@ -83,7 +83,7 @@ xfs_swapext(
83 } 83 }
84 84
85 if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) || 85 if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) ||
86 ((tvp = vn_from_inode(tfp->f_dentry->d_inode)) == NULL)) { 86 ((tvp = vn_from_inode(tfp->f_path.dentry->d_inode)) == NULL)) {
87 error = XFS_ERROR(EINVAL); 87 error = XFS_ERROR(EINVAL);
88 goto error0; 88 goto error0;
89 } 89 }
diff --git a/include/asm-alpha/termbits.h b/include/asm-alpha/termbits.h
index 5541101b58ae..ad854a4a3af6 100644
--- a/include/asm-alpha/termbits.h
+++ b/include/asm-alpha/termbits.h
@@ -25,6 +25,19 @@ struct termios {
25 speed_t c_ospeed; /* output speed */ 25 speed_t c_ospeed; /* output speed */
26}; 26};
27 27
28/* Alpha has matching termios and ktermios */
29
30struct ktermios {
31 tcflag_t c_iflag; /* input mode flags */
32 tcflag_t c_oflag; /* output mode flags */
33 tcflag_t c_cflag; /* control mode flags */
34 tcflag_t c_lflag; /* local mode flags */
35 cc_t c_cc[NCCS]; /* control characters */
36 cc_t c_line; /* line discipline (== c_cc[19]) */
37 speed_t c_ispeed; /* input speed */
38 speed_t c_ospeed; /* output speed */
39};
40
28/* c_cc characters */ 41/* c_cc characters */
29#define VEOF 0 42#define VEOF 0
30#define VEOL 1 43#define VEOL 1
diff --git a/include/asm-arm/arch-pnx4008/i2c.h b/include/asm-arm/arch-pnx4008/i2c.h
new file mode 100644
index 000000000000..92e8d65006f7
--- /dev/null
+++ b/include/asm-arm/arch-pnx4008/i2c.h
@@ -0,0 +1,67 @@
1/*
2 * PNX4008-specific tweaks for I2C IP3204 block
3 *
4 * Author: Vitaly Wool <vwool@ru.mvista.com>
5 *
6 * 2005 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef __ASM_ARCH_I2C_H__
13#define __ASM_ARCH_I2C_H__
14
15#include <linux/pm.h>
16#include <linux/platform_device.h>
17
18enum {
19 mstatus_tdi = 0x00000001,
20 mstatus_afi = 0x00000002,
21 mstatus_nai = 0x00000004,
22 mstatus_drmi = 0x00000008,
23 mstatus_active = 0x00000020,
24 mstatus_scl = 0x00000040,
25 mstatus_sda = 0x00000080,
26 mstatus_rff = 0x00000100,
27 mstatus_rfe = 0x00000200,
28 mstatus_tff = 0x00000400,
29 mstatus_tfe = 0x00000800,
30};
31
32enum {
33 mcntrl_tdie = 0x00000001,
34 mcntrl_afie = 0x00000002,
35 mcntrl_naie = 0x00000004,
36 mcntrl_drmie = 0x00000008,
37 mcntrl_daie = 0x00000020,
38 mcntrl_rffie = 0x00000040,
39 mcntrl_tffie = 0x00000080,
40 mcntrl_reset = 0x00000100,
41 mcntrl_cdbmode = 0x00000400,
42};
43
44enum {
45 rw_bit = 1 << 0,
46 start_bit = 1 << 8,
47 stop_bit = 1 << 9,
48};
49
50#define I2C_REG_RX(a) ((a)->ioaddr) /* Rx FIFO reg (RO) */
51#define I2C_REG_TX(a) ((a)->ioaddr) /* Tx FIFO reg (WO) */
52#define I2C_REG_STS(a) ((a)->ioaddr + 0x04) /* Status reg (RO) */
53#define I2C_REG_CTL(a) ((a)->ioaddr + 0x08) /* Ctl reg */
54#define I2C_REG_CKL(a) ((a)->ioaddr + 0x0c) /* Clock divider low */
55#define I2C_REG_CKH(a) ((a)->ioaddr + 0x10) /* Clock divider high */
56#define I2C_REG_ADR(a) ((a)->ioaddr + 0x14) /* I2C address */
57#define I2C_REG_RFL(a) ((a)->ioaddr + 0x18) /* Rx FIFO level (RO) */
58#define I2C_REG_TFL(a) ((a)->ioaddr + 0x1c) /* Tx FIFO level (RO) */
59#define I2C_REG_RXB(a) ((a)->ioaddr + 0x20) /* Num of bytes Rx-ed (RO) */
60#define I2C_REG_TXB(a) ((a)->ioaddr + 0x24) /* Num of bytes Tx-ed (RO) */
61#define I2C_REG_TXS(a) ((a)->ioaddr + 0x28) /* Tx slave FIFO (RO) */
62#define I2C_REG_STFL(a) ((a)->ioaddr + 0x2c) /* Tx slave FIFO level (RO) */
63
64#define HCLK_MHZ 13
65#define I2C_CHIP_NAME "PNX4008-I2C"
66
67#endif /* __ASM_ARCH_I2C_H___ */
diff --git a/include/asm-arm/arch-pxa/pxa2xx_spi.h b/include/asm-arm/arch-pxa/pxa2xx_spi.h
index 915590c391c8..acc7ec7a84a1 100644
--- a/include/asm-arm/arch-pxa/pxa2xx_spi.h
+++ b/include/asm-arm/arch-pxa/pxa2xx_spi.h
@@ -27,16 +27,13 @@
27#define SSP1_SerClkDiv(x) (((CLOCK_SPEED_HZ/2/(x+1))<<8)&0x0000ff00) 27#define SSP1_SerClkDiv(x) (((CLOCK_SPEED_HZ/2/(x+1))<<8)&0x0000ff00)
28#define SSP2_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00) 28#define SSP2_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00)
29#define SSP3_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00) 29#define SSP3_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00)
30#define SSP_TIMEOUT_SCALE (2712)
31#elif defined(CONFIG_PXA27x) 30#elif defined(CONFIG_PXA27x)
32#define CLOCK_SPEED_HZ 13000000 31#define CLOCK_SPEED_HZ 13000000
33#define SSP1_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00) 32#define SSP1_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00)
34#define SSP2_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00) 33#define SSP2_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00)
35#define SSP3_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00) 34#define SSP3_SerClkDiv(x) (((CLOCK_SPEED_HZ/(x+1))<<8)&0x000fff00)
36#define SSP_TIMEOUT_SCALE (769)
37#endif 35#endif
38 36
39#define SSP_TIMEOUT(x) ((x*10000)/SSP_TIMEOUT_SCALE)
40#define SSP1_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(1))))) 37#define SSP1_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(1)))))
41#define SSP2_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(2))))) 38#define SSP2_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(2)))))
42#define SSP3_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(3))))) 39#define SSP3_VIRT ((void *)(io_p2v(__PREG(SSCR0_P(3)))))
@@ -63,7 +60,7 @@ struct pxa2xx_spi_chip {
63 u8 tx_threshold; 60 u8 tx_threshold;
64 u8 rx_threshold; 61 u8 rx_threshold;
65 u8 dma_burst_size; 62 u8 dma_burst_size;
66 u32 timeout_microsecs; 63 u32 timeout;
67 u8 enable_loopback; 64 u8 enable_loopback;
68 void (*cs_control)(u32 command); 65 void (*cs_control)(u32 command);
69}; 66};
diff --git a/include/asm-arm/arch-s3c2410/fb.h b/include/asm-arm/arch-s3c2410/fb.h
index 90894214cace..93a58e7862b0 100644
--- a/include/asm-arm/arch-s3c2410/fb.h
+++ b/include/asm-arm/arch-s3c2410/fb.h
@@ -31,6 +31,9 @@ struct s3c2410fb_hw {
31struct s3c2410fb_mach_info { 31struct s3c2410fb_mach_info {
32 unsigned char fixed_syncs; /* do not update sync/border */ 32 unsigned char fixed_syncs; /* do not update sync/border */
33 33
34 /* LCD types */
35 int type;
36
34 /* Screen size */ 37 /* Screen size */
35 int width; 38 int width;
36 int height; 39 int height;
diff --git a/include/asm-arm/termbits.h b/include/asm-arm/termbits.h
index bbc6e1d24d3f..a3f4fe1742d0 100644
--- a/include/asm-arm/termbits.h
+++ b/include/asm-arm/termbits.h
@@ -15,6 +15,18 @@ struct termios {
15 cc_t c_cc[NCCS]; /* control characters */ 15 cc_t c_cc[NCCS]; /* control characters */
16}; 16};
17 17
18struct ktermios {
19 tcflag_t c_iflag; /* input mode flags */
20 tcflag_t c_oflag; /* output mode flags */
21 tcflag_t c_cflag; /* control mode flags */
22 tcflag_t c_lflag; /* local mode flags */
23 cc_t c_line; /* line discipline */
24 cc_t c_cc[NCCS]; /* control characters */
25 speed_t c_ispeed; /* input speed */
26 speed_t c_ospeed; /* output speed */
27};
28
29
18/* c_cc characters */ 30/* c_cc characters */
19#define VINTR 0 31#define VINTR 0
20#define VQUIT 1 32#define VQUIT 1
diff --git a/include/asm-arm26/termbits.h b/include/asm-arm26/termbits.h
index bbc6e1d24d3f..a3f4fe1742d0 100644
--- a/include/asm-arm26/termbits.h
+++ b/include/asm-arm26/termbits.h
@@ -15,6 +15,18 @@ struct termios {
15 cc_t c_cc[NCCS]; /* control characters */ 15 cc_t c_cc[NCCS]; /* control characters */
16}; 16};
17 17
18struct ktermios {
19 tcflag_t c_iflag; /* input mode flags */
20 tcflag_t c_oflag; /* output mode flags */
21 tcflag_t c_cflag; /* control mode flags */
22 tcflag_t c_lflag; /* local mode flags */
23 cc_t c_line; /* line discipline */
24 cc_t c_cc[NCCS]; /* control characters */
25 speed_t c_ispeed; /* input speed */
26 speed_t c_ospeed; /* output speed */
27};
28
29
18/* c_cc characters */ 30/* c_cc characters */
19#define VINTR 0 31#define VINTR 0
20#define VQUIT 1 32#define VQUIT 1
diff --git a/include/asm-avr32/arch-at32ap/at32ap7000.h b/include/asm-avr32/arch-at32ap/at32ap7000.h
new file mode 100644
index 000000000000..ba85e04553d4
--- /dev/null
+++ b/include/asm-avr32/arch-at32ap/at32ap7000.h
@@ -0,0 +1,33 @@
1/*
2 * Pin definitions for AT32AP7000.
3 *
4 * Copyright (C) 2006 Atmel Corporation
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#ifndef __ASM_ARCH_AT32AP7000_H__
11#define __ASM_ARCH_AT32AP7000_H__
12
13#define GPIO_PERIPH_A 0
14#define GPIO_PERIPH_B 1
15
16#define NR_GPIO_CONTROLLERS 4
17
18/*
19 * Pin numbers identifying specific GPIO pins on the chip. They can
20 * also be converted to IRQ numbers by passing them through
21 * gpio_to_irq().
22 */
23#define GPIO_PIOA_BASE (0)
24#define GPIO_PIOB_BASE (GPIO_PIOA_BASE + 32)
25#define GPIO_PIOC_BASE (GPIO_PIOB_BASE + 32)
26#define GPIO_PIOD_BASE (GPIO_PIOC_BASE + 32)
27
28#define GPIO_PIN_PA(N) (GPIO_PIOA_BASE + (N))
29#define GPIO_PIN_PB(N) (GPIO_PIOB_BASE + (N))
30#define GPIO_PIN_PC(N) (GPIO_PIOC_BASE + (N))
31#define GPIO_PIN_PD(N) (GPIO_PIOD_BASE + (N))
32
33#endif /* __ASM_ARCH_AT32AP7000_H__ */
diff --git a/include/asm-avr32/arch-at32ap/board.h b/include/asm-avr32/arch-at32ap/board.h
index a39b3e999f18..b120ee030c86 100644
--- a/include/asm-avr32/arch-at32ap/board.h
+++ b/include/asm-avr32/arch-at32ap/board.h
@@ -21,10 +21,7 @@ void at32_map_usart(unsigned int hw_id, unsigned int line);
21struct platform_device *at32_add_device_usart(unsigned int id); 21struct platform_device *at32_add_device_usart(unsigned int id);
22 22
23struct eth_platform_data { 23struct eth_platform_data {
24 u8 valid;
25 u8 mii_phy_addr;
26 u8 is_rmii; 24 u8 is_rmii;
27 u8 hw_addr[6];
28}; 25};
29struct platform_device * 26struct platform_device *
30at32_add_device_eth(unsigned int id, struct eth_platform_data *data); 27at32_add_device_eth(unsigned int id, struct eth_platform_data *data);
diff --git a/include/asm-avr32/arch-at32ap/portmux.h b/include/asm-avr32/arch-at32ap/portmux.h
index 4d50421262a1..83c690571322 100644
--- a/include/asm-avr32/arch-at32ap/portmux.h
+++ b/include/asm-avr32/arch-at32ap/portmux.h
@@ -7,10 +7,20 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#ifndef __ASM_AVR32_AT32_PORTMUX_H__ 10#ifndef __ASM_ARCH_PORTMUX_H__
11#define __ASM_AVR32_AT32_PORTMUX_H__ 11#define __ASM_ARCH_PORTMUX_H__
12 12
13void portmux_set_func(unsigned int portmux_id, unsigned int pin_id, 13/*
14 unsigned int function_id); 14 * Set up pin multiplexing, called from board init only.
15 *
16 * The following flags determine the initial state of the pin.
17 */
18#define AT32_GPIOF_PULLUP 0x00000001 /* Enable pull-up */
19#define AT32_GPIOF_OUTPUT 0x00000002 /* Enable output driver */
20#define AT32_GPIOF_HIGH 0x00000004 /* Set output high */
21
22void at32_select_periph(unsigned int pin, unsigned int periph,
23 unsigned long flags);
24void at32_select_gpio(unsigned int pin, unsigned long flags);
15 25
16#endif /* __ASM_AVR32_AT32_PORTMUX_H__ */ 26#endif /* __ASM_ARCH_PORTMUX_H__ */
diff --git a/include/asm-avr32/dma-mapping.h b/include/asm-avr32/dma-mapping.h
index 0580b5d62bba..5c01e27f0b41 100644
--- a/include/asm-avr32/dma-mapping.h
+++ b/include/asm-avr32/dma-mapping.h
@@ -109,7 +109,7 @@ static inline dma_addr_t
109dma_map_single(struct device *dev, void *cpu_addr, size_t size, 109dma_map_single(struct device *dev, void *cpu_addr, size_t size,
110 enum dma_data_direction direction) 110 enum dma_data_direction direction)
111{ 111{
112 dma_cache_sync(cpu_addr, size, direction); 112 dma_cache_sync(dev, cpu_addr, size, direction);
113 return virt_to_bus(cpu_addr); 113 return virt_to_bus(cpu_addr);
114} 114}
115 115
@@ -211,7 +211,7 @@ dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
211 211
212 sg[i].dma_address = page_to_bus(sg[i].page) + sg[i].offset; 212 sg[i].dma_address = page_to_bus(sg[i].page) + sg[i].offset;
213 virt = page_address(sg[i].page) + sg[i].offset; 213 virt = page_address(sg[i].page) + sg[i].offset;
214 dma_cache_sync(virt, sg[i].length, direction); 214 dma_cache_sync(dev, virt, sg[i].length, direction);
215 } 215 }
216 216
217 return nents; 217 return nents;
@@ -256,14 +256,14 @@ static inline void
256dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, 256dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
257 size_t size, enum dma_data_direction direction) 257 size_t size, enum dma_data_direction direction)
258{ 258{
259 dma_cache_sync(bus_to_virt(dma_handle), size, direction); 259 dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction);
260} 260}
261 261
262static inline void 262static inline void
263dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, 263dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
264 size_t size, enum dma_data_direction direction) 264 size_t size, enum dma_data_direction direction)
265{ 265{
266 dma_cache_sync(bus_to_virt(dma_handle), size, direction); 266 dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction);
267} 267}
268 268
269/** 269/**
@@ -286,7 +286,7 @@ dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
286 int i; 286 int i;
287 287
288 for (i = 0; i < nents; i++) { 288 for (i = 0; i < nents; i++) {
289 dma_cache_sync(page_address(sg[i].page) + sg[i].offset, 289 dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset,
290 sg[i].length, direction); 290 sg[i].length, direction);
291 } 291 }
292} 292}
@@ -298,7 +298,7 @@ dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
298 int i; 298 int i;
299 299
300 for (i = 0; i < nents; i++) { 300 for (i = 0; i < nents; i++) {
301 dma_cache_sync(page_address(sg[i].page) + sg[i].offset, 301 dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset,
302 sg[i].length, direction); 302 sg[i].length, direction);
303 } 303 }
304} 304}
diff --git a/include/asm-avr32/termbits.h b/include/asm-avr32/termbits.h
index 9dc6eacafa33..c215fafdae4d 100644
--- a/include/asm-avr32/termbits.h
+++ b/include/asm-avr32/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-cris/termbits.h b/include/asm-cris/termbits.h
index be0836d2f282..8d8cec225fe1 100644
--- a/include/asm-cris/termbits.h
+++ b/include/asm-cris/termbits.h
@@ -19,6 +19,17 @@ struct termios {
19 cc_t c_cc[NCCS]; /* control characters */ 19 cc_t c_cc[NCCS]; /* control characters */
20}; 20};
21 21
22struct ktermios {
23 tcflag_t c_iflag; /* input mode flags */
24 tcflag_t c_oflag; /* output mode flags */
25 tcflag_t c_cflag; /* control mode flags */
26 tcflag_t c_lflag; /* local mode flags */
27 cc_t c_line; /* line discipline */
28 cc_t c_cc[NCCS]; /* control characters */
29 speed_t c_ispeed; /* input speed */
30 speed_t c_ospeed; /* output speed */
31};
32
22/* c_cc characters */ 33/* c_cc characters */
23#define VINTR 0 34#define VINTR 0
24#define VQUIT 1 35#define VQUIT 1
diff --git a/include/asm-frv/bitops.h b/include/asm-frv/bitops.h
index 1f70d47148bd..f8560edf59ff 100644
--- a/include/asm-frv/bitops.h
+++ b/include/asm-frv/bitops.h
@@ -256,6 +256,50 @@ int __ffs(unsigned long x)
256 return 31 - bit; 256 return 31 - bit;
257} 257}
258 258
259/*
260 * special slimline version of fls() for calculating ilog2_u32()
261 * - note: no protection against n == 0
262 */
263#define ARCH_HAS_ILOG2_U32
264static inline __attribute__((const))
265int __ilog2_u32(u32 n)
266{
267 int bit;
268 asm("scan %1,gr0,%0" : "=r"(bit) : "r"(n));
269 return 31 - bit;
270}
271
272/*
273 * special slimline version of fls64() for calculating ilog2_u64()
274 * - note: no protection against n == 0
275 */
276#define ARCH_HAS_ILOG2_U64
277static inline __attribute__((const))
278int __ilog2_u64(u64 n)
279{
280 union {
281 u64 ll;
282 struct { u32 h, l; };
283 } _;
284 int bit, x, y;
285
286 _.ll = n;
287
288 asm(" subcc %3,gr0,gr0,icc0 \n"
289 " ckeq icc0,cc4 \n"
290 " cscan.p %3,gr0,%0 ,cc4,0 \n"
291 " setlos #63,%1 \n"
292 " cscan.p %4,gr0,%0 ,cc4,1 \n"
293 " setlos #31,%2 \n"
294 " csub.p %1,%0,%0 ,cc4,0 \n"
295 " csub %2,%0,%0 ,cc4,1 \n"
296 : "=&r"(bit), "=r"(x), "=r"(y)
297 : "0r"(_.h), "r"(_.l)
298 : "icc0", "cc4"
299 );
300 return bit;
301}
302
259#include <asm-generic/bitops/sched.h> 303#include <asm-generic/bitops/sched.h>
260#include <asm-generic/bitops/hweight.h> 304#include <asm-generic/bitops/hweight.h>
261 305
diff --git a/include/asm-frv/termbits.h b/include/asm-frv/termbits.h
index 74f20d6e292f..2d6d389cff49 100644
--- a/include/asm-frv/termbits.h
+++ b/include/asm-frv/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index c92ae0f166ff..a06eecd48292 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -4,6 +4,22 @@
4#include <linux/compiler.h> 4#include <linux/compiler.h>
5 5
6#ifdef CONFIG_BUG 6#ifdef CONFIG_BUG
7
8#ifdef CONFIG_GENERIC_BUG
9#ifndef __ASSEMBLY__
10struct bug_entry {
11 unsigned long bug_addr;
12#ifdef CONFIG_DEBUG_BUGVERBOSE
13 const char *file;
14 unsigned short line;
15#endif
16 unsigned short flags;
17};
18#endif /* __ASSEMBLY__ */
19
20#define BUGFLAG_WARNING (1<<0)
21#endif /* CONFIG_GENERIC_BUG */
22
7#ifndef HAVE_ARCH_BUG 23#ifndef HAVE_ARCH_BUG
8#define BUG() do { \ 24#define BUG() do { \
9 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \ 25 printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
@@ -19,7 +35,7 @@
19#define WARN_ON(condition) ({ \ 35#define WARN_ON(condition) ({ \
20 typeof(condition) __ret_warn_on = (condition); \ 36 typeof(condition) __ret_warn_on = (condition); \
21 if (unlikely(__ret_warn_on)) { \ 37 if (unlikely(__ret_warn_on)) { \
22 printk("BUG: warning at %s:%d/%s()\n", __FILE__, \ 38 printk("WARNING at %s:%d %s()\n", __FILE__, \
23 __LINE__, __FUNCTION__); \ 39 __LINE__, __FUNCTION__); \
24 dump_stack(); \ 40 dump_stack(); \
25 } \ 41 } \
diff --git a/include/asm-generic/page.h b/include/asm-generic/page.h
index a96b5d986b6e..b55052ce2330 100644
--- a/include/asm-generic/page.h
+++ b/include/asm-generic/page.h
@@ -4,21 +4,51 @@
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5#ifndef __ASSEMBLY__ 5#ifndef __ASSEMBLY__
6 6
7#include <linux/compiler.h> 7#include <linux/log2.h>
8 8
9/* Pure 2^n version of get_order */ 9/*
10static __inline__ __attribute_const__ int get_order(unsigned long size) 10 * non-const pure 2^n version of get_order
11 * - the arch may override these in asm/bitops.h if they can be implemented
12 * more efficiently than using the arch log2 routines
13 * - we use the non-const log2() instead if the arch has defined one suitable
14 */
15#ifndef ARCH_HAS_GET_ORDER
16static inline __attribute__((const))
17int __get_order(unsigned long size, int page_shift)
11{ 18{
19#if BITS_PER_LONG == 32 && defined(ARCH_HAS_ILOG2_U32)
20 int order = __ilog2_u32(size) - page_shift;
21 return order >= 0 ? order : 0;
22#elif BITS_PER_LONG == 64 && defined(ARCH_HAS_ILOG2_U64)
23 int order = __ilog2_u64(size) - page_shift;
24 return order >= 0 ? order : 0;
25#else
12 int order; 26 int order;
13 27
14 size = (size - 1) >> (PAGE_SHIFT - 1); 28 size = (size - 1) >> (page_shift - 1);
15 order = -1; 29 order = -1;
16 do { 30 do {
17 size >>= 1; 31 size >>= 1;
18 order++; 32 order++;
19 } while (size); 33 } while (size);
20 return order; 34 return order;
35#endif
21} 36}
37#endif
38
39/**
40 * get_order - calculate log2(pages) to hold a block of the specified size
41 * @n - size
42 *
43 * calculate allocation order based on the current page size
44 * - this can be used to initialise global variables from constant data
45 */
46#define get_order(n) \
47( \
48 __builtin_constant_p(n) ? \
49 ((n < (1UL << PAGE_SHIFT)) ? 0 : ilog2(n) - PAGE_SHIFT) : \
50 __get_order(n, PAGE_SHIFT) \
51 )
22 52
23#endif /* __ASSEMBLY__ */ 53#endif /* __ASSEMBLY__ */
24#endif /* __KERNEL__ */ 54#endif /* __KERNEL__ */
diff --git a/include/asm-generic/termios.h b/include/asm-generic/termios.h
index 1e58ca39592c..3769e6bd63b1 100644
--- a/include/asm-generic/termios.h
+++ b/include/asm-generic/termios.h
@@ -11,7 +11,7 @@
11/* 11/*
12 * Translate a "termio" structure into a "termios". Ugh. 12 * Translate a "termio" structure into a "termios". Ugh.
13 */ 13 */
14static inline int user_termio_to_kernel_termios(struct termios *termios, 14static inline int user_termio_to_kernel_termios(struct ktermios *termios,
15 struct termio __user *termio) 15 struct termio __user *termio)
16{ 16{
17 unsigned short tmp; 17 unsigned short tmp;
@@ -48,7 +48,7 @@ static inline int user_termio_to_kernel_termios(struct termios *termios,
48 * Translate a "termios" structure into a "termio". Ugh. 48 * Translate a "termios" structure into a "termio". Ugh.
49 */ 49 */
50static inline int kernel_termios_to_user_termio(struct termio __user *termio, 50static inline int kernel_termios_to_user_termio(struct termio __user *termio,
51 struct termios *termios) 51 struct ktermios *termios)
52{ 52{
53 if (put_user(termios->c_iflag, &termio->c_iflag) < 0 || 53 if (put_user(termios->c_iflag, &termio->c_iflag) < 0 ||
54 put_user(termios->c_oflag, &termio->c_oflag) < 0 || 54 put_user(termios->c_oflag, &termio->c_oflag) < 0 ||
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 4d4c62d11059..7437ccaada77 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -218,6 +218,14 @@
218 .stab.indexstr 0 : { *(.stab.indexstr) } \ 218 .stab.indexstr 0 : { *(.stab.indexstr) } \
219 .comment 0 : { *(.comment) } 219 .comment 0 : { *(.comment) }
220 220
221#define BUG_TABLE \
222 . = ALIGN(8); \
223 __bug_table : AT(ADDR(__bug_table) - LOAD_OFFSET) { \
224 __start___bug_table = .; \
225 *(__bug_table) \
226 __stop___bug_table = .; \
227 }
228
221#define NOTES \ 229#define NOTES \
222 .notes : { *(.note.*) } :note 230 .notes : { *(.note.*) } :note
223 231
@@ -234,6 +242,7 @@
234 *(.initcall4s.init) \ 242 *(.initcall4s.init) \
235 *(.initcall5.init) \ 243 *(.initcall5.init) \
236 *(.initcall5s.init) \ 244 *(.initcall5s.init) \
245 *(.initcallrootfs.init) \
237 *(.initcall6.init) \ 246 *(.initcall6.init) \
238 *(.initcall6s.init) \ 247 *(.initcall6s.init) \
239 *(.initcall7.init) \ 248 *(.initcall7.init) \
diff --git a/include/asm-h8300/termbits.h b/include/asm-h8300/termbits.h
index fa69ae00eda3..6a1f4d3807b4 100644
--- a/include/asm-h8300/termbits.h
+++ b/include/asm-h8300/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-i386/bug.h b/include/asm-i386/bug.h
index 8062cdbf2587..b0fd78ca2619 100644
--- a/include/asm-i386/bug.h
+++ b/include/asm-i386/bug.h
@@ -4,20 +4,32 @@
4 4
5/* 5/*
6 * Tell the user there is some problem. 6 * Tell the user there is some problem.
7 * The offending file and line are encoded after the "officially 7 * The offending file and line are encoded encoded in the __bug_table section.
8 * undefined" opcode for parsing in the trap handler.
9 */ 8 */
10 9
11#ifdef CONFIG_BUG 10#ifdef CONFIG_BUG
12#define HAVE_ARCH_BUG 11#define HAVE_ARCH_BUG
12
13#ifdef CONFIG_DEBUG_BUGVERBOSE 13#ifdef CONFIG_DEBUG_BUGVERBOSE
14#define BUG() \ 14#define BUG() \
15 __asm__ __volatile__( "ud2\n" \ 15 do { \
16 "\t.word %c0\n" \ 16 asm volatile("1:\tud2\n" \
17 "\t.long %c1\n" \ 17 ".pushsection __bug_table,\"a\"\n" \
18 : : "i" (__LINE__), "i" (__FILE__)) 18 "2:\t.long 1b, %c0\n" \
19 "\t.word %c1, 0\n" \
20 "\t.org 2b+%c2\n" \
21 ".popsection" \
22 : : "i" (__FILE__), "i" (__LINE__), \
23 "i" (sizeof(struct bug_entry))); \
24 for(;;) ; \
25 } while(0)
26
19#else 27#else
20#define BUG() __asm__ __volatile__("ud2\n") 28#define BUG() \
29 do { \
30 asm volatile("ud2"); \
31 for(;;) ; \
32 } while(0)
21#endif 33#endif
22#endif 34#endif
23 35
diff --git a/include/asm-i386/ide.h b/include/asm-i386/ide.h
index 73465d2892b9..0fc240c80f49 100644
--- a/include/asm-i386/ide.h
+++ b/include/asm-i386/ide.h
@@ -40,13 +40,14 @@ static __inline__ int ide_default_irq(unsigned long base)
40 40
41static __inline__ unsigned long ide_default_io_base(int index) 41static __inline__ unsigned long ide_default_io_base(int index)
42{ 42{
43 struct pci_dev *pdev;
43 /* 44 /*
44 * If PCI is present then it is not safe to poke around 45 * If PCI is present then it is not safe to poke around
45 * the other legacy IDE ports. Only 0x1f0 and 0x170 are 46 * the other legacy IDE ports. Only 0x1f0 and 0x170 are
46 * defined compatibility mode ports for PCI. A user can 47 * defined compatibility mode ports for PCI. A user can
47 * override this using ide= but we must default safe. 48 * override this using ide= but we must default safe.
48 */ 49 */
49 if (pci_find_device(PCI_ANY_ID, PCI_ANY_ID, NULL) == NULL) { 50 if ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL)) == NULL) {
50 switch(index) { 51 switch(index) {
51 case 2: return 0x1e8; 52 case 2: return 0x1e8;
52 case 3: return 0x168; 53 case 3: return 0x168;
@@ -54,6 +55,7 @@ static __inline__ unsigned long ide_default_io_base(int index)
54 case 5: return 0x160; 55 case 5: return 0x160;
55 } 56 }
56 } 57 }
58 pci_dev_put(pdev);
57 switch (index) { 59 switch (index) {
58 case 0: return 0x1f0; 60 case 0: return 0x1f0;
59 case 1: return 0x170; 61 case 1: return 0x170;
diff --git a/include/asm-i386/termbits.h b/include/asm-i386/termbits.h
index 72c10e3190f8..12baf1d6343f 100644
--- a/include/asm-i386/termbits.h
+++ b/include/asm-i386/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-i386/topology.h b/include/asm-i386/topology.h
index 978d09596130..ac58580ad664 100644
--- a/include/asm-i386/topology.h
+++ b/include/asm-i386/topology.h
@@ -89,6 +89,7 @@ static inline int node_to_first_cpu(int node)
89 .flags = SD_LOAD_BALANCE \ 89 .flags = SD_LOAD_BALANCE \
90 | SD_BALANCE_EXEC \ 90 | SD_BALANCE_EXEC \
91 | SD_BALANCE_FORK \ 91 | SD_BALANCE_FORK \
92 | SD_SERIALIZE \
92 | SD_WAKE_BALANCE, \ 93 | SD_WAKE_BALANCE, \
93 .last_balance = jiffies, \ 94 .last_balance = jiffies, \
94 .balance_interval = 1, \ 95 .balance_interval = 1, \
diff --git a/include/asm-ia64/termbits.h b/include/asm-ia64/termbits.h
index b9e843f7dc42..4531a511bde5 100644
--- a/include/asm-ia64/termbits.h
+++ b/include/asm-ia64/termbits.h
@@ -26,6 +26,17 @@ struct termios {
26 cc_t c_cc[NCCS]; /* control characters */ 26 cc_t c_cc[NCCS]; /* control characters */
27}; 27};
28 28
29struct ktermios {
30 tcflag_t c_iflag; /* input mode flags */
31 tcflag_t c_oflag; /* output mode flags */
32 tcflag_t c_cflag; /* control mode flags */
33 tcflag_t c_lflag; /* local mode flags */
34 cc_t c_line; /* line discipline */
35 cc_t c_cc[NCCS]; /* control characters */
36 speed_t c_ispeed; /* input speed */
37 speed_t c_ospeed; /* output speed */
38};
39
29/* c_cc characters */ 40/* c_cc characters */
30#define VINTR 0 41#define VINTR 0
31#define VQUIT 1 42#define VQUIT 1
diff --git a/include/asm-ia64/topology.h b/include/asm-ia64/topology.h
index a6e38565ab4c..22ed6749557e 100644
--- a/include/asm-ia64/topology.h
+++ b/include/asm-ia64/topology.h
@@ -101,6 +101,7 @@ void build_cpu_to_node_map(void);
101 .flags = SD_LOAD_BALANCE \ 101 .flags = SD_LOAD_BALANCE \
102 | SD_BALANCE_EXEC \ 102 | SD_BALANCE_EXEC \
103 | SD_BALANCE_FORK \ 103 | SD_BALANCE_FORK \
104 | SD_SERIALIZE \
104 | SD_WAKE_BALANCE, \ 105 | SD_WAKE_BALANCE, \
105 .last_balance = jiffies, \ 106 .last_balance = jiffies, \
106 .balance_interval = 64, \ 107 .balance_interval = 64, \
diff --git a/include/asm-m32r/ide.h b/include/asm-m32r/ide.h
index 219a0f74eff3..c82ebe8f250d 100644
--- a/include/asm-m32r/ide.h
+++ b/include/asm-m32r/ide.h
@@ -32,7 +32,8 @@
32static __inline__ int ide_default_irq(unsigned long base) 32static __inline__ int ide_default_irq(unsigned long base)
33{ 33{
34 switch (base) { 34 switch (base) {
35#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) 35#if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \
36 || defined(CONFIG_PLAT_OPSPUT)
36 case 0x1f0: return PLD_IRQ_CFIREQ; 37 case 0x1f0: return PLD_IRQ_CFIREQ;
37 default: 38 default:
38 return 0; 39 return 0;
diff --git a/include/asm-m32r/m32102.h b/include/asm-m32r/m32102.h
index a1f0d1fe9eb8..52807f8db166 100644
--- a/include/asm-m32r/m32102.h
+++ b/include/asm-m32r/m32102.h
@@ -104,7 +104,8 @@
104#define M32R_MFT5RLD_PORTL (0x0C+M32R_MFT5_OFFSET) /* MFT4 reload */ 104#define M32R_MFT5RLD_PORTL (0x0C+M32R_MFT5_OFFSET) /* MFT4 reload */
105#define M32R_MFT5CMPRLD_PORTL (0x10+M32R_MFT5_OFFSET) /* MFT4 compare reload */ 105#define M32R_MFT5CMPRLD_PORTL (0x10+M32R_MFT5_OFFSET) /* MFT4 compare reload */
106 106
107#if defined(CONFIG_CHIP_M32700) || defined(CONFIG_CHIP_M32104) 107#if (defined(CONFIG_CHIP_M32700) && !defined(CONFIG_PLAT_MAPPI2)) \
108 || defined(CONFIG_CHIP_M32104)
108#define M32R_MFTCR_MFT0MSK (1UL<<31) /* b0 */ 109#define M32R_MFTCR_MFT0MSK (1UL<<31) /* b0 */
109#define M32R_MFTCR_MFT1MSK (1UL<<30) /* b1 */ 110#define M32R_MFTCR_MFT1MSK (1UL<<30) /* b1 */
110#define M32R_MFTCR_MFT2MSK (1UL<<29) /* b2 */ 111#define M32R_MFTCR_MFT2MSK (1UL<<29) /* b2 */
@@ -117,7 +118,7 @@
117#define M32R_MFTCR_MFT3EN (1UL<<20) /* b11 */ 118#define M32R_MFTCR_MFT3EN (1UL<<20) /* b11 */
118#define M32R_MFTCR_MFT4EN (1UL<<19) /* b12 */ 119#define M32R_MFTCR_MFT4EN (1UL<<19) /* b12 */
119#define M32R_MFTCR_MFT5EN (1UL<<18) /* b13 */ 120#define M32R_MFTCR_MFT5EN (1UL<<18) /* b13 */
120#else /* not CONFIG_CHIP_M32700 && not CONFIG_CHIP_M32104 */ 121#else
121#define M32R_MFTCR_MFT0MSK (1UL<<15) /* b16 */ 122#define M32R_MFTCR_MFT0MSK (1UL<<15) /* b16 */
122#define M32R_MFTCR_MFT1MSK (1UL<<14) /* b17 */ 123#define M32R_MFTCR_MFT1MSK (1UL<<14) /* b17 */
123#define M32R_MFTCR_MFT2MSK (1UL<<13) /* b18 */ 124#define M32R_MFTCR_MFT2MSK (1UL<<13) /* b18 */
@@ -130,7 +131,7 @@
130#define M32R_MFTCR_MFT3EN (1UL<<4) /* b27 */ 131#define M32R_MFTCR_MFT3EN (1UL<<4) /* b27 */
131#define M32R_MFTCR_MFT4EN (1UL<<3) /* b28 */ 132#define M32R_MFTCR_MFT4EN (1UL<<3) /* b28 */
132#define M32R_MFTCR_MFT5EN (1UL<<2) /* b29 */ 133#define M32R_MFTCR_MFT5EN (1UL<<2) /* b29 */
133#endif /* not CONFIG_CHIP_M32700 && not CONFIG_CHIP_M32104 */ 134#endif
134 135
135#define M32R_MFTMOD_CC_MASK (1UL<<15) /* b16 */ 136#define M32R_MFTMOD_CC_MASK (1UL<<15) /* b16 */
136#define M32R_MFTMOD_TCCR (1UL<<13) /* b18 */ 137#define M32R_MFTMOD_TCCR (1UL<<13) /* b18 */
diff --git a/include/asm-m32r/ptrace.h b/include/asm-m32r/ptrace.h
index 2d2a6c97331e..632b4ce4269a 100644
--- a/include/asm-m32r/ptrace.h
+++ b/include/asm-m32r/ptrace.h
@@ -33,21 +33,10 @@
33#define PT_R15 PT_SP 33#define PT_R15 PT_SP
34 34
35/* processor status and miscellaneous context registers. */ 35/* processor status and miscellaneous context registers. */
36#if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
37#define PT_ACC0H 15 36#define PT_ACC0H 15
38#define PT_ACC0L 16 37#define PT_ACC0L 16
39#define PT_ACC1H 17 38#define PT_ACC1H 17 /* ISA_DSP_LEVEL2 only */
40#define PT_ACC1L 18 39#define PT_ACC1L 18 /* ISA_DSP_LEVEL2 only */
41#define PT_ACCH PT_ACC0H
42#define PT_ACCL PT_ACC0L
43#elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
44#define PT_ACCH 15
45#define PT_ACCL 16
46#define PT_DUMMY_ACC1H 17
47#define PT_DUMMY_ACC1L 18
48#else
49#error unknown isa conifiguration
50#endif
51#define PT_PSW 19 40#define PT_PSW 19
52#define PT_BPC 20 41#define PT_BPC 20
53#define PT_BBPSW 21 42#define PT_BBPSW 21
@@ -103,19 +92,10 @@ struct pt_regs {
103 long syscall_nr; 92 long syscall_nr;
104 93
105 /* Saved main processor status and miscellaneous context registers. */ 94 /* Saved main processor status and miscellaneous context registers. */
106#if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
107 unsigned long acc0h; 95 unsigned long acc0h;
108 unsigned long acc0l; 96 unsigned long acc0l;
109 unsigned long acc1h; 97 unsigned long acc1h; /* ISA_DSP_LEVEL2 only */
110 unsigned long acc1l; 98 unsigned long acc1l; /* ISA_DSP_LEVEL2 only */
111#elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
112 unsigned long acch;
113 unsigned long accl;
114 unsigned long dummy_acc1h;
115 unsigned long dummy_acc1l;
116#else
117#error unknown isa configuration
118#endif
119 unsigned long psw; 99 unsigned long psw;
120 unsigned long bpc; /* saved PC for TRAP syscalls */ 100 unsigned long bpc; /* saved PC for TRAP syscalls */
121 unsigned long bbpsw; 101 unsigned long bbpsw;
diff --git a/include/asm-m32r/sigcontext.h b/include/asm-m32r/sigcontext.h
index 73025c0c41a1..62537dc4dec9 100644
--- a/include/asm-m32r/sigcontext.h
+++ b/include/asm-m32r/sigcontext.h
@@ -23,19 +23,10 @@ struct sigcontext {
23 unsigned long sc_r12; 23 unsigned long sc_r12;
24 24
25 /* Saved main processor status and miscellaneous context registers. */ 25 /* Saved main processor status and miscellaneous context registers. */
26#if defined(CONFIG_ISA_M32R2) && defined(CONFIG_ISA_DSP_LEVEL2)
27 unsigned long sc_acc0h; 26 unsigned long sc_acc0h;
28 unsigned long sc_acc0l; 27 unsigned long sc_acc0l;
29 unsigned long sc_acc1h; 28 unsigned long sc_acc1h; /* ISA_DSP_LEVEL2 only */
30 unsigned long sc_acc1l; 29 unsigned long sc_acc1l; /* ISA_DSP_LEVEL2 only */
31#elif defined(CONFIG_ISA_M32R2) || defined(CONFIG_ISA_M32R)
32 unsigned long sc_acch;
33 unsigned long sc_accl;
34 unsigned long sc_dummy_acc1h;
35 unsigned long sc_dummy_acc1l;
36#else
37#error unknown isa configuration
38#endif
39 unsigned long sc_psw; 30 unsigned long sc_psw;
40 unsigned long sc_bpc; /* saved PC for TRAP syscalls */ 31 unsigned long sc_bpc; /* saved PC for TRAP syscalls */
41 unsigned long sc_bbpsw; 32 unsigned long sc_bbpsw;
diff --git a/include/asm-m32r/termbits.h b/include/asm-m32r/termbits.h
index 5ace3702df75..faf2bd0504c1 100644
--- a/include/asm-m32r/termbits.h
+++ b/include/asm-m32r/termbits.h
@@ -19,6 +19,17 @@ struct termios {
19 cc_t c_cc[NCCS]; /* control characters */ 19 cc_t c_cc[NCCS]; /* control characters */
20}; 20};
21 21
22struct ktermios {
23 tcflag_t c_iflag; /* input mode flags */
24 tcflag_t c_oflag; /* output mode flags */
25 tcflag_t c_cflag; /* control mode flags */
26 tcflag_t c_lflag; /* local mode flags */
27 cc_t c_line; /* line discipline */
28 cc_t c_cc[NCCS]; /* control characters */
29 speed_t c_ispeed; /* input speed */
30 speed_t c_ospeed; /* output speed */
31};
32
22/* c_cc characters */ 33/* c_cc characters */
23#define VINTR 0 34#define VINTR 0
24#define VQUIT 1 35#define VQUIT 1
diff --git a/include/asm-m68k/sun3-head.h b/include/asm-m68k/sun3-head.h
index f799d95bad53..e74f384e269f 100644
--- a/include/asm-m68k/sun3-head.h
+++ b/include/asm-m68k/sun3-head.h
@@ -4,7 +4,6 @@
4 4
5#define KERNBASE 0xE000000 /* First address the kernel will eventually be */ 5#define KERNBASE 0xE000000 /* First address the kernel will eventually be */
6#define LOAD_ADDR 0x4000 /* prom jumps to us here unless this is elf /boot */ 6#define LOAD_ADDR 0x4000 /* prom jumps to us here unless this is elf /boot */
7#define BI_START (KERNBASE + 0x3000) /* beginning of the bootinfo records */
8#define FC_CONTROL 3 7#define FC_CONTROL 3
9#define FC_SUPERD 5 8#define FC_SUPERD 5
10#define FC_CPU 7 9#define FC_CPU 7
diff --git a/include/asm-m68k/sun3ints.h b/include/asm-m68k/sun3ints.h
index de91fa071b99..309d6e6a1374 100644
--- a/include/asm-m68k/sun3ints.h
+++ b/include/asm-m68k/sun3ints.h
@@ -16,6 +16,7 @@
16#include <asm/intersil.h> 16#include <asm/intersil.h>
17#include <asm/oplib.h> 17#include <asm/oplib.h>
18#include <asm/traps.h> 18#include <asm/traps.h>
19#include <asm/irq.h>
19 20
20#define SUN3_INT_VECS 192 21#define SUN3_INT_VECS 192
21 22
diff --git a/include/asm-m68k/termbits.h b/include/asm-m68k/termbits.h
index e9eec3eb0718..a194092240fb 100644
--- a/include/asm-m68k/termbits.h
+++ b/include/asm-m68k/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-mips/bootinfo.h b/include/asm-mips/bootinfo.h
index 1e5ccdad3b02..8e321f53a382 100644
--- a/include/asm-mips/bootinfo.h
+++ b/include/asm-mips/bootinfo.h
@@ -131,6 +131,7 @@
131#define MACH_PHILIPS_NINO 0 /* Nino */ 131#define MACH_PHILIPS_NINO 0 /* Nino */
132#define MACH_PHILIPS_VELO 1 /* Velo */ 132#define MACH_PHILIPS_VELO 1 /* Velo */
133#define MACH_PHILIPS_JBS 2 /* JBS */ 133#define MACH_PHILIPS_JBS 2 /* JBS */
134#define MACH_PHILIPS_STB810 3 /* STB810 */
134 135
135/* 136/*
136 * Valid machtype for group SIBYTE 137 * Valid machtype for group SIBYTE
diff --git a/include/asm-mips/compat.h b/include/asm-mips/compat.h
index 55a0152feb08..432653d7ae09 100644
--- a/include/asm-mips/compat.h
+++ b/include/asm-mips/compat.h
@@ -5,6 +5,7 @@
5 */ 5 */
6#include <linux/types.h> 6#include <linux/types.h>
7#include <asm/page.h> 7#include <asm/page.h>
8#include <asm/ptrace.h>
8 9
9#define COMPAT_USER_HZ 100 10#define COMPAT_USER_HZ 100
10 11
diff --git a/include/asm-mips/mach-ip27/irq.h b/include/asm-mips/mach-ip27/irq.h
index 806213ce31b6..25f0c3f39adf 100644
--- a/include/asm-mips/mach-ip27/irq.h
+++ b/include/asm-mips/mach-ip27/irq.h
@@ -10,8 +10,6 @@
10#ifndef __ASM_MACH_IP27_IRQ_H 10#ifndef __ASM_MACH_IP27_IRQ_H
11#define __ASM_MACH_IP27_IRQ_H 11#define __ASM_MACH_IP27_IRQ_H
12 12
13#include <asm/sn/arch.h>
14
15/* 13/*
16 * A hardwired interrupt number is completly stupid for this system - a 14 * A hardwired interrupt number is completly stupid for this system - a
17 * large configuration might have thousands if not tenthousands of 15 * large configuration might have thousands if not tenthousands of
diff --git a/include/asm-mips/mach-ip27/topology.h b/include/asm-mips/mach-ip27/topology.h
index a13b715fd9ca..44790fdc5d00 100644
--- a/include/asm-mips/mach-ip27/topology.h
+++ b/include/asm-mips/mach-ip27/topology.h
@@ -1,7 +1,6 @@
1#ifndef _ASM_MACH_TOPOLOGY_H 1#ifndef _ASM_MACH_TOPOLOGY_H
2#define _ASM_MACH_TOPOLOGY_H 1 2#define _ASM_MACH_TOPOLOGY_H 1
3 3
4#include <asm/sn/arch.h>
5#include <asm/sn/hub.h> 4#include <asm/sn/hub.h>
6#include <asm/mmzone.h> 5#include <asm/mmzone.h>
7 6
diff --git a/include/asm-mips/mach-rm200/cpu-feature-overrides.h b/include/asm-mips/mach-rm/cpu-feature-overrides.h
index 11410ae10d36..11410ae10d36 100644
--- a/include/asm-mips/mach-rm200/cpu-feature-overrides.h
+++ b/include/asm-mips/mach-rm/cpu-feature-overrides.h
diff --git a/include/asm-mips/mach-rm200/mc146818rtc.h b/include/asm-mips/mach-rm/mc146818rtc.h
index d37ae68dc6a3..d37ae68dc6a3 100644
--- a/include/asm-mips/mach-rm200/mc146818rtc.h
+++ b/include/asm-mips/mach-rm/mc146818rtc.h
diff --git a/include/asm-mips/mach-rm200/timex.h b/include/asm-mips/mach-rm/timex.h
index 11ff6cb0f214..11ff6cb0f214 100644
--- a/include/asm-mips/mach-rm200/timex.h
+++ b/include/asm-mips/mach-rm/timex.h
diff --git a/include/asm-mips/pci.h b/include/asm-mips/pci.h
index c4d68bebdca6..7f0f120ca07c 100644
--- a/include/asm-mips/pci.h
+++ b/include/asm-mips/pci.h
@@ -187,4 +187,10 @@ static inline void pcibios_add_platform_entries(struct pci_dev *dev)
187/* Do platform specific device initialization at pci_enable_device() time */ 187/* Do platform specific device initialization at pci_enable_device() time */
188extern int pcibios_plat_dev_init(struct pci_dev *dev); 188extern int pcibios_plat_dev_init(struct pci_dev *dev);
189 189
190/* Chances are this interrupt is wired PC-style ... */
191static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
192{
193 return channel ? 15 : 14;
194}
195
190#endif /* _ASM_PCI_H */ 196#endif /* _ASM_PCI_H */
diff --git a/include/asm-mips/ptrace.h b/include/asm-mips/ptrace.h
index 30bf555faeaa..8a1f2b6f04ac 100644
--- a/include/asm-mips/ptrace.h
+++ b/include/asm-mips/ptrace.h
@@ -82,6 +82,14 @@ struct pt_regs {
82 82
83extern asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit); 83extern asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit);
84 84
85extern NORET_TYPE void die(const char *, struct pt_regs *);
86
87static inline void die_if_kernel(const char *str, struct pt_regs *regs)
88{
89 if (unlikely(!user_mode(regs)))
90 die(str, regs);
91}
92
85#endif 93#endif
86 94
87#endif /* _ASM_PTRACE_H */ 95#endif /* _ASM_PTRACE_H */
diff --git a/include/asm-mips/sn/arch.h b/include/asm-mips/sn/arch.h
index 51174af6ac52..da523de628be 100644
--- a/include/asm-mips/sn/arch.h
+++ b/include/asm-mips/sn/arch.h
@@ -18,7 +18,6 @@
18#endif 18#endif
19 19
20typedef u64 hubreg_t; 20typedef u64 hubreg_t;
21typedef u64 nic_t;
22 21
23#define cputonasid(cpu) (cpu_data[(cpu)].p_nasid) 22#define cputonasid(cpu) (cpu_data[(cpu)].p_nasid)
24#define cputoslice(cpu) (cpu_data[(cpu)].p_slice) 23#define cputoslice(cpu) (cpu_data[(cpu)].p_slice)
diff --git a/include/asm-mips/sn/klconfig.h b/include/asm-mips/sn/klconfig.h
index 15d70ca56187..82aeb9e322db 100644
--- a/include/asm-mips/sn/klconfig.h
+++ b/include/asm-mips/sn/klconfig.h
@@ -61,6 +61,8 @@
61#endif /* CONFIG_SGI_IP35 */ 61#endif /* CONFIG_SGI_IP35 */
62#endif /* CONFIG_SGI_IP27 || CONFIG_SGI_IP35 */ 62#endif /* CONFIG_SGI_IP27 || CONFIG_SGI_IP35 */
63 63
64typedef u64 nic_t;
65
64#define KLCFGINFO_MAGIC 0xbeedbabe 66#define KLCFGINFO_MAGIC 0xbeedbabe
65 67
66typedef s32 klconf_off_t; 68typedef s32 klconf_off_t;
diff --git a/include/asm-mips/system.h b/include/asm-mips/system.h
index 9428057a50cf..5e1289c85ed9 100644
--- a/include/asm-mips/system.h
+++ b/include/asm-mips/system.h
@@ -19,7 +19,6 @@
19#include <asm/barrier.h> 19#include <asm/barrier.h>
20#include <asm/cpu-features.h> 20#include <asm/cpu-features.h>
21#include <asm/dsp.h> 21#include <asm/dsp.h>
22#include <asm/ptrace.h>
23#include <asm/war.h> 22#include <asm/war.h>
24 23
25 24
@@ -336,14 +335,6 @@ extern void *set_except_vector(int n, void *addr);
336extern unsigned long ebase; 335extern unsigned long ebase;
337extern void per_cpu_trap_init(void); 336extern void per_cpu_trap_init(void);
338 337
339extern NORET_TYPE void die(const char *, struct pt_regs *);
340
341static inline void die_if_kernel(const char *str, struct pt_regs *regs)
342{
343 if (unlikely(!user_mode(regs)))
344 die(str, regs);
345}
346
347extern int stop_a_enabled; 338extern int stop_a_enabled;
348 339
349/* 340/*
diff --git a/include/asm-mips/termbits.h b/include/asm-mips/termbits.h
index b62ec7c521cc..0bbe07b42a07 100644
--- a/include/asm-mips/termbits.h
+++ b/include/asm-mips/termbits.h
@@ -30,6 +30,17 @@ struct termios {
30 cc_t c_cc[NCCS]; /* control characters */ 30 cc_t c_cc[NCCS]; /* control characters */
31}; 31};
32 32
33struct ktermios {
34 tcflag_t c_iflag; /* input mode flags */
35 tcflag_t c_oflag; /* output mode flags */
36 tcflag_t c_cflag; /* control mode flags */
37 tcflag_t c_lflag; /* local mode flags */
38 cc_t c_line; /* line discipline */
39 cc_t c_cc[NCCS]; /* control characters */
40 speed_t c_ispeed; /* input speed */
41 speed_t c_ospeed; /* output speed */
42};
43
33/* c_cc characters */ 44/* c_cc characters */
34#define VINTR 0 /* Interrupt character [ISIG]. */ 45#define VINTR 0 /* Interrupt character [ISIG]. */
35#define VQUIT 1 /* Quit character [ISIG]. */ 46#define VQUIT 1 /* Quit character [ISIG]. */
diff --git a/include/asm-mips/war.h b/include/asm-mips/war.h
index 3ac146c019c9..13a3502eef44 100644
--- a/include/asm-mips/war.h
+++ b/include/asm-mips/war.h
@@ -76,7 +76,7 @@
76/* 76/*
77 * But the RM200C seems to have been shipped only with V2.0 R4600s 77 * But the RM200C seems to have been shipped only with V2.0 R4600s
78 */ 78 */
79#ifdef CONFIG_SNI_RM200_PCI 79#ifdef CONFIG_SNI_RM
80 80
81#define R4600_V2_HIT_CACHEOP_WAR 1 81#define R4600_V2_HIT_CACHEOP_WAR 1
82 82
diff --git a/include/asm-parisc/termbits.h b/include/asm-parisc/termbits.h
index 372b634892c9..a46e299a9391 100644
--- a/include/asm-parisc/termbits.h
+++ b/include/asm-parisc/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-powerpc/Kbuild b/include/asm-powerpc/Kbuild
index 1e637381c118..703970fb0ec0 100644
--- a/include/asm-powerpc/Kbuild
+++ b/include/asm-powerpc/Kbuild
@@ -17,7 +17,6 @@ header-y += ipc.h
17header-y += poll.h 17header-y += poll.h
18header-y += shmparam.h 18header-y += shmparam.h
19header-y += sockios.h 19header-y += sockios.h
20header-y += spu_info.h
21header-y += ucontext.h 20header-y += ucontext.h
22header-y += ioctl.h 21header-y += ioctl.h
23header-y += linkage.h 22header-y += linkage.h
@@ -37,6 +36,7 @@ unifdef-y += posix_types.h
37unifdef-y += ptrace.h 36unifdef-y += ptrace.h
38unifdef-y += seccomp.h 37unifdef-y += seccomp.h
39unifdef-y += signal.h 38unifdef-y += signal.h
39unifdef-y += spu_info.h
40unifdef-y += termios.h 40unifdef-y += termios.h
41unifdef-y += types.h 41unifdef-y += types.h
42unifdef-y += unistd.h 42unifdef-y += unistd.h
diff --git a/include/asm-powerpc/bitops.h b/include/asm-powerpc/bitops.h
index c341063d0804..8f757f6246e4 100644
--- a/include/asm-powerpc/bitops.h
+++ b/include/asm-powerpc/bitops.h
@@ -190,7 +190,8 @@ static __inline__ void set_bits(unsigned long mask, unsigned long *addr)
190 * Return the zero-based bit position (LE, not IBM bit numbering) of 190 * Return the zero-based bit position (LE, not IBM bit numbering) of
191 * the most significant 1-bit in a double word. 191 * the most significant 1-bit in a double word.
192 */ 192 */
193static __inline__ int __ilog2(unsigned long x) 193static __inline__ __attribute__((const))
194int __ilog2(unsigned long x)
194{ 195{
195 int lz; 196 int lz;
196 197
@@ -198,6 +199,24 @@ static __inline__ int __ilog2(unsigned long x)
198 return BITS_PER_LONG - 1 - lz; 199 return BITS_PER_LONG - 1 - lz;
199} 200}
200 201
202static inline __attribute__((const))
203int __ilog2_u32(u32 n)
204{
205 int bit;
206 asm ("cntlzw %0,%1" : "=r" (bit) : "r" (n));
207 return 31 - bit;
208}
209
210#ifdef __powerpc64__
211static inline __attribute__((const))
212int __ilog2_u64(u64 n)
213{
214 int bit;
215 asm ("cntlzd %0,%1" : "=r" (bit) : "r" (n));
216 return 63 - bit;
217}
218#endif
219
201/* 220/*
202 * Determines the bit position of the least significant 0 bit in the 221 * Determines the bit position of the least significant 0 bit in the
203 * specified double word. The returned bit position will be 222 * specified double word. The returned bit position will be
diff --git a/include/asm-powerpc/bug.h b/include/asm-powerpc/bug.h
index 978b2c7e84ea..709568879f73 100644
--- a/include/asm-powerpc/bug.h
+++ b/include/asm-powerpc/bug.h
@@ -13,36 +13,39 @@
13 13
14#ifndef __ASSEMBLY__ 14#ifndef __ASSEMBLY__
15 15
16struct bug_entry {
17 unsigned long bug_addr;
18 long line;
19 const char *file;
20 const char *function;
21};
22
23struct bug_entry *find_bug(unsigned long bugaddr);
24
25/*
26 * If this bit is set in the line number it means that the trap
27 * is for WARN_ON rather than BUG or BUG_ON.
28 */
29#define BUG_WARNING_TRAP 0x1000000
30
31#ifdef CONFIG_BUG 16#ifdef CONFIG_BUG
32 17
18/* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
19 sizeof(struct bug_entry), respectively */
20#ifdef CONFIG_DEBUG_BUGVERBOSE
21#define _EMIT_BUG_ENTRY \
22 ".section __bug_table,\"a\"\n" \
23 "2:\t" PPC_LONG "1b, %0\n" \
24 "\t.short %1, %2\n" \
25 ".org 2b+%3\n" \
26 ".previous\n"
27#else
28#define _EMIT_BUG_ENTRY \
29 ".section __bug_table,\"a\"\n" \
30 "2:\t" PPC_LONG "1b\n" \
31 "\t.short %2\n" \
32 ".org 2b+%3\n" \
33 ".previous\n"
34#endif
35
33/* 36/*
34 * BUG_ON() and WARN_ON() do their best to cooperate with compile-time 37 * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
35 * optimisations. However depending on the complexity of the condition 38 * optimisations. However depending on the complexity of the condition
36 * some compiler versions may not produce optimal results. 39 * some compiler versions may not produce optimal results.
37 */ 40 */
38 41
39#define BUG() do { \ 42#define BUG() do { \
40 __asm__ __volatile__( \ 43 __asm__ __volatile__( \
41 "1: twi 31,0,0\n" \ 44 "1: twi 31,0,0\n" \
42 ".section __bug_table,\"a\"\n" \ 45 _EMIT_BUG_ENTRY \
43 "\t"PPC_LONG" 1b,%0,%1,%2\n" \ 46 : : "i" (__FILE__), "i" (__LINE__), \
44 ".previous" \ 47 "i" (0), "i" (sizeof(struct bug_entry))); \
45 : : "i" (__LINE__), "i" (__FILE__), "i" (__FUNCTION__)); \ 48 for(;;) ; \
46} while (0) 49} while (0)
47 50
48#define BUG_ON(x) do { \ 51#define BUG_ON(x) do { \
@@ -51,23 +54,21 @@ struct bug_entry *find_bug(unsigned long bugaddr);
51 BUG(); \ 54 BUG(); \
52 } else { \ 55 } else { \
53 __asm__ __volatile__( \ 56 __asm__ __volatile__( \
54 "1: "PPC_TLNEI" %0,0\n" \ 57 "1: "PPC_TLNEI" %4,0\n" \
55 ".section __bug_table,\"a\"\n" \ 58 _EMIT_BUG_ENTRY \
56 "\t"PPC_LONG" 1b,%1,%2,%3\n" \ 59 : : "i" (__FILE__), "i" (__LINE__), "i" (0), \
57 ".previous" \ 60 "i" (sizeof(struct bug_entry)), \
58 : : "r" ((long)(x)), "i" (__LINE__), \ 61 "r" ((long)(x))); \
59 "i" (__FILE__), "i" (__FUNCTION__)); \
60 } \ 62 } \
61} while (0) 63} while (0)
62 64
63#define __WARN() do { \ 65#define __WARN() do { \
64 __asm__ __volatile__( \ 66 __asm__ __volatile__( \
65 "1: twi 31,0,0\n" \ 67 "1: twi 31,0,0\n" \
66 ".section __bug_table,\"a\"\n" \ 68 _EMIT_BUG_ENTRY \
67 "\t"PPC_LONG" 1b,%0,%1,%2\n" \ 69 : : "i" (__FILE__), "i" (__LINE__), \
68 ".previous" \ 70 "i" (BUGFLAG_WARNING), \
69 : : "i" (__LINE__ + BUG_WARNING_TRAP), \ 71 "i" (sizeof(struct bug_entry))); \
70 "i" (__FILE__), "i" (__FUNCTION__)); \
71} while (0) 72} while (0)
72 73
73#define WARN_ON(x) ({ \ 74#define WARN_ON(x) ({ \
@@ -77,13 +78,12 @@ struct bug_entry *find_bug(unsigned long bugaddr);
77 __WARN(); \ 78 __WARN(); \
78 } else { \ 79 } else { \
79 __asm__ __volatile__( \ 80 __asm__ __volatile__( \
80 "1: "PPC_TLNEI" %0,0\n" \ 81 "1: "PPC_TLNEI" %4,0\n" \
81 ".section __bug_table,\"a\"\n" \ 82 _EMIT_BUG_ENTRY \
82 "\t"PPC_LONG" 1b,%1,%2,%3\n" \ 83 : : "i" (__FILE__), "i" (__LINE__), \
83 ".previous" \ 84 "i" (BUGFLAG_WARNING), \
84 : : "r" (__ret_warn_on), \ 85 "i" (sizeof(struct bug_entry)), \
85 "i" (__LINE__ + BUG_WARNING_TRAP), \ 86 "r" (__ret_warn_on)); \
86 "i" (__FILE__), "i" (__FUNCTION__)); \
87 } \ 87 } \
88 unlikely(__ret_warn_on); \ 88 unlikely(__ret_warn_on); \
89}) 89})
diff --git a/include/asm-powerpc/cputable.h b/include/asm-powerpc/cputable.h
index 6fe5c9d4ca3b..7384b8086b75 100644
--- a/include/asm-powerpc/cputable.h
+++ b/include/asm-powerpc/cputable.h
@@ -126,6 +126,7 @@ extern void do_feature_fixups(unsigned long value, void *fixup_start,
126#define CPU_FTR_NODSISRALIGN ASM_CONST(0x0000000000100000) 126#define CPU_FTR_NODSISRALIGN ASM_CONST(0x0000000000100000)
127#define CPU_FTR_PPC_LE ASM_CONST(0x0000000000200000) 127#define CPU_FTR_PPC_LE ASM_CONST(0x0000000000200000)
128#define CPU_FTR_REAL_LE ASM_CONST(0x0000000000400000) 128#define CPU_FTR_REAL_LE ASM_CONST(0x0000000000400000)
129#define CPU_FTR_FPU_UNAVAILABLE ASM_CONST(0x0000000000800000)
129 130
130/* 131/*
131 * Add the 64-bit processor unique features in the top half of the word; 132 * Add the 64-bit processor unique features in the top half of the word;
@@ -152,6 +153,7 @@ extern void do_feature_fixups(unsigned long value, void *fixup_start,
152#define CPU_FTR_PURR LONG_ASM_CONST(0x0000400000000000) 153#define CPU_FTR_PURR LONG_ASM_CONST(0x0000400000000000)
153#define CPU_FTR_CELL_TB_BUG LONG_ASM_CONST(0x0000800000000000) 154#define CPU_FTR_CELL_TB_BUG LONG_ASM_CONST(0x0000800000000000)
154#define CPU_FTR_SPURR LONG_ASM_CONST(0x0001000000000000) 155#define CPU_FTR_SPURR LONG_ASM_CONST(0x0001000000000000)
156#define CPU_FTR_DSCR LONG_ASM_CONST(0x0002000000000000)
155 157
156#ifndef __ASSEMBLY__ 158#ifndef __ASSEMBLY__
157 159
@@ -295,6 +297,9 @@ extern void do_feature_fixups(unsigned long value, void *fixup_start,
295#define CPU_FTRS_E300 (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_MAYBE_CAN_DOZE | \ 297#define CPU_FTRS_E300 (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_MAYBE_CAN_DOZE | \
296 CPU_FTR_USE_TB | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_HAS_HIGH_BATS | \ 298 CPU_FTR_USE_TB | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_HAS_HIGH_BATS | \
297 CPU_FTR_COMMON) 299 CPU_FTR_COMMON)
300#define CPU_FTRS_E300C2 (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_MAYBE_CAN_DOZE | \
301 CPU_FTR_USE_TB | CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_HAS_HIGH_BATS | \
302 CPU_FTR_COMMON | CPU_FTR_FPU_UNAVAILABLE)
298#define CPU_FTRS_CLASSIC32 (CPU_FTR_COMMON | CPU_FTR_SPLIT_ID_CACHE | \ 303#define CPU_FTRS_CLASSIC32 (CPU_FTR_COMMON | CPU_FTR_SPLIT_ID_CACHE | \
299 CPU_FTR_USE_TB | CPU_FTR_HPTE_TABLE) 304 CPU_FTR_USE_TB | CPU_FTR_HPTE_TABLE)
300#define CPU_FTRS_8XX (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB) 305#define CPU_FTRS_8XX (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB)
@@ -330,13 +335,14 @@ extern void do_feature_fixups(unsigned long value, void *fixup_start,
330 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ 335 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \
331 CPU_FTR_MMCRA | CPU_FTR_SMT | \ 336 CPU_FTR_MMCRA | CPU_FTR_SMT | \
332 CPU_FTR_COHERENT_ICACHE | CPU_FTR_LOCKLESS_TLBIE | \ 337 CPU_FTR_COHERENT_ICACHE | CPU_FTR_LOCKLESS_TLBIE | \
333 CPU_FTR_PURR | CPU_FTR_SPURR | CPU_FTR_REAL_LE) 338 CPU_FTR_PURR | CPU_FTR_SPURR | CPU_FTR_REAL_LE | \
339 CPU_FTR_DSCR)
334#define CPU_FTRS_POWER6X (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB | \ 340#define CPU_FTRS_POWER6X (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB | \
335 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ 341 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \
336 CPU_FTR_MMCRA | CPU_FTR_SMT | \ 342 CPU_FTR_MMCRA | CPU_FTR_SMT | \
337 CPU_FTR_COHERENT_ICACHE | CPU_FTR_LOCKLESS_TLBIE | \ 343 CPU_FTR_COHERENT_ICACHE | CPU_FTR_LOCKLESS_TLBIE | \
338 CPU_FTR_PURR | CPU_FTR_CI_LARGE_PAGE | \ 344 CPU_FTR_PURR | CPU_FTR_CI_LARGE_PAGE | \
339 CPU_FTR_SPURR | CPU_FTR_REAL_LE) 345 CPU_FTR_SPURR | CPU_FTR_REAL_LE | CPU_FTR_DSCR)
340#define CPU_FTRS_CELL (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB | \ 346#define CPU_FTRS_CELL (CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_USE_TB | \
341 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \ 347 CPU_FTR_HPTE_TABLE | CPU_FTR_PPCAS_ARCH_V2 | CPU_FTR_CTRL | \
342 CPU_FTR_ALTIVEC_COMP | CPU_FTR_MMCRA | CPU_FTR_SMT | \ 348 CPU_FTR_ALTIVEC_COMP | CPU_FTR_MMCRA | CPU_FTR_SMT | \
@@ -364,7 +370,8 @@ enum {
364 CPU_FTRS_7450_21 | CPU_FTRS_7450_23 | CPU_FTRS_7455_1 | 370 CPU_FTRS_7450_21 | CPU_FTRS_7450_23 | CPU_FTRS_7455_1 |
365 CPU_FTRS_7455_20 | CPU_FTRS_7455 | CPU_FTRS_7447_10 | 371 CPU_FTRS_7455_20 | CPU_FTRS_7455 | CPU_FTRS_7447_10 |
366 CPU_FTRS_7447 | CPU_FTRS_7447A | CPU_FTRS_82XX | 372 CPU_FTRS_7447 | CPU_FTRS_7447A | CPU_FTRS_82XX |
367 CPU_FTRS_G2_LE | CPU_FTRS_E300 | CPU_FTRS_CLASSIC32 | 373 CPU_FTRS_G2_LE | CPU_FTRS_E300 | CPU_FTRS_E300C2 |
374 CPU_FTRS_CLASSIC32 |
368#else 375#else
369 CPU_FTRS_GENERIC_32 | 376 CPU_FTRS_GENERIC_32 |
370#endif 377#endif
@@ -403,7 +410,8 @@ enum {
403 CPU_FTRS_7450_21 & CPU_FTRS_7450_23 & CPU_FTRS_7455_1 & 410 CPU_FTRS_7450_21 & CPU_FTRS_7450_23 & CPU_FTRS_7455_1 &
404 CPU_FTRS_7455_20 & CPU_FTRS_7455 & CPU_FTRS_7447_10 & 411 CPU_FTRS_7455_20 & CPU_FTRS_7455 & CPU_FTRS_7447_10 &
405 CPU_FTRS_7447 & CPU_FTRS_7447A & CPU_FTRS_82XX & 412 CPU_FTRS_7447 & CPU_FTRS_7447A & CPU_FTRS_82XX &
406 CPU_FTRS_G2_LE & CPU_FTRS_E300 & CPU_FTRS_CLASSIC32 & 413 CPU_FTRS_G2_LE & CPU_FTRS_E300 & CPU_FTRS_E300C2 &
414 CPU_FTRS_CLASSIC32 &
407#else 415#else
408 CPU_FTRS_GENERIC_32 & 416 CPU_FTRS_GENERIC_32 &
409#endif 417#endif
diff --git a/include/asm-powerpc/dcr-native.h b/include/asm-powerpc/dcr-native.h
index fd4a5f5e33d1..d7a1bc1551c6 100644
--- a/include/asm-powerpc/dcr-native.h
+++ b/include/asm-powerpc/dcr-native.h
@@ -20,8 +20,7 @@
20#ifndef _ASM_POWERPC_DCR_NATIVE_H 20#ifndef _ASM_POWERPC_DCR_NATIVE_H
21#define _ASM_POWERPC_DCR_NATIVE_H 21#define _ASM_POWERPC_DCR_NATIVE_H
22#ifdef __KERNEL__ 22#ifdef __KERNEL__
23 23#ifndef __ASSEMBLY__
24#include <asm/reg.h>
25 24
26typedef struct {} dcr_host_t; 25typedef struct {} dcr_host_t;
27 26
@@ -32,7 +31,41 @@ typedef struct {} dcr_host_t;
32#define dcr_read(host, dcr_n) mfdcr(dcr_n) 31#define dcr_read(host, dcr_n) mfdcr(dcr_n)
33#define dcr_write(host, dcr_n, value) mtdcr(dcr_n, value) 32#define dcr_write(host, dcr_n, value) mtdcr(dcr_n, value)
34 33
34/* Device Control Registers */
35void __mtdcr(int reg, unsigned int val);
36unsigned int __mfdcr(int reg);
37#define mfdcr(rn) \
38 ({unsigned int rval; \
39 if (__builtin_constant_p(rn)) \
40 asm volatile("mfdcr %0," __stringify(rn) \
41 : "=r" (rval)); \
42 else \
43 rval = __mfdcr(rn); \
44 rval;})
45
46#define mtdcr(rn, v) \
47do { \
48 if (__builtin_constant_p(rn)) \
49 asm volatile("mtdcr " __stringify(rn) ",%0" \
50 : : "r" (v)); \
51 else \
52 __mtdcr(rn, v); \
53} while (0)
54
55/* R/W of indirect DCRs make use of standard naming conventions for DCRs */
56#define mfdcri(base, reg) \
57({ \
58 mtdcr(base ## _CFGADDR, base ## _ ## reg); \
59 mfdcr(base ## _CFGDATA); \
60})
61
62#define mtdcri(base, reg, data) \
63do { \
64 mtdcr(base ## _CFGADDR, base ## _ ## reg); \
65 mtdcr(base ## _CFGDATA, data); \
66} while (0)
35 67
68#endif /* __ASSEMBLY__ */
36#endif /* __KERNEL__ */ 69#endif /* __KERNEL__ */
37#endif /* _ASM_POWERPC_DCR_NATIVE_H */ 70#endif /* _ASM_POWERPC_DCR_NATIVE_H */
38 71
diff --git a/include/asm-powerpc/dcr.h b/include/asm-powerpc/dcr.h
index 473f2c7fd892..b66c5e6941f0 100644
--- a/include/asm-powerpc/dcr.h
+++ b/include/asm-powerpc/dcr.h
@@ -20,6 +20,7 @@
20#ifndef _ASM_POWERPC_DCR_H 20#ifndef _ASM_POWERPC_DCR_H
21#define _ASM_POWERPC_DCR_H 21#define _ASM_POWERPC_DCR_H
22#ifdef __KERNEL__ 22#ifdef __KERNEL__
23#ifdef CONFIG_PPC_DCR
23 24
24#ifdef CONFIG_PPC_DCR_NATIVE 25#ifdef CONFIG_PPC_DCR_NATIVE
25#include <asm/dcr-native.h> 26#include <asm/dcr-native.h>
@@ -38,5 +39,6 @@ extern unsigned int dcr_resource_len(struct device_node *np,
38 unsigned int index); 39 unsigned int index);
39#endif /* CONFIG_PPC_MERGE */ 40#endif /* CONFIG_PPC_MERGE */
40 41
42#endif /* CONFIG_PPC_DCR */
41#endif /* __KERNEL__ */ 43#endif /* __KERNEL__ */
42#endif /* _ASM_POWERPC_DCR_H */ 44#endif /* _ASM_POWERPC_DCR_H */
diff --git a/include/asm-powerpc/hw_irq.h b/include/asm-powerpc/hw_irq.h
index d604863d72fb..9e4dd98eb220 100644
--- a/include/asm-powerpc/hw_irq.h
+++ b/include/asm-powerpc/hw_irq.h
@@ -107,25 +107,6 @@ static inline void local_irq_save_ptr(unsigned long *flags)
107 107
108#endif /* CONFIG_PPC64 */ 108#endif /* CONFIG_PPC64 */
109 109
110#define mask_irq(irq) \
111 ({ \
112 irq_desc_t *desc = get_irq_desc(irq); \
113 if (desc->chip && desc->chip->disable) \
114 desc->chip->disable(irq); \
115 })
116#define unmask_irq(irq) \
117 ({ \
118 irq_desc_t *desc = get_irq_desc(irq); \
119 if (desc->chip && desc->chip->enable) \
120 desc->chip->enable(irq); \
121 })
122#define ack_irq(irq) \
123 ({ \
124 irq_desc_t *desc = get_irq_desc(irq); \
125 if (desc->chip && desc->chip->ack) \
126 desc->chip->ack(irq); \
127 })
128
129/* 110/*
130 * interrupt-retrigger: should we handle this via lost interrupts and IPIs 111 * interrupt-retrigger: should we handle this via lost interrupts and IPIs
131 * or should we not care like we do now ? --BenH. 112 * or should we not care like we do now ? --BenH.
diff --git a/include/asm-powerpc/module.h b/include/asm-powerpc/module.h
index 584fabfb4f08..e5f14b13ccf0 100644
--- a/include/asm-powerpc/module.h
+++ b/include/asm-powerpc/module.h
@@ -46,8 +46,6 @@ struct mod_arch_specific {
46 unsigned int num_bugs; 46 unsigned int num_bugs;
47}; 47};
48 48
49extern struct bug_entry *module_find_bug(unsigned long bugaddr);
50
51/* 49/*
52 * Select ELF headers. 50 * Select ELF headers.
53 * Make empty section for module_frob_arch_sections to expand. 51 * Make empty section for module_frob_arch_sections to expand.
diff --git a/include/asm-powerpc/page_32.h b/include/asm-powerpc/page_32.h
index 2677bad70f40..07f6d3cf5e5a 100644
--- a/include/asm-powerpc/page_32.h
+++ b/include/asm-powerpc/page_32.h
@@ -26,15 +26,7 @@ extern void clear_pages(void *page, int order);
26static inline void clear_page(void *page) { clear_pages(page, 0); } 26static inline void clear_page(void *page) { clear_pages(page, 0); }
27extern void copy_page(void *to, void *from); 27extern void copy_page(void *to, void *from);
28 28
29/* Pure 2^n version of get_order */ 29#include <asm-generic/page.h>
30extern __inline__ int get_order(unsigned long size)
31{
32 int lz;
33
34 size = (size-1) >> PAGE_SHIFT;
35 asm ("cntlzw %0,%1" : "=r" (lz) : "r" (size));
36 return 32 - lz;
37}
38 30
39#endif /* __ASSEMBLY__ */ 31#endif /* __ASSEMBLY__ */
40 32
diff --git a/include/asm-powerpc/pci-bridge.h b/include/asm-powerpc/pci-bridge.h
index 7bb7f9009806..cb02c9d1ef93 100644
--- a/include/asm-powerpc/pci-bridge.h
+++ b/include/asm-powerpc/pci-bridge.h
@@ -31,12 +31,12 @@ struct pci_controller {
31 int last_busno; 31 int last_busno;
32 32
33 void __iomem *io_base_virt; 33 void __iomem *io_base_virt;
34 unsigned long io_base_phys; 34 resource_size_t io_base_phys;
35 35
36 /* Some machines have a non 1:1 mapping of 36 /* Some machines have a non 1:1 mapping of
37 * the PCI memory space in the CPU bus space 37 * the PCI memory space in the CPU bus space
38 */ 38 */
39 unsigned long pci_mem_offset; 39 resource_size_t pci_mem_offset;
40 unsigned long pci_io_size; 40 unsigned long pci_io_size;
41 41
42 struct pci_ops *ops; 42 struct pci_ops *ops;
diff --git a/include/asm-powerpc/pci.h b/include/asm-powerpc/pci.h
index 16f13319c769..ac656ee6bb19 100644
--- a/include/asm-powerpc/pci.h
+++ b/include/asm-powerpc/pci.h
@@ -143,8 +143,13 @@ int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
143/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */ 143/* Tell drivers/pci/proc.c that we have pci_mmap_page_range() */
144#define HAVE_PCI_MMAP 1 144#define HAVE_PCI_MMAP 1
145 145
146#ifdef CONFIG_PPC64 146#if defined(CONFIG_PPC64) || defined(CONFIG_NOT_COHERENT_CACHE)
147/* pci_unmap_{single,page} is not a nop, thus... */ 147/*
148 * For 64-bit kernels, pci_unmap_{single,page} is not a nop.
149 * For 32-bit non-coherent kernels, pci_dma_sync_single_for_cpu() and
150 * so on are not nops.
151 * and thus...
152 */
148#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \ 153#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
149 dma_addr_t ADDR_NAME; 154 dma_addr_t ADDR_NAME;
150#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \ 155#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
@@ -158,6 +163,20 @@ int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
158#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \ 163#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
159 (((PTR)->LEN_NAME) = (VAL)) 164 (((PTR)->LEN_NAME) = (VAL))
160 165
166#else /* 32-bit && coherent */
167
168/* pci_unmap_{page,single} is a nop so... */
169#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
170#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
171#define pci_unmap_addr(PTR, ADDR_NAME) (0)
172#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
173#define pci_unmap_len(PTR, LEN_NAME) (0)
174#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
175
176#endif /* CONFIG_PPC64 || CONFIG_NOT_COHERENT_CACHE */
177
178#ifdef CONFIG_PPC64
179
161/* The PCI address space does not equal the physical memory address 180/* The PCI address space does not equal the physical memory address
162 * space (we have an IOMMU). The IDE and SCSI device layers use 181 * space (we have an IOMMU). The IDE and SCSI device layers use
163 * this boolean for bounce buffer decisions. 182 * this boolean for bounce buffer decisions.
@@ -172,16 +191,8 @@ int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
172 */ 191 */
173#define PCI_DMA_BUS_IS_PHYS (1) 192#define PCI_DMA_BUS_IS_PHYS (1)
174 193
175/* pci_unmap_{page,single} is a nop so... */
176#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
177#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
178#define pci_unmap_addr(PTR, ADDR_NAME) (0)
179#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
180#define pci_unmap_len(PTR, LEN_NAME) (0)
181#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
182
183#endif /* CONFIG_PPC64 */ 194#endif /* CONFIG_PPC64 */
184 195
185extern void pcibios_resource_to_bus(struct pci_dev *dev, 196extern void pcibios_resource_to_bus(struct pci_dev *dev,
186 struct pci_bus_region *region, 197 struct pci_bus_region *region,
187 struct resource *res); 198 struct resource *res);
diff --git a/include/asm-powerpc/reg.h b/include/asm-powerpc/reg.h
index 6faae7b14d55..a3631b15754c 100644
--- a/include/asm-powerpc/reg.h
+++ b/include/asm-powerpc/reg.h
@@ -143,6 +143,7 @@
143 143
144/* Special Purpose Registers (SPRNs)*/ 144/* Special Purpose Registers (SPRNs)*/
145#define SPRN_CTR 0x009 /* Count Register */ 145#define SPRN_CTR 0x009 /* Count Register */
146#define SPRN_DSCR 0x11
146#define SPRN_CTRLF 0x088 147#define SPRN_CTRLF 0x088
147#define SPRN_CTRLT 0x098 148#define SPRN_CTRLT 0x098
148#define CTRL_CT 0xc0000000 /* current thread */ 149#define CTRL_CT 0xc0000000 /* current thread */
@@ -163,6 +164,7 @@
163#define SPRN_TBRU 0x10D /* Time Base Read Upper Register (user, R/O) */ 164#define SPRN_TBRU 0x10D /* Time Base Read Upper Register (user, R/O) */
164#define SPRN_TBWL 0x11C /* Time Base Lower Register (super, R/W) */ 165#define SPRN_TBWL 0x11C /* Time Base Lower Register (super, R/W) */
165#define SPRN_TBWU 0x11D /* Time Base Upper Register (super, R/W) */ 166#define SPRN_TBWU 0x11D /* Time Base Upper Register (super, R/W) */
167#define SPRN_SPURR 0x134 /* Scaled PURR */
166#define SPRN_HIOR 0x137 /* 970 Hypervisor interrupt offset */ 168#define SPRN_HIOR 0x137 /* 970 Hypervisor interrupt offset */
167#define SPRN_DBAT0L 0x219 /* Data BAT 0 Lower Register */ 169#define SPRN_DBAT0L 0x219 /* Data BAT 0 Lower Register */
168#define SPRN_DBAT0U 0x218 /* Data BAT 0 Upper Register */ 170#define SPRN_DBAT0U 0x218 /* Data BAT 0 Upper Register */
diff --git a/include/asm-powerpc/rtas.h b/include/asm-powerpc/rtas.h
index 5a0c136c0416..8eaa7b28d9d0 100644
--- a/include/asm-powerpc/rtas.h
+++ b/include/asm-powerpc/rtas.h
@@ -159,6 +159,7 @@ extern struct rtas_t rtas;
159 159
160extern void enter_rtas(unsigned long); 160extern void enter_rtas(unsigned long);
161extern int rtas_token(const char *service); 161extern int rtas_token(const char *service);
162extern int rtas_service_present(const char *service);
162extern int rtas_call(int token, int, int, int *, ...); 163extern int rtas_call(int token, int, int, int *, ...);
163extern void rtas_restart(char *cmd); 164extern void rtas_restart(char *cmd);
164extern void rtas_power_off(void); 165extern void rtas_power_off(void);
@@ -221,8 +222,6 @@ extern int rtas_get_error_log_max(void);
221extern spinlock_t rtas_data_buf_lock; 222extern spinlock_t rtas_data_buf_lock;
222extern char rtas_data_buf[RTAS_DATA_BUF_SIZE]; 223extern char rtas_data_buf[RTAS_DATA_BUF_SIZE];
223 224
224extern void rtas_stop_self(void);
225
226/* RMO buffer reserved for user-space RTAS use */ 225/* RMO buffer reserved for user-space RTAS use */
227extern unsigned long rtas_rmo_buf; 226extern unsigned long rtas_rmo_buf;
228 227
diff --git a/include/asm-powerpc/termbits.h b/include/asm-powerpc/termbits.h
index 6d533b07aaf5..5e79198f7d18 100644
--- a/include/asm-powerpc/termbits.h
+++ b/include/asm-powerpc/termbits.h
@@ -30,6 +30,19 @@ struct termios {
30 speed_t c_ospeed; /* output speed */ 30 speed_t c_ospeed; /* output speed */
31}; 31};
32 32
33/* For PowerPC the termios and ktermios are the same */
34
35struct ktermios {
36 tcflag_t c_iflag; /* input mode flags */
37 tcflag_t c_oflag; /* output mode flags */
38 tcflag_t c_cflag; /* control mode flags */
39 tcflag_t c_lflag; /* local mode flags */
40 cc_t c_cc[NCCS]; /* control characters */
41 cc_t c_line; /* line discipline (== c_cc[19]) */
42 speed_t c_ispeed; /* input speed */
43 speed_t c_ospeed; /* output speed */
44};
45
33/* c_cc characters */ 46/* c_cc characters */
34#define VINTR 0 47#define VINTR 0
35#define VQUIT 1 48#define VQUIT 1
diff --git a/include/asm-powerpc/topology.h b/include/asm-powerpc/topology.h
index 50c014007de7..6610495f5f16 100644
--- a/include/asm-powerpc/topology.h
+++ b/include/asm-powerpc/topology.h
@@ -66,6 +66,7 @@ static inline int pcibus_to_node(struct pci_bus *bus)
66 | SD_BALANCE_EXEC \ 66 | SD_BALANCE_EXEC \
67 | SD_BALANCE_NEWIDLE \ 67 | SD_BALANCE_NEWIDLE \
68 | SD_WAKE_IDLE \ 68 | SD_WAKE_IDLE \
69 | SD_SERIALIZE \
69 | SD_WAKE_BALANCE, \ 70 | SD_WAKE_BALANCE, \
70 .last_balance = jiffies, \ 71 .last_balance = jiffies, \
71 .balance_interval = 1, \ 72 .balance_interval = 1, \
diff --git a/include/asm-ppc/pci-bridge.h b/include/asm-ppc/pci-bridge.h
index 6c955d0c1ef0..4d35b844bc58 100644
--- a/include/asm-ppc/pci-bridge.h
+++ b/include/asm-ppc/pci-bridge.h
@@ -20,8 +20,8 @@ extern unsigned long pci_bus_mem_base_phys(unsigned int bus);
20extern struct pci_controller* pcibios_alloc_controller(void); 20extern struct pci_controller* pcibios_alloc_controller(void);
21 21
22/* Helper function for setting up resources */ 22/* Helper function for setting up resources */
23extern void pci_init_resource(struct resource *res, unsigned long start, 23extern void pci_init_resource(struct resource *res, resource_size_t start,
24 unsigned long end, int flags, char *name); 24 resource_size_t end, int flags, char *name);
25 25
26/* Get the PCI host controller for a bus */ 26/* Get the PCI host controller for a bus */
27extern struct pci_controller* pci_bus_to_hose(int bus); 27extern struct pci_controller* pci_bus_to_hose(int bus);
@@ -50,12 +50,12 @@ struct pci_controller {
50 int bus_offset; 50 int bus_offset;
51 51
52 void __iomem *io_base_virt; 52 void __iomem *io_base_virt;
53 unsigned long io_base_phys; 53 resource_size_t io_base_phys;
54 54
55 /* Some machines (PReP) have a non 1:1 mapping of 55 /* Some machines (PReP) have a non 1:1 mapping of
56 * the PCI memory space in the CPU bus space 56 * the PCI memory space in the CPU bus space
57 */ 57 */
58 unsigned long pci_mem_offset; 58 resource_size_t pci_mem_offset;
59 59
60 struct pci_ops *ops; 60 struct pci_ops *ops;
61 volatile unsigned int __iomem *cfg_addr; 61 volatile unsigned int __iomem *cfg_addr;
diff --git a/include/asm-ppc/pci.h b/include/asm-ppc/pci.h
index 11ffaaa5da16..9d162028dab9 100644
--- a/include/asm-ppc/pci.h
+++ b/include/asm-ppc/pci.h
@@ -61,6 +61,27 @@ extern unsigned long pci_bus_to_phys(unsigned int ba, int busnr);
61 */ 61 */
62#define PCI_DMA_BUS_IS_PHYS (1) 62#define PCI_DMA_BUS_IS_PHYS (1)
63 63
64#ifdef CONFIG_NOT_COHERENT_CACHE
65/*
66 * pci_unmap_{page,single} are NOPs but pci_dma_sync_single_for_cpu()
67 * and so on are not, so...
68 */
69
70#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) \
71 dma_addr_t ADDR_NAME;
72#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) \
73 __u32 LEN_NAME;
74#define pci_unmap_addr(PTR, ADDR_NAME) \
75 ((PTR)->ADDR_NAME)
76#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
77 (((PTR)->ADDR_NAME) = (VAL))
78#define pci_unmap_len(PTR, LEN_NAME) \
79 ((PTR)->LEN_NAME)
80#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
81 (((PTR)->LEN_NAME) = (VAL))
82
83#else /* coherent */
84
64/* pci_unmap_{page,single} is a nop so... */ 85/* pci_unmap_{page,single} is a nop so... */
65#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) 86#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
66#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) 87#define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
@@ -69,6 +90,8 @@ extern unsigned long pci_bus_to_phys(unsigned int ba, int busnr);
69#define pci_unmap_len(PTR, LEN_NAME) (0) 90#define pci_unmap_len(PTR, LEN_NAME) (0)
70#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 91#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
71 92
93#endif /* CONFIG_NOT_COHERENT_CACHE */
94
72#ifdef CONFIG_PCI 95#ifdef CONFIG_PCI
73static inline void pci_dma_burst_advice(struct pci_dev *pdev, 96static inline void pci_dma_burst_advice(struct pci_dev *pdev,
74 enum pci_dma_burst_strategy *strat, 97 enum pci_dma_burst_strategy *strat,
diff --git a/include/asm-ppc/reg_booke.h b/include/asm-ppc/reg_booke.h
index 602fbadeaf48..a263fc1e65c4 100644
--- a/include/asm-ppc/reg_booke.h
+++ b/include/asm-ppc/reg_booke.h
@@ -9,41 +9,9 @@
9#ifndef __ASM_PPC_REG_BOOKE_H__ 9#ifndef __ASM_PPC_REG_BOOKE_H__
10#define __ASM_PPC_REG_BOOKE_H__ 10#define __ASM_PPC_REG_BOOKE_H__
11 11
12#ifndef __ASSEMBLY__ 12#include <asm/dcr.h>
13/* Device Control Registers */
14void __mtdcr(int reg, unsigned int val);
15unsigned int __mfdcr(int reg);
16#define mfdcr(rn) \
17 ({unsigned int rval; \
18 if (__builtin_constant_p(rn)) \
19 asm volatile("mfdcr %0," __stringify(rn) \
20 : "=r" (rval)); \
21 else \
22 rval = __mfdcr(rn); \
23 rval;})
24
25#define mtdcr(rn, v) \
26do { \
27 if (__builtin_constant_p(rn)) \
28 asm volatile("mtdcr " __stringify(rn) ",%0" \
29 : : "r" (v)); \
30 else \
31 __mtdcr(rn, v); \
32} while (0)
33
34/* R/W of indirect DCRs make use of standard naming conventions for DCRs */
35#define mfdcri(base, reg) \
36({ \
37 mtdcr(base ## _CFGADDR, base ## _ ## reg); \
38 mfdcr(base ## _CFGDATA); \
39})
40
41#define mtdcri(base, reg, data) \
42do { \
43 mtdcr(base ## _CFGADDR, base ## _ ## reg); \
44 mtdcr(base ## _CFGDATA, data); \
45} while (0)
46 13
14#ifndef __ASSEMBLY__
47/* Performance Monitor Registers */ 15/* Performance Monitor Registers */
48#define mfpmr(rn) ({unsigned int rval; \ 16#define mfpmr(rn) ({unsigned int rval; \
49 asm volatile("mfpmr %0," __stringify(rn) \ 17 asm volatile("mfpmr %0," __stringify(rn) \
diff --git a/include/asm-s390/dasd.h b/include/asm-s390/dasd.h
index c042f9578081..604f68fa6f56 100644
--- a/include/asm-s390/dasd.h
+++ b/include/asm-s390/dasd.h
@@ -69,11 +69,13 @@ typedef struct dasd_information2_t {
69 * 0x01: readonly (ro) 69 * 0x01: readonly (ro)
70 * 0x02: use diag discipline (diag) 70 * 0x02: use diag discipline (diag)
71 * 0x04: set the device initially online (internal use only) 71 * 0x04: set the device initially online (internal use only)
72 * 0x08: enable ERP related logging
72 */ 73 */
73#define DASD_FEATURE_DEFAULT 0x00 74#define DASD_FEATURE_DEFAULT 0x00
74#define DASD_FEATURE_READONLY 0x01 75#define DASD_FEATURE_READONLY 0x01
75#define DASD_FEATURE_USEDIAG 0x02 76#define DASD_FEATURE_USEDIAG 0x02
76#define DASD_FEATURE_INITIAL_ONLINE 0x04 77#define DASD_FEATURE_INITIAL_ONLINE 0x04
78#define DASD_FEATURE_ERPLOG 0x08
77 79
78#define DASD_PARTN_BITS 2 80#define DASD_PARTN_BITS 2
79 81
diff --git a/include/asm-s390/page.h b/include/asm-s390/page.h
index 363ea761d5ee..05ea6f172786 100644
--- a/include/asm-s390/page.h
+++ b/include/asm-s390/page.h
@@ -127,6 +127,26 @@ page_get_storage_key(unsigned long addr)
127 return skey; 127 return skey;
128} 128}
129 129
130extern unsigned long max_pfn;
131
132static inline int pfn_valid(unsigned long pfn)
133{
134 unsigned long dummy;
135 int ccode;
136
137 if (pfn >= max_pfn)
138 return 0;
139
140 asm volatile(
141 " lra %0,0(%2)\n"
142 " ipm %1\n"
143 " srl %1,28\n"
144 : "=d" (dummy), "=d" (ccode)
145 : "a" (pfn << PAGE_SHIFT)
146 : "cc");
147 return !ccode;
148}
149
130#endif /* !__ASSEMBLY__ */ 150#endif /* !__ASSEMBLY__ */
131 151
132/* to align the pointer to the (next) page boundary */ 152/* to align the pointer to the (next) page boundary */
@@ -138,8 +158,6 @@ page_get_storage_key(unsigned long addr)
138#define __va(x) (void *)(unsigned long)(x) 158#define __va(x) (void *)(unsigned long)(x)
139#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 159#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
140#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 160#define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
141
142#define pfn_valid(pfn) ((pfn) < max_mapnr)
143#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 161#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
144 162
145#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ 163#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
diff --git a/include/asm-s390/pgalloc.h b/include/asm-s390/pgalloc.h
index 28619de5ecae..0707a7e2fc16 100644
--- a/include/asm-s390/pgalloc.h
+++ b/include/asm-s390/pgalloc.h
@@ -25,8 +25,11 @@ extern void diag10(unsigned long addr);
25 * Page allocation orders. 25 * Page allocation orders.
26 */ 26 */
27#ifndef __s390x__ 27#ifndef __s390x__
28# define PTE_ALLOC_ORDER 0
29# define PMD_ALLOC_ORDER 0
28# define PGD_ALLOC_ORDER 1 30# define PGD_ALLOC_ORDER 1
29#else /* __s390x__ */ 31#else /* __s390x__ */
32# define PTE_ALLOC_ORDER 0
30# define PMD_ALLOC_ORDER 2 33# define PMD_ALLOC_ORDER 2
31# define PGD_ALLOC_ORDER 2 34# define PGD_ALLOC_ORDER 2
32#endif /* __s390x__ */ 35#endif /* __s390x__ */
diff --git a/include/asm-s390/pgtable.h b/include/asm-s390/pgtable.h
index 2d968a69ed1f..ae61aca5d483 100644
--- a/include/asm-s390/pgtable.h
+++ b/include/asm-s390/pgtable.h
@@ -107,23 +107,25 @@ extern char empty_zero_page[PAGE_SIZE];
107 * The vmalloc() routines leaves a hole of 4kB between each vmalloced 107 * The vmalloc() routines leaves a hole of 4kB between each vmalloced
108 * area for the same reason. ;) 108 * area for the same reason. ;)
109 */ 109 */
110extern unsigned long vmalloc_end;
110#define VMALLOC_OFFSET (8*1024*1024) 111#define VMALLOC_OFFSET (8*1024*1024)
111#define VMALLOC_START (((unsigned long) high_memory + VMALLOC_OFFSET) \ 112#define VMALLOC_START (((unsigned long) high_memory + VMALLOC_OFFSET) \
112 & ~(VMALLOC_OFFSET-1)) 113 & ~(VMALLOC_OFFSET-1))
114#define VMALLOC_END vmalloc_end
113 115
114/* 116/*
115 * We need some free virtual space to be able to do vmalloc. 117 * We need some free virtual space to be able to do vmalloc.
116 * VMALLOC_MIN_SIZE defines the minimum size of the vmalloc 118 * VMALLOC_MIN_SIZE defines the minimum size of the vmalloc
117 * area. On a machine with 2GB memory we make sure that we 119 * area. On a machine with 2GB memory we make sure that we
118 * have at least 128MB free space for vmalloc. On a machine 120 * have at least 128MB free space for vmalloc. On a machine
119 * with 4TB we make sure we have at least 1GB. 121 * with 4TB we make sure we have at least 128GB.
120 */ 122 */
121#ifndef __s390x__ 123#ifndef __s390x__
122#define VMALLOC_MIN_SIZE 0x8000000UL 124#define VMALLOC_MIN_SIZE 0x8000000UL
123#define VMALLOC_END 0x80000000UL 125#define VMALLOC_END_INIT 0x80000000UL
124#else /* __s390x__ */ 126#else /* __s390x__ */
125#define VMALLOC_MIN_SIZE 0x40000000UL 127#define VMALLOC_MIN_SIZE 0x2000000000UL
126#define VMALLOC_END 0x40000000000UL 128#define VMALLOC_END_INIT 0x40000000000UL
127#endif /* __s390x__ */ 129#endif /* __s390x__ */
128 130
129/* 131/*
@@ -815,11 +817,17 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset)
815 817
816#define kern_addr_valid(addr) (1) 818#define kern_addr_valid(addr) (1)
817 819
820extern int add_shared_memory(unsigned long start, unsigned long size);
821extern int remove_shared_memory(unsigned long start, unsigned long size);
822
818/* 823/*
819 * No page table caches to initialise 824 * No page table caches to initialise
820 */ 825 */
821#define pgtable_cache_init() do { } while (0) 826#define pgtable_cache_init() do { } while (0)
822 827
828#define __HAVE_ARCH_MEMMAP_INIT
829extern void memmap_init(unsigned long, int, unsigned long, unsigned long);
830
823#define __HAVE_ARCH_PTEP_ESTABLISH 831#define __HAVE_ARCH_PTEP_ESTABLISH
824#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS 832#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
825#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 833#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
diff --git a/include/asm-s390/termbits.h b/include/asm-s390/termbits.h
index eb3f8bfabf61..585c78a6e407 100644
--- a/include/asm-s390/termbits.h
+++ b/include/asm-s390/termbits.h
@@ -25,6 +25,17 @@ struct termios {
25 cc_t c_cc[NCCS]; /* control characters */ 25 cc_t c_cc[NCCS]; /* control characters */
26}; 26};
27 27
28struct ktermios {
29 tcflag_t c_iflag; /* input mode flags */
30 tcflag_t c_oflag; /* output mode flags */
31 tcflag_t c_cflag; /* control mode flags */
32 tcflag_t c_lflag; /* local mode flags */
33 cc_t c_line; /* line discipline */
34 cc_t c_cc[NCCS]; /* control characters */
35 speed_t c_ispeed; /* input speed */
36 speed_t c_ospeed; /* output speed */
37};
38
28/* c_cc characters */ 39/* c_cc characters */
29#define VINTR 0 40#define VINTR 0
30#define VQUIT 1 41#define VQUIT 1
diff --git a/include/asm-sh/atomic-irq.h b/include/asm-sh/atomic-irq.h
new file mode 100644
index 000000000000..74f7943cff6f
--- /dev/null
+++ b/include/asm-sh/atomic-irq.h
@@ -0,0 +1,71 @@
1#ifndef __ASM_SH_ATOMIC_IRQ_H
2#define __ASM_SH_ATOMIC_IRQ_H
3
4/*
5 * To get proper branch prediction for the main line, we must branch
6 * forward to code at the end of this object's .text section, then
7 * branch back to restart the operation.
8 */
9static inline void atomic_add(int i, atomic_t *v)
10{
11 unsigned long flags;
12
13 local_irq_save(flags);
14 *(long *)v += i;
15 local_irq_restore(flags);
16}
17
18static inline void atomic_sub(int i, atomic_t *v)
19{
20 unsigned long flags;
21
22 local_irq_save(flags);
23 *(long *)v -= i;
24 local_irq_restore(flags);
25}
26
27static inline int atomic_add_return(int i, atomic_t *v)
28{
29 unsigned long temp, flags;
30
31 local_irq_save(flags);
32 temp = *(long *)v;
33 temp += i;
34 *(long *)v = temp;
35 local_irq_restore(flags);
36
37 return temp;
38}
39
40static inline int atomic_sub_return(int i, atomic_t *v)
41{
42 unsigned long temp, flags;
43
44 local_irq_save(flags);
45 temp = *(long *)v;
46 temp -= i;
47 *(long *)v = temp;
48 local_irq_restore(flags);
49
50 return temp;
51}
52
53static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
54{
55 unsigned long flags;
56
57 local_irq_save(flags);
58 *(long *)v &= ~mask;
59 local_irq_restore(flags);
60}
61
62static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
63{
64 unsigned long flags;
65
66 local_irq_save(flags);
67 *(long *)v |= mask;
68 local_irq_restore(flags);
69}
70
71#endif /* __ASM_SH_ATOMIC_IRQ_H */
diff --git a/include/asm-sh/atomic-llsc.h b/include/asm-sh/atomic-llsc.h
new file mode 100644
index 000000000000..4b00b78e3f4f
--- /dev/null
+++ b/include/asm-sh/atomic-llsc.h
@@ -0,0 +1,107 @@
1#ifndef __ASM_SH_ATOMIC_LLSC_H
2#define __ASM_SH_ATOMIC_LLSC_H
3
4/*
5 * To get proper branch prediction for the main line, we must branch
6 * forward to code at the end of this object's .text section, then
7 * branch back to restart the operation.
8 */
9static inline void atomic_add(int i, atomic_t *v)
10{
11 unsigned long tmp;
12
13 __asm__ __volatile__ (
14"1: movli.l @%2, %0 ! atomic_add \n"
15" add %1, %0 \n"
16" movco.l %0, @%2 \n"
17" bf 1b \n"
18 : "=&z" (tmp)
19 : "r" (i), "r" (&v->counter)
20 : "t");
21}
22
23static inline void atomic_sub(int i, atomic_t *v)
24{
25 unsigned long tmp;
26
27 __asm__ __volatile__ (
28"1: movli.l @%2, %0 ! atomic_sub \n"
29" sub %1, %0 \n"
30" movco.l %0, @%2 \n"
31" bf 1b \n"
32 : "=&z" (tmp)
33 : "r" (i), "r" (&v->counter)
34 : "t");
35}
36
37/*
38 * SH-4A note:
39 *
40 * We basically get atomic_xxx_return() for free compared with
41 * atomic_xxx(). movli.l/movco.l require r0 due to the instruction
42 * encoding, so the retval is automatically set without having to
43 * do any special work.
44 */
45static inline int atomic_add_return(int i, atomic_t *v)
46{
47 unsigned long temp;
48
49 __asm__ __volatile__ (
50"1: movli.l @%2, %0 ! atomic_add_return \n"
51" add %1, %0 \n"
52" movco.l %0, @%2 \n"
53" bf 1b \n"
54" synco \n"
55 : "=&z" (temp)
56 : "r" (i), "r" (&v->counter)
57 : "t");
58
59 return temp;
60}
61
62static inline int atomic_sub_return(int i, atomic_t *v)
63{
64 unsigned long temp;
65
66 __asm__ __volatile__ (
67"1: movli.l @%2, %0 ! atomic_sub_return \n"
68" sub %1, %0 \n"
69" movco.l %0, @%2 \n"
70" bf 1b \n"
71" synco \n"
72 : "=&z" (temp)
73 : "r" (i), "r" (&v->counter)
74 : "t");
75
76 return temp;
77}
78
79static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
80{
81 unsigned long tmp;
82
83 __asm__ __volatile__ (
84"1: movli.l @%2, %0 ! atomic_clear_mask \n"
85" and %1, %0 \n"
86" movco.l %0, @%2 \n"
87" bf 1b \n"
88 : "=&z" (tmp)
89 : "r" (~mask), "r" (&v->counter)
90 : "t");
91}
92
93static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
94{
95 unsigned long tmp;
96
97 __asm__ __volatile__ (
98"1: movli.l @%2, %0 ! atomic_set_mask \n"
99" or %1, %0 \n"
100" movco.l %0, @%2 \n"
101" bf 1b \n"
102 : "=&z" (tmp)
103 : "r" (mask), "r" (&v->counter)
104 : "t");
105}
106
107#endif /* __ASM_SH_ATOMIC_LLSC_H */
diff --git a/include/asm-sh/atomic.h b/include/asm-sh/atomic.h
index 28305c3cbddf..e12570b9339d 100644
--- a/include/asm-sh/atomic.h
+++ b/include/asm-sh/atomic.h
@@ -17,119 +17,14 @@ typedef struct { volatile int counter; } atomic_t;
17#include <linux/compiler.h> 17#include <linux/compiler.h>
18#include <asm/system.h> 18#include <asm/system.h>
19 19
20/*
21 * To get proper branch prediction for the main line, we must branch
22 * forward to code at the end of this object's .text section, then
23 * branch back to restart the operation.
24 */
25static inline void atomic_add(int i, atomic_t *v)
26{
27#ifdef CONFIG_CPU_SH4A 20#ifdef CONFIG_CPU_SH4A
28 unsigned long tmp; 21#include <asm/atomic-llsc.h>
29
30 __asm__ __volatile__ (
31"1: movli.l @%2, %0 ! atomic_add \n"
32" add %1, %0 \n"
33" movco.l %0, @%2 \n"
34" bf 1b \n"
35 : "=&z" (tmp)
36 : "r" (i), "r" (&v->counter)
37 : "t");
38#else 22#else
39 unsigned long flags; 23#include <asm/atomic-irq.h>
40
41 local_irq_save(flags);
42 *(long *)v += i;
43 local_irq_restore(flags);
44#endif
45}
46
47static inline void atomic_sub(int i, atomic_t *v)
48{
49#ifdef CONFIG_CPU_SH4A
50 unsigned long tmp;
51
52 __asm__ __volatile__ (
53"1: movli.l @%2, %0 ! atomic_sub \n"
54" sub %1, %0 \n"
55" movco.l %0, @%2 \n"
56" bf 1b \n"
57 : "=&z" (tmp)
58 : "r" (i), "r" (&v->counter)
59 : "t");
60#else
61 unsigned long flags;
62
63 local_irq_save(flags);
64 *(long *)v -= i;
65 local_irq_restore(flags);
66#endif 24#endif
67}
68
69/*
70 * SH-4A note:
71 *
72 * We basically get atomic_xxx_return() for free compared with
73 * atomic_xxx(). movli.l/movco.l require r0 due to the instruction
74 * encoding, so the retval is automatically set without having to
75 * do any special work.
76 */
77static inline int atomic_add_return(int i, atomic_t *v)
78{
79 unsigned long temp;
80
81#ifdef CONFIG_CPU_SH4A
82 __asm__ __volatile__ (
83"1: movli.l @%2, %0 ! atomic_add_return \n"
84" add %1, %0 \n"
85" movco.l %0, @%2 \n"
86" bf 1b \n"
87" synco \n"
88 : "=&z" (temp)
89 : "r" (i), "r" (&v->counter)
90 : "t");
91#else
92 unsigned long flags;
93
94 local_irq_save(flags);
95 temp = *(long *)v;
96 temp += i;
97 *(long *)v = temp;
98 local_irq_restore(flags);
99#endif
100
101 return temp;
102}
103 25
104#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0) 26#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
105 27
106static inline int atomic_sub_return(int i, atomic_t *v)
107{
108 unsigned long temp;
109
110#ifdef CONFIG_CPU_SH4A
111 __asm__ __volatile__ (
112"1: movli.l @%2, %0 ! atomic_sub_return \n"
113" sub %1, %0 \n"
114" movco.l %0, @%2 \n"
115" bf 1b \n"
116" synco \n"
117 : "=&z" (temp)
118 : "r" (i), "r" (&v->counter)
119 : "t");
120#else
121 unsigned long flags;
122
123 local_irq_save(flags);
124 temp = *(long *)v;
125 temp -= i;
126 *(long *)v = temp;
127 local_irq_restore(flags);
128#endif
129
130 return temp;
131}
132
133#define atomic_dec_return(v) atomic_sub_return(1,(v)) 28#define atomic_dec_return(v) atomic_sub_return(1,(v))
134#define atomic_inc_return(v) atomic_add_return(1,(v)) 29#define atomic_inc_return(v) atomic_add_return(1,(v))
135 30
@@ -180,50 +75,6 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
180} 75}
181#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) 76#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
182 77
183static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
184{
185#ifdef CONFIG_CPU_SH4A
186 unsigned long tmp;
187
188 __asm__ __volatile__ (
189"1: movli.l @%2, %0 ! atomic_clear_mask \n"
190" and %1, %0 \n"
191" movco.l %0, @%2 \n"
192" bf 1b \n"
193 : "=&z" (tmp)
194 : "r" (~mask), "r" (&v->counter)
195 : "t");
196#else
197 unsigned long flags;
198
199 local_irq_save(flags);
200 *(long *)v &= ~mask;
201 local_irq_restore(flags);
202#endif
203}
204
205static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
206{
207#ifdef CONFIG_CPU_SH4A
208 unsigned long tmp;
209
210 __asm__ __volatile__ (
211"1: movli.l @%2, %0 ! atomic_set_mask \n"
212" or %1, %0 \n"
213" movco.l %0, @%2 \n"
214" bf 1b \n"
215 : "=&z" (tmp)
216 : "r" (mask), "r" (&v->counter)
217 : "t");
218#else
219 unsigned long flags;
220
221 local_irq_save(flags);
222 *(long *)v |= mask;
223 local_irq_restore(flags);
224#endif
225}
226
227/* Atomic operations are already serializing on SH */ 78/* Atomic operations are already serializing on SH */
228#define smp_mb__before_atomic_dec() barrier() 79#define smp_mb__before_atomic_dec() barrier()
229#define smp_mb__after_atomic_dec() barrier() 80#define smp_mb__after_atomic_dec() barrier()
diff --git a/include/asm-sh/bug.h b/include/asm-sh/bug.h
index 1b4fc52a59e8..2f89dd06d0cd 100644
--- a/include/asm-sh/bug.h
+++ b/include/asm-sh/bug.h
@@ -1,19 +1,54 @@
1#ifndef __ASM_SH_BUG_H 1#ifndef __ASM_SH_BUG_H
2#define __ASM_SH_BUG_H 2#define __ASM_SH_BUG_H
3 3
4
5#ifdef CONFIG_BUG 4#ifdef CONFIG_BUG
6/* 5
7 * Tell the user there is some problem. 6struct bug_frame {
8 */ 7 unsigned short opcode;
9#define BUG() do { \ 8 unsigned short line;
10 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ 9 const char *file;
11 *(volatile int *)0 = 0; \ 10 const char *func;
11};
12
13struct pt_regs;
14
15extern void handle_BUG(struct pt_regs *);
16
17#define TRAPA_BUG_OPCODE 0xc33e /* trapa #0x3e */
18
19#ifdef CONFIG_DEBUG_BUGVERBOSE
20
21#define BUG() \
22do { \
23 __asm__ __volatile__ ( \
24 ".align 2\n\t" \
25 ".short %O0\n\t" \
26 ".short %O1\n\t" \
27 ".long %O2\n\t" \
28 ".long %O3\n\t" \
29 : \
30 : "n" (TRAPA_BUG_OPCODE), \
31 "i" (__LINE__), "X" (__FILE__), \
32 "X" (__FUNCTION__)); \
33} while (0)
34
35#else
36
37#define BUG() \
38do { \
39 __asm__ __volatile__ ( \
40 ".align 2\n\t" \
41 ".short %O0\n\t" \
42 : \
43 : "n" (TRAPA_BUG_OPCODE)); \
12} while (0) 44} while (0)
13 45
46#endif /* CONFIG_DEBUG_BUGVERBOSE */
47
14#define HAVE_ARCH_BUG 48#define HAVE_ARCH_BUG
15#endif 49
50#endif /* CONFIG_BUG */
16 51
17#include <asm-generic/bug.h> 52#include <asm-generic/bug.h>
18 53
19#endif 54#endif /* __ASM_SH_BUG_H */
diff --git a/include/asm-sh/bugs.h b/include/asm-sh/bugs.h
index 795047da5e17..a294997a8412 100644
--- a/include/asm-sh/bugs.h
+++ b/include/asm-sh/bugs.h
@@ -16,9 +16,8 @@
16 16
17static void __init check_bugs(void) 17static void __init check_bugs(void)
18{ 18{
19 extern char *get_cpu_subtype(void);
20 extern unsigned long loops_per_jiffy; 19 extern unsigned long loops_per_jiffy;
21 char *p= &init_utsname()->machine[2]; /* "sh" */ 20 char *p = &init_utsname()->machine[2]; /* "sh" */
22 21
23 cpu_data->loops_per_jiffy = loops_per_jiffy; 22 cpu_data->loops_per_jiffy = loops_per_jiffy;
24 23
@@ -40,6 +39,15 @@ static void __init check_bugs(void)
40 *p++ = '4'; 39 *p++ = '4';
41 *p++ = 'a'; 40 *p++ = 'a';
42 break; 41 break;
42 case CPU_SH73180 ... CPU_SH7722:
43 *p++ = '4';
44 *p++ = 'a';
45 *p++ = 'l';
46 *p++ = '-';
47 *p++ = 'd';
48 *p++ = 's';
49 *p++ = 'p';
50 break;
43 default: 51 default:
44 *p++ = '?'; 52 *p++ = '?';
45 *p++ = '!'; 53 *p++ = '!';
diff --git a/include/asm-sh/checksum.h b/include/asm-sh/checksum.h
index d44344c88e73..4bc8357e8892 100644
--- a/include/asm-sh/checksum.h
+++ b/include/asm-sh/checksum.h
@@ -34,25 +34,26 @@ asmlinkage __wsum csum_partial(const void *buff, int len, __wsum sum);
34 */ 34 */
35 35
36asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst, 36asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
37 int len, __wsum sum, int *src_err_ptr, int *dst_err_ptr); 37 int len, __wsum sum,
38 int *src_err_ptr, int *dst_err_ptr);
38 39
39/* 40/*
40 * Note: when you get a NULL pointer exception here this means someone 41 * Note: when you get a NULL pointer exception here this means someone
41 * passed in an incorrect kernel address to one of these functions. 42 * passed in an incorrect kernel address to one of these functions.
42 * 43 *
43 * If you use these functions directly please don't forget the 44 * If you use these functions directly please don't forget the
44 * access_ok(). 45 * access_ok().
45 */ 46 */
46static __inline__ 47static inline
47__wsum csum_partial_copy_nocheck(const void *src, void *dst, 48__wsum csum_partial_copy_nocheck(const void *src, void *dst,
48 int len, __wsum sum) 49 int len, __wsum sum)
49{ 50{
50 return csum_partial_copy_generic ( src, dst, len, sum, NULL, NULL); 51 return csum_partial_copy_generic(src, dst, len, sum, NULL, NULL);
51} 52}
52 53
53static __inline__ 54static inline
54__wsum csum_partial_copy_from_user(const void __user *src, void *dst, 55__wsum csum_partial_copy_from_user(const void __user *src, void *dst,
55 int len, __wsum sum, int *err_ptr) 56 int len, __wsum sum, int *err_ptr)
56{ 57{
57 return csum_partial_copy_generic((__force const void *)src, dst, 58 return csum_partial_copy_generic((__force const void *)src, dst,
58 len, sum, err_ptr, NULL); 59 len, sum, err_ptr, NULL);
@@ -62,7 +63,7 @@ __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
62 * Fold a partial checksum 63 * Fold a partial checksum
63 */ 64 */
64 65
65static __inline__ __sum16 csum_fold(__wsum sum) 66static inline __sum16 csum_fold(__wsum sum)
66{ 67{
67 unsigned int __dummy; 68 unsigned int __dummy;
68 __asm__("swap.w %0, %1\n\t" 69 __asm__("swap.w %0, %1\n\t"
@@ -85,7 +86,7 @@ static __inline__ __sum16 csum_fold(__wsum sum)
85 * i386 version by Jorge Cwik <jorge@laser.satlink.net>, adapted 86 * i386 version by Jorge Cwik <jorge@laser.satlink.net>, adapted
86 * for linux by * Arnt Gulbrandsen. 87 * for linux by * Arnt Gulbrandsen.
87 */ 88 */
88static __inline__ __sum16 ip_fast_csum(const void *iph, unsigned int ihl) 89static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
89{ 90{
90 unsigned int sum, __dummy0, __dummy1; 91 unsigned int sum, __dummy0, __dummy1;
91 92
@@ -113,10 +114,10 @@ static __inline__ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
113 return csum_fold(sum); 114 return csum_fold(sum);
114} 115}
115 116
116static __inline__ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr, 117static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
117 unsigned short len, 118 unsigned short len,
118 unsigned short proto, 119 unsigned short proto,
119 __wsum sum) 120 __wsum sum)
120{ 121{
121#ifdef __LITTLE_ENDIAN__ 122#ifdef __LITTLE_ENDIAN__
122 unsigned long len_proto = (proto + len) << 8; 123 unsigned long len_proto = (proto + len) << 8;
@@ -132,6 +133,7 @@ static __inline__ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
132 : "=r" (sum), "=r" (len_proto) 133 : "=r" (sum), "=r" (len_proto)
133 : "r" (daddr), "r" (saddr), "1" (len_proto), "0" (sum) 134 : "r" (daddr), "r" (saddr), "1" (len_proto), "0" (sum)
134 : "t"); 135 : "t");
136
135 return sum; 137 return sum;
136} 138}
137 139
@@ -139,30 +141,28 @@ static __inline__ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
139 * computes the checksum of the TCP/UDP pseudo-header 141 * computes the checksum of the TCP/UDP pseudo-header
140 * returns a 16-bit checksum, already complemented 142 * returns a 16-bit checksum, already complemented
141 */ 143 */
142static __inline__ __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr, 144static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
143 unsigned short len, 145 unsigned short len,
144 unsigned short proto, 146 unsigned short proto,
145 __wsum sum) 147 __wsum sum)
146{ 148{
147 return csum_fold(csum_tcpudp_nofold(saddr,daddr,len,proto,sum)); 149 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
148} 150}
149 151
150/* 152/*
151 * this routine is used for miscellaneous IP-like checksums, mainly 153 * this routine is used for miscellaneous IP-like checksums, mainly
152 * in icmp.c 154 * in icmp.c
153 */ 155 */
154 156static inline __sum16 ip_compute_csum(const void *buff, int len)
155static __inline__ __sum16 ip_compute_csum(const void *buff, int len)
156{ 157{
157 return csum_fold (csum_partial(buff, len, 0)); 158 return csum_fold(csum_partial(buff, len, 0));
158} 159}
159 160
160#define _HAVE_ARCH_IPV6_CSUM 161#define _HAVE_ARCH_IPV6_CSUM
161#ifdef CONFIG_IPV6 162static inline __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
162static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr, 163 const struct in6_addr *daddr,
163 const struct in6_addr *daddr, 164 __u32 len, unsigned short proto,
164 __u32 len, unsigned short proto, 165 __wsum sum)
165 __wsum sum)
166{ 166{
167 unsigned int __dummy; 167 unsigned int __dummy;
168 __asm__("clrt\n\t" 168 __asm__("clrt\n\t"
@@ -187,22 +187,21 @@ static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
187 "movt %1\n\t" 187 "movt %1\n\t"
188 "add %1, %0\n" 188 "add %1, %0\n"
189 : "=r" (sum), "=&r" (__dummy) 189 : "=r" (sum), "=&r" (__dummy)
190 : "r" (saddr), "r" (daddr), 190 : "r" (saddr), "r" (daddr),
191 "r" (htonl(len)), "r" (htonl(proto)), "0" (sum) 191 "r" (htonl(len)), "r" (htonl(proto)), "0" (sum)
192 : "t"); 192 : "t");
193 193
194 return csum_fold(sum); 194 return csum_fold(sum);
195} 195}
196#endif
197 196
198/* 197/*
199 * Copy and checksum to user 198 * Copy and checksum to user
200 */ 199 */
201#define HAVE_CSUM_COPY_USER 200#define HAVE_CSUM_COPY_USER
202static __inline__ __wsum csum_and_copy_to_user (const void *src, 201static inline __wsum csum_and_copy_to_user(const void *src,
203 void __user *dst, 202 void __user *dst,
204 int len, __wsum sum, 203 int len, __wsum sum,
205 int *err_ptr) 204 int *err_ptr)
206{ 205{
207 if (access_ok(VERIFY_WRITE, dst, len)) 206 if (access_ok(VERIFY_WRITE, dst, len))
208 return csum_partial_copy_generic((__force const void *)src, 207 return csum_partial_copy_generic((__force const void *)src,
diff --git a/include/asm-sh/cpu-sh4/cache.h b/include/asm-sh/cpu-sh4/cache.h
index 6e9c7e6ee8e4..f92b20a0983d 100644
--- a/include/asm-sh/cpu-sh4/cache.h
+++ b/include/asm-sh/cpu-sh4/cache.h
@@ -22,7 +22,7 @@
22#define CCR_CACHE_ICE 0x0100 /* Instruction Cache Enable */ 22#define CCR_CACHE_ICE 0x0100 /* Instruction Cache Enable */
23#define CCR_CACHE_ICI 0x0800 /* IC Invalidate */ 23#define CCR_CACHE_ICI 0x0800 /* IC Invalidate */
24#define CCR_CACHE_IIX 0x8000 /* IC Index Enable */ 24#define CCR_CACHE_IIX 0x8000 /* IC Index Enable */
25#ifndef CONFIG_CPU_SUBTYPE_SH7780 25#ifndef CONFIG_CPU_SH4A
26#define CCR_CACHE_EMODE 0x80000000 /* EMODE Enable */ 26#define CCR_CACHE_EMODE 0x80000000 /* EMODE Enable */
27#endif 27#endif
28 28
diff --git a/include/asm-sh/cpu-sh4/freq.h b/include/asm-sh/cpu-sh4/freq.h
index ef2b9b1ae41f..602d061ca2dc 100644
--- a/include/asm-sh/cpu-sh4/freq.h
+++ b/include/asm-sh/cpu-sh4/freq.h
@@ -10,7 +10,7 @@
10#ifndef __ASM_CPU_SH4_FREQ_H 10#ifndef __ASM_CPU_SH4_FREQ_H
11#define __ASM_CPU_SH4_FREQ_H 11#define __ASM_CPU_SH4_FREQ_H
12 12
13#if defined(CONFIG_CPU_SUBTYPE_SH73180) 13#if defined(CONFIG_CPU_SUBTYPE_SH73180) || defined(CONFIG_CPU_SUBTYPE_SH7722)
14#define FRQCR 0xa4150000 14#define FRQCR 0xa4150000
15#elif defined(CONFIG_CPU_SUBTYPE_SH7780) 15#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
16#define FRQCR 0xffc80000 16#define FRQCR 0xffc80000
diff --git a/include/asm-sh/dma-mapping.h b/include/asm-sh/dma-mapping.h
index 37ab0c131a4d..8d0867b98e05 100644
--- a/include/asm-sh/dma-mapping.h
+++ b/include/asm-sh/dma-mapping.h
@@ -67,7 +67,7 @@ static inline dma_addr_t dma_map_single(struct device *dev,
67 if (dev->bus == &pci_bus_type) 67 if (dev->bus == &pci_bus_type)
68 return virt_to_bus(ptr); 68 return virt_to_bus(ptr);
69#endif 69#endif
70 dma_cache_sync(ptr, size, dir); 70 dma_cache_sync(dev, ptr, size, dir);
71 71
72 return virt_to_bus(ptr); 72 return virt_to_bus(ptr);
73} 73}
@@ -81,7 +81,7 @@ static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
81 81
82 for (i = 0; i < nents; i++) { 82 for (i = 0; i < nents; i++) {
83#if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT) 83#if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
84 dma_cache_sync(page_address(sg[i].page) + sg[i].offset, 84 dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset,
85 sg[i].length, dir); 85 sg[i].length, dir);
86#endif 86#endif
87 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset; 87 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
@@ -112,7 +112,7 @@ static inline void dma_sync_single(struct device *dev, dma_addr_t dma_handle,
112 if (dev->bus == &pci_bus_type) 112 if (dev->bus == &pci_bus_type)
113 return; 113 return;
114#endif 114#endif
115 dma_cache_sync(bus_to_virt(dma_handle), size, dir); 115 dma_cache_sync(dev, bus_to_virt(dma_handle), size, dir);
116} 116}
117 117
118static inline void dma_sync_single_range(struct device *dev, 118static inline void dma_sync_single_range(struct device *dev,
@@ -124,7 +124,7 @@ static inline void dma_sync_single_range(struct device *dev,
124 if (dev->bus == &pci_bus_type) 124 if (dev->bus == &pci_bus_type)
125 return; 125 return;
126#endif 126#endif
127 dma_cache_sync(bus_to_virt(dma_handle) + offset, size, dir); 127 dma_cache_sync(dev, bus_to_virt(dma_handle) + offset, size, dir);
128} 128}
129 129
130static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg, 130static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
@@ -134,7 +134,7 @@ static inline void dma_sync_sg(struct device *dev, struct scatterlist *sg,
134 134
135 for (i = 0; i < nelems; i++) { 135 for (i = 0; i < nelems; i++) {
136#if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT) 136#if !defined(CONFIG_PCI) || defined(CONFIG_SH_PCIDMA_NONCOHERENT)
137 dma_cache_sync(page_address(sg[i].page) + sg[i].offset, 137 dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset,
138 sg[i].length, dir); 138 sg[i].length, dir);
139#endif 139#endif
140 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset; 140 sg[i].dma_address = page_to_phys(sg[i].page) + sg[i].offset;
diff --git a/include/asm-sh/irq.h b/include/asm-sh/irq.h
index fd576088e47e..bff965ef4b95 100644
--- a/include/asm-sh/irq.h
+++ b/include/asm-sh/irq.h
@@ -37,7 +37,8 @@
37# define ONCHIP_NR_IRQS 144 37# define ONCHIP_NR_IRQS 144
38#elif defined(CONFIG_CPU_SUBTYPE_SH7300) || \ 38#elif defined(CONFIG_CPU_SUBTYPE_SH7300) || \
39 defined(CONFIG_CPU_SUBTYPE_SH73180) || \ 39 defined(CONFIG_CPU_SUBTYPE_SH73180) || \
40 defined(CONFIG_CPU_SUBTYPE_SH7343) 40 defined(CONFIG_CPU_SUBTYPE_SH7343) || \
41 defined(CONFIG_CPU_SUBTYPE_SH7722)
41# define ONCHIP_NR_IRQS 109 42# define ONCHIP_NR_IRQS 109
42#elif defined(CONFIG_CPU_SUBTYPE_SH7780) 43#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
43# define ONCHIP_NR_IRQS 111 44# define ONCHIP_NR_IRQS 111
@@ -79,6 +80,8 @@
79# define OFFCHIP_NR_IRQS 16 80# define OFFCHIP_NR_IRQS 16
80#elif defined(CONFIG_SH_7343_SOLUTION_ENGINE) 81#elif defined(CONFIG_SH_7343_SOLUTION_ENGINE)
81# define OFFCHIP_NR_IRQS 12 82# define OFFCHIP_NR_IRQS 12
83#elif defined(CONFIG_SH_7722_SOLUTION_ENGINE)
84# define OFFCHIP_NR_IRQS 14
82#elif defined(CONFIG_SH_UNKNOWN) 85#elif defined(CONFIG_SH_UNKNOWN)
83# define OFFCHIP_NR_IRQS 16 /* Must also be last */ 86# define OFFCHIP_NR_IRQS 16 /* Must also be last */
84#else 87#else
diff --git a/include/asm-sh/pgtable.h b/include/asm-sh/pgtable.h
index c84901dbd8e5..036ca2843866 100644
--- a/include/asm-sh/pgtable.h
+++ b/include/asm-sh/pgtable.h
@@ -508,16 +508,50 @@ struct vm_area_struct;
508extern void update_mmu_cache(struct vm_area_struct * vma, 508extern void update_mmu_cache(struct vm_area_struct * vma,
509 unsigned long address, pte_t pte); 509 unsigned long address, pte_t pte);
510 510
511/* Encode and de-code a swap entry */
512/* 511/*
512 * Encode and de-code a swap entry
513 *
514 * Constraints:
515 * _PAGE_FILE at bit 0
516 * _PAGE_PRESENT at bit 8
517 * _PAGE_PROTNONE at bit 9
518 *
519 * For the normal case, we encode the swap type into bits 0:7 and the
520 * swap offset into bits 10:30. For the 64-bit PTE case, we keep the
521 * preserved bits in the low 32-bits and use the upper 32 as the swap
522 * offset (along with a 5-bit type), following the same approach as x86
523 * PAE. This keeps the logic quite simple, and allows for a full 32
524 * PTE_FILE_MAX_BITS, as opposed to the 29-bits we're constrained with
525 * in the pte_low case.
526 *
527 * As is evident by the Alpha code, if we ever get a 64-bit unsigned
528 * long (swp_entry_t) to match up with the 64-bit PTEs, this all becomes
529 * much cleaner..
530 *
513 * NOTE: We should set ZEROs at the position of _PAGE_PRESENT 531 * NOTE: We should set ZEROs at the position of _PAGE_PRESENT
514 * and _PAGE_PROTNONE bits 532 * and _PAGE_PROTNONE bits
515 */ 533 */
516#define __swp_type(x) ((x).val & 0xff) 534#ifdef CONFIG_X2TLB
517#define __swp_offset(x) ((x).val >> 10) 535#define __swp_type(x) ((x).val & 0x1f)
518#define __swp_entry(type, offset) ((swp_entry_t) { (type) | ((offset) << 10) }) 536#define __swp_offset(x) ((x).val >> 5)
519#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 }) 537#define __swp_entry(type, offset) ((swp_entry_t){ (type) | (offset) << 5})
520#define __swp_entry_to_pte(x) ((pte_t) { (x).val << 1 }) 538#define __pte_to_swp_entry(pte) ((swp_entry_t){ (pte).pte_high })
539#define __swp_entry_to_pte(x) ((pte_t){ 0, (x).val })
540
541/*
542 * Encode and decode a nonlinear file mapping entry
543 */
544#define pte_to_pgoff(pte) ((pte).pte_high)
545#define pgoff_to_pte(off) ((pte_t) { _PAGE_FILE, (off) })
546
547#define PTE_FILE_MAX_BITS 32
548#else
549#define __swp_type(x) ((x).val & 0xff)
550#define __swp_offset(x) ((x).val >> 10)
551#define __swp_entry(type, offset) ((swp_entry_t){(type) | (offset) <<10})
552
553#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 1 })
554#define __swp_entry_to_pte(x) ((pte_t) { (x).val << 1 })
521 555
522/* 556/*
523 * Encode and decode a nonlinear file mapping entry 557 * Encode and decode a nonlinear file mapping entry
@@ -525,6 +559,7 @@ extern void update_mmu_cache(struct vm_area_struct * vma,
525#define PTE_FILE_MAX_BITS 29 559#define PTE_FILE_MAX_BITS 29
526#define pte_to_pgoff(pte) (pte_val(pte) >> 1) 560#define pte_to_pgoff(pte) (pte_val(pte) >> 1)
527#define pgoff_to_pte(off) ((pte_t) { ((off) << 1) | _PAGE_FILE }) 561#define pgoff_to_pte(off) ((pte_t) { ((off) << 1) | _PAGE_FILE })
562#endif
528 563
529typedef pte_t *pte_addr_t; 564typedef pte_t *pte_addr_t;
530 565
diff --git a/include/asm-sh/processor.h b/include/asm-sh/processor.h
index 6f1dd7ca1b1d..e29f2abb92de 100644
--- a/include/asm-sh/processor.h
+++ b/include/asm-sh/processor.h
@@ -27,6 +27,8 @@
27#define CCN_CVR 0xff000040 27#define CCN_CVR 0xff000040
28#define CCN_PRR 0xff000044 28#define CCN_PRR 0xff000044
29 29
30const char *get_cpu_subtype(void);
31
30/* 32/*
31 * CPU type and hardware bug flags. Kept separately for each CPU. 33 * CPU type and hardware bug flags. Kept separately for each CPU.
32 * 34 *
@@ -52,8 +54,10 @@ enum cpu_type {
52 CPU_SH7760, CPU_ST40RA, CPU_ST40GX1, CPU_SH4_202, CPU_SH4_501, 54 CPU_SH7760, CPU_ST40RA, CPU_ST40GX1, CPU_SH4_202, CPU_SH4_501,
53 55
54 /* SH-4A types */ 56 /* SH-4A types */
55 CPU_SH73180, CPU_SH7343, CPU_SH7770, CPU_SH7780, CPU_SH7781, 57 CPU_SH7770, CPU_SH7780, CPU_SH7781, CPU_SH7785,
56 CPU_SH7785, 58
59 /* SH4AL-DSP types */
60 CPU_SH73180, CPU_SH7343, CPU_SH7722,
57 61
58 /* Unknown subtype */ 62 /* Unknown subtype */
59 CPU_SH_NONE 63 CPU_SH_NONE
diff --git a/include/asm-sh/push-switch.h b/include/asm-sh/push-switch.h
index dfc6bad567f0..4903f9e52dd8 100644
--- a/include/asm-sh/push-switch.h
+++ b/include/asm-sh/push-switch.h
@@ -4,6 +4,7 @@
4#include <linux/timer.h> 4#include <linux/timer.h>
5#include <linux/interrupt.h> 5#include <linux/interrupt.h>
6#include <linux/workqueue.h> 6#include <linux/workqueue.h>
7#include <linux/platform_device.h>
7 8
8struct push_switch { 9struct push_switch {
9 /* switch state */ 10 /* switch state */
@@ -12,6 +13,8 @@ struct push_switch {
12 struct timer_list debounce; 13 struct timer_list debounce;
13 /* workqueue */ 14 /* workqueue */
14 struct work_struct work; 15 struct work_struct work;
16 /* platform device, for workqueue handler */
17 struct platform_device *pdev;
15}; 18};
16 19
17struct push_switch_platform_info { 20struct push_switch_platform_info {
diff --git a/include/asm-sh/termbits.h b/include/asm-sh/termbits.h
index 4f9822a8e7b4..f1b7b46f4e9a 100644
--- a/include/asm-sh/termbits.h
+++ b/include/asm-sh/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-sparc/termbits.h b/include/asm-sparc/termbits.h
index 1794d71134b7..5eb00a105d7c 100644
--- a/include/asm-sparc/termbits.h
+++ b/include/asm-sparc/termbits.h
@@ -31,6 +31,18 @@ struct termios {
31#endif 31#endif
32}; 32};
33 33
34struct ktermios {
35 tcflag_t c_iflag; /* input mode flags */
36 tcflag_t c_oflag; /* output mode flags */
37 tcflag_t c_cflag; /* control mode flags */
38 tcflag_t c_lflag; /* local mode flags */
39 cc_t c_line; /* line discipline */
40 cc_t c_cc[NCCS]; /* control characters */
41 cc_t _x_cc[2]; /* We need them to hold vmin/vtime */
42 speed_t c_ispeed; /* input speed */
43 speed_t c_ospeed; /* output speed */
44};
45
34/* c_cc characters */ 46/* c_cc characters */
35#define VINTR 0 47#define VINTR 0
36#define VQUIT 1 48#define VQUIT 1
diff --git a/include/asm-sparc64/dma.h b/include/asm-sparc64/dma.h
index 27f65972b3bb..93e5a062df88 100644
--- a/include/asm-sparc64/dma.h
+++ b/include/asm-sparc64/dma.h
@@ -152,9 +152,9 @@ extern void dvma_init(struct sbus_bus *);
152#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL)) 152#define DMA_MAXEND(addr) (0x01000000UL-(((unsigned long)(addr))&0x00ffffffUL))
153 153
154/* Yes, I hack a lot of elisp in my spare time... */ 154/* Yes, I hack a lot of elisp in my spare time... */
155#define DMA_ERROR_P(regs) (((sbus_readl((regs) + DMA_CSR) & DMA_HNDL_ERROR)) 155#define DMA_ERROR_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_HNDL_ERROR))
156#define DMA_IRQ_P(regs) (((sbus_readl((regs) + DMA_CSR)) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))) 156#define DMA_IRQ_P(regs) ((sbus_readl((regs) + DMA_CSR)) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))
157#define DMA_WRITE_P(regs) (((sbus_readl((regs) + DMA_CSR) & DMA_ST_WRITE)) 157#define DMA_WRITE_P(regs) ((sbus_readl((regs) + DMA_CSR) & DMA_ST_WRITE))
158#define DMA_OFF(__regs) \ 158#define DMA_OFF(__regs) \
159do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \ 159do { u32 tmp = sbus_readl((__regs) + DMA_CSR); \
160 tmp &= ~DMA_ENABLE; \ 160 tmp &= ~DMA_ENABLE; \
diff --git a/include/asm-sparc64/irqflags.h b/include/asm-sparc64/irqflags.h
new file mode 100644
index 000000000000..024fc54d0682
--- /dev/null
+++ b/include/asm-sparc64/irqflags.h
@@ -0,0 +1,89 @@
1/*
2 * include/asm-sparc64/irqflags.h
3 *
4 * IRQ flags handling
5 *
6 * This file gets included from lowlevel asm headers too, to provide
7 * wrapped versions of the local_irq_*() APIs, based on the
8 * raw_local_irq_*() functions from the lowlevel headers.
9 */
10#ifndef _ASM_IRQFLAGS_H
11#define _ASM_IRQFLAGS_H
12
13#ifndef __ASSEMBLY__
14
15static inline unsigned long __raw_local_save_flags(void)
16{
17 unsigned long flags;
18
19 __asm__ __volatile__(
20 "rdpr %%pil, %0"
21 : "=r" (flags)
22 );
23
24 return flags;
25}
26
27#define raw_local_save_flags(flags) \
28 do { (flags) = __raw_local_save_flags(); } while (0)
29
30static inline void raw_local_irq_restore(unsigned long flags)
31{
32 __asm__ __volatile__(
33 "wrpr %0, %%pil"
34 : /* no output */
35 : "r" (flags)
36 : "memory"
37 );
38}
39
40static inline void raw_local_irq_disable(void)
41{
42 __asm__ __volatile__(
43 "wrpr 15, %%pil"
44 : /* no outputs */
45 : /* no inputs */
46 : "memory"
47 );
48}
49
50static inline void raw_local_irq_enable(void)
51{
52 __asm__ __volatile__(
53 "wrpr 0, %%pil"
54 : /* no outputs */
55 : /* no inputs */
56 : "memory"
57 );
58}
59
60static inline int raw_irqs_disabled_flags(unsigned long flags)
61{
62 return (flags > 0);
63}
64
65static inline int raw_irqs_disabled(void)
66{
67 unsigned long flags = __raw_local_save_flags();
68
69 return raw_irqs_disabled_flags(flags);
70}
71
72/*
73 * For spinlocks, etc:
74 */
75static inline unsigned long __raw_local_irq_save(void)
76{
77 unsigned long flags = __raw_local_save_flags();
78
79 raw_local_irq_disable();
80
81 return flags;
82}
83
84#define raw_local_irq_save(flags) \
85 do { (flags) = __raw_local_irq_save(); } while (0)
86
87#endif /* (__ASSEMBLY__) */
88
89#endif /* !(_ASM_IRQFLAGS_H) */
diff --git a/include/asm-sparc64/kprobes.h b/include/asm-sparc64/kprobes.h
index c9f5c34d318c..becc38fa06c5 100644
--- a/include/asm-sparc64/kprobes.h
+++ b/include/asm-sparc64/kprobes.h
@@ -13,7 +13,11 @@ typedef u32 kprobe_opcode_t;
13#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry 13#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry
14#define arch_remove_kprobe(p) do {} while (0) 14#define arch_remove_kprobe(p) do {} while (0)
15#define ARCH_INACTIVE_KPROBE_COUNT 0 15#define ARCH_INACTIVE_KPROBE_COUNT 0
16#define flush_insn_slot(p) do { } while (0) 16
17#define flush_insn_slot(p) \
18do { flushi(&(p)->ainsn.insn[0]); \
19 flushi(&(p)->ainsn.insn[1]); \
20} while (0)
17 21
18/* Architecture specific copy of original instruction*/ 22/* Architecture specific copy of original instruction*/
19struct arch_specific_insn { 23struct arch_specific_insn {
@@ -23,7 +27,7 @@ struct arch_specific_insn {
23 27
24struct prev_kprobe { 28struct prev_kprobe {
25 struct kprobe *kp; 29 struct kprobe *kp;
26 unsigned int status; 30 unsigned long status;
27 unsigned long orig_tnpc; 31 unsigned long orig_tnpc;
28 unsigned long orig_tstate_pil; 32 unsigned long orig_tstate_pil;
29}; 33};
@@ -33,10 +37,7 @@ struct kprobe_ctlblk {
33 unsigned long kprobe_status; 37 unsigned long kprobe_status;
34 unsigned long kprobe_orig_tnpc; 38 unsigned long kprobe_orig_tnpc;
35 unsigned long kprobe_orig_tstate_pil; 39 unsigned long kprobe_orig_tstate_pil;
36 long *jprobe_saved_esp;
37 struct pt_regs jprobe_saved_regs; 40 struct pt_regs jprobe_saved_regs;
38 struct pt_regs *jprobe_saved_regs_location;
39 struct sparc_stackf jprobe_saved_stack;
40 struct prev_kprobe prev_kprobe; 41 struct prev_kprobe prev_kprobe;
41}; 42};
42 43
diff --git a/include/asm-sparc64/rwsem.h b/include/asm-sparc64/rwsem.h
index cef5e8270421..1294b7ce5d06 100644
--- a/include/asm-sparc64/rwsem.h
+++ b/include/asm-sparc64/rwsem.h
@@ -23,20 +23,33 @@ struct rw_semaphore {
23 signed int count; 23 signed int count;
24 spinlock_t wait_lock; 24 spinlock_t wait_lock;
25 struct list_head wait_list; 25 struct list_head wait_list;
26#ifdef CONFIG_DEBUG_LOCK_ALLOC
27 struct lockdep_map dep_map;
28#endif
26}; 29};
27 30
31#ifdef CONFIG_DEBUG_LOCK_ALLOC
32# define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname }
33#else
34# define __RWSEM_DEP_MAP_INIT(lockname)
35#endif
36
28#define __RWSEM_INITIALIZER(name) \ 37#define __RWSEM_INITIALIZER(name) \
29{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) } 38{ RWSEM_UNLOCKED_VALUE, SPIN_LOCK_UNLOCKED, LIST_HEAD_INIT((name).wait_list) \
39 __RWSEM_DEP_MAP_INIT(name) }
30 40
31#define DECLARE_RWSEM(name) \ 41#define DECLARE_RWSEM(name) \
32 struct rw_semaphore name = __RWSEM_INITIALIZER(name) 42 struct rw_semaphore name = __RWSEM_INITIALIZER(name)
33 43
34static __inline__ void init_rwsem(struct rw_semaphore *sem) 44extern void __init_rwsem(struct rw_semaphore *sem, const char *name,
35{ 45 struct lock_class_key *key);
36 sem->count = RWSEM_UNLOCKED_VALUE; 46
37 spin_lock_init(&sem->wait_lock); 47#define init_rwsem(sem) \
38 INIT_LIST_HEAD(&sem->wait_list); 48do { \
39} 49 static struct lock_class_key __key; \
50 \
51 __init_rwsem((sem), #sem, &__key); \
52} while (0)
40 53
41extern void __down_read(struct rw_semaphore *sem); 54extern void __down_read(struct rw_semaphore *sem);
42extern int __down_read_trylock(struct rw_semaphore *sem); 55extern int __down_read_trylock(struct rw_semaphore *sem);
@@ -46,6 +59,11 @@ extern void __up_read(struct rw_semaphore *sem);
46extern void __up_write(struct rw_semaphore *sem); 59extern void __up_write(struct rw_semaphore *sem);
47extern void __downgrade_write(struct rw_semaphore *sem); 60extern void __downgrade_write(struct rw_semaphore *sem);
48 61
62static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
63{
64 __down_write(sem);
65}
66
49static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem) 67static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
50{ 68{
51 return atomic_add_return(delta, (atomic_t *)(&sem->count)); 69 return atomic_add_return(delta, (atomic_t *)(&sem->count));
diff --git a/include/asm-sparc64/system.h b/include/asm-sparc64/system.h
index a8b7432c9a70..32281acb878b 100644
--- a/include/asm-sparc64/system.h
+++ b/include/asm-sparc64/system.h
@@ -7,6 +7,9 @@
7#include <asm/visasm.h> 7#include <asm/visasm.h>
8 8
9#ifndef __ASSEMBLY__ 9#ifndef __ASSEMBLY__
10
11#include <linux/irqflags.h>
12
10/* 13/*
11 * Sparc (general) CPU types 14 * Sparc (general) CPU types
12 */ 15 */
@@ -72,52 +75,6 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
72 75
73#endif 76#endif
74 77
75#define setipl(__new_ipl) \
76 __asm__ __volatile__("wrpr %0, %%pil" : : "r" (__new_ipl) : "memory")
77
78#define local_irq_disable() \
79 __asm__ __volatile__("wrpr 15, %%pil" : : : "memory")
80
81#define local_irq_enable() \
82 __asm__ __volatile__("wrpr 0, %%pil" : : : "memory")
83
84#define getipl() \
85({ unsigned long retval; __asm__ __volatile__("rdpr %%pil, %0" : "=r" (retval)); retval; })
86
87#define swap_pil(__new_pil) \
88({ unsigned long retval; \
89 __asm__ __volatile__("rdpr %%pil, %0\n\t" \
90 "wrpr %1, %%pil" \
91 : "=&r" (retval) \
92 : "r" (__new_pil) \
93 : "memory"); \
94 retval; \
95})
96
97#define read_pil_and_cli() \
98({ unsigned long retval; \
99 __asm__ __volatile__("rdpr %%pil, %0\n\t" \
100 "wrpr 15, %%pil" \
101 : "=r" (retval) \
102 : : "memory"); \
103 retval; \
104})
105
106#define local_save_flags(flags) ((flags) = getipl())
107#define local_irq_save(flags) ((flags) = read_pil_and_cli())
108#define local_irq_restore(flags) setipl((flags))
109
110/* On sparc64 IRQ flags are the PIL register. A value of zero
111 * means all interrupt levels are enabled, any other value means
112 * only IRQ levels greater than that value will be received.
113 * Consequently this means that the lowest IRQ level is one.
114 */
115#define irqs_disabled() \
116({ unsigned long flags; \
117 local_save_flags(flags);\
118 (flags > 0); \
119})
120
121#define nop() __asm__ __volatile__ ("nop") 78#define nop() __asm__ __volatile__ ("nop")
122 79
123#define read_barrier_depends() do { } while(0) 80#define read_barrier_depends() do { } while(0)
diff --git a/include/asm-sparc64/termbits.h b/include/asm-sparc64/termbits.h
index b07715273ed4..705cd44b4173 100644
--- a/include/asm-sparc64/termbits.h
+++ b/include/asm-sparc64/termbits.h
@@ -33,6 +33,18 @@ struct termios {
33#endif 33#endif
34}; 34};
35 35
36struct ktermios {
37 tcflag_t c_iflag; /* input mode flags */
38 tcflag_t c_oflag; /* output mode flags */
39 tcflag_t c_cflag; /* control mode flags */
40 tcflag_t c_lflag; /* local mode flags */
41 cc_t c_line; /* line discipline */
42 cc_t c_cc[NCCS]; /* control characters */
43 cc_t _x_cc[2]; /* We need them to hold vmin/vtime */
44 speed_t c_ispeed; /* input speed */
45 speed_t c_ospeed; /* output speed */
46};
47
36/* c_cc characters */ 48/* c_cc characters */
37#define VINTR 0 49#define VINTR 0
38#define VQUIT 1 50#define VQUIT 1
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index f2352606a79f..c2a16e188499 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -137,10 +137,49 @@
137#endif 137#endif
138#define BREAKPOINT_TRAP TRAP(breakpoint_trap) 138#define BREAKPOINT_TRAP TRAP(breakpoint_trap)
139 139
140#ifdef CONFIG_TRACE_IRQFLAGS
141
142#define TRAP_IRQ(routine, level) \
143 rdpr %pil, %g2; \
144 wrpr %g0, 15, %pil; \
145 sethi %hi(1f-4), %g7; \
146 ba,pt %xcc, etrap_irq; \
147 or %g7, %lo(1f-4), %g7; \
148 nop; \
149 nop; \
150 nop; \
151 .subsection 2; \
1521: call trace_hardirqs_off; \
153 nop; \
154 mov level, %o0; \
155 call routine; \
156 add %sp, PTREGS_OFF, %o1; \
157 ba,a,pt %xcc, rtrap_irq; \
158 .previous;
159
160#define TICK_SMP_IRQ \
161 rdpr %pil, %g2; \
162 wrpr %g0, 15, %pil; \
163 sethi %hi(1f-4), %g7; \
164 ba,pt %xcc, etrap_irq; \
165 or %g7, %lo(1f-4), %g7; \
166 nop; \
167 nop; \
168 nop; \
169 .subsection 2; \
1701: call trace_hardirqs_off; \
171 nop; \
172 call smp_percpu_timer_interrupt; \
173 add %sp, PTREGS_OFF, %o0; \
174 ba,a,pt %xcc, rtrap_irq; \
175 .previous;
176
177#else
178
140#define TRAP_IRQ(routine, level) \ 179#define TRAP_IRQ(routine, level) \
141 rdpr %pil, %g2; \ 180 rdpr %pil, %g2; \
142 wrpr %g0, 15, %pil; \ 181 wrpr %g0, 15, %pil; \
143 b,pt %xcc, etrap_irq; \ 182 ba,pt %xcc, etrap_irq; \
144 rd %pc, %g7; \ 183 rd %pc, %g7; \
145 mov level, %o0; \ 184 mov level, %o0; \
146 call routine; \ 185 call routine; \
@@ -151,12 +190,14 @@
151 rdpr %pil, %g2; \ 190 rdpr %pil, %g2; \
152 wrpr %g0, 15, %pil; \ 191 wrpr %g0, 15, %pil; \
153 sethi %hi(109f), %g7; \ 192 sethi %hi(109f), %g7; \
154 b,pt %xcc, etrap_irq; \ 193 ba,pt %xcc, etrap_irq; \
155109: or %g7, %lo(109b), %g7; \ 194109: or %g7, %lo(109b), %g7; \
156 call smp_percpu_timer_interrupt; \ 195 call smp_percpu_timer_interrupt; \
157 add %sp, PTREGS_OFF, %o0; \ 196 add %sp, PTREGS_OFF, %o0; \
158 ba,a,pt %xcc, rtrap_irq; 197 ba,a,pt %xcc, rtrap_irq;
159 198
199#endif
200
160#define TRAP_IVEC TRAP_NOSAVE(do_ivec) 201#define TRAP_IVEC TRAP_NOSAVE(do_ivec)
161 202
162#define BTRAP(lvl) TRAP_ARG(bad_trap, lvl) 203#define BTRAP(lvl) TRAP_ARG(bad_trap, lvl)
diff --git a/include/asm-um/bug.h b/include/asm-um/bug.h
index 1e22fa26ff06..3357c5e2468e 100644
--- a/include/asm-um/bug.h
+++ b/include/asm-um/bug.h
@@ -1,4 +1,6 @@
1#ifndef __UM_BUG_H 1#ifndef __UM_BUG_H
2#define __UM_BUG_H 2#define __UM_BUG_H
3#include <asm-generic/bug.h> 3
4#include <asm/arch/bug.h>
5
4#endif 6#endif
diff --git a/include/asm-v850/termbits.h b/include/asm-v850/termbits.h
index 212d4e279263..f3b433032089 100644
--- a/include/asm-v850/termbits.h
+++ b/include/asm-v850/termbits.h
@@ -17,6 +17,17 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct ktermios {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
20/* c_cc characters */ 31/* c_cc characters */
21#define VINTR 0 32#define VINTR 0
22#define VQUIT 1 33#define VQUIT 1
diff --git a/include/asm-x86_64/bug.h b/include/asm-x86_64/bug.h
index 80ac1fe966ac..682606414913 100644
--- a/include/asm-x86_64/bug.h
+++ b/include/asm-x86_64/bug.h
@@ -1,30 +1,30 @@
1#ifndef __ASM_X8664_BUG_H 1#ifndef __ASM_X8664_BUG_H
2#define __ASM_X8664_BUG_H 1 2#define __ASM_X8664_BUG_H 1
3 3
4#include <linux/stringify.h>
5
6/*
7 * Tell the user there is some problem. The exception handler decodes
8 * this frame.
9 */
10struct bug_frame {
11 unsigned char ud2[2];
12 unsigned char push;
13 signed int filename;
14 unsigned char ret;
15 unsigned short line;
16} __attribute__((packed));
17
18#ifdef CONFIG_BUG 4#ifdef CONFIG_BUG
19#define HAVE_ARCH_BUG 5#define HAVE_ARCH_BUG
20/* We turn the bug frame into valid instructions to not confuse 6
21 the disassembler. Thanks to Jan Beulich & Suresh Siddha 7#ifdef CONFIG_DEBUG_BUGVERBOSE
22 for nice instruction selection. 8#define BUG() \
23 The magic numbers generate mov $64bitimm,%eax ; ret $offset. */ 9 do { \
24#define BUG() \ 10 asm volatile("1:\tud2\n" \
25 asm volatile( \ 11 ".pushsection __bug_table,\"a\"\n" \
26 "ud2 ; pushq $%c1 ; ret $%c0" :: \ 12 "2:\t.quad 1b, %c0\n" \
27 "i"(__LINE__), "i" (__FILE__)) 13 "\t.word %c1, 0\n" \
14 "\t.org 2b+%c2\n" \
15 ".popsection" \
16 : : "i" (__FILE__), "i" (__LINE__), \
17 "i" (sizeof(struct bug_entry))); \
18 for(;;) ; \
19 } while(0)
20#else
21#define BUG() \
22 do { \
23 asm volatile("ud2"); \
24 for(;;) ; \
25 } while(0)
26#endif
27
28void out_of_line_bug(void); 28void out_of_line_bug(void);
29#else 29#else
30static inline void out_of_line_bug(void) { } 30static inline void out_of_line_bug(void) { }
diff --git a/include/asm-x86_64/ioctls.h b/include/asm-x86_64/ioctls.h
index 62caf8b6e4e1..3fc0b15a0d7e 100644
--- a/include/asm-x86_64/ioctls.h
+++ b/include/asm-x86_64/ioctls.h
@@ -46,6 +46,10 @@
46#define TIOCSBRK 0x5427 /* BSD compatibility */ 46#define TIOCSBRK 0x5427 /* BSD compatibility */
47#define TIOCCBRK 0x5428 /* BSD compatibility */ 47#define TIOCCBRK 0x5428 /* BSD compatibility */
48#define TIOCGSID 0x5429 /* Return the session ID of FD */ 48#define TIOCGSID 0x5429 /* Return the session ID of FD */
49#define TCGETS2 _IOR('T',0x2A, struct termios2)
50#define TCSETS2 _IOW('T',0x2B, struct termios2)
51#define TCSETSW2 _IOW('T',0x2C, struct termios2)
52#define TCSETSF2 _IOW('T',0x2D, struct termios2)
49#define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ 53#define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
50#define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ 54#define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */
51 55
diff --git a/include/asm-x86_64/termbits.h b/include/asm-x86_64/termbits.h
index bd950946e52c..6cfc3bb10c1a 100644
--- a/include/asm-x86_64/termbits.h
+++ b/include/asm-x86_64/termbits.h
@@ -17,6 +17,28 @@ struct termios {
17 cc_t c_cc[NCCS]; /* control characters */ 17 cc_t c_cc[NCCS]; /* control characters */
18}; 18};
19 19
20struct termios2 {
21 tcflag_t c_iflag; /* input mode flags */
22 tcflag_t c_oflag; /* output mode flags */
23 tcflag_t c_cflag; /* control mode flags */
24 tcflag_t c_lflag; /* local mode flags */
25 cc_t c_line; /* line discipline */
26 cc_t c_cc[NCCS]; /* control characters */
27 speed_t c_ispeed; /* input speed */
28 speed_t c_ospeed; /* output speed */
29};
30
31struct ktermios {
32 tcflag_t c_iflag; /* input mode flags */
33 tcflag_t c_oflag; /* output mode flags */
34 tcflag_t c_cflag; /* control mode flags */
35 tcflag_t c_lflag; /* local mode flags */
36 cc_t c_line; /* line discipline */
37 cc_t c_cc[NCCS]; /* control characters */
38 speed_t c_ispeed; /* input speed */
39 speed_t c_ospeed; /* output speed */
40};
41
20/* c_cc characters */ 42/* c_cc characters */
21#define VINTR 0 43#define VINTR 0
22#define VQUIT 1 44#define VQUIT 1
@@ -118,6 +140,7 @@ struct termios {
118#define HUPCL 0002000 140#define HUPCL 0002000
119#define CLOCAL 0004000 141#define CLOCAL 0004000
120#define CBAUDEX 0010000 142#define CBAUDEX 0010000
143#define BOTHER 0010000 /* non standard rate */
121#define B57600 0010001 144#define B57600 0010001
122#define B115200 0010002 145#define B115200 0010002
123#define B230400 0010003 146#define B230400 0010003
@@ -133,10 +156,12 @@ struct termios {
133#define B3000000 0010015 156#define B3000000 0010015
134#define B3500000 0010016 157#define B3500000 0010016
135#define B4000000 0010017 158#define B4000000 0010017
136#define CIBAUD 002003600000 /* input baud rate (not used) */ 159#define CIBAUD 002003600000 /* input baud rate */
137#define CMSPAR 010000000000 /* mark or space (stick) parity */ 160#define CMSPAR 010000000000 /* mark or space (stick) parity */
138#define CRTSCTS 020000000000 /* flow control */ 161#define CRTSCTS 020000000000 /* flow control */
139 162
163#define IBSHIFT 8 /* Shift from CBAUD to CIBAUD */
164
140/* c_lflag bits */ 165/* c_lflag bits */
141#define ISIG 0000001 166#define ISIG 0000001
142#define ICANON 0000002 167#define ICANON 0000002
diff --git a/include/asm-x86_64/termios.h b/include/asm-x86_64/termios.h
index 041a91f7ddfb..443b225537f0 100644
--- a/include/asm-x86_64/termios.h
+++ b/include/asm-x86_64/termios.h
@@ -98,8 +98,10 @@ struct termio {
98 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 98 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
99}) 99})
100 100
101#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios)) 101#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
102#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios)) 102#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
103#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
104#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
103 105
104#endif /* __KERNEL__ */ 106#endif /* __KERNEL__ */
105 107
diff --git a/include/asm-x86_64/topology.h b/include/asm-x86_64/topology.h
index 5c8f49280dbc..2facec5914d2 100644
--- a/include/asm-x86_64/topology.h
+++ b/include/asm-x86_64/topology.h
@@ -47,6 +47,7 @@ extern int __node_distance(int, int);
47 .flags = SD_LOAD_BALANCE \ 47 .flags = SD_LOAD_BALANCE \
48 | SD_BALANCE_FORK \ 48 | SD_BALANCE_FORK \
49 | SD_BALANCE_EXEC \ 49 | SD_BALANCE_EXEC \
50 | SD_SERIALIZE \
50 | SD_WAKE_BALANCE, \ 51 | SD_WAKE_BALANCE, \
51 .last_balance = jiffies, \ 52 .last_balance = jiffies, \
52 .balance_interval = 1, \ 53 .balance_interval = 1, \
diff --git a/include/asm-xtensa/asmmacro.h b/include/asm-xtensa/asmmacro.h
new file mode 100644
index 000000000000..76915cabad17
--- /dev/null
+++ b/include/asm-xtensa/asmmacro.h
@@ -0,0 +1,153 @@
1/*
2 * include/asm-xtensa/asmmacro.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2005 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_ASMMACRO_H
12#define _XTENSA_ASMMACRO_H
13
14#include <asm/variant/core.h>
15
16/*
17 * Some little helpers for loops. Use zero-overhead-loops
18 * where applicable and if supported by the processor.
19 *
20 * __loopi ar, at, size, inc
21 * ar register initialized with the start address
22 * at scratch register used by macro
23 * size size immediate value
24 * inc increment
25 *
26 * __loops ar, as, at, inc_log2[, mask_log2][, cond][, ncond]
27 * ar register initialized with the start address
28 * as register initialized with the size
29 * at scratch register use by macro
30 * inc_log2 increment [in log2]
31 * mask_log2 mask [in log2]
32 * cond true condition (used in loop'cond')
33 * ncond false condition (used in b'ncond')
34 *
35 * __loop as
36 * restart loop. 'as' register must not have been modified!
37 *
38 * __endla ar, at, incr
39 * ar start address (modified)
40 * as scratch register used by macro
41 * inc increment
42 */
43
44/*
45 * loop for given size as immediate
46 */
47
48 .macro __loopi ar, at, size, incr
49
50#if XCHAL_HAVE_LOOPS
51 movi \at, ((\size + \incr - 1) / (\incr))
52 loop \at, 99f
53#else
54 addi \at, \ar, \size
55 98:
56#endif
57
58 .endm
59
60/*
61 * loop for given size in register
62 */
63
64 .macro __loops ar, as, at, incr_log2, mask_log2, cond, ncond
65
66#if XCHAL_HAVE_LOOPS
67 .ifgt \incr_log2 - 1
68 addi \at, \as, (1 << \incr_log2) - 1
69 .ifnc \mask_log2,
70 extui \at, \at, \incr_log2, \mask_log2
71 .else
72 srli \at, \at, \incr_log2
73 .endif
74 .endif
75 loop\cond \at, 99f
76#else
77 .ifnc \mask_log2,
78 extui \at, \as, \incr_log2, \mask_log2
79 .else
80 .ifnc \ncond,
81 srli \at, \as, \incr_log2
82 .endif
83 .endif
84 .ifnc \ncond,
85 b\ncond \at, 99f
86
87 .endif
88 .ifnc \mask_log2,
89 slli \at, \at, \incr_log2
90 add \at, \ar, \at
91 .else
92 add \at, \ar, \as
93 .endif
94#endif
95 98:
96
97 .endm
98
99/*
100 * loop from ar to ax
101 */
102
103 .macro __loopt ar, as, at, incr_log2
104
105#if XCHAL_HAVE_LOOPS
106 sub \at, \as, \ar
107 .ifgt \incr_log2 - 1
108 addi \at, \at, (1 << \incr_log2) - 1
109 srli \at, \at, \incr_log2
110 .endif
111 loop \at, 99f
112#else
113 98:
114#endif
115
116 .endm
117
118/*
119 * restart loop. registers must be unchanged
120 */
121
122 .macro __loop as
123
124#if XCHAL_HAVE_LOOPS
125 loop \as, 99f
126#else
127 98:
128#endif
129
130 .endm
131
132/*
133 * end of loop with no increment of the address.
134 */
135
136 .macro __endl ar, as
137#if !XCHAL_HAVE_LOOPS
138 bltu \ar, \as, 98b
139#endif
140 99:
141 .endm
142
143/*
144 * end of loop with increment of the address.
145 */
146
147 .macro __endla ar, as, incr
148 addi \ar, \ar, \incr
149 __endl \ar \as
150 .endm
151
152
153#endif /* _XTENSA_ASMMACRO_H */
diff --git a/include/asm-xtensa/bug.h b/include/asm-xtensa/bug.h
index 56703659b204..3e52d72712f1 100644
--- a/include/asm-xtensa/bug.h
+++ b/include/asm-xtensa/bug.h
@@ -13,29 +13,6 @@
13#ifndef _XTENSA_BUG_H 13#ifndef _XTENSA_BUG_H
14#define _XTENSA_BUG_H 14#define _XTENSA_BUG_H
15 15
16#include <linux/stringify.h> 16#include <asm-generic/bug.h>
17
18#define ILL __asm__ __volatile__ (".byte 0,0,0\n")
19
20#ifdef CONFIG_KALLSYMS
21# define BUG() do { \
22 printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
23 ILL; \
24} while (0)
25#else
26# define BUG() do { \
27 printk("kernel BUG!\n"); \
28 ILL; \
29} while (0)
30#endif
31
32#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
33#define PAGE_BUG(page) do { BUG(); } while (0)
34#define WARN_ON(condition) do { \
35 if (unlikely((condition)!=0)) { \
36 printk ("Warning in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
37 dump_stack(); \
38 } \
39} while (0)
40 17
41#endif /* _XTENSA_BUG_H */ 18#endif /* _XTENSA_BUG_H */
diff --git a/include/asm-xtensa/byteorder.h b/include/asm-xtensa/byteorder.h
index 0b1552569aae..0f540a5f4c01 100644
--- a/include/asm-xtensa/byteorder.h
+++ b/include/asm-xtensa/byteorder.h
@@ -11,10 +11,9 @@
11#ifndef _XTENSA_BYTEORDER_H 11#ifndef _XTENSA_BYTEORDER_H
12#define _XTENSA_BYTEORDER_H 12#define _XTENSA_BYTEORDER_H
13 13
14#include <asm/processor.h>
15#include <asm/types.h> 14#include <asm/types.h>
16 15
17static __inline__ __const__ __u32 ___arch__swab32(__u32 x) 16static __inline__ __attribute_const__ __u32 ___arch__swab32(__u32 x)
18{ 17{
19 __u32 res; 18 __u32 res;
20 /* instruction sequence from Xtensa ISA release 2/2000 */ 19 /* instruction sequence from Xtensa ISA release 2/2000 */
@@ -29,7 +28,7 @@ static __inline__ __const__ __u32 ___arch__swab32(__u32 x)
29 return res; 28 return res;
30} 29}
31 30
32static __inline__ __const__ __u16 ___arch__swab16(__u16 x) 31static __inline__ __attribute_const__ __u16 ___arch__swab16(__u16 x)
33{ 32{
34 /* Given that 'short' values are signed (i.e., can be negative), 33 /* Given that 'short' values are signed (i.e., can be negative),
35 * we cannot assume that the upper 16-bits of the register are 34 * we cannot assume that the upper 16-bits of the register are
diff --git a/include/asm-xtensa/cache.h b/include/asm-xtensa/cache.h
index 1e79c0e27460..1c4a78f29ae2 100644
--- a/include/asm-xtensa/cache.h
+++ b/include/asm-xtensa/cache.h
@@ -4,7 +4,6 @@
4 * This file is subject to the terms and conditions of the GNU General Public 4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 2 of the License, or (at your option) any later version.
8 * 7 *
9 * (C) 2001 - 2005 Tensilica Inc. 8 * (C) 2001 - 2005 Tensilica Inc.
10 */ 9 */
@@ -12,21 +11,14 @@
12#ifndef _XTENSA_CACHE_H 11#ifndef _XTENSA_CACHE_H
13#define _XTENSA_CACHE_H 12#define _XTENSA_CACHE_H
14 13
15#include <xtensa/config/core.h> 14#include <asm/variant/core.h>
16 15
17#if XCHAL_ICACHE_SIZE > 0 16#define L1_CACHE_SHIFT XCHAL_DCACHE_LINEWIDTH
18# if (XCHAL_ICACHE_SIZE % (XCHAL_ICACHE_LINESIZE*XCHAL_ICACHE_WAYS*4)) != 0 17#define L1_CACHE_BYTES XCHAL_DCACHE_LINESIZE
19# error cache configuration outside expected/supported range! 18#define SMP_CACHE_BYTES L1_CACHE_BYTES
20# endif
21#endif
22 19
23#if XCHAL_DCACHE_SIZE > 0 20#define DCACHE_WAY_SIZE (XCHAL_DCACHE_SIZE/XCHAL_DCACHE_WAYS)
24# if (XCHAL_DCACHE_SIZE % (XCHAL_DCACHE_LINESIZE*XCHAL_DCACHE_WAYS*4)) != 0 21#define ICACHE_WAY_SIZE (XCHAL_ICACHE_SIZE/XCHAL_ICACHE_WAYS)
25# error cache configuration outside expected/supported range!
26# endif
27#endif
28 22
29#define L1_CACHE_SHIFT XCHAL_CACHE_LINEWIDTH_MAX
30#define L1_CACHE_BYTES XCHAL_CACHE_LINESIZE_MAX
31 23
32#endif /* _XTENSA_CACHE_H */ 24#endif /* _XTENSA_CACHE_H */
diff --git a/include/asm-xtensa/cacheasm.h b/include/asm-xtensa/cacheasm.h
new file mode 100644
index 000000000000..2c20a58f94cd
--- /dev/null
+++ b/include/asm-xtensa/cacheasm.h
@@ -0,0 +1,177 @@
1/*
2 * include/asm-xtensa/cacheasm.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2006 Tensilica Inc.
9 */
10
11#include <asm/cache.h>
12#include <asm/asmmacro.h>
13#include <linux/stringify.h>
14
15/*
16 * Define cache functions as macros here so that they can be used
17 * by the kernel and boot loader. We should consider moving them to a
18 * library that can be linked by both.
19 *
20 * Locking
21 *
22 * ___unlock_dcache_all
23 * ___unlock_icache_all
24 *
25 * Flush and invaldating
26 *
27 * ___flush_invalidate_dcache_{all|range|page}
28 * ___flush_dcache_{all|range|page}
29 * ___invalidate_dcache_{all|range|page}
30 * ___invalidate_icache_{all|range|page}
31 *
32 */
33
34 .macro __loop_cache_all ar at insn size line_width
35
36 movi \ar, 0
37
38 __loopi \ar, \at, \size, (4 << (\line_width))
39 \insn \ar, 0 << (\line_width)
40 \insn \ar, 1 << (\line_width)
41 \insn \ar, 2 << (\line_width)
42 \insn \ar, 3 << (\line_width)
43 __endla \ar, \at, 4 << (\line_width)
44
45 .endm
46
47
48 .macro __loop_cache_range ar as at insn line_width
49
50 extui \at, \ar, 0, \line_width
51 add \as, \as, \at
52
53 __loops \ar, \as, \at, \line_width
54 \insn \ar, 0
55 __endla \ar, \at, (1 << (\line_width))
56
57 .endm
58
59
60 .macro __loop_cache_page ar at insn line_width
61
62 __loopi \ar, \at, PAGE_SIZE, 4 << (\line_width)
63 \insn \ar, 0 << (\line_width)
64 \insn \ar, 1 << (\line_width)
65 \insn \ar, 2 << (\line_width)
66 \insn \ar, 3 << (\line_width)
67 __endla \ar, \at, 4 << (\line_width)
68
69 .endm
70
71
72#if XCHAL_DCACHE_LINE_LOCKABLE
73
74 .macro ___unlock_dcache_all ar at
75
76 __loop_cache_all \ar \at diu XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
77
78 .endm
79
80#endif
81
82#if XCHAL_ICACHE_LINE_LOCKABLE
83
84 .macro ___unlock_icache_all ar at
85
86 __loop_cache_all \ar \at iiu XCHAL_ICACHE_SIZE XCHAL_ICACHE_LINEWIDTH
87
88 .endm
89#endif
90
91 .macro ___flush_invalidate_dcache_all ar at
92
93 __loop_cache_all \ar \at diwbi XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
94
95 .endm
96
97
98 .macro ___flush_dcache_all ar at
99
100 __loop_cache_all \ar \at diwb XCHAL_DCACHE_SIZE XCHAL_DCACHE_LINEWIDTH
101
102 .endm
103
104
105 .macro ___invalidate_dcache_all ar at
106
107 __loop_cache_all \ar \at dii __stringify(DCACHE_WAY_SIZE) \
108 XCHAL_DCACHE_LINEWIDTH
109
110 .endm
111
112
113 .macro ___invalidate_icache_all ar at
114
115 __loop_cache_all \ar \at iii __stringify(ICACHE_WAY_SIZE) \
116 XCHAL_ICACHE_LINEWIDTH
117
118 .endm
119
120
121
122 .macro ___flush_invalidate_dcache_range ar as at
123
124 __loop_cache_range \ar \as \at dhwbi XCHAL_DCACHE_LINEWIDTH
125
126 .endm
127
128
129 .macro ___flush_dcache_range ar as at
130
131 __loop_cache_range \ar \as \at dhwb XCHAL_DCACHE_LINEWIDTH
132
133 .endm
134
135
136 .macro ___invalidate_dcache_range ar as at
137
138 __loop_cache_range \ar \as \at dhi XCHAL_DCACHE_LINEWIDTH
139
140 .endm
141
142
143 .macro ___invalidate_icache_range ar as at
144
145 __loop_cache_range \ar \as \at ihi XCHAL_ICACHE_LINEWIDTH
146
147 .endm
148
149
150
151 .macro ___flush_invalidate_dcache_page ar as
152
153 __loop_cache_page \ar \as dhwbi XCHAL_DCACHE_LINEWIDTH
154
155 .endm
156
157
158 .macro ___flush_dcache_page ar as
159
160 __loop_cache_page \ar \as dhwb XCHAL_DCACHE_LINEWIDTH
161
162 .endm
163
164
165 .macro ___invalidate_dcache_page ar as
166
167 __loop_cache_page \ar \as dhi XCHAL_DCACHE_LINEWIDTH
168
169 .endm
170
171
172 .macro ___invalidate_icache_page ar as
173
174 __loop_cache_page \ar \as ihi XCHAL_ICACHE_LINEWIDTH
175
176 .endm
177
diff --git a/include/asm-xtensa/cacheflush.h b/include/asm-xtensa/cacheflush.h
index 44a36e087844..337765b629de 100644
--- a/include/asm-xtensa/cacheflush.h
+++ b/include/asm-xtensa/cacheflush.h
@@ -5,7 +5,7 @@
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details. 6 * for more details.
7 * 7 *
8 * (C) 2001 - 2005 Tensilica Inc. 8 * (C) 2001 - 2006 Tensilica Inc.
9 */ 9 */
10 10
11#ifndef _XTENSA_CACHEFLUSH_H 11#ifndef _XTENSA_CACHEFLUSH_H
diff --git a/include/asm-xtensa/checksum.h b/include/asm-xtensa/checksum.h
index 5435aff9a4b7..23534c60b3a4 100644
--- a/include/asm-xtensa/checksum.h
+++ b/include/asm-xtensa/checksum.h
@@ -12,7 +12,7 @@
12#define _XTENSA_CHECKSUM_H 12#define _XTENSA_CHECKSUM_H
13 13
14#include <linux/in6.h> 14#include <linux/in6.h>
15#include <xtensa/config/core.h> 15#include <asm/variant/core.h>
16 16
17/* 17/*
18 * computes the checksum of a memory block at buff, length len, 18 * computes the checksum of a memory block at buff, length len,
diff --git a/include/asm-xtensa/coprocessor.h b/include/asm-xtensa/coprocessor.h
index 5093034723be..bd09ec02d57f 100644
--- a/include/asm-xtensa/coprocessor.h
+++ b/include/asm-xtensa/coprocessor.h
@@ -11,7 +11,16 @@
11#ifndef _XTENSA_COPROCESSOR_H 11#ifndef _XTENSA_COPROCESSOR_H
12#define _XTENSA_COPROCESSOR_H 12#define _XTENSA_COPROCESSOR_H
13 13
14#include <xtensa/config/core.h> 14#include <asm/variant/core.h>
15#include <asm/variant/tie.h>
16
17#if !XCHAL_HAVE_CP
18
19#define XTENSA_CP_EXTRA_OFFSET 0
20#define XTENSA_CP_EXTRA_ALIGN 1 /* must be a power of 2 */
21#define XTENSA_CP_EXTRA_SIZE 0
22
23#else
15 24
16#define XTOFS(last_start,last_size,align) \ 25#define XTOFS(last_start,last_size,align) \
17 ((last_start+last_size+align-1) & -align) 26 ((last_start+last_size+align-1) & -align)
@@ -67,4 +76,6 @@ extern void save_coprocessor_registers(void*, int);
67# endif 76# endif
68#endif 77#endif
69 78
79#endif
80
70#endif /* _XTENSA_COPROCESSOR_H */ 81#endif /* _XTENSA_COPROCESSOR_H */
diff --git a/include/asm-xtensa/dma.h b/include/asm-xtensa/dma.h
index db2633f67789..e30f3abf48f0 100644
--- a/include/asm-xtensa/dma.h
+++ b/include/asm-xtensa/dma.h
@@ -12,7 +12,6 @@
12#define _XTENSA_DMA_H 12#define _XTENSA_DMA_H
13 13
14#include <asm/io.h> /* need byte IO */ 14#include <asm/io.h> /* need byte IO */
15#include <xtensa/config/core.h>
16 15
17/* 16/*
18 * This is only to be defined if we have PC-like DMA. 17 * This is only to be defined if we have PC-like DMA.
@@ -44,7 +43,9 @@
44 * enters another area, and virt_to_phys() may not return 43 * enters another area, and virt_to_phys() may not return
45 * the value desired). 44 * the value desired).
46 */ 45 */
47#define MAX_DMA_ADDRESS (PAGE_OFFSET + XCHAL_KSEG_CACHED_SIZE - 1) 46
47#define MAX_DMA_ADDRESS (PAGE_OFFSET + XCHAL_KIO_SIZE - 1)
48
48 49
49/* Reserve and release a DMA channel */ 50/* Reserve and release a DMA channel */
50extern int request_dma(unsigned int dmanr, const char * device_id); 51extern int request_dma(unsigned int dmanr, const char * device_id);
diff --git a/include/asm-xtensa/elf.h b/include/asm-xtensa/elf.h
index de0667453b2e..f0f9fd8560a5 100644
--- a/include/asm-xtensa/elf.h
+++ b/include/asm-xtensa/elf.h
@@ -13,9 +13,8 @@
13#ifndef _XTENSA_ELF_H 13#ifndef _XTENSA_ELF_H
14#define _XTENSA_ELF_H 14#define _XTENSA_ELF_H
15 15
16#include <asm/variant/core.h>
16#include <asm/ptrace.h> 17#include <asm/ptrace.h>
17#include <asm/coprocessor.h>
18#include <xtensa/config/core.h>
19 18
20/* Xtensa processor ELF architecture-magic number */ 19/* Xtensa processor ELF architecture-magic number */
21 20
@@ -118,11 +117,15 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
118 * using memcpy(). But we do allow space for such alignment, 117 * using memcpy(). But we do allow space for such alignment,
119 * to allow optimizations of layout and copying. 118 * to allow optimizations of layout and copying.
120 */ 119 */
121 120#if 0
122#define TOTAL_FPREGS_SIZE \ 121#define TOTAL_FPREGS_SIZE \
123 (4 + XTENSA_CPE_LTABLE_SIZE + XTENSA_CP_EXTRA_SIZE) 122 (4 + XTENSA_CPE_LTABLE_SIZE + XTENSA_CP_EXTRA_SIZE)
124#define ELF_NFPREG \ 123#define ELF_NFPREG \
125 ((TOTAL_FPREGS_SIZE + sizeof(elf_fpreg_t) - 1) / sizeof(elf_fpreg_t)) 124 ((TOTAL_FPREGS_SIZE + sizeof(elf_fpreg_t) - 1) / sizeof(elf_fpreg_t))
125#else
126#define TOTAL_FPREGS_SIZE 0
127#define ELF_NFPREG 0
128#endif
126 129
127typedef unsigned int elf_fpreg_t; 130typedef unsigned int elf_fpreg_t;
128typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG]; 131typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
diff --git a/include/asm-xtensa/fcntl.h b/include/asm-xtensa/fcntl.h
index ec066ae96caf..0609fc691b72 100644
--- a/include/asm-xtensa/fcntl.h
+++ b/include/asm-xtensa/fcntl.h
@@ -14,48 +14,86 @@
14 14
15/* open/fcntl - O_SYNC is only implemented on blocks devices and on files 15/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
16 located on an ext2 file system */ 16 located on an ext2 file system */
17#define O_APPEND 0x0008 17#define O_ACCMODE 0003
18#define O_SYNC 0x0010 18#define O_RDONLY 00
19#define O_NONBLOCK 0x0080 19#define O_WRONLY 01
20#define O_CREAT 0x0100 /* not fcntl */ 20#define O_RDWR 02
21#define O_EXCL 0x0400 /* not fcntl */ 21#define O_CREAT 0100 /* not fcntl */
22#define O_NOCTTY 0x0800 /* not fcntl */ 22#define O_EXCL 0200 /* not fcntl */
23#define FASYNC 0x1000 /* fcntl, for BSD compatibility */ 23#define O_NOCTTY 0400 /* not fcntl */
24#define O_LARGEFILE 0x2000 /* allow large file opens - currently ignored */ 24#define O_TRUNC 01000 /* not fcntl */
25#define O_DIRECT 0x8000 /* direct disk access hint - currently ignored*/ 25#define O_APPEND 02000
26#define O_NOATIME 0x100000 26#define O_NONBLOCK 04000
27 27#define O_NDELAY O_NONBLOCK
28#define F_GETLK 14 28#define O_SYNC 010000
29#define F_GETLK64 15 29#define FASYNC 020000 /* fcntl, for BSD compatibility */
30#define O_DIRECT 040000 /* direct disk access hint */
31#define O_LARGEFILE 0100000
32#define O_DIRECTORY 0200000 /* must be a directory */
33#define O_NOFOLLOW 0400000 /* don't follow links */
34#define O_NOATIME 01000000
35
36#define F_DUPFD 0 /* dup */
37#define F_GETFD 1 /* get close_on_exec */
38#define F_SETFD 2 /* set/clear close_on_exec */
39#define F_GETFL 3 /* get file->f_flags */
40#define F_SETFL 4 /* set file->f_flags */
41#define F_GETLK 5
30#define F_SETLK 6 42#define F_SETLK 6
31#define F_SETLKW 7 43#define F_SETLKW 7
32#define F_SETLK64 16
33#define F_SETLKW64 17
34 44
35#define F_SETOWN 24 /* for sockets. */ 45#define F_SETOWN 8 /* for sockets. */
36#define F_GETOWN 23 /* for sockets. */ 46#define F_GETOWN 9 /* for sockets. */
47#define F_SETSIG 10 /* for sockets. */
48#define F_GETSIG 11 /* for sockets. */
49
50#define F_GETLK64 12 /* using 'struct flock64' */
51#define F_SETLK64 13
52#define F_SETLKW64 14
53
54/* for F_[GET|SET]FL */
55#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
56
57/* for posix fcntl() and lockf() */
58#define F_RDLCK 0
59#define F_WRLCK 1
60#define F_UNLCK 2
61
62/* for old implementation of bsd flock () */
63#define F_EXLCK 4 /* or 3 */
64#define F_SHLCK 8 /* or 4 */
37 65
38typedef struct flock { 66/* for leases */
67#define F_INPROGRESS 16
68
69/* operations for bsd flock(), also used by the kernel implementation */
70#define LOCK_SH 1 /* shared lock */
71#define LOCK_EX 2 /* exclusive lock */
72#define LOCK_NB 4 /* or'd with one of the above to prevent
73 blocking */
74#define LOCK_UN 8 /* remove lock */
75
76#define LOCK_MAND 32 /* This is a mandatory flock */
77#define LOCK_READ 64 /* ... Which allows concurrent read operations */
78#define LOCK_WRITE 128 /* ... Which allows concurrent write operations */
79#define LOCK_RW 192 /* ... Which allows concurrent read & write ops */
80
81struct flock {
39 short l_type; 82 short l_type;
40 short l_whence; 83 short l_whence;
41 __kernel_off_t l_start; 84 off_t l_start;
42 __kernel_off_t l_len; 85 off_t l_len;
43 long l_sysid; 86 pid_t l_pid;
44 __kernel_pid_t l_pid; 87};
45 long pad[4];
46} flock_t;
47 88
48struct flock64 { 89struct flock64 {
49 short l_type; 90 short l_type;
50 short l_whence; 91 short l_whence;
51 __kernel_off_t l_start; 92 loff_t l_start;
52 __kernel_off_t l_len; 93 loff_t l_len;
53 pid_t l_pid; 94 pid_t l_pid;
54}; 95};
55 96
56#define HAVE_ARCH_STRUCT_FLOCK 97#define F_LINUX_SPECIFIC_BASE 1024
57#define HAVE_ARCH_STRUCT_FLOCK64
58
59#include <asm-generic/fcntl.h>
60 98
61#endif /* _XTENSA_FCNTL_H */ 99#endif /* _XTENSA_FCNTL_H */
diff --git a/include/asm-xtensa/fixmap.h b/include/asm-xtensa/fixmap.h
deleted file mode 100644
index 4423b8ad4954..000000000000
--- a/include/asm-xtensa/fixmap.h
+++ /dev/null
@@ -1,252 +0,0 @@
1/*
2 * include/asm-xtensa/fixmap.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_FIXMAP_H
12#define _XTENSA_FIXMAP_H
13
14#include <asm/processor.h>
15
16#ifdef CONFIG_MMU
17
18/*
19 * Here we define all the compile-time virtual addresses.
20 */
21
22#if XCHAL_SEG_MAPPABLE_VADDR != 0
23# error "Current port requires virtual user space starting at 0"
24#endif
25#if XCHAL_SEG_MAPPABLE_SIZE < 0x80000000
26# error "Current port requires at least 0x8000000 bytes for user space"
27#endif
28
29/* Verify instruction/data ram/rom and xlmi don't overlay vmalloc space. */
30
31#define __IN_VMALLOC(addr) \
32 (((addr) >= VMALLOC_START) && ((addr) < VMALLOC_END))
33#define __SPAN_VMALLOC(start,end) \
34 (((start) < VMALLOC_START) && ((end) >= VMALLOC_END))
35#define INSIDE_VMALLOC(start,end) \
36 (__IN_VMALLOC((start)) || __IN_VMALLOC(end) || __SPAN_VMALLOC((start),(end)))
37
38#if XCHAL_NUM_INSTROM
39# if XCHAL_NUM_INSTROM == 1
40# if INSIDE_VMALLOC(XCHAL_INSTROM0_VADDR,XCHAL_INSTROM0_VADDR+XCHAL_INSTROM0_SIZE)
41# error vmalloc range conflicts with instrom0
42# endif
43# endif
44# if XCHAL_NUM_INSTROM == 2
45# if INSIDE_VMALLOC(XCHAL_INSTROM1_VADDR,XCHAL_INSTROM1_VADDR+XCHAL_INSTROM1_SIZE)
46# error vmalloc range conflicts with instrom1
47# endif
48# endif
49#endif
50
51#if XCHAL_NUM_INSTRAM
52# if XCHAL_NUM_INSTRAM == 1
53# if INSIDE_VMALLOC(XCHAL_INSTRAM0_VADDR,XCHAL_INSTRAM0_VADDR+XCHAL_INSTRAM0_SIZE)
54# error vmalloc range conflicts with instram0
55# endif
56# endif
57# if XCHAL_NUM_INSTRAM == 2
58# if INSIDE_VMALLOC(XCHAL_INSTRAM1_VADDR,XCHAL_INSTRAM1_VADDR+XCHAL_INSTRAM1_SIZE)
59# error vmalloc range conflicts with instram1
60# endif
61# endif
62#endif
63
64#if XCHAL_NUM_DATAROM
65# if XCHAL_NUM_DATAROM == 1
66# if INSIDE_VMALLOC(XCHAL_DATAROM0_VADDR,XCHAL_DATAROM0_VADDR+XCHAL_DATAROM0_SIZE)
67# error vmalloc range conflicts with datarom0
68# endif
69# endif
70# if XCHAL_NUM_DATAROM == 2
71# if INSIDE_VMALLOC(XCHAL_DATAROM1_VADDR,XCHAL_DATAROM1_VADDR+XCHAL_DATAROM1_SIZE)
72# error vmalloc range conflicts with datarom1
73# endif
74# endif
75#endif
76
77#if XCHAL_NUM_DATARAM
78# if XCHAL_NUM_DATARAM == 1
79# if INSIDE_VMALLOC(XCHAL_DATARAM0_VADDR,XCHAL_DATARAM0_VADDR+XCHAL_DATARAM0_SIZE)
80# error vmalloc range conflicts with dataram0
81# endif
82# endif
83# if XCHAL_NUM_DATARAM == 2
84# if INSIDE_VMALLOC(XCHAL_DATARAM1_VADDR,XCHAL_DATARAM1_VADDR+XCHAL_DATARAM1_SIZE)
85# error vmalloc range conflicts with dataram1
86# endif
87# endif
88#endif
89
90#if XCHAL_NUM_XLMI
91# if XCHAL_NUM_XLMI == 1
92# if INSIDE_VMALLOC(XCHAL_XLMI0_VADDR,XCHAL_XLMI0_VADDR+XCHAL_XLMI0_SIZE)
93# error vmalloc range conflicts with xlmi0
94# endif
95# endif
96# if XCHAL_NUM_XLMI == 2
97# if INSIDE_VMALLOC(XCHAL_XLMI1_VADDR,XCHAL_XLMI1_VADDR+XCHAL_XLMI1_SIZE)
98# error vmalloc range conflicts with xlmi1
99# endif
100# endif
101#endif
102
103#if (XCHAL_NUM_INSTROM > 2) || \
104 (XCHAL_NUM_INSTRAM > 2) || \
105 (XCHAL_NUM_DATARAM > 2) || \
106 (XCHAL_NUM_DATAROM > 2) || \
107 (XCHAL_NUM_XLMI > 2)
108# error Insufficient checks on vmalloc above for more than 2 devices
109#endif
110
111/*
112 * USER_VM_SIZE does not necessarily equal TASK_SIZE. We bumped
113 * TASK_SIZE down to 0x4000000 to simplify the handling of windowed
114 * call instructions (currently limited to a range of 1 GByte). User
115 * tasks may very well reclaim the VM space from 0x40000000 to
116 * 0x7fffffff in the future, so we do not want the kernel becoming
117 * accustomed to having any of its stuff (e.g., page tables) in this
118 * region. This VM region is no-man's land for now.
119 */
120
121#define USER_VM_START XCHAL_SEG_MAPPABLE_VADDR
122#define USER_VM_SIZE 0x80000000
123
124/* Size of page table: */
125
126#define PGTABLE_SIZE_BITS (32 - XCHAL_MMU_MIN_PTE_PAGE_SIZE + 2)
127#define PGTABLE_SIZE (1L << PGTABLE_SIZE_BITS)
128
129/* All kernel-mappable space: */
130
131#define KERNEL_ALLMAP_START (USER_VM_START + USER_VM_SIZE)
132#define KERNEL_ALLMAP_SIZE (XCHAL_SEG_MAPPABLE_SIZE - KERNEL_ALLMAP_START)
133
134/* Carve out page table at start of kernel-mappable area: */
135
136#if KERNEL_ALLMAP_SIZE < PGTABLE_SIZE
137#error "Gimme some space for page table!"
138#endif
139#define PGTABLE_START KERNEL_ALLMAP_START
140
141/* Remaining kernel-mappable space: */
142
143#define KERNEL_MAPPED_START (KERNEL_ALLMAP_START + PGTABLE_SIZE)
144#define KERNEL_MAPPED_SIZE (KERNEL_ALLMAP_SIZE - PGTABLE_SIZE)
145
146#if KERNEL_MAPPED_SIZE < 0x01000000 /* 16 MB is arbitrary for now */
147# error "Shouldn't the kernel have at least *some* mappable space?"
148#endif
149
150#define MAX_LOW_MEMORY XCHAL_KSEG_CACHED_SIZE
151
152#endif
153
154/*
155 * Some constants used elsewhere, but perhaps only in Xtensa header
156 * files, so maybe we can get rid of some and access compile-time HAL
157 * directly...
158 *
159 * Note: We assume that system RAM is located at the very start of the
160 * kernel segments !!
161 */
162#define KERNEL_VM_LOW XCHAL_KSEG_CACHED_VADDR
163#define KERNEL_VM_HIGH XCHAL_KSEG_BYPASS_VADDR
164#define KERNEL_SPACE XCHAL_KSEG_CACHED_VADDR
165
166/*
167 * Returns the physical/virtual addresses of the kernel space
168 * (works with the cached kernel segment only, which is the
169 * one normally used for kernel operation).
170 */
171
172/* PHYSICAL BYPASS CACHED
173 *
174 * bypass vaddr bypass paddr * cached vaddr
175 * cached vaddr cached paddr bypass vaddr *
176 * bypass paddr * bypass vaddr cached vaddr
177 * cached paddr * bypass vaddr cached vaddr
178 * other * * *
179 */
180
181#define PHYSADDR(a) \
182(((unsigned)(a) >= XCHAL_KSEG_BYPASS_VADDR \
183 && (unsigned)(a) < XCHAL_KSEG_BYPASS_VADDR + XCHAL_KSEG_BYPASS_SIZE) ? \
184 (unsigned)(a) - XCHAL_KSEG_BYPASS_VADDR + XCHAL_KSEG_BYPASS_PADDR : \
185 ((unsigned)(a) >= XCHAL_KSEG_CACHED_VADDR \
186 && (unsigned)(a) < XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_CACHED_SIZE) ? \
187 (unsigned)(a) - XCHAL_KSEG_CACHED_VADDR + XCHAL_KSEG_CACHED_PADDR : \
188 (unsigned)(a))
189
190#define BYPASS_ADDR(a) \
191(((unsigned)(a) >= XCHAL_KSEG_BYPASS_PADDR \
192 && (unsigned)(a) < XCHAL_KSEG_BYPASS_PADDR + XCHAL_KSEG_BYPASS_SIZE) ? \
193 (unsigned)(a) - XCHAL_KSEG_BYPASS_PADDR + XCHAL_KSEG_BYPASS_VADDR : \
194 ((unsigned)(a) >= XCHAL_KSEG_CACHED_PADDR \
195 && (unsigned)(a) < XCHAL_KSEG_CACHED_PADDR + XCHAL_KSEG_CACHED_SIZE) ? \
196 (unsigned)(a) - XCHAL_KSEG_CACHED_PADDR + XCHAL_KSEG_BYPASS_VADDR : \
197 ((unsigned)(a) >= XCHAL_KSEG_CACHED_VADDR \
198 && (unsigned)(a) < XCHAL_KSEG_CACHED_VADDR+XCHAL_KSEG_CACHED_SIZE)? \
199 (unsigned)(a) - XCHAL_KSEG_CACHED_VADDR+XCHAL_KSEG_BYPASS_VADDR: \
200 (unsigned)(a))
201
202#define CACHED_ADDR(a) \
203(((unsigned)(a) >= XCHAL_KSEG_BYPASS_PADDR \
204 && (unsigned)(a) < XCHAL_KSEG_BYPASS_PADDR + XCHAL_KSEG_BYPASS_SIZE) ? \
205 (unsigned)(a) - XCHAL_KSEG_BYPASS_PADDR + XCHAL_KSEG_CACHED_VADDR : \
206 ((unsigned)(a) >= XCHAL_KSEG_CACHED_PADDR \
207 && (unsigned)(a) < XCHAL_KSEG_CACHED_PADDR + XCHAL_KSEG_CACHED_SIZE) ? \
208 (unsigned)(a) - XCHAL_KSEG_CACHED_PADDR + XCHAL_KSEG_CACHED_VADDR : \
209 ((unsigned)(a) >= XCHAL_KSEG_BYPASS_VADDR \
210 && (unsigned)(a) < XCHAL_KSEG_BYPASS_VADDR+XCHAL_KSEG_BYPASS_SIZE) ? \
211 (unsigned)(a) - XCHAL_KSEG_BYPASS_VADDR+XCHAL_KSEG_CACHED_VADDR : \
212 (unsigned)(a))
213
214#define PHYSADDR_IO(a) \
215(((unsigned)(a) >= XCHAL_KIO_BYPASS_VADDR \
216 && (unsigned)(a) < XCHAL_KIO_BYPASS_VADDR + XCHAL_KIO_BYPASS_SIZE) ? \
217 (unsigned)(a) - XCHAL_KIO_BYPASS_VADDR + XCHAL_KIO_BYPASS_PADDR : \
218 ((unsigned)(a) >= XCHAL_KIO_CACHED_VADDR \
219 && (unsigned)(a) < XCHAL_KIO_CACHED_VADDR + XCHAL_KIO_CACHED_SIZE) ? \
220 (unsigned)(a) - XCHAL_KIO_CACHED_VADDR + XCHAL_KIO_CACHED_PADDR : \
221 (unsigned)(a))
222
223#define BYPASS_ADDR_IO(a) \
224(((unsigned)(a) >= XCHAL_KIO_BYPASS_PADDR \
225 && (unsigned)(a) < XCHAL_KIO_BYPASS_PADDR + XCHAL_KIO_BYPASS_SIZE) ? \
226 (unsigned)(a) - XCHAL_KIO_BYPASS_PADDR + XCHAL_KIO_BYPASS_VADDR : \
227 ((unsigned)(a) >= XCHAL_KIO_CACHED_PADDR \
228 && (unsigned)(a) < XCHAL_KIO_CACHED_PADDR + XCHAL_KIO_CACHED_SIZE) ? \
229 (unsigned)(a) - XCHAL_KIO_CACHED_PADDR + XCHAL_KIO_BYPASS_VADDR : \
230 ((unsigned)(a) >= XCHAL_KIO_CACHED_VADDR \
231 && (unsigned)(a) < XCHAL_KIO_CACHED_VADDR + XCHAL_KIO_CACHED_SIZE) ? \
232 (unsigned)(a) - XCHAL_KIO_CACHED_VADDR + XCHAL_KIO_BYPASS_VADDR : \
233 (unsigned)(a))
234
235#define CACHED_ADDR_IO(a) \
236(((unsigned)(a) >= XCHAL_KIO_BYPASS_PADDR \
237 && (unsigned)(a) < XCHAL_KIO_BYPASS_PADDR + XCHAL_KIO_BYPASS_SIZE) ? \
238 (unsigned)(a) - XCHAL_KIO_BYPASS_PADDR + XCHAL_KIO_CACHED_VADDR : \
239 ((unsigned)(a) >= XCHAL_KIO_CACHED_PADDR \
240 && (unsigned)(a) < XCHAL_KIO_CACHED_PADDR + XCHAL_KIO_CACHED_SIZE) ? \
241 (unsigned)(a) - XCHAL_KIO_CACHED_PADDR + XCHAL_KIO_CACHED_VADDR : \
242 ((unsigned)(a) >= XCHAL_KIO_BYPASS_VADDR \
243 && (unsigned)(a) < XCHAL_KIO_BYPASS_VADDR + XCHAL_KIO_BYPASS_SIZE) ? \
244 (unsigned)(a) - XCHAL_KIO_BYPASS_VADDR + XCHAL_KIO_CACHED_VADDR : \
245 (unsigned)(a))
246
247#endif /* _XTENSA_ADDRSPACE_H */
248
249
250
251
252
diff --git a/include/asm-xtensa/io.h b/include/asm-xtensa/io.h
index 556e5eed34f5..31ffc3f119c1 100644
--- a/include/asm-xtensa/io.h
+++ b/include/asm-xtensa/io.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/include/asm-xtensa/io.h 2 * include/asm-xtensa/io.h
3 * 3 *
4 * This file is subject to the terms and conditions of the GNU General Public 4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive 5 * License. See the file "COPYING" in the main directory of this archive
@@ -15,10 +15,11 @@
15#include <asm/byteorder.h> 15#include <asm/byteorder.h>
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <asm/fixmap.h>
19
20#define _IO_BASE 0
21 18
19#define XCHAL_KIO_CACHED_VADDR 0xf0000000
20#define XCHAL_KIO_BYPASS_VADDR 0xf8000000
21#define XCHAL_KIO_PADDR 0xf0000000
22#define XCHAL_KIO_SIZE 0x08000000
22 23
23/* 24/*
24 * swap functions to change byte order from little-endian to big-endian and 25 * swap functions to change byte order from little-endian to big-endian and
@@ -42,40 +43,43 @@ static inline unsigned int _swapl (unsigned int v)
42 43
43static inline unsigned long virt_to_phys(volatile void * address) 44static inline unsigned long virt_to_phys(volatile void * address)
44{ 45{
45 return PHYSADDR((unsigned long)address); 46 return __pa(address);
46} 47}
47 48
48static inline void * phys_to_virt(unsigned long address) 49static inline void * phys_to_virt(unsigned long address)
49{ 50{
50 return (void*) CACHED_ADDR(address); 51 return __va(address);
51} 52}
52 53
53/* 54/*
54 * IO bus memory addresses are also 1:1 with the physical address 55 * virt_to_bus and bus_to_virt are deprecated.
55 */ 56 */
56 57
57static inline unsigned long virt_to_bus(volatile void * address) 58#define virt_to_bus(x) virt_to_phys(x)
58{ 59#define bus_to_virt(x) phys_to_virt(x)
59 return PHYSADDR((unsigned long)address);
60}
61
62static inline void * bus_to_virt (unsigned long address)
63{
64 return (void *) CACHED_ADDR(address);
65}
66 60
67/* 61/*
68 * Change "struct page" to physical address. 62 * Return the virtual (cached) address for the specified bus memory.
63 * Note that we currently don't support any address outside the KIO segment.
69 */ 64 */
70 65
71static inline void *ioremap(unsigned long offset, unsigned long size) 66static inline void *ioremap(unsigned long offset, unsigned long size)
72{ 67{
73 return (void *) CACHED_ADDR_IO(offset); 68 if (offset >= XCHAL_KIO_PADDR
69 && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
70 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR);
71
72 else
73 BUG();
74} 74}
75 75
76static inline void *ioremap_nocache(unsigned long offset, unsigned long size) 76static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
77{ 77{
78 return (void *) BYPASS_ADDR_IO(offset); 78 if (offset >= XCHAL_KIO_PADDR
79 && offset < XCHAL_KIO_PADDR + XCHAL_KIO_SIZE)
80 return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR);
81 else
82 BUG();
79} 83}
80 84
81static inline void iounmap(void *addr) 85static inline void iounmap(void *addr)
@@ -121,9 +125,6 @@ static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
121 *(__force volatile __u32 *)(addr) = b; 125 *(__force volatile __u32 *)(addr) = b;
122} 126}
123 127
124
125
126
127/* These are the definitions for the x86 IO instructions 128/* These are the definitions for the x86 IO instructions
128 * inb/inw/inl/outb/outw/outl, the "string" versions 129 * inb/inw/inl/outb/outw/outl, the "string" versions
129 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions 130 * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
@@ -131,11 +132,11 @@ static inline void __raw_writel(__u32 b, volatile void __iomem *addr)
131 * The macros don't do byte-swapping. 132 * The macros don't do byte-swapping.
132 */ 133 */
133 134
134#define inb(port) readb((u8 *)((port)+_IO_BASE)) 135#define inb(port) readb((u8 *)((port)))
135#define outb(val, port) writeb((val),(u8 *)((unsigned long)(port)+_IO_BASE)) 136#define outb(val, port) writeb((val),(u8 *)((unsigned long)(port)))
136#define inw(port) readw((u16 *)((port)+_IO_BASE)) 137#define inw(port) readw((u16 *)((port)))
137#define outw(val, port) writew((val),(u16 *)((unsigned long)(port)+_IO_BASE)) 138#define outw(val, port) writew((val),(u16 *)((unsigned long)(port)))
138#define inl(port) readl((u32 *)((port)+_IO_BASE)) 139#define inl(port) readl((u32 *)((port)))
139#define outl(val, port) writel((val),(u32 *)((unsigned long)(port))) 140#define outl(val, port) writel((val),(u32 *)((unsigned long)(port)))
140 141
141#define inb_p(port) inb((port)) 142#define inb_p(port) inb((port))
@@ -180,14 +181,13 @@ extern void outsl (unsigned long port, const void *src, unsigned long count);
180 181
181 182
182/* 183/*
183 * * Convert a physical pointer to a virtual kernel pointer for /dev/mem 184 * Convert a physical pointer to a virtual kernel pointer for /dev/mem access
184 * * access 185 */
185 * */
186#define xlate_dev_mem_ptr(p) __va(p) 186#define xlate_dev_mem_ptr(p) __va(p)
187 187
188/* 188/*
189 * * Convert a virtual cached pointer to an uncached pointer 189 * Convert a virtual cached pointer to an uncached pointer
190 * */ 190 */
191#define xlate_dev_kmem_ptr(p) p 191#define xlate_dev_kmem_ptr(p) p
192 192
193 193
diff --git a/include/asm-xtensa/irq.h b/include/asm-xtensa/irq.h
index 049fde7e752d..fc73b7f11aff 100644
--- a/include/asm-xtensa/irq.h
+++ b/include/asm-xtensa/irq.h
@@ -12,8 +12,7 @@
12#define _XTENSA_IRQ_H 12#define _XTENSA_IRQ_H
13 13
14#include <asm/platform/hardware.h> 14#include <asm/platform/hardware.h>
15 15#include <asm/variant/core.h>
16#include <xtensa/config/core.h>
17 16
18#ifndef PLATFORM_NR_IRQS 17#ifndef PLATFORM_NR_IRQS
19# define PLATFORM_NR_IRQS 0 18# define PLATFORM_NR_IRQS 0
@@ -27,10 +26,5 @@ static __inline__ int irq_canonicalize(int irq)
27} 26}
28 27
29struct irqaction; 28struct irqaction;
30#if 0 // FIXME
31extern void disable_irq_nosync(unsigned int);
32extern void disable_irq(unsigned int);
33extern void enable_irq(unsigned int);
34#endif
35 29
36#endif /* _XTENSA_IRQ_H */ 30#endif /* _XTENSA_IRQ_H */
diff --git a/include/asm-xtensa/irq_regs.h b/include/asm-xtensa/irq_regs.h
new file mode 100644
index 000000000000..3dd9c0b70270
--- /dev/null
+++ b/include/asm-xtensa/irq_regs.h
@@ -0,0 +1 @@
#include <asm-generic/irq_regs.h>
diff --git a/include/asm-xtensa/mmu_context.h b/include/asm-xtensa/mmu_context.h
index af683a74a4ec..f14851f086c3 100644
--- a/include/asm-xtensa/mmu_context.h
+++ b/include/asm-xtensa/mmu_context.h
@@ -16,187 +16,32 @@
16#include <linux/stringify.h> 16#include <linux/stringify.h>
17 17
18#include <asm/pgtable.h> 18#include <asm/pgtable.h>
19#include <asm/mmu_context.h>
20#include <asm/cacheflush.h> 19#include <asm/cacheflush.h>
21#include <asm/tlbflush.h> 20#include <asm/tlbflush.h>
22 21
23/* 22#define XCHAL_MMU_ASID_BITS 8
24 * Linux was ported to Xtensa assuming all auto-refill ways in set 0
25 * had the same properties (a very likely assumption). Multiple sets
26 * of auto-refill ways will still work properly, but not as optimally
27 * as the Xtensa designer may have assumed.
28 *
29 * We make this case a hard #error, killing the kernel build, to alert
30 * the developer to this condition (which is more likely an error).
31 * You super-duper clever developers can change it to a warning or
32 * remove it altogether if you think you know what you're doing. :)
33 */
34 23
35#if (XCHAL_HAVE_TLBS != 1) 24#if (XCHAL_HAVE_TLBS != 1)
36# error "Linux must have an MMU!" 25# error "Linux must have an MMU!"
37#endif 26#endif
38 27
39#if ((XCHAL_ITLB_ARF_WAYS == 0) || (XCHAL_DTLB_ARF_WAYS == 0))
40# error "MMU must have auto-refill ways"
41#endif
42
43#if ((XCHAL_ITLB_ARF_SETS != 1) || (XCHAL_DTLB_ARF_SETS != 1))
44# error Linux may not use all auto-refill ways as efficiently as you think
45#endif
46
47#if (XCHAL_MMU_MAX_PTE_PAGE_SIZE != XCHAL_MMU_MIN_PTE_PAGE_SIZE)
48# error Only one page size allowed!
49#endif
50
51extern unsigned long asid_cache; 28extern unsigned long asid_cache;
52extern pgd_t *current_pgd;
53
54/*
55 * Define the number of entries per auto-refill way in set 0 of both I and D
56 * TLBs. We deal only with set 0 here (an assumption further explained in
57 * assertions.h). Also, define the total number of ARF entries in both TLBs.
58 */
59
60#define ITLB_ENTRIES_PER_ARF_WAY (XCHAL_ITLB_SET(XCHAL_ITLB_ARF_SET0,ENTRIES))
61#define DTLB_ENTRIES_PER_ARF_WAY (XCHAL_DTLB_SET(XCHAL_DTLB_ARF_SET0,ENTRIES))
62
63#define ITLB_ENTRIES \
64 (ITLB_ENTRIES_PER_ARF_WAY * (XCHAL_ITLB_SET(XCHAL_ITLB_ARF_SET0,WAYS)))
65#define DTLB_ENTRIES \
66 (DTLB_ENTRIES_PER_ARF_WAY * (XCHAL_DTLB_SET(XCHAL_DTLB_ARF_SET0,WAYS)))
67
68
69/*
70 * SMALLEST_NTLB_ENTRIES is the smaller of ITLB_ENTRIES and DTLB_ENTRIES.
71 * In practice, they are probably equal. This macro simplifies function
72 * flush_tlb_range().
73 */
74
75#if (DTLB_ENTRIES < ITLB_ENTRIES)
76# define SMALLEST_NTLB_ENTRIES DTLB_ENTRIES
77#else
78# define SMALLEST_NTLB_ENTRIES ITLB_ENTRIES
79#endif
80
81
82/*
83 * asid_cache tracks only the ASID[USER_RING] field of the RASID special
84 * register, which is the current user-task asid allocation value.
85 * mm->context has the same meaning. When it comes time to write the
86 * asid_cache or mm->context values to the RASID special register, we first
87 * shift the value left by 8, then insert the value.
88 * ASID[0] always contains the kernel's asid value, and we reserve three
89 * other asid values that we never assign to user tasks.
90 */
91
92#define ASID_INC 0x1
93#define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
94
95/*
96 * XCHAL_MMU_ASID_INVALID is a configurable Xtensa processor constant
97 * indicating invalid address space. XCHAL_MMU_ASID_KERNEL is a configurable
98 * Xtensa processor constant indicating the kernel address space. They can
99 * be arbitrary values.
100 *
101 * We identify three more unique, reserved ASID values to use in the unused
102 * ring positions. No other user process will be assigned these reserved
103 * ASID values.
104 *
105 * For example, given that
106 *
107 * XCHAL_MMU_ASID_INVALID == 0
108 * XCHAL_MMU_ASID_KERNEL == 1
109 *
110 * the following maze of #if statements would generate
111 *
112 * ASID_RESERVED_1 == 2
113 * ASID_RESERVED_2 == 3
114 * ASID_RESERVED_3 == 4
115 * ASID_FIRST_NONRESERVED == 5
116 */
117
118#if (XCHAL_MMU_ASID_INVALID != XCHAL_MMU_ASID_KERNEL + 1)
119# define ASID_RESERVED_1 ((XCHAL_MMU_ASID_KERNEL + 1) & ASID_MASK)
120#else
121# define ASID_RESERVED_1 ((XCHAL_MMU_ASID_KERNEL + 2) & ASID_MASK)
122#endif
123
124#if (XCHAL_MMU_ASID_INVALID != ASID_RESERVED_1 + 1)
125# define ASID_RESERVED_2 ((ASID_RESERVED_1 + 1) & ASID_MASK)
126#else
127# define ASID_RESERVED_2 ((ASID_RESERVED_1 + 2) & ASID_MASK)
128#endif
129
130#if (XCHAL_MMU_ASID_INVALID != ASID_RESERVED_2 + 1)
131# define ASID_RESERVED_3 ((ASID_RESERVED_2 + 1) & ASID_MASK)
132#else
133# define ASID_RESERVED_3 ((ASID_RESERVED_2 + 2) & ASID_MASK)
134#endif
135
136#if (XCHAL_MMU_ASID_INVALID != ASID_RESERVED_3 + 1)
137# define ASID_FIRST_NONRESERVED ((ASID_RESERVED_3 + 1) & ASID_MASK)
138#else
139# define ASID_FIRST_NONRESERVED ((ASID_RESERVED_3 + 2) & ASID_MASK)
140#endif
141
142#define ASID_ALL_RESERVED ( ((ASID_RESERVED_1) << 24) + \
143 ((ASID_RESERVED_2) << 16) + \
144 ((ASID_RESERVED_3) << 8) + \
145 ((XCHAL_MMU_ASID_KERNEL)) )
146
147 29
148/* 30/*
149 * NO_CONTEXT is the invalid ASID value that we don't ever assign to 31 * NO_CONTEXT is the invalid ASID value that we don't ever assign to
150 * any user or kernel context. NO_CONTEXT is a better mnemonic than 32 * any user or kernel context.
151 * XCHAL_MMU_ASID_INVALID, so we use it in code instead. 33 *
152 */ 34 * 0 invalid
153 35 * 1 kernel
154#define NO_CONTEXT XCHAL_MMU_ASID_INVALID 36 * 2 reserved
155 37 * 3 reserved
156#if (KERNEL_RING != 0) 38 * 4...255 available
157# error The KERNEL_RING really should be zero.
158#endif
159
160#if (USER_RING >= XCHAL_MMU_RINGS)
161# error USER_RING cannot be greater than the highest numbered ring.
162#endif
163
164#if (USER_RING == KERNEL_RING)
165# error The user and kernel rings really should not be equal.
166#endif
167
168#if (USER_RING == 1)
169#define ASID_INSERT(x) ( ((ASID_RESERVED_1) << 24) + \
170 ((ASID_RESERVED_2) << 16) + \
171 (((x) & (ASID_MASK)) << 8) + \
172 ((XCHAL_MMU_ASID_KERNEL)) )
173
174#elif (USER_RING == 2)
175#define ASID_INSERT(x) ( ((ASID_RESERVED_1) << 24) + \
176 (((x) & (ASID_MASK)) << 16) + \
177 ((ASID_RESERVED_2) << 8) + \
178 ((XCHAL_MMU_ASID_KERNEL)) )
179
180#elif (USER_RING == 3)
181#define ASID_INSERT(x) ( (((x) & (ASID_MASK)) << 24) + \
182 ((ASID_RESERVED_1) << 16) + \
183 ((ASID_RESERVED_2) << 8) + \
184 ((XCHAL_MMU_ASID_KERNEL)) )
185
186#else
187#error Goofy value for USER_RING
188
189#endif /* USER_RING == 1 */
190
191
192/*
193 * All unused by hardware upper bits will be considered
194 * as a software asid extension.
195 */ 39 */
196 40
197#define ASID_VERSION_MASK ((unsigned long)~(ASID_MASK|(ASID_MASK-1))) 41#define NO_CONTEXT 0
198#define ASID_FIRST_VERSION \ 42#define ASID_USER_FIRST 4
199 ((unsigned long)(~ASID_VERSION_MASK) + 1 + ASID_FIRST_NONRESERVED) 43#define ASID_MASK ((1 << XCHAL_MMU_ASID_BITS) - 1)
44#define ASID_INSERT(x) (0x03020001 | (((x) & ASID_MASK) << 8))
200 45
201static inline void set_rasid_register (unsigned long val) 46static inline void set_rasid_register (unsigned long val)
202{ 47{
@@ -207,67 +52,28 @@ static inline void set_rasid_register (unsigned long val)
207static inline unsigned long get_rasid_register (void) 52static inline unsigned long get_rasid_register (void)
208{ 53{
209 unsigned long tmp; 54 unsigned long tmp;
210 __asm__ __volatile__ (" rsr %0, "__stringify(RASID)"\n\t" : "=a" (tmp)); 55 __asm__ __volatile__ (" rsr %0,"__stringify(RASID)"\n\t" : "=a" (tmp));
211 return tmp; 56 return tmp;
212} 57}
213 58
214
215#if ((XCHAL_MMU_ASID_INVALID == 0) && (XCHAL_MMU_ASID_KERNEL == 1))
216
217static inline void 59static inline void
218get_new_mmu_context(struct mm_struct *mm, unsigned long asid) 60__get_new_mmu_context(struct mm_struct *mm)
219{ 61{
220 extern void flush_tlb_all(void); 62 extern void flush_tlb_all(void);
221 if (! ((asid += ASID_INC) & ASID_MASK) ) { 63 if (! (++asid_cache & ASID_MASK) ) {
222 flush_tlb_all(); /* start new asid cycle */ 64 flush_tlb_all(); /* start new asid cycle */
223 if (!asid) /* fix version if needed */ 65 asid_cache += ASID_USER_FIRST;
224 asid = ASID_FIRST_VERSION - ASID_FIRST_NONRESERVED;
225 asid += ASID_FIRST_NONRESERVED;
226 } 66 }
227 mm->context = asid_cache = asid; 67 mm->context = asid_cache;
228}
229
230#else
231#warning ASID_{INVALID,KERNEL} values impose non-optimal get_new_mmu_context implementation
232
233/* XCHAL_MMU_ASID_INVALID == 0 and XCHAL_MMU_ASID_KERNEL ==1 are
234 really the best, but if you insist... */
235
236static inline int validate_asid (unsigned long asid)
237{
238 switch (asid) {
239 case XCHAL_MMU_ASID_INVALID:
240 case XCHAL_MMU_ASID_KERNEL:
241 case ASID_RESERVED_1:
242 case ASID_RESERVED_2:
243 case ASID_RESERVED_3:
244 return 0; /* can't use these values as ASIDs */
245 }
246 return 1; /* valid */
247} 68}
248 69
249static inline void 70static inline void
250get_new_mmu_context(struct mm_struct *mm, unsigned long asid) 71__load_mmu_context(struct mm_struct *mm)
251{ 72{
252 extern void flush_tlb_all(void); 73 set_rasid_register(ASID_INSERT(mm->context));
253 while (1) { 74 invalidate_page_directory();
254 asid += ASID_INC;
255 if ( ! (asid & ASID_MASK) ) {
256 flush_tlb_all(); /* start new asid cycle */
257 if (!asid) /* fix version if needed */
258 asid = ASID_FIRST_VERSION - ASID_FIRST_NONRESERVED;
259 asid += ASID_FIRST_NONRESERVED;
260 break; /* no need to validate here */
261 }
262 if (validate_asid (asid & ASID_MASK))
263 break;
264 }
265 mm->context = asid_cache = asid;
266} 75}
267 76
268#endif
269
270
271/* 77/*
272 * Initialize the context related info for a new mm_struct 78 * Initialize the context related info for a new mm_struct
273 * instance. 79 * instance.
@@ -280,6 +86,20 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
280 return 0; 86 return 0;
281} 87}
282 88
89/*
90 * After we have set current->mm to a new value, this activates
91 * the context for the new mm so we see the new mappings.
92 */
93static inline void
94activate_mm(struct mm_struct *prev, struct mm_struct *next)
95{
96 /* Unconditionally get a new ASID. */
97
98 __get_new_mmu_context(next);
99 __load_mmu_context(next);
100}
101
102
283static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, 103static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
284 struct task_struct *tsk) 104 struct task_struct *tsk)
285{ 105{
@@ -287,11 +107,10 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
287 107
288 /* Check if our ASID is of an older version and thus invalid */ 108 /* Check if our ASID is of an older version and thus invalid */
289 109
290 if ((next->context ^ asid) & ASID_VERSION_MASK) 110 if (next->context == NO_CONTEXT || ((next->context^asid) & ~ASID_MASK))
291 get_new_mmu_context(next, asid); 111 __get_new_mmu_context(next);
292 112
293 set_rasid_register (ASID_INSERT(next->context)); 113 __load_mmu_context(next);
294 invalidate_page_directory();
295} 114}
296 115
297#define deactivate_mm(tsk, mm) do { } while(0) 116#define deactivate_mm(tsk, mm) do { } while(0)
@@ -302,20 +121,6 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
302 */ 121 */
303static inline void destroy_context(struct mm_struct *mm) 122static inline void destroy_context(struct mm_struct *mm)
304{ 123{
305 /* Nothing to do. */
306}
307
308/*
309 * After we have set current->mm to a new value, this activates
310 * the context for the new mm so we see the new mappings.
311 */
312static inline void
313activate_mm(struct mm_struct *prev, struct mm_struct *next)
314{
315 /* Unconditionally get a new ASID. */
316
317 get_new_mmu_context(next, asid_cache);
318 set_rasid_register (ASID_INSERT(next->context));
319 invalidate_page_directory(); 124 invalidate_page_directory();
320} 125}
321 126
diff --git a/include/asm-xtensa/page.h b/include/asm-xtensa/page.h
index 40f4c6c3f580..c631d006194b 100644
--- a/include/asm-xtensa/page.h
+++ b/include/asm-xtensa/page.h
@@ -15,18 +15,24 @@
15 15
16#include <asm/processor.h> 16#include <asm/processor.h>
17 17
18#define XCHAL_KSEG_CACHED_VADDR 0xd0000000
19#define XCHAL_KSEG_BYPASS_VADDR 0xd8000000
20#define XCHAL_KSEG_PADDR 0x00000000
21#define XCHAL_KSEG_SIZE 0x08000000
22
18/* 23/*
19 * PAGE_SHIFT determines the page size 24 * PAGE_SHIFT determines the page size
20 * PAGE_ALIGN(x) aligns the pointer to the (next) page boundary 25 * PAGE_ALIGN(x) aligns the pointer to the (next) page boundary
21 */ 26 */
22 27
23#define PAGE_SHIFT XCHAL_MMU_MIN_PTE_PAGE_SIZE 28#define PAGE_SHIFT 12
24#define PAGE_SIZE (1 << PAGE_SHIFT) 29#define PAGE_SIZE (1 << PAGE_SHIFT)
25#define PAGE_MASK (~(PAGE_SIZE-1)) 30#define PAGE_MASK (~(PAGE_SIZE-1))
26#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE - 1) & PAGE_MASK) 31#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE - 1) & PAGE_MASK)
27 32
28#define DCACHE_WAY_SIZE (XCHAL_DCACHE_SIZE / XCHAL_DCACHE_WAYS)
29#define PAGE_OFFSET XCHAL_KSEG_CACHED_VADDR 33#define PAGE_OFFSET XCHAL_KSEG_CACHED_VADDR
34#define MAX_MEM_PFN XCHAL_KSEG_SIZE
35#define PGTABLE_START 0x80000000
30 36
31#ifdef __ASSEMBLY__ 37#ifdef __ASSEMBLY__
32 38
diff --git a/include/asm-xtensa/param.h b/include/asm-xtensa/param.h
index c0eec8260b0e..6f281392e3f8 100644
--- a/include/asm-xtensa/param.h
+++ b/include/asm-xtensa/param.h
@@ -11,7 +11,7 @@
11#ifndef _XTENSA_PARAM_H 11#ifndef _XTENSA_PARAM_H
12#define _XTENSA_PARAM_H 12#define _XTENSA_PARAM_H
13 13
14#include <xtensa/config/core.h> 14#include <asm/variant/core.h>
15 15
16#ifdef __KERNEL__ 16#ifdef __KERNEL__
17# define HZ 100 /* internal timer frequency */ 17# define HZ 100 /* internal timer frequency */
diff --git a/include/asm-xtensa/pgtable.h b/include/asm-xtensa/pgtable.h
index b4318934b10d..2d4b5db6ea63 100644
--- a/include/asm-xtensa/pgtable.h
+++ b/include/asm-xtensa/pgtable.h
@@ -14,45 +14,6 @@
14#include <asm-generic/pgtable-nopmd.h> 14#include <asm-generic/pgtable-nopmd.h>
15#include <asm/page.h> 15#include <asm/page.h>
16 16
17/* Assertions. */
18
19#ifdef CONFIG_MMU
20
21
22#if (XCHAL_MMU_RINGS < 2)
23# error Linux build assumes at least 2 ring levels.
24#endif
25
26#if (XCHAL_MMU_CA_BITS != 4)
27# error We assume exactly four bits for CA.
28#endif
29
30#if (XCHAL_MMU_SR_BITS != 0)
31# error We have no room for SR bits.
32#endif
33
34/*
35 * Use the first min-wired way for mapping page-table pages.
36 * Page coloring requires a second min-wired way.
37 */
38
39#if (XCHAL_DTLB_MINWIRED_SETS == 0)
40# error Need a min-wired way for mapping page-table pages
41#endif
42
43#define DTLB_WAY_PGTABLE XCHAL_DTLB_SET(XCHAL_DTLB_MINWIRED_SET0, WAY)
44
45#if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
46# if XCHAL_DTLB_SET(XCHAL_DTLB_MINWIRED_SET0, WAYS) >= 2
47# define DTLB_WAY_DCACHE_ALIAS0 (DTLB_WAY_PGTABLE + 1)
48# define DTLB_WAY_DCACHE_ALIAS1 (DTLB_WAY_PGTABLE + 2)
49# else
50# error Page coloring requires its own wired dtlb way!
51# endif
52#endif
53
54#endif /* CONFIG_MMU */
55
56/* 17/*
57 * We only use two ring levels, user and kernel space. 18 * We only use two ring levels, user and kernel space.
58 */ 19 */
@@ -97,7 +58,7 @@
97#define PGD_ORDER 0 58#define PGD_ORDER 0
98#define PMD_ORDER 0 59#define PMD_ORDER 0
99#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) 60#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
100#define FIRST_USER_ADDRESS XCHAL_SEG_MAPPABLE_VADDR 61#define FIRST_USER_ADDRESS 0
101#define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT) 62#define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT)
102 63
103/* virtual memory area. We keep a distance to other memory regions to be 64/* virtual memory area. We keep a distance to other memory regions to be
diff --git a/include/asm-xtensa/platform-iss/hardware.h b/include/asm-xtensa/platform-iss/hardware.h
index 22240f001803..6930c12adc16 100644
--- a/include/asm-xtensa/platform-iss/hardware.h
+++ b/include/asm-xtensa/platform-iss/hardware.h
@@ -12,18 +12,18 @@
12 * This file contains the default configuration of ISS. 12 * This file contains the default configuration of ISS.
13 */ 13 */
14 14
15#ifndef __ASM_XTENSA_ISS_HARDWARE 15#ifndef _XTENSA_PLATFORM_ISS_HARDWARE_H
16#define __ASM_XTENSA_ISS_HARDWARE 16#define _XTENSA_PLATFORM_ISS_HARDWARE_H
17 17
18/* 18/*
19 * Memory configuration. 19 * Memory configuration.
20 */ 20 */
21 21
22#define PLATFORM_DEFAULT_MEM_START XSHAL_RAM_PADDR 22#define PLATFORM_DEFAULT_MEM_START 0x00000000
23#define PLATFORM_DEFAULT_MEM_SIZE XSHAL_RAM_VSIZE 23#define PLATFORM_DEFAULT_MEM_SIZE 0x08000000
24 24
25/* 25/*
26 * Interrupt configuration. 26 * Interrupt configuration.
27 */ 27 */
28 28
29#endif /* __ASM_XTENSA_ISS_HARDWARE */ 29#endif /* _XTENSA_PLATFORM_ISS_HARDWARE_H */
diff --git a/include/asm-xtensa/platform-iss/simcall.h b/include/asm-xtensa/platform-iss/simcall.h
new file mode 100644
index 000000000000..6acb572759a6
--- /dev/null
+++ b/include/asm-xtensa/platform-iss/simcall.h
@@ -0,0 +1,62 @@
1/*
2 * include/asm-xtensa/platform-iss/hardware.h
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2001 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_PLATFORM_ISS_SIMCALL_H
12#define _XTENSA_PLATFORM_ISS_SIMCALL_H
13
14
15/*
16 * System call like services offered by the simulator host.
17 */
18
19#define SYS_nop 0 /* unused */
20#define SYS_exit 1 /*x*/
21#define SYS_fork 2
22#define SYS_read 3 /*x*/
23#define SYS_write 4 /*x*/
24#define SYS_open 5 /*x*/
25#define SYS_close 6 /*x*/
26#define SYS_rename 7 /*x 38 - waitpid */
27#define SYS_creat 8 /*x*/
28#define SYS_link 9 /*x (not implemented on WIN32) */
29#define SYS_unlink 10 /*x*/
30#define SYS_execv 11 /* n/a - execve */
31#define SYS_execve 12 /* 11 - chdir */
32#define SYS_pipe 13 /* 42 - time */
33#define SYS_stat 14 /* 106 - mknod */
34#define SYS_chmod 15
35#define SYS_chown 16 /* 202 - lchown */
36#define SYS_utime 17 /* 30 - break */
37#define SYS_wait 18 /* n/a - oldstat */
38#define SYS_lseek 19 /*x*/
39#define SYS_getpid 20
40#define SYS_isatty 21 /* n/a - mount */
41#define SYS_fstat 22 /* 108 - oldumount */
42#define SYS_time 23 /* 13 - setuid */
43#define SYS_gettimeofday 24 /*x 78 - getuid (not implemented on WIN32) */
44#define SYS_times 25 /*X 43 - stime (Xtensa-specific implementation) */
45#define SYS_socket 26
46#define SYS_sendto 27
47#define SYS_recvfrom 28
48#define SYS_select_one 29 /* not compitible select, one file descriptor at the time */
49#define SYS_bind 30
50#define SYS_ioctl 31
51
52/*
53 * SYS_select_one specifiers
54 */
55
56#define XTISS_SELECT_ONE_READ 1
57#define XTISS_SELECT_ONE_WRITE 2
58#define XTISS_SELECT_ONE_EXCEPT 3
59
60
61#endif /* _XTENSA_PLATFORM_ISS_SIMCALL_H */
62
diff --git a/include/asm-xtensa/posix_types.h b/include/asm-xtensa/posix_types.h
index 2c816b0e7762..3470b44c12ce 100644
--- a/include/asm-xtensa/posix_types.h
+++ b/include/asm-xtensa/posix_types.h
@@ -21,7 +21,7 @@
21 21
22typedef unsigned long __kernel_ino_t; 22typedef unsigned long __kernel_ino_t;
23typedef unsigned int __kernel_mode_t; 23typedef unsigned int __kernel_mode_t;
24typedef unsigned short __kernel_nlink_t; 24typedef unsigned long __kernel_nlink_t;
25typedef long __kernel_off_t; 25typedef long __kernel_off_t;
26typedef int __kernel_pid_t; 26typedef int __kernel_pid_t;
27typedef unsigned short __kernel_ipc_pid_t; 27typedef unsigned short __kernel_ipc_pid_t;
diff --git a/include/asm-xtensa/processor.h b/include/asm-xtensa/processor.h
index 8b96e77c9d82..4feb9f7f35a6 100644
--- a/include/asm-xtensa/processor.h
+++ b/include/asm-xtensa/processor.h
@@ -11,24 +11,18 @@
11#ifndef _XTENSA_PROCESSOR_H 11#ifndef _XTENSA_PROCESSOR_H
12#define _XTENSA_PROCESSOR_H 12#define _XTENSA_PROCESSOR_H
13 13
14#ifdef __ASSEMBLY__ 14#include <asm/variant/core.h>
15#define _ASMLANGUAGE 15#include <asm/coprocessor.h>
16#endif
17
18#include <xtensa/config/core.h>
19#include <xtensa/config/specreg.h>
20#include <xtensa/config/tie.h>
21#include <xtensa/config/system.h>
22 16
23#include <linux/compiler.h> 17#include <linux/compiler.h>
24#include <asm/ptrace.h> 18#include <asm/ptrace.h>
25#include <asm/types.h> 19#include <asm/types.h>
26#include <asm/coprocessor.h> 20#include <asm/regs.h>
27 21
28/* Assertions. */ 22/* Assertions. */
29 23
30#if (XCHAL_HAVE_WINDOWED != 1) 24#if (XCHAL_HAVE_WINDOWED != 1)
31#error Linux requires the Xtensa Windowed Registers Option. 25# error Linux requires the Xtensa Windowed Registers Option.
32#endif 26#endif
33 27
34/* 28/*
@@ -145,11 +139,11 @@ struct thread_struct {
145 * Note: We set-up ps as if we did a call4 to the new pc. 139 * Note: We set-up ps as if we did a call4 to the new pc.
146 * set_thread_state in signal.c depends on it. 140 * set_thread_state in signal.c depends on it.
147 */ 141 */
148#define USER_PS_VALUE ( (1 << XCHAL_PS_WOE_SHIFT) + \ 142#define USER_PS_VALUE ((1 << PS_WOE_BIT) | \
149 (1 << XCHAL_PS_CALLINC_SHIFT) + \ 143 (1 << PS_CALLINC_SHIFT) | \
150 (USER_RING << XCHAL_PS_RING_SHIFT) + \ 144 (USER_RING << PS_RING_SHIFT) | \
151 (1 << XCHAL_PS_PROGSTACK_SHIFT) + \ 145 (1 << PS_UM_BIT) | \
152 (1 << XCHAL_PS_EXCM_SHIFT) ) 146 (1 << PS_EXCM_BIT))
153 147
154/* Clearing a0 terminates the backtrace. */ 148/* Clearing a0 terminates the backtrace. */
155#define start_thread(regs, new_pc, new_sp) \ 149#define start_thread(regs, new_pc, new_sp) \
diff --git a/include/asm-xtensa/ptrace.h b/include/asm-xtensa/ptrace.h
index a5ac71a5205c..1b7fe363fad1 100644
--- a/include/asm-xtensa/ptrace.h
+++ b/include/asm-xtensa/ptrace.h
@@ -11,7 +11,7 @@
11#ifndef _XTENSA_PTRACE_H 11#ifndef _XTENSA_PTRACE_H
12#define _XTENSA_PTRACE_H 12#define _XTENSA_PTRACE_H
13 13
14#include <xtensa/config/core.h> 14#include <asm/variant/core.h>
15 15
16/* 16/*
17 * Kernel stack 17 * Kernel stack
diff --git a/include/asm-xtensa/regs.h b/include/asm-xtensa/regs.h
new file mode 100644
index 000000000000..c913d259faaa
--- /dev/null
+++ b/include/asm-xtensa/regs.h
@@ -0,0 +1,138 @@
1/*
2 * Copyright (c) 2006 Tensilica, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2.1 of the GNU Lesser General Public
6 * License as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
22 * USA.
23 */
24
25#ifndef _XTENSA_REGS_H
26#define _XTENSA_REGS_H
27
28/* Special registers. */
29
30#define LBEG 0
31#define LEND 1
32#define LCOUNT 2
33#define SAR 3
34#define BR 4
35#define SCOMPARE1 12
36#define ACCHI 16
37#define ACCLO 17
38#define MR 32
39#define WINDOWBASE 72
40#define WINDOWSTART 73
41#define PTEVADDR 83
42#define RASID 90
43#define ITLBCFG 91
44#define DTLBCFG 92
45#define IBREAKENABLE 96
46#define DDR 104
47#define IBREAKA 128
48#define DBREAKA 144
49#define DBREAKC 160
50#define EPC 176
51#define EPC_1 177
52#define DEPC 192
53#define EPS 192
54#define EPS_1 193
55#define EXCSAVE 208
56#define EXCSAVE_1 209
57#define INTERRUPT 226
58#define INTENABLE 228
59#define PS 230
60#define THREADPTR 231
61#define EXCCAUSE 232
62#define DEBUGCAUSE 233
63#define CCOUNT 234
64#define PRID 235
65#define ICOUNT 236
66#define ICOUNTLEVEL 237
67#define EXCVADDR 238
68#define CCOMPARE 240
69#define MISC 244
70
71/* Special names for read-only and write-only interrupt registers. */
72
73#define INTREAD 226
74#define INTSET 226
75#define INTCLEAR 227
76
77/* EXCCAUSE register fields */
78
79#define EXCCAUSE_EXCCAUSE_SHIFT 0
80#define EXCCAUSE_EXCCAUSE_MASK 0x3F
81
82#define EXCCAUSE_ILLEGAL_INSTRUCTION 0
83#define EXCCAUSE_SYSTEM_CALL 1
84#define EXCCAUSE_INSTRUCTION_FETCH_ERROR 2
85#define EXCCAUSE_LOAD_STORE_ERROR 3
86#define EXCCAUSE_LEVEL1_INTERRUPT 4
87#define EXCCAUSE_ALLOCA 5
88#define EXCCAUSE_INTEGER_DIVIDE_BY_ZERO 6
89#define EXCCAUSE_SPECULATION 7
90#define EXCCAUSE_PRIVILEGED 8
91#define EXCCAUSE_UNALIGNED 9
92#define EXCCAUSE_ITLB_MISS 16
93#define EXCCAUSE_ITLB_MULTIHIT 17
94#define EXCCAUSE_ITLB_PRIVILEGE 18
95#define EXCCAUSE_ITLB_SIZE_RESTRICTION 19
96#define EXCCAUSE_FETCH_CACHE_ATTRIBUTE 20
97#define EXCCAUSE_DTLB_MISS 24
98#define EXCCAUSE_DTLB_MULTIHIT 25
99#define EXCCAUSE_DTLB_PRIVILEGE 26
100#define EXCCAUSE_DTLB_SIZE_RESTRICTION 27
101#define EXCCAUSE_LOAD_CACHE_ATTRIBUTE 28
102#define EXCCAUSE_STORE_CACHE_ATTRIBUTE 29
103#define EXCCAUSE_FLOATING_POINT 40
104
105/* PS register fields. */
106
107#define PS_WOE_BIT 18
108#define PS_CALLINC_SHIFT 16
109#define PS_CALLINC_MASK 0x00030000
110#define PS_OWB_SHIFT 8
111#define PS_OWB_MASK 0x00000F00
112#define PS_RING_SHIFT 6
113#define PS_RING_MASK 0x000000C0
114#define PS_UM_BIT 5
115#define PS_EXCM_BIT 4
116#define PS_INTLEVEL_SHIFT 0
117#define PS_INTLEVEL_MASK 0x0000000F
118
119/* DBREAKCn register fields. */
120
121#define DBREAKC_MASK_BIT 0
122#define DBREAKC_MASK_MASK 0x0000003F
123#define DBREAKC_LOAD_BIT 30
124#define DBREAKC_LOAD_MASK 0x40000000
125#define DBREAKC_STOR_BIT 31
126#define DBREAKC_STOR_MASK 0x80000000
127
128/* DEBUGCAUSE register fields. */
129
130#define DEBUGCAUSE_DEBUGINT_BIT 5 /* External debug interrupt */
131#define DEBUGCAUSE_BREAKN_BIT 4 /* BREAK.N instruction */
132#define DEBUGCAUSE_BREAK_BIT 3 /* BREAK instruction */
133#define DEBUGCAUSE_DBREAK_BIT 2 /* DBREAK match */
134#define DEBUGCAUSE_IBREAK_BIT 1 /* IBREAK match */
135#define DEBUGCAUSE_ICOUNT_BIT 0 /* ICOUNT would incr. to zero */
136
137#endif /* _XTENSA_SPECREG_H */
138
diff --git a/include/asm-xtensa/sembuf.h b/include/asm-xtensa/sembuf.h
index 2d26c47666fe..c15870493b33 100644
--- a/include/asm-xtensa/sembuf.h
+++ b/include/asm-xtensa/sembuf.h
@@ -25,7 +25,7 @@
25 25
26struct semid64_ds { 26struct semid64_ds {
27 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */ 27 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
28#if XCHAL_HAVE_LE 28#ifdef __XTENSA_EL__
29 __kernel_time_t sem_otime; /* last semop time */ 29 __kernel_time_t sem_otime; /* last semop time */
30 unsigned long __unused1; 30 unsigned long __unused1;
31 __kernel_time_t sem_ctime; /* last change time */ 31 __kernel_time_t sem_ctime; /* last change time */
diff --git a/include/asm-xtensa/shmbuf.h b/include/asm-xtensa/shmbuf.h
index a30b81a4b933..ad4b0121782c 100644
--- a/include/asm-xtensa/shmbuf.h
+++ b/include/asm-xtensa/shmbuf.h
@@ -19,6 +19,7 @@
19#ifndef _XTENSA_SHMBUF_H 19#ifndef _XTENSA_SHMBUF_H
20#define _XTENSA_SHMBUF_H 20#define _XTENSA_SHMBUF_H
21 21
22#if defined (__XTENSA_EL__)
22struct shmid64_ds { 23struct shmid64_ds {
23 struct ipc64_perm shm_perm; /* operation perms */ 24 struct ipc64_perm shm_perm; /* operation perms */
24 size_t shm_segsz; /* size of segment (bytes) */ 25 size_t shm_segsz; /* size of segment (bytes) */
@@ -34,6 +35,26 @@ struct shmid64_ds {
34 unsigned long __unused4; 35 unsigned long __unused4;
35 unsigned long __unused5; 36 unsigned long __unused5;
36}; 37};
38#elif defined (__XTENSA_EB__)
39struct shmid64_ds {
40 struct ipc64_perm shm_perm; /* operation perms */
41 size_t shm_segsz; /* size of segment (bytes) */
42 __kernel_time_t shm_atime; /* last attach time */
43 unsigned long __unused1;
44 __kernel_time_t shm_dtime; /* last detach time */
45 unsigned long __unused2;
46 __kernel_time_t shm_ctime; /* last change time */
47 unsigned long __unused3;
48 __kernel_pid_t shm_cpid; /* pid of creator */
49 __kernel_pid_t shm_lpid; /* pid of last operator */
50 unsigned long shm_nattch; /* no. of current attaches */
51 unsigned long __unused4;
52 unsigned long __unused5;
53};
54#else
55# error endian order not defined
56#endif
57
37 58
38struct shminfo64 { 59struct shminfo64 {
39 unsigned long shmmax; 60 unsigned long shmmax;
diff --git a/include/asm-xtensa/stat.h b/include/asm-xtensa/stat.h
index 2f4662ff6c3a..149f4bce092f 100644
--- a/include/asm-xtensa/stat.h
+++ b/include/asm-xtensa/stat.h
@@ -13,93 +13,57 @@
13 13
14#include <linux/types.h> 14#include <linux/types.h>
15 15
16struct __old_kernel_stat {
17 unsigned short st_dev;
18 unsigned short st_ino;
19 unsigned short st_mode;
20 unsigned short st_nlink;
21 unsigned short st_uid;
22 unsigned short st_gid;
23 unsigned short st_rdev;
24 unsigned long st_size;
25 unsigned long st_atime;
26 unsigned long st_mtime;
27 unsigned long st_ctime;
28};
29
30#define STAT_HAVE_NSEC 1 16#define STAT_HAVE_NSEC 1
31 17
32struct stat { 18struct stat {
33 unsigned short st_dev; 19 unsigned long st_dev;
34 unsigned short __pad1; 20 ino_t st_ino;
35 unsigned long st_ino; 21 mode_t st_mode;
36 unsigned short st_mode; 22 nlink_t st_nlink;
37 unsigned short st_nlink; 23 uid_t st_uid;
38 unsigned short st_uid; 24 gid_t st_gid;
39 unsigned short st_gid; 25 unsigned int st_rdev;
40 unsigned short st_rdev; 26 off_t st_size;
41 unsigned short __pad2; 27 unsigned long st_blksize;
42 unsigned long st_size; 28 unsigned long st_blocks;
43 unsigned long st_blksize; 29 unsigned long st_atime;
44 unsigned long st_blocks; 30 unsigned long st_atime_nsec;
45 unsigned long st_atime; 31 unsigned long st_mtime;
46 unsigned long st_atime_nsec; 32 unsigned long st_mtime_nsec;
47 unsigned long st_mtime; 33 unsigned long st_ctime;
48 unsigned long st_mtime_nsec; 34 unsigned long st_ctime_nsec;
49 unsigned long st_ctime; 35 unsigned long __unused4;
50 unsigned long st_ctime_nsec; 36 unsigned long __unused5;
51 unsigned long __unused4;
52 unsigned long __unused5;
53}; 37};
54 38
55/* This matches struct stat64 in glibc-2.2.3. */ 39/* This matches struct stat64 in glibc-2.3 */
56 40
57struct stat64 { 41struct stat64 {
58#ifdef __XTENSA_EL__ 42 unsigned long long st_dev; /* Device */
59 unsigned short st_dev; /* Device */ 43 unsigned long long st_ino; /* File serial number */
60 unsigned char __pad0[10];
61#else
62 unsigned char __pad0[6];
63 unsigned short st_dev;
64 unsigned char __pad1[2];
65#endif
66
67#define STAT64_HAS_BROKEN_ST_INO 1
68 unsigned long __st_ino; /* 32bit file serial number. */
69
70 unsigned int st_mode; /* File mode. */ 44 unsigned int st_mode; /* File mode. */
71 unsigned int st_nlink; /* Link count. */ 45 unsigned int st_nlink; /* Link count. */
72 unsigned int st_uid; /* User ID of the file's owner. */ 46 unsigned int st_uid; /* User ID of the file's owner. */
73 unsigned int st_gid; /* Group ID of the file's group. */ 47 unsigned int st_gid; /* Group ID of the file's group. */
74 48 unsigned long long st_rdev; /* Device number, if device. */
75#ifdef __XTENSA_EL__ 49 long long st_size; /* Size of file, in bytes. */
76 unsigned short st_rdev; /* Device number, if device. */ 50 long st_blksize; /* Optimal block size for I/O. */
77 unsigned char __pad3[10]; 51 unsigned long __unused2;
78#else 52#ifdef __XTENSA_EB__
79 unsigned char __pad2[6]; 53 unsigned long __unused3;
80 unsigned short st_rdev; 54 long st_blocks; /* Number 512-byte blocks allocated. */
81 unsigned char __pad3[2];
82#endif
83
84 long long int st_size; /* Size of file, in bytes. */
85 long int st_blksize; /* Optimal block size for I/O. */
86
87#ifdef __XTENSA_EL__
88 unsigned long st_blocks; /* Number 512-byte blocks allocated. */
89 unsigned long __pad4;
90#else 55#else
91 unsigned long __pad4; 56 long st_blocks; /* Number 512-byte blocks allocated. */
92 unsigned long st_blocks; 57 unsigned long __unused3;
93#endif 58#endif
94 59 long st_atime; /* Time of last access. */
95 unsigned long __pad5; 60 unsigned long st_atime_nsec;
96 long int st_atime; /* Time of last access. */ 61 long st_mtime; /* Time of last modification. */
97 unsigned long st_atime_nsec; 62 unsigned long st_mtime_nsec;
98 long int st_mtime; /* Time of last modification. */ 63 long st_ctime; /* Time of last status change. */
99 unsigned long st_mtime_nsec; 64 unsigned long st_ctime_nsec;
100 long int st_ctime; /* Time of last status change. */ 65 unsigned long __unused4;
101 unsigned long st_ctime_nsec; 66 unsigned long __unused5;
102 unsigned long long int st_ino; /* File serial number. */
103}; 67};
104 68
105#endif /* _XTENSA_STAT_H */ 69#endif /* _XTENSA_STAT_H */
diff --git a/include/asm-xtensa/syscall.h b/include/asm-xtensa/syscall.h
new file mode 100644
index 000000000000..6cb0d42f11c8
--- /dev/null
+++ b/include/asm-xtensa/syscall.h
@@ -0,0 +1,20 @@
1struct pt_regs;
2struct sigaction;
3asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*);
4asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*);
5asmlinkage long xtensa_pipe(int __user *);
6asmlinkage long xtensa_mmap2(unsigned long, unsigned long, unsigned long,
7 unsigned long, unsigned long, unsigned long);
8asmlinkage long xtensa_ptrace(long, long, long, long);
9asmlinkage long xtensa_sigreturn(struct pt_regs*);
10asmlinkage long xtensa_rt_sigreturn(struct pt_regs*);
11asmlinkage long xtensa_sigsuspend(struct pt_regs*);
12asmlinkage long xtensa_rt_sigsuspend(struct pt_regs*);
13asmlinkage long xtensa_sigaction(int, const struct old_sigaction*,
14 struct old_sigaction*);
15asmlinkage long xtensa_sigaltstack(struct pt_regs *regs);
16asmlinkage long sys_rt_sigaction(int,
17 const struct sigaction __user *,
18 struct sigaction __user *,
19 size_t);
20asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg);
diff --git a/include/asm-xtensa/system.h b/include/asm-xtensa/system.h
index 932bda92a21c..4aaed7fe6cfe 100644
--- a/include/asm-xtensa/system.h
+++ b/include/asm-xtensa/system.h
@@ -213,7 +213,7 @@ static inline void spill_registers(void)
213 unsigned int a0, ps; 213 unsigned int a0, ps;
214 214
215 __asm__ __volatile__ ( 215 __asm__ __volatile__ (
216 "movi a14," __stringify (PS_EXCM_MASK) " | 1\n\t" 216 "movi a14," __stringify (PS_EXCM_BIT) " | 1\n\t"
217 "mov a12, a0\n\t" 217 "mov a12, a0\n\t"
218 "rsr a13," __stringify(SAR) "\n\t" 218 "rsr a13," __stringify(SAR) "\n\t"
219 "xsr a14," __stringify(PS) "\n\t" 219 "xsr a14," __stringify(PS) "\n\t"
diff --git a/include/asm-xtensa/timex.h b/include/asm-xtensa/timex.h
index c7b705e66655..28c7985a4000 100644
--- a/include/asm-xtensa/timex.h
+++ b/include/asm-xtensa/timex.h
@@ -16,17 +16,22 @@
16#include <asm/processor.h> 16#include <asm/processor.h>
17#include <linux/stringify.h> 17#include <linux/stringify.h>
18 18
19#if XCHAL_INT_LEVEL(XCHAL_TIMER0_INTERRUPT) == 1 19#define _INTLEVEL(x) XCHAL_INT ## x ## _LEVEL
20#define INTLEVEL(x) _INTLEVEL(x)
21
22#if INTLEVEL(XCHAL_TIMER0_INTERRUPT) == 1
20# define LINUX_TIMER 0 23# define LINUX_TIMER 0
21#elif XCHAL_INT_LEVEL(XCHAL_TIMER1_INTERRUPT) == 1 24# define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
25#elif INTLEVEL(XCHAL_TIMER1_INTERRUPT) == 1
22# define LINUX_TIMER 1 26# define LINUX_TIMER 1
23#elif XCHAL_INT_LEVEL(XCHAL_TIMER2_INTERRUPT) == 1 27# define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
28#elif INTLEVEL(XCHAL_TIMER2_INTERRUPT) == 1
24# define LINUX_TIMER 2 29# define LINUX_TIMER 2
30# define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
25#else 31#else
26# error "Bad timer number for Linux configurations!" 32# error "Bad timer number for Linux configurations!"
27#endif 33#endif
28 34
29#define LINUX_TIMER_INT XCHAL_TIMER_INTERRUPT(LINUX_TIMER)
30#define LINUX_TIMER_MASK (1L << LINUX_TIMER_INT) 35#define LINUX_TIMER_MASK (1L << LINUX_TIMER_INT)
31 36
32#define CLOCK_TICK_RATE 1193180 /* (everyone is using this value) */ 37#define CLOCK_TICK_RATE 1193180 /* (everyone is using this value) */
@@ -60,8 +65,8 @@ extern cycles_t cacheflush_time;
60 65
61#define WSR_CCOUNT(r) __asm__("wsr %0,"__stringify(CCOUNT) :: "a" (r)) 66#define WSR_CCOUNT(r) __asm__("wsr %0,"__stringify(CCOUNT) :: "a" (r))
62#define RSR_CCOUNT(r) __asm__("rsr %0,"__stringify(CCOUNT) : "=a" (r)) 67#define RSR_CCOUNT(r) __asm__("rsr %0,"__stringify(CCOUNT) : "=a" (r))
63#define WSR_CCOMPARE(x,r) __asm__("wsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) :: "a"(r)) 68#define WSR_CCOMPARE(x,r) __asm__("wsr %0,"__stringify(CCOMPARE)"+"__stringify(x) :: "a"(r))
64#define RSR_CCOMPARE(x,r) __asm__("rsr %0,"__stringify(CCOMPARE_0)"+"__stringify(x) : "=a"(r)) 69#define RSR_CCOMPARE(x,r) __asm__("rsr %0,"__stringify(CCOMPARE)"+"__stringify(x) : "=a"(r))
65 70
66static inline unsigned long get_ccount (void) 71static inline unsigned long get_ccount (void)
67{ 72{
diff --git a/include/asm-xtensa/tlbflush.h b/include/asm-xtensa/tlbflush.h
index 43f6ec859af9..7c637b3c352c 100644
--- a/include/asm-xtensa/tlbflush.h
+++ b/include/asm-xtensa/tlbflush.h
@@ -11,12 +11,20 @@
11#ifndef _XTENSA_TLBFLUSH_H 11#ifndef _XTENSA_TLBFLUSH_H
12#define _XTENSA_TLBFLUSH_H 12#define _XTENSA_TLBFLUSH_H
13 13
14#define DEBUG_TLB
15
16#ifdef __KERNEL__ 14#ifdef __KERNEL__
17 15
18#include <asm/processor.h>
19#include <linux/stringify.h> 16#include <linux/stringify.h>
17#include <asm/processor.h>
18
19#define DTLB_WAY_PGD 7
20
21#define ITLB_ARF_WAYS 4
22#define DTLB_ARF_WAYS 4
23
24#define ITLB_HIT_BIT 3
25#define DTLB_HIT_BIT 4
26
27#ifndef __ASSEMBLY__
20 28
21/* TLB flushing: 29/* TLB flushing:
22 * 30 *
@@ -46,11 +54,6 @@ static inline void flush_tlb_pgtables(struct mm_struct *mm,
46 54
47/* TLB operations. */ 55/* TLB operations. */
48 56
49#define ITLB_WAYS_LOG2 XCHAL_ITLB_WAY_BITS
50#define DTLB_WAYS_LOG2 XCHAL_DTLB_WAY_BITS
51#define ITLB_PROBE_SUCCESS (1 << ITLB_WAYS_LOG2)
52#define DTLB_PROBE_SUCCESS (1 << DTLB_WAYS_LOG2)
53
54static inline unsigned long itlb_probe(unsigned long addr) 57static inline unsigned long itlb_probe(unsigned long addr)
55{ 58{
56 unsigned long tmp; 59 unsigned long tmp;
@@ -131,29 +134,30 @@ static inline void write_itlb_entry (pte_t entry, int way)
131 134
132static inline void invalidate_page_directory (void) 135static inline void invalidate_page_directory (void)
133{ 136{
134 invalidate_dtlb_entry (DTLB_WAY_PGTABLE); 137 invalidate_dtlb_entry (DTLB_WAY_PGD);
138 invalidate_dtlb_entry (DTLB_WAY_PGD+1);
139 invalidate_dtlb_entry (DTLB_WAY_PGD+2);
135} 140}
136 141
137static inline void invalidate_itlb_mapping (unsigned address) 142static inline void invalidate_itlb_mapping (unsigned address)
138{ 143{
139 unsigned long tlb_entry; 144 unsigned long tlb_entry;
140 while ((tlb_entry = itlb_probe (address)) & ITLB_PROBE_SUCCESS) 145 if (((tlb_entry = itlb_probe(address)) & (1 << ITLB_HIT_BIT)) != 0)
141 invalidate_itlb_entry (tlb_entry); 146 invalidate_itlb_entry(tlb_entry);
142} 147}
143 148
144static inline void invalidate_dtlb_mapping (unsigned address) 149static inline void invalidate_dtlb_mapping (unsigned address)
145{ 150{
146 unsigned long tlb_entry; 151 unsigned long tlb_entry;
147 while ((tlb_entry = dtlb_probe (address)) & DTLB_PROBE_SUCCESS) 152 if (((tlb_entry = dtlb_probe(address)) & (1 << DTLB_HIT_BIT)) != 0)
148 invalidate_dtlb_entry (tlb_entry); 153 invalidate_dtlb_entry(tlb_entry);
149} 154}
150 155
151#define check_pgt_cache() do { } while (0) 156#define check_pgt_cache() do { } while (0)
152 157
153 158
154#ifdef DEBUG_TLB 159/*
155 160 * DO NOT USE THESE FUNCTIONS. These instructions aren't part of the Xtensa
156/* DO NOT USE THESE FUNCTIONS. These instructions aren't part of the Xtensa
157 * ISA and exist only for test purposes.. 161 * ISA and exist only for test purposes..
158 * You may find it helpful for MMU debugging, however. 162 * You may find it helpful for MMU debugging, however.
159 * 163 *
@@ -193,8 +197,6 @@ static inline unsigned long read_itlb_translation (int way)
193 return tmp; 197 return tmp;
194} 198}
195 199
196#endif /* DEBUG_TLB */ 200#endif /* __ASSEMBLY__ */
197
198
199#endif /* __KERNEL__ */ 201#endif /* __KERNEL__ */
200#endif /* _XTENSA_PGALLOC_H */ 202#endif /* _XTENSA_TLBFLUSH_H */
diff --git a/include/asm-xtensa/unistd.h b/include/asm-xtensa/unistd.h
index 2e1a1b997e7d..8a7fb6964ce1 100644
--- a/include/asm-xtensa/unistd.h
+++ b/include/asm-xtensa/unistd.h
@@ -11,212 +11,593 @@
11#ifndef _XTENSA_UNISTD_H 11#ifndef _XTENSA_UNISTD_H
12#define _XTENSA_UNISTD_H 12#define _XTENSA_UNISTD_H
13 13
14#define __NR_spill 0 14#ifndef __SYSCALL
15#define __NR_exit 1 15# define __SYSCALL(nr,func,nargs)
16#define __NR_read 3 16#endif
17#define __NR_write 4 17
18#define __NR_open 5 18#define __NR_spill 0
19#define __NR_close 6 19__SYSCALL( 0, sys_ni_syscall, 0)
20#define __NR_creat 8 20#define __NR_xtensa 1
21#define __NR_link 9 21__SYSCALL( 1, sys_ni_syscall, 0)
22#define __NR_unlink 10 22#define __NR_available4 2
23#define __NR_execve 11 23__SYSCALL( 2, sys_ni_syscall, 0)
24#define __NR_chdir 12 24#define __NR_available5 3
25#define __NR_mknod 14 25__SYSCALL( 3, sys_ni_syscall, 0)
26#define __NR_chmod 15 26#define __NR_available6 4
27#define __NR_lchown 16 27__SYSCALL( 4, sys_ni_syscall, 0)
28#define __NR_break 17 28#define __NR_available7 5
29#define __NR_lseek 19 29__SYSCALL( 5, sys_ni_syscall, 0)
30#define __NR_getpid 20 30#define __NR_available8 6
31#define __NR_mount 21 31__SYSCALL( 6, sys_ni_syscall, 0)
32#define __NR_setuid 23 32#define __NR_available9 7
33#define __NR_getuid 24 33__SYSCALL( 7, sys_ni_syscall, 0)
34#define __NR_ptrace 26 34
35#define __NR_utime 30 35/* File Operations */
36#define __NR_stty 31 36
37#define __NR_gtty 32 37#define __NR_open 8
38#define __NR_access 33 38__SYSCALL( 8, sys_open, 3)
39#define __NR_ftime 35 39#define __NR_close 9
40#define __NR_sync 36 40__SYSCALL( 9, sys_close, 1)
41#define __NR_kill 37 41#define __NR_dup 10
42#define __NR_rename 38 42__SYSCALL( 10, sys_dup, 1)
43#define __NR_mkdir 39 43#define __NR_dup2 11
44#define __NR_rmdir 40 44__SYSCALL( 11, sys_dup2, 2)
45#define __NR_dup 41 45#define __NR_read 12
46#define __NR_pipe 42 46__SYSCALL( 12, sys_read, 3)
47#define __NR_times 43 47#define __NR_write 13
48#define __NR_prof 44 48__SYSCALL( 13, sys_write, 3)
49#define __NR_brk 45 49#define __NR_select 14
50#define __NR_setgid 46 50__SYSCALL( 14, sys_select, 5)
51#define __NR_getgid 47 51#define __NR_lseek 15
52#define __NR_signal 48 52__SYSCALL( 15, sys_lseek, 3)
53#define __NR_geteuid 49 53#define __NR_poll 16
54#define __NR_getegid 50 54__SYSCALL( 16, sys_poll, 3)
55#define __NR_acct 51 55#define __NR__llseek 17
56#define __NR_lock 53 56__SYSCALL( 17, sys_llseek, 5)
57#define __NR_ioctl 54 57#define __NR_epoll_wait 18
58#define __NR_fcntl 55 58__SYSCALL( 18, sys_epoll_wait, 4)
59#define __NR_setpgid 57 59#define __NR_epoll_ctl 19
60#define __NR_ulimit 58 60__SYSCALL( 19, sys_epoll_ctl, 4)
61#define __NR_umask 60 61#define __NR_epoll_create 20
62#define __NR_chroot 61 62__SYSCALL( 20, sys_epoll_create, 1)
63#define __NR_ustat 62 63#define __NR_creat 21
64#define __NR_dup2 63 64__SYSCALL( 21, sys_creat, 2)
65#define __NR_getppid 64 65#define __NR_truncate 22
66#define __NR_setsid 66 66__SYSCALL( 22, sys_truncate, 2)
67#define __NR_sigaction 67 67#define __NR_ftruncate 23
68#define __NR_setreuid 70 68__SYSCALL( 23, sys_ftruncate, 2)
69#define __NR_setregid 71 69#define __NR_readv 24
70#define __NR_sigsuspend 72 70__SYSCALL( 24, sys_readv, 3)
71#define __NR_sigpending 73 71#define __NR_writev 25
72#define __NR_sethostname 74 72__SYSCALL( 25, sys_writev, 3)
73#define __NR_setrlimit 75 73#define __NR_fsync 26
74#define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */ 74__SYSCALL( 26, sys_fsync, 1)
75#define __NR_getrusage 77 75#define __NR_fdatasync 27
76#define __NR_gettimeofday 78 76__SYSCALL( 27, sys_fdatasync, 1)
77#define __NR_settimeofday 79 77#define __NR_truncate64 28
78#define __NR_getgroups 80 78__SYSCALL( 28, sys_truncate64, 2)
79#define __NR_setgroups 81 79#define __NR_ftruncate64 29
80#define __NR_select 82 80__SYSCALL( 29, sys_ftruncate64, 2)
81#define __NR_symlink 83 81#define __NR_pread64 30
82#define __NR_readlink 85 82__SYSCALL( 30, sys_pread64, 6)
83#define __NR_uselib 86 83#define __NR_pwrite64 31
84#define __NR_swapon 87 84__SYSCALL( 31, sys_pwrite64, 6)
85#define __NR_reboot 88 85
86#define __NR_munmap 91 86#define __NR_link 32
87#define __NR_truncate 92 87__SYSCALL( 32, sys_link, 2)
88#define __NR_ftruncate 93 88#define __NR_rename 33
89#define __NR_fchmod 94 89__SYSCALL( 33, sys_rename, 2)
90#define __NR_fchown 95 90#define __NR_symlink 34
91#define __NR_getpriority 96 91__SYSCALL( 34, sys_symlink, 2)
92#define __NR_setpriority 97 92#define __NR_readlink 35
93#define __NR_profil 98 93__SYSCALL( 35, sys_readlink, 3)
94#define __NR_statfs 99 94#define __NR_mknod 36
95#define __NR_fstatfs 100 95__SYSCALL( 36, sys_mknod, 3)
96#define __NR_ioperm 101 96#define __NR_pipe 37
97#define __NR_syslog 103 97__SYSCALL( 37, xtensa_pipe, 1)
98#define __NR_setitimer 104 98#define __NR_unlink 38
99#define __NR_getitimer 105 99__SYSCALL( 38, sys_unlink, 1)
100#define __NR_stat 106 100#define __NR_rmdir 39
101#define __NR_lstat 107 101__SYSCALL( 39, sys_rmdir, 1)
102#define __NR_fstat 108 102
103#define __NR_iopl 110 103#define __NR_mkdir 40
104#define __NR_vhangup 111 104__SYSCALL( 40, sys_mkdir, 2)
105#define __NR_idle 112 105#define __NR_chdir 41
106#define __NR_wait4 114 106__SYSCALL( 41, sys_chdir, 1)
107#define __NR_swapoff 115 107#define __NR_fchdir 42
108#define __NR_sysinfo 116 108__SYSCALL( 42, sys_fchdir, 1)
109#define __NR_fsync 118 109#define __NR_getcwd 43
110#define __NR_sigreturn 119 110__SYSCALL( 43, sys_getcwd, 2)
111#define __NR_clone 120 111
112#define __NR_setdomainname 121 112#define __NR_chmod 44
113#define __NR_uname 122 113__SYSCALL( 44, sys_chmod, 2)
114#define __NR_modify_ldt 123 114#define __NR_chown 45
115#define __NR_adjtimex 124 115__SYSCALL( 45, sys_chown, 3)
116#define __NR_mprotect 125 116#define __NR_stat 46
117#define __NR_create_module 127 117__SYSCALL( 46, sys_newstat, 2)
118#define __NR_init_module 128 118#define __NR_stat64 47
119#define __NR_delete_module 129 119__SYSCALL( 47, sys_stat64, 2)
120#define __NR_quotactl 131 120
121#define __NR_getpgid 132 121#define __NR_lchown 48
122#define __NR_fchdir 133 122__SYSCALL( 48, sys_lchown, 3)
123#define __NR_bdflush 134 123#define __NR_lstat 49
124#define __NR_sysfs 135 124__SYSCALL( 49, sys_newlstat, 2)
125#define __NR_personality 136 125#define __NR_lstat64 50
126#define __NR_setfsuid 138 126__SYSCALL( 50, sys_lstat64, 2)
127#define __NR_setfsgid 139 127#define __NR_available51 51
128#define __NR__llseek 140 128__SYSCALL( 51, sys_ni_syscall, 0)
129#define __NR_getdents 141 129
130#define __NR__newselect 142 130#define __NR_fchmod 52
131#define __NR_flock 143 131__SYSCALL( 52, sys_fchmod, 2)
132#define __NR_msync 144 132#define __NR_fchown 53
133#define __NR_readv 145 133__SYSCALL( 53, sys_fchown, 3)
134#define __NR_writev 146 134#define __NR_fstat 54
135#define __NR_cacheflush 147 135__SYSCALL( 54, sys_newfstat, 2)
136#define __NR_cachectl 148 136#define __NR_fstat64 55
137#define __NR_sysxtensa 149 137__SYSCALL( 55, sys_fstat64, 2)
138#define __NR_sysdummy 150 138
139#define __NR_getsid 151 139#define __NR_flock 56
140#define __NR_fdatasync 152 140__SYSCALL( 56, sys_flock, 2)
141#define __NR__sysctl 153 141#define __NR_access 57
142#define __NR_mlock 154 142__SYSCALL( 57, sys_access, 2)
143#define __NR_munlock 155 143#define __NR_umask 58
144#define __NR_mlockall 156 144__SYSCALL( 58, sys_umask, 1)
145#define __NR_munlockall 157 145#define __NR_getdents 59
146#define __NR_sched_setparam 158 146__SYSCALL( 59, sys_getdents, 3)
147#define __NR_sched_getparam 159 147#define __NR_getdents64 60
148#define __NR_sched_setscheduler 160 148__SYSCALL( 60, sys_getdents64, 3)
149#define __NR_sched_getscheduler 161 149#define __NR_fcntl64 61
150#define __NR_sched_yield 162 150__SYSCALL( 61, sys_fcntl64, 3)
151#define __NR_sched_get_priority_max 163 151#define __NR_available62 62
152#define __NR_sched_get_priority_min 164 152__SYSCALL( 62, sys_ni_syscall, 0)
153#define __NR_sched_rr_get_interval 165 153#define __NR_fadvise64_64 63
154#define __NR_nanosleep 166 154__SYSCALL( 63, sys_fadvise64_64, 6)
155#define __NR_mremap 167 155#define __NR_utime 64 /* glibc 2.3.3 ?? */
156#define __NR_accept 168 156__SYSCALL( 64, sys_utime, 2)
157#define __NR_bind 169 157#define __NR_utimes 65
158#define __NR_connect 170 158__SYSCALL( 65, sys_utimes, 2)
159#define __NR_getpeername 171 159#define __NR_ioctl 66
160#define __NR_getsockname 172 160__SYSCALL( 66, sys_ioctl, 3)
161#define __NR_getsockopt 173 161#define __NR_fcntl 67
162#define __NR_listen 174 162__SYSCALL( 67, sys_fcntl, 3)
163#define __NR_recv 175 163
164#define __NR_recvfrom 176 164#define __NR_setxattr 68
165#define __NR_recvmsg 177 165__SYSCALL( 68, sys_setxattr, 5)
166#define __NR_send 178 166#define __NR_getxattr 69
167#define __NR_sendmsg 179 167__SYSCALL( 69, sys_getxattr, 4)
168#define __NR_sendto 180 168#define __NR_listxattr 70
169#define __NR_setsockopt 181 169__SYSCALL( 70, sys_listxattr, 3)
170#define __NR_shutdown 182 170#define __NR_removexattr 71
171#define __NR_socket 183 171__SYSCALL( 71, sys_removexattr, 2)
172#define __NR_socketpair 184 172#define __NR_lsetxattr 72
173#define __NR_setresuid 185 173__SYSCALL( 72, sys_lsetxattr, 5)
174#define __NR_getresuid 186 174#define __NR_lgetxattr 73
175#define __NR_query_module 187 175__SYSCALL( 73, sys_lgetxattr, 4)
176#define __NR_poll 188 176#define __NR_llistxattr 74
177#define __NR_nfsservctl 189 177__SYSCALL( 74, sys_llistxattr, 3)
178#define __NR_setresgid 190 178#define __NR_lremovexattr 75
179#define __NR_getresgid 191 179__SYSCALL( 75, sys_lremovexattr, 2)
180#define __NR_prctl 192 180#define __NR_fsetxattr 76
181#define __NR_rt_sigreturn 193 181__SYSCALL( 76, sys_fsetxattr, 5)
182#define __NR_rt_sigaction 194 182#define __NR_fgetxattr 77
183#define __NR_rt_sigprocmask 195 183__SYSCALL( 77, sys_fgetxattr, 4)
184#define __NR_rt_sigpending 196 184#define __NR_flistxattr 78
185#define __NR_rt_sigtimedwait 197 185__SYSCALL( 78, sys_flistxattr, 3)
186#define __NR_rt_sigqueueinfo 198 186#define __NR_fremovexattr 79
187#define __NR_rt_sigsuspend 199 187__SYSCALL( 79, sys_fremovexattr, 2)
188#define __NR_pread 200 188
189#define __NR_pwrite 201 189/* File Map / Shared Memory Operations */
190#define __NR_chown 202 190
191#define __NR_getcwd 203 191#define __NR_mmap2 80
192#define __NR_capget 204 192__SYSCALL( 80, xtensa_mmap2, 6)
193#define __NR_capset 205 193#define __NR_munmap 81
194#define __NR_sigaltstack 206 194__SYSCALL( 81, sys_munmap, 2)
195#define __NR_sendfile 207 195#define __NR_mprotect 82
196#define __NR_mmap2 210 196__SYSCALL( 82, sys_mprotect, 3)
197#define __NR_truncate64 211 197#define __NR_brk 83
198#define __NR_ftruncate64 212 198__SYSCALL( 83, sys_brk, 1)
199#define __NR_stat64 213 199#define __NR_mlock 84
200#define __NR_lstat64 214 200__SYSCALL( 84, sys_mlock, 2)
201#define __NR_fstat64 215 201#define __NR_munlock 85
202#define __NR_pivot_root 216 202__SYSCALL( 85, sys_munlock, 2)
203#define __NR_mincore 217 203#define __NR_mlockall 86
204#define __NR_madvise 218 204__SYSCALL( 86, sys_mlockall, 1)
205#define __NR_getdents64 219 205#define __NR_munlockall 87
206 206__SYSCALL( 87, sys_munlockall, 0)
207/* Keep this last; should always equal the last valid call number. */ 207#define __NR_mremap 88
208#define __NR_Linux_syscalls 220 208__SYSCALL( 88, sys_mremap, 4)
209 209#define __NR_msync 89
210/* user-visible error numbers are in the range -1 - -125: see 210__SYSCALL( 89, sys_msync, 3)
211 * <asm-xtensa/errno.h> */ 211#define __NR_mincore 90
212 212__SYSCALL( 90, sys_mincore, 3)
213#define SYSXTENSA_RESERVED 0 /* don't use this */ 213#define __NR_madvise 91
214#define SYSXTENSA_ATOMIC_SET 1 /* set variable */ 214__SYSCALL( 91, sys_madvise, 3)
215#define SYSXTENSA_ATOMIC_EXG_ADD 2 /* exchange memory and add */ 215#define __NR_shmget 92
216#define SYSXTENSA_ATOMIC_ADD 3 /* add to memory */ 216__SYSCALL( 92, sys_shmget, 4)
217#define SYSXTENSA_ATOMIC_CMP_SWP 4 /* compare and swap */ 217#define __NR_shmat 93
218 218__SYSCALL( 93, xtensa_shmat, 4)
219#define SYSXTENSA_COUNT 5 /* count of syscall0 functions*/ 219#define __NR_shmctl 94
220__SYSCALL( 94, sys_shmctl, 4)
221#define __NR_shmdt 95
222__SYSCALL( 95, sys_shmdt, 4)
223
224/* Socket Operations */
225
226#define __NR_socket 96
227__SYSCALL( 96, sys_socket, 3)
228#define __NR_setsockopt 97
229__SYSCALL( 97, sys_setsockopt, 5)
230#define __NR_getsockopt 98
231__SYSCALL( 98, sys_getsockopt, 5)
232#define __NR_shutdown 99
233__SYSCALL( 99, sys_shutdown, 2)
234
235#define __NR_bind 100
236__SYSCALL(100, sys_bind, 3)
237#define __NR_connect 101
238__SYSCALL(101, sys_connect, 3)
239#define __NR_listen 102
240__SYSCALL(102, sys_listen, 2)
241#define __NR_accept 103
242__SYSCALL(103, sys_accept, 3)
243
244#define __NR_getsockname 104
245__SYSCALL(104, sys_getsockname, 3)
246#define __NR_getpeername 105
247__SYSCALL(105, sys_getpeername, 3)
248#define __NR_sendmsg 106
249__SYSCALL(106, sys_sendmsg, 3)
250#define __NR_recvmsg 107
251__SYSCALL(107, sys_recvmsg, 3)
252#define __NR_send 108
253__SYSCALL(108, sys_send, 4)
254#define __NR_recv 109
255__SYSCALL(109, sys_recv, 4)
256#define __NR_sendto 110
257__SYSCALL(110, sys_sendto, 6)
258#define __NR_recvfrom 111
259__SYSCALL(111, sys_recvfrom, 6)
260
261#define __NR_socketpair 112
262__SYSCALL(112, sys_socketpair, 4)
263#define __NR_sendfile 113
264__SYSCALL(113, sys_sendfile, 4)
265#define __NR_sendfile64 114
266__SYSCALL(114, sys_sendfile64, 4)
267#define __NR_available115 115
268__SYSCALL(115, sys_ni_syscall, 0)
269
270/* Process Operations */
271
272#define __NR_clone 116
273__SYSCALL(116, xtensa_clone, 5)
274#define __NR_execve 117
275__SYSCALL(117, xtensa_execve, 3)
276#define __NR_exit 118
277__SYSCALL(118, sys_exit, 1)
278#define __NR_exit_group 119
279__SYSCALL(119, sys_exit_group, 1)
280#define __NR_getpid 120
281__SYSCALL(120, sys_getpid, 0)
282#define __NR_wait4 121
283__SYSCALL(121, sys_wait4, 4)
284#define __NR_waitid 122
285__SYSCALL(122, sys_waitid, 5)
286#define __NR_kill 123
287__SYSCALL(123, sys_kill, 2)
288#define __NR_tkill 124
289__SYSCALL(124, sys_tkill, 2)
290#define __NR_tgkill 125
291__SYSCALL(125, sys_tgkill, 3)
292#define __NR_set_tid_address 126
293__SYSCALL(126, sys_set_tid_address, 1)
294#define __NR_gettid 127
295__SYSCALL(127, sys_gettid, 0)
296#define __NR_setsid 128
297__SYSCALL(128, sys_setsid, 0)
298#define __NR_getsid 129
299__SYSCALL(129, sys_getsid, 1)
300#define __NR_prctl 130
301__SYSCALL(130, sys_prctl, 5)
302#define __NR_personality 131
303__SYSCALL(131, sys_personality, 1)
304#define __NR_getpriority 132
305__SYSCALL(132, sys_getpriority, 2)
306#define __NR_setpriority 133
307__SYSCALL(133, sys_setpriority, 3)
308#define __NR_setitimer 134
309__SYSCALL(134, sys_setitimer, 3)
310#define __NR_getitimer 135
311__SYSCALL(135, sys_getitimer, 2)
312#define __NR_setuid 136
313__SYSCALL(136, sys_setuid, 1)
314#define __NR_getuid 137
315__SYSCALL(137, sys_getuid, 0)
316#define __NR_setgid 138
317__SYSCALL(138, sys_setgid, 1)
318#define __NR_getgid 139
319__SYSCALL(139, sys_getgid, 0)
320#define __NR_geteuid 140
321__SYSCALL(140, sys_geteuid, 0)
322#define __NR_getegid 141
323__SYSCALL(141, sys_getegid, 0)
324#define __NR_setreuid 142
325__SYSCALL(142, sys_setreuid, 2)
326#define __NR_setregid 143
327__SYSCALL(143, sys_setregid, 2)
328#define __NR_setresuid 144
329__SYSCALL(144, sys_setresuid, 3)
330#define __NR_getresuid 145
331__SYSCALL(145, sys_getresuid, 3)
332#define __NR_setresgid 146
333__SYSCALL(146, sys_setresgid, 3)
334#define __NR_getresgid 147
335__SYSCALL(147, sys_getresgid, 3)
336#define __NR_setpgid 148
337__SYSCALL(148, sys_setpgid, 2)
338#define __NR_getpgid 149
339__SYSCALL(149, sys_getpgid, 1)
340#define __NR_getppid 150
341__SYSCALL(150, sys_getppid, 0)
342#define __NR_available151 151
343__SYSCALL(151, sys_ni_syscall, 0)
344
345#define __NR_reserved152 152 /* set_thread_area */
346__SYSCALL(152, sys_ni_syscall, 0)
347#define __NR_reserved153 153 /* get_thread_area */
348__SYSCALL(153, sys_ni_syscall, 0)
349#define __NR_times 154
350__SYSCALL(154, sys_times, 1)
351#define __NR_acct 155
352__SYSCALL(155, sys_acct, 1)
353#define __NR_sched_setaffinity 156
354__SYSCALL(156, sys_sched_setaffinity, 3)
355#define __NR_sched_getaffinity 157
356__SYSCALL(157, sys_sched_getaffinity, 3)
357#define __NR_capget 158
358__SYSCALL(158, sys_capget, 2)
359#define __NR_capset 159
360__SYSCALL(159, sys_capset, 2)
361#define __NR_ptrace 160
362__SYSCALL(160, sys_ptrace, 4)
363#define __NR_semtimedop 161
364__SYSCALL(161, sys_semtimedop, 5)
365#define __NR_semget 162
366__SYSCALL(162, sys_semget, 4)
367#define __NR_semop 163
368__SYSCALL(163, sys_semop, 4)
369#define __NR_semctl 164
370__SYSCALL(164, sys_semctl, 4)
371#define __NR_available165 165
372__SYSCALL(165, sys_ni_syscall, 0)
373#define __NR_msgget 166
374__SYSCALL(166, sys_msgget, 4)
375#define __NR_msgsnd 167
376__SYSCALL(167, sys_msgsnd, 4)
377#define __NR_msgrcv 168
378__SYSCALL(168, sys_msgrcv, 4)
379#define __NR_msgctl 169
380__SYSCALL(169, sys_msgctl, 4)
381#define __NR_available170 170
382__SYSCALL(170, sys_ni_syscall, 0)
383#define __NR_available171 171
384__SYSCALL(171, sys_ni_syscall, 0)
385
386/* File System */
387
388#define __NR_mount 172
389__SYSCALL(172, sys_mount, 5)
390#define __NR_swapon 173
391__SYSCALL(173, sys_swapon, 2)
392#define __NR_chroot 174
393__SYSCALL(174, sys_chroot, 1)
394#define __NR_pivot_root 175
395__SYSCALL(175, sys_pivot_root, 2)
396#define __NR_umount 176
397__SYSCALL(176, sys_umount, 2)
398#define __NR_swapoff 177
399__SYSCALL(177, sys_swapoff, 1)
400#define __NR_sync 178
401__SYSCALL(178, sys_sync, 0)
402#define __NR_available179 179
403__SYSCALL(179, sys_ni_syscall, 0)
404#define __NR_setfsuid 180
405__SYSCALL(180, sys_setfsuid, 1)
406#define __NR_setfsgid 181
407__SYSCALL(181, sys_setfsgid, 1)
408#define __NR_sysfs 182
409__SYSCALL(182, sys_sysfs, 3)
410#define __NR_ustat 183
411__SYSCALL(183, sys_ustat, 2)
412#define __NR_statfs 184
413__SYSCALL(184, sys_statfs, 2)
414#define __NR_fstatfs 185
415__SYSCALL(185, sys_fstatfs, 2)
416#define __NR_statfs64 186
417__SYSCALL(186, sys_statfs64, 3)
418#define __NR_fstatfs64 187
419__SYSCALL(187, sys_fstatfs64, 3)
420
421/* System */
422
423#define __NR_setrlimit 188
424__SYSCALL(188, sys_setrlimit, 2)
425#define __NR_getrlimit 189
426__SYSCALL(189, sys_getrlimit, 2)
427#define __NR_getrusage 190
428__SYSCALL(190, sys_getrusage, 2)
429#define __NR_futex 191
430__SYSCALL(191, sys_futex, 5)
431#define __NR_gettimeofday 192
432__SYSCALL(192, sys_gettimeofday, 2)
433#define __NR_settimeofday 193
434__SYSCALL(193, sys_settimeofday, 2)
435#define __NR_adjtimex 194
436__SYSCALL(194, sys_adjtimex, 1)
437#define __NR_nanosleep 195
438__SYSCALL(195, sys_nanosleep, 2)
439#define __NR_getgroups 196
440__SYSCALL(196, sys_getgroups, 2)
441#define __NR_setgroups 197
442__SYSCALL(197, sys_setgroups, 2)
443#define __NR_sethostname 198
444__SYSCALL(198, sys_sethostname, 2)
445#define __NR_setdomainname 199
446__SYSCALL(199, sys_setdomainname, 2)
447#define __NR_syslog 200
448__SYSCALL(200, sys_syslog, 3)
449#define __NR_vhangup 201
450__SYSCALL(201, sys_vhangup, 0)
451#define __NR_uselib 202
452__SYSCALL(202, sys_uselib, 1)
453#define __NR_reboot 203
454__SYSCALL(203, sys_reboot, 3)
455#define __NR_quotactl 204
456__SYSCALL(204, sys_quotactl, 4)
457#define __NR_nfsservctl 205
458__SYSCALL(205, sys_nfsservctl, 3)
459#define __NR__sysctl 206
460__SYSCALL(206, sys_sysctl, 1)
461#define __NR_bdflush 207
462__SYSCALL(207, sys_bdflush, 2)
463#define __NR_uname 208
464__SYSCALL(208, sys_newuname, 1)
465#define __NR_sysinfo 209
466__SYSCALL(209, sys_sysinfo, 1)
467#define __NR_init_module 210
468__SYSCALL(210, sys_init_module, 2)
469#define __NR_delete_module 211
470__SYSCALL(211, sys_delete_module, 1)
471
472#define __NR_sched_setparam 212
473__SYSCALL(212, sys_sched_setparam, 2)
474#define __NR_sched_getparam 213
475__SYSCALL(213, sys_sched_getparam, 2)
476#define __NR_sched_setscheduler 214
477__SYSCALL(214, sys_sched_setscheduler, 3)
478#define __NR_sched_getscheduler 215
479__SYSCALL(215, sys_sched_getscheduler, 1)
480#define __NR_sched_get_priority_max 216
481__SYSCALL(216, sys_sched_get_priority_max, 1)
482#define __NR_sched_get_priority_min 217
483__SYSCALL(217, sys_sched_get_priority_min, 1)
484#define __NR_sched_rr_get_interval 218
485__SYSCALL(218, sys_sched_rr_get_interval, 2)
486#define __NR_sched_yield 219
487__SYSCALL(219, sys_sched_yield, 0)
488#define __NR_sigreturn 222
489__SYSCALL(222, xtensa_sigreturn, 0)
490
491/* Signal Handling */
492
493#define __NR_restart_syscall 223
494__SYSCALL(223, sys_restart_syscall, 0)
495#define __NR_sigaltstack 224
496__SYSCALL(224, xtensa_sigaltstack, 2)
497#define __NR_rt_sigreturn 225
498__SYSCALL(225, xtensa_rt_sigreturn, 1)
499#define __NR_rt_sigaction 226
500__SYSCALL(226, sys_rt_sigaction, 4)
501#define __NR_rt_sigprocmask 227
502__SYSCALL(227, sys_rt_sigprocmask, 4)
503#define __NR_rt_sigpending 228
504__SYSCALL(228, sys_rt_sigpending, 2)
505#define __NR_rt_sigtimedwait 229
506__SYSCALL(229, sys_rt_sigtimedwait, 4)
507#define __NR_rt_sigqueueinfo 230
508__SYSCALL(230, sys_rt_sigqueueinfo, 3)
509#define __NR_rt_sigsuspend 231
510__SYSCALL(231, xtensa_rt_sigsuspend, 2)
511
512/* Message */
513
514#define __NR_mq_open 232
515__SYSCALL(232, sys_mq_open, 4)
516#define __NR_mq_unlink 233
517__SYSCALL(233, sys_mq_unlink, 1)
518#define __NR_mq_timedsend 234
519__SYSCALL(234, sys_mq_timedsend, 5)
520#define __NR_mq_timedreceive 235
521__SYSCALL(235, sys_mq_timedreceive, 5)
522#define __NR_mq_notify 236
523__SYSCALL(236, sys_mq_notify, 2)
524#define __NR_mq_getsetattr 237
525__SYSCALL(237, sys_mq_getsetattr, 3)
526#define __NR_available238 238
527__SYSCALL(238, sys_ni_syscall, 0)
528
529/* IO */
530
531#define __NR_io_setup 239
532__SYSCALL(239, sys_io_setup, 2)
533#define __NR_io_destroy 240
534__SYSCALL(240, sys_io_destroy, 1)
535#define __NR_io_submit 241
536__SYSCALL(241, sys_io_submit, 3)
537#define __NR_io_getevents 242
538__SYSCALL(242, sys_io_getevents, 5)
539#define __NR_io_cancel 243
540__SYSCALL(243, sys_io_cancel, 3)
541#define __NR_clock_settime 244
542__SYSCALL(244, sys_clock_settime, 2)
543#define __NR_clock_gettime 245
544__SYSCALL(245, sys_clock_gettime, 2)
545#define __NR_clock_getres 246
546__SYSCALL(246, sys_clock_getres, 2)
547#define __NR_clock_nanosleep 247
548__SYSCALL(247, sys_clock_nanosleep, 4)
549
550/* Timer */
551
552#define __NR_timer_create 248
553__SYSCALL(248, sys_timer_create, 3)
554#define __NR_timer_delete 249
555__SYSCALL(249, sys_timer_delete, 1)
556#define __NR_timer_settime 250
557__SYSCALL(250, sys_timer_settime, 4)
558#define __NR_timer_gettime 251
559__SYSCALL(251, sys_timer_gettime, 2)
560#define __NR_timer_getoverrun 252
561__SYSCALL(252, sys_timer_getoverrun, 1)
562
563/* System */
564
565#define __NR_reserved244 253
566__SYSCALL(253, sys_ni_syscall, 0)
567#define __NR_lookup_dcookie 254
568__SYSCALL(254, sys_lookup_dcookie, 4)
569#define __NR_available255 255
570__SYSCALL(255, sys_ni_syscall, 0)
571#define __NR_add_key 256
572__SYSCALL(256, sys_add_key, 5)
573#define __NR_request_key 257
574__SYSCALL(257, sys_request_key, 5)
575#define __NR_keyctl 258
576__SYSCALL(258, sys_keyctl, 5)
577#define __NR_available259 259
578__SYSCALL(259, sys_ni_syscall, 0)
579
580#define __NR_syscall_count 261
581
582/*
583 * sysxtensa syscall handler
584 *
585 * int sysxtensa (SYS_XTENSA_ATOMIC_SET, ptr, val, unused);
586 * int sysxtensa (SYS_XTENSA_ATOMIC_ADD, ptr, val, unused);
587 * int sysxtensa (SYS_XTENSA_ATOMIC_EXG_ADD, ptr, val, unused);
588 * int sysxtensa (SYS_XTENSA_ATOMIC_CMP_SWP, ptr, oldval, newval);
589 * a2 a6 a3 a4 a5
590 */
591
592#define SYS_XTENSA_RESERVED 0 /* don't use this */
593#define SYS_XTENSA_ATOMIC_SET 1 /* set variable */
594#define SYS_XTENSA_ATOMIC_EXG_ADD 2 /* exchange memory and add */
595#define SYS_XTENSA_ATOMIC_ADD 3 /* add to memory */
596#define SYS_XTENSA_ATOMIC_CMP_SWP 4 /* compare and swap */
597
598#define SYS_XTENSA_COUNT 5 /* count */
599
600#ifdef __KERNEL__
220 601
221/* 602/*
222 * "Conditional" syscalls 603 * "Conditional" syscalls
@@ -230,6 +611,9 @@
230#define __ARCH_WANT_SYS_UTIME 611#define __ARCH_WANT_SYS_UTIME
231#define __ARCH_WANT_SYS_LLSEEK 612#define __ARCH_WANT_SYS_LLSEEK
232#define __ARCH_WANT_SYS_RT_SIGACTION 613#define __ARCH_WANT_SYS_RT_SIGACTION
233#endif /* __KERNEL__ */ 614#define __ARCH_WANT_SYS_RT_SIGSUSPEND
615
616#endif /* __KERNEL__ */
234 617
235#endif /* _XTENSA_UNISTD_H */ 618#endif /* _XTENSA_UNISTD_H */
619
diff --git a/include/asm-xtensa/variant-fsf/core.h b/include/asm-xtensa/variant-fsf/core.h
new file mode 100644
index 000000000000..2f337605c744
--- /dev/null
+++ b/include/asm-xtensa/variant-fsf/core.h
@@ -0,0 +1,359 @@
1/*
2 * Xtensa processor core configuration information.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1999-2006 Tensilica Inc.
9 */
10
11#ifndef _XTENSA_CORE_H
12#define _XTENSA_CORE_H
13
14
15/****************************************************************************
16 Parameters Useful for Any Code, USER or PRIVILEGED
17 ****************************************************************************/
18
19/*
20 * Note: Macros of the form XCHAL_HAVE_*** have a value of 1 if the option is
21 * configured, and a value of 0 otherwise. These macros are always defined.
22 */
23
24
25/*----------------------------------------------------------------------
26 ISA
27 ----------------------------------------------------------------------*/
28
29#define XCHAL_HAVE_BE 1 /* big-endian byte ordering */
30#define XCHAL_HAVE_WINDOWED 1 /* windowed registers option */
31#define XCHAL_NUM_AREGS 64 /* num of physical addr regs */
32#define XCHAL_NUM_AREGS_LOG2 6 /* log2(XCHAL_NUM_AREGS) */
33#define XCHAL_MAX_INSTRUCTION_SIZE 3 /* max instr bytes (3..8) */
34#define XCHAL_HAVE_DEBUG 1 /* debug option */
35#define XCHAL_HAVE_DENSITY 1 /* 16-bit instructions */
36#define XCHAL_HAVE_LOOPS 1 /* zero-overhead loops */
37#define XCHAL_HAVE_NSA 1 /* NSA/NSAU instructions */
38#define XCHAL_HAVE_MINMAX 0 /* MIN/MAX instructions */
39#define XCHAL_HAVE_SEXT 0 /* SEXT instruction */
40#define XCHAL_HAVE_CLAMPS 0 /* CLAMPS instruction */
41#define XCHAL_HAVE_MUL16 0 /* MUL16S/MUL16U instructions */
42#define XCHAL_HAVE_MUL32 0 /* MULL instruction */
43#define XCHAL_HAVE_MUL32_HIGH 0 /* MULUH/MULSH instructions */
44#define XCHAL_HAVE_L32R 1 /* L32R instruction */
45#define XCHAL_HAVE_ABSOLUTE_LITERALS 1 /* non-PC-rel (extended) L32R */
46#define XCHAL_HAVE_CONST16 0 /* CONST16 instruction */
47#define XCHAL_HAVE_ADDX 1 /* ADDX#/SUBX# instructions */
48#define XCHAL_HAVE_WIDE_BRANCHES 0 /* B*.W18 or B*.W15 instr's */
49#define XCHAL_HAVE_PREDICTED_BRANCHES 0 /* B[EQ/EQZ/NE/NEZ]T instr's */
50#define XCHAL_HAVE_CALL4AND12 1 /* (obsolete option) */
51#define XCHAL_HAVE_ABS 1 /* ABS instruction */
52/*#define XCHAL_HAVE_POPC 0*/ /* POPC instruction */
53/*#define XCHAL_HAVE_CRC 0*/ /* CRC instruction */
54#define XCHAL_HAVE_RELEASE_SYNC 0 /* L32AI/S32RI instructions */
55#define XCHAL_HAVE_S32C1I 0 /* S32C1I instruction */
56#define XCHAL_HAVE_SPECULATION 0 /* speculation */
57#define XCHAL_HAVE_FULL_RESET 1 /* all regs/state reset */
58#define XCHAL_NUM_CONTEXTS 1 /* */
59#define XCHAL_NUM_MISC_REGS 2 /* num of scratch regs (0..4) */
60#define XCHAL_HAVE_TAP_MASTER 0 /* JTAG TAP control instr's */
61#define XCHAL_HAVE_PRID 1 /* processor ID register */
62#define XCHAL_HAVE_THREADPTR 1 /* THREADPTR register */
63#define XCHAL_HAVE_BOOLEANS 0 /* boolean registers */
64#define XCHAL_HAVE_CP 0 /* CPENABLE reg (coprocessor) */
65#define XCHAL_CP_MAXCFG 0 /* max allowed cp id plus one */
66#define XCHAL_HAVE_MAC16 0 /* MAC16 package */
67#define XCHAL_HAVE_VECTORFPU2005 0 /* vector floating-point pkg */
68#define XCHAL_HAVE_FP 0 /* floating point pkg */
69#define XCHAL_HAVE_VECTRA1 0 /* Vectra I pkg */
70#define XCHAL_HAVE_VECTRALX 0 /* Vectra LX pkg */
71#define XCHAL_HAVE_HIFI2 0 /* HiFi2 Audio Engine pkg */
72
73
74/*----------------------------------------------------------------------
75 MISC
76 ----------------------------------------------------------------------*/
77
78#define XCHAL_NUM_WRITEBUFFER_ENTRIES 4 /* size of write buffer */
79#define XCHAL_INST_FETCH_WIDTH 4 /* instr-fetch width in bytes */
80#define XCHAL_DATA_WIDTH 4 /* data width in bytes */
81/* In T1050, applies to selected core load and store instructions (see ISA): */
82#define XCHAL_UNALIGNED_LOAD_EXCEPTION 1 /* unaligned loads cause exc. */
83#define XCHAL_UNALIGNED_STORE_EXCEPTION 1 /* unaligned stores cause exc.*/
84
85#define XCHAL_CORE_ID "fsf" /* alphanum core name
86 (CoreID) set in the Xtensa
87 Processor Generator */
88
89#define XCHAL_BUILD_UNIQUE_ID 0x00006700 /* 22-bit sw build ID */
90
91/*
92 * These definitions describe the hardware targeted by this software.
93 */
94#define XCHAL_HW_CONFIGID0 0xC103C3FF /* ConfigID hi 32 bits*/
95#define XCHAL_HW_CONFIGID1 0x0C006700 /* ConfigID lo 32 bits*/
96#define XCHAL_HW_VERSION_NAME "LX2.0.0" /* full version name */
97#define XCHAL_HW_VERSION_MAJOR 2200 /* major ver# of targeted hw */
98#define XCHAL_HW_VERSION_MINOR 0 /* minor ver# of targeted hw */
99#define XTHAL_HW_REL_LX2 1
100#define XTHAL_HW_REL_LX2_0 1
101#define XTHAL_HW_REL_LX2_0_0 1
102#define XCHAL_HW_CONFIGID_RELIABLE 1
103/* If software targets a *range* of hardware versions, these are the bounds: */
104#define XCHAL_HW_MIN_VERSION_MAJOR 2200 /* major v of earliest tgt hw */
105#define XCHAL_HW_MIN_VERSION_MINOR 0 /* minor v of earliest tgt hw */
106#define XCHAL_HW_MAX_VERSION_MAJOR 2200 /* major v of latest tgt hw */
107#define XCHAL_HW_MAX_VERSION_MINOR 0 /* minor v of latest tgt hw */
108
109
110/*----------------------------------------------------------------------
111 CACHE
112 ----------------------------------------------------------------------*/
113
114#define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
115#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
116#define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
117#define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
118
119#define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
120#define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
121
122#define XCHAL_DCACHE_IS_WRITEBACK 0 /* writeback feature */
123
124
125
126
127/****************************************************************************
128 Parameters Useful for PRIVILEGED (Supervisory or Non-Virtualized) Code
129 ****************************************************************************/
130
131
132#ifndef XTENSA_HAL_NON_PRIVILEGED_ONLY
133
134/*----------------------------------------------------------------------
135 CACHE
136 ----------------------------------------------------------------------*/
137
138#define XCHAL_HAVE_PIF 1 /* any outbound PIF present */
139
140/* If present, cache size in bytes == (ways * 2^(linewidth + setwidth)). */
141
142/* Number of cache sets in log2(lines per way): */
143#define XCHAL_ICACHE_SETWIDTH 8
144#define XCHAL_DCACHE_SETWIDTH 8
145
146/* Cache set associativity (number of ways): */
147#define XCHAL_ICACHE_WAYS 2
148#define XCHAL_DCACHE_WAYS 2
149
150/* Cache features: */
151#define XCHAL_ICACHE_LINE_LOCKABLE 0
152#define XCHAL_DCACHE_LINE_LOCKABLE 0
153#define XCHAL_ICACHE_ECC_PARITY 0
154#define XCHAL_DCACHE_ECC_PARITY 0
155
156/* Number of encoded cache attr bits (see <xtensa/hal.h> for decoded bits): */
157#define XCHAL_CA_BITS 4
158
159
160/*----------------------------------------------------------------------
161 INTERNAL I/D RAM/ROMs and XLMI
162 ----------------------------------------------------------------------*/
163
164#define XCHAL_NUM_INSTROM 0 /* number of core instr. ROMs */
165#define XCHAL_NUM_INSTRAM 0 /* number of core instr. RAMs */
166#define XCHAL_NUM_DATAROM 0 /* number of core data ROMs */
167#define XCHAL_NUM_DATARAM 0 /* number of core data RAMs */
168#define XCHAL_NUM_URAM 0 /* number of core unified RAMs*/
169#define XCHAL_NUM_XLMI 0 /* number of core XLMI ports */
170
171
172/*----------------------------------------------------------------------
173 INTERRUPTS and TIMERS
174 ----------------------------------------------------------------------*/
175
176#define XCHAL_HAVE_INTERRUPTS 1 /* interrupt option */
177#define XCHAL_HAVE_HIGHPRI_INTERRUPTS 1 /* med/high-pri. interrupts */
178#define XCHAL_HAVE_NMI 0 /* non-maskable interrupt */
179#define XCHAL_HAVE_CCOUNT 1 /* CCOUNT reg. (timer option) */
180#define XCHAL_NUM_TIMERS 3 /* number of CCOMPAREn regs */
181#define XCHAL_NUM_INTERRUPTS 17 /* number of interrupts */
182#define XCHAL_NUM_INTERRUPTS_LOG2 5 /* ceil(log2(NUM_INTERRUPTS)) */
183#define XCHAL_NUM_EXTINTERRUPTS 10 /* num of external interrupts */
184#define XCHAL_NUM_INTLEVELS 4 /* number of interrupt levels
185 (not including level zero) */
186#define XCHAL_EXCM_LEVEL 1 /* level masked by PS.EXCM */
187 /* (always 1 in XEA1; levels 2 .. EXCM_LEVEL are "medium priority") */
188
189/* Masks of interrupts at each interrupt level: */
190#define XCHAL_INTLEVEL1_MASK 0x000064F9
191#define XCHAL_INTLEVEL2_MASK 0x00008902
192#define XCHAL_INTLEVEL3_MASK 0x00011204
193#define XCHAL_INTLEVEL4_MASK 0x00000000
194#define XCHAL_INTLEVEL5_MASK 0x00000000
195#define XCHAL_INTLEVEL6_MASK 0x00000000
196#define XCHAL_INTLEVEL7_MASK 0x00000000
197
198/* Masks of interrupts at each range 1..n of interrupt levels: */
199#define XCHAL_INTLEVEL1_ANDBELOW_MASK 0x000064F9
200#define XCHAL_INTLEVEL2_ANDBELOW_MASK 0x0000EDFB
201#define XCHAL_INTLEVEL3_ANDBELOW_MASK 0x0001FFFF
202#define XCHAL_INTLEVEL4_ANDBELOW_MASK 0x0001FFFF
203#define XCHAL_INTLEVEL5_ANDBELOW_MASK 0x0001FFFF
204#define XCHAL_INTLEVEL6_ANDBELOW_MASK 0x0001FFFF
205#define XCHAL_INTLEVEL7_ANDBELOW_MASK 0x0001FFFF
206
207/* Level of each interrupt: */
208#define XCHAL_INT0_LEVEL 1
209#define XCHAL_INT1_LEVEL 2
210#define XCHAL_INT2_LEVEL 3
211#define XCHAL_INT3_LEVEL 1
212#define XCHAL_INT4_LEVEL 1
213#define XCHAL_INT5_LEVEL 1
214#define XCHAL_INT6_LEVEL 1
215#define XCHAL_INT7_LEVEL 1
216#define XCHAL_INT8_LEVEL 2
217#define XCHAL_INT9_LEVEL 3
218#define XCHAL_INT10_LEVEL 1
219#define XCHAL_INT11_LEVEL 2
220#define XCHAL_INT12_LEVEL 3
221#define XCHAL_INT13_LEVEL 1
222#define XCHAL_INT14_LEVEL 1
223#define XCHAL_INT15_LEVEL 2
224#define XCHAL_INT16_LEVEL 3
225#define XCHAL_DEBUGLEVEL 4 /* debug interrupt level */
226#define XCHAL_HAVE_DEBUG_EXTERN_INT 0 /* OCD external db interrupt */
227
228/* Type of each interrupt: */
229#define XCHAL_INT0_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
230#define XCHAL_INT1_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
231#define XCHAL_INT2_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
232#define XCHAL_INT3_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
233#define XCHAL_INT4_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
234#define XCHAL_INT5_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
235#define XCHAL_INT6_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
236#define XCHAL_INT7_TYPE XTHAL_INTTYPE_EXTERN_EDGE
237#define XCHAL_INT8_TYPE XTHAL_INTTYPE_EXTERN_EDGE
238#define XCHAL_INT9_TYPE XTHAL_INTTYPE_EXTERN_EDGE
239#define XCHAL_INT10_TYPE XTHAL_INTTYPE_TIMER
240#define XCHAL_INT11_TYPE XTHAL_INTTYPE_TIMER
241#define XCHAL_INT12_TYPE XTHAL_INTTYPE_TIMER
242#define XCHAL_INT13_TYPE XTHAL_INTTYPE_SOFTWARE
243#define XCHAL_INT14_TYPE XTHAL_INTTYPE_SOFTWARE
244#define XCHAL_INT15_TYPE XTHAL_INTTYPE_SOFTWARE
245#define XCHAL_INT16_TYPE XTHAL_INTTYPE_SOFTWARE
246
247/* Masks of interrupts for each type of interrupt: */
248#define XCHAL_INTTYPE_MASK_UNCONFIGURED 0xFFFE0000
249#define XCHAL_INTTYPE_MASK_SOFTWARE 0x0001E000
250#define XCHAL_INTTYPE_MASK_EXTERN_EDGE 0x00000380
251#define XCHAL_INTTYPE_MASK_EXTERN_LEVEL 0x0000007F
252#define XCHAL_INTTYPE_MASK_TIMER 0x00001C00
253#define XCHAL_INTTYPE_MASK_NMI 0x00000000
254#define XCHAL_INTTYPE_MASK_WRITE_ERROR 0x00000000
255
256/* Interrupt numbers assigned to specific interrupt sources: */
257#define XCHAL_TIMER0_INTERRUPT 10 /* CCOMPARE0 */
258#define XCHAL_TIMER1_INTERRUPT 11 /* CCOMPARE1 */
259#define XCHAL_TIMER2_INTERRUPT 12 /* CCOMPARE2 */
260#define XCHAL_TIMER3_INTERRUPT XTHAL_TIMER_UNCONFIGURED
261
262/* Interrupt numbers for levels at which only one interrupt is configured: */
263/* (There are many interrupts each at level(s) 1, 2, 3.) */
264
265
266/*
267 * External interrupt vectors/levels.
268 * These macros describe how Xtensa processor interrupt numbers
269 * (as numbered internally, eg. in INTERRUPT and INTENABLE registers)
270 * map to external BInterrupt<n> pins, for those interrupts
271 * configured as external (level-triggered, edge-triggered, or NMI).
272 * See the Xtensa processor databook for more details.
273 */
274
275/* Core interrupt numbers mapped to each EXTERNAL interrupt number: */
276#define XCHAL_EXTINT0_NUM 0 /* (intlevel 1) */
277#define XCHAL_EXTINT1_NUM 1 /* (intlevel 2) */
278#define XCHAL_EXTINT2_NUM 2 /* (intlevel 3) */
279#define XCHAL_EXTINT3_NUM 3 /* (intlevel 1) */
280#define XCHAL_EXTINT4_NUM 4 /* (intlevel 1) */
281#define XCHAL_EXTINT5_NUM 5 /* (intlevel 1) */
282#define XCHAL_EXTINT6_NUM 6 /* (intlevel 1) */
283#define XCHAL_EXTINT7_NUM 7 /* (intlevel 1) */
284#define XCHAL_EXTINT8_NUM 8 /* (intlevel 2) */
285#define XCHAL_EXTINT9_NUM 9 /* (intlevel 3) */
286
287
288/*----------------------------------------------------------------------
289 EXCEPTIONS and VECTORS
290 ----------------------------------------------------------------------*/
291
292#define XCHAL_XEA_VERSION 2 /* Xtensa Exception Architecture
293 number: 1 == XEA1 (old)
294 2 == XEA2 (new)
295 0 == XEAX (extern) */
296#define XCHAL_HAVE_XEA1 0 /* Exception Architecture 1 */
297#define XCHAL_HAVE_XEA2 1 /* Exception Architecture 2 */
298#define XCHAL_HAVE_XEAX 0 /* External Exception Arch. */
299#define XCHAL_HAVE_EXCEPTIONS 1 /* exception option */
300#define XCHAL_HAVE_MEM_ECC_PARITY 0 /* local memory ECC/parity */
301
302#define XCHAL_RESET_VECTOR_VADDR 0xFE000020
303#define XCHAL_RESET_VECTOR_PADDR 0xFE000020
304#define XCHAL_USER_VECTOR_VADDR 0xD0000220
305#define XCHAL_USER_VECTOR_PADDR 0x00000220
306#define XCHAL_KERNEL_VECTOR_VADDR 0xD0000200
307#define XCHAL_KERNEL_VECTOR_PADDR 0x00000200
308#define XCHAL_DOUBLEEXC_VECTOR_VADDR 0xD0000290
309#define XCHAL_DOUBLEEXC_VECTOR_PADDR 0x00000290
310#define XCHAL_WINDOW_VECTORS_VADDR 0xD0000000
311#define XCHAL_WINDOW_VECTORS_PADDR 0x00000000
312#define XCHAL_INTLEVEL2_VECTOR_VADDR 0xD0000240
313#define XCHAL_INTLEVEL2_VECTOR_PADDR 0x00000240
314#define XCHAL_INTLEVEL3_VECTOR_VADDR 0xD0000250
315#define XCHAL_INTLEVEL3_VECTOR_PADDR 0x00000250
316#define XCHAL_INTLEVEL4_VECTOR_VADDR 0xFE000520
317#define XCHAL_INTLEVEL4_VECTOR_PADDR 0xFE000520
318#define XCHAL_DEBUG_VECTOR_VADDR XCHAL_INTLEVEL4_VECTOR_VADDR
319#define XCHAL_DEBUG_VECTOR_PADDR XCHAL_INTLEVEL4_VECTOR_PADDR
320
321
322/*----------------------------------------------------------------------
323 DEBUG
324 ----------------------------------------------------------------------*/
325
326#define XCHAL_HAVE_OCD 1 /* OnChipDebug option */
327#define XCHAL_NUM_IBREAK 2 /* number of IBREAKn regs */
328#define XCHAL_NUM_DBREAK 2 /* number of DBREAKn regs */
329#define XCHAL_HAVE_OCD_DIR_ARRAY 1 /* faster OCD option */
330
331
332/*----------------------------------------------------------------------
333 MMU
334 ----------------------------------------------------------------------*/
335
336/* See <xtensa/config/core-matmap.h> header file for more details. */
337
338#define XCHAL_HAVE_TLBS 1 /* inverse of HAVE_CACHEATTR */
339#define XCHAL_HAVE_SPANNING_WAY 0 /* one way maps I+D 4GB vaddr */
340#define XCHAL_HAVE_IDENTITY_MAP 0 /* vaddr == paddr always */
341#define XCHAL_HAVE_CACHEATTR 0 /* CACHEATTR register present */
342#define XCHAL_HAVE_MIMIC_CACHEATTR 0 /* region protection */
343#define XCHAL_HAVE_XLT_CACHEATTR 0 /* region prot. w/translation */
344#define XCHAL_HAVE_PTP_MMU 1 /* full MMU (with page table
345 [autorefill] and protection)
346 usable for an MMU-based OS */
347/* If none of the above last 4 are set, it's a custom TLB configuration. */
348#define XCHAL_ITLB_ARF_ENTRIES_LOG2 2 /* log2(autorefill way size) */
349#define XCHAL_DTLB_ARF_ENTRIES_LOG2 2 /* log2(autorefill way size) */
350
351#define XCHAL_MMU_ASID_BITS 8 /* number of bits in ASIDs */
352#define XCHAL_MMU_RINGS 4 /* number of rings (1..4) */
353#define XCHAL_MMU_RING_BITS 2 /* num of bits in RING field */
354
355#endif /* !XTENSA_HAL_NON_PRIVILEGED_ONLY */
356
357
358#endif /* _XTENSA_CORE_CONFIGURATION_H */
359
diff --git a/include/asm-xtensa/variant-fsf/tie.h b/include/asm-xtensa/variant-fsf/tie.h
new file mode 100644
index 000000000000..a73c71664918
--- /dev/null
+++ b/include/asm-xtensa/variant-fsf/tie.h
@@ -0,0 +1,22 @@
1/*
2 * Xtensa processor core configuration information.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 1999-2006 Tensilica Inc.
9 */
10
11#ifndef XTENSA_TIE_H
12#define XTENSA_TIE_H
13
14/*----------------------------------------------------------------------
15 COPROCESSORS and EXTRA STATE
16 ----------------------------------------------------------------------*/
17
18#define XCHAL_CP_NUM 0 /* number of coprocessors */
19#define XCHAL_CP_MASK 0x00
20
21#endif /*XTENSA_CONFIG_TIE_H*/
22
diff --git a/include/asm-xtensa/xtensa/cacheasm.h b/include/asm-xtensa/xtensa/cacheasm.h
deleted file mode 100644
index 0cdbb0bf180e..000000000000
--- a/include/asm-xtensa/xtensa/cacheasm.h
+++ /dev/null
@@ -1,708 +0,0 @@
1#ifndef XTENSA_CACHEASM_H
2#define XTENSA_CACHEASM_H
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/cacheasm.h -- assembler-specific cache
8 * related definitions that depend on CORE configuration.
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 *
14 * Copyright (C) 2002 Tensilica Inc.
15 */
16
17
18#include <xtensa/coreasm.h>
19
20
21/*
22 * This header file defines assembler macros of the form:
23 * <x>cache_<func>
24 * where <x> is 'i' or 'd' for instruction and data caches,
25 * and <func> indicates the function of the macro.
26 *
27 * The following functions <func> are defined,
28 * and apply only to the specified cache (I or D):
29 *
30 * reset
31 * Resets the cache.
32 *
33 * sync
34 * Makes sure any previous cache instructions have been completed;
35 * ie. makes sure any previous cache control operations
36 * have had full effect and been synchronized to memory.
37 * Eg. any invalidate completed [so as not to generate a hit],
38 * any writebacks or other pipelined writes written to memory, etc.
39 *
40 * invalidate_line (single cache line)
41 * invalidate_region (specified memory range)
42 * invalidate_all (entire cache)
43 * Invalidates all cache entries that cache
44 * data from the specified memory range.
45 * NOTE: locked entries are not invalidated.
46 *
47 * writeback_line (single cache line)
48 * writeback_region (specified memory range)
49 * writeback_all (entire cache)
50 * Writes back to memory all dirty cache entries
51 * that cache data from the specified memory range,
52 * and marks these entries as clean.
53 * NOTE: on some future implementations, this might
54 * also invalidate.
55 * NOTE: locked entries are written back, but never invalidated.
56 * NOTE: instruction caches never implement writeback.
57 *
58 * writeback_inv_line (single cache line)
59 * writeback_inv_region (specified memory range)
60 * writeback_inv_all (entire cache)
61 * Writes back to memory all dirty cache entries
62 * that cache data from the specified memory range,
63 * and invalidates these entries (including all clean
64 * cache entries that cache data from that range).
65 * NOTE: locked entries are written back but not invalidated.
66 * NOTE: instruction caches never implement writeback.
67 *
68 * lock_line (single cache line)
69 * lock_region (specified memory range)
70 * Prefetch and lock the specified memory range into cache.
71 * NOTE: if any part of the specified memory range cannot
72 * be locked, a ??? exception occurs. These macros don't
73 * do anything special (yet anyway) to handle this situation.
74 *
75 * unlock_line (single cache line)
76 * unlock_region (specified memory range)
77 * unlock_all (entire cache)
78 * Unlock cache entries that cache the specified memory range.
79 * Entries not already locked are unaffected.
80 */
81
82
83
84/*************************** GENERIC -- ALL CACHES ***************************/
85
86
87/*
88 * The following macros assume the following cache size/parameter limits
89 * in the current Xtensa core implementation:
90 * cache size: 1024 bytes minimum
91 * line size: 16 - 64 bytes
92 * way count: 1 - 4
93 *
94 * Minimum entries per way (ie. per associativity) = 1024 / 64 / 4 = 4
95 * Hence the assumption that each loop can execute four cache instructions.
96 *
97 * Correspondingly, the offset range of instructions is assumed able to cover
98 * four lines, ie. offsets {0,1,2,3} * line_size are assumed valid for
99 * both hit and indexed cache instructions. Ie. these offsets are all
100 * valid: 0, 16, 32, 48, 64, 96, 128, 192 (for line sizes 16, 32, 64).
101 * This is true of all original cache instructions
102 * (dhi, ihi, dhwb, dhwbi, dii, iii) which have offsets
103 * of 0 to 1020 in multiples of 4 (ie. 8 bits shifted by 2).
104 * This is also true of subsequent cache instructions
105 * (dhu, ihu, diu, iiu, diwb, diwbi, dpfl, ipfl) which have offsets
106 * of 0 to 240 in multiples of 16 (ie. 4 bits shifted by 4).
107 *
108 * (Maximum cache size, currently 32k, doesn't affect the following macros.
109 * Cache ways > MMU min page size cause aliasing but that's another matter.)
110 */
111
112
113
114/*
115 * Macro to apply an 'indexed' cache instruction to the entire cache.
116 *
117 * Parameters:
118 * cainst instruction/ that takes an address register parameter
119 * and an offset parameter (in range 0 .. 3*linesize).
120 * size size of cache in bytes
121 * linesize size of cache line in bytes
122 * assoc_or1 number of associativities (ways/sets) in cache
123 * if all sets affected by cainst,
124 * or 1 if only one set (or not all sets) of the cache
125 * is affected by cainst (eg. DIWB or DIWBI [not yet ISA defined]).
126 * aa, ab unique address registers (temporaries)
127 */
128
129 .macro cache_index_all cainst, size, linesize, assoc_or1, aa, ab
130
131 // Sanity-check on cache parameters:
132 .ifne (\size % (\linesize * \assoc_or1 * 4))
133 .err // cache configuration outside expected/supported range!
134 .endif
135
136 // \size byte cache, \linesize byte lines, \assoc_or1 way(s) affected by each \cainst.
137 movi \aa, (\size / (\linesize * \assoc_or1 * 4))
138 // Possible improvement: need only loop if \aa > 1 ;
139 // however that particular condition is highly unlikely.
140 movi \ab, 0 // to iterate over cache
141 floop \aa, cachex\@
142 \cainst \ab, 0*\linesize
143 \cainst \ab, 1*\linesize
144 \cainst \ab, 2*\linesize
145 \cainst \ab, 3*\linesize
146 addi \ab, \ab, 4*\linesize // move to next line
147 floopend \aa, cachex\@
148
149 .endm
150
151
152/*
153 * Macro to apply a 'hit' cache instruction to a memory region,
154 * ie. to any cache entries that cache a specified portion (region) of memory.
155 * Takes care of the unaligned cases, ie. may apply to one
156 * more cache line than $asize / lineSize if $aaddr is not aligned.
157 *
158 *
159 * Parameters are:
160 * cainst instruction/macro that takes an address register parameter
161 * and an offset parameter (currently always zero)
162 * and generates a cache instruction (eg. "dhi", "dhwb", "ihi", etc.)
163 * linesize_log2 log2(size of cache line in bytes)
164 * addr register containing start address of region (clobbered)
165 * asize register containing size of the region in bytes (clobbered)
166 * askew unique register used as temporary
167 *
168 * !?!?! 2DO: optimization: iterate max(cache_size and \asize) / linesize
169 */
170
171 .macro cache_hit_region cainst, linesize_log2, addr, asize, askew
172
173 // Make \asize the number of iterations:
174 extui \askew, \addr, 0, \linesize_log2 // get unalignment amount of \addr
175 add \asize, \asize, \askew // ... and add it to \asize
176 addi \asize, \asize, (1 << \linesize_log2) - 1 // round up!
177 srli \asize, \asize, \linesize_log2
178
179 // Iterate over region:
180 floopnez \asize, cacheh\@
181 \cainst \addr, 0
182 addi \addr, \addr, (1 << \linesize_log2) // move to next line
183 floopend \asize, cacheh\@
184
185 .endm
186
187
188
189
190
191/*************************** INSTRUCTION CACHE ***************************/
192
193
194/*
195 * Reset/initialize the instruction cache by simply invalidating it:
196 * (need to unlock first also, if cache locking implemented):
197 *
198 * Parameters:
199 * aa, ab unique address registers (temporaries)
200 */
201 .macro icache_reset aa, ab
202 icache_unlock_all \aa, \ab
203 icache_invalidate_all \aa, \ab
204 .endm
205
206
207/*
208 * Synchronize after an instruction cache operation,
209 * to be sure everything is in sync with memory as to be
210 * expected following any previous instruction cache control operations.
211 *
212 * Parameters are:
213 * ar an address register (temporary) (currently unused, but may be used in future)
214 */
215 .macro icache_sync ar
216#if XCHAL_ICACHE_SIZE > 0
217 isync
218#endif
219 .endm
220
221
222
223/*
224 * Invalidate a single line of the instruction cache.
225 * Parameters are:
226 * ar address register that contains (virtual) address to invalidate
227 * (may get clobbered in a future implementation, but not currently)
228 * offset (optional) offset to add to \ar to compute effective address to invalidate
229 * (note: some number of lsbits are ignored)
230 */
231 .macro icache_invalidate_line ar, offset
232#if XCHAL_ICACHE_SIZE > 0
233 ihi \ar, \offset // invalidate icache line
234 /*
235 * NOTE: in some version of the silicon [!!!SHOULD HAVE BEEN DOCUMENTED!!!]
236 * 'ihi' doesn't work, so it had been replaced with 'iii'
237 * (which would just invalidate more than it should,
238 * which should be okay other than the performance hit
239 * because cache locking did not exist in that version,
240 * unless user somehow relies on something being cached).
241 * [WHAT VERSION IS IT!!?!?
242 * IS THERE ANY WAY TO TEST FOR THAT HERE, TO OUTPUT 'III' ONLY IF NEEDED!?!?].
243 *
244 * iii \ar, \offset
245 */
246 icache_sync \ar
247#endif
248 .endm
249
250
251
252
253/*
254 * Invalidate instruction cache entries that cache a specified portion of memory.
255 * Parameters are:
256 * astart start address (register gets clobbered)
257 * asize size of the region in bytes (register gets clobbered)
258 * ac unique register used as temporary
259 */
260 .macro icache_invalidate_region astart, asize, ac
261#if XCHAL_ICACHE_SIZE > 0
262 // Instruction cache region invalidation:
263 cache_hit_region ihi, XCHAL_ICACHE_LINEWIDTH, \astart, \asize, \ac
264 icache_sync \ac
265 // End of instruction cache region invalidation
266#endif
267 .endm
268
269
270
271/*
272 * Invalidate entire instruction cache.
273 *
274 * Parameters:
275 * aa, ab unique address registers (temporaries)
276 */
277 .macro icache_invalidate_all aa, ab
278#if XCHAL_ICACHE_SIZE > 0
279 // Instruction cache invalidation:
280 cache_index_all iii, XCHAL_ICACHE_SIZE, XCHAL_ICACHE_LINESIZE, XCHAL_ICACHE_WAYS, \aa, \ab
281 icache_sync \aa
282 // End of instruction cache invalidation
283#endif
284 .endm
285
286
287
288/*
289 * Lock (prefetch & lock) a single line of the instruction cache.
290 *
291 * Parameters are:
292 * ar address register that contains (virtual) address to lock
293 * (may get clobbered in a future implementation, but not currently)
294 * offset offset to add to \ar to compute effective address to lock
295 * (note: some number of lsbits are ignored)
296 */
297 .macro icache_lock_line ar, offset
298#if XCHAL_ICACHE_SIZE > 0 && XCHAL_ICACHE_LINE_LOCKABLE
299 ipfl \ar, \offset /* prefetch and lock icache line */
300 icache_sync \ar
301#endif
302 .endm
303
304
305
306/*
307 * Lock (prefetch & lock) a specified portion of memory into the instruction cache.
308 * Parameters are:
309 * astart start address (register gets clobbered)
310 * asize size of the region in bytes (register gets clobbered)
311 * ac unique register used as temporary
312 */
313 .macro icache_lock_region astart, asize, ac
314#if XCHAL_ICACHE_SIZE > 0 && XCHAL_ICACHE_LINE_LOCKABLE
315 // Instruction cache region lock:
316 cache_hit_region ipfl, XCHAL_ICACHE_LINEWIDTH, \astart, \asize, \ac
317 icache_sync \ac
318 // End of instruction cache region lock
319#endif
320 .endm
321
322
323
324/*
325 * Unlock a single line of the instruction cache.
326 *
327 * Parameters are:
328 * ar address register that contains (virtual) address to unlock
329 * (may get clobbered in a future implementation, but not currently)
330 * offset offset to add to \ar to compute effective address to unlock
331 * (note: some number of lsbits are ignored)
332 */
333 .macro icache_unlock_line ar, offset
334#if XCHAL_ICACHE_SIZE > 0 && XCHAL_ICACHE_LINE_LOCKABLE
335 ihu \ar, \offset /* unlock icache line */
336 icache_sync \ar
337#endif
338 .endm
339
340
341
342/*
343 * Unlock a specified portion of memory from the instruction cache.
344 * Parameters are:
345 * astart start address (register gets clobbered)
346 * asize size of the region in bytes (register gets clobbered)
347 * ac unique register used as temporary
348 */
349 .macro icache_unlock_region astart, asize, ac
350#if XCHAL_ICACHE_SIZE > 0 && XCHAL_ICACHE_LINE_LOCKABLE
351 // Instruction cache region unlock:
352 cache_hit_region ihu, XCHAL_ICACHE_LINEWIDTH, \astart, \asize, \ac
353 icache_sync \ac
354 // End of instruction cache region unlock
355#endif
356 .endm
357
358
359
360/*
361 * Unlock entire instruction cache.
362 *
363 * Parameters:
364 * aa, ab unique address registers (temporaries)
365 */
366 .macro icache_unlock_all aa, ab
367#if XCHAL_ICACHE_SIZE > 0 && XCHAL_ICACHE_LINE_LOCKABLE
368 // Instruction cache unlock:
369 cache_index_all iiu, XCHAL_ICACHE_SIZE, XCHAL_ICACHE_LINESIZE, 1, \aa, \ab
370 icache_sync \aa
371 // End of instruction cache unlock
372#endif
373 .endm
374
375
376
377
378
379/*************************** DATA CACHE ***************************/
380
381
382
383/*
384 * Reset/initialize the data cache by simply invalidating it
385 * (need to unlock first also, if cache locking implemented):
386 *
387 * Parameters:
388 * aa, ab unique address registers (temporaries)
389 */
390 .macro dcache_reset aa, ab
391 dcache_unlock_all \aa, \ab
392 dcache_invalidate_all \aa, \ab
393 .endm
394
395
396
397
398/*
399 * Synchronize after a data cache operation,
400 * to be sure everything is in sync with memory as to be
401 * expected following any previous data cache control operations.
402 *
403 * Parameters are:
404 * ar an address register (temporary) (currently unused, but may be used in future)
405 */
406 .macro dcache_sync ar
407#if XCHAL_DCACHE_SIZE > 0
408 // This previous sequence errs on the conservative side (too much so); a DSYNC should be sufficient:
409 //memw // synchronize data cache changes relative to subsequent memory accesses
410 //isync // be conservative and ISYNC as well (just to be sure)
411
412 dsync
413#endif
414 .endm
415
416
417
418/*
419 * Synchronize after a data store operation,
420 * to be sure the stored data is completely off the processor
421 * (and assuming there is no buffering outside the processor,
422 * that the data is in memory). This may be required to
423 * ensure that the processor's write buffers are emptied.
424 * A MEMW followed by a read guarantees this, by definition.
425 * We also try to make sure the read itself completes.
426 *
427 * Parameters are:
428 * ar an address register (temporary)
429 */
430 .macro write_sync ar
431 memw // ensure previous memory accesses are complete prior to subsequent memory accesses
432 l32i \ar, sp, 0 // completing this read ensures any previous write has completed, because of MEMW
433 //slot
434 add \ar, \ar, \ar // use the result of the read to help ensure the read completes (in future architectures)
435 .endm
436
437
438/*
439 * Invalidate a single line of the data cache.
440 * Parameters are:
441 * ar address register that contains (virtual) address to invalidate
442 * (may get clobbered in a future implementation, but not currently)
443 * offset (optional) offset to add to \ar to compute effective address to invalidate
444 * (note: some number of lsbits are ignored)
445 */
446 .macro dcache_invalidate_line ar, offset
447#if XCHAL_DCACHE_SIZE > 0
448 dhi \ar, \offset
449 dcache_sync \ar
450#endif
451 .endm
452
453
454
455
456
457/*
458 * Invalidate data cache entries that cache a specified portion of memory.
459 * Parameters are:
460 * astart start address (register gets clobbered)
461 * asize size of the region in bytes (register gets clobbered)
462 * ac unique register used as temporary
463 */
464 .macro dcache_invalidate_region astart, asize, ac
465#if XCHAL_DCACHE_SIZE > 0
466 // Data cache region invalidation:
467 cache_hit_region dhi, XCHAL_DCACHE_LINEWIDTH, \astart, \asize, \ac
468 dcache_sync \ac
469 // End of data cache region invalidation
470#endif
471 .endm
472
473
474
475#if 0
476/*
477 * This is a work-around for a bug in SiChip1 (???).
478 * There should be a proper mechanism for not outputting
479 * these instructions when not needed.
480 * To enable work-around, uncomment this and replace 'dii'
481 * with 'dii_s1' everywhere, eg. in dcache_invalidate_all
482 * macro below.
483 */
484 .macro dii_s1 ar, offset
485 dii \ar, \offset
486 or \ar, \ar, \ar
487 or \ar, \ar, \ar
488 or \ar, \ar, \ar
489 or \ar, \ar, \ar
490 .endm
491#endif
492
493
494/*
495 * Invalidate entire data cache.
496 *
497 * Parameters:
498 * aa, ab unique address registers (temporaries)
499 */
500 .macro dcache_invalidate_all aa, ab
501#if XCHAL_DCACHE_SIZE > 0
502 // Data cache invalidation:
503 cache_index_all dii, XCHAL_DCACHE_SIZE, XCHAL_DCACHE_LINESIZE, XCHAL_DCACHE_WAYS, \aa, \ab
504 dcache_sync \aa
505 // End of data cache invalidation
506#endif
507 .endm
508
509
510
511/*
512 * Writeback a single line of the data cache.
513 * Parameters are:
514 * ar address register that contains (virtual) address to writeback
515 * (may get clobbered in a future implementation, but not currently)
516 * offset offset to add to \ar to compute effective address to writeback
517 * (note: some number of lsbits are ignored)
518 */
519 .macro dcache_writeback_line ar, offset
520#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_IS_WRITEBACK
521 dhwb \ar, \offset
522 dcache_sync \ar
523#endif
524 .endm
525
526
527
528/*
529 * Writeback dirty data cache entries that cache a specified portion of memory.
530 * Parameters are:
531 * astart start address (register gets clobbered)
532 * asize size of the region in bytes (register gets clobbered)
533 * ac unique register used as temporary
534 */
535 .macro dcache_writeback_region astart, asize, ac
536#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_IS_WRITEBACK
537 // Data cache region writeback:
538 cache_hit_region dhwb, XCHAL_DCACHE_LINEWIDTH, \astart, \asize, \ac
539 dcache_sync \ac
540 // End of data cache region writeback
541#endif
542 .endm
543
544
545
546/*
547 * Writeback entire data cache.
548 * Parameters:
549 * aa, ab unique address registers (temporaries)
550 */
551 .macro dcache_writeback_all aa, ab
552#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_IS_WRITEBACK
553 // Data cache writeback:
554 cache_index_all diwb, XCHAL_DCACHE_SIZE, XCHAL_DCACHE_LINESIZE, 1, \aa, \ab
555 dcache_sync \aa
556 // End of data cache writeback
557#endif
558 .endm
559
560
561
562/*
563 * Writeback and invalidate a single line of the data cache.
564 * Parameters are:
565 * ar address register that contains (virtual) address to writeback and invalidate
566 * (may get clobbered in a future implementation, but not currently)
567 * offset offset to add to \ar to compute effective address to writeback and invalidate
568 * (note: some number of lsbits are ignored)
569 */
570 .macro dcache_writeback_inv_line ar, offset
571#if XCHAL_DCACHE_SIZE > 0
572 dhwbi \ar, \offset /* writeback and invalidate dcache line */
573 dcache_sync \ar
574#endif
575 .endm
576
577
578
579/*
580 * Writeback and invalidate data cache entries that cache a specified portion of memory.
581 * Parameters are:
582 * astart start address (register gets clobbered)
583 * asize size of the region in bytes (register gets clobbered)
584 * ac unique register used as temporary
585 */
586 .macro dcache_writeback_inv_region astart, asize, ac
587#if XCHAL_DCACHE_SIZE > 0
588 // Data cache region writeback and invalidate:
589 cache_hit_region dhwbi, XCHAL_DCACHE_LINEWIDTH, \astart, \asize, \ac
590 dcache_sync \ac
591 // End of data cache region writeback and invalidate
592#endif
593 .endm
594
595
596
597/*
598 * Writeback and invalidate entire data cache.
599 * Parameters:
600 * aa, ab unique address registers (temporaries)
601 */
602 .macro dcache_writeback_inv_all aa, ab
603#if XCHAL_DCACHE_SIZE > 0
604 // Data cache writeback and invalidate:
605#if XCHAL_DCACHE_IS_WRITEBACK
606 cache_index_all diwbi, XCHAL_DCACHE_SIZE, XCHAL_DCACHE_LINESIZE, 1, \aa, \ab
607 dcache_sync \aa
608#else /*writeback*/
609 // Data cache does not support writeback, so just invalidate: */
610 dcache_invalidate_all \aa, \ab
611#endif /*writeback*/
612 // End of data cache writeback and invalidate
613#endif
614 .endm
615
616
617
618
619/*
620 * Lock (prefetch & lock) a single line of the data cache.
621 *
622 * Parameters are:
623 * ar address register that contains (virtual) address to lock
624 * (may get clobbered in a future implementation, but not currently)
625 * offset offset to add to \ar to compute effective address to lock
626 * (note: some number of lsbits are ignored)
627 */
628 .macro dcache_lock_line ar, offset
629#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_LINE_LOCKABLE
630 dpfl \ar, \offset /* prefetch and lock dcache line */
631 dcache_sync \ar
632#endif
633 .endm
634
635
636
637/*
638 * Lock (prefetch & lock) a specified portion of memory into the data cache.
639 * Parameters are:
640 * astart start address (register gets clobbered)
641 * asize size of the region in bytes (register gets clobbered)
642 * ac unique register used as temporary
643 */
644 .macro dcache_lock_region astart, asize, ac
645#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_LINE_LOCKABLE
646 // Data cache region lock:
647 cache_hit_region dpfl, XCHAL_DCACHE_LINEWIDTH, \astart, \asize, \ac
648 dcache_sync \ac
649 // End of data cache region lock
650#endif
651 .endm
652
653
654
655/*
656 * Unlock a single line of the data cache.
657 *
658 * Parameters are:
659 * ar address register that contains (virtual) address to unlock
660 * (may get clobbered in a future implementation, but not currently)
661 * offset offset to add to \ar to compute effective address to unlock
662 * (note: some number of lsbits are ignored)
663 */
664 .macro dcache_unlock_line ar, offset
665#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_LINE_LOCKABLE
666 dhu \ar, \offset /* unlock dcache line */
667 dcache_sync \ar
668#endif
669 .endm
670
671
672
673/*
674 * Unlock a specified portion of memory from the data cache.
675 * Parameters are:
676 * astart start address (register gets clobbered)
677 * asize size of the region in bytes (register gets clobbered)
678 * ac unique register used as temporary
679 */
680 .macro dcache_unlock_region astart, asize, ac
681#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_LINE_LOCKABLE
682 // Data cache region unlock:
683 cache_hit_region dhu, XCHAL_DCACHE_LINEWIDTH, \astart, \asize, \ac
684 dcache_sync \ac
685 // End of data cache region unlock
686#endif
687 .endm
688
689
690
691/*
692 * Unlock entire data cache.
693 *
694 * Parameters:
695 * aa, ab unique address registers (temporaries)
696 */
697 .macro dcache_unlock_all aa, ab
698#if XCHAL_DCACHE_SIZE > 0 && XCHAL_DCACHE_LINE_LOCKABLE
699 // Data cache unlock:
700 cache_index_all diu, XCHAL_DCACHE_SIZE, XCHAL_DCACHE_LINESIZE, 1, \aa, \ab
701 dcache_sync \aa
702 // End of data cache unlock
703#endif
704 .endm
705
706
707#endif /*XTENSA_CACHEASM_H*/
708
diff --git a/include/asm-xtensa/xtensa/cacheattrasm.h b/include/asm-xtensa/xtensa/cacheattrasm.h
deleted file mode 100644
index 1c3e117b3592..000000000000
--- a/include/asm-xtensa/xtensa/cacheattrasm.h
+++ /dev/null
@@ -1,432 +0,0 @@
1#ifndef XTENSA_CACHEATTRASM_H
2#define XTENSA_CACHEATTRASM_H
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/cacheattrasm.h -- assembler-specific
8 * CACHEATTR register related definitions that depend on CORE
9 * configuration.
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 *
15 * Copyright (C) 2002 Tensilica Inc.
16 */
17
18
19#include <xtensa/coreasm.h>
20
21
22/*
23 * This header file defines assembler macros of the form:
24 * <x>cacheattr_<func>
25 * where:
26 * <x> is 'i', 'd' or absent for instruction, data
27 * or both caches; and
28 * <func> indicates the function of the macro.
29 *
30 * The following functions are defined:
31 *
32 * icacheattr_get
33 * Reads I-cache CACHEATTR into a2 (clobbers a3-a5).
34 *
35 * dcacheattr_get
36 * Reads D-cache CACHEATTR into a2 (clobbers a3-a5).
37 * (Note: for configs with a real CACHEATTR register, the
38 * above two macros are identical.)
39 *
40 * cacheattr_set
41 * Writes both I-cache and D-cache CACHEATTRs from a2 (a3-a8 clobbered).
42 * Works even when changing one's own code's attributes.
43 *
44 * icacheattr_is_enabled label
45 * Branches to \label if I-cache appears to have been enabled
46 * (eg. if CACHEATTR contains a cache-enabled attribute).
47 * (clobbers a2-a5,SAR)
48 *
49 * dcacheattr_is_enabled label
50 * Branches to \label if D-cache appears to have been enabled
51 * (eg. if CACHEATTR contains a cache-enabled attribute).
52 * (clobbers a2-a5,SAR)
53 *
54 * cacheattr_is_enabled label
55 * Branches to \label if either I-cache or D-cache appears to have been enabled
56 * (eg. if CACHEATTR contains a cache-enabled attribute).
57 * (clobbers a2-a5,SAR)
58 *
59 * The following macros are only defined under certain conditions:
60 *
61 * icacheattr_set (if XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR)
62 * Writes I-cache CACHEATTR from a2 (a3-a8 clobbered).
63 *
64 * dcacheattr_set (if XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR)
65 * Writes D-cache CACHEATTR from a2 (a3-a8 clobbered).
66 */
67
68
69
70/*************************** GENERIC -- ALL CACHES ***************************/
71
72/*
73 * _cacheattr_get
74 *
75 * (Internal macro.)
76 * Returns value of CACHEATTR register (or closest equivalent) in a2.
77 *
78 * Entry:
79 * (none)
80 * Exit:
81 * a2 value read from CACHEATTR
82 * a3-a5 clobbered (temporaries)
83 */
84 .macro _cacheattr_get tlb
85#if XCHAL_HAVE_CACHEATTR
86 rsr a2, CACHEATTR
87#elif XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
88 // We have a config that "mimics" CACHEATTR using a simplified
89 // "MMU" composed of a single statically-mapped way.
90 // DTLB and ITLB are independent, so there's no single
91 // cache attribute that can describe both. So for now
92 // just return the DTLB state.
93 movi a5, 0xE0000000
94 movi a2, 0
95 movi a3, 0
961: add a3, a3, a5 // next segment
97 r&tlb&1 a4, a3 // get PPN+CA of segment at 0xE0000000, 0xC0000000, ..., 0
98 dsync // interlock???
99 slli a2, a2, 4
100 extui a4, a4, 0, 4 // extract CA
101 or a2, a2, a4
102 bnez a3, 1b
103#else
104 // This macro isn't applicable to arbitrary MMU configurations.
105 // Just return zero.
106 movi a2, 0
107#endif
108 .endm
109
110 .macro icacheattr_get
111 _cacheattr_get itlb
112 .endm
113
114 .macro dcacheattr_get
115 _cacheattr_get dtlb
116 .endm
117
118
119#define XCHAL_CACHEATTR_ALL_BYPASS 0x22222222 /* default (powerup/reset) value of CACHEATTR, all BYPASS
120 mode (ie. disabled/bypassed caches) */
121
122#if XCHAL_HAVE_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
123
124#define XCHAL_FCA_ENAMASK 0x001A /* bitmap of fetch attributes that require enabled icache */
125#define XCHAL_LCA_ENAMASK 0x0003 /* bitmap of load attributes that require enabled dcache */
126#define XCHAL_SCA_ENAMASK 0x0003 /* bitmap of store attributes that require enabled dcache */
127#define XCHAL_LSCA_ENAMASK (XCHAL_LCA_ENAMASK|XCHAL_SCA_ENAMASK) /* l/s attrs requiring enabled dcache */
128#define XCHAL_ALLCA_ENAMASK (XCHAL_FCA_ENAMASK|XCHAL_LSCA_ENAMASK) /* all attrs requiring enabled caches */
129
130/*
131 * _cacheattr_is_enabled
132 *
133 * (Internal macro.)
134 * Branches to \label if CACHEATTR in a2 indicates an enabled
135 * cache, using mask in a3.
136 *
137 * Parameters:
138 * label where to branch to if cache is enabled
139 * Entry:
140 * a2 contains CACHEATTR value used to determine whether
141 * caches are enabled
142 * a3 16-bit constant where each bit correspond to
143 * one of the 16 possible CA values (in a CACHEATTR mask);
144 * CA values that indicate the cache is enabled
145 * have their corresponding bit set in this mask
146 * (eg. use XCHAL_xCA_ENAMASK , above)
147 * Exit:
148 * a2,a4,a5 clobbered
149 * SAR clobbered
150 */
151 .macro _cacheattr_is_enabled label
152 movi a4, 8 // loop 8 times
153.Lcaife\@:
154 extui a5, a2, 0, 4 // get CA nibble
155 ssr a5 // index into mask according to CA...
156 srl a5, a3 // ...and get CA's mask bit in a5 bit 0
157 bbsi.l a5, 0, \label // if CA indicates cache enabled, jump to label
158 srli a2, a2, 4 // next nibble
159 addi a4, a4, -1
160 bnez a4, .Lcaife\@ // loop for each nibble
161 .endm
162
163#else /* XCHAL_HAVE_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR */
164 .macro _cacheattr_is_enabled label
165 j \label // macro not applicable, assume caches always enabled
166 .endm
167#endif /* XCHAL_HAVE_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR */
168
169
170
171/*
172 * icacheattr_is_enabled
173 *
174 * Branches to \label if I-cache is enabled.
175 *
176 * Parameters:
177 * label where to branch to if icache is enabled
178 * Entry:
179 * (none)
180 * Exit:
181 * a2-a5, SAR clobbered (temporaries)
182 */
183 .macro icacheattr_is_enabled label
184#if XCHAL_HAVE_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
185 icacheattr_get
186 movi a3, XCHAL_FCA_ENAMASK
187#endif
188 _cacheattr_is_enabled \label
189 .endm
190
191/*
192 * dcacheattr_is_enabled
193 *
194 * Branches to \label if D-cache is enabled.
195 *
196 * Parameters:
197 * label where to branch to if dcache is enabled
198 * Entry:
199 * (none)
200 * Exit:
201 * a2-a5, SAR clobbered (temporaries)
202 */
203 .macro dcacheattr_is_enabled label
204#if XCHAL_HAVE_CACHEATTR || XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
205 dcacheattr_get
206 movi a3, XCHAL_LSCA_ENAMASK
207#endif
208 _cacheattr_is_enabled \label
209 .endm
210
211/*
212 * cacheattr_is_enabled
213 *
214 * Branches to \label if either I-cache or D-cache is enabled.
215 *
216 * Parameters:
217 * label where to branch to if a cache is enabled
218 * Entry:
219 * (none)
220 * Exit:
221 * a2-a5, SAR clobbered (temporaries)
222 */
223 .macro cacheattr_is_enabled label
224#if XCHAL_HAVE_CACHEATTR
225 rsr a2, CACHEATTR
226 movi a3, XCHAL_ALLCA_ENAMASK
227#elif XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
228 icacheattr_get
229 movi a3, XCHAL_FCA_ENAMASK
230 _cacheattr_is_enabled \label
231 dcacheattr_get
232 movi a3, XCHAL_LSCA_ENAMASK
233#endif
234 _cacheattr_is_enabled \label
235 .endm
236
237
238
239/*
240 * The ISA does not have a defined way to change the
241 * instruction cache attributes of the running code,
242 * ie. of the memory area that encloses the current PC.
243 * However, each micro-architecture (or class of
244 * configurations within a micro-architecture)
245 * provides a way to deal with this issue.
246 *
247 * Here are a few macros used to implement the relevant
248 * approach taken.
249 */
250
251#if XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
252 // We have a config that "mimics" CACHEATTR using a simplified
253 // "MMU" composed of a single statically-mapped way.
254
255/*
256 * icacheattr_set
257 *
258 * Entry:
259 * a2 cacheattr value to set
260 * Exit:
261 * a2 unchanged
262 * a3-a8 clobbered (temporaries)
263 */
264 .macro icacheattr_set
265
266 movi a5, 0xE0000000 // mask of upper 3 bits
267 movi a6, 3f // PC where ITLB is set
268 movi a3, 0 // start at region 0 (0 .. 7)
269 and a6, a6, a5 // upper 3 bits of local PC area
270 mov a7, a2 // copy a2 so it doesn't get clobbered
271 j 3f
272
273# if XCHAL_HAVE_XLT_CACHEATTR
274 // Can do translations, use generic method:
2751: sub a6, a3, a5 // address of some other segment
276 ritlb1 a8, a6 // save its PPN+CA
277 dsync // interlock??
278 witlb a4, a6 // make it translate to this code area
279 movi a6, 5f // where to jump into it
280 isync
281 sub a6, a6, a5 // adjust jump address within that other segment
282 jx a6
283
284 // Note that in the following code snippet, which runs at a different virtual
285 // address than it is assembled for, we avoid using literals (eg. via movi/l32r)
286 // just in case literals end up in a different 512 MB segment, and we avoid
287 // instructions that rely on the current PC being what is expected.
288 //
289 .align 4
290 _j 6f // this is at label '5' minus 4 bytes
291 .align 4
2925: witlb a4, a3 // we're in other segment, now can write previous segment's CA
293 isync
294 add a6, a6, a5 // back to previous segment
295 addi a6, a6, -4 // next jump label
296 jx a6
297
2986: sub a6, a3, a5 // address of some other segment
299 witlb a8, a6 // restore PPN+CA of other segment
300 mov a6, a3 // restore a6
301 isync
302# else /* XCHAL_HAVE_XLT_CACHEATTR */
303 // Use micro-architecture specific method.
304 // The following 4-instruction sequence is aligned such that
305 // it all fits within a single I-cache line. Sixteen byte
306 // alignment is sufficient for this (using XCHAL_ICACHE_LINESIZE
307 // actually causes problems because that can be greater than
308 // the alignment of the reset vector, where this macro is often
309 // invoked, which would cause the linker to align the reset
310 // vector code away from the reset vector!!).
311 .align 16 /*XCHAL_ICACHE_LINESIZE*/
3121: _witlb a4, a3 // write wired PTE (CA, no PPN) of 512MB segment to ITLB
313 _isync
314 nop
315 nop
316# endif /* XCHAL_HAVE_XLT_CACHEATTR */
317 beq a3, a5, 4f // done?
318
319 // Note that in the WITLB loop, we don't do any load/stores
320 // (may not be an issue here, but it is important in the DTLB case).
3212: srli a7, a7, 4 // next CA
322 sub a3, a3, a5 // next segment (add 0x20000000)
3233:
324# if XCHAL_HAVE_XLT_CACHEATTR /* if have translation, preserve it */
325 ritlb1 a8, a3 // get current PPN+CA of segment
326 dsync // interlock???
327 extui a4, a7, 0, 4 // extract CA to set
328 srli a8, a8, 4 // clear CA but keep PPN ...
329 slli a8, a8, 4 // ...
330 add a4, a4, a8 // combine new CA with PPN to preserve
331# else
332 extui a4, a7, 0, 4 // extract CA
333# endif
334 beq a3, a6, 1b // current PC's region? if so, do it in a safe way
335 witlb a4, a3 // write wired PTE (CA [+PPN]) of 512MB segment to ITLB
336 bne a3, a5, 2b
337 isync // make sure all ifetch changes take effect
3384:
339 .endm // icacheattr_set
340
341
342/*
343 * dcacheattr_set
344 *
345 * Entry:
346 * a2 cacheattr value to set
347 * Exit:
348 * a2 unchanged
349 * a3-a8 clobbered (temporaries)
350 */
351
352 .macro dcacheattr_set
353
354 movi a5, 0xE0000000 // mask of upper 3 bits
355 movi a3, 0 // start at region 0 (0 .. 7)
356 mov a7, a2 // copy a2 so it doesn't get clobbered
357 j 3f
358 // Note that in the WDTLB loop, we don't do any load/stores
359 // (including implicit l32r via movi) because it isn't safe.
3602: srli a7, a7, 4 // next CA
361 sub a3, a3, a5 // next segment (add 0x20000000)
3623:
363# if XCHAL_HAVE_XLT_CACHEATTR /* if have translation, preserve it */
364 rdtlb1 a8, a3 // get current PPN+CA of segment
365 dsync // interlock???
366 extui a4, a7, 0, 4 // extract CA to set
367 srli a8, a8, 4 // clear CA but keep PPN ...
368 slli a8, a8, 4 // ...
369 add a4, a4, a8 // combine new CA with PPN to preserve
370# else
371 extui a4, a7, 0, 4 // extract CA to set
372# endif
373 wdtlb a4, a3 // write wired PTE (CA [+PPN]) of 512MB segment to DTLB
374 bne a3, a5, 2b
375 dsync // make sure all data path changes take effect
376 .endm // dcacheattr_set
377
378#endif /* XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR */
379
380
381
382/*
383 * cacheattr_set
384 *
385 * Macro that sets the current CACHEATTR safely
386 * (both i and d) according to the current contents of a2.
387 * It works even when changing the cache attributes of
388 * the currently running code.
389 *
390 * Entry:
391 * a2 cacheattr value to set
392 * Exit:
393 * a2 unchanged
394 * a3-a8 clobbered (temporaries)
395 */
396 .macro cacheattr_set
397
398#if XCHAL_HAVE_CACHEATTR
399# if XCHAL_ICACHE_LINESIZE < 4
400 // No i-cache, so can always safely write to CACHEATTR:
401 wsr a2, CACHEATTR
402# else
403 // The Athens micro-architecture, when using the old
404 // exception architecture option (ie. with the CACHEATTR register)
405 // allows changing the cache attributes of the running code
406 // using the following exact sequence aligned to be within
407 // an instruction cache line. (NOTE: using XCHAL_ICACHE_LINESIZE
408 // alignment actually causes problems because that can be greater
409 // than the alignment of the reset vector, where this macro is often
410 // invoked, which would cause the linker to align the reset
411 // vector code away from the reset vector!!).
412 j 1f
413 .align 16 /*XCHAL_ICACHE_LINESIZE*/ // align to within an I-cache line
4141: _wsr a2, CACHEATTR
415 _isync
416 nop
417 nop
418# endif
419#elif XCHAL_HAVE_MIMIC_CACHEATTR || XCHAL_HAVE_XLT_CACHEATTR
420 // DTLB and ITLB are independent, but to keep semantics
421 // of this macro we simply write to both.
422 icacheattr_set
423 dcacheattr_set
424#else
425 // This macro isn't applicable to arbitrary MMU configurations.
426 // Do nothing in this case.
427#endif
428 .endm
429
430
431#endif /*XTENSA_CACHEATTRASM_H*/
432
diff --git a/include/asm-xtensa/xtensa/config-linux_be/core.h b/include/asm-xtensa/xtensa/config-linux_be/core.h
deleted file mode 100644
index d54fe5eb1064..000000000000
--- a/include/asm-xtensa/xtensa/config-linux_be/core.h
+++ /dev/null
@@ -1,1270 +0,0 @@
1/*
2 * xtensa/config/core.h -- HAL definitions that are dependent on CORE configuration
3 *
4 * This header file is sometimes referred to as the "compile-time HAL" or CHAL.
5 * It was generated for a specific Xtensa processor configuration.
6 *
7 * Source for configuration-independent binaries (which link in a
8 * configuration-specific HAL library) must NEVER include this file.
9 * It is perfectly normal, however, for the HAL source itself to include this file.
10 */
11
12/*
13 * Copyright (c) 2003 Tensilica, Inc. All Rights Reserved.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of version 2.1 of the GNU Lesser General Public
17 * License as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it would be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 *
23 * Further, this software is distributed without any warranty that it is
24 * free of the rightful claim of any third person regarding infringement
25 * or the like. Any license provided herein, whether implied or
26 * otherwise, applies only to this software file. Patent licenses, if
27 * any, provided herein do not apply to combinations of this program with
28 * other software, or any other product whatsoever.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this program; if not, write the Free Software
32 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
33 * USA.
34 */
35
36
37#ifndef XTENSA_CONFIG_CORE_H
38#define XTENSA_CONFIG_CORE_H
39
40#include <xtensa/hal.h>
41
42
43/*----------------------------------------------------------------------
44 GENERAL
45 ----------------------------------------------------------------------*/
46
47/*
48 * Separators for macros that expand into arrays.
49 * These can be predefined by files that #include this one,
50 * when different separators are required.
51 */
52/* Element separator for macros that expand into 1-dimensional arrays: */
53#ifndef XCHAL_SEP
54#define XCHAL_SEP ,
55#endif
56/* Array separator for macros that expand into 2-dimensional arrays: */
57#ifndef XCHAL_SEP2
58#define XCHAL_SEP2 },{
59#endif
60
61
62/*----------------------------------------------------------------------
63 ENDIANNESS
64 ----------------------------------------------------------------------*/
65
66#define XCHAL_HAVE_BE 1
67#define XCHAL_HAVE_LE 0
68#define XCHAL_MEMORY_ORDER XTHAL_BIGENDIAN
69
70
71/*----------------------------------------------------------------------
72 REGISTER WINDOWS
73 ----------------------------------------------------------------------*/
74
75#define XCHAL_HAVE_WINDOWED 1 /* 1 if windowed registers option configured, 0 otherwise */
76#define XCHAL_NUM_AREGS 64 /* number of physical address regs */
77#define XCHAL_NUM_AREGS_LOG2 6 /* log2(XCHAL_NUM_AREGS) */
78
79
80/*----------------------------------------------------------------------
81 ADDRESS ALIGNMENT
82 ----------------------------------------------------------------------*/
83
84/* These apply to a selected set of core load and store instructions only (see ISA): */
85#define XCHAL_UNALIGNED_LOAD_EXCEPTION 1 /* 1 if unaligned loads cause an exception, 0 otherwise */
86#define XCHAL_UNALIGNED_STORE_EXCEPTION 1 /* 1 if unaligned stores cause an exception, 0 otherwise */
87
88
89/*----------------------------------------------------------------------
90 INTERRUPTS
91 ----------------------------------------------------------------------*/
92
93#define XCHAL_HAVE_INTERRUPTS 1 /* 1 if interrupt option configured, 0 otherwise */
94#define XCHAL_HAVE_HIGHPRI_INTERRUPTS 1 /* 1 if high-priority interrupt option configured, 0 otherwise */
95#define XCHAL_HAVE_HIGHLEVEL_INTERRUPTS XCHAL_HAVE_HIGHPRI_INTERRUPTS
96#define XCHAL_HAVE_NMI 0 /* 1 if NMI option configured, 0 otherwise */
97#define XCHAL_NUM_INTERRUPTS 17 /* number of interrupts */
98#define XCHAL_NUM_INTERRUPTS_LOG2 5 /* number of bits to hold an interrupt number: roundup(log2(number of interrupts)) */
99#define XCHAL_NUM_EXTINTERRUPTS 10 /* number of external interrupts */
100#define XCHAL_NUM_INTLEVELS 4 /* number of interrupt levels (not including level zero!) */
101#define XCHAL_NUM_LOWPRI_LEVELS 1 /* number of low-priority interrupt levels (always 1) */
102#define XCHAL_FIRST_HIGHPRI_LEVEL (XCHAL_NUM_LOWPRI_LEVELS+1) /* level of first high-priority interrupt (always 2) */
103#define XCHAL_EXCM_LEVEL 1 /* level of interrupts masked by PS.EXCM (XEA2 only; always 1 in T10xx);
104 for XEA1, where there is no PS.EXCM, this is always 1;
105 interrupts at levels FIRST_HIGHPRI <= n <= EXCM_LEVEL, if any,
106 are termed "medium priority" interrupts (post T10xx only) */
107/* Note: 1 <= LOWPRI_LEVELS <= EXCM_LEVEL < DEBUGLEVEL <= NUM_INTLEVELS < NMILEVEL <= 15 */
108
109/* Masks of interrupts at each interrupt level: */
110#define XCHAL_INTLEVEL0_MASK 0x00000000
111#define XCHAL_INTLEVEL1_MASK 0x000064F9
112#define XCHAL_INTLEVEL2_MASK 0x00008902
113#define XCHAL_INTLEVEL3_MASK 0x00011204
114#define XCHAL_INTLEVEL4_MASK 0x00000000
115#define XCHAL_INTLEVEL5_MASK 0x00000000
116#define XCHAL_INTLEVEL6_MASK 0x00000000
117#define XCHAL_INTLEVEL7_MASK 0x00000000
118#define XCHAL_INTLEVEL8_MASK 0x00000000
119#define XCHAL_INTLEVEL9_MASK 0x00000000
120#define XCHAL_INTLEVEL10_MASK 0x00000000
121#define XCHAL_INTLEVEL11_MASK 0x00000000
122#define XCHAL_INTLEVEL12_MASK 0x00000000
123#define XCHAL_INTLEVEL13_MASK 0x00000000
124#define XCHAL_INTLEVEL14_MASK 0x00000000
125#define XCHAL_INTLEVEL15_MASK 0x00000000
126/* As an array of entries (eg. for C constant arrays): */
127#define XCHAL_INTLEVEL_MASKS 0x00000000 XCHAL_SEP \
128 0x000064F9 XCHAL_SEP \
129 0x00008902 XCHAL_SEP \
130 0x00011204 XCHAL_SEP \
131 0x00000000 XCHAL_SEP \
132 0x00000000 XCHAL_SEP \
133 0x00000000 XCHAL_SEP \
134 0x00000000 XCHAL_SEP \
135 0x00000000 XCHAL_SEP \
136 0x00000000 XCHAL_SEP \
137 0x00000000 XCHAL_SEP \
138 0x00000000 XCHAL_SEP \
139 0x00000000 XCHAL_SEP \
140 0x00000000 XCHAL_SEP \
141 0x00000000 XCHAL_SEP \
142 0x00000000
143
144/* Masks of interrupts at each range 1..n of interrupt levels: */
145#define XCHAL_INTLEVEL0_ANDBELOW_MASK 0x00000000
146#define XCHAL_INTLEVEL1_ANDBELOW_MASK 0x000064F9
147#define XCHAL_INTLEVEL2_ANDBELOW_MASK 0x0000EDFB
148#define XCHAL_INTLEVEL3_ANDBELOW_MASK 0x0001FFFF
149#define XCHAL_INTLEVEL4_ANDBELOW_MASK 0x0001FFFF
150#define XCHAL_INTLEVEL5_ANDBELOW_MASK 0x0001FFFF
151#define XCHAL_INTLEVEL6_ANDBELOW_MASK 0x0001FFFF
152#define XCHAL_INTLEVEL7_ANDBELOW_MASK 0x0001FFFF
153#define XCHAL_INTLEVEL8_ANDBELOW_MASK 0x0001FFFF
154#define XCHAL_INTLEVEL9_ANDBELOW_MASK 0x0001FFFF
155#define XCHAL_INTLEVEL10_ANDBELOW_MASK 0x0001FFFF
156#define XCHAL_INTLEVEL11_ANDBELOW_MASK 0x0001FFFF
157#define XCHAL_INTLEVEL12_ANDBELOW_MASK 0x0001FFFF
158#define XCHAL_INTLEVEL13_ANDBELOW_MASK 0x0001FFFF
159#define XCHAL_INTLEVEL14_ANDBELOW_MASK 0x0001FFFF
160#define XCHAL_INTLEVEL15_ANDBELOW_MASK 0x0001FFFF
161#define XCHAL_LOWPRI_MASK XCHAL_INTLEVEL1_ANDBELOW_MASK /* mask of all low-priority interrupts */
162#define XCHAL_EXCM_MASK XCHAL_INTLEVEL1_ANDBELOW_MASK /* mask of all interrupts masked by PS.EXCM (or CEXCM) */
163/* As an array of entries (eg. for C constant arrays): */
164#define XCHAL_INTLEVEL_ANDBELOW_MASKS 0x00000000 XCHAL_SEP \
165 0x000064F9 XCHAL_SEP \
166 0x0000EDFB XCHAL_SEP \
167 0x0001FFFF XCHAL_SEP \
168 0x0001FFFF XCHAL_SEP \
169 0x0001FFFF XCHAL_SEP \
170 0x0001FFFF XCHAL_SEP \
171 0x0001FFFF XCHAL_SEP \
172 0x0001FFFF XCHAL_SEP \
173 0x0001FFFF XCHAL_SEP \
174 0x0001FFFF XCHAL_SEP \
175 0x0001FFFF XCHAL_SEP \
176 0x0001FFFF XCHAL_SEP \
177 0x0001FFFF XCHAL_SEP \
178 0x0001FFFF XCHAL_SEP \
179 0x0001FFFF
180
181/* Interrupt numbers for each interrupt level at which only one interrupt was configured: */
182/*#define XCHAL_INTLEVEL1_NUM ...more than one interrupt at this level...*/
183/*#define XCHAL_INTLEVEL2_NUM ...more than one interrupt at this level...*/
184/*#define XCHAL_INTLEVEL3_NUM ...more than one interrupt at this level...*/
185
186/* Level of each interrupt: */
187#define XCHAL_INT0_LEVEL 1
188#define XCHAL_INT1_LEVEL 2
189#define XCHAL_INT2_LEVEL 3
190#define XCHAL_INT3_LEVEL 1
191#define XCHAL_INT4_LEVEL 1
192#define XCHAL_INT5_LEVEL 1
193#define XCHAL_INT6_LEVEL 1
194#define XCHAL_INT7_LEVEL 1
195#define XCHAL_INT8_LEVEL 2
196#define XCHAL_INT9_LEVEL 3
197#define XCHAL_INT10_LEVEL 1
198#define XCHAL_INT11_LEVEL 2
199#define XCHAL_INT12_LEVEL 3
200#define XCHAL_INT13_LEVEL 1
201#define XCHAL_INT14_LEVEL 1
202#define XCHAL_INT15_LEVEL 2
203#define XCHAL_INT16_LEVEL 3
204#define XCHAL_INT17_LEVEL 0
205#define XCHAL_INT18_LEVEL 0
206#define XCHAL_INT19_LEVEL 0
207#define XCHAL_INT20_LEVEL 0
208#define XCHAL_INT21_LEVEL 0
209#define XCHAL_INT22_LEVEL 0
210#define XCHAL_INT23_LEVEL 0
211#define XCHAL_INT24_LEVEL 0
212#define XCHAL_INT25_LEVEL 0
213#define XCHAL_INT26_LEVEL 0
214#define XCHAL_INT27_LEVEL 0
215#define XCHAL_INT28_LEVEL 0
216#define XCHAL_INT29_LEVEL 0
217#define XCHAL_INT30_LEVEL 0
218#define XCHAL_INT31_LEVEL 0
219/* As an array of entries (eg. for C constant arrays): */
220#define XCHAL_INT_LEVELS 1 XCHAL_SEP \
221 2 XCHAL_SEP \
222 3 XCHAL_SEP \
223 1 XCHAL_SEP \
224 1 XCHAL_SEP \
225 1 XCHAL_SEP \
226 1 XCHAL_SEP \
227 1 XCHAL_SEP \
228 2 XCHAL_SEP \
229 3 XCHAL_SEP \
230 1 XCHAL_SEP \
231 2 XCHAL_SEP \
232 3 XCHAL_SEP \
233 1 XCHAL_SEP \
234 1 XCHAL_SEP \
235 2 XCHAL_SEP \
236 3 XCHAL_SEP \
237 0 XCHAL_SEP \
238 0 XCHAL_SEP \
239 0 XCHAL_SEP \
240 0 XCHAL_SEP \
241 0 XCHAL_SEP \
242 0 XCHAL_SEP \
243 0 XCHAL_SEP \
244 0 XCHAL_SEP \
245 0 XCHAL_SEP \
246 0 XCHAL_SEP \
247 0 XCHAL_SEP \
248 0 XCHAL_SEP \
249 0 XCHAL_SEP \
250 0 XCHAL_SEP \
251 0
252
253/* Type of each interrupt: */
254#define XCHAL_INT0_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
255#define XCHAL_INT1_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
256#define XCHAL_INT2_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
257#define XCHAL_INT3_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
258#define XCHAL_INT4_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
259#define XCHAL_INT5_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
260#define XCHAL_INT6_TYPE XTHAL_INTTYPE_EXTERN_LEVEL
261#define XCHAL_INT7_TYPE XTHAL_INTTYPE_EXTERN_EDGE
262#define XCHAL_INT8_TYPE XTHAL_INTTYPE_EXTERN_EDGE
263#define XCHAL_INT9_TYPE XTHAL_INTTYPE_EXTERN_EDGE
264#define XCHAL_INT10_TYPE XTHAL_INTTYPE_TIMER
265#define XCHAL_INT11_TYPE XTHAL_INTTYPE_TIMER
266#define XCHAL_INT12_TYPE XTHAL_INTTYPE_TIMER
267#define XCHAL_INT13_TYPE XTHAL_INTTYPE_SOFTWARE
268#define XCHAL_INT14_TYPE XTHAL_INTTYPE_SOFTWARE
269#define XCHAL_INT15_TYPE XTHAL_INTTYPE_SOFTWARE
270#define XCHAL_INT16_TYPE XTHAL_INTTYPE_SOFTWARE
271#define XCHAL_INT17_TYPE XTHAL_INTTYPE_UNCONFIGURED
272#define XCHAL_INT18_TYPE XTHAL_INTTYPE_UNCONFIGURED
273#define XCHAL_INT19_TYPE XTHAL_INTTYPE_UNCONFIGURED
274#define XCHAL_INT20_TYPE XTHAL_INTTYPE_UNCONFIGURED
275#define XCHAL_INT21_TYPE XTHAL_INTTYPE_UNCONFIGURED
276#define XCHAL_INT22_TYPE XTHAL_INTTYPE_UNCONFIGURED
277#define XCHAL_INT23_TYPE XTHAL_INTTYPE_UNCONFIGURED
278#define XCHAL_INT24_TYPE XTHAL_INTTYPE_UNCONFIGURED
279#define XCHAL_INT25_TYPE XTHAL_INTTYPE_UNCONFIGURED
280#define XCHAL_INT26_TYPE XTHAL_INTTYPE_UNCONFIGURED
281#define XCHAL_INT27_TYPE XTHAL_INTTYPE_UNCONFIGURED
282#define XCHAL_INT28_TYPE XTHAL_INTTYPE_UNCONFIGURED
283#define XCHAL_INT29_TYPE XTHAL_INTTYPE_UNCONFIGURED
284#define XCHAL_INT30_TYPE XTHAL_INTTYPE_UNCONFIGURED
285#define XCHAL_INT31_TYPE XTHAL_INTTYPE_UNCONFIGURED
286/* As an array of entries (eg. for C constant arrays): */
287#define XCHAL_INT_TYPES XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
288 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
289 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
290 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
291 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
292 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
293 XTHAL_INTTYPE_EXTERN_LEVEL XCHAL_SEP \
294 XTHAL_INTTYPE_EXTERN_EDGE XCHAL_SEP \
295 XTHAL_INTTYPE_EXTERN_EDGE XCHAL_SEP \
296 XTHAL_INTTYPE_EXTERN_EDGE XCHAL_SEP \
297 XTHAL_INTTYPE_TIMER XCHAL_SEP \
298 XTHAL_INTTYPE_TIMER XCHAL_SEP \
299 XTHAL_INTTYPE_TIMER XCHAL_SEP \
300 XTHAL_INTTYPE_SOFTWARE XCHAL_SEP \
301 XTHAL_INTTYPE_SOFTWARE XCHAL_SEP \
302 XTHAL_INTTYPE_SOFTWARE XCHAL_SEP \
303 XTHAL_INTTYPE_SOFTWARE XCHAL_SEP \
304 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
305 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
306 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
307 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
308 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
309 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
310 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
311 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
312 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
313 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
314 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
315 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
316 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
317 XTHAL_INTTYPE_UNCONFIGURED XCHAL_SEP \
318 XTHAL_INTTYPE_UNCONFIGURED
319
320/* Masks of interrupts for each type of interrupt: */
321#define XCHAL_INTTYPE_MASK_UNCONFIGURED 0xFFFE0000
322#define XCHAL_INTTYPE_MASK_SOFTWARE 0x0001E000
323#define XCHAL_INTTYPE_MASK_EXTERN_EDGE 0x00000380
324#define XCHAL_INTTYPE_MASK_EXTERN_LEVEL 0x0000007F
325#define XCHAL_INTTYPE_MASK_TIMER 0x00001C00
326#define XCHAL_INTTYPE_MASK_NMI 0x00000000
327/* As an array of entries (eg. for C constant arrays): */
328#define XCHAL_INTTYPE_MASKS 0xFFFE0000 XCHAL_SEP \
329 0x0001E000 XCHAL_SEP \
330 0x00000380 XCHAL_SEP \
331 0x0000007F XCHAL_SEP \
332 0x00001C00 XCHAL_SEP \
333 0x00000000
334
335/* Interrupts assigned to each timer (CCOMPARE0 to CCOMPARE3), -1 if unassigned */
336#define XCHAL_TIMER0_INTERRUPT 10
337#define XCHAL_TIMER1_INTERRUPT 11
338#define XCHAL_TIMER2_INTERRUPT 12
339#define XCHAL_TIMER3_INTERRUPT XTHAL_TIMER_UNCONFIGURED
340/* As an array of entries (eg. for C constant arrays): */
341#define XCHAL_TIMER_INTERRUPTS 10 XCHAL_SEP \
342 11 XCHAL_SEP \
343 12 XCHAL_SEP \
344 XTHAL_TIMER_UNCONFIGURED
345
346/* Indexing macros: */
347#define _XCHAL_INTLEVEL_MASK(n) XCHAL_INTLEVEL ## n ## _MASK
348#define XCHAL_INTLEVEL_MASK(n) _XCHAL_INTLEVEL_MASK(n) /* n = 0 .. 15 */
349#define _XCHAL_INTLEVEL_ANDBELOWMASK(n) XCHAL_INTLEVEL ## n ## _ANDBELOW_MASK
350#define XCHAL_INTLEVEL_ANDBELOW_MASK(n) _XCHAL_INTLEVEL_ANDBELOWMASK(n) /* n = 0 .. 15 */
351#define _XCHAL_INT_LEVEL(n) XCHAL_INT ## n ## _LEVEL
352#define XCHAL_INT_LEVEL(n) _XCHAL_INT_LEVEL(n) /* n = 0 .. 31 */
353#define _XCHAL_INT_TYPE(n) XCHAL_INT ## n ## _TYPE
354#define XCHAL_INT_TYPE(n) _XCHAL_INT_TYPE(n) /* n = 0 .. 31 */
355#define _XCHAL_TIMER_INTERRUPT(n) XCHAL_TIMER ## n ## _INTERRUPT
356#define XCHAL_TIMER_INTERRUPT(n) _XCHAL_TIMER_INTERRUPT(n) /* n = 0 .. 3 */
357
358
359
360/*
361 * External interrupt vectors/levels.
362 * These macros describe how Xtensa processor interrupt numbers
363 * (as numbered internally, eg. in INTERRUPT and INTENABLE registers)
364 * map to external BInterrupt<n> pins, for those interrupts
365 * configured as external (level-triggered, edge-triggered, or NMI).
366 * See the Xtensa processor databook for more details.
367 */
368
369/* Core interrupt numbers mapped to each EXTERNAL interrupt number: */
370#define XCHAL_EXTINT0_NUM 0 /* (intlevel 1) */
371#define XCHAL_EXTINT1_NUM 1 /* (intlevel 2) */
372#define XCHAL_EXTINT2_NUM 2 /* (intlevel 3) */
373#define XCHAL_EXTINT3_NUM 3 /* (intlevel 1) */
374#define XCHAL_EXTINT4_NUM 4 /* (intlevel 1) */
375#define XCHAL_EXTINT5_NUM 5 /* (intlevel 1) */
376#define XCHAL_EXTINT6_NUM 6 /* (intlevel 1) */
377#define XCHAL_EXTINT7_NUM 7 /* (intlevel 1) */
378#define XCHAL_EXTINT8_NUM 8 /* (intlevel 2) */
379#define XCHAL_EXTINT9_NUM 9 /* (intlevel 3) */
380
381/* Corresponding interrupt masks: */
382#define XCHAL_EXTINT0_MASK 0x00000001
383#define XCHAL_EXTINT1_MASK 0x00000002
384#define XCHAL_EXTINT2_MASK 0x00000004
385#define XCHAL_EXTINT3_MASK 0x00000008
386#define XCHAL_EXTINT4_MASK 0x00000010
387#define XCHAL_EXTINT5_MASK 0x00000020
388#define XCHAL_EXTINT6_MASK 0x00000040
389#define XCHAL_EXTINT7_MASK 0x00000080
390#define XCHAL_EXTINT8_MASK 0x00000100
391#define XCHAL_EXTINT9_MASK 0x00000200
392
393/* Core config interrupt levels mapped to each external interrupt: */
394#define XCHAL_EXTINT0_LEVEL 1 /* (int number 0) */
395#define XCHAL_EXTINT1_LEVEL 2 /* (int number 1) */
396#define XCHAL_EXTINT2_LEVEL 3 /* (int number 2) */
397#define XCHAL_EXTINT3_LEVEL 1 /* (int number 3) */
398#define XCHAL_EXTINT4_LEVEL 1 /* (int number 4) */
399#define XCHAL_EXTINT5_LEVEL 1 /* (int number 5) */
400#define XCHAL_EXTINT6_LEVEL 1 /* (int number 6) */
401#define XCHAL_EXTINT7_LEVEL 1 /* (int number 7) */
402#define XCHAL_EXTINT8_LEVEL 2 /* (int number 8) */
403#define XCHAL_EXTINT9_LEVEL 3 /* (int number 9) */
404
405
406/*----------------------------------------------------------------------
407 EXCEPTIONS and VECTORS
408 ----------------------------------------------------------------------*/
409
410#define XCHAL_HAVE_EXCEPTIONS 1 /* 1 if exception option configured, 0 otherwise */
411
412#define XCHAL_XEA_VERSION 2 /* Xtensa Exception Architecture number: 1 for XEA1 (old), 2 for XEA2 (new) */
413#define XCHAL_HAVE_XEA1 0 /* 1 if XEA1, 0 otherwise */
414#define XCHAL_HAVE_XEA2 1 /* 1 if XEA2, 0 otherwise */
415/* For backward compatibility ONLY -- DO NOT USE (will be removed in future release): */
416#define XCHAL_HAVE_OLD_EXC_ARCH XCHAL_HAVE_XEA1 /* (DEPRECATED) 1 if old exception architecture (XEA1), 0 otherwise (eg. XEA2) */
417#define XCHAL_HAVE_EXCM XCHAL_HAVE_XEA2 /* (DEPRECATED) 1 if PS.EXCM bit exists (currently equals XCHAL_HAVE_TLBS) */
418
419#define XCHAL_RESET_VECTOR_VADDR 0xFE000020
420#define XCHAL_RESET_VECTOR_PADDR 0xFE000020
421#define XCHAL_USER_VECTOR_VADDR 0xD0000220
422#define XCHAL_PROGRAMEXC_VECTOR_VADDR XCHAL_USER_VECTOR_VADDR /* for backward compatibility */
423#define XCHAL_USEREXC_VECTOR_VADDR XCHAL_USER_VECTOR_VADDR /* for backward compatibility */
424#define XCHAL_USER_VECTOR_PADDR 0x00000220
425#define XCHAL_PROGRAMEXC_VECTOR_PADDR XCHAL_USER_VECTOR_PADDR /* for backward compatibility */
426#define XCHAL_USEREXC_VECTOR_PADDR XCHAL_USER_VECTOR_PADDR /* for backward compatibility */
427#define XCHAL_KERNEL_VECTOR_VADDR 0xD0000200
428#define XCHAL_STACKEDEXC_VECTOR_VADDR XCHAL_KERNEL_VECTOR_VADDR /* for backward compatibility */
429#define XCHAL_KERNELEXC_VECTOR_VADDR XCHAL_KERNEL_VECTOR_VADDR /* for backward compatibility */
430#define XCHAL_KERNEL_VECTOR_PADDR 0x00000200
431#define XCHAL_STACKEDEXC_VECTOR_PADDR XCHAL_KERNEL_VECTOR_PADDR /* for backward compatibility */
432#define XCHAL_KERNELEXC_VECTOR_PADDR XCHAL_KERNEL_VECTOR_PADDR /* for backward compatibility */
433#define XCHAL_DOUBLEEXC_VECTOR_VADDR 0xD0000290
434#define XCHAL_DOUBLEEXC_VECTOR_PADDR 0x00000290
435#define XCHAL_WINDOW_VECTORS_VADDR 0xD0000000
436#define XCHAL_WINDOW_VECTORS_PADDR 0x00000000
437#define XCHAL_INTLEVEL2_VECTOR_VADDR 0xD0000240
438#define XCHAL_INTLEVEL2_VECTOR_PADDR 0x00000240
439#define XCHAL_INTLEVEL3_VECTOR_VADDR 0xD0000250
440#define XCHAL_INTLEVEL3_VECTOR_PADDR 0x00000250
441#define XCHAL_INTLEVEL4_VECTOR_VADDR 0xFE000520
442#define XCHAL_INTLEVEL4_VECTOR_PADDR 0xFE000520
443#define XCHAL_DEBUG_VECTOR_VADDR XCHAL_INTLEVEL4_VECTOR_VADDR
444#define XCHAL_DEBUG_VECTOR_PADDR XCHAL_INTLEVEL4_VECTOR_PADDR
445
446/* Indexing macros: */
447#define _XCHAL_INTLEVEL_VECTOR_VADDR(n) XCHAL_INTLEVEL ## n ## _VECTOR_VADDR
448#define XCHAL_INTLEVEL_VECTOR_VADDR(n) _XCHAL_INTLEVEL_VECTOR_VADDR(n) /* n = 0 .. 15 */
449
450/*
451 * General Exception Causes
452 * (values of EXCCAUSE special register set by general exceptions,
453 * which vector to the user, kernel, or double-exception vectors):
454 */
455#define XCHAL_EXCCAUSE_ILLEGAL_INSTRUCTION 0 /* Illegal Instruction (IllegalInstruction) */
456#define XCHAL_EXCCAUSE_SYSTEM_CALL 1 /* System Call (SystemCall) */
457#define XCHAL_EXCCAUSE_INSTRUCTION_FETCH_ERROR 2 /* Instruction Fetch Error (InstructionFetchError) */
458#define XCHAL_EXCCAUSE_LOAD_STORE_ERROR 3 /* Load Store Error (LoadStoreError) */
459#define XCHAL_EXCCAUSE_LEVEL1_INTERRUPT 4 /* Level 1 Interrupt (Level1Interrupt) */
460#define XCHAL_EXCCAUSE_ALLOCA 5 /* Stack Extension Assist (Alloca) */
461#define XCHAL_EXCCAUSE_INTEGER_DIVIDE_BY_ZERO 6 /* Integer Divide by Zero (IntegerDivideByZero) */
462#define XCHAL_EXCCAUSE_SPECULATION 7 /* Speculation (Speculation) */
463#define XCHAL_EXCCAUSE_PRIVILEGED 8 /* Privileged Instruction (Privileged) */
464#define XCHAL_EXCCAUSE_UNALIGNED 9 /* Unaligned Load Store (Unaligned) */
465#define XCHAL_EXCCAUSE_ITLB_MISS 16 /* ITlb Miss Exception (ITlbMiss) */
466#define XCHAL_EXCCAUSE_ITLB_MULTIHIT 17 /* ITlb Mutltihit Exception (ITlbMultihit) */
467#define XCHAL_EXCCAUSE_ITLB_PRIVILEGE 18 /* ITlb Privilege Exception (ITlbPrivilege) */
468#define XCHAL_EXCCAUSE_ITLB_SIZE_RESTRICTION 19 /* ITlb Size Restriction Exception (ITlbSizeRestriction) */
469#define XCHAL_EXCCAUSE_FETCH_CACHE_ATTRIBUTE 20 /* Fetch Cache Attribute Exception (FetchCacheAttribute) */
470#define XCHAL_EXCCAUSE_DTLB_MISS 24 /* DTlb Miss Exception (DTlbMiss) */
471#define XCHAL_EXCCAUSE_DTLB_MULTIHIT 25 /* DTlb Multihit Exception (DTlbMultihit) */
472#define XCHAL_EXCCAUSE_DTLB_PRIVILEGE 26 /* DTlb Privilege Exception (DTlbPrivilege) */
473#define XCHAL_EXCCAUSE_DTLB_SIZE_RESTRICTION 27 /* DTlb Size Restriction Exception (DTlbSizeRestriction) */
474#define XCHAL_EXCCAUSE_LOAD_CACHE_ATTRIBUTE 28 /* Load Cache Attribute Exception (LoadCacheAttribute) */
475#define XCHAL_EXCCAUSE_STORE_CACHE_ATTRIBUTE 29 /* Store Cache Attribute Exception (StoreCacheAttribute) */
476#define XCHAL_EXCCAUSE_FLOATING_POINT 40 /* Floating Point Exception (FloatingPoint) */
477
478
479
480/*----------------------------------------------------------------------
481 TIMERS
482 ----------------------------------------------------------------------*/
483
484#define XCHAL_HAVE_CCOUNT 1 /* 1 if have CCOUNT, 0 otherwise */
485/*#define XCHAL_HAVE_TIMERS XCHAL_HAVE_CCOUNT*/
486#define XCHAL_NUM_TIMERS 3 /* number of CCOMPAREn regs */
487
488
489
490/*----------------------------------------------------------------------
491 DEBUG
492 ----------------------------------------------------------------------*/
493
494#define XCHAL_HAVE_DEBUG 1 /* 1 if debug option configured, 0 otherwise */
495#define XCHAL_HAVE_OCD 1 /* 1 if OnChipDebug option configured, 0 otherwise */
496#define XCHAL_NUM_IBREAK 2 /* number of IBREAKn regs */
497#define XCHAL_NUM_DBREAK 2 /* number of DBREAKn regs */
498#define XCHAL_DEBUGLEVEL 4 /* debug interrupt level */
499/*DebugExternalInterrupt 0 0|1*/
500/*DebugUseDIRArray 0 0|1*/
501
502
503
504
505/*----------------------------------------------------------------------
506 COPROCESSORS and EXTRA STATE
507 ----------------------------------------------------------------------*/
508
509#define XCHAL_HAVE_CP 0 /* 1 if coprocessor option configured (CPENABLE present) */
510#define XCHAL_CP_MAXCFG 0 /* max allowed cp id plus one (per cfg) */
511
512#include <xtensa/config/tie.h>
513
514
515
516
517/*----------------------------------------------------------------------
518 INTERNAL I/D RAM/ROMs and XLMI
519 ----------------------------------------------------------------------*/
520
521#define XCHAL_NUM_INSTROM 0 /* number of core instruction ROMs configured */
522#define XCHAL_NUM_INSTRAM 0 /* number of core instruction RAMs configured */
523#define XCHAL_NUM_DATAROM 0 /* number of core data ROMs configured */
524#define XCHAL_NUM_DATARAM 0 /* number of core data RAMs configured */
525#define XCHAL_NUM_XLMI 0 /* number of core XLMI ports configured */
526#define XCHAL_NUM_IROM XCHAL_NUM_INSTROM /* (DEPRECATED) */
527#define XCHAL_NUM_IRAM XCHAL_NUM_INSTRAM /* (DEPRECATED) */
528#define XCHAL_NUM_DROM XCHAL_NUM_DATAROM /* (DEPRECATED) */
529#define XCHAL_NUM_DRAM XCHAL_NUM_DATARAM /* (DEPRECATED) */
530
531
532
533/*----------------------------------------------------------------------
534 CACHE
535 ----------------------------------------------------------------------*/
536
537/* Size of the cache lines in log2(bytes): */
538#define XCHAL_ICACHE_LINEWIDTH 4
539#define XCHAL_DCACHE_LINEWIDTH 4
540/* Size of the cache lines in bytes: */
541#define XCHAL_ICACHE_LINESIZE 16
542#define XCHAL_DCACHE_LINESIZE 16
543/* Max for both I-cache and D-cache (used for general alignment): */
544#define XCHAL_CACHE_LINEWIDTH_MAX 4
545#define XCHAL_CACHE_LINESIZE_MAX 16
546
547/* Number of cache sets in log2(lines per way): */
548#define XCHAL_ICACHE_SETWIDTH 8
549#define XCHAL_DCACHE_SETWIDTH 8
550/* Max for both I-cache and D-cache (used for general cache-coherency page alignment): */
551#define XCHAL_CACHE_SETWIDTH_MAX 8
552#define XCHAL_CACHE_SETSIZE_MAX 256
553
554/* Cache set associativity (number of ways): */
555#define XCHAL_ICACHE_WAYS 2
556#define XCHAL_DCACHE_WAYS 2
557
558/* Size of the caches in bytes (ways * 2^(linewidth + setwidth)): */
559#define XCHAL_ICACHE_SIZE 8192
560#define XCHAL_DCACHE_SIZE 8192
561
562/* Cache features: */
563#define XCHAL_DCACHE_IS_WRITEBACK 0
564/* Whether cache locking feature is available: */
565#define XCHAL_ICACHE_LINE_LOCKABLE 0
566#define XCHAL_DCACHE_LINE_LOCKABLE 0
567
568/* Number of (encoded) cache attribute bits: */
569#define XCHAL_CA_BITS 4 /* number of bits needed to hold cache attribute encoding */
570/* (The number of access mode bits (decoded cache attribute bits) is defined by the architecture; see xtensa/hal.h?) */
571
572
573/* Cache Attribute encodings -- lists of access modes for each cache attribute: */
574#define XCHAL_FCA_LIST XTHAL_FAM_EXCEPTION XCHAL_SEP \
575 XTHAL_FAM_BYPASS XCHAL_SEP \
576 XTHAL_FAM_EXCEPTION XCHAL_SEP \
577 XTHAL_FAM_BYPASS XCHAL_SEP \
578 XTHAL_FAM_EXCEPTION XCHAL_SEP \
579 XTHAL_FAM_CACHED XCHAL_SEP \
580 XTHAL_FAM_EXCEPTION XCHAL_SEP \
581 XTHAL_FAM_CACHED XCHAL_SEP \
582 XTHAL_FAM_EXCEPTION XCHAL_SEP \
583 XTHAL_FAM_CACHED XCHAL_SEP \
584 XTHAL_FAM_EXCEPTION XCHAL_SEP \
585 XTHAL_FAM_CACHED XCHAL_SEP \
586 XTHAL_FAM_EXCEPTION XCHAL_SEP \
587 XTHAL_FAM_EXCEPTION XCHAL_SEP \
588 XTHAL_FAM_EXCEPTION XCHAL_SEP \
589 XTHAL_FAM_EXCEPTION
590#define XCHAL_LCA_LIST XTHAL_LAM_EXCEPTION XCHAL_SEP \
591 XTHAL_LAM_BYPASSG XCHAL_SEP \
592 XTHAL_LAM_EXCEPTION XCHAL_SEP \
593 XTHAL_LAM_BYPASSG XCHAL_SEP \
594 XTHAL_LAM_EXCEPTION XCHAL_SEP \
595 XTHAL_LAM_CACHED XCHAL_SEP \
596 XTHAL_LAM_EXCEPTION XCHAL_SEP \
597 XTHAL_LAM_CACHED XCHAL_SEP \
598 XTHAL_LAM_EXCEPTION XCHAL_SEP \
599 XTHAL_LAM_NACACHED XCHAL_SEP \
600 XTHAL_LAM_EXCEPTION XCHAL_SEP \
601 XTHAL_LAM_NACACHED XCHAL_SEP \
602 XTHAL_LAM_EXCEPTION XCHAL_SEP \
603 XTHAL_LAM_ISOLATE XCHAL_SEP \
604 XTHAL_LAM_EXCEPTION XCHAL_SEP \
605 XTHAL_LAM_CACHED
606#define XCHAL_SCA_LIST XTHAL_SAM_EXCEPTION XCHAL_SEP \
607 XTHAL_SAM_EXCEPTION XCHAL_SEP \
608 XTHAL_SAM_EXCEPTION XCHAL_SEP \
609 XTHAL_SAM_BYPASS XCHAL_SEP \
610 XTHAL_SAM_EXCEPTION XCHAL_SEP \
611 XTHAL_SAM_EXCEPTION XCHAL_SEP \
612 XTHAL_SAM_EXCEPTION XCHAL_SEP \
613 XTHAL_SAM_WRITETHRU XCHAL_SEP \
614 XTHAL_SAM_EXCEPTION XCHAL_SEP \
615 XTHAL_SAM_EXCEPTION XCHAL_SEP \
616 XTHAL_SAM_EXCEPTION XCHAL_SEP \
617 XTHAL_SAM_WRITETHRU XCHAL_SEP \
618 XTHAL_SAM_EXCEPTION XCHAL_SEP \
619 XTHAL_SAM_ISOLATE XCHAL_SEP \
620 XTHAL_SAM_EXCEPTION XCHAL_SEP \
621 XTHAL_SAM_WRITETHRU
622
623/* Test:
624 read/only: 0 + 1 + 2 + 4 + 5 + 6 + 8 + 9 + 10 + 12 + 14
625 read/only: 0 + 1 + 2 + 4 + 5 + 6 + 8 + 9 + 10 + 12 + 14
626 all: 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15
627 fault: 0 + 2 + 4 + 6 + 8 + 10 + 12 + 14
628 r/w/x cached:
629 r/w/x dcached:
630 I-bypass: 1 + 3
631
632 load guard bit set: 1 + 3
633 load guard bit clr: 0 + 2 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15
634 hit-cache r/w/x: 7 + 11
635
636 fams: 5
637 fams: 0 / 6 / 18 / 1 / 2
638 fams: Bypass / Isolate / Cached / Exception / NACached
639
640 MMU okay: yes
641*/
642
643
644/*----------------------------------------------------------------------
645 MMU
646 ----------------------------------------------------------------------*/
647
648/*
649 * General notes on MMU parameters.
650 *
651 * Terminology:
652 * ASID = address-space ID (acts as an "extension" of virtual addresses)
653 * VPN = virtual page number
654 * PPN = physical page number
655 * CA = encoded cache attribute (access modes)
656 * TLB = translation look-aside buffer (term is stretched somewhat here)
657 * I = instruction (fetch accesses)
658 * D = data (load and store accesses)
659 * way = each TLB (ITLB and DTLB) consists of a number of "ways"
660 * that simultaneously match the virtual address of an access;
661 * a TLB successfully translates a virtual address if exactly
662 * one way matches the vaddr; if none match, it is a miss;
663 * if multiple match, one gets a "multihit" exception;
664 * each way can be independently configured in terms of number of
665 * entries, page sizes, which fields are writable or constant, etc.
666 * set = group of contiguous ways with exactly identical parameters
667 * ARF = auto-refill; hardware services a 1st-level miss by loading a PTE
668 * from the page table and storing it in one of the auto-refill ways;
669 * if this PTE load also misses, a miss exception is posted for s/w.
670 * min-wired = a "min-wired" way can be used to map a single (minimum-sized)
671 * page arbitrarily under program control; it has a single entry,
672 * is non-auto-refill (some other way(s) must be auto-refill),
673 * all its fields (VPN, PPN, ASID, CA) are all writable, and it
674 * supports the XCHAL_MMU_MIN_PTE_PAGE_SIZE page size (a current
675 * restriction is that this be the only page size it supports).
676 *
677 * TLB way entries are virtually indexed.
678 * TLB ways that support multiple page sizes:
679 * - must have all writable VPN and PPN fields;
680 * - can only use one page size at any given time (eg. setup at startup),
681 * selected by the respective ITLBCFG or DTLBCFG special register,
682 * whose bits n*4+3 .. n*4 index the list of page sizes for way n
683 * (XCHAL_xTLB_SETm_PAGESZ_LOG2_LIST for set m corresponding to way n);
684 * this list may be sparse for auto-refill ways because auto-refill
685 * ways have independent lists of supported page sizes sharing a
686 * common encoding with PTE entries; the encoding is the index into
687 * this list; unsupported sizes for a given way are zero in the list;
688 * selecting unsupported sizes results in undefined hardware behaviour;
689 * - is only possible for ways 0 thru 7 (due to ITLBCFG/DTLBCFG definition).
690 */
691
692#define XCHAL_HAVE_CACHEATTR 0 /* 1 if CACHEATTR register present, 0 if TLBs present instead */
693#define XCHAL_HAVE_TLBS 1 /* 1 if TLBs present, 0 if CACHEATTR present instead */
694#define XCHAL_HAVE_MMU XCHAL_HAVE_TLBS /* (DEPRECATED; use XCHAL_HAVE_TLBS instead; will be removed in future release) */
695#define XCHAL_HAVE_SPANNING_WAY 0 /* 1 if single way maps entire virtual address space in I+D */
696#define XCHAL_HAVE_IDENTITY_MAP 0 /* 1 if virtual addr == physical addr always, 0 otherwise */
697#define XCHAL_HAVE_MIMIC_CACHEATTR 0 /* 1 if have MMU that mimics a CACHEATTR config (CaMMU) */
698#define XCHAL_HAVE_XLT_CACHEATTR 0 /* 1 if have MMU that mimics a CACHEATTR config, but with translation (CaXltMMU) */
699
700#define XCHAL_MMU_ASID_BITS 8 /* number of bits in ASIDs (address space IDs) */
701#define XCHAL_MMU_ASID_INVALID 0 /* ASID value indicating invalid address space */
702#define XCHAL_MMU_ASID_KERNEL 1 /* ASID value indicating kernel (ring 0) address space */
703#define XCHAL_MMU_RINGS 4 /* number of rings supported (1..4) */
704#define XCHAL_MMU_RING_BITS 2 /* number of bits needed to hold ring number */
705#define XCHAL_MMU_SR_BITS 0 /* number of size-restriction bits supported */
706#define XCHAL_MMU_CA_BITS 4 /* number of bits needed to hold cache attribute encoding */
707#define XCHAL_MMU_MAX_PTE_PAGE_SIZE 12 /* max page size in a PTE structure (log2) */
708#define XCHAL_MMU_MIN_PTE_PAGE_SIZE 12 /* min page size in a PTE structure (log2) */
709
710
711/*** Instruction TLB: ***/
712
713#define XCHAL_ITLB_WAY_BITS 3 /* number of bits holding the ways */
714#define XCHAL_ITLB_WAYS 7 /* number of ways (n-way set-associative TLB) */
715#define XCHAL_ITLB_ARF_WAYS 4 /* number of auto-refill ways */
716#define XCHAL_ITLB_SETS 4 /* number of sets (groups of ways with identical settings) */
717
718/* Way set to which each way belongs: */
719#define XCHAL_ITLB_WAY0_SET 0
720#define XCHAL_ITLB_WAY1_SET 0
721#define XCHAL_ITLB_WAY2_SET 0
722#define XCHAL_ITLB_WAY3_SET 0
723#define XCHAL_ITLB_WAY4_SET 1
724#define XCHAL_ITLB_WAY5_SET 2
725#define XCHAL_ITLB_WAY6_SET 3
726
727/* Ways sets that are used by hardware auto-refill (ARF): */
728#define XCHAL_ITLB_ARF_SETS 1 /* number of auto-refill sets */
729#define XCHAL_ITLB_ARF_SET0 0 /* index of n'th auto-refill set */
730
731/* Way sets that are "min-wired" (see terminology comment above): */
732#define XCHAL_ITLB_MINWIRED_SETS 0 /* number of "min-wired" sets */
733
734
735/* ITLB way set 0 (group of ways 0 thru 3): */
736#define XCHAL_ITLB_SET0_WAY 0 /* index of first way in this way set */
737#define XCHAL_ITLB_SET0_WAYS 4 /* number of (contiguous) ways in this way set */
738#define XCHAL_ITLB_SET0_ENTRIES_LOG2 2 /* log2(number of entries in this way) */
739#define XCHAL_ITLB_SET0_ENTRIES 4 /* number of entries in this way (always a power of 2) */
740#define XCHAL_ITLB_SET0_ARF 1 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
741#define XCHAL_ITLB_SET0_PAGESIZES 1 /* number of supported page sizes in this way */
742#define XCHAL_ITLB_SET0_PAGESZ_BITS 0 /* number of bits to encode the page size */
743#define XCHAL_ITLB_SET0_PAGESZ_LOG2_MIN 12 /* log2(minimum supported page size) */
744#define XCHAL_ITLB_SET0_PAGESZ_LOG2_MAX 12 /* log2(maximum supported page size) */
745#define XCHAL_ITLB_SET0_PAGESZ_LOG2_LIST 12 /* list of log2(page size)s, separated by XCHAL_SEP;
746 2^PAGESZ_BITS entries in list, unsupported entries are zero */
747#define XCHAL_ITLB_SET0_ASID_CONSTMASK 0 /* constant ASID bits; 0 if all writable */
748#define XCHAL_ITLB_SET0_VPN_CONSTMASK 0 /* constant VPN bits, not including entry index bits; 0 if all writable */
749#define XCHAL_ITLB_SET0_PPN_CONSTMASK 0 /* constant PPN bits, including entry index bits; 0 if all writable */
750#define XCHAL_ITLB_SET0_CA_CONSTMASK 0 /* constant CA bits; 0 if all writable */
751#define XCHAL_ITLB_SET0_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
752#define XCHAL_ITLB_SET0_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
753#define XCHAL_ITLB_SET0_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
754#define XCHAL_ITLB_SET0_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
755
756/* ITLB way set 1 (group of ways 4 thru 4): */
757#define XCHAL_ITLB_SET1_WAY 4 /* index of first way in this way set */
758#define XCHAL_ITLB_SET1_WAYS 1 /* number of (contiguous) ways in this way set */
759#define XCHAL_ITLB_SET1_ENTRIES_LOG2 2 /* log2(number of entries in this way) */
760#define XCHAL_ITLB_SET1_ENTRIES 4 /* number of entries in this way (always a power of 2) */
761#define XCHAL_ITLB_SET1_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
762#define XCHAL_ITLB_SET1_PAGESIZES 4 /* number of supported page sizes in this way */
763#define XCHAL_ITLB_SET1_PAGESZ_BITS 2 /* number of bits to encode the page size */
764#define XCHAL_ITLB_SET1_PAGESZ_LOG2_MIN 20 /* log2(minimum supported page size) */
765#define XCHAL_ITLB_SET1_PAGESZ_LOG2_MAX 26 /* log2(maximum supported page size) */
766#define XCHAL_ITLB_SET1_PAGESZ_LOG2_LIST 20 XCHAL_SEP 22 XCHAL_SEP 24 XCHAL_SEP 26 /* list of log2(page size)s, separated by XCHAL_SEP;
767 2^PAGESZ_BITS entries in list, unsupported entries are zero */
768#define XCHAL_ITLB_SET1_ASID_CONSTMASK 0 /* constant ASID bits; 0 if all writable */
769#define XCHAL_ITLB_SET1_VPN_CONSTMASK 0 /* constant VPN bits, not including entry index bits; 0 if all writable */
770#define XCHAL_ITLB_SET1_PPN_CONSTMASK 0 /* constant PPN bits, including entry index bits; 0 if all writable */
771#define XCHAL_ITLB_SET1_CA_CONSTMASK 0 /* constant CA bits; 0 if all writable */
772#define XCHAL_ITLB_SET1_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
773#define XCHAL_ITLB_SET1_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
774#define XCHAL_ITLB_SET1_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
775#define XCHAL_ITLB_SET1_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
776
777/* ITLB way set 2 (group of ways 5 thru 5): */
778#define XCHAL_ITLB_SET2_WAY 5 /* index of first way in this way set */
779#define XCHAL_ITLB_SET2_WAYS 1 /* number of (contiguous) ways in this way set */
780#define XCHAL_ITLB_SET2_ENTRIES_LOG2 1 /* log2(number of entries in this way) */
781#define XCHAL_ITLB_SET2_ENTRIES 2 /* number of entries in this way (always a power of 2) */
782#define XCHAL_ITLB_SET2_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
783#define XCHAL_ITLB_SET2_PAGESIZES 1 /* number of supported page sizes in this way */
784#define XCHAL_ITLB_SET2_PAGESZ_BITS 0 /* number of bits to encode the page size */
785#define XCHAL_ITLB_SET2_PAGESZ_LOG2_MIN 27 /* log2(minimum supported page size) */
786#define XCHAL_ITLB_SET2_PAGESZ_LOG2_MAX 27 /* log2(maximum supported page size) */
787#define XCHAL_ITLB_SET2_PAGESZ_LOG2_LIST 27 /* list of log2(page size)s, separated by XCHAL_SEP;
788 2^PAGESZ_BITS entries in list, unsupported entries are zero */
789#define XCHAL_ITLB_SET2_ASID_CONSTMASK 0xFF /* constant ASID bits; 0 if all writable */
790#define XCHAL_ITLB_SET2_VPN_CONSTMASK 0xF0000000 /* constant VPN bits, not including entry index bits; 0 if all writable */
791#define XCHAL_ITLB_SET2_PPN_CONSTMASK 0xF8000000 /* constant PPN bits, including entry index bits; 0 if all writable */
792#define XCHAL_ITLB_SET2_CA_CONSTMASK 0x0000000F /* constant CA bits; 0 if all writable */
793#define XCHAL_ITLB_SET2_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
794#define XCHAL_ITLB_SET2_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
795#define XCHAL_ITLB_SET2_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
796#define XCHAL_ITLB_SET2_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
797/* Constant ASID values for each entry of ITLB way set 2 (because ASID_CONSTMASK is non-zero): */
798#define XCHAL_ITLB_SET2_E0_ASID_CONST 0x01
799#define XCHAL_ITLB_SET2_E1_ASID_CONST 0x01
800/* Constant VPN values for each entry of ITLB way set 2 (because VPN_CONSTMASK is non-zero): */
801#define XCHAL_ITLB_SET2_E0_VPN_CONST 0xD0000000
802#define XCHAL_ITLB_SET2_E1_VPN_CONST 0xD8000000
803/* Constant PPN values for each entry of ITLB way set 2 (because PPN_CONSTMASK is non-zero): */
804#define XCHAL_ITLB_SET2_E0_PPN_CONST 0x00000000
805#define XCHAL_ITLB_SET2_E1_PPN_CONST 0x00000000
806/* Constant CA values for each entry of ITLB way set 2 (because CA_CONSTMASK is non-zero): */
807#define XCHAL_ITLB_SET2_E0_CA_CONST 0x07
808#define XCHAL_ITLB_SET2_E1_CA_CONST 0x03
809
810/* ITLB way set 3 (group of ways 6 thru 6): */
811#define XCHAL_ITLB_SET3_WAY 6 /* index of first way in this way set */
812#define XCHAL_ITLB_SET3_WAYS 1 /* number of (contiguous) ways in this way set */
813#define XCHAL_ITLB_SET3_ENTRIES_LOG2 1 /* log2(number of entries in this way) */
814#define XCHAL_ITLB_SET3_ENTRIES 2 /* number of entries in this way (always a power of 2) */
815#define XCHAL_ITLB_SET3_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
816#define XCHAL_ITLB_SET3_PAGESIZES 1 /* number of supported page sizes in this way */
817#define XCHAL_ITLB_SET3_PAGESZ_BITS 0 /* number of bits to encode the page size */
818#define XCHAL_ITLB_SET3_PAGESZ_LOG2_MIN 28 /* log2(minimum supported page size) */
819#define XCHAL_ITLB_SET3_PAGESZ_LOG2_MAX 28 /* log2(maximum supported page size) */
820#define XCHAL_ITLB_SET3_PAGESZ_LOG2_LIST 28 /* list of log2(page size)s, separated by XCHAL_SEP;
821 2^PAGESZ_BITS entries in list, unsupported entries are zero */
822#define XCHAL_ITLB_SET3_ASID_CONSTMASK 0xFF /* constant ASID bits; 0 if all writable */
823#define XCHAL_ITLB_SET3_VPN_CONSTMASK 0xE0000000 /* constant VPN bits, not including entry index bits; 0 if all writable */
824#define XCHAL_ITLB_SET3_PPN_CONSTMASK 0xF0000000 /* constant PPN bits, including entry index bits; 0 if all writable */
825#define XCHAL_ITLB_SET3_CA_CONSTMASK 0x0000000F /* constant CA bits; 0 if all writable */
826#define XCHAL_ITLB_SET3_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
827#define XCHAL_ITLB_SET3_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
828#define XCHAL_ITLB_SET3_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
829#define XCHAL_ITLB_SET3_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
830/* Constant ASID values for each entry of ITLB way set 3 (because ASID_CONSTMASK is non-zero): */
831#define XCHAL_ITLB_SET3_E0_ASID_CONST 0x01
832#define XCHAL_ITLB_SET3_E1_ASID_CONST 0x01
833/* Constant VPN values for each entry of ITLB way set 3 (because VPN_CONSTMASK is non-zero): */
834#define XCHAL_ITLB_SET3_E0_VPN_CONST 0xE0000000
835#define XCHAL_ITLB_SET3_E1_VPN_CONST 0xF0000000
836/* Constant PPN values for each entry of ITLB way set 3 (because PPN_CONSTMASK is non-zero): */
837#define XCHAL_ITLB_SET3_E0_PPN_CONST 0xF0000000
838#define XCHAL_ITLB_SET3_E1_PPN_CONST 0xF0000000
839/* Constant CA values for each entry of ITLB way set 3 (because CA_CONSTMASK is non-zero): */
840#define XCHAL_ITLB_SET3_E0_CA_CONST 0x07
841#define XCHAL_ITLB_SET3_E1_CA_CONST 0x03
842
843/* Indexing macros: */
844#define _XCHAL_ITLB_SET(n,_what) XCHAL_ITLB_SET ## n ## _what
845#define XCHAL_ITLB_SET(n,what) _XCHAL_ITLB_SET(n, _ ## what )
846#define _XCHAL_ITLB_SET_E(n,i,_what) XCHAL_ITLB_SET ## n ## _E ## i ## _what
847#define XCHAL_ITLB_SET_E(n,i,what) _XCHAL_ITLB_SET_E(n,i, _ ## what )
848/*
849 * Example use: XCHAL_ITLB_SET(XCHAL_ITLB_ARF_SET0,ENTRIES)
850 * to get the value of XCHAL_ITLB_SET<n>_ENTRIES where <n> is the first auto-refill set.
851 */
852
853
854/*** Data TLB: ***/
855
856#define XCHAL_DTLB_WAY_BITS 4 /* number of bits holding the ways */
857#define XCHAL_DTLB_WAYS 10 /* number of ways (n-way set-associative TLB) */
858#define XCHAL_DTLB_ARF_WAYS 4 /* number of auto-refill ways */
859#define XCHAL_DTLB_SETS 5 /* number of sets (groups of ways with identical settings) */
860
861/* Way set to which each way belongs: */
862#define XCHAL_DTLB_WAY0_SET 0
863#define XCHAL_DTLB_WAY1_SET 0
864#define XCHAL_DTLB_WAY2_SET 0
865#define XCHAL_DTLB_WAY3_SET 0
866#define XCHAL_DTLB_WAY4_SET 1
867#define XCHAL_DTLB_WAY5_SET 2
868#define XCHAL_DTLB_WAY6_SET 3
869#define XCHAL_DTLB_WAY7_SET 4
870#define XCHAL_DTLB_WAY8_SET 4
871#define XCHAL_DTLB_WAY9_SET 4
872
873/* Ways sets that are used by hardware auto-refill (ARF): */
874#define XCHAL_DTLB_ARF_SETS 1 /* number of auto-refill sets */
875#define XCHAL_DTLB_ARF_SET0 0 /* index of n'th auto-refill set */
876
877/* Way sets that are "min-wired" (see terminology comment above): */
878#define XCHAL_DTLB_MINWIRED_SETS 1 /* number of "min-wired" sets */
879#define XCHAL_DTLB_MINWIRED_SET0 4 /* index of n'th "min-wired" set */
880
881
882/* DTLB way set 0 (group of ways 0 thru 3): */
883#define XCHAL_DTLB_SET0_WAY 0 /* index of first way in this way set */
884#define XCHAL_DTLB_SET0_WAYS 4 /* number of (contiguous) ways in this way set */
885#define XCHAL_DTLB_SET0_ENTRIES_LOG2 2 /* log2(number of entries in this way) */
886#define XCHAL_DTLB_SET0_ENTRIES 4 /* number of entries in this way (always a power of 2) */
887#define XCHAL_DTLB_SET0_ARF 1 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
888#define XCHAL_DTLB_SET0_PAGESIZES 1 /* number of supported page sizes in this way */
889#define XCHAL_DTLB_SET0_PAGESZ_BITS 0 /* number of bits to encode the page size */
890#define XCHAL_DTLB_SET0_PAGESZ_LOG2_MIN 12 /* log2(minimum supported page size) */
891#define XCHAL_DTLB_SET0_PAGESZ_LOG2_MAX 12 /* log2(maximum supported page size) */
892#define XCHAL_DTLB_SET0_PAGESZ_LOG2_LIST 12 /* list of log2(page size)s, separated by XCHAL_SEP;
893 2^PAGESZ_BITS entries in list, unsupported entries are zero */
894#define XCHAL_DTLB_SET0_ASID_CONSTMASK 0 /* constant ASID bits; 0 if all writable */
895#define XCHAL_DTLB_SET0_VPN_CONSTMASK 0 /* constant VPN bits, not including entry index bits; 0 if all writable */
896#define XCHAL_DTLB_SET0_PPN_CONSTMASK 0 /* constant PPN bits, including entry index bits; 0 if all writable */
897#define XCHAL_DTLB_SET0_CA_CONSTMASK 0 /* constant CA bits; 0 if all writable */
898#define XCHAL_DTLB_SET0_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
899#define XCHAL_DTLB_SET0_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
900#define XCHAL_DTLB_SET0_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
901#define XCHAL_DTLB_SET0_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
902
903/* DTLB way set 1 (group of ways 4 thru 4): */
904#define XCHAL_DTLB_SET1_WAY 4 /* index of first way in this way set */
905#define XCHAL_DTLB_SET1_WAYS 1 /* number of (contiguous) ways in this way set */
906#define XCHAL_DTLB_SET1_ENTRIES_LOG2 2 /* log2(number of entries in this way) */
907#define XCHAL_DTLB_SET1_ENTRIES 4 /* number of entries in this way (always a power of 2) */
908#define XCHAL_DTLB_SET1_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
909#define XCHAL_DTLB_SET1_PAGESIZES 4 /* number of supported page sizes in this way */
910#define XCHAL_DTLB_SET1_PAGESZ_BITS 2 /* number of bits to encode the page size */
911#define XCHAL_DTLB_SET1_PAGESZ_LOG2_MIN 20 /* log2(minimum supported page size) */
912#define XCHAL_DTLB_SET1_PAGESZ_LOG2_MAX 26 /* log2(maximum supported page size) */
913#define XCHAL_DTLB_SET1_PAGESZ_LOG2_LIST 20 XCHAL_SEP 22 XCHAL_SEP 24 XCHAL_SEP 26 /* list of log2(page size)s, separated by XCHAL_SEP;
914 2^PAGESZ_BITS entries in list, unsupported entries are zero */
915#define XCHAL_DTLB_SET1_ASID_CONSTMASK 0 /* constant ASID bits; 0 if all writable */
916#define XCHAL_DTLB_SET1_VPN_CONSTMASK 0 /* constant VPN bits, not including entry index bits; 0 if all writable */
917#define XCHAL_DTLB_SET1_PPN_CONSTMASK 0 /* constant PPN bits, including entry index bits; 0 if all writable */
918#define XCHAL_DTLB_SET1_CA_CONSTMASK 0 /* constant CA bits; 0 if all writable */
919#define XCHAL_DTLB_SET1_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
920#define XCHAL_DTLB_SET1_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
921#define XCHAL_DTLB_SET1_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
922#define XCHAL_DTLB_SET1_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
923
924/* DTLB way set 2 (group of ways 5 thru 5): */
925#define XCHAL_DTLB_SET2_WAY 5 /* index of first way in this way set */
926#define XCHAL_DTLB_SET2_WAYS 1 /* number of (contiguous) ways in this way set */
927#define XCHAL_DTLB_SET2_ENTRIES_LOG2 1 /* log2(number of entries in this way) */
928#define XCHAL_DTLB_SET2_ENTRIES 2 /* number of entries in this way (always a power of 2) */
929#define XCHAL_DTLB_SET2_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
930#define XCHAL_DTLB_SET2_PAGESIZES 1 /* number of supported page sizes in this way */
931#define XCHAL_DTLB_SET2_PAGESZ_BITS 0 /* number of bits to encode the page size */
932#define XCHAL_DTLB_SET2_PAGESZ_LOG2_MIN 27 /* log2(minimum supported page size) */
933#define XCHAL_DTLB_SET2_PAGESZ_LOG2_MAX 27 /* log2(maximum supported page size) */
934#define XCHAL_DTLB_SET2_PAGESZ_LOG2_LIST 27 /* list of log2(page size)s, separated by XCHAL_SEP;
935 2^PAGESZ_BITS entries in list, unsupported entries are zero */
936#define XCHAL_DTLB_SET2_ASID_CONSTMASK 0xFF /* constant ASID bits; 0 if all writable */
937#define XCHAL_DTLB_SET2_VPN_CONSTMASK 0xF0000000 /* constant VPN bits, not including entry index bits; 0 if all writable */
938#define XCHAL_DTLB_SET2_PPN_CONSTMASK 0xF8000000 /* constant PPN bits, including entry index bits; 0 if all writable */
939#define XCHAL_DTLB_SET2_CA_CONSTMASK 0x0000000F /* constant CA bits; 0 if all writable */
940#define XCHAL_DTLB_SET2_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
941#define XCHAL_DTLB_SET2_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
942#define XCHAL_DTLB_SET2_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
943#define XCHAL_DTLB_SET2_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
944/* Constant ASID values for each entry of DTLB way set 2 (because ASID_CONSTMASK is non-zero): */
945#define XCHAL_DTLB_SET2_E0_ASID_CONST 0x01
946#define XCHAL_DTLB_SET2_E1_ASID_CONST 0x01
947/* Constant VPN values for each entry of DTLB way set 2 (because VPN_CONSTMASK is non-zero): */
948#define XCHAL_DTLB_SET2_E0_VPN_CONST 0xD0000000
949#define XCHAL_DTLB_SET2_E1_VPN_CONST 0xD8000000
950/* Constant PPN values for each entry of DTLB way set 2 (because PPN_CONSTMASK is non-zero): */
951#define XCHAL_DTLB_SET2_E0_PPN_CONST 0x00000000
952#define XCHAL_DTLB_SET2_E1_PPN_CONST 0x00000000
953/* Constant CA values for each entry of DTLB way set 2 (because CA_CONSTMASK is non-zero): */
954#define XCHAL_DTLB_SET2_E0_CA_CONST 0x07
955#define XCHAL_DTLB_SET2_E1_CA_CONST 0x03
956
957/* DTLB way set 3 (group of ways 6 thru 6): */
958#define XCHAL_DTLB_SET3_WAY 6 /* index of first way in this way set */
959#define XCHAL_DTLB_SET3_WAYS 1 /* number of (contiguous) ways in this way set */
960#define XCHAL_DTLB_SET3_ENTRIES_LOG2 1 /* log2(number of entries in this way) */
961#define XCHAL_DTLB_SET3_ENTRIES 2 /* number of entries in this way (always a power of 2) */
962#define XCHAL_DTLB_SET3_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
963#define XCHAL_DTLB_SET3_PAGESIZES 1 /* number of supported page sizes in this way */
964#define XCHAL_DTLB_SET3_PAGESZ_BITS 0 /* number of bits to encode the page size */
965#define XCHAL_DTLB_SET3_PAGESZ_LOG2_MIN 28 /* log2(minimum supported page size) */
966#define XCHAL_DTLB_SET3_PAGESZ_LOG2_MAX 28 /* log2(maximum supported page size) */
967#define XCHAL_DTLB_SET3_PAGESZ_LOG2_LIST 28 /* list of log2(page size)s, separated by XCHAL_SEP;
968 2^PAGESZ_BITS entries in list, unsupported entries are zero */
969#define XCHAL_DTLB_SET3_ASID_CONSTMASK 0xFF /* constant ASID bits; 0 if all writable */
970#define XCHAL_DTLB_SET3_VPN_CONSTMASK 0xE0000000 /* constant VPN bits, not including entry index bits; 0 if all writable */
971#define XCHAL_DTLB_SET3_PPN_CONSTMASK 0xF0000000 /* constant PPN bits, including entry index bits; 0 if all writable */
972#define XCHAL_DTLB_SET3_CA_CONSTMASK 0x0000000F /* constant CA bits; 0 if all writable */
973#define XCHAL_DTLB_SET3_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
974#define XCHAL_DTLB_SET3_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
975#define XCHAL_DTLB_SET3_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
976#define XCHAL_DTLB_SET3_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
977/* Constant ASID values for each entry of DTLB way set 3 (because ASID_CONSTMASK is non-zero): */
978#define XCHAL_DTLB_SET3_E0_ASID_CONST 0x01
979#define XCHAL_DTLB_SET3_E1_ASID_CONST 0x01
980/* Constant VPN values for each entry of DTLB way set 3 (because VPN_CONSTMASK is non-zero): */
981#define XCHAL_DTLB_SET3_E0_VPN_CONST 0xE0000000
982#define XCHAL_DTLB_SET3_E1_VPN_CONST 0xF0000000
983/* Constant PPN values for each entry of DTLB way set 3 (because PPN_CONSTMASK is non-zero): */
984#define XCHAL_DTLB_SET3_E0_PPN_CONST 0xF0000000
985#define XCHAL_DTLB_SET3_E1_PPN_CONST 0xF0000000
986/* Constant CA values for each entry of DTLB way set 3 (because CA_CONSTMASK is non-zero): */
987#define XCHAL_DTLB_SET3_E0_CA_CONST 0x07
988#define XCHAL_DTLB_SET3_E1_CA_CONST 0x03
989
990/* DTLB way set 4 (group of ways 7 thru 9): */
991#define XCHAL_DTLB_SET4_WAY 7 /* index of first way in this way set */
992#define XCHAL_DTLB_SET4_WAYS 3 /* number of (contiguous) ways in this way set */
993#define XCHAL_DTLB_SET4_ENTRIES_LOG2 0 /* log2(number of entries in this way) */
994#define XCHAL_DTLB_SET4_ENTRIES 1 /* number of entries in this way (always a power of 2) */
995#define XCHAL_DTLB_SET4_ARF 0 /* 1=autorefill by h/w, 0=non-autorefill (wired/constant/static) */
996#define XCHAL_DTLB_SET4_PAGESIZES 1 /* number of supported page sizes in this way */
997#define XCHAL_DTLB_SET4_PAGESZ_BITS 0 /* number of bits to encode the page size */
998#define XCHAL_DTLB_SET4_PAGESZ_LOG2_MIN 12 /* log2(minimum supported page size) */
999#define XCHAL_DTLB_SET4_PAGESZ_LOG2_MAX 12 /* log2(maximum supported page size) */
1000#define XCHAL_DTLB_SET4_PAGESZ_LOG2_LIST 12 /* list of log2(page size)s, separated by XCHAL_SEP;
1001 2^PAGESZ_BITS entries in list, unsupported entries are zero */
1002#define XCHAL_DTLB_SET4_ASID_CONSTMASK 0 /* constant ASID bits; 0 if all writable */
1003#define XCHAL_DTLB_SET4_VPN_CONSTMASK 0 /* constant VPN bits, not including entry index bits; 0 if all writable */
1004#define XCHAL_DTLB_SET4_PPN_CONSTMASK 0 /* constant PPN bits, including entry index bits; 0 if all writable */
1005#define XCHAL_DTLB_SET4_CA_CONSTMASK 0 /* constant CA bits; 0 if all writable */
1006#define XCHAL_DTLB_SET4_ASID_RESET 0 /* 1 if ASID reset values defined (and all writable); 0 otherwise */
1007#define XCHAL_DTLB_SET4_VPN_RESET 0 /* 1 if VPN reset values defined (and all writable); 0 otherwise */
1008#define XCHAL_DTLB_SET4_PPN_RESET 0 /* 1 if PPN reset values defined (and all writable); 0 otherwise */
1009#define XCHAL_DTLB_SET4_CA_RESET 0 /* 1 if CA reset values defined (and all writable); 0 otherwise */
1010
1011/* Indexing macros: */
1012#define _XCHAL_DTLB_SET(n,_what) XCHAL_DTLB_SET ## n ## _what
1013#define XCHAL_DTLB_SET(n,what) _XCHAL_DTLB_SET(n, _ ## what )
1014#define _XCHAL_DTLB_SET_E(n,i,_what) XCHAL_DTLB_SET ## n ## _E ## i ## _what
1015#define XCHAL_DTLB_SET_E(n,i,what) _XCHAL_DTLB_SET_E(n,i, _ ## what )
1016/*
1017 * Example use: XCHAL_DTLB_SET(XCHAL_DTLB_ARF_SET0,ENTRIES)
1018 * to get the value of XCHAL_DTLB_SET<n>_ENTRIES where <n> is the first auto-refill set.
1019 */
1020
1021
1022/*
1023 * Determine whether we have a full MMU (with Page Table and Protection)
1024 * usable for an MMU-based OS:
1025 */
1026#if XCHAL_HAVE_TLBS && !XCHAL_HAVE_SPANNING_WAY && XCHAL_ITLB_ARF_WAYS > 0 && XCHAL_DTLB_ARF_WAYS > 0 && XCHAL_MMU_RINGS >= 2
1027# define XCHAL_HAVE_PTP_MMU 1 /* have full MMU (with page table [autorefill] and protection) */
1028#else
1029# define XCHAL_HAVE_PTP_MMU 0 /* don't have full MMU */
1030#endif
1031
1032/*
1033 * For full MMUs, report kernel RAM segment and kernel I/O segment static page mappings:
1034 */
1035#if XCHAL_HAVE_PTP_MMU
1036#define XCHAL_KSEG_CACHED_VADDR 0xD0000000 /* virt.addr of kernel RAM cached static map */
1037#define XCHAL_KSEG_CACHED_PADDR 0x00000000 /* phys.addr of kseg_cached */
1038#define XCHAL_KSEG_CACHED_SIZE 0x08000000 /* size in bytes of kseg_cached (assumed power of 2!!!) */
1039#define XCHAL_KSEG_BYPASS_VADDR 0xD8000000 /* virt.addr of kernel RAM bypass (uncached) static map */
1040#define XCHAL_KSEG_BYPASS_PADDR 0x00000000 /* phys.addr of kseg_bypass */
1041#define XCHAL_KSEG_BYPASS_SIZE 0x08000000 /* size in bytes of kseg_bypass (assumed power of 2!!!) */
1042
1043#define XCHAL_KIO_CACHED_VADDR 0xE0000000 /* virt.addr of kernel I/O cached static map */
1044#define XCHAL_KIO_CACHED_PADDR 0xF0000000 /* phys.addr of kio_cached */
1045#define XCHAL_KIO_CACHED_SIZE 0x10000000 /* size in bytes of kio_cached (assumed power of 2!!!) */
1046#define XCHAL_KIO_BYPASS_VADDR 0xF0000000 /* virt.addr of kernel I/O bypass (uncached) static map */
1047#define XCHAL_KIO_BYPASS_PADDR 0xF0000000 /* phys.addr of kio_bypass */
1048#define XCHAL_KIO_BYPASS_SIZE 0x10000000 /* size in bytes of kio_bypass (assumed power of 2!!!) */
1049
1050#define XCHAL_SEG_MAPPABLE_VADDR 0x00000000 /* start of largest non-static-mapped virtual addr area */
1051#define XCHAL_SEG_MAPPABLE_SIZE 0xD0000000 /* size in bytes of " */
1052/* define XCHAL_SEG_MAPPABLE2_xxx if more areas present, sorted in order of descending size. */
1053#endif
1054
1055
1056/*----------------------------------------------------------------------
1057 MISC
1058 ----------------------------------------------------------------------*/
1059
1060#define XCHAL_NUM_WRITEBUFFER_ENTRIES 4 /* number of write buffer entries */
1061
1062#define XCHAL_CORE_ID "linux_be" /* configuration's alphanumeric core identifier
1063 (CoreID) set in the Xtensa Processor Generator */
1064
1065#define XCHAL_BUILD_UNIQUE_ID 0x00003256 /* software build-unique ID (22-bit) */
1066
1067/* These definitions describe the hardware targeted by this software: */
1068#define XCHAL_HW_CONFIGID0 0xC103D1FF /* config ID reg 0 value (upper 32 of 64 bits) */
1069#define XCHAL_HW_CONFIGID1 0x00803256 /* config ID reg 1 value (lower 32 of 64 bits) */
1070#define XCHAL_CONFIGID0 XCHAL_HW_CONFIGID0 /* for backward compatibility only -- don't use! */
1071#define XCHAL_CONFIGID1 XCHAL_HW_CONFIGID1 /* for backward compatibility only -- don't use! */
1072#define XCHAL_HW_RELEASE_MAJOR 1050 /* major release of targeted hardware */
1073#define XCHAL_HW_RELEASE_MINOR 1 /* minor release of targeted hardware */
1074#define XCHAL_HW_RELEASE_NAME "T1050.1" /* full release name of targeted hardware */
1075#define XTHAL_HW_REL_T1050 1
1076#define XTHAL_HW_REL_T1050_1 1
1077#define XCHAL_HW_CONFIGID_RELIABLE 1
1078
1079
1080/*
1081 * Miscellaneous special register fields:
1082 */
1083
1084
1085/* DBREAKC (special register number 160): */
1086#define XCHAL_DBREAKC_VALIDMASK 0xC000003F /* bits of DBREAKC that are defined */
1087/* MASK field: */
1088#define XCHAL_DBREAKC_MASK_BITS 6 /* number of bits in MASK field */
1089#define XCHAL_DBREAKC_MASK_NUM 64 /* max number of possible causes (2^bits) */
1090#define XCHAL_DBREAKC_MASK_SHIFT 0 /* position of MASK bits in DBREAKC, starting from lsbit */
1091#define XCHAL_DBREAKC_MASK_MASK 0x0000003F /* mask of bits in MASK field of DBREAKC */
1092/* LOADBREAK field: */
1093#define XCHAL_DBREAKC_LOADBREAK_BITS 1 /* number of bits in LOADBREAK field */
1094#define XCHAL_DBREAKC_LOADBREAK_NUM 2 /* max number of possible causes (2^bits) */
1095#define XCHAL_DBREAKC_LOADBREAK_SHIFT 30 /* position of LOADBREAK bits in DBREAKC, starting from lsbit */
1096#define XCHAL_DBREAKC_LOADBREAK_MASK 0x40000000 /* mask of bits in LOADBREAK field of DBREAKC */
1097/* STOREBREAK field: */
1098#define XCHAL_DBREAKC_STOREBREAK_BITS 1 /* number of bits in STOREBREAK field */
1099#define XCHAL_DBREAKC_STOREBREAK_NUM 2 /* max number of possible causes (2^bits) */
1100#define XCHAL_DBREAKC_STOREBREAK_SHIFT 31 /* position of STOREBREAK bits in DBREAKC, starting from lsbit */
1101#define XCHAL_DBREAKC_STOREBREAK_MASK 0x80000000 /* mask of bits in STOREBREAK field of DBREAKC */
1102
1103/* PS (special register number 230): */
1104#define XCHAL_PS_VALIDMASK 0x00070FFF /* bits of PS that are defined */
1105/* INTLEVEL field: */
1106#define XCHAL_PS_INTLEVEL_BITS 4 /* number of bits in INTLEVEL field */
1107#define XCHAL_PS_INTLEVEL_NUM 16 /* max number of possible causes (2^bits) */
1108#define XCHAL_PS_INTLEVEL_SHIFT 0 /* position of INTLEVEL bits in PS, starting from lsbit */
1109#define XCHAL_PS_INTLEVEL_MASK 0x0000000F /* mask of bits in INTLEVEL field of PS */
1110/* EXCM field: */
1111#define XCHAL_PS_EXCM_BITS 1 /* number of bits in EXCM field */
1112#define XCHAL_PS_EXCM_NUM 2 /* max number of possible causes (2^bits) */
1113#define XCHAL_PS_EXCM_SHIFT 4 /* position of EXCM bits in PS, starting from lsbit */
1114#define XCHAL_PS_EXCM_MASK 0x00000010 /* mask of bits in EXCM field of PS */
1115/* PROGSTACK field: */
1116#define XCHAL_PS_PROGSTACK_BITS 1 /* number of bits in PROGSTACK field */
1117#define XCHAL_PS_PROGSTACK_NUM 2 /* max number of possible causes (2^bits) */
1118#define XCHAL_PS_PROGSTACK_SHIFT 5 /* position of PROGSTACK bits in PS, starting from lsbit */
1119#define XCHAL_PS_PROGSTACK_MASK 0x00000020 /* mask of bits in PROGSTACK field of PS */
1120/* RING field: */
1121#define XCHAL_PS_RING_BITS 2 /* number of bits in RING field */
1122#define XCHAL_PS_RING_NUM 4 /* max number of possible causes (2^bits) */
1123#define XCHAL_PS_RING_SHIFT 6 /* position of RING bits in PS, starting from lsbit */
1124#define XCHAL_PS_RING_MASK 0x000000C0 /* mask of bits in RING field of PS */
1125/* OWB field: */
1126#define XCHAL_PS_OWB_BITS 4 /* number of bits in OWB field */
1127#define XCHAL_PS_OWB_NUM 16 /* max number of possible causes (2^bits) */
1128#define XCHAL_PS_OWB_SHIFT 8 /* position of OWB bits in PS, starting from lsbit */
1129#define XCHAL_PS_OWB_MASK 0x00000F00 /* mask of bits in OWB field of PS */
1130/* CALLINC field: */
1131#define XCHAL_PS_CALLINC_BITS 2 /* number of bits in CALLINC field */
1132#define XCHAL_PS_CALLINC_NUM 4 /* max number of possible causes (2^bits) */
1133#define XCHAL_PS_CALLINC_SHIFT 16 /* position of CALLINC bits in PS, starting from lsbit */
1134#define XCHAL_PS_CALLINC_MASK 0x00030000 /* mask of bits in CALLINC field of PS */
1135/* WOE field: */
1136#define XCHAL_PS_WOE_BITS 1 /* number of bits in WOE field */
1137#define XCHAL_PS_WOE_NUM 2 /* max number of possible causes (2^bits) */
1138#define XCHAL_PS_WOE_SHIFT 18 /* position of WOE bits in PS, starting from lsbit */
1139#define XCHAL_PS_WOE_MASK 0x00040000 /* mask of bits in WOE field of PS */
1140
1141/* EXCCAUSE (special register number 232): */
1142#define XCHAL_EXCCAUSE_VALIDMASK 0x0000003F /* bits of EXCCAUSE that are defined */
1143/* EXCCAUSE field: */
1144#define XCHAL_EXCCAUSE_BITS 6 /* number of bits in EXCCAUSE register */
1145#define XCHAL_EXCCAUSE_NUM 64 /* max number of possible causes (2^bits) */
1146#define XCHAL_EXCCAUSE_SHIFT 0 /* position of EXCCAUSE bits in register, starting from lsbit */
1147#define XCHAL_EXCCAUSE_MASK 0x0000003F /* mask of bits in EXCCAUSE register */
1148
1149/* DEBUGCAUSE (special register number 233): */
1150#define XCHAL_DEBUGCAUSE_VALIDMASK 0x0000003F /* bits of DEBUGCAUSE that are defined */
1151/* ICOUNT field: */
1152#define XCHAL_DEBUGCAUSE_ICOUNT_BITS 1 /* number of bits in ICOUNT field */
1153#define XCHAL_DEBUGCAUSE_ICOUNT_NUM 2 /* max number of possible causes (2^bits) */
1154#define XCHAL_DEBUGCAUSE_ICOUNT_SHIFT 0 /* position of ICOUNT bits in DEBUGCAUSE, starting from lsbit */
1155#define XCHAL_DEBUGCAUSE_ICOUNT_MASK 0x00000001 /* mask of bits in ICOUNT field of DEBUGCAUSE */
1156/* IBREAK field: */
1157#define XCHAL_DEBUGCAUSE_IBREAK_BITS 1 /* number of bits in IBREAK field */
1158#define XCHAL_DEBUGCAUSE_IBREAK_NUM 2 /* max number of possible causes (2^bits) */
1159#define XCHAL_DEBUGCAUSE_IBREAK_SHIFT 1 /* position of IBREAK bits in DEBUGCAUSE, starting from lsbit */
1160#define XCHAL_DEBUGCAUSE_IBREAK_MASK 0x00000002 /* mask of bits in IBREAK field of DEBUGCAUSE */
1161/* DBREAK field: */
1162#define XCHAL_DEBUGCAUSE_DBREAK_BITS 1 /* number of bits in DBREAK field */
1163#define XCHAL_DEBUGCAUSE_DBREAK_NUM 2 /* max number of possible causes (2^bits) */
1164#define XCHAL_DEBUGCAUSE_DBREAK_SHIFT 2 /* position of DBREAK bits in DEBUGCAUSE, starting from lsbit */
1165#define XCHAL_DEBUGCAUSE_DBREAK_MASK 0x00000004 /* mask of bits in DBREAK field of DEBUGCAUSE */
1166/* BREAK field: */
1167#define XCHAL_DEBUGCAUSE_BREAK_BITS 1 /* number of bits in BREAK field */
1168#define XCHAL_DEBUGCAUSE_BREAK_NUM 2 /* max number of possible causes (2^bits) */
1169#define XCHAL_DEBUGCAUSE_BREAK_SHIFT 3 /* position of BREAK bits in DEBUGCAUSE, starting from lsbit */
1170#define XCHAL_DEBUGCAUSE_BREAK_MASK 0x00000008 /* mask of bits in BREAK field of DEBUGCAUSE */
1171/* BREAKN field: */
1172#define XCHAL_DEBUGCAUSE_BREAKN_BITS 1 /* number of bits in BREAKN field */
1173#define XCHAL_DEBUGCAUSE_BREAKN_NUM 2 /* max number of possible causes (2^bits) */
1174#define XCHAL_DEBUGCAUSE_BREAKN_SHIFT 4 /* position of BREAKN bits in DEBUGCAUSE, starting from lsbit */
1175#define XCHAL_DEBUGCAUSE_BREAKN_MASK 0x00000010 /* mask of bits in BREAKN field of DEBUGCAUSE */
1176/* DEBUGINT field: */
1177#define XCHAL_DEBUGCAUSE_DEBUGINT_BITS 1 /* number of bits in DEBUGINT field */
1178#define XCHAL_DEBUGCAUSE_DEBUGINT_NUM 2 /* max number of possible causes (2^bits) */
1179#define XCHAL_DEBUGCAUSE_DEBUGINT_SHIFT 5 /* position of DEBUGINT bits in DEBUGCAUSE, starting from lsbit */
1180#define XCHAL_DEBUGCAUSE_DEBUGINT_MASK 0x00000020 /* mask of bits in DEBUGINT field of DEBUGCAUSE */
1181
1182
1183
1184/*----------------------------------------------------------------------
1185 ISA
1186 ----------------------------------------------------------------------*/
1187
1188#define XCHAL_HAVE_DENSITY 1 /* 1 if density option configured, 0 otherwise */
1189#define XCHAL_HAVE_LOOPS 1 /* 1 if zero-overhead loops option configured, 0 otherwise */
1190/* Misc instructions: */
1191#define XCHAL_HAVE_NSA 0 /* 1 if NSA/NSAU instructions option configured, 0 otherwise */
1192#define XCHAL_HAVE_MINMAX 0 /* 1 if MIN/MAX instructions option configured, 0 otherwise */
1193#define XCHAL_HAVE_SEXT 0 /* 1 if sign-extend instruction option configured, 0 otherwise */
1194#define XCHAL_HAVE_CLAMPS 0 /* 1 if CLAMPS instruction option configured, 0 otherwise */
1195#define XCHAL_HAVE_MAC16 0 /* 1 if MAC16 option configured, 0 otherwise */
1196#define XCHAL_HAVE_MUL16 0 /* 1 if 16-bit integer multiply option configured, 0 otherwise */
1197/*#define XCHAL_HAVE_POPC 0*/ /* 1 if CRC instruction option configured, 0 otherwise */
1198/*#define XCHAL_HAVE_CRC 0*/ /* 1 if POPC instruction option configured, 0 otherwise */
1199
1200#define XCHAL_HAVE_SPECULATION 0 /* 1 if speculation option configured, 0 otherwise */
1201/*#define XCHAL_HAVE_MP_SYNC 0*/ /* 1 if multiprocessor sync. option configured, 0 otherwise */
1202#define XCHAL_HAVE_PRID 0 /* 1 if processor ID register configured, 0 otherwise */
1203
1204#define XCHAL_NUM_MISC_REGS 2 /* number of miscellaneous registers (0..4) */
1205
1206/* These relate a bit more to TIE: */
1207#define XCHAL_HAVE_BOOLEANS 0 /* 1 if booleans option configured, 0 otherwise */
1208#define XCHAL_HAVE_MUL32 0 /* 1 if 32-bit integer multiply option configured, 0 otherwise */
1209#define XCHAL_HAVE_MUL32_HIGH 0 /* 1 if MUL32 option includes MULUH and MULSH, 0 otherwise */
1210#define XCHAL_HAVE_FP 0 /* 1 if floating point option configured, 0 otherwise */
1211
1212
1213/*----------------------------------------------------------------------
1214 DERIVED
1215 ----------------------------------------------------------------------*/
1216
1217#if XCHAL_HAVE_BE
1218#define XCHAL_INST_ILLN 0xD60F /* 2-byte illegal instruction, msb-first */
1219#define XCHAL_INST_ILLN_BYTE0 0xD6 /* 2-byte illegal instruction, 1st byte */
1220#define XCHAL_INST_ILLN_BYTE1 0x0F /* 2-byte illegal instruction, 2nd byte */
1221#else
1222#define XCHAL_INST_ILLN 0xF06D /* 2-byte illegal instruction, lsb-first */
1223#define XCHAL_INST_ILLN_BYTE0 0x6D /* 2-byte illegal instruction, 1st byte */
1224#define XCHAL_INST_ILLN_BYTE1 0xF0 /* 2-byte illegal instruction, 2nd byte */
1225#endif
1226/* Belongs in xtensa/hal.h: */
1227#define XTHAL_INST_ILL 0x000000 /* 3-byte illegal instruction */
1228
1229
1230/*
1231 * Because information as to exactly which hardware release is targeted
1232 * by a given software build is not always available, compile-time HAL
1233 * Hardware-Release "_AT" macros are fuzzy (return 0, 1, or XCHAL_MAYBE):
1234 */
1235#ifndef XCHAL_HW_RELEASE_MAJOR
1236# define XCHAL_HW_CONFIGID_RELIABLE 0
1237#endif
1238#if XCHAL_HW_CONFIGID_RELIABLE
1239# define XCHAL_HW_RELEASE_AT_OR_BELOW(major,minor) (XTHAL_REL_LE( XCHAL_HW_RELEASE_MAJOR,XCHAL_HW_RELEASE_MINOR, major,minor ) ? 1 : 0)
1240# define XCHAL_HW_RELEASE_AT_OR_ABOVE(major,minor) (XTHAL_REL_GE( XCHAL_HW_RELEASE_MAJOR,XCHAL_HW_RELEASE_MINOR, major,minor ) ? 1 : 0)
1241# define XCHAL_HW_RELEASE_AT(major,minor) (XTHAL_REL_EQ( XCHAL_HW_RELEASE_MAJOR,XCHAL_HW_RELEASE_MINOR, major,minor ) ? 1 : 0)
1242# define XCHAL_HW_RELEASE_MAJOR_AT(major) ((XCHAL_HW_RELEASE_MAJOR == (major)) ? 1 : 0)
1243#else
1244# define XCHAL_HW_RELEASE_AT_OR_BELOW(major,minor) ( ((major) < 1040 && XCHAL_HAVE_XEA2) ? 0 \
1245 : ((major) > 1050 && XCHAL_HAVE_XEA1) ? 1 \
1246 : XTHAL_MAYBE )
1247# define XCHAL_HW_RELEASE_AT_OR_ABOVE(major,minor) ( ((major) >= 2000 && XCHAL_HAVE_XEA1) ? 0 \
1248 : (XTHAL_REL_LE(major,minor, 1040,0) && XCHAL_HAVE_XEA2) ? 1 \
1249 : XTHAL_MAYBE )
1250# define XCHAL_HW_RELEASE_AT(major,minor) ( (((major) < 1040 && XCHAL_HAVE_XEA2) || \
1251 ((major) >= 2000 && XCHAL_HAVE_XEA1)) ? 0 : XTHAL_MAYBE)
1252# define XCHAL_HW_RELEASE_MAJOR_AT(major) XCHAL_HW_RELEASE_AT(major,0)
1253#endif
1254
1255/*
1256 * Specific errata:
1257 */
1258
1259/*
1260 * Erratum T1020.H13, T1030.H7, T1040.H10, T1050.H4 (fixed in T1040.3 and T1050.1;
1261 * relevant only in XEA1, kernel-vector mode, level-one interrupts and overflows enabled):
1262 */
1263#define XCHAL_MAYHAVE_ERRATUM_XEA1KWIN (XCHAL_HAVE_XEA1 && \
1264 (XCHAL_HW_RELEASE_AT_OR_BELOW(1040,2) != 0 \
1265 || XCHAL_HW_RELEASE_AT(1050,0)))
1266
1267
1268
1269#endif /*XTENSA_CONFIG_CORE_H*/
1270
diff --git a/include/asm-xtensa/xtensa/config-linux_be/defs.h b/include/asm-xtensa/xtensa/config-linux_be/defs.h
deleted file mode 100644
index f7c58b273371..000000000000
--- a/include/asm-xtensa/xtensa/config-linux_be/defs.h
+++ /dev/null
@@ -1,270 +0,0 @@
1/* Definitions for Xtensa instructions, types, and protos. */
2
3/*
4 * Copyright (c) 2003 Tensilica, Inc. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2.1 of the GNU Lesser General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *
14 * Further, this software is distributed without any warranty that it is
15 * free of the rightful claim of any third person regarding infringement
16 * or the like. Any license provided herein, whether implied or
17 * otherwise, applies only to this software file. Patent licenses, if
18 * any, provided herein do not apply to combinations of this program with
19 * other software, or any other product whatsoever.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
24 * USA.
25 */
26
27/* Do not modify. This is automatically generated.*/
28
29#ifndef _XTENSA_BASE_HEADER
30#define _XTENSA_BASE_HEADER
31
32#ifdef __XTENSA__
33#if defined(__GNUC__) && !defined(__XCC__)
34
35#define L8UI_ASM(arr, ars, imm) { \
36 __asm__ volatile("l8ui %0, %1, %2" : "=a" (arr) : "a" (ars) , "i" (imm)); \
37}
38
39#define XT_L8UI(ars, imm) \
40({ \
41 unsigned char _arr; \
42 const unsigned char *_ars = ars; \
43 L8UI_ASM(_arr, _ars, imm); \
44 _arr; \
45})
46
47#define L16UI_ASM(arr, ars, imm) { \
48 __asm__ volatile("l16ui %0, %1, %2" : "=a" (arr) : "a" (ars) , "i" (imm)); \
49}
50
51#define XT_L16UI(ars, imm) \
52({ \
53 unsigned short _arr; \
54 const unsigned short *_ars = ars; \
55 L16UI_ASM(_arr, _ars, imm); \
56 _arr; \
57})
58
59#define L16SI_ASM(arr, ars, imm) {\
60 __asm__ volatile("l16si %0, %1, %2" : "=a" (arr) : "a" (ars) , "i" (imm)); \
61}
62
63#define XT_L16SI(ars, imm) \
64({ \
65 signed short _arr; \
66 const signed short *_ars = ars; \
67 L16SI_ASM(_arr, _ars, imm); \
68 _arr; \
69})
70
71#define L32I_ASM(arr, ars, imm) { \
72 __asm__ volatile("l32i %0, %1, %2" : "=a" (arr) : "a" (ars) , "i" (imm)); \
73}
74
75#define XT_L32I(ars, imm) \
76({ \
77 unsigned _arr; \
78 const unsigned *_ars = ars; \
79 L32I_ASM(_arr, _ars, imm); \
80 _arr; \
81})
82
83#define S8I_ASM(arr, ars, imm) {\
84 __asm__ volatile("s8i %0, %1, %2" : : "a" (arr), "a" (ars) , "i" (imm) : "memory" ); \
85}
86
87#define XT_S8I(arr, ars, imm) \
88({ \
89 signed char _arr = arr; \
90 const signed char *_ars = ars; \
91 S8I_ASM(_arr, _ars, imm); \
92})
93
94#define S16I_ASM(arr, ars, imm) {\
95 __asm__ volatile("s16i %0, %1, %2" : : "a" (arr), "a" (ars) , "i" (imm) : "memory" ); \
96}
97
98#define XT_S16I(arr, ars, imm) \
99({ \
100 signed short _arr = arr; \
101 const signed short *_ars = ars; \
102 S16I_ASM(_arr, _ars, imm); \
103})
104
105#define S32I_ASM(arr, ars, imm) { \
106 __asm__ volatile("s32i %0, %1, %2" : : "a" (arr), "a" (ars) , "i" (imm) : "memory" ); \
107}
108
109#define XT_S32I(arr, ars, imm) \
110({ \
111 signed int _arr = arr; \
112 const signed int *_ars = ars; \
113 S32I_ASM(_arr, _ars, imm); \
114})
115
116#define ADDI_ASM(art, ars, imm) {\
117 __asm__ ("addi %0, %1, %2" : "=a" (art) : "a" (ars), "i" (imm)); \
118}
119
120#define XT_ADDI(ars, imm) \
121({ \
122 unsigned _art; \
123 unsigned _ars = ars; \
124 ADDI_ASM(_art, _ars, imm); \
125 _art; \
126})
127
128#define ABS_ASM(arr, art) {\
129 __asm__ ("abs %0, %1" : "=a" (arr) : "a" (art)); \
130}
131
132#define XT_ABS(art) \
133({ \
134 unsigned _arr; \
135 signed _art = art; \
136 ABS_ASM(_arr, _art); \
137 _arr; \
138})
139
140/* Note: In the following macros that reference SAR, the magic "state"
141 register is used to capture the dependency on SAR. This is because
142 SAR is a 5-bit register and thus there are no C types that can be
143 used to represent it. It doesn't appear that the SAR register is
144 even relevant to GCC, but it is marked as "clobbered" just in
145 case. */
146
147#define SRC_ASM(arr, ars, art) {\
148 register int _xt_sar __asm__ ("state"); \
149 __asm__ ("src %0, %1, %2" \
150 : "=a" (arr) : "a" (ars), "a" (art), "t" (_xt_sar)); \
151}
152
153#define XT_SRC(ars, art) \
154({ \
155 unsigned _arr; \
156 unsigned _ars = ars; \
157 unsigned _art = art; \
158 SRC_ASM(_arr, _ars, _art); \
159 _arr; \
160})
161
162#define SSR_ASM(ars) {\
163 register int _xt_sar __asm__ ("state"); \
164 __asm__ ("ssr %1" : "=t" (_xt_sar) : "a" (ars) : "sar"); \
165}
166
167#define XT_SSR(ars) \
168({ \
169 unsigned _ars = ars; \
170 SSR_ASM(_ars); \
171})
172
173#define SSL_ASM(ars) {\
174 register int _xt_sar __asm__ ("state"); \
175 __asm__ ("ssl %1" : "=t" (_xt_sar) : "a" (ars) : "sar"); \
176}
177
178#define XT_SSL(ars) \
179({ \
180 unsigned _ars = ars; \
181 SSL_ASM(_ars); \
182})
183
184#define SSA8B_ASM(ars) {\
185 register int _xt_sar __asm__ ("state"); \
186 __asm__ ("ssa8b %1" : "=t" (_xt_sar) : "a" (ars) : "sar"); \
187}
188
189#define XT_SSA8B(ars) \
190({ \
191 unsigned _ars = ars; \
192 SSA8B_ASM(_ars); \
193})
194
195#define SSA8L_ASM(ars) {\
196 register int _xt_sar __asm__ ("state"); \
197 __asm__ ("ssa8l %1" : "=t" (_xt_sar) : "a" (ars) : "sar"); \
198}
199
200#define XT_SSA8L(ars) \
201({ \
202 unsigned _ars = ars; \
203 SSA8L_ASM(_ars); \
204})
205
206#define SSAI_ASM(imm) {\
207 register int _xt_sar __asm__ ("state"); \
208 __asm__ ("ssai %1" : "=t" (_xt_sar) : "i" (imm) : "sar"); \
209}
210
211#define XT_SSAI(imm) \
212({ \
213 SSAI_ASM(imm); \
214})
215
216
217
218
219
220
221
222
223#endif /* __GNUC__ && !__XCC__ */
224
225#ifdef __XCC__
226
227/* Core load/store instructions */
228extern unsigned char _TIE_L8UI(const unsigned char * ars, immediate imm);
229extern unsigned short _TIE_L16UI(const unsigned short * ars, immediate imm);
230extern signed short _TIE_L16SI(const signed short * ars, immediate imm);
231extern unsigned _TIE_L32I(const unsigned * ars, immediate imm);
232extern void _TIE_S8I(unsigned char arr, unsigned char * ars, immediate imm);
233extern void _TIE_S16I(unsigned short arr, unsigned short * ars, immediate imm);
234extern void _TIE_S32I(unsigned arr, unsigned * ars, immediate imm);
235
236#define XT_L8UI _TIE_L8UI
237#define XT_L16UI _TIE_L16UI
238#define XT_L16SI _TIE_L16SI
239#define XT_L32I _TIE_L32I
240#define XT_S8I _TIE_S8I
241#define XT_S16I _TIE_S16I
242#define XT_S32I _TIE_S32I
243
244/* Add-immediate instruction */
245extern unsigned _TIE_ADDI(unsigned ars, immediate imm);
246#define XT_ADDI _TIE_ADDI
247
248/* Absolute value instruction */
249extern unsigned _TIE_ABS(int art);
250#define XT_ABS _TIE_ABS
251
252/* funnel shift instructions */
253extern unsigned _TIE_SRC(unsigned ars, unsigned art);
254#define XT_SRC _TIE_SRC
255extern void _TIE_SSR(unsigned ars);
256#define XT_SSR _TIE_SSR
257extern void _TIE_SSL(unsigned ars);
258#define XT_SSL _TIE_SSL
259extern void _TIE_SSA8B(unsigned ars);
260#define XT_SSA8B _TIE_SSA8B
261extern void _TIE_SSA8L(unsigned ars);
262#define XT_SSA8L _TIE_SSA8L
263extern void _TIE_SSAI(immediate imm);
264#define XT_SSAI _TIE_SSAI
265
266
267#endif /* __XCC__ */
268
269#endif /* __XTENSA__ */
270#endif /* !_XTENSA_BASE_HEADER */
diff --git a/include/asm-xtensa/xtensa/config-linux_be/specreg.h b/include/asm-xtensa/xtensa/config-linux_be/specreg.h
deleted file mode 100644
index fa4106aa9a02..000000000000
--- a/include/asm-xtensa/xtensa/config-linux_be/specreg.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * Xtensa Special Register symbolic names
3 */
4
5/* $Id: specreg.h,v 1.2 2003/03/07 19:15:18 joetaylor Exp $ */
6
7/*
8 * Copyright (c) 2003 Tensilica, Inc. All Rights Reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2.1 of the GNU Lesser General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it would be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * Further, this software is distributed without any warranty that it is
19 * free of the rightful claim of any third person regarding infringement
20 * or the like. Any license provided herein, whether implied or
21 * otherwise, applies only to this software file. Patent licenses, if
22 * any, provided herein do not apply to combinations of this program with
23 * other software, or any other product whatsoever.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this program; if not, write the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
28 * USA.
29 */
30
31#ifndef XTENSA_SPECREG_H
32#define XTENSA_SPECREG_H
33
34/* Include these special register bitfield definitions, for historical reasons: */
35#include <xtensa/corebits.h>
36
37
38/* Special registers: */
39#define LBEG 0
40#define LEND 1
41#define LCOUNT 2
42#define SAR 3
43#define WINDOWBASE 72
44#define WINDOWSTART 73
45#define PTEVADDR 83
46#define RASID 90
47#define ITLBCFG 91
48#define DTLBCFG 92
49#define IBREAKENABLE 96
50#define DDR 104
51#define IBREAKA_0 128
52#define IBREAKA_1 129
53#define DBREAKA_0 144
54#define DBREAKA_1 145
55#define DBREAKC_0 160
56#define DBREAKC_1 161
57#define EPC_1 177
58#define EPC_2 178
59#define EPC_3 179
60#define EPC_4 180
61#define DEPC 192
62#define EPS_2 194
63#define EPS_3 195
64#define EPS_4 196
65#define EXCSAVE_1 209
66#define EXCSAVE_2 210
67#define EXCSAVE_3 211
68#define EXCSAVE_4 212
69#define INTERRUPT 226
70#define INTENABLE 228
71#define PS 230
72#define EXCCAUSE 232
73#define DEBUGCAUSE 233
74#define CCOUNT 234
75#define ICOUNT 236
76#define ICOUNTLEVEL 237
77#define EXCVADDR 238
78#define CCOMPARE_0 240
79#define CCOMPARE_1 241
80#define CCOMPARE_2 242
81#define MISC_REG_0 244
82#define MISC_REG_1 245
83
84/* Special cases (bases of special register series): */
85#define IBREAKA 128
86#define DBREAKA 144
87#define DBREAKC 160
88#define EPC 176
89#define EPS 192
90#define EXCSAVE 208
91#define CCOMPARE 240
92
93/* Special names for read-only and write-only interrupt registers: */
94#define INTREAD 226
95#define INTSET 226
96#define INTCLEAR 227
97
98#endif /* XTENSA_SPECREG_H */
99
diff --git a/include/asm-xtensa/xtensa/config-linux_be/system.h b/include/asm-xtensa/xtensa/config-linux_be/system.h
deleted file mode 100644
index cf9d4d308e3a..000000000000
--- a/include/asm-xtensa/xtensa/config-linux_be/system.h
+++ /dev/null
@@ -1,198 +0,0 @@
1/*
2 * xtensa/config/system.h -- HAL definitions that are dependent on SYSTEM configuration
3 *
4 * NOTE: The location and contents of this file are highly subject to change.
5 *
6 * Source for configuration-independent binaries (which link in a
7 * configuration-specific HAL library) must NEVER include this file.
8 * The HAL itself has historically included this file in some instances,
9 * but this is not appropriate either, because the HAL is meant to be
10 * core-specific but system independent.
11 */
12
13/*
14 * Copyright (c) 2003 Tensilica, Inc. All Rights Reserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of version 2.1 of the GNU Lesser General Public
18 * License as published by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it would be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 *
24 * Further, this software is distributed without any warranty that it is
25 * free of the rightful claim of any third person regarding infringement
26 * or the like. Any license provided herein, whether implied or
27 * otherwise, applies only to this software file. Patent licenses, if
28 * any, provided herein do not apply to combinations of this program with
29 * other software, or any other product whatsoever.
30 *
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this program; if not, write the Free Software
33 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
34 * USA.
35 */
36
37
38#ifndef XTENSA_CONFIG_SYSTEM_H
39#define XTENSA_CONFIG_SYSTEM_H
40
41/*#include <xtensa/hal.h>*/
42
43
44
45/*----------------------------------------------------------------------
46 DEVICE ADDRESSES
47 ----------------------------------------------------------------------*/
48
49/*
50 * Strange place to find these, but the configuration GUI
51 * allows moving these around to account for various core
52 * configurations. Specific boards (and their BSP software)
53 * will have specific meanings for these components.
54 */
55
56/* I/O Block areas: */
57#define XSHAL_IOBLOCK_CACHED_VADDR 0xE0000000
58#define XSHAL_IOBLOCK_CACHED_PADDR 0xF0000000
59#define XSHAL_IOBLOCK_CACHED_SIZE 0x0E000000
60
61#define XSHAL_IOBLOCK_BYPASS_VADDR 0xF0000000
62#define XSHAL_IOBLOCK_BYPASS_PADDR 0xF0000000
63#define XSHAL_IOBLOCK_BYPASS_SIZE 0x0E000000
64
65/* System ROM: */
66#define XSHAL_ROM_VADDR 0xEE000000
67#define XSHAL_ROM_PADDR 0xFE000000
68#define XSHAL_ROM_SIZE 0x00400000
69/* Largest available area (free of vectors): */
70#define XSHAL_ROM_AVAIL_VADDR 0xEE00052C
71#define XSHAL_ROM_AVAIL_VSIZE 0x003FFAD4
72
73/* System RAM: */
74#define XSHAL_RAM_VADDR 0xD0000000
75#define XSHAL_RAM_PADDR 0x00000000
76#define XSHAL_RAM_VSIZE 0x08000000
77#define XSHAL_RAM_PSIZE 0x10000000
78#define XSHAL_RAM_SIZE XSHAL_RAM_PSIZE
79/* Largest available area (free of vectors): */
80#define XSHAL_RAM_AVAIL_VADDR 0xD0000370
81#define XSHAL_RAM_AVAIL_VSIZE 0x07FFFC90
82
83/*
84 * Shadow system RAM (same device as system RAM, at different address).
85 * (Emulation boards need this for the SONIC Ethernet driver
86 * when data caches are configured for writeback mode.)
87 * NOTE: on full MMU configs, this points to the BYPASS virtual address
88 * of system RAM, ie. is the same as XSHAL_RAM_* except that virtual
89 * addresses are viewed through the BYPASS static map rather than
90 * the CACHED static map.
91 */
92#define XSHAL_RAM_BYPASS_VADDR 0xD8000000
93#define XSHAL_RAM_BYPASS_PADDR 0x00000000
94#define XSHAL_RAM_BYPASS_PSIZE 0x08000000
95
96/* Alternate system RAM (different device than system RAM): */
97#define XSHAL_ALTRAM_VADDR 0xCEE00000
98#define XSHAL_ALTRAM_PADDR 0xC0000000
99#define XSHAL_ALTRAM_SIZE 0x00200000
100
101
102/*----------------------------------------------------------------------
103 * DEVICE-ADDRESS DEPENDENT...
104 *
105 * Values written to CACHEATTR special register (or its equivalent)
106 * to enable and disable caches in various modes.
107 *----------------------------------------------------------------------*/
108
109/*----------------------------------------------------------------------
110 BACKWARD COMPATIBILITY ...
111 ----------------------------------------------------------------------*/
112
113/*
114 * NOTE: the following two macros are DEPRECATED. Use the latter
115 * board-specific macros instead, which are specially tuned for the
116 * particular target environments' memory maps.
117 */
118#define XSHAL_CACHEATTR_BYPASS XSHAL_XT2000_CACHEATTR_BYPASS /* disable caches in bypass mode */
119#define XSHAL_CACHEATTR_DEFAULT XSHAL_XT2000_CACHEATTR_DEFAULT /* default setting to enable caches (no writeback!) */
120
121/*----------------------------------------------------------------------
122 ISS (Instruction Set Simulator) SPECIFIC ...
123 ----------------------------------------------------------------------*/
124
125#define XSHAL_ISS_CACHEATTR_WRITEBACK 0x1122222F /* enable caches in write-back mode */
126#define XSHAL_ISS_CACHEATTR_WRITEALLOC 0x1122222F /* enable caches in write-allocate mode */
127#define XSHAL_ISS_CACHEATTR_WRITETHRU 0x1122222F /* enable caches in write-through mode */
128#define XSHAL_ISS_CACHEATTR_BYPASS 0x2222222F /* disable caches in bypass mode */
129#define XSHAL_ISS_CACHEATTR_DEFAULT XSHAL_ISS_CACHEATTR_WRITEBACK /* default setting to enable caches */
130
131/* For Coware only: */
132#define XSHAL_COWARE_CACHEATTR_WRITEBACK 0x11222222 /* enable caches in write-back mode */
133#define XSHAL_COWARE_CACHEATTR_WRITEALLOC 0x11222222 /* enable caches in write-allocate mode */
134#define XSHAL_COWARE_CACHEATTR_WRITETHRU 0x11222222 /* enable caches in write-through mode */
135#define XSHAL_COWARE_CACHEATTR_BYPASS 0x22222222 /* disable caches in bypass mode */
136#define XSHAL_COWARE_CACHEATTR_DEFAULT XSHAL_COWARE_CACHEATTR_WRITEBACK /* default setting to enable caches */
137
138/* For BFM and other purposes: */
139#define XSHAL_ALLVALID_CACHEATTR_WRITEBACK 0x11222222 /* enable caches without any invalid regions */
140#define XSHAL_ALLVALID_CACHEATTR_DEFAULT XSHAL_ALLVALID_CACHEATTR_WRITEBACK /* default setting for caches without any invalid regions */
141
142#define XSHAL_ISS_PIPE_REGIONS 0
143#define XSHAL_ISS_SDRAM_REGIONS 0
144
145
146/*----------------------------------------------------------------------
147 XT2000 BOARD SPECIFIC ...
148 ----------------------------------------------------------------------*/
149
150#define XSHAL_XT2000_CACHEATTR_WRITEBACK 0x22FFFFFF /* enable caches in write-back mode */
151#define XSHAL_XT2000_CACHEATTR_WRITEALLOC 0x22FFFFFF /* enable caches in write-allocate mode */
152#define XSHAL_XT2000_CACHEATTR_WRITETHRU 0x22FFFFFF /* enable caches in write-through mode */
153#define XSHAL_XT2000_CACHEATTR_BYPASS 0x22FFFFFF /* disable caches in bypass mode */
154#define XSHAL_XT2000_CACHEATTR_DEFAULT XSHAL_XT2000_CACHEATTR_WRITEBACK /* default setting to enable caches */
155
156#define XSHAL_XT2000_PIPE_REGIONS 0x00001000 /* BusInt pipeline regions */
157#define XSHAL_XT2000_SDRAM_REGIONS 0x00000005 /* BusInt SDRAM regions */
158
159
160/*----------------------------------------------------------------------
161 VECTOR SIZES
162 ----------------------------------------------------------------------*/
163
164/*
165 * Sizes allocated to vectors by the system (memory map) configuration.
166 * These sizes are constrained by core configuration (eg. one vector's
167 * code cannot overflow into another vector) but are dependent on the
168 * system or board (or LSP) memory map configuration.
169 *
170 * Whether or not each vector happens to be in a system ROM is also
171 * a system configuration matter, sometimes useful, included here also:
172 */
173#define XSHAL_RESET_VECTOR_SIZE 0x000004E0
174#define XSHAL_RESET_VECTOR_ISROM 1
175#define XSHAL_USER_VECTOR_SIZE 0x0000001C
176#define XSHAL_USER_VECTOR_ISROM 0
177#define XSHAL_PROGRAMEXC_VECTOR_SIZE XSHAL_USER_VECTOR_SIZE /* for backward compatibility */
178#define XSHAL_USEREXC_VECTOR_SIZE XSHAL_USER_VECTOR_SIZE /* for backward compatibility */
179#define XSHAL_KERNEL_VECTOR_SIZE 0x0000001C
180#define XSHAL_KERNEL_VECTOR_ISROM 0
181#define XSHAL_STACKEDEXC_VECTOR_SIZE XSHAL_KERNEL_VECTOR_SIZE /* for backward compatibility */
182#define XSHAL_KERNELEXC_VECTOR_SIZE XSHAL_KERNEL_VECTOR_SIZE /* for backward compatibility */
183#define XSHAL_DOUBLEEXC_VECTOR_SIZE 0x000000E0
184#define XSHAL_DOUBLEEXC_VECTOR_ISROM 0
185#define XSHAL_WINDOW_VECTORS_SIZE 0x00000180
186#define XSHAL_WINDOW_VECTORS_ISROM 0
187#define XSHAL_INTLEVEL2_VECTOR_SIZE 0x0000000C
188#define XSHAL_INTLEVEL2_VECTOR_ISROM 0
189#define XSHAL_INTLEVEL3_VECTOR_SIZE 0x0000000C
190#define XSHAL_INTLEVEL3_VECTOR_ISROM 0
191#define XSHAL_INTLEVEL4_VECTOR_SIZE 0x0000000C
192#define XSHAL_INTLEVEL4_VECTOR_ISROM 1
193#define XSHAL_DEBUG_VECTOR_SIZE XSHAL_INTLEVEL4_VECTOR_SIZE
194#define XSHAL_DEBUG_VECTOR_ISROM XSHAL_INTLEVEL4_VECTOR_ISROM
195
196
197#endif /*XTENSA_CONFIG_SYSTEM_H*/
198
diff --git a/include/asm-xtensa/xtensa/config-linux_be/tie.h b/include/asm-xtensa/xtensa/config-linux_be/tie.h
deleted file mode 100644
index 3c2e514602f4..000000000000
--- a/include/asm-xtensa/xtensa/config-linux_be/tie.h
+++ /dev/null
@@ -1,275 +0,0 @@
1/*
2 * xtensa/config/tie.h -- HAL definitions that are dependent on CORE and TIE configuration
3 *
4 * This header file is sometimes referred to as the "compile-time HAL" or CHAL.
5 * It was generated for a specific Xtensa processor configuration,
6 * and furthermore for a specific set of TIE source files that extend
7 * basic core functionality.
8 *
9 * Source for configuration-independent binaries (which link in a
10 * configuration-specific HAL library) must NEVER include this file.
11 * It is perfectly normal, however, for the HAL source itself to include this file.
12 */
13
14/*
15 * Copyright (c) 2003 Tensilica, Inc. All Rights Reserved.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of version 2.1 of the GNU Lesser General Public
19 * License as published by the Free Software Foundation.
20 *
21 * This program is distributed in the hope that it would be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 *
25 * Further, this software is distributed without any warranty that it is
26 * free of the rightful claim of any third person regarding infringement
27 * or the like. Any license provided herein, whether implied or
28 * otherwise, applies only to this software file. Patent licenses, if
29 * any, provided herein do not apply to combinations of this program with
30 * other software, or any other product whatsoever.
31 *
32 * You should have received a copy of the GNU Lesser General Public
33 * License along with this program; if not, write the Free Software
34 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
35 * USA.
36 */
37
38
39#ifndef XTENSA_CONFIG_TIE_H
40#define XTENSA_CONFIG_TIE_H
41
42#include <xtensa/hal.h>
43
44
45/*----------------------------------------------------------------------
46 GENERAL
47 ----------------------------------------------------------------------*/
48
49/*
50 * Separators for macros that expand into arrays.
51 * These can be predefined by files that #include this one,
52 * when different separators are required.
53 */
54/* Element separator for macros that expand into 1-dimensional arrays: */
55#ifndef XCHAL_SEP
56#define XCHAL_SEP ,
57#endif
58/* Array separator for macros that expand into 2-dimensional arrays: */
59#ifndef XCHAL_SEP2
60#define XCHAL_SEP2 },{
61#endif
62
63
64
65
66
67
68/*----------------------------------------------------------------------
69 COPROCESSORS and EXTRA STATE
70 ----------------------------------------------------------------------*/
71
72#define XCHAL_CP_NUM 0 /* number of coprocessors */
73#define XCHAL_CP_MAX 0 /* max coprocessor id plus one (0 if none) */
74#define XCHAL_CP_MASK 0x00 /* bitmask of coprocessors by id */
75
76/* Space for coprocessors' state save areas: */
77#define XCHAL_CP0_SA_SIZE 0
78#define XCHAL_CP1_SA_SIZE 0
79#define XCHAL_CP2_SA_SIZE 0
80#define XCHAL_CP3_SA_SIZE 0
81#define XCHAL_CP4_SA_SIZE 0
82#define XCHAL_CP5_SA_SIZE 0
83#define XCHAL_CP6_SA_SIZE 0
84#define XCHAL_CP7_SA_SIZE 0
85/* Minimum required alignments of CP state save areas: */
86#define XCHAL_CP0_SA_ALIGN 1
87#define XCHAL_CP1_SA_ALIGN 1
88#define XCHAL_CP2_SA_ALIGN 1
89#define XCHAL_CP3_SA_ALIGN 1
90#define XCHAL_CP4_SA_ALIGN 1
91#define XCHAL_CP5_SA_ALIGN 1
92#define XCHAL_CP6_SA_ALIGN 1
93#define XCHAL_CP7_SA_ALIGN 1
94
95/* Indexing macros: */
96#define _XCHAL_CP_SA_SIZE(n) XCHAL_CP ## n ## _SA_SIZE
97#define XCHAL_CP_SA_SIZE(n) _XCHAL_CP_SA_SIZE(n) /* n = 0 .. 7 */
98#define _XCHAL_CP_SA_ALIGN(n) XCHAL_CP ## n ## _SA_ALIGN
99#define XCHAL_CP_SA_ALIGN(n) _XCHAL_CP_SA_ALIGN(n) /* n = 0 .. 7 */
100
101
102/* Space for "extra" state (user special registers and non-cp TIE) save area: */
103#define XCHAL_EXTRA_SA_SIZE 0
104#define XCHAL_EXTRA_SA_ALIGN 1
105
106/* Total save area size (extra + all coprocessors) */
107/* (not useful until xthal_{save,restore}_all_extra() is implemented, */
108/* but included for Tor2 beta; doesn't account for alignment!): */
109#define XCHAL_CPEXTRA_SA_SIZE_TOR2 0 /* Tor2Beta temporary definition -- do not use */
110
111/* Combined required alignment for all CP and EXTRA state save areas */
112/* (does not include required alignment for any base config registers): */
113#define XCHAL_CPEXTRA_SA_ALIGN 1
114
115/* ... */
116
117
118#ifdef _ASMLANGUAGE
119/*
120 * Assembly-language specific definitions (assembly macros, etc.).
121 */
122#include <xtensa/config/specreg.h>
123
124/********************
125 * Macros to save and restore the non-coprocessor TIE portion of EXTRA state.
126 */
127
128/* (none) */
129
130
131/********************
132 * Macros to create functions that save and restore all EXTRA (non-coprocessor) state
133 * (does not include zero-overhead loop registers and non-optional registers).
134 */
135
136 /*
137 * Macro that expands to the body of a function that
138 * stores the extra (non-coprocessor) optional/custom state.
139 * Entry: a2 = ptr to save area in which to save extra state
140 * Exit: any register a2-a15 (?) may have been clobbered.
141 */
142 .macro xchal_extra_store_funcbody
143 .endm
144
145
146 /*
147 * Macro that expands to the body of a function that
148 * loads the extra (non-coprocessor) optional/custom state.
149 * Entry: a2 = ptr to save area from which to restore extra state
150 * Exit: any register a2-a15 (?) may have been clobbered.
151 */
152 .macro xchal_extra_load_funcbody
153 .endm
154
155
156/********************
157 * Macros to save and restore the state of each TIE coprocessor.
158 */
159
160
161
162/********************
163 * Macros to create functions that save and restore the state of *any* TIE coprocessor.
164 */
165
166 /*
167 * Macro that expands to the body of a function
168 * that stores the selected coprocessor's state (registers etc).
169 * Entry: a2 = ptr to save area in which to save cp state
170 * a3 = coprocessor number
171 * Exit: any register a2-a15 (?) may have been clobbered.
172 */
173 .macro xchal_cpi_store_funcbody
174 .endm
175
176
177 /*
178 * Macro that expands to the body of a function
179 * that loads the selected coprocessor's state (registers etc).
180 * Entry: a2 = ptr to save area from which to restore cp state
181 * a3 = coprocessor number
182 * Exit: any register a2-a15 (?) may have been clobbered.
183 */
184 .macro xchal_cpi_load_funcbody
185 .endm
186
187#endif /*_ASMLANGUAGE*/
188
189
190/*
191 * Contents of save areas in terms of libdb register numbers.
192 * NOTE: CONTENTS_LIBDB_{UREG,REGF} macros are not defined in this file;
193 * it is up to the user of this header file to define these macros
194 * usefully before each expansion of the CONTENTS_LIBDB macros.
195 * (Fields rsv[123] are reserved for future additions; they are currently
196 * set to zero but may be set to some useful values in the future.)
197 *
198 * CONTENTS_LIBDB_SREG(libdbnum, offset, size, align, rsv1, name, sregnum, bitmask, rsv2, rsv3)
199 * CONTENTS_LIBDB_UREG(libdbnum, offset, size, align, rsv1, name, uregnum, bitmask, rsv2, rsv3)
200 * CONTENTS_LIBDB_REGF(libdbnum, offset, size, align, rsv1, name, index, numentries, contentsize, regname_base, regfile_name, rsv2, rsv3)
201 */
202
203#define XCHAL_EXTRA_SA_CONTENTS_LIBDB_NUM 0
204#define XCHAL_EXTRA_SA_CONTENTS_LIBDB /* empty */
205
206#define XCHAL_CP0_SA_CONTENTS_LIBDB_NUM 0
207#define XCHAL_CP0_SA_CONTENTS_LIBDB /* empty */
208
209#define XCHAL_CP1_SA_CONTENTS_LIBDB_NUM 0
210#define XCHAL_CP1_SA_CONTENTS_LIBDB /* empty */
211
212#define XCHAL_CP2_SA_CONTENTS_LIBDB_NUM 0
213#define XCHAL_CP2_SA_CONTENTS_LIBDB /* empty */
214
215#define XCHAL_CP3_SA_CONTENTS_LIBDB_NUM 0
216#define XCHAL_CP3_SA_CONTENTS_LIBDB /* empty */
217
218#define XCHAL_CP4_SA_CONTENTS_LIBDB_NUM 0
219#define XCHAL_CP4_SA_CONTENTS_LIBDB /* empty */
220
221#define XCHAL_CP5_SA_CONTENTS_LIBDB_NUM 0
222#define XCHAL_CP5_SA_CONTENTS_LIBDB /* empty */
223
224#define XCHAL_CP6_SA_CONTENTS_LIBDB_NUM 0
225#define XCHAL_CP6_SA_CONTENTS_LIBDB /* empty */
226
227#define XCHAL_CP7_SA_CONTENTS_LIBDB_NUM 0
228#define XCHAL_CP7_SA_CONTENTS_LIBDB /* empty */
229
230
231
232
233
234
235/*----------------------------------------------------------------------
236 MISC
237 ----------------------------------------------------------------------*/
238
239#if 0 /* is there something equivalent for user TIE? */
240#define XCHAL_CORE_ID "linux_be" /* configuration's alphanumeric core identifier
241 (CoreID) set in the Xtensa Processor Generator */
242
243#define XCHAL_BUILD_UNIQUE_ID 0x00003256 /* software build-unique ID (22-bit) */
244
245/* These definitions describe the hardware targeted by this software: */
246#define XCHAL_HW_CONFIGID0 0xC103D1FF /* config ID reg 0 value (upper 32 of 64 bits) */
247#define XCHAL_HW_CONFIGID1 0x00803256 /* config ID reg 1 value (lower 32 of 64 bits) */
248#define XCHAL_CONFIGID0 XCHAL_HW_CONFIGID0 /* for backward compatibility only -- don't use! */
249#define XCHAL_CONFIGID1 XCHAL_HW_CONFIGID1 /* for backward compatibility only -- don't use! */
250#define XCHAL_HW_RELEASE_MAJOR 1050 /* major release of targeted hardware */
251#define XCHAL_HW_RELEASE_MINOR 1 /* minor release of targeted hardware */
252#define XCHAL_HW_RELEASE_NAME "T1050.1" /* full release name of targeted hardware */
253#define XTHAL_HW_REL_T1050 1
254#define XTHAL_HW_REL_T1050_1 1
255#define XCHAL_HW_CONFIGID_RELIABLE 1
256#endif /*0*/
257
258
259
260/*----------------------------------------------------------------------
261 ISA
262 ----------------------------------------------------------------------*/
263
264#if 0 /* these probably don't belong here, but are related to or implemented using TIE */
265#define XCHAL_HAVE_BOOLEANS 0 /* 1 if booleans option configured, 0 otherwise */
266/* Misc instructions: */
267#define XCHAL_HAVE_MUL32 0 /* 1 if 32-bit integer multiply option configured, 0 otherwise */
268#define XCHAL_HAVE_MUL32_HIGH 0 /* 1 if MUL32 option includes MULUH and MULSH, 0 otherwise */
269
270#define XCHAL_HAVE_FP 0 /* 1 if floating point option configured, 0 otherwise */
271#endif /*0*/
272
273
274#endif /*XTENSA_CONFIG_TIE_H*/
275
diff --git a/include/asm-xtensa/xtensa/coreasm.h b/include/asm-xtensa/xtensa/coreasm.h
deleted file mode 100644
index a8cfb54c20a1..000000000000
--- a/include/asm-xtensa/xtensa/coreasm.h
+++ /dev/null
@@ -1,526 +0,0 @@
1#ifndef XTENSA_COREASM_H
2#define XTENSA_COREASM_H
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/coreasm.h -- assembler-specific
8 * definitions that depend on CORE configuration.
9 *
10 * Source for configuration-independent binaries (which link in a
11 * configuration-specific HAL library) must NEVER include this file.
12 * It is perfectly normal, however, for the HAL itself to include this
13 * file.
14 *
15 * This file must NOT include xtensa/config/system.h. Any assembler
16 * header file that depends on system information should likely go in
17 * a new systemasm.h (or sysasm.h) header file.
18 *
19 * NOTE: macro beqi32 is NOT configuration-dependent, and is placed
20 * here til we will have configuration-independent header file.
21 *
22 * This file is subject to the terms and conditions of the GNU General
23 * Public License. See the file "COPYING" in the main directory of
24 * this archive for more details.
25 *
26 * Copyright (C) 2002 Tensilica Inc.
27 */
28
29
30#include <xtensa/config/core.h>
31#include <xtensa/config/specreg.h>
32
33/*
34 * Assembly-language specific definitions (assembly macros, etc.).
35 */
36
37/*----------------------------------------------------------------------
38 * find_ms_setbit
39 *
40 * This macro finds the most significant bit that is set in <as>
41 * and return its index + <base> in <ad>, or <base> - 1 if <as> is zero.
42 * The index counts starting at zero for the lsbit, so the return
43 * value ranges from <base>-1 (no bit set) to <base>+31 (msbit set).
44 *
45 * Parameters:
46 * <ad> destination address register (any register)
47 * <as> source address register
48 * <at> temporary address register (must be different than <as>)
49 * <base> constant value added to result (usually 0 or 1)
50 * On entry:
51 * <ad> = undefined if different than <as>
52 * <as> = value whose most significant set bit is to be found
53 * <at> = undefined
54 * no other registers are used by this macro.
55 * On exit:
56 * <ad> = <base> + index of msbit set in original <as>,
57 * = <base> - 1 if original <as> was zero.
58 * <as> clobbered (if not <ad>)
59 * <at> clobbered (if not <ad>)
60 * Example:
61 * find_ms_setbit a0, a4, a0, 0 -- return in a0 index of msbit set in a4
62 */
63
64 .macro find_ms_setbit ad, as, at, base
65#if XCHAL_HAVE_NSA
66 movi \at, 31+\base
67 nsau \as, \as // get index of \as, numbered from msbit (32 if absent)
68 sub \ad, \at, \as // get numbering from lsbit (0..31, -1 if absent)
69#else /* XCHAL_HAVE_NSA */
70 movi \at, \base // start with result of 0 (point to lsbit of 32)
71
72 beqz \as, 2f // special case for zero argument: return -1
73 bltui \as, 0x10000, 1f // is it one of the 16 lsbits? (if so, check lower 16 bits)
74 addi \at, \at, 16 // no, increment result to upper 16 bits (of 32)
75 //srli \as, \as, 16 // check upper half (shift right 16 bits)
76 extui \as, \as, 16, 16 // check upper half (shift right 16 bits)
771: bltui \as, 0x100, 1f // is it one of the 8 lsbits? (if so, check lower 8 bits)
78 addi \at, \at, 8 // no, increment result to upper 8 bits (of 16)
79 srli \as, \as, 8 // shift right to check upper 8 bits
801: bltui \as, 0x10, 1f // is it one of the 4 lsbits? (if so, check lower 4 bits)
81 addi \at, \at, 4 // no, increment result to upper 4 bits (of 8)
82 srli \as, \as, 4 // shift right 4 bits to check upper half
831: bltui \as, 0x4, 1f // is it one of the 2 lsbits? (if so, check lower 2 bits)
84 addi \at, \at, 2 // no, increment result to upper 2 bits (of 4)
85 srli \as, \as, 2 // shift right 2 bits to check upper half
861: bltui \as, 0x2, 1f // is it the lsbit?
87 addi \at, \at, 2 // no, increment result to upper bit (of 2)
882: addi \at, \at, -1 // (from just above: add 1; from beqz: return -1)
89 //srli \as, \as, 1
901: // done! \at contains index of msbit set (or -1 if none set)
91 .if 0x\ad - 0x\at // destination different than \at ? (works because regs are a0-a15)
92 mov \ad, \at // then move result to \ad
93 .endif
94#endif /* XCHAL_HAVE_NSA */
95 .endm // find_ms_setbit
96
97/*----------------------------------------------------------------------
98 * find_ls_setbit
99 *
100 * This macro finds the least significant bit that is set in <as>,
101 * and return its index in <ad>.
102 * Usage is the same as for the find_ms_setbit macro.
103 * Example:
104 * find_ls_setbit a0, a4, a0, 0 -- return in a0 index of lsbit set in a4
105 */
106
107 .macro find_ls_setbit ad, as, at, base
108 neg \at, \as // keep only the least-significant bit that is set...
109 and \as, \at, \as // ... in \as
110 find_ms_setbit \ad, \as, \at, \base
111 .endm // find_ls_setbit
112
113/*----------------------------------------------------------------------
114 * find_ls_one
115 *
116 * Same as find_ls_setbit with base zero.
117 * Source (as) and destination (ad) registers must be different.
118 * Provided for backward compatibility.
119 */
120
121 .macro find_ls_one ad, as
122 find_ls_setbit \ad, \as, \ad, 0
123 .endm // find_ls_one
124
125/*----------------------------------------------------------------------
126 * floop, floopnez, floopgtz, floopend
127 *
128 * These macros are used for fast inner loops that
129 * work whether or not the Loops options is configured.
130 * If the Loops option is configured, they simply use
131 * the zero-overhead LOOP instructions; otherwise
132 * they use explicit decrement and branch instructions.
133 *
134 * They are used in pairs, with floop, floopnez or floopgtz
135 * at the beginning of the loop, and floopend at the end.
136 *
137 * Each pair of loop macro calls must be given the loop count
138 * address register and a unique label for that loop.
139 *
140 * Example:
141 *
142 * movi a3, 16 // loop 16 times
143 * floop a3, myloop1
144 * :
145 * bnez a7, end1 // exit loop if a7 != 0
146 * :
147 * floopend a3, myloop1
148 * end1:
149 *
150 * Like the LOOP instructions, these macros cannot be
151 * nested, must include at least one instruction,
152 * cannot call functions inside the loop, etc.
153 * The loop can be exited by jumping to the instruction
154 * following floopend (or elsewhere outside the loop),
155 * or continued by jumping to a NOP instruction placed
156 * immediately before floopend.
157 *
158 * Unlike LOOP instructions, the register passed to floop*
159 * cannot be used inside the loop, because it is used as
160 * the loop counter if the Loops option is not configured.
161 * And its value is undefined after exiting the loop.
162 * And because the loop counter register is active inside
163 * the loop, you can't easily use this construct to loop
164 * across a register file using ROTW as you might with LOOP
165 * instructions, unless you copy the loop register along.
166 */
167
168 /* Named label version of the macros: */
169
170 .macro floop ar, endlabel
171 floop_ \ar, .Lfloopstart_\endlabel, .Lfloopend_\endlabel
172 .endm
173
174 .macro floopnez ar, endlabel
175 floopnez_ \ar, .Lfloopstart_\endlabel, .Lfloopend_\endlabel
176 .endm
177
178 .macro floopgtz ar, endlabel
179 floopgtz_ \ar, .Lfloopstart_\endlabel, .Lfloopend_\endlabel
180 .endm
181
182 .macro floopend ar, endlabel
183 floopend_ \ar, .Lfloopstart_\endlabel, .Lfloopend_\endlabel
184 .endm
185
186 /* Numbered local label version of the macros: */
187#if 0 /*UNTESTED*/
188 .macro floop89 ar
189 floop_ \ar, 8, 9f
190 .endm
191
192 .macro floopnez89 ar
193 floopnez_ \ar, 8, 9f
194 .endm
195
196 .macro floopgtz89 ar
197 floopgtz_ \ar, 8, 9f
198 .endm
199
200 .macro floopend89 ar
201 floopend_ \ar, 8b, 9
202 .endm
203#endif /*0*/
204
205 /* Underlying version of the macros: */
206
207 .macro floop_ ar, startlabel, endlabelref
208 .ifdef _infloop_
209 .if _infloop_
210 .err // Error: floop cannot be nested
211 .endif
212 .endif
213 .set _infloop_, 1
214#if XCHAL_HAVE_LOOPS
215 loop \ar, \endlabelref
216#else /* XCHAL_HAVE_LOOPS */
217\startlabel:
218 addi \ar, \ar, -1
219#endif /* XCHAL_HAVE_LOOPS */
220 .endm // floop_
221
222 .macro floopnez_ ar, startlabel, endlabelref
223 .ifdef _infloop_
224 .if _infloop_
225 .err // Error: floopnez cannot be nested
226 .endif
227 .endif
228 .set _infloop_, 1
229#if XCHAL_HAVE_LOOPS
230 loopnez \ar, \endlabelref
231#else /* XCHAL_HAVE_LOOPS */
232 beqz \ar, \endlabelref
233\startlabel:
234 addi \ar, \ar, -1
235#endif /* XCHAL_HAVE_LOOPS */
236 .endm // floopnez_
237
238 .macro floopgtz_ ar, startlabel, endlabelref
239 .ifdef _infloop_
240 .if _infloop_
241 .err // Error: floopgtz cannot be nested
242 .endif
243 .endif
244 .set _infloop_, 1
245#if XCHAL_HAVE_LOOPS
246 loopgtz \ar, \endlabelref
247#else /* XCHAL_HAVE_LOOPS */
248 bltz \ar, \endlabelref
249 beqz \ar, \endlabelref
250\startlabel:
251 addi \ar, \ar, -1
252#endif /* XCHAL_HAVE_LOOPS */
253 .endm // floopgtz_
254
255
256 .macro floopend_ ar, startlabelref, endlabel
257 .ifndef _infloop_
258 .err // Error: floopend without matching floopXXX
259 .endif
260 .ifeq _infloop_
261 .err // Error: floopend without matching floopXXX
262 .endif
263 .set _infloop_, 0
264#if ! XCHAL_HAVE_LOOPS
265 bnez \ar, \startlabelref
266#endif /* XCHAL_HAVE_LOOPS */
267\endlabel:
268 .endm // floopend_
269
270/*----------------------------------------------------------------------
271 * crsil -- conditional RSIL (read/set interrupt level)
272 *
273 * Executes the RSIL instruction if it exists, else just reads PS.
274 * The RSIL instruction does not exist in the new exception architecture
275 * if the interrupt option is not selected.
276 */
277
278 .macro crsil ar, newlevel
279#if XCHAL_HAVE_OLD_EXC_ARCH || XCHAL_HAVE_INTERRUPTS
280 rsil \ar, \newlevel
281#else
282 rsr \ar, PS
283#endif
284 .endm // crsil
285
286/*----------------------------------------------------------------------
287 * window_spill{4,8,12}
288 *
289 * These macros spill callers' register windows to the stack.
290 * They work for both privileged and non-privileged tasks.
291 * Must be called from a windowed ABI context, eg. within
292 * a windowed ABI function (ie. valid stack frame, window
293 * exceptions enabled, not in exception mode, etc).
294 *
295 * This macro requires a single invocation of the window_spill_common
296 * macro in the same assembly unit and section.
297 *
298 * Note that using window_spill{4,8,12} macros is more efficient
299 * than calling a function implemented using window_spill_function,
300 * because the latter needs extra code to figure out the size of
301 * the call to the spilling function.
302 *
303 * Example usage:
304 *
305 * .text
306 * .align 4
307 * .global some_function
308 * .type some_function,@function
309 * some_function:
310 * entry a1, 16
311 * :
312 * :
313 *
314 * window_spill4 // spill windows of some_function's callers; preserves a0..a3 only;
315 * // to use window_spill{8,12} in this example function we'd have
316 * // to increase space allocated by the entry instruction, because
317 * // 16 bytes only allows call4; 32 or 48 bytes (+locals) are needed
318 * // for call8/window_spill8 or call12/window_spill12 respectively.
319 * :
320 *
321 * retw
322 *
323 * window_spill_common // instantiates code used by window_spill4
324 *
325 *
326 * On entry:
327 * none (if window_spill4)
328 * stack frame has enough space allocated for call8 (if window_spill8)
329 * stack frame has enough space allocated for call12 (if window_spill12)
330 * On exit:
331 * a4..a15 clobbered (if window_spill4)
332 * a8..a15 clobbered (if window_spill8)
333 * a12..a15 clobbered (if window_spill12)
334 * no caller windows are in live registers
335 */
336
337 .macro window_spill4
338#if XCHAL_HAVE_WINDOWED
339# if XCHAL_NUM_AREGS == 16
340 movi a15, 0 // for 16-register files, no need to call to reach the end
341# elif XCHAL_NUM_AREGS == 32
342 call4 .L__wdwspill_assist28 // call deep enough to clear out any live callers
343# elif XCHAL_NUM_AREGS == 64
344 call4 .L__wdwspill_assist60 // call deep enough to clear out any live callers
345# endif
346#endif
347 .endm // window_spill4
348
349 .macro window_spill8
350#if XCHAL_HAVE_WINDOWED
351# if XCHAL_NUM_AREGS == 16
352 movi a15, 0 // for 16-register files, no need to call to reach the end
353# elif XCHAL_NUM_AREGS == 32
354 call8 .L__wdwspill_assist24 // call deep enough to clear out any live callers
355# elif XCHAL_NUM_AREGS == 64
356 call8 .L__wdwspill_assist56 // call deep enough to clear out any live callers
357# endif
358#endif
359 .endm // window_spill8
360
361 .macro window_spill12
362#if XCHAL_HAVE_WINDOWED
363# if XCHAL_NUM_AREGS == 16
364 movi a15, 0 // for 16-register files, no need to call to reach the end
365# elif XCHAL_NUM_AREGS == 32
366 call12 .L__wdwspill_assist20 // call deep enough to clear out any live callers
367# elif XCHAL_NUM_AREGS == 64
368 call12 .L__wdwspill_assist52 // call deep enough to clear out any live callers
369# endif
370#endif
371 .endm // window_spill12
372
373/*----------------------------------------------------------------------
374 * window_spill_function
375 *
376 * This macro outputs a function that will spill its caller's callers'
377 * register windows to the stack. Eg. it could be used to implement
378 * a version of xthal_window_spill() that works in non-privileged tasks.
379 * This works for both privileged and non-privileged tasks.
380 *
381 * Typical usage:
382 *
383 * .text
384 * .align 4
385 * .global my_spill_function
386 * .type my_spill_function,@function
387 * my_spill_function:
388 * window_spill_function
389 *
390 * On entry to resulting function:
391 * none
392 * On exit from resulting function:
393 * none (no caller windows are in live registers)
394 */
395
396 .macro window_spill_function
397#if XCHAL_HAVE_WINDOWED
398# if XCHAL_NUM_AREGS == 32
399 entry sp, 48
400 bbci.l a0, 31, 1f // branch if called with call4
401 bbsi.l a0, 30, 2f // branch if called with call12
402 call8 .L__wdwspill_assist16 // called with call8, only need another 8
403 retw
4041: call12 .L__wdwspill_assist16 // called with call4, only need another 12
405 retw
4062: call4 .L__wdwspill_assist16 // called with call12, only need another 4
407 retw
408# elif XCHAL_NUM_AREGS == 64
409 entry sp, 48
410 bbci.l a0, 31, 1f // branch if called with call4
411 bbsi.l a0, 30, 2f // branch if called with call12
412 call4 .L__wdwspill_assist52 // called with call8, only need a call4
413 retw
4141: call8 .L__wdwspill_assist52 // called with call4, only need a call8
415 retw
4162: call12 .L__wdwspill_assist40 // called with call12, can skip a call12
417 retw
418# elif XCHAL_NUM_AREGS == 16
419 entry sp, 16
420 bbci.l a0, 31, 1f // branch if called with call4
421 bbsi.l a0, 30, 2f // branch if called with call12
422 movi a7, 0 // called with call8
423 retw
4241: movi a11, 0 // called with call4
4252: retw // if called with call12, everything already spilled
426
427// movi a15, 0 // trick to spill all but the direct caller
428// j 1f
429// // The entry instruction is magical in the assembler (gets auto-aligned)
430// // so we have to jump to it to avoid falling through the padding.
431// // We need entry/retw to know where to return.
432//1: entry sp, 16
433// retw
434# else
435# error "unrecognized address register file size"
436# endif
437#endif /* XCHAL_HAVE_WINDOWED */
438 window_spill_common
439 .endm // window_spill_function
440
441/*----------------------------------------------------------------------
442 * window_spill_common
443 *
444 * Common code used by any number of invocations of the window_spill##
445 * and window_spill_function macros.
446 *
447 * Must be instantiated exactly once within a given assembly unit,
448 * within call/j range of and same section as window_spill##
449 * macro invocations for that assembly unit.
450 * (Is automatically instantiated by the window_spill_function macro.)
451 */
452
453 .macro window_spill_common
454#if XCHAL_HAVE_WINDOWED && (XCHAL_NUM_AREGS == 32 || XCHAL_NUM_AREGS == 64)
455 .ifndef .L__wdwspill_defined
456# if XCHAL_NUM_AREGS >= 64
457.L__wdwspill_assist60:
458 entry sp, 32
459 call8 .L__wdwspill_assist52
460 retw
461.L__wdwspill_assist56:
462 entry sp, 16
463 call4 .L__wdwspill_assist52
464 retw
465.L__wdwspill_assist52:
466 entry sp, 48
467 call12 .L__wdwspill_assist40
468 retw
469.L__wdwspill_assist40:
470 entry sp, 48
471 call12 .L__wdwspill_assist28
472 retw
473# endif
474.L__wdwspill_assist28:
475 entry sp, 48
476 call12 .L__wdwspill_assist16
477 retw
478.L__wdwspill_assist24:
479 entry sp, 32
480 call8 .L__wdwspill_assist16
481 retw
482.L__wdwspill_assist20:
483 entry sp, 16
484 call4 .L__wdwspill_assist16
485 retw
486.L__wdwspill_assist16:
487 entry sp, 16
488 movi a15, 0
489 retw
490 .set .L__wdwspill_defined, 1
491 .endif
492#endif /* XCHAL_HAVE_WINDOWED with 32 or 64 aregs */
493 .endm // window_spill_common
494
495/*----------------------------------------------------------------------
496 * beqi32
497 *
498 * macro implements version of beqi for arbitrary 32-bit immidiate value
499 *
500 * beqi32 ax, ay, imm32, label
501 *
502 * Compares value in register ax with imm32 value and jumps to label if
503 * equal. Clobberes register ay if needed
504 *
505 */
506 .macro beqi32 ax, ay, imm, label
507 .ifeq ((\imm-1) & ~7) // 1..8 ?
508 beqi \ax, \imm, \label
509 .else
510 .ifeq (\imm+1) // -1 ?
511 beqi \ax, \imm, \label
512 .else
513 .ifeq (\imm) // 0 ?
514 beqz \ax, \label
515 .else
516 // We could also handle immediates 10,12,16,32,64,128,256
517 // but it would be a long macro...
518 movi \ay, \imm
519 beq \ax, \ay, \label
520 .endif
521 .endif
522 .endif
523 .endm // beqi32
524
525#endif /*XTENSA_COREASM_H*/
526
diff --git a/include/asm-xtensa/xtensa/corebits.h b/include/asm-xtensa/xtensa/corebits.h
deleted file mode 100644
index e578ade41632..000000000000
--- a/include/asm-xtensa/xtensa/corebits.h
+++ /dev/null
@@ -1,77 +0,0 @@
1#ifndef XTENSA_COREBITS_H
2#define XTENSA_COREBITS_H
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * xtensa/corebits.h - Xtensa Special Register field positions and masks.
8 *
9 * (In previous releases, these were defined in specreg.h, a generated file.
10 * This file is not generated, i.e. it is processor configuration independent.)
11 */
12
13
14/* EXCCAUSE register fields: */
15#define EXCCAUSE_EXCCAUSE_SHIFT 0
16#define EXCCAUSE_EXCCAUSE_MASK 0x3F
17/* Exception causes (mostly incomplete!): */
18#define EXCCAUSE_ILLEGAL 0
19#define EXCCAUSE_SYSCALL 1
20#define EXCCAUSE_IFETCHERROR 2
21#define EXCCAUSE_LOADSTOREERROR 3
22#define EXCCAUSE_LEVEL1INTERRUPT 4
23#define EXCCAUSE_ALLOCA 5
24
25/* PS register fields: */
26#define PS_WOE_SHIFT 18
27#define PS_WOE_MASK 0x00040000
28#define PS_WOE PS_WOE_MASK
29#define PS_CALLINC_SHIFT 16
30#define PS_CALLINC_MASK 0x00030000
31#define PS_CALLINC(n) (((n)&3)<<PS_CALLINC_SHIFT) /* n = 0..3 */
32#define PS_OWB_SHIFT 8
33#define PS_OWB_MASK 0x00000F00
34#define PS_OWB(n) (((n)&15)<<PS_OWB_SHIFT) /* n = 0..15 (or 0..7) */
35#define PS_RING_SHIFT 6
36#define PS_RING_MASK 0x000000C0
37#define PS_RING(n) (((n)&3)<<PS_RING_SHIFT) /* n = 0..3 */
38#define PS_UM_SHIFT 5
39#define PS_UM_MASK 0x00000020
40#define PS_UM PS_UM_MASK
41#define PS_EXCM_SHIFT 4
42#define PS_EXCM_MASK 0x00000010
43#define PS_EXCM PS_EXCM_MASK
44#define PS_INTLEVEL_SHIFT 0
45#define PS_INTLEVEL_MASK 0x0000000F
46#define PS_INTLEVEL(n) ((n)&PS_INTLEVEL_MASK) /* n = 0..15 */
47/* Backward compatibility (deprecated): */
48#define PS_PROGSTACK_SHIFT PS_UM_SHIFT
49#define PS_PROGSTACK_MASK PS_UM_MASK
50#define PS_PROG_SHIFT PS_UM_SHIFT
51#define PS_PROG_MASK PS_UM_MASK
52#define PS_PROG PS_UM
53
54/* DBREAKCn register fields: */
55#define DBREAKC_MASK_SHIFT 0
56#define DBREAKC_MASK_MASK 0x0000003F
57#define DBREAKC_LOADBREAK_SHIFT 30
58#define DBREAKC_LOADBREAK_MASK 0x40000000
59#define DBREAKC_STOREBREAK_SHIFT 31
60#define DBREAKC_STOREBREAK_MASK 0x80000000
61
62/* DEBUGCAUSE register fields: */
63#define DEBUGCAUSE_DEBUGINT_SHIFT 5
64#define DEBUGCAUSE_DEBUGINT_MASK 0x20 /* debug interrupt */
65#define DEBUGCAUSE_BREAKN_SHIFT 4
66#define DEBUGCAUSE_BREAKN_MASK 0x10 /* BREAK.N instruction */
67#define DEBUGCAUSE_BREAK_SHIFT 3
68#define DEBUGCAUSE_BREAK_MASK 0x08 /* BREAK instruction */
69#define DEBUGCAUSE_DBREAK_SHIFT 2
70#define DEBUGCAUSE_DBREAK_MASK 0x04 /* DBREAK match */
71#define DEBUGCAUSE_IBREAK_SHIFT 1
72#define DEBUGCAUSE_IBREAK_MASK 0x02 /* IBREAK match */
73#define DEBUGCAUSE_ICOUNT_SHIFT 0
74#define DEBUGCAUSE_ICOUNT_MASK 0x01 /* ICOUNT would increment to zero */
75
76#endif /*XTENSA_COREBITS_H*/
77
diff --git a/include/asm-xtensa/xtensa/hal.h b/include/asm-xtensa/xtensa/hal.h
deleted file mode 100644
index d10472505454..000000000000
--- a/include/asm-xtensa/xtensa/hal.h
+++ /dev/null
@@ -1,822 +0,0 @@
1#ifndef XTENSA_HAL_H
2#define XTENSA_HAL_H
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/hal.h -- contains a definition of the
8 * Core HAL interface.
9 *
10 * All definitions in this header file are independent of any specific
11 * Xtensa processor configuration. Thus an OS or other software can
12 * include this header file and be compiled into configuration-
13 * independent objects that can be distributed and eventually linked
14 * to the HAL library (libhal.a) to create a configuration-specific
15 * final executable.
16 *
17 * Certain definitions, however, are release-specific -- such as the
18 * XTHAL_RELEASE_xxx macros (or additions made in later releases).
19 *
20 * This file is subject to the terms and conditions of the GNU General Public
21 * License. See the file "COPYING" in the main directory of this archive
22 * for more details.
23 *
24 * Copyright (C) 2002 Tensilica Inc.
25 */
26
27
28/*----------------------------------------------------------------------
29 Constant Definitions
30 (shared with assembly)
31 ----------------------------------------------------------------------*/
32
33/* Software release information (not configuration-specific!): */
34#define XTHAL_RELEASE_MAJOR 1050
35#define XTHAL_RELEASE_MINOR 0
36#define XTHAL_RELEASE_NAME "T1050.0-2002-08-06-eng0"
37#define XTHAL_RELEASE_INTERNAL "2002-08-06-eng0"
38#define XTHAL_REL_T1050 1
39#define XTHAL_REL_T1050_0 1
40#define XTHAL_REL_T1050_0_2002 1
41#define XTHAL_REL_T1050_0_2002_08 1
42#define XTHAL_REL_T1050_0_2002_08_06 1
43#define XTHAL_REL_T1050_0_2002_08_06_ENG0 1
44
45/* HAL version numbers (these names are for backward compatibility): */
46#define XTHAL_MAJOR_REV XTHAL_RELEASE_MAJOR
47#define XTHAL_MINOR_REV XTHAL_RELEASE_MINOR
48/*
49 * A bit of software release history on values of XTHAL_{MAJOR,MINOR}_REV:
50 *
51 * Release MAJOR MINOR Comment
52 * ======= ===== ===== =======
53 * T1015.n n/a n/a (HAL not yet available)
54 * T1020.{0,1,2} 0 1 (HAL beta)
55 * T1020.{3,4} 0 2 First release.
56 * T1020.n (n>4) 0 2 or >3 (TBD)
57 * T1030.0 0 1 (HAL beta)
58 * T1030.{1,2} 0 3 Equivalent to first release.
59 * T1030.n (n>=3) 0 >= 3 (TBD)
60 * T1040.n 1040 n Full CHAL available from T1040.2
61 * T1050.n 1050 n Current release.
62 *
63 *
64 * Note: there is a distinction between the software release with
65 * which something is compiled (accessible using XTHAL_RELEASE_* macros)
66 * and the software release with which the HAL library was compiled
67 * (accessible using Xthal_release_* global variables). This
68 * distinction is particularly relevant for vendors that distribute
69 * configuration-independent binaries (eg. an OS), where their customer
70 * might link it with a HAL of a different Xtensa software release.
71 * In this case, it may be appropriate for the OS to verify at run-time
72 * whether XTHAL_RELEASE_* and Xthal_release_* are compatible.
73 * [Guidelines as to which release is compatible with which are not
74 * currently provided explicitly, but might be inferred from reading
75 * OSKit documentation for all releases -- compatibility is also highly
76 * dependent on which HAL features are used. Each release is usually
77 * backward compatible, with very few exceptions if any.]
78 *
79 * Notes:
80 * Tornado 2.0 supported in T1020.3+, T1030.1+, and T1040.{0,1} only.
81 * Tornado 2.0.2 supported in T1040.2+, and T1050.
82 * Compile-time HAL port of NucleusPlus supported by T1040.2+ and T1050.
83 */
84
85
86/*
87 * Architectural limits, independent of configuration.
88 * Note that these are ISA-defined limits, not micro-architecture implementation
89 * limits enforced by the Xtensa Processor Generator (which may be stricter than
90 * these below).
91 */
92#define XTHAL_MAX_CPS 8 /* max number of coprocessors (0..7) */
93#define XTHAL_MAX_INTERRUPTS 32 /* max number of interrupts (0..31) */
94#define XTHAL_MAX_INTLEVELS 16 /* max number of interrupt levels (0..15) */
95 /* (as of T1040, implementation limit is 7: 0..6) */
96#define XTHAL_MAX_TIMERS 4 /* max number of timers (CCOMPARE0..CCOMPARE3) */
97 /* (as of T1040, implementation limit is 3: 0..2) */
98
99/* Misc: */
100#define XTHAL_LITTLEENDIAN 0
101#define XTHAL_BIGENDIAN 1
102
103
104/* Interrupt types: */
105#define XTHAL_INTTYPE_UNCONFIGURED 0
106#define XTHAL_INTTYPE_SOFTWARE 1
107#define XTHAL_INTTYPE_EXTERN_EDGE 2
108#define XTHAL_INTTYPE_EXTERN_LEVEL 3
109#define XTHAL_INTTYPE_TIMER 4
110#define XTHAL_INTTYPE_NMI 5
111#define XTHAL_MAX_INTTYPES 6 /* number of interrupt types */
112
113/* Timer related: */
114#define XTHAL_TIMER_UNCONFIGURED -1 /* Xthal_timer_interrupt[] value for non-existent timers */
115#define XTHAL_TIMER_UNASSIGNED XTHAL_TIMER_UNCONFIGURED /* (for backwards compatibility only) */
116
117
118/* Access Mode bits (tentative): */ /* bit abbr unit short_name PPC equ - Description */
119#define XTHAL_AMB_EXCEPTION 0 /* 001 E EX fls: EXception none - generate exception on any access (aka "illegal") */
120#define XTHAL_AMB_HITCACHE 1 /* 002 C CH fls: use Cache on Hit ~(I CI) - use cache on hit -- way from tag match [or H HC, or U UC] (ISA: same, except for Isolate case) */
121#define XTHAL_AMB_ALLOCATE 2 /* 004 A AL fl?: ALlocate none - refill cache on miss -- way from LRU [or F FI fill] (ISA: Read/Write Miss Refill) */
122#define XTHAL_AMB_WRITETHRU 3 /* 008 W WT --s: WriteThrough W WT - store immediately to memory (ISA: same) */
123#define XTHAL_AMB_ISOLATE 4 /* 010 I IS fls: ISolate none - use cache regardless of hit-vs-miss -- way from vaddr (ISA: use-cache-on-miss+hit) */
124#define XTHAL_AMB_GUARD 5 /* 020 G GU ?l?: GUard G * - non-speculative; spec/replay refs not permitted */
125#if 0
126#define XTHAL_AMB_ORDERED x /* 000 O OR fls: ORdered G * - mem accesses cannot be out of order */
127#define XTHAL_AMB_FUSEWRITES x /* 000 F FW --s: FuseWrites none - allow combining/merging multiple writes (to same datapath data unit) into one (implied by writeback) */
128#define XTHAL_AMB_COHERENT x /* 000 M MC fl?: Mem/MP Coherent M - on reads, other CPUs/bus-masters may need to supply data */
129#define XTHAL_AMB_TRUSTED x /* 000 T TR ?l?: TRusted none - memory will not bus error (if it does, handle as fatal imprecise interrupt) */
130#define XTHAL_AMB_PREFETCH x /* 000 P PR fl?: PRefetch none - on refill, read line+1 into prefetch buffers */
131#define XTHAL_AMB_STREAM x /* 000 S ST ???: STreaming none - access one of N stream buffers */
132#endif /*0*/
133
134#define XTHAL_AM_EXCEPTION (1<<XTHAL_AMB_EXCEPTION)
135#define XTHAL_AM_HITCACHE (1<<XTHAL_AMB_HITCACHE)
136#define XTHAL_AM_ALLOCATE (1<<XTHAL_AMB_ALLOCATE)
137#define XTHAL_AM_WRITETHRU (1<<XTHAL_AMB_WRITETHRU)
138#define XTHAL_AM_ISOLATE (1<<XTHAL_AMB_ISOLATE)
139#define XTHAL_AM_GUARD (1<<XTHAL_AMB_GUARD)
140#if 0
141#define XTHAL_AM_ORDERED (1<<XTHAL_AMB_ORDERED)
142#define XTHAL_AM_FUSEWRITES (1<<XTHAL_AMB_FUSEWRITES)
143#define XTHAL_AM_COHERENT (1<<XTHAL_AMB_COHERENT)
144#define XTHAL_AM_TRUSTED (1<<XTHAL_AMB_TRUSTED)
145#define XTHAL_AM_PREFETCH (1<<XTHAL_AMB_PREFETCH)
146#define XTHAL_AM_STREAM (1<<XTHAL_AMB_STREAM)
147#endif /*0*/
148
149/*
150 * Allowed Access Modes (bit combinations).
151 *
152 * Columns are:
153 * "FOGIWACE"
154 * Access mode bits (see XTHAL_AMB_xxx above).
155 * <letter> = bit is set
156 * '-' = bit is clear
157 * '.' = bit is irrelevant / don't care, as follows:
158 * E=1 makes all others irrelevant
159 * W,F relevant only for stores
160 * "2345"
161 * Indicates which Xtensa releases support the corresponding
162 * access mode. Releases for each character column are:
163 * 2 = prior to T1020.2: T1015 (V1.5), T1020.0, T1020.1
164 * 3 = T1020.2 and later: T1020.2+, T1030
165 * 4 = T1040
166 * 5 = T1050 (maybe)
167 * And the character column contents are:
168 * <number> = support by release(s)
169 * "." = unsupported by release(s)
170 * "?" = support unknown
171 */
172 /* FOGIWACE 2345 */
173/* For instruction fetch: */
174#define XTHAL_FAM_EXCEPTION 0x001 /* .......E 2345 exception */
175#define XTHAL_FAM_ISOLATE 0x012 /* .--I.-C- .... isolate */
176#define XTHAL_FAM_BYPASS 0x000 /* .---.--- 2345 bypass */
177#define XTHAL_FAM_NACACHED 0x002 /* .---.-C- .... cached no-allocate (frozen) */
178#define XTHAL_FAM_CACHED 0x006 /* .---.AC- 2345 cached */
179/* For data load: */
180#define XTHAL_LAM_EXCEPTION 0x001 /* .......E 2345 exception */
181#define XTHAL_LAM_ISOLATE 0x012 /* .--I.-C- 2345 isolate */
182#define XTHAL_LAM_BYPASS 0x000 /* .O--.--- 2... bypass speculative */
183#define XTHAL_LAM_BYPASSG 0x020 /* .OG-.--- .345 bypass guarded */
184#define XTHAL_LAM_NACACHED 0x002 /* .O--.-C- 2... cached no-allocate speculative */
185#define XTHAL_LAM_NACACHEDG 0x022 /* .OG-.-C- .345 cached no-allocate guarded */
186#define XTHAL_LAM_CACHED 0x006 /* .---.AC- 2345 cached speculative */
187#define XTHAL_LAM_CACHEDG 0x026 /* .?G-.AC- .... cached guarded */
188/* For data store: */
189#define XTHAL_SAM_EXCEPTION 0x001 /* .......E 2345 exception */
190#define XTHAL_SAM_ISOLATE 0x032 /* .-GI--C- 2345 isolate */
191#define XTHAL_SAM_BYPASS 0x028 /* -OG-W--- 2345 bypass */
192/*efine XTHAL_SAM_BYPASSF 0x028*/ /* F-G-W--- ...? bypass write-combined */
193#define XTHAL_SAM_WRITETHRU 0x02A /* -OG-W-C- 234? writethrough */
194/*efine XTHAL_SAM_WRITETHRUF 0x02A*/ /* F-G-W-C- ...5 writethrough write-combined */
195#define XTHAL_SAM_WRITEALLOC 0x02E /* -OG-WAC- ...? writethrough-allocate */
196/*efine XTHAL_SAM_WRITEALLOCF 0x02E*/ /* F-G-WAC- ...? writethrough-allocate write-combined */
197#define XTHAL_SAM_WRITEBACK 0x026 /* F-G--AC- ...5 writeback */
198
199#if 0
200/*
201 Cache attribute encoding for CACHEATTR (per ISA):
202 (Note: if this differs from ISA Ref Manual, ISA has precedence)
203
204 Inst-fetches Loads Stores
205 ------------- ------------ -------------
2060x0 FCA_EXCEPTION ?LCA_NACACHED_G* SCA_WRITETHRU "uncached"
2070x1 FCA_CACHED LCA_CACHED SCA_WRITETHRU cached
2080x2 FCA_BYPASS LCA_BYPASS_G* SCA_BYPASS bypass
2090x3 FCA_CACHED LCA_CACHED SCA_WRITEALLOCF write-allocate
210 or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
2110x4 FCA_CACHED LCA_CACHED SCA_WRITEBACK write-back
212 or LCA_EXCEPTION SCA_EXCEPTION (if unimplemented)
2130x5..D FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION (reserved)
2140xE FCA_EXCEPTION LCA_ISOLATE SCA_ISOLATE isolate
2150xF FCA_EXCEPTION LCA_EXCEPTION SCA_EXCEPTION illegal
216 * Prior to T1020.2?, guard feature not supported, this defaulted to speculative (no _G)
217*/
218#endif /*0*/
219
220
221#if !defined(__ASSEMBLY__) && !defined(_NOCLANGUAGE)
222#ifdef __cplusplus
223extern "C" {
224#endif
225
226/*----------------------------------------------------------------------
227 HAL
228 ----------------------------------------------------------------------*/
229
230/* Constant to be checked in build = (XTHAL_MAJOR_REV<<16)|XTHAL_MINOR_REV */
231extern const unsigned int Xthal_rev_no;
232
233
234/*----------------------------------------------------------------------
235 Processor State
236 ----------------------------------------------------------------------*/
237/* save & restore the extra processor state */
238extern void xthal_save_extra(void *base);
239extern void xthal_restore_extra(void *base);
240
241extern void xthal_save_cpregs(void *base, int);
242extern void xthal_restore_cpregs(void *base, int);
243
244/*extern void xthal_save_all_extra(void *base);*/
245/*extern void xthal_restore_all_extra(void *base);*/
246
247/* space for processor state */
248extern const unsigned int Xthal_extra_size;
249extern const unsigned int Xthal_extra_align;
250/* space for TIE register files */
251extern const unsigned int Xthal_cpregs_size[XTHAL_MAX_CPS];
252extern const unsigned int Xthal_cpregs_align[XTHAL_MAX_CPS];
253
254/* total of space for the processor state (for Tor2) */
255extern const unsigned int Xthal_all_extra_size;
256extern const unsigned int Xthal_all_extra_align;
257
258/* initialize the extra processor */
259/*extern void xthal_init_extra(void);*/
260/* initialize the TIE coprocessor */
261/*extern void xthal_init_cp(int);*/
262
263/* initialize the extra processor */
264extern void xthal_init_mem_extra(void *);
265/* initialize the TIE coprocessor */
266extern void xthal_init_mem_cp(void *, int);
267
268/* validate & invalidate the TIE register file */
269extern void xthal_validate_cp(int);
270extern void xthal_invalidate_cp(int);
271
272/* the number of TIE coprocessors contiguous from zero (for Tor2) */
273extern const unsigned int Xthal_num_coprocessors;
274
275/* actual number of coprocessors */
276extern const unsigned char Xthal_cp_num;
277/* index of highest numbered coprocessor, plus one */
278extern const unsigned char Xthal_cp_max;
279/* index of highest allowed coprocessor number, per cfg, plus one */
280/*extern const unsigned char Xthal_cp_maxcfg;*/
281/* bitmask of which coprocessors are present */
282extern const unsigned int Xthal_cp_mask;
283
284/* read and write cpenable register */
285extern void xthal_set_cpenable(unsigned);
286extern unsigned xthal_get_cpenable(void);
287
288/* read & write extra state register */
289/*extern int xthal_read_extra(void *base, unsigned reg, unsigned *value);*/
290/*extern int xthal_write_extra(void *base, unsigned reg, unsigned value);*/
291
292/* read & write a TIE coprocessor register */
293/*extern int xthal_read_cpreg(void *base, int cp, unsigned reg, unsigned *value);*/
294/*extern int xthal_write_cpreg(void *base, int cp, unsigned reg, unsigned value);*/
295
296/* return coprocessor number based on register */
297/*extern int xthal_which_cp(unsigned reg);*/
298
299/*----------------------------------------------------------------------
300 Interrupts
301 ----------------------------------------------------------------------*/
302
303/* the number of interrupt levels */
304extern const unsigned char Xthal_num_intlevels;
305/* the number of interrupts */
306extern const unsigned char Xthal_num_interrupts;
307
308/* mask for level of interrupts */
309extern const unsigned int Xthal_intlevel_mask[XTHAL_MAX_INTLEVELS];
310/* mask for level 0 to N interrupts */
311extern const unsigned int Xthal_intlevel_andbelow_mask[XTHAL_MAX_INTLEVELS];
312
313/* level of each interrupt */
314extern const unsigned char Xthal_intlevel[XTHAL_MAX_INTERRUPTS];
315
316/* type per interrupt */
317extern const unsigned char Xthal_inttype[XTHAL_MAX_INTERRUPTS];
318
319/* masks of each type of interrupt */
320extern const unsigned int Xthal_inttype_mask[XTHAL_MAX_INTTYPES];
321
322/* interrupt numbers assigned to each timer interrupt */
323extern const int Xthal_timer_interrupt[XTHAL_MAX_TIMERS];
324
325/*** Virtual interrupt prioritization: ***/
326
327/* Convert between interrupt levels (as per PS.INTLEVEL) and virtual interrupt priorities: */
328extern unsigned xthal_vpri_to_intlevel(unsigned vpri);
329extern unsigned xthal_intlevel_to_vpri(unsigned intlevel);
330
331/* Enables/disables given set (mask) of interrupts; returns previous enabled-mask of all ints: */
332extern unsigned xthal_int_enable(unsigned);
333extern unsigned xthal_int_disable(unsigned);
334
335/* Set/get virtual priority of an interrupt: */
336extern int xthal_set_int_vpri(int intnum, int vpri);
337extern int xthal_get_int_vpri(int intnum);
338
339/* Set/get interrupt lockout level for exclusive access to virtual priority data structures: */
340extern void xthal_set_vpri_locklevel(unsigned intlevel);
341extern unsigned xthal_get_vpri_locklevel(void);
342
343/* Set/get current virtual interrupt priority: */
344extern unsigned xthal_set_vpri(unsigned vpri);
345extern unsigned xthal_get_vpri(unsigned vpri);
346extern unsigned xthal_set_vpri_intlevel(unsigned intlevel);
347extern unsigned xthal_set_vpri_lock(void);
348
349
350
351/*----------------------------------------------------------------------
352 Generic Interrupt Trampolining Support
353 ----------------------------------------------------------------------*/
354
355typedef void (XtHalVoidFunc)(void);
356
357/*
358 * Bitmask of interrupts currently trampolining down:
359 */
360extern unsigned Xthal_tram_pending;
361
362/*
363 * Bitmask of which interrupts currently trampolining down
364 * synchronously are actually enabled; this bitmask is necessary
365 * because INTENABLE cannot hold that state (sync-trampolining
366 * interrupts must be kept disabled while trampolining);
367 * in the current implementation, any bit set here is not set
368 * in INTENABLE, and vice-versa; once a sync-trampoline is
369 * handled (at level one), its enable bit must be moved from
370 * here to INTENABLE:
371 */
372extern unsigned Xthal_tram_enabled;
373
374/*
375 * Bitmask of interrupts configured for sync trampolining:
376 */
377extern unsigned Xthal_tram_sync;
378
379
380/* Trampoline support functions: */
381extern unsigned xthal_tram_pending_to_service( void );
382extern void xthal_tram_done( unsigned serviced_mask );
383extern int xthal_tram_set_sync( int intnum, int sync );
384extern XtHalVoidFunc* xthal_set_tram_trigger_func( XtHalVoidFunc *trigger_fn );
385
386/* INTENABLE,INTREAD,INTSET,INTCLEAR register access functions: */
387extern unsigned xthal_get_intenable( void );
388extern void xthal_set_intenable( unsigned );
389extern unsigned xthal_get_intread( void );
390extern void xthal_set_intset( unsigned );
391extern void xthal_set_intclear( unsigned );
392
393
394/*----------------------------------------------------------------------
395 Register Windows
396 ----------------------------------------------------------------------*/
397
398/* number of registers in register window */
399extern const unsigned int Xthal_num_aregs;
400extern const unsigned char Xthal_num_aregs_log2;
401
402/* This spill any live register windows (other than the caller's): */
403extern void xthal_window_spill( void );
404
405
406/*----------------------------------------------------------------------
407 Cache
408 ----------------------------------------------------------------------*/
409
410/* size of the cache lines in log2(bytes) */
411extern const unsigned char Xthal_icache_linewidth;
412extern const unsigned char Xthal_dcache_linewidth;
413/* size of the cache lines in bytes */
414extern const unsigned short Xthal_icache_linesize;
415extern const unsigned short Xthal_dcache_linesize;
416/* number of cache sets in log2(lines per way) */
417extern const unsigned char Xthal_icache_setwidth;
418extern const unsigned char Xthal_dcache_setwidth;
419/* cache set associativity (number of ways) */
420extern const unsigned int Xthal_icache_ways;
421extern const unsigned int Xthal_dcache_ways;
422/* size of the caches in bytes (ways * 2^(linewidth + setwidth)) */
423extern const unsigned int Xthal_icache_size;
424extern const unsigned int Xthal_dcache_size;
425/* cache features */
426extern const unsigned char Xthal_dcache_is_writeback;
427extern const unsigned char Xthal_icache_line_lockable;
428extern const unsigned char Xthal_dcache_line_lockable;
429
430/* cache attribute register control (used by other HAL routines) */
431extern unsigned xthal_get_cacheattr( void );
432extern unsigned xthal_get_icacheattr( void );
433extern unsigned xthal_get_dcacheattr( void );
434extern void xthal_set_cacheattr( unsigned );
435extern void xthal_set_icacheattr( unsigned );
436extern void xthal_set_dcacheattr( unsigned );
437
438/* initialize cache support (must be called once at startup, before all other cache calls) */
439/*extern void xthal_cache_startinit( void );*/
440/* reset caches */
441/*extern void xthal_icache_reset( void );*/
442/*extern void xthal_dcache_reset( void );*/
443/* enable caches */
444extern void xthal_icache_enable( void ); /* DEPRECATED */
445extern void xthal_dcache_enable( void ); /* DEPRECATED */
446/* disable caches */
447extern void xthal_icache_disable( void ); /* DEPRECATED */
448extern void xthal_dcache_disable( void ); /* DEPRECATED */
449
450/* invalidate the caches */
451extern void xthal_icache_all_invalidate( void );
452extern void xthal_dcache_all_invalidate( void );
453extern void xthal_icache_region_invalidate( void *addr, unsigned size );
454extern void xthal_dcache_region_invalidate( void *addr, unsigned size );
455extern void xthal_icache_line_invalidate(void *addr);
456extern void xthal_dcache_line_invalidate(void *addr);
457/* write dirty data back */
458extern void xthal_dcache_all_writeback( void );
459extern void xthal_dcache_region_writeback( void *addr, unsigned size );
460extern void xthal_dcache_line_writeback(void *addr);
461/* write dirty data back and invalidate */
462extern void xthal_dcache_all_writeback_inv( void );
463extern void xthal_dcache_region_writeback_inv( void *addr, unsigned size );
464extern void xthal_dcache_line_writeback_inv(void *addr);
465/* prefetch and lock specified memory range into cache */
466extern void xthal_icache_region_lock( void *addr, unsigned size );
467extern void xthal_dcache_region_lock( void *addr, unsigned size );
468extern void xthal_icache_line_lock(void *addr);
469extern void xthal_dcache_line_lock(void *addr);
470/* unlock from cache */
471extern void xthal_icache_all_unlock( void );
472extern void xthal_dcache_all_unlock( void );
473extern void xthal_icache_region_unlock( void *addr, unsigned size );
474extern void xthal_dcache_region_unlock( void *addr, unsigned size );
475extern void xthal_icache_line_unlock(void *addr);
476extern void xthal_dcache_line_unlock(void *addr);
477
478
479/* sync icache and memory */
480extern void xthal_icache_sync( void );
481/* sync dcache and memory */
482extern void xthal_dcache_sync( void );
483
484/*----------------------------------------------------------------------
485 Debug
486 ----------------------------------------------------------------------*/
487
488/* 1 if debug option configured, 0 if not: */
489extern const int Xthal_debug_configured;
490
491/* Number of instruction and data break registers: */
492extern const int Xthal_num_ibreak;
493extern const int Xthal_num_dbreak;
494
495/* Set (plant) and remove software breakpoint, both synchronizing cache: */
496extern unsigned int xthal_set_soft_break(void *addr);
497extern void xthal_remove_soft_break(void *addr, unsigned int);
498
499
500/*----------------------------------------------------------------------
501 Disassembler
502 ----------------------------------------------------------------------*/
503
504/* Max expected size of the return buffer for a disassembled instruction (hint only): */
505#define XTHAL_DISASM_BUFSIZE 80
506
507/* Disassembly option bits for selecting what to return: */
508#define XTHAL_DISASM_OPT_ADDR 0x0001 /* display address */
509#define XTHAL_DISASM_OPT_OPHEX 0x0002 /* display opcode bytes in hex */
510#define XTHAL_DISASM_OPT_OPCODE 0x0004 /* display opcode name (mnemonic) */
511#define XTHAL_DISASM_OPT_PARMS 0x0008 /* display parameters */
512#define XTHAL_DISASM_OPT_ALL 0x0FFF /* display everything */
513
514/* routine to get a string for the disassembled instruction */
515extern int xthal_disassemble( unsigned char *instr_buf, void *tgt_addr,
516 char *buffer, unsigned buflen, unsigned options );
517
518/* routine to get the size of the next instruction. Returns 0 for
519 illegal instruction */
520extern int xthal_disassemble_size( unsigned char *instr_buf );
521
522
523/*----------------------------------------------------------------------
524 Core Counter
525 ----------------------------------------------------------------------*/
526
527/* counter info */
528extern const unsigned char Xthal_have_ccount; /* set if CCOUNT register present */
529extern const unsigned char Xthal_num_ccompare; /* number of CCOMPAREn registers */
530
531/* get CCOUNT register (if not present return 0) */
532extern unsigned xthal_get_ccount(void);
533
534/* set and get CCOMPAREn registers (if not present, get returns 0) */
535extern void xthal_set_ccompare(int, unsigned);
536extern unsigned xthal_get_ccompare(int);
537
538
539/*----------------------------------------------------------------------
540 Instruction/Data RAM/ROM Access
541 ----------------------------------------------------------------------*/
542
543extern void* xthal_memcpy(void *dst, const void *src, unsigned len);
544extern void* xthal_bcopy(const void *src, void *dst, unsigned len);
545
546/*----------------------------------------------------------------------
547 MP Synchronization
548 ----------------------------------------------------------------------*/
549extern int xthal_compare_and_set( int *addr, int test_val, int compare_val );
550extern unsigned xthal_get_prid( void );
551
552/*extern const char Xthal_have_s32c1i;*/
553extern const unsigned char Xthal_have_prid;
554
555
556/*----------------------------------------------------------------------
557 Miscellaneous
558 ----------------------------------------------------------------------*/
559
560extern const unsigned int Xthal_release_major;
561extern const unsigned int Xthal_release_minor;
562extern const char * const Xthal_release_name;
563extern const char * const Xthal_release_internal;
564
565extern const unsigned char Xthal_memory_order;
566extern const unsigned char Xthal_have_windowed;
567extern const unsigned char Xthal_have_density;
568extern const unsigned char Xthal_have_booleans;
569extern const unsigned char Xthal_have_loops;
570extern const unsigned char Xthal_have_nsa;
571extern const unsigned char Xthal_have_minmax;
572extern const unsigned char Xthal_have_sext;
573extern const unsigned char Xthal_have_clamps;
574extern const unsigned char Xthal_have_mac16;
575extern const unsigned char Xthal_have_mul16;
576extern const unsigned char Xthal_have_fp;
577extern const unsigned char Xthal_have_speculation;
578extern const unsigned char Xthal_have_exceptions;
579extern const unsigned char Xthal_xea_version;
580extern const unsigned char Xthal_have_interrupts;
581extern const unsigned char Xthal_have_highlevel_interrupts;
582extern const unsigned char Xthal_have_nmi;
583
584extern const unsigned short Xthal_num_writebuffer_entries;
585
586extern const unsigned int Xthal_build_unique_id;
587/* Release info for hardware targeted by software upgrades: */
588extern const unsigned int Xthal_hw_configid0;
589extern const unsigned int Xthal_hw_configid1;
590extern const unsigned int Xthal_hw_release_major;
591extern const unsigned int Xthal_hw_release_minor;
592extern const char * const Xthal_hw_release_name;
593extern const char * const Xthal_hw_release_internal;
594
595
596/* Internal memories... */
597
598extern const unsigned char Xthal_num_instrom;
599extern const unsigned char Xthal_num_instram;
600extern const unsigned char Xthal_num_datarom;
601extern const unsigned char Xthal_num_dataram;
602extern const unsigned char Xthal_num_xlmi;
603extern const unsigned int Xthal_instrom_vaddr[1];
604extern const unsigned int Xthal_instrom_paddr[1];
605extern const unsigned int Xthal_instrom_size [1];
606extern const unsigned int Xthal_instram_vaddr[1];
607extern const unsigned int Xthal_instram_paddr[1];
608extern const unsigned int Xthal_instram_size [1];
609extern const unsigned int Xthal_datarom_vaddr[1];
610extern const unsigned int Xthal_datarom_paddr[1];
611extern const unsigned int Xthal_datarom_size [1];
612extern const unsigned int Xthal_dataram_vaddr[1];
613extern const unsigned int Xthal_dataram_paddr[1];
614extern const unsigned int Xthal_dataram_size [1];
615extern const unsigned int Xthal_xlmi_vaddr[1];
616extern const unsigned int Xthal_xlmi_paddr[1];
617extern const unsigned int Xthal_xlmi_size [1];
618
619
620
621/*----------------------------------------------------------------------
622 Memory Management Unit
623 ----------------------------------------------------------------------*/
624
625extern const unsigned char Xthal_have_spanning_way;
626extern const unsigned char Xthal_have_identity_map;
627extern const unsigned char Xthal_have_mimic_cacheattr;
628extern const unsigned char Xthal_have_xlt_cacheattr;
629extern const unsigned char Xthal_have_cacheattr;
630extern const unsigned char Xthal_have_tlbs;
631
632extern const unsigned char Xthal_mmu_asid_bits; /* 0 .. 8 */
633extern const unsigned char Xthal_mmu_asid_kernel;
634extern const unsigned char Xthal_mmu_rings; /* 1 .. 4 (perhaps 0 if no MMU and/or no protection?) */
635extern const unsigned char Xthal_mmu_ring_bits;
636extern const unsigned char Xthal_mmu_sr_bits;
637extern const unsigned char Xthal_mmu_ca_bits;
638extern const unsigned int Xthal_mmu_max_pte_page_size;
639extern const unsigned int Xthal_mmu_min_pte_page_size;
640
641extern const unsigned char Xthal_itlb_way_bits;
642extern const unsigned char Xthal_itlb_ways;
643extern const unsigned char Xthal_itlb_arf_ways;
644extern const unsigned char Xthal_dtlb_way_bits;
645extern const unsigned char Xthal_dtlb_ways;
646extern const unsigned char Xthal_dtlb_arf_ways;
647
648/* Convert between virtual and physical addresses (through static maps only): */
649/*** WARNING: these two functions may go away in a future release; don't depend on them! ***/
650extern int xthal_static_v2p( unsigned vaddr, unsigned *paddrp );
651extern int xthal_static_p2v( unsigned paddr, unsigned *vaddrp, unsigned cached );
652
653#if 0
654/******************* EXPERIMENTAL AND TENTATIVE ONLY ********************/
655
656#define XTHAL_MMU_PAGESZ_COUNT_MAX 8 /* maximum number of different page sizes */
657extern const char Xthal_mmu_pagesz_count; /* 0 .. 8 number of different page sizes configured */
658
659/* Note: the following table doesn't necessarily have page sizes in increasing order: */
660extern const char Xthal_mmu_pagesz_log2[XTHAL_MMU_PAGESZ_COUNT_MAX]; /* 10 .. 28 (0 past count) */
661
662/* Sorted (increasing) table of page sizes, that indexes into the above table: */
663extern const char Xthal_mmu_pagesz_sorted[XTHAL_MMU_PAGESZ_COUNT_MAX]; /* 0 .. 7 (0 past count) */
664
665/*u32 Xthal_virtual_exceptions;*/ /* bitmask of which exceptions execute in virtual mode... */
666
667extern const char Xthal_mmu_pte_pagesz_log2_min; /* ?? minimum page size in PTEs */
668extern const char Xthal_mmu_pte_pagesz_log2_max; /* ?? maximum page size in PTEs */
669
670/* Cache Attribute Bits Implemented by the Cache (part of the cache abstraction) */
671extern const char Xthal_icache_fca_bits_implemented; /* ITLB/UTLB only! */
672extern const char Xthal_dcache_lca_bits_implemented; /* DTLB/UTLB only! */
673extern const char Xthal_dcache_sca_bits_implemented; /* DTLB/UTLB only! */
674
675/* Per TLB Parameters (Instruction, Data, Unified) */
676struct XtHalMmuTlb Xthal_itlb; /* description of MMU I-TLB generic features */
677struct XtHalMmuTlb Xthal_dtlb; /* description of MMU D-TLB generic features */
678struct XtHalMmuTlb Xthal_utlb; /* description of MMU U-TLB generic features */
679
680#define XTHAL_MMU_WAYS_MAX 8 /* maximum number of ways (associativities) for each TLB */
681
682/* Structure for common information described for each possible TLB (instruction, data and unified): */
683typedef struct XtHalMmuTlb {
684 u8 va_bits; /* 32 (number of virtual address bits) */
685 u8 pa_bits; /* 32 (number of physical address bits) */
686 bool tlb_va_indexed; /* 1 (set if TLB is indexed by virtual address) */
687 bool tlb_va_tagged; /* 0 (set if TLB is tagged by virtual address) */
688 bool cache_va_indexed; /* 1 (set if cache is indexed by virtual address) */
689 bool cache_va_tagged; /* 0 (set if cache is tagged by virtual address) */
690 /*bool (whether page tables are traversed in vaddr sorted order, paddr sorted order, ...) */
691 /*u8 (set of available page attribute bits, other than cache attribute bits defined above) */
692 /*u32 (various masks for pages, MMU table/TLB entries, etc.) */
693 u8 way_count; /* 0 .. 8 (number of ways, a.k.a. associativities, for this TLB) */
694 XtHalMmuTlbWay * ways[XTHAL_MMU_WAYS_MAX]; /* pointers to per-way parms for each way */
695} XtHalMmuTlb;
696
697/* Per TLB Way (Per Associativity) Parameters */
698typedef struct XtHalMmuTlbWay {
699 u32 index_count_log2; /* 0 .. 4 */
700 u32 pagesz_mask; /* 0 .. 2^pagesz_count - 1 (each bit corresponds to a size */
701 /* defined in the Xthal_mmu_pagesz_log2[] table) */
702 u32 vpn_const_mask;
703 u32 vpn_const_value;
704 u64 ppn_const_mask; /* future may support pa_bits > 32 */
705 u64 ppn_const_value;
706 u32 ppn_id_mask; /* paddr bits taken directly from vaddr */
707 bool backgnd_match; /* 0 or 1 */
708 /* These are defined in terms of the XTHAL_CACHE_xxx bits: */
709 u8 fca_const_mask; /* ITLB/UTLB only! */
710 u8 fca_const_value; /* ITLB/UTLB only! */
711 u8 lca_const_mask; /* DTLB/UTLB only! */
712 u8 lca_const_value; /* DTLB/UTLB only! */
713 u8 sca_const_mask; /* DTLB/UTLB only! */
714 u8 sca_const_value; /* DTLB/UTLB only! */
715 /* These define an encoding that map 5 bits in TLB and PTE entries to */
716 /* 8 bits (FCA, ITLB), 16 bits (LCA+SCA, DTLB) or 24 bits (FCA+LCA+SCA, UTLB): */
717 /* (they may be moved to struct XtHalMmuTlb) */
718 u8 ca_bits; /* number of bits in TLB/PTE entries for cache attributes */
719 u32 * ca_map; /* pointer to array of 2^ca_bits entries of FCA+LCA+SCA bits */
720} XtHalMmuTlbWay;
721
722/*
723 * The way to determine whether protection support is present in core
724 * is to [look at Xthal_mmu_rings ???].
725 * Give info on memory requirements for MMU tables and other in-memory
726 * data structures (globally, per task, base and per page, etc.) - whatever bounds can be calculated.
727 */
728
729
730/* Default vectors: */
731xthal_immu_fetch_miss_vector
732xthal_dmmu_load_miss_vector
733xthal_dmmu_store_miss_vector
734
735/* Functions called when a fault is detected: */
736typedef void (XtHalMmuFaultFunc)( unsigned vaddr, ...context... );
737/* Or, */
738/* a? = vaddr */
739/* a? = context... */
740/* PS.xxx = xxx */
741XtHalMMuFaultFunc *Xthal_immu_fetch_fault_func;
742XtHalMMuFaultFunc *Xthal_dmmu_load_fault_func;
743XtHalMMuFaultFunc *Xthal_dmmu_store_fault_func;
744
745/* Default Handlers: */
746/* The user and/or kernel exception handlers may jump to these handlers to handle the relevant exceptions,
747 * according to the value of EXCCAUSE. The exact register state on entry to these handlers is TBD. */
748/* When multiple TLB entries match (hit) on the same access: */
749xthal_immu_fetch_multihit_handler
750xthal_dmmu_load_multihit_handler
751xthal_dmmu_store_multihit_handler
752/* Protection violations according to cache attributes, and other cache attribute mismatches: */
753xthal_immu_fetch_attr_handler
754xthal_dmmu_load_attr_handler
755xthal_dmmu_store_attr_handler
756/* Protection violations due to insufficient ring level: */
757xthal_immu_fetch_priv_handler
758xthal_dmmu_load_priv_handler
759xthal_dmmu_store_priv_handler
760/* Alignment exception handlers (if supported by the particular Xtensa MMU configuration): */
761xthal_dmmu_load_align_handler
762xthal_dmmu_store_align_handler
763
764/* Or, alternatively, the OS user and/or kernel exception handlers may simply jump to the
765 * following entry points which will handle any values of EXCCAUSE not handled by the OS: */
766xthal_user_exc_default_handler
767xthal_kernel_exc_default_handler
768
769#endif /*0*/
770
771#ifdef INCLUDE_DEPRECATED_HAL_CODE
772extern const unsigned char Xthal_have_old_exc_arch;
773extern const unsigned char Xthal_have_mmu;
774extern const unsigned int Xthal_num_regs;
775extern const unsigned char Xthal_num_iroms;
776extern const unsigned char Xthal_num_irams;
777extern const unsigned char Xthal_num_droms;
778extern const unsigned char Xthal_num_drams;
779extern const unsigned int Xthal_configid0;
780extern const unsigned int Xthal_configid1;
781#endif
782
783#ifdef INCLUDE_DEPRECATED_HAL_DEBUG_CODE
784#define XTHAL_24_BIT_BREAK 0x80000000
785#define XTHAL_16_BIT_BREAK 0x40000000
786extern const unsigned short Xthal_ill_inst_16[16];
787#define XTHAL_DEST_REG 0xf0000000 /* Mask for destination register */
788#define XTHAL_DEST_REG_INST 0x08000000 /* Branch address is in register */
789#define XTHAL_DEST_REL_INST 0x04000000 /* Branch address is relative */
790#define XTHAL_RFW_INST 0x00000800
791#define XTHAL_RFUE_INST 0x00000400
792#define XTHAL_RFI_INST 0x00000200
793#define XTHAL_RFE_INST 0x00000100
794#define XTHAL_RET_INST 0x00000080
795#define XTHAL_BREAK_INST 0x00000040
796#define XTHAL_SYSCALL_INST 0x00000020
797#define XTHAL_LOOP_END 0x00000010 /* Not set by xthal_inst_type */
798#define XTHAL_JUMP_INST 0x00000008 /* Call or jump instruction */
799#define XTHAL_BRANCH_INST 0x00000004 /* Branch instruction */
800#define XTHAL_24_BIT_INST 0x00000002
801#define XTHAL_16_BIT_INST 0x00000001
802typedef struct xthal_state {
803 unsigned pc;
804 unsigned ar[16];
805 unsigned lbeg;
806 unsigned lend;
807 unsigned lcount;
808 unsigned extra_ptr;
809 unsigned cpregs_ptr[XTHAL_MAX_CPS];
810} XTHAL_STATE;
811extern unsigned int xthal_inst_type(void *addr);
812extern unsigned int xthal_branch_addr(void *addr);
813extern unsigned int xthal_get_npc(XTHAL_STATE *user_state);
814#endif /* INCLUDE_DEPRECATED_HAL_DEBUG_CODE */
815
816#ifdef __cplusplus
817}
818#endif
819#endif /*!__ASSEMBLY__ */
820
821#endif /*XTENSA_HAL_H*/
822
diff --git a/include/asm-xtensa/xtensa/simcall.h b/include/asm-xtensa/xtensa/simcall.h
deleted file mode 100644
index a2b868929a49..000000000000
--- a/include/asm-xtensa/xtensa/simcall.h
+++ /dev/null
@@ -1,130 +0,0 @@
1#ifndef SIMCALL_INCLUDED
2#define SIMCALL_INCLUDED
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/simcall.h - Simulator call numbers
8 *
9 * This file is subject to the terms and conditions of the GNU General
10 * Public License. See the file "COPYING" in the main directory of
11 * this archive for more details.
12 *
13 * Copyright (C) 2002 Tensilica Inc.
14 */
15
16
17/*
18 * System call like services offered by the simulator host.
19 * These are modeled after the Linux 2.4 kernel system calls
20 * for Xtensa processors. However not all system calls and
21 * not all functionality of a given system call are implemented,
22 * or necessarily have well defined or equivalent semantics in
23 * the context of a simulation (as opposed to a Unix kernel).
24 *
25 * These services behave largely as if they had been invoked
26 * as a task in the simulator host's operating system
27 * (eg. files accessed are those of the simulator host).
28 * However, these SIMCALLs model a virtual operating system
29 * so that various definitions, bit assignments etc
30 * (eg. open mode bits, errno values, etc) are independent
31 * of the host operating system used to run the simulation.
32 * Rather these definitions are specific to the Xtensa ISS.
33 * This way Xtensa ISA code written to use these SIMCALLs
34 * can (in principle) be simulated on any host.
35 *
36 * Up to 6 parameters are passed in registers a3 to a8
37 * (note the 6th parameter isn't passed on the stack,
38 * unlike windowed function calling conventions).
39 * The return value is in a2. A negative value in the
40 * range -4096 to -1 indicates a negated error code to be
41 * reported in errno with a return value of -1, otherwise
42 * the value in a2 is returned as is.
43 */
44
45/* These #defines need to match what's in Xtensa/OS/vxworks/xtiss/simcalls.c */
46
47#define SYS_nop 0 /* n/a - setup; used to flush register windows */
48#define SYS_exit 1 /*x*/
49#define SYS_fork 2
50#define SYS_read 3 /*x*/
51#define SYS_write 4 /*x*/
52#define SYS_open 5 /*x*/
53#define SYS_close 6 /*x*/
54#define SYS_rename 7 /*x 38 - waitpid */
55#define SYS_creat 8 /*x*/
56#define SYS_link 9 /*x (not implemented on WIN32) */
57#define SYS_unlink 10 /*x*/
58#define SYS_execv 11 /* n/a - execve */
59#define SYS_execve 12 /* 11 - chdir */
60#define SYS_pipe 13 /* 42 - time */
61#define SYS_stat 14 /* 106 - mknod */
62#define SYS_chmod 15
63#define SYS_chown 16 /* 202 - lchown */
64#define SYS_utime 17 /* 30 - break */
65#define SYS_wait 18 /* n/a - oldstat */
66#define SYS_lseek 19 /*x*/
67#define SYS_getpid 20
68#define SYS_isatty 21 /* n/a - mount */
69#define SYS_fstat 22 /* 108 - oldumount */
70#define SYS_time 23 /* 13 - setuid */
71#define SYS_gettimeofday 24 /*x 78 - getuid (not implemented on WIN32) */
72#define SYS_times 25 /*X 43 - stime (Xtensa-specific implementation) */
73#define SYS_socket 26
74#define SYS_sendto 27
75#define SYS_recvfrom 28
76#define SYS_select_one 29 /* not compitible select, one file descriptor at the time */
77#define SYS_bind 30
78#define SYS_ioctl 31
79
80/*
81 * Other...
82 */
83#define SYS_iss_argc 1000 /* returns value of argc */
84#define SYS_iss_argv_size 1001 /* bytes needed for argv & arg strings */
85#define SYS_iss_set_argv 1002 /* saves argv & arg strings at given addr */
86
87/*
88 * SIMCALLs for the ferret memory debugger. All are invoked by
89 * libferret.a ... ( Xtensa/Target-Libs/ferret )
90 */
91#define SYS_ferret 1010
92#define SYS_malloc 1011
93#define SYS_free 1012
94#define SYS_more_heap 1013
95#define SYS_no_heap 1014
96
97
98/*
99 * Extra SIMCALLs for GDB:
100 */
101#define SYS_gdb_break -1 /* invoked by XTOS on user exceptions if EPC points
102 to a break.n/break, regardless of cause! */
103#define SYS_xmon_out -2 /* invoked by XMON: ... */
104#define SYS_xmon_in -3 /* invoked by XMON: ... */
105#define SYS_xmon_flush -4 /* invoked by XMON: ... */
106#define SYS_gdb_abort -5 /* invoked by XTOS in _xtos_panic() */
107#define SYS_gdb_illegal_inst -6 /* invoked by XTOS for illegal instructions (too deeply) */
108#define SYS_xmon_init -7 /* invoked by XMON: ... */
109#define SYS_gdb_enter_sktloop -8 /* invoked by XTOS on debug exceptions */
110
111/*
112 * SIMCALLs for vxWorks xtiss BSP:
113 */
114#define SYS_setup_ppp_pipes -83
115#define SYS_log_msg -84
116
117/*
118 * Test SIMCALLs:
119 */
120#define SYS_test_write_state -100
121#define SYS_test_read_state -101
122
123/*
124 * SYS_select_one specifiers
125 */
126#define XTISS_SELECT_ONE_READ 1
127#define XTISS_SELECT_ONE_WRITE 2
128#define XTISS_SELECT_ONE_EXCEPT 3
129
130#endif /* !SIMCALL_INCLUDED */
diff --git a/include/asm-xtensa/xtensa/xt2000-uart.h b/include/asm-xtensa/xtensa/xt2000-uart.h
deleted file mode 100644
index 0154460f0ed8..000000000000
--- a/include/asm-xtensa/xtensa/xt2000-uart.h
+++ /dev/null
@@ -1,155 +0,0 @@
1#ifndef _uart_h_included_
2#define _uart_h_included_
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/xt2000-uart.h -- NatSemi PC16552D DUART
8 * definitions
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 *
14 * Copyright (C) 2002 Tensilica Inc.
15 */
16
17
18#include <xtensa/xt2000.h>
19
20
21/* 16550 UART DEVICE REGISTERS
22 The XT2000 board aligns each register to a 32-bit word but the UART device only uses
23 one byte of the word, which is the least-significant byte regardless of the
24 endianness of the core (ie. byte offset 0 for little-endian and 3 for big-endian).
25 So if using word accesses then endianness doesn't matter.
26 The macros provided here do that.
27*/
28struct uart_dev_s {
29 union {
30 unsigned int rxb; /* DLAB=0: receive buffer, read-only */
31 unsigned int txb; /* DLAB=0: transmit buffer, write-only */
32 unsigned int dll; /* DLAB=1: divisor, least-significant byte latch (was write-only?) */
33 } w0;
34 union {
35 unsigned int ier; /* DLAB=0: interrupt-enable register (was write-only?) */
36 unsigned int dlm; /* DLAB=1: divisor, most-significant byte latch (was write-only?) */
37 } w1;
38
39 union {
40 unsigned int isr; /* DLAB=0: interrupt status register, read-only */
41 unsigned int fcr; /* DLAB=0: FIFO control register, write-only */
42 unsigned int afr; /* DLAB=1: alternate function register */
43 } w2;
44
45 unsigned int lcr; /* line control-register, write-only */
46 unsigned int mcr; /* modem control-regsiter, write-only */
47 unsigned int lsr; /* line status register, read-only */
48 unsigned int msr; /* modem status register, read-only */
49 unsigned int scr; /* scratch regsiter, read/write */
50};
51
52#define _RXB(u) ((u)->w0.rxb)
53#define _TXB(u) ((u)->w0.txb)
54#define _DLL(u) ((u)->w0.dll)
55#define _IER(u) ((u)->w1.ier)
56#define _DLM(u) ((u)->w1.dlm)
57#define _ISR(u) ((u)->w2.isr)
58#define _FCR(u) ((u)->w2.fcr)
59#define _AFR(u) ((u)->w2.afr)
60#define _LCR(u) ((u)->lcr)
61#define _MCR(u) ((u)->mcr)
62#define _LSR(u) ((u)->lsr)
63#define _MSR(u) ((u)->msr)
64#define _SCR(u) ((u)->scr)
65
66typedef volatile struct uart_dev_s uart_dev_t;
67
68/* IER bits */
69#define RCVR_DATA_REG_INTENABLE 0x01
70#define XMIT_HOLD_REG_INTENABLE 0x02
71#define RCVR_STATUS_INTENABLE 0x04
72#define MODEM_STATUS_INTENABLE 0x08
73
74/* FCR bits */
75#define _FIFO_ENABLE 0x01
76#define RCVR_FIFO_RESET 0x02
77#define XMIT_FIFO_RESET 0x04
78#define DMA_MODE_SELECT 0x08
79#define RCVR_TRIGGER_LSB 0x40
80#define RCVR_TRIGGER_MSB 0x80
81
82/* AFR bits */
83#define AFR_CONC_WRITE 0x01
84#define AFR_BAUDOUT_SEL 0x02
85#define AFR_RXRDY_SEL 0x04
86
87/* ISR bits */
88#define INT_STATUS(r) ((r)&1)
89#define INT_PRIORITY(r) (((r)>>1)&0x7)
90
91/* LCR bits */
92#define WORD_LENGTH(n) (((n)-5)&0x3)
93#define STOP_BIT_ENABLE 0x04
94#define PARITY_ENABLE 0x08
95#define EVEN_PARITY 0x10
96#define FORCE_PARITY 0x20
97#define XMIT_BREAK 0x40
98#define DLAB_ENABLE 0x80
99
100/* MCR bits */
101#define _DTR 0x01
102#define _RTS 0x02
103#define _OP1 0x04
104#define _OP2 0x08
105#define LOOP_BACK 0x10
106
107/* LSR Bits */
108#define RCVR_DATA_READY 0x01
109#define OVERRUN_ERROR 0x02
110#define PARITY_ERROR 0x04
111#define FRAMING_ERROR 0x08
112#define BREAK_INTERRUPT 0x10
113#define XMIT_HOLD_EMPTY 0x20
114#define XMIT_EMPTY 0x40
115#define FIFO_ERROR 0x80
116#define RCVR_READY(u) (_LSR(u)&RCVR_DATA_READY)
117#define XMIT_READY(u) (_LSR(u)&XMIT_HOLD_EMPTY)
118
119/* MSR bits */
120#define _RDR 0x01
121#define DELTA_DSR 0x02
122#define DELTA_RI 0x04
123#define DELTA_CD 0x08
124#define _CTS 0x10
125#define _DSR 0x20
126#define _RI 0x40
127#define _CD 0x80
128
129/* prototypes */
130void uart_init( uart_dev_t *u, int bitrate );
131void uart_out( uart_dev_t *u, char c );
132void uart_puts( uart_dev_t *u, char *s );
133char uart_in( uart_dev_t *u );
134void uart_enable_rcvr_int( uart_dev_t *u );
135void uart_disable_rcvr_int( uart_dev_t *u );
136
137#ifdef DUART16552_1_VADDR
138/* DUART present. */
139#define DUART_1_BASE (*(uart_dev_t*)DUART16552_1_VADDR)
140#define DUART_2_BASE (*(uart_dev_t*)DUART16552_2_VADDR)
141#define UART1_PUTS(s) uart_puts( &DUART_1_BASE, s )
142#define UART2_PUTS(s) uart_puts( &DUART_2_BASE, s )
143#else
144/* DUART not configured, use dummy placeholders to allow compiles to work. */
145#define DUART_1_BASE (*(uart_dev_t*)0)
146#define DUART_2_BASE (*(uart_dev_t*)0)
147#define UART1_PUTS(s)
148#define UART2_PUTS(s)
149#endif
150
151/* Compute 16-bit divisor for baudrate generator, with rounding: */
152#define DUART_DIVISOR(crystal,speed) (((crystal)/16 + (speed)/2)/(speed))
153
154#endif /*_uart_h_included_*/
155
diff --git a/include/asm-xtensa/xtensa/xt2000.h b/include/asm-xtensa/xtensa/xt2000.h
deleted file mode 100644
index 703a45002f8f..000000000000
--- a/include/asm-xtensa/xtensa/xt2000.h
+++ /dev/null
@@ -1,408 +0,0 @@
1#ifndef _INC_XT2000_H_
2#define _INC_XT2000_H_
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * include/asm-xtensa/xtensa/xt2000.h - Definitions specific to the
8 * Tensilica XT2000 Emulation Board
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 *
14 * Copyright (C) 2002 Tensilica Inc.
15 */
16
17
18#include <xtensa/config/core.h>
19#include <xtensa/config/system.h>
20
21
22/*
23 * Default assignment of XT2000 devices to external interrupts.
24 */
25
26/* Ethernet interrupt: */
27#ifdef XCHAL_EXTINT3_NUM
28#define SONIC83934_INTNUM XCHAL_EXTINT3_NUM
29#define SONIC83934_INTLEVEL XCHAL_EXTINT3_LEVEL
30#define SONIC83934_INTMASK XCHAL_EXTINT3_MASK
31#else
32#define SONIC83934_INTMASK 0
33#endif
34
35/* DUART channel 1 interrupt (P1 - console): */
36#ifdef XCHAL_EXTINT4_NUM
37#define DUART16552_1_INTNUM XCHAL_EXTINT4_NUM
38#define DUART16552_1_INTLEVEL XCHAL_EXTINT4_LEVEL
39#define DUART16552_1_INTMASK XCHAL_EXTINT4_MASK
40#else
41#define DUART16552_1_INTMASK 0
42#endif
43
44/* DUART channel 2 interrupt (P2 - 2nd serial port): */
45#ifdef XCHAL_EXTINT5_NUM
46#define DUART16552_2_INTNUM XCHAL_EXTINT5_NUM
47#define DUART16552_2_INTLEVEL XCHAL_EXTINT5_LEVEL
48#define DUART16552_2_INTMASK XCHAL_EXTINT5_MASK
49#else
50#define DUART16552_2_INTMASK 0
51#endif
52
53/* FPGA-combined PCI/etc interrupts: */
54#ifdef XCHAL_EXTINT6_NUM
55#define XT2000_FPGAPCI_INTNUM XCHAL_EXTINT6_NUM
56#define XT2000_FPGAPCI_INTLEVEL XCHAL_EXTINT6_LEVEL
57#define XT2000_FPGAPCI_INTMASK XCHAL_EXTINT6_MASK
58#else
59#define XT2000_FPGAPCI_INTMASK 0
60#endif
61
62
63
64/*
65 * Device addresses.
66 *
67 * Note: for endianness-independence, use 32-bit loads and stores for all
68 * register accesses to Ethernet, DUART and LED devices. Undefined bits
69 * may need to be masked out if needed when reading if the actual register
70 * size is smaller than 32 bits.
71 *
72 * Note: XT2000 bus byte lanes are defined in terms of msbyte and lsbyte
73 * relative to the processor. So 32-bit registers are accessed consistently
74 * from both big and little endian processors. However, this means byte
75 * sequences are not consistent between big and little endian processors.
76 * This is fine for RAM, and for ROM if ROM is created for a specific
77 * processor (and thus has correct byte sequences). However this may be
78 * unexpected for Flash, which might contain a file-system that one wants
79 * to use for multiple processor configurations (eg. the Flash might contain
80 * the Ethernet card's address, endianness-independent application data, etc).
81 * That is, byte sequences written in Flash by a core of a given endianness
82 * will be byte-swapped when seen by a core of the other endianness.
83 * Someone implementing an endianness-independent Flash file system will
84 * likely handle this byte-swapping issue in the Flash driver software.
85 */
86
87#define DUART16552_XTAL_FREQ 18432000 /* crystal frequency in Hz */
88#define XTBOARD_FLASH_MAXSIZE 0x4000000 /* 64 MB (max; depends on what is socketed!) */
89#define XTBOARD_EPROM_MAXSIZE 0x0400000 /* 4 MB (max; depends on what is socketed!) */
90#define XTBOARD_EEPROM_MAXSIZE 0x0080000 /* 512 kB (max; depends on what is socketed!) */
91#define XTBOARD_ASRAM_SIZE 0x0100000 /* 1 MB */
92#define XTBOARD_PCI_MEM_SIZE 0x8000000 /* 128 MB (allocated) */
93#define XTBOARD_PCI_IO_SIZE 0x1000000 /* 16 MB (allocated) */
94
95#ifdef XSHAL_IOBLOCK_BYPASS_PADDR
96/* PCI memory space: */
97# define XTBOARD_PCI_MEM_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0x0000000)
98/* Socketed Flash (eg. 2 x 16-bit devices): */
99# define XTBOARD_FLASH_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0x8000000)
100/* PCI I/O space: */
101# define XTBOARD_PCI_IO_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xC000000)
102/* V3 PCI interface chip register/config space: */
103# define XTBOARD_V3PCI_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD000000)
104/* Bus Interface registers: */
105# define XTBOARD_BUSINT_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD010000)
106/* FPGA registers: */
107# define XT2000_FPGAREGS_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD020000)
108/* SONIC SN83934 Ethernet controller/transceiver: */
109# define SONIC83934_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD030000)
110/* 8-character bitmapped LED display: */
111# define XTBOARD_LED_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD040000)
112/* National-Semi PC16552D DUART: */
113# define DUART16552_1_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD050020) /* channel 1 (P1 - console) */
114# define DUART16552_2_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD050000) /* channel 2 (P2) */
115/* Asynchronous Static RAM: */
116# define XTBOARD_ASRAM_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD400000)
117/* 8-bit EEPROM: */
118# define XTBOARD_EEPROM_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD600000)
119/* 2 x 16-bit EPROMs: */
120# define XTBOARD_EPROM_PADDR (XSHAL_IOBLOCK_BYPASS_PADDR+0xD800000)
121#endif /* XSHAL_IOBLOCK_BYPASS_PADDR */
122
123/* These devices might be accessed cached: */
124#ifdef XSHAL_IOBLOCK_CACHED_PADDR
125# define XTBOARD_PCI_MEM_CACHED_PADDR (XSHAL_IOBLOCK_CACHED_PADDR+0x0000000)
126# define XTBOARD_FLASH_CACHED_PADDR (XSHAL_IOBLOCK_CACHED_PADDR+0x8000000)
127# define XTBOARD_ASRAM_CACHED_PADDR (XSHAL_IOBLOCK_CACHED_PADDR+0xD400000)
128# define XTBOARD_EEPROM_CACHED_PADDR (XSHAL_IOBLOCK_CACHED_PADDR+0xD600000)
129# define XTBOARD_EPROM_CACHED_PADDR (XSHAL_IOBLOCK_CACHED_PADDR+0xD800000)
130#endif /* XSHAL_IOBLOCK_CACHED_PADDR */
131
132
133/*** Same thing over again, this time with virtual addresses: ***/
134
135#ifdef XSHAL_IOBLOCK_BYPASS_VADDR
136/* PCI memory space: */
137# define XTBOARD_PCI_MEM_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0x0000000)
138/* Socketed Flash (eg. 2 x 16-bit devices): */
139# define XTBOARD_FLASH_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0x8000000)
140/* PCI I/O space: */
141# define XTBOARD_PCI_IO_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xC000000)
142/* V3 PCI interface chip register/config space: */
143# define XTBOARD_V3PCI_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD000000)
144/* Bus Interface registers: */
145# define XTBOARD_BUSINT_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD010000)
146/* FPGA registers: */
147# define XT2000_FPGAREGS_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD020000)
148/* SONIC SN83934 Ethernet controller/transceiver: */
149# define SONIC83934_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD030000)
150/* 8-character bitmapped LED display: */
151# define XTBOARD_LED_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD040000)
152/* National-Semi PC16552D DUART: */
153# define DUART16552_1_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD050020) /* channel 1 (P1 - console) */
154# define DUART16552_2_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD050000) /* channel 2 (P2) */
155/* Asynchronous Static RAM: */
156# define XTBOARD_ASRAM_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD400000)
157/* 8-bit EEPROM: */
158# define XTBOARD_EEPROM_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD600000)
159/* 2 x 16-bit EPROMs: */
160# define XTBOARD_EPROM_VADDR (XSHAL_IOBLOCK_BYPASS_VADDR+0xD800000)
161#endif /* XSHAL_IOBLOCK_BYPASS_VADDR */
162
163/* These devices might be accessed cached: */
164#ifdef XSHAL_IOBLOCK_CACHED_VADDR
165# define XTBOARD_PCI_MEM_CACHED_VADDR (XSHAL_IOBLOCK_CACHED_VADDR+0x0000000)
166# define XTBOARD_FLASH_CACHED_VADDR (XSHAL_IOBLOCK_CACHED_VADDR+0x8000000)
167# define XTBOARD_ASRAM_CACHED_VADDR (XSHAL_IOBLOCK_CACHED_VADDR+0xD400000)
168# define XTBOARD_EEPROM_CACHED_VADDR (XSHAL_IOBLOCK_CACHED_VADDR+0xD600000)
169# define XTBOARD_EPROM_CACHED_VADDR (XSHAL_IOBLOCK_CACHED_VADDR+0xD800000)
170#endif /* XSHAL_IOBLOCK_CACHED_VADDR */
171
172
173/* System ROM: */
174#define XTBOARD_ROM_SIZE XSHAL_ROM_SIZE
175#ifdef XSHAL_ROM_VADDR
176#define XTBOARD_ROM_VADDR XSHAL_ROM_VADDR
177#endif
178#ifdef XSHAL_ROM_PADDR
179#define XTBOARD_ROM_PADDR XSHAL_ROM_PADDR
180#endif
181
182/* System RAM: */
183#define XTBOARD_RAM_SIZE XSHAL_RAM_SIZE
184#ifdef XSHAL_RAM_VADDR
185#define XTBOARD_RAM_VADDR XSHAL_RAM_VADDR
186#endif
187#ifdef XSHAL_RAM_PADDR
188#define XTBOARD_RAM_PADDR XSHAL_RAM_PADDR
189#endif
190#define XTBOARD_RAM_BYPASS_VADDR XSHAL_RAM_BYPASS_VADDR
191#define XTBOARD_RAM_BYPASS_PADDR XSHAL_RAM_BYPASS_PADDR
192
193
194
195/*
196 * Things that depend on device addresses.
197 */
198
199
200#define XTBOARD_CACHEATTR_WRITEBACK XSHAL_XT2000_CACHEATTR_WRITEBACK
201#define XTBOARD_CACHEATTR_WRITEALLOC XSHAL_XT2000_CACHEATTR_WRITEALLOC
202#define XTBOARD_CACHEATTR_WRITETHRU XSHAL_XT2000_CACHEATTR_WRITETHRU
203#define XTBOARD_CACHEATTR_BYPASS XSHAL_XT2000_CACHEATTR_BYPASS
204#define XTBOARD_CACHEATTR_DEFAULT XSHAL_XT2000_CACHEATTR_DEFAULT
205
206#define XTBOARD_BUSINT_PIPE_REGIONS XSHAL_XT2000_PIPE_REGIONS
207#define XTBOARD_BUSINT_SDRAM_REGIONS XSHAL_XT2000_SDRAM_REGIONS
208
209
210
211/*
212 * BusLogic (FPGA) registers.
213 * All these registers are normally accessed using 32-bit loads/stores.
214 */
215
216/* Register offsets: */
217#define XT2000_DATECD_OFS 0x00 /* date code (read-only) */
218#define XT2000_STSREG_OFS 0x04 /* status (read-only) */
219#define XT2000_SYSLED_OFS 0x08 /* system LED */
220#define XT2000_WRPROT_OFS 0x0C /* write protect */
221#define XT2000_SWRST_OFS 0x10 /* software reset */
222#define XT2000_SYSRST_OFS 0x14 /* system (peripherals) reset */
223#define XT2000_IMASK_OFS 0x18 /* interrupt mask */
224#define XT2000_ISTAT_OFS 0x1C /* interrupt status */
225#define XT2000_V3CFG_OFS 0x20 /* V3 config (V320 PCI) */
226
227/* Physical register addresses: */
228#ifdef XT2000_FPGAREGS_PADDR
229#define XT2000_DATECD_PADDR (XT2000_FPGAREGS_PADDR+XT2000_DATECD_OFS)
230#define XT2000_STSREG_PADDR (XT2000_FPGAREGS_PADDR+XT2000_STSREG_OFS)
231#define XT2000_SYSLED_PADDR (XT2000_FPGAREGS_PADDR+XT2000_SYSLED_OFS)
232#define XT2000_WRPROT_PADDR (XT2000_FPGAREGS_PADDR+XT2000_WRPROT_OFS)
233#define XT2000_SWRST_PADDR (XT2000_FPGAREGS_PADDR+XT2000_SWRST_OFS)
234#define XT2000_SYSRST_PADDR (XT2000_FPGAREGS_PADDR+XT2000_SYSRST_OFS)
235#define XT2000_IMASK_PADDR (XT2000_FPGAREGS_PADDR+XT2000_IMASK_OFS)
236#define XT2000_ISTAT_PADDR (XT2000_FPGAREGS_PADDR+XT2000_ISTAT_OFS)
237#define XT2000_V3CFG_PADDR (XT2000_FPGAREGS_PADDR+XT2000_V3CFG_OFS)
238#endif
239
240/* Virtual register addresses: */
241#ifdef XT2000_FPGAREGS_VADDR
242#define XT2000_DATECD_VADDR (XT2000_FPGAREGS_VADDR+XT2000_DATECD_OFS)
243#define XT2000_STSREG_VADDR (XT2000_FPGAREGS_VADDR+XT2000_STSREG_OFS)
244#define XT2000_SYSLED_VADDR (XT2000_FPGAREGS_VADDR+XT2000_SYSLED_OFS)
245#define XT2000_WRPROT_VADDR (XT2000_FPGAREGS_VADDR+XT2000_WRPROT_OFS)
246#define XT2000_SWRST_VADDR (XT2000_FPGAREGS_VADDR+XT2000_SWRST_OFS)
247#define XT2000_SYSRST_VADDR (XT2000_FPGAREGS_VADDR+XT2000_SYSRST_OFS)
248#define XT2000_IMASK_VADDR (XT2000_FPGAREGS_VADDR+XT2000_IMASK_OFS)
249#define XT2000_ISTAT_VADDR (XT2000_FPGAREGS_VADDR+XT2000_ISTAT_OFS)
250#define XT2000_V3CFG_VADDR (XT2000_FPGAREGS_VADDR+XT2000_V3CFG_OFS)
251/* Register access (for C code): */
252#define XT2000_DATECD_REG (*(volatile unsigned*) XT2000_DATECD_VADDR)
253#define XT2000_STSREG_REG (*(volatile unsigned*) XT2000_STSREG_VADDR)
254#define XT2000_SYSLED_REG (*(volatile unsigned*) XT2000_SYSLED_VADDR)
255#define XT2000_WRPROT_REG (*(volatile unsigned*) XT2000_WRPROT_VADDR)
256#define XT2000_SWRST_REG (*(volatile unsigned*) XT2000_SWRST_VADDR)
257#define XT2000_SYSRST_REG (*(volatile unsigned*) XT2000_SYSRST_VADDR)
258#define XT2000_IMASK_REG (*(volatile unsigned*) XT2000_IMASK_VADDR)
259#define XT2000_ISTAT_REG (*(volatile unsigned*) XT2000_ISTAT_VADDR)
260#define XT2000_V3CFG_REG (*(volatile unsigned*) XT2000_V3CFG_VADDR)
261#endif
262
263/* DATECD (date code) bit fields: */
264
265/* BCD-coded month (01..12): */
266#define XT2000_DATECD_MONTH_SHIFT 24
267#define XT2000_DATECD_MONTH_BITS 8
268#define XT2000_DATECD_MONTH_MASK 0xFF000000
269/* BCD-coded day (01..31): */
270#define XT2000_DATECD_DAY_SHIFT 16
271#define XT2000_DATECD_DAY_BITS 8
272#define XT2000_DATECD_DAY_MASK 0x00FF0000
273/* BCD-coded year (2001..9999): */
274#define XT2000_DATECD_YEAR_SHIFT 0
275#define XT2000_DATECD_YEAR_BITS 16
276#define XT2000_DATECD_YEAR_MASK 0x0000FFFF
277
278/* STSREG (status) bit fields: */
279
280/* Switch SW3 setting bit fields (0=off/up, 1=on/down): */
281#define XT2000_STSREG_SW3_SHIFT 0
282#define XT2000_STSREG_SW3_BITS 4
283#define XT2000_STSREG_SW3_MASK 0x0000000F
284/* Boot-select bits of switch SW3: */
285#define XT2000_STSREG_BOOTSEL_SHIFT 0
286#define XT2000_STSREG_BOOTSEL_BITS 2
287#define XT2000_STSREG_BOOTSEL_MASK 0x00000003
288/* Boot-select values: */
289#define XT2000_STSREG_BOOTSEL_FLASH 0
290#define XT2000_STSREG_BOOTSEL_EPROM16 1
291#define XT2000_STSREG_BOOTSEL_PROM8 2
292#define XT2000_STSREG_BOOTSEL_ASRAM 3
293/* User-defined bits of switch SW3: */
294#define XT2000_STSREG_SW3_2_SHIFT 2
295#define XT2000_STSREG_SW3_2_MASK 0x00000004
296#define XT2000_STSREG_SW3_3_SHIFT 3
297#define XT2000_STSREG_SW3_3_MASK 0x00000008
298
299/* SYSLED (system LED) bit fields: */
300
301/* LED control bit (0=off, 1=on): */
302#define XT2000_SYSLED_LEDON_SHIFT 0
303#define XT2000_SYSLED_LEDON_MASK 0x00000001
304
305/* WRPROT (write protect) bit fields (0=writable, 1=write-protected [default]): */
306
307/* Flash write protect: */
308#define XT2000_WRPROT_FLWP_SHIFT 0
309#define XT2000_WRPROT_FLWP_MASK 0x00000001
310/* Reserved but present write protect bits: */
311#define XT2000_WRPROT_WRP_SHIFT 1
312#define XT2000_WRPROT_WRP_BITS 7
313#define XT2000_WRPROT_WRP_MASK 0x000000FE
314
315/* SWRST (software reset; allows s/w to generate power-on equivalent reset): */
316
317/* Software reset bits: */
318#define XT2000_SWRST_SWR_SHIFT 0
319#define XT2000_SWRST_SWR_BITS 16
320#define XT2000_SWRST_SWR_MASK 0x0000FFFF
321/* Software reset value -- writing this value resets the board: */
322#define XT2000_SWRST_RESETVALUE 0x0000DEAD
323
324/* SYSRST (system reset; controls reset of individual peripherals): */
325
326/* All-device reset: */
327#define XT2000_SYSRST_ALL_SHIFT 0
328#define XT2000_SYSRST_ALL_BITS 4
329#define XT2000_SYSRST_ALL_MASK 0x0000000F
330/* HDSP-2534 LED display reset (1=reset, 0=nothing): */
331#define XT2000_SYSRST_LED_SHIFT 0
332#define XT2000_SYSRST_LED_MASK 0x00000001
333/* Sonic DP83934 Ethernet controller reset (1=reset, 0=nothing): */
334#define XT2000_SYSRST_SONIC_SHIFT 1
335#define XT2000_SYSRST_SONIC_MASK 0x00000002
336/* DP16552 DUART reset (1=reset, 0=nothing): */
337#define XT2000_SYSRST_DUART_SHIFT 2
338#define XT2000_SYSRST_DUART_MASK 0x00000004
339/* V3 V320 PCI bridge controller reset (1=reset, 0=nothing): */
340#define XT2000_SYSRST_V3_SHIFT 3
341#define XT2000_SYSRST_V3_MASK 0x00000008
342
343/* IMASK (interrupt mask; 0=disable, 1=enable): */
344/* ISTAT (interrupt status; 0=inactive, 1=pending): */
345
346/* PCI INTP interrupt: */
347#define XT2000_INTMUX_PCI_INTP_SHIFT 2
348#define XT2000_INTMUX_PCI_INTP_MASK 0x00000004
349/* PCI INTS interrupt: */
350#define XT2000_INTMUX_PCI_INTS_SHIFT 3
351#define XT2000_INTMUX_PCI_INTS_MASK 0x00000008
352/* PCI INTD interrupt: */
353#define XT2000_INTMUX_PCI_INTD_SHIFT 4
354#define XT2000_INTMUX_PCI_INTD_MASK 0x00000010
355/* V320 PCI controller interrupt: */
356#define XT2000_INTMUX_V3_SHIFT 5
357#define XT2000_INTMUX_V3_MASK 0x00000020
358/* PCI ENUM interrupt: */
359#define XT2000_INTMUX_PCI_ENUM_SHIFT 6
360#define XT2000_INTMUX_PCI_ENUM_MASK 0x00000040
361/* PCI DEG interrupt: */
362#define XT2000_INTMUX_PCI_DEG_SHIFT 7
363#define XT2000_INTMUX_PCI_DEG_MASK 0x00000080
364
365/* V3CFG (V3 config, V320 PCI controller): */
366
367/* V3 address control (0=pass-thru, 1=V3 address bits 31:28 set to 4'b0001 [default]): */
368#define XT2000_V3CFG_V3ADC_SHIFT 0
369#define XT2000_V3CFG_V3ADC_MASK 0x00000001
370
371/* I2C Devices */
372
373#define XT2000_I2C_RTC_ID 0x68
374#define XT2000_I2C_NVRAM0_ID 0x56 /* 1st 256 byte block */
375#define XT2000_I2C_NVRAM1_ID 0x57 /* 2nd 256 byte block */
376
377/* NVRAM Board Info structure: */
378
379#define XT2000_NVRAM_SIZE 512
380
381#define XT2000_NVRAM_BINFO_START 0x100
382#define XT2000_NVRAM_BINFO_SIZE 0x20
383#define XT2000_NVRAM_BINFO_VERSION 0x10 /* version 1.0 */
384#if 0
385#define XT2000_NVRAM_BINFO_VERSION_OFFSET 0x00
386#define XT2000_NVRAM_BINFO_VERSION_SIZE 0x1
387#define XT2000_NVRAM_BINFO_ETH_ADDR_OFFSET 0x02
388#define XT2000_NVRAM_BINFO_ETH_ADDR_SIZE 0x6
389#define XT2000_NVRAM_BINFO_SN_OFFSET 0x10
390#define XT2000_NVRAM_BINFO_SN_SIZE 0xE
391#define XT2000_NVRAM_BINFO_CRC_OFFSET 0x1E
392#define XT2000_NVRAM_BINFO_CRC_SIZE 0x2
393#endif /*0*/
394
395#if !defined(__ASSEMBLY__) && !defined(_NOCLANGUAGE)
396typedef struct xt2000_nvram_binfo {
397 unsigned char version;
398 unsigned char reserved1;
399 unsigned char eth_addr[6];
400 unsigned char reserved8[8];
401 unsigned char serialno[14];
402 unsigned char crc[2]; /* 16-bit CRC */
403} xt2000_nvram_binfo;
404#endif /*!__ASSEMBLY__ && !_NOCLANGUAGE*/
405
406
407#endif /*_INC_XT2000_H_*/
408
diff --git a/include/asm-xtensa/xtensa/xtboard.h b/include/asm-xtensa/xtensa/xtboard.h
deleted file mode 100644
index 22469c175307..000000000000
--- a/include/asm-xtensa/xtensa/xtboard.h
+++ /dev/null
@@ -1,120 +0,0 @@
1#ifndef _xtboard_h_included_
2#define _xtboard_h_included_
3
4/*
5 * THIS FILE IS GENERATED -- DO NOT MODIFY BY HAND
6 *
7 * xtboard.h -- Routines for getting useful information from the board.
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 *
13 * Copyright (C) 2002 Tensilica Inc.
14 */
15
16
17#include <xtensa/xt2000.h>
18
19#define XTBOARD_RTC_ERROR -1
20#define XTBOARD_RTC_STOPPED -2
21
22
23/* xt2000-i2cdev.c: */
24typedef void XtboardDelayFunc( unsigned );
25extern XtboardDelayFunc* xtboard_set_nsdelay_func( XtboardDelayFunc *delay_fn );
26extern int xtboard_i2c_read (unsigned id, unsigned char *buf, unsigned addr, unsigned size);
27extern int xtboard_i2c_write(unsigned id, unsigned char *buf, unsigned addr, unsigned size);
28extern int xtboard_i2c_wait_nvram_ack(unsigned id, unsigned swtimer);
29
30/* xtboard.c: */
31extern int xtboard_nvram_read (unsigned addr, unsigned len, unsigned char *buf);
32extern int xtboard_nvram_write(unsigned addr, unsigned len, unsigned char *buf);
33extern int xtboard_nvram_binfo_read (xt2000_nvram_binfo *buf);
34extern int xtboard_nvram_binfo_write(xt2000_nvram_binfo *buf);
35extern int xtboard_nvram_binfo_valid(xt2000_nvram_binfo *buf);
36extern int xtboard_ethermac_get(unsigned char *buf);
37extern int xtboard_ethermac_set(unsigned char *buf);
38
39/*+*----------------------------------------------------------------------------
40/ Function: xtboard_get_rtc_time
41/
42/ Description: Get time stored in real-time clock.
43/
44/ Returns: time in seconds stored in real-time clock.
45/-**----------------------------------------------------------------------------*/
46
47extern unsigned xtboard_get_rtc_time(void);
48
49/*+*----------------------------------------------------------------------------
50/ Function: xtboard_set_rtc_time
51/
52/ Description: Set time stored in real-time clock.
53/
54/ Parameters: time -- time in seconds to store to real-time clock
55/
56/ Returns: 0 on success, xtboard_i2c_write() error code otherwise.
57/-**----------------------------------------------------------------------------*/
58
59extern int xtboard_set_rtc_time(unsigned time);
60
61
62/* xtfreq.c: */
63/*+*----------------------------------------------------------------------------
64/ Function: xtboard_measure_sys_clk
65/
66/ Description: Get frequency of system clock.
67/
68/ Parameters: none
69/
70/ Returns: frequency of system clock.
71/-**----------------------------------------------------------------------------*/
72
73extern unsigned xtboard_measure_sys_clk(void);
74
75
76#if 0 /* old stuff from xtboard.c: */
77
78/*+*----------------------------------------------------------------------------
79/ Function: xtboard_nvram valid
80/
81/ Description: Determines if data in NVRAM is valid.
82/
83/ Parameters: delay -- 10us delay function
84/
85/ Returns: 1 if NVRAM is valid, 0 otherwise
86/-**----------------------------------------------------------------------------*/
87
88extern unsigned xtboard_nvram_valid(void (*delay)( void ));
89
90/*+*----------------------------------------------------------------------------
91/ Function: xtboard_get_nvram_contents
92/
93/ Description: Returns contents of NVRAM.
94/
95/ Parameters: buf -- buffer to NVRAM contents.
96/ delay -- 10us delay function
97/
98/ Returns: 1 if NVRAM is valid, 0 otherwise
99/-**----------------------------------------------------------------------------*/
100
101extern unsigned xtboard_get_nvram_contents(unsigned char *buf, void (*delay)( void ));
102
103/*+*----------------------------------------------------------------------------
104/ Function: xtboard_get_ether_addr
105/
106/ Description: Returns ethernet address of board.
107/
108/ Parameters: buf -- buffer to store ethernet address
109/ delay -- 10us delay function
110/
111/ Returns: nothing.
112/-**----------------------------------------------------------------------------*/
113
114extern void xtboard_get_ether_addr(unsigned char *buf, void (*delay)( void ));
115
116#endif /*0*/
117
118
119#endif /*_xtboard_h_included_*/
120
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index e618b25b5add..a1b04d8a1d01 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -61,7 +61,6 @@ header-y += fd.h
61header-y += fdreg.h 61header-y += fdreg.h
62header-y += fib_rules.h 62header-y += fib_rules.h
63header-y += fuse.h 63header-y += fuse.h
64header-y += futex.h
65header-y += genetlink.h 64header-y += genetlink.h
66header-y += gen_stats.h 65header-y += gen_stats.h
67header-y += gigaset_dev.h 66header-y += gigaset_dev.h
@@ -203,6 +202,7 @@ unifdef-y += fb.h
203unifdef-y += fcntl.h 202unifdef-y += fcntl.h
204unifdef-y += filter.h 203unifdef-y += filter.h
205unifdef-y += flat.h 204unifdef-y += flat.h
205unifdef-y += futex.h
206unifdef-y += fs.h 206unifdef-y += fs.h
207unifdef-y += gameport.h 207unifdef-y += gameport.h
208unifdef-y += generic_serial.h 208unifdef-y += generic_serial.h
diff --git a/include/linux/bitrev.h b/include/linux/bitrev.h
new file mode 100644
index 000000000000..05e540d6963a
--- /dev/null
+++ b/include/linux/bitrev.h
@@ -0,0 +1,15 @@
1#ifndef _LINUX_BITREV_H
2#define _LINUX_BITREV_H
3
4#include <linux/types.h>
5
6extern u8 const byte_rev_table[256];
7
8static inline u8 bitrev8(u8 byte)
9{
10 return byte_rev_table[byte];
11}
12
13extern u32 bitrev32(u32 in);
14
15#endif /* _LINUX_BITREV_H */
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index e1c7286165ff..ea330d7b46c0 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -342,7 +342,6 @@ typedef void (unplug_fn) (request_queue_t *);
342 342
343struct bio_vec; 343struct bio_vec;
344typedef int (merge_bvec_fn) (request_queue_t *, struct bio *, struct bio_vec *); 344typedef int (merge_bvec_fn) (request_queue_t *, struct bio *, struct bio_vec *);
345typedef void (activity_fn) (void *data, int rw);
346typedef int (issue_flush_fn) (request_queue_t *, struct gendisk *, sector_t *); 345typedef int (issue_flush_fn) (request_queue_t *, struct gendisk *, sector_t *);
347typedef void (prepare_flush_fn) (request_queue_t *, struct request *); 346typedef void (prepare_flush_fn) (request_queue_t *, struct request *);
348typedef void (softirq_done_fn)(struct request *); 347typedef void (softirq_done_fn)(struct request *);
@@ -384,7 +383,6 @@ struct request_queue
384 prep_rq_fn *prep_rq_fn; 383 prep_rq_fn *prep_rq_fn;
385 unplug_fn *unplug_fn; 384 unplug_fn *unplug_fn;
386 merge_bvec_fn *merge_bvec_fn; 385 merge_bvec_fn *merge_bvec_fn;
387 activity_fn *activity_fn;
388 issue_flush_fn *issue_flush_fn; 386 issue_flush_fn *issue_flush_fn;
389 prepare_flush_fn *prepare_flush_fn; 387 prepare_flush_fn *prepare_flush_fn;
390 softirq_done_fn *softirq_done_fn; 388 softirq_done_fn *softirq_done_fn;
@@ -411,8 +409,6 @@ struct request_queue
411 */ 409 */
412 void *queuedata; 410 void *queuedata;
413 411
414 void *activity_data;
415
416 /* 412 /*
417 * queue needs bounce pages for pages above this limit 413 * queue needs bounce pages for pages above this limit
418 */ 414 */
@@ -677,7 +673,6 @@ extern void blk_sync_queue(struct request_queue *q);
677extern void __blk_stop_queue(request_queue_t *q); 673extern void __blk_stop_queue(request_queue_t *q);
678extern void blk_run_queue(request_queue_t *); 674extern void blk_run_queue(request_queue_t *);
679extern void blk_start_queueing(request_queue_t *); 675extern void blk_start_queueing(request_queue_t *);
680extern void blk_queue_activity_fn(request_queue_t *, activity_fn *, void *);
681extern int blk_rq_map_user(request_queue_t *, struct request *, void __user *, unsigned long); 676extern int blk_rq_map_user(request_queue_t *, struct request *, void __user *, unsigned long);
682extern int blk_rq_unmap_user(struct request *); 677extern int blk_rq_unmap_user(struct request *);
683extern int blk_rq_map_kern(request_queue_t *, struct request *, void *, unsigned int, gfp_t); 678extern int blk_rq_map_kern(request_queue_t *, struct request *, void *, unsigned int, gfp_t);
diff --git a/include/linux/bug.h b/include/linux/bug.h
new file mode 100644
index 000000000000..42aa0a54b6f4
--- /dev/null
+++ b/include/linux/bug.h
@@ -0,0 +1,47 @@
1#ifndef _LINUX_BUG_H
2#define _LINUX_BUG_H
3
4#include <linux/module.h>
5#include <asm/bug.h>
6
7enum bug_trap_type {
8 BUG_TRAP_TYPE_NONE = 0,
9 BUG_TRAP_TYPE_WARN = 1,
10 BUG_TRAP_TYPE_BUG = 2,
11};
12
13#ifdef CONFIG_GENERIC_BUG
14#include <asm-generic/bug.h>
15
16static inline int is_warning_bug(const struct bug_entry *bug)
17{
18 return bug->flags & BUGFLAG_WARNING;
19}
20
21const struct bug_entry *find_bug(unsigned long bugaddr);
22
23enum bug_trap_type report_bug(unsigned long bug_addr);
24
25int module_bug_finalize(const Elf_Ehdr *, const Elf_Shdr *,
26 struct module *);
27void module_bug_cleanup(struct module *);
28
29/* These are defined by the architecture */
30int is_valid_bugaddr(unsigned long addr);
31
32#else /* !CONFIG_GENERIC_BUG */
33
34static inline enum bug_trap_type report_bug(unsigned long bug_addr)
35{
36 return BUG_TRAP_TYPE_BUG;
37}
38static inline int module_bug_finalize(const Elf_Ehdr *hdr,
39 const Elf_Shdr *sechdrs,
40 struct module *mod)
41{
42 return 0;
43}
44static inline void module_bug_cleanup(struct module *mod) {}
45
46#endif /* CONFIG_GENERIC_BUG */
47#endif /* _LINUX_BUG_H */
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index d852024ed095..1622d23a8dc3 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -159,7 +159,7 @@ static inline s64 cyc2ns(struct clocksource *cs, cycle_t cycles)
159 * Unless you're the timekeeping code, you should not be using this! 159 * Unless you're the timekeeping code, you should not be using this!
160 */ 160 */
161static inline void clocksource_calculate_interval(struct clocksource *c, 161static inline void clocksource_calculate_interval(struct clocksource *c,
162 unsigned long length_nsec) 162 unsigned long length_nsec)
163{ 163{
164 u64 tmp; 164 u64 tmp;
165 165
diff --git a/include/linux/crc32.h b/include/linux/crc32.h
index 56c0645789a9..e20dd1f9b40a 100644
--- a/include/linux/crc32.h
+++ b/include/linux/crc32.h
@@ -6,10 +6,10 @@
6#define _LINUX_CRC32_H 6#define _LINUX_CRC32_H
7 7
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/bitrev.h>
9 10
10extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len); 11extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len);
11extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len); 12extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len);
12extern u32 bitreverse(u32 in);
13 13
14#define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length) 14#define crc32(seed, data, length) crc32_le(seed, (unsigned char const *)data, length)
15 15
@@ -21,7 +21,7 @@ extern u32 bitreverse(u32 in);
21 * is in bit nr 0], thus it must be reversed before use. Except for 21 * is in bit nr 0], thus it must be reversed before use. Except for
22 * nics that bit swap the result internally... 22 * nics that bit swap the result internally...
23 */ 23 */
24#define ether_crc(length, data) bitreverse(crc32_le(~0, data, length)) 24#define ether_crc(length, data) bitrev32(crc32_le(~0, data, length))
25#define ether_crc_le(length, data) crc32_le(~0, data, length) 25#define ether_crc_le(length, data) crc32_le(~0, data, length)
26 26
27#endif /* _LINUX_CRC32_H */ 27#endif /* _LINUX_CRC32_H */
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index ed6cc8962d87..1cb054bd93f2 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -176,20 +176,20 @@ enum {
176}; 176};
177 177
178/* DCCP features (RFC 4340 section 6.4) */ 178/* DCCP features (RFC 4340 section 6.4) */
179 enum { 179enum {
180 DCCPF_RESERVED = 0, 180 DCCPF_RESERVED = 0,
181 DCCPF_CCID = 1, 181 DCCPF_CCID = 1,
182 DCCPF_SHORT_SEQNOS = 2, /* XXX: not yet implemented */ 182 DCCPF_SHORT_SEQNOS = 2, /* XXX: not yet implemented */
183 DCCPF_SEQUENCE_WINDOW = 3, 183 DCCPF_SEQUENCE_WINDOW = 3,
184 DCCPF_ECN_INCAPABLE = 4, /* XXX: not yet implemented */ 184 DCCPF_ECN_INCAPABLE = 4, /* XXX: not yet implemented */
185 DCCPF_ACK_RATIO = 5, 185 DCCPF_ACK_RATIO = 5,
186 DCCPF_SEND_ACK_VECTOR = 6, 186 DCCPF_SEND_ACK_VECTOR = 6,
187 DCCPF_SEND_NDP_COUNT = 7, 187 DCCPF_SEND_NDP_COUNT = 7,
188 DCCPF_MIN_CSUM_COVER = 8, 188 DCCPF_MIN_CSUM_COVER = 8,
189 DCCPF_DATA_CHECKSUM = 9, /* XXX: not yet implemented */ 189 DCCPF_DATA_CHECKSUM = 9, /* XXX: not yet implemented */
190 /* 10-127 reserved */ 190 /* 10-127 reserved */
191 DCCPF_MIN_CCID_SPECIFIC = 128, 191 DCCPF_MIN_CCID_SPECIFIC = 128,
192 DCCPF_MAX_CCID_SPECIFIC = 255, 192 DCCPF_MAX_CCID_SPECIFIC = 255,
193}; 193};
194 194
195/* this structure is argument to DCCP_SOCKOPT_CHANGE_X */ 195/* this structure is argument to DCCP_SOCKOPT_CHANGE_X */
@@ -427,7 +427,7 @@ struct dccp_service_list {
427}; 427};
428 428
429#define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1) 429#define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1)
430#define DCCP_SERVICE_CODE_IS_ABSENT 0 430#define DCCP_SERVICE_CODE_IS_ABSENT 0
431 431
432static inline int dccp_list_has_service(const struct dccp_service_list *sl, 432static inline int dccp_list_has_service(const struct dccp_service_list *sl,
433 const __be32 service) 433 const __be32 service)
@@ -436,7 +436,7 @@ static inline int dccp_list_has_service(const struct dccp_service_list *sl,
436 u32 i = sl->dccpsl_nr; 436 u32 i = sl->dccpsl_nr;
437 while (i--) 437 while (i--)
438 if (sl->dccpsl_list[i] == service) 438 if (sl->dccpsl_list[i] == service)
439 return 1; 439 return 1;
440 } 440 }
441 return 0; 441 return 0;
442} 442}
@@ -511,7 +511,7 @@ struct dccp_sock {
511 __u8 dccps_hc_tx_insert_options:1; 511 __u8 dccps_hc_tx_insert_options:1;
512 struct timer_list dccps_xmit_timer; 512 struct timer_list dccps_xmit_timer;
513}; 513};
514 514
515static inline struct dccp_sock *dccp_sk(const struct sock *sk) 515static inline struct dccp_sock *dccp_sk(const struct sock *sk)
516{ 516{
517 return (struct dccp_sock *)sk; 517 return (struct dccp_sock *)sk;
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index 03ef41c1eaac..499f5373e213 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -39,7 +39,8 @@ typedef void (*dm_dtr_fn) (struct dm_target *ti);
39 * The map function must return: 39 * The map function must return:
40 * < 0: error 40 * < 0: error
41 * = 0: The target will handle the io by resubmitting it later 41 * = 0: The target will handle the io by resubmitting it later
42 * > 0: simple remap complete 42 * = 1: simple remap complete
43 * = 2: The target wants to push back the io
43 */ 44 */
44typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio, 45typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
45 union map_info *map_context); 46 union map_info *map_context);
@@ -50,6 +51,7 @@ typedef int (*dm_map_fn) (struct dm_target *ti, struct bio *bio,
50 * 0 : ended successfully 51 * 0 : ended successfully
51 * 1 : for some reason the io has still not completed (eg, 52 * 1 : for some reason the io has still not completed (eg,
52 * multipath target might want to requeue a failed io). 53 * multipath target might want to requeue a failed io).
54 * 2 : The target wants to push back the io
53 */ 55 */
54typedef int (*dm_endio_fn) (struct dm_target *ti, 56typedef int (*dm_endio_fn) (struct dm_target *ti,
55 struct bio *bio, int error, 57 struct bio *bio, int error,
@@ -173,7 +175,7 @@ void *dm_get_mdptr(struct mapped_device *md);
173/* 175/*
174 * A device can still be used while suspended, but I/O is deferred. 176 * A device can still be used while suspended, but I/O is deferred.
175 */ 177 */
176int dm_suspend(struct mapped_device *md, int with_lockfs); 178int dm_suspend(struct mapped_device *md, unsigned suspend_flags);
177int dm_resume(struct mapped_device *md); 179int dm_resume(struct mapped_device *md);
178 180
179/* 181/*
@@ -188,6 +190,7 @@ int dm_wait_event(struct mapped_device *md, int event_nr);
188const char *dm_device_name(struct mapped_device *md); 190const char *dm_device_name(struct mapped_device *md);
189struct gendisk *dm_disk(struct mapped_device *md); 191struct gendisk *dm_disk(struct mapped_device *md);
190int dm_suspended(struct mapped_device *md); 192int dm_suspended(struct mapped_device *md);
193int dm_noflush_suspending(struct dm_target *ti);
191 194
192/* 195/*
193 * Geometry functions. 196 * Geometry functions.
diff --git a/include/linux/dm-ioctl.h b/include/linux/dm-ioctl.h
index 8853fc4d1c5e..b93486107821 100644
--- a/include/linux/dm-ioctl.h
+++ b/include/linux/dm-ioctl.h
@@ -285,9 +285,9 @@ typedef char ioctl_struct[308];
285#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 285#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
286 286
287#define DM_VERSION_MAJOR 4 287#define DM_VERSION_MAJOR 4
288#define DM_VERSION_MINOR 10 288#define DM_VERSION_MINOR 11
289#define DM_VERSION_PATCHLEVEL 0 289#define DM_VERSION_PATCHLEVEL 0
290#define DM_VERSION_EXTRA "-ioctl (2006-09-14)" 290#define DM_VERSION_EXTRA "-ioctl (2006-10-12)"
291 291
292/* Status bits */ 292/* Status bits */
293#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 293#define DM_READONLY_FLAG (1 << 0) /* In/Out */
@@ -323,4 +323,9 @@ typedef char ioctl_struct[308];
323 */ 323 */
324#define DM_SKIP_LOCKFS_FLAG (1 << 10) /* In */ 324#define DM_SKIP_LOCKFS_FLAG (1 << 10) /* In */
325 325
326/*
327 * Set this to suspend without flushing queued ios.
328 */
329#define DM_NOFLUSH_FLAG (1 << 11) /* In */
330
326#endif /* _LINUX_DM_IOCTL_H */ 331#endif /* _LINUX_DM_IOCTL_H */
diff --git a/include/linux/fault-inject.h b/include/linux/fault-inject.h
new file mode 100644
index 000000000000..32368c4f0326
--- /dev/null
+++ b/include/linux/fault-inject.h
@@ -0,0 +1,84 @@
1#ifndef _LINUX_FAULT_INJECT_H
2#define _LINUX_FAULT_INJECT_H
3
4#ifdef CONFIG_FAULT_INJECTION
5
6#include <linux/types.h>
7#include <linux/debugfs.h>
8#include <asm/atomic.h>
9
10/*
11 * For explanation of the elements of this struct, see
12 * Documentation/fault-injection/fault-injection.txt
13 */
14struct fault_attr {
15 unsigned long probability;
16 unsigned long interval;
17 atomic_t times;
18 atomic_t space;
19 unsigned long verbose;
20 u32 task_filter;
21 unsigned long stacktrace_depth;
22 unsigned long require_start;
23 unsigned long require_end;
24 unsigned long reject_start;
25 unsigned long reject_end;
26
27 unsigned long count;
28
29#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
30
31 struct {
32 struct dentry *dir;
33
34 struct dentry *probability_file;
35 struct dentry *interval_file;
36 struct dentry *times_file;
37 struct dentry *space_file;
38 struct dentry *verbose_file;
39 struct dentry *task_filter_file;
40 struct dentry *stacktrace_depth_file;
41 struct dentry *require_start_file;
42 struct dentry *require_end_file;
43 struct dentry *reject_start_file;
44 struct dentry *reject_end_file;
45 } dentries;
46
47#endif
48};
49
50#define FAULT_ATTR_INITIALIZER { \
51 .interval = 1, \
52 .times = ATOMIC_INIT(1), \
53 .require_end = ULONG_MAX, \
54 .stacktrace_depth = 32, \
55 .verbose = 2, \
56 }
57
58#define DECLARE_FAULT_ATTR(name) struct fault_attr name = FAULT_ATTR_INITIALIZER
59int setup_fault_attr(struct fault_attr *attr, char *str);
60void should_fail_srandom(unsigned long entropy);
61bool should_fail(struct fault_attr *attr, ssize_t size);
62
63#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
64
65int init_fault_attr_dentries(struct fault_attr *attr, const char *name);
66void cleanup_fault_attr_dentries(struct fault_attr *attr);
67
68#else /* CONFIG_FAULT_INJECTION_DEBUG_FS */
69
70static inline int init_fault_attr_dentries(struct fault_attr *attr,
71 const char *name)
72{
73 return -ENODEV;
74}
75
76static inline void cleanup_fault_attr_dentries(struct fault_attr *attr)
77{
78}
79
80#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
81
82#endif /* CONFIG_FAULT_INJECTION */
83
84#endif /* _LINUX_FAULT_INJECT_H */
diff --git a/include/linux/fb.h b/include/linux/fb.h
index fa23e0671bb3..6fe56aaa6685 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -970,11 +970,11 @@ extern struct fb_videomode *fb_find_best_display(struct fb_monspecs *specs,
970/* drivers/video/fbcmap.c */ 970/* drivers/video/fbcmap.c */
971extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 971extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
972extern void fb_dealloc_cmap(struct fb_cmap *cmap); 972extern void fb_dealloc_cmap(struct fb_cmap *cmap);
973extern int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to); 973extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
974extern int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to); 974extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
975extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); 975extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info);
976extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); 976extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info);
977extern struct fb_cmap *fb_default_cmap(int len); 977extern const struct fb_cmap *fb_default_cmap(int len);
978extern void fb_invert_cmaps(void); 978extern void fb_invert_cmaps(void);
979 979
980struct fb_videomode { 980struct fb_videomode {
diff --git a/include/linux/file.h b/include/linux/file.h
index 6e77b9177f9e..edca361f2ab4 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -26,19 +26,12 @@ struct embedded_fd_set {
26 unsigned long fds_bits[1]; 26 unsigned long fds_bits[1];
27}; 27};
28 28
29/*
30 * More than this number of fds: we use a separately allocated fd_set
31 */
32#define EMBEDDED_FD_SET_SIZE (BITS_PER_BYTE * sizeof(struct embedded_fd_set))
33
34struct fdtable { 29struct fdtable {
35 unsigned int max_fds; 30 unsigned int max_fds;
36 int max_fdset;
37 struct file ** fd; /* current fd array */ 31 struct file ** fd; /* current fd array */
38 fd_set *close_on_exec; 32 fd_set *close_on_exec;
39 fd_set *open_fds; 33 fd_set *open_fds;
40 struct rcu_head rcu; 34 struct rcu_head rcu;
41 struct files_struct *free_files;
42 struct fdtable *next; 35 struct fdtable *next;
43}; 36};
44 37
@@ -83,14 +76,8 @@ extern int get_unused_fd(void);
83extern void FASTCALL(put_unused_fd(unsigned int fd)); 76extern void FASTCALL(put_unused_fd(unsigned int fd));
84struct kmem_cache; 77struct kmem_cache;
85 78
86extern struct file ** alloc_fd_array(int);
87extern void free_fd_array(struct file **, int);
88
89extern fd_set *alloc_fdset(int);
90extern void free_fdset(fd_set *, int);
91
92extern int expand_files(struct files_struct *, int nr); 79extern int expand_files(struct files_struct *, int nr);
93extern void free_fdtable(struct fdtable *fdt); 80extern void free_fdtable_rcu(struct rcu_head *rcu);
94extern void __init files_defer_init(void); 81extern void __init files_defer_init(void);
95 82
96static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd) 83static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index 6e05e3e7ce39..393063096134 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -1,5 +1,7 @@
1/* Freezer declarations */ 1/* Freezer declarations */
2 2
3#include <linux/sched.h>
4
3#ifdef CONFIG_PM 5#ifdef CONFIG_PM
4/* 6/*
5 * Check if a process has been frozen 7 * Check if a process has been frozen
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 70b99fbb560b..adce6e1d70c2 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -269,6 +269,7 @@ extern int dir_notify_enable;
269#include <linux/types.h> 269#include <linux/types.h>
270#include <linux/kdev_t.h> 270#include <linux/kdev_t.h>
271#include <linux/dcache.h> 271#include <linux/dcache.h>
272#include <linux/namei.h>
272#include <linux/stat.h> 273#include <linux/stat.h>
273#include <linux/cache.h> 274#include <linux/cache.h>
274#include <linux/kobject.h> 275#include <linux/kobject.h>
@@ -482,21 +483,6 @@ struct block_device {
482}; 483};
483 484
484/* 485/*
485 * bdev->bd_mutex nesting subclasses for the lock validator:
486 *
487 * 0: normal
488 * 1: 'whole'
489 * 2: 'partition'
490 */
491enum bdev_bd_mutex_lock_class
492{
493 BD_MUTEX_NORMAL,
494 BD_MUTEX_WHOLE,
495 BD_MUTEX_PARTITION
496};
497
498
499/*
500 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache 486 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
501 * radix trees 487 * radix trees
502 */ 488 */
@@ -726,8 +712,9 @@ struct file {
726 struct list_head fu_list; 712 struct list_head fu_list;
727 struct rcu_head fu_rcuhead; 713 struct rcu_head fu_rcuhead;
728 } f_u; 714 } f_u;
729 struct dentry *f_dentry; 715 struct path f_path;
730 struct vfsmount *f_vfsmnt; 716#define f_dentry f_path.dentry
717#define f_vfsmnt f_path.mnt
731 const struct file_operations *f_op; 718 const struct file_operations *f_op;
732 atomic_t f_count; 719 atomic_t f_count;
733 unsigned int f_flags; 720 unsigned int f_flags;
@@ -1239,7 +1226,7 @@ extern void touch_atime(struct vfsmount *mnt, struct dentry *dentry);
1239static inline void file_accessed(struct file *file) 1226static inline void file_accessed(struct file *file)
1240{ 1227{
1241 if (!(file->f_flags & O_NOATIME)) 1228 if (!(file->f_flags & O_NOATIME))
1242 touch_atime(file->f_vfsmnt, file->f_dentry); 1229 touch_atime(file->f_path.mnt, file->f_path.dentry);
1243} 1230}
1244 1231
1245int sync_inode(struct inode *inode, struct writeback_control *wbc); 1232int sync_inode(struct inode *inode, struct writeback_control *wbc);
@@ -1499,7 +1486,6 @@ extern void bd_set_size(struct block_device *, loff_t size);
1499extern void bd_forget(struct inode *inode); 1486extern void bd_forget(struct inode *inode);
1500extern void bdput(struct block_device *); 1487extern void bdput(struct block_device *);
1501extern struct block_device *open_by_devnum(dev_t, unsigned); 1488extern struct block_device *open_by_devnum(dev_t, unsigned);
1502extern struct block_device *open_partition_by_devnum(dev_t, unsigned);
1503extern const struct address_space_operations def_blk_aops; 1489extern const struct address_space_operations def_blk_aops;
1504#else 1490#else
1505static inline void bd_forget(struct inode *inode) {} 1491static inline void bd_forget(struct inode *inode) {}
@@ -1517,7 +1503,6 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1517extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1503extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1518extern int blkdev_get(struct block_device *, mode_t, unsigned); 1504extern int blkdev_get(struct block_device *, mode_t, unsigned);
1519extern int blkdev_put(struct block_device *); 1505extern int blkdev_put(struct block_device *);
1520extern int blkdev_put_partition(struct block_device *);
1521extern int bd_claim(struct block_device *, void *); 1506extern int bd_claim(struct block_device *, void *);
1522extern void bd_release(struct block_device *); 1507extern void bd_release(struct block_device *);
1523#ifdef CONFIG_SYSFS 1508#ifdef CONFIG_SYSFS
@@ -1632,7 +1617,7 @@ static inline void put_write_access(struct inode * inode)
1632static inline void allow_write_access(struct file *file) 1617static inline void allow_write_access(struct file *file)
1633{ 1618{
1634 if (file) 1619 if (file)
1635 atomic_inc(&file->f_dentry->d_inode->i_writecount); 1620 atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
1636} 1621}
1637extern int do_pipe(int *); 1622extern int do_pipe(int *);
1638extern struct file *create_read_pipe(struct file *f); 1623extern struct file *create_read_pipe(struct file *f);
diff --git a/include/linux/fs_stack.h b/include/linux/fs_stack.h
new file mode 100644
index 000000000000..bb516ceeefc9
--- /dev/null
+++ b/include/linux/fs_stack.h
@@ -0,0 +1,31 @@
1#ifndef _LINUX_FS_STACK_H
2#define _LINUX_FS_STACK_H
3
4/* This file defines generic functions used primarily by stackable
5 * filesystems; none of these functions require i_mutex to be held.
6 */
7
8#include <linux/fs.h>
9
10/* externs for fs/stack.c */
11extern void fsstack_copy_attr_all(struct inode *dest, const struct inode *src,
12 int (*get_nlinks)(struct inode *));
13
14extern void fsstack_copy_inode_size(struct inode *dst, const struct inode *src);
15
16/* inlines */
17static inline void fsstack_copy_attr_atime(struct inode *dest,
18 const struct inode *src)
19{
20 dest->i_atime = src->i_atime;
21}
22
23static inline void fsstack_copy_attr_times(struct inode *dest,
24 const struct inode *src)
25{
26 dest->i_atime = src->i_atime;
27 dest->i_mtime = src->i_mtime;
28 dest->i_ctime = src->i_ctime;
29}
30
31#endif /* _LINUX_FS_STACK_H */
diff --git a/include/linux/fsl_devices.h b/include/linux/fsl_devices.h
index 3da29e2d524a..abb64c437f6f 100644
--- a/include/linux/fsl_devices.h
+++ b/include/linux/fsl_devices.h
@@ -19,6 +19,7 @@
19#define _FSL_DEVICE_H_ 19#define _FSL_DEVICE_H_
20 20
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/phy.h>
22 23
23/* 24/*
24 * Some conventions on how we handle peripherals on Freescale chips 25 * Some conventions on how we handle peripherals on Freescale chips
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index d4f219ffaa5d..dfc4e4f68da4 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -164,7 +164,7 @@ static inline void fsnotify_open(struct dentry *dentry)
164 */ 164 */
165static inline void fsnotify_close(struct file *file) 165static inline void fsnotify_close(struct file *file)
166{ 166{
167 struct dentry *dentry = file->f_dentry; 167 struct dentry *dentry = file->f_path.dentry;
168 struct inode *inode = dentry->d_inode; 168 struct inode *inode = dentry->d_inode;
169 const char *name = dentry->d_name.name; 169 const char *name = dentry->d_name.name;
170 mode_t mode = file->f_mode; 170 mode_t mode = file->f_mode;
diff --git a/include/linux/futex.h b/include/linux/futex.h
index d097b5b72bc6..3f153b4e156c 100644
--- a/include/linux/futex.h
+++ b/include/linux/futex.h
@@ -93,6 +93,7 @@ struct robust_list_head {
93 */ 93 */
94#define ROBUST_LIST_LIMIT 2048 94#define ROBUST_LIST_LIMIT 2048
95 95
96#ifdef __KERNEL__
96long do_futex(u32 __user *uaddr, int op, u32 val, unsigned long timeout, 97long do_futex(u32 __user *uaddr, int op, u32 val, unsigned long timeout,
97 u32 __user *uaddr2, u32 val2, u32 val3); 98 u32 __user *uaddr2, u32 val2, u32 val3);
98 99
@@ -110,6 +111,7 @@ static inline void exit_pi_state_list(struct task_struct *curr)
110{ 111{
111} 112}
112#endif 113#endif
114#endif /* __KERNEL__ */
113 115
114#define FUTEX_OP_SET 0 /* *(int *)UADDR2 = OPARG; */ 116#define FUTEX_OP_SET 0 /* *(int *)UADDR2 = OPARG; */
115#define FUTEX_OP_ADD 1 /* *(int *)UADDR2 += OPARG; */ 117#define FUTEX_OP_ADD 1 /* *(int *)UADDR2 += OPARG; */
diff --git a/include/linux/generic_serial.h b/include/linux/generic_serial.h
index e25384561955..5412da28fa47 100644
--- a/include/linux/generic_serial.h
+++ b/include/linux/generic_serial.h
@@ -91,7 +91,7 @@ void gs_hangup(struct tty_struct *tty);
91int gs_block_til_ready(void *port, struct file *filp); 91int gs_block_til_ready(void *port, struct file *filp);
92void gs_close(struct tty_struct *tty, struct file *filp); 92void gs_close(struct tty_struct *tty, struct file *filp);
93void gs_set_termios (struct tty_struct * tty, 93void gs_set_termios (struct tty_struct * tty,
94 struct termios * old_termios); 94 struct ktermios * old_termios);
95int gs_init_port(struct gs_port *port); 95int gs_init_port(struct gs_port *port);
96int gs_setserial(struct gs_port *port, struct serial_struct __user *sp); 96int gs_setserial(struct gs_port *port, struct serial_struct __user *sp);
97int gs_getserial(struct gs_port *port, struct serial_struct __user *sp); 97int gs_getserial(struct gs_port *port, struct serial_struct __user *sp);
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 41f276fdd185..0a022b2f63fc 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -83,6 +83,9 @@ struct hd_struct {
83 struct kobject *holder_dir; 83 struct kobject *holder_dir;
84 unsigned ios[2], sectors[2]; /* READs and WRITEs */ 84 unsigned ios[2], sectors[2]; /* READs and WRITEs */
85 int policy, partno; 85 int policy, partno;
86#ifdef CONFIG_FAIL_MAKE_REQUEST
87 int make_it_fail;
88#endif
86}; 89};
87 90
88#define GENHD_FL_REMOVABLE 1 91#define GENHD_FL_REMOVABLE 1
@@ -90,6 +93,7 @@ struct hd_struct {
90#define GENHD_FL_CD 8 93#define GENHD_FL_CD 8
91#define GENHD_FL_UP 16 94#define GENHD_FL_UP 16
92#define GENHD_FL_SUPPRESS_PARTITION_INFO 32 95#define GENHD_FL_SUPPRESS_PARTITION_INFO 32
96#define GENHD_FL_FAIL 64
93 97
94struct disk_stats { 98struct disk_stats {
95 unsigned long sectors[2]; /* READs and WRITEs */ 99 unsigned long sectors[2]; /* READs and WRITEs */
diff --git a/drivers/usb/input/hid-debug.h b/include/linux/hid-debug.h
index f04d6d75c098..f04d6d75c098 100644
--- a/drivers/usb/input/hid-debug.h
+++ b/include/linux/hid-debug.h
diff --git a/drivers/usb/input/hid.h b/include/linux/hid.h
index 2a9bf07944c0..770120add15a 100644
--- a/drivers/usb/input/hid.h
+++ b/include/linux/hid.h
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (c) 1999 Andreas Gal 7 * Copyright (c) 1999 Andreas Gal
8 * Copyright (c) 2000-2001 Vojtech Pavlik 8 * Copyright (c) 2000-2001 Vojtech Pavlik
9 * Copyright (c) 2006 Jiri Kosina
9 */ 10 */
10 11
11/* 12/*
@@ -33,6 +34,7 @@
33#include <linux/list.h> 34#include <linux/list.h>
34#include <linux/timer.h> 35#include <linux/timer.h>
35#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/input.h>
36 38
37/* 39/*
38 * USB HID (Human Interface Device) interface class code 40 * USB HID (Human Interface Device) interface class code
@@ -260,7 +262,8 @@ struct hid_item {
260#define HID_QUIRK_POWERBOOK_HAS_FN 0x00001000 262#define HID_QUIRK_POWERBOOK_HAS_FN 0x00001000
261#define HID_QUIRK_POWERBOOK_FN_ON 0x00002000 263#define HID_QUIRK_POWERBOOK_FN_ON 0x00002000
262#define HID_QUIRK_INVERT_HWHEEL 0x00004000 264#define HID_QUIRK_INVERT_HWHEEL 0x00004000
263#define HID_QUIRK_POWERBOOK_ISO_KEYBOARD 0x00008000 265#define HID_QUIRK_POWERBOOK_ISO_KEYBOARD 0x00008000
266#define HID_QUIRK_BAD_RELATIVE_KEYS 0x00010000
264 267
265/* 268/*
266 * This is the global environment of the parser. This information is 269 * This is the global environment of the parser. This information is
@@ -400,42 +403,14 @@ struct hid_device { /* device report descriptor */
400 unsigned collection_size; /* Number of allocated hid_collections */ 403 unsigned collection_size; /* Number of allocated hid_collections */
401 unsigned maxcollection; /* Number of parsed collections */ 404 unsigned maxcollection; /* Number of parsed collections */
402 unsigned maxapplication; /* Number of applications */ 405 unsigned maxapplication; /* Number of applications */
406 unsigned short bus; /* BUS ID */
407 unsigned short vendor; /* Vendor ID */
408 unsigned short product; /* Product ID */
403 unsigned version; /* HID version */ 409 unsigned version; /* HID version */
404 unsigned country; /* HID country */ 410 unsigned country; /* HID country */
405 struct hid_report_enum report_enum[HID_REPORT_TYPES]; 411 struct hid_report_enum report_enum[HID_REPORT_TYPES];
406 412
407 struct usb_device *dev; /* USB device */ 413 struct device *dev; /* device */
408 struct usb_interface *intf; /* USB interface */
409 int ifnum; /* USB interface number */
410
411 unsigned long iofl; /* I/O flags (CTRL_RUNNING, OUT_RUNNING) */
412 struct timer_list io_retry; /* Retry timer */
413 unsigned long stop_retry; /* Time to give up, in jiffies */
414 unsigned int retry_delay; /* Delay length in ms */
415 struct work_struct reset_work; /* Task context for resets */
416
417 unsigned int bufsize; /* URB buffer size */
418
419 struct urb *urbin; /* Input URB */
420 char *inbuf; /* Input buffer */
421 dma_addr_t inbuf_dma; /* Input buffer dma */
422 spinlock_t inlock; /* Input fifo spinlock */
423
424 struct urb *urbctrl; /* Control URB */
425 struct usb_ctrlrequest *cr; /* Control request struct */
426 dma_addr_t cr_dma; /* Control request struct dma */
427 struct hid_control_fifo ctrl[HID_CONTROL_FIFO_SIZE]; /* Control fifo */
428 unsigned char ctrlhead, ctrltail; /* Control fifo head & tail */
429 char *ctrlbuf; /* Control buffer */
430 dma_addr_t ctrlbuf_dma; /* Control buffer dma */
431 spinlock_t ctrllock; /* Control fifo spinlock */
432
433 struct urb *urbout; /* Output URB */
434 struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
435 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
436 char *outbuf; /* Output buffer */
437 dma_addr_t outbuf_dma; /* Output buffer dma */
438 spinlock_t outlock; /* Output fifo spinlock */
439 414
440 unsigned claimed; /* Claimed by hidinput, hiddev? */ 415 unsigned claimed; /* Claimed by hidinput, hiddev? */
441 unsigned quirks; /* Various quirks the device can pull on us */ 416 unsigned quirks; /* Various quirks the device can pull on us */
@@ -451,7 +426,19 @@ struct hid_device { /* device report descriptor */
451 char phys[64]; /* Device physical location */ 426 char phys[64]; /* Device physical location */
452 char uniq[64]; /* Device unique identifier (serial #) */ 427 char uniq[64]; /* Device unique identifier (serial #) */
453 428
429 void *driver_data;
430
431 /* device-specific function pointers */
432 int (*hidinput_input_event) (struct input_dev *, unsigned int, unsigned int, int);
433 int (*hidinput_open) (struct input_dev *);
434 void (*hidinput_close) (struct input_dev *);
435
436 /* hiddev event handler */
437 void (*hiddev_hid_event) (struct hid_device *, struct hid_field *field,
438 struct hid_usage *, __s32);
439 void (*hiddev_report_event) (struct hid_device *, struct hid_report *);
454#ifdef CONFIG_USB_HIDINPUT_POWERBOOK 440#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
441 unsigned int pb_fnmode;
455 unsigned long pb_pressed_fn[NBITS(KEY_MAX)]; 442 unsigned long pb_pressed_fn[NBITS(KEY_MAX)];
456 unsigned long pb_pressed_numlock[NBITS(KEY_MAX)]; 443 unsigned long pb_pressed_numlock[NBITS(KEY_MAX)];
457#endif 444#endif
@@ -495,31 +482,23 @@ struct hid_descriptor {
495#define resolv_event(a,b) do { } while (0) 482#define resolv_event(a,b) do { } while (0)
496#endif 483#endif
497 484
498#endif
499
500#ifdef CONFIG_USB_HIDINPUT
501/* Applications from HID Usage Tables 4/8/99 Version 1.1 */ 485/* Applications from HID Usage Tables 4/8/99 Version 1.1 */
502/* We ignore a few input applications that are not widely used */ 486/* We ignore a few input applications that are not widely used */
503#define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001)) 487#define IS_INPUT_APPLICATION(a) (((a >= 0x00010000) && (a <= 0x00010008)) || (a == 0x00010080) || (a == 0x000c0001))
488
489/* HID core API */
504extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32); 490extern void hidinput_hid_event(struct hid_device *, struct hid_field *, struct hid_usage *, __s32);
505extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report); 491extern void hidinput_report_event(struct hid_device *hid, struct hid_report *report);
506extern int hidinput_connect(struct hid_device *); 492extern int hidinput_connect(struct hid_device *);
507extern void hidinput_disconnect(struct hid_device *); 493extern void hidinput_disconnect(struct hid_device *);
508#else
509#define IS_INPUT_APPLICATION(a) (0)
510static inline void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) { }
511static inline void hidinput_report_event(struct hid_device *hid, struct hid_report *report) { }
512static inline int hidinput_connect(struct hid_device *hid) { return -ENODEV; }
513static inline void hidinput_disconnect(struct hid_device *hid) { }
514#endif
515 494
516int hid_open(struct hid_device *);
517void hid_close(struct hid_device *);
518int hid_set_field(struct hid_field *, unsigned, __s32); 495int hid_set_field(struct hid_field *, unsigned, __s32);
519void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir); 496int hid_input_report(struct hid_device *, int type, u8 *, int, int);
520void hid_init_reports(struct hid_device *hid); 497int hidinput_find_field(struct hid_device *hid, unsigned int type, unsigned int code, struct hid_field **field);
521int hid_wait_io(struct hid_device* hid); 498void hid_input_field(struct hid_device *hid, struct hid_field *field, __u8 *data, int interrupt);
522 499void hid_output_report(struct hid_report *report, __u8 *data);
500void hid_free_device(struct hid_device *device);
501struct hid_device *hid_parse_report(__u8 *start, unsigned size);
523 502
524#ifdef CONFIG_HID_FF 503#ifdef CONFIG_HID_FF
525int hid_ff_init(struct hid_device *hid); 504int hid_ff_init(struct hid_device *hid);
@@ -536,4 +515,14 @@ static inline int hid_pidff_init(struct hid_device *hid) { return -ENODEV; }
536#else 515#else
537static inline int hid_ff_init(struct hid_device *hid) { return -1; } 516static inline int hid_ff_init(struct hid_device *hid) { return -1; }
538#endif 517#endif
518#ifdef DEBUG
519#define dbg(format, arg...) printk(KERN_DEBUG "%s: " format "\n" , \
520 __FILE__ , ## arg)
521#else
522#define dbg(format, arg...) do {} while (0)
523#endif
524
525#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , \
526 __FILE__ , ## arg)
527#endif
539 528
diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
index c8f8df25c7e0..937da70cb4c4 100644
--- a/include/linux/i2c-algo-bit.h
+++ b/include/linux/i2c-algo-bit.h
@@ -26,9 +26,9 @@
26 26
27/* --- Defines for bit-adapters --------------------------------------- */ 27/* --- Defines for bit-adapters --------------------------------------- */
28/* 28/*
29 * This struct contains the hw-dependent functions of bit-style adapters to 29 * This struct contains the hw-dependent functions of bit-style adapters to
30 * manipulate the line states, and to init any hw-specific features. This is 30 * manipulate the line states, and to init any hw-specific features. This is
31 * only used if you have more than one hw-type of adapter running. 31 * only used if you have more than one hw-type of adapter running.
32 */ 32 */
33struct i2c_algo_bit_data { 33struct i2c_algo_bit_data {
34 void *data; /* private data for lowlevel routines */ 34 void *data; /* private data for lowlevel routines */
@@ -44,6 +44,5 @@ struct i2c_algo_bit_data {
44}; 44};
45 45
46int i2c_bit_add_bus(struct i2c_adapter *); 46int i2c_bit_add_bus(struct i2c_adapter *);
47int i2c_bit_del_bus(struct i2c_adapter *);
48 47
49#endif /* _LINUX_I2C_ALGO_BIT_H */ 48#endif /* _LINUX_I2C_ALGO_BIT_H */
diff --git a/include/linux/i2c-algo-ite.h b/include/linux/i2c-algo-ite.h
deleted file mode 100644
index 0073fe96c76e..000000000000
--- a/include/linux/i2c-algo-ite.h
+++ /dev/null
@@ -1,72 +0,0 @@
1/* ------------------------------------------------------------------------- */
2/* i2c-algo-ite.h i2c driver algorithms for ITE IIC adapters */
3/* ------------------------------------------------------------------------- */
4/* Copyright (C) 1995-97 Simon G. Vogl
5 1998-99 Hans Berglund
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20/* ------------------------------------------------------------------------- */
21
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl> */
24
25/* Modifications by MontaVista Software, 2001
26 Changes made to support the ITE IIC peripheral */
27
28
29#ifndef I2C_ALGO_ITE_H
30#define I2C_ALGO_ITE_H 1
31
32#include <linux/types.h>
33
34/* Example of a sequential read request:
35 struct i2c_iic_msg s_msg;
36
37 s_msg.addr=device_address;
38 s_msg.len=length;
39 s_msg.buf=buffer;
40 s_msg.waddr=word_address;
41 ioctl(file,I2C_SREAD, &s_msg);
42 */
43#define I2C_SREAD 0x780 /* SREAD ioctl command */
44
45struct i2c_iic_msg {
46 __u16 addr; /* device address */
47 __u16 waddr; /* word address */
48 short len; /* msg length */
49 char *buf; /* pointer to msg data */
50};
51
52#ifdef __KERNEL__
53struct i2c_adapter;
54
55struct i2c_algo_iic_data {
56 void *data; /* private data for lolevel routines */
57 void (*setiic) (void *data, int ctl, int val);
58 int (*getiic) (void *data, int ctl);
59 int (*getown) (void *data);
60 int (*getclock) (void *data);
61 void (*waitforpin) (void);
62
63 /* local settings */
64 int udelay;
65 int mdelay;
66 int timeout;
67};
68
69int i2c_iic_add_bus(struct i2c_adapter *);
70int i2c_iic_del_bus(struct i2c_adapter *);
71#endif /* __KERNEL__ */
72#endif /* I2C_ALGO_ITE_H */
diff --git a/include/linux/i2c-algo-pca.h b/include/linux/i2c-algo-pca.h
index 226693e0d88b..fce47c051bb1 100644
--- a/include/linux/i2c-algo-pca.h
+++ b/include/linux/i2c-algo-pca.h
@@ -10,6 +10,5 @@ struct i2c_algo_pca_data {
10}; 10};
11 11
12int i2c_pca_add_bus(struct i2c_adapter *); 12int i2c_pca_add_bus(struct i2c_adapter *);
13int i2c_pca_del_bus(struct i2c_adapter *);
14 13
15#endif /* _LINUX_I2C_ALGO_PCA_H */ 14#endif /* _LINUX_I2C_ALGO_PCA_H */
diff --git a/include/linux/i2c-algo-pcf.h b/include/linux/i2c-algo-pcf.h
index 9908f3fc4839..994eb86f882c 100644
--- a/include/linux/i2c-algo-pcf.h
+++ b/include/linux/i2c-algo-pcf.h
@@ -31,7 +31,7 @@ struct i2c_algo_pcf_data {
31 int (*getpcf) (void *data, int ctl); 31 int (*getpcf) (void *data, int ctl);
32 int (*getown) (void *data); 32 int (*getown) (void *data);
33 int (*getclock) (void *data); 33 int (*getclock) (void *data);
34 void (*waitforpin) (void); 34 void (*waitforpin) (void);
35 35
36 /* local settings */ 36 /* local settings */
37 int udelay; 37 int udelay;
@@ -39,6 +39,5 @@ struct i2c_algo_pcf_data {
39}; 39};
40 40
41int i2c_pcf_add_bus(struct i2c_adapter *); 41int i2c_pcf_add_bus(struct i2c_adapter *);
42int i2c_pcf_del_bus(struct i2c_adapter *);
43 42
44#endif /* _LINUX_I2C_ALGO_PCF_H */ 43#endif /* _LINUX_I2C_ALGO_PCF_H */
diff --git a/include/linux/i2c-algo-sgi.h b/include/linux/i2c-algo-sgi.h
index 4a0113d64064..3b7715024e69 100644
--- a/include/linux/i2c-algo-sgi.h
+++ b/include/linux/i2c-algo-sgi.h
@@ -22,6 +22,5 @@ struct i2c_algo_sgi_data {
22}; 22};
23 23
24int i2c_sgi_add_bus(struct i2c_adapter *); 24int i2c_sgi_add_bus(struct i2c_adapter *);
25int i2c_sgi_del_bus(struct i2c_adapter *);
26 25
27#endif /* I2C_ALGO_SGI_H */ 26#endif /* I2C_ALGO_SGI_H */
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index 0a8f750cbede..7ae3c3326643 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------- */ 1/* ------------------------------------------------------------------------- */
2/* */ 2/* */
3/* i2c-id.h - identifier values for i2c drivers and adapters */ 3/* i2c-id.h - identifier values for i2c drivers and adapters */
4/* */ 4/* */
5/* ------------------------------------------------------------------------- */ 5/* ------------------------------------------------------------------------- */
6/* Copyright (C) 1995-1999 Simon G. Vogl 6/* Copyright (C) 1995-1999 Simon G. Vogl
7 7
@@ -40,10 +40,10 @@
40#define I2C_DRIVERID_SAA7120 11 /* video encoder */ 40#define I2C_DRIVERID_SAA7120 11 /* video encoder */
41#define I2C_DRIVERID_SAA7121 12 /* video encoder */ 41#define I2C_DRIVERID_SAA7121 12 /* video encoder */
42#define I2C_DRIVERID_SAA7185B 13 /* video encoder */ 42#define I2C_DRIVERID_SAA7185B 13 /* video encoder */
43#define I2C_DRIVERID_CH7003 14 /* digital pc to tv encoder */ 43#define I2C_DRIVERID_CH7003 14 /* digital pc to tv encoder */
44#define I2C_DRIVERID_PCF8574A 15 /* i2c expander - 8 bit in/out */ 44#define I2C_DRIVERID_PCF8574A 15 /* i2c expander - 8 bit in/out */
45#define I2C_DRIVERID_PCF8582C 16 /* eeprom */ 45#define I2C_DRIVERID_PCF8582C 16 /* eeprom */
46#define I2C_DRIVERID_AT24Cxx 17 /* eeprom 1/2/4/8/16 K */ 46#define I2C_DRIVERID_AT24Cxx 17 /* eeprom 1/2/4/8/16 K */
47#define I2C_DRIVERID_TEA6300 18 /* audio mixer */ 47#define I2C_DRIVERID_TEA6300 18 /* audio mixer */
48#define I2C_DRIVERID_BT829 19 /* pc to tv encoder */ 48#define I2C_DRIVERID_BT829 19 /* pc to tv encoder */
49#define I2C_DRIVERID_TDA9850 20 /* audio mixer */ 49#define I2C_DRIVERID_TDA9850 20 /* audio mixer */
@@ -82,9 +82,8 @@
82#define I2C_DRIVERID_STM41T00 52 /* real time clock */ 82#define I2C_DRIVERID_STM41T00 52 /* real time clock */
83#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */ 83#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */
84#define I2C_DRIVERID_ADV7170 54 /* video encoder */ 84#define I2C_DRIVERID_ADV7170 54 /* video encoder */
85#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */
86#define I2C_DRIVERID_MAX1617 56 /* temp sensor */ 85#define I2C_DRIVERID_MAX1617 56 /* temp sensor */
87#define I2C_DRIVERID_SAA7191 57 /* video encoder */ 86#define I2C_DRIVERID_SAA7191 57 /* video decoder */
88#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */ 87#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */
89#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */ 88#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */
90#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */ 89#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */
@@ -132,7 +131,6 @@
132#define I2C_DRIVERID_ADM1021 1008 131#define I2C_DRIVERID_ADM1021 1008
133#define I2C_DRIVERID_ADM9240 1009 132#define I2C_DRIVERID_ADM9240 1009
134#define I2C_DRIVERID_LTC1710 1010 133#define I2C_DRIVERID_LTC1710 1010
135#define I2C_DRIVERID_ICSPLL 1012
136#define I2C_DRIVERID_BT869 1013 134#define I2C_DRIVERID_BT869 1013
137#define I2C_DRIVERID_MAXILIFE 1014 135#define I2C_DRIVERID_MAXILIFE 1014
138#define I2C_DRIVERID_MATORB 1015 136#define I2C_DRIVERID_MATORB 1015
@@ -159,12 +157,13 @@
159#define I2C_DRIVERID_ASB100 1043 157#define I2C_DRIVERID_ASB100 1043
160#define I2C_DRIVERID_FSCHER 1046 158#define I2C_DRIVERID_FSCHER 1046
161#define I2C_DRIVERID_W83L785TS 1047 159#define I2C_DRIVERID_W83L785TS 1047
160#define I2C_DRIVERID_OV7670 1048 /* Omnivision 7670 camera */
162 161
163/* 162/*
164 * ---- Adapter types ---------------------------------------------------- 163 * ---- Adapter types ----------------------------------------------------
165 */ 164 */
166 165
167/* --- Bit algorithm adapters */ 166/* --- Bit algorithm adapters */
168#define I2C_HW_B_LP 0x010000 /* Parallel port Philips style */ 167#define I2C_HW_B_LP 0x010000 /* Parallel port Philips style */
169#define I2C_HW_B_SER 0x010002 /* Serial line interface */ 168#define I2C_HW_B_SER 0x010002 /* Serial line interface */
170#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */ 169#define I2C_HW_B_BT848 0x010005 /* BT848 video boards */
@@ -212,9 +211,6 @@
212/* --- MPC8xx PowerPC adapters */ 211/* --- MPC8xx PowerPC adapters */
213#define I2C_HW_MPC8XX_EPON 0x110000 /* Eponymous MPC8xx I2C adapter */ 212#define I2C_HW_MPC8XX_EPON 0x110000 /* Eponymous MPC8xx I2C adapter */
214 213
215/* --- ITE based algorithms */
216#define I2C_HW_I_IIC 0x080000 /* controller on the ITE */
217
218/* --- PowerPC on-chip adapters */ 214/* --- PowerPC on-chip adapters */
219#define I2C_HW_OCP 0x120000 /* IBM on-chip I2C adapter */ 215#define I2C_HW_OCP 0x120000 /* IBM on-chip I2C adapter */
220 216
@@ -250,6 +246,7 @@
250#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */ 246#define I2C_HW_SMBUS_OV518 0x04000f /* OV518(+) USB 1.1 webcam ICs */
251#define I2C_HW_SMBUS_OV519 0x040010 /* OV519 USB 1.1 webcam IC */ 247#define I2C_HW_SMBUS_OV519 0x040010 /* OV519 USB 1.1 webcam IC */
252#define I2C_HW_SMBUS_OVFX2 0x040011 /* Cypress/OmniVision FX2 webcam */ 248#define I2C_HW_SMBUS_OVFX2 0x040011 /* Cypress/OmniVision FX2 webcam */
249#define I2C_HW_SMBUS_CAFE 0x040012 /* Marvell 88ALP01 "CAFE" cam */
253 250
254/* --- ISA pseudo-adapter */ 251/* --- ISA pseudo-adapter */
255#define I2C_HW_ISA 0x050000 252#define I2C_HW_ISA 0x050000
diff --git a/include/linux/i2c-pnx.h b/include/linux/i2c-pnx.h
new file mode 100644
index 000000000000..e6e9c814da61
--- /dev/null
+++ b/include/linux/i2c-pnx.h
@@ -0,0 +1,43 @@
1/*
2 * Header file for I2C support on PNX010x/4008.
3 *
4 * Author: Dennis Kovalev <dkovalev@ru.mvista.com>
5 *
6 * 2004-2006 (c) MontaVista Software, Inc. This file is licensed under
7 * the terms of the GNU General Public License version 2. This program
8 * is licensed "as is" without any warranty of any kind, whether express
9 * or implied.
10 */
11
12#ifndef __I2C_PNX_H__
13#define __I2C_PNX_H__
14
15#include <asm/arch/i2c.h>
16
17struct i2c_pnx_mif {
18 int ret; /* Return value */
19 int mode; /* Interface mode */
20 struct completion complete; /* I/O completion */
21 struct timer_list timer; /* Timeout */
22 char * buf; /* Data buffer */
23 int len; /* Length of data buffer */
24};
25
26struct i2c_pnx_algo_data {
27 u32 base;
28 u32 ioaddr;
29 int irq;
30 struct i2c_pnx_mif mif;
31 int last;
32};
33
34struct i2c_pnx_data {
35 int (*suspend) (struct platform_device *pdev, pm_message_t state);
36 int (*resume) (struct platform_device *pdev);
37 u32 (*calculate_input_freq) (struct platform_device *pdev);
38 int (*set_clock_run) (struct platform_device *pdev);
39 int (*set_clock_stop) (struct platform_device *pdev);
40 struct i2c_adapter *adapter;
41};
42
43#endif /* __I2C_PNX_H__ */
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 9b5d04768c2c..71e50d3e492f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------- */ 1/* ------------------------------------------------------------------------- */
2/* */ 2/* */
3/* i2c.h - definitions for the i2c-bus interface */ 3/* i2c.h - definitions for the i2c-bus interface */
4/* */ 4/* */
5/* ------------------------------------------------------------------------- */ 5/* ------------------------------------------------------------------------- */
6/* Copyright (C) 1995-2000 Simon G. Vogl 6/* Copyright (C) 1995-2000 Simon G. Vogl
7 7
@@ -27,7 +27,7 @@
27#define _LINUX_I2C_H 27#define _LINUX_I2C_H
28 28
29#include <linux/types.h> 29#include <linux/types.h>
30#ifdef __KERNEL__ 30#ifdef __KERNEL__
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/i2c-id.h> 32#include <linux/i2c-id.h>
33#include <linux/mod_devicetable.h> 33#include <linux/mod_devicetable.h>
@@ -53,8 +53,8 @@ union i2c_smbus_data;
53 53
54/* 54/*
55 * The master routines are the ones normally used to transmit data to devices 55 * The master routines are the ones normally used to transmit data to devices
56 * on a bus (or read from them). Apart from two basic transfer functions to 56 * on a bus (or read from them). Apart from two basic transfer functions to
57 * transmit one message at a time, a more complex version can be used to 57 * transmit one message at a time, a more complex version can be used to
58 * transmit an arbitrary number of messages without interruption. 58 * transmit an arbitrary number of messages without interruption.
59 */ 59 */
60extern int i2c_master_send(struct i2c_client *,const char* ,int); 60extern int i2c_master_send(struct i2c_client *,const char* ,int);
@@ -67,10 +67,10 @@ extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
67 67
68/* This is the very generalized SMBus access routine. You probably do not 68/* This is the very generalized SMBus access routine. You probably do not
69 want to use this, though; one of the functions below may be much easier, 69 want to use this, though; one of the functions below may be much easier,
70 and probably just as fast. 70 and probably just as fast.
71 Note that we use i2c_adapter here, because you do not need a specific 71 Note that we use i2c_adapter here, because you do not need a specific
72 smbus adapter to call this function. */ 72 smbus adapter to call this function. */
73extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr, 73extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr,
74 unsigned short flags, 74 unsigned short flags,
75 char read_write, u8 command, int size, 75 char read_write, u8 command, int size,
76 union i2c_smbus_data * data); 76 union i2c_smbus_data * data);
@@ -112,14 +112,14 @@ struct i2c_driver {
112 112
113 /* Notifies the driver that a new bus has appeared. This routine 113 /* Notifies the driver that a new bus has appeared. This routine
114 * can be used by the driver to test if the bus meets its conditions 114 * can be used by the driver to test if the bus meets its conditions
115 * & seek for the presence of the chip(s) it supports. If found, it 115 * & seek for the presence of the chip(s) it supports. If found, it
116 * registers the client(s) that are on the bus to the i2c admin. via 116 * registers the client(s) that are on the bus to the i2c admin. via
117 * i2c_attach_client. 117 * i2c_attach_client.
118 */ 118 */
119 int (*attach_adapter)(struct i2c_adapter *); 119 int (*attach_adapter)(struct i2c_adapter *);
120 int (*detach_adapter)(struct i2c_adapter *); 120 int (*detach_adapter)(struct i2c_adapter *);
121 121
122 /* tells the driver that a client is about to be deleted & gives it 122 /* tells the driver that a client is about to be deleted & gives it
123 * the chance to remove its private data. Also, if the client struct 123 * the chance to remove its private data. Also, if the client struct
124 * has been dynamically allocated by the driver in the function above, 124 * has been dynamically allocated by the driver in the function above,
125 * it must be freed here. 125 * it must be freed here.
@@ -139,13 +139,13 @@ struct i2c_driver {
139#define I2C_NAME_SIZE 50 139#define I2C_NAME_SIZE 50
140 140
141/* 141/*
142 * i2c_client identifies a single device (i.e. chip) that is connected to an 142 * i2c_client identifies a single device (i.e. chip) that is connected to an
143 * i2c bus. The behaviour is defined by the routines of the driver. This 143 * i2c bus. The behaviour is defined by the routines of the driver. This
144 * function is mainly used for lookup & other admin. functions. 144 * function is mainly used for lookup & other admin. functions.
145 */ 145 */
146struct i2c_client { 146struct i2c_client {
147 unsigned int flags; /* div., see below */ 147 unsigned int flags; /* div., see below */
148 unsigned short addr; /* chip address - NOTE: 7bit */ 148 unsigned short addr; /* chip address - NOTE: 7bit */
149 /* addresses are stored in the */ 149 /* addresses are stored in the */
150 /* _LOWER_ 7 bits */ 150 /* _LOWER_ 7 bits */
151 struct i2c_adapter *adapter; /* the adapter we sit on */ 151 struct i2c_adapter *adapter; /* the adapter we sit on */
@@ -182,14 +182,14 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
182 */ 182 */
183struct i2c_algorithm { 183struct i2c_algorithm {
184 /* If an adapter algorithm can't do I2C-level access, set master_xfer 184 /* If an adapter algorithm can't do I2C-level access, set master_xfer
185 to NULL. If an adapter algorithm can do SMBus access, set 185 to NULL. If an adapter algorithm can do SMBus access, set
186 smbus_xfer. If set to NULL, the SMBus protocol is simulated 186 smbus_xfer. If set to NULL, the SMBus protocol is simulated
187 using common I2C messages */ 187 using common I2C messages */
188 /* master_xfer should return the number of messages successfully 188 /* master_xfer should return the number of messages successfully
189 processed, or a negative value on error */ 189 processed, or a negative value on error */
190 int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs, 190 int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs,
191 int num); 191 int num);
192 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, 192 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
193 unsigned short flags, char read_write, 193 unsigned short flags, char read_write,
194 u8 command, int size, union i2c_smbus_data * data); 194 u8 command, int size, union i2c_smbus_data * data);
195 195
@@ -216,6 +216,7 @@ struct i2c_adapter {
216 int (*client_unregister)(struct i2c_client *); 216 int (*client_unregister)(struct i2c_client *);
217 217
218 /* data fields that are valid for all devices */ 218 /* data fields that are valid for all devices */
219 u8 level; /* nesting level for lockdep */
219 struct mutex bus_lock; 220 struct mutex bus_lock;
220 struct mutex clist_lock; 221 struct mutex clist_lock;
221 222
@@ -316,7 +317,7 @@ extern int i2c_check_addr (struct i2c_adapter *adapter, int addr);
316 * It will only call found_proc if some client is connected at the 317 * It will only call found_proc if some client is connected at the
317 * specific address (unless a 'force' matched); 318 * specific address (unless a 'force' matched);
318 */ 319 */
319extern int i2c_probe(struct i2c_adapter *adapter, 320extern int i2c_probe(struct i2c_adapter *adapter,
320 struct i2c_client_address_data *address_data, 321 struct i2c_client_address_data *address_data,
321 int (*found_proc) (struct i2c_adapter *, int, int)); 322 int (*found_proc) (struct i2c_adapter *, int, int));
322 323
@@ -352,15 +353,15 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
352 */ 353 */
353struct i2c_msg { 354struct i2c_msg {
354 __u16 addr; /* slave address */ 355 __u16 addr; /* slave address */
355 __u16 flags; 356 __u16 flags;
356#define I2C_M_TEN 0x10 /* we have a ten bit chip address */ 357#define I2C_M_TEN 0x10 /* we have a ten bit chip address */
357#define I2C_M_RD 0x01 358#define I2C_M_RD 0x01
358#define I2C_M_NOSTART 0x4000 359#define I2C_M_NOSTART 0x4000
359#define I2C_M_REV_DIR_ADDR 0x2000 360#define I2C_M_REV_DIR_ADDR 0x2000
360#define I2C_M_IGNORE_NAK 0x1000 361#define I2C_M_IGNORE_NAK 0x1000
361#define I2C_M_NO_RD_ACK 0x0800 362#define I2C_M_NO_RD_ACK 0x0800
362 __u16 len; /* msg length */ 363 __u16 len; /* msg length */
363 __u8 *buf; /* pointer to msg data */ 364 __u8 *buf; /* pointer to msg data */
364}; 365};
365 366
366/* To determine what functionality is present */ 367/* To determine what functionality is present */
@@ -370,16 +371,16 @@ struct i2c_msg {
370#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */ 371#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
371#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */ 372#define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */
372#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */ 373#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
373#define I2C_FUNC_SMBUS_QUICK 0x00010000 374#define I2C_FUNC_SMBUS_QUICK 0x00010000
374#define I2C_FUNC_SMBUS_READ_BYTE 0x00020000 375#define I2C_FUNC_SMBUS_READ_BYTE 0x00020000
375#define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000 376#define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000
376#define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000 377#define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000
377#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000 378#define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000
378#define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000 379#define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000
379#define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000 380#define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000
380#define I2C_FUNC_SMBUS_PROC_CALL 0x00800000 381#define I2C_FUNC_SMBUS_PROC_CALL 0x00800000
381#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000 382#define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000
382#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 383#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
383#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */ 384#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
384#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */ 385#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
385#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */ 386#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */
@@ -406,10 +407,10 @@ struct i2c_msg {
406 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \ 407 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
407 I2C_FUNC_SMBUS_I2C_BLOCK) 408 I2C_FUNC_SMBUS_I2C_BLOCK)
408 409
409/* 410/*
410 * Data for SMBus Messages 411 * Data for SMBus Messages
411 */ 412 */
412#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */ 413#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
413union i2c_smbus_data { 414union i2c_smbus_data {
414 __u8 byte; 415 __u8 byte;
415 __u16 word; 416 __u16 word;
@@ -421,11 +422,11 @@ union i2c_smbus_data {
421#define I2C_SMBUS_READ 1 422#define I2C_SMBUS_READ 1
422#define I2C_SMBUS_WRITE 0 423#define I2C_SMBUS_WRITE 0
423 424
424/* SMBus transaction types (size parameter in the above functions) 425/* SMBus transaction types (size parameter in the above functions)
425 Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */ 426 Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
426#define I2C_SMBUS_QUICK 0 427#define I2C_SMBUS_QUICK 0
427#define I2C_SMBUS_BYTE 1 428#define I2C_SMBUS_BYTE 1
428#define I2C_SMBUS_BYTE_DATA 2 429#define I2C_SMBUS_BYTE_DATA 2
429#define I2C_SMBUS_WORD_DATA 3 430#define I2C_SMBUS_WORD_DATA 3
430#define I2C_SMBUS_PROC_CALL 4 431#define I2C_SMBUS_PROC_CALL 4
431#define I2C_SMBUS_BLOCK_DATA 5 432#define I2C_SMBUS_BLOCK_DATA 5
@@ -434,15 +435,15 @@ union i2c_smbus_data {
434 435
435 436
436/* ----- commands for the ioctl like i2c_command call: 437/* ----- commands for the ioctl like i2c_command call:
437 * note that additional calls are defined in the algorithm and hw 438 * note that additional calls are defined in the algorithm and hw
438 * dependent layers - these can be listed here, or see the 439 * dependent layers - these can be listed here, or see the
439 * corresponding header files. 440 * corresponding header files.
440 */ 441 */
441 /* -> bit-adapter specific ioctls */ 442 /* -> bit-adapter specific ioctls */
442#define I2C_RETRIES 0x0701 /* number of times a device address */ 443#define I2C_RETRIES 0x0701 /* number of times a device address */
443 /* should be polled when not */ 444 /* should be polled when not */
444 /* acknowledging */ 445 /* acknowledging */
445#define I2C_TIMEOUT 0x0702 /* set timeout - call with int */ 446#define I2C_TIMEOUT 0x0702 /* set timeout - call with int */
446 447
447 448
448/* this is for i2c-dev.c */ 449/* this is for i2c-dev.c */
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 9c2050293f17..e26a03981a94 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -796,6 +796,7 @@ typedef struct hwif_s {
796 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ 796 unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */
797 unsigned no_io_32bit : 1; /* 1 = can not do 32-bit IO ops */ 797 unsigned no_io_32bit : 1; /* 1 = can not do 32-bit IO ops */
798 unsigned err_stops_fifo : 1; /* 1=data FIFO is cleared by an error */ 798 unsigned err_stops_fifo : 1; /* 1=data FIFO is cleared by an error */
799 unsigned atapi_irq_bogon : 1; /* Generates spurious DMA interrupts in PIO mode */
799 800
800 struct device gendev; 801 struct device gendev;
801 struct completion gendev_rel_comp; /* To deal with device release() */ 802 struct completion gendev_rel_comp; /* To deal with device release() */
@@ -803,8 +804,6 @@ typedef struct hwif_s {
803 void *hwif_data; /* extra hwif data */ 804 void *hwif_data; /* extra hwif data */
804 805
805 unsigned dma; 806 unsigned dma;
806
807 void (*led_act)(void *data, int rw);
808} ____cacheline_internodealigned_in_smp ide_hwif_t; 807} ____cacheline_internodealigned_in_smp ide_hwif_t;
809 808
810/* 809/*
diff --git a/include/linux/if_addr.h b/include/linux/if_addr.h
index dbe8f6120a40..d557e4ce9b6b 100644
--- a/include/linux/if_addr.h
+++ b/include/linux/if_addr.h
@@ -52,4 +52,10 @@ struct ifa_cacheinfo
52 __u32 tstamp; /* updated timestamp, hundredths of seconds */ 52 __u32 tstamp; /* updated timestamp, hundredths of seconds */
53}; 53};
54 54
55/* backwards compatibility for userspace */
56#ifndef __KERNEL__
57#define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
58#define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
59#endif
60
55#endif 61#endif
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index e963a077e6f5..35ed3b5467f3 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -82,6 +82,12 @@ enum
82 82
83#define IFLA_MAX (__IFLA_MAX - 1) 83#define IFLA_MAX (__IFLA_MAX - 1)
84 84
85/* backwards compatibility for userspace */
86#ifndef __KERNEL__
87#define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
88#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
89#endif
90
85/* ifi_flags. 91/* ifi_flags.
86 92
87 IFF_* flags. 93 IFF_* flags.
diff --git a/include/linux/init.h b/include/linux/init.h
index 5eb5d24b7680..5a593a1dec1e 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -111,6 +111,7 @@ extern void setup_arch(char **);
111#define subsys_initcall_sync(fn) __define_initcall("4s",fn,4s) 111#define subsys_initcall_sync(fn) __define_initcall("4s",fn,4s)
112#define fs_initcall(fn) __define_initcall("5",fn,5) 112#define fs_initcall(fn) __define_initcall("5",fn,5)
113#define fs_initcall_sync(fn) __define_initcall("5s",fn,5s) 113#define fs_initcall_sync(fn) __define_initcall("5s",fn,5s)
114#define rootfs_initcall(fn) __define_initcall("rootfs",fn,rootfs)
114#define device_initcall(fn) __define_initcall("6",fn,6) 115#define device_initcall(fn) __define_initcall("6",fn,6)
115#define device_initcall_sync(fn) __define_initcall("6s",fn,6s) 116#define device_initcall_sync(fn) __define_initcall("6s",fn,6s)
116#define late_initcall(fn) __define_initcall("7",fn,7) 117#define late_initcall(fn) __define_initcall("7",fn,7)
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 733790d4f7db..b5315150199e 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -7,16 +7,15 @@
7#include <linux/utsname.h> 7#include <linux/utsname.h>
8#include <linux/lockdep.h> 8#include <linux/lockdep.h>
9#include <linux/ipc.h> 9#include <linux/ipc.h>
10#include <linux/pid_namespace.h>
10 11
11#define INIT_FDTABLE \ 12#define INIT_FDTABLE \
12{ \ 13{ \
13 .max_fds = NR_OPEN_DEFAULT, \ 14 .max_fds = NR_OPEN_DEFAULT, \
14 .max_fdset = EMBEDDED_FD_SET_SIZE, \
15 .fd = &init_files.fd_array[0], \ 15 .fd = &init_files.fd_array[0], \
16 .close_on_exec = (fd_set *)&init_files.close_on_exec_init, \ 16 .close_on_exec = (fd_set *)&init_files.close_on_exec_init, \
17 .open_fds = (fd_set *)&init_files.open_fds_init, \ 17 .open_fds = (fd_set *)&init_files.open_fds_init, \
18 .rcu = RCU_HEAD_INIT, \ 18 .rcu = RCU_HEAD_INIT, \
19 .free_files = NULL, \
20 .next = NULL, \ 19 .next = NULL, \
21} 20}
22 21
@@ -57,25 +56,28 @@
57 .cpu_vm_mask = CPU_MASK_ALL, \ 56 .cpu_vm_mask = CPU_MASK_ALL, \
58} 57}
59 58
60#define INIT_SIGNALS(sig) { \ 59#define INIT_SIGNALS(sig) { \
61 .count = ATOMIC_INIT(1), \ 60 .count = ATOMIC_INIT(1), \
62 .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\ 61 .wait_chldexit = __WAIT_QUEUE_HEAD_INITIALIZER(sig.wait_chldexit),\
63 .shared_pending = { \ 62 .shared_pending = { \
64 .list = LIST_HEAD_INIT(sig.shared_pending.list), \ 63 .list = LIST_HEAD_INIT(sig.shared_pending.list), \
65 .signal = {{0}}}, \ 64 .signal = {{0}}}, \
66 .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \ 65 .posix_timers = LIST_HEAD_INIT(sig.posix_timers), \
67 .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \ 66 .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
68 .rlim = INIT_RLIMITS, \ 67 .rlim = INIT_RLIMITS, \
69 .pgrp = 1, \ 68 .pgrp = 1, \
70 .session = 1, \ 69 .tty_old_pgrp = 0, \
70 { .__session = 1}, \
71} 71}
72 72
73extern struct nsproxy init_nsproxy; 73extern struct nsproxy init_nsproxy;
74#define INIT_NSPROXY(nsproxy) { \ 74#define INIT_NSPROXY(nsproxy) { \
75 .pid_ns = &init_pid_ns, \
75 .count = ATOMIC_INIT(1), \ 76 .count = ATOMIC_INIT(1), \
76 .nslock = __SPIN_LOCK_UNLOCKED(nsproxy.nslock), \ 77 .nslock = __SPIN_LOCK_UNLOCKED(nsproxy.nslock), \
78 .id = 0, \
77 .uts_ns = &init_uts_ns, \ 79 .uts_ns = &init_uts_ns, \
78 .namespace = NULL, \ 80 .mnt_ns = NULL, \
79 INIT_IPC_NS(ipc_ns) \ 81 INIT_IPC_NS(ipc_ns) \
80} 82}
81 83
diff --git a/include/linux/input.h b/include/linux/input.h
index c38507ba38b5..4e61158b06a0 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -663,7 +663,7 @@ struct input_absinfo {
663#define BUS_GSC 0x1A 663#define BUS_GSC 0x1A
664 664
665/* 665/*
666 * Values describing the status of an effect 666 * Values describing the status of a force-feedback effect
667 */ 667 */
668#define FF_STATUS_STOPPED 0x00 668#define FF_STATUS_STOPPED 0x00
669#define FF_STATUS_PLAYING 0x01 669#define FF_STATUS_PLAYING 0x01
@@ -680,7 +680,7 @@ struct input_absinfo {
680 */ 680 */
681 681
682/** 682/**
683 * struct ff_replay - defines scheduling of the effect 683 * struct ff_replay - defines scheduling of the force-feedback effect
684 * @length: duration of the effect 684 * @length: duration of the effect
685 * @delay: delay before effect should start playing 685 * @delay: delay before effect should start playing
686 */ 686 */
@@ -690,7 +690,7 @@ struct ff_replay {
690}; 690};
691 691
692/** 692/**
693 * struct ff_trigger - defines what triggers the effect 693 * struct ff_trigger - defines what triggers the force-feedback effect
694 * @button: number of the button triggering the effect 694 * @button: number of the button triggering the effect
695 * @interval: controls how soon the effect can be re-triggered 695 * @interval: controls how soon the effect can be re-triggered
696 */ 696 */
@@ -700,7 +700,7 @@ struct ff_trigger {
700}; 700};
701 701
702/** 702/**
703 * struct ff_envelope - generic effect envelope 703 * struct ff_envelope - generic force-feedback effect envelope
704 * @attack_length: duration of the attack (ms) 704 * @attack_length: duration of the attack (ms)
705 * @attack_level: level at the beginning of the attack 705 * @attack_level: level at the beginning of the attack
706 * @fade_length: duration of fade (ms) 706 * @fade_length: duration of fade (ms)
@@ -719,7 +719,7 @@ struct ff_envelope {
719}; 719};
720 720
721/** 721/**
722 * struct ff_constant_effect - defines parameters of a constant effect 722 * struct ff_constant_effect - defines parameters of a constant force-feedback effect
723 * @level: strength of the effect; may be negative 723 * @level: strength of the effect; may be negative
724 * @envelope: envelope data 724 * @envelope: envelope data
725 */ 725 */
@@ -729,7 +729,7 @@ struct ff_constant_effect {
729}; 729};
730 730
731/** 731/**
732 * struct ff_ramp_effect - defines parameters of a ramp effect 732 * struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
733 * @start_level: beginning strength of the effect; may be negative 733 * @start_level: beginning strength of the effect; may be negative
734 * @end_level: final strength of the effect; may be negative 734 * @end_level: final strength of the effect; may be negative
735 * @envelope: envelope data 735 * @envelope: envelope data
@@ -741,7 +741,7 @@ struct ff_ramp_effect {
741}; 741};
742 742
743/** 743/**
744 * struct ff_condition_effect - defines a spring or friction effect 744 * struct ff_condition_effect - defines a spring or friction force-feedback effect
745 * @right_saturation: maximum level when joystick moved all way to the right 745 * @right_saturation: maximum level when joystick moved all way to the right
746 * @left_saturation: same for the left side 746 * @left_saturation: same for the left side
747 * @right_coeff: controls how fast the force grows when the joystick moves 747 * @right_coeff: controls how fast the force grows when the joystick moves
@@ -762,7 +762,7 @@ struct ff_condition_effect {
762}; 762};
763 763
764/** 764/**
765 * struct ff_periodic_effect - defines parameters of a periodic effect 765 * struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
766 * @waveform: kind of the effect (wave) 766 * @waveform: kind of the effect (wave)
767 * @period: period of the wave (ms) 767 * @period: period of the wave (ms)
768 * @magnitude: peak value 768 * @magnitude: peak value
@@ -793,7 +793,7 @@ struct ff_periodic_effect {
793}; 793};
794 794
795/** 795/**
796 * struct ff_rumble_effect - defines parameters of a periodic effect 796 * struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
797 * @strong_magnitude: magnitude of the heavy motor 797 * @strong_magnitude: magnitude of the heavy motor
798 * @weak_magnitude: magnitude of the light one 798 * @weak_magnitude: magnitude of the light one
799 * 799 *
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index de7593f4e895..e36e86c869fb 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -231,7 +231,8 @@ enum
231 NET_TX_SOFTIRQ, 231 NET_TX_SOFTIRQ,
232 NET_RX_SOFTIRQ, 232 NET_RX_SOFTIRQ,
233 BLOCK_SOFTIRQ, 233 BLOCK_SOFTIRQ,
234 TASKLET_SOFTIRQ 234 TASKLET_SOFTIRQ,
235 SCHED_SOFTIRQ,
235}; 236};
236 237
237/* softirq mask and active fields moved to irq_cpustat_t in 238/* softirq mask and active fields moved to irq_cpustat_t in
diff --git a/include/linux/isdn.h b/include/linux/isdn.h
index 62991148d5a5..3c7875b7ab5b 100644
--- a/include/linux/isdn.h
+++ b/include/linux/isdn.h
@@ -511,8 +511,8 @@ typedef struct modem_info {
511#endif 511#endif
512 struct tty_struct *tty; /* Pointer to corresponding tty */ 512 struct tty_struct *tty; /* Pointer to corresponding tty */
513 atemu emu; /* AT-emulator data */ 513 atemu emu; /* AT-emulator data */
514 struct termios normal_termios; /* For saving termios structs */ 514 struct ktermios normal_termios; /* For saving termios structs */
515 struct termios callout_termios; 515 struct ktermios callout_termios;
516 wait_queue_head_t open_wait, close_wait; 516 wait_queue_head_t open_wait, close_wait;
517 struct semaphore write_sem; 517 struct semaphore write_sem;
518 spinlock_t readlock; 518 spinlock_t readlock;
@@ -525,8 +525,8 @@ typedef struct _isdn_modem {
525 int refcount; /* Number of opens */ 525 int refcount; /* Number of opens */
526 struct tty_driver *tty_modem; /* tty-device */ 526 struct tty_driver *tty_modem; /* tty-device */
527 struct tty_struct *modem_table[ISDN_MAX_CHANNELS]; /* ?? copied from Orig */ 527 struct tty_struct *modem_table[ISDN_MAX_CHANNELS]; /* ?? copied from Orig */
528 struct termios *modem_termios[ISDN_MAX_CHANNELS]; 528 struct ktermios *modem_termios[ISDN_MAX_CHANNELS];
529 struct termios *modem_termios_locked[ISDN_MAX_CHANNELS]; 529 struct ktermios *modem_termios_locked[ISDN_MAX_CHANNELS];
530 modem_info info[ISDN_MAX_CHANNELS]; /* Private data */ 530 modem_info info[ISDN_MAX_CHANNELS]; /* Private data */
531} isdn_modem_t; 531} isdn_modem_t;
532 532
diff --git a/include/linux/istallion.h b/include/linux/istallion.h
index b55e2a035605..106a5e85e5c4 100644
--- a/include/linux/istallion.h
+++ b/include/linux/istallion.h
@@ -49,13 +49,13 @@
49 * communication with the slave board will always be on a per port 49 * communication with the slave board will always be on a per port
50 * basis. 50 * basis.
51 */ 51 */
52typedef struct { 52struct stliport {
53 unsigned long magic; 53 unsigned long magic;
54 int portnr; 54 unsigned int portnr;
55 int panelnr; 55 unsigned int panelnr;
56 int brdnr; 56 unsigned int brdnr;
57 unsigned long state; 57 unsigned long state;
58 int devnr; 58 unsigned int devnr;
59 int flags; 59 int flags;
60 int baud_base; 60 int baud_base;
61 int custom_divisor; 61 int custom_divisor;
@@ -72,7 +72,7 @@ typedef struct {
72 wait_queue_head_t close_wait; 72 wait_queue_head_t close_wait;
73 wait_queue_head_t raw_wait; 73 wait_queue_head_t raw_wait;
74 struct work_struct tqhangup; 74 struct work_struct tqhangup;
75 asysigs_t asig; 75 struct asysigs asig;
76 unsigned long addr; 76 unsigned long addr;
77 unsigned long rxoffset; 77 unsigned long rxoffset;
78 unsigned long txoffset; 78 unsigned long txoffset;
@@ -83,31 +83,31 @@ typedef struct {
83 unsigned char reqbit; 83 unsigned char reqbit;
84 unsigned char portidx; 84 unsigned char portidx;
85 unsigned char portbit; 85 unsigned char portbit;
86} stliport_t; 86};
87 87
88/* 88/*
89 * Use a structure of function pointers to do board level operations. 89 * Use a structure of function pointers to do board level operations.
90 * These include, enable/disable, paging shared memory, interrupting, etc. 90 * These include, enable/disable, paging shared memory, interrupting, etc.
91 */ 91 */
92typedef struct stlibrd { 92struct stlibrd {
93 unsigned long magic; 93 unsigned long magic;
94 int brdnr; 94 unsigned int brdnr;
95 int brdtype; 95 unsigned int brdtype;
96 int state; 96 unsigned int state;
97 int nrpanels; 97 unsigned int nrpanels;
98 int nrports; 98 unsigned int nrports;
99 int nrdevs; 99 unsigned int nrdevs;
100 unsigned int iobase; 100 unsigned int iobase;
101 int iosize; 101 int iosize;
102 unsigned long memaddr; 102 unsigned long memaddr;
103 void __iomem *membase; 103 void __iomem *membase;
104 int memsize; 104 unsigned long memsize;
105 int pagesize; 105 int pagesize;
106 int hostoffset; 106 int hostoffset;
107 int slaveoffset; 107 int slaveoffset;
108 int bitsize; 108 int bitsize;
109 int enabval; 109 int enabval;
110 int panels[STL_MAXPANELS]; 110 unsigned int panels[STL_MAXPANELS];
111 int panelids[STL_MAXPANELS]; 111 int panelids[STL_MAXPANELS];
112 void (*init)(struct stlibrd *brdp); 112 void (*init)(struct stlibrd *brdp);
113 void (*enable)(struct stlibrd *brdp); 113 void (*enable)(struct stlibrd *brdp);
@@ -116,8 +116,8 @@ typedef struct stlibrd {
116 void __iomem *(*getmemptr)(struct stlibrd *brdp, unsigned long offset, int line); 116 void __iomem *(*getmemptr)(struct stlibrd *brdp, unsigned long offset, int line);
117 void (*intr)(struct stlibrd *brdp); 117 void (*intr)(struct stlibrd *brdp);
118 void (*reset)(struct stlibrd *brdp); 118 void (*reset)(struct stlibrd *brdp);
119 stliport_t *ports[STL_MAXPORTS]; 119 struct stliport *ports[STL_MAXPORTS];
120} stlibrd_t; 120};
121 121
122 122
123/* 123/*
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6738283ac385..b0c4a05a4b0c 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -13,11 +13,10 @@
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/compiler.h> 14#include <linux/compiler.h>
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/log2.h>
16#include <asm/byteorder.h> 17#include <asm/byteorder.h>
17#include <asm/bug.h> 18#include <asm/bug.h>
18 19
19extern const char linux_banner[];
20
21#define INT_MAX ((int)(~0U>>1)) 20#define INT_MAX ((int)(~0U>>1))
22#define INT_MIN (-INT_MAX - 1) 21#define INT_MIN (-INT_MAX - 1)
23#define UINT_MAX (~0U) 22#define UINT_MAX (~0U)
@@ -157,20 +156,6 @@ static inline int printk(const char *s, ...) { return 0; }
157 156
158unsigned long int_sqrt(unsigned long); 157unsigned long int_sqrt(unsigned long);
159 158
160static inline int __attribute_pure__ long_log2(unsigned long x)
161{
162 int r = 0;
163 for (x >>= 1; x > 0; x >>= 1)
164 r++;
165 return r;
166}
167
168static inline unsigned long
169__attribute_const__ roundup_pow_of_two(unsigned long x)
170{
171 return 1UL << fls_long(x - 1);
172}
173
174extern int printk_ratelimit(void); 159extern int printk_ratelimit(void);
175extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst); 160extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
176extern bool printk_timed_ratelimit(unsigned long *caller_jiffies, 161extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
new file mode 100644
index 000000000000..5bb2c3c585c1
--- /dev/null
+++ b/include/linux/kvm.h
@@ -0,0 +1,227 @@
1#ifndef __LINUX_KVM_H
2#define __LINUX_KVM_H
3
4/*
5 * Userspace interface for /dev/kvm - kernel based virtual machine
6 *
7 * Note: this interface is considered experimental and may change without
8 * notice.
9 */
10
11#include <asm/types.h>
12#include <linux/ioctl.h>
13
14/*
15 * Architectural interrupt line count, and the size of the bitmap needed
16 * to hold them.
17 */
18#define KVM_NR_INTERRUPTS 256
19#define KVM_IRQ_BITMAP_SIZE_BYTES ((KVM_NR_INTERRUPTS + 7) / 8)
20#define KVM_IRQ_BITMAP_SIZE(type) (KVM_IRQ_BITMAP_SIZE_BYTES / sizeof(type))
21
22
23/* for KVM_CREATE_MEMORY_REGION */
24struct kvm_memory_region {
25 __u32 slot;
26 __u32 flags;
27 __u64 guest_phys_addr;
28 __u64 memory_size; /* bytes */
29};
30
31/* for kvm_memory_region::flags */
32#define KVM_MEM_LOG_DIRTY_PAGES 1UL
33
34
35#define KVM_EXIT_TYPE_FAIL_ENTRY 1
36#define KVM_EXIT_TYPE_VM_EXIT 2
37
38enum kvm_exit_reason {
39 KVM_EXIT_UNKNOWN = 0,
40 KVM_EXIT_EXCEPTION = 1,
41 KVM_EXIT_IO = 2,
42 KVM_EXIT_CPUID = 3,
43 KVM_EXIT_DEBUG = 4,
44 KVM_EXIT_HLT = 5,
45 KVM_EXIT_MMIO = 6,
46};
47
48/* for KVM_RUN */
49struct kvm_run {
50 /* in */
51 __u32 vcpu;
52 __u32 emulated; /* skip current instruction */
53 __u32 mmio_completed; /* mmio request completed */
54
55 /* out */
56 __u32 exit_type;
57 __u32 exit_reason;
58 __u32 instruction_length;
59 union {
60 /* KVM_EXIT_UNKNOWN */
61 struct {
62 __u32 hardware_exit_reason;
63 } hw;
64 /* KVM_EXIT_EXCEPTION */
65 struct {
66 __u32 exception;
67 __u32 error_code;
68 } ex;
69 /* KVM_EXIT_IO */
70 struct {
71#define KVM_EXIT_IO_IN 0
72#define KVM_EXIT_IO_OUT 1
73 __u8 direction;
74 __u8 size; /* bytes */
75 __u8 string;
76 __u8 string_down;
77 __u8 rep;
78 __u8 pad;
79 __u16 port;
80 __u64 count;
81 union {
82 __u64 address;
83 __u32 value;
84 };
85 } io;
86 struct {
87 } debug;
88 /* KVM_EXIT_MMIO */
89 struct {
90 __u64 phys_addr;
91 __u8 data[8];
92 __u32 len;
93 __u8 is_write;
94 } mmio;
95 };
96};
97
98/* for KVM_GET_REGS and KVM_SET_REGS */
99struct kvm_regs {
100 /* in */
101 __u32 vcpu;
102 __u32 padding;
103
104 /* out (KVM_GET_REGS) / in (KVM_SET_REGS) */
105 __u64 rax, rbx, rcx, rdx;
106 __u64 rsi, rdi, rsp, rbp;
107 __u64 r8, r9, r10, r11;
108 __u64 r12, r13, r14, r15;
109 __u64 rip, rflags;
110};
111
112struct kvm_segment {
113 __u64 base;
114 __u32 limit;
115 __u16 selector;
116 __u8 type;
117 __u8 present, dpl, db, s, l, g, avl;
118 __u8 unusable;
119 __u8 padding;
120};
121
122struct kvm_dtable {
123 __u64 base;
124 __u16 limit;
125 __u16 padding[3];
126};
127
128/* for KVM_GET_SREGS and KVM_SET_SREGS */
129struct kvm_sregs {
130 /* in */
131 __u32 vcpu;
132 __u32 padding;
133
134 /* out (KVM_GET_SREGS) / in (KVM_SET_SREGS) */
135 struct kvm_segment cs, ds, es, fs, gs, ss;
136 struct kvm_segment tr, ldt;
137 struct kvm_dtable gdt, idt;
138 __u64 cr0, cr2, cr3, cr4, cr8;
139 __u64 efer;
140 __u64 apic_base;
141 __u64 interrupt_bitmap[KVM_IRQ_BITMAP_SIZE(__u64)];
142};
143
144struct kvm_msr_entry {
145 __u32 index;
146 __u32 reserved;
147 __u64 data;
148};
149
150/* for KVM_GET_MSRS and KVM_SET_MSRS */
151struct kvm_msrs {
152 __u32 vcpu;
153 __u32 nmsrs; /* number of msrs in entries */
154
155 struct kvm_msr_entry entries[0];
156};
157
158/* for KVM_GET_MSR_INDEX_LIST */
159struct kvm_msr_list {
160 __u32 nmsrs; /* number of msrs in entries */
161 __u32 indices[0];
162};
163
164/* for KVM_TRANSLATE */
165struct kvm_translation {
166 /* in */
167 __u64 linear_address;
168 __u32 vcpu;
169 __u32 padding;
170
171 /* out */
172 __u64 physical_address;
173 __u8 valid;
174 __u8 writeable;
175 __u8 usermode;
176};
177
178/* for KVM_INTERRUPT */
179struct kvm_interrupt {
180 /* in */
181 __u32 vcpu;
182 __u32 irq;
183};
184
185struct kvm_breakpoint {
186 __u32 enabled;
187 __u32 padding;
188 __u64 address;
189};
190
191/* for KVM_DEBUG_GUEST */
192struct kvm_debug_guest {
193 /* int */
194 __u32 vcpu;
195 __u32 enabled;
196 struct kvm_breakpoint breakpoints[4];
197 __u32 singlestep;
198};
199
200/* for KVM_GET_DIRTY_LOG */
201struct kvm_dirty_log {
202 __u32 slot;
203 __u32 padding;
204 union {
205 void __user *dirty_bitmap; /* one bit per page */
206 __u64 padding;
207 };
208};
209
210#define KVMIO 0xAE
211
212#define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)
213#define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)
214#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
215#define KVM_GET_SREGS _IOWR(KVMIO, 5, struct kvm_sregs)
216#define KVM_SET_SREGS _IOW(KVMIO, 6, struct kvm_sregs)
217#define KVM_TRANSLATE _IOWR(KVMIO, 7, struct kvm_translation)
218#define KVM_INTERRUPT _IOW(KVMIO, 8, struct kvm_interrupt)
219#define KVM_DEBUG_GUEST _IOW(KVMIO, 9, struct kvm_debug_guest)
220#define KVM_SET_MEMORY_REGION _IOW(KVMIO, 10, struct kvm_memory_region)
221#define KVM_CREATE_VCPU _IOW(KVMIO, 11, int /* vcpu_slot */)
222#define KVM_GET_DIRTY_LOG _IOW(KVMIO, 12, struct kvm_dirty_log)
223#define KVM_GET_MSRS _IOWR(KVMIO, 13, struct kvm_msrs)
224#define KVM_SET_MSRS _IOWR(KVMIO, 14, struct kvm_msrs)
225#define KVM_GET_MSR_INDEX_LIST _IOWR(KVMIO, 15, struct kvm_msr_list)
226
227#endif
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index 8c39654549d8..0c962b82a9de 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -206,7 +206,7 @@ void nlmsvc_invalidate_all(void);
206static __inline__ struct inode * 206static __inline__ struct inode *
207nlmsvc_file_inode(struct nlm_file *file) 207nlmsvc_file_inode(struct nlm_file *file)
208{ 208{
209 return file->f_file->f_dentry->d_inode; 209 return file->f_file->f_path.dentry->d_inode;
210} 210}
211 211
212/* 212/*
diff --git a/include/linux/log2.h b/include/linux/log2.h
new file mode 100644
index 000000000000..d02e1a547a7e
--- /dev/null
+++ b/include/linux/log2.h
@@ -0,0 +1,157 @@
1/* Integer base 2 logarithm calculation
2 *
3 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#ifndef _LINUX_LOG2_H
13#define _LINUX_LOG2_H
14
15#include <linux/types.h>
16#include <linux/bitops.h>
17
18/*
19 * deal with unrepresentable constant logarithms
20 */
21extern __attribute__((const, noreturn))
22int ____ilog2_NaN(void);
23
24/*
25 * non-constant log of base 2 calculators
26 * - the arch may override these in asm/bitops.h if they can be implemented
27 * more efficiently than using fls() and fls64()
28 * - the arch is not required to handle n==0 if implementing the fallback
29 */
30#ifndef CONFIG_ARCH_HAS_ILOG2_U32
31static inline __attribute__((const))
32int __ilog2_u32(u32 n)
33{
34 return fls(n) - 1;
35}
36#endif
37
38#ifndef CONFIG_ARCH_HAS_ILOG2_U64
39static inline __attribute__((const))
40int __ilog2_u64(u64 n)
41{
42 return fls64(n) - 1;
43}
44#endif
45
46/*
47 * round up to nearest power of two
48 */
49static inline __attribute__((const))
50unsigned long __roundup_pow_of_two(unsigned long n)
51{
52 return 1UL << fls_long(n - 1);
53}
54
55/**
56 * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value
57 * @n - parameter
58 *
59 * constant-capable log of base 2 calculation
60 * - this can be used to initialise global variables from constant data, hence
61 * the massive ternary operator construction
62 *
63 * selects the appropriately-sized optimised version depending on sizeof(n)
64 */
65#define ilog2(n) \
66( \
67 __builtin_constant_p(n) ? ( \
68 (n) < 1 ? ____ilog2_NaN() : \
69 (n) & (1ULL << 63) ? 63 : \
70 (n) & (1ULL << 62) ? 62 : \
71 (n) & (1ULL << 61) ? 61 : \
72 (n) & (1ULL << 60) ? 60 : \
73 (n) & (1ULL << 59) ? 59 : \
74 (n) & (1ULL << 58) ? 58 : \
75 (n) & (1ULL << 57) ? 57 : \
76 (n) & (1ULL << 56) ? 56 : \
77 (n) & (1ULL << 55) ? 55 : \
78 (n) & (1ULL << 54) ? 54 : \
79 (n) & (1ULL << 53) ? 53 : \
80 (n) & (1ULL << 52) ? 52 : \
81 (n) & (1ULL << 51) ? 51 : \
82 (n) & (1ULL << 50) ? 50 : \
83 (n) & (1ULL << 49) ? 49 : \
84 (n) & (1ULL << 48) ? 48 : \
85 (n) & (1ULL << 47) ? 47 : \
86 (n) & (1ULL << 46) ? 46 : \
87 (n) & (1ULL << 45) ? 45 : \
88 (n) & (1ULL << 44) ? 44 : \
89 (n) & (1ULL << 43) ? 43 : \
90 (n) & (1ULL << 42) ? 42 : \
91 (n) & (1ULL << 41) ? 41 : \
92 (n) & (1ULL << 40) ? 40 : \
93 (n) & (1ULL << 39) ? 39 : \
94 (n) & (1ULL << 38) ? 38 : \
95 (n) & (1ULL << 37) ? 37 : \
96 (n) & (1ULL << 36) ? 36 : \
97 (n) & (1ULL << 35) ? 35 : \
98 (n) & (1ULL << 34) ? 34 : \
99 (n) & (1ULL << 33) ? 33 : \
100 (n) & (1ULL << 32) ? 32 : \
101 (n) & (1ULL << 31) ? 31 : \
102 (n) & (1ULL << 30) ? 30 : \
103 (n) & (1ULL << 29) ? 29 : \
104 (n) & (1ULL << 28) ? 28 : \
105 (n) & (1ULL << 27) ? 27 : \
106 (n) & (1ULL << 26) ? 26 : \
107 (n) & (1ULL << 25) ? 25 : \
108 (n) & (1ULL << 24) ? 24 : \
109 (n) & (1ULL << 23) ? 23 : \
110 (n) & (1ULL << 22) ? 22 : \
111 (n) & (1ULL << 21) ? 21 : \
112 (n) & (1ULL << 20) ? 20 : \
113 (n) & (1ULL << 19) ? 19 : \
114 (n) & (1ULL << 18) ? 18 : \
115 (n) & (1ULL << 17) ? 17 : \
116 (n) & (1ULL << 16) ? 16 : \
117 (n) & (1ULL << 15) ? 15 : \
118 (n) & (1ULL << 14) ? 14 : \
119 (n) & (1ULL << 13) ? 13 : \
120 (n) & (1ULL << 12) ? 12 : \
121 (n) & (1ULL << 11) ? 11 : \
122 (n) & (1ULL << 10) ? 10 : \
123 (n) & (1ULL << 9) ? 9 : \
124 (n) & (1ULL << 8) ? 8 : \
125 (n) & (1ULL << 7) ? 7 : \
126 (n) & (1ULL << 6) ? 6 : \
127 (n) & (1ULL << 5) ? 5 : \
128 (n) & (1ULL << 4) ? 4 : \
129 (n) & (1ULL << 3) ? 3 : \
130 (n) & (1ULL << 2) ? 2 : \
131 (n) & (1ULL << 1) ? 1 : \
132 (n) & (1ULL << 0) ? 0 : \
133 ____ilog2_NaN() \
134 ) : \
135 (sizeof(n) <= 4) ? \
136 __ilog2_u32(n) : \
137 __ilog2_u64(n) \
138 )
139
140/**
141 * roundup_pow_of_two - round the given value up to nearest power of two
142 * @n - parameter
143 *
144 * round the given balue up to the nearest power of two
145 * - the result is undefined when n == 0
146 * - this can be used to initialise global variables from constant data
147 */
148#define roundup_pow_of_two(n) \
149( \
150 __builtin_constant_p(n) ? ( \
151 (n == 1) ? 0 : \
152 (1UL << (ilog2((n) - 1) + 1)) \
153 ) : \
154 __roundup_pow_of_two(n) \
155 )
156
157#endif /* _LINUX_LOG2_H */
diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h
new file mode 100644
index 000000000000..4af0b1fc282a
--- /dev/null
+++ b/include/linux/mnt_namespace.h
@@ -0,0 +1,42 @@
1#ifndef _NAMESPACE_H_
2#define _NAMESPACE_H_
3#ifdef __KERNEL__
4
5#include <linux/mount.h>
6#include <linux/sched.h>
7#include <linux/nsproxy.h>
8
9struct mnt_namespace {
10 atomic_t count;
11 struct vfsmount * root;
12 struct list_head list;
13 wait_queue_head_t poll;
14 int event;
15};
16
17extern int copy_mnt_ns(int, struct task_struct *);
18extern void __put_mnt_ns(struct mnt_namespace *ns);
19extern struct mnt_namespace *dup_mnt_ns(struct task_struct *,
20 struct fs_struct *);
21
22static inline void put_mnt_ns(struct mnt_namespace *ns)
23{
24 if (atomic_dec_and_lock(&ns->count, &vfsmount_lock))
25 /* releases vfsmount_lock */
26 __put_mnt_ns(ns);
27}
28
29static inline void exit_mnt_ns(struct task_struct *p)
30{
31 struct mnt_namespace *ns = p->nsproxy->mnt_ns;
32 if (ns)
33 put_mnt_ns(ns);
34}
35
36static inline void get_mnt_ns(struct mnt_namespace *ns)
37{
38 atomic_inc(&ns->count);
39}
40
41#endif
42#endif
diff --git a/include/linux/module.h b/include/linux/module.h
index d33df2408e05..10f771a49997 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -319,6 +319,13 @@ struct module
319 319
320 unsigned int taints; /* same bits as kernel:tainted */ 320 unsigned int taints; /* same bits as kernel:tainted */
321 321
322#ifdef CONFIG_GENERIC_BUG
323 /* Support for BUG */
324 struct list_head bug_list;
325 struct bug_entry *bug_table;
326 unsigned num_bugs;
327#endif
328
322#ifdef CONFIG_MODULE_UNLOAD 329#ifdef CONFIG_MODULE_UNLOAD
323 /* Reference counts */ 330 /* Reference counts */
324 struct module_ref ref[NR_CPUS]; 331 struct module_ref ref[NR_CPUS];
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 403d1a97c512..e357dc86a4de 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -20,7 +20,7 @@
20struct super_block; 20struct super_block;
21struct vfsmount; 21struct vfsmount;
22struct dentry; 22struct dentry;
23struct namespace; 23struct mnt_namespace;
24 24
25#define MNT_NOSUID 0x01 25#define MNT_NOSUID 0x01
26#define MNT_NODEV 0x02 26#define MNT_NODEV 0x02
@@ -52,7 +52,7 @@ struct vfsmount {
52 struct list_head mnt_slave_list;/* list of slave mounts */ 52 struct list_head mnt_slave_list;/* list of slave mounts */
53 struct list_head mnt_slave; /* slave list entry */ 53 struct list_head mnt_slave; /* slave list entry */
54 struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */ 54 struct vfsmount *mnt_master; /* slave is on master->mnt_slave_list */
55 struct namespace *mnt_namespace; /* containing namespace */ 55 struct mnt_namespace *mnt_ns; /* containing namespace */
56 int mnt_pinned; 56 int mnt_pinned;
57}; 57};
58 58
diff --git a/include/linux/mutex.h b/include/linux/mutex.h
index b2b91c477563..a7544afd7582 100644
--- a/include/linux/mutex.h
+++ b/include/linux/mutex.h
@@ -125,8 +125,10 @@ extern int fastcall mutex_lock_interruptible(struct mutex *lock);
125 125
126#ifdef CONFIG_DEBUG_LOCK_ALLOC 126#ifdef CONFIG_DEBUG_LOCK_ALLOC
127extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass); 127extern void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
128extern int mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass);
128#else 129#else
129# define mutex_lock_nested(lock, subclass) mutex_lock(lock) 130# define mutex_lock_nested(lock, subclass) mutex_lock(lock)
131# define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
130#endif 132#endif
131 133
132/* 134/*
diff --git a/include/linux/namei.h b/include/linux/namei.h
index f5f19606effb..d39a5a67e979 100644
--- a/include/linux/namei.h
+++ b/include/linux/namei.h
@@ -29,6 +29,11 @@ struct nameidata {
29 } intent; 29 } intent;
30}; 30};
31 31
32struct path {
33 struct vfsmount *mnt;
34 struct dentry *dentry;
35};
36
32/* 37/*
33 * Type of the last component on LOOKUP_PARENT 38 * Type of the last component on LOOKUP_PARENT
34 */ 39 */
diff --git a/include/linux/namespace.h b/include/linux/namespace.h
deleted file mode 100644
index d137009f0b2b..000000000000
--- a/include/linux/namespace.h
+++ /dev/null
@@ -1,42 +0,0 @@
1#ifndef _NAMESPACE_H_
2#define _NAMESPACE_H_
3#ifdef __KERNEL__
4
5#include <linux/mount.h>
6#include <linux/sched.h>
7#include <linux/nsproxy.h>
8
9struct namespace {
10 atomic_t count;
11 struct vfsmount * root;
12 struct list_head list;
13 wait_queue_head_t poll;
14 int event;
15};
16
17extern int copy_namespace(int, struct task_struct *);
18extern void __put_namespace(struct namespace *namespace);
19extern struct namespace *dup_namespace(struct task_struct *, struct fs_struct *);
20
21static inline void put_namespace(struct namespace *namespace)
22{
23 if (atomic_dec_and_lock(&namespace->count, &vfsmount_lock))
24 /* releases vfsmount_lock */
25 __put_namespace(namespace);
26}
27
28static inline void exit_namespace(struct task_struct *p)
29{
30 struct namespace *namespace = p->nsproxy->namespace;
31 if (namespace) {
32 put_namespace(namespace);
33 }
34}
35
36static inline void get_namespace(struct namespace *namespace)
37{
38 atomic_inc(&namespace->count);
39}
40
41#endif
42#endif
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index c57088f575a3..6be767c76b37 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -193,13 +193,20 @@ struct hh_cache
193{ 193{
194 struct hh_cache *hh_next; /* Next entry */ 194 struct hh_cache *hh_next; /* Next entry */
195 atomic_t hh_refcnt; /* number of users */ 195 atomic_t hh_refcnt; /* number of users */
196 __be16 hh_type; /* protocol identifier, f.e ETH_P_IP 196/*
197 * We want hh_output, hh_len, hh_lock and hh_data be a in a separate
198 * cache line on SMP.
199 * They are mostly read, but hh_refcnt may be changed quite frequently,
200 * incurring cache line ping pongs.
201 */
202 __be16 hh_type ____cacheline_aligned_in_smp;
203 /* protocol identifier, f.e ETH_P_IP
197 * NOTE: For VLANs, this will be the 204 * NOTE: For VLANs, this will be the
198 * encapuslated type. --BLG 205 * encapuslated type. --BLG
199 */ 206 */
200 u16 hh_len; /* length of header */ 207 u16 hh_len; /* length of header */
201 int (*hh_output)(struct sk_buff *skb); 208 int (*hh_output)(struct sk_buff *skb);
202 rwlock_t hh_lock; 209 seqlock_t hh_lock;
203 210
204 /* cached hardware header; allow for machine alignment needs. */ 211 /* cached hardware header; allow for machine alignment needs. */
205#define HH_DATA_MOD 16 212#define HH_DATA_MOD 16
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index 971d1c6dfc4b..fdfb0e44912f 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -4,9 +4,10 @@
4#include <linux/spinlock.h> 4#include <linux/spinlock.h>
5#include <linux/sched.h> 5#include <linux/sched.h>
6 6
7struct namespace; 7struct mnt_namespace;
8struct uts_namespace; 8struct uts_namespace;
9struct ipc_namespace; 9struct ipc_namespace;
10struct pid_namespace;
10 11
11/* 12/*
12 * A structure to contain pointers to all per-process 13 * A structure to contain pointers to all per-process
@@ -23,9 +24,11 @@ struct ipc_namespace;
23struct nsproxy { 24struct nsproxy {
24 atomic_t count; 25 atomic_t count;
25 spinlock_t nslock; 26 spinlock_t nslock;
27 unsigned long id;
26 struct uts_namespace *uts_ns; 28 struct uts_namespace *uts_ns;
27 struct ipc_namespace *ipc_ns; 29 struct ipc_namespace *ipc_ns;
28 struct namespace *namespace; 30 struct mnt_namespace *mnt_ns;
31 struct pid_namespace *pid_ns;
29}; 32};
30extern struct nsproxy init_nsproxy; 33extern struct nsproxy init_nsproxy;
31 34
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 4d972bbef316..51180dba9a98 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1785,14 +1785,17 @@
1785#define PCI_DEVICE_ID_MOXA_C104 0x1040 1785#define PCI_DEVICE_ID_MOXA_C104 0x1040
1786#define PCI_DEVICE_ID_MOXA_CP104U 0x1041 1786#define PCI_DEVICE_ID_MOXA_CP104U 0x1041
1787#define PCI_DEVICE_ID_MOXA_CP104JU 0x1042 1787#define PCI_DEVICE_ID_MOXA_CP104JU 0x1042
1788#define PCI_DEVICE_ID_MOXA_CP104EL 0x1043
1788#define PCI_DEVICE_ID_MOXA_CT114 0x1140 1789#define PCI_DEVICE_ID_MOXA_CT114 0x1140
1789#define PCI_DEVICE_ID_MOXA_CP114 0x1141 1790#define PCI_DEVICE_ID_MOXA_CP114 0x1141
1790#define PCI_DEVICE_ID_MOXA_CP118U 0x1180 1791#define PCI_DEVICE_ID_MOXA_CP118U 0x1180
1792#define PCI_DEVICE_ID_MOXA_CP118EL 0x1181
1791#define PCI_DEVICE_ID_MOXA_CP132 0x1320 1793#define PCI_DEVICE_ID_MOXA_CP132 0x1320
1792#define PCI_DEVICE_ID_MOXA_CP132U 0x1321 1794#define PCI_DEVICE_ID_MOXA_CP132U 0x1321
1793#define PCI_DEVICE_ID_MOXA_CP134U 0x1340 1795#define PCI_DEVICE_ID_MOXA_CP134U 0x1340
1794#define PCI_DEVICE_ID_MOXA_C168 0x1680 1796#define PCI_DEVICE_ID_MOXA_C168 0x1680
1795#define PCI_DEVICE_ID_MOXA_CP168U 0x1681 1797#define PCI_DEVICE_ID_MOXA_CP168U 0x1681
1798#define PCI_DEVICE_ID_MOXA_CP168EL 0x1682
1796 1799
1797#define PCI_VENDOR_ID_CCD 0x1397 1800#define PCI_VENDOR_ID_CCD 0x1397
1798#define PCI_DEVICE_ID_CCD_2BD0 0x2bd0 1801#define PCI_DEVICE_ID_CCD_2BD0 0x2bd0
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 2c0007d17218..4dec047b1837 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -35,8 +35,9 @@ enum pid_type
35 * 35 *
36 * Holding a reference to struct pid solves both of these problems. 36 * Holding a reference to struct pid solves both of these problems.
37 * It is small so holding a reference does not consume a lot of 37 * It is small so holding a reference does not consume a lot of
38 * resources, and since a new struct pid is allocated when the numeric 38 * resources, and since a new struct pid is allocated when the numeric pid
39 * pid value is reused we don't mistakenly refer to new processes. 39 * value is reused (when pids wrap around) we don't mistakenly refer to new
40 * processes.
40 */ 41 */
41 42
42struct pid 43struct pid
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
new file mode 100644
index 000000000000..d2a9d419f01f
--- /dev/null
+++ b/include/linux/pid_namespace.h
@@ -0,0 +1,45 @@
1#ifndef _LINUX_PID_NS_H
2#define _LINUX_PID_NS_H
3
4#include <linux/sched.h>
5#include <linux/mm.h>
6#include <linux/threads.h>
7#include <linux/pid.h>
8#include <linux/nsproxy.h>
9#include <linux/kref.h>
10
11struct pidmap {
12 atomic_t nr_free;
13 void *page;
14};
15
16#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
17
18struct pid_namespace {
19 struct kref kref;
20 struct pidmap pidmap[PIDMAP_ENTRIES];
21 int last_pid;
22 struct task_struct *child_reaper;
23};
24
25extern struct pid_namespace init_pid_ns;
26
27static inline void get_pid_ns(struct pid_namespace *ns)
28{
29 kref_get(&ns->kref);
30}
31
32extern int copy_pid_ns(int flags, struct task_struct *tsk);
33extern void free_pid_ns(struct kref *kref);
34
35static inline void put_pid_ns(struct pid_namespace *ns)
36{
37 kref_put(&ns->kref, free_pid_ns);
38}
39
40static inline struct task_struct *child_reaper(struct task_struct *tsk)
41{
42 return tsk->nsproxy->pid_ns->child_reaper;
43}
44
45#endif /* _LINUX_PID_NS_H */
diff --git a/include/linux/pktcdvd.h b/include/linux/pktcdvd.h
index 8a94c717c266..5ea4f05683f6 100644
--- a/include/linux/pktcdvd.h
+++ b/include/linux/pktcdvd.h
@@ -111,6 +111,13 @@ struct pkt_ctrl_command {
111#include <linux/blkdev.h> 111#include <linux/blkdev.h>
112#include <linux/completion.h> 112#include <linux/completion.h>
113#include <linux/cdrom.h> 113#include <linux/cdrom.h>
114#include <linux/kobject.h>
115#include <linux/sysfs.h>
116
117/* default bio write queue congestion marks */
118#define PKT_WRITE_CONGESTION_ON 10000
119#define PKT_WRITE_CONGESTION_OFF 9000
120
114 121
115struct packet_settings 122struct packet_settings
116{ 123{
@@ -241,6 +248,14 @@ struct packet_stacked_data
241}; 248};
242#define PSD_POOL_SIZE 64 249#define PSD_POOL_SIZE 64
243 250
251struct pktcdvd_kobj
252{
253 struct kobject kobj;
254 struct pktcdvd_device *pd;
255};
256#define to_pktcdvdkobj(_k) \
257 ((struct pktcdvd_kobj*)container_of(_k,struct pktcdvd_kobj,kobj))
258
244struct pktcdvd_device 259struct pktcdvd_device
245{ 260{
246 struct block_device *bdev; /* dev attached */ 261 struct block_device *bdev; /* dev attached */
@@ -271,6 +286,16 @@ struct pktcdvd_device
271 286
272 struct packet_iosched iosched; 287 struct packet_iosched iosched;
273 struct gendisk *disk; 288 struct gendisk *disk;
289
290 int write_congestion_off;
291 int write_congestion_on;
292
293 struct class_device *clsdev; /* sysfs pktcdvd[0-7] class dev */
294 struct pktcdvd_kobj *kobj_stat; /* sysfs pktcdvd[0-7]/stat/ */
295 struct pktcdvd_kobj *kobj_wqueue; /* sysfs pktcdvd[0-7]/write_queue/ */
296
297 struct dentry *dfs_d_root; /* debugfs: devname directory */
298 struct dentry *dfs_f_info; /* debugfs: info file */
274}; 299};
275 300
276#endif /* __KERNEL__ */ 301#endif /* __KERNEL__ */
diff --git a/include/linux/pspace.h b/include/linux/pspace.h
deleted file mode 100644
index 91d48b8b2d99..000000000000
--- a/include/linux/pspace.h
+++ /dev/null
@@ -1,23 +0,0 @@
1#ifndef _LINUX_PSPACE_H
2#define _LINUX_PSPACE_H
3
4#include <linux/sched.h>
5#include <linux/mm.h>
6#include <linux/threads.h>
7#include <linux/pid.h>
8
9struct pidmap {
10 atomic_t nr_free;
11 void *page;
12};
13
14#define PIDMAP_ENTRIES ((PID_MAX_LIMIT + 8*PAGE_SIZE - 1)/PAGE_SIZE/8)
15
16struct pspace {
17 struct pidmap pidmap[PIDMAP_ENTRIES];
18 int last_pid;
19};
20
21extern struct pspace init_pspace;
22
23#endif /* _LINUX_PSPACE_H */
diff --git a/include/linux/raid/raid5.h b/include/linux/raid/raid5.h
index 03636d7918fe..d8286db60b96 100644
--- a/include/linux/raid/raid5.h
+++ b/include/linux/raid/raid5.h
@@ -227,7 +227,10 @@ struct raid5_private_data {
227 struct list_head handle_list; /* stripes needing handling */ 227 struct list_head handle_list; /* stripes needing handling */
228 struct list_head delayed_list; /* stripes that have plugged requests */ 228 struct list_head delayed_list; /* stripes that have plugged requests */
229 struct list_head bitmap_list; /* stripes delaying awaiting bitmap update */ 229 struct list_head bitmap_list; /* stripes delaying awaiting bitmap update */
230 struct bio *retry_read_aligned; /* currently retrying aligned bios */
231 struct bio *retry_read_aligned_list; /* aligned bios retry list */
230 atomic_t preread_active_stripes; /* stripes with scheduled io */ 232 atomic_t preread_active_stripes; /* stripes with scheduled io */
233 atomic_t active_aligned_reads;
231 234
232 atomic_t reshape_stripes; /* stripes with pending writes for reshape */ 235 atomic_t reshape_stripes; /* stripes with pending writes for reshape */
233 /* unfortunately we need two cache names as we temporarily have 236 /* unfortunately we need two cache names as we temporarily have
diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
index d0e4dce33ad5..c3fc6caaad3f 100644
--- a/include/linux/reiserfs_fs.h
+++ b/include/linux/reiserfs_fs.h
@@ -1159,7 +1159,7 @@ znodes are the way! */
1159#define PATH_READA 0x1 /* do read ahead */ 1159#define PATH_READA 0x1 /* do read ahead */
1160#define PATH_READA_BACK 0x2 /* read backwards */ 1160#define PATH_READA_BACK 0x2 /* read backwards */
1161 1161
1162struct path { 1162struct treepath {
1163 int path_length; /* Length of the array above. */ 1163 int path_length; /* Length of the array above. */
1164 int reada; 1164 int reada;
1165 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */ 1165 struct path_element path_elements[EXTENDED_MAX_HEIGHT]; /* Array of the path elements. */
@@ -1169,7 +1169,7 @@ struct path {
1169#define pos_in_item(path) ((path)->pos_in_item) 1169#define pos_in_item(path) ((path)->pos_in_item)
1170 1170
1171#define INITIALIZE_PATH(var) \ 1171#define INITIALIZE_PATH(var) \
1172struct path var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,} 1172struct treepath var = {.path_length = ILLEGAL_PATH_ELEMENT_OFFSET, .reada = 0,}
1173 1173
1174/* Get path element by path and path position. */ 1174/* Get path element by path and path position. */
1175#define PATH_OFFSET_PELEMENT(p_s_path,n_offset) ((p_s_path)->path_elements +(n_offset)) 1175#define PATH_OFFSET_PELEMENT(p_s_path,n_offset) ((p_s_path)->path_elements +(n_offset))
@@ -1327,7 +1327,7 @@ struct tree_balance {
1327 int need_balance_dirty; 1327 int need_balance_dirty;
1328 struct super_block *tb_sb; 1328 struct super_block *tb_sb;
1329 struct reiserfs_transaction_handle *transaction_handle; 1329 struct reiserfs_transaction_handle *transaction_handle;
1330 struct path *tb_path; 1330 struct treepath *tb_path;
1331 struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */ 1331 struct buffer_head *L[MAX_HEIGHT]; /* array of left neighbors of nodes in the path */
1332 struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */ 1332 struct buffer_head *R[MAX_HEIGHT]; /* array of right neighbors of nodes in the path */
1333 struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */ 1333 struct buffer_head *FL[MAX_HEIGHT]; /* array of fathers of the left neighbors */
@@ -1793,41 +1793,41 @@ static inline void copy_key(struct reiserfs_key *to,
1793 memcpy(to, from, KEY_SIZE); 1793 memcpy(to, from, KEY_SIZE);
1794} 1794}
1795 1795
1796int comp_items(const struct item_head *stored_ih, const struct path *p_s_path); 1796int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_path);
1797const struct reiserfs_key *get_rkey(const struct path *p_s_chk_path, 1797const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path,
1798 const struct super_block *p_s_sb); 1798 const struct super_block *p_s_sb);
1799int search_by_key(struct super_block *, const struct cpu_key *, 1799int search_by_key(struct super_block *, const struct cpu_key *,
1800 struct path *, int); 1800 struct treepath *, int);
1801#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL) 1801#define search_item(s,key,path) search_by_key (s, key, path, DISK_LEAF_NODE_LEVEL)
1802int search_for_position_by_key(struct super_block *p_s_sb, 1802int search_for_position_by_key(struct super_block *p_s_sb,
1803 const struct cpu_key *p_s_cpu_key, 1803 const struct cpu_key *p_s_cpu_key,
1804 struct path *p_s_search_path); 1804 struct treepath *p_s_search_path);
1805extern void decrement_bcount(struct buffer_head *p_s_bh); 1805extern void decrement_bcount(struct buffer_head *p_s_bh);
1806void decrement_counters_in_path(struct path *p_s_search_path); 1806void decrement_counters_in_path(struct treepath *p_s_search_path);
1807void pathrelse(struct path *p_s_search_path); 1807void pathrelse(struct treepath *p_s_search_path);
1808int reiserfs_check_path(struct path *p); 1808int reiserfs_check_path(struct treepath *p);
1809void pathrelse_and_restore(struct super_block *s, struct path *p_s_search_path); 1809void pathrelse_and_restore(struct super_block *s, struct treepath *p_s_search_path);
1810 1810
1811int reiserfs_insert_item(struct reiserfs_transaction_handle *th, 1811int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
1812 struct path *path, 1812 struct treepath *path,
1813 const struct cpu_key *key, 1813 const struct cpu_key *key,
1814 struct item_head *ih, 1814 struct item_head *ih,
1815 struct inode *inode, const char *body); 1815 struct inode *inode, const char *body);
1816 1816
1817int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, 1817int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th,
1818 struct path *path, 1818 struct treepath *path,
1819 const struct cpu_key *key, 1819 const struct cpu_key *key,
1820 struct inode *inode, 1820 struct inode *inode,
1821 const char *body, int paste_size); 1821 const char *body, int paste_size);
1822 1822
1823int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, 1823int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1824 struct path *path, 1824 struct treepath *path,
1825 struct cpu_key *key, 1825 struct cpu_key *key,
1826 struct inode *inode, 1826 struct inode *inode,
1827 struct page *page, loff_t new_file_size); 1827 struct page *page, loff_t new_file_size);
1828 1828
1829int reiserfs_delete_item(struct reiserfs_transaction_handle *th, 1829int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1830 struct path *path, 1830 struct treepath *path,
1831 const struct cpu_key *key, 1831 const struct cpu_key *key,
1832 struct inode *inode, struct buffer_head *p_s_un_bh); 1832 struct inode *inode, struct buffer_head *p_s_un_bh);
1833 1833
@@ -1858,7 +1858,7 @@ void padd_item(char *item, int total_length, int length);
1858#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */ 1858#define GET_BLOCK_NO_DANGLE 16 /* don't leave any transactions running */
1859 1859
1860int restart_transaction(struct reiserfs_transaction_handle *th, 1860int restart_transaction(struct reiserfs_transaction_handle *th,
1861 struct inode *inode, struct path *path); 1861 struct inode *inode, struct treepath *path);
1862void reiserfs_read_locked_inode(struct inode *inode, 1862void reiserfs_read_locked_inode(struct inode *inode,
1863 struct reiserfs_iget_args *args); 1863 struct reiserfs_iget_args *args);
1864int reiserfs_find_actor(struct inode *inode, void *p); 1864int reiserfs_find_actor(struct inode *inode, void *p);
@@ -1905,7 +1905,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr);
1905/* namei.c */ 1905/* namei.c */
1906void set_de_name_and_namelen(struct reiserfs_dir_entry *de); 1906void set_de_name_and_namelen(struct reiserfs_dir_entry *de);
1907int search_by_entry_key(struct super_block *sb, const struct cpu_key *key, 1907int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
1908 struct path *path, struct reiserfs_dir_entry *de); 1908 struct treepath *path, struct reiserfs_dir_entry *de);
1909struct dentry *reiserfs_get_parent(struct dentry *); 1909struct dentry *reiserfs_get_parent(struct dentry *);
1910/* procfs.c */ 1910/* procfs.c */
1911 1911
@@ -1956,9 +1956,9 @@ extern const struct file_operations reiserfs_dir_operations;
1956 1956
1957/* tail_conversion.c */ 1957/* tail_conversion.c */
1958int direct2indirect(struct reiserfs_transaction_handle *, struct inode *, 1958int direct2indirect(struct reiserfs_transaction_handle *, struct inode *,
1959 struct path *, struct buffer_head *, loff_t); 1959 struct treepath *, struct buffer_head *, loff_t);
1960int indirect2direct(struct reiserfs_transaction_handle *, struct inode *, 1960int indirect2direct(struct reiserfs_transaction_handle *, struct inode *,
1961 struct page *, struct path *, const struct cpu_key *, 1961 struct page *, struct treepath *, const struct cpu_key *,
1962 loff_t, char *); 1962 loff_t, char *);
1963void reiserfs_unmap_buffer(struct buffer_head *); 1963void reiserfs_unmap_buffer(struct buffer_head *);
1964 1964
@@ -2045,7 +2045,7 @@ struct __reiserfs_blocknr_hint {
2045 struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */ 2045 struct inode *inode; /* inode passed to allocator, if we allocate unf. nodes */
2046 long block; /* file offset, in blocks */ 2046 long block; /* file offset, in blocks */
2047 struct in_core_key key; 2047 struct in_core_key key;
2048 struct path *path; /* search path, used by allocator to deternine search_start by 2048 struct treepath *path; /* search path, used by allocator to deternine search_start by
2049 * various ways */ 2049 * various ways */
2050 struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and 2050 struct reiserfs_transaction_handle *th; /* transaction handle is needed to log super blocks and
2051 * bitmap blocks changes */ 2051 * bitmap blocks changes */
@@ -2101,7 +2101,7 @@ static inline int reiserfs_new_form_blocknrs(struct tree_balance *tb,
2101static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle 2101static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2102 *th, struct inode *inode, 2102 *th, struct inode *inode,
2103 b_blocknr_t * new_blocknrs, 2103 b_blocknr_t * new_blocknrs,
2104 struct path *path, long block) 2104 struct treepath *path, long block)
2105{ 2105{
2106 reiserfs_blocknr_hint_t hint = { 2106 reiserfs_blocknr_hint_t hint = {
2107 .th = th, 2107 .th = th,
@@ -2118,7 +2118,7 @@ static inline int reiserfs_new_unf_blocknrs(struct reiserfs_transaction_handle
2118static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle 2118static inline int reiserfs_new_unf_blocknrs2(struct reiserfs_transaction_handle
2119 *th, struct inode *inode, 2119 *th, struct inode *inode,
2120 b_blocknr_t * new_blocknrs, 2120 b_blocknr_t * new_blocknrs,
2121 struct path *path, long block) 2121 struct treepath *path, long block)
2122{ 2122{
2123 reiserfs_blocknr_hint_t hint = { 2123 reiserfs_blocknr_hint_t hint = {
2124 .th = th, 2124 .th = th,
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 09ff4c3e2713..5e22d4510d11 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -106,6 +106,7 @@ extern int rtc_year_days(unsigned int day, unsigned int month, unsigned int year
106extern int rtc_valid_tm(struct rtc_time *tm); 106extern int rtc_valid_tm(struct rtc_time *tm);
107extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time); 107extern int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
108extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm); 108extern void rtc_time_to_tm(unsigned long time, struct rtc_time *tm);
109extern void rtc_merge_alarm(struct rtc_time *now, struct rtc_time *alarm);
109 110
110#include <linux/device.h> 111#include <linux/device.h>
111#include <linux/seq_file.h> 112#include <linux/seq_file.h>
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 493297acdae8..4a629ea70cc4 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -3,6 +3,8 @@
3 3
4#include <linux/netlink.h> 4#include <linux/netlink.h>
5#include <linux/if_link.h> 5#include <linux/if_link.h>
6#include <linux/if_addr.h>
7#include <linux/neighbour.h>
6 8
7/**** 9/****
8 * Routing/neighbour discovery messages. 10 * Routing/neighbour discovery messages.
diff --git a/include/linux/sched.h b/include/linux/sched.h
index dede82c63445..ea92e5c89089 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -82,6 +82,7 @@ struct sched_param {
82#include <linux/resource.h> 82#include <linux/resource.h>
83#include <linux/timer.h> 83#include <linux/timer.h>
84#include <linux/hrtimer.h> 84#include <linux/hrtimer.h>
85#include <linux/task_io_accounting.h>
85 86
86#include <asm/processor.h> 87#include <asm/processor.h>
87 88
@@ -436,7 +437,12 @@ struct signal_struct {
436 /* job control IDs */ 437 /* job control IDs */
437 pid_t pgrp; 438 pid_t pgrp;
438 pid_t tty_old_pgrp; 439 pid_t tty_old_pgrp;
439 pid_t session; 440
441 union {
442 pid_t session __deprecated;
443 pid_t __session;
444 };
445
440 /* boolean value for session group leader */ 446 /* boolean value for session group leader */
441 int leader; 447 int leader;
442 448
@@ -642,6 +648,7 @@ enum idle_type
642#define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */ 648#define SD_SHARE_CPUPOWER 128 /* Domain members share cpu power */
643#define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */ 649#define SD_POWERSAVINGS_BALANCE 256 /* Balance for power savings */
644#define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */ 650#define SD_SHARE_PKG_RESOURCES 512 /* Domain members share cpu pkg resources */
651#define SD_SERIALIZE 1024 /* Only a single load balancing instance */
645 652
646#define BALANCE_FOR_MC_POWER \ 653#define BALANCE_FOR_MC_POWER \
647 (sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0) 654 (sched_smt_power_savings ? SD_POWERSAVINGS_BALANCE : 0)
@@ -1008,6 +1015,7 @@ struct task_struct {
1008 wait_queue_t *io_wait; 1015 wait_queue_t *io_wait;
1009/* i/o counters(bytes read/written, #syscalls */ 1016/* i/o counters(bytes read/written, #syscalls */
1010 u64 rchar, wchar, syscr, syscw; 1017 u64 rchar, wchar, syscr, syscw;
1018 struct task_io_accounting ioac;
1011#if defined(CONFIG_TASK_XACCT) 1019#if defined(CONFIG_TASK_XACCT)
1012 u64 acct_rss_mem1; /* accumulated rss usage */ 1020 u64 acct_rss_mem1; /* accumulated rss usage */
1013 u64 acct_vm_mem1; /* accumulated virtual memory usage */ 1021 u64 acct_vm_mem1; /* accumulated virtual memory usage */
@@ -1040,6 +1048,9 @@ struct task_struct {
1040#ifdef CONFIG_TASK_DELAY_ACCT 1048#ifdef CONFIG_TASK_DELAY_ACCT
1041 struct task_delay_info *delays; 1049 struct task_delay_info *delays;
1042#endif 1050#endif
1051#ifdef CONFIG_FAULT_INJECTION
1052 int make_it_fail;
1053#endif
1043}; 1054};
1044 1055
1045static inline pid_t process_group(struct task_struct *tsk) 1056static inline pid_t process_group(struct task_struct *tsk)
@@ -1047,6 +1058,21 @@ static inline pid_t process_group(struct task_struct *tsk)
1047 return tsk->signal->pgrp; 1058 return tsk->signal->pgrp;
1048} 1059}
1049 1060
1061static inline pid_t signal_session(struct signal_struct *sig)
1062{
1063 return sig->__session;
1064}
1065
1066static inline pid_t process_session(struct task_struct *tsk)
1067{
1068 return signal_session(tsk->signal);
1069}
1070
1071static inline void set_signal_session(struct signal_struct *sig, pid_t session)
1072{
1073 sig->__session = session;
1074}
1075
1050static inline struct pid *task_pid(struct task_struct *task) 1076static inline struct pid *task_pid(struct task_struct *task)
1051{ 1077{
1052 return task->pids[PIDTYPE_PID].pid; 1078 return task->pids[PIDTYPE_PID].pid;
@@ -1240,7 +1266,6 @@ extern struct mm_struct init_mm;
1240 1266
1241#define find_task_by_pid(nr) find_task_by_pid_type(PIDTYPE_PID, nr) 1267#define find_task_by_pid(nr) find_task_by_pid_type(PIDTYPE_PID, nr)
1242extern struct task_struct *find_task_by_pid_type(int type, int pid); 1268extern struct task_struct *find_task_by_pid_type(int type, int pid);
1243extern void set_special_pids(pid_t session, pid_t pgrp);
1244extern void __set_special_pids(pid_t session, pid_t pgrp); 1269extern void __set_special_pids(pid_t session, pid_t pgrp);
1245 1270
1246/* per-UID process charging. */ 1271/* per-UID process charging. */
@@ -1381,7 +1406,6 @@ extern NORET_TYPE void do_group_exit(int);
1381extern void daemonize(const char *, ...); 1406extern void daemonize(const char *, ...);
1382extern int allow_signal(int); 1407extern int allow_signal(int);
1383extern int disallow_signal(int); 1408extern int disallow_signal(int);
1384extern struct task_struct *child_reaper;
1385 1409
1386extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *); 1410extern int do_execve(char *, char __user * __user *, char __user * __user *, struct pt_regs *);
1387extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *); 1411extern long do_fork(unsigned long, unsigned long, struct pt_regs *, unsigned long, int __user *, int __user *);
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 46000936f8f1..6b0648cfdffc 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -44,8 +44,11 @@ typedef struct {
44#define SEQLOCK_UNLOCKED \ 44#define SEQLOCK_UNLOCKED \
45 __SEQLOCK_UNLOCKED(old_style_seqlock_init) 45 __SEQLOCK_UNLOCKED(old_style_seqlock_init)
46 46
47#define seqlock_init(x) \ 47#define seqlock_init(x) \
48 do { *(x) = (seqlock_t) __SEQLOCK_UNLOCKED(x); } while (0) 48 do { \
49 (x)->sequence = 0; \
50 spin_lock_init(&(x)->lock); \
51 } while (0)
49 52
50#define DEFINE_SEQLOCK(x) \ 53#define DEFINE_SEQLOCK(x) \
51 seqlock_t x = __SEQLOCK_UNLOCKED(x) 54 seqlock_t x = __SEQLOCK_UNLOCKED(x)
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 827672136646..cf23813cbec2 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -166,8 +166,8 @@ struct uart_ops {
166 void (*break_ctl)(struct uart_port *, int ctl); 166 void (*break_ctl)(struct uart_port *, int ctl);
167 int (*startup)(struct uart_port *); 167 int (*startup)(struct uart_port *);
168 void (*shutdown)(struct uart_port *); 168 void (*shutdown)(struct uart_port *);
169 void (*set_termios)(struct uart_port *, struct termios *new, 169 void (*set_termios)(struct uart_port *, struct ktermios *new,
170 struct termios *old); 170 struct ktermios *old);
171 void (*pm)(struct uart_port *, unsigned int state, 171 void (*pm)(struct uart_port *, unsigned int state,
172 unsigned int oldstate); 172 unsigned int oldstate);
173 int (*set_wake)(struct uart_port *, unsigned int state); 173 int (*set_wake)(struct uart_port *, unsigned int state);
@@ -361,8 +361,8 @@ void uart_write_wakeup(struct uart_port *port);
361 */ 361 */
362void uart_update_timeout(struct uart_port *port, unsigned int cflag, 362void uart_update_timeout(struct uart_port *port, unsigned int cflag,
363 unsigned int baud); 363 unsigned int baud);
364unsigned int uart_get_baud_rate(struct uart_port *port, struct termios *termios, 364unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
365 struct termios *old, unsigned int min, 365 struct ktermios *old, unsigned int min,
366 unsigned int max); 366 unsigned int max);
367unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); 367unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud);
368 368
diff --git a/include/linux/serio.h b/include/linux/serio.h
index b99c5ca9708d..0f478a8791a2 100644
--- a/include/linux/serio.h
+++ b/include/linux/serio.h
@@ -85,18 +85,8 @@ static inline void serio_register_port(struct serio *serio)
85 85
86void serio_unregister_port(struct serio *serio); 86void serio_unregister_port(struct serio *serio);
87void serio_unregister_child_port(struct serio *serio); 87void serio_unregister_child_port(struct serio *serio);
88void __serio_unregister_port_delayed(struct serio *serio, struct module *owner);
89static inline void serio_unregister_port_delayed(struct serio *serio)
90{
91 __serio_unregister_port_delayed(serio, THIS_MODULE);
92}
93
94void __serio_register_driver(struct serio_driver *drv, struct module *owner);
95static inline void serio_register_driver(struct serio_driver *drv)
96{
97 __serio_register_driver(drv, THIS_MODULE);
98}
99 88
89int serio_register_driver(struct serio_driver *drv);
100void serio_unregister_driver(struct serio_driver *drv); 90void serio_unregister_driver(struct serio_driver *drv);
101 91
102static inline int serio_write(struct serio *serio, unsigned char data) 92static inline int serio_write(struct serio *serio, unsigned char data)
diff --git a/include/linux/stallion.h b/include/linux/stallion.h
index 13a37f137ea2..4a0a329beafb 100644
--- a/include/linux/stallion.h
+++ b/include/linux/stallion.h
@@ -52,11 +52,11 @@
52 * protection - since "write" code only needs to change the head, and 52 * protection - since "write" code only needs to change the head, and
53 * interrupt code only needs to change the tail. 53 * interrupt code only needs to change the tail.
54 */ 54 */
55typedef struct { 55struct stlrq {
56 char *buf; 56 char *buf;
57 char *head; 57 char *head;
58 char *tail; 58 char *tail;
59} stlrq_t; 59};
60 60
61/* 61/*
62 * Port, panel and board structures to hold status info about each. 62 * Port, panel and board structures to hold status info about each.
@@ -67,14 +67,14 @@ typedef struct {
67 * is associated with, this makes it (fairly) easy to get back to the 67 * is associated with, this makes it (fairly) easy to get back to the
68 * board/panel info for a port. 68 * board/panel info for a port.
69 */ 69 */
70typedef struct stlport { 70struct stlport {
71 unsigned long magic; 71 unsigned long magic;
72 int portnr; 72 unsigned int portnr;
73 int panelnr; 73 unsigned int panelnr;
74 int brdnr; 74 unsigned int brdnr;
75 int ioaddr; 75 int ioaddr;
76 int uartaddr; 76 int uartaddr;
77 int pagenr; 77 unsigned int pagenr;
78 long istate; 78 long istate;
79 int flags; 79 int flags;
80 int baud_base; 80 int baud_base;
@@ -97,31 +97,31 @@ typedef struct stlport {
97 wait_queue_head_t close_wait; 97 wait_queue_head_t close_wait;
98 struct work_struct tqueue; 98 struct work_struct tqueue;
99 comstats_t stats; 99 comstats_t stats;
100 stlrq_t tx; 100 struct stlrq tx;
101} stlport_t; 101};
102 102
103typedef struct stlpanel { 103struct stlpanel {
104 unsigned long magic; 104 unsigned long magic;
105 int panelnr; 105 unsigned int panelnr;
106 int brdnr; 106 unsigned int brdnr;
107 int pagenr; 107 unsigned int pagenr;
108 int nrports; 108 unsigned int nrports;
109 int iobase; 109 int iobase;
110 void *uartp; 110 void *uartp;
111 void (*isr)(struct stlpanel *panelp, unsigned int iobase); 111 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
112 unsigned int hwid; 112 unsigned int hwid;
113 unsigned int ackmask; 113 unsigned int ackmask;
114 stlport_t *ports[STL_PORTSPERPANEL]; 114 struct stlport *ports[STL_PORTSPERPANEL];
115} stlpanel_t; 115};
116 116
117typedef struct stlbrd { 117struct stlbrd {
118 unsigned long magic; 118 unsigned long magic;
119 int brdnr; 119 unsigned int brdnr;
120 int brdtype; 120 unsigned int brdtype;
121 int state; 121 unsigned int state;
122 int nrpanels; 122 unsigned int nrpanels;
123 int nrports; 123 unsigned int nrports;
124 int nrbnks; 124 unsigned int nrbnks;
125 int irq; 125 int irq;
126 int irqtype; 126 int irqtype;
127 int (*isr)(struct stlbrd *brdp); 127 int (*isr)(struct stlbrd *brdp);
@@ -136,9 +136,9 @@ typedef struct stlbrd {
136 unsigned long clk; 136 unsigned long clk;
137 unsigned int bnkpageaddr[STL_MAXBANKS]; 137 unsigned int bnkpageaddr[STL_MAXBANKS];
138 unsigned int bnkstataddr[STL_MAXBANKS]; 138 unsigned int bnkstataddr[STL_MAXBANKS];
139 stlpanel_t *bnk2panel[STL_MAXBANKS]; 139 struct stlpanel *bnk2panel[STL_MAXBANKS];
140 stlpanel_t *panels[STL_MAXPANELS]; 140 struct stlpanel *panels[STL_MAXPANELS];
141} stlbrd_t; 141};
142 142
143 143
144/* 144/*
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 94316a98e0d0..6d8846e7be6d 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -918,8 +918,7 @@ typedef struct ctl_table ctl_table;
918 918
919typedef int ctl_handler (ctl_table *table, int __user *name, int nlen, 919typedef int ctl_handler (ctl_table *table, int __user *name, int nlen,
920 void __user *oldval, size_t __user *oldlenp, 920 void __user *oldval, size_t __user *oldlenp,
921 void __user *newval, size_t newlen, 921 void __user *newval, size_t newlen);
922 void **context);
923 922
924typedef int proc_handler (ctl_table *ctl, int write, struct file * filp, 923typedef int proc_handler (ctl_table *ctl, int write, struct file * filp,
925 void __user *buffer, size_t *lenp, loff_t *ppos); 924 void __user *buffer, size_t *lenp, loff_t *ppos);
@@ -950,7 +949,7 @@ extern int do_sysctl (int __user *name, int nlen,
950extern int do_sysctl_strategy (ctl_table *table, 949extern int do_sysctl_strategy (ctl_table *table,
951 int __user *name, int nlen, 950 int __user *name, int nlen,
952 void __user *oldval, size_t __user *oldlenp, 951 void __user *oldval, size_t __user *oldlenp,
953 void __user *newval, size_t newlen, void ** context); 952 void __user *newval, size_t newlen);
954 953
955extern ctl_handler sysctl_string; 954extern ctl_handler sysctl_string;
956extern ctl_handler sysctl_intvec; 955extern ctl_handler sysctl_intvec;
diff --git a/include/linux/task_io_accounting.h b/include/linux/task_io_accounting.h
new file mode 100644
index 000000000000..44d00e9cceea
--- /dev/null
+++ b/include/linux/task_io_accounting.h
@@ -0,0 +1,37 @@
1/*
2 * task_io_accounting: a structure which is used for recording a single task's
3 * IO statistics.
4 *
5 * Don't include this header file directly - it is designed to be dragged in via
6 * sched.h.
7 *
8 * Blame akpm@osdl.org for all this.
9 */
10
11#ifdef CONFIG_TASK_IO_ACCOUNTING
12struct task_io_accounting {
13 /*
14 * The number of bytes which this task has caused to be read from
15 * storage.
16 */
17 u64 read_bytes;
18
19 /*
20 * The number of bytes which this task has caused, or shall cause to be
21 * written to disk.
22 */
23 u64 write_bytes;
24
25 /*
26 * A task can cause "negative" IO too. If this task truncates some
27 * dirty pagecache, some IO which another task has been accounted for
28 * (in its write_bytes) will not be happening. We _could_ just
29 * subtract that from the truncating task's write_bytes, but there is
30 * information loss in doing that.
31 */
32 u64 cancelled_write_bytes;
33};
34#else
35struct task_io_accounting {
36};
37#endif
diff --git a/include/linux/task_io_accounting_ops.h b/include/linux/task_io_accounting_ops.h
new file mode 100644
index 000000000000..df2a319106b2
--- /dev/null
+++ b/include/linux/task_io_accounting_ops.h
@@ -0,0 +1,47 @@
1/*
2 * Task I/O accounting operations
3 */
4#ifndef __TASK_IO_ACCOUNTING_OPS_INCLUDED
5#define __TASK_IO_ACCOUNTING_OPS_INCLUDED
6
7#ifdef CONFIG_TASK_IO_ACCOUNTING
8static inline void task_io_account_read(size_t bytes)
9{
10 current->ioac.read_bytes += bytes;
11}
12
13static inline void task_io_account_write(size_t bytes)
14{
15 current->ioac.write_bytes += bytes;
16}
17
18static inline void task_io_account_cancelled_write(size_t bytes)
19{
20 current->ioac.cancelled_write_bytes += bytes;
21}
22
23static inline void task_io_accounting_init(struct task_struct *tsk)
24{
25 memset(&tsk->ioac, 0, sizeof(tsk->ioac));
26}
27
28#else
29
30static inline void task_io_account_read(size_t bytes)
31{
32}
33
34static inline void task_io_account_write(size_t bytes)
35{
36}
37
38static inline void task_io_account_cancelled_write(size_t bytes)
39{
40}
41
42static inline void task_io_accounting_init(struct task_struct *tsk)
43{
44}
45
46#endif /* CONFIG_TASK_IO_ACCOUNTING */
47#endif /* __TASK_IO_ACCOUNTING_OPS_INCLUDED */
diff --git a/include/linux/taskstats.h b/include/linux/taskstats.h
index 45248806ae9c..3fced4798255 100644
--- a/include/linux/taskstats.h
+++ b/include/linux/taskstats.h
@@ -31,7 +31,7 @@
31 */ 31 */
32 32
33 33
34#define TASKSTATS_VERSION 2 34#define TASKSTATS_VERSION 3
35#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN 35#define TS_COMM_LEN 32 /* should be >= TASK_COMM_LEN
36 * in linux/sched.h */ 36 * in linux/sched.h */
37 37
@@ -115,31 +115,37 @@ struct taskstats {
115 __u64 ac_majflt; /* Major Page Fault Count */ 115 __u64 ac_majflt; /* Major Page Fault Count */
116 /* Basic Accounting Fields end */ 116 /* Basic Accounting Fields end */
117 117
118 /* Extended accounting fields start */ 118 /* Extended accounting fields start */
119 /* Accumulated RSS usage in duration of a task, in MBytes-usecs. 119 /* Accumulated RSS usage in duration of a task, in MBytes-usecs.
120 * The current rss usage is added to this counter every time 120 * The current rss usage is added to this counter every time
121 * a tick is charged to a task's system time. So, at the end we 121 * a tick is charged to a task's system time. So, at the end we
122 * will have memory usage multiplied by system time. Thus an 122 * will have memory usage multiplied by system time. Thus an
123 * average usage per system time unit can be calculated. 123 * average usage per system time unit can be calculated.
124 */ 124 */
125 __u64 coremem; /* accumulated RSS usage in MB-usec */ 125 __u64 coremem; /* accumulated RSS usage in MB-usec */
126 /* Accumulated virtual memory usage in duration of a task. 126 /* Accumulated virtual memory usage in duration of a task.
127 * Same as acct_rss_mem1 above except that we keep track of VM usage. 127 * Same as acct_rss_mem1 above except that we keep track of VM usage.
128 */ 128 */
129 __u64 virtmem; /* accumulated VM usage in MB-usec */ 129 __u64 virtmem; /* accumulated VM usage in MB-usec */
130 130
131 /* High watermark of RSS and virtual memory usage in duration of 131 /* High watermark of RSS and virtual memory usage in duration of
132 * a task, in KBytes. 132 * a task, in KBytes.
133 */ 133 */
134 __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */ 134 __u64 hiwater_rss; /* High-watermark of RSS usage, in KB */
135 __u64 hiwater_vm; /* High-water VM usage, in KB */ 135 __u64 hiwater_vm; /* High-water VM usage, in KB */
136 136
137 /* The following four fields are I/O statistics of a task. */ 137 /* The following four fields are I/O statistics of a task. */
138 __u64 read_char; /* bytes read */ 138 __u64 read_char; /* bytes read */
139 __u64 write_char; /* bytes written */ 139 __u64 write_char; /* bytes written */
140 __u64 read_syscalls; /* read syscalls */ 140 __u64 read_syscalls; /* read syscalls */
141 __u64 write_syscalls; /* write syscalls */ 141 __u64 write_syscalls; /* write syscalls */
142 /* Extended accounting fields end */ 142 /* Extended accounting fields end */
143
144#define TASKSTATS_HAS_IO_ACCOUNTING
145 /* Per-task storage I/O accounting starts */
146 __u64 read_bytes; /* bytes of read I/O */
147 __u64 write_bytes; /* bytes of write I/O */
148 __u64 cancelled_write_bytes; /* bytes of cancelled write I/O */
143}; 149};
144 150
145 151
diff --git a/include/linux/tfrc.h b/include/linux/tfrc.h
index 31a9b25276fe..8a8462b4a4dd 100644
--- a/include/linux/tfrc.h
+++ b/include/linux/tfrc.h
@@ -37,10 +37,14 @@ struct tfrc_rx_info {
37 * @tfrctx_p: current loss event rate (5.4) 37 * @tfrctx_p: current loss event rate (5.4)
38 * @tfrctx_rto: estimate of RTO, equals 4*RTT (4.3) 38 * @tfrctx_rto: estimate of RTO, equals 4*RTT (4.3)
39 * @tfrctx_ipi: inter-packet interval (4.6) 39 * @tfrctx_ipi: inter-packet interval (4.6)
40 *
41 * Note: X and X_recv are both maintained in units of 64 * bytes/second. This
42 * enables a finer resolution of sending rates and avoids problems with
43 * integer arithmetic; u32 is not sufficient as scaling consumes 6 bits.
40 */ 44 */
41struct tfrc_tx_info { 45struct tfrc_tx_info {
42 __u32 tfrctx_x; 46 __u64 tfrctx_x;
43 __u32 tfrctx_x_recv; 47 __u64 tfrctx_x_recv;
44 __u32 tfrctx_x_calc; 48 __u32 tfrctx_x_calc;
45 __u32 tfrctx_rtt; 49 __u32 tfrctx_rtt;
46 __u32 tfrctx_p; 50 __u32 tfrctx_p;
diff --git a/include/linux/timer.h b/include/linux/timer.h
index c982304dbafd..eeef6643d4c6 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -98,4 +98,10 @@ extern void run_local_timers(void);
98struct hrtimer; 98struct hrtimer;
99extern int it_real_fn(struct hrtimer *); 99extern int it_real_fn(struct hrtimer *);
100 100
101unsigned long __round_jiffies(unsigned long j, int cpu);
102unsigned long __round_jiffies_relative(unsigned long j, int cpu);
103unsigned long round_jiffies(unsigned long j);
104unsigned long round_jiffies_relative(unsigned long j);
105
106
101#endif 107#endif
diff --git a/include/linux/topology.h b/include/linux/topology.h
index da508d1998e4..6c5a6e6e813b 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -93,7 +93,7 @@
93 .groups = NULL, \ 93 .groups = NULL, \
94 .min_interval = 1, \ 94 .min_interval = 1, \
95 .max_interval = 2, \ 95 .max_interval = 2, \
96 .busy_factor = 8, \ 96 .busy_factor = 64, \
97 .imbalance_pct = 110, \ 97 .imbalance_pct = 110, \
98 .cache_nice_tries = 0, \ 98 .cache_nice_tries = 0, \
99 .per_cpu_gain = 25, \ 99 .per_cpu_gain = 25, \
@@ -194,7 +194,8 @@
194 .wake_idx = 0, /* unused */ \ 194 .wake_idx = 0, /* unused */ \
195 .forkexec_idx = 0, /* unused */ \ 195 .forkexec_idx = 0, /* unused */ \
196 .per_cpu_gain = 100, \ 196 .per_cpu_gain = 100, \
197 .flags = SD_LOAD_BALANCE, \ 197 .flags = SD_LOAD_BALANCE \
198 | SD_SERIALIZE, \
198 .last_balance = jiffies, \ 199 .last_balance = jiffies, \
199 .balance_interval = 64, \ 200 .balance_interval = 64, \
200 .nr_balance_failed = 0, \ 201 .nr_balance_failed = 0, \
diff --git a/include/linux/tty.h b/include/linux/tty.h
index f717f0898238..65cbcf22c31e 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -175,7 +175,7 @@ struct tty_struct {
175 int index; 175 int index;
176 struct tty_ldisc ldisc; 176 struct tty_ldisc ldisc;
177 struct mutex termios_mutex; 177 struct mutex termios_mutex;
178 struct termios *termios, *termios_locked; 178 struct ktermios *termios, *termios_locked;
179 char name[64]; 179 char name[64];
180 int pgrp; 180 int pgrp;
181 int session; 181 int session;
@@ -258,7 +258,7 @@ struct tty_struct {
258 258
259extern void tty_write_flush(struct tty_struct *); 259extern void tty_write_flush(struct tty_struct *);
260 260
261extern struct termios tty_std_termios; 261extern struct ktermios tty_std_termios;
262 262
263extern int kmsg_redirect; 263extern int kmsg_redirect;
264 264
@@ -293,8 +293,9 @@ extern int tty_hung_up_p(struct file * filp);
293extern void do_SAK(struct tty_struct *tty); 293extern void do_SAK(struct tty_struct *tty);
294extern void disassociate_ctty(int priv); 294extern void disassociate_ctty(int priv);
295extern void tty_flip_buffer_push(struct tty_struct *tty); 295extern void tty_flip_buffer_push(struct tty_struct *tty);
296extern int tty_get_baud_rate(struct tty_struct *tty); 296extern speed_t tty_get_baud_rate(struct tty_struct *tty);
297extern int tty_termios_baud_rate(struct termios *termios); 297extern speed_t tty_termios_baud_rate(struct ktermios *termios);
298extern speed_t tty_termios_input_baud_rate(struct ktermios *termios);
298 299
299extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 300extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
300extern void tty_ldisc_deref(struct tty_ldisc *); 301extern void tty_ldisc_deref(struct tty_ldisc *);
@@ -309,6 +310,12 @@ extern void tty_ldisc_flush(struct tty_struct *tty);
309extern int tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 310extern int tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
310 unsigned long arg); 311 unsigned long arg);
311 312
313extern dev_t tty_devnum(struct tty_struct *tty);
314extern void proc_clear_tty(struct task_struct *p);
315extern void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
316extern void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
317extern struct tty_struct *get_current_tty(void);
318
312extern struct mutex tty_mutex; 319extern struct mutex tty_mutex;
313 320
314/* n_tty.c */ 321/* n_tty.c */
@@ -335,10 +342,5 @@ extern void console_print(const char *);
335extern int vt_ioctl(struct tty_struct *tty, struct file * file, 342extern int vt_ioctl(struct tty_struct *tty, struct file * file,
336 unsigned int cmd, unsigned long arg); 343 unsigned int cmd, unsigned long arg);
337 344
338static inline dev_t tty_devnum(struct tty_struct *tty)
339{
340 return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
341}
342
343#endif /* __KERNEL__ */ 345#endif /* __KERNEL__ */
344#endif 346#endif
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 5c8473bb6882..659487e3ebeb 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -53,7 +53,7 @@
53 * device-specific ioctl's. If the ioctl number passed in cmd 53 * device-specific ioctl's. If the ioctl number passed in cmd
54 * is not recognized by the driver, it should return ENOIOCTLCMD. 54 * is not recognized by the driver, it should return ENOIOCTLCMD.
55 * 55 *
56 * void (*set_termios)(struct tty_struct *tty, struct termios * old); 56 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
57 * 57 *
58 * This routine allows the tty driver to be notified when 58 * This routine allows the tty driver to be notified when
59 * device's termios settings have changed. Note that a 59 * device's termios settings have changed. Note that a
@@ -132,7 +132,7 @@ struct tty_operations {
132 int (*chars_in_buffer)(struct tty_struct *tty); 132 int (*chars_in_buffer)(struct tty_struct *tty);
133 int (*ioctl)(struct tty_struct *tty, struct file * file, 133 int (*ioctl)(struct tty_struct *tty, struct file * file,
134 unsigned int cmd, unsigned long arg); 134 unsigned int cmd, unsigned long arg);
135 void (*set_termios)(struct tty_struct *tty, struct termios * old); 135 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
136 void (*throttle)(struct tty_struct * tty); 136 void (*throttle)(struct tty_struct * tty);
137 void (*unthrottle)(struct tty_struct * tty); 137 void (*unthrottle)(struct tty_struct * tty);
138 void (*stop)(struct tty_struct *tty); 138 void (*stop)(struct tty_struct *tty);
@@ -165,7 +165,7 @@ struct tty_driver {
165 int num; /* number of devices allocated */ 165 int num; /* number of devices allocated */
166 short type; /* type of tty driver */ 166 short type; /* type of tty driver */
167 short subtype; /* subtype of tty driver */ 167 short subtype; /* subtype of tty driver */
168 struct termios init_termios; /* Initial termios */ 168 struct ktermios init_termios; /* Initial termios */
169 int flags; /* tty driver flags */ 169 int flags; /* tty driver flags */
170 int refcount; /* for loadable tty drivers */ 170 int refcount; /* for loadable tty drivers */
171 struct proc_dir_entry *proc_entry; /* /proc fs entry */ 171 struct proc_dir_entry *proc_entry; /* /proc fs entry */
@@ -175,8 +175,8 @@ struct tty_driver {
175 * Pointer to the tty data structures 175 * Pointer to the tty data structures
176 */ 176 */
177 struct tty_struct **ttys; 177 struct tty_struct **ttys;
178 struct termios **termios; 178 struct ktermios **termios;
179 struct termios **termios_locked; 179 struct ktermios **termios_locked;
180 void *driver_state; /* only used for the PTY driver */ 180 void *driver_state; /* only used for the PTY driver */
181 181
182 /* 182 /*
@@ -193,7 +193,7 @@ struct tty_driver {
193 int (*chars_in_buffer)(struct tty_struct *tty); 193 int (*chars_in_buffer)(struct tty_struct *tty);
194 int (*ioctl)(struct tty_struct *tty, struct file * file, 194 int (*ioctl)(struct tty_struct *tty, struct file * file,
195 unsigned int cmd, unsigned long arg); 195 unsigned int cmd, unsigned long arg);
196 void (*set_termios)(struct tty_struct *tty, struct termios * old); 196 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
197 void (*throttle)(struct tty_struct * tty); 197 void (*throttle)(struct tty_struct * tty);
198 void (*unthrottle)(struct tty_struct * tty); 198 void (*unthrottle)(struct tty_struct * tty);
199 void (*stop)(struct tty_struct *tty); 199 void (*stop)(struct tty_struct *tty);
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 83c6e6c10ebb..d75932e27710 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -59,7 +59,7 @@
59 * low-level driver can "grab" an ioctl request before the line 59 * low-level driver can "grab" an ioctl request before the line
60 * discpline has a chance to see it. 60 * discpline has a chance to see it.
61 * 61 *
62 * void (*set_termios)(struct tty_struct *tty, struct termios * old); 62 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
63 * 63 *
64 * This function notifies the line discpline that a change has 64 * This function notifies the line discpline that a change has
65 * been made to the termios structure. 65 * been made to the termios structure.
@@ -118,7 +118,7 @@ struct tty_ldisc {
118 const unsigned char * buf, size_t nr); 118 const unsigned char * buf, size_t nr);
119 int (*ioctl)(struct tty_struct * tty, struct file * file, 119 int (*ioctl)(struct tty_struct * tty, struct file * file,
120 unsigned int cmd, unsigned long arg); 120 unsigned int cmd, unsigned long arg);
121 void (*set_termios)(struct tty_struct *tty, struct termios * old); 121 void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
122 unsigned int (*poll)(struct tty_struct *, struct file *, 122 unsigned int (*poll)(struct tty_struct *, struct file *,
123 struct poll_table_struct *); 123 struct poll_table_struct *);
124 int (*hangup)(struct tty_struct *tty); 124 int (*hangup)(struct tty_struct *tty);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 91b3ea2bbb14..10f99e5f1a97 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -218,7 +218,7 @@ struct usb_serial_driver {
218 int (*write) (struct usb_serial_port *port, const unsigned char *buf, int count); 218 int (*write) (struct usb_serial_port *port, const unsigned char *buf, int count);
219 int (*write_room) (struct usb_serial_port *port); 219 int (*write_room) (struct usb_serial_port *port);
220 int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg); 220 int (*ioctl) (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
221 void (*set_termios) (struct usb_serial_port *port, struct termios * old); 221 void (*set_termios) (struct usb_serial_port *port, struct ktermios * old);
222 void (*break_ctl) (struct usb_serial_port *port, int break_state); 222 void (*break_ctl) (struct usb_serial_port *port, int break_state);
223 int (*chars_in_buffer) (struct usb_serial_port *port); 223 int (*chars_in_buffer) (struct usb_serial_port *port);
224 void (*throttle) (struct usb_serial_port *port); 224 void (*throttle) (struct usb_serial_port *port);
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index df5c4654360d..5cb380a559fd 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -244,6 +244,7 @@ struct v4l2_pix_format
244#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */ 244#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */
245#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */ 245#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */
246#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H','M','1','2') /* 8 YUV 4:2:0 16x16 macroblocks */ 246#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H','M','1','2') /* 8 YUV 4:2:0 16x16 macroblocks */
247#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R','4','4','4') /* 16 xxxxrrrr ggggbbbb */
247 248
248/* see http://www.siliconimaging.com/RGB%20Bayer.htm */ 249/* see http://www.siliconimaging.com/RGB%20Bayer.htm */
249#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */ 250#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
index 088ba8113f7e..9529ea1ae392 100644
--- a/include/linux/xfrm.h
+++ b/include/linux/xfrm.h
@@ -357,7 +357,7 @@ struct xfrm_user_report {
357#define XFRMGRP_EXPIRE 2 357#define XFRMGRP_EXPIRE 2
358#define XFRMGRP_SA 4 358#define XFRMGRP_SA 4
359#define XFRMGRP_POLICY 8 359#define XFRMGRP_POLICY 8
360#define XFRMGRP_REPORT 0x10 360#define XFRMGRP_REPORT 0x20
361#endif 361#endif
362 362
363enum xfrm_nlgroups { 363enum xfrm_nlgroups {
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index 8f58406533c6..2b25f5c95006 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -92,6 +92,7 @@ extern IR_KEYTAB_TYPE ir_codes_hauppauge_new[IR_KEYTAB_SIZE];
92extern IR_KEYTAB_TYPE ir_codes_npgtech[IR_KEYTAB_SIZE]; 92extern IR_KEYTAB_TYPE ir_codes_npgtech[IR_KEYTAB_SIZE];
93extern IR_KEYTAB_TYPE ir_codes_norwood[IR_KEYTAB_SIZE]; 93extern IR_KEYTAB_TYPE ir_codes_norwood[IR_KEYTAB_SIZE];
94extern IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE]; 94extern IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE];
95extern IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE];
95 96
96#endif 97#endif
97 98
diff --git a/include/media/saa7146.h b/include/media/saa7146.h
index fee579f10b32..796bcf151a3a 100644
--- a/include/media/saa7146.h
+++ b/include/media/saa7146.h
@@ -42,10 +42,6 @@ extern unsigned int saa7146_debug;
42#define DEB_INT(x) if (0!=(DEBUG_VARIABLE&0x20)) { DEBUG_PROLOG; printk x; } /* interrupt debug messages */ 42#define DEB_INT(x) if (0!=(DEBUG_VARIABLE&0x20)) { DEBUG_PROLOG; printk x; } /* interrupt debug messages */
43#define DEB_CAP(x) if (0!=(DEBUG_VARIABLE&0x40)) { DEBUG_PROLOG; printk x; } /* capture debug messages */ 43#define DEB_CAP(x) if (0!=(DEBUG_VARIABLE&0x40)) { DEBUG_PROLOG; printk x; } /* capture debug messages */
44 44
45#define SAA7146_IER_DISABLE(x,y) \
46 saa7146_write(x, IER, saa7146_read(x, IER) & ~(y));
47#define SAA7146_IER_ENABLE(x,y) \
48 saa7146_write(x, IER, saa7146_read(x, IER) | (y));
49#define SAA7146_ISR_CLEAR(x,y) \ 45#define SAA7146_ISR_CLEAR(x,y) \
50 saa7146_write(x, ISR, (y)); 46 saa7146_write(x, ISR, (y));
51 47
@@ -441,4 +437,20 @@ int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop);
441#define SAA7146_I2C_BUS_BIT_RATE_80 (0x200) 437#define SAA7146_I2C_BUS_BIT_RATE_80 (0x200)
442#define SAA7146_I2C_BUS_BIT_RATE_60 (0x300) 438#define SAA7146_I2C_BUS_BIT_RATE_60 (0x300)
443 439
440static inline void SAA7146_IER_DISABLE(struct saa7146_dev *x, unsigned y)
441{
442 unsigned long flags;
443 spin_lock_irqsave(&x->int_slock, flags);
444 saa7146_write(x, IER, saa7146_read(x, IER) & ~y);
445 spin_unlock_irqrestore(&x->int_slock, flags);
446}
447
448static inline void SAA7146_IER_ENABLE(struct saa7146_dev *x, unsigned y)
449{
450 unsigned long flags;
451 spin_lock_irqsave(&x->int_slock, flags);
452 saa7146_write(x, IER, saa7146_read(x, IER) | y);
453 spin_unlock_irqrestore(&x->int_slock, flags);
454}
455
444#endif 456#endif
diff --git a/include/media/tuner-types.h b/include/media/tuner-types.h
index 37dad07a8439..e5ad3fcfe984 100644
--- a/include/media/tuner-types.h
+++ b/include/media/tuner-types.h
@@ -50,6 +50,10 @@ struct tuner_params {
50 sensitivity. If this setting is 1, then set PORT2 to 1 to 50 sensitivity. If this setting is 1, then set PORT2 to 1 to
51 get proper FM reception. */ 51 get proper FM reception. */
52 unsigned int port2_fm_high_sensitivity:1; 52 unsigned int port2_fm_high_sensitivity:1;
53 /* Some Philips tuners use tda9887 cGainNormal to select the FM radio
54 sensitivity. If this setting is 1, e register will use cGainNormal
55 instead of cGainLow. */
56 unsigned int fm_gain_normal:1;
53 /* Most tuners with a tda9887 use QSS mode. Some (cheaper) tuners 57 /* Most tuners with a tda9887 use QSS mode. Some (cheaper) tuners
54 use Intercarrier mode. If this setting is 1, then the tuner 58 use Intercarrier mode. If this setting is 1, then the tuner
55 needs to be set to intercarrier mode. */ 59 needs to be set to intercarrier mode. */
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 3116e750132f..99acf847365c 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -145,6 +145,7 @@ extern int tuner_debug;
145#define TDA9887_DEEMPHASIS_75 (3<<16) 145#define TDA9887_DEEMPHASIS_75 (3<<16)
146#define TDA9887_AUTOMUTE (1<<18) 146#define TDA9887_AUTOMUTE (1<<18)
147#define TDA9887_GATING_18 (1<<19) 147#define TDA9887_GATING_18 (1<<19)
148#define TDA9887_GAIN_NORMAL (1<<20)
148 149
149#ifdef __KERNEL__ 150#ifdef __KERNEL__
150 151
diff --git a/include/media/tveeprom.h b/include/media/tveeprom.h
index e9fc1a785497..5660ea24996b 100644
--- a/include/media/tveeprom.h
+++ b/include/media/tveeprom.h
@@ -3,7 +3,7 @@
3 3
4struct tveeprom { 4struct tveeprom {
5 u32 has_radio; 5 u32 has_radio;
6 u32 has_ir; /* 0: no IR, 1: IR present, 2: unknown */ 6 u32 has_ir; /* bit 0: IR receiver present, bit 1: IR transmitter (blaster) present. -1 == unknown */
7 u32 has_MAC_address; /* 0: no MAC, 1: MAC present, 2: unknown */ 7 u32 has_MAC_address; /* 0: no MAC, 1: MAC present, 2: unknown */
8 8
9 u32 tuner_type; 9 u32 tuner_type;
diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h
index aecc946980a3..91b19921f958 100644
--- a/include/media/v4l2-common.h
+++ b/include/media/v4l2-common.h
@@ -144,6 +144,9 @@ enum v4l2_chip_ident {
144 V4L2_IDENT_CX25841 = 241, 144 V4L2_IDENT_CX25841 = 241,
145 V4L2_IDENT_CX25842 = 242, 145 V4L2_IDENT_CX25842 = 242,
146 V4L2_IDENT_CX25843 = 243, 146 V4L2_IDENT_CX25843 = 243,
147
148 /* OmniVision sensors - range 250-299 */
149 V4L2_IDENT_OV7670 = 250,
147}; 150};
148 151
149/* audio ioctls */ 152/* audio ioctls */
@@ -251,4 +254,8 @@ struct v4l2_crystal_freq {
251 If the frequency is not supported, then -EINVAL is returned. */ 254 If the frequency is not supported, then -EINVAL is returned. */
252#define VIDIOC_INT_S_CRYSTAL_FREQ _IOW ('d', 113, struct v4l2_crystal_freq) 255#define VIDIOC_INT_S_CRYSTAL_FREQ _IOW ('d', 113, struct v4l2_crystal_freq)
253 256
257/* Initialize the sensor registors to some sort of reasonable
258 default values. */
259#define VIDIOC_INT_INIT _IOW ('d', 114, u32)
260
254#endif /* V4L2_COMMON_H_ */ 261#endif /* V4L2_COMMON_H_ */
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 6a11d772700f..fb96472a1bd3 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -43,6 +43,7 @@
43 43
44/* Video standard functions */ 44/* Video standard functions */
45extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs); 45extern unsigned int v4l2_video_std_fps(struct v4l2_standard *vs);
46extern char *v4l2_norm_to_name(v4l2_std_id id);
46extern int v4l2_video_std_construct(struct v4l2_standard *vs, 47extern int v4l2_video_std_construct(struct v4l2_standard *vs,
47 int id, char *name); 48 int id, char *name);
48 49
@@ -81,12 +82,6 @@ extern long v4l_compat_ioctl32(struct file *file, unsigned int cmd,
81 * This version moves redundant code from video device code to 82 * This version moves redundant code from video device code to
82 * the common handler 83 * the common handler
83 */ 84 */
84struct v4l2_tvnorm {
85 char *name;
86 v4l2_std_id id;
87
88 void *priv_data;
89};
90 85
91struct video_device 86struct video_device
92{ 87{
@@ -104,9 +99,8 @@ struct video_device
104 int debug; /* Activates debug level*/ 99 int debug; /* Activates debug level*/
105 100
106 /* Video standard vars */ 101 /* Video standard vars */
107 int tvnormsize; /* Size of tvnorm array */ 102 v4l2_std_id tvnorms; /* Supported tv norms */
108 v4l2_std_id current_norm; /* Current tvnorm */ 103 v4l2_std_id current_norm; /* Current tvnorm */
109 struct v4l2_tvnorm *tvnorms;
110 104
111 /* callbacks */ 105 /* callbacks */
112 void (*release)(struct video_device *vfd); 106 void (*release)(struct video_device *vfd);
@@ -211,7 +205,7 @@ struct video_device
211 /* Standard handling 205 /* Standard handling
212 G_STD and ENUMSTD are handled by videodev.c 206 G_STD and ENUMSTD are handled by videodev.c
213 */ 207 */
214 int (*vidioc_s_std) (struct file *file, void *fh, v4l2_std_id a); 208 int (*vidioc_s_std) (struct file *file, void *fh, v4l2_std_id *norm);
215 int (*vidioc_querystd) (struct file *file, void *fh, v4l2_std_id *a); 209 int (*vidioc_querystd) (struct file *file, void *fh, v4l2_std_id *a);
216 210
217 /* Input handling */ 211 /* Input handling */
diff --git a/include/net/ax25.h b/include/net/ax25.h
index 69374cd1a857..14b72d868f03 100644
--- a/include/net/ax25.h
+++ b/include/net/ax25.h
@@ -282,15 +282,19 @@ extern void ax25_fillin_cb(ax25_cb *, ax25_dev *);
282extern struct sock *ax25_make_new(struct sock *, struct ax25_dev *); 282extern struct sock *ax25_make_new(struct sock *, struct ax25_dev *);
283 283
284/* ax25_addr.c */ 284/* ax25_addr.c */
285extern ax25_address null_ax25_address; 285extern const ax25_address ax25_bcast;
286extern char *ax2asc(char *buf, ax25_address *); 286extern const ax25_address ax25_defaddr;
287extern void asc2ax(ax25_address *addr, char *callsign); 287extern const ax25_address null_ax25_address;
288extern int ax25cmp(ax25_address *, ax25_address *); 288extern char *ax2asc(char *buf, const ax25_address *);
289extern int ax25digicmp(ax25_digi *, ax25_digi *); 289extern void asc2ax(ax25_address *addr, const char *callsign);
290extern unsigned char *ax25_addr_parse(unsigned char *, int, ax25_address *, ax25_address *, ax25_digi *, int *, int *); 290extern int ax25cmp(const ax25_address *, const ax25_address *);
291extern int ax25_addr_build(unsigned char *, ax25_address *, ax25_address *, ax25_digi *, int, int); 291extern int ax25digicmp(const ax25_digi *, const ax25_digi *);
292extern int ax25_addr_size(ax25_digi *); 292extern const unsigned char *ax25_addr_parse(const unsigned char *, int,
293extern void ax25_digi_invert(ax25_digi *, ax25_digi *); 293 ax25_address *, ax25_address *, ax25_digi *, int *, int *);
294extern int ax25_addr_build(unsigned char *, const ax25_address *,
295 const ax25_address *, const ax25_digi *, int, int);
296extern int ax25_addr_size(const ax25_digi *);
297extern void ax25_digi_invert(const ax25_digi *, ax25_digi *);
294 298
295/* ax25_dev.c */ 299/* ax25_dev.c */
296extern ax25_dev *ax25_dev_list; 300extern ax25_dev *ax25_dev_list;
diff --git a/include/net/ip.h b/include/net/ip.h
index 83cb9ac5554e..053f02b5cb89 100644
--- a/include/net/ip.h
+++ b/include/net/ip.h
@@ -376,8 +376,7 @@ int ipv4_doint_and_flush(ctl_table *ctl, int write,
376 size_t *lenp, loff_t *ppos); 376 size_t *lenp, loff_t *ppos);
377int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen, 377int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
378 void __user *oldval, size_t __user *oldlenp, 378 void __user *oldval, size_t __user *oldlenp,
379 void __user *newval, size_t newlen, 379 void __user *newval, size_t newlen);
380 void **context);
381#ifdef CONFIG_PROC_FS 380#ifdef CONFIG_PROC_FS
382extern int ip_misc_proc_init(void); 381extern int ip_misc_proc_init(void);
383#endif 382#endif
diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
index 87699cb4ef8c..8dabdd603fe1 100644
--- a/include/net/irda/ircomm_tty.h
+++ b/include/net/irda/ircomm_tty.h
@@ -126,7 +126,7 @@ extern int ircomm_tty_tiocmset(struct tty_struct *tty, struct file *file,
126extern int ircomm_tty_ioctl(struct tty_struct *tty, struct file *file, 126extern int ircomm_tty_ioctl(struct tty_struct *tty, struct file *file,
127 unsigned int cmd, unsigned long arg); 127 unsigned int cmd, unsigned long arg);
128extern void ircomm_tty_set_termios(struct tty_struct *tty, 128extern void ircomm_tty_set_termios(struct tty_struct *tty,
129 struct termios *old_termios); 129 struct ktermios *old_termios);
130extern hashbin_t *ircomm_tty; 130extern hashbin_t *ircomm_tty;
131 131
132#endif 132#endif
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 23967031ddb7..3725b93c52f3 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -309,6 +309,24 @@ static inline int neigh_event_send(struct neighbour *neigh, struct sk_buff *skb)
309 return 0; 309 return 0;
310} 310}
311 311
312static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
313{
314 unsigned seq;
315 int hh_len;
316
317 do {
318 int hh_alen;
319
320 seq = read_seqbegin(&hh->hh_lock);
321 hh_len = hh->hh_len;
322 hh_alen = HH_DATA_ALIGN(hh_len);
323 memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
324 } while (read_seqretry(&hh->hh_lock, seq));
325
326 skb_push(skb, hh_len);
327 return hh->hh_output(skb);
328}
329
312static inline struct neighbour * 330static inline struct neighbour *
313__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat) 331__neigh_lookup(struct neigh_table *tbl, const void *pkey, struct net_device *dev, int creat)
314{ 332{
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 215461f18db1..c818f87122af 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -368,7 +368,7 @@ static inline void sctp_sysctl_register(void) { return; }
368static inline void sctp_sysctl_unregister(void) { return; } 368static inline void sctp_sysctl_unregister(void) { return; }
369static inline int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen, 369static inline int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
370 void __user *oldval, size_t __user *oldlenp, 370 void __user *oldval, size_t __user *oldlenp,
371 void __user *newval, size_t newlen, void **context) { 371 void __user *newval, size_t newlen) {
372 return -ENOSYS; 372 return -ENOSYS;
373} 373}
374#endif 374#endif
diff --git a/include/video/mbxfb.h b/include/video/mbxfb.h
index 3bde0f5cd55c..20b9002712ef 100644
--- a/include/video/mbxfb.h
+++ b/include/video/mbxfb.h
@@ -1,6 +1,9 @@
1#ifndef __MBX_FB_H 1#ifndef __MBX_FB_H
2#define __MBX_FB_H 2#define __MBX_FB_H
3 3
4#include <asm/ioctl.h>
5#include <asm/types.h>
6
4struct mbxfb_val { 7struct mbxfb_val {
5 unsigned int defval; 8 unsigned int defval;
6 unsigned int min; 9 unsigned int min;
@@ -25,4 +28,32 @@ struct mbxfb_platform_data {
25 int (*remove)(struct fb_info *fb); 28 int (*remove)(struct fb_info *fb);
26}; 29};
27 30
31/* planar */
32#define MBXFB_FMT_YUV12 0
33
34/* packed */
35#define MBXFB_FMT_UY0VY1 1
36#define MBXFB_FMT_VY0UY1 2
37#define MBXFB_FMT_Y0UY1V 3
38#define MBXFB_FMT_Y0VY1U 4
39struct mbxfb_overlaySetup {
40 __u32 enable;
41 __u32 x, y;
42 __u32 width, height;
43 __u32 alpha;
44 __u32 fmt;
45 __u32 mem_offset;
46 __u32 scaled_width;
47 __u32 scaled_height;
48
49 /* Filled by the driver */
50 __u32 U_offset;
51 __u32 V_offset;
52
53 __u16 Y_stride;
54 __u16 UV_stride;
55};
56
57#define MBXFB_IOCX_OVERLAY _IOWR(0xF4, 0x00,struct mbxfb_overlaySetup)
58
28#endif /* __MBX_FB_H */ 59#endif /* __MBX_FB_H */
diff --git a/include/video/pm3fb.h b/include/video/pm3fb.h
index ac021379ac40..94c7d2da90ea 100644
--- a/include/video/pm3fb.h
+++ b/include/video/pm3fb.h
@@ -607,16 +607,16 @@
607#define PM3FBDestReadModeOr 0xac98 607#define PM3FBDestReadModeOr 0xac98
608 #define PM3FBDestReadMode_ReadDisable 0<<0 608 #define PM3FBDestReadMode_ReadDisable 0<<0
609 #define PM3FBDestReadMode_ReadEnable 1<<0 609 #define PM3FBDestReadMode_ReadEnable 1<<0
610 #define PM3FBDestReadMode_StripePitch(sp) (((sp)&0x7)<<2 610 #define PM3FBDestReadMode_StripePitch(sp) (((sp)&0x7)<<2)
611 #define PM3FBDestReadMode_StripeHeight(sh) (((sh)&0x7)<<7 611 #define PM3FBDestReadMode_StripeHeight(sh) (((sh)&0x7)<<7)
612 #define PM3FBDestReadMode_Enable0 1<<8 612 #define PM3FBDestReadMode_Enable0 1<<8
613 #define PM3FBDestReadMode_Enable1 1<<9 613 #define PM3FBDestReadMode_Enable1 1<<9
614 #define PM3FBDestReadMode_Enable2 1<<10 614 #define PM3FBDestReadMode_Enable2 1<<10
615 #define PM3FBDestReadMode_Enable3 1<<11 615 #define PM3FBDestReadMode_Enable3 1<<11
616 #define PM3FBDestReadMode_Layout0(l) (((l)&0x3)<<12 616 #define PM3FBDestReadMode_Layout0(l) (((l)&0x3)<<12)
617 #define PM3FBDestReadMode_Layout1(l) (((l)&0x3)<<14 617 #define PM3FBDestReadMode_Layout1(l) (((l)&0x3)<<14)
618 #define PM3FBDestReadMode_Layout2(l) (((l)&0x3)<<16 618 #define PM3FBDestReadMode_Layout2(l) (((l)&0x3)<<16)
619 #define PM3FBDestReadMode_Layout3(l) (((l)&0x3)<<18 619 #define PM3FBDestReadMode_Layout3(l) (((l)&0x3)<<18)
620 #define PM3FBDestReadMode_Origin0 1<<20 620 #define PM3FBDestReadMode_Origin0 1<<20
621 #define PM3FBDestReadMode_Origin1 1<<21 621 #define PM3FBDestReadMode_Origin1 1<<21
622 #define PM3FBDestReadMode_Origin2 1<<22 622 #define PM3FBDestReadMode_Origin2 1<<22
@@ -640,16 +640,16 @@
640#define PM3FBSourceReadModeOr 0xaca8 640#define PM3FBSourceReadModeOr 0xaca8
641 #define PM3FBSourceReadMode_ReadDisable (0<<0) 641 #define PM3FBSourceReadMode_ReadDisable (0<<0)
642 #define PM3FBSourceReadMode_ReadEnable (1<<0) 642 #define PM3FBSourceReadMode_ReadEnable (1<<0)
643 #define PM3FBSourceReadMode_StripePitch(sp) (((sp)&0x7)<<2 643 #define PM3FBSourceReadMode_StripePitch(sp) (((sp)&0x7)<<2)
644 #define PM3FBSourceReadMode_StripeHeight(sh) (((sh)&0x7)<<7 644 #define PM3FBSourceReadMode_StripeHeight(sh) (((sh)&0x7)<<7)
645 #define PM3FBSourceReadMode_Layout(l) (((l)&0x3)<<8 645 #define PM3FBSourceReadMode_Layout(l) (((l)&0x3)<<8)
646 #define PM3FBSourceReadMode_Origin 1<<10 646 #define PM3FBSourceReadMode_Origin 1<<10
647 #define PM3FBSourceReadMode_Blocking 1<<11 647 #define PM3FBSourceReadMode_Blocking 1<<11
648 #define PM3FBSourceReadMode_UserTexelCoord 1<<13 648 #define PM3FBSourceReadMode_UserTexelCoord 1<<13
649 #define PM3FBSourceReadMode_WrapXEnable 1<<14 649 #define PM3FBSourceReadMode_WrapXEnable 1<<14
650 #define PM3FBSourceReadMode_WrapYEnable 1<<15 650 #define PM3FBSourceReadMode_WrapYEnable 1<<15
651 #define PM3FBSourceReadMode_WrapX(w) (((w)&0xf)<<16 651 #define PM3FBSourceReadMode_WrapX(w) (((w)&0xf)<<16)
652 #define PM3FBSourceReadMode_WrapY(w) (((w)&0xf)<<20 652 #define PM3FBSourceReadMode_WrapY(w) (((w)&0xf)<<20)
653 #define PM3FBSourceReadMode_ExternalSourceData 1<<24 653 #define PM3FBSourceReadMode_ExternalSourceData 1<<24
654#define PM3FBWriteBufferAddr0 0xb000 654#define PM3FBWriteBufferAddr0 0xb000
655#define PM3FBWriteBufferAddr1 0xb008 655#define PM3FBWriteBufferAddr1 0xb008
@@ -942,7 +942,7 @@
942#define PM3Window 0x8980 942#define PM3Window 0x8980
943 #define PM3Window_ForceLBUpdate 1<<3 943 #define PM3Window_ForceLBUpdate 1<<3
944 #define PM3Window_LBUpdateSource 1<<4 944 #define PM3Window_LBUpdateSource 1<<4
945 #define PM3Window_FrameCount(c) (((c)&0xff)<<9 945 #define PM3Window_FrameCount(c) (((c)&0xff)<<9)
946 #define PM3Window_StencilFCP 1<<17 946 #define PM3Window_StencilFCP 1<<17
947 #define PM3Window_DepthFCP 1<<18 947 #define PM3Window_DepthFCP 1<<18
948 #define PM3Window_OverrideWriteFiltering 1<<19 948 #define PM3Window_OverrideWriteFiltering 1<<19
diff --git a/init/Kconfig b/init/Kconfig
index 14d484606fab..9edf103b3ec3 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -304,6 +304,15 @@ config TASK_XACCT
304 304
305 Say N if unsure. 305 Say N if unsure.
306 306
307config TASK_IO_ACCOUNTING
308 bool "Enable per-task storage I/O accounting (EXPERIMENTAL)"
309 depends on TASK_XACCT
310 help
311 Collect information on the number of bytes of storage I/O which this
312 task has caused.
313
314 Say N if unsure.
315
307config SYSCTL 316config SYSCTL
308 bool 317 bool
309 318
diff --git a/init/Makefile b/init/Makefile
index 633a268d270d..d6c764d0eabb 100644
--- a/init/Makefile
+++ b/init/Makefile
@@ -15,6 +15,7 @@ clean-files := ../include/linux/compile.h
15 15
16# dependencies on generated files need to be listed explicitly 16# dependencies on generated files need to be listed explicitly
17 17
18$(obj)/main.o: include/linux/compile.h
18$(obj)/version.o: include/linux/compile.h 19$(obj)/version.o: include/linux/compile.h
19 20
20# compile.h changes depending on hostname, generation number, etc, 21# compile.h changes depending on hostname, generation number, etc,
diff --git a/init/initramfs.c b/init/initramfs.c
index 85f04037ade1..4fa0f7977de1 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -526,7 +526,7 @@ static void __init free_initrd(void)
526 526
527#endif 527#endif
528 528
529void __init populate_rootfs(void) 529static int __init populate_rootfs(void)
530{ 530{
531 char *err = unpack_to_rootfs(__initramfs_start, 531 char *err = unpack_to_rootfs(__initramfs_start,
532 __initramfs_end - __initramfs_start, 0); 532 __initramfs_end - __initramfs_start, 0);
@@ -544,7 +544,7 @@ void __init populate_rootfs(void)
544 unpack_to_rootfs((char *)initrd_start, 544 unpack_to_rootfs((char *)initrd_start,
545 initrd_end - initrd_start, 0); 545 initrd_end - initrd_start, 0);
546 free_initrd(); 546 free_initrd();
547 return; 547 return 0;
548 } 548 }
549 printk("it isn't (%s); looks like an initrd\n", err); 549 printk("it isn't (%s); looks like an initrd\n", err);
550 fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700); 550 fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 0700);
@@ -565,4 +565,6 @@ void __init populate_rootfs(void)
565#endif 565#endif
566 } 566 }
567#endif 567#endif
568 return 0;
568} 569}
570rootfs_initcall(populate_rootfs);
diff --git a/init/main.c b/init/main.c
index 1174ae3aec8c..e3f0bb20b4dd 100644
--- a/init/main.c
+++ b/init/main.c
@@ -50,6 +50,9 @@
50#include <linux/buffer_head.h> 50#include <linux/buffer_head.h>
51#include <linux/debug_locks.h> 51#include <linux/debug_locks.h>
52#include <linux/lockdep.h> 52#include <linux/lockdep.h>
53#include <linux/utsrelease.h>
54#include <linux/pid_namespace.h>
55#include <linux/compile.h>
53 56
54#include <asm/io.h> 57#include <asm/io.h>
55#include <asm/bugs.h> 58#include <asm/bugs.h>
@@ -91,7 +94,6 @@ extern void pidmap_init(void);
91extern void prio_tree_init(void); 94extern void prio_tree_init(void);
92extern void radix_tree_init(void); 95extern void radix_tree_init(void);
93extern void free_initmem(void); 96extern void free_initmem(void);
94extern void populate_rootfs(void);
95extern void driver_init(void); 97extern void driver_init(void);
96extern void prepare_namespace(void); 98extern void prepare_namespace(void);
97#ifdef CONFIG_ACPI 99#ifdef CONFIG_ACPI
@@ -480,6 +482,12 @@ void __init __attribute__((weak)) smp_setup_processor_id(void)
480{ 482{
481} 483}
482 484
485static const char linux_banner[] =
486 "Linux version " UTS_RELEASE
487 " (" LINUX_COMPILE_BY "@" LINUX_COMPILE_HOST ")"
488 " (" LINUX_COMPILER ")"
489 " " UTS_VERSION "\n";
490
483asmlinkage void __init start_kernel(void) 491asmlinkage void __init start_kernel(void)
484{ 492{
485 char * command_line; 493 char * command_line;
@@ -624,8 +632,6 @@ static int __init initcall_debug_setup(char *str)
624} 632}
625__setup("initcall_debug", initcall_debug_setup); 633__setup("initcall_debug", initcall_debug_setup);
626 634
627struct task_struct *child_reaper = &init_task;
628
629extern initcall_t __initcall_start[], __initcall_end[]; 635extern initcall_t __initcall_start[], __initcall_end[];
630 636
631static void __init do_initcalls(void) 637static void __init do_initcalls(void)
@@ -725,7 +731,7 @@ static int init(void * unused)
725 * assumptions about where in the task array this 731 * assumptions about where in the task array this
726 * can be found. 732 * can be found.
727 */ 733 */
728 child_reaper = current; 734 init_pid_ns.child_reaper = current;
729 735
730 cad_pid = task_pid(current); 736 cad_pid = task_pid(current);
731 737
@@ -738,12 +744,6 @@ static int init(void * unused)
738 744
739 cpuset_init_smp(); 745 cpuset_init_smp();
740 746
741 /*
742 * Do this before initcalls, because some drivers want to access
743 * firmware files.
744 */
745 populate_rootfs();
746
747 do_basic_setup(); 747 do_basic_setup();
748 748
749 /* 749 /*
diff --git a/init/version.c b/init/version.c
index 8f28344d9c70..9d96d36501ca 100644
--- a/init/version.c
+++ b/init/version.c
@@ -33,7 +33,3 @@ struct uts_namespace init_uts_ns = {
33 }, 33 },
34}; 34};
35EXPORT_SYMBOL_GPL(init_uts_ns); 35EXPORT_SYMBOL_GPL(init_uts_ns);
36
37const char linux_banner[] =
38 "Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
39 LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
diff --git a/ipc/mqueue.c b/ipc/mqueue.c
index 3acc1661e517..02717f71d8d0 100644
--- a/ipc/mqueue.c
+++ b/ipc/mqueue.c
@@ -322,7 +322,7 @@ static int mqueue_unlink(struct inode *dir, struct dentry *dentry)
322static ssize_t mqueue_read_file(struct file *filp, char __user *u_data, 322static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
323 size_t count, loff_t * off) 323 size_t count, loff_t * off)
324{ 324{
325 struct mqueue_inode_info *info = MQUEUE_I(filp->f_dentry->d_inode); 325 struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
326 char buffer[FILENT_SIZE]; 326 char buffer[FILENT_SIZE];
327 size_t slen; 327 size_t slen;
328 loff_t o; 328 loff_t o;
@@ -354,13 +354,13 @@ static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
354 return -EFAULT; 354 return -EFAULT;
355 355
356 *off = o + count; 356 *off = o + count;
357 filp->f_dentry->d_inode->i_atime = filp->f_dentry->d_inode->i_ctime = CURRENT_TIME; 357 filp->f_path.dentry->d_inode->i_atime = filp->f_path.dentry->d_inode->i_ctime = CURRENT_TIME;
358 return count; 358 return count;
359} 359}
360 360
361static int mqueue_flush_file(struct file *filp, fl_owner_t id) 361static int mqueue_flush_file(struct file *filp, fl_owner_t id)
362{ 362{
363 struct mqueue_inode_info *info = MQUEUE_I(filp->f_dentry->d_inode); 363 struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
364 364
365 spin_lock(&info->lock); 365 spin_lock(&info->lock);
366 if (task_tgid(current) == info->notify_owner) 366 if (task_tgid(current) == info->notify_owner)
@@ -372,7 +372,7 @@ static int mqueue_flush_file(struct file *filp, fl_owner_t id)
372 372
373static unsigned int mqueue_poll_file(struct file *filp, struct poll_table_struct *poll_tab) 373static unsigned int mqueue_poll_file(struct file *filp, struct poll_table_struct *poll_tab)
374{ 374{
375 struct mqueue_inode_info *info = MQUEUE_I(filp->f_dentry->d_inode); 375 struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
376 int retval = 0; 376 int retval = 0;
377 377
378 poll_wait(filp, &info->wait_q, poll_tab); 378 poll_wait(filp, &info->wait_q, poll_tab);
@@ -836,7 +836,7 @@ asmlinkage long sys_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr,
836 if (unlikely(!filp)) 836 if (unlikely(!filp))
837 goto out; 837 goto out;
838 838
839 inode = filp->f_dentry->d_inode; 839 inode = filp->f_path.dentry->d_inode;
840 if (unlikely(filp->f_op != &mqueue_file_operations)) 840 if (unlikely(filp->f_op != &mqueue_file_operations))
841 goto out_fput; 841 goto out_fput;
842 info = MQUEUE_I(inode); 842 info = MQUEUE_I(inode);
@@ -919,7 +919,7 @@ asmlinkage ssize_t sys_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr,
919 if (unlikely(!filp)) 919 if (unlikely(!filp))
920 goto out; 920 goto out;
921 921
922 inode = filp->f_dentry->d_inode; 922 inode = filp->f_path.dentry->d_inode;
923 if (unlikely(filp->f_op != &mqueue_file_operations)) 923 if (unlikely(filp->f_op != &mqueue_file_operations))
924 goto out_fput; 924 goto out_fput;
925 info = MQUEUE_I(inode); 925 info = MQUEUE_I(inode);
@@ -1056,7 +1056,7 @@ retry:
1056 if (!filp) 1056 if (!filp)
1057 goto out; 1057 goto out;
1058 1058
1059 inode = filp->f_dentry->d_inode; 1059 inode = filp->f_path.dentry->d_inode;
1060 if (unlikely(filp->f_op != &mqueue_file_operations)) 1060 if (unlikely(filp->f_op != &mqueue_file_operations))
1061 goto out_fput; 1061 goto out_fput;
1062 info = MQUEUE_I(inode); 1062 info = MQUEUE_I(inode);
@@ -1126,7 +1126,7 @@ asmlinkage long sys_mq_getsetattr(mqd_t mqdes,
1126 if (!filp) 1126 if (!filp)
1127 goto out; 1127 goto out;
1128 1128
1129 inode = filp->f_dentry->d_inode; 1129 inode = filp->f_path.dentry->d_inode;
1130 if (unlikely(filp->f_op != &mqueue_file_operations)) 1130 if (unlikely(filp->f_op != &mqueue_file_operations))
1131 goto out_fput; 1131 goto out_fput;
1132 info = MQUEUE_I(inode); 1132 info = MQUEUE_I(inode);
diff --git a/ipc/shm.c b/ipc/shm.c
index d1198dd07a1a..6d16bb6de7d2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -168,7 +168,7 @@ static inline void shm_inc(struct ipc_namespace *ns, int id)
168static void shm_open(struct vm_area_struct *shmd) 168static void shm_open(struct vm_area_struct *shmd)
169{ 169{
170 shm_inc(shm_file_ns(shmd->vm_file), 170 shm_inc(shm_file_ns(shmd->vm_file),
171 shmd->vm_file->f_dentry->d_inode->i_ino); 171 shmd->vm_file->f_path.dentry->d_inode->i_ino);
172} 172}
173 173
174/* 174/*
@@ -187,7 +187,7 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
187 if (!is_file_hugepages(shp->shm_file)) 187 if (!is_file_hugepages(shp->shm_file))
188 shmem_lock(shp->shm_file, 0, shp->mlock_user); 188 shmem_lock(shp->shm_file, 0, shp->mlock_user);
189 else 189 else
190 user_shm_unlock(shp->shm_file->f_dentry->d_inode->i_size, 190 user_shm_unlock(shp->shm_file->f_path.dentry->d_inode->i_size,
191 shp->mlock_user); 191 shp->mlock_user);
192 fput (shp->shm_file); 192 fput (shp->shm_file);
193 security_shm_free(shp); 193 security_shm_free(shp);
@@ -203,7 +203,7 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
203static void shm_close (struct vm_area_struct *shmd) 203static void shm_close (struct vm_area_struct *shmd)
204{ 204{
205 struct file * file = shmd->vm_file; 205 struct file * file = shmd->vm_file;
206 int id = file->f_dentry->d_inode->i_ino; 206 int id = file->f_path.dentry->d_inode->i_ino;
207 struct shmid_kernel *shp; 207 struct shmid_kernel *shp;
208 struct ipc_namespace *ns; 208 struct ipc_namespace *ns;
209 209
@@ -233,7 +233,7 @@ static int shm_mmap(struct file * file, struct vm_area_struct * vma)
233 vma->vm_ops = &shm_vm_ops; 233 vma->vm_ops = &shm_vm_ops;
234 if (!(vma->vm_flags & VM_WRITE)) 234 if (!(vma->vm_flags & VM_WRITE))
235 vma->vm_flags &= ~VM_MAYWRITE; 235 vma->vm_flags &= ~VM_MAYWRITE;
236 shm_inc(shm_file_ns(file), file->f_dentry->d_inode->i_ino); 236 shm_inc(shm_file_ns(file), file->f_path.dentry->d_inode->i_ino);
237 } 237 }
238 238
239 return ret; 239 return ret;
@@ -330,7 +330,7 @@ static int newseg (struct ipc_namespace *ns, key_t key, int shmflg, size_t size)
330 shp->shm_nattch = 0; 330 shp->shm_nattch = 0;
331 shp->id = shm_buildid(ns, id, shp->shm_perm.seq); 331 shp->id = shm_buildid(ns, id, shp->shm_perm.seq);
332 shp->shm_file = file; 332 shp->shm_file = file;
333 file->f_dentry->d_inode->i_ino = shp->id; 333 file->f_path.dentry->d_inode->i_ino = shp->id;
334 334
335 shm_file_ns(file) = get_ipc_ns(ns); 335 shm_file_ns(file) = get_ipc_ns(ns);
336 336
@@ -495,7 +495,7 @@ static void shm_get_stat(struct ipc_namespace *ns, unsigned long *rss,
495 if(!shp) 495 if(!shp)
496 continue; 496 continue;
497 497
498 inode = shp->shm_file->f_dentry->d_inode; 498 inode = shp->shm_file->f_path.dentry->d_inode;
499 499
500 if (is_file_hugepages(shp->shm_file)) { 500 if (is_file_hugepages(shp->shm_file)) {
501 struct address_space *mapping = inode->i_mapping; 501 struct address_space *mapping = inode->i_mapping;
@@ -843,7 +843,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
843 } 843 }
844 844
845 file = shp->shm_file; 845 file = shp->shm_file;
846 size = i_size_read(file->f_dentry->d_inode); 846 size = i_size_read(file->f_path.dentry->d_inode);
847 shp->shm_nattch++; 847 shp->shm_nattch++;
848 shm_unlock(shp); 848 shm_unlock(shp);
849 849
@@ -948,7 +948,7 @@ asmlinkage long sys_shmdt(char __user *shmaddr)
948 (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) { 948 (vma->vm_start - addr)/PAGE_SIZE == vma->vm_pgoff) {
949 949
950 950
951 size = vma->vm_file->f_dentry->d_inode->i_size; 951 size = vma->vm_file->f_path.dentry->d_inode->i_size;
952 do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start); 952 do_munmap(mm, vma->vm_start, vma->vm_end - vma->vm_start);
953 /* 953 /*
954 * We discovered the size of the shm segment, so 954 * We discovered the size of the shm segment, so
diff --git a/kernel/acct.c b/kernel/acct.c
index dc12db8600e7..70d0d88e5554 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -118,7 +118,7 @@ static int check_free_space(struct file *file)
118 spin_unlock(&acct_globals.lock); 118 spin_unlock(&acct_globals.lock);
119 119
120 /* May block */ 120 /* May block */
121 if (vfs_statfs(file->f_dentry, &sbuf)) 121 if (vfs_statfs(file->f_path.dentry, &sbuf))
122 return res; 122 return res;
123 suspend = sbuf.f_blocks * SUSPEND; 123 suspend = sbuf.f_blocks * SUSPEND;
124 resume = sbuf.f_blocks * RESUME; 124 resume = sbuf.f_blocks * RESUME;
@@ -194,7 +194,7 @@ static void acct_file_reopen(struct file *file)
194 add_timer(&acct_globals.timer); 194 add_timer(&acct_globals.timer);
195 } 195 }
196 if (old_acct) { 196 if (old_acct) {
197 mnt_unpin(old_acct->f_vfsmnt); 197 mnt_unpin(old_acct->f_path.mnt);
198 spin_unlock(&acct_globals.lock); 198 spin_unlock(&acct_globals.lock);
199 do_acct_process(old_acct); 199 do_acct_process(old_acct);
200 filp_close(old_acct, NULL); 200 filp_close(old_acct, NULL);
@@ -212,7 +212,7 @@ static int acct_on(char *name)
212 if (IS_ERR(file)) 212 if (IS_ERR(file))
213 return PTR_ERR(file); 213 return PTR_ERR(file);
214 214
215 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) { 215 if (!S_ISREG(file->f_path.dentry->d_inode->i_mode)) {
216 filp_close(file, NULL); 216 filp_close(file, NULL);
217 return -EACCES; 217 return -EACCES;
218 } 218 }
@@ -229,11 +229,11 @@ static int acct_on(char *name)
229 } 229 }
230 230
231 spin_lock(&acct_globals.lock); 231 spin_lock(&acct_globals.lock);
232 mnt_pin(file->f_vfsmnt); 232 mnt_pin(file->f_path.mnt);
233 acct_file_reopen(file); 233 acct_file_reopen(file);
234 spin_unlock(&acct_globals.lock); 234 spin_unlock(&acct_globals.lock);
235 235
236 mntput(file->f_vfsmnt); /* it's pinned, now give up active reference */ 236 mntput(file->f_path.mnt); /* it's pinned, now give up active reference */
237 237
238 return 0; 238 return 0;
239} 239}
@@ -283,7 +283,7 @@ asmlinkage long sys_acct(const char __user *name)
283void acct_auto_close_mnt(struct vfsmount *m) 283void acct_auto_close_mnt(struct vfsmount *m)
284{ 284{
285 spin_lock(&acct_globals.lock); 285 spin_lock(&acct_globals.lock);
286 if (acct_globals.file && acct_globals.file->f_vfsmnt == m) 286 if (acct_globals.file && acct_globals.file->f_path.mnt == m)
287 acct_file_reopen(NULL); 287 acct_file_reopen(NULL);
288 spin_unlock(&acct_globals.lock); 288 spin_unlock(&acct_globals.lock);
289} 289}
@@ -299,7 +299,7 @@ void acct_auto_close(struct super_block *sb)
299{ 299{
300 spin_lock(&acct_globals.lock); 300 spin_lock(&acct_globals.lock);
301 if (acct_globals.file && 301 if (acct_globals.file &&
302 acct_globals.file->f_vfsmnt->mnt_sb == sb) { 302 acct_globals.file->f_path.mnt->mnt_sb == sb) {
303 acct_file_reopen(NULL); 303 acct_file_reopen(NULL);
304 } 304 }
305 spin_unlock(&acct_globals.lock); 305 spin_unlock(&acct_globals.lock);
@@ -428,6 +428,7 @@ static void do_acct_process(struct file *file)
428 u64 elapsed; 428 u64 elapsed;
429 u64 run_time; 429 u64 run_time;
430 struct timespec uptime; 430 struct timespec uptime;
431 struct tty_struct *tty;
431 432
432 /* 433 /*
433 * First check to see if there is enough free_space to continue 434 * First check to see if there is enough free_space to continue
@@ -484,16 +485,9 @@ static void do_acct_process(struct file *file)
484 ac.ac_ppid = current->parent->tgid; 485 ac.ac_ppid = current->parent->tgid;
485#endif 486#endif
486 487
487 mutex_lock(&tty_mutex);
488 /* FIXME: Whoever is responsible for current->signal locking needs
489 to use the same locking all over the kernel and document it */
490 read_lock(&tasklist_lock);
491 ac.ac_tty = current->signal->tty ?
492 old_encode_dev(tty_devnum(current->signal->tty)) : 0;
493 read_unlock(&tasklist_lock);
494 mutex_unlock(&tty_mutex);
495
496 spin_lock_irq(&current->sighand->siglock); 488 spin_lock_irq(&current->sighand->siglock);
489 tty = current->signal->tty;
490 ac.ac_tty = tty ? old_encode_dev(tty_devnum(tty)) : 0;
497 ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime))); 491 ac.ac_utime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_utime)));
498 ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime))); 492 ac.ac_stime = encode_comp_t(jiffies_to_AHZ(cputime_to_jiffies(pacct->ac_stime)));
499 ac.ac_flag = pacct->ac_flag; 493 ac.ac_flag = pacct->ac_flag;
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 40722e26de98..298897559ca4 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -781,8 +781,8 @@ static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk
781 if ((vma->vm_flags & VM_EXECUTABLE) && 781 if ((vma->vm_flags & VM_EXECUTABLE) &&
782 vma->vm_file) { 782 vma->vm_file) {
783 audit_log_d_path(ab, "exe=", 783 audit_log_d_path(ab, "exe=",
784 vma->vm_file->f_dentry, 784 vma->vm_file->f_path.dentry,
785 vma->vm_file->f_vfsmnt); 785 vma->vm_file->f_path.mnt);
786 break; 786 break;
787 } 787 }
788 vma = vma->vm_next; 788 vma = vma->vm_next;
@@ -826,10 +826,12 @@ static void audit_log_exit(struct audit_context *context, struct task_struct *ts
826 context->return_code); 826 context->return_code);
827 827
828 mutex_lock(&tty_mutex); 828 mutex_lock(&tty_mutex);
829 read_lock(&tasklist_lock);
829 if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name) 830 if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name)
830 tty = tsk->signal->tty->name; 831 tty = tsk->signal->tty->name;
831 else 832 else
832 tty = "(none)"; 833 tty = "(none)";
834 read_unlock(&tasklist_lock);
833 audit_log_format(ab, 835 audit_log_format(ab,
834 " a0=%lx a1=%lx a2=%lx a3=%lx items=%d" 836 " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
835 " ppid=%d pid=%d auid=%u uid=%u gid=%u" 837 " ppid=%d pid=%d auid=%u uid=%u gid=%u"
diff --git a/kernel/cpuset.c b/kernel/cpuset.c
index 0a6b4d89f9a0..2c3b4431472b 100644
--- a/kernel/cpuset.c
+++ b/kernel/cpuset.c
@@ -413,8 +413,8 @@ static struct file_system_type cpuset_fs_type = {
413 * 413 *
414 * 414 *
415 * When reading/writing to a file: 415 * When reading/writing to a file:
416 * - the cpuset to use in file->f_dentry->d_parent->d_fsdata 416 * - the cpuset to use in file->f_path.dentry->d_parent->d_fsdata
417 * - the 'cftype' of the file is file->f_dentry->d_fsdata 417 * - the 'cftype' of the file is file->f_path.dentry->d_fsdata
418 */ 418 */
419 419
420struct cftype { 420struct cftype {
@@ -1284,8 +1284,8 @@ static ssize_t cpuset_common_file_write(struct file *file,
1284 const char __user *userbuf, 1284 const char __user *userbuf,
1285 size_t nbytes, loff_t *unused_ppos) 1285 size_t nbytes, loff_t *unused_ppos)
1286{ 1286{
1287 struct cpuset *cs = __d_cs(file->f_dentry->d_parent); 1287 struct cpuset *cs = __d_cs(file->f_path.dentry->d_parent);
1288 struct cftype *cft = __d_cft(file->f_dentry); 1288 struct cftype *cft = __d_cft(file->f_path.dentry);
1289 cpuset_filetype_t type = cft->private; 1289 cpuset_filetype_t type = cft->private;
1290 char *buffer; 1290 char *buffer;
1291 char *pathbuf = NULL; 1291 char *pathbuf = NULL;
@@ -1367,7 +1367,7 @@ static ssize_t cpuset_file_write(struct file *file, const char __user *buf,
1367 size_t nbytes, loff_t *ppos) 1367 size_t nbytes, loff_t *ppos)
1368{ 1368{
1369 ssize_t retval = 0; 1369 ssize_t retval = 0;
1370 struct cftype *cft = __d_cft(file->f_dentry); 1370 struct cftype *cft = __d_cft(file->f_path.dentry);
1371 if (!cft) 1371 if (!cft)
1372 return -ENODEV; 1372 return -ENODEV;
1373 1373
@@ -1417,8 +1417,8 @@ static int cpuset_sprintf_memlist(char *page, struct cpuset *cs)
1417static ssize_t cpuset_common_file_read(struct file *file, char __user *buf, 1417static ssize_t cpuset_common_file_read(struct file *file, char __user *buf,
1418 size_t nbytes, loff_t *ppos) 1418 size_t nbytes, loff_t *ppos)
1419{ 1419{
1420 struct cftype *cft = __d_cft(file->f_dentry); 1420 struct cftype *cft = __d_cft(file->f_path.dentry);
1421 struct cpuset *cs = __d_cs(file->f_dentry->d_parent); 1421 struct cpuset *cs = __d_cs(file->f_path.dentry->d_parent);
1422 cpuset_filetype_t type = cft->private; 1422 cpuset_filetype_t type = cft->private;
1423 char *page; 1423 char *page;
1424 ssize_t retval = 0; 1424 ssize_t retval = 0;
@@ -1476,7 +1476,7 @@ static ssize_t cpuset_file_read(struct file *file, char __user *buf, size_t nbyt
1476 loff_t *ppos) 1476 loff_t *ppos)
1477{ 1477{
1478 ssize_t retval = 0; 1478 ssize_t retval = 0;
1479 struct cftype *cft = __d_cft(file->f_dentry); 1479 struct cftype *cft = __d_cft(file->f_path.dentry);
1480 if (!cft) 1480 if (!cft)
1481 return -ENODEV; 1481 return -ENODEV;
1482 1482
@@ -1498,7 +1498,7 @@ static int cpuset_file_open(struct inode *inode, struct file *file)
1498 if (err) 1498 if (err)
1499 return err; 1499 return err;
1500 1500
1501 cft = __d_cft(file->f_dentry); 1501 cft = __d_cft(file->f_path.dentry);
1502 if (!cft) 1502 if (!cft)
1503 return -ENODEV; 1503 return -ENODEV;
1504 if (cft->open) 1504 if (cft->open)
@@ -1511,7 +1511,7 @@ static int cpuset_file_open(struct inode *inode, struct file *file)
1511 1511
1512static int cpuset_file_release(struct inode *inode, struct file *file) 1512static int cpuset_file_release(struct inode *inode, struct file *file)
1513{ 1513{
1514 struct cftype *cft = __d_cft(file->f_dentry); 1514 struct cftype *cft = __d_cft(file->f_path.dentry);
1515 if (cft->release) 1515 if (cft->release)
1516 return cft->release(inode, file); 1516 return cft->release(inode, file);
1517 return 0; 1517 return 0;
@@ -1700,7 +1700,7 @@ static int pid_array_to_buf(char *buf, int sz, pid_t *a, int npids)
1700 */ 1700 */
1701static int cpuset_tasks_open(struct inode *unused, struct file *file) 1701static int cpuset_tasks_open(struct inode *unused, struct file *file)
1702{ 1702{
1703 struct cpuset *cs = __d_cs(file->f_dentry->d_parent); 1703 struct cpuset *cs = __d_cs(file->f_path.dentry->d_parent);
1704 struct ctr_struct *ctr; 1704 struct ctr_struct *ctr;
1705 pid_t *pidarray; 1705 pid_t *pidarray;
1706 int npids; 1706 int npids;
diff --git a/kernel/exit.c b/kernel/exit.c
index 4e3f919edc48..122fadb972fc 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -13,7 +13,7 @@
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/personality.h> 14#include <linux/personality.h>
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/namespace.h> 16#include <linux/mnt_namespace.h>
17#include <linux/key.h> 17#include <linux/key.h>
18#include <linux/security.h> 18#include <linux/security.h>
19#include <linux/cpu.h> 19#include <linux/cpu.h>
@@ -22,6 +22,7 @@
22#include <linux/file.h> 22#include <linux/file.h>
23#include <linux/binfmts.h> 23#include <linux/binfmts.h>
24#include <linux/nsproxy.h> 24#include <linux/nsproxy.h>
25#include <linux/pid_namespace.h>
25#include <linux/ptrace.h> 26#include <linux/ptrace.h>
26#include <linux/profile.h> 27#include <linux/profile.h>
27#include <linux/mount.h> 28#include <linux/mount.h>
@@ -48,7 +49,6 @@
48#include <asm/mmu_context.h> 49#include <asm/mmu_context.h>
49 50
50extern void sem_exit (void); 51extern void sem_exit (void);
51extern struct task_struct *child_reaper;
52 52
53static void exit_mm(struct task_struct * tsk); 53static void exit_mm(struct task_struct * tsk);
54 54
@@ -189,21 +189,18 @@ repeat:
189int session_of_pgrp(int pgrp) 189int session_of_pgrp(int pgrp)
190{ 190{
191 struct task_struct *p; 191 struct task_struct *p;
192 int sid = -1; 192 int sid = 0;
193 193
194 read_lock(&tasklist_lock); 194 read_lock(&tasklist_lock);
195 do_each_task_pid(pgrp, PIDTYPE_PGID, p) { 195
196 if (p->signal->session > 0) { 196 p = find_task_by_pid_type(PIDTYPE_PGID, pgrp);
197 sid = p->signal->session; 197 if (p == NULL)
198 goto out; 198 p = find_task_by_pid(pgrp);
199 } 199 if (p != NULL)
200 } while_each_task_pid(pgrp, PIDTYPE_PGID, p); 200 sid = process_session(p);
201 p = find_task_by_pid(pgrp); 201
202 if (p)
203 sid = p->signal->session;
204out:
205 read_unlock(&tasklist_lock); 202 read_unlock(&tasklist_lock);
206 203
207 return sid; 204 return sid;
208} 205}
209 206
@@ -225,8 +222,8 @@ static int will_become_orphaned_pgrp(int pgrp, struct task_struct *ignored_task)
225 || p->exit_state 222 || p->exit_state
226 || is_init(p->real_parent)) 223 || is_init(p->real_parent))
227 continue; 224 continue;
228 if (process_group(p->real_parent) != pgrp 225 if (process_group(p->real_parent) != pgrp &&
229 && p->real_parent->signal->session == p->signal->session) { 226 process_session(p->real_parent) == process_session(p)) {
230 ret = 0; 227 ret = 0;
231 break; 228 break;
232 } 229 }
@@ -260,7 +257,8 @@ static int has_stopped_jobs(int pgrp)
260} 257}
261 258
262/** 259/**
263 * reparent_to_init - Reparent the calling kernel thread to the init task. 260 * reparent_to_init - Reparent the calling kernel thread to the init task
261 * of the pid space that the thread belongs to.
264 * 262 *
265 * If a kernel thread is launched as a result of a system call, or if 263 * If a kernel thread is launched as a result of a system call, or if
266 * it ever exits, it should generally reparent itself to init so that 264 * it ever exits, it should generally reparent itself to init so that
@@ -278,8 +276,8 @@ static void reparent_to_init(void)
278 ptrace_unlink(current); 276 ptrace_unlink(current);
279 /* Reparent to init */ 277 /* Reparent to init */
280 remove_parent(current); 278 remove_parent(current);
281 current->parent = child_reaper; 279 current->parent = child_reaper(current);
282 current->real_parent = child_reaper; 280 current->real_parent = child_reaper(current);
283 add_parent(current); 281 add_parent(current);
284 282
285 /* Set the exit signal to SIGCHLD so we signal init on exit */ 283 /* Set the exit signal to SIGCHLD so we signal init on exit */
@@ -302,9 +300,9 @@ void __set_special_pids(pid_t session, pid_t pgrp)
302{ 300{
303 struct task_struct *curr = current->group_leader; 301 struct task_struct *curr = current->group_leader;
304 302
305 if (curr->signal->session != session) { 303 if (process_session(curr) != session) {
306 detach_pid(curr, PIDTYPE_SID); 304 detach_pid(curr, PIDTYPE_SID);
307 curr->signal->session = session; 305 set_signal_session(curr->signal, session);
308 attach_pid(curr, PIDTYPE_SID, session); 306 attach_pid(curr, PIDTYPE_SID, session);
309 } 307 }
310 if (process_group(curr) != pgrp) { 308 if (process_group(curr) != pgrp) {
@@ -314,7 +312,7 @@ void __set_special_pids(pid_t session, pid_t pgrp)
314 } 312 }
315} 313}
316 314
317void set_special_pids(pid_t session, pid_t pgrp) 315static void set_special_pids(pid_t session, pid_t pgrp)
318{ 316{
319 write_lock_irq(&tasklist_lock); 317 write_lock_irq(&tasklist_lock);
320 __set_special_pids(session, pgrp); 318 __set_special_pids(session, pgrp);
@@ -384,9 +382,7 @@ void daemonize(const char *name, ...)
384 exit_mm(current); 382 exit_mm(current);
385 383
386 set_special_pids(1, 1); 384 set_special_pids(1, 1);
387 mutex_lock(&tty_mutex); 385 proc_clear_tty(current);
388 current->signal->tty = NULL;
389 mutex_unlock(&tty_mutex);
390 386
391 /* Block and flush all signals */ 387 /* Block and flush all signals */
392 sigfillset(&blocked); 388 sigfillset(&blocked);
@@ -429,7 +425,7 @@ static void close_files(struct files_struct * files)
429 for (;;) { 425 for (;;) {
430 unsigned long set; 426 unsigned long set;
431 i = j * __NFDBITS; 427 i = j * __NFDBITS;
432 if (i >= fdt->max_fdset || i >= fdt->max_fds) 428 if (i >= fdt->max_fds)
433 break; 429 break;
434 set = fdt->open_fds->fds_bits[j++]; 430 set = fdt->open_fds->fds_bits[j++];
435 while (set) { 431 while (set) {
@@ -470,11 +466,9 @@ void fastcall put_files_struct(struct files_struct *files)
470 * you can free files immediately. 466 * you can free files immediately.
471 */ 467 */
472 fdt = files_fdtable(files); 468 fdt = files_fdtable(files);
473 if (fdt == &files->fdtab) 469 if (fdt != &files->fdtab)
474 fdt->free_files = files;
475 else
476 kmem_cache_free(files_cachep, files); 470 kmem_cache_free(files_cachep, files);
477 free_fdtable(fdt); 471 call_rcu(&fdt->rcu, free_fdtable_rcu);
478 } 472 }
479} 473}
480 474
@@ -649,10 +643,11 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
649 * outside, so the child pgrp is now orphaned. 643 * outside, so the child pgrp is now orphaned.
650 */ 644 */
651 if ((process_group(p) != process_group(father)) && 645 if ((process_group(p) != process_group(father)) &&
652 (p->signal->session == father->signal->session)) { 646 (process_session(p) == process_session(father))) {
653 int pgrp = process_group(p); 647 int pgrp = process_group(p);
654 648
655 if (will_become_orphaned_pgrp(pgrp, NULL) && has_stopped_jobs(pgrp)) { 649 if (will_become_orphaned_pgrp(pgrp, NULL) &&
650 has_stopped_jobs(pgrp)) {
656 __kill_pg_info(SIGHUP, SEND_SIG_PRIV, pgrp); 651 __kill_pg_info(SIGHUP, SEND_SIG_PRIV, pgrp);
657 __kill_pg_info(SIGCONT, SEND_SIG_PRIV, pgrp); 652 __kill_pg_info(SIGCONT, SEND_SIG_PRIV, pgrp);
658 } 653 }
@@ -663,7 +658,8 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
663 * When we die, we re-parent all our children. 658 * When we die, we re-parent all our children.
664 * Try to give them to another thread in our thread 659 * Try to give them to another thread in our thread
665 * group, and if no such member exists, give it to 660 * group, and if no such member exists, give it to
666 * the global child reaper process (ie "init") 661 * the child reaper process (ie "init") in our pid
662 * space.
667 */ 663 */
668static void 664static void
669forget_original_parent(struct task_struct *father, struct list_head *to_release) 665forget_original_parent(struct task_struct *father, struct list_head *to_release)
@@ -674,7 +670,7 @@ forget_original_parent(struct task_struct *father, struct list_head *to_release)
674 do { 670 do {
675 reaper = next_thread(reaper); 671 reaper = next_thread(reaper);
676 if (reaper == father) { 672 if (reaper == father) {
677 reaper = child_reaper; 673 reaper = child_reaper(father);
678 break; 674 break;
679 } 675 }
680 } while (reaper->exit_state); 676 } while (reaper->exit_state);
@@ -786,7 +782,7 @@ static void exit_notify(struct task_struct *tsk)
786 t = tsk->real_parent; 782 t = tsk->real_parent;
787 783
788 if ((process_group(t) != process_group(tsk)) && 784 if ((process_group(t) != process_group(tsk)) &&
789 (t->signal->session == tsk->signal->session) && 785 (process_session(t) == process_session(tsk)) &&
790 will_become_orphaned_pgrp(process_group(tsk), tsk) && 786 will_become_orphaned_pgrp(process_group(tsk), tsk) &&
791 has_stopped_jobs(process_group(tsk))) { 787 has_stopped_jobs(process_group(tsk))) {
792 __kill_pg_info(SIGHUP, SEND_SIG_PRIV, process_group(tsk)); 788 __kill_pg_info(SIGHUP, SEND_SIG_PRIV, process_group(tsk));
@@ -860,8 +856,13 @@ fastcall NORET_TYPE void do_exit(long code)
860 panic("Aiee, killing interrupt handler!"); 856 panic("Aiee, killing interrupt handler!");
861 if (unlikely(!tsk->pid)) 857 if (unlikely(!tsk->pid))
862 panic("Attempted to kill the idle task!"); 858 panic("Attempted to kill the idle task!");
863 if (unlikely(tsk == child_reaper)) 859 if (unlikely(tsk == child_reaper(tsk))) {
864 panic("Attempted to kill init!"); 860 if (tsk->nsproxy->pid_ns != &init_pid_ns)
861 tsk->nsproxy->pid_ns->child_reaper = init_pid_ns.child_reaper;
862 else
863 panic("Attempted to kill init!");
864 }
865
865 866
866 if (unlikely(current->ptrace & PT_TRACE_EXIT)) { 867 if (unlikely(current->ptrace & PT_TRACE_EXIT)) {
867 current->ptrace_message = code; 868 current->ptrace_message = code;
diff --git a/kernel/fork.c b/kernel/fork.c
index 7f2e31ba33af..d16c566eb645 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -18,7 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
20#include <linux/completion.h> 20#include <linux/completion.h>
21#include <linux/namespace.h> 21#include <linux/mnt_namespace.h>
22#include <linux/personality.h> 22#include <linux/personality.h>
23#include <linux/mempolicy.h> 23#include <linux/mempolicy.h>
24#include <linux/sem.h> 24#include <linux/sem.h>
@@ -36,6 +36,7 @@
36#include <linux/syscalls.h> 36#include <linux/syscalls.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/futex.h> 38#include <linux/futex.h>
39#include <linux/task_io_accounting_ops.h>
39#include <linux/rcupdate.h> 40#include <linux/rcupdate.h>
40#include <linux/ptrace.h> 41#include <linux/ptrace.h>
41#include <linux/mount.h> 42#include <linux/mount.h>
@@ -252,7 +253,7 @@ static inline int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
252 anon_vma_link(tmp); 253 anon_vma_link(tmp);
253 file = tmp->vm_file; 254 file = tmp->vm_file;
254 if (file) { 255 if (file) {
255 struct inode *inode = file->f_dentry->d_inode; 256 struct inode *inode = file->f_path.dentry->d_inode;
256 get_file(file); 257 get_file(file);
257 if (tmp->vm_flags & VM_DENYWRITE) 258 if (tmp->vm_flags & VM_DENYWRITE)
258 atomic_dec(&inode->i_writecount); 259 atomic_dec(&inode->i_writecount);
@@ -613,7 +614,7 @@ static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk)
613 614
614static int count_open_files(struct fdtable *fdt) 615static int count_open_files(struct fdtable *fdt)
615{ 616{
616 int size = fdt->max_fdset; 617 int size = fdt->max_fds;
617 int i; 618 int i;
618 619
619 /* Find the last open fd */ 620 /* Find the last open fd */
@@ -640,12 +641,10 @@ static struct files_struct *alloc_files(void)
640 newf->next_fd = 0; 641 newf->next_fd = 0;
641 fdt = &newf->fdtab; 642 fdt = &newf->fdtab;
642 fdt->max_fds = NR_OPEN_DEFAULT; 643 fdt->max_fds = NR_OPEN_DEFAULT;
643 fdt->max_fdset = EMBEDDED_FD_SET_SIZE;
644 fdt->close_on_exec = (fd_set *)&newf->close_on_exec_init; 644 fdt->close_on_exec = (fd_set *)&newf->close_on_exec_init;
645 fdt->open_fds = (fd_set *)&newf->open_fds_init; 645 fdt->open_fds = (fd_set *)&newf->open_fds_init;
646 fdt->fd = &newf->fd_array[0]; 646 fdt->fd = &newf->fd_array[0];
647 INIT_RCU_HEAD(&fdt->rcu); 647 INIT_RCU_HEAD(&fdt->rcu);
648 fdt->free_files = NULL;
649 fdt->next = NULL; 648 fdt->next = NULL;
650 rcu_assign_pointer(newf->fdt, fdt); 649 rcu_assign_pointer(newf->fdt, fdt);
651out: 650out:
@@ -661,7 +660,7 @@ static struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
661{ 660{
662 struct files_struct *newf; 661 struct files_struct *newf;
663 struct file **old_fds, **new_fds; 662 struct file **old_fds, **new_fds;
664 int open_files, size, i, expand; 663 int open_files, size, i;
665 struct fdtable *old_fdt, *new_fdt; 664 struct fdtable *old_fdt, *new_fdt;
666 665
667 *errorp = -ENOMEM; 666 *errorp = -ENOMEM;
@@ -672,25 +671,14 @@ static struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
672 spin_lock(&oldf->file_lock); 671 spin_lock(&oldf->file_lock);
673 old_fdt = files_fdtable(oldf); 672 old_fdt = files_fdtable(oldf);
674 new_fdt = files_fdtable(newf); 673 new_fdt = files_fdtable(newf);
675 size = old_fdt->max_fdset;
676 open_files = count_open_files(old_fdt); 674 open_files = count_open_files(old_fdt);
677 expand = 0;
678 675
679 /* 676 /*
680 * Check whether we need to allocate a larger fd array or fd set. 677 * Check whether we need to allocate a larger fd array and fd set.
681 * Note: we're not a clone task, so the open count won't change. 678 * Note: we're not a clone task, so the open count won't change.
682 */ 679 */
683 if (open_files > new_fdt->max_fdset) {
684 new_fdt->max_fdset = 0;
685 expand = 1;
686 }
687 if (open_files > new_fdt->max_fds) { 680 if (open_files > new_fdt->max_fds) {
688 new_fdt->max_fds = 0; 681 new_fdt->max_fds = 0;
689 expand = 1;
690 }
691
692 /* if the old fdset gets grown now, we'll only copy up to "size" fds */
693 if (expand) {
694 spin_unlock(&oldf->file_lock); 682 spin_unlock(&oldf->file_lock);
695 spin_lock(&newf->file_lock); 683 spin_lock(&newf->file_lock);
696 *errorp = expand_files(newf, open_files-1); 684 *errorp = expand_files(newf, open_files-1);
@@ -710,8 +698,10 @@ static struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
710 old_fds = old_fdt->fd; 698 old_fds = old_fdt->fd;
711 new_fds = new_fdt->fd; 699 new_fds = new_fdt->fd;
712 700
713 memcpy(new_fdt->open_fds->fds_bits, old_fdt->open_fds->fds_bits, open_files/8); 701 memcpy(new_fdt->open_fds->fds_bits,
714 memcpy(new_fdt->close_on_exec->fds_bits, old_fdt->close_on_exec->fds_bits, open_files/8); 702 old_fdt->open_fds->fds_bits, open_files/8);
703 memcpy(new_fdt->close_on_exec->fds_bits,
704 old_fdt->close_on_exec->fds_bits, open_files/8);
715 705
716 for (i = open_files; i != 0; i--) { 706 for (i = open_files; i != 0; i--) {
717 struct file *f = *old_fds++; 707 struct file *f = *old_fds++;
@@ -736,22 +726,19 @@ static struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
736 /* This is long word aligned thus could use a optimized version */ 726 /* This is long word aligned thus could use a optimized version */
737 memset(new_fds, 0, size); 727 memset(new_fds, 0, size);
738 728
739 if (new_fdt->max_fdset > open_files) { 729 if (new_fdt->max_fds > open_files) {
740 int left = (new_fdt->max_fdset-open_files)/8; 730 int left = (new_fdt->max_fds-open_files)/8;
741 int start = open_files / (8 * sizeof(unsigned long)); 731 int start = open_files / (8 * sizeof(unsigned long));
742 732
743 memset(&new_fdt->open_fds->fds_bits[start], 0, left); 733 memset(&new_fdt->open_fds->fds_bits[start], 0, left);
744 memset(&new_fdt->close_on_exec->fds_bits[start], 0, left); 734 memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
745 } 735 }
746 736
747out:
748 return newf; 737 return newf;
749 738
750out_release: 739out_release:
751 free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
752 free_fdset (new_fdt->open_fds, new_fdt->max_fdset);
753 free_fd_array(new_fdt->fd, new_fdt->max_fds);
754 kmem_cache_free(files_cachep, newf); 740 kmem_cache_free(files_cachep, newf);
741out:
755 return NULL; 742 return NULL;
756} 743}
757 744
@@ -1055,6 +1042,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1055 p->wchar = 0; /* I/O counter: bytes written */ 1042 p->wchar = 0; /* I/O counter: bytes written */
1056 p->syscr = 0; /* I/O counter: read syscalls */ 1043 p->syscr = 0; /* I/O counter: read syscalls */
1057 p->syscw = 0; /* I/O counter: write syscalls */ 1044 p->syscw = 0; /* I/O counter: write syscalls */
1045 task_io_accounting_init(p);
1058 acct_clear_integrals(p); 1046 acct_clear_integrals(p);
1059 1047
1060 p->it_virt_expires = cputime_zero; 1048 p->it_virt_expires = cputime_zero;
@@ -1259,9 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1259 if (thread_group_leader(p)) { 1247 if (thread_group_leader(p)) {
1260 p->signal->tty = current->signal->tty; 1248 p->signal->tty = current->signal->tty;
1261 p->signal->pgrp = process_group(current); 1249 p->signal->pgrp = process_group(current);
1262 p->signal->session = current->signal->session; 1250 set_signal_session(p->signal, process_session(current));
1263 attach_pid(p, PIDTYPE_PGID, process_group(p)); 1251 attach_pid(p, PIDTYPE_PGID, process_group(p));
1264 attach_pid(p, PIDTYPE_SID, p->signal->session); 1252 attach_pid(p, PIDTYPE_SID, process_session(p));
1265 1253
1266 list_add_tail_rcu(&p->tasks, &init_task.tasks); 1254 list_add_tail_rcu(&p->tasks, &init_task.tasks);
1267 __get_cpu_var(process_counts)++; 1255 __get_cpu_var(process_counts)++;
@@ -1525,17 +1513,18 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
1525} 1513}
1526 1514
1527/* 1515/*
1528 * Unshare the namespace structure if it is being shared 1516 * Unshare the mnt_namespace structure if it is being shared
1529 */ 1517 */
1530static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs) 1518static int unshare_mnt_namespace(unsigned long unshare_flags,
1519 struct mnt_namespace **new_nsp, struct fs_struct *new_fs)
1531{ 1520{
1532 struct namespace *ns = current->nsproxy->namespace; 1521 struct mnt_namespace *ns = current->nsproxy->mnt_ns;
1533 1522
1534 if ((unshare_flags & CLONE_NEWNS) && ns) { 1523 if ((unshare_flags & CLONE_NEWNS) && ns) {
1535 if (!capable(CAP_SYS_ADMIN)) 1524 if (!capable(CAP_SYS_ADMIN))
1536 return -EPERM; 1525 return -EPERM;
1537 1526
1538 *new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs); 1527 *new_nsp = dup_mnt_ns(current, new_fs ? new_fs : current->fs);
1539 if (!*new_nsp) 1528 if (!*new_nsp)
1540 return -ENOMEM; 1529 return -ENOMEM;
1541 } 1530 }
@@ -1544,15 +1533,13 @@ static int unshare_namespace(unsigned long unshare_flags, struct namespace **new
1544} 1533}
1545 1534
1546/* 1535/*
1547 * Unsharing of sighand for tasks created with CLONE_SIGHAND is not 1536 * Unsharing of sighand is not supported yet
1548 * supported yet
1549 */ 1537 */
1550static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp) 1538static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp)
1551{ 1539{
1552 struct sighand_struct *sigh = current->sighand; 1540 struct sighand_struct *sigh = current->sighand;
1553 1541
1554 if ((unshare_flags & CLONE_SIGHAND) && 1542 if ((unshare_flags & CLONE_SIGHAND) && atomic_read(&sigh->count) > 1)
1555 (sigh && atomic_read(&sigh->count) > 1))
1556 return -EINVAL; 1543 return -EINVAL;
1557 else 1544 else
1558 return 0; 1545 return 0;
@@ -1625,8 +1612,8 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
1625{ 1612{
1626 int err = 0; 1613 int err = 0;
1627 struct fs_struct *fs, *new_fs = NULL; 1614 struct fs_struct *fs, *new_fs = NULL;
1628 struct namespace *ns, *new_ns = NULL; 1615 struct mnt_namespace *ns, *new_ns = NULL;
1629 struct sighand_struct *sigh, *new_sigh = NULL; 1616 struct sighand_struct *new_sigh = NULL;
1630 struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL; 1617 struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
1631 struct files_struct *fd, *new_fd = NULL; 1618 struct files_struct *fd, *new_fd = NULL;
1632 struct sem_undo_list *new_ulist = NULL; 1619 struct sem_undo_list *new_ulist = NULL;
@@ -1647,7 +1634,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
1647 goto bad_unshare_out; 1634 goto bad_unshare_out;
1648 if ((err = unshare_fs(unshare_flags, &new_fs))) 1635 if ((err = unshare_fs(unshare_flags, &new_fs)))
1649 goto bad_unshare_cleanup_thread; 1636 goto bad_unshare_cleanup_thread;
1650 if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs))) 1637 if ((err = unshare_mnt_namespace(unshare_flags, &new_ns, new_fs)))
1651 goto bad_unshare_cleanup_fs; 1638 goto bad_unshare_cleanup_fs;
1652 if ((err = unshare_sighand(unshare_flags, &new_sigh))) 1639 if ((err = unshare_sighand(unshare_flags, &new_sigh)))
1653 goto bad_unshare_cleanup_ns; 1640 goto bad_unshare_cleanup_ns;
@@ -1671,7 +1658,7 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
1671 } 1658 }
1672 } 1659 }
1673 1660
1674 if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist || 1661 if (new_fs || new_ns || new_mm || new_fd || new_ulist ||
1675 new_uts || new_ipc) { 1662 new_uts || new_ipc) {
1676 1663
1677 task_lock(current); 1664 task_lock(current);
@@ -1688,17 +1675,11 @@ asmlinkage long sys_unshare(unsigned long unshare_flags)
1688 } 1675 }
1689 1676
1690 if (new_ns) { 1677 if (new_ns) {
1691 ns = current->nsproxy->namespace; 1678 ns = current->nsproxy->mnt_ns;
1692 current->nsproxy->namespace = new_ns; 1679 current->nsproxy->mnt_ns = new_ns;
1693 new_ns = ns; 1680 new_ns = ns;
1694 } 1681 }
1695 1682
1696 if (new_sigh) {
1697 sigh = current->sighand;
1698 rcu_assign_pointer(current->sighand, new_sigh);
1699 new_sigh = sigh;
1700 }
1701
1702 if (new_mm) { 1683 if (new_mm) {
1703 mm = current->mm; 1684 mm = current->mm;
1704 active_mm = current->active_mm; 1685 active_mm = current->active_mm;
@@ -1756,7 +1737,7 @@ bad_unshare_cleanup_sigh:
1756 1737
1757bad_unshare_cleanup_ns: 1738bad_unshare_cleanup_ns:
1758 if (new_ns) 1739 if (new_ns)
1759 put_namespace(new_ns); 1740 put_mnt_ns(new_ns);
1760 1741
1761bad_unshare_cleanup_fs: 1742bad_unshare_cleanup_fs:
1762 if (new_fs) 1743 if (new_fs)
diff --git a/kernel/futex.c b/kernel/futex.c
index 95989a3b4168..5a737de857d3 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -166,7 +166,7 @@ static inline int match_futex(union futex_key *key1, union futex_key *key2)
166/* 166/*
167 * Get parameters which are the keys for a futex. 167 * Get parameters which are the keys for a futex.
168 * 168 *
169 * For shared mappings, it's (page->index, vma->vm_file->f_dentry->d_inode, 169 * For shared mappings, it's (page->index, vma->vm_file->f_path.dentry->d_inode,
170 * offset_within_page). For private mappings, it's (uaddr, current->mm). 170 * offset_within_page). For private mappings, it's (uaddr, current->mm).
171 * We can usually work out the index without swapping in the page. 171 * We can usually work out the index without swapping in the page.
172 * 172 *
@@ -223,7 +223,7 @@ static int get_futex_key(u32 __user *uaddr, union futex_key *key)
223 /* 223 /*
224 * Linear file mappings are also simple. 224 * Linear file mappings are also simple.
225 */ 225 */
226 key->shared.inode = vma->vm_file->f_dentry->d_inode; 226 key->shared.inode = vma->vm_file->f_path.dentry->d_inode;
227 key->both.offset++; /* Bit 0 of offset indicates inode-based key. */ 227 key->both.offset++; /* Bit 0 of offset indicates inode-based key. */
228 if (likely(!(vma->vm_flags & VM_NONLINEAR))) { 228 if (likely(!(vma->vm_flags & VM_NONLINEAR))) {
229 key->shared.pgoff = (((address - vma->vm_start) >> PAGE_SHIFT) 229 key->shared.pgoff = (((address - vma->vm_start) >> PAGE_SHIFT)
@@ -1528,9 +1528,9 @@ static int futex_fd(u32 __user *uaddr, int signal)
1528 goto out; 1528 goto out;
1529 } 1529 }
1530 filp->f_op = &futex_fops; 1530 filp->f_op = &futex_fops;
1531 filp->f_vfsmnt = mntget(futex_mnt); 1531 filp->f_path.mnt = mntget(futex_mnt);
1532 filp->f_dentry = dget(futex_mnt->mnt_root); 1532 filp->f_path.dentry = dget(futex_mnt->mnt_root);
1533 filp->f_mapping = filp->f_dentry->d_inode->i_mapping; 1533 filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping;
1534 1534
1535 if (signal) { 1535 if (signal) {
1536 err = __f_setown(filp, task_pid(current), PIDTYPE_PID, 1); 1536 err = __f_setown(filp, task_pid(current), PIDTYPE_PID, 1);
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 9a352667007c..61f5c717a8f5 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -54,7 +54,8 @@ static int irq_affinity_write_proc(struct file *file, const char __user *buffer,
54 unsigned int irq = (int)(long)data, full_count = count, err; 54 unsigned int irq = (int)(long)data, full_count = count, err;
55 cpumask_t new_value, tmp; 55 cpumask_t new_value, tmp;
56 56
57 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity) 57 if (!irq_desc[irq].chip->set_affinity || no_irq_affinity ||
58 CHECK_IRQ_PER_CPU(irq_desc[irq].status))
58 return -EIO; 59 return -EIO;
59 60
60 err = cpumask_parse_user(buffer, count, new_value); 61 err = cpumask_parse_user(buffer, count, new_value);
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index ab63cfc42992..6f294ff4f9ee 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -31,14 +31,14 @@
31#endif 31#endif
32 32
33/* These will be re-linked against their real values during the second link stage */ 33/* These will be re-linked against their real values during the second link stage */
34extern unsigned long kallsyms_addresses[] __attribute__((weak)); 34extern const unsigned long kallsyms_addresses[] __attribute__((weak));
35extern unsigned long kallsyms_num_syms __attribute__((weak,section("data"))); 35extern const unsigned long kallsyms_num_syms __attribute__((weak));
36extern u8 kallsyms_names[] __attribute__((weak)); 36extern const u8 kallsyms_names[] __attribute__((weak));
37 37
38extern u8 kallsyms_token_table[] __attribute__((weak)); 38extern const u8 kallsyms_token_table[] __attribute__((weak));
39extern u16 kallsyms_token_index[] __attribute__((weak)); 39extern const u16 kallsyms_token_index[] __attribute__((weak));
40 40
41extern unsigned long kallsyms_markers[] __attribute__((weak)); 41extern const unsigned long kallsyms_markers[] __attribute__((weak));
42 42
43static inline int is_kernel_inittext(unsigned long addr) 43static inline int is_kernel_inittext(unsigned long addr)
44{ 44{
@@ -84,7 +84,7 @@ static int is_ksym_addr(unsigned long addr)
84static unsigned int kallsyms_expand_symbol(unsigned int off, char *result) 84static unsigned int kallsyms_expand_symbol(unsigned int off, char *result)
85{ 85{
86 int len, skipped_first = 0; 86 int len, skipped_first = 0;
87 u8 *tptr, *data; 87 const u8 *tptr, *data;
88 88
89 /* get the compressed symbol length from the first symbol byte */ 89 /* get the compressed symbol length from the first symbol byte */
90 data = &kallsyms_names[off]; 90 data = &kallsyms_names[off];
@@ -132,7 +132,7 @@ static char kallsyms_get_symbol_type(unsigned int off)
132 * kallsyms array */ 132 * kallsyms array */
133static unsigned int get_symbol_offset(unsigned long pos) 133static unsigned int get_symbol_offset(unsigned long pos)
134{ 134{
135 u8 *name; 135 const u8 *name;
136 int i; 136 int i;
137 137
138 /* use the closest marker we have. We have markers every 256 positions, 138 /* use the closest marker we have. We have markers every 256 positions,
diff --git a/kernel/kmod.c b/kernel/kmod.c
index 8d2bea09a4ec..3a7379aa31ca 100644
--- a/kernel/kmod.c
+++ b/kernel/kmod.c
@@ -25,7 +25,7 @@
25#include <linux/kmod.h> 25#include <linux/kmod.h>
26#include <linux/smp_lock.h> 26#include <linux/smp_lock.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/namespace.h> 28#include <linux/mnt_namespace.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
30#include <linux/file.h> 30#include <linux/file.h>
31#include <linux/workqueue.h> 31#include <linux/workqueue.h>
diff --git a/kernel/mutex.c b/kernel/mutex.c
index 8c71cf72a497..e7cbbb82765b 100644
--- a/kernel/mutex.c
+++ b/kernel/mutex.c
@@ -206,6 +206,15 @@ mutex_lock_nested(struct mutex *lock, unsigned int subclass)
206} 206}
207 207
208EXPORT_SYMBOL_GPL(mutex_lock_nested); 208EXPORT_SYMBOL_GPL(mutex_lock_nested);
209
210int __sched
211mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass)
212{
213 might_sleep();
214 return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, subclass);
215}
216
217EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
209#endif 218#endif
210 219
211/* 220/*
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index 674aceb7335a..e2ce748e96af 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -17,8 +17,9 @@
17#include <linux/version.h> 17#include <linux/version.h>
18#include <linux/nsproxy.h> 18#include <linux/nsproxy.h>
19#include <linux/init_task.h> 19#include <linux/init_task.h>
20#include <linux/namespace.h> 20#include <linux/mnt_namespace.h>
21#include <linux/utsname.h> 21#include <linux/utsname.h>
22#include <linux/pid_namespace.h>
22 23
23struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy); 24struct nsproxy init_nsproxy = INIT_NSPROXY(init_nsproxy);
24 25
@@ -45,8 +46,10 @@ static inline struct nsproxy *clone_namespaces(struct nsproxy *orig)
45 struct nsproxy *ns; 46 struct nsproxy *ns;
46 47
47 ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL); 48 ns = kmemdup(orig, sizeof(struct nsproxy), GFP_KERNEL);
48 if (ns) 49 if (ns) {
49 atomic_set(&ns->count, 1); 50 atomic_set(&ns->count, 1);
51 ns->id = -1;
52 }
50 return ns; 53 return ns;
51} 54}
52 55
@@ -60,12 +63,14 @@ struct nsproxy *dup_namespaces(struct nsproxy *orig)
60 struct nsproxy *ns = clone_namespaces(orig); 63 struct nsproxy *ns = clone_namespaces(orig);
61 64
62 if (ns) { 65 if (ns) {
63 if (ns->namespace) 66 if (ns->mnt_ns)
64 get_namespace(ns->namespace); 67 get_mnt_ns(ns->mnt_ns);
65 if (ns->uts_ns) 68 if (ns->uts_ns)
66 get_uts_ns(ns->uts_ns); 69 get_uts_ns(ns->uts_ns);
67 if (ns->ipc_ns) 70 if (ns->ipc_ns)
68 get_ipc_ns(ns->ipc_ns); 71 get_ipc_ns(ns->ipc_ns);
72 if (ns->pid_ns)
73 get_pid_ns(ns->pid_ns);
69 } 74 }
70 75
71 return ns; 76 return ns;
@@ -97,7 +102,7 @@ int copy_namespaces(int flags, struct task_struct *tsk)
97 102
98 tsk->nsproxy = new_ns; 103 tsk->nsproxy = new_ns;
99 104
100 err = copy_namespace(flags, tsk); 105 err = copy_mnt_ns(flags, tsk);
101 if (err) 106 if (err)
102 goto out_ns; 107 goto out_ns;
103 108
@@ -109,16 +114,23 @@ int copy_namespaces(int flags, struct task_struct *tsk)
109 if (err) 114 if (err)
110 goto out_ipc; 115 goto out_ipc;
111 116
117 err = copy_pid_ns(flags, tsk);
118 if (err)
119 goto out_pid;
120
112out: 121out:
113 put_nsproxy(old_ns); 122 put_nsproxy(old_ns);
114 return err; 123 return err;
115 124
125out_pid:
126 if (new_ns->ipc_ns)
127 put_ipc_ns(new_ns->ipc_ns);
116out_ipc: 128out_ipc:
117 if (new_ns->uts_ns) 129 if (new_ns->uts_ns)
118 put_uts_ns(new_ns->uts_ns); 130 put_uts_ns(new_ns->uts_ns);
119out_uts: 131out_uts:
120 if (new_ns->namespace) 132 if (new_ns->mnt_ns)
121 put_namespace(new_ns->namespace); 133 put_mnt_ns(new_ns->mnt_ns);
122out_ns: 134out_ns:
123 tsk->nsproxy = old_ns; 135 tsk->nsproxy = old_ns;
124 kfree(new_ns); 136 kfree(new_ns);
@@ -127,11 +139,13 @@ out_ns:
127 139
128void free_nsproxy(struct nsproxy *ns) 140void free_nsproxy(struct nsproxy *ns)
129{ 141{
130 if (ns->namespace) 142 if (ns->mnt_ns)
131 put_namespace(ns->namespace); 143 put_mnt_ns(ns->mnt_ns);
132 if (ns->uts_ns) 144 if (ns->uts_ns)
133 put_uts_ns(ns->uts_ns); 145 put_uts_ns(ns->uts_ns);
134 if (ns->ipc_ns) 146 if (ns->ipc_ns)
135 put_ipc_ns(ns->ipc_ns); 147 put_ipc_ns(ns->ipc_ns);
136 kfree(ns); 148 if (ns->pid_ns)
149 put_pid_ns(ns->pid_ns);
150 kfree(ns);
137} 151}
diff --git a/kernel/pid.c b/kernel/pid.c
index a48879b0b921..2efe9d8d367b 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -26,7 +26,7 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/bootmem.h> 27#include <linux/bootmem.h>
28#include <linux/hash.h> 28#include <linux/hash.h>
29#include <linux/pspace.h> 29#include <linux/pid_namespace.h>
30 30
31#define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift) 31#define pid_hashfn(nr) hash_long((unsigned long)nr, pidhash_shift)
32static struct hlist_head *pid_hash; 32static struct hlist_head *pid_hash;
@@ -43,9 +43,10 @@ int pid_max_max = PID_MAX_LIMIT;
43#define BITS_PER_PAGE (PAGE_SIZE*8) 43#define BITS_PER_PAGE (PAGE_SIZE*8)
44#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1) 44#define BITS_PER_PAGE_MASK (BITS_PER_PAGE-1)
45 45
46static inline int mk_pid(struct pspace *pspace, struct pidmap *map, int off) 46static inline int mk_pid(struct pid_namespace *pid_ns,
47 struct pidmap *map, int off)
47{ 48{
48 return (map - pspace->pidmap)*BITS_PER_PAGE + off; 49 return (map - pid_ns->pidmap)*BITS_PER_PAGE + off;
49} 50}
50 51
51#define find_next_offset(map, off) \ 52#define find_next_offset(map, off) \
@@ -57,11 +58,15 @@ static inline int mk_pid(struct pspace *pspace, struct pidmap *map, int off)
57 * value does not cause lots of bitmaps to be allocated, but 58 * value does not cause lots of bitmaps to be allocated, but
58 * the scheme scales to up to 4 million PIDs, runtime. 59 * the scheme scales to up to 4 million PIDs, runtime.
59 */ 60 */
60struct pspace init_pspace = { 61struct pid_namespace init_pid_ns = {
62 .kref = {
63 .refcount = ATOMIC_INIT(2),
64 },
61 .pidmap = { 65 .pidmap = {
62 [ 0 ... PIDMAP_ENTRIES-1] = { ATOMIC_INIT(BITS_PER_PAGE), NULL } 66 [ 0 ... PIDMAP_ENTRIES-1] = { ATOMIC_INIT(BITS_PER_PAGE), NULL }
63 }, 67 },
64 .last_pid = 0 68 .last_pid = 0,
69 .child_reaper = &init_task
65}; 70};
66 71
67/* 72/*
@@ -80,25 +85,25 @@ struct pspace init_pspace = {
80 85
81static __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock); 86static __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock);
82 87
83static fastcall void free_pidmap(struct pspace *pspace, int pid) 88static fastcall void free_pidmap(struct pid_namespace *pid_ns, int pid)
84{ 89{
85 struct pidmap *map = pspace->pidmap + pid / BITS_PER_PAGE; 90 struct pidmap *map = pid_ns->pidmap + pid / BITS_PER_PAGE;
86 int offset = pid & BITS_PER_PAGE_MASK; 91 int offset = pid & BITS_PER_PAGE_MASK;
87 92
88 clear_bit(offset, map->page); 93 clear_bit(offset, map->page);
89 atomic_inc(&map->nr_free); 94 atomic_inc(&map->nr_free);
90} 95}
91 96
92static int alloc_pidmap(struct pspace *pspace) 97static int alloc_pidmap(struct pid_namespace *pid_ns)
93{ 98{
94 int i, offset, max_scan, pid, last = pspace->last_pid; 99 int i, offset, max_scan, pid, last = pid_ns->last_pid;
95 struct pidmap *map; 100 struct pidmap *map;
96 101
97 pid = last + 1; 102 pid = last + 1;
98 if (pid >= pid_max) 103 if (pid >= pid_max)
99 pid = RESERVED_PIDS; 104 pid = RESERVED_PIDS;
100 offset = pid & BITS_PER_PAGE_MASK; 105 offset = pid & BITS_PER_PAGE_MASK;
101 map = &pspace->pidmap[pid/BITS_PER_PAGE]; 106 map = &pid_ns->pidmap[pid/BITS_PER_PAGE];
102 max_scan = (pid_max + BITS_PER_PAGE - 1)/BITS_PER_PAGE - !offset; 107 max_scan = (pid_max + BITS_PER_PAGE - 1)/BITS_PER_PAGE - !offset;
103 for (i = 0; i <= max_scan; ++i) { 108 for (i = 0; i <= max_scan; ++i) {
104 if (unlikely(!map->page)) { 109 if (unlikely(!map->page)) {
@@ -120,11 +125,11 @@ static int alloc_pidmap(struct pspace *pspace)
120 do { 125 do {
121 if (!test_and_set_bit(offset, map->page)) { 126 if (!test_and_set_bit(offset, map->page)) {
122 atomic_dec(&map->nr_free); 127 atomic_dec(&map->nr_free);
123 pspace->last_pid = pid; 128 pid_ns->last_pid = pid;
124 return pid; 129 return pid;
125 } 130 }
126 offset = find_next_offset(map, offset); 131 offset = find_next_offset(map, offset);
127 pid = mk_pid(pspace, map, offset); 132 pid = mk_pid(pid_ns, map, offset);
128 /* 133 /*
129 * find_next_offset() found a bit, the pid from it 134 * find_next_offset() found a bit, the pid from it
130 * is in-bounds, and if we fell back to the last 135 * is in-bounds, and if we fell back to the last
@@ -135,34 +140,34 @@ static int alloc_pidmap(struct pspace *pspace)
135 (i != max_scan || pid < last || 140 (i != max_scan || pid < last ||
136 !((last+1) & BITS_PER_PAGE_MASK))); 141 !((last+1) & BITS_PER_PAGE_MASK)));
137 } 142 }
138 if (map < &pspace->pidmap[(pid_max-1)/BITS_PER_PAGE]) { 143 if (map < &pid_ns->pidmap[(pid_max-1)/BITS_PER_PAGE]) {
139 ++map; 144 ++map;
140 offset = 0; 145 offset = 0;
141 } else { 146 } else {
142 map = &pspace->pidmap[0]; 147 map = &pid_ns->pidmap[0];
143 offset = RESERVED_PIDS; 148 offset = RESERVED_PIDS;
144 if (unlikely(last == offset)) 149 if (unlikely(last == offset))
145 break; 150 break;
146 } 151 }
147 pid = mk_pid(pspace, map, offset); 152 pid = mk_pid(pid_ns, map, offset);
148 } 153 }
149 return -1; 154 return -1;
150} 155}
151 156
152static int next_pidmap(struct pspace *pspace, int last) 157static int next_pidmap(struct pid_namespace *pid_ns, int last)
153{ 158{
154 int offset; 159 int offset;
155 struct pidmap *map, *end; 160 struct pidmap *map, *end;
156 161
157 offset = (last + 1) & BITS_PER_PAGE_MASK; 162 offset = (last + 1) & BITS_PER_PAGE_MASK;
158 map = &pspace->pidmap[(last + 1)/BITS_PER_PAGE]; 163 map = &pid_ns->pidmap[(last + 1)/BITS_PER_PAGE];
159 end = &pspace->pidmap[PIDMAP_ENTRIES]; 164 end = &pid_ns->pidmap[PIDMAP_ENTRIES];
160 for (; map < end; map++, offset = 0) { 165 for (; map < end; map++, offset = 0) {
161 if (unlikely(!map->page)) 166 if (unlikely(!map->page))
162 continue; 167 continue;
163 offset = find_next_bit((map)->page, BITS_PER_PAGE, offset); 168 offset = find_next_bit((map)->page, BITS_PER_PAGE, offset);
164 if (offset < BITS_PER_PAGE) 169 if (offset < BITS_PER_PAGE)
165 return mk_pid(pspace, map, offset); 170 return mk_pid(pid_ns, map, offset);
166 } 171 }
167 return -1; 172 return -1;
168} 173}
@@ -192,7 +197,7 @@ fastcall void free_pid(struct pid *pid)
192 hlist_del_rcu(&pid->pid_chain); 197 hlist_del_rcu(&pid->pid_chain);
193 spin_unlock_irqrestore(&pidmap_lock, flags); 198 spin_unlock_irqrestore(&pidmap_lock, flags);
194 199
195 free_pidmap(&init_pspace, pid->nr); 200 free_pidmap(current->nsproxy->pid_ns, pid->nr);
196 call_rcu(&pid->rcu, delayed_put_pid); 201 call_rcu(&pid->rcu, delayed_put_pid);
197} 202}
198 203
@@ -206,7 +211,7 @@ struct pid *alloc_pid(void)
206 if (!pid) 211 if (!pid)
207 goto out; 212 goto out;
208 213
209 nr = alloc_pidmap(&init_pspace); 214 nr = alloc_pidmap(current->nsproxy->pid_ns);
210 if (nr < 0) 215 if (nr < 0)
211 goto out_free; 216 goto out_free;
212 217
@@ -348,13 +353,33 @@ struct pid *find_ge_pid(int nr)
348 pid = find_pid(nr); 353 pid = find_pid(nr);
349 if (pid) 354 if (pid)
350 break; 355 break;
351 nr = next_pidmap(&init_pspace, nr); 356 nr = next_pidmap(current->nsproxy->pid_ns, nr);
352 } while (nr > 0); 357 } while (nr > 0);
353 358
354 return pid; 359 return pid;
355} 360}
356EXPORT_SYMBOL_GPL(find_get_pid); 361EXPORT_SYMBOL_GPL(find_get_pid);
357 362
363int copy_pid_ns(int flags, struct task_struct *tsk)
364{
365 struct pid_namespace *old_ns = tsk->nsproxy->pid_ns;
366 int err = 0;
367
368 if (!old_ns)
369 return 0;
370
371 get_pid_ns(old_ns);
372 return err;
373}
374
375void free_pid_ns(struct kref *kref)
376{
377 struct pid_namespace *ns;
378
379 ns = container_of(kref, struct pid_namespace, kref);
380 kfree(ns);
381}
382
358/* 383/*
359 * The pid hash table is scaled according to the amount of memory in the 384 * The pid hash table is scaled according to the amount of memory in the
360 * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or 385 * machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or
@@ -382,10 +407,10 @@ void __init pidhash_init(void)
382 407
383void __init pidmap_init(void) 408void __init pidmap_init(void)
384{ 409{
385 init_pspace.pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL); 410 init_pid_ns.pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL);
386 /* Reserve PID 0. We never call free_pidmap(0) */ 411 /* Reserve PID 0. We never call free_pidmap(0) */
387 set_bit(0, init_pspace.pidmap[0].page); 412 set_bit(0, init_pid_ns.pidmap[0].page);
388 atomic_dec(&init_pspace.pidmap[0].nr_free); 413 atomic_dec(&init_pid_ns.pidmap[0].nr_free);
389 414
390 pid_cachep = kmem_cache_create("pid", sizeof(struct pid), 415 pid_cachep = kmem_cache_create("pid", sizeof(struct pid),
391 __alignof__(struct pid), 416 __alignof__(struct pid),
diff --git a/kernel/relay.c b/kernel/relay.c
index 75a3a9a7efc2..818e514729cf 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -959,7 +959,7 @@ static inline ssize_t relay_file_read_subbufs(struct file *filp,
959 if (!desc->count) 959 if (!desc->count)
960 return 0; 960 return 0;
961 961
962 mutex_lock(&filp->f_dentry->d_inode->i_mutex); 962 mutex_lock(&filp->f_path.dentry->d_inode->i_mutex);
963 do { 963 do {
964 if (!relay_file_read_avail(buf, *ppos)) 964 if (!relay_file_read_avail(buf, *ppos))
965 break; 965 break;
@@ -979,7 +979,7 @@ static inline ssize_t relay_file_read_subbufs(struct file *filp,
979 *ppos = relay_file_read_end_pos(buf, read_start, ret); 979 *ppos = relay_file_read_end_pos(buf, read_start, ret);
980 } 980 }
981 } while (desc->count && ret); 981 } while (desc->count && ret);
982 mutex_unlock(&filp->f_dentry->d_inode->i_mutex); 982 mutex_unlock(&filp->f_path.dentry->d_inode->i_mutex);
983 983
984 return desc->written; 984 return desc->written;
985} 985}
diff --git a/kernel/sched.c b/kernel/sched.c
index f385eff4682d..8a0afb97af71 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -225,8 +225,10 @@ struct rq {
225 unsigned long nr_uninterruptible; 225 unsigned long nr_uninterruptible;
226 226
227 unsigned long expired_timestamp; 227 unsigned long expired_timestamp;
228 unsigned long long timestamp_last_tick; 228 /* Cached timestamp set by update_cpu_clock() */
229 unsigned long long most_recent_timestamp;
229 struct task_struct *curr, *idle; 230 struct task_struct *curr, *idle;
231 unsigned long next_balance;
230 struct mm_struct *prev_mm; 232 struct mm_struct *prev_mm;
231 struct prio_array *active, *expired, arrays[2]; 233 struct prio_array *active, *expired, arrays[2];
232 int best_expired_prio; 234 int best_expired_prio;
@@ -426,7 +428,7 @@ static inline void task_rq_unlock(struct rq *rq, unsigned long *flags)
426 * bump this up when changing the output format or the meaning of an existing 428 * bump this up when changing the output format or the meaning of an existing
427 * format, so that tools can adapt (or abort) 429 * format, so that tools can adapt (or abort)
428 */ 430 */
429#define SCHEDSTAT_VERSION 12 431#define SCHEDSTAT_VERSION 14
430 432
431static int show_schedstat(struct seq_file *seq, void *v) 433static int show_schedstat(struct seq_file *seq, void *v)
432{ 434{
@@ -464,7 +466,8 @@ static int show_schedstat(struct seq_file *seq, void *v)
464 seq_printf(seq, "domain%d %s", dcnt++, mask_str); 466 seq_printf(seq, "domain%d %s", dcnt++, mask_str);
465 for (itype = SCHED_IDLE; itype < MAX_IDLE_TYPES; 467 for (itype = SCHED_IDLE; itype < MAX_IDLE_TYPES;
466 itype++) { 468 itype++) {
467 seq_printf(seq, " %lu %lu %lu %lu %lu %lu %lu %lu", 469 seq_printf(seq, " %lu %lu %lu %lu %lu %lu %lu "
470 "%lu",
468 sd->lb_cnt[itype], 471 sd->lb_cnt[itype],
469 sd->lb_balanced[itype], 472 sd->lb_balanced[itype],
470 sd->lb_failed[itype], 473 sd->lb_failed[itype],
@@ -474,11 +477,13 @@ static int show_schedstat(struct seq_file *seq, void *v)
474 sd->lb_nobusyq[itype], 477 sd->lb_nobusyq[itype],
475 sd->lb_nobusyg[itype]); 478 sd->lb_nobusyg[itype]);
476 } 479 }
477 seq_printf(seq, " %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu %lu\n", 480 seq_printf(seq, " %lu %lu %lu %lu %lu %lu %lu %lu %lu"
481 " %lu %lu %lu\n",
478 sd->alb_cnt, sd->alb_failed, sd->alb_pushed, 482 sd->alb_cnt, sd->alb_failed, sd->alb_pushed,
479 sd->sbe_cnt, sd->sbe_balanced, sd->sbe_pushed, 483 sd->sbe_cnt, sd->sbe_balanced, sd->sbe_pushed,
480 sd->sbf_cnt, sd->sbf_balanced, sd->sbf_pushed, 484 sd->sbf_cnt, sd->sbf_balanced, sd->sbf_pushed,
481 sd->ttwu_wake_remote, sd->ttwu_move_affine, sd->ttwu_move_balance); 485 sd->ttwu_wake_remote, sd->ttwu_move_affine,
486 sd->ttwu_move_balance);
482 } 487 }
483 preempt_enable(); 488 preempt_enable();
484#endif 489#endif
@@ -547,7 +552,7 @@ rq_sched_info_depart(struct rq *rq, unsigned long delta_jiffies)
547#endif 552#endif
548 553
549/* 554/*
550 * rq_lock - lock a given runqueue and disable interrupts. 555 * this_rq_lock - lock this runqueue and disable interrupts.
551 */ 556 */
552static inline struct rq *this_rq_lock(void) 557static inline struct rq *this_rq_lock(void)
553 __acquires(rq->lock) 558 __acquires(rq->lock)
@@ -938,13 +943,16 @@ static void activate_task(struct task_struct *p, struct rq *rq, int local)
938{ 943{
939 unsigned long long now; 944 unsigned long long now;
940 945
946 if (rt_task(p))
947 goto out;
948
941 now = sched_clock(); 949 now = sched_clock();
942#ifdef CONFIG_SMP 950#ifdef CONFIG_SMP
943 if (!local) { 951 if (!local) {
944 /* Compensate for drifting sched_clock */ 952 /* Compensate for drifting sched_clock */
945 struct rq *this_rq = this_rq(); 953 struct rq *this_rq = this_rq();
946 now = (now - this_rq->timestamp_last_tick) 954 now = (now - this_rq->most_recent_timestamp)
947 + rq->timestamp_last_tick; 955 + rq->most_recent_timestamp;
948 } 956 }
949#endif 957#endif
950 958
@@ -959,8 +967,7 @@ static void activate_task(struct task_struct *p, struct rq *rq, int local)
959 (now - p->timestamp) >> 20); 967 (now - p->timestamp) >> 20);
960 } 968 }
961 969
962 if (!rt_task(p)) 970 p->prio = recalc_task_prio(p, now);
963 p->prio = recalc_task_prio(p, now);
964 971
965 /* 972 /*
966 * This checks to make sure it's not an uninterruptible task 973 * This checks to make sure it's not an uninterruptible task
@@ -985,7 +992,7 @@ static void activate_task(struct task_struct *p, struct rq *rq, int local)
985 } 992 }
986 } 993 }
987 p->timestamp = now; 994 p->timestamp = now;
988 995out:
989 __activate_task(p, rq); 996 __activate_task(p, rq);
990} 997}
991 998
@@ -1450,7 +1457,9 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
1450 1457
1451 if (this_sd->flags & SD_WAKE_AFFINE) { 1458 if (this_sd->flags & SD_WAKE_AFFINE) {
1452 unsigned long tl = this_load; 1459 unsigned long tl = this_load;
1453 unsigned long tl_per_task = cpu_avg_load_per_task(this_cpu); 1460 unsigned long tl_per_task;
1461
1462 tl_per_task = cpu_avg_load_per_task(this_cpu);
1454 1463
1455 /* 1464 /*
1456 * If sync wakeup then subtract the (maximum possible) 1465 * If sync wakeup then subtract the (maximum possible)
@@ -1688,8 +1697,8 @@ void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
1688 * Not the local CPU - must adjust timestamp. This should 1697 * Not the local CPU - must adjust timestamp. This should
1689 * get optimised away in the !CONFIG_SMP case. 1698 * get optimised away in the !CONFIG_SMP case.
1690 */ 1699 */
1691 p->timestamp = (p->timestamp - this_rq->timestamp_last_tick) 1700 p->timestamp = (p->timestamp - this_rq->most_recent_timestamp)
1692 + rq->timestamp_last_tick; 1701 + rq->most_recent_timestamp;
1693 __activate_task(p, rq); 1702 __activate_task(p, rq);
1694 if (TASK_PREEMPTS_CURR(p, rq)) 1703 if (TASK_PREEMPTS_CURR(p, rq))
1695 resched_task(rq->curr); 1704 resched_task(rq->curr);
@@ -1952,6 +1961,7 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2)
1952 __acquires(rq1->lock) 1961 __acquires(rq1->lock)
1953 __acquires(rq2->lock) 1962 __acquires(rq2->lock)
1954{ 1963{
1964 BUG_ON(!irqs_disabled());
1955 if (rq1 == rq2) { 1965 if (rq1 == rq2) {
1956 spin_lock(&rq1->lock); 1966 spin_lock(&rq1->lock);
1957 __acquire(rq2->lock); /* Fake it out ;) */ 1967 __acquire(rq2->lock); /* Fake it out ;) */
@@ -1991,6 +2001,11 @@ static void double_lock_balance(struct rq *this_rq, struct rq *busiest)
1991 __acquires(busiest->lock) 2001 __acquires(busiest->lock)
1992 __acquires(this_rq->lock) 2002 __acquires(this_rq->lock)
1993{ 2003{
2004 if (unlikely(!irqs_disabled())) {
2005 /* printk() doesn't work good under rq->lock */
2006 spin_unlock(&this_rq->lock);
2007 BUG_ON(1);
2008 }
1994 if (unlikely(!spin_trylock(&busiest->lock))) { 2009 if (unlikely(!spin_trylock(&busiest->lock))) {
1995 if (busiest < this_rq) { 2010 if (busiest < this_rq) {
1996 spin_unlock(&this_rq->lock); 2011 spin_unlock(&this_rq->lock);
@@ -2061,8 +2076,8 @@ static void pull_task(struct rq *src_rq, struct prio_array *src_array,
2061 set_task_cpu(p, this_cpu); 2076 set_task_cpu(p, this_cpu);
2062 inc_nr_running(p, this_rq); 2077 inc_nr_running(p, this_rq);
2063 enqueue_task(p, this_array); 2078 enqueue_task(p, this_array);
2064 p->timestamp = (p->timestamp - src_rq->timestamp_last_tick) 2079 p->timestamp = (p->timestamp - src_rq->most_recent_timestamp)
2065 + this_rq->timestamp_last_tick; 2080 + this_rq->most_recent_timestamp;
2066 /* 2081 /*
2067 * Note that idle threads have a prio of MAX_PRIO, for this test 2082 * Note that idle threads have a prio of MAX_PRIO, for this test
2068 * to be always true for them. 2083 * to be always true for them.
@@ -2098,10 +2113,15 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu,
2098 * 2) too many balance attempts have failed. 2113 * 2) too many balance attempts have failed.
2099 */ 2114 */
2100 2115
2101 if (sd->nr_balance_failed > sd->cache_nice_tries) 2116 if (sd->nr_balance_failed > sd->cache_nice_tries) {
2117#ifdef CONFIG_SCHEDSTATS
2118 if (task_hot(p, rq->most_recent_timestamp, sd))
2119 schedstat_inc(sd, lb_hot_gained[idle]);
2120#endif
2102 return 1; 2121 return 1;
2122 }
2103 2123
2104 if (task_hot(p, rq->timestamp_last_tick, sd)) 2124 if (task_hot(p, rq->most_recent_timestamp, sd))
2105 return 0; 2125 return 0;
2106 return 1; 2126 return 1;
2107} 2127}
@@ -2199,11 +2219,6 @@ skip_queue:
2199 goto skip_bitmap; 2219 goto skip_bitmap;
2200 } 2220 }
2201 2221
2202#ifdef CONFIG_SCHEDSTATS
2203 if (task_hot(tmp, busiest->timestamp_last_tick, sd))
2204 schedstat_inc(sd, lb_hot_gained[idle]);
2205#endif
2206
2207 pull_task(busiest, array, tmp, this_rq, dst_array, this_cpu); 2222 pull_task(busiest, array, tmp, this_rq, dst_array, this_cpu);
2208 pulled++; 2223 pulled++;
2209 rem_load_move -= tmp->load_weight; 2224 rem_load_move -= tmp->load_weight;
@@ -2241,7 +2256,7 @@ out:
2241static struct sched_group * 2256static struct sched_group *
2242find_busiest_group(struct sched_domain *sd, int this_cpu, 2257find_busiest_group(struct sched_domain *sd, int this_cpu,
2243 unsigned long *imbalance, enum idle_type idle, int *sd_idle, 2258 unsigned long *imbalance, enum idle_type idle, int *sd_idle,
2244 cpumask_t *cpus) 2259 cpumask_t *cpus, int *balance)
2245{ 2260{
2246 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; 2261 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups;
2247 unsigned long max_load, avg_load, total_load, this_load, total_pwr; 2262 unsigned long max_load, avg_load, total_load, this_load, total_pwr;
@@ -2270,10 +2285,14 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
2270 unsigned long load, group_capacity; 2285 unsigned long load, group_capacity;
2271 int local_group; 2286 int local_group;
2272 int i; 2287 int i;
2288 unsigned int balance_cpu = -1, first_idle_cpu = 0;
2273 unsigned long sum_nr_running, sum_weighted_load; 2289 unsigned long sum_nr_running, sum_weighted_load;
2274 2290
2275 local_group = cpu_isset(this_cpu, group->cpumask); 2291 local_group = cpu_isset(this_cpu, group->cpumask);
2276 2292
2293 if (local_group)
2294 balance_cpu = first_cpu(group->cpumask);
2295
2277 /* Tally up the load of all CPUs in the group */ 2296 /* Tally up the load of all CPUs in the group */
2278 sum_weighted_load = sum_nr_running = avg_load = 0; 2297 sum_weighted_load = sum_nr_running = avg_load = 0;
2279 2298
@@ -2289,9 +2308,14 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
2289 *sd_idle = 0; 2308 *sd_idle = 0;
2290 2309
2291 /* Bias balancing toward cpus of our domain */ 2310 /* Bias balancing toward cpus of our domain */
2292 if (local_group) 2311 if (local_group) {
2312 if (idle_cpu(i) && !first_idle_cpu) {
2313 first_idle_cpu = 1;
2314 balance_cpu = i;
2315 }
2316
2293 load = target_load(i, load_idx); 2317 load = target_load(i, load_idx);
2294 else 2318 } else
2295 load = source_load(i, load_idx); 2319 load = source_load(i, load_idx);
2296 2320
2297 avg_load += load; 2321 avg_load += load;
@@ -2299,6 +2323,16 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
2299 sum_weighted_load += rq->raw_weighted_load; 2323 sum_weighted_load += rq->raw_weighted_load;
2300 } 2324 }
2301 2325
2326 /*
2327 * First idle cpu or the first cpu(busiest) in this sched group
2328 * is eligible for doing load balancing at this and above
2329 * domains.
2330 */
2331 if (local_group && balance_cpu != this_cpu && balance) {
2332 *balance = 0;
2333 goto ret;
2334 }
2335
2302 total_load += avg_load; 2336 total_load += avg_load;
2303 total_pwr += group->cpu_power; 2337 total_pwr += group->cpu_power;
2304 2338
@@ -2458,18 +2492,21 @@ small_imbalance:
2458 pwr_now /= SCHED_LOAD_SCALE; 2492 pwr_now /= SCHED_LOAD_SCALE;
2459 2493
2460 /* Amount of load we'd subtract */ 2494 /* Amount of load we'd subtract */
2461 tmp = busiest_load_per_task*SCHED_LOAD_SCALE/busiest->cpu_power; 2495 tmp = busiest_load_per_task * SCHED_LOAD_SCALE /
2496 busiest->cpu_power;
2462 if (max_load > tmp) 2497 if (max_load > tmp)
2463 pwr_move += busiest->cpu_power * 2498 pwr_move += busiest->cpu_power *
2464 min(busiest_load_per_task, max_load - tmp); 2499 min(busiest_load_per_task, max_load - tmp);
2465 2500
2466 /* Amount of load we'd add */ 2501 /* Amount of load we'd add */
2467 if (max_load*busiest->cpu_power < 2502 if (max_load * busiest->cpu_power <
2468 busiest_load_per_task*SCHED_LOAD_SCALE) 2503 busiest_load_per_task * SCHED_LOAD_SCALE)
2469 tmp = max_load*busiest->cpu_power/this->cpu_power; 2504 tmp = max_load * busiest->cpu_power / this->cpu_power;
2470 else 2505 else
2471 tmp = busiest_load_per_task*SCHED_LOAD_SCALE/this->cpu_power; 2506 tmp = busiest_load_per_task * SCHED_LOAD_SCALE /
2472 pwr_move += this->cpu_power*min(this_load_per_task, this_load + tmp); 2507 this->cpu_power;
2508 pwr_move += this->cpu_power *
2509 min(this_load_per_task, this_load + tmp);
2473 pwr_move /= SCHED_LOAD_SCALE; 2510 pwr_move /= SCHED_LOAD_SCALE;
2474 2511
2475 /* Move if we gain throughput */ 2512 /* Move if we gain throughput */
@@ -2490,8 +2527,8 @@ out_balanced:
2490 *imbalance = min_load_per_task; 2527 *imbalance = min_load_per_task;
2491 return group_min; 2528 return group_min;
2492 } 2529 }
2493ret:
2494#endif 2530#endif
2531ret:
2495 *imbalance = 0; 2532 *imbalance = 0;
2496 return NULL; 2533 return NULL;
2497} 2534}
@@ -2540,17 +2577,17 @@ static inline unsigned long minus_1_or_zero(unsigned long n)
2540/* 2577/*
2541 * Check this_cpu to ensure it is balanced within domain. Attempt to move 2578 * Check this_cpu to ensure it is balanced within domain. Attempt to move
2542 * tasks if there is an imbalance. 2579 * tasks if there is an imbalance.
2543 *
2544 * Called with this_rq unlocked.
2545 */ 2580 */
2546static int load_balance(int this_cpu, struct rq *this_rq, 2581static int load_balance(int this_cpu, struct rq *this_rq,
2547 struct sched_domain *sd, enum idle_type idle) 2582 struct sched_domain *sd, enum idle_type idle,
2583 int *balance)
2548{ 2584{
2549 int nr_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; 2585 int nr_moved, all_pinned = 0, active_balance = 0, sd_idle = 0;
2550 struct sched_group *group; 2586 struct sched_group *group;
2551 unsigned long imbalance; 2587 unsigned long imbalance;
2552 struct rq *busiest; 2588 struct rq *busiest;
2553 cpumask_t cpus = CPU_MASK_ALL; 2589 cpumask_t cpus = CPU_MASK_ALL;
2590 unsigned long flags;
2554 2591
2555 /* 2592 /*
2556 * When power savings policy is enabled for the parent domain, idle 2593 * When power savings policy is enabled for the parent domain, idle
@@ -2566,7 +2603,11 @@ static int load_balance(int this_cpu, struct rq *this_rq,
2566 2603
2567redo: 2604redo:
2568 group = find_busiest_group(sd, this_cpu, &imbalance, idle, &sd_idle, 2605 group = find_busiest_group(sd, this_cpu, &imbalance, idle, &sd_idle,
2569 &cpus); 2606 &cpus, balance);
2607
2608 if (*balance == 0)
2609 goto out_balanced;
2610
2570 if (!group) { 2611 if (!group) {
2571 schedstat_inc(sd, lb_nobusyg[idle]); 2612 schedstat_inc(sd, lb_nobusyg[idle]);
2572 goto out_balanced; 2613 goto out_balanced;
@@ -2590,11 +2631,13 @@ redo:
2590 * still unbalanced. nr_moved simply stays zero, so it is 2631 * still unbalanced. nr_moved simply stays zero, so it is
2591 * correctly treated as an imbalance. 2632 * correctly treated as an imbalance.
2592 */ 2633 */
2634 local_irq_save(flags);
2593 double_rq_lock(this_rq, busiest); 2635 double_rq_lock(this_rq, busiest);
2594 nr_moved = move_tasks(this_rq, this_cpu, busiest, 2636 nr_moved = move_tasks(this_rq, this_cpu, busiest,
2595 minus_1_or_zero(busiest->nr_running), 2637 minus_1_or_zero(busiest->nr_running),
2596 imbalance, sd, idle, &all_pinned); 2638 imbalance, sd, idle, &all_pinned);
2597 double_rq_unlock(this_rq, busiest); 2639 double_rq_unlock(this_rq, busiest);
2640 local_irq_restore(flags);
2598 2641
2599 /* All tasks on this runqueue were pinned by CPU affinity */ 2642 /* All tasks on this runqueue were pinned by CPU affinity */
2600 if (unlikely(all_pinned)) { 2643 if (unlikely(all_pinned)) {
@@ -2611,13 +2654,13 @@ redo:
2611 2654
2612 if (unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2)) { 2655 if (unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2)) {
2613 2656
2614 spin_lock(&busiest->lock); 2657 spin_lock_irqsave(&busiest->lock, flags);
2615 2658
2616 /* don't kick the migration_thread, if the curr 2659 /* don't kick the migration_thread, if the curr
2617 * task on busiest cpu can't be moved to this_cpu 2660 * task on busiest cpu can't be moved to this_cpu
2618 */ 2661 */
2619 if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { 2662 if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) {
2620 spin_unlock(&busiest->lock); 2663 spin_unlock_irqrestore(&busiest->lock, flags);
2621 all_pinned = 1; 2664 all_pinned = 1;
2622 goto out_one_pinned; 2665 goto out_one_pinned;
2623 } 2666 }
@@ -2627,7 +2670,7 @@ redo:
2627 busiest->push_cpu = this_cpu; 2670 busiest->push_cpu = this_cpu;
2628 active_balance = 1; 2671 active_balance = 1;
2629 } 2672 }
2630 spin_unlock(&busiest->lock); 2673 spin_unlock_irqrestore(&busiest->lock, flags);
2631 if (active_balance) 2674 if (active_balance)
2632 wake_up_process(busiest->migration_thread); 2675 wake_up_process(busiest->migration_thread);
2633 2676
@@ -2706,7 +2749,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd)
2706 schedstat_inc(sd, lb_cnt[NEWLY_IDLE]); 2749 schedstat_inc(sd, lb_cnt[NEWLY_IDLE]);
2707redo: 2750redo:
2708 group = find_busiest_group(sd, this_cpu, &imbalance, NEWLY_IDLE, 2751 group = find_busiest_group(sd, this_cpu, &imbalance, NEWLY_IDLE,
2709 &sd_idle, &cpus); 2752 &sd_idle, &cpus, NULL);
2710 if (!group) { 2753 if (!group) {
2711 schedstat_inc(sd, lb_nobusyg[NEWLY_IDLE]); 2754 schedstat_inc(sd, lb_nobusyg[NEWLY_IDLE]);
2712 goto out_balanced; 2755 goto out_balanced;
@@ -2766,14 +2809,28 @@ out_balanced:
2766static void idle_balance(int this_cpu, struct rq *this_rq) 2809static void idle_balance(int this_cpu, struct rq *this_rq)
2767{ 2810{
2768 struct sched_domain *sd; 2811 struct sched_domain *sd;
2812 int pulled_task = 0;
2813 unsigned long next_balance = jiffies + 60 * HZ;
2769 2814
2770 for_each_domain(this_cpu, sd) { 2815 for_each_domain(this_cpu, sd) {
2771 if (sd->flags & SD_BALANCE_NEWIDLE) { 2816 if (sd->flags & SD_BALANCE_NEWIDLE) {
2772 /* If we've pulled tasks over stop searching: */ 2817 /* If we've pulled tasks over stop searching: */
2773 if (load_balance_newidle(this_cpu, this_rq, sd)) 2818 pulled_task = load_balance_newidle(this_cpu,
2819 this_rq, sd);
2820 if (time_after(next_balance,
2821 sd->last_balance + sd->balance_interval))
2822 next_balance = sd->last_balance
2823 + sd->balance_interval;
2824 if (pulled_task)
2774 break; 2825 break;
2775 } 2826 }
2776 } 2827 }
2828 if (!pulled_task)
2829 /*
2830 * We are going idle. next_balance may be set based on
2831 * a busy processor. So reset next_balance.
2832 */
2833 this_rq->next_balance = next_balance;
2777} 2834}
2778 2835
2779/* 2836/*
@@ -2826,26 +2883,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
2826 spin_unlock(&target_rq->lock); 2883 spin_unlock(&target_rq->lock);
2827} 2884}
2828 2885
2829/* 2886static void update_load(struct rq *this_rq)
2830 * rebalance_tick will get called every timer tick, on every CPU.
2831 *
2832 * It checks each scheduling domain to see if it is due to be balanced,
2833 * and initiates a balancing operation if so.
2834 *
2835 * Balancing parameters are set up in arch_init_sched_domains.
2836 */
2837
2838/* Don't have all balancing operations going off at once: */
2839static inline unsigned long cpu_offset(int cpu)
2840{ 2887{
2841 return jiffies + cpu * HZ / NR_CPUS; 2888 unsigned long this_load;
2842}
2843
2844static void
2845rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2846{
2847 unsigned long this_load, interval, j = cpu_offset(this_cpu);
2848 struct sched_domain *sd;
2849 int i, scale; 2889 int i, scale;
2850 2890
2851 this_load = this_rq->raw_weighted_load; 2891 this_load = this_rq->raw_weighted_load;
@@ -2865,6 +2905,32 @@ rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2865 new_load += scale-1; 2905 new_load += scale-1;
2866 this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) / scale; 2906 this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) / scale;
2867 } 2907 }
2908}
2909
2910/*
2911 * run_rebalance_domains is triggered when needed from the scheduler tick.
2912 *
2913 * It checks each scheduling domain to see if it is due to be balanced,
2914 * and initiates a balancing operation if so.
2915 *
2916 * Balancing parameters are set up in arch_init_sched_domains.
2917 */
2918static DEFINE_SPINLOCK(balancing);
2919
2920static void run_rebalance_domains(struct softirq_action *h)
2921{
2922 int this_cpu = smp_processor_id(), balance = 1;
2923 struct rq *this_rq = cpu_rq(this_cpu);
2924 unsigned long interval;
2925 struct sched_domain *sd;
2926 /*
2927 * We are idle if there are no processes running. This
2928 * is valid even if we are the idle process (SMT).
2929 */
2930 enum idle_type idle = !this_rq->nr_running ?
2931 SCHED_IDLE : NOT_IDLE;
2932 /* Earliest time when we have to call run_rebalance_domains again */
2933 unsigned long next_balance = jiffies + 60*HZ;
2868 2934
2869 for_each_domain(this_cpu, sd) { 2935 for_each_domain(this_cpu, sd) {
2870 if (!(sd->flags & SD_LOAD_BALANCE)) 2936 if (!(sd->flags & SD_LOAD_BALANCE))
@@ -2879,8 +2945,13 @@ rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2879 if (unlikely(!interval)) 2945 if (unlikely(!interval))
2880 interval = 1; 2946 interval = 1;
2881 2947
2882 if (j - sd->last_balance >= interval) { 2948 if (sd->flags & SD_SERIALIZE) {
2883 if (load_balance(this_cpu, this_rq, sd, idle)) { 2949 if (!spin_trylock(&balancing))
2950 goto out;
2951 }
2952
2953 if (time_after_eq(jiffies, sd->last_balance + interval)) {
2954 if (load_balance(this_cpu, this_rq, sd, idle, &balance)) {
2884 /* 2955 /*
2885 * We've pulled tasks over so either we're no 2956 * We've pulled tasks over so either we're no
2886 * longer idle, or one of our SMT siblings is 2957 * longer idle, or one of our SMT siblings is
@@ -2888,39 +2959,48 @@ rebalance_tick(int this_cpu, struct rq *this_rq, enum idle_type idle)
2888 */ 2959 */
2889 idle = NOT_IDLE; 2960 idle = NOT_IDLE;
2890 } 2961 }
2891 sd->last_balance += interval; 2962 sd->last_balance = jiffies;
2892 } 2963 }
2964 if (sd->flags & SD_SERIALIZE)
2965 spin_unlock(&balancing);
2966out:
2967 if (time_after(next_balance, sd->last_balance + interval))
2968 next_balance = sd->last_balance + interval;
2969
2970 /*
2971 * Stop the load balance at this level. There is another
2972 * CPU in our sched group which is doing load balancing more
2973 * actively.
2974 */
2975 if (!balance)
2976 break;
2893 } 2977 }
2978 this_rq->next_balance = next_balance;
2894} 2979}
2895#else 2980#else
2896/* 2981/*
2897 * on UP we do not need to balance between CPUs: 2982 * on UP we do not need to balance between CPUs:
2898 */ 2983 */
2899static inline void rebalance_tick(int cpu, struct rq *rq, enum idle_type idle)
2900{
2901}
2902static inline void idle_balance(int cpu, struct rq *rq) 2984static inline void idle_balance(int cpu, struct rq *rq)
2903{ 2985{
2904} 2986}
2905#endif 2987#endif
2906 2988
2907static inline int wake_priority_sleeper(struct rq *rq) 2989static inline void wake_priority_sleeper(struct rq *rq)
2908{ 2990{
2909 int ret = 0;
2910
2911#ifdef CONFIG_SCHED_SMT 2991#ifdef CONFIG_SCHED_SMT
2992 if (!rq->nr_running)
2993 return;
2994
2912 spin_lock(&rq->lock); 2995 spin_lock(&rq->lock);
2913 /* 2996 /*
2914 * If an SMT sibling task has been put to sleep for priority 2997 * If an SMT sibling task has been put to sleep for priority
2915 * reasons reschedule the idle task to see if it can now run. 2998 * reasons reschedule the idle task to see if it can now run.
2916 */ 2999 */
2917 if (rq->nr_running) { 3000 if (rq->nr_running)
2918 resched_task(rq->idle); 3001 resched_task(rq->idle);
2919 ret = 1;
2920 }
2921 spin_unlock(&rq->lock); 3002 spin_unlock(&rq->lock);
2922#endif 3003#endif
2923 return ret;
2924} 3004}
2925 3005
2926DEFINE_PER_CPU(struct kernel_stat, kstat); 3006DEFINE_PER_CPU(struct kernel_stat, kstat);
@@ -2934,7 +3014,8 @@ EXPORT_PER_CPU_SYMBOL(kstat);
2934static inline void 3014static inline void
2935update_cpu_clock(struct task_struct *p, struct rq *rq, unsigned long long now) 3015update_cpu_clock(struct task_struct *p, struct rq *rq, unsigned long long now)
2936{ 3016{
2937 p->sched_time += now - max(p->timestamp, rq->timestamp_last_tick); 3017 p->sched_time += now - p->last_ran;
3018 p->last_ran = rq->most_recent_timestamp = now;
2938} 3019}
2939 3020
2940/* 3021/*
@@ -2947,8 +3028,7 @@ unsigned long long current_sched_time(const struct task_struct *p)
2947 unsigned long flags; 3028 unsigned long flags;
2948 3029
2949 local_irq_save(flags); 3030 local_irq_save(flags);
2950 ns = max(p->timestamp, task_rq(p)->timestamp_last_tick); 3031 ns = p->sched_time + sched_clock() - p->last_ran;
2951 ns = p->sched_time + sched_clock() - ns;
2952 local_irq_restore(flags); 3032 local_irq_restore(flags);
2953 3033
2954 return ns; 3034 return ns;
@@ -3048,35 +3128,12 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
3048 cpustat->steal = cputime64_add(cpustat->steal, tmp); 3128 cpustat->steal = cputime64_add(cpustat->steal, tmp);
3049} 3129}
3050 3130
3051/* 3131static void task_running_tick(struct rq *rq, struct task_struct *p)
3052 * This function gets called by the timer code, with HZ frequency.
3053 * We call it with interrupts disabled.
3054 *
3055 * It also gets called by the fork code, when changing the parent's
3056 * timeslices.
3057 */
3058void scheduler_tick(void)
3059{ 3132{
3060 unsigned long long now = sched_clock();
3061 struct task_struct *p = current;
3062 int cpu = smp_processor_id();
3063 struct rq *rq = cpu_rq(cpu);
3064
3065 update_cpu_clock(p, rq, now);
3066
3067 rq->timestamp_last_tick = now;
3068
3069 if (p == rq->idle) {
3070 if (wake_priority_sleeper(rq))
3071 goto out;
3072 rebalance_tick(cpu, rq, SCHED_IDLE);
3073 return;
3074 }
3075
3076 /* Task might have expired already, but not scheduled off yet */
3077 if (p->array != rq->active) { 3133 if (p->array != rq->active) {
3134 /* Task has expired but was not scheduled yet */
3078 set_tsk_need_resched(p); 3135 set_tsk_need_resched(p);
3079 goto out; 3136 return;
3080 } 3137 }
3081 spin_lock(&rq->lock); 3138 spin_lock(&rq->lock);
3082 /* 3139 /*
@@ -3144,8 +3201,34 @@ void scheduler_tick(void)
3144 } 3201 }
3145out_unlock: 3202out_unlock:
3146 spin_unlock(&rq->lock); 3203 spin_unlock(&rq->lock);
3147out: 3204}
3148 rebalance_tick(cpu, rq, NOT_IDLE); 3205
3206/*
3207 * This function gets called by the timer code, with HZ frequency.
3208 * We call it with interrupts disabled.
3209 *
3210 * It also gets called by the fork code, when changing the parent's
3211 * timeslices.
3212 */
3213void scheduler_tick(void)
3214{
3215 unsigned long long now = sched_clock();
3216 struct task_struct *p = current;
3217 int cpu = smp_processor_id();
3218 struct rq *rq = cpu_rq(cpu);
3219
3220 update_cpu_clock(p, rq, now);
3221
3222 if (p == rq->idle)
3223 /* Task on the idle queue */
3224 wake_priority_sleeper(rq);
3225 else
3226 task_running_tick(rq, p);
3227#ifdef CONFIG_SMP
3228 update_load(rq);
3229 if (time_after_eq(jiffies, rq->next_balance))
3230 raise_softirq(SCHED_SOFTIRQ);
3231#endif
3149} 3232}
3150 3233
3151#ifdef CONFIG_SCHED_SMT 3234#ifdef CONFIG_SCHED_SMT
@@ -3291,7 +3374,8 @@ void fastcall add_preempt_count(int val)
3291 /* 3374 /*
3292 * Spinlock count overflowing soon? 3375 * Spinlock count overflowing soon?
3293 */ 3376 */
3294 DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >= PREEMPT_MASK-10); 3377 DEBUG_LOCKS_WARN_ON((preempt_count() & PREEMPT_MASK) >=
3378 PREEMPT_MASK - 10);
3295} 3379}
3296EXPORT_SYMBOL(add_preempt_count); 3380EXPORT_SYMBOL(add_preempt_count);
3297 3381
@@ -4990,8 +5074,8 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu)
4990 * afterwards, and pretending it was a local activate. 5074 * afterwards, and pretending it was a local activate.
4991 * This way is cleaner and logically correct. 5075 * This way is cleaner and logically correct.
4992 */ 5076 */
4993 p->timestamp = p->timestamp - rq_src->timestamp_last_tick 5077 p->timestamp = p->timestamp - rq_src->most_recent_timestamp
4994 + rq_dest->timestamp_last_tick; 5078 + rq_dest->most_recent_timestamp;
4995 deactivate_task(p, rq_src); 5079 deactivate_task(p, rq_src);
4996 __activate_task(p, rq_dest); 5080 __activate_task(p, rq_dest);
4997 if (TASK_PREEMPTS_CURR(p, rq_dest)) 5081 if (TASK_PREEMPTS_CURR(p, rq_dest))
@@ -5067,7 +5151,10 @@ wait_to_die:
5067} 5151}
5068 5152
5069#ifdef CONFIG_HOTPLUG_CPU 5153#ifdef CONFIG_HOTPLUG_CPU
5070/* Figure out where task on dead CPU should go, use force if neccessary. */ 5154/*
5155 * Figure out where task on dead CPU should go, use force if neccessary.
5156 * NOTE: interrupts should be disabled by the caller
5157 */
5071static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) 5158static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
5072{ 5159{
5073 unsigned long flags; 5160 unsigned long flags;
@@ -5187,6 +5274,7 @@ void idle_task_exit(void)
5187 mmdrop(mm); 5274 mmdrop(mm);
5188} 5275}
5189 5276
5277/* called under rq->lock with disabled interrupts */
5190static void migrate_dead(unsigned int dead_cpu, struct task_struct *p) 5278static void migrate_dead(unsigned int dead_cpu, struct task_struct *p)
5191{ 5279{
5192 struct rq *rq = cpu_rq(dead_cpu); 5280 struct rq *rq = cpu_rq(dead_cpu);
@@ -5203,10 +5291,11 @@ static void migrate_dead(unsigned int dead_cpu, struct task_struct *p)
5203 * Drop lock around migration; if someone else moves it, 5291 * Drop lock around migration; if someone else moves it,
5204 * that's OK. No task can be added to this CPU, so iteration is 5292 * that's OK. No task can be added to this CPU, so iteration is
5205 * fine. 5293 * fine.
5294 * NOTE: interrupts should be left disabled --dev@
5206 */ 5295 */
5207 spin_unlock_irq(&rq->lock); 5296 spin_unlock(&rq->lock);
5208 move_task_off_dead_cpu(dead_cpu, p); 5297 move_task_off_dead_cpu(dead_cpu, p);
5209 spin_lock_irq(&rq->lock); 5298 spin_lock(&rq->lock);
5210 5299
5211 put_task_struct(p); 5300 put_task_struct(p);
5212} 5301}
@@ -5359,16 +5448,19 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
5359 if (!(sd->flags & SD_LOAD_BALANCE)) { 5448 if (!(sd->flags & SD_LOAD_BALANCE)) {
5360 printk("does not load-balance\n"); 5449 printk("does not load-balance\n");
5361 if (sd->parent) 5450 if (sd->parent)
5362 printk(KERN_ERR "ERROR: !SD_LOAD_BALANCE domain has parent"); 5451 printk(KERN_ERR "ERROR: !SD_LOAD_BALANCE domain"
5452 " has parent");
5363 break; 5453 break;
5364 } 5454 }
5365 5455
5366 printk("span %s\n", str); 5456 printk("span %s\n", str);
5367 5457
5368 if (!cpu_isset(cpu, sd->span)) 5458 if (!cpu_isset(cpu, sd->span))
5369 printk(KERN_ERR "ERROR: domain->span does not contain CPU%d\n", cpu); 5459 printk(KERN_ERR "ERROR: domain->span does not contain "
5460 "CPU%d\n", cpu);
5370 if (!cpu_isset(cpu, group->cpumask)) 5461 if (!cpu_isset(cpu, group->cpumask))
5371 printk(KERN_ERR "ERROR: domain->groups does not contain CPU%d\n", cpu); 5462 printk(KERN_ERR "ERROR: domain->groups does not contain"
5463 " CPU%d\n", cpu);
5372 5464
5373 printk(KERN_DEBUG); 5465 printk(KERN_DEBUG);
5374 for (i = 0; i < level + 2; i++) 5466 for (i = 0; i < level + 2; i++)
@@ -5383,7 +5475,8 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
5383 5475
5384 if (!group->cpu_power) { 5476 if (!group->cpu_power) {
5385 printk("\n"); 5477 printk("\n");
5386 printk(KERN_ERR "ERROR: domain->cpu_power not set\n"); 5478 printk(KERN_ERR "ERROR: domain->cpu_power not "
5479 "set\n");
5387 } 5480 }
5388 5481
5389 if (!cpus_weight(group->cpumask)) { 5482 if (!cpus_weight(group->cpumask)) {
@@ -5406,15 +5499,17 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
5406 printk("\n"); 5499 printk("\n");
5407 5500
5408 if (!cpus_equal(sd->span, groupmask)) 5501 if (!cpus_equal(sd->span, groupmask))
5409 printk(KERN_ERR "ERROR: groups don't span domain->span\n"); 5502 printk(KERN_ERR "ERROR: groups don't span "
5503 "domain->span\n");
5410 5504
5411 level++; 5505 level++;
5412 sd = sd->parent; 5506 sd = sd->parent;
5507 if (!sd)
5508 continue;
5413 5509
5414 if (sd) { 5510 if (!cpus_subset(groupmask, sd->span))
5415 if (!cpus_subset(groupmask, sd->span)) 5511 printk(KERN_ERR "ERROR: parent span is not a superset "
5416 printk(KERN_ERR "ERROR: parent span is not a superset of domain->span\n"); 5512 "of domain->span\n");
5417 }
5418 5513
5419 } while (sd); 5514 } while (sd);
5420} 5515}
@@ -5528,28 +5623,27 @@ static int __init isolated_cpu_setup(char *str)
5528__setup ("isolcpus=", isolated_cpu_setup); 5623__setup ("isolcpus=", isolated_cpu_setup);
5529 5624
5530/* 5625/*
5531 * init_sched_build_groups takes an array of groups, the cpumask we wish 5626 * init_sched_build_groups takes the cpumask we wish to span, and a pointer
5532 * to span, and a pointer to a function which identifies what group a CPU 5627 * to a function which identifies what group(along with sched group) a CPU
5533 * belongs to. The return value of group_fn must be a valid index into the 5628 * belongs to. The return value of group_fn must be a >= 0 and < NR_CPUS
5534 * groups[] array, and must be >= 0 and < NR_CPUS (due to the fact that we 5629 * (due to the fact that we keep track of groups covered with a cpumask_t).
5535 * keep track of groups covered with a cpumask_t).
5536 * 5630 *
5537 * init_sched_build_groups will build a circular linked list of the groups 5631 * init_sched_build_groups will build a circular linked list of the groups
5538 * covered by the given span, and will set each group's ->cpumask correctly, 5632 * covered by the given span, and will set each group's ->cpumask correctly,
5539 * and ->cpu_power to 0. 5633 * and ->cpu_power to 0.
5540 */ 5634 */
5541static void 5635static void
5542init_sched_build_groups(struct sched_group groups[], cpumask_t span, 5636init_sched_build_groups(cpumask_t span, const cpumask_t *cpu_map,
5543 const cpumask_t *cpu_map, 5637 int (*group_fn)(int cpu, const cpumask_t *cpu_map,
5544 int (*group_fn)(int cpu, const cpumask_t *cpu_map)) 5638 struct sched_group **sg))
5545{ 5639{
5546 struct sched_group *first = NULL, *last = NULL; 5640 struct sched_group *first = NULL, *last = NULL;
5547 cpumask_t covered = CPU_MASK_NONE; 5641 cpumask_t covered = CPU_MASK_NONE;
5548 int i; 5642 int i;
5549 5643
5550 for_each_cpu_mask(i, span) { 5644 for_each_cpu_mask(i, span) {
5551 int group = group_fn(i, cpu_map); 5645 struct sched_group *sg;
5552 struct sched_group *sg = &groups[group]; 5646 int group = group_fn(i, cpu_map, &sg);
5553 int j; 5647 int j;
5554 5648
5555 if (cpu_isset(i, covered)) 5649 if (cpu_isset(i, covered))
@@ -5559,7 +5653,7 @@ init_sched_build_groups(struct sched_group groups[], cpumask_t span,
5559 sg->cpu_power = 0; 5653 sg->cpu_power = 0;
5560 5654
5561 for_each_cpu_mask(j, span) { 5655 for_each_cpu_mask(j, span) {
5562 if (group_fn(j, cpu_map) != group) 5656 if (group_fn(j, cpu_map, NULL) != group)
5563 continue; 5657 continue;
5564 5658
5565 cpu_set(j, covered); 5659 cpu_set(j, covered);
@@ -5733,8 +5827,9 @@ __setup("max_cache_size=", setup_max_cache_size);
5733 */ 5827 */
5734static void touch_cache(void *__cache, unsigned long __size) 5828static void touch_cache(void *__cache, unsigned long __size)
5735{ 5829{
5736 unsigned long size = __size/sizeof(long), chunk1 = size/3, 5830 unsigned long size = __size / sizeof(long);
5737 chunk2 = 2*size/3; 5831 unsigned long chunk1 = size / 3;
5832 unsigned long chunk2 = 2 * size / 3;
5738 unsigned long *cache = __cache; 5833 unsigned long *cache = __cache;
5739 int i; 5834 int i;
5740 5835
@@ -5843,11 +5938,11 @@ measure_cost(int cpu1, int cpu2, void *cache, unsigned int size)
5843 */ 5938 */
5844 measure_one(cache, size, cpu1, cpu2); 5939 measure_one(cache, size, cpu1, cpu2);
5845 for (i = 0; i < ITERATIONS; i++) 5940 for (i = 0; i < ITERATIONS; i++)
5846 cost1 += measure_one(cache, size - i*1024, cpu1, cpu2); 5941 cost1 += measure_one(cache, size - i * 1024, cpu1, cpu2);
5847 5942
5848 measure_one(cache, size, cpu2, cpu1); 5943 measure_one(cache, size, cpu2, cpu1);
5849 for (i = 0; i < ITERATIONS; i++) 5944 for (i = 0; i < ITERATIONS; i++)
5850 cost1 += measure_one(cache, size - i*1024, cpu2, cpu1); 5945 cost1 += measure_one(cache, size - i * 1024, cpu2, cpu1);
5851 5946
5852 /* 5947 /*
5853 * (We measure the non-migrating [cached] cost on both 5948 * (We measure the non-migrating [cached] cost on both
@@ -5857,17 +5952,17 @@ measure_cost(int cpu1, int cpu2, void *cache, unsigned int size)
5857 5952
5858 measure_one(cache, size, cpu1, cpu1); 5953 measure_one(cache, size, cpu1, cpu1);
5859 for (i = 0; i < ITERATIONS; i++) 5954 for (i = 0; i < ITERATIONS; i++)
5860 cost2 += measure_one(cache, size - i*1024, cpu1, cpu1); 5955 cost2 += measure_one(cache, size - i * 1024, cpu1, cpu1);
5861 5956
5862 measure_one(cache, size, cpu2, cpu2); 5957 measure_one(cache, size, cpu2, cpu2);
5863 for (i = 0; i < ITERATIONS; i++) 5958 for (i = 0; i < ITERATIONS; i++)
5864 cost2 += measure_one(cache, size - i*1024, cpu2, cpu2); 5959 cost2 += measure_one(cache, size - i * 1024, cpu2, cpu2);
5865 5960
5866 /* 5961 /*
5867 * Get the per-iteration migration cost: 5962 * Get the per-iteration migration cost:
5868 */ 5963 */
5869 do_div(cost1, 2*ITERATIONS); 5964 do_div(cost1, 2 * ITERATIONS);
5870 do_div(cost2, 2*ITERATIONS); 5965 do_div(cost2, 2 * ITERATIONS);
5871 5966
5872 return cost1 - cost2; 5967 return cost1 - cost2;
5873} 5968}
@@ -5905,7 +6000,7 @@ static unsigned long long measure_migration_cost(int cpu1, int cpu2)
5905 */ 6000 */
5906 cache = vmalloc(max_size); 6001 cache = vmalloc(max_size);
5907 if (!cache) { 6002 if (!cache) {
5908 printk("could not vmalloc %d bytes for cache!\n", 2*max_size); 6003 printk("could not vmalloc %d bytes for cache!\n", 2 * max_size);
5909 return 1000000; /* return 1 msec on very small boxen */ 6004 return 1000000; /* return 1 msec on very small boxen */
5910 } 6005 }
5911 6006
@@ -5930,7 +6025,8 @@ static unsigned long long measure_migration_cost(int cpu1, int cpu2)
5930 avg_fluct = (avg_fluct + fluct)/2; 6025 avg_fluct = (avg_fluct + fluct)/2;
5931 6026
5932 if (migration_debug) 6027 if (migration_debug)
5933 printk("-> [%d][%d][%7d] %3ld.%ld [%3ld.%ld] (%ld): (%8Ld %8Ld)\n", 6028 printk("-> [%d][%d][%7d] %3ld.%ld [%3ld.%ld] (%ld): "
6029 "(%8Ld %8Ld)\n",
5934 cpu1, cpu2, size, 6030 cpu1, cpu2, size,
5935 (long)cost / 1000000, 6031 (long)cost / 1000000,
5936 ((long)cost / 100000) % 10, 6032 ((long)cost / 100000) % 10,
@@ -6025,20 +6121,18 @@ static void calibrate_migration_costs(const cpumask_t *cpu_map)
6025 -1 6121 -1
6026#endif 6122#endif
6027 ); 6123 );
6028 if (system_state == SYSTEM_BOOTING) { 6124 if (system_state == SYSTEM_BOOTING && num_online_cpus() > 1) {
6029 if (num_online_cpus() > 1) { 6125 printk("migration_cost=");
6030 printk("migration_cost="); 6126 for (distance = 0; distance <= max_distance; distance++) {
6031 for (distance = 0; distance <= max_distance; distance++) { 6127 if (distance)
6032 if (distance) 6128 printk(",");
6033 printk(","); 6129 printk("%ld", (long)migration_cost[distance] / 1000);
6034 printk("%ld", (long)migration_cost[distance] / 1000);
6035 }
6036 printk("\n");
6037 } 6130 }
6131 printk("\n");
6038 } 6132 }
6039 j1 = jiffies; 6133 j1 = jiffies;
6040 if (migration_debug) 6134 if (migration_debug)
6041 printk("migration: %ld seconds\n", (j1-j0)/HZ); 6135 printk("migration: %ld seconds\n", (j1-j0) / HZ);
6042 6136
6043 /* 6137 /*
6044 * Move back to the original CPU. NUMA-Q gets confused 6138 * Move back to the original CPU. NUMA-Q gets confused
@@ -6135,10 +6229,13 @@ int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
6135 */ 6229 */
6136#ifdef CONFIG_SCHED_SMT 6230#ifdef CONFIG_SCHED_SMT
6137static DEFINE_PER_CPU(struct sched_domain, cpu_domains); 6231static DEFINE_PER_CPU(struct sched_domain, cpu_domains);
6138static struct sched_group sched_group_cpus[NR_CPUS]; 6232static DEFINE_PER_CPU(struct sched_group, sched_group_cpus);
6139 6233
6140static int cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map) 6234static int cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map,
6235 struct sched_group **sg)
6141{ 6236{
6237 if (sg)
6238 *sg = &per_cpu(sched_group_cpus, cpu);
6142 return cpu; 6239 return cpu;
6143} 6240}
6144#endif 6241#endif
@@ -6148,39 +6245,52 @@ static int cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map)
6148 */ 6245 */
6149#ifdef CONFIG_SCHED_MC 6246#ifdef CONFIG_SCHED_MC
6150static DEFINE_PER_CPU(struct sched_domain, core_domains); 6247static DEFINE_PER_CPU(struct sched_domain, core_domains);
6151static struct sched_group sched_group_core[NR_CPUS]; 6248static DEFINE_PER_CPU(struct sched_group, sched_group_core);
6152#endif 6249#endif
6153 6250
6154#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) 6251#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT)
6155static int cpu_to_core_group(int cpu, const cpumask_t *cpu_map) 6252static int cpu_to_core_group(int cpu, const cpumask_t *cpu_map,
6253 struct sched_group **sg)
6156{ 6254{
6255 int group;
6157 cpumask_t mask = cpu_sibling_map[cpu]; 6256 cpumask_t mask = cpu_sibling_map[cpu];
6158 cpus_and(mask, mask, *cpu_map); 6257 cpus_and(mask, mask, *cpu_map);
6159 return first_cpu(mask); 6258 group = first_cpu(mask);
6259 if (sg)
6260 *sg = &per_cpu(sched_group_core, group);
6261 return group;
6160} 6262}
6161#elif defined(CONFIG_SCHED_MC) 6263#elif defined(CONFIG_SCHED_MC)
6162static int cpu_to_core_group(int cpu, const cpumask_t *cpu_map) 6264static int cpu_to_core_group(int cpu, const cpumask_t *cpu_map,
6265 struct sched_group **sg)
6163{ 6266{
6267 if (sg)
6268 *sg = &per_cpu(sched_group_core, cpu);
6164 return cpu; 6269 return cpu;
6165} 6270}
6166#endif 6271#endif
6167 6272
6168static DEFINE_PER_CPU(struct sched_domain, phys_domains); 6273static DEFINE_PER_CPU(struct sched_domain, phys_domains);
6169static struct sched_group sched_group_phys[NR_CPUS]; 6274static DEFINE_PER_CPU(struct sched_group, sched_group_phys);
6170 6275
6171static int cpu_to_phys_group(int cpu, const cpumask_t *cpu_map) 6276static int cpu_to_phys_group(int cpu, const cpumask_t *cpu_map,
6277 struct sched_group **sg)
6172{ 6278{
6279 int group;
6173#ifdef CONFIG_SCHED_MC 6280#ifdef CONFIG_SCHED_MC
6174 cpumask_t mask = cpu_coregroup_map(cpu); 6281 cpumask_t mask = cpu_coregroup_map(cpu);
6175 cpus_and(mask, mask, *cpu_map); 6282 cpus_and(mask, mask, *cpu_map);
6176 return first_cpu(mask); 6283 group = first_cpu(mask);
6177#elif defined(CONFIG_SCHED_SMT) 6284#elif defined(CONFIG_SCHED_SMT)
6178 cpumask_t mask = cpu_sibling_map[cpu]; 6285 cpumask_t mask = cpu_sibling_map[cpu];
6179 cpus_and(mask, mask, *cpu_map); 6286 cpus_and(mask, mask, *cpu_map);
6180 return first_cpu(mask); 6287 group = first_cpu(mask);
6181#else 6288#else
6182 return cpu; 6289 group = cpu;
6183#endif 6290#endif
6291 if (sg)
6292 *sg = &per_cpu(sched_group_phys, group);
6293 return group;
6184} 6294}
6185 6295
6186#ifdef CONFIG_NUMA 6296#ifdef CONFIG_NUMA
@@ -6193,12 +6303,22 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains);
6193static struct sched_group **sched_group_nodes_bycpu[NR_CPUS]; 6303static struct sched_group **sched_group_nodes_bycpu[NR_CPUS];
6194 6304
6195static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); 6305static DEFINE_PER_CPU(struct sched_domain, allnodes_domains);
6196static struct sched_group *sched_group_allnodes_bycpu[NR_CPUS]; 6306static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes);
6197 6307
6198static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map) 6308static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map,
6309 struct sched_group **sg)
6199{ 6310{
6200 return cpu_to_node(cpu); 6311 cpumask_t nodemask = node_to_cpumask(cpu_to_node(cpu));
6312 int group;
6313
6314 cpus_and(nodemask, nodemask, *cpu_map);
6315 group = first_cpu(nodemask);
6316
6317 if (sg)
6318 *sg = &per_cpu(sched_group_allnodes, group);
6319 return group;
6201} 6320}
6321
6202static void init_numa_sched_groups_power(struct sched_group *group_head) 6322static void init_numa_sched_groups_power(struct sched_group *group_head)
6203{ 6323{
6204 struct sched_group *sg = group_head; 6324 struct sched_group *sg = group_head;
@@ -6234,16 +6354,9 @@ static void free_sched_groups(const cpumask_t *cpu_map)
6234 int cpu, i; 6354 int cpu, i;
6235 6355
6236 for_each_cpu_mask(cpu, *cpu_map) { 6356 for_each_cpu_mask(cpu, *cpu_map) {
6237 struct sched_group *sched_group_allnodes
6238 = sched_group_allnodes_bycpu[cpu];
6239 struct sched_group **sched_group_nodes 6357 struct sched_group **sched_group_nodes
6240 = sched_group_nodes_bycpu[cpu]; 6358 = sched_group_nodes_bycpu[cpu];
6241 6359
6242 if (sched_group_allnodes) {
6243 kfree(sched_group_allnodes);
6244 sched_group_allnodes_bycpu[cpu] = NULL;
6245 }
6246
6247 if (!sched_group_nodes) 6360 if (!sched_group_nodes)
6248 continue; 6361 continue;
6249 6362
@@ -6337,7 +6450,7 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6337 struct sched_domain *sd; 6450 struct sched_domain *sd;
6338#ifdef CONFIG_NUMA 6451#ifdef CONFIG_NUMA
6339 struct sched_group **sched_group_nodes = NULL; 6452 struct sched_group **sched_group_nodes = NULL;
6340 struct sched_group *sched_group_allnodes = NULL; 6453 int sd_allnodes = 0;
6341 6454
6342 /* 6455 /*
6343 * Allocate the per-node list of sched groups 6456 * Allocate the per-node list of sched groups
@@ -6355,7 +6468,6 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6355 * Set up domains for cpus specified by the cpu_map. 6468 * Set up domains for cpus specified by the cpu_map.
6356 */ 6469 */
6357 for_each_cpu_mask(i, *cpu_map) { 6470 for_each_cpu_mask(i, *cpu_map) {
6358 int group;
6359 struct sched_domain *sd = NULL, *p; 6471 struct sched_domain *sd = NULL, *p;
6360 cpumask_t nodemask = node_to_cpumask(cpu_to_node(i)); 6472 cpumask_t nodemask = node_to_cpumask(cpu_to_node(i));
6361 6473
@@ -6364,26 +6476,12 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6364#ifdef CONFIG_NUMA 6476#ifdef CONFIG_NUMA
6365 if (cpus_weight(*cpu_map) 6477 if (cpus_weight(*cpu_map)
6366 > SD_NODES_PER_DOMAIN*cpus_weight(nodemask)) { 6478 > SD_NODES_PER_DOMAIN*cpus_weight(nodemask)) {
6367 if (!sched_group_allnodes) {
6368 sched_group_allnodes
6369 = kmalloc_node(sizeof(struct sched_group)
6370 * MAX_NUMNODES,
6371 GFP_KERNEL,
6372 cpu_to_node(i));
6373 if (!sched_group_allnodes) {
6374 printk(KERN_WARNING
6375 "Can not alloc allnodes sched group\n");
6376 goto error;
6377 }
6378 sched_group_allnodes_bycpu[i]
6379 = sched_group_allnodes;
6380 }
6381 sd = &per_cpu(allnodes_domains, i); 6479 sd = &per_cpu(allnodes_domains, i);
6382 *sd = SD_ALLNODES_INIT; 6480 *sd = SD_ALLNODES_INIT;
6383 sd->span = *cpu_map; 6481 sd->span = *cpu_map;
6384 group = cpu_to_allnodes_group(i, cpu_map); 6482 cpu_to_allnodes_group(i, cpu_map, &sd->groups);
6385 sd->groups = &sched_group_allnodes[group];
6386 p = sd; 6483 p = sd;
6484 sd_allnodes = 1;
6387 } else 6485 } else
6388 p = NULL; 6486 p = NULL;
6389 6487
@@ -6398,36 +6496,33 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6398 6496
6399 p = sd; 6497 p = sd;
6400 sd = &per_cpu(phys_domains, i); 6498 sd = &per_cpu(phys_domains, i);
6401 group = cpu_to_phys_group(i, cpu_map);
6402 *sd = SD_CPU_INIT; 6499 *sd = SD_CPU_INIT;
6403 sd->span = nodemask; 6500 sd->span = nodemask;
6404 sd->parent = p; 6501 sd->parent = p;
6405 if (p) 6502 if (p)
6406 p->child = sd; 6503 p->child = sd;
6407 sd->groups = &sched_group_phys[group]; 6504 cpu_to_phys_group(i, cpu_map, &sd->groups);
6408 6505
6409#ifdef CONFIG_SCHED_MC 6506#ifdef CONFIG_SCHED_MC
6410 p = sd; 6507 p = sd;
6411 sd = &per_cpu(core_domains, i); 6508 sd = &per_cpu(core_domains, i);
6412 group = cpu_to_core_group(i, cpu_map);
6413 *sd = SD_MC_INIT; 6509 *sd = SD_MC_INIT;
6414 sd->span = cpu_coregroup_map(i); 6510 sd->span = cpu_coregroup_map(i);
6415 cpus_and(sd->span, sd->span, *cpu_map); 6511 cpus_and(sd->span, sd->span, *cpu_map);
6416 sd->parent = p; 6512 sd->parent = p;
6417 p->child = sd; 6513 p->child = sd;
6418 sd->groups = &sched_group_core[group]; 6514 cpu_to_core_group(i, cpu_map, &sd->groups);
6419#endif 6515#endif
6420 6516
6421#ifdef CONFIG_SCHED_SMT 6517#ifdef CONFIG_SCHED_SMT
6422 p = sd; 6518 p = sd;
6423 sd = &per_cpu(cpu_domains, i); 6519 sd = &per_cpu(cpu_domains, i);
6424 group = cpu_to_cpu_group(i, cpu_map);
6425 *sd = SD_SIBLING_INIT; 6520 *sd = SD_SIBLING_INIT;
6426 sd->span = cpu_sibling_map[i]; 6521 sd->span = cpu_sibling_map[i];
6427 cpus_and(sd->span, sd->span, *cpu_map); 6522 cpus_and(sd->span, sd->span, *cpu_map);
6428 sd->parent = p; 6523 sd->parent = p;
6429 p->child = sd; 6524 p->child = sd;
6430 sd->groups = &sched_group_cpus[group]; 6525 cpu_to_cpu_group(i, cpu_map, &sd->groups);
6431#endif 6526#endif
6432 } 6527 }
6433 6528
@@ -6439,8 +6534,7 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6439 if (i != first_cpu(this_sibling_map)) 6534 if (i != first_cpu(this_sibling_map))
6440 continue; 6535 continue;
6441 6536
6442 init_sched_build_groups(sched_group_cpus, this_sibling_map, 6537 init_sched_build_groups(this_sibling_map, cpu_map, &cpu_to_cpu_group);
6443 cpu_map, &cpu_to_cpu_group);
6444 } 6538 }
6445#endif 6539#endif
6446 6540
@@ -6451,8 +6545,7 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6451 cpus_and(this_core_map, this_core_map, *cpu_map); 6545 cpus_and(this_core_map, this_core_map, *cpu_map);
6452 if (i != first_cpu(this_core_map)) 6546 if (i != first_cpu(this_core_map))
6453 continue; 6547 continue;
6454 init_sched_build_groups(sched_group_core, this_core_map, 6548 init_sched_build_groups(this_core_map, cpu_map, &cpu_to_core_group);
6455 cpu_map, &cpu_to_core_group);
6456 } 6549 }
6457#endif 6550#endif
6458 6551
@@ -6465,15 +6558,13 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6465 if (cpus_empty(nodemask)) 6558 if (cpus_empty(nodemask))
6466 continue; 6559 continue;
6467 6560
6468 init_sched_build_groups(sched_group_phys, nodemask, 6561 init_sched_build_groups(nodemask, cpu_map, &cpu_to_phys_group);
6469 cpu_map, &cpu_to_phys_group);
6470 } 6562 }
6471 6563
6472#ifdef CONFIG_NUMA 6564#ifdef CONFIG_NUMA
6473 /* Set up node groups */ 6565 /* Set up node groups */
6474 if (sched_group_allnodes) 6566 if (sd_allnodes)
6475 init_sched_build_groups(sched_group_allnodes, *cpu_map, 6567 init_sched_build_groups(*cpu_map, cpu_map, &cpu_to_allnodes_group);
6476 cpu_map, &cpu_to_allnodes_group);
6477 6568
6478 for (i = 0; i < MAX_NUMNODES; i++) { 6569 for (i = 0; i < MAX_NUMNODES; i++) {
6479 /* Set up node groups */ 6570 /* Set up node groups */
@@ -6565,10 +6656,10 @@ static int build_sched_domains(const cpumask_t *cpu_map)
6565 for (i = 0; i < MAX_NUMNODES; i++) 6656 for (i = 0; i < MAX_NUMNODES; i++)
6566 init_numa_sched_groups_power(sched_group_nodes[i]); 6657 init_numa_sched_groups_power(sched_group_nodes[i]);
6567 6658
6568 if (sched_group_allnodes) { 6659 if (sd_allnodes) {
6569 int group = cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map); 6660 struct sched_group *sg;
6570 struct sched_group *sg = &sched_group_allnodes[group];
6571 6661
6662 cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg);
6572 init_numa_sched_groups_power(sg); 6663 init_numa_sched_groups_power(sg);
6573 } 6664 }
6574#endif 6665#endif
@@ -6847,6 +6938,10 @@ void __init sched_init(void)
6847 6938
6848 set_load_weight(&init_task); 6939 set_load_weight(&init_task);
6849 6940
6941#ifdef CONFIG_SMP
6942 open_softirq(SCHED_SOFTIRQ, run_rebalance_domains, NULL);
6943#endif
6944
6850#ifdef CONFIG_RT_MUTEXES 6945#ifdef CONFIG_RT_MUTEXES
6851 plist_head_init(&init_task.pi_waiters, &init_task.pi_lock); 6946 plist_head_init(&init_task.pi_waiters, &init_task.pi_lock);
6852#endif 6947#endif
diff --git a/kernel/signal.c b/kernel/signal.c
index ec81defde339..1921ffdc5e77 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -24,6 +24,9 @@
24#include <linux/signal.h> 24#include <linux/signal.h>
25#include <linux/capability.h> 25#include <linux/capability.h>
26#include <linux/freezer.h> 26#include <linux/freezer.h>
27#include <linux/pid_namespace.h>
28#include <linux/nsproxy.h>
29
27#include <asm/param.h> 30#include <asm/param.h>
28#include <asm/uaccess.h> 31#include <asm/uaccess.h>
29#include <asm/unistd.h> 32#include <asm/unistd.h>
@@ -583,7 +586,7 @@ static int check_kill_permission(int sig, struct siginfo *info,
583 error = -EPERM; 586 error = -EPERM;
584 if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) 587 if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
585 && ((sig != SIGCONT) || 588 && ((sig != SIGCONT) ||
586 (current->signal->session != t->signal->session)) 589 (process_session(current) != process_session(t)))
587 && (current->euid ^ t->suid) && (current->euid ^ t->uid) 590 && (current->euid ^ t->suid) && (current->euid ^ t->uid)
588 && (current->uid ^ t->suid) && (current->uid ^ t->uid) 591 && (current->uid ^ t->suid) && (current->uid ^ t->uid)
589 && !capable(CAP_KILL)) 592 && !capable(CAP_KILL))
@@ -1877,8 +1880,12 @@ relock:
1877 if (sig_kernel_ignore(signr)) /* Default is nothing. */ 1880 if (sig_kernel_ignore(signr)) /* Default is nothing. */
1878 continue; 1881 continue;
1879 1882
1880 /* Init gets no signals it doesn't want. */ 1883 /*
1881 if (current == child_reaper) 1884 * Init of a pid space gets no signals it doesn't want from
1885 * within that pid space. It can of course get signals from
1886 * its parent pid space.
1887 */
1888 if (current == child_reaper(current))
1882 continue; 1889 continue;
1883 1890
1884 if (sig_kernel_stop(signr)) { 1891 if (sig_kernel_stop(signr)) {
diff --git a/kernel/sys.c b/kernel/sys.c
index a0c1a29a507f..c7675c1bfdf2 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1381,7 +1381,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1381 1381
1382 if (p->real_parent == group_leader) { 1382 if (p->real_parent == group_leader) {
1383 err = -EPERM; 1383 err = -EPERM;
1384 if (p->signal->session != group_leader->signal->session) 1384 if (process_session(p) != process_session(group_leader))
1385 goto out; 1385 goto out;
1386 err = -EACCES; 1386 err = -EACCES;
1387 if (p->did_exec) 1387 if (p->did_exec)
@@ -1397,16 +1397,13 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
1397 goto out; 1397 goto out;
1398 1398
1399 if (pgid != pid) { 1399 if (pgid != pid) {
1400 struct task_struct *p; 1400 struct task_struct *g =
1401 find_task_by_pid_type(PIDTYPE_PGID, pgid);
1401 1402
1402 do_each_task_pid(pgid, PIDTYPE_PGID, p) { 1403 if (!g || process_session(g) != process_session(group_leader))
1403 if (p->signal->session == group_leader->signal->session) 1404 goto out;
1404 goto ok_pgid;
1405 } while_each_task_pid(pgid, PIDTYPE_PGID, p);
1406 goto out;
1407 } 1405 }
1408 1406
1409ok_pgid:
1410 err = security_task_setpgid(p, pgid); 1407 err = security_task_setpgid(p, pgid);
1411 if (err) 1408 if (err)
1412 goto out; 1409 goto out;
@@ -1459,7 +1456,7 @@ asmlinkage long sys_getpgrp(void)
1459asmlinkage long sys_getsid(pid_t pid) 1456asmlinkage long sys_getsid(pid_t pid)
1460{ 1457{
1461 if (!pid) 1458 if (!pid)
1462 return current->signal->session; 1459 return process_session(current);
1463 else { 1460 else {
1464 int retval; 1461 int retval;
1465 struct task_struct *p; 1462 struct task_struct *p;
@@ -1471,7 +1468,7 @@ asmlinkage long sys_getsid(pid_t pid)
1471 if (p) { 1468 if (p) {
1472 retval = security_task_getsid(p); 1469 retval = security_task_getsid(p);
1473 if (!retval) 1470 if (!retval)
1474 retval = p->signal->session; 1471 retval = process_session(p);
1475 } 1472 }
1476 read_unlock(&tasklist_lock); 1473 read_unlock(&tasklist_lock);
1477 return retval; 1474 return retval;
@@ -1484,7 +1481,6 @@ asmlinkage long sys_setsid(void)
1484 pid_t session; 1481 pid_t session;
1485 int err = -EPERM; 1482 int err = -EPERM;
1486 1483
1487 mutex_lock(&tty_mutex);
1488 write_lock_irq(&tasklist_lock); 1484 write_lock_irq(&tasklist_lock);
1489 1485
1490 /* Fail if I am already a session leader */ 1486 /* Fail if I am already a session leader */
@@ -1504,12 +1500,15 @@ asmlinkage long sys_setsid(void)
1504 1500
1505 group_leader->signal->leader = 1; 1501 group_leader->signal->leader = 1;
1506 __set_special_pids(session, session); 1502 __set_special_pids(session, session);
1503
1504 spin_lock(&group_leader->sighand->siglock);
1507 group_leader->signal->tty = NULL; 1505 group_leader->signal->tty = NULL;
1508 group_leader->signal->tty_old_pgrp = 0; 1506 group_leader->signal->tty_old_pgrp = 0;
1507 spin_unlock(&group_leader->sighand->siglock);
1508
1509 err = process_group(group_leader); 1509 err = process_group(group_leader);
1510out: 1510out:
1511 write_unlock_irq(&tasklist_lock); 1511 write_unlock_irq(&tasklist_lock);
1512 mutex_unlock(&tty_mutex);
1513 return err; 1512 return err;
1514} 1513}
1515 1514
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8e9f00fd6d18..130c5ec9ee0b 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -92,7 +92,9 @@ extern char modprobe_path[];
92extern int sg_big_buff; 92extern int sg_big_buff;
93#endif 93#endif
94#ifdef CONFIG_SYSVIPC 94#ifdef CONFIG_SYSVIPC
95static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp, 95static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
97static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos); 98 void __user *buffer, size_t *lenp, loff_t *ppos);
97#endif 99#endif
98 100
@@ -131,12 +133,22 @@ extern int max_lock_depth;
131 133
132#ifdef CONFIG_SYSCTL_SYSCALL 134#ifdef CONFIG_SYSCTL_SYSCALL
133static int parse_table(int __user *, int, void __user *, size_t __user *, 135static int parse_table(int __user *, int, void __user *, size_t __user *,
134 void __user *, size_t, ctl_table *, void **); 136 void __user *, size_t, ctl_table *);
135#endif 137#endif
136 138
137static int proc_do_uts_string(ctl_table *table, int write, struct file *filp, 139static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos); 140 void __user *buffer, size_t *lenp, loff_t *ppos);
139 141
142static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
143 void __user *oldval, size_t __user *oldlenp,
144 void __user *newval, size_t newlen);
145
146#ifdef CONFIG_SYSVIPC
147static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
148 void __user *oldval, size_t __user *oldlenp,
149 void __user *newval, size_t newlen);
150#endif
151
140#ifdef CONFIG_PROC_SYSCTL 152#ifdef CONFIG_PROC_SYSCTL
141static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp, 153static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
142 void __user *buffer, size_t *lenp, loff_t *ppos); 154 void __user *buffer, size_t *lenp, loff_t *ppos);
@@ -163,6 +175,40 @@ extern ctl_table inotify_table[];
163int sysctl_legacy_va_layout; 175int sysctl_legacy_va_layout;
164#endif 176#endif
165 177
178static void *get_uts(ctl_table *table, int write)
179{
180 char *which = table->data;
181#ifdef CONFIG_UTS_NS
182 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
183 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
184#endif
185 if (!write)
186 down_read(&uts_sem);
187 else
188 down_write(&uts_sem);
189 return which;
190}
191
192static void put_uts(ctl_table *table, int write, void *which)
193{
194 if (!write)
195 up_read(&uts_sem);
196 else
197 up_write(&uts_sem);
198}
199
200#ifdef CONFIG_SYSVIPC
201static void *get_ipc(ctl_table *table, int write)
202{
203 char *which = table->data;
204 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
205 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
206 return which;
207}
208#else
209#define get_ipc(T,W) ((T)->data)
210#endif
211
166/* /proc declarations: */ 212/* /proc declarations: */
167 213
168#ifdef CONFIG_PROC_SYSCTL 214#ifdef CONFIG_PROC_SYSCTL
@@ -229,7 +275,6 @@ static ctl_table root_table[] = {
229}; 275};
230 276
231static ctl_table kern_table[] = { 277static ctl_table kern_table[] = {
232#ifndef CONFIG_UTS_NS
233 { 278 {
234 .ctl_name = KERN_OSTYPE, 279 .ctl_name = KERN_OSTYPE,
235 .procname = "ostype", 280 .procname = "ostype",
@@ -237,7 +282,7 @@ static ctl_table kern_table[] = {
237 .maxlen = sizeof(init_uts_ns.name.sysname), 282 .maxlen = sizeof(init_uts_ns.name.sysname),
238 .mode = 0444, 283 .mode = 0444,
239 .proc_handler = &proc_do_uts_string, 284 .proc_handler = &proc_do_uts_string,
240 .strategy = &sysctl_string, 285 .strategy = &sysctl_uts_string,
241 }, 286 },
242 { 287 {
243 .ctl_name = KERN_OSRELEASE, 288 .ctl_name = KERN_OSRELEASE,
@@ -246,7 +291,7 @@ static ctl_table kern_table[] = {
246 .maxlen = sizeof(init_uts_ns.name.release), 291 .maxlen = sizeof(init_uts_ns.name.release),
247 .mode = 0444, 292 .mode = 0444,
248 .proc_handler = &proc_do_uts_string, 293 .proc_handler = &proc_do_uts_string,
249 .strategy = &sysctl_string, 294 .strategy = &sysctl_uts_string,
250 }, 295 },
251 { 296 {
252 .ctl_name = KERN_VERSION, 297 .ctl_name = KERN_VERSION,
@@ -255,7 +300,7 @@ static ctl_table kern_table[] = {
255 .maxlen = sizeof(init_uts_ns.name.version), 300 .maxlen = sizeof(init_uts_ns.name.version),
256 .mode = 0444, 301 .mode = 0444,
257 .proc_handler = &proc_do_uts_string, 302 .proc_handler = &proc_do_uts_string,
258 .strategy = &sysctl_string, 303 .strategy = &sysctl_uts_string,
259 }, 304 },
260 { 305 {
261 .ctl_name = KERN_NODENAME, 306 .ctl_name = KERN_NODENAME,
@@ -264,7 +309,7 @@ static ctl_table kern_table[] = {
264 .maxlen = sizeof(init_uts_ns.name.nodename), 309 .maxlen = sizeof(init_uts_ns.name.nodename),
265 .mode = 0644, 310 .mode = 0644,
266 .proc_handler = &proc_do_uts_string, 311 .proc_handler = &proc_do_uts_string,
267 .strategy = &sysctl_string, 312 .strategy = &sysctl_uts_string,
268 }, 313 },
269 { 314 {
270 .ctl_name = KERN_DOMAINNAME, 315 .ctl_name = KERN_DOMAINNAME,
@@ -273,56 +318,8 @@ static ctl_table kern_table[] = {
273 .maxlen = sizeof(init_uts_ns.name.domainname), 318 .maxlen = sizeof(init_uts_ns.name.domainname),
274 .mode = 0644, 319 .mode = 0644,
275 .proc_handler = &proc_do_uts_string, 320 .proc_handler = &proc_do_uts_string,
276 .strategy = &sysctl_string, 321 .strategy = &sysctl_uts_string,
277 },
278#else /* !CONFIG_UTS_NS */
279 {
280 .ctl_name = KERN_OSTYPE,
281 .procname = "ostype",
282 .data = NULL,
283 /* could maybe use __NEW_UTS_LEN here? */
284 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
285 .mode = 0444,
286 .proc_handler = &proc_do_uts_string,
287 .strategy = &sysctl_string,
288 },
289 {
290 .ctl_name = KERN_OSRELEASE,
291 .procname = "osrelease",
292 .data = NULL,
293 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
294 .mode = 0444,
295 .proc_handler = &proc_do_uts_string,
296 .strategy = &sysctl_string,
297 },
298 {
299 .ctl_name = KERN_VERSION,
300 .procname = "version",
301 .data = NULL,
302 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
303 .mode = 0444,
304 .proc_handler = &proc_do_uts_string,
305 .strategy = &sysctl_string,
306 },
307 {
308 .ctl_name = KERN_NODENAME,
309 .procname = "hostname",
310 .data = NULL,
311 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
312 .mode = 0644,
313 .proc_handler = &proc_do_uts_string,
314 .strategy = &sysctl_string,
315 },
316 {
317 .ctl_name = KERN_DOMAINNAME,
318 .procname = "domainname",
319 .data = NULL,
320 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
321 .mode = 0644,
322 .proc_handler = &proc_do_uts_string,
323 .strategy = &sysctl_string,
324 }, 322 },
325#endif /* !CONFIG_UTS_NS */
326 { 323 {
327 .ctl_name = KERN_PANIC, 324 .ctl_name = KERN_PANIC,
328 .procname = "panic", 325 .procname = "panic",
@@ -481,58 +478,65 @@ static ctl_table kern_table[] = {
481 { 478 {
482 .ctl_name = KERN_SHMMAX, 479 .ctl_name = KERN_SHMMAX,
483 .procname = "shmmax", 480 .procname = "shmmax",
484 .data = NULL, 481 .data = &init_ipc_ns.shm_ctlmax,
485 .maxlen = sizeof (size_t), 482 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
486 .mode = 0644, 483 .mode = 0644,
487 .proc_handler = &proc_do_ipc_string, 484 .proc_handler = &proc_ipc_doulongvec_minmax,
485 .strategy = sysctl_ipc_data,
488 }, 486 },
489 { 487 {
490 .ctl_name = KERN_SHMALL, 488 .ctl_name = KERN_SHMALL,
491 .procname = "shmall", 489 .procname = "shmall",
492 .data = NULL, 490 .data = &init_ipc_ns.shm_ctlall,
493 .maxlen = sizeof (size_t), 491 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
494 .mode = 0644, 492 .mode = 0644,
495 .proc_handler = &proc_do_ipc_string, 493 .proc_handler = &proc_ipc_doulongvec_minmax,
494 .strategy = sysctl_ipc_data,
496 }, 495 },
497 { 496 {
498 .ctl_name = KERN_SHMMNI, 497 .ctl_name = KERN_SHMMNI,
499 .procname = "shmmni", 498 .procname = "shmmni",
500 .data = NULL, 499 .data = &init_ipc_ns.shm_ctlmni,
501 .maxlen = sizeof (int), 500 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
502 .mode = 0644, 501 .mode = 0644,
503 .proc_handler = &proc_do_ipc_string, 502 .proc_handler = &proc_ipc_dointvec,
503 .strategy = sysctl_ipc_data,
504 }, 504 },
505 { 505 {
506 .ctl_name = KERN_MSGMAX, 506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax", 507 .procname = "msgmax",
508 .data = NULL, 508 .data = &init_ipc_ns.msg_ctlmax,
509 .maxlen = sizeof (int), 509 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
510 .mode = 0644, 510 .mode = 0644,
511 .proc_handler = &proc_do_ipc_string, 511 .proc_handler = &proc_ipc_dointvec,
512 .strategy = sysctl_ipc_data,
512 }, 513 },
513 { 514 {
514 .ctl_name = KERN_MSGMNI, 515 .ctl_name = KERN_MSGMNI,
515 .procname = "msgmni", 516 .procname = "msgmni",
516 .data = NULL, 517 .data = &init_ipc_ns.msg_ctlmni,
517 .maxlen = sizeof (int), 518 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
518 .mode = 0644, 519 .mode = 0644,
519 .proc_handler = &proc_do_ipc_string, 520 .proc_handler = &proc_ipc_dointvec,
521 .strategy = sysctl_ipc_data,
520 }, 522 },
521 { 523 {
522 .ctl_name = KERN_MSGMNB, 524 .ctl_name = KERN_MSGMNB,
523 .procname = "msgmnb", 525 .procname = "msgmnb",
524 .data = NULL, 526 .data = &init_ipc_ns.msg_ctlmnb,
525 .maxlen = sizeof (int), 527 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
526 .mode = 0644, 528 .mode = 0644,
527 .proc_handler = &proc_do_ipc_string, 529 .proc_handler = &proc_ipc_dointvec,
530 .strategy = sysctl_ipc_data,
528 }, 531 },
529 { 532 {
530 .ctl_name = KERN_SEM, 533 .ctl_name = KERN_SEM,
531 .procname = "sem", 534 .procname = "sem",
532 .data = NULL, 535 .data = &init_ipc_ns.sem_ctls,
533 .maxlen = 4*sizeof (int), 536 .maxlen = 4*sizeof (int),
534 .mode = 0644, 537 .mode = 0644,
535 .proc_handler = &proc_do_ipc_string, 538 .proc_handler = &proc_ipc_dointvec,
539 .strategy = sysctl_ipc_data,
536 }, 540 },
537#endif 541#endif
538#ifdef CONFIG_MAGIC_SYSRQ 542#ifdef CONFIG_MAGIC_SYSRQ
@@ -1239,7 +1243,6 @@ int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *ol
1239 do { 1243 do {
1240 struct ctl_table_header *head = 1244 struct ctl_table_header *head =
1241 list_entry(tmp, struct ctl_table_header, ctl_entry); 1245 list_entry(tmp, struct ctl_table_header, ctl_entry);
1242 void *context = NULL;
1243 1246
1244 if (!use_table(head)) 1247 if (!use_table(head))
1245 continue; 1248 continue;
@@ -1247,9 +1250,7 @@ int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *ol
1247 spin_unlock(&sysctl_lock); 1250 spin_unlock(&sysctl_lock);
1248 1251
1249 error = parse_table(name, nlen, oldval, oldlenp, 1252 error = parse_table(name, nlen, oldval, oldlenp,
1250 newval, newlen, head->ctl_table, 1253 newval, newlen, head->ctl_table);
1251 &context);
1252 kfree(context);
1253 1254
1254 spin_lock(&sysctl_lock); 1255 spin_lock(&sysctl_lock);
1255 unuse_table(head); 1256 unuse_table(head);
@@ -1305,7 +1306,7 @@ static inline int ctl_perm(ctl_table *table, int op)
1305static int parse_table(int __user *name, int nlen, 1306static int parse_table(int __user *name, int nlen,
1306 void __user *oldval, size_t __user *oldlenp, 1307 void __user *oldval, size_t __user *oldlenp,
1307 void __user *newval, size_t newlen, 1308 void __user *newval, size_t newlen,
1308 ctl_table *table, void **context) 1309 ctl_table *table)
1309{ 1310{
1310 int n; 1311 int n;
1311repeat: 1312repeat:
@@ -1325,7 +1326,7 @@ repeat:
1325 error = table->strategy( 1326 error = table->strategy(
1326 table, name, nlen, 1327 table, name, nlen,
1327 oldval, oldlenp, 1328 oldval, oldlenp,
1328 newval, newlen, context); 1329 newval, newlen);
1329 if (error) 1330 if (error)
1330 return error; 1331 return error;
1331 } 1332 }
@@ -1336,7 +1337,7 @@ repeat:
1336 } 1337 }
1337 error = do_sysctl_strategy(table, name, nlen, 1338 error = do_sysctl_strategy(table, name, nlen,
1338 oldval, oldlenp, 1339 oldval, oldlenp,
1339 newval, newlen, context); 1340 newval, newlen);
1340 return error; 1341 return error;
1341 } 1342 }
1342 } 1343 }
@@ -1347,7 +1348,7 @@ repeat:
1347int do_sysctl_strategy (ctl_table *table, 1348int do_sysctl_strategy (ctl_table *table,
1348 int __user *name, int nlen, 1349 int __user *name, int nlen,
1349 void __user *oldval, size_t __user *oldlenp, 1350 void __user *oldval, size_t __user *oldlenp,
1350 void __user *newval, size_t newlen, void **context) 1351 void __user *newval, size_t newlen)
1351{ 1352{
1352 int op = 0, rc; 1353 int op = 0, rc;
1353 size_t len; 1354 size_t len;
@@ -1361,7 +1362,7 @@ int do_sysctl_strategy (ctl_table *table,
1361 1362
1362 if (table->strategy) { 1363 if (table->strategy) {
1363 rc = table->strategy(table, name, nlen, oldval, oldlenp, 1364 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1364 newval, newlen, context); 1365 newval, newlen);
1365 if (rc < 0) 1366 if (rc < 0)
1366 return rc; 1367 return rc;
1367 if (rc > 0) 1368 if (rc > 0)
@@ -1614,7 +1615,7 @@ static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1614 size_t count, loff_t *ppos) 1615 size_t count, loff_t *ppos)
1615{ 1616{
1616 int op; 1617 int op;
1617 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode); 1618 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1618 struct ctl_table *table; 1619 struct ctl_table *table;
1619 size_t res; 1620 size_t res;
1620 ssize_t error = -ENOTDIR; 1621 ssize_t error = -ENOTDIR;
@@ -1753,66 +1754,17 @@ int proc_dostring(ctl_table *table, int write, struct file *filp,
1753 * Special case of dostring for the UTS structure. This has locks 1754 * Special case of dostring for the UTS structure. This has locks
1754 * to observe. Should this be in kernel/sys.c ???? 1755 * to observe. Should this be in kernel/sys.c ????
1755 */ 1756 */
1756
1757#ifndef CONFIG_UTS_NS
1758static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1760{
1761 int r;
1762 1757
1763 if (!write) {
1764 down_read(&uts_sem);
1765 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1766 up_read(&uts_sem);
1767 } else {
1768 down_write(&uts_sem);
1769 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1770 up_write(&uts_sem);
1771 }
1772 return r;
1773}
1774#else /* !CONFIG_UTS_NS */
1775static int proc_do_uts_string(ctl_table *table, int write, struct file *filp, 1758static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1776 void __user *buffer, size_t *lenp, loff_t *ppos) 1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1777{ 1760{
1778 int r; 1761 int r;
1779 struct uts_namespace* uts_ns = current->nsproxy->uts_ns; 1762 void *which;
1780 char* which; 1763 which = get_uts(table, write);
1781 1764 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1782 switch (table->ctl_name) { 1765 put_uts(table, write, which);
1783 case KERN_OSTYPE:
1784 which = uts_ns->name.sysname;
1785 break;
1786 case KERN_NODENAME:
1787 which = uts_ns->name.nodename;
1788 break;
1789 case KERN_OSRELEASE:
1790 which = uts_ns->name.release;
1791 break;
1792 case KERN_VERSION:
1793 which = uts_ns->name.version;
1794 break;
1795 case KERN_DOMAINNAME:
1796 which = uts_ns->name.domainname;
1797 break;
1798 default:
1799 r = -EINVAL;
1800 goto out;
1801 }
1802
1803 if (!write) {
1804 down_read(&uts_sem);
1805 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1806 up_read(&uts_sem);
1807 } else {
1808 down_write(&uts_sem);
1809 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1810 up_write(&uts_sem);
1811 }
1812 out:
1813 return r; 1766 return r;
1814} 1767}
1815#endif /* !CONFIG_UTS_NS */
1816 1768
1817static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 1769static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1818 int *valp, 1770 int *valp,
@@ -1976,9 +1928,6 @@ int proc_dointvec(ctl_table *table, int write, struct file *filp,
1976 1928
1977#define OP_SET 0 1929#define OP_SET 0
1978#define OP_AND 1 1930#define OP_AND 1
1979#define OP_OR 2
1980#define OP_MAX 3
1981#define OP_MIN 4
1982 1931
1983static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, 1932static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1984 int *valp, 1933 int *valp,
@@ -1990,13 +1939,6 @@ static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1990 switch(op) { 1939 switch(op) {
1991 case OP_SET: *valp = val; break; 1940 case OP_SET: *valp = val; break;
1992 case OP_AND: *valp &= val; break; 1941 case OP_AND: *valp &= val; break;
1993 case OP_OR: *valp |= val; break;
1994 case OP_MAX: if(*valp < val)
1995 *valp = val;
1996 break;
1997 case OP_MIN: if(*valp > val)
1998 *valp = val;
1999 break;
2000 } 1942 }
2001 } else { 1943 } else {
2002 int val = *valp; 1944 int val = *valp;
@@ -2391,46 +2333,24 @@ int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2391} 2333}
2392 2334
2393#ifdef CONFIG_SYSVIPC 2335#ifdef CONFIG_SYSVIPC
2394static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp, 2336static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos) 2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2396{ 2338{
2397 void *data; 2339 void *which;
2398 struct ipc_namespace *ns; 2340 which = get_ipc(table, write);
2399 2341 return __do_proc_dointvec(which, table, write, filp, buffer,
2400 ns = current->nsproxy->ipc_ns;
2401
2402 switch (table->ctl_name) {
2403 case KERN_SHMMAX:
2404 data = &ns->shm_ctlmax;
2405 goto proc_minmax;
2406 case KERN_SHMALL:
2407 data = &ns->shm_ctlall;
2408 goto proc_minmax;
2409 case KERN_SHMMNI:
2410 data = &ns->shm_ctlmni;
2411 break;
2412 case KERN_MSGMAX:
2413 data = &ns->msg_ctlmax;
2414 break;
2415 case KERN_MSGMNI:
2416 data = &ns->msg_ctlmni;
2417 break;
2418 case KERN_MSGMNB:
2419 data = &ns->msg_ctlmnb;
2420 break;
2421 case KERN_SEM:
2422 data = &ns->sem_ctls;
2423 break;
2424 default:
2425 return -EINVAL;
2426 }
2427
2428 return __do_proc_dointvec(data, table, write, filp, buffer,
2429 lenp, ppos, NULL, NULL); 2342 lenp, ppos, NULL, NULL);
2430proc_minmax: 2343}
2431 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer, 2344
2345static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2346 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2347{
2348 void *which;
2349 which = get_ipc(table, write);
2350 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2432 lenp, ppos, 1l, 1l); 2351 lenp, ppos, 1l, 1l);
2433} 2352}
2353
2434#endif 2354#endif
2435 2355
2436static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp, 2356static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
@@ -2475,6 +2395,17 @@ static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2475{ 2395{
2476 return -ENOSYS; 2396 return -ENOSYS;
2477} 2397}
2398static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2400{
2401 return -ENOSYS;
2402}
2403static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2404 struct file *filp, void __user *buffer,
2405 size_t *lenp, loff_t *ppos)
2406{
2407 return -ENOSYS;
2408}
2478#endif 2409#endif
2479 2410
2480int proc_dointvec(ctl_table *table, int write, struct file *filp, 2411int proc_dointvec(ctl_table *table, int write, struct file *filp,
@@ -2539,7 +2470,7 @@ int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2539/* The generic string strategy routine: */ 2470/* The generic string strategy routine: */
2540int sysctl_string(ctl_table *table, int __user *name, int nlen, 2471int sysctl_string(ctl_table *table, int __user *name, int nlen,
2541 void __user *oldval, size_t __user *oldlenp, 2472 void __user *oldval, size_t __user *oldlenp,
2542 void __user *newval, size_t newlen, void **context) 2473 void __user *newval, size_t newlen)
2543{ 2474{
2544 if (!table->data || !table->maxlen) 2475 if (!table->data || !table->maxlen)
2545 return -ENOTDIR; 2476 return -ENOTDIR;
@@ -2585,7 +2516,7 @@ int sysctl_string(ctl_table *table, int __user *name, int nlen,
2585 */ 2516 */
2586int sysctl_intvec(ctl_table *table, int __user *name, int nlen, 2517int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp, 2518 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen, void **context) 2519 void __user *newval, size_t newlen)
2589{ 2520{
2590 2521
2591 if (newval && newlen) { 2522 if (newval && newlen) {
@@ -2621,7 +2552,7 @@ int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2621/* Strategy function to convert jiffies to seconds */ 2552/* Strategy function to convert jiffies to seconds */
2622int sysctl_jiffies(ctl_table *table, int __user *name, int nlen, 2553int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2623 void __user *oldval, size_t __user *oldlenp, 2554 void __user *oldval, size_t __user *oldlenp,
2624 void __user *newval, size_t newlen, void **context) 2555 void __user *newval, size_t newlen)
2625{ 2556{
2626 if (oldval) { 2557 if (oldval) {
2627 size_t olen; 2558 size_t olen;
@@ -2649,7 +2580,7 @@ int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2649/* Strategy function to convert jiffies to seconds */ 2580/* Strategy function to convert jiffies to seconds */
2650int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen, 2581int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp, 2582 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen, void **context) 2583 void __user *newval, size_t newlen)
2653{ 2584{
2654 if (oldval) { 2585 if (oldval) {
2655 size_t olen; 2586 size_t olen;
@@ -2674,6 +2605,64 @@ int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2674 return 1; 2605 return 1;
2675} 2606}
2676 2607
2608
2609/* The generic string strategy routine: */
2610static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2611 void __user *oldval, size_t __user *oldlenp,
2612 void __user *newval, size_t newlen)
2613{
2614 struct ctl_table uts_table;
2615 int r, write;
2616 write = newval && newlen;
2617 memcpy(&uts_table, table, sizeof(uts_table));
2618 uts_table.data = get_uts(table, write);
2619 r = sysctl_string(&uts_table, name, nlen,
2620 oldval, oldlenp, newval, newlen);
2621 put_uts(table, write, uts_table.data);
2622 return r;
2623}
2624
2625#ifdef CONFIG_SYSVIPC
2626/* The generic sysctl ipc data routine. */
2627static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2628 void __user *oldval, size_t __user *oldlenp,
2629 void __user *newval, size_t newlen)
2630{
2631 size_t len;
2632 void *data;
2633
2634 /* Get out of I don't have a variable */
2635 if (!table->data || !table->maxlen)
2636 return -ENOTDIR;
2637
2638 data = get_ipc(table, 1);
2639 if (!data)
2640 return -ENOTDIR;
2641
2642 if (oldval && oldlenp) {
2643 if (get_user(len, oldlenp))
2644 return -EFAULT;
2645 if (len) {
2646 if (len > table->maxlen)
2647 len = table->maxlen;
2648 if (copy_to_user(oldval, data, len))
2649 return -EFAULT;
2650 if (put_user(len, oldlenp))
2651 return -EFAULT;
2652 }
2653 }
2654
2655 if (newval && newlen) {
2656 if (newlen > table->maxlen)
2657 newlen = table->maxlen;
2658
2659 if (copy_from_user(data, newval, newlen))
2660 return -EFAULT;
2661 }
2662 return 1;
2663}
2664#endif
2665
2677#else /* CONFIG_SYSCTL_SYSCALL */ 2666#else /* CONFIG_SYSCTL_SYSCALL */
2678 2667
2679 2668
@@ -2712,32 +2701,44 @@ out:
2712 2701
2713int sysctl_string(ctl_table *table, int __user *name, int nlen, 2702int sysctl_string(ctl_table *table, int __user *name, int nlen,
2714 void __user *oldval, size_t __user *oldlenp, 2703 void __user *oldval, size_t __user *oldlenp,
2715 void __user *newval, size_t newlen, void **context) 2704 void __user *newval, size_t newlen)
2716{ 2705{
2717 return -ENOSYS; 2706 return -ENOSYS;
2718} 2707}
2719 2708
2720int sysctl_intvec(ctl_table *table, int __user *name, int nlen, 2709int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2721 void __user *oldval, size_t __user *oldlenp, 2710 void __user *oldval, size_t __user *oldlenp,
2722 void __user *newval, size_t newlen, void **context) 2711 void __user *newval, size_t newlen)
2723{ 2712{
2724 return -ENOSYS; 2713 return -ENOSYS;
2725} 2714}
2726 2715
2727int sysctl_jiffies(ctl_table *table, int __user *name, int nlen, 2716int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp, 2717 void __user *oldval, size_t __user *oldlenp,
2729 void __user *newval, size_t newlen, void **context) 2718 void __user *newval, size_t newlen)
2730{ 2719{
2731 return -ENOSYS; 2720 return -ENOSYS;
2732} 2721}
2733 2722
2734int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen, 2723int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp, 2724 void __user *oldval, size_t __user *oldlenp,
2736 void __user *newval, size_t newlen, void **context) 2725 void __user *newval, size_t newlen)
2737{ 2726{
2738 return -ENOSYS; 2727 return -ENOSYS;
2739} 2728}
2740 2729
2730static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2731 void __user *oldval, size_t __user *oldlenp,
2732 void __user *newval, size_t newlen)
2733{
2734 return -ENOSYS;
2735}
2736static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2737 void __user *oldval, size_t __user *oldlenp,
2738 void __user *newval, size_t newlen)
2739{
2740 return -ENOSYS;
2741}
2741#endif /* CONFIG_SYSCTL_SYSCALL */ 2742#endif /* CONFIG_SYSCTL_SYSCALL */
2742 2743
2743/* 2744/*
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 74eca5939bd9..22504afc0d34 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -156,7 +156,7 @@ int clocksource_register(struct clocksource *c)
156 /* check if clocksource is already registered */ 156 /* check if clocksource is already registered */
157 if (is_registered_source(c)) { 157 if (is_registered_source(c)) {
158 printk("register_clocksource: Cannot register %s. " 158 printk("register_clocksource: Cannot register %s. "
159 "Already registered!", c->name); 159 "Already registered!", c->name);
160 ret = -EBUSY; 160 ret = -EBUSY;
161 } else { 161 } else {
162 /* register it */ 162 /* register it */
@@ -186,6 +186,7 @@ void clocksource_reselect(void)
186} 186}
187EXPORT_SYMBOL(clocksource_reselect); 187EXPORT_SYMBOL(clocksource_reselect);
188 188
189#ifdef CONFIG_SYSFS
189/** 190/**
190 * sysfs_show_current_clocksources - sysfs interface for current clocksource 191 * sysfs_show_current_clocksources - sysfs interface for current clocksource
191 * @dev: unused 192 * @dev: unused
@@ -275,10 +276,10 @@ sysfs_show_available_clocksources(struct sys_device *dev, char *buf)
275 * Sysfs setup bits: 276 * Sysfs setup bits:
276 */ 277 */
277static SYSDEV_ATTR(current_clocksource, 0600, sysfs_show_current_clocksources, 278static SYSDEV_ATTR(current_clocksource, 0600, sysfs_show_current_clocksources,
278 sysfs_override_clocksource); 279 sysfs_override_clocksource);
279 280
280static SYSDEV_ATTR(available_clocksource, 0600, 281static SYSDEV_ATTR(available_clocksource, 0600,
281 sysfs_show_available_clocksources, NULL); 282 sysfs_show_available_clocksources, NULL);
282 283
283static struct sysdev_class clocksource_sysclass = { 284static struct sysdev_class clocksource_sysclass = {
284 set_kset_name("clocksource"), 285 set_kset_name("clocksource"),
@@ -307,6 +308,7 @@ static int __init init_clocksource_sysfs(void)
307} 308}
308 309
309device_initcall(init_clocksource_sysfs); 310device_initcall(init_clocksource_sysfs);
311#endif /* CONFIG_SYSFS */
310 312
311/** 313/**
312 * boot_override_clocksource - boot clock override 314 * boot_override_clocksource - boot clock override
diff --git a/kernel/timer.c b/kernel/timer.c
index c1c7fbcffec1..0256ab443d8a 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -80,6 +80,138 @@ tvec_base_t boot_tvec_bases;
80EXPORT_SYMBOL(boot_tvec_bases); 80EXPORT_SYMBOL(boot_tvec_bases);
81static DEFINE_PER_CPU(tvec_base_t *, tvec_bases) = &boot_tvec_bases; 81static DEFINE_PER_CPU(tvec_base_t *, tvec_bases) = &boot_tvec_bases;
82 82
83/**
84 * __round_jiffies - function to round jiffies to a full second
85 * @j: the time in (absolute) jiffies that should be rounded
86 * @cpu: the processor number on which the timeout will happen
87 *
88 * __round_jiffies rounds an absolute time in the future (in jiffies)
89 * up or down to (approximately) full seconds. This is useful for timers
90 * for which the exact time they fire does not matter too much, as long as
91 * they fire approximately every X seconds.
92 *
93 * By rounding these timers to whole seconds, all such timers will fire
94 * at the same time, rather than at various times spread out. The goal
95 * of this is to have the CPU wake up less, which saves power.
96 *
97 * The exact rounding is skewed for each processor to avoid all
98 * processors firing at the exact same time, which could lead
99 * to lock contention or spurious cache line bouncing.
100 *
101 * The return value is the rounded version of the "j" parameter.
102 */
103unsigned long __round_jiffies(unsigned long j, int cpu)
104{
105 int rem;
106 unsigned long original = j;
107
108 /*
109 * We don't want all cpus firing their timers at once hitting the
110 * same lock or cachelines, so we skew each extra cpu with an extra
111 * 3 jiffies. This 3 jiffies came originally from the mm/ code which
112 * already did this.
113 * The skew is done by adding 3*cpunr, then round, then subtract this
114 * extra offset again.
115 */
116 j += cpu * 3;
117
118 rem = j % HZ;
119
120 /*
121 * If the target jiffie is just after a whole second (which can happen
122 * due to delays of the timer irq, long irq off times etc etc) then
123 * we should round down to the whole second, not up. Use 1/4th second
124 * as cutoff for this rounding as an extreme upper bound for this.
125 */
126 if (rem < HZ/4) /* round down */
127 j = j - rem;
128 else /* round up */
129 j = j - rem + HZ;
130
131 /* now that we have rounded, subtract the extra skew again */
132 j -= cpu * 3;
133
134 if (j <= jiffies) /* rounding ate our timeout entirely; */
135 return original;
136 return j;
137}
138EXPORT_SYMBOL_GPL(__round_jiffies);
139
140/**
141 * __round_jiffies_relative - function to round jiffies to a full second
142 * @j: the time in (relative) jiffies that should be rounded
143 * @cpu: the processor number on which the timeout will happen
144 *
145 * __round_jiffies_relative rounds a time delta in the future (in jiffies)
146 * up or down to (approximately) full seconds. This is useful for timers
147 * for which the exact time they fire does not matter too much, as long as
148 * they fire approximately every X seconds.
149 *
150 * By rounding these timers to whole seconds, all such timers will fire
151 * at the same time, rather than at various times spread out. The goal
152 * of this is to have the CPU wake up less, which saves power.
153 *
154 * The exact rounding is skewed for each processor to avoid all
155 * processors firing at the exact same time, which could lead
156 * to lock contention or spurious cache line bouncing.
157 *
158 * The return value is the rounded version of the "j" parameter.
159 */
160unsigned long __round_jiffies_relative(unsigned long j, int cpu)
161{
162 /*
163 * In theory the following code can skip a jiffy in case jiffies
164 * increments right between the addition and the later subtraction.
165 * However since the entire point of this function is to use approximate
166 * timeouts, it's entirely ok to not handle that.
167 */
168 return __round_jiffies(j + jiffies, cpu) - jiffies;
169}
170EXPORT_SYMBOL_GPL(__round_jiffies_relative);
171
172/**
173 * round_jiffies - function to round jiffies to a full second
174 * @j: the time in (absolute) jiffies that should be rounded
175 *
176 * round_jiffies rounds an absolute time in the future (in jiffies)
177 * up or down to (approximately) full seconds. This is useful for timers
178 * for which the exact time they fire does not matter too much, as long as
179 * they fire approximately every X seconds.
180 *
181 * By rounding these timers to whole seconds, all such timers will fire
182 * at the same time, rather than at various times spread out. The goal
183 * of this is to have the CPU wake up less, which saves power.
184 *
185 * The return value is the rounded version of the "j" parameter.
186 */
187unsigned long round_jiffies(unsigned long j)
188{
189 return __round_jiffies(j, raw_smp_processor_id());
190}
191EXPORT_SYMBOL_GPL(round_jiffies);
192
193/**
194 * round_jiffies_relative - function to round jiffies to a full second
195 * @j: the time in (relative) jiffies that should be rounded
196 *
197 * round_jiffies_relative rounds a time delta in the future (in jiffies)
198 * up or down to (approximately) full seconds. This is useful for timers
199 * for which the exact time they fire does not matter too much, as long as
200 * they fire approximately every X seconds.
201 *
202 * By rounding these timers to whole seconds, all such timers will fire
203 * at the same time, rather than at various times spread out. The goal
204 * of this is to have the CPU wake up less, which saves power.
205 *
206 * The return value is the rounded version of the "j" parameter.
207 */
208unsigned long round_jiffies_relative(unsigned long j)
209{
210 return __round_jiffies_relative(j, raw_smp_processor_id());
211}
212EXPORT_SYMBOL_GPL(round_jiffies_relative);
213
214
83static inline void set_running_timer(tvec_base_t *base, 215static inline void set_running_timer(tvec_base_t *base,
84 struct timer_list *timer) 216 struct timer_list *timer)
85{ 217{
@@ -714,7 +846,7 @@ static int change_clocksource(void)
714 clock = new; 846 clock = new;
715 clock->cycle_last = now; 847 clock->cycle_last = now;
716 printk(KERN_INFO "Time: %s clocksource has been installed.\n", 848 printk(KERN_INFO "Time: %s clocksource has been installed.\n",
717 clock->name); 849 clock->name);
718 return 1; 850 return 1;
719 } else if (clock->update_callback) { 851 } else if (clock->update_callback) {
720 return clock->update_callback(); 852 return clock->update_callback();
@@ -722,7 +854,10 @@ static int change_clocksource(void)
722 return 0; 854 return 0;
723} 855}
724#else 856#else
725#define change_clocksource() (0) 857static inline int change_clocksource(void)
858{
859 return 0;
860}
726#endif 861#endif
727 862
728/** 863/**
@@ -820,7 +955,8 @@ device_initcall(timekeeping_init_device);
820 * If the error is already larger, we look ahead even further 955 * If the error is already larger, we look ahead even further
821 * to compensate for late or lost adjustments. 956 * to compensate for late or lost adjustments.
822 */ 957 */
823static __always_inline int clocksource_bigadjust(s64 error, s64 *interval, s64 *offset) 958static __always_inline int clocksource_bigadjust(s64 error, s64 *interval,
959 s64 *offset)
824{ 960{
825 s64 tick_error, i; 961 s64 tick_error, i;
826 u32 look_ahead, adj; 962 u32 look_ahead, adj;
@@ -844,7 +980,8 @@ static __always_inline int clocksource_bigadjust(s64 error, s64 *interval, s64 *
844 * Now calculate the error in (1 << look_ahead) ticks, but first 980 * Now calculate the error in (1 << look_ahead) ticks, but first
845 * remove the single look ahead already included in the error. 981 * remove the single look ahead already included in the error.
846 */ 982 */
847 tick_error = current_tick_length() >> (TICK_LENGTH_SHIFT - clock->shift + 1); 983 tick_error = current_tick_length() >>
984 (TICK_LENGTH_SHIFT - clock->shift + 1);
848 tick_error -= clock->xtime_interval >> 1; 985 tick_error -= clock->xtime_interval >> 1;
849 error = ((error - tick_error) >> look_ahead) + tick_error; 986 error = ((error - tick_error) >> look_ahead) + tick_error;
850 987
@@ -896,7 +1033,8 @@ static void clocksource_adjust(struct clocksource *clock, s64 offset)
896 clock->mult += adj; 1033 clock->mult += adj;
897 clock->xtime_interval += interval; 1034 clock->xtime_interval += interval;
898 clock->xtime_nsec -= offset; 1035 clock->xtime_nsec -= offset;
899 clock->error -= (interval - offset) << (TICK_LENGTH_SHIFT - clock->shift); 1036 clock->error -= (interval - offset) <<
1037 (TICK_LENGTH_SHIFT - clock->shift);
900} 1038}
901 1039
902/** 1040/**
diff --git a/kernel/tsacct.c b/kernel/tsacct.c
index 96f77013d3f0..baacc3691415 100644
--- a/kernel/tsacct.c
+++ b/kernel/tsacct.c
@@ -96,6 +96,15 @@ void xacct_add_tsk(struct taskstats *stats, struct task_struct *p)
96 stats->write_char = p->wchar; 96 stats->write_char = p->wchar;
97 stats->read_syscalls = p->syscr; 97 stats->read_syscalls = p->syscr;
98 stats->write_syscalls = p->syscw; 98 stats->write_syscalls = p->syscw;
99#ifdef CONFIG_TASK_IO_ACCOUNTING
100 stats->read_bytes = p->ioac.read_bytes;
101 stats->write_bytes = p->ioac.write_bytes;
102 stats->cancelled_write_bytes = p->ioac.cancelled_write_bytes;
103#else
104 stats->read_bytes = 0;
105 stats->write_bytes = 0;
106 stats->cancelled_write_bytes = 0;
107#endif
99} 108}
100#undef KB 109#undef KB
101#undef MB 110#undef MB
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 6b186750e9be..db49886bfae1 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -85,22 +85,19 @@ static inline int is_single_threaded(struct workqueue_struct *wq)
85 return list_empty(&wq->list); 85 return list_empty(&wq->list);
86} 86}
87 87
88/*
89 * Set the workqueue on which a work item is to be run
90 * - Must *only* be called if the pending flag is set
91 */
88static inline void set_wq_data(struct work_struct *work, void *wq) 92static inline void set_wq_data(struct work_struct *work, void *wq)
89{ 93{
90 unsigned long new, old, res; 94 unsigned long new;
95
96 BUG_ON(!work_pending(work));
91 97
92 /* assume the pending flag is already set and that the task has already
93 * been queued on this workqueue */
94 new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING); 98 new = (unsigned long) wq | (1UL << WORK_STRUCT_PENDING);
95 res = work->management; 99 new |= work->management & WORK_STRUCT_FLAG_MASK;
96 if (res != new) { 100 work->management = new;
97 do {
98 old = res;
99 new = (unsigned long) wq;
100 new |= (old & WORK_STRUCT_FLAG_MASK);
101 res = cmpxchg(&work->management, old, new);
102 } while (res != old);
103 }
104} 101}
105 102
106static inline void *get_wq_data(struct work_struct *work) 103static inline void *get_wq_data(struct work_struct *work)
diff --git a/lib/Kconfig b/lib/Kconfig
index 734ce95a93d1..47b172df3e31 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -4,6 +4,9 @@
4 4
5menu "Library routines" 5menu "Library routines"
6 6
7config BITREVERSE
8 tristate
9
7config CRC_CCITT 10config CRC_CCITT
8 tristate "CRC-CCITT functions" 11 tristate "CRC-CCITT functions"
9 help 12 help
@@ -23,6 +26,7 @@ config CRC16
23config CRC32 26config CRC32
24 tristate "CRC32 functions" 27 tristate "CRC32 functions"
25 default y 28 default y
29 select BITREVERSE
26 help 30 help
27 This option is provided for the case where no in-kernel-tree 31 This option is provided for the case where no in-kernel-tree
28 modules require CRC32 functions, but a module built outside the 32 modules require CRC32 functions, but a module built outside the
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index b75fed737f25..0701ddda1df8 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -47,6 +47,30 @@ config UNUSED_SYMBOLS
47 you really need it, and what the merge plan to the mainline kernel for 47 you really need it, and what the merge plan to the mainline kernel for
48 your module is. 48 your module is.
49 49
50config DEBUG_FS
51 bool "Debug Filesystem"
52 depends on SYSFS
53 help
54 debugfs is a virtual file system that kernel developers use to put
55 debugging files into. Enable this option to be able to read and
56 write to these files.
57
58 If unsure, say N.
59
60config HEADERS_CHECK
61 bool "Run 'make headers_check' when building vmlinux"
62 depends on !UML
63 help
64 This option will extract the user-visible kernel headers whenever
65 building the kernel, and will run basic sanity checks on them to
66 ensure that exported files do not attempt to include files which
67 were not exported, etc.
68
69 If you're making modifications to header files which are
70 relevant for userspace, say 'Y', and check the headers
71 exported to $(INSTALL_HDR_PATH) (usually 'usr/include' in
72 your build tree), to make sure they're suitable.
73
50config DEBUG_KERNEL 74config DEBUG_KERNEL
51 bool "Kernel debugging" 75 bool "Kernel debugging"
52 help 76 help
@@ -285,7 +309,7 @@ config DEBUG_HIGHMEM
285config DEBUG_BUGVERBOSE 309config DEBUG_BUGVERBOSE
286 bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EMBEDDED 310 bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EMBEDDED
287 depends on BUG 311 depends on BUG
288 depends on ARM || ARM26 || AVR32 || M32R || M68K || SPARC32 || SPARC64 || X86_32 || FRV || SUPERH 312 depends on ARM || ARM26 || AVR32 || M32R || M68K || SPARC32 || SPARC64 || FRV || SUPERH || GENERIC_BUG
289 default !EMBEDDED 313 default !EMBEDDED
290 help 314 help
291 Say Y here to make BUG() panics output the file name and line number 315 Say Y here to make BUG() panics output the file name and line number
@@ -302,16 +326,6 @@ config DEBUG_INFO
302 326
303 If unsure, say N. 327 If unsure, say N.
304 328
305config DEBUG_FS
306 bool "Debug Filesystem"
307 depends on SYSFS
308 help
309 debugfs is a virtual file system that kernel developers use to put
310 debugging files into. Enable this option to be able to read and
311 write to these files.
312
313 If unsure, say N.
314
315config DEBUG_VM 329config DEBUG_VM
316 bool "Debug VM" 330 bool "Debug VM"
317 depends on DEBUG_KERNEL 331 depends on DEBUG_KERNEL
@@ -372,20 +386,6 @@ config FORCED_INLINING
372 become the default in the future, until then this option is there to 386 become the default in the future, until then this option is there to
373 test gcc for this. 387 test gcc for this.
374 388
375config HEADERS_CHECK
376 bool "Run 'make headers_check' when building vmlinux"
377 depends on !UML
378 help
379 This option will extract the user-visible kernel headers whenever
380 building the kernel, and will run basic sanity checks on them to
381 ensure that exported files do not attempt to include files which
382 were not exported, etc.
383
384 If you're making modifications to header files which are
385 relevant for userspace, say 'Y', and check the headers
386 exported to $(INSTALL_HDR_PATH) (usually 'usr/include' in
387 your build tree), to make sure they're suitable.
388
389config RCU_TORTURE_TEST 389config RCU_TORTURE_TEST
390 tristate "torture tests for RCU" 390 tristate "torture tests for RCU"
391 depends on DEBUG_KERNEL 391 depends on DEBUG_KERNEL
@@ -402,6 +402,7 @@ config RCU_TORTURE_TEST
402 402
403config LKDTM 403config LKDTM
404 tristate "Linux Kernel Dump Test Tool Module" 404 tristate "Linux Kernel Dump Test Tool Module"
405 depends on DEBUG_KERNEL
405 depends on KPROBES 406 depends on KPROBES
406 default n 407 default n
407 help 408 help
@@ -413,3 +414,36 @@ config LKDTM
413 414
414 Documentation on how to use the module can be found in 415 Documentation on how to use the module can be found in
415 drivers/misc/lkdtm.c 416 drivers/misc/lkdtm.c
417
418config FAULT_INJECTION
419 bool "Fault-injection framework"
420 depends on DEBUG_KERNEL
421 depends on STACKTRACE
422 select FRAME_POINTER
423 help
424 Provide fault-injection framework.
425 For more details, see Documentation/fault-injection/.
426
427config FAILSLAB
428 bool "Fault-injection capability for kmalloc"
429 depends on FAULT_INJECTION
430 help
431 Provide fault-injection capability for kmalloc.
432
433config FAIL_PAGE_ALLOC
434 bool "Fault-injection capabilitiy for alloc_pages()"
435 depends on FAULT_INJECTION
436 help
437 Provide fault-injection capability for alloc_pages().
438
439config FAIL_MAKE_REQUEST
440 bool "Fault-injection capabilitiy for disk IO"
441 depends on FAULT_INJECTION
442 help
443 Provide fault-injection capability for disk IO.
444
445config FAULT_INJECTION_DEBUG_FS
446 bool "Debugfs entries for fault-injection capabilities"
447 depends on FAULT_INJECTION && SYSFS && DEBUG_FS
448 help
449 Enable configuration of fault-injection capabilities via debugfs.
diff --git a/lib/Makefile b/lib/Makefile
index fea8f9035f07..2d6106af53cd 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -35,6 +35,7 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
35 lib-y += dec_and_lock.o 35 lib-y += dec_and_lock.o
36endif 36endif
37 37
38obj-$(CONFIG_BITREVERSE) += bitrev.o
38obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o 39obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
39obj-$(CONFIG_CRC16) += crc16.o 40obj-$(CONFIG_CRC16) += crc16.o
40obj-$(CONFIG_CRC32) += crc32.o 41obj-$(CONFIG_CRC32) += crc32.o
@@ -54,6 +55,9 @@ obj-$(CONFIG_SMP) += percpu_counter.o
54obj-$(CONFIG_AUDIT_GENERIC) += audit.o 55obj-$(CONFIG_AUDIT_GENERIC) += audit.o
55 56
56obj-$(CONFIG_SWIOTLB) += swiotlb.o 57obj-$(CONFIG_SWIOTLB) += swiotlb.o
58obj-$(CONFIG_FAULT_INJECTION) += fault-inject.o
59
60lib-$(CONFIG_GENERIC_BUG) += bug.o
57 61
58hostprogs-y := gen_crc32table 62hostprogs-y := gen_crc32table
59clean-files := crc32table.h 63clean-files := crc32table.h
diff --git a/lib/bitrev.c b/lib/bitrev.c
new file mode 100644
index 000000000000..989aff73f881
--- /dev/null
+++ b/lib/bitrev.c
@@ -0,0 +1,58 @@
1#include <linux/types.h>
2#include <linux/module.h>
3#include <linux/bitrev.h>
4
5MODULE_AUTHOR("Akinobu Mita <akinobu.mita@gmail.com>");
6MODULE_DESCRIPTION("Bit ordering reversal functions");
7MODULE_LICENSE("GPL");
8
9const u8 byte_rev_table[256] = {
10 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
11 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
12 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
13 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
14 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
15 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
16 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
17 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
18 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
19 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
20 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
21 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
22 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
23 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
24 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
25 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
26 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
27 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
28 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
29 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
30 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
31 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
32 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
33 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
34 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
35 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
36 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
37 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
38 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
39 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
40 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
41 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
42};
43EXPORT_SYMBOL_GPL(byte_rev_table);
44
45static __always_inline u16 bitrev16(u16 x)
46{
47 return (bitrev8(x & 0xff) << 8) | bitrev8(x >> 8);
48}
49
50/**
51 * bitrev32 - reverse the order of bits in a u32 value
52 * @x: value to be bit-reversed
53 */
54u32 bitrev32(u32 x)
55{
56 return (bitrev16(x & 0xffff) << 16) | bitrev16(x >> 16);
57}
58EXPORT_SYMBOL(bitrev32);
diff --git a/lib/bug.c b/lib/bug.c
new file mode 100644
index 000000000000..014b582c5c4b
--- /dev/null
+++ b/lib/bug.c
@@ -0,0 +1,163 @@
1/*
2 Generic support for BUG()
3
4 This respects the following config options:
5
6 CONFIG_BUG - emit BUG traps. Nothing happens without this.
7 CONFIG_GENERIC_BUG - enable this code.
8 CONFIG_DEBUG_BUGVERBOSE - emit full file+line information for each BUG
9
10 CONFIG_BUG and CONFIG_DEBUG_BUGVERBOSE are potentially user-settable
11 (though they're generally always on).
12
13 CONFIG_GENERIC_BUG is set by each architecture using this code.
14
15 To use this, your architecture must:
16
17 1. Set up the config options:
18 - Enable CONFIG_GENERIC_BUG if CONFIG_BUG
19
20 2. Implement BUG (and optionally BUG_ON, WARN, WARN_ON)
21 - Define HAVE_ARCH_BUG
22 - Implement BUG() to generate a faulting instruction
23 - NOTE: struct bug_entry does not have "file" or "line" entries
24 when CONFIG_DEBUG_BUGVERBOSE is not enabled, so you must generate
25 the values accordingly.
26
27 3. Implement the trap
28 - In the illegal instruction trap handler (typically), verify
29 that the fault was in kernel mode, and call report_bug()
30 - report_bug() will return whether it was a false alarm, a warning,
31 or an actual bug.
32 - You must implement the is_valid_bugaddr(bugaddr) callback which
33 returns true if the eip is a real kernel address, and it points
34 to the expected BUG trap instruction.
35
36 Jeremy Fitzhardinge <jeremy@goop.org> 2006
37 */
38#include <linux/list.h>
39#include <linux/module.h>
40#include <linux/bug.h>
41
42extern const struct bug_entry __start___bug_table[], __stop___bug_table[];
43
44#ifdef CONFIG_MODULES
45static LIST_HEAD(module_bug_list);
46
47static const struct bug_entry *module_find_bug(unsigned long bugaddr)
48{
49 struct module *mod;
50
51 list_for_each_entry(mod, &module_bug_list, bug_list) {
52 const struct bug_entry *bug = mod->bug_table;
53 unsigned i;
54
55 for (i = 0; i < mod->num_bugs; ++i, ++bug)
56 if (bugaddr == bug->bug_addr)
57 return bug;
58 }
59 return NULL;
60}
61
62int module_bug_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
63 struct module *mod)
64{
65 char *secstrings;
66 unsigned int i;
67
68 mod->bug_table = NULL;
69 mod->num_bugs = 0;
70
71 /* Find the __bug_table section, if present */
72 secstrings = (char *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
73 for (i = 1; i < hdr->e_shnum; i++) {
74 if (strcmp(secstrings+sechdrs[i].sh_name, "__bug_table"))
75 continue;
76 mod->bug_table = (void *) sechdrs[i].sh_addr;
77 mod->num_bugs = sechdrs[i].sh_size / sizeof(struct bug_entry);
78 break;
79 }
80
81 /*
82 * Strictly speaking this should have a spinlock to protect against
83 * traversals, but since we only traverse on BUG()s, a spinlock
84 * could potentially lead to deadlock and thus be counter-productive.
85 */
86 list_add(&mod->bug_list, &module_bug_list);
87
88 return 0;
89}
90
91void module_bug_cleanup(struct module *mod)
92{
93 list_del(&mod->bug_list);
94}
95
96#else
97
98static inline const struct bug_entry *module_find_bug(unsigned long bugaddr)
99{
100 return NULL;
101}
102#endif
103
104const struct bug_entry *find_bug(unsigned long bugaddr)
105{
106 const struct bug_entry *bug;
107
108 for (bug = __start___bug_table; bug < __stop___bug_table; ++bug)
109 if (bugaddr == bug->bug_addr)
110 return bug;
111
112 return module_find_bug(bugaddr);
113}
114
115enum bug_trap_type report_bug(unsigned long bugaddr)
116{
117 const struct bug_entry *bug;
118 const char *file;
119 unsigned line, warning;
120
121 if (!is_valid_bugaddr(bugaddr))
122 return BUG_TRAP_TYPE_NONE;
123
124 bug = find_bug(bugaddr);
125
126 printk(KERN_EMERG "------------[ cut here ]------------\n");
127
128 file = NULL;
129 line = 0;
130 warning = 0;
131
132 if (bug) {
133#ifdef CONFIG_DEBUG_BUGVERBOSE
134 file = bug->file;
135 line = bug->line;
136#endif
137 warning = (bug->flags & BUGFLAG_WARNING) != 0;
138 }
139
140 if (warning) {
141 /* this is a WARN_ON rather than BUG/BUG_ON */
142 if (file)
143 printk(KERN_ERR "Badness at %s:%u\n",
144 file, line);
145 else
146 printk(KERN_ERR "Badness at %p "
147 "[verbose debug info unavailable]\n",
148 (void *)bugaddr);
149
150 dump_stack();
151 return BUG_TRAP_TYPE_WARN;
152 }
153
154 if (file)
155 printk(KERN_CRIT "kernel BUG at %s:%u!\n",
156 file, line);
157 else
158 printk(KERN_CRIT "Kernel BUG at %p "
159 "[verbose debug info unavailable]\n",
160 (void *)bugaddr);
161
162 return BUG_TRAP_TYPE_BUG;
163}
diff --git a/lib/crc32.c b/lib/crc32.c
index 285fd9bc61be..bfc33314c720 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -235,23 +235,8 @@ u32 __attribute_pure__ crc32_be(u32 crc, unsigned char const *p, size_t len)
235} 235}
236#endif 236#endif
237 237
238/**
239 * bitreverse - reverse the order of bits in a u32 value
240 * @x: value to be bit-reversed
241 */
242u32 bitreverse(u32 x)
243{
244 x = (x >> 16) | (x << 16);
245 x = (x >> 8 & 0x00ff00ff) | (x << 8 & 0xff00ff00);
246 x = (x >> 4 & 0x0f0f0f0f) | (x << 4 & 0xf0f0f0f0);
247 x = (x >> 2 & 0x33333333) | (x << 2 & 0xcccccccc);
248 x = (x >> 1 & 0x55555555) | (x << 1 & 0xaaaaaaaa);
249 return x;
250}
251
252EXPORT_SYMBOL(crc32_le); 238EXPORT_SYMBOL(crc32_le);
253EXPORT_SYMBOL(crc32_be); 239EXPORT_SYMBOL(crc32_be);
254EXPORT_SYMBOL(bitreverse);
255 240
256/* 241/*
257 * A brief CRC tutorial. 242 * A brief CRC tutorial.
@@ -400,10 +385,7 @@ buf_dump(char const *prefix, unsigned char const *buf, size_t len)
400static void bytereverse(unsigned char *buf, size_t len) 385static void bytereverse(unsigned char *buf, size_t len)
401{ 386{
402 while (len--) { 387 while (len--) {
403 unsigned char x = *buf; 388 unsigned char x = bitrev8(*buf);
404 x = (x >> 4) | (x << 4);
405 x = (x >> 2 & 0x33) | (x << 2 & 0xcc);
406 x = (x >> 1 & 0x55) | (x << 1 & 0xaa);
407 *buf++ = x; 389 *buf++ = x;
408 } 390 }
409} 391}
@@ -460,11 +442,11 @@ static u32 test_step(u32 init, unsigned char *buf, size_t len)
460 /* Now swap it around for the other test */ 442 /* Now swap it around for the other test */
461 443
462 bytereverse(buf, len + 4); 444 bytereverse(buf, len + 4);
463 init = bitreverse(init); 445 init = bitrev32(init);
464 crc2 = bitreverse(crc1); 446 crc2 = bitrev32(crc1);
465 if (crc1 != bitreverse(crc2)) 447 if (crc1 != bitrev32(crc2))
466 printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n", 448 printf("\nBit reversal fail: 0x%08x -> 0x%08x -> 0x%08x\n",
467 crc1, crc2, bitreverse(crc2)); 449 crc1, crc2, bitrev32(crc2));
468 crc1 = crc32_le(init, buf, len); 450 crc1 = crc32_le(init, buf, len);
469 if (crc1 != crc2) 451 if (crc1 != crc2)
470 printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1, 452 printf("\nCRC endianness fail: 0x%08x != 0x%08x\n", crc1,
diff --git a/lib/fault-inject.c b/lib/fault-inject.c
new file mode 100644
index 000000000000..d143c0faf248
--- /dev/null
+++ b/lib/fault-inject.c
@@ -0,0 +1,336 @@
1#include <linux/kernel.h>
2#include <linux/init.h>
3#include <linux/random.h>
4#include <linux/stat.h>
5#include <linux/types.h>
6#include <linux/fs.h>
7#include <linux/module.h>
8#include <linux/interrupt.h>
9#include <linux/unwind.h>
10#include <linux/stacktrace.h>
11#include <linux/kallsyms.h>
12#include <linux/fault-inject.h>
13
14/*
15 * setup_fault_attr() is a helper function for various __setup handlers, so it
16 * returns 0 on error, because that is what __setup handlers do.
17 */
18int __init setup_fault_attr(struct fault_attr *attr, char *str)
19{
20 unsigned long probability;
21 unsigned long interval;
22 int times;
23 int space;
24
25 /* "<interval>,<probability>,<space>,<times>" */
26 if (sscanf(str, "%lu,%lu,%d,%d",
27 &interval, &probability, &space, &times) < 4) {
28 printk(KERN_WARNING
29 "FAULT_INJECTION: failed to parse arguments\n");
30 return 0;
31 }
32
33 attr->probability = probability;
34 attr->interval = interval;
35 atomic_set(&attr->times, times);
36 atomic_set(&attr->space, space);
37
38 return 1;
39}
40
41static void fail_dump(struct fault_attr *attr)
42{
43 if (attr->verbose > 0)
44 printk(KERN_NOTICE "FAULT_INJECTION: forcing a failure\n");
45 if (attr->verbose > 1)
46 dump_stack();
47}
48
49#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
50
51static bool fail_task(struct fault_attr *attr, struct task_struct *task)
52{
53 return !in_interrupt() && task->make_it_fail;
54}
55
56#define MAX_STACK_TRACE_DEPTH 32
57
58#ifdef CONFIG_STACK_UNWIND
59
60static asmlinkage int fail_stacktrace_callback(struct unwind_frame_info *info,
61 void *arg)
62{
63 int depth;
64 struct fault_attr *attr = arg;
65 bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX);
66
67 for (depth = 0; depth < attr->stacktrace_depth
68 && unwind(info) == 0 && UNW_PC(info); depth++) {
69 if (arch_unw_user_mode(info))
70 break;
71 if (attr->reject_start <= UNW_PC(info) &&
72 UNW_PC(info) < attr->reject_end)
73 return false;
74 if (attr->require_start <= UNW_PC(info) &&
75 UNW_PC(info) < attr->require_end)
76 found = true;
77 }
78 return found;
79}
80
81static bool fail_stacktrace(struct fault_attr *attr)
82{
83 struct unwind_frame_info info;
84
85 return unwind_init_running(&info, fail_stacktrace_callback, attr);
86}
87
88#elif defined(CONFIG_STACKTRACE)
89
90static bool fail_stacktrace(struct fault_attr *attr)
91{
92 struct stack_trace trace;
93 int depth = attr->stacktrace_depth;
94 unsigned long entries[MAX_STACK_TRACE_DEPTH];
95 int n;
96 bool found = (attr->require_start == 0 && attr->require_end == ULONG_MAX);
97
98 if (depth == 0)
99 return found;
100
101 trace.nr_entries = 0;
102 trace.entries = entries;
103 trace.max_entries = depth;
104 trace.skip = 1;
105 trace.all_contexts = 0;
106
107 save_stack_trace(&trace, NULL);
108 for (n = 0; n < trace.nr_entries; n++) {
109 if (attr->reject_start <= entries[n] &&
110 entries[n] < attr->reject_end)
111 return false;
112 if (attr->require_start <= entries[n] &&
113 entries[n] < attr->require_end)
114 found = true;
115 }
116 return found;
117}
118
119#else
120
121static inline bool fail_stacktrace(struct fault_attr *attr)
122{
123 static bool firsttime = true;
124
125 if (firsttime) {
126 printk(KERN_WARNING
127 "This architecture does not implement save_stack_trace()\n");
128 firsttime = false;
129 }
130 return false;
131}
132
133#endif
134
135/*
136 * This code is stolen from failmalloc-1.0
137 * http://www.nongnu.org/failmalloc/
138 */
139
140bool should_fail(struct fault_attr *attr, ssize_t size)
141{
142 if (attr->task_filter && !fail_task(attr, current))
143 return false;
144
145 if (atomic_read(&attr->times) == 0)
146 return false;
147
148 if (atomic_read(&attr->space) > size) {
149 atomic_sub(size, &attr->space);
150 return false;
151 }
152
153 if (attr->interval > 1) {
154 attr->count++;
155 if (attr->count % attr->interval)
156 return false;
157 }
158
159 if (attr->probability <= random32() % 100)
160 return false;
161
162 if (!fail_stacktrace(attr))
163 return false;
164
165 fail_dump(attr);
166
167 if (atomic_read(&attr->times) != -1)
168 atomic_dec_not_zero(&attr->times);
169
170 return true;
171}
172
173#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
174
175static void debugfs_ul_set(void *data, u64 val)
176{
177 *(unsigned long *)data = val;
178}
179
180static void debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
181{
182 *(unsigned long *)data =
183 val < MAX_STACK_TRACE_DEPTH ?
184 val : MAX_STACK_TRACE_DEPTH;
185}
186
187static u64 debugfs_ul_get(void *data)
188{
189 return *(unsigned long *)data;
190}
191
192DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
193
194static struct dentry *debugfs_create_ul(const char *name, mode_t mode,
195 struct dentry *parent, unsigned long *value)
196{
197 return debugfs_create_file(name, mode, parent, value, &fops_ul);
198}
199
200DEFINE_SIMPLE_ATTRIBUTE(fops_ul_MAX_STACK_TRACE_DEPTH, debugfs_ul_get,
201 debugfs_ul_set_MAX_STACK_TRACE_DEPTH, "%llu\n");
202
203static struct dentry *debugfs_create_ul_MAX_STACK_TRACE_DEPTH(
204 const char *name, mode_t mode,
205 struct dentry *parent, unsigned long *value)
206{
207 return debugfs_create_file(name, mode, parent, value,
208 &fops_ul_MAX_STACK_TRACE_DEPTH);
209}
210
211static void debugfs_atomic_t_set(void *data, u64 val)
212{
213 atomic_set((atomic_t *)data, val);
214}
215
216static u64 debugfs_atomic_t_get(void *data)
217{
218 return atomic_read((atomic_t *)data);
219}
220
221DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
222 debugfs_atomic_t_set, "%lld\n");
223
224static struct dentry *debugfs_create_atomic_t(const char *name, mode_t mode,
225 struct dentry *parent, atomic_t *value)
226{
227 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
228}
229
230void cleanup_fault_attr_dentries(struct fault_attr *attr)
231{
232 debugfs_remove(attr->dentries.probability_file);
233 attr->dentries.probability_file = NULL;
234
235 debugfs_remove(attr->dentries.interval_file);
236 attr->dentries.interval_file = NULL;
237
238 debugfs_remove(attr->dentries.times_file);
239 attr->dentries.times_file = NULL;
240
241 debugfs_remove(attr->dentries.space_file);
242 attr->dentries.space_file = NULL;
243
244 debugfs_remove(attr->dentries.verbose_file);
245 attr->dentries.verbose_file = NULL;
246
247 debugfs_remove(attr->dentries.task_filter_file);
248 attr->dentries.task_filter_file = NULL;
249
250 debugfs_remove(attr->dentries.stacktrace_depth_file);
251 attr->dentries.stacktrace_depth_file = NULL;
252
253 debugfs_remove(attr->dentries.require_start_file);
254 attr->dentries.require_start_file = NULL;
255
256 debugfs_remove(attr->dentries.require_end_file);
257 attr->dentries.require_end_file = NULL;
258
259 debugfs_remove(attr->dentries.reject_start_file);
260 attr->dentries.reject_start_file = NULL;
261
262 debugfs_remove(attr->dentries.reject_end_file);
263 attr->dentries.reject_end_file = NULL;
264
265 if (attr->dentries.dir)
266 WARN_ON(!simple_empty(attr->dentries.dir));
267
268 debugfs_remove(attr->dentries.dir);
269 attr->dentries.dir = NULL;
270}
271
272int init_fault_attr_dentries(struct fault_attr *attr, const char *name)
273{
274 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
275 struct dentry *dir;
276
277 memset(&attr->dentries, 0, sizeof(attr->dentries));
278
279 dir = debugfs_create_dir(name, NULL);
280 if (!dir)
281 goto fail;
282 attr->dentries.dir = dir;
283
284 attr->dentries.probability_file =
285 debugfs_create_ul("probability", mode, dir, &attr->probability);
286
287 attr->dentries.interval_file =
288 debugfs_create_ul("interval", mode, dir, &attr->interval);
289
290 attr->dentries.times_file =
291 debugfs_create_atomic_t("times", mode, dir, &attr->times);
292
293 attr->dentries.space_file =
294 debugfs_create_atomic_t("space", mode, dir, &attr->space);
295
296 attr->dentries.verbose_file =
297 debugfs_create_ul("verbose", mode, dir, &attr->verbose);
298
299 attr->dentries.task_filter_file = debugfs_create_bool("task-filter",
300 mode, dir, &attr->task_filter);
301
302 attr->dentries.stacktrace_depth_file =
303 debugfs_create_ul_MAX_STACK_TRACE_DEPTH(
304 "stacktrace-depth", mode, dir, &attr->stacktrace_depth);
305
306 attr->dentries.require_start_file =
307 debugfs_create_ul("require-start", mode, dir, &attr->require_start);
308
309 attr->dentries.require_end_file =
310 debugfs_create_ul("require-end", mode, dir, &attr->require_end);
311
312 attr->dentries.reject_start_file =
313 debugfs_create_ul("reject-start", mode, dir, &attr->reject_start);
314
315 attr->dentries.reject_end_file =
316 debugfs_create_ul("reject-end", mode, dir, &attr->reject_end);
317
318
319 if (!attr->dentries.probability_file || !attr->dentries.interval_file
320 || !attr->dentries.times_file || !attr->dentries.space_file
321 || !attr->dentries.verbose_file || !attr->dentries.task_filter_file
322 || !attr->dentries.stacktrace_depth_file
323 || !attr->dentries.require_start_file
324 || !attr->dentries.require_end_file
325 || !attr->dentries.reject_start_file
326 || !attr->dentries.reject_end_file
327 )
328 goto fail;
329
330 return 0;
331fail:
332 cleanup_fault_attr_dentries(attr);
333 return -ENOMEM;
334}
335
336#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
diff --git a/mm/fadvise.c b/mm/fadvise.c
index 168c78a121bb..0df4c899e979 100644
--- a/mm/fadvise.c
+++ b/mm/fadvise.c
@@ -38,7 +38,7 @@ asmlinkage long sys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice)
38 if (!file) 38 if (!file)
39 return -EBADF; 39 return -EBADF;
40 40
41 if (S_ISFIFO(file->f_dentry->d_inode->i_mode)) { 41 if (S_ISFIFO(file->f_path.dentry->d_inode->i_mode)) {
42 ret = -ESPIPE; 42 ret = -ESPIPE;
43 goto out; 43 goto out;
44 } 44 }
diff --git a/mm/filemap.c b/mm/filemap.c
index af7e2f5caea9..8332c77b1bd1 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1181,8 +1181,6 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
1181 if (pos < size) { 1181 if (pos < size) {
1182 retval = generic_file_direct_IO(READ, iocb, 1182 retval = generic_file_direct_IO(READ, iocb,
1183 iov, pos, nr_segs); 1183 iov, pos, nr_segs);
1184 if (retval > 0 && !is_sync_kiocb(iocb))
1185 retval = -EIOCBQUEUED;
1186 if (retval > 0) 1184 if (retval > 0)
1187 *ppos = pos + retval; 1185 *ppos = pos + retval;
1188 } 1186 }
@@ -2047,15 +2045,14 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
2047 * Sync the fs metadata but not the minor inode changes and 2045 * Sync the fs metadata but not the minor inode changes and
2048 * of course not the data as we did direct DMA for the IO. 2046 * of course not the data as we did direct DMA for the IO.
2049 * i_mutex is held, which protects generic_osync_inode() from 2047 * i_mutex is held, which protects generic_osync_inode() from
2050 * livelocking. 2048 * livelocking. AIO O_DIRECT ops attempt to sync metadata here.
2051 */ 2049 */
2052 if (written >= 0 && ((file->f_flags & O_SYNC) || IS_SYNC(inode))) { 2050 if ((written >= 0 || written == -EIOCBQUEUED) &&
2051 ((file->f_flags & O_SYNC) || IS_SYNC(inode))) {
2053 int err = generic_osync_inode(inode, mapping, OSYNC_METADATA); 2052 int err = generic_osync_inode(inode, mapping, OSYNC_METADATA);
2054 if (err < 0) 2053 if (err < 0)
2055 written = err; 2054 written = err;
2056 } 2055 }
2057 if (written == count && !is_sync_kiocb(iocb))
2058 written = -EIOCBQUEUED;
2059 return written; 2056 return written;
2060} 2057}
2061EXPORT_SYMBOL(generic_file_direct_write); 2058EXPORT_SYMBOL(generic_file_direct_write);
@@ -2269,7 +2266,7 @@ __generic_file_aio_write_nolock(struct kiocb *iocb, const struct iovec *iov,
2269 if (count == 0) 2266 if (count == 0)
2270 goto out; 2267 goto out;
2271 2268
2272 err = remove_suid(file->f_dentry); 2269 err = remove_suid(file->f_path.dentry);
2273 if (err) 2270 if (err)
2274 goto out; 2271 goto out;
2275 2272
diff --git a/mm/filemap_xip.c b/mm/filemap_xip.c
index b4fd0d7c9bfb..8d667617f558 100644
--- a/mm/filemap_xip.c
+++ b/mm/filemap_xip.c
@@ -379,7 +379,7 @@ xip_file_write(struct file *filp, const char __user *buf, size_t len,
379 if (count == 0) 379 if (count == 0)
380 goto out_backing; 380 goto out_backing;
381 381
382 ret = remove_suid(filp->f_dentry); 382 ret = remove_suid(filp->f_path.dentry);
383 if (ret) 383 if (ret)
384 goto out_backing; 384 goto out_backing;
385 385
diff --git a/mm/memory.c b/mm/memory.c
index 4198df0dff1c..bf6100236e62 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1110,23 +1110,29 @@ static int zeromap_pte_range(struct mm_struct *mm, pmd_t *pmd,
1110{ 1110{
1111 pte_t *pte; 1111 pte_t *pte;
1112 spinlock_t *ptl; 1112 spinlock_t *ptl;
1113 int err = 0;
1113 1114
1114 pte = pte_alloc_map_lock(mm, pmd, addr, &ptl); 1115 pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
1115 if (!pte) 1116 if (!pte)
1116 return -ENOMEM; 1117 return -EAGAIN;
1117 arch_enter_lazy_mmu_mode(); 1118 arch_enter_lazy_mmu_mode();
1118 do { 1119 do {
1119 struct page *page = ZERO_PAGE(addr); 1120 struct page *page = ZERO_PAGE(addr);
1120 pte_t zero_pte = pte_wrprotect(mk_pte(page, prot)); 1121 pte_t zero_pte = pte_wrprotect(mk_pte(page, prot));
1122
1123 if (unlikely(!pte_none(*pte))) {
1124 err = -EEXIST;
1125 pte++;
1126 break;
1127 }
1121 page_cache_get(page); 1128 page_cache_get(page);
1122 page_add_file_rmap(page); 1129 page_add_file_rmap(page);
1123 inc_mm_counter(mm, file_rss); 1130 inc_mm_counter(mm, file_rss);
1124 BUG_ON(!pte_none(*pte));
1125 set_pte_at(mm, addr, pte, zero_pte); 1131 set_pte_at(mm, addr, pte, zero_pte);
1126 } while (pte++, addr += PAGE_SIZE, addr != end); 1132 } while (pte++, addr += PAGE_SIZE, addr != end);
1127 arch_leave_lazy_mmu_mode(); 1133 arch_leave_lazy_mmu_mode();
1128 pte_unmap_unlock(pte - 1, ptl); 1134 pte_unmap_unlock(pte - 1, ptl);
1129 return 0; 1135 return err;
1130} 1136}
1131 1137
1132static inline int zeromap_pmd_range(struct mm_struct *mm, pud_t *pud, 1138static inline int zeromap_pmd_range(struct mm_struct *mm, pud_t *pud,
@@ -1134,16 +1140,18 @@ static inline int zeromap_pmd_range(struct mm_struct *mm, pud_t *pud,
1134{ 1140{
1135 pmd_t *pmd; 1141 pmd_t *pmd;
1136 unsigned long next; 1142 unsigned long next;
1143 int err;
1137 1144
1138 pmd = pmd_alloc(mm, pud, addr); 1145 pmd = pmd_alloc(mm, pud, addr);
1139 if (!pmd) 1146 if (!pmd)
1140 return -ENOMEM; 1147 return -EAGAIN;
1141 do { 1148 do {
1142 next = pmd_addr_end(addr, end); 1149 next = pmd_addr_end(addr, end);
1143 if (zeromap_pte_range(mm, pmd, addr, next, prot)) 1150 err = zeromap_pte_range(mm, pmd, addr, next, prot);
1144 return -ENOMEM; 1151 if (err)
1152 break;
1145 } while (pmd++, addr = next, addr != end); 1153 } while (pmd++, addr = next, addr != end);
1146 return 0; 1154 return err;
1147} 1155}
1148 1156
1149static inline int zeromap_pud_range(struct mm_struct *mm, pgd_t *pgd, 1157static inline int zeromap_pud_range(struct mm_struct *mm, pgd_t *pgd,
@@ -1151,16 +1159,18 @@ static inline int zeromap_pud_range(struct mm_struct *mm, pgd_t *pgd,
1151{ 1159{
1152 pud_t *pud; 1160 pud_t *pud;
1153 unsigned long next; 1161 unsigned long next;
1162 int err;
1154 1163
1155 pud = pud_alloc(mm, pgd, addr); 1164 pud = pud_alloc(mm, pgd, addr);
1156 if (!pud) 1165 if (!pud)
1157 return -ENOMEM; 1166 return -EAGAIN;
1158 do { 1167 do {
1159 next = pud_addr_end(addr, end); 1168 next = pud_addr_end(addr, end);
1160 if (zeromap_pmd_range(mm, pud, addr, next, prot)) 1169 err = zeromap_pmd_range(mm, pud, addr, next, prot);
1161 return -ENOMEM; 1170 if (err)
1171 break;
1162 } while (pud++, addr = next, addr != end); 1172 } while (pud++, addr = next, addr != end);
1163 return 0; 1173 return err;
1164} 1174}
1165 1175
1166int zeromap_page_range(struct vm_area_struct *vma, 1176int zeromap_page_range(struct vm_area_struct *vma,
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index b917d6fdc1bb..da9463946556 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1857,7 +1857,7 @@ int show_numa_map(struct seq_file *m, void *v)
1857 1857
1858 if (file) { 1858 if (file) {
1859 seq_printf(m, " file="); 1859 seq_printf(m, " file=");
1860 seq_path(m, file->f_vfsmnt, file->f_dentry, "\n\t= "); 1860 seq_path(m, file->f_path.mnt, file->f_path.dentry, "\n\t= ");
1861 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) { 1861 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
1862 seq_printf(m, " heap"); 1862 seq_printf(m, " heap");
1863 } else if (vma->vm_start <= mm->start_stack && 1863 } else if (vma->vm_start <= mm->start_stack &&
diff --git a/mm/mmap.c b/mm/mmap.c
index 7be110e98d4c..9717337293c3 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -188,7 +188,7 @@ static void __remove_shared_vm_struct(struct vm_area_struct *vma,
188 struct file *file, struct address_space *mapping) 188 struct file *file, struct address_space *mapping)
189{ 189{
190 if (vma->vm_flags & VM_DENYWRITE) 190 if (vma->vm_flags & VM_DENYWRITE)
191 atomic_inc(&file->f_dentry->d_inode->i_writecount); 191 atomic_inc(&file->f_path.dentry->d_inode->i_writecount);
192 if (vma->vm_flags & VM_SHARED) 192 if (vma->vm_flags & VM_SHARED)
193 mapping->i_mmap_writable--; 193 mapping->i_mmap_writable--;
194 194
@@ -399,7 +399,7 @@ static inline void __vma_link_file(struct vm_area_struct *vma)
399 struct address_space *mapping = file->f_mapping; 399 struct address_space *mapping = file->f_mapping;
400 400
401 if (vma->vm_flags & VM_DENYWRITE) 401 if (vma->vm_flags & VM_DENYWRITE)
402 atomic_dec(&file->f_dentry->d_inode->i_writecount); 402 atomic_dec(&file->f_path.dentry->d_inode->i_writecount);
403 if (vma->vm_flags & VM_SHARED) 403 if (vma->vm_flags & VM_SHARED)
404 mapping->i_mmap_writable++; 404 mapping->i_mmap_writable++;
405 405
@@ -907,7 +907,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
907 * mounted, in which case we dont add PROT_EXEC.) 907 * mounted, in which case we dont add PROT_EXEC.)
908 */ 908 */
909 if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC)) 909 if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
910 if (!(file && (file->f_vfsmnt->mnt_flags & MNT_NOEXEC))) 910 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
911 prot |= PROT_EXEC; 911 prot |= PROT_EXEC;
912 912
913 if (!len) 913 if (!len)
@@ -960,7 +960,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
960 return -EAGAIN; 960 return -EAGAIN;
961 } 961 }
962 962
963 inode = file ? file->f_dentry->d_inode : NULL; 963 inode = file ? file->f_path.dentry->d_inode : NULL;
964 964
965 if (file) { 965 if (file) {
966 switch (flags & MAP_TYPE) { 966 switch (flags & MAP_TYPE) {
@@ -989,7 +989,7 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
989 case MAP_PRIVATE: 989 case MAP_PRIVATE:
990 if (!(file->f_mode & FMODE_READ)) 990 if (!(file->f_mode & FMODE_READ))
991 return -EACCES; 991 return -EACCES;
992 if (file->f_vfsmnt->mnt_flags & MNT_NOEXEC) { 992 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC) {
993 if (vm_flags & VM_EXEC) 993 if (vm_flags & VM_EXEC)
994 return -EPERM; 994 return -EPERM;
995 vm_flags &= ~VM_MAYEXEC; 995 vm_flags &= ~VM_MAYEXEC;
diff --git a/mm/nommu.c b/mm/nommu.c
index af874569d0f1..23fb033e596d 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -523,7 +523,7 @@ static int validate_mmap_request(struct file *file,
523 */ 523 */
524 mapping = file->f_mapping; 524 mapping = file->f_mapping;
525 if (!mapping) 525 if (!mapping)
526 mapping = file->f_dentry->d_inode->i_mapping; 526 mapping = file->f_path.dentry->d_inode->i_mapping;
527 527
528 capabilities = 0; 528 capabilities = 0;
529 if (mapping && mapping->backing_dev_info) 529 if (mapping && mapping->backing_dev_info)
@@ -532,7 +532,7 @@ static int validate_mmap_request(struct file *file,
532 if (!capabilities) { 532 if (!capabilities) {
533 /* no explicit capabilities set, so assume some 533 /* no explicit capabilities set, so assume some
534 * defaults */ 534 * defaults */
535 switch (file->f_dentry->d_inode->i_mode & S_IFMT) { 535 switch (file->f_path.dentry->d_inode->i_mode & S_IFMT) {
536 case S_IFREG: 536 case S_IFREG:
537 case S_IFBLK: 537 case S_IFBLK:
538 capabilities = BDI_CAP_MAP_COPY; 538 capabilities = BDI_CAP_MAP_COPY;
@@ -563,11 +563,11 @@ static int validate_mmap_request(struct file *file,
563 !(file->f_mode & FMODE_WRITE)) 563 !(file->f_mode & FMODE_WRITE))
564 return -EACCES; 564 return -EACCES;
565 565
566 if (IS_APPEND(file->f_dentry->d_inode) && 566 if (IS_APPEND(file->f_path.dentry->d_inode) &&
567 (file->f_mode & FMODE_WRITE)) 567 (file->f_mode & FMODE_WRITE))
568 return -EACCES; 568 return -EACCES;
569 569
570 if (locks_verify_locked(file->f_dentry->d_inode)) 570 if (locks_verify_locked(file->f_path.dentry->d_inode))
571 return -EAGAIN; 571 return -EAGAIN;
572 572
573 if (!(capabilities & BDI_CAP_MAP_DIRECT)) 573 if (!(capabilities & BDI_CAP_MAP_DIRECT))
@@ -598,7 +598,7 @@ static int validate_mmap_request(struct file *file,
598 598
599 /* handle executable mappings and implied executable 599 /* handle executable mappings and implied executable
600 * mappings */ 600 * mappings */
601 if (file->f_vfsmnt->mnt_flags & MNT_NOEXEC) { 601 if (file->f_path.mnt->mnt_flags & MNT_NOEXEC) {
602 if (prot & PROT_EXEC) 602 if (prot & PROT_EXEC)
603 return -EPERM; 603 return -EPERM;
604 } 604 }
@@ -833,7 +833,7 @@ unsigned long do_mmap_pgoff(struct file *file,
833 continue; 833 continue;
834 834
835 /* search for overlapping mappings on the same file */ 835 /* search for overlapping mappings on the same file */
836 if (vma->vm_file->f_dentry->d_inode != file->f_dentry->d_inode) 836 if (vma->vm_file->f_path.dentry->d_inode != file->f_path.dentry->d_inode)
837 continue; 837 continue;
838 838
839 if (vma->vm_pgoff >= pgoff + pglen) 839 if (vma->vm_pgoff >= pgoff + pglen)
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 8d9b19f239c3..237107c1b084 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -21,6 +21,7 @@
21#include <linux/writeback.h> 21#include <linux/writeback.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/backing-dev.h> 23#include <linux/backing-dev.h>
24#include <linux/task_io_accounting_ops.h>
24#include <linux/blkdev.h> 25#include <linux/blkdev.h>
25#include <linux/mpage.h> 26#include <linux/mpage.h>
26#include <linux/rmap.h> 27#include <linux/rmap.h>
@@ -761,23 +762,24 @@ int __set_page_dirty_nobuffers(struct page *page)
761 struct address_space *mapping = page_mapping(page); 762 struct address_space *mapping = page_mapping(page);
762 struct address_space *mapping2; 763 struct address_space *mapping2;
763 764
764 if (mapping) { 765 if (!mapping)
765 write_lock_irq(&mapping->tree_lock); 766 return 1;
766 mapping2 = page_mapping(page); 767
767 if (mapping2) { /* Race with truncate? */ 768 write_lock_irq(&mapping->tree_lock);
768 BUG_ON(mapping2 != mapping); 769 mapping2 = page_mapping(page);
769 if (mapping_cap_account_dirty(mapping)) 770 if (mapping2) { /* Race with truncate? */
770 __inc_zone_page_state(page, 771 BUG_ON(mapping2 != mapping);
771 NR_FILE_DIRTY); 772 if (mapping_cap_account_dirty(mapping)) {
772 radix_tree_tag_set(&mapping->page_tree, 773 __inc_zone_page_state(page, NR_FILE_DIRTY);
773 page_index(page), PAGECACHE_TAG_DIRTY); 774 task_io_account_write(PAGE_CACHE_SIZE);
774 }
775 write_unlock_irq(&mapping->tree_lock);
776 if (mapping->host) {
777 /* !PageAnon && !swapper_space */
778 __mark_inode_dirty(mapping->host,
779 I_DIRTY_PAGES);
780 } 775 }
776 radix_tree_tag_set(&mapping->page_tree,
777 page_index(page), PAGECACHE_TAG_DIRTY);
778 }
779 write_unlock_irq(&mapping->tree_lock);
780 if (mapping->host) {
781 /* !PageAnon && !swapper_space */
782 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
781 } 783 }
782 return 1; 784 return 1;
783 } 785 }
@@ -851,27 +853,26 @@ int test_clear_page_dirty(struct page *page)
851 struct address_space *mapping = page_mapping(page); 853 struct address_space *mapping = page_mapping(page);
852 unsigned long flags; 854 unsigned long flags;
853 855
854 if (mapping) { 856 if (!mapping)
855 write_lock_irqsave(&mapping->tree_lock, flags); 857 return TestClearPageDirty(page);
856 if (TestClearPageDirty(page)) { 858
857 radix_tree_tag_clear(&mapping->page_tree, 859 write_lock_irqsave(&mapping->tree_lock, flags);
858 page_index(page), 860 if (TestClearPageDirty(page)) {
859 PAGECACHE_TAG_DIRTY); 861 radix_tree_tag_clear(&mapping->page_tree,
860 write_unlock_irqrestore(&mapping->tree_lock, flags); 862 page_index(page), PAGECACHE_TAG_DIRTY);
861 /*
862 * We can continue to use `mapping' here because the
863 * page is locked, which pins the address_space
864 */
865 if (mapping_cap_account_dirty(mapping)) {
866 page_mkclean(page);
867 dec_zone_page_state(page, NR_FILE_DIRTY);
868 }
869 return 1;
870 }
871 write_unlock_irqrestore(&mapping->tree_lock, flags); 863 write_unlock_irqrestore(&mapping->tree_lock, flags);
872 return 0; 864 /*
865 * We can continue to use `mapping' here because the
866 * page is locked, which pins the address_space
867 */
868 if (mapping_cap_account_dirty(mapping)) {
869 page_mkclean(page);
870 dec_zone_page_state(page, NR_FILE_DIRTY);
871 }
872 return 1;
873 } 873 }
874 return TestClearPageDirty(page); 874 write_unlock_irqrestore(&mapping->tree_lock, flags);
875 return 0;
875} 876}
876EXPORT_SYMBOL(test_clear_page_dirty); 877EXPORT_SYMBOL(test_clear_page_dirty);
877 878
@@ -893,17 +894,17 @@ int clear_page_dirty_for_io(struct page *page)
893{ 894{
894 struct address_space *mapping = page_mapping(page); 895 struct address_space *mapping = page_mapping(page);
895 896
896 if (mapping) { 897 if (!mapping)
897 if (TestClearPageDirty(page)) { 898 return TestClearPageDirty(page);
898 if (mapping_cap_account_dirty(mapping)) { 899
899 page_mkclean(page); 900 if (TestClearPageDirty(page)) {
900 dec_zone_page_state(page, NR_FILE_DIRTY); 901 if (mapping_cap_account_dirty(mapping)) {
901 } 902 page_mkclean(page);
902 return 1; 903 dec_zone_page_state(page, NR_FILE_DIRTY);
903 } 904 }
904 return 0; 905 return 1;
905 } 906 }
906 return TestClearPageDirty(page); 907 return 0;
907} 908}
908EXPORT_SYMBOL(clear_page_dirty_for_io); 909EXPORT_SYMBOL(clear_page_dirty_for_io);
909 910
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cace22b3ac25..e6b17b2989e0 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -40,6 +40,7 @@
40#include <linux/sort.h> 40#include <linux/sort.h>
41#include <linux/pfn.h> 41#include <linux/pfn.h>
42#include <linux/backing-dev.h> 42#include <linux/backing-dev.h>
43#include <linux/fault-inject.h>
43 44
44#include <asm/tlbflush.h> 45#include <asm/tlbflush.h>
45#include <asm/div64.h> 46#include <asm/div64.h>
@@ -892,6 +893,91 @@ failed:
892#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */ 893#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
893#define ALLOC_CPUSET 0x40 /* check for correct cpuset */ 894#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
894 895
896#ifdef CONFIG_FAIL_PAGE_ALLOC
897
898static struct fail_page_alloc_attr {
899 struct fault_attr attr;
900
901 u32 ignore_gfp_highmem;
902 u32 ignore_gfp_wait;
903
904#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
905
906 struct dentry *ignore_gfp_highmem_file;
907 struct dentry *ignore_gfp_wait_file;
908
909#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
910
911} fail_page_alloc = {
912 .attr = FAULT_ATTR_INITIALIZER,
913 .ignore_gfp_wait = 1,
914 .ignore_gfp_highmem = 1,
915};
916
917static int __init setup_fail_page_alloc(char *str)
918{
919 return setup_fault_attr(&fail_page_alloc.attr, str);
920}
921__setup("fail_page_alloc=", setup_fail_page_alloc);
922
923static int should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
924{
925 if (gfp_mask & __GFP_NOFAIL)
926 return 0;
927 if (fail_page_alloc.ignore_gfp_highmem && (gfp_mask & __GFP_HIGHMEM))
928 return 0;
929 if (fail_page_alloc.ignore_gfp_wait && (gfp_mask & __GFP_WAIT))
930 return 0;
931
932 return should_fail(&fail_page_alloc.attr, 1 << order);
933}
934
935#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
936
937static int __init fail_page_alloc_debugfs(void)
938{
939 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
940 struct dentry *dir;
941 int err;
942
943 err = init_fault_attr_dentries(&fail_page_alloc.attr,
944 "fail_page_alloc");
945 if (err)
946 return err;
947 dir = fail_page_alloc.attr.dentries.dir;
948
949 fail_page_alloc.ignore_gfp_wait_file =
950 debugfs_create_bool("ignore-gfp-wait", mode, dir,
951 &fail_page_alloc.ignore_gfp_wait);
952
953 fail_page_alloc.ignore_gfp_highmem_file =
954 debugfs_create_bool("ignore-gfp-highmem", mode, dir,
955 &fail_page_alloc.ignore_gfp_highmem);
956
957 if (!fail_page_alloc.ignore_gfp_wait_file ||
958 !fail_page_alloc.ignore_gfp_highmem_file) {
959 err = -ENOMEM;
960 debugfs_remove(fail_page_alloc.ignore_gfp_wait_file);
961 debugfs_remove(fail_page_alloc.ignore_gfp_highmem_file);
962 cleanup_fault_attr_dentries(&fail_page_alloc.attr);
963 }
964
965 return err;
966}
967
968late_initcall(fail_page_alloc_debugfs);
969
970#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
971
972#else /* CONFIG_FAIL_PAGE_ALLOC */
973
974static inline int should_fail_alloc_page(gfp_t gfp_mask, unsigned int order)
975{
976 return 0;
977}
978
979#endif /* CONFIG_FAIL_PAGE_ALLOC */
980
895/* 981/*
896 * Return 1 if free pages are above 'mark'. This takes into account the order 982 * Return 1 if free pages are above 'mark'. This takes into account the order
897 * of the allocation. 983 * of the allocation.
@@ -1136,6 +1222,9 @@ __alloc_pages(gfp_t gfp_mask, unsigned int order,
1136 1222
1137 might_sleep_if(wait); 1223 might_sleep_if(wait);
1138 1224
1225 if (should_fail_alloc_page(gfp_mask, order))
1226 return NULL;
1227
1139restart: 1228restart:
1140 z = zonelist->zones; /* the list of zones suitable for gfp_mask */ 1229 z = zonelist->zones; /* the list of zones suitable for gfp_mask */
1141 1230
@@ -3244,7 +3333,7 @@ void *__init alloc_large_system_hash(const char *tablename,
3244 if (numentries > max) 3333 if (numentries > max)
3245 numentries = max; 3334 numentries = max;
3246 3335
3247 log2qty = long_log2(numentries); 3336 log2qty = ilog2(numentries);
3248 3337
3249 do { 3338 do {
3250 size = bucketsize << log2qty; 3339 size = bucketsize << log2qty;
@@ -3266,7 +3355,7 @@ void *__init alloc_large_system_hash(const char *tablename,
3266 printk("%s hash table entries: %d (order: %d, %lu bytes)\n", 3355 printk("%s hash table entries: %d (order: %d, %lu bytes)\n",
3267 tablename, 3356 tablename,
3268 (1U << log2qty), 3357 (1U << log2qty),
3269 long_log2(size) - PAGE_SHIFT, 3358 ilog2(size) - PAGE_SHIFT,
3270 size); 3359 size);
3271 3360
3272 if (_hash_shift) 3361 if (_hash_shift)
diff --git a/mm/readahead.c b/mm/readahead.c
index a386f2b6b335..0f539e8e827a 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/blkdev.h> 14#include <linux/blkdev.h>
15#include <linux/backing-dev.h> 15#include <linux/backing-dev.h>
16#include <linux/task_io_accounting_ops.h>
16#include <linux/pagevec.h> 17#include <linux/pagevec.h>
17 18
18void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page) 19void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
@@ -151,6 +152,7 @@ int read_cache_pages(struct address_space *mapping, struct list_head *pages,
151 put_pages_list(pages); 152 put_pages_list(pages);
152 break; 153 break;
153 } 154 }
155 task_io_account_read(PAGE_CACHE_SIZE);
154 } 156 }
155 pagevec_lru_add(&lru_pvec); 157 pagevec_lru_add(&lru_pvec);
156 return ret; 158 return ret;
@@ -450,7 +452,7 @@ static int make_ahead_window(struct address_space *mapping, struct file *filp,
450 * 452 *
451 * Note that @filp is purely used for passing on to the ->readpage[s]() 453 * Note that @filp is purely used for passing on to the ->readpage[s]()
452 * handler: it may refer to a different file from @mapping (so we may not use 454 * handler: it may refer to a different file from @mapping (so we may not use
453 * @filp->f_mapping or @filp->f_dentry->d_inode here). 455 * @filp->f_mapping or @filp->f_path.dentry->d_inode here).
454 * Also, @ra may not be equal to &@filp->f_ra. 456 * Also, @ra may not be equal to &@filp->f_ra.
455 * 457 *
456 */ 458 */
diff --git a/mm/shmem.c b/mm/shmem.c
index c820b4f77b8d..4bb28d218eb5 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1225,7 +1225,7 @@ failed:
1225 1225
1226struct page *shmem_nopage(struct vm_area_struct *vma, unsigned long address, int *type) 1226struct page *shmem_nopage(struct vm_area_struct *vma, unsigned long address, int *type)
1227{ 1227{
1228 struct inode *inode = vma->vm_file->f_dentry->d_inode; 1228 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
1229 struct page *page = NULL; 1229 struct page *page = NULL;
1230 unsigned long idx; 1230 unsigned long idx;
1231 int error; 1231 int error;
@@ -1248,7 +1248,7 @@ static int shmem_populate(struct vm_area_struct *vma,
1248 unsigned long addr, unsigned long len, 1248 unsigned long addr, unsigned long len,
1249 pgprot_t prot, unsigned long pgoff, int nonblock) 1249 pgprot_t prot, unsigned long pgoff, int nonblock)
1250{ 1250{
1251 struct inode *inode = vma->vm_file->f_dentry->d_inode; 1251 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
1252 struct mm_struct *mm = vma->vm_mm; 1252 struct mm_struct *mm = vma->vm_mm;
1253 enum sgp_type sgp = nonblock? SGP_QUICK: SGP_CACHE; 1253 enum sgp_type sgp = nonblock? SGP_QUICK: SGP_CACHE;
1254 unsigned long size; 1254 unsigned long size;
@@ -1293,14 +1293,14 @@ static int shmem_populate(struct vm_area_struct *vma,
1293#ifdef CONFIG_NUMA 1293#ifdef CONFIG_NUMA
1294int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *new) 1294int shmem_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
1295{ 1295{
1296 struct inode *i = vma->vm_file->f_dentry->d_inode; 1296 struct inode *i = vma->vm_file->f_path.dentry->d_inode;
1297 return mpol_set_shared_policy(&SHMEM_I(i)->policy, vma, new); 1297 return mpol_set_shared_policy(&SHMEM_I(i)->policy, vma, new);
1298} 1298}
1299 1299
1300struct mempolicy * 1300struct mempolicy *
1301shmem_get_policy(struct vm_area_struct *vma, unsigned long addr) 1301shmem_get_policy(struct vm_area_struct *vma, unsigned long addr)
1302{ 1302{
1303 struct inode *i = vma->vm_file->f_dentry->d_inode; 1303 struct inode *i = vma->vm_file->f_path.dentry->d_inode;
1304 unsigned long idx; 1304 unsigned long idx;
1305 1305
1306 idx = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff; 1306 idx = ((addr - vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
@@ -1310,7 +1310,7 @@ shmem_get_policy(struct vm_area_struct *vma, unsigned long addr)
1310 1310
1311int shmem_lock(struct file *file, int lock, struct user_struct *user) 1311int shmem_lock(struct file *file, int lock, struct user_struct *user)
1312{ 1312{
1313 struct inode *inode = file->f_dentry->d_inode; 1313 struct inode *inode = file->f_path.dentry->d_inode;
1314 struct shmem_inode_info *info = SHMEM_I(inode); 1314 struct shmem_inode_info *info = SHMEM_I(inode);
1315 int retval = -ENOMEM; 1315 int retval = -ENOMEM;
1316 1316
@@ -1422,7 +1422,7 @@ shmem_prepare_write(struct file *file, struct page *page, unsigned offset, unsig
1422static ssize_t 1422static ssize_t
1423shmem_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 1423shmem_file_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
1424{ 1424{
1425 struct inode *inode = file->f_dentry->d_inode; 1425 struct inode *inode = file->f_path.dentry->d_inode;
1426 loff_t pos; 1426 loff_t pos;
1427 unsigned long written; 1427 unsigned long written;
1428 ssize_t err; 1428 ssize_t err;
@@ -1442,7 +1442,7 @@ shmem_file_write(struct file *file, const char __user *buf, size_t count, loff_t
1442 if (err || !count) 1442 if (err || !count)
1443 goto out; 1443 goto out;
1444 1444
1445 err = remove_suid(file->f_dentry); 1445 err = remove_suid(file->f_path.dentry);
1446 if (err) 1446 if (err)
1447 goto out; 1447 goto out;
1448 1448
@@ -1524,7 +1524,7 @@ out:
1524 1524
1525static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor) 1525static void do_shmem_file_read(struct file *filp, loff_t *ppos, read_descriptor_t *desc, read_actor_t actor)
1526{ 1526{
1527 struct inode *inode = filp->f_dentry->d_inode; 1527 struct inode *inode = filp->f_path.dentry->d_inode;
1528 struct address_space *mapping = inode->i_mapping; 1528 struct address_space *mapping = inode->i_mapping;
1529 unsigned long index, offset; 1529 unsigned long index, offset;
1530 1530
@@ -2493,8 +2493,8 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2493 d_instantiate(dentry, inode); 2493 d_instantiate(dentry, inode);
2494 inode->i_size = size; 2494 inode->i_size = size;
2495 inode->i_nlink = 0; /* It is unlinked */ 2495 inode->i_nlink = 0; /* It is unlinked */
2496 file->f_vfsmnt = mntget(shm_mnt); 2496 file->f_path.mnt = mntget(shm_mnt);
2497 file->f_dentry = dentry; 2497 file->f_path.dentry = dentry;
2498 file->f_mapping = inode->i_mapping; 2498 file->f_mapping = inode->i_mapping;
2499 file->f_op = &shmem_file_operations; 2499 file->f_op = &shmem_file_operations;
2500 file->f_mode = FMODE_WRITE | FMODE_READ; 2500 file->f_mode = FMODE_WRITE | FMODE_READ;
diff --git a/mm/slab.c b/mm/slab.c
index 068cb4503c15..2c655532f5ef 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -107,6 +107,7 @@
107#include <linux/nodemask.h> 107#include <linux/nodemask.h>
108#include <linux/mempolicy.h> 108#include <linux/mempolicy.h>
109#include <linux/mutex.h> 109#include <linux/mutex.h>
110#include <linux/fault-inject.h>
110#include <linux/rtmutex.h> 111#include <linux/rtmutex.h>
111 112
112#include <asm/cacheflush.h> 113#include <asm/cacheflush.h>
@@ -945,7 +946,8 @@ static void __devinit start_cpu_timer(int cpu)
945 if (keventd_up() && reap_work->work.func == NULL) { 946 if (keventd_up() && reap_work->work.func == NULL) {
946 init_reap_node(cpu); 947 init_reap_node(cpu);
947 INIT_DELAYED_WORK(reap_work, cache_reap); 948 INIT_DELAYED_WORK(reap_work, cache_reap);
948 schedule_delayed_work_on(cpu, reap_work, HZ + 3 * cpu); 949 schedule_delayed_work_on(cpu, reap_work,
950 __round_jiffies_relative(HZ, cpu));
949 } 951 }
950} 952}
951 953
@@ -3088,12 +3090,89 @@ static void *cache_alloc_debugcheck_after(struct kmem_cache *cachep,
3088#define cache_alloc_debugcheck_after(a,b,objp,d) (objp) 3090#define cache_alloc_debugcheck_after(a,b,objp,d) (objp)
3089#endif 3091#endif
3090 3092
3093#ifdef CONFIG_FAILSLAB
3094
3095static struct failslab_attr {
3096
3097 struct fault_attr attr;
3098
3099 u32 ignore_gfp_wait;
3100#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
3101 struct dentry *ignore_gfp_wait_file;
3102#endif
3103
3104} failslab = {
3105 .attr = FAULT_ATTR_INITIALIZER,
3106 .ignore_gfp_wait = 1,
3107};
3108
3109static int __init setup_failslab(char *str)
3110{
3111 return setup_fault_attr(&failslab.attr, str);
3112}
3113__setup("failslab=", setup_failslab);
3114
3115static int should_failslab(struct kmem_cache *cachep, gfp_t flags)
3116{
3117 if (cachep == &cache_cache)
3118 return 0;
3119 if (flags & __GFP_NOFAIL)
3120 return 0;
3121 if (failslab.ignore_gfp_wait && (flags & __GFP_WAIT))
3122 return 0;
3123
3124 return should_fail(&failslab.attr, obj_size(cachep));
3125}
3126
3127#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
3128
3129static int __init failslab_debugfs(void)
3130{
3131 mode_t mode = S_IFREG | S_IRUSR | S_IWUSR;
3132 struct dentry *dir;
3133 int err;
3134
3135 err = init_fault_attr_dentries(&failslab.attr, "failslab");
3136 if (err)
3137 return err;
3138 dir = failslab.attr.dentries.dir;
3139
3140 failslab.ignore_gfp_wait_file =
3141 debugfs_create_bool("ignore-gfp-wait", mode, dir,
3142 &failslab.ignore_gfp_wait);
3143
3144 if (!failslab.ignore_gfp_wait_file) {
3145 err = -ENOMEM;
3146 debugfs_remove(failslab.ignore_gfp_wait_file);
3147 cleanup_fault_attr_dentries(&failslab.attr);
3148 }
3149
3150 return err;
3151}
3152
3153late_initcall(failslab_debugfs);
3154
3155#endif /* CONFIG_FAULT_INJECTION_DEBUG_FS */
3156
3157#else /* CONFIG_FAILSLAB */
3158
3159static inline int should_failslab(struct kmem_cache *cachep, gfp_t flags)
3160{
3161 return 0;
3162}
3163
3164#endif /* CONFIG_FAILSLAB */
3165
3091static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags) 3166static inline void *____cache_alloc(struct kmem_cache *cachep, gfp_t flags)
3092{ 3167{
3093 void *objp; 3168 void *objp;
3094 struct array_cache *ac; 3169 struct array_cache *ac;
3095 3170
3096 check_irq_off(); 3171 check_irq_off();
3172
3173 if (should_failslab(cachep, flags))
3174 return NULL;
3175
3097 ac = cpu_cache_get(cachep); 3176 ac = cpu_cache_get(cachep);
3098 if (likely(ac->avail)) { 3177 if (likely(ac->avail)) {
3099 STATS_INC_ALLOCHIT(cachep); 3178 STATS_INC_ALLOCHIT(cachep);
@@ -3182,7 +3261,7 @@ retry:
3182 for (z = zonelist->zones; *z && !obj; z++) { 3261 for (z = zonelist->zones; *z && !obj; z++) {
3183 nid = zone_to_nid(*z); 3262 nid = zone_to_nid(*z);
3184 3263
3185 if (cpuset_zone_allowed(*z, flags) && 3264 if (cpuset_zone_allowed(*z, flags | __GFP_HARDWALL) &&
3186 cache->nodelists[nid] && 3265 cache->nodelists[nid] &&
3187 cache->nodelists[nid]->free_objects) 3266 cache->nodelists[nid]->free_objects)
3188 obj = ____cache_alloc_node(cache, 3267 obj = ____cache_alloc_node(cache,
@@ -3928,7 +4007,7 @@ static void cache_reap(struct work_struct *unused)
3928 if (!mutex_trylock(&cache_chain_mutex)) { 4007 if (!mutex_trylock(&cache_chain_mutex)) {
3929 /* Give up. Setup the next iteration. */ 4008 /* Give up. Setup the next iteration. */
3930 schedule_delayed_work(&__get_cpu_var(reap_work), 4009 schedule_delayed_work(&__get_cpu_var(reap_work),
3931 REAPTIMEOUT_CPUC); 4010 round_jiffies_relative(REAPTIMEOUT_CPUC));
3932 return; 4011 return;
3933 } 4012 }
3934 4013
@@ -3974,7 +4053,8 @@ next:
3974 next_reap_node(); 4053 next_reap_node();
3975 refresh_cpu_vm_stats(smp_processor_id()); 4054 refresh_cpu_vm_stats(smp_processor_id());
3976 /* Set up the next iteration */ 4055 /* Set up the next iteration */
3977 schedule_delayed_work(&__get_cpu_var(reap_work), REAPTIMEOUT_CPUC); 4056 schedule_delayed_work(&__get_cpu_var(reap_work),
4057 round_jiffies_relative(REAPTIMEOUT_CPUC));
3978} 4058}
3979 4059
3980#ifdef CONFIG_PROC_FS 4060#ifdef CONFIG_PROC_FS
diff --git a/mm/swapfile.c b/mm/swapfile.c
index c5431072f422..b9fc0e5de6d5 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -1357,10 +1357,10 @@ static int swap_show(struct seq_file *swap, void *v)
1357 } 1357 }
1358 1358
1359 file = ptr->swap_file; 1359 file = ptr->swap_file;
1360 len = seq_path(swap, file->f_vfsmnt, file->f_dentry, " \t\n\\"); 1360 len = seq_path(swap, file->f_path.mnt, file->f_path.dentry, " \t\n\\");
1361 seq_printf(swap, "%*s%s\t%u\t%u\t%d\n", 1361 seq_printf(swap, "%*s%s\t%u\t%u\t%d\n",
1362 len < 40 ? 40 - len : 1, " ", 1362 len < 40 ? 40 - len : 1, " ",
1363 S_ISBLK(file->f_dentry->d_inode->i_mode) ? 1363 S_ISBLK(file->f_path.dentry->d_inode->i_mode) ?
1364 "partition" : "file\t", 1364 "partition" : "file\t",
1365 ptr->pages << (PAGE_SHIFT - 10), 1365 ptr->pages << (PAGE_SHIFT - 10),
1366 ptr->inuse_pages << (PAGE_SHIFT - 10), 1366 ptr->inuse_pages << (PAGE_SHIFT - 10),
diff --git a/mm/tiny-shmem.c b/mm/tiny-shmem.c
index 5f2cbf0f153c..c7f6e1914bc4 100644
--- a/mm/tiny-shmem.c
+++ b/mm/tiny-shmem.c
@@ -79,8 +79,8 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
79 d_instantiate(dentry, inode); 79 d_instantiate(dentry, inode);
80 inode->i_nlink = 0; /* It is unlinked */ 80 inode->i_nlink = 0; /* It is unlinked */
81 81
82 file->f_vfsmnt = mntget(shm_mnt); 82 file->f_path.mnt = mntget(shm_mnt);
83 file->f_dentry = dentry; 83 file->f_path.dentry = dentry;
84 file->f_mapping = inode->i_mapping; 84 file->f_mapping = inode->i_mapping;
85 file->f_op = &ramfs_file_operations; 85 file->f_op = &ramfs_file_operations;
86 file->f_mode = FMODE_WRITE | FMODE_READ; 86 file->f_mode = FMODE_WRITE | FMODE_READ;
diff --git a/mm/truncate.c b/mm/truncate.c
index e07b1e682c38..9bfb8e853860 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/pagemap.h> 14#include <linux/pagemap.h>
15#include <linux/pagevec.h> 15#include <linux/pagevec.h>
16#include <linux/task_io_accounting_ops.h>
16#include <linux/buffer_head.h> /* grr. try_to_release_page, 17#include <linux/buffer_head.h> /* grr. try_to_release_page,
17 do_invalidatepage */ 18 do_invalidatepage */
18 19
@@ -69,7 +70,8 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
69 if (PagePrivate(page)) 70 if (PagePrivate(page))
70 do_invalidatepage(page, 0); 71 do_invalidatepage(page, 0);
71 72
72 clear_page_dirty(page); 73 if (test_clear_page_dirty(page))
74 task_io_account_cancelled_write(PAGE_CACHE_SIZE);
73 ClearPageUptodate(page); 75 ClearPageUptodate(page);
74 ClearPageMappedToDisk(page); 76 ClearPageMappedToDisk(page);
75 remove_from_page_cache(page); 77 remove_from_page_cache(page);
diff --git a/net/atm/proc.c b/net/atm/proc.c
index 91fe5f53ff11..739866bfe9e9 100644
--- a/net/atm/proc.c
+++ b/net/atm/proc.c
@@ -393,7 +393,7 @@ static ssize_t proc_dev_atm_read(struct file *file, char __user *buf,
393 if (count == 0) return 0; 393 if (count == 0) return 0;
394 page = get_zeroed_page(GFP_KERNEL); 394 page = get_zeroed_page(GFP_KERNEL);
395 if (!page) return -ENOMEM; 395 if (!page) return -ENOMEM;
396 dev = PDE(file->f_dentry->d_inode)->data; 396 dev = PDE(file->f_path.dentry->d_inode)->data;
397 if (!dev->ops->proc_read) 397 if (!dev->ops->proc_read)
398 length = -EINVAL; 398 length = -EINVAL;
399 else { 399 else {
diff --git a/net/ax25/ax25_addr.c b/net/ax25/ax25_addr.c
index 5f0896ad0042..97a49c79c605 100644
--- a/net/ax25/ax25_addr.c
+++ b/net/ax25/ax25_addr.c
@@ -29,17 +29,26 @@
29#include <linux/interrupt.h> 29#include <linux/interrupt.h>
30 30
31/* 31/*
32 * The null address is defined as a callsign of all spaces with an 32 * The default broadcast address of an interface is QST-0; the default address
33 * SSID of zero. 33 * is LINUX-1. The null address is defined as a callsign of all spaces with
34 * an SSID of zero.
34 */ 35 */
35ax25_address null_ax25_address = {{0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00}};
36 36
37const ax25_address ax25_bcast =
38 {{'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}};
39const ax25_address ax25_defaddr =
40 {{'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, 1 << 1}};
41const ax25_address null_ax25_address =
42 {{' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, ' ' << 1, 0 << 1}};
43
44EXPORT_SYMBOL_GPL(ax25_bcast);
45EXPORT_SYMBOL_GPL(ax25_defaddr);
37EXPORT_SYMBOL(null_ax25_address); 46EXPORT_SYMBOL(null_ax25_address);
38 47
39/* 48/*
40 * ax25 -> ascii conversion 49 * ax25 -> ascii conversion
41 */ 50 */
42char *ax2asc(char *buf, ax25_address *a) 51char *ax2asc(char *buf, const ax25_address *a)
43{ 52{
44 char c, *s; 53 char c, *s;
45 int n; 54 int n;
@@ -72,9 +81,9 @@ EXPORT_SYMBOL(ax2asc);
72/* 81/*
73 * ascii -> ax25 conversion 82 * ascii -> ax25 conversion
74 */ 83 */
75void asc2ax(ax25_address *addr, char *callsign) 84void asc2ax(ax25_address *addr, const char *callsign)
76{ 85{
77 char *s; 86 const char *s;
78 int n; 87 int n;
79 88
80 for (s = callsign, n = 0; n < 6; n++) { 89 for (s = callsign, n = 0; n < 6; n++) {
@@ -107,7 +116,7 @@ EXPORT_SYMBOL(asc2ax);
107/* 116/*
108 * Compare two ax.25 addresses 117 * Compare two ax.25 addresses
109 */ 118 */
110int ax25cmp(ax25_address *a, ax25_address *b) 119int ax25cmp(const ax25_address *a, const ax25_address *b)
111{ 120{
112 int ct = 0; 121 int ct = 0;
113 122
@@ -128,7 +137,7 @@ EXPORT_SYMBOL(ax25cmp);
128/* 137/*
129 * Compare two AX.25 digipeater paths. 138 * Compare two AX.25 digipeater paths.
130 */ 139 */
131int ax25digicmp(ax25_digi *digi1, ax25_digi *digi2) 140int ax25digicmp(const ax25_digi *digi1, const ax25_digi *digi2)
132{ 141{
133 int i; 142 int i;
134 143
@@ -149,7 +158,9 @@ int ax25digicmp(ax25_digi *digi1, ax25_digi *digi2)
149 * Given an AX.25 address pull of to, from, digi list, command/response and the start of data 158 * Given an AX.25 address pull of to, from, digi list, command/response and the start of data
150 * 159 *
151 */ 160 */
152unsigned char *ax25_addr_parse(unsigned char *buf, int len, ax25_address *src, ax25_address *dest, ax25_digi *digi, int *flags, int *dama) 161const unsigned char *ax25_addr_parse(const unsigned char *buf, int len,
162 ax25_address *src, ax25_address *dest, ax25_digi *digi, int *flags,
163 int *dama)
153{ 164{
154 int d = 0; 165 int d = 0;
155 166
@@ -204,7 +215,8 @@ unsigned char *ax25_addr_parse(unsigned char *buf, int len, ax25_address *src, a
204/* 215/*
205 * Assemble an AX.25 header from the bits 216 * Assemble an AX.25 header from the bits
206 */ 217 */
207int ax25_addr_build(unsigned char *buf, ax25_address *src, ax25_address *dest, ax25_digi *d, int flag, int modulus) 218int ax25_addr_build(unsigned char *buf, const ax25_address *src,
219 const ax25_address *dest, const ax25_digi *d, int flag, int modulus)
208{ 220{
209 int len = 0; 221 int len = 0;
210 int ct = 0; 222 int ct = 0;
@@ -261,7 +273,7 @@ int ax25_addr_build(unsigned char *buf, ax25_address *src, ax25_address *dest, a
261 return len; 273 return len;
262} 274}
263 275
264int ax25_addr_size(ax25_digi *dp) 276int ax25_addr_size(const ax25_digi *dp)
265{ 277{
266 if (dp == NULL) 278 if (dp == NULL)
267 return 2 * AX25_ADDR_LEN; 279 return 2 * AX25_ADDR_LEN;
@@ -272,7 +284,7 @@ int ax25_addr_size(ax25_digi *dp)
272/* 284/*
273 * Reverse Digipeat List. May not pass both parameters as same struct 285 * Reverse Digipeat List. May not pass both parameters as same struct
274 */ 286 */
275void ax25_digi_invert(ax25_digi *in, ax25_digi *out) 287void ax25_digi_invert(const ax25_digi *in, ax25_digi *out)
276{ 288{
277 int ct; 289 int ct;
278 290
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 1fb5d42f37ae..e0e0d09023b2 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -752,9 +752,9 @@ static int rfcomm_tty_ioctl(struct tty_struct *tty, struct file *filp, unsigned
752 return -ENOIOCTLCMD; 752 return -ENOIOCTLCMD;
753} 753}
754 754
755static void rfcomm_tty_set_termios(struct tty_struct *tty, struct termios *old) 755static void rfcomm_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
756{ 756{
757 struct termios *new = (struct termios *) tty->termios; 757 struct ktermios *new = tty->termios;
758 int old_baud_rate = tty_termios_baud_rate(old); 758 int old_baud_rate = tty_termios_baud_rate(old);
759 int new_baud_rate = tty_termios_baud_rate(new); 759 int new_baud_rate = tty_termios_baud_rate(new);
760 760
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index 0ab1987b9348..e7300b6b4079 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -577,9 +577,10 @@ void neigh_destroy(struct neighbour *neigh)
577 while ((hh = neigh->hh) != NULL) { 577 while ((hh = neigh->hh) != NULL) {
578 neigh->hh = hh->hh_next; 578 neigh->hh = hh->hh_next;
579 hh->hh_next = NULL; 579 hh->hh_next = NULL;
580 write_lock_bh(&hh->hh_lock); 580
581 write_seqlock_bh(&hh->hh_lock);
581 hh->hh_output = neigh_blackhole; 582 hh->hh_output = neigh_blackhole;
582 write_unlock_bh(&hh->hh_lock); 583 write_sequnlock_bh(&hh->hh_lock);
583 if (atomic_dec_and_test(&hh->hh_refcnt)) 584 if (atomic_dec_and_test(&hh->hh_refcnt))
584 kfree(hh); 585 kfree(hh);
585 } 586 }
@@ -897,9 +898,9 @@ static void neigh_update_hhs(struct neighbour *neigh)
897 898
898 if (update) { 899 if (update) {
899 for (hh = neigh->hh; hh; hh = hh->hh_next) { 900 for (hh = neigh->hh; hh; hh = hh->hh_next) {
900 write_lock_bh(&hh->hh_lock); 901 write_seqlock_bh(&hh->hh_lock);
901 update(hh, neigh->dev, neigh->ha); 902 update(hh, neigh->dev, neigh->ha);
902 write_unlock_bh(&hh->hh_lock); 903 write_sequnlock_bh(&hh->hh_lock);
903 } 904 }
904 } 905 }
905} 906}
@@ -1089,7 +1090,7 @@ static void neigh_hh_init(struct neighbour *n, struct dst_entry *dst,
1089 break; 1090 break;
1090 1091
1091 if (!hh && (hh = kzalloc(sizeof(*hh), GFP_ATOMIC)) != NULL) { 1092 if (!hh && (hh = kzalloc(sizeof(*hh), GFP_ATOMIC)) != NULL) {
1092 rwlock_init(&hh->hh_lock); 1093 seqlock_init(&hh->hh_lock);
1093 hh->hh_type = protocol; 1094 hh->hh_type = protocol;
1094 atomic_set(&hh->hh_refcnt, 0); 1095 atomic_set(&hh->hh_refcnt, 0);
1095 hh->hh_next = NULL; 1096 hh->hh_next = NULL;
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index b3c559b9ac35..823215d8e90f 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -55,6 +55,7 @@ static void queue_process(struct work_struct *work)
55 struct netpoll_info *npinfo = 55 struct netpoll_info *npinfo =
56 container_of(work, struct netpoll_info, tx_work.work); 56 container_of(work, struct netpoll_info, tx_work.work);
57 struct sk_buff *skb; 57 struct sk_buff *skb;
58 unsigned long flags;
58 59
59 while ((skb = skb_dequeue(&npinfo->txq))) { 60 while ((skb = skb_dequeue(&npinfo->txq))) {
60 struct net_device *dev = skb->dev; 61 struct net_device *dev = skb->dev;
@@ -64,15 +65,19 @@ static void queue_process(struct work_struct *work)
64 continue; 65 continue;
65 } 66 }
66 67
67 netif_tx_lock_bh(dev); 68 local_irq_save(flags);
69 netif_tx_lock(dev);
68 if (netif_queue_stopped(dev) || 70 if (netif_queue_stopped(dev) ||
69 dev->hard_start_xmit(skb, dev) != NETDEV_TX_OK) { 71 dev->hard_start_xmit(skb, dev) != NETDEV_TX_OK) {
70 skb_queue_head(&npinfo->txq, skb); 72 skb_queue_head(&npinfo->txq, skb);
71 netif_tx_unlock_bh(dev); 73 netif_tx_unlock(dev);
74 local_irq_restore(flags);
72 75
73 schedule_delayed_work(&npinfo->tx_work, HZ/10); 76 schedule_delayed_work(&npinfo->tx_work, HZ/10);
74 return; 77 return;
75 } 78 }
79 netif_tx_unlock(dev);
80 local_irq_restore(flags);
76 } 81 }
77} 82}
78 83
@@ -242,22 +247,28 @@ static void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
242 247
243 /* don't get messages out of order, and no recursion */ 248 /* don't get messages out of order, and no recursion */
244 if (skb_queue_len(&npinfo->txq) == 0 && 249 if (skb_queue_len(&npinfo->txq) == 0 &&
245 npinfo->poll_owner != smp_processor_id() && 250 npinfo->poll_owner != smp_processor_id()) {
246 netif_tx_trylock(dev)) { 251 unsigned long flags;
247 /* try until next clock tick */
248 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL; tries > 0; --tries) {
249 if (!netif_queue_stopped(dev))
250 status = dev->hard_start_xmit(skb, dev);
251 252
252 if (status == NETDEV_TX_OK) 253 local_irq_save(flags);
253 break; 254 if (netif_tx_trylock(dev)) {
255 /* try until next clock tick */
256 for (tries = jiffies_to_usecs(1)/USEC_PER_POLL;
257 tries > 0; --tries) {
258 if (!netif_queue_stopped(dev))
259 status = dev->hard_start_xmit(skb, dev);
254 260
255 /* tickle device maybe there is some cleanup */ 261 if (status == NETDEV_TX_OK)
256 netpoll_poll(np); 262 break;
263
264 /* tickle device maybe there is some cleanup */
265 netpoll_poll(np);
257 266
258 udelay(USEC_PER_POLL); 267 udelay(USEC_PER_POLL);
268 }
269 netif_tx_unlock(dev);
259 } 270 }
260 netif_tx_unlock(dev); 271 local_irq_restore(flags);
261 } 272 }
262 273
263 if (status != NETDEV_TX_OK) { 274 if (status != NETDEV_TX_OK) {
@@ -330,6 +341,7 @@ static void arp_reply(struct sk_buff *skb)
330 unsigned char *arp_ptr; 341 unsigned char *arp_ptr;
331 int size, type = ARPOP_REPLY, ptype = ETH_P_ARP; 342 int size, type = ARPOP_REPLY, ptype = ETH_P_ARP;
332 __be32 sip, tip; 343 __be32 sip, tip;
344 unsigned char *sha;
333 struct sk_buff *send_skb; 345 struct sk_buff *send_skb;
334 struct netpoll *np = NULL; 346 struct netpoll *np = NULL;
335 347
@@ -356,9 +368,14 @@ static void arp_reply(struct sk_buff *skb)
356 arp->ar_op != htons(ARPOP_REQUEST)) 368 arp->ar_op != htons(ARPOP_REQUEST))
357 return; 369 return;
358 370
359 arp_ptr = (unsigned char *)(arp+1) + skb->dev->addr_len; 371 arp_ptr = (unsigned char *)(arp+1);
372 /* save the location of the src hw addr */
373 sha = arp_ptr;
374 arp_ptr += skb->dev->addr_len;
360 memcpy(&sip, arp_ptr, 4); 375 memcpy(&sip, arp_ptr, 4);
361 arp_ptr += 4 + skb->dev->addr_len; 376 arp_ptr += 4;
377 /* if we actually cared about dst hw addr, it would get copied here */
378 arp_ptr += skb->dev->addr_len;
362 memcpy(&tip, arp_ptr, 4); 379 memcpy(&tip, arp_ptr, 4);
363 380
364 /* Should we ignore arp? */ 381 /* Should we ignore arp? */
@@ -381,7 +398,7 @@ static void arp_reply(struct sk_buff *skb)
381 398
382 if (np->dev->hard_header && 399 if (np->dev->hard_header &&
383 np->dev->hard_header(send_skb, skb->dev, ptype, 400 np->dev->hard_header(send_skb, skb->dev, ptype,
384 np->remote_mac, np->local_mac, 401 sha, np->local_mac,
385 send_skb->len) < 0) { 402 send_skb->len) < 0) {
386 kfree_skb(send_skb); 403 kfree_skb(send_skb);
387 return; 404 return;
@@ -405,7 +422,7 @@ static void arp_reply(struct sk_buff *skb)
405 arp_ptr += np->dev->addr_len; 422 arp_ptr += np->dev->addr_len;
406 memcpy(arp_ptr, &tip, 4); 423 memcpy(arp_ptr, &tip, 4);
407 arp_ptr += 4; 424 arp_ptr += 4;
408 memcpy(arp_ptr, np->remote_mac, np->dev->addr_len); 425 memcpy(arp_ptr, sha, np->dev->addr_len);
409 arp_ptr += np->dev->addr_len; 426 arp_ptr += np->dev->addr_len;
410 memcpy(arp_ptr, &sip, 4); 427 memcpy(arp_ptr, &sip, 4);
411 428
diff --git a/net/dccp/ackvec.c b/net/dccp/ackvec.c
index 1f4727ddbdbf..a086c6312d3b 100644
--- a/net/dccp/ackvec.c
+++ b/net/dccp/ackvec.c
@@ -223,7 +223,7 @@ static inline int dccp_ackvec_set_buf_head_state(struct dccp_ackvec *av,
223 gap = -new_head; 223 gap = -new_head;
224 } 224 }
225 new_head += DCCP_MAX_ACKVEC_LEN; 225 new_head += DCCP_MAX_ACKVEC_LEN;
226 } 226 }
227 227
228 av->dccpav_buf_head = new_head; 228 av->dccpav_buf_head = new_head;
229 229
@@ -336,7 +336,7 @@ out_duplicate:
336void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len) 336void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len)
337{ 337{
338 dccp_pr_debug_cat("ACK vector len=%d, ackno=%llu |", len, 338 dccp_pr_debug_cat("ACK vector len=%d, ackno=%llu |", len,
339 (unsigned long long)ackno); 339 (unsigned long long)ackno);
340 340
341 while (len--) { 341 while (len--) {
342 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6; 342 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6;
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h
index bcc2d12ae81c..c65cb2453e43 100644
--- a/net/dccp/ccid.h
+++ b/net/dccp/ccid.h
@@ -43,8 +43,6 @@ struct ccid_operations {
43 unsigned char* value); 43 unsigned char* value);
44 int (*ccid_hc_rx_insert_options)(struct sock *sk, 44 int (*ccid_hc_rx_insert_options)(struct sock *sk,
45 struct sk_buff *skb); 45 struct sk_buff *skb);
46 int (*ccid_hc_tx_insert_options)(struct sock *sk,
47 struct sk_buff *skb);
48 void (*ccid_hc_tx_packet_recv)(struct sock *sk, 46 void (*ccid_hc_tx_packet_recv)(struct sock *sk,
49 struct sk_buff *skb); 47 struct sk_buff *skb);
50 int (*ccid_hc_tx_parse_options)(struct sock *sk, 48 int (*ccid_hc_tx_parse_options)(struct sock *sk,
@@ -146,14 +144,6 @@ static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
146 return rc; 144 return rc;
147} 145}
148 146
149static inline int ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk,
150 struct sk_buff *skb)
151{
152 if (ccid->ccid_ops->ccid_hc_tx_insert_options != NULL)
153 return ccid->ccid_ops->ccid_hc_tx_insert_options(sk, skb);
154 return 0;
155}
156
157static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, 147static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
158 struct sk_buff *skb) 148 struct sk_buff *skb)
159{ 149{
diff --git a/net/dccp/ccids/ccid2.c b/net/dccp/ccids/ccid2.c
index 2555be8f4790..fd38b05d6f79 100644
--- a/net/dccp/ccids/ccid2.c
+++ b/net/dccp/ccids/ccid2.c
@@ -351,7 +351,7 @@ static void ccid2_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len)
351 351
352 while (seqp != hctx->ccid2hctx_seqh) { 352 while (seqp != hctx->ccid2hctx_seqh) {
353 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n", 353 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n",
354 (unsigned long long)seqp->ccid2s_seq, 354 (unsigned long long)seqp->ccid2s_seq,
355 seqp->ccid2s_acked, seqp->ccid2s_sent); 355 seqp->ccid2s_acked, seqp->ccid2s_sent);
356 seqp = seqp->ccid2s_next; 356 seqp = seqp->ccid2s_next;
357 } 357 }
@@ -473,7 +473,7 @@ static inline void ccid2_new_ack(struct sock *sk,
473 /* first measurement */ 473 /* first measurement */
474 if (hctx->ccid2hctx_srtt == -1) { 474 if (hctx->ccid2hctx_srtt == -1) {
475 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n", 475 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n",
476 r, jiffies, 476 r, jiffies,
477 (unsigned long long)seqp->ccid2s_seq); 477 (unsigned long long)seqp->ccid2s_seq);
478 ccid2_change_srtt(hctx, r); 478 ccid2_change_srtt(hctx, r);
479 hctx->ccid2hctx_rttvar = r >> 1; 479 hctx->ccid2hctx_rttvar = r >> 1;
@@ -518,8 +518,8 @@ static inline void ccid2_new_ack(struct sock *sk,
518 hctx->ccid2hctx_lastrtt = jiffies; 518 hctx->ccid2hctx_lastrtt = jiffies;
519 519
520 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n", 520 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n",
521 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, 521 hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar,
522 hctx->ccid2hctx_rto, HZ, r); 522 hctx->ccid2hctx_rto, HZ, r);
523 hctx->ccid2hctx_sent = 0; 523 hctx->ccid2hctx_sent = 0;
524 } 524 }
525 525
@@ -667,9 +667,9 @@ static void ccid2_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
667 /* new packet received or marked */ 667 /* new packet received or marked */
668 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED && 668 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED &&
669 !seqp->ccid2s_acked) { 669 !seqp->ccid2s_acked) {
670 if (state == 670 if (state ==
671 DCCP_ACKVEC_STATE_ECN_MARKED) { 671 DCCP_ACKVEC_STATE_ECN_MARKED) {
672 ccid2_congestion_event(hctx, 672 ccid2_congestion_event(hctx,
673 seqp); 673 seqp);
674 } else 674 } else
675 ccid2_new_ack(sk, seqp, 675 ccid2_new_ack(sk, seqp,
diff --git a/net/dccp/ccids/ccid3.c b/net/dccp/ccids/ccid3.c
index 66a27b9688ca..fa6b75372ed7 100644
--- a/net/dccp/ccids/ccid3.c
+++ b/net/dccp/ccids/ccid3.c
@@ -41,27 +41,6 @@
41#include "lib/tfrc.h" 41#include "lib/tfrc.h"
42#include "ccid3.h" 42#include "ccid3.h"
43 43
44/*
45 * Reason for maths here is to avoid 32 bit overflow when a is big.
46 * With this we get close to the limit.
47 */
48static u32 usecs_div(const u32 a, const u32 b)
49{
50 const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 :
51 a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 :
52 a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 :
53 a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 :
54 a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 :
55 a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 :
56 a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 :
57 a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 :
58 100000;
59 const u32 tmp = a * (USEC_PER_SEC / div);
60 return (b >= 2 * div) ? tmp / (b / div) : tmp;
61}
62
63
64
65#ifdef CONFIG_IP_DCCP_CCID3_DEBUG 44#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
66static int ccid3_debug; 45static int ccid3_debug;
67#define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a) 46#define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
@@ -108,8 +87,9 @@ static inline void ccid3_update_send_time(struct ccid3_hc_tx_sock *hctx)
108{ 87{
109 timeval_sub_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); 88 timeval_sub_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi);
110 89
111 /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ 90 /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */
112 hctx->ccid3hctx_t_ipi = usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_x); 91 hctx->ccid3hctx_t_ipi = scaled_div(hctx->ccid3hctx_s,
92 hctx->ccid3hctx_x >> 6);
113 93
114 /* Update nominal send time with regard to the new t_ipi */ 94 /* Update nominal send time with regard to the new t_ipi */
115 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); 95 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi);
@@ -128,40 +108,44 @@ static inline void ccid3_update_send_time(struct ccid3_hc_tx_sock *hctx)
128 * X = max(min(2 * X, 2 * X_recv), s / R); 108 * X = max(min(2 * X, 2 * X_recv), s / R);
129 * tld = now; 109 * tld = now;
130 * 110 *
111 * Note: X and X_recv are both stored in units of 64 * bytes/second, to support
112 * fine-grained resolution of sending rates. This requires scaling by 2^6
113 * throughout the code. Only X_calc is unscaled (in bytes/second).
114 *
131 * If X has changed, we also update the scheduled send time t_now, 115 * If X has changed, we also update the scheduled send time t_now,
132 * the inter-packet interval t_ipi, and the delta value. 116 * the inter-packet interval t_ipi, and the delta value.
133 */ 117 */
134static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now) 118static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now)
135 119
136{ 120{
137 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 121 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
138 const __u32 old_x = hctx->ccid3hctx_x; 122 const __u64 old_x = hctx->ccid3hctx_x;
139 123
140 if (hctx->ccid3hctx_p > 0) { 124 if (hctx->ccid3hctx_p > 0) {
141 hctx->ccid3hctx_x_calc = tfrc_calc_x(hctx->ccid3hctx_s, 125
142 hctx->ccid3hctx_rtt, 126 hctx->ccid3hctx_x = min(((__u64)hctx->ccid3hctx_x_calc) << 6,
143 hctx->ccid3hctx_p); 127 hctx->ccid3hctx_x_recv * 2);
144 hctx->ccid3hctx_x = max_t(u32, min(hctx->ccid3hctx_x_calc, 128 hctx->ccid3hctx_x = max(hctx->ccid3hctx_x,
145 hctx->ccid3hctx_x_recv * 2), 129 (((__u64)hctx->ccid3hctx_s) << 6) /
146 hctx->ccid3hctx_s / TFRC_T_MBI); 130 TFRC_T_MBI);
147 131
148 } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) >= 132 } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) -
149 hctx->ccid3hctx_rtt) { 133 (suseconds_t)hctx->ccid3hctx_rtt >= 0) {
150 hctx->ccid3hctx_x = max(min(hctx->ccid3hctx_x_recv, 134
151 hctx->ccid3hctx_x ) * 2, 135 hctx->ccid3hctx_x =
152 usecs_div(hctx->ccid3hctx_s, 136 max(2 * min(hctx->ccid3hctx_x, hctx->ccid3hctx_x_recv),
153 hctx->ccid3hctx_rtt) ); 137 scaled_div(((__u64)hctx->ccid3hctx_s) << 6,
138 hctx->ccid3hctx_rtt));
154 hctx->ccid3hctx_t_ld = *now; 139 hctx->ccid3hctx_t_ld = *now;
155 } else 140 }
156 ccid3_pr_debug("Not changing X\n");
157 141
158 if (hctx->ccid3hctx_x != old_x) 142 if (hctx->ccid3hctx_x != old_x)
159 ccid3_update_send_time(hctx); 143 ccid3_update_send_time(hctx);
160} 144}
161 145
162/* 146/*
163 * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1) 147 * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1)
164 * @len: DCCP packet payload size in bytes 148 * @len: DCCP packet payload size in bytes
165 */ 149 */
166static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) 150static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len)
167{ 151{
@@ -178,6 +162,33 @@ static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len)
178 */ 162 */
179} 163}
180 164
165/*
166 * Update Window Counter using the algorithm from [RFC 4342, 8.1].
167 * The algorithm is not applicable if RTT < 4 microseconds.
168 */
169static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx,
170 struct timeval *now)
171{
172 suseconds_t delta;
173 u32 quarter_rtts;
174
175 if (unlikely(hctx->ccid3hctx_rtt < 4)) /* avoid divide-by-zero */
176 return;
177
178 delta = timeval_delta(now, &hctx->ccid3hctx_t_last_win_count);
179 DCCP_BUG_ON(delta < 0);
180
181 quarter_rtts = (u32)delta / (hctx->ccid3hctx_rtt / 4);
182
183 if (quarter_rtts > 0) {
184 hctx->ccid3hctx_t_last_win_count = *now;
185 hctx->ccid3hctx_last_win_count += min_t(u32, quarter_rtts, 5);
186 hctx->ccid3hctx_last_win_count &= 0xF; /* mod 16 */
187
188 ccid3_pr_debug("now at %#X\n", hctx->ccid3hctx_last_win_count);
189 }
190}
191
181static void ccid3_hc_tx_no_feedback_timer(unsigned long data) 192static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
182{ 193{
183 struct sock *sk = (struct sock *)data; 194 struct sock *sk = (struct sock *)data;
@@ -191,20 +202,20 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
191 goto restart_timer; 202 goto restart_timer;
192 } 203 }
193 204
194 ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, 205 ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk,
195 ccid3_tx_state_name(hctx->ccid3hctx_state)); 206 ccid3_tx_state_name(hctx->ccid3hctx_state));
196 207
197 switch (hctx->ccid3hctx_state) { 208 switch (hctx->ccid3hctx_state) {
198 case TFRC_SSTATE_NO_FBACK: 209 case TFRC_SSTATE_NO_FBACK:
199 /* RFC 3448, 4.4: Halve send rate directly */ 210 /* RFC 3448, 4.4: Halve send rate directly */
200 hctx->ccid3hctx_x = min_t(u32, hctx->ccid3hctx_x / 2, 211 hctx->ccid3hctx_x = max(hctx->ccid3hctx_x / 2,
201 hctx->ccid3hctx_s / TFRC_T_MBI); 212 (((__u64)hctx->ccid3hctx_s) << 6) /
213 TFRC_T_MBI);
202 214
203 ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d " 215 ccid3_pr_debug("%s(%p, state=%s), updated tx rate to %u "
204 "bytes/s\n", 216 "bytes/s\n", dccp_role(sk), sk,
205 dccp_role(sk), sk,
206 ccid3_tx_state_name(hctx->ccid3hctx_state), 217 ccid3_tx_state_name(hctx->ccid3hctx_state),
207 hctx->ccid3hctx_x); 218 (unsigned)(hctx->ccid3hctx_x >> 6));
208 /* The value of R is still undefined and so we can not recompute 219 /* The value of R is still undefined and so we can not recompute
209 * the timout value. Keep initial value as per [RFC 4342, 5]. */ 220 * the timout value. Keep initial value as per [RFC 4342, 5]. */
210 t_nfb = TFRC_INITIAL_TIMEOUT; 221 t_nfb = TFRC_INITIAL_TIMEOUT;
@@ -213,34 +224,46 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
213 case TFRC_SSTATE_FBACK: 224 case TFRC_SSTATE_FBACK:
214 /* 225 /*
215 * Check if IDLE since last timeout and recv rate is less than 226 * Check if IDLE since last timeout and recv rate is less than
216 * 4 packets per RTT 227 * 4 packets (in units of 64*bytes/sec) per RTT
217 */ 228 */
218 if (!hctx->ccid3hctx_idle || 229 if (!hctx->ccid3hctx_idle ||
219 (hctx->ccid3hctx_x_recv >= 230 (hctx->ccid3hctx_x_recv >= 4 *
220 4 * usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_rtt))) { 231 scaled_div(((__u64)hctx->ccid3hctx_s) << 6,
232 hctx->ccid3hctx_rtt))) {
221 struct timeval now; 233 struct timeval now;
222 234
223 ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", 235 ccid3_pr_debug("%s(%p, state=%s), not idle\n",
224 dccp_role(sk), sk, 236 dccp_role(sk), sk,
225 ccid3_tx_state_name(hctx->ccid3hctx_state)); 237 ccid3_tx_state_name(hctx->ccid3hctx_state));
226 /* Halve sending rate */
227 238
228 /* If (p == 0 || X_calc > 2 * X_recv) 239 /*
240 * Modify the cached value of X_recv [RFC 3448, 4.4]
241 *
242 * If (p == 0 || X_calc > 2 * X_recv)
229 * X_recv = max(X_recv / 2, s / (2 * t_mbi)); 243 * X_recv = max(X_recv / 2, s / (2 * t_mbi));
230 * Else 244 * Else
231 * X_recv = X_calc / 4; 245 * X_recv = X_calc / 4;
246 *
247 * Note that X_recv is scaled by 2^6 while X_calc is not
232 */ 248 */
233 BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc); 249 BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc);
234 250
235 if (hctx->ccid3hctx_p == 0 || 251 if (hctx->ccid3hctx_p == 0 ||
236 hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) 252 (hctx->ccid3hctx_x_calc >
237 hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, 253 (hctx->ccid3hctx_x_recv >> 5))) {
238 hctx->ccid3hctx_s / (2 * TFRC_T_MBI)); 254
239 else 255 hctx->ccid3hctx_x_recv =
240 hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; 256 max(hctx->ccid3hctx_x_recv / 2,
241 257 (((__u64)hctx->ccid3hctx_s) << 6) /
242 /* Update sending rate */ 258 (2 * TFRC_T_MBI));
243 dccp_timestamp(sk, &now); 259
260 if (hctx->ccid3hctx_p == 0)
261 dccp_timestamp(sk, &now);
262 } else {
263 hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc;
264 hctx->ccid3hctx_x_recv <<= 4;
265 }
266 /* Now recalculate X [RFC 3448, 4.3, step (4)] */
244 ccid3_hc_tx_update_x(sk, &now); 267 ccid3_hc_tx_update_x(sk, &now);
245 } 268 }
246 /* 269 /*
@@ -251,7 +274,7 @@ static void ccid3_hc_tx_no_feedback_timer(unsigned long data)
251 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 274 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi);
252 break; 275 break;
253 case TFRC_SSTATE_NO_SENT: 276 case TFRC_SSTATE_NO_SENT:
254 DCCP_BUG("Illegal %s state NO_SENT, sk=%p", dccp_role(sk), sk); 277 DCCP_BUG("%s(%p) - Illegal state NO_SENT", dccp_role(sk), sk);
255 /* fall through */ 278 /* fall through */
256 case TFRC_SSTATE_TERM: 279 case TFRC_SSTATE_TERM:
257 goto out; 280 goto out;
@@ -277,9 +300,8 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
277{ 300{
278 struct dccp_sock *dp = dccp_sk(sk); 301 struct dccp_sock *dp = dccp_sk(sk);
279 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 302 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
280 struct dccp_tx_hist_entry *new_packet;
281 struct timeval now; 303 struct timeval now;
282 long delay; 304 suseconds_t delay;
283 305
284 BUG_ON(hctx == NULL); 306 BUG_ON(hctx == NULL);
285 307
@@ -291,34 +313,21 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
291 if (unlikely(skb->len == 0)) 313 if (unlikely(skb->len == 0))
292 return -EBADMSG; 314 return -EBADMSG;
293 315
294 /* See if last packet allocated was not sent */
295 new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist);
296 if (new_packet == NULL || new_packet->dccphtx_sent) {
297 new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist,
298 GFP_ATOMIC);
299
300 if (unlikely(new_packet == NULL)) {
301 DCCP_WARN("%s, sk=%p, not enough mem to add to history,"
302 "send refused\n", dccp_role(sk), sk);
303 return -ENOBUFS;
304 }
305
306 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet);
307 }
308
309 dccp_timestamp(sk, &now); 316 dccp_timestamp(sk, &now);
310 317
311 switch (hctx->ccid3hctx_state) { 318 switch (hctx->ccid3hctx_state) {
312 case TFRC_SSTATE_NO_SENT: 319 case TFRC_SSTATE_NO_SENT:
313 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 320 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
314 jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); 321 (jiffies +
322 usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)));
315 hctx->ccid3hctx_last_win_count = 0; 323 hctx->ccid3hctx_last_win_count = 0;
316 hctx->ccid3hctx_t_last_win_count = now; 324 hctx->ccid3hctx_t_last_win_count = now;
317 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); 325 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK);
318 326
319 /* Set initial sending rate to 1 packet per second */ 327 /* Set initial sending rate X/s to 1pps (X is scaled by 2^6) */
320 ccid3_hc_tx_update_s(hctx, skb->len); 328 ccid3_hc_tx_update_s(hctx, skb->len);
321 hctx->ccid3hctx_x = hctx->ccid3hctx_s; 329 hctx->ccid3hctx_x = hctx->ccid3hctx_s;
330 hctx->ccid3hctx_x <<= 6;
322 331
323 /* First timeout, according to [RFC 3448, 4.2], is 1 second */ 332 /* First timeout, according to [RFC 3448, 4.2], is 1 second */
324 hctx->ccid3hctx_t_ipi = USEC_PER_SEC; 333 hctx->ccid3hctx_t_ipi = USEC_PER_SEC;
@@ -332,77 +341,57 @@ static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb)
332 case TFRC_SSTATE_FBACK: 341 case TFRC_SSTATE_FBACK:
333 delay = timeval_delta(&hctx->ccid3hctx_t_nom, &now); 342 delay = timeval_delta(&hctx->ccid3hctx_t_nom, &now);
334 /* 343 /*
335 * Scheduling of packet transmissions [RFC 3448, 4.6] 344 * Scheduling of packet transmissions [RFC 3448, 4.6]
336 * 345 *
337 * if (t_now > t_nom - delta) 346 * if (t_now > t_nom - delta)
338 * // send the packet now 347 * // send the packet now
339 * else 348 * else
340 * // send the packet in (t_nom - t_now) milliseconds. 349 * // send the packet in (t_nom - t_now) milliseconds.
341 */ 350 */
342 if (delay - (long)hctx->ccid3hctx_delta >= 0) 351 if (delay - (suseconds_t)hctx->ccid3hctx_delta >= 0)
343 return delay / 1000L; 352 return delay / 1000L;
353
354 ccid3_hc_tx_update_win_count(hctx, &now);
344 break; 355 break;
345 case TFRC_SSTATE_TERM: 356 case TFRC_SSTATE_TERM:
346 DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 357 DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
347 return -EINVAL; 358 return -EINVAL;
348 } 359 }
349 360
350 /* prepare to send now (add options etc.) */ 361 /* prepare to send now (add options etc.) */
351 dp->dccps_hc_tx_insert_options = 1; 362 dp->dccps_hc_tx_insert_options = 1;
352 new_packet->dccphtx_ccval = DCCP_SKB_CB(skb)->dccpd_ccval = 363 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
353 hctx->ccid3hctx_last_win_count; 364
365 /* set the nominal send time for the next following packet */
354 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); 366 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi);
355 367
356 return 0; 368 return 0;
357} 369}
358 370
359static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) 371static void ccid3_hc_tx_packet_sent(struct sock *sk, int more,
372 unsigned int len)
360{ 373{
361 const struct dccp_sock *dp = dccp_sk(sk);
362 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 374 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
363 struct timeval now; 375 struct timeval now;
364 unsigned long quarter_rtt;
365 struct dccp_tx_hist_entry *packet; 376 struct dccp_tx_hist_entry *packet;
366 377
367 BUG_ON(hctx == NULL); 378 BUG_ON(hctx == NULL);
368 379
369 dccp_timestamp(sk, &now);
370
371 ccid3_hc_tx_update_s(hctx, len); 380 ccid3_hc_tx_update_s(hctx, len);
372 381
373 packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); 382 packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC);
374 if (unlikely(packet == NULL)) { 383 if (unlikely(packet == NULL)) {
375 DCCP_WARN("packet doesn't exist in history!\n"); 384 DCCP_CRIT("packet history - out of memory!");
376 return;
377 }
378 if (unlikely(packet->dccphtx_sent)) {
379 DCCP_WARN("no unsent packet in history!\n");
380 return; 385 return;
381 } 386 }
382 packet->dccphtx_tstamp = now; 387 dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, packet);
383 packet->dccphtx_seqno = dp->dccps_gss;
384 /*
385 * Check if win_count have changed
386 * Algorithm in "8.1. Window Counter Value" in RFC 4342.
387 */
388 quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count);
389 if (likely(hctx->ccid3hctx_rtt > 8))
390 quarter_rtt /= hctx->ccid3hctx_rtt / 4;
391
392 if (quarter_rtt > 0) {
393 hctx->ccid3hctx_t_last_win_count = now;
394 hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count +
395 min_t(unsigned long, quarter_rtt, 5)) % 16;
396 ccid3_pr_debug("%s, sk=%p, window changed from "
397 "%u to %u!\n",
398 dccp_role(sk), sk,
399 packet->dccphtx_ccval,
400 hctx->ccid3hctx_last_win_count);
401 }
402 388
403 hctx->ccid3hctx_idle = 0; 389 dccp_timestamp(sk, &now);
404 packet->dccphtx_rtt = hctx->ccid3hctx_rtt; 390 packet->dccphtx_tstamp = now;
405 packet->dccphtx_sent = 1; 391 packet->dccphtx_seqno = dccp_sk(sk)->dccps_gss;
392 packet->dccphtx_rtt = hctx->ccid3hctx_rtt;
393 packet->dccphtx_sent = 1;
394 hctx->ccid3hctx_idle = 0;
406} 395}
407 396
408static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) 397static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
@@ -414,7 +403,7 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
414 struct timeval now; 403 struct timeval now;
415 unsigned long t_nfb; 404 unsigned long t_nfb;
416 u32 pinv; 405 u32 pinv;
417 long r_sample, t_elapsed; 406 suseconds_t r_sample, t_elapsed;
418 407
419 BUG_ON(hctx == NULL); 408 BUG_ON(hctx == NULL);
420 409
@@ -430,44 +419,44 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
430 case TFRC_SSTATE_FBACK: 419 case TFRC_SSTATE_FBACK:
431 /* get packet from history to look up t_recvdata */ 420 /* get packet from history to look up t_recvdata */
432 packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, 421 packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist,
433 DCCP_SKB_CB(skb)->dccpd_ack_seq); 422 DCCP_SKB_CB(skb)->dccpd_ack_seq);
434 if (unlikely(packet == NULL)) { 423 if (unlikely(packet == NULL)) {
435 DCCP_WARN("%s(%p), seqno %llu(%s) doesn't exist " 424 DCCP_WARN("%s(%p), seqno %llu(%s) doesn't exist "
436 "in history!\n", dccp_role(sk), sk, 425 "in history!\n", dccp_role(sk), sk,
437 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, 426 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq,
438 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); 427 dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type));
439 return; 428 return;
440 } 429 }
441 430
442 /* Update receive rate */ 431 /* Update receive rate in units of 64 * bytes/second */
443 hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate; 432 hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate;
433 hctx->ccid3hctx_x_recv <<= 6;
444 434
445 /* Update loss event rate */ 435 /* Update loss event rate */
446 pinv = opt_recv->ccid3or_loss_event_rate; 436 pinv = opt_recv->ccid3or_loss_event_rate;
447 if (pinv == ~0U || pinv == 0) 437 if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */
448 hctx->ccid3hctx_p = 0; 438 hctx->ccid3hctx_p = 0;
449 else 439 else /* can not exceed 100% */
450 hctx->ccid3hctx_p = 1000000 / pinv; 440 hctx->ccid3hctx_p = 1000000 / pinv;
451 441
452 dccp_timestamp(sk, &now); 442 dccp_timestamp(sk, &now);
453 443
454 /* 444 /*
455 * Calculate new round trip sample as per [RFC 3448, 4.3] by 445 * Calculate new round trip sample as per [RFC 3448, 4.3] by
456 * R_sample = (now - t_recvdata) - t_elapsed 446 * R_sample = (now - t_recvdata) - t_elapsed
457 */ 447 */
458 r_sample = timeval_delta(&now, &packet->dccphtx_tstamp); 448 r_sample = timeval_delta(&now, &packet->dccphtx_tstamp);
459 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10; 449 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10;
460 450
461 if (unlikely(r_sample <= 0)) { 451 DCCP_BUG_ON(r_sample < 0);
462 DCCP_WARN("WARNING: R_sample (%ld) <= 0!\n", r_sample); 452 if (unlikely(r_sample <= t_elapsed))
463 r_sample = 0; 453 DCCP_WARN("WARNING: r_sample=%dus <= t_elapsed=%dus\n",
464 } else if (unlikely(r_sample <= t_elapsed)) 454 (int)r_sample, (int)t_elapsed);
465 DCCP_WARN("WARNING: r_sample=%ldus <= t_elapsed=%ldus\n",
466 r_sample, t_elapsed);
467 else 455 else
468 r_sample -= t_elapsed; 456 r_sample -= t_elapsed;
457 CCID3_RTT_SANITY_CHECK(r_sample);
469 458
470 /* Update RTT estimate by 459 /* Update RTT estimate by
471 * If (No feedback recv) 460 * If (No feedback recv)
472 * R = R_sample; 461 * R = R_sample;
473 * Else 462 * Else
@@ -476,34 +465,45 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
476 * q is a constant, RFC 3448 recomments 0.9 465 * q is a constant, RFC 3448 recomments 0.9
477 */ 466 */
478 if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { 467 if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) {
479 /* Use Larger Initial Windows [RFC 4342, sec. 5] 468 /*
480 * We deviate in that we use `s' instead of `MSS'. */ 469 * Larger Initial Windows [RFC 4342, sec. 5]
481 u16 w_init = max( 4 * hctx->ccid3hctx_s, 470 * We deviate in that we use `s' instead of `MSS'.
482 max(2 * hctx->ccid3hctx_s, 4380)); 471 */
472 __u64 w_init = min(4 * hctx->ccid3hctx_s,
473 max(2 * hctx->ccid3hctx_s, 4380));
483 hctx->ccid3hctx_rtt = r_sample; 474 hctx->ccid3hctx_rtt = r_sample;
484 hctx->ccid3hctx_x = usecs_div(w_init, r_sample); 475 hctx->ccid3hctx_x = scaled_div(w_init << 6, r_sample);
485 hctx->ccid3hctx_t_ld = now; 476 hctx->ccid3hctx_t_ld = now;
486 477
487 ccid3_update_send_time(hctx); 478 ccid3_update_send_time(hctx);
488 479
489 ccid3_pr_debug("%s(%p), s=%u, w_init=%u, " 480 ccid3_pr_debug("%s(%p), s=%u, w_init=%llu, "
490 "R_sample=%ldus, X=%u\n", dccp_role(sk), 481 "R_sample=%dus, X=%u\n", dccp_role(sk),
491 sk, hctx->ccid3hctx_s, w_init, r_sample, 482 sk, hctx->ccid3hctx_s, w_init,
492 hctx->ccid3hctx_x); 483 (int)r_sample,
484 (unsigned)(hctx->ccid3hctx_x >> 6));
493 485
494 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); 486 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK);
495 } else { 487 } else {
496 hctx->ccid3hctx_rtt = (9 * hctx->ccid3hctx_rtt + 488 hctx->ccid3hctx_rtt = (9 * hctx->ccid3hctx_rtt +
497 (u32)r_sample ) / 10; 489 (u32)r_sample) / 10;
498 490
491 /* Update sending rate (step 4 of [RFC 3448, 4.3]) */
492 if (hctx->ccid3hctx_p > 0)
493 hctx->ccid3hctx_x_calc =
494 tfrc_calc_x(hctx->ccid3hctx_s,
495 hctx->ccid3hctx_rtt,
496 hctx->ccid3hctx_p);
499 ccid3_hc_tx_update_x(sk, &now); 497 ccid3_hc_tx_update_x(sk, &now);
500 498
501 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%ldus), s=%u, " 499 ccid3_pr_debug("%s(%p), RTT=%uus (sample=%dus), s=%u, "
502 "p=%u, X_calc=%u, X=%u\n", dccp_role(sk), 500 "p=%u, X_calc=%u, X_recv=%u, X=%u\n",
503 sk, hctx->ccid3hctx_rtt, r_sample, 501 dccp_role(sk),
502 sk, hctx->ccid3hctx_rtt, (int)r_sample,
504 hctx->ccid3hctx_s, hctx->ccid3hctx_p, 503 hctx->ccid3hctx_s, hctx->ccid3hctx_p,
505 hctx->ccid3hctx_x_calc, 504 hctx->ccid3hctx_x_calc,
506 hctx->ccid3hctx_x); 505 (unsigned)(hctx->ccid3hctx_x_recv >> 6),
506 (unsigned)(hctx->ccid3hctx_x >> 6));
507 } 507 }
508 508
509 /* unschedule no feedback timer */ 509 /* unschedule no feedback timer */
@@ -513,57 +513,48 @@ static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb)
513 dccp_tx_hist_purge_older(ccid3_tx_hist, 513 dccp_tx_hist_purge_older(ccid3_tx_hist,
514 &hctx->ccid3hctx_hist, packet); 514 &hctx->ccid3hctx_hist, packet);
515 /* 515 /*
516 * As we have calculated new ipi, delta, t_nom it is possible that 516 * As we have calculated new ipi, delta, t_nom it is possible
517 * we now can send a packet, so wake up dccp_wait_for_ccid 517 * that we now can send a packet, so wake up dccp_wait_for_ccid
518 */ 518 */
519 sk->sk_write_space(sk); 519 sk->sk_write_space(sk);
520 520
521 /* 521 /*
522 * Update timeout interval for the nofeedback timer. 522 * Update timeout interval for the nofeedback timer.
523 * We use a configuration option to increase the lower bound. 523 * We use a configuration option to increase the lower bound.
524 * This can help avoid triggering the nofeedback timer too often 524 * This can help avoid triggering the nofeedback timer too
525 * ('spinning') on LANs with small RTTs. 525 * often ('spinning') on LANs with small RTTs.
526 */ 526 */
527 hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, 527 hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt,
528 CONFIG_IP_DCCP_CCID3_RTO * 528 CONFIG_IP_DCCP_CCID3_RTO *
529 (USEC_PER_SEC/1000) ); 529 (USEC_PER_SEC/1000));
530 /* 530 /*
531 * Schedule no feedback timer to expire in 531 * Schedule no feedback timer to expire in
532 * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi) 532 * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi)
533 */ 533 */
534 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 534 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi);
535 535
536 ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to " 536 ccid3_pr_debug("%s(%p), Scheduled no feedback timer to "
537 "expire in %lu jiffies (%luus)\n", 537 "expire in %lu jiffies (%luus)\n",
538 dccp_role(sk), sk, 538 dccp_role(sk),
539 usecs_to_jiffies(t_nfb), t_nfb); 539 sk, usecs_to_jiffies(t_nfb), t_nfb);
540 540
541 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 541 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer,
542 jiffies + usecs_to_jiffies(t_nfb)); 542 jiffies + usecs_to_jiffies(t_nfb));
543 543
544 /* set idle flag */ 544 /* set idle flag */
545 hctx->ccid3hctx_idle = 1; 545 hctx->ccid3hctx_idle = 1;
546 break; 546 break;
547 case TFRC_SSTATE_NO_SENT: 547 case TFRC_SSTATE_NO_SENT:
548 if (dccp_sk(sk)->dccps_role == DCCP_ROLE_CLIENT) 548 /*
549 DCCP_WARN("Illegal ACK received - no packet sent\n"); 549 * XXX when implementing bidirectional rx/tx check this again
550 */
551 DCCP_WARN("Illegal ACK received - no packet sent\n");
550 /* fall through */ 552 /* fall through */
551 case TFRC_SSTATE_TERM: /* ignore feedback when closing */ 553 case TFRC_SSTATE_TERM: /* ignore feedback when closing */
552 break; 554 break;
553 } 555 }
554} 556}
555 557
556static int ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb)
557{
558 const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk);
559
560 BUG_ON(hctx == NULL);
561
562 if (sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)
563 DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count;
564 return 0;
565}
566
567static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, 558static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
568 unsigned char len, u16 idx, 559 unsigned char len, u16 idx,
569 unsigned char *value) 560 unsigned char *value)
@@ -588,13 +579,14 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
588 switch (option) { 579 switch (option) {
589 case TFRC_OPT_LOSS_EVENT_RATE: 580 case TFRC_OPT_LOSS_EVENT_RATE:
590 if (unlikely(len != 4)) { 581 if (unlikely(len != 4)) {
591 DCCP_WARN("%s, sk=%p, invalid len %d " 582 DCCP_WARN("%s(%p), invalid len %d "
592 "for TFRC_OPT_LOSS_EVENT_RATE\n", 583 "for TFRC_OPT_LOSS_EVENT_RATE\n",
593 dccp_role(sk), sk, len); 584 dccp_role(sk), sk, len);
594 rc = -EINVAL; 585 rc = -EINVAL;
595 } else { 586 } else {
596 opt_recv->ccid3or_loss_event_rate = ntohl(*(__be32 *)value); 587 opt_recv->ccid3or_loss_event_rate =
597 ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", 588 ntohl(*(__be32 *)value);
589 ccid3_pr_debug("%s(%p), LOSS_EVENT_RATE=%u\n",
598 dccp_role(sk), sk, 590 dccp_role(sk), sk,
599 opt_recv->ccid3or_loss_event_rate); 591 opt_recv->ccid3or_loss_event_rate);
600 } 592 }
@@ -602,20 +594,21 @@ static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option,
602 case TFRC_OPT_LOSS_INTERVALS: 594 case TFRC_OPT_LOSS_INTERVALS:
603 opt_recv->ccid3or_loss_intervals_idx = idx; 595 opt_recv->ccid3or_loss_intervals_idx = idx;
604 opt_recv->ccid3or_loss_intervals_len = len; 596 opt_recv->ccid3or_loss_intervals_len = len;
605 ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", 597 ccid3_pr_debug("%s(%p), LOSS_INTERVALS=(%u, %u)\n",
606 dccp_role(sk), sk, 598 dccp_role(sk), sk,
607 opt_recv->ccid3or_loss_intervals_idx, 599 opt_recv->ccid3or_loss_intervals_idx,
608 opt_recv->ccid3or_loss_intervals_len); 600 opt_recv->ccid3or_loss_intervals_len);
609 break; 601 break;
610 case TFRC_OPT_RECEIVE_RATE: 602 case TFRC_OPT_RECEIVE_RATE:
611 if (unlikely(len != 4)) { 603 if (unlikely(len != 4)) {
612 DCCP_WARN("%s, sk=%p, invalid len %d " 604 DCCP_WARN("%s(%p), invalid len %d "
613 "for TFRC_OPT_RECEIVE_RATE\n", 605 "for TFRC_OPT_RECEIVE_RATE\n",
614 dccp_role(sk), sk, len); 606 dccp_role(sk), sk, len);
615 rc = -EINVAL; 607 rc = -EINVAL;
616 } else { 608 } else {
617 opt_recv->ccid3or_receive_rate = ntohl(*(__be32 *)value); 609 opt_recv->ccid3or_receive_rate =
618 ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", 610 ntohl(*(__be32 *)value);
611 ccid3_pr_debug("%s(%p), RECEIVE_RATE=%u\n",
619 dccp_role(sk), sk, 612 dccp_role(sk), sk,
620 opt_recv->ccid3or_receive_rate); 613 opt_recv->ccid3or_receive_rate);
621 } 614 }
@@ -630,10 +623,12 @@ static int ccid3_hc_tx_init(struct ccid *ccid, struct sock *sk)
630 struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); 623 struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid);
631 624
632 hctx->ccid3hctx_s = 0; 625 hctx->ccid3hctx_s = 0;
626 hctx->ccid3hctx_rtt = 0;
633 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; 627 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT;
634 INIT_LIST_HEAD(&hctx->ccid3hctx_hist); 628 INIT_LIST_HEAD(&hctx->ccid3hctx_hist);
635 629
636 hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; 630 hctx->ccid3hctx_no_feedback_timer.function =
631 ccid3_hc_tx_no_feedback_timer;
637 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; 632 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk;
638 init_timer(&hctx->ccid3hctx_no_feedback_timer); 633 init_timer(&hctx->ccid3hctx_no_feedback_timer);
639 634
@@ -698,8 +693,9 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
698 struct dccp_sock *dp = dccp_sk(sk); 693 struct dccp_sock *dp = dccp_sk(sk);
699 struct dccp_rx_hist_entry *packet; 694 struct dccp_rx_hist_entry *packet;
700 struct timeval now; 695 struct timeval now;
696 suseconds_t delta;
701 697
702 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 698 ccid3_pr_debug("%s(%p) - entry \n", dccp_role(sk), sk);
703 699
704 dccp_timestamp(sk, &now); 700 dccp_timestamp(sk, &now);
705 701
@@ -707,21 +703,21 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
707 case TFRC_RSTATE_NO_DATA: 703 case TFRC_RSTATE_NO_DATA:
708 hcrx->ccid3hcrx_x_recv = 0; 704 hcrx->ccid3hcrx_x_recv = 0;
709 break; 705 break;
710 case TFRC_RSTATE_DATA: { 706 case TFRC_RSTATE_DATA:
711 const u32 delta = timeval_delta(&now, 707 delta = timeval_delta(&now,
712 &hcrx->ccid3hcrx_tstamp_last_feedback); 708 &hcrx->ccid3hcrx_tstamp_last_feedback);
713 hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, 709 DCCP_BUG_ON(delta < 0);
714 delta); 710 hcrx->ccid3hcrx_x_recv =
715 } 711 scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
716 break; 712 break;
717 case TFRC_RSTATE_TERM: 713 case TFRC_RSTATE_TERM:
718 DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 714 DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
719 return; 715 return;
720 } 716 }
721 717
722 packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist); 718 packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist);
723 if (unlikely(packet == NULL)) { 719 if (unlikely(packet == NULL)) {
724 DCCP_WARN("%s, sk=%p, no data packet in history!\n", 720 DCCP_WARN("%s(%p), no data packet in history!\n",
725 dccp_role(sk), sk); 721 dccp_role(sk), sk);
726 return; 722 return;
727 } 723 }
@@ -730,13 +726,19 @@ static void ccid3_hc_rx_send_feedback(struct sock *sk)
730 hcrx->ccid3hcrx_ccval_last_counter = packet->dccphrx_ccval; 726 hcrx->ccid3hcrx_ccval_last_counter = packet->dccphrx_ccval;
731 hcrx->ccid3hcrx_bytes_recv = 0; 727 hcrx->ccid3hcrx_bytes_recv = 0;
732 728
733 /* Convert to multiples of 10us */ 729 /* Elapsed time information [RFC 4340, 13.2] in units of 10 * usecs */
734 hcrx->ccid3hcrx_elapsed_time = 730 delta = timeval_delta(&now, &packet->dccphrx_tstamp);
735 timeval_delta(&now, &packet->dccphrx_tstamp) / 10; 731 DCCP_BUG_ON(delta < 0);
732 hcrx->ccid3hcrx_elapsed_time = delta / 10;
733
736 if (hcrx->ccid3hcrx_p == 0) 734 if (hcrx->ccid3hcrx_p == 0)
737 hcrx->ccid3hcrx_pinv = ~0; 735 hcrx->ccid3hcrx_pinv = ~0U; /* see RFC 4342, 8.5 */
738 else 736 else if (hcrx->ccid3hcrx_p > 1000000) {
737 DCCP_WARN("p (%u) > 100%%\n", hcrx->ccid3hcrx_p);
738 hcrx->ccid3hcrx_pinv = 1; /* use 100% in this case */
739 } else
739 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; 740 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p;
741
740 dp->dccps_hc_rx_insert_options = 1; 742 dp->dccps_hc_rx_insert_options = 1;
741 dccp_send_ack(sk); 743 dccp_send_ack(sk);
742} 744}
@@ -764,9 +766,9 @@ static int ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb)
764 hcrx->ccid3hcrx_elapsed_time)) || 766 hcrx->ccid3hcrx_elapsed_time)) ||
765 dccp_insert_option_timestamp(sk, skb) || 767 dccp_insert_option_timestamp(sk, skb) ||
766 dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, 768 dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE,
767 &pinv, sizeof(pinv)) || 769 &pinv, sizeof(pinv)) ||
768 dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, 770 dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE,
769 &x_recv, sizeof(x_recv))) 771 &x_recv, sizeof(x_recv)))
770 return -1; 772 return -1;
771 773
772 return 0; 774 return 0;
@@ -780,12 +782,13 @@ static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
780{ 782{
781 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 783 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
782 struct dccp_rx_hist_entry *entry, *next, *tail = NULL; 784 struct dccp_rx_hist_entry *entry, *next, *tail = NULL;
783 u32 rtt, delta, x_recv, fval, p, tmp2; 785 u32 x_recv, p;
786 suseconds_t rtt, delta;
784 struct timeval tstamp = { 0, }; 787 struct timeval tstamp = { 0, };
785 int interval = 0; 788 int interval = 0;
786 int win_count = 0; 789 int win_count = 0;
787 int step = 0; 790 int step = 0;
788 u64 tmp1; 791 u64 fval;
789 792
790 list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, 793 list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist,
791 dccphrx_node) { 794 dccphrx_node) {
@@ -810,13 +813,13 @@ static u32 ccid3_hc_rx_calc_first_li(struct sock *sk)
810 } 813 }
811 814
812 if (unlikely(step == 0)) { 815 if (unlikely(step == 0)) {
813 DCCP_WARN("%s, sk=%p, packet history has no data packets!\n", 816 DCCP_WARN("%s(%p), packet history has no data packets!\n",
814 dccp_role(sk), sk); 817 dccp_role(sk), sk);
815 return ~0; 818 return ~0;
816 } 819 }
817 820
818 if (unlikely(interval == 0)) { 821 if (unlikely(interval == 0)) {
819 DCCP_WARN("%s, sk=%p, Could not find a win_count interval > 0." 822 DCCP_WARN("%s(%p), Could not find a win_count interval > 0."
820 "Defaulting to 1\n", dccp_role(sk), sk); 823 "Defaulting to 1\n", dccp_role(sk), sk);
821 interval = 1; 824 interval = 1;
822 } 825 }
@@ -825,41 +828,51 @@ found:
825 DCCP_CRIT("tail is null\n"); 828 DCCP_CRIT("tail is null\n");
826 return ~0; 829 return ~0;
827 } 830 }
828 rtt = timeval_delta(&tstamp, &tail->dccphrx_tstamp) * 4 / interval;
829 ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n",
830 dccp_role(sk), sk, rtt);
831 831
832 if (rtt == 0) { 832 delta = timeval_delta(&tstamp, &tail->dccphrx_tstamp);
833 DCCP_WARN("RTT==0, setting to 1\n"); 833 DCCP_BUG_ON(delta < 0);
834 rtt = 1; 834
835 rtt = delta * 4 / interval;
836 ccid3_pr_debug("%s(%p), approximated RTT to %dus\n",
837 dccp_role(sk), sk, (int)rtt);
838
839 /*
840 * Determine the length of the first loss interval via inverse lookup.
841 * Assume that X_recv can be computed by the throughput equation
842 * s
843 * X_recv = --------
844 * R * fval
845 * Find some p such that f(p) = fval; return 1/p [RFC 3448, 6.3.1].
846 */
847 if (rtt == 0) { /* would result in divide-by-zero */
848 DCCP_WARN("RTT==0, returning 1/p = 1\n");
849 return 1000000;
835 } 850 }
836 851
837 dccp_timestamp(sk, &tstamp); 852 dccp_timestamp(sk, &tstamp);
838 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback); 853 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback);
839 x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta); 854 DCCP_BUG_ON(delta <= 0);
840 855
841 if (x_recv == 0) 856 x_recv = scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta);
842 x_recv = hcrx->ccid3hcrx_x_recv; 857 if (x_recv == 0) { /* would also trigger divide-by-zero */
843 858 DCCP_WARN("X_recv==0\n");
844 tmp1 = (u64)x_recv * (u64)rtt; 859 if ((x_recv = hcrx->ccid3hcrx_x_recv) == 0) {
845 do_div(tmp1,10000000); 860 DCCP_BUG("stored value of X_recv is zero");
846 tmp2 = (u32)tmp1; 861 return 1000000;
847 862 }
848 if (!tmp2) {
849 DCCP_CRIT("tmp2 = 0, x_recv = %u, rtt =%u\n", x_recv, rtt);
850 return ~0;
851 } 863 }
852 864
853 fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; 865 fval = scaled_div(hcrx->ccid3hcrx_s, rtt);
854 /* do not alter order above or you will get overflow on 32 bit */ 866 fval = scaled_div32(fval, x_recv);
855 p = tfrc_calc_x_reverse_lookup(fval); 867 p = tfrc_calc_x_reverse_lookup(fval);
856 ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " 868
869 ccid3_pr_debug("%s(%p), receive rate=%u bytes/s, implied "
857 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); 870 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p);
858 871
859 if (p == 0) 872 if (p == 0)
860 return ~0; 873 return ~0;
861 else 874 else
862 return 1000000 / p; 875 return 1000000 / p;
863} 876}
864 877
865static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) 878static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss)
@@ -913,7 +926,8 @@ static int ccid3_hc_rx_detect_loss(struct sock *sk,
913 struct dccp_rx_hist_entry *packet) 926 struct dccp_rx_hist_entry *packet)
914{ 927{
915 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 928 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk);
916 struct dccp_rx_hist_entry *rx_hist = dccp_rx_hist_head(&hcrx->ccid3hcrx_hist); 929 struct dccp_rx_hist_entry *rx_hist =
930 dccp_rx_hist_head(&hcrx->ccid3hcrx_hist);
917 u64 seqno = packet->dccphrx_seqno; 931 u64 seqno = packet->dccphrx_seqno;
918 u64 tmp_seqno; 932 u64 tmp_seqno;
919 int loss = 0; 933 int loss = 0;
@@ -941,7 +955,7 @@ static int ccid3_hc_rx_detect_loss(struct sock *sk,
941 dccp_inc_seqno(&tmp_seqno); 955 dccp_inc_seqno(&tmp_seqno);
942 while (dccp_rx_hist_find_entry(&hcrx->ccid3hcrx_hist, 956 while (dccp_rx_hist_find_entry(&hcrx->ccid3hcrx_hist,
943 tmp_seqno, &ccval)) { 957 tmp_seqno, &ccval)) {
944 hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno; 958 hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno;
945 hcrx->ccid3hcrx_ccval_nonloss = ccval; 959 hcrx->ccid3hcrx_ccval_nonloss = ccval;
946 dccp_inc_seqno(&tmp_seqno); 960 dccp_inc_seqno(&tmp_seqno);
947 } 961 }
@@ -967,7 +981,8 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
967 const struct dccp_options_received *opt_recv; 981 const struct dccp_options_received *opt_recv;
968 struct dccp_rx_hist_entry *packet; 982 struct dccp_rx_hist_entry *packet;
969 struct timeval now; 983 struct timeval now;
970 u32 p_prev, rtt_prev, r_sample, t_elapsed; 984 u32 p_prev, rtt_prev;
985 suseconds_t r_sample, t_elapsed;
971 int loss, payload_size; 986 int loss, payload_size;
972 987
973 BUG_ON(hcrx == NULL); 988 BUG_ON(hcrx == NULL);
@@ -987,11 +1002,13 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
987 r_sample = timeval_usecs(&now); 1002 r_sample = timeval_usecs(&now);
988 t_elapsed = opt_recv->dccpor_elapsed_time * 10; 1003 t_elapsed = opt_recv->dccpor_elapsed_time * 10;
989 1004
1005 DCCP_BUG_ON(r_sample < 0);
990 if (unlikely(r_sample <= t_elapsed)) 1006 if (unlikely(r_sample <= t_elapsed))
991 DCCP_WARN("r_sample=%uus, t_elapsed=%uus\n", 1007 DCCP_WARN("r_sample=%ldus, t_elapsed=%ldus\n",
992 r_sample, t_elapsed); 1008 r_sample, t_elapsed);
993 else 1009 else
994 r_sample -= t_elapsed; 1010 r_sample -= t_elapsed;
1011 CCID3_RTT_SANITY_CHECK(r_sample);
995 1012
996 if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) 1013 if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA)
997 hcrx->ccid3hcrx_rtt = r_sample; 1014 hcrx->ccid3hcrx_rtt = r_sample;
@@ -1000,8 +1017,8 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1000 r_sample / 10; 1017 r_sample / 10;
1001 1018
1002 if (rtt_prev != hcrx->ccid3hcrx_rtt) 1019 if (rtt_prev != hcrx->ccid3hcrx_rtt)
1003 ccid3_pr_debug("%s, New RTT=%uus, elapsed time=%u\n", 1020 ccid3_pr_debug("%s(%p), New RTT=%uus, elapsed time=%u\n",
1004 dccp_role(sk), hcrx->ccid3hcrx_rtt, 1021 dccp_role(sk), sk, hcrx->ccid3hcrx_rtt,
1005 opt_recv->dccpor_elapsed_time); 1022 opt_recv->dccpor_elapsed_time);
1006 break; 1023 break;
1007 case DCCP_PKT_DATA: 1024 case DCCP_PKT_DATA:
@@ -1013,7 +1030,7 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1013 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp, 1030 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp,
1014 skb, GFP_ATOMIC); 1031 skb, GFP_ATOMIC);
1015 if (unlikely(packet == NULL)) { 1032 if (unlikely(packet == NULL)) {
1016 DCCP_WARN("%s, sk=%p, Not enough mem to add rx packet " 1033 DCCP_WARN("%s(%p), Not enough mem to add rx packet "
1017 "to history, consider it lost!\n", dccp_role(sk), sk); 1034 "to history, consider it lost!\n", dccp_role(sk), sk);
1018 return; 1035 return;
1019 } 1036 }
@@ -1028,9 +1045,8 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1028 1045
1029 switch (hcrx->ccid3hcrx_state) { 1046 switch (hcrx->ccid3hcrx_state) {
1030 case TFRC_RSTATE_NO_DATA: 1047 case TFRC_RSTATE_NO_DATA:
1031 ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial " 1048 ccid3_pr_debug("%s(%p, state=%s), skb=%p, sending initial "
1032 "feedback\n", 1049 "feedback\n", dccp_role(sk), sk,
1033 dccp_role(sk), sk,
1034 dccp_state_name(sk->sk_state), skb); 1050 dccp_state_name(sk->sk_state), skb);
1035 ccid3_hc_rx_send_feedback(sk); 1051 ccid3_hc_rx_send_feedback(sk);
1036 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); 1052 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA);
@@ -1041,19 +1057,19 @@ static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb)
1041 break; 1057 break;
1042 1058
1043 dccp_timestamp(sk, &now); 1059 dccp_timestamp(sk, &now);
1044 if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= 1060 if ((timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) -
1045 hcrx->ccid3hcrx_rtt) { 1061 (suseconds_t)hcrx->ccid3hcrx_rtt) >= 0) {
1046 hcrx->ccid3hcrx_tstamp_last_ack = now; 1062 hcrx->ccid3hcrx_tstamp_last_ack = now;
1047 ccid3_hc_rx_send_feedback(sk); 1063 ccid3_hc_rx_send_feedback(sk);
1048 } 1064 }
1049 return; 1065 return;
1050 case TFRC_RSTATE_TERM: 1066 case TFRC_RSTATE_TERM:
1051 DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 1067 DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk);
1052 return; 1068 return;
1053 } 1069 }
1054 1070
1055 /* Dealing with packet loss */ 1071 /* Dealing with packet loss */
1056 ccid3_pr_debug("%s, sk=%p(%s), data loss! Reacting...\n", 1072 ccid3_pr_debug("%s(%p, state=%s), data loss! Reacting...\n",
1057 dccp_role(sk), sk, dccp_state_name(sk->sk_state)); 1073 dccp_role(sk), sk, dccp_state_name(sk->sk_state));
1058 1074
1059 p_prev = hcrx->ccid3hcrx_p; 1075 p_prev = hcrx->ccid3hcrx_p;
@@ -1078,7 +1094,7 @@ static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
1078{ 1094{
1079 struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); 1095 struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid);
1080 1096
1081 ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1097 ccid3_pr_debug("entry\n");
1082 1098
1083 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; 1099 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA;
1084 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); 1100 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist);
@@ -1086,7 +1102,7 @@ static int ccid3_hc_rx_init(struct ccid *ccid, struct sock *sk)
1086 dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack); 1102 dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack);
1087 hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack; 1103 hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack;
1088 hcrx->ccid3hcrx_s = 0; 1104 hcrx->ccid3hcrx_s = 0;
1089 hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */ 1105 hcrx->ccid3hcrx_rtt = 0;
1090 return 0; 1106 return 0;
1091} 1107}
1092 1108
@@ -1115,9 +1131,9 @@ static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info)
1115 1131
1116 BUG_ON(hcrx == NULL); 1132 BUG_ON(hcrx == NULL);
1117 1133
1118 info->tcpi_ca_state = hcrx->ccid3hcrx_state; 1134 info->tcpi_ca_state = hcrx->ccid3hcrx_state;
1119 info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 1135 info->tcpi_options |= TCPI_OPT_TIMESTAMPS;
1120 info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; 1136 info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt;
1121} 1137}
1122 1138
1123static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) 1139static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info)
@@ -1198,7 +1214,6 @@ static struct ccid_operations ccid3 = {
1198 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, 1214 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet,
1199 .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, 1215 .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent,
1200 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, 1216 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv,
1201 .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options,
1202 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, 1217 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options,
1203 .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock), 1218 .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock),
1204 .ccid_hc_rx_init = ccid3_hc_rx_init, 1219 .ccid_hc_rx_init = ccid3_hc_rx_init,
@@ -1210,7 +1225,7 @@ static struct ccid_operations ccid3 = {
1210 .ccid_hc_rx_getsockopt = ccid3_hc_rx_getsockopt, 1225 .ccid_hc_rx_getsockopt = ccid3_hc_rx_getsockopt,
1211 .ccid_hc_tx_getsockopt = ccid3_hc_tx_getsockopt, 1226 .ccid_hc_tx_getsockopt = ccid3_hc_tx_getsockopt,
1212}; 1227};
1213 1228
1214#ifdef CONFIG_IP_DCCP_CCID3_DEBUG 1229#ifdef CONFIG_IP_DCCP_CCID3_DEBUG
1215module_param(ccid3_debug, int, 0444); 1230module_param(ccid3_debug, int, 0444);
1216MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); 1231MODULE_PARM_DESC(ccid3_debug, "Enable debug messages");
@@ -1233,7 +1248,7 @@ static __init int ccid3_module_init(void)
1233 goto out_free_tx; 1248 goto out_free_tx;
1234 1249
1235 rc = ccid_register(&ccid3); 1250 rc = ccid_register(&ccid3);
1236 if (rc != 0) 1251 if (rc != 0)
1237 goto out_free_loss_interval_history; 1252 goto out_free_loss_interval_history;
1238out: 1253out:
1239 return rc; 1254 return rc;
diff --git a/net/dccp/ccids/ccid3.h b/net/dccp/ccids/ccid3.h
index 07596d704ef9..15776a88c090 100644
--- a/net/dccp/ccids/ccid3.h
+++ b/net/dccp/ccids/ccid3.h
@@ -51,6 +51,16 @@
51/* Parameter t_mbi from [RFC 3448, 4.3]: backoff interval in seconds */ 51/* Parameter t_mbi from [RFC 3448, 4.3]: backoff interval in seconds */
52#define TFRC_T_MBI 64 52#define TFRC_T_MBI 64
53 53
54/* What we think is a reasonable upper limit on RTT values */
55#define CCID3_SANE_RTT_MAX ((suseconds_t)(4 * USEC_PER_SEC))
56
57#define CCID3_RTT_SANITY_CHECK(rtt) do { \
58 if (rtt > CCID3_SANE_RTT_MAX) { \
59 DCCP_CRIT("RTT (%d) too large, substituting %d", \
60 (int)rtt, (int)CCID3_SANE_RTT_MAX); \
61 rtt = CCID3_SANE_RTT_MAX; \
62 } } while (0)
63
54enum ccid3_options { 64enum ccid3_options {
55 TFRC_OPT_LOSS_EVENT_RATE = 192, 65 TFRC_OPT_LOSS_EVENT_RATE = 192,
56 TFRC_OPT_LOSS_INTERVALS = 193, 66 TFRC_OPT_LOSS_INTERVALS = 193,
@@ -67,7 +77,7 @@ struct ccid3_options_received {
67 77
68/* TFRC sender states */ 78/* TFRC sender states */
69enum ccid3_hc_tx_states { 79enum ccid3_hc_tx_states {
70 TFRC_SSTATE_NO_SENT = 1, 80 TFRC_SSTATE_NO_SENT = 1,
71 TFRC_SSTATE_NO_FBACK, 81 TFRC_SSTATE_NO_FBACK,
72 TFRC_SSTATE_FBACK, 82 TFRC_SSTATE_FBACK,
73 TFRC_SSTATE_TERM, 83 TFRC_SSTATE_TERM,
@@ -75,23 +85,23 @@ enum ccid3_hc_tx_states {
75 85
76/** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket 86/** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket
77 * 87 *
78 * @ccid3hctx_x - Current sending rate 88 * @ccid3hctx_x - Current sending rate in 64 * bytes per second
79 * @ccid3hctx_x_recv - Receive rate 89 * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second
80 * @ccid3hctx_x_calc - Calculated send rate (RFC 3448, 3.1) 90 * @ccid3hctx_x_calc - Calculated rate in bytes per second
81 * @ccid3hctx_rtt - Estimate of current round trip time in usecs 91 * @ccid3hctx_rtt - Estimate of current round trip time in usecs
82 * @ccid3hctx_p - Current loss event rate (0-1) scaled by 1000000 92 * @ccid3hctx_p - Current loss event rate (0-1) scaled by 1000000
83 * @ccid3hctx_s - Packet size 93 * @ccid3hctx_s - Packet size in bytes
84 * @ccid3hctx_t_rto - Retransmission Timeout (RFC 3448, 3.1) 94 * @ccid3hctx_t_rto - Nofeedback Timer setting in usecs
85 * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) 95 * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs
86 * @ccid3hctx_state - Sender state, one of %ccid3_hc_tx_states 96 * @ccid3hctx_state - Sender state, one of %ccid3_hc_tx_states
87 * @ccid3hctx_last_win_count - Last window counter sent 97 * @ccid3hctx_last_win_count - Last window counter sent
88 * @ccid3hctx_t_last_win_count - Timestamp of earliest packet 98 * @ccid3hctx_t_last_win_count - Timestamp of earliest packet
89 * with last_win_count value sent 99 * with last_win_count value sent
90 * @ccid3hctx_no_feedback_timer - Handle to no feedback timer 100 * @ccid3hctx_no_feedback_timer - Handle to no feedback timer
91 * @ccid3hctx_idle - Flag indicating that sender is idling 101 * @ccid3hctx_idle - Flag indicating that sender is idling
92 * @ccid3hctx_t_ld - Time last doubled during slow start 102 * @ccid3hctx_t_ld - Time last doubled during slow start
93 * @ccid3hctx_t_nom - Nominal send time of next packet 103 * @ccid3hctx_t_nom - Nominal send time of next packet
94 * @ccid3hctx_delta - Send timer delta 104 * @ccid3hctx_delta - Send timer delta (RFC 3448, 4.6) in usecs
95 * @ccid3hctx_hist - Packet history 105 * @ccid3hctx_hist - Packet history
96 * @ccid3hctx_options_received - Parsed set of retrieved options 106 * @ccid3hctx_options_received - Parsed set of retrieved options
97 */ 107 */
@@ -105,7 +115,7 @@ struct ccid3_hc_tx_sock {
105#define ccid3hctx_t_rto ccid3hctx_tfrc.tfrctx_rto 115#define ccid3hctx_t_rto ccid3hctx_tfrc.tfrctx_rto
106#define ccid3hctx_t_ipi ccid3hctx_tfrc.tfrctx_ipi 116#define ccid3hctx_t_ipi ccid3hctx_tfrc.tfrctx_ipi
107 u16 ccid3hctx_s; 117 u16 ccid3hctx_s;
108 enum ccid3_hc_tx_states ccid3hctx_state:8; 118 enum ccid3_hc_tx_states ccid3hctx_state:8;
109 u8 ccid3hctx_last_win_count; 119 u8 ccid3hctx_last_win_count;
110 u8 ccid3hctx_idle; 120 u8 ccid3hctx_idle;
111 struct timeval ccid3hctx_t_last_win_count; 121 struct timeval ccid3hctx_t_last_win_count;
@@ -119,7 +129,7 @@ struct ccid3_hc_tx_sock {
119 129
120/* TFRC receiver states */ 130/* TFRC receiver states */
121enum ccid3_hc_rx_states { 131enum ccid3_hc_rx_states {
122 TFRC_RSTATE_NO_DATA = 1, 132 TFRC_RSTATE_NO_DATA = 1,
123 TFRC_RSTATE_DATA, 133 TFRC_RSTATE_DATA,
124 TFRC_RSTATE_TERM = 127, 134 TFRC_RSTATE_TERM = 127,
125}; 135};
@@ -147,18 +157,18 @@ struct ccid3_hc_rx_sock {
147#define ccid3hcrx_x_recv ccid3hcrx_tfrc.tfrcrx_x_recv 157#define ccid3hcrx_x_recv ccid3hcrx_tfrc.tfrcrx_x_recv
148#define ccid3hcrx_rtt ccid3hcrx_tfrc.tfrcrx_rtt 158#define ccid3hcrx_rtt ccid3hcrx_tfrc.tfrcrx_rtt
149#define ccid3hcrx_p ccid3hcrx_tfrc.tfrcrx_p 159#define ccid3hcrx_p ccid3hcrx_tfrc.tfrcrx_p
150 u64 ccid3hcrx_seqno_nonloss:48, 160 u64 ccid3hcrx_seqno_nonloss:48,
151 ccid3hcrx_ccval_nonloss:4, 161 ccid3hcrx_ccval_nonloss:4,
152 ccid3hcrx_ccval_last_counter:4; 162 ccid3hcrx_ccval_last_counter:4;
153 enum ccid3_hc_rx_states ccid3hcrx_state:8; 163 enum ccid3_hc_rx_states ccid3hcrx_state:8;
154 u32 ccid3hcrx_bytes_recv; 164 u32 ccid3hcrx_bytes_recv;
155 struct timeval ccid3hcrx_tstamp_last_feedback; 165 struct timeval ccid3hcrx_tstamp_last_feedback;
156 struct timeval ccid3hcrx_tstamp_last_ack; 166 struct timeval ccid3hcrx_tstamp_last_ack;
157 struct list_head ccid3hcrx_hist; 167 struct list_head ccid3hcrx_hist;
158 struct list_head ccid3hcrx_li_hist; 168 struct list_head ccid3hcrx_li_hist;
159 u16 ccid3hcrx_s; 169 u16 ccid3hcrx_s;
160 u32 ccid3hcrx_pinv; 170 u32 ccid3hcrx_pinv;
161 u32 ccid3hcrx_elapsed_time; 171 u32 ccid3hcrx_elapsed_time;
162}; 172};
163 173
164static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk) 174static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
diff --git a/net/dccp/ccids/lib/packet_history.c b/net/dccp/ccids/lib/packet_history.c
index b876c9c81c65..2e8ef42721e2 100644
--- a/net/dccp/ccids/lib/packet_history.c
+++ b/net/dccp/ccids/lib/packet_history.c
@@ -36,9 +36,100 @@
36 36
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/string.h> 38#include <linux/string.h>
39
40#include "packet_history.h" 39#include "packet_history.h"
41 40
41/*
42 * Transmitter History Routines
43 */
44struct dccp_tx_hist *dccp_tx_hist_new(const char *name)
45{
46 struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
47 static const char dccp_tx_hist_mask[] = "tx_hist_%s";
48 char *slab_name;
49
50 if (hist == NULL)
51 goto out;
52
53 slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1,
54 GFP_ATOMIC);
55 if (slab_name == NULL)
56 goto out_free_hist;
57
58 sprintf(slab_name, dccp_tx_hist_mask, name);
59 hist->dccptxh_slab = kmem_cache_create(slab_name,
60 sizeof(struct dccp_tx_hist_entry),
61 0, SLAB_HWCACHE_ALIGN,
62 NULL, NULL);
63 if (hist->dccptxh_slab == NULL)
64 goto out_free_slab_name;
65out:
66 return hist;
67out_free_slab_name:
68 kfree(slab_name);
69out_free_hist:
70 kfree(hist);
71 hist = NULL;
72 goto out;
73}
74
75EXPORT_SYMBOL_GPL(dccp_tx_hist_new);
76
77void dccp_tx_hist_delete(struct dccp_tx_hist *hist)
78{
79 const char* name = kmem_cache_name(hist->dccptxh_slab);
80
81 kmem_cache_destroy(hist->dccptxh_slab);
82 kfree(name);
83 kfree(hist);
84}
85
86EXPORT_SYMBOL_GPL(dccp_tx_hist_delete);
87
88struct dccp_tx_hist_entry *
89 dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq)
90{
91 struct dccp_tx_hist_entry *packet = NULL, *entry;
92
93 list_for_each_entry(entry, list, dccphtx_node)
94 if (entry->dccphtx_seqno == seq) {
95 packet = entry;
96 break;
97 }
98
99 return packet;
100}
101
102EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry);
103
104void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list)
105{
106 struct dccp_tx_hist_entry *entry, *next;
107
108 list_for_each_entry_safe(entry, next, list, dccphtx_node) {
109 list_del_init(&entry->dccphtx_node);
110 dccp_tx_hist_entry_delete(hist, entry);
111 }
112}
113
114EXPORT_SYMBOL_GPL(dccp_tx_hist_purge);
115
116void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
117 struct list_head *list,
118 struct dccp_tx_hist_entry *packet)
119{
120 struct dccp_tx_hist_entry *next;
121
122 list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) {
123 list_del_init(&packet->dccphtx_node);
124 dccp_tx_hist_entry_delete(hist, packet);
125 }
126}
127
128EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older);
129
130/*
131 * Receiver History Routines
132 */
42struct dccp_rx_hist *dccp_rx_hist_new(const char *name) 133struct dccp_rx_hist *dccp_rx_hist_new(const char *name)
43{ 134{
44 struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); 135 struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
@@ -83,18 +174,24 @@ void dccp_rx_hist_delete(struct dccp_rx_hist *hist)
83 174
84EXPORT_SYMBOL_GPL(dccp_rx_hist_delete); 175EXPORT_SYMBOL_GPL(dccp_rx_hist_delete);
85 176
86void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list) 177int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
178 u8 *ccval)
87{ 179{
88 struct dccp_rx_hist_entry *entry, *next; 180 struct dccp_rx_hist_entry *packet = NULL, *entry;
89 181
90 list_for_each_entry_safe(entry, next, list, dccphrx_node) { 182 list_for_each_entry(entry, list, dccphrx_node)
91 list_del_init(&entry->dccphrx_node); 183 if (entry->dccphrx_seqno == seq) {
92 kmem_cache_free(hist->dccprxh_slab, entry); 184 packet = entry;
93 } 185 break;
94} 186 }
95 187
96EXPORT_SYMBOL_GPL(dccp_rx_hist_purge); 188 if (packet)
189 *ccval = packet->dccphrx_ccval;
97 190
191 return packet != NULL;
192}
193
194EXPORT_SYMBOL_GPL(dccp_rx_hist_find_entry);
98struct dccp_rx_hist_entry * 195struct dccp_rx_hist_entry *
99 dccp_rx_hist_find_data_packet(const struct list_head *list) 196 dccp_rx_hist_find_data_packet(const struct list_head *list)
100{ 197{
@@ -184,110 +281,18 @@ void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
184 281
185EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet); 282EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet);
186 283
187struct dccp_tx_hist *dccp_tx_hist_new(const char *name) 284void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list)
188{
189 struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
190 static const char dccp_tx_hist_mask[] = "tx_hist_%s";
191 char *slab_name;
192
193 if (hist == NULL)
194 goto out;
195
196 slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1,
197 GFP_ATOMIC);
198 if (slab_name == NULL)
199 goto out_free_hist;
200
201 sprintf(slab_name, dccp_tx_hist_mask, name);
202 hist->dccptxh_slab = kmem_cache_create(slab_name,
203 sizeof(struct dccp_tx_hist_entry),
204 0, SLAB_HWCACHE_ALIGN,
205 NULL, NULL);
206 if (hist->dccptxh_slab == NULL)
207 goto out_free_slab_name;
208out:
209 return hist;
210out_free_slab_name:
211 kfree(slab_name);
212out_free_hist:
213 kfree(hist);
214 hist = NULL;
215 goto out;
216}
217
218EXPORT_SYMBOL_GPL(dccp_tx_hist_new);
219
220void dccp_tx_hist_delete(struct dccp_tx_hist *hist)
221{
222 const char* name = kmem_cache_name(hist->dccptxh_slab);
223
224 kmem_cache_destroy(hist->dccptxh_slab);
225 kfree(name);
226 kfree(hist);
227}
228
229EXPORT_SYMBOL_GPL(dccp_tx_hist_delete);
230
231struct dccp_tx_hist_entry *
232 dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq)
233{
234 struct dccp_tx_hist_entry *packet = NULL, *entry;
235
236 list_for_each_entry(entry, list, dccphtx_node)
237 if (entry->dccphtx_seqno == seq) {
238 packet = entry;
239 break;
240 }
241
242 return packet;
243}
244
245EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry);
246
247int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
248 u8 *ccval)
249{
250 struct dccp_rx_hist_entry *packet = NULL, *entry;
251
252 list_for_each_entry(entry, list, dccphrx_node)
253 if (entry->dccphrx_seqno == seq) {
254 packet = entry;
255 break;
256 }
257
258 if (packet)
259 *ccval = packet->dccphrx_ccval;
260
261 return packet != NULL;
262}
263
264EXPORT_SYMBOL_GPL(dccp_rx_hist_find_entry);
265
266void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
267 struct list_head *list,
268 struct dccp_tx_hist_entry *packet)
269{ 285{
270 struct dccp_tx_hist_entry *next; 286 struct dccp_rx_hist_entry *entry, *next;
271 287
272 list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) { 288 list_for_each_entry_safe(entry, next, list, dccphrx_node) {
273 list_del_init(&packet->dccphtx_node); 289 list_del_init(&entry->dccphrx_node);
274 dccp_tx_hist_entry_delete(hist, packet); 290 kmem_cache_free(hist->dccprxh_slab, entry);
275 } 291 }
276} 292}
277 293
278EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older); 294EXPORT_SYMBOL_GPL(dccp_rx_hist_purge);
279
280void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list)
281{
282 struct dccp_tx_hist_entry *entry, *next;
283
284 list_for_each_entry_safe(entry, next, list, dccphtx_node) {
285 list_del_init(&entry->dccphtx_node);
286 dccp_tx_hist_entry_delete(hist, entry);
287 }
288}
289 295
290EXPORT_SYMBOL_GPL(dccp_tx_hist_purge);
291 296
292MODULE_AUTHOR("Ian McDonald <ian.mcdonald@jandi.co.nz>, " 297MODULE_AUTHOR("Ian McDonald <ian.mcdonald@jandi.co.nz>, "
293 "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); 298 "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
diff --git a/net/dccp/ccids/lib/packet_history.h b/net/dccp/ccids/lib/packet_history.h
index 9a8bcf224aa7..1f960c19ea1b 100644
--- a/net/dccp/ccids/lib/packet_history.h
+++ b/net/dccp/ccids/lib/packet_history.h
@@ -49,43 +49,27 @@
49#define TFRC_WIN_COUNT_PER_RTT 4 49#define TFRC_WIN_COUNT_PER_RTT 4
50#define TFRC_WIN_COUNT_LIMIT 16 50#define TFRC_WIN_COUNT_LIMIT 16
51 51
52/*
53 * Transmitter History data structures and declarations
54 */
52struct dccp_tx_hist_entry { 55struct dccp_tx_hist_entry {
53 struct list_head dccphtx_node; 56 struct list_head dccphtx_node;
54 u64 dccphtx_seqno:48, 57 u64 dccphtx_seqno:48,
55 dccphtx_ccval:4,
56 dccphtx_sent:1; 58 dccphtx_sent:1;
57 u32 dccphtx_rtt; 59 u32 dccphtx_rtt;
58 struct timeval dccphtx_tstamp; 60 struct timeval dccphtx_tstamp;
59}; 61};
60 62
61struct dccp_rx_hist_entry {
62 struct list_head dccphrx_node;
63 u64 dccphrx_seqno:48,
64 dccphrx_ccval:4,
65 dccphrx_type:4;
66 u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
67 struct timeval dccphrx_tstamp;
68};
69
70struct dccp_tx_hist { 63struct dccp_tx_hist {
71 struct kmem_cache *dccptxh_slab; 64 struct kmem_cache *dccptxh_slab;
72}; 65};
73 66
74extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name); 67extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
75extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist); 68extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist);
76
77struct dccp_rx_hist {
78 struct kmem_cache *dccprxh_slab;
79};
80
81extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
82extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
83extern struct dccp_rx_hist_entry *
84 dccp_rx_hist_find_data_packet(const struct list_head *list);
85 69
86static inline struct dccp_tx_hist_entry * 70static inline struct dccp_tx_hist_entry *
87 dccp_tx_hist_entry_new(struct dccp_tx_hist *hist, 71 dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
88 const gfp_t prio) 72 const gfp_t prio)
89{ 73{
90 struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab, 74 struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
91 prio); 75 prio);
@@ -96,18 +80,20 @@ static inline struct dccp_tx_hist_entry *
96 return entry; 80 return entry;
97} 81}
98 82
99static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist, 83static inline struct dccp_tx_hist_entry *
100 struct dccp_tx_hist_entry *entry) 84 dccp_tx_hist_head(struct list_head *list)
101{ 85{
102 if (entry != NULL) 86 struct dccp_tx_hist_entry *head = NULL;
103 kmem_cache_free(hist->dccptxh_slab, entry); 87
88 if (!list_empty(list))
89 head = list_entry(list->next, struct dccp_tx_hist_entry,
90 dccphtx_node);
91 return head;
104} 92}
105 93
106extern struct dccp_tx_hist_entry * 94extern struct dccp_tx_hist_entry *
107 dccp_tx_hist_find_entry(const struct list_head *list, 95 dccp_tx_hist_find_entry(const struct list_head *list,
108 const u64 seq); 96 const u64 seq);
109extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
110 u8 *ccval);
111 97
112static inline void dccp_tx_hist_add_entry(struct list_head *list, 98static inline void dccp_tx_hist_add_entry(struct list_head *list,
113 struct dccp_tx_hist_entry *entry) 99 struct dccp_tx_hist_entry *entry)
@@ -115,30 +101,45 @@ static inline void dccp_tx_hist_add_entry(struct list_head *list,
115 list_add(&entry->dccphtx_node, list); 101 list_add(&entry->dccphtx_node, list);
116} 102}
117 103
104static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
105 struct dccp_tx_hist_entry *entry)
106{
107 if (entry != NULL)
108 kmem_cache_free(hist->dccptxh_slab, entry);
109}
110
111extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
112 struct list_head *list);
113
118extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, 114extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
119 struct list_head *list, 115 struct list_head *list,
120 struct dccp_tx_hist_entry *next); 116 struct dccp_tx_hist_entry *next);
121 117
122extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist, 118/*
123 struct list_head *list); 119 * Receiver History data structures and declarations
120 */
121struct dccp_rx_hist_entry {
122 struct list_head dccphrx_node;
123 u64 dccphrx_seqno:48,
124 dccphrx_ccval:4,
125 dccphrx_type:4;
126 u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
127 struct timeval dccphrx_tstamp;
128};
124 129
125static inline struct dccp_tx_hist_entry * 130struct dccp_rx_hist {
126 dccp_tx_hist_head(struct list_head *list) 131 struct kmem_cache *dccprxh_slab;
127{ 132};
128 struct dccp_tx_hist_entry *head = NULL;
129 133
130 if (!list_empty(list)) 134extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
131 head = list_entry(list->next, struct dccp_tx_hist_entry, 135extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
132 dccphtx_node);
133 return head;
134}
135 136
136static inline struct dccp_rx_hist_entry * 137static inline struct dccp_rx_hist_entry *
137 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, 138 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
138 const struct sock *sk, 139 const struct sock *sk,
139 const u32 ndp, 140 const u32 ndp,
140 const struct sk_buff *skb, 141 const struct sk_buff *skb,
141 const gfp_t prio) 142 const gfp_t prio)
142{ 143{
143 struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab, 144 struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
144 prio); 145 prio);
@@ -156,18 +157,8 @@ static inline struct dccp_rx_hist_entry *
156 return entry; 157 return entry;
157} 158}
158 159
159static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
160 struct dccp_rx_hist_entry *entry)
161{
162 if (entry != NULL)
163 kmem_cache_free(hist->dccprxh_slab, entry);
164}
165
166extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
167 struct list_head *list);
168
169static inline struct dccp_rx_hist_entry * 160static inline struct dccp_rx_hist_entry *
170 dccp_rx_hist_head(struct list_head *list) 161 dccp_rx_hist_head(struct list_head *list)
171{ 162{
172 struct dccp_rx_hist_entry *head = NULL; 163 struct dccp_rx_hist_entry *head = NULL;
173 164
@@ -177,6 +168,27 @@ static inline struct dccp_rx_hist_entry *
177 return head; 168 return head;
178} 169}
179 170
171extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
172 u8 *ccval);
173extern struct dccp_rx_hist_entry *
174 dccp_rx_hist_find_data_packet(const struct list_head *list);
175
176extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
177 struct list_head *rx_list,
178 struct list_head *li_list,
179 struct dccp_rx_hist_entry *packet,
180 u64 nonloss_seqno);
181
182static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
183 struct dccp_rx_hist_entry *entry)
184{
185 if (entry != NULL)
186 kmem_cache_free(hist->dccprxh_slab, entry);
187}
188
189extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
190 struct list_head *list);
191
180static inline int 192static inline int
181 dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry) 193 dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
182{ 194{
@@ -184,12 +196,6 @@ static inline int
184 entry->dccphrx_type == DCCP_PKT_DATAACK; 196 entry->dccphrx_type == DCCP_PKT_DATAACK;
185} 197}
186 198
187extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
188 struct list_head *rx_list,
189 struct list_head *li_list,
190 struct dccp_rx_hist_entry *packet,
191 u64 nonloss_seqno);
192
193extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list, 199extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
194 struct list_head *li_list, u8 *win_loss); 200 struct list_head *li_list, u8 *win_loss);
195 201
diff --git a/net/dccp/ccids/lib/tfrc.h b/net/dccp/ccids/lib/tfrc.h
index 45f30f59ea2a..faf5f7e219e3 100644
--- a/net/dccp/ccids/lib/tfrc.h
+++ b/net/dccp/ccids/lib/tfrc.h
@@ -13,8 +13,29 @@
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
15 */ 15 */
16
17#include <linux/types.h> 16#include <linux/types.h>
17#include <asm/div64.h>
18
19/* integer-arithmetic divisions of type (a * 1000000)/b */
20static inline u64 scaled_div(u64 a, u32 b)
21{
22 BUG_ON(b==0);
23 a *= 1000000;
24 do_div(a, b);
25 return a;
26}
27
28static inline u32 scaled_div32(u64 a, u32 b)
29{
30 u64 result = scaled_div(a, b);
31
32 if (result > UINT_MAX) {
33 DCCP_CRIT("Overflow: a(%llu)/b(%u) > ~0U",
34 (unsigned long long)a, b);
35 return UINT_MAX;
36 }
37 return result;
38}
18 39
19extern u32 tfrc_calc_x(u16 s, u32 R, u32 p); 40extern u32 tfrc_calc_x(u16 s, u32 R, u32 p);
20extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue); 41extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue);
diff --git a/net/dccp/ccids/lib/tfrc_equation.c b/net/dccp/ccids/lib/tfrc_equation.c
index ddac2c511e2f..90009fd77e15 100644
--- a/net/dccp/ccids/lib/tfrc_equation.c
+++ b/net/dccp/ccids/lib/tfrc_equation.c
@@ -13,7 +13,6 @@
13 */ 13 */
14 14
15#include <linux/module.h> 15#include <linux/module.h>
16#include <asm/div64.h>
17#include "../../dccp.h" 16#include "../../dccp.h"
18#include "tfrc.h" 17#include "tfrc.h"
19 18
@@ -616,15 +615,12 @@ static inline u32 tfrc_binsearch(u32 fval, u8 small)
616 * @R: RTT scaled by 1000000 (i.e., microseconds) 615 * @R: RTT scaled by 1000000 (i.e., microseconds)
617 * @p: loss ratio estimate scaled by 1000000 616 * @p: loss ratio estimate scaled by 1000000
618 * Returns X_calc in bytes per second (not scaled). 617 * Returns X_calc in bytes per second (not scaled).
619 *
620 * Note: DO NOT alter this code unless you run test cases against it,
621 * as the code has been optimized to stop underflow/overflow.
622 */ 618 */
623u32 tfrc_calc_x(u16 s, u32 R, u32 p) 619u32 tfrc_calc_x(u16 s, u32 R, u32 p)
624{ 620{
625 int index; 621 u16 index;
626 u32 f; 622 u32 f;
627 u64 tmp1, tmp2; 623 u64 result;
628 624
629 /* check against invalid parameters and divide-by-zero */ 625 /* check against invalid parameters and divide-by-zero */
630 BUG_ON(p > 1000000); /* p must not exceed 100% */ 626 BUG_ON(p > 1000000); /* p must not exceed 100% */
@@ -650,15 +646,17 @@ u32 tfrc_calc_x(u16 s, u32 R, u32 p)
650 f = tfrc_calc_x_lookup[index][0]; 646 f = tfrc_calc_x_lookup[index][0];
651 } 647 }
652 648
653 /* The following computes X = s/(R*f(p)) in bytes per second. Since f(p) 649 /*
654 * and R are both scaled by 1000000, we need to multiply by 1000000^2. 650 * Compute X = s/(R*f(p)) in bytes per second.
655 * ==> DO NOT alter this unless you test against overflow on 32 bit */ 651 * Since f(p) and R are both scaled by 1000000, we need to multiply by
656 tmp1 = ((u64)s * 100000000); 652 * 1000000^2. To avoid overflow, the result is computed in two stages.
657 tmp2 = ((u64)R * (u64)f); 653 * This works under almost all reasonable operational conditions, for a
658 do_div(tmp2, 10000); 654 * wide range of parameters. Yet, should some strange combination of
659 do_div(tmp1, tmp2); 655 * parameters result in overflow, the use of scaled_div32 will catch
660 656 * this and return UINT_MAX - which is a logically adequate consequence.
661 return (u32)tmp1; 657 */
658 result = scaled_div(s, R);
659 return scaled_div32(result, f);
662} 660}
663 661
664EXPORT_SYMBOL_GPL(tfrc_calc_x); 662EXPORT_SYMBOL_GPL(tfrc_calc_x);
diff --git a/net/dccp/dccp.h b/net/dccp/dccp.h
index 68886986c8e4..a0900bf98e6b 100644
--- a/net/dccp/dccp.h
+++ b/net/dccp/dccp.h
@@ -80,8 +80,6 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo);
80 80
81#define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ 81#define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */
82 82
83#define DCCP_XMIT_TIMEO 30000 /* Time/msecs for blocking transmit per packet */
84
85/* sysctl variables for DCCP */ 83/* sysctl variables for DCCP */
86extern int sysctl_dccp_request_retries; 84extern int sysctl_dccp_request_retries;
87extern int sysctl_dccp_retries1; 85extern int sysctl_dccp_retries1;
@@ -434,6 +432,7 @@ static inline void timeval_sub_usecs(struct timeval *tv,
434 tv->tv_sec--; 432 tv->tv_sec--;
435 tv->tv_usec += USEC_PER_SEC; 433 tv->tv_usec += USEC_PER_SEC;
436 } 434 }
435 DCCP_BUG_ON(tv->tv_sec < 0);
437} 436}
438 437
439#ifdef CONFIG_SYSCTL 438#ifdef CONFIG_SYSCTL
diff --git a/net/dccp/feat.c b/net/dccp/feat.c
index 4dc487f27a1f..95b6927ec653 100644
--- a/net/dccp/feat.c
+++ b/net/dccp/feat.c
@@ -329,7 +329,7 @@ static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
329 switch (type) { 329 switch (type) {
330 case DCCPO_CHANGE_L: opt->dccpop_type = DCCPO_CONFIRM_R; break; 330 case DCCPO_CHANGE_L: opt->dccpop_type = DCCPO_CONFIRM_R; break;
331 case DCCPO_CHANGE_R: opt->dccpop_type = DCCPO_CONFIRM_L; break; 331 case DCCPO_CHANGE_R: opt->dccpop_type = DCCPO_CONFIRM_L; break;
332 default: DCCP_WARN("invalid type %d\n", type); return; 332 default: DCCP_WARN("invalid type %d\n", type); return;
333 333
334 } 334 }
335 opt->dccpop_feat = feature; 335 opt->dccpop_feat = feature;
@@ -427,7 +427,7 @@ int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
427 switch (type) { 427 switch (type) {
428 case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; 428 case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break;
429 case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; 429 case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break;
430 default: DCCP_WARN("invalid type %d\n", type); 430 default: DCCP_WARN("invalid type %d\n", type);
431 return 1; 431 return 1;
432 432
433 } 433 }
@@ -610,7 +610,7 @@ const char *dccp_feat_typename(const u8 type)
610 case DCCPO_CHANGE_R: return("ChangeR"); 610 case DCCPO_CHANGE_R: return("ChangeR");
611 case DCCPO_CONFIRM_R: return("ConfirmR"); 611 case DCCPO_CONFIRM_R: return("ConfirmR");
612 /* the following case must not appear in feature negotation */ 612 /* the following case must not appear in feature negotation */
613 default: dccp_pr_debug("unknown type %d [BUG!]\n", type); 613 default: dccp_pr_debug("unknown type %d [BUG!]\n", type);
614 } 614 }
615 return NULL; 615 return NULL;
616} 616}
diff --git a/net/dccp/input.c b/net/dccp/input.c
index 7371a2f3acf4..565bc80557ce 100644
--- a/net/dccp/input.c
+++ b/net/dccp/input.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * net/dccp/input.c 2 * net/dccp/input.c
3 * 3 *
4 * An implementation of the DCCP protocol 4 * An implementation of the DCCP protocol
5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * 6 *
@@ -82,7 +82,7 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
82 * Otherwise, 82 * Otherwise,
83 * Drop packet and return 83 * Drop packet and return
84 */ 84 */
85 if (dh->dccph_type == DCCP_PKT_SYNC || 85 if (dh->dccph_type == DCCP_PKT_SYNC ||
86 dh->dccph_type == DCCP_PKT_SYNCACK) { 86 dh->dccph_type == DCCP_PKT_SYNCACK) {
87 if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, 87 if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq,
88 dp->dccps_awl, dp->dccps_awh) && 88 dp->dccps_awl, dp->dccps_awh) &&
@@ -185,8 +185,8 @@ static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
185 dccp_rcv_close(sk, skb); 185 dccp_rcv_close(sk, skb);
186 return 0; 186 return 0;
187 case DCCP_PKT_REQUEST: 187 case DCCP_PKT_REQUEST:
188 /* Step 7 188 /* Step 7
189 * or (S.is_server and P.type == Response) 189 * or (S.is_server and P.type == Response)
190 * or (S.is_client and P.type == Request) 190 * or (S.is_client and P.type == Request)
191 * or (S.state >= OPEN and P.type == Request 191 * or (S.state >= OPEN and P.type == Request
192 * and P.seqno >= S.OSR) 192 * and P.seqno >= S.OSR)
@@ -248,8 +248,18 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
248 DCCP_ACKVEC_STATE_RECEIVED)) 248 DCCP_ACKVEC_STATE_RECEIVED))
249 goto discard; 249 goto discard;
250 250
251 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 251 /*
252 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 252 * Deliver to the CCID module in charge.
253 * FIXME: Currently DCCP operates one-directional only, i.e. a listening
254 * server is not at the same time a connecting client. There is
255 * not much sense in delivering to both rx/tx sides at the moment
256 * (only one is active at a time); when moving to bidirectional
257 * service, this needs to be revised.
258 */
259 if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER)
260 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
261 else
262 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
253 263
254 return __dccp_rcv_established(sk, skb, dh, len); 264 return __dccp_rcv_established(sk, skb, dh, len);
255discard: 265discard:
@@ -264,7 +274,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
264 const struct dccp_hdr *dh, 274 const struct dccp_hdr *dh,
265 const unsigned len) 275 const unsigned len)
266{ 276{
267 /* 277 /*
268 * Step 4: Prepare sequence numbers in REQUEST 278 * Step 4: Prepare sequence numbers in REQUEST
269 * If S.state == REQUEST, 279 * If S.state == REQUEST,
270 * If (P.type == Response or P.type == Reset) 280 * If (P.type == Response or P.type == Reset)
@@ -332,7 +342,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
332 * from the Response * / 342 * from the Response * /
333 * S.state := PARTOPEN 343 * S.state := PARTOPEN
334 * Set PARTOPEN timer 344 * Set PARTOPEN timer
335 * Continue with S.state == PARTOPEN 345 * Continue with S.state == PARTOPEN
336 * / * Step 12 will send the Ack completing the 346 * / * Step 12 will send the Ack completing the
337 * three-way handshake * / 347 * three-way handshake * /
338 */ 348 */
@@ -363,7 +373,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
363 */ 373 */
364 __kfree_skb(skb); 374 __kfree_skb(skb);
365 return 0; 375 return 0;
366 } 376 }
367 dccp_send_ack(sk); 377 dccp_send_ack(sk);
368 return -1; 378 return -1;
369 } 379 }
@@ -371,7 +381,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk,
371out_invalid_packet: 381out_invalid_packet:
372 /* dccp_v4_do_rcv will send a reset */ 382 /* dccp_v4_do_rcv will send a reset */
373 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR; 383 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR;
374 return 1; 384 return 1;
375} 385}
376 386
377static int dccp_rcv_respond_partopen_state_process(struct sock *sk, 387static int dccp_rcv_respond_partopen_state_process(struct sock *sk,
@@ -478,14 +488,17 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
478 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 488 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ)
479 dccp_event_ack_recv(sk, skb); 489 dccp_event_ack_recv(sk, skb);
480 490
481 if (dccp_msk(sk)->dccpms_send_ack_vector && 491 if (dccp_msk(sk)->dccpms_send_ack_vector &&
482 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 492 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk,
483 DCCP_SKB_CB(skb)->dccpd_seq, 493 DCCP_SKB_CB(skb)->dccpd_seq,
484 DCCP_ACKVEC_STATE_RECEIVED)) 494 DCCP_ACKVEC_STATE_RECEIVED))
485 goto discard; 495 goto discard;
486 496
487 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 497 /* XXX see the comments in dccp_rcv_established about this */
488 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 498 if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER)
499 ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb);
500 else
501 ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb);
489 } 502 }
490 503
491 /* 504 /*
@@ -567,7 +580,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
567 } 580 }
568 } 581 }
569 582
570 if (!queued) { 583 if (!queued) {
571discard: 584discard:
572 __kfree_skb(skb); 585 __kfree_skb(skb);
573 } 586 }
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index ff81679c9f17..90c74b4adb73 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -157,7 +157,7 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
157 /* We don't check in the destentry if pmtu discovery is forbidden 157 /* We don't check in the destentry if pmtu discovery is forbidden
158 * on this route. We just assume that no packet_to_big packets 158 * on this route. We just assume that no packet_to_big packets
159 * are send back when pmtu discovery is not active. 159 * are send back when pmtu discovery is not active.
160 * There is a small race when the user changes this flag in the 160 * There is a small race when the user changes this flag in the
161 * route, but I think that's acceptable. 161 * route, but I think that's acceptable.
162 */ 162 */
163 if ((dst = __sk_dst_check(sk, 0)) == NULL) 163 if ((dst = __sk_dst_check(sk, 0)) == NULL)
@@ -467,7 +467,7 @@ static struct dst_entry* dccp_v4_route_skb(struct sock *sk,
467 .uli_u = { .ports = 467 .uli_u = { .ports =
468 { .sport = dccp_hdr(skb)->dccph_dport, 468 { .sport = dccp_hdr(skb)->dccph_dport,
469 .dport = dccp_hdr(skb)->dccph_sport } 469 .dport = dccp_hdr(skb)->dccph_sport }
470 } 470 }
471 }; 471 };
472 472
473 security_skb_classify_flow(skb, &fl); 473 security_skb_classify_flow(skb, &fl);
@@ -595,7 +595,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
595 struct inet_request_sock *ireq; 595 struct inet_request_sock *ireq;
596 struct request_sock *req; 596 struct request_sock *req;
597 struct dccp_request_sock *dreq; 597 struct dccp_request_sock *dreq;
598 const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 598 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
599 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 599 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
600 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 600 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
601 601
@@ -609,7 +609,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
609 if (dccp_bad_service_code(sk, service)) { 609 if (dccp_bad_service_code(sk, service)) {
610 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; 610 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE;
611 goto drop; 611 goto drop;
612 } 612 }
613 /* 613 /*
614 * TW buckets are converted to open requests without 614 * TW buckets are converted to open requests without
615 * limitations, they conserve resources and peer is 615 * limitations, they conserve resources and peer is
@@ -644,7 +644,7 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
644 ireq->rmt_addr = skb->nh.iph->saddr; 644 ireq->rmt_addr = skb->nh.iph->saddr;
645 ireq->opt = NULL; 645 ireq->opt = NULL;
646 646
647 /* 647 /*
648 * Step 3: Process LISTEN state 648 * Step 3: Process LISTEN state
649 * 649 *
650 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie 650 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie
@@ -846,15 +846,15 @@ static int dccp_v4_rcv(struct sk_buff *skb)
846 } 846 }
847 847
848 /* Step 2: 848 /* Step 2:
849 * Look up flow ID in table and get corresponding socket */ 849 * Look up flow ID in table and get corresponding socket */
850 sk = __inet_lookup(&dccp_hashinfo, 850 sk = __inet_lookup(&dccp_hashinfo,
851 skb->nh.iph->saddr, dh->dccph_sport, 851 skb->nh.iph->saddr, dh->dccph_sport,
852 skb->nh.iph->daddr, dh->dccph_dport, 852 skb->nh.iph->daddr, dh->dccph_dport,
853 inet_iif(skb)); 853 inet_iif(skb));
854 854
855 /* 855 /*
856 * Step 2: 856 * Step 2:
857 * If no socket ... 857 * If no socket ...
858 */ 858 */
859 if (sk == NULL) { 859 if (sk == NULL) {
860 dccp_pr_debug("failed to look up flow ID in table and " 860 dccp_pr_debug("failed to look up flow ID in table and "
@@ -862,9 +862,9 @@ static int dccp_v4_rcv(struct sk_buff *skb)
862 goto no_dccp_socket; 862 goto no_dccp_socket;
863 } 863 }
864 864
865 /* 865 /*
866 * Step 2: 866 * Step 2:
867 * ... or S.state == TIMEWAIT, 867 * ... or S.state == TIMEWAIT,
868 * Generate Reset(No Connection) unless P.type == Reset 868 * Generate Reset(No Connection) unless P.type == Reset
869 * Drop packet and return 869 * Drop packet and return
870 */ 870 */
@@ -876,8 +876,8 @@ static int dccp_v4_rcv(struct sk_buff *skb)
876 876
877 /* 877 /*
878 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage 878 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage
879 * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 879 * o if MinCsCov = 0, only packets with CsCov = 0 are accepted
880 * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 880 * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov
881 */ 881 */
882 min_cov = dccp_sk(sk)->dccps_pcrlen; 882 min_cov = dccp_sk(sk)->dccps_pcrlen;
883 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) { 883 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) {
@@ -900,7 +900,7 @@ no_dccp_socket:
900 goto discard_it; 900 goto discard_it;
901 /* 901 /*
902 * Step 2: 902 * Step 2:
903 * If no socket ... 903 * If no socket ...
904 * Generate Reset(No Connection) unless P.type == Reset 904 * Generate Reset(No Connection) unless P.type == Reset
905 * Drop packet and return 905 * Drop packet and return
906 */ 906 */
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index c7aaa2574f52..6b91a9dd0411 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -77,7 +77,7 @@ static inline void dccp_v6_send_check(struct sock *sk, int unused_value,
77} 77}
78 78
79static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr, 79static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr,
80 __be16 sport, __be16 dport ) 80 __be16 sport, __be16 dport )
81{ 81{
82 return secure_tcpv6_sequence_number(saddr, daddr, sport, dport); 82 return secure_tcpv6_sequence_number(saddr, daddr, sport, dport);
83} 83}
@@ -329,7 +329,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
329 skb = alloc_skb(dccp_v6_ctl_socket->sk->sk_prot->max_header, 329 skb = alloc_skb(dccp_v6_ctl_socket->sk->sk_prot->max_header,
330 GFP_ATOMIC); 330 GFP_ATOMIC);
331 if (skb == NULL) 331 if (skb == NULL)
332 return; 332 return;
333 333
334 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header); 334 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);
335 335
@@ -353,7 +353,7 @@ static void dccp_v6_ctl_send_reset(struct sock *sk, struct sk_buff *rxskb)
353 353
354 dccp_csum_outgoing(skb); 354 dccp_csum_outgoing(skb);
355 dh->dccph_checksum = dccp_v6_csum_finish(skb, &rxskb->nh.ipv6h->saddr, 355 dh->dccph_checksum = dccp_v6_csum_finish(skb, &rxskb->nh.ipv6h->saddr,
356 &rxskb->nh.ipv6h->daddr); 356 &rxskb->nh.ipv6h->daddr);
357 357
358 memset(&fl, 0, sizeof(fl)); 358 memset(&fl, 0, sizeof(fl));
359 ipv6_addr_copy(&fl.fl6_dst, &rxskb->nh.ipv6h->saddr); 359 ipv6_addr_copy(&fl.fl6_dst, &rxskb->nh.ipv6h->saddr);
@@ -424,7 +424,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
424 struct dccp_request_sock *dreq; 424 struct dccp_request_sock *dreq;
425 struct inet6_request_sock *ireq6; 425 struct inet6_request_sock *ireq6;
426 struct ipv6_pinfo *np = inet6_sk(sk); 426 struct ipv6_pinfo *np = inet6_sk(sk);
427 const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 427 const __be32 service = dccp_hdr_request(skb)->dccph_req_service;
428 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 428 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb);
429 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 429 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY;
430 430
@@ -437,7 +437,7 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
437 if (dccp_bad_service_code(sk, service)) { 437 if (dccp_bad_service_code(sk, service)) {
438 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; 438 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE;
439 goto drop; 439 goto drop;
440 } 440 }
441 /* 441 /*
442 * There are no SYN attacks on IPv6, yet... 442 * There are no SYN attacks on IPv6, yet...
443 */ 443 */
@@ -787,7 +787,7 @@ static int dccp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
787 * otherwise we just shortcircuit this and continue with 787 * otherwise we just shortcircuit this and continue with
788 * the new socket.. 788 * the new socket..
789 */ 789 */
790 if (nsk != sk) { 790 if (nsk != sk) {
791 if (dccp_child_process(sk, nsk, skb)) 791 if (dccp_child_process(sk, nsk, skb))
792 goto reset; 792 goto reset;
793 if (opt_skb != NULL) 793 if (opt_skb != NULL)
@@ -843,14 +843,14 @@ static int dccp_v6_rcv(struct sk_buff **pskb)
843 DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb); 843 DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb);
844 844
845 /* Step 2: 845 /* Step 2:
846 * Look up flow ID in table and get corresponding socket */ 846 * Look up flow ID in table and get corresponding socket */
847 sk = __inet6_lookup(&dccp_hashinfo, &skb->nh.ipv6h->saddr, 847 sk = __inet6_lookup(&dccp_hashinfo, &skb->nh.ipv6h->saddr,
848 dh->dccph_sport, 848 dh->dccph_sport,
849 &skb->nh.ipv6h->daddr, ntohs(dh->dccph_dport), 849 &skb->nh.ipv6h->daddr, ntohs(dh->dccph_dport),
850 inet6_iif(skb)); 850 inet6_iif(skb));
851 /* 851 /*
852 * Step 2: 852 * Step 2:
853 * If no socket ... 853 * If no socket ...
854 */ 854 */
855 if (sk == NULL) { 855 if (sk == NULL) {
856 dccp_pr_debug("failed to look up flow ID in table and " 856 dccp_pr_debug("failed to look up flow ID in table and "
@@ -860,7 +860,7 @@ static int dccp_v6_rcv(struct sk_buff **pskb)
860 860
861 /* 861 /*
862 * Step 2: 862 * Step 2:
863 * ... or S.state == TIMEWAIT, 863 * ... or S.state == TIMEWAIT,
864 * Generate Reset(No Connection) unless P.type == Reset 864 * Generate Reset(No Connection) unless P.type == Reset
865 * Drop packet and return 865 * Drop packet and return
866 */ 866 */
@@ -872,8 +872,8 @@ static int dccp_v6_rcv(struct sk_buff **pskb)
872 872
873 /* 873 /*
874 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage 874 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage
875 * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 875 * o if MinCsCov = 0, only packets with CsCov = 0 are accepted
876 * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 876 * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov
877 */ 877 */
878 min_cov = dccp_sk(sk)->dccps_pcrlen; 878 min_cov = dccp_sk(sk)->dccps_pcrlen;
879 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) { 879 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) {
@@ -893,7 +893,7 @@ no_dccp_socket:
893 goto discard_it; 893 goto discard_it;
894 /* 894 /*
895 * Step 2: 895 * Step 2:
896 * If no socket ... 896 * If no socket ...
897 * Generate Reset(No Connection) unless P.type == Reset 897 * Generate Reset(No Connection) unless P.type == Reset
898 * Drop packet and return 898 * Drop packet and return
899 */ 899 */
diff --git a/net/dccp/minisocks.c b/net/dccp/minisocks.c
index 4c9e26775f72..6656bb497c7b 100644
--- a/net/dccp/minisocks.c
+++ b/net/dccp/minisocks.c
@@ -182,7 +182,7 @@ out_free:
182 182
183EXPORT_SYMBOL_GPL(dccp_create_openreq_child); 183EXPORT_SYMBOL_GPL(dccp_create_openreq_child);
184 184
185/* 185/*
186 * Process an incoming packet for RESPOND sockets represented 186 * Process an incoming packet for RESPOND sockets represented
187 * as an request_sock. 187 * as an request_sock.
188 */ 188 */
diff --git a/net/dccp/options.c b/net/dccp/options.c
index f398b43bc055..c03ba61eb6da 100644
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -557,11 +557,6 @@ int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
557 return -1; 557 return -1;
558 dp->dccps_hc_rx_insert_options = 0; 558 dp->dccps_hc_rx_insert_options = 0;
559 } 559 }
560 if (dp->dccps_hc_tx_insert_options) {
561 if (ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb))
562 return -1;
563 dp->dccps_hc_tx_insert_options = 0;
564 }
565 560
566 /* Feature negotiation */ 561 /* Feature negotiation */
567 /* Data packets can't do feat negotiation */ 562 /* Data packets can't do feat negotiation */
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 400c30b6fcae..824569659083 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * net/dccp/output.c 2 * net/dccp/output.c
3 * 3 *
4 * An implementation of the DCCP protocol 4 * An implementation of the DCCP protocol
5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * 6 *
@@ -175,14 +175,12 @@ void dccp_write_space(struct sock *sk)
175/** 175/**
176 * dccp_wait_for_ccid - Wait for ccid to tell us we can send a packet 176 * dccp_wait_for_ccid - Wait for ccid to tell us we can send a packet
177 * @sk: socket to wait for 177 * @sk: socket to wait for
178 * @timeo: for how long
179 */ 178 */
180static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb, 179static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb)
181 long *timeo)
182{ 180{
183 struct dccp_sock *dp = dccp_sk(sk); 181 struct dccp_sock *dp = dccp_sk(sk);
184 DEFINE_WAIT(wait); 182 DEFINE_WAIT(wait);
185 long delay; 183 unsigned long delay;
186 int rc; 184 int rc;
187 185
188 while (1) { 186 while (1) {
@@ -190,8 +188,6 @@ static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb,
190 188
191 if (sk->sk_err) 189 if (sk->sk_err)
192 goto do_error; 190 goto do_error;
193 if (!*timeo)
194 goto do_nonblock;
195 if (signal_pending(current)) 191 if (signal_pending(current))
196 goto do_interrupted; 192 goto do_interrupted;
197 193
@@ -199,12 +195,9 @@ static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb,
199 if (rc <= 0) 195 if (rc <= 0)
200 break; 196 break;
201 delay = msecs_to_jiffies(rc); 197 delay = msecs_to_jiffies(rc);
202 if (delay > *timeo || delay < 0)
203 goto do_nonblock;
204
205 sk->sk_write_pending++; 198 sk->sk_write_pending++;
206 release_sock(sk); 199 release_sock(sk);
207 *timeo -= schedule_timeout(delay); 200 schedule_timeout(delay);
208 lock_sock(sk); 201 lock_sock(sk);
209 sk->sk_write_pending--; 202 sk->sk_write_pending--;
210 } 203 }
@@ -215,11 +208,8 @@ out:
215do_error: 208do_error:
216 rc = -EPIPE; 209 rc = -EPIPE;
217 goto out; 210 goto out;
218do_nonblock:
219 rc = -EAGAIN;
220 goto out;
221do_interrupted: 211do_interrupted:
222 rc = sock_intr_errno(*timeo); 212 rc = -EINTR;
223 goto out; 213 goto out;
224} 214}
225 215
@@ -240,8 +230,6 @@ void dccp_write_xmit(struct sock *sk, int block)
240{ 230{
241 struct dccp_sock *dp = dccp_sk(sk); 231 struct dccp_sock *dp = dccp_sk(sk);
242 struct sk_buff *skb; 232 struct sk_buff *skb;
243 long timeo = DCCP_XMIT_TIMEO; /* If a packet is taking longer than
244 this we have other issues */
245 233
246 while ((skb = skb_peek(&sk->sk_write_queue))) { 234 while ((skb = skb_peek(&sk->sk_write_queue))) {
247 int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb); 235 int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb);
@@ -251,11 +239,9 @@ void dccp_write_xmit(struct sock *sk, int block)
251 sk_reset_timer(sk, &dp->dccps_xmit_timer, 239 sk_reset_timer(sk, &dp->dccps_xmit_timer,
252 msecs_to_jiffies(err)+jiffies); 240 msecs_to_jiffies(err)+jiffies);
253 break; 241 break;
254 } else { 242 } else
255 err = dccp_wait_for_ccid(sk, skb, &timeo); 243 err = dccp_wait_for_ccid(sk, skb);
256 timeo = DCCP_XMIT_TIMEO; 244 if (err && err != -EINTR)
257 }
258 if (err)
259 DCCP_BUG("err=%d after dccp_wait_for_ccid", err); 245 DCCP_BUG("err=%d after dccp_wait_for_ccid", err);
260 } 246 }
261 247
@@ -281,8 +267,10 @@ void dccp_write_xmit(struct sock *sk, int block)
281 if (err) 267 if (err)
282 DCCP_BUG("err=%d after ccid_hc_tx_packet_sent", 268 DCCP_BUG("err=%d after ccid_hc_tx_packet_sent",
283 err); 269 err);
284 } else 270 } else {
271 dccp_pr_debug("packet discarded\n");
285 kfree(skb); 272 kfree(skb);
273 }
286 } 274 }
287} 275}
288 276
@@ -350,7 +338,6 @@ EXPORT_SYMBOL_GPL(dccp_make_response);
350 338
351static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst, 339static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
352 const enum dccp_reset_codes code) 340 const enum dccp_reset_codes code)
353
354{ 341{
355 struct dccp_hdr *dh; 342 struct dccp_hdr *dh;
356 struct dccp_sock *dp = dccp_sk(sk); 343 struct dccp_sock *dp = dccp_sk(sk);
@@ -431,14 +418,14 @@ static inline void dccp_connect_init(struct sock *sk)
431 418
432 dccp_sync_mss(sk, dst_mtu(dst)); 419 dccp_sync_mss(sk, dst_mtu(dst));
433 420
434 /* 421 /*
435 * SWL and AWL are initially adjusted so that they are not less than 422 * SWL and AWL are initially adjusted so that they are not less than
436 * the initial Sequence Numbers received and sent, respectively: 423 * the initial Sequence Numbers received and sent, respectively:
437 * SWL := max(GSR + 1 - floor(W/4), ISR), 424 * SWL := max(GSR + 1 - floor(W/4), ISR),
438 * AWL := max(GSS - W' + 1, ISS). 425 * AWL := max(GSS - W' + 1, ISS).
439 * These adjustments MUST be applied only at the beginning of the 426 * These adjustments MUST be applied only at the beginning of the
440 * connection. 427 * connection.
441 */ 428 */
442 dccp_update_gss(sk, dp->dccps_iss); 429 dccp_update_gss(sk, dp->dccps_iss);
443 dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss)); 430 dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss));
444 431
diff --git a/net/dccp/proto.c b/net/dccp/proto.c
index 5ec47d9ee447..63b3fa20e14b 100644
--- a/net/dccp/proto.c
+++ b/net/dccp/proto.c
@@ -196,7 +196,7 @@ int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
196 sk, GFP_KERNEL); 196 sk, GFP_KERNEL);
197 dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid, 197 dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid,
198 sk, GFP_KERNEL); 198 sk, GFP_KERNEL);
199 if (unlikely(dp->dccps_hc_rx_ccid == NULL || 199 if (unlikely(dp->dccps_hc_rx_ccid == NULL ||
200 dp->dccps_hc_tx_ccid == NULL)) { 200 dp->dccps_hc_tx_ccid == NULL)) {
201 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); 201 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
202 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); 202 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
@@ -390,7 +390,7 @@ static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
390 struct dccp_sock *dp = dccp_sk(sk); 390 struct dccp_sock *dp = dccp_sk(sk);
391 struct dccp_service_list *sl = NULL; 391 struct dccp_service_list *sl = NULL;
392 392
393 if (service == DCCP_SERVICE_INVALID_VALUE || 393 if (service == DCCP_SERVICE_INVALID_VALUE ||
394 optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32)) 394 optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32))
395 return -EINVAL; 395 return -EINVAL;
396 396
@@ -830,7 +830,7 @@ EXPORT_SYMBOL_GPL(inet_dccp_listen);
830static const unsigned char dccp_new_state[] = { 830static const unsigned char dccp_new_state[] = {
831 /* current state: new state: action: */ 831 /* current state: new state: action: */
832 [0] = DCCP_CLOSED, 832 [0] = DCCP_CLOSED,
833 [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 833 [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN,
834 [DCCP_REQUESTING] = DCCP_CLOSED, 834 [DCCP_REQUESTING] = DCCP_CLOSED,
835 [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 835 [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN,
836 [DCCP_LISTEN] = DCCP_CLOSED, 836 [DCCP_LISTEN] = DCCP_CLOSED,
diff --git a/net/dccp/timer.c b/net/dccp/timer.c
index e8f519e7f481..e5348f369c60 100644
--- a/net/dccp/timer.c
+++ b/net/dccp/timer.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * net/dccp/timer.c 2 * net/dccp/timer.c
3 * 3 *
4 * An implementation of the DCCP protocol 4 * An implementation of the DCCP protocol
5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
6 * 6 *
@@ -102,13 +102,13 @@ static void dccp_retransmit_timer(struct sock *sk)
102 * sk->sk_send_head has to have one skb with 102 * sk->sk_send_head has to have one skb with
103 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP 103 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP
104 * packet types. The only packets eligible for retransmission are: 104 * packet types. The only packets eligible for retransmission are:
105 * -- Requests in client-REQUEST state (sec. 8.1.1) 105 * -- Requests in client-REQUEST state (sec. 8.1.1)
106 * -- Acks in client-PARTOPEN state (sec. 8.1.5) 106 * -- Acks in client-PARTOPEN state (sec. 8.1.5)
107 * -- CloseReq in server-CLOSEREQ state (sec. 8.3) 107 * -- CloseReq in server-CLOSEREQ state (sec. 8.3)
108 * -- Close in node-CLOSING state (sec. 8.3) */ 108 * -- Close in node-CLOSING state (sec. 8.3) */
109 BUG_TRAP(sk->sk_send_head != NULL); 109 BUG_TRAP(sk->sk_send_head != NULL);
110 110
111 /* 111 /*
112 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was 112 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was
113 * sent, no need to retransmit, this sock is dead. 113 * sent, no need to retransmit, this sock is dead.
114 */ 114 */
@@ -200,7 +200,7 @@ static void dccp_keepalive_timer(unsigned long data)
200 /* Only process if socket is not in use. */ 200 /* Only process if socket is not in use. */
201 bh_lock_sock(sk); 201 bh_lock_sock(sk);
202 if (sock_owned_by_user(sk)) { 202 if (sock_owned_by_user(sk)) {
203 /* Try again later. */ 203 /* Try again later. */
204 inet_csk_reset_keepalive_timer(sk, HZ / 20); 204 inet_csk_reset_keepalive_timer(sk, HZ / 20);
205 goto out; 205 goto out;
206 } 206 }
diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
index 0b9d4c955154..fc6f3c023a54 100644
--- a/net/decnet/dn_dev.c
+++ b/net/decnet/dn_dev.c
@@ -167,8 +167,7 @@ static int dn_forwarding_proc(ctl_table *, int, struct file *,
167 void __user *, size_t *, loff_t *); 167 void __user *, size_t *, loff_t *);
168static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen, 168static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
169 void __user *oldval, size_t __user *oldlenp, 169 void __user *oldval, size_t __user *oldlenp,
170 void __user *newval, size_t newlen, 170 void __user *newval, size_t newlen);
171 void **context);
172 171
173static struct dn_dev_sysctl_table { 172static struct dn_dev_sysctl_table {
174 struct ctl_table_header *sysctl_header; 173 struct ctl_table_header *sysctl_header;
@@ -347,8 +346,7 @@ static int dn_forwarding_proc(ctl_table *table, int write,
347 346
348static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen, 347static int dn_forwarding_sysctl(ctl_table *table, int __user *name, int nlen,
349 void __user *oldval, size_t __user *oldlenp, 348 void __user *oldval, size_t __user *oldlenp,
350 void __user *newval, size_t newlen, 349 void __user *newval, size_t newlen)
351 void **context)
352{ 350{
353#ifdef CONFIG_DECNET_ROUTER 351#ifdef CONFIG_DECNET_ROUTER
354 struct net_device *dev = table->extra1; 352 struct net_device *dev = table->extra1;
diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
index e246f054f368..a4065eb1341e 100644
--- a/net/decnet/sysctl_net_decnet.c
+++ b/net/decnet/sysctl_net_decnet.c
@@ -134,8 +134,7 @@ static int parse_addr(__le16 *addr, char *str)
134 134
135static int dn_node_address_strategy(ctl_table *table, int __user *name, int nlen, 135static int dn_node_address_strategy(ctl_table *table, int __user *name, int nlen,
136 void __user *oldval, size_t __user *oldlenp, 136 void __user *oldval, size_t __user *oldlenp,
137 void __user *newval, size_t newlen, 137 void __user *newval, size_t newlen)
138 void **context)
139{ 138{
140 size_t len; 139 size_t len;
141 __le16 addr; 140 __le16 addr;
@@ -220,8 +219,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
220 219
221static int dn_def_dev_strategy(ctl_table *table, int __user *name, int nlen, 220static int dn_def_dev_strategy(ctl_table *table, int __user *name, int nlen,
222 void __user *oldval, size_t __user *oldlenp, 221 void __user *oldval, size_t __user *oldlenp,
223 void __user *newval, size_t newlen, 222 void __user *newval, size_t newlen)
224 void **context)
225{ 223{
226 size_t len; 224 size_t len;
227 struct net_device *dev; 225 struct net_device *dev;
diff --git a/net/ieee80211/softmac/ieee80211softmac_assoc.c b/net/ieee80211/softmac/ieee80211softmac_assoc.c
index eec1a1dd91da..e3f37fdda65f 100644
--- a/net/ieee80211/softmac/ieee80211softmac_assoc.c
+++ b/net/ieee80211/softmac/ieee80211softmac_assoc.c
@@ -438,7 +438,7 @@ ieee80211softmac_try_reassoc(struct ieee80211softmac_device *mac)
438 438
439 spin_lock_irqsave(&mac->lock, flags); 439 spin_lock_irqsave(&mac->lock, flags);
440 mac->associnfo.associating = 1; 440 mac->associnfo.associating = 1;
441 schedule_work(&mac->associnfo.work); 441 schedule_delayed_work(&mac->associnfo.work, 0);
442 spin_unlock_irqrestore(&mac->lock, flags); 442 spin_unlock_irqrestore(&mac->lock, flags);
443} 443}
444 444
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 2fd899160f85..84bed40273ad 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1303,8 +1303,7 @@ int ipv4_doint_and_flush(ctl_table *ctl, int write,
1303 1303
1304int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen, 1304int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
1305 void __user *oldval, size_t __user *oldlenp, 1305 void __user *oldval, size_t __user *oldlenp,
1306 void __user *newval, size_t newlen, 1306 void __user *newval, size_t newlen)
1307 void **context)
1308{ 1307{
1309 int *valp = table->data; 1308 int *valp = table->data;
1310 int new; 1309 int new;
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index a35209d517ad..f071f84808fa 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -164,7 +164,6 @@ EXPORT_SYMBOL_GPL(ip_build_and_send_pkt);
164static inline int ip_finish_output2(struct sk_buff *skb) 164static inline int ip_finish_output2(struct sk_buff *skb)
165{ 165{
166 struct dst_entry *dst = skb->dst; 166 struct dst_entry *dst = skb->dst;
167 struct hh_cache *hh = dst->hh;
168 struct net_device *dev = dst->dev; 167 struct net_device *dev = dst->dev;
169 int hh_len = LL_RESERVED_SPACE(dev); 168 int hh_len = LL_RESERVED_SPACE(dev);
170 169
@@ -183,16 +182,9 @@ static inline int ip_finish_output2(struct sk_buff *skb)
183 skb = skb2; 182 skb = skb2;
184 } 183 }
185 184
186 if (hh) { 185 if (dst->hh)
187 int hh_alen; 186 return neigh_hh_output(dst->hh, skb);
188 187 else if (dst->neighbour)
189 read_lock_bh(&hh->hh_lock);
190 hh_alen = HH_DATA_ALIGN(hh->hh_len);
191 memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
192 read_unlock_bh(&hh->hh_lock);
193 skb_push(skb, hh->hh_len);
194 return hh->hh_output(skb);
195 } else if (dst->neighbour)
196 return dst->neighbour->output(skb); 188 return dst->neighbour->output(skb);
197 189
198 if (net_ratelimit()) 190 if (net_ratelimit())
diff --git a/net/ipv4/ipvs/ip_vs_sync.c b/net/ipv4/ipvs/ip_vs_sync.c
index 91a075edd68e..7ea2d981a932 100644
--- a/net/ipv4/ipvs/ip_vs_sync.c
+++ b/net/ipv4/ipvs/ip_vs_sync.c
@@ -657,7 +657,7 @@ static void sync_master_loop(void)
657 if (stop_master_sync) 657 if (stop_master_sync)
658 break; 658 break;
659 659
660 ssleep(1); 660 msleep_interruptible(1000);
661 } 661 }
662 662
663 /* clean up the sync_buff queue */ 663 /* clean up the sync_buff queue */
@@ -714,7 +714,7 @@ static void sync_backup_loop(void)
714 if (stop_backup_sync) 714 if (stop_backup_sync)
715 break; 715 break;
716 716
717 ssleep(1); 717 msleep_interruptible(1000);
718 } 718 }
719 719
720 /* release the sending multicast socket */ 720 /* release the sending multicast socket */
@@ -826,7 +826,7 @@ static int fork_sync_thread(void *startup)
826 if ((pid = kernel_thread(sync_thread, startup, 0)) < 0) { 826 if ((pid = kernel_thread(sync_thread, startup, 0)) < 0) {
827 IP_VS_ERR("could not create sync_thread due to %d... " 827 IP_VS_ERR("could not create sync_thread due to %d... "
828 "retrying.\n", pid); 828 "retrying.\n", pid);
829 ssleep(1); 829 msleep_interruptible(1000);
830 goto repeat; 830 goto repeat;
831 } 831 }
832 832
@@ -849,10 +849,12 @@ int start_sync_thread(int state, char *mcast_ifn, __u8 syncid)
849 849
850 ip_vs_sync_state |= state; 850 ip_vs_sync_state |= state;
851 if (state == IP_VS_STATE_MASTER) { 851 if (state == IP_VS_STATE_MASTER) {
852 strlcpy(ip_vs_master_mcast_ifn, mcast_ifn, sizeof(ip_vs_master_mcast_ifn)); 852 strlcpy(ip_vs_master_mcast_ifn, mcast_ifn,
853 sizeof(ip_vs_master_mcast_ifn));
853 ip_vs_master_syncid = syncid; 854 ip_vs_master_syncid = syncid;
854 } else { 855 } else {
855 strlcpy(ip_vs_backup_mcast_ifn, mcast_ifn, sizeof(ip_vs_backup_mcast_ifn)); 856 strlcpy(ip_vs_backup_mcast_ifn, mcast_ifn,
857 sizeof(ip_vs_backup_mcast_ifn));
856 ip_vs_backup_syncid = syncid; 858 ip_vs_backup_syncid = syncid;
857 } 859 }
858 860
@@ -860,7 +862,7 @@ int start_sync_thread(int state, char *mcast_ifn, __u8 syncid)
860 if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) { 862 if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) {
861 IP_VS_ERR("could not create fork_sync_thread due to %d... " 863 IP_VS_ERR("could not create fork_sync_thread due to %d... "
862 "retrying.\n", pid); 864 "retrying.\n", pid);
863 ssleep(1); 865 msleep_interruptible(1000);
864 goto repeat; 866 goto repeat;
865 } 867 }
866 868
@@ -880,7 +882,8 @@ int stop_sync_thread(int state)
880 882
881 IP_VS_DBG(7, "%s: pid %d\n", __FUNCTION__, current->pid); 883 IP_VS_DBG(7, "%s: pid %d\n", __FUNCTION__, current->pid);
882 IP_VS_INFO("stopping sync thread %d ...\n", 884 IP_VS_INFO("stopping sync thread %d ...\n",
883 (state == IP_VS_STATE_MASTER) ? sync_master_pid : sync_backup_pid); 885 (state == IP_VS_STATE_MASTER) ?
886 sync_master_pid : sync_backup_pid);
884 887
885 __set_current_state(TASK_UNINTERRUPTIBLE); 888 __set_current_state(TASK_UNINTERRUPTIBLE);
886 add_wait_queue(&stop_sync_wait, &wait); 889 add_wait_queue(&stop_sync_wait, &wait);
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
index 098365062234..fef56ae61abe 100644
--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
@@ -683,7 +683,7 @@ static ssize_t clusterip_proc_write(struct file *file, const char __user *input,
683{ 683{
684#define PROC_WRITELEN 10 684#define PROC_WRITELEN 10
685 char buffer[PROC_WRITELEN+1]; 685 char buffer[PROC_WRITELEN+1];
686 struct proc_dir_entry *pde = PDE(file->f_dentry->d_inode); 686 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
687 struct clusterip_config *c = pde->data; 687 struct clusterip_config *c = pde->data;
688 unsigned long nodenum; 688 unsigned long nodenum;
689 689
diff --git a/net/ipv4/netfilter/ipt_recent.c b/net/ipv4/netfilter/ipt_recent.c
index 126db44e71a8..4db0e73c56f1 100644
--- a/net/ipv4/netfilter/ipt_recent.c
+++ b/net/ipv4/netfilter/ipt_recent.c
@@ -401,7 +401,7 @@ static int recent_seq_open(struct inode *inode, struct file *file)
401static ssize_t recent_proc_write(struct file *file, const char __user *input, 401static ssize_t recent_proc_write(struct file *file, const char __user *input,
402 size_t size, loff_t *loff) 402 size_t size, loff_t *loff)
403{ 403{
404 struct proc_dir_entry *pde = PDE(file->f_dentry->d_inode); 404 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
405 struct recent_table *t = pde->data; 405 struct recent_table *t = pde->data;
406 struct recent_entry *e; 406 struct recent_entry *e;
407 char buf[sizeof("+255.255.255.255")], *c = buf; 407 char buf[sizeof("+255.255.255.255")], *c = buf;
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 11c167118e87..1aaff0a2e098 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2872,8 +2872,7 @@ static int ipv4_sysctl_rtcache_flush_strategy(ctl_table *table,
2872 void __user *oldval, 2872 void __user *oldval,
2873 size_t __user *oldlenp, 2873 size_t __user *oldlenp,
2874 void __user *newval, 2874 void __user *newval,
2875 size_t newlen, 2875 size_t newlen)
2876 void **context)
2877{ 2876{
2878 int delay; 2877 int delay;
2879 if (newlen != sizeof(int)) 2878 if (newlen != sizeof(int))
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index dfcf47f10f88..fabf69a9108c 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -51,8 +51,7 @@ int ipv4_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
51static int ipv4_sysctl_forward_strategy(ctl_table *table, 51static int ipv4_sysctl_forward_strategy(ctl_table *table,
52 int __user *name, int nlen, 52 int __user *name, int nlen,
53 void __user *oldval, size_t __user *oldlenp, 53 void __user *oldval, size_t __user *oldlenp,
54 void __user *newval, size_t newlen, 54 void __user *newval, size_t newlen)
55 void **context)
56{ 55{
57 int *valp = table->data; 56 int *valp = table->data;
58 int new; 57 int new;
@@ -111,8 +110,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write, struct file *
111static int sysctl_tcp_congestion_control(ctl_table *table, int __user *name, 110static int sysctl_tcp_congestion_control(ctl_table *table, int __user *name,
112 int nlen, void __user *oldval, 111 int nlen, void __user *oldval,
113 size_t __user *oldlenp, 112 size_t __user *oldlenp,
114 void __user *newval, size_t newlen, 113 void __user *newval, size_t newlen)
115 void **context)
116{ 114{
117 char val[TCP_CA_NAME_MAX]; 115 char val[TCP_CA_NAME_MAX];
118 ctl_table tbl = { 116 ctl_table tbl = {
@@ -122,8 +120,7 @@ static int sysctl_tcp_congestion_control(ctl_table *table, int __user *name,
122 int ret; 120 int ret;
123 121
124 tcp_get_default_congestion_control(val); 122 tcp_get_default_congestion_control(val);
125 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen, 123 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen);
126 context);
127 if (ret == 0 && newval && newlen) 124 if (ret == 0 && newval && newlen)
128 ret = tcp_set_default_congestion_control(val); 125 ret = tcp_set_default_congestion_control(val);
129 return ret; 126 return ret;
@@ -169,8 +166,8 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
169static int strategy_allowed_congestion_control(ctl_table *table, int __user *name, 166static int strategy_allowed_congestion_control(ctl_table *table, int __user *name,
170 int nlen, void __user *oldval, 167 int nlen, void __user *oldval,
171 size_t __user *oldlenp, 168 size_t __user *oldlenp,
172 void __user *newval, size_t newlen, 169 void __user *newval,
173 void **context) 170 size_t newlen)
174{ 171{
175 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX }; 172 ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
176 int ret; 173 int ret;
@@ -180,8 +177,7 @@ static int strategy_allowed_congestion_control(ctl_table *table, int __user *nam
180 return -ENOMEM; 177 return -ENOMEM;
181 178
182 tcp_get_available_congestion_control(tbl.data, tbl.maxlen); 179 tcp_get_available_congestion_control(tbl.data, tbl.maxlen);
183 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen, 180 ret = sysctl_string(&tbl, name, nlen, oldval, oldlenp, newval, newlen);
184 context);
185 if (ret == 0 && newval && newlen) 181 if (ret == 0 && newval && newlen)
186 ret = tcp_set_allowed_congestion_control(tbl.data); 182 ret = tcp_set_allowed_congestion_control(tbl.data);
187 kfree(tbl.data); 183 kfree(tbl.data);
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index a5e8d207a51b..9b0a90643151 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3656,8 +3656,7 @@ static int addrconf_sysctl_forward_strategy(ctl_table *table,
3656 int __user *name, int nlen, 3656 int __user *name, int nlen,
3657 void __user *oldval, 3657 void __user *oldval,
3658 size_t __user *oldlenp, 3658 size_t __user *oldlenp,
3659 void __user *newval, size_t newlen, 3659 void __user *newval, size_t newlen)
3660 void **context)
3661{ 3660{
3662 int *valp = table->data; 3661 int *valp = table->data;
3663 int new; 3662 int new;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index e9212c7ff5cf..7b7bd44fbf47 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -72,20 +72,11 @@ static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *f
72 72
73static inline int ip6_output_finish(struct sk_buff *skb) 73static inline int ip6_output_finish(struct sk_buff *skb)
74{ 74{
75
76 struct dst_entry *dst = skb->dst; 75 struct dst_entry *dst = skb->dst;
77 struct hh_cache *hh = dst->hh; 76
78 77 if (dst->hh)
79 if (hh) { 78 return neigh_hh_output(dst->hh, skb);
80 int hh_alen; 79 else if (dst->neighbour)
81
82 read_lock_bh(&hh->hh_lock);
83 hh_alen = HH_DATA_ALIGN(hh->hh_len);
84 memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
85 read_unlock_bh(&hh->hh_lock);
86 skb_push(skb, hh->hh_len);
87 return hh->hh_output(skb);
88 } else if (dst->neighbour)
89 return dst->neighbour->output(skb); 80 return dst->neighbour->output(skb);
90 81
91 IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES); 82 IP6_INC_STATS_BH(ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
index 56ea92837307..6a9f616de37d 100644
--- a/net/ipv6/ndisc.c
+++ b/net/ipv6/ndisc.c
@@ -1667,8 +1667,7 @@ int ndisc_ifinfo_sysctl_change(struct ctl_table *ctl, int write, struct file * f
1667static int ndisc_ifinfo_sysctl_strategy(ctl_table *ctl, int __user *name, 1667static int ndisc_ifinfo_sysctl_strategy(ctl_table *ctl, int __user *name,
1668 int nlen, void __user *oldval, 1668 int nlen, void __user *oldval,
1669 size_t __user *oldlenp, 1669 size_t __user *oldlenp,
1670 void __user *newval, size_t newlen, 1670 void __user *newval, size_t newlen)
1671 void **context)
1672{ 1671{
1673 struct net_device *dev = ctl->extra1; 1672 struct net_device *dev = ctl->extra1;
1674 struct inet6_dev *idev; 1673 struct inet6_dev *idev;
@@ -1681,14 +1680,12 @@ static int ndisc_ifinfo_sysctl_strategy(ctl_table *ctl, int __user *name,
1681 switch (ctl->ctl_name) { 1680 switch (ctl->ctl_name) {
1682 case NET_NEIGH_REACHABLE_TIME: 1681 case NET_NEIGH_REACHABLE_TIME:
1683 ret = sysctl_jiffies(ctl, name, nlen, 1682 ret = sysctl_jiffies(ctl, name, nlen,
1684 oldval, oldlenp, newval, newlen, 1683 oldval, oldlenp, newval, newlen);
1685 context);
1686 break; 1684 break;
1687 case NET_NEIGH_RETRANS_TIME_MS: 1685 case NET_NEIGH_RETRANS_TIME_MS:
1688 case NET_NEIGH_REACHABLE_TIME_MS: 1686 case NET_NEIGH_REACHABLE_TIME_MS:
1689 ret = sysctl_ms_jiffies(ctl, name, nlen, 1687 ret = sysctl_ms_jiffies(ctl, name, nlen,
1690 oldval, oldlenp, newval, newlen, 1688 oldval, oldlenp, newval, newlen);
1691 context);
1692 break; 1689 break;
1693 default: 1690 default:
1694 ret = 0; 1691 ret = 0;
diff --git a/net/irda/ircomm/ircomm_tty_ioctl.c b/net/irda/ircomm/ircomm_tty_ioctl.c
index 197e3e7ed7e2..75e39ea599d8 100644
--- a/net/irda/ircomm/ircomm_tty_ioctl.c
+++ b/net/irda/ircomm/ircomm_tty_ioctl.c
@@ -146,7 +146,7 @@ static void ircomm_tty_change_speed(struct ircomm_tty_cb *self)
146 * do something rational. 146 * do something rational.
147 */ 147 */
148void ircomm_tty_set_termios(struct tty_struct *tty, 148void ircomm_tty_set_termios(struct tty_struct *tty,
149 struct termios *old_termios) 149 struct ktermios *old_termios)
150{ 150{
151 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data; 151 struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
152 unsigned int cflag = tty->termios->c_cflag; 152 unsigned int cflag = tty->termios->c_cflag;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 3baafb10f8f3..276131fe56dd 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -699,7 +699,7 @@ static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
699 699
700struct sock *netlink_getsockbyfilp(struct file *filp) 700struct sock *netlink_getsockbyfilp(struct file *filp)
701{ 701{
702 struct inode *inode = filp->f_dentry->d_inode; 702 struct inode *inode = filp->f_path.dentry->d_inode;
703 struct sock *sock; 703 struct sock *sock;
704 704
705 if (!S_ISSOCK(inode->i_mode)) 705 if (!S_ISSOCK(inode->i_mode))
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index ba82dfab6043..f79a4f3d0a95 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -371,8 +371,6 @@ static void cbq_deactivate_class(struct cbq_class *this)
371 return; 371 return;
372 } 372 }
373 } 373 }
374
375 cl = cl_prev->next_alive;
376 return; 374 return;
377 } 375 }
378 } while ((cl_prev = cl) != q->active[prio]); 376 } while ((cl_prev = cl) != q->active[prio]);
@@ -1258,6 +1256,8 @@ static unsigned int cbq_drop(struct Qdisc* sch)
1258 do { 1256 do {
1259 if (cl->q->ops->drop && (len = cl->q->ops->drop(cl->q))) { 1257 if (cl->q->ops->drop && (len = cl->q->ops->drop(cl->q))) {
1260 sch->q.qlen--; 1258 sch->q.qlen--;
1259 if (!cl->q->q.qlen)
1260 cbq_deactivate_class(cl);
1261 return len; 1261 return len;
1262 } 1262 }
1263 } while ((cl = cl->next_alive) != cl_head); 1263 } while ((cl = cl->next_alive) != cl_head);
@@ -1685,8 +1685,7 @@ static int cbq_graft(struct Qdisc *sch, unsigned long arg, struct Qdisc *new,
1685#endif 1685#endif
1686 } 1686 }
1687 sch_tree_lock(sch); 1687 sch_tree_lock(sch);
1688 *old = cl->q; 1688 *old = xchg(&cl->q, new);
1689 cl->q = new;
1690 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen); 1689 qdisc_tree_decrease_qlen(*old, (*old)->q.qlen);
1691 qdisc_reset(*old); 1690 qdisc_reset(*old);
1692 sch_tree_unlock(sch); 1691 sch_tree_unlock(sch);
@@ -1704,6 +1703,14 @@ cbq_leaf(struct Qdisc *sch, unsigned long arg)
1704 return cl ? cl->q : NULL; 1703 return cl ? cl->q : NULL;
1705} 1704}
1706 1705
1706static void cbq_qlen_notify(struct Qdisc *sch, unsigned long arg)
1707{
1708 struct cbq_class *cl = (struct cbq_class *)arg;
1709
1710 if (cl->q->q.qlen == 0)
1711 cbq_deactivate_class(cl);
1712}
1713
1707static unsigned long cbq_get(struct Qdisc *sch, u32 classid) 1714static unsigned long cbq_get(struct Qdisc *sch, u32 classid)
1708{ 1715{
1709 struct cbq_sched_data *q = qdisc_priv(sch); 1716 struct cbq_sched_data *q = qdisc_priv(sch);
@@ -1988,12 +1995,17 @@ static int cbq_delete(struct Qdisc *sch, unsigned long arg)
1988{ 1995{
1989 struct cbq_sched_data *q = qdisc_priv(sch); 1996 struct cbq_sched_data *q = qdisc_priv(sch);
1990 struct cbq_class *cl = (struct cbq_class*)arg; 1997 struct cbq_class *cl = (struct cbq_class*)arg;
1998 unsigned int qlen;
1991 1999
1992 if (cl->filters || cl->children || cl == &q->link) 2000 if (cl->filters || cl->children || cl == &q->link)
1993 return -EBUSY; 2001 return -EBUSY;
1994 2002
1995 sch_tree_lock(sch); 2003 sch_tree_lock(sch);
1996 2004
2005 qlen = cl->q->q.qlen;
2006 qdisc_reset(cl->q);
2007 qdisc_tree_decrease_qlen(cl->q, qlen);
2008
1997 if (cl->next_alive) 2009 if (cl->next_alive)
1998 cbq_deactivate_class(cl); 2010 cbq_deactivate_class(cl);
1999 2011
@@ -2084,6 +2096,7 @@ static void cbq_walk(struct Qdisc *sch, struct qdisc_walker *arg)
2084static struct Qdisc_class_ops cbq_class_ops = { 2096static struct Qdisc_class_ops cbq_class_ops = {
2085 .graft = cbq_graft, 2097 .graft = cbq_graft,
2086 .leaf = cbq_leaf, 2098 .leaf = cbq_leaf,
2099 .qlen_notify = cbq_qlen_notify,
2087 .get = cbq_get, 2100 .get = cbq_get,
2088 .put = cbq_put, 2101 .put = cbq_put,
2089 .change = cbq_change_class, 2102 .change = cbq_change_class,
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
index 215e68c2b615..15f23c5511a8 100644
--- a/net/sched/sch_htb.c
+++ b/net/sched/sch_htb.c
@@ -147,6 +147,10 @@ struct htb_class {
147 psched_tdiff_t mbuffer; /* max wait time */ 147 psched_tdiff_t mbuffer; /* max wait time */
148 long tokens, ctokens; /* current number of tokens */ 148 long tokens, ctokens; /* current number of tokens */
149 psched_time_t t_c; /* checkpoint time */ 149 psched_time_t t_c; /* checkpoint time */
150
151 int prio; /* For parent to leaf return possible here */
152 int quantum; /* we do backup. Finally full replacement */
153 /* of un.leaf originals should be done. */
150}; 154};
151 155
152/* TODO: maybe compute rate when size is too large .. or drop ? */ 156/* TODO: maybe compute rate when size is too large .. or drop ? */
@@ -1271,6 +1275,38 @@ static void htb_destroy_filters(struct tcf_proto **fl)
1271 } 1275 }
1272} 1276}
1273 1277
1278static inline int htb_parent_last_child(struct htb_class *cl)
1279{
1280 if (!cl->parent)
1281 /* the root class */
1282 return 0;
1283
1284 if (!(cl->parent->children.next == &cl->sibling &&
1285 cl->parent->children.prev == &cl->sibling))
1286 /* not the last child */
1287 return 0;
1288
1289 return 1;
1290}
1291
1292static void htb_parent_to_leaf(struct htb_class *cl, struct Qdisc *new_q)
1293{
1294 struct htb_class *parent = cl->parent;
1295
1296 BUG_TRAP(!cl->level && cl->un.leaf.q && !cl->prio_activity);
1297
1298 parent->level = 0;
1299 memset(&parent->un.inner, 0, sizeof(parent->un.inner));
1300 INIT_LIST_HEAD(&parent->un.leaf.drop_list);
1301 parent->un.leaf.q = new_q ? new_q : &noop_qdisc;
1302 parent->un.leaf.quantum = parent->quantum;
1303 parent->un.leaf.prio = parent->prio;
1304 parent->tokens = parent->buffer;
1305 parent->ctokens = parent->cbuffer;
1306 PSCHED_GET_TIME(parent->t_c);
1307 parent->cmode = HTB_CAN_SEND;
1308}
1309
1274static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl) 1310static void htb_destroy_class(struct Qdisc *sch, struct htb_class *cl)
1275{ 1311{
1276 struct htb_sched *q = qdisc_priv(sch); 1312 struct htb_sched *q = qdisc_priv(sch);
@@ -1328,6 +1364,8 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
1328 struct htb_sched *q = qdisc_priv(sch); 1364 struct htb_sched *q = qdisc_priv(sch);
1329 struct htb_class *cl = (struct htb_class *)arg; 1365 struct htb_class *cl = (struct htb_class *)arg;
1330 unsigned int qlen; 1366 unsigned int qlen;
1367 struct Qdisc *new_q = NULL;
1368 int last_child = 0;
1331 1369
1332 // TODO: why don't allow to delete subtree ? references ? does 1370 // TODO: why don't allow to delete subtree ? references ? does
1333 // tc subsys quarantee us that in htb_destroy it holds no class 1371 // tc subsys quarantee us that in htb_destroy it holds no class
@@ -1335,6 +1373,12 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
1335 if (!list_empty(&cl->children) || cl->filter_cnt) 1373 if (!list_empty(&cl->children) || cl->filter_cnt)
1336 return -EBUSY; 1374 return -EBUSY;
1337 1375
1376 if (!cl->level && htb_parent_last_child(cl)) {
1377 new_q = qdisc_create_dflt(sch->dev, &pfifo_qdisc_ops,
1378 cl->parent->classid);
1379 last_child = 1;
1380 }
1381
1338 sch_tree_lock(sch); 1382 sch_tree_lock(sch);
1339 1383
1340 /* delete from hash and active; remainder in destroy_class */ 1384 /* delete from hash and active; remainder in destroy_class */
@@ -1349,6 +1393,9 @@ static int htb_delete(struct Qdisc *sch, unsigned long arg)
1349 if (cl->prio_activity) 1393 if (cl->prio_activity)
1350 htb_deactivate(q, cl); 1394 htb_deactivate(q, cl);
1351 1395
1396 if (last_child)
1397 htb_parent_to_leaf(cl, new_q);
1398
1352 if (--cl->refcnt == 0) 1399 if (--cl->refcnt == 0)
1353 htb_destroy_class(sch, cl); 1400 htb_destroy_class(sch, cl);
1354 1401
@@ -1483,6 +1530,10 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
1483 cl->un.leaf.quantum = hopt->quantum; 1530 cl->un.leaf.quantum = hopt->quantum;
1484 if ((cl->un.leaf.prio = hopt->prio) >= TC_HTB_NUMPRIO) 1531 if ((cl->un.leaf.prio = hopt->prio) >= TC_HTB_NUMPRIO)
1485 cl->un.leaf.prio = TC_HTB_NUMPRIO - 1; 1532 cl->un.leaf.prio = TC_HTB_NUMPRIO - 1;
1533
1534 /* backup for htb_parent_to_leaf */
1535 cl->quantum = cl->un.leaf.quantum;
1536 cl->prio = cl->un.leaf.prio;
1486 } 1537 }
1487 1538
1488 cl->buffer = hopt->buffer; 1539 cl->buffer = hopt->buffer;
diff --git a/net/socket.c b/net/socket.c
index 29ea1de43ecb..4e396312f8d5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -362,20 +362,20 @@ static int sock_attach_fd(struct socket *sock, struct file *file)
362 this.name = name; 362 this.name = name;
363 this.hash = 0; 363 this.hash = 0;
364 364
365 file->f_dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this); 365 file->f_path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &this);
366 if (unlikely(!file->f_dentry)) 366 if (unlikely(!file->f_path.dentry))
367 return -ENOMEM; 367 return -ENOMEM;
368 368
369 file->f_dentry->d_op = &sockfs_dentry_operations; 369 file->f_path.dentry->d_op = &sockfs_dentry_operations;
370 /* 370 /*
371 * We dont want to push this dentry into global dentry hash table. 371 * We dont want to push this dentry into global dentry hash table.
372 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 372 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED
373 * This permits a working /proc/$pid/fd/XXX on sockets 373 * This permits a working /proc/$pid/fd/XXX on sockets
374 */ 374 */
375 file->f_dentry->d_flags &= ~DCACHE_UNHASHED; 375 file->f_path.dentry->d_flags &= ~DCACHE_UNHASHED;
376 d_instantiate(file->f_dentry, SOCK_INODE(sock)); 376 d_instantiate(file->f_path.dentry, SOCK_INODE(sock));
377 file->f_vfsmnt = mntget(sock_mnt); 377 file->f_path.mnt = mntget(sock_mnt);
378 file->f_mapping = file->f_dentry->d_inode->i_mapping; 378 file->f_mapping = file->f_path.dentry->d_inode->i_mapping;
379 379
380 sock->file = file; 380 sock->file = file;
381 file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops; 381 file->f_op = SOCK_INODE(sock)->i_fop = &socket_file_ops;
@@ -413,7 +413,7 @@ static struct socket *sock_from_file(struct file *file, int *err)
413 if (file->f_op == &socket_file_ops) 413 if (file->f_op == &socket_file_ops)
414 return file->private_data; /* set in sock_map_fd */ 414 return file->private_data; /* set in sock_map_fd */
415 415
416 inode = file->f_dentry->d_inode; 416 inode = file->f_path.dentry->d_inode;
417 if (!S_ISSOCK(inode->i_mode)) { 417 if (!S_ISSOCK(inode->i_mode)) {
418 *err = -ENOTSOCK; 418 *err = -ENOTSOCK;
419 return NULL; 419 return NULL;
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index a02ecc1f230d..e1a104abb782 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -501,7 +501,7 @@ gss_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
501 if (!buf) 501 if (!buf)
502 goto out; 502 goto out;
503 503
504 clnt = RPC_I(filp->f_dentry->d_inode)->private; 504 clnt = RPC_I(filp->f_path.dentry->d_inode)->private;
505 err = -EFAULT; 505 err = -EFAULT;
506 if (copy_from_user(buf, src, mlen)) 506 if (copy_from_user(buf, src, mlen))
507 goto err; 507 goto err;
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index d96fd466a9a4..80aff0474572 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -670,7 +670,7 @@ cache_read(struct file *filp, char __user *buf, size_t count, loff_t *ppos)
670{ 670{
671 struct cache_reader *rp = filp->private_data; 671 struct cache_reader *rp = filp->private_data;
672 struct cache_request *rq; 672 struct cache_request *rq;
673 struct cache_detail *cd = PDE(filp->f_dentry->d_inode)->data; 673 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
674 int err; 674 int err;
675 675
676 if (count == 0) 676 if (count == 0)
@@ -747,7 +747,7 @@ cache_write(struct file *filp, const char __user *buf, size_t count,
747 loff_t *ppos) 747 loff_t *ppos)
748{ 748{
749 int err; 749 int err;
750 struct cache_detail *cd = PDE(filp->f_dentry->d_inode)->data; 750 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
751 751
752 if (count == 0) 752 if (count == 0)
753 return 0; 753 return 0;
@@ -778,7 +778,7 @@ cache_poll(struct file *filp, poll_table *wait)
778 unsigned int mask; 778 unsigned int mask;
779 struct cache_reader *rp = filp->private_data; 779 struct cache_reader *rp = filp->private_data;
780 struct cache_queue *cq; 780 struct cache_queue *cq;
781 struct cache_detail *cd = PDE(filp->f_dentry->d_inode)->data; 781 struct cache_detail *cd = PDE(filp->f_path.dentry->d_inode)->data;
782 782
783 poll_wait(filp, &queue_wait, wait); 783 poll_wait(filp, &queue_wait, wait);
784 784
@@ -1254,7 +1254,7 @@ static struct file_operations content_file_operations = {
1254static ssize_t read_flush(struct file *file, char __user *buf, 1254static ssize_t read_flush(struct file *file, char __user *buf,
1255 size_t count, loff_t *ppos) 1255 size_t count, loff_t *ppos)
1256{ 1256{
1257 struct cache_detail *cd = PDE(file->f_dentry->d_inode)->data; 1257 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1258 char tbuf[20]; 1258 char tbuf[20];
1259 unsigned long p = *ppos; 1259 unsigned long p = *ppos;
1260 int len; 1260 int len;
@@ -1275,7 +1275,7 @@ static ssize_t read_flush(struct file *file, char __user *buf,
1275static ssize_t write_flush(struct file * file, const char __user * buf, 1275static ssize_t write_flush(struct file * file, const char __user * buf,
1276 size_t count, loff_t *ppos) 1276 size_t count, loff_t *ppos)
1277{ 1277{
1278 struct cache_detail *cd = PDE(file->f_dentry->d_inode)->data; 1278 struct cache_detail *cd = PDE(file->f_path.dentry->d_inode)->data;
1279 char tbuf[20]; 1279 char tbuf[20];
1280 char *ep; 1280 char *ep;
1281 long flushtime; 1281 long flushtime;
diff --git a/net/sunrpc/rpc_pipe.c b/net/sunrpc/rpc_pipe.c
index 19703aa9659e..89273d35e0cc 100644
--- a/net/sunrpc/rpc_pipe.c
+++ b/net/sunrpc/rpc_pipe.c
@@ -214,7 +214,7 @@ out:
214static ssize_t 214static ssize_t
215rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset) 215rpc_pipe_read(struct file *filp, char __user *buf, size_t len, loff_t *offset)
216{ 216{
217 struct inode *inode = filp->f_dentry->d_inode; 217 struct inode *inode = filp->f_path.dentry->d_inode;
218 struct rpc_inode *rpci = RPC_I(inode); 218 struct rpc_inode *rpci = RPC_I(inode);
219 struct rpc_pipe_msg *msg; 219 struct rpc_pipe_msg *msg;
220 int res = 0; 220 int res = 0;
@@ -257,7 +257,7 @@ out_unlock:
257static ssize_t 257static ssize_t
258rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset) 258rpc_pipe_write(struct file *filp, const char __user *buf, size_t len, loff_t *offset)
259{ 259{
260 struct inode *inode = filp->f_dentry->d_inode; 260 struct inode *inode = filp->f_path.dentry->d_inode;
261 struct rpc_inode *rpci = RPC_I(inode); 261 struct rpc_inode *rpci = RPC_I(inode);
262 int res; 262 int res;
263 263
@@ -275,7 +275,7 @@ rpc_pipe_poll(struct file *filp, struct poll_table_struct *wait)
275 struct rpc_inode *rpci; 275 struct rpc_inode *rpci;
276 unsigned int mask = 0; 276 unsigned int mask = 0;
277 277
278 rpci = RPC_I(filp->f_dentry->d_inode); 278 rpci = RPC_I(filp->f_path.dentry->d_inode);
279 poll_wait(filp, &rpci->waitq, wait); 279 poll_wait(filp, &rpci->waitq, wait);
280 280
281 mask = POLLOUT | POLLWRNORM; 281 mask = POLLOUT | POLLWRNORM;
@@ -290,7 +290,7 @@ static int
290rpc_pipe_ioctl(struct inode *ino, struct file *filp, 290rpc_pipe_ioctl(struct inode *ino, struct file *filp,
291 unsigned int cmd, unsigned long arg) 291 unsigned int cmd, unsigned long arg)
292{ 292{
293 struct rpc_inode *rpci = RPC_I(filp->f_dentry->d_inode); 293 struct rpc_inode *rpci = RPC_I(filp->f_path.dentry->d_inode);
294 int len; 294 int len;
295 295
296 switch (cmd) { 296 switch (cmd) {
diff --git a/net/unix/garbage.c b/net/unix/garbage.c
index 746c2f4a5fa6..f14ad6635fcc 100644
--- a/net/unix/garbage.c
+++ b/net/unix/garbage.c
@@ -96,7 +96,7 @@ atomic_t unix_tot_inflight = ATOMIC_INIT(0);
96static struct sock *unix_get_socket(struct file *filp) 96static struct sock *unix_get_socket(struct file *filp)
97{ 97{
98 struct sock *u_sock = NULL; 98 struct sock *u_sock = NULL;
99 struct inode *inode = filp->f_dentry->d_inode; 99 struct inode *inode = filp->f_path.dentry->d_inode;
100 100
101 /* 101 /*
102 * Socket ? 102 * Socket ?
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 4f5ff19b992b..f01f8c072852 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -56,6 +56,9 @@ endef
56# gcc support functions 56# gcc support functions
57# See documentation in Documentation/kbuild/makefiles.txt 57# See documentation in Documentation/kbuild/makefiles.txt
58 58
59# output directory for tests below
60TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
61
59# as-option 62# as-option
60# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,) 63# Usage: cflags-y += $(call as-option, -Wa$(comma)-isa=foo,)
61 64
@@ -66,9 +69,11 @@ as-option = $(shell if $(CC) $(CFLAGS) $(1) -Wa,-Z -c -o /dev/null \
66# as-instr 69# as-instr
67# Usage: cflags-y += $(call as-instr, instr, option1, option2) 70# Usage: cflags-y += $(call as-instr, instr, option1, option2)
68 71
69as-instr = $(shell if echo -e "$(1)" | $(AS) >/dev/null 2>&1 -W -Z -o astest$$$$.out ; \ 72as-instr = $(shell if echo -e "$(1)" | \
70 then echo "$(2)"; else echo "$(3)"; fi; \ 73 $(CC) $(AFLAGS) -c -xassembler - \
71 rm -f astest$$$$.out) 74 -o $(TMPOUT)astest$$$$.out > /dev/null 2>&1; \
75 then rm $(TMPOUT)astest$$$$.out; echo "$(2)"; \
76 else echo "$(3)"; fi)
72 77
73# cc-option 78# cc-option
74# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586) 79# Usage: cflags-y += $(call cc-option, -march=winchip-c6, -march=i586)
@@ -97,10 +102,10 @@ cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \
97 102
98# ld-option 103# ld-option
99# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both) 104# Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both)
100ld-option = $(shell if $(CC) $(1) \ 105ld-option = $(shell if $(CC) $(1) -nostdlib -xc /dev/null \
101 -nostdlib -o ldtest$$$$.out -xc /dev/null \ 106 -o $(TMPOUT)ldtest$$$$.out > /dev/null 2>&1; \
102 > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi; \ 107 then rm $(TMPOUT)ldtest$$$$.out; echo "$(1)"; \
103 rm -f ldtest$$$$.out) 108 else echo "$(2)"; fi)
104 109
105### 110###
106# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 111# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index f359b730c2c5..8b809b264d18 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -265,7 +265,7 @@ static void write_src(void)
265 printf("#define ALGN .align 4\n"); 265 printf("#define ALGN .align 4\n");
266 printf("#endif\n"); 266 printf("#endif\n");
267 267
268 printf(".data\n"); 268 printf("\t.section .rodata, \"a\"\n");
269 269
270 /* Provide proper symbols relocatability by their '_text' 270 /* Provide proper symbols relocatability by their '_text'
271 * relativeness. The symbol names cannot be used to construct 271 * relativeness. The symbol names cannot be used to construct
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 44e9cd470543..65fb5e8ea941 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1120,8 +1120,8 @@ static int file_has_perm(struct task_struct *tsk,
1120{ 1120{
1121 struct task_security_struct *tsec = tsk->security; 1121 struct task_security_struct *tsec = tsk->security;
1122 struct file_security_struct *fsec = file->f_security; 1122 struct file_security_struct *fsec = file->f_security;
1123 struct vfsmount *mnt = file->f_vfsmnt; 1123 struct vfsmount *mnt = file->f_path.mnt;
1124 struct dentry *dentry = file->f_dentry; 1124 struct dentry *dentry = file->f_path.dentry;
1125 struct inode *inode = dentry->d_inode; 1125 struct inode *inode = dentry->d_inode;
1126 struct avc_audit_data ad; 1126 struct avc_audit_data ad;
1127 int rc; 1127 int rc;
@@ -1581,7 +1581,7 @@ static int selinux_bprm_alloc_security(struct linux_binprm *bprm)
1581static int selinux_bprm_set_security(struct linux_binprm *bprm) 1581static int selinux_bprm_set_security(struct linux_binprm *bprm)
1582{ 1582{
1583 struct task_security_struct *tsec; 1583 struct task_security_struct *tsec;
1584 struct inode *inode = bprm->file->f_dentry->d_inode; 1584 struct inode *inode = bprm->file->f_path.dentry->d_inode;
1585 struct inode_security_struct *isec; 1585 struct inode_security_struct *isec;
1586 struct bprm_security_struct *bsec; 1586 struct bprm_security_struct *bsec;
1587 u32 newsid; 1587 u32 newsid;
@@ -1621,10 +1621,10 @@ static int selinux_bprm_set_security(struct linux_binprm *bprm)
1621 } 1621 }
1622 1622
1623 AVC_AUDIT_DATA_INIT(&ad, FS); 1623 AVC_AUDIT_DATA_INIT(&ad, FS);
1624 ad.u.fs.mnt = bprm->file->f_vfsmnt; 1624 ad.u.fs.mnt = bprm->file->f_path.mnt;
1625 ad.u.fs.dentry = bprm->file->f_dentry; 1625 ad.u.fs.dentry = bprm->file->f_path.dentry;
1626 1626
1627 if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) 1627 if (bprm->file->f_path.mnt->mnt_flags & MNT_NOSUID)
1628 newsid = tsec->sid; 1628 newsid = tsec->sid;
1629 1629
1630 if (tsec->sid == newsid) { 1630 if (tsec->sid == newsid) {
@@ -1695,9 +1695,10 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1695 struct tty_struct *tty; 1695 struct tty_struct *tty;
1696 struct fdtable *fdt; 1696 struct fdtable *fdt;
1697 long j = -1; 1697 long j = -1;
1698 int drop_tty = 0;
1698 1699
1699 mutex_lock(&tty_mutex); 1700 mutex_lock(&tty_mutex);
1700 tty = current->signal->tty; 1701 tty = get_current_tty();
1701 if (tty) { 1702 if (tty) {
1702 file_list_lock(); 1703 file_list_lock();
1703 file = list_entry(tty->tty_files.next, typeof(*file), f_u.fu_list); 1704 file = list_entry(tty->tty_files.next, typeof(*file), f_u.fu_list);
@@ -1707,15 +1708,17 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1707 than using file_has_perm, as this particular open 1708 than using file_has_perm, as this particular open
1708 file may belong to another process and we are only 1709 file may belong to another process and we are only
1709 interested in the inode-based check here. */ 1710 interested in the inode-based check here. */
1710 struct inode *inode = file->f_dentry->d_inode; 1711 struct inode *inode = file->f_path.dentry->d_inode;
1711 if (inode_has_perm(current, inode, 1712 if (inode_has_perm(current, inode,
1712 FILE__READ | FILE__WRITE, NULL)) { 1713 FILE__READ | FILE__WRITE, NULL)) {
1713 /* Reset controlling tty. */ 1714 drop_tty = 1;
1714 current->signal->tty = NULL;
1715 current->signal->tty_old_pgrp = 0;
1716 } 1715 }
1717 } 1716 }
1718 file_list_unlock(); 1717 file_list_unlock();
1718
1719 /* Reset controlling tty. */
1720 if (drop_tty)
1721 proc_set_tty(current, NULL);
1719 } 1722 }
1720 mutex_unlock(&tty_mutex); 1723 mutex_unlock(&tty_mutex);
1721 1724
@@ -1731,7 +1734,7 @@ static inline void flush_unauthorized_files(struct files_struct * files)
1731 j++; 1734 j++;
1732 i = j * __NFDBITS; 1735 i = j * __NFDBITS;
1733 fdt = files_fdtable(files); 1736 fdt = files_fdtable(files);
1734 if (i >= fdt->max_fds || i >= fdt->max_fdset) 1737 if (i >= fdt->max_fds)
1735 break; 1738 break;
1736 set = fdt->open_fds->fds_bits[j]; 1739 set = fdt->open_fds->fds_bits[j];
1737 if (!set) 1740 if (!set)
@@ -2417,7 +2420,7 @@ static int selinux_inode_listsecurity(struct inode *inode, char *buffer, size_t
2417static int selinux_file_permission(struct file *file, int mask) 2420static int selinux_file_permission(struct file *file, int mask)
2418{ 2421{
2419 int rc; 2422 int rc;
2420 struct inode *inode = file->f_dentry->d_inode; 2423 struct inode *inode = file->f_path.dentry->d_inode;
2421 2424
2422 if (!mask) { 2425 if (!mask) {
2423 /* No permission to check. Existence test. */ 2426 /* No permission to check. Existence test. */
@@ -2594,7 +2597,7 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd,
2594 2597
2595 switch (cmd) { 2598 switch (cmd) {
2596 case F_SETFL: 2599 case F_SETFL:
2597 if (!file->f_dentry || !file->f_dentry->d_inode) { 2600 if (!file->f_path.dentry || !file->f_path.dentry->d_inode) {
2598 err = -EINVAL; 2601 err = -EINVAL;
2599 break; 2602 break;
2600 } 2603 }
@@ -2620,7 +2623,7 @@ static int selinux_file_fcntl(struct file *file, unsigned int cmd,
2620 case F_SETLK64: 2623 case F_SETLK64:
2621 case F_SETLKW64: 2624 case F_SETLKW64:
2622#endif 2625#endif
2623 if (!file->f_dentry || !file->f_dentry->d_inode) { 2626 if (!file->f_path.dentry || !file->f_path.dentry->d_inode) {
2624 err = -EINVAL; 2627 err = -EINVAL;
2625 break; 2628 break;
2626 } 2629 }
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index cd244419c980..c8bf6e172f6e 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -448,7 +448,7 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
448 448
449static ssize_t selinux_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos) 449static ssize_t selinux_transaction_write(struct file *file, const char __user *buf, size_t size, loff_t *pos)
450{ 450{
451 ino_t ino = file->f_dentry->d_inode->i_ino; 451 ino_t ino = file->f_path.dentry->d_inode->i_ino;
452 char *data; 452 char *data;
453 ssize_t rv; 453 ssize_t rv;
454 454
@@ -805,7 +805,7 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,
805 goto out; 805 goto out;
806 } 806 }
807 807
808 inode = filep->f_dentry->d_inode; 808 inode = filep->f_path.dentry->d_inode;
809 cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET); 809 cur_enforcing = security_get_bool_value(inode->i_ino - BOOL_INO_OFFSET);
810 if (cur_enforcing < 0) { 810 if (cur_enforcing < 0) {
811 ret = cur_enforcing; 811 ret = cur_enforcing;
@@ -864,7 +864,7 @@ static ssize_t sel_write_bool(struct file *filep, const char __user *buf,
864 if (new_value) 864 if (new_value)
865 new_value = 1; 865 new_value = 1;
866 866
867 inode = filep->f_dentry->d_inode; 867 inode = filep->f_path.dentry->d_inode;
868 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value; 868 bool_pending_values[inode->i_ino - BOOL_INO_OFFSET] = new_value;
869 length = count; 869 length = count;
870 870
@@ -965,7 +965,7 @@ static void sel_remove_bools(struct dentry *de)
965 file_list_lock(); 965 file_list_lock();
966 list_for_each(p, &sb->s_files) { 966 list_for_each(p, &sb->s_files) {
967 struct file * filp = list_entry(p, struct file, f_u.fu_list); 967 struct file * filp = list_entry(p, struct file, f_u.fu_list);
968 struct dentry * dentry = filp->f_dentry; 968 struct dentry * dentry = filp->f_path.dentry;
969 969
970 if (dentry->d_parent != de) { 970 if (dentry->d_parent != de) {
971 continue; 971 continue;
diff --git a/sound/Kconfig b/sound/Kconfig
index 95949b6806ac..9d77300746c6 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -93,4 +93,12 @@ endmenu
93 93
94endif 94endif
95 95
96config AC97_BUS
97 tristate
98 help
99 This is used to avoid config and link hard dependencies between the
100 sound subsystem and other function drivers completely unrelated to
101 sound although they're sharing the AC97 bus. Concerned drivers
102 should "select" this.
103
96endmenu 104endmenu
diff --git a/sound/Makefile b/sound/Makefile
index 5f6bef57e825..9aee54c4882d 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -8,6 +8,9 @@ obj-$(CONFIG_DMASOUND) += oss/
8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/ 8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ synth/ usb/ sparc/ parisc/ pcmcia/ mips/
9obj-$(CONFIG_SND_AOA) += aoa/ 9obj-$(CONFIG_SND_AOA) += aoa/
10 10
11# This one must be compilable even if sound is configured out
12obj-$(CONFIG_AC97_BUS) += ac97_bus.o
13
11ifeq ($(CONFIG_SND),y) 14ifeq ($(CONFIG_SND),y)
12 obj-y += last.o 15 obj-y += last.o
13endif 16endif
diff --git a/sound/pci/ac97/ac97_bus.c b/sound/ac97_bus.c
index 66de2c2f1554..66de2c2f1554 100644
--- a/sound/pci/ac97/ac97_bus.c
+++ b/sound/ac97_bus.c
diff --git a/sound/core/info.c b/sound/core/info.c
index 0b4aab3225e5..54591e2eb6ee 100644
--- a/sound/core/info.c
+++ b/sound/core/info.c
@@ -488,7 +488,7 @@ static long snd_info_entry_ioctl(struct file *file, unsigned int cmd,
488 488
489static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma) 489static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
490{ 490{
491 struct inode *inode = file->f_dentry->d_inode; 491 struct inode *inode = file->f_path.dentry->d_inode;
492 struct snd_info_private_data *data; 492 struct snd_info_private_data *data;
493 struct snd_info_entry *entry; 493 struct snd_info_entry *entry;
494 494
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 6ea67b16c676..b52e89393fa3 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1604,7 +1604,7 @@ static struct file *snd_pcm_file_fd(int fd)
1604 file = fget(fd); 1604 file = fget(fd);
1605 if (!file) 1605 if (!file)
1606 return NULL; 1606 return NULL;
1607 inode = file->f_dentry->d_inode; 1607 inode = file->f_path.dentry->d_inode;
1608 if (!S_ISCHR(inode->i_mode) || 1608 if (!S_ISCHR(inode->i_mode) ||
1609 imajor(inode) != snd_major) { 1609 imajor(inode) != snd_major) {
1610 fput(file); 1610 fput(file);
diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig
index 7971285dfd5b..40ebd2f44056 100644
--- a/sound/drivers/Kconfig
+++ b/sound/drivers/Kconfig
@@ -26,11 +26,7 @@ config SND_VX_LIB
26config SND_AC97_CODEC 26config SND_AC97_CODEC
27 tristate 27 tristate
28 select SND_PCM 28 select SND_PCM
29 select SND_AC97_BUS 29 select AC97_BUS
30
31config SND_AC97_BUS
32 tristate
33
34 30
35config SND_DUMMY 31config SND_DUMMY
36 tristate "Dummy (/dev/null) soundcard" 32 tristate "Dummy (/dev/null) soundcard"
diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c
index 87bd3100aef3..80b836e80d99 100644
--- a/sound/oss/dmasound/dmasound_core.c
+++ b/sound/oss/dmasound/dmasound_core.c
@@ -1051,7 +1051,7 @@ static int sq_release(struct inode *inode, struct file *file)
1051 1051
1052 if (file->f_mode & FMODE_WRITE) { 1052 if (file->f_mode & FMODE_WRITE) {
1053 if (write_sq.busy) 1053 if (write_sq.busy)
1054 rc = sq_fsync(file, file->f_dentry); 1054 rc = sq_fsync(file, file->f_path.dentry);
1055 1055
1056 sq_reset_output() ; /* make sure dma is stopped and all is quiet */ 1056 sq_reset_output() ; /* make sure dma is stopped and all is quiet */
1057 write_sq_release_buffers(); 1057 write_sq_release_buffers();
@@ -1217,7 +1217,7 @@ static int sq_ioctl(struct inode *inode, struct file *file, u_int cmd,
1217 if ((file->f_mode & FMODE_READ) && dmasound.mach.record) 1217 if ((file->f_mode & FMODE_READ) && dmasound.mach.record)
1218 sq_reset_input() ; 1218 sq_reset_input() ;
1219 if (file->f_mode & FMODE_WRITE) { 1219 if (file->f_mode & FMODE_WRITE) {
1220 result = sq_fsync(file, file->f_dentry); 1220 result = sq_fsync(file, file->f_path.dentry);
1221 sq_reset_output() ; 1221 sq_reset_output() ;
1222 } 1222 }
1223 /* if we are the shared resource owner then release them */ 1223 /* if we are the shared resource owner then release them */
diff --git a/sound/oss/msnd_pinnacle.c b/sound/oss/msnd_pinnacle.c
index d5146790f5e3..24110d63b136 100644
--- a/sound/oss/msnd_pinnacle.c
+++ b/sound/oss/msnd_pinnacle.c
@@ -1007,7 +1007,7 @@ static int dsp_write(const char __user *buf, size_t len)
1007 1007
1008static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off) 1008static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
1009{ 1009{
1010 int minor = iminor(file->f_dentry->d_inode); 1010 int minor = iminor(file->f_path.dentry->d_inode);
1011 if (minor == dev.dsp_minor) 1011 if (minor == dev.dsp_minor)
1012 return dsp_read(buf, count); 1012 return dsp_read(buf, count);
1013 else 1013 else
@@ -1016,7 +1016,7 @@ static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_
1016 1016
1017static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off) 1017static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
1018{ 1018{
1019 int minor = iminor(file->f_dentry->d_inode); 1019 int minor = iminor(file->f_path.dentry->d_inode);
1020 if (minor == dev.dsp_minor) 1020 if (minor == dev.dsp_minor)
1021 return dsp_write(buf, count); 1021 return dsp_write(buf, count);
1022 else 1022 else
diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c
index 8fb8e7f99556..a89108cb74ea 100644
--- a/sound/oss/soundcard.c
+++ b/sound/oss/soundcard.c
@@ -141,7 +141,7 @@ static int get_mixer_levels(void __user * arg)
141 141
142static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 142static ssize_t sound_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
143{ 143{
144 int dev = iminor(file->f_dentry->d_inode); 144 int dev = iminor(file->f_path.dentry->d_inode);
145 int ret = -EINVAL; 145 int ret = -EINVAL;
146 146
147 /* 147 /*
@@ -174,7 +174,7 @@ static ssize_t sound_read(struct file *file, char __user *buf, size_t count, lof
174 174
175static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 175static ssize_t sound_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
176{ 176{
177 int dev = iminor(file->f_dentry->d_inode); 177 int dev = iminor(file->f_path.dentry->d_inode);
178 int ret = -EINVAL; 178 int ret = -EINVAL;
179 179
180 lock_kernel(); 180 lock_kernel();
@@ -393,7 +393,7 @@ static int sound_ioctl(struct inode *inode, struct file *file,
393 393
394static unsigned int sound_poll(struct file *file, poll_table * wait) 394static unsigned int sound_poll(struct file *file, poll_table * wait)
395{ 395{
396 struct inode *inode = file->f_dentry->d_inode; 396 struct inode *inode = file->f_path.dentry->d_inode;
397 int dev = iminor(inode); 397 int dev = iminor(inode);
398 398
399 DEB(printk("sound_poll(dev=%d)\n", dev)); 399 DEB(printk("sound_poll(dev=%d)\n", dev));
@@ -418,7 +418,7 @@ static int sound_mmap(struct file *file, struct vm_area_struct *vma)
418 int dev_class; 418 int dev_class;
419 unsigned long size; 419 unsigned long size;
420 struct dma_buffparms *dmap = NULL; 420 struct dma_buffparms *dmap = NULL;
421 int dev = iminor(file->f_dentry->d_inode); 421 int dev = iminor(file->f_path.dentry->d_inode);
422 422
423 dev_class = dev & 0x0f; 423 dev_class = dev & 0x0f;
424 dev >>= 4; 424 dev >>= 4;
diff --git a/sound/pci/ac97/Makefile b/sound/pci/ac97/Makefile
index 77b3482cb133..3c3222122d8b 100644
--- a/sound/pci/ac97/Makefile
+++ b/sound/pci/ac97/Makefile
@@ -10,11 +10,9 @@ snd-ac97-codec-objs += ac97_proc.o
10endif 10endif
11 11
12snd-ak4531-codec-objs := ak4531_codec.o 12snd-ak4531-codec-objs := ak4531_codec.o
13snd-ac97-bus-objs := ac97_bus.o
14 13
15# Toplevel Module Dependency 14# Toplevel Module Dependency
16obj-$(CONFIG_SND_AC97_CODEC) += snd-ac97-codec.o 15obj-$(CONFIG_SND_AC97_CODEC) += snd-ac97-codec.o
17obj-$(CONFIG_SND_ENS1370) += snd-ak4531-codec.o 16obj-$(CONFIG_SND_ENS1370) += snd-ak4531-codec.o
18obj-$(CONFIG_SND_AC97_BUS) += snd-ac97-bus.o
19 17
20obj-m := $(sort $(obj-m)) 18obj-m := $(sort $(obj-m))
diff --git a/sound/sound_firmware.c b/sound/sound_firmware.c
index 3a181d4c0dc6..3304344713ae 100644
--- a/sound/sound_firmware.c
+++ b/sound/sound_firmware.c
@@ -19,7 +19,7 @@ static int do_mod_firmware_load(const char *fn, char **fp)
19 printk(KERN_INFO "Unable to load '%s'.\n", fn); 19 printk(KERN_INFO "Unable to load '%s'.\n", fn);
20 return 0; 20 return 0;
21 } 21 }
22 l = filp->f_dentry->d_inode->i_size; 22 l = filp->f_path.dentry->d_inode->i_size;
23 if (l <= 0 || l > 131072) 23 if (l <= 0 || l > 131072)
24 { 24 {
25 printk(KERN_INFO "Invalid firmware '%s'\n", fn); 25 printk(KERN_INFO "Invalid firmware '%s'\n", fn);